This repository has been archived by the owner on Mar 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 284
/
wallet.go
100 lines (69 loc) · 3.79 KB
/
wallet.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
97
98
99
100
package bitcoin
import (
"github.com/OpenBazaar/spvwallet"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
btc "github.com/btcsuite/btcutil"
hd "github.com/btcsuite/btcutil/hdkeychain"
"time"
)
type BitcoinWallet interface {
// Start the wallet
Start()
// Return the network parameters
Params() *chaincfg.Params
// Returns the type of crytocurrency this wallet implements
CurrencyCode() string
// Check if this amount is considered dust
IsDust(amount int64) bool
// Get the master private key
MasterPrivateKey() *hd.ExtendedKey
// Get the master public key
MasterPublicKey() *hd.ExtendedKey
// Get the current address for the given purpose
CurrentAddress(purpose spvwallet.KeyPurpose) btc.Address
// Returns a fresh address that has never been returned by this function
NewAddress(purpose spvwallet.KeyPurpose) btc.Address
// Parse the address string and return an address interface
DecodeAddress(addr string) (btc.Address, error)
// Turn the given output script into an address
ScriptToAddress(script []byte) (btc.Address, error)
// Turn the given address into an output script
AddressToScript(addr btc.Address) ([]byte, error)
// Returns if the wallet has the key for the given address
HasKey(addr btc.Address) bool
// Get the confirmed and unconfirmed balances
Balance() (confirmed, unconfirmed int64)
// Returns a list of transactions for this wallet
Transactions() ([]spvwallet.Txn, error)
// Get info on a specific transaction
GetTransaction(txid chainhash.Hash) (spvwallet.Txn, error)
// Get the height and best hash of the blockchain
ChainTip() (uint32, chainhash.Hash)
// Get the current fee per byte
GetFeePerByte(feeLevel spvwallet.FeeLevel) uint64
// Send bitcoins to an external wallet
Spend(amount int64, addr btc.Address, feeLevel spvwallet.FeeLevel) (*chainhash.Hash, error)
// Bump the fee for the given transaction
BumpFee(txid chainhash.Hash) (*chainhash.Hash, error)
// Calculates the estimated size of the transaction and returns the total fee for the given feePerByte
EstimateFee(ins []spvwallet.TransactionInput, outs []spvwallet.TransactionOutput, feePerByte uint64) uint64
// Build and broadcast a transaction that sweeps all coins from an address. If it is a p2sh multisig, the redeemScript must be included
SweepAddress(utxos []spvwallet.Utxo, address *btc.Address, key *hd.ExtendedKey, redeemScript *[]byte, feeLevel spvwallet.FeeLevel) (*chainhash.Hash, error)
// Create a signature for a multisig transaction
CreateMultisigSignature(ins []spvwallet.TransactionInput, outs []spvwallet.TransactionOutput, key *hd.ExtendedKey, redeemScript []byte, feePerByte uint64) ([]spvwallet.Signature, error)
// Combine signatures and optionally broadcast
Multisign(ins []spvwallet.TransactionInput, outs []spvwallet.TransactionOutput, sigs1 []spvwallet.Signature, sigs2 []spvwallet.Signature, redeemScript []byte, feePerByte uint64, broadcast bool) ([]byte, error)
// Generate a multisig script from public keys. If a timeout is included the returned script should be a timelocked escrow which releases using the timeoutKey.
GenerateMultisigScript(keys []hd.ExtendedKey, threshold int, timeout time.Duration, timeoutKey *hd.ExtendedKey) (addr btc.Address, redeemScript []byte, err error)
// Add a script to the wallet and get notifications back when coins are received or spent from it
AddWatchedScript(script []byte) error
// Add a callback for incoming transactions
AddTransactionListener(func(spvwallet.TransactionCallback))
// Use this to re-download merkle blocks in case of missed transactions
ReSyncBlockchain(fromHeight int32)
// Return the number of confirmations and the height for a transaction
GetConfirmations(txid chainhash.Hash) (confirms, atHeight uint32, err error)
// Cleanly disconnect from the wallet
Close()
}