-
Notifications
You must be signed in to change notification settings - Fork 13
/
balance.go
46 lines (36 loc) · 1.09 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
// Copyright (c) 2014-2018 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/keypair"
"github.com/bitmark-inc/bitmarkd/merkle"
"github.com/bitmark-inc/bitmarkd/rpc"
)
type BalanceData struct {
Owner *keypair.KeyPair
ShareId string
Count int
}
func (client *Client) GetBalance(balanceConfig *BalanceData) (*rpc.ShareBalanceReply, 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
}
}
ownerAddress := makeAddress(balanceConfig.Owner, client.testnet)
balanceArgs := rpc.ShareBalanceArguments{
Owner: ownerAddress,
ShareId: shareId,
Count: balanceConfig.Count,
}
client.printJson("Balance Request", balanceArgs)
reply := &rpc.ShareBalanceReply{}
err := client.client.Call("Share.Balance", balanceArgs, reply)
if nil != err {
return nil, err
}
client.printJson("Balance Reply", reply)
return reply, nil
}