-
Notifications
You must be signed in to change notification settings - Fork 13
/
run-swap.go
86 lines (67 loc) · 1.9 KB
/
run-swap.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// 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 runSwap(c *cli.Context) error {
m := c.App.Metadata["config"].(*metadata)
to, recipient, err := checkRecipient(c, "receiver", m.config)
if nil != err {
return err
}
shareIdOne, err := checkTxId(c.String("share-id-one"))
if nil != err {
return err
}
quantityOne := c.Uint64("quantity-one")
if quantityOne == 0 {
return fmt.Errorf("invalid quantity-one: %d", quantityOne)
}
shareIdTwo, err := checkTxId(c.String("share-id-two"))
if nil != err {
return err
}
quantityTwo := c.Uint64("quantity-two")
if quantityTwo == 0 {
return fmt.Errorf("invalid quantity-two: %d", quantityTwo)
}
beforeBlock := c.Uint64("before-block")
from, owner, err := checkOwnerWithPasswordPrompt(c.GlobalString("identity"), m.config, c)
if nil != err {
return err
}
if m.verbose {
fmt.Fprintf(m.e, "shareIdOne: %s\n", shareIdOne)
fmt.Fprintf(m.e, "quantityOne: %d\n", quantityOne)
fmt.Fprintf(m.e, "ownerOne: %s\n", from)
fmt.Fprintf(m.e, "shareIdTwo: %s\n", shareIdTwo)
fmt.Fprintf(m.e, "quantityTwo: %d\n", quantityTwo)
fmt.Fprintf(m.e, "ownerTwo: %s\n", to)
fmt.Fprintf(m.e, "beforeBlock: %d\n", beforeBlock)
}
client, err := rpccalls.NewClient(m.testnet, m.config.Connections[m.connectionOffset], m.verbose, m.e)
if nil != err {
return err
}
defer client.Close()
swapConfig := &rpccalls.SwapData{
ShareIdOne: shareIdOne,
QuantityOne: quantityOne,
OwnerOne: owner,
ShareIdTwo: shareIdTwo,
QuantityTwo: quantityTwo,
OwnerTwo: recipient,
BeforeBlock: beforeBlock,
}
response, err := client.Swap(swapConfig)
if nil != err {
return err
}
printJson(m.w, response)
return nil
}