MCPcopy Create free account
hub / github.com/DNAProject/DNA / GetBalance

Function GetBalance

cmd/utils/gas.go:67–82  ·  view source on GitHub ↗

Return balance of address in base58 code

(address string)

Source from the content-addressed store, hash-verified

65
66//Return balance of address in base58 code
67func GetBalance(address string) (*httpcom.BalanceOfRsp, error) {
68 result, ontErr := sendRpcRequest("getbalance", []interface{}{address})
69 if ontErr != nil {
70 switch ontErr.ErrorCode {
71 case ERROR_INVALID_PARAMS:
72 return nil, fmt.Errorf("invalid address:%s", address)
73 }
74 return nil, ontErr.Error
75 }
76 balance := &httpcom.BalanceOfRsp{}
77 err := json.Unmarshal(result, balance)
78 if err != nil {
79 return nil, fmt.Errorf("json.Unmarshal error:%s", err)
80 }
81 return balance, nil
82}
83
84func GetAccountBalance(address, asset string) (uint64, error) {
85 balances, err := GetBalance(address)

Callers 2

getBalanceFunction · 0.92
GetAccountBalanceFunction · 0.70

Calls 2

sendRpcRequestFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected