Skip to content

Commit

Permalink
corrected type for assetBalance
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Mar 23, 2024
1 parent 51e92b2 commit 3a8114d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions blockchain/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ type AssetsBalanceRequest struct {
AssetId uint64 `json:"asset_id"`
}
type AssetsBalanceResponse struct {
Amount uint64 `json:"amount"`
}
type MobileAssetsBalanceResponse struct {
Amount string `json:"amount"`
}

Expand Down
29 changes: 28 additions & 1 deletion mobile/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,38 @@ func (c *Client) AccountBalance(account string) ([]byte, error) {
return c.bl.AccountBalance(ctx, c.bloxPid, blockchain.AccountBalanceRequest{Account: account})
}

type AssetsBalanceResponse struct {
Amount uint64 `json:"amount"`
}

// AssetsBalance requests blox at Config.BloxAddr to get the balance of the account.
// the addr must be a valid multiaddr that includes peer ID.
func (c *Client) AssetsBalance(account string, assetId int, classId int) ([]byte, error) {
ctx := context.TODO()
return c.bl.AssetsBalance(ctx, c.bloxPid, blockchain.AssetsBalanceRequest{Account: account, AssetId: uint64(assetId), ClassId: uint64(classId)})
responseBytes, err := c.bl.AssetsBalance(ctx, c.bloxPid, blockchain.AssetsBalanceRequest{Account: account, AssetId: uint64(assetId), ClassId: uint64(classId)})
if err != nil {
return nil, err
}

// Decode the response into the temporary struct
var tempResponse AssetsBalanceResponse
err = json.Unmarshal(responseBytes, &tempResponse)
if err != nil {
return nil, err
}

// Construct a new response with Amount as a string
modifiedResponse := map[string]string{
"amount": strconv.FormatUint(tempResponse.Amount, 10),
}

// Re-encode the modified response to JSON
modifiedResponseBytes, err := json.Marshal(modifiedResponse)
if err != nil {
return nil, err
}

return modifiedResponseBytes, nil
}

// AccountFund requests blox at Config.BloxAddr to fund the account.
Expand Down

0 comments on commit 3a8114d

Please sign in to comment.