-
Notifications
You must be signed in to change notification settings - Fork 13
/
balance.go
48 lines (38 loc) · 1.16 KB
/
balance.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-License-Identifier: ISC
// Copyright (c) 2014-2020 Bitmark Inc.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package rpccalls
import (
"github.com/bitmark-inc/bitmarkd/account"
"github.com/bitmark-inc/bitmarkd/merkle"
"github.com/bitmark-inc/bitmarkd/rpc/share"
)
// BalanceData - the parameters for a balance request
type BalanceData struct {
Owner *account.Account
ShareId string
Count int
}
// GetBalance - retrieve some balance data
func (client *Client) GetBalance(balanceConfig *BalanceData) (*share.BalanceReply, error) {
var shareId merkle.Digest // if not present the all zero id
if "" != balanceConfig.ShareId {
if err := shareId.UnmarshalText([]byte(balanceConfig.ShareId)); nil != err {
return nil, err
}
}
balanceArgs := share.BalanceArguments{
Owner: balanceConfig.Owner,
ShareId: shareId,
Count: balanceConfig.Count,
}
client.printJson("Balance Request", balanceArgs)
reply := &share.BalanceReply{}
err := client.client.Call("Share.Balance", balanceArgs, reply)
if nil != err {
return nil, err
}
client.printJson("Balance Reply", reply)
return reply, nil
}