-
Notifications
You must be signed in to change notification settings - Fork 13
/
run-share.go
61 lines (47 loc) · 1.21 KB
/
run-share.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
// 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 runShare(c *cli.Context) error {
m := c.App.Metadata["config"].(*metadata)
txId, err := checkTxId(c.String("txid"))
if nil != err {
return err
}
quantity := c.Int("quantity")
if quantity <= 0 {
return fmt.Errorf("invalid quantity: %d", quantity)
}
from, owner, err := checkOwnerWithPasswordPrompt(c.GlobalString("identity"), m.config, c)
if nil != err {
return err
}
if m.verbose {
fmt.Fprintf(m.e, "from: %s\n", from)
fmt.Fprintf(m.e, "txid: %s\n", txId)
fmt.Fprintf(m.e, "quantity: %d\n", quantity)
}
client, err := rpccalls.NewClient(m.testnet, m.config.Connections[m.connectionOffset], m.verbose, m.e)
if nil != err {
return err
}
defer client.Close()
// make Share
shareConfig := &rpccalls.ShareData{
Owner: owner,
TxId: txId,
Quantity: uint64(quantity),
}
response, err := client.Share(shareConfig)
if nil != err {
return err
}
printJson(m.w, response)
return nil
}