-
Notifications
You must be signed in to change notification settings - Fork 13
/
run-transfer.go
71 lines (54 loc) · 1.35 KB
/
run-transfer.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
66
67
68
69
70
71
// 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 main
import (
"fmt"
"github.com/urfave/cli"
"github.com/bitmark-inc/bitmarkd/command/bitmark-cli/rpccalls"
)
func runTransfer(c *cli.Context) error {
m := c.App.Metadata["config"].(*metadata)
txId, err := checkTxId(c.String("txid"))
if nil != err {
return err
}
to, recipient, err := checkRecipient(c, "receiver", m.config)
if nil != err {
return err
}
from, owner, err := checkOwnerWithPasswordPrompt(c.GlobalString("identity"), m.config, c)
if nil != err {
return err
}
if m.verbose {
fmt.Fprintf(m.e, "txid: %s\n", txId)
fmt.Fprintf(m.e, "receiver: %s\n", to)
fmt.Fprintf(m.e, "sender: %s\n", from)
}
client, err := rpccalls.NewClient(m.testnet, m.config.Connections[m.connectionOffset], m.verbose, m.e)
if nil != err {
return err
}
defer client.Close()
transferConfig := &rpccalls.TransferData{
Owner: owner,
NewOwner: recipient,
TxId: txId,
}
if c.Bool("unratified") {
response, err := client.Transfer(transferConfig)
if nil != err {
return err
}
printJson(m.w, response)
} else {
response, err := client.SingleSignedTransfer(transferConfig)
if nil != err {
return err
}
printJson(m.w, response)
}
return nil
}