forked from BuxOrg/bux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmock_chainstate_test.go
170 lines (139 loc) · 4.31 KB
/
mock_chainstate_test.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package bux
import (
"context"
"time"
"github.com/bitcoin-sv/go-broadcast-client/broadcast"
"github.com/libsv/go-bc"
"github.com/tonicpow/go-minercraft/v2"
"github.com/BuxOrg/bux/chainstate"
"github.com/BuxOrg/bux/utils"
)
// chainStateBase is the base interface / methods
type chainStateBase struct{}
func (c *chainStateBase) Broadcast(context.Context, string, string, time.Duration) (string, error) {
return "", nil
}
func (c *chainStateBase) QueryTransaction(context.Context, string,
chainstate.RequiredIn, time.Duration,
) (*chainstate.TransactionInfo, error) {
return nil, nil
}
func (c *chainStateBase) QueryTransactionFastest(context.Context, string, chainstate.RequiredIn,
time.Duration,
) (*chainstate.TransactionInfo, error) {
return nil, nil
}
func (c *chainStateBase) BroadcastMiners() []*chainstate.Miner {
return nil
}
func (c *chainStateBase) Close(context.Context) {}
func (c *chainStateBase) Debug(bool) {}
func (c *chainStateBase) DebugLog(string) {}
func (c *chainStateBase) HTTPClient() chainstate.HTTPInterface {
return nil
}
func (c *chainStateBase) IsDebug() bool {
return false
}
func (c *chainStateBase) IsNewRelicEnabled() bool {
return true
}
func (c *chainStateBase) Minercraft() minercraft.ClientInterface {
return nil
}
func (c *chainStateBase) Miners() []*chainstate.Miner {
return nil
}
func (c *chainStateBase) Network() chainstate.Network {
return chainstate.MainNet
}
func (c *chainStateBase) QueryMiners() []*chainstate.Miner {
return nil
}
func (c *chainStateBase) QueryTimeout() time.Duration {
return 10 * time.Second
}
func (c *chainStateBase) ValidateMiners(_ context.Context) {}
type chainStateEverythingInMempool struct {
chainStateBase
}
func (c *chainStateEverythingInMempool) Broadcast(context.Context, string, string, time.Duration) (string, error) {
return "", nil
}
func (c *chainStateEverythingInMempool) QueryTransaction(_ context.Context, id string,
_ chainstate.RequiredIn, _ time.Duration,
) (*chainstate.TransactionInfo, error) {
minerID, _ := utils.RandomHex(32)
return &chainstate.TransactionInfo{
BlockHash: "",
BlockHeight: 0,
Confirmations: 0,
ID: id,
MinerID: minerID,
Provider: "some-miner-name",
}, nil
}
func (c *chainStateEverythingInMempool) QueryTransactionFastest(_ context.Context, id string, _ chainstate.RequiredIn,
_ time.Duration,
) (*chainstate.TransactionInfo, error) {
minerID, _ := utils.RandomHex(32)
return &chainstate.TransactionInfo{
BlockHash: "",
BlockHeight: 0,
Confirmations: 0,
ID: id,
MinerID: minerID,
Provider: "some-miner-name",
}, nil
}
type chainStateEverythingOnChain struct {
chainStateEverythingInMempool
}
func (c *chainStateEverythingOnChain) Monitor() chainstate.MonitorService {
return nil
}
func (c *chainStateEverythingOnChain) BroadcastClient() broadcast.Client {
return nil
}
func (c *chainStateEverythingOnChain) QueryTransaction(_ context.Context, id string,
_ chainstate.RequiredIn, _ time.Duration,
) (*chainstate.TransactionInfo, error) {
hash, _ := utils.RandomHex(32)
return &chainstate.TransactionInfo{
BlockHash: hash,
BlockHeight: 600000,
Confirmations: 10,
ID: id,
MinerID: "",
Provider: "whatsonchain",
MerkleProof: &bc.MerkleProof{
Index: 37008,
TxOrID: id,
Nodes: []string{"3228f78cfd3c96262ec521225f1b9dd6326b4d3e245d1551bb06258f2101cb65", "05267706279d2e5ebcf89ed0645d4283108c7e850cdb84aeb0974738ae447a8d"},
},
}, nil
}
func (c *chainStateEverythingOnChain) QueryTransactionFastest(_ context.Context, id string, _ chainstate.RequiredIn,
_ time.Duration,
) (*chainstate.TransactionInfo, error) {
hash, _ := utils.RandomHex(32)
return &chainstate.TransactionInfo{
BlockHash: hash,
BlockHeight: 600000,
Confirmations: 10,
ID: id,
MinerID: "",
Provider: "whatsonchain",
MerkleProof: &bc.MerkleProof{
Index: 37008,
TxOrID: id,
Nodes: []string{"3228f78cfd3c96262ec521225f1b9dd6326b4d3e245d1551bb06258f2101cb65", "05267706279d2e5ebcf89ed0645d4283108c7e850cdb84aeb0974738ae447a8d"},
},
}, nil
}
func (c *chainStateEverythingOnChain) FeeUnit() *utils.FeeUnit {
return chainstate.DefaultFee
}
func (c *chainStateEverythingOnChain) VerifyMerkleRoots(_ context.Context, _ []chainstate.MerkleRootConfirmationRequestItem) error {
return nil
}