Skip to content

Commit

Permalink
refactor: account_balance_query now returns AccountBalance
Browse files Browse the repository at this point in the history
  • Loading branch information
andrix10 committed Oct 21, 2020
1 parent 2843883 commit 06c0cc3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion account_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package hedera

type AccountBalance struct {
Hbar Hbar
Token map[TokenID]int64
Token *[]TokenBalance
}
39 changes: 34 additions & 5 deletions account_balance_query.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package hedera

import "github.com/hashgraph/hedera-sdk-go/proto"
import (
"github.com/hashgraph/hedera-sdk-go/proto"
)

// AccountBalanceQuery gets the balance of a CryptoCurrency account. This returns only the balance, so it is a smaller
// and faster reply than AccountInfoQuery, which returns the balance plus additional information.
Expand Down Expand Up @@ -61,9 +63,9 @@ func accountBalanceQuery_getMethod(_ request, channel *channel) method {
}
}

func (query *AccountBalanceQuery) Execute(client *Client) (Hbar, error) {
func (query *AccountBalanceQuery) Execute(client *Client) (AccountBalance, error) {
if client == nil || client.operator == nil {
return Hbar{}, errNoClientProvided
return AccountBalance{}, errNoClientProvided
}

resp, err := execute(
Expand All @@ -80,11 +82,38 @@ func (query *AccountBalanceQuery) Execute(client *Client) (Hbar, error) {
query_mapResponse,
)

//for _, id := range transaction.nodeIDs {
// transaction.pbBody.NodeAccountID = id.toProtobuf()
// bodyBytes, err := protobuf.Marshal(transaction.pbBody)
// if err != nil {
// // This should be unreachable
// // From the documentation this appears to only be possible if there are missing proto types
// panic(err)
// }
//
// sigmap := proto.SignatureMap{
// SigPair: make([]*proto.SignaturePair, 0),
// }
// transaction.signatures = append(transaction.signatures, &sigmap)
// transaction.transactions = append(transaction.transactions, &proto.Transaction{
// BodyBytes: bodyBytes,
// SigMap: &sigmap,
// })
//}

if err != nil {
return Hbar{}, err
return AccountBalance{}, err
}

var tokens []TokenBalance
for i, token := range resp.query.GetCryptogetAccountBalance().TokenBalances {
tokens[i] = tokenBalancesFromProtobuf(token)
}

return HbarFromTinybar(int64(resp.query.GetCryptogetAccountBalance().Balance)), err
return AccountBalance{
Hbar: HbarFromTinybar(int64(resp.query.GetCryptogetAccountBalance().Balance)),
Token: &tokens,
}, nil
}

// SetMaxQueryPayment sets the maximum payment allowed for this Query.
Expand Down

0 comments on commit 06c0cc3

Please sign in to comment.