Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/blockonomics-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"time"

"github.com/centum/blockonomics"
"github.com/marcusbello/blockonomics"
)

func main() {
Expand All @@ -16,6 +16,7 @@ func main() {
addr,
txid,
account,
crypto,
currency,
description,
tag string
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/centum/blockonomics
module github.com/marcusbello/blockonomics

go 1.14
6 changes: 5 additions & 1 deletion new_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
25 changes: 22 additions & 3 deletions new_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand Down