Navigation Menu

Skip to content

Commit

Permalink
Create address API
Browse files Browse the repository at this point in the history
  • Loading branch information
crossle committed Oct 14, 2018
1 parent 564937f commit 299e171
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 7 deletions.
67 changes: 67 additions & 0 deletions address.go
@@ -0,0 +1,67 @@
package bot

import (
"context"
"encoding/json"
"time"
)

type AddressInput struct {
AssetId string
Label string
PublicKey string
AccountName string
AccountTag string
}

type Address struct {
AddressId string `json:"address_id"`
AssetId string `json:"asset_id"`
Label string `json:"label"`
PublicKey string `json:"public_key,omitempty"`
AccountName string `json:"account_name,omitempty"`
AccountTag string `json:"account_tag,omitempty"`
Fee string `json:"fee"`
Reserve string `json:"reserve"`
UpdatedAt string `json:"updated_at"`
}

func CreateAddress(ctx context.Context, in *AddressInput, uid, sid, sessionKey, pin, pinToken string) (*Address, error) {
encryptedPIN, err := EncryptPIN(ctx, pin, pinToken, sid, sessionKey, uint64(time.Now().UnixNano()))
if err != nil {
return nil, err
}
data, err := json.Marshal(map[string]interface{}{
"asset_id": in.AssetId,
"label": in.Label,
"public_key": in.PublicKey,
"account_name": in.AccountName,
"account_tag": in.AccountTag,
"pin": encryptedPIN,
})
if err != nil {
return nil, err
}

token, err := SignAuthenticationToken(uid, sid, sessionKey, "POST", "/addresses", string(data))
if err != nil {
return nil, err
}
body, err := Request(ctx, "POST", "/addresses", data, token)
if err != nil {
return nil, err
}

var resp struct {
Data *Address `json:"data"`
Error Error `json:"error"`
}
err = json.Unmarshal(body, &resp)
if err != nil {
return nil, BadDataError(ctx)
}
if resp.Error.Code > 0 {
return nil, resp.Error
}
return resp.Data, nil
}
18 changes: 11 additions & 7 deletions asset.go
Expand Up @@ -6,13 +6,17 @@ import (
)

type Asset struct {
AssetId string `json:"asset_id"`
Symbol string `json:"symbol"`
Name string `json:"name"`
IconURL string `json:"icon_url"`
PriceBTC string `json:"price_btc"`
PriceUSD string `json:"price_usd"`
Balance string `json:"balance"`
AssetId string `json:"asset_id"`
ChainId string `json:"chain_id"`
Symbol string `json:"symbol"`
Name string `json:"name"`
IconURL string `json:"icon_url"`
PriceBTC string `json:"price_btc"`
PriceUSD string `json:"price_usd"`
Balance string `json:"balance"`
PublicKey string `json:"public_key"`
AccountName string `json:"account_name"`
AccountTag string `json:"account_tag"`
}

func AssetList(ctx context.Context, accessToken string) ([]Asset, error) {
Expand Down

0 comments on commit 299e171

Please sign in to comment.