diff --git a/client_test.go b/client_test.go index 901302d..023a2ed 100644 --- a/client_test.go +++ b/client_test.go @@ -40,6 +40,7 @@ func (s *BlockonomicsHandlers) NewAddress(w http.ResponseWriter, r *http.Request data.Reset = 1 } data.Account = r.URL.Query().Get("match_account") + data.Crypto = r.URL.Query().Get("crypto") body, err := json.Marshal(&data) if err != nil { @@ -103,7 +104,7 @@ func TestClient(t *testing.T) { c := NewClient("token", WithTimeout(time.Duration(30)*time.Second)) c.APIBase = b.server.URL - _, err := c.NewAddress("", false) + _, err := c.NewAddress("", "BTC", false) if !errors.Is(err, ErrUnauthorised) { t.Error("must be error: ErrUnauthorised") } diff --git a/cmd/blockonomics-cli/main.go b/cmd/blockonomics-cli/main.go index d3c26d7..155b1bb 100644 --- a/cmd/blockonomics-cli/main.go +++ b/cmd/blockonomics-cli/main.go @@ -7,7 +7,7 @@ import ( "os" "time" - "github.com/centum/blockonomics" + "github.com/marcusbello/blockonomics" ) func main() { @@ -16,6 +16,7 @@ func main() { addr, txid, account, + crypto, currency, description, tag string @@ -43,6 +44,7 @@ func main() { case "addr_new": cmd.StringVar(&token, "token", "", "access token to API Blockonomics") cmd.StringVar(&account, "account", "", "get address for account") + cmd.StringVar(&crypto, "crypto", "", "get address for crypto") cmd.BoolVar(&reset, "reset", false, "reset prev address") case "balance": cmd.StringVar(&token, "token", "", "access token to API Blockonomics") @@ -87,7 +89,7 @@ func main() { fmt.Println(api.AddrMonDelete(addr)) case "addr_new": - dump(api.NewAddress(account, reset)) + dump(api.NewAddress(account, crypto, reset)) case "balance": dump(api.Balance(addr)) diff --git a/go.mod b/go.mod index 14b6901..7c1edc2 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/centum/blockonomics +module github.com/marcusbello/blockonomics go 1.14 diff --git a/new_address.go b/new_address.go index 1df1edb..098a515 100644 --- a/new_address.go +++ b/new_address.go @@ -7,11 +7,12 @@ import ( type NewAddress struct { Address string `json:"address"` + Crypto string `json:"crypto,omitempty"` Reset int `json:"reset,omitempty"` Account string `json:"account,omitempty"` } -func (c *APIClient) NewAddress(account string, reset bool) (*NewAddress, error) { +func (c *APIClient) NewAddress(account, crypto string, reset bool) (*NewAddress, error) { req, err := c.newRequest(http.MethodPost, "/api/new_address", nil) if err != nil { return nil, err @@ -25,6 +26,9 @@ func (c *APIClient) NewAddress(account string, reset bool) (*NewAddress, error) if account != "" { params.Add("match_account", account) } + if crypto != "" { + params.Add("crypto", crypto) + } req.URL.RawQuery = params.Encode() var newAddress NewAddress diff --git a/new_address_test.go b/new_address_test.go index d57227e..e00a2b4 100644 --- a/new_address_test.go +++ b/new_address_test.go @@ -16,7 +16,7 @@ func TestNewAddress(t *testing.T) { c.APIBase = b.server.URL t.Run("new address", func(t *testing.T) { - a, err := c.NewAddress("", false) + a, err := c.NewAddress("", "", false) if err != nil { t.Error("error is not nil") } @@ -29,7 +29,7 @@ func TestNewAddress(t *testing.T) { }) t.Run("new address with reset", func(t *testing.T) { - a, err := c.NewAddress("", true) + a, err := c.NewAddress("", "", true) if err != nil { t.Error("error is not nil") } @@ -44,8 +44,27 @@ func TestNewAddress(t *testing.T) { } }) + t.Run("new address with usdt wallet", func(t *testing.T) { + a, err := c.NewAddress("", "USDT", true) + if err != nil { + t.Error("error is not nil") + } + if a == nil { + t.Fatal("address is nil") + } + if a.Address == "" { + t.Fatal("address is empty") + } + if a.Crypto != "USDT" { + t.Fatal("crypto is not USDT") + } + if a.Reset != 1 { + t.Fatal("Reset is not equal 1") + } + }) + t.Run("new address with another account", func(t *testing.T) { - a, err := c.NewAddress("xpub6D9qFCtaxyyP3aAMy6D9qFCtaxyyP3aAMy", false) + a, err := c.NewAddress("xpub6D9qFCtaxyyP3aAMy6D9qFCtaxyyP3aAMy", "", false) if err != nil { t.Error("error is not nil") }