-
Notifications
You must be signed in to change notification settings - Fork 13
/
run-balance.go
65 lines (50 loc) · 1.26 KB
/
run-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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// SPDX-License-Identifier: ISC
// Copyright (c) 2014-2019 Bitmark Inc.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"github.com/urfave/cli"
"github.com/bitmark-inc/bitmarkd/command/bitmark-cli/rpccalls"
)
func runBalance(c *cli.Context) error {
m := c.App.Metadata["config"].(*metadata)
shareId := c.String("share-id")
count := c.Int("count")
if count <= 0 {
return fmt.Errorf("invalid count: %d", count)
}
name, owner, err := checkRecipient(c, "owner", m.config)
if nil != err {
name = c.GlobalString("identity")
if "" == name {
name = m.config.DefaultIdentity
}
owner, err = m.config.Account(name)
if nil != err {
return err
}
}
if m.verbose {
fmt.Fprintf(m.e, "owner: %s\n", name)
fmt.Fprintf(m.e, "shareId: %s\n", shareId)
fmt.Fprintf(m.e, "count: %d\n", count)
}
client, err := rpccalls.NewClient(m.testnet, m.config.Connections[m.connectionOffset], m.verbose, m.e)
if nil != err {
return err
}
defer client.Close()
balanceConfig := &rpccalls.BalanceData{
Owner: owner,
ShareId: shareId,
Count: count,
}
response, err := client.GetBalance(balanceConfig)
if nil != err {
return err
}
printJson(m.w, response)
return nil
}