-
Notifications
You must be signed in to change notification settings - Fork 5
/
wallet-operations-advanced.go
96 lines (81 loc) · 2.3 KB
/
wallet-operations-advanced.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
87
88
89
90
91
92
93
94
95
96
package bitgo
import (
"fmt"
)
type TotalBalances struct {
Balance int `json:"balance"`
BalanceString string `json:"balanceString"`
ConfirmedBalance int `json:"confirmedBalance"`
ConfirmedBalanceString string `json:"confirmedBalanceString"`
SpendableBalance int `json:"spendableBalance"`
SpendableBalanceString string `json:"spendableBalanceString"`
}
// Get Total Balances
func (b *BitGo) GetTotalBalances() (total TotalBalances, err error) {
err = b.get(
fmt.Sprintf("%s/wallet/balances",
b.coin),
nil,
&total)
return
}
// Build Transaction
type BuildTransactionParams struct {
Recipients []Recipient `json:"recipients"`
}
type Transaction struct {
TxHex string `json:"txHex"`
TxInfo struct {
NP2SHInputs int `json:"nP2SHInputs"`
NSegwitInputs int `json:"nSegwitInputs"`
NOutputs int `json:"nOutputs"`
Unspents []struct {
Chain int `json:"chain"`
Index int `json:"index"`
RedeemScript string `json:"redeemScript"`
ID string `json:"id"`
Address string `json:"address"`
Value int `json:"value"`
} `json:"unspents"`
ChangeAddresses []string `json:"changeAddresses"`
} `json:"txInfo"`
FeeInfo struct {
Size int `json:"size"`
Fee int `json:"fee"`
FeeRate int `json:"feeRate"`
PayGoFee int `json:"payGoFee"`
PayGoFeeString string `json:"payGoFeeString"`
} `json:"feeInfo"`
}
func (b *BitGo) BuildTransaction(walletId string, params BuildTransactionParams) (transaction Transaction, err error) {
err = b.post(
fmt.Sprintf("%s/wallet/%s/tx/build",
b.coin,
walletId),
params,
&transaction)
return
}
// Sign Transaction
type Keychain struct {
EncryptedPrv string `json:"encryptedPrv"`
}
type SignTransactionParams struct {
TxPrebuild Transaction `json:"txPrebuild"`
Keychain Keychain `json:"keychain"`
WalletPassphrase string `json:"walletPassphrase"`
}
type SignedTransaction struct {
TxHex string `json:"txHex"`
}
func (b *BitGo) SignTransaction(walletId string, params SignTransactionParams) (signedTransaction SignedTransaction, err error) {
err = b.post(
fmt.Sprintf("%s/wallet/%s/signtx",
b.coin,
walletId),
params,
&signedTransaction)
return
}
// Send Transaction
// TODO