/
client.go
90 lines (80 loc) · 2.56 KB
/
client.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
package client
///////////////////////////////// Client interface ///////////////////////////
//
// architecture
//
// Client
//
// /\
// (controller)
// / \
// / \
// / \
//
// Wallet Node
//
// The client interface describes the behaviors of the client controller.
// It is implemented for each coin asset client.
import (
"context"
"github.com/btcsuite/btcd/wire"
"github.com/dev-warrior777/go-electrum-client/electrumx"
"github.com/dev-warrior777/go-electrum-client/wallet"
)
type NodeType int
const (
// ElectrumX Server(s)
SingleNode NodeType = iota
MultiNode NodeType = 1
)
const (
// Electrum Wallet
GAP_LIMIT = 10
)
type ElectrumClient interface {
Start(ctx context.Context) error
Stop()
//
GetConfig() *ClientConfig
GetWallet() wallet.ElectrumWallet
GetNode() electrumx.ElectrumXNode
//
RegisterTipChangeNotify() (<-chan int64, error)
UnregisterTipChangeNotify()
//
CreateWallet(pw string) error
LoadWallet(pw string) error
RecreateWallet(ctx context.Context, pw, mnenomic string) error
//
SyncWallet(ctx context.Context) error
RescanWallet(ctx context.Context) error
ImportAndSweep(ctx context.Context, keyPairs []string) error
//
// Small subset of electrum-like methods
Tip() (int64, bool)
GetBlockHeader(height int64) *wire.BlockHeader
GetBlockHeaders(startHeight, count int64) ([]*wire.BlockHeader, error)
Spend(pw string, amount int64, toAddress string, feeLevel wallet.FeeLevel) (int, string, string, error)
GetPrivKeyForAddress(pw, addr string) (string, error)
ListUnspent() ([]wallet.Utxo, error)
ListConfirmedUnspent() ([]wallet.Utxo, error)
ListFrozenUnspent() ([]wallet.Utxo, error)
FreezeUTXO(txid string, out uint32) error
UnfreezeUTXO(txid string, out uint32) error
UnusedAddress(ctx context.Context) (string, error)
ChangeAddress(ctx context.Context) (string, error)
ValidateAddress(addr string) (bool, bool, error)
SignTx(pw string, txBytes []byte) ([]byte, error)
GetWalletTx(txid string) (int, bool, []byte, error)
GetWalletSpents() ([]wallet.Stxo, error)
Balance() (int64, int64, int64, error)
// adapt and pass thru
Broadcast(ctx context.Context, rawTx []byte) (string, error)
FeeRate(ctx context.Context, confTarget int64) (int64, error)
//pass thru
GetTransaction(ctx context.Context, txid string) (*electrumx.GetTransactionResult, error)
GetRawTransaction(ctx context.Context, txid string) ([]byte, error)
GetAddressHistory(ctx context.Context, addr string) (electrumx.HistoryResult, error)
GetAddressUnspent(ctx context.Context, addr string) (electrumx.ListUnspentResult, error)
//...
}