mainnet-js 2.3.15 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.html +1 -1
- package/dist/{mainnet-2.3.15.js → mainnet-2.4.0.js} +15 -5
- package/dist/module/history/electrumTransformer.d.ts +11 -3
- package/dist/module/history/electrumTransformer.d.ts.map +1 -1
- package/dist/module/history/electrumTransformer.js +199 -195
- package/dist/module/history/electrumTransformer.js.map +1 -1
- package/dist/module/history/interface.d.ts +19 -13
- package/dist/module/history/interface.d.ts.map +1 -1
- package/dist/module/interface.d.ts +10 -1
- package/dist/module/interface.d.ts.map +1 -1
- package/dist/module/interface.js.map +1 -1
- package/dist/module/network/ElectrumNetworkProvider.d.ts +8 -6
- package/dist/module/network/ElectrumNetworkProvider.d.ts.map +1 -1
- package/dist/module/network/ElectrumNetworkProvider.js +28 -6
- package/dist/module/network/ElectrumNetworkProvider.js.map +1 -1
- package/dist/module/network/NetworkProvider.d.ts +8 -3
- package/dist/module/network/NetworkProvider.d.ts.map +1 -1
- package/dist/module/util/header.d.ts +3 -0
- package/dist/module/util/header.d.ts.map +1 -0
- package/dist/module/util/header.js +13 -0
- package/dist/module/util/header.js.map +1 -0
- package/dist/module/util/index.d.ts +1 -0
- package/dist/module/util/index.d.ts.map +1 -1
- package/dist/module/util/index.js +1 -0
- package/dist/module/util/index.js.map +1 -1
- package/dist/module/wallet/Wif.d.ts +27 -6
- package/dist/module/wallet/Wif.d.ts.map +1 -1
- package/dist/module/wallet/Wif.js +29 -7
- package/dist/module/wallet/Wif.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/history/electrumTransformer.test.ts +112 -55
- package/src/history/electrumTransformer.ts +279 -284
- package/src/history/interface.ts +19 -13
- package/src/interface.ts +11 -1
- package/src/network/ElectrumNetworkProvider.ts +58 -11
- package/src/network/NetworkProvider.ts +13 -3
- package/src/util/header.test.ts +34 -0
- package/src/util/header.ts +16 -0
- package/src/util/index.ts +1 -0
- package/src/wallet/Wif.ts +55 -21
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { RegTestWallet } from "../wallet/Wif";
|
|
1
|
+
import { RegTestWallet, Wallet } from "../wallet/Wif";
|
|
2
2
|
import { WalletTypeEnum } from "../wallet/enum";
|
|
3
3
|
import { createWallet } from "../wallet/createWallet";
|
|
4
|
-
import { getAddressHistory } from "./electrumTransformer";
|
|
5
4
|
import { mine } from "../mine";
|
|
5
|
+
import { getAddressHistory } from "./electrumTransformer";
|
|
6
6
|
|
|
7
|
-
// This class transforms outputs from electrum to a standard array of history.
|
|
7
|
+
// // This class transforms outputs from electrum to a standard array of history.
|
|
8
8
|
test("Should get an address history", async () => {
|
|
9
9
|
// Build Alice's wallet from Wallet Import Format string
|
|
10
10
|
if (!process.env.PRIVATE_WIF) {
|
|
@@ -52,20 +52,40 @@ test("Should get an address history", async () => {
|
|
|
52
52
|
await mine({ cashaddr: alice.getDepositAddress(), blocks: 10 });
|
|
53
53
|
|
|
54
54
|
// Build Bob's wallet from a public address, check his balance.
|
|
55
|
-
const bobHistory = await getAddressHistory(
|
|
56
|
-
bob.getDepositAddress(),
|
|
57
|
-
bob.provider
|
|
58
|
-
);
|
|
59
|
-
expect(bobHistory
|
|
60
|
-
expect(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
expect(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
const bobHistory = await getAddressHistory({
|
|
56
|
+
address: bob.getDepositAddress(),
|
|
57
|
+
provider: bob.provider!,
|
|
58
|
+
});
|
|
59
|
+
expect(bobHistory[0].valueChange).toBe(-2320);
|
|
60
|
+
expect(
|
|
61
|
+
bobHistory[0].outputs.some(
|
|
62
|
+
(output) => output.address === alice.getDepositAddress()
|
|
63
|
+
)
|
|
64
|
+
).toBe(true);
|
|
65
|
+
expect(
|
|
66
|
+
bobHistory[0].inputs.some(
|
|
67
|
+
(input) => input.address === bob.getDepositAddress()
|
|
68
|
+
)
|
|
69
|
+
).toBe(true);
|
|
70
|
+
expect(bobHistory[1].valueChange).toBe(-2320);
|
|
71
|
+
expect(
|
|
72
|
+
bobHistory[1].inputs.some(
|
|
73
|
+
(input) => input.address === bob.getDepositAddress()
|
|
74
|
+
)
|
|
75
|
+
).toBe(true);
|
|
76
|
+
expect(
|
|
77
|
+
bobHistory[1].outputs.some(
|
|
78
|
+
(output) => output.address === charlie.getDepositAddress()
|
|
79
|
+
)
|
|
80
|
+
).toBe(true);
|
|
81
|
+
expect(bobHistory[2].valueChange).toBe(31000);
|
|
82
|
+
expect(bobHistory[2].balance).toBe(31000);
|
|
83
|
+
expect(bobHistory[2].fee).not.toBe(0);
|
|
84
|
+
expect(
|
|
85
|
+
bobHistory[2].inputs.some(
|
|
86
|
+
(input) => input.address === alice.getDepositAddress()
|
|
87
|
+
)
|
|
88
|
+
).toBe(true);
|
|
69
89
|
}
|
|
70
90
|
});
|
|
71
91
|
|
|
@@ -98,36 +118,57 @@ test("Should get a history with multi-party sends", async () => {
|
|
|
98
118
|
value: 2100,
|
|
99
119
|
unit: "satoshis",
|
|
100
120
|
},
|
|
121
|
+
]);
|
|
122
|
+
await mine({ cashaddr: alice.getDepositAddress(), blocks: 1 });
|
|
123
|
+
await bob.send([
|
|
101
124
|
{
|
|
102
125
|
cashaddr: alice.cashaddr!,
|
|
103
126
|
value: 2100,
|
|
104
127
|
unit: "satoshis",
|
|
105
128
|
},
|
|
106
129
|
]);
|
|
107
|
-
await mine({ cashaddr: alice.getDepositAddress(), blocks: 1 });
|
|
108
130
|
expect(sendResponse!.txId!.length).toBe(64);
|
|
109
131
|
expect(sendResponse.balance!.bch).toBeGreaterThan(0.01);
|
|
110
132
|
await mine({ cashaddr: alice.getDepositAddress(), blocks: 1 });
|
|
111
133
|
|
|
112
134
|
// Build Bob's wallet from a public address, check his balance.
|
|
113
|
-
const bobHistory = await getAddressHistory(
|
|
114
|
-
bob.getDepositAddress(),
|
|
115
|
-
bob.provider
|
|
116
|
-
);
|
|
117
|
-
expect(bobHistory.transactions[1].txn).toBe(bobHistory.transactions[0].txn);
|
|
118
|
-
expect(bobHistory.transactions[1].fee).toBe(bobHistory.transactions[0].fee);
|
|
119
|
-
expect(bobHistory.transactions[1].fee).toBeGreaterThan(120);
|
|
120
|
-
expect(bobHistory.transactions[1].fee).toBeLessThan(150);
|
|
121
|
-
expect(bobHistory.transactions[0].value).toBe(-2100);
|
|
122
|
-
expect(bobHistory.transactions[0].to).toBe(alice.getDepositAddress());
|
|
123
|
-
expect(bobHistory.transactions[0].from).toBe(bob.getDepositAddress());
|
|
124
|
-
expect(bobHistory.transactions[1].value).toBe(-2100);
|
|
125
|
-
expect(bobHistory.transactions[1].to).toBe(charlie.getDepositAddress());
|
|
126
|
-
expect(bobHistory.transactions[1].from).toBe(bob.getDepositAddress());
|
|
135
|
+
const bobHistory = await getAddressHistory({
|
|
136
|
+
address: bob.getDepositAddress(),
|
|
137
|
+
provider: bob.provider!,
|
|
138
|
+
});
|
|
127
139
|
|
|
128
|
-
expect(bobHistory
|
|
129
|
-
expect(bobHistory
|
|
130
|
-
expect(bobHistory
|
|
140
|
+
expect(bobHistory[1].fee).toBeGreaterThan(120);
|
|
141
|
+
expect(bobHistory[1].fee).toBe(220);
|
|
142
|
+
expect(bobHistory[0].valueChange).toBe(-2320);
|
|
143
|
+
expect(
|
|
144
|
+
bobHistory[0].outputs.some(
|
|
145
|
+
(output) => output.address === alice.getDepositAddress()
|
|
146
|
+
)
|
|
147
|
+
).toBe(true);
|
|
148
|
+
expect(
|
|
149
|
+
bobHistory[0].inputs.some(
|
|
150
|
+
(input) => input.address === bob.getDepositAddress()
|
|
151
|
+
)
|
|
152
|
+
).toBe(true);
|
|
153
|
+
expect(bobHistory[1].valueChange).toBe(-2320);
|
|
154
|
+
expect(
|
|
155
|
+
bobHistory[1].outputs.some(
|
|
156
|
+
(output) => output.address === charlie.getDepositAddress()
|
|
157
|
+
)
|
|
158
|
+
).toBe(true);
|
|
159
|
+
expect(
|
|
160
|
+
bobHistory[1].inputs.some(
|
|
161
|
+
(input) => input.address === bob.getDepositAddress()
|
|
162
|
+
)
|
|
163
|
+
).toBe(true);
|
|
164
|
+
|
|
165
|
+
expect(bobHistory[2].valueChange).toBe(31000);
|
|
166
|
+
expect(bobHistory[2].fee).not.toBe(0);
|
|
167
|
+
expect(
|
|
168
|
+
bobHistory[2].inputs.some(
|
|
169
|
+
(input) => input.address === alice.getDepositAddress()
|
|
170
|
+
)
|
|
171
|
+
).toBe(true);
|
|
131
172
|
}
|
|
132
173
|
});
|
|
133
174
|
|
|
@@ -177,19 +218,27 @@ test("Should cut results with a longer history to given count", async () => {
|
|
|
177
218
|
await mine({ cashaddr: alice.getDepositAddress(), blocks: 10 });
|
|
178
219
|
|
|
179
220
|
// Build Bob's wallet from a public address, check his balance.
|
|
180
|
-
const bobHistory = await getAddressHistory(
|
|
181
|
-
bob.getDepositAddress(),
|
|
182
|
-
bob.provider!,
|
|
183
|
-
"sat",
|
|
184
|
-
0,
|
|
185
|
-
2
|
|
186
|
-
);
|
|
187
|
-
expect(bobHistory.
|
|
221
|
+
const bobHistory = await getAddressHistory({
|
|
222
|
+
address: bob.getDepositAddress(),
|
|
223
|
+
provider: bob.provider!,
|
|
224
|
+
unit: "sat",
|
|
225
|
+
start: 0,
|
|
226
|
+
count: 2,
|
|
227
|
+
});
|
|
228
|
+
expect(bobHistory.length).toBe(2);
|
|
188
229
|
|
|
189
|
-
expect(bobHistory
|
|
190
|
-
expect(
|
|
191
|
-
|
|
192
|
-
|
|
230
|
+
expect(bobHistory[0].valueChange).toBe(-6588);
|
|
231
|
+
expect(
|
|
232
|
+
bobHistory[0].outputs.some(
|
|
233
|
+
(output) => output.address === alice.getDepositAddress()
|
|
234
|
+
)
|
|
235
|
+
).toBe(true);
|
|
236
|
+
expect(bobHistory[1].valueChange).toBe(31000);
|
|
237
|
+
expect(
|
|
238
|
+
bobHistory[1].outputs.some(
|
|
239
|
+
(output) => output.address === alice.getDepositAddress()
|
|
240
|
+
)
|
|
241
|
+
).toBe(true);
|
|
193
242
|
}
|
|
194
243
|
});
|
|
195
244
|
|
|
@@ -238,14 +287,22 @@ test("Should handel input and fee from many utxos", async () => {
|
|
|
238
287
|
await mine({ cashaddr: alice.getDepositAddress(), blocks: 10 });
|
|
239
288
|
|
|
240
289
|
// Build Bob's wallet from a public address, check his balance.
|
|
241
|
-
const bobHistory = await getAddressHistory(
|
|
242
|
-
bob.getDepositAddress(),
|
|
243
|
-
bob.provider!,
|
|
244
|
-
"sat"
|
|
245
|
-
);
|
|
290
|
+
const bobHistory = await getAddressHistory({
|
|
291
|
+
address: bob.getDepositAddress(),
|
|
292
|
+
provider: bob.provider!,
|
|
293
|
+
unit: "sat",
|
|
294
|
+
});
|
|
246
295
|
|
|
247
|
-
expect(bobHistory
|
|
248
|
-
expect(
|
|
249
|
-
|
|
296
|
+
expect(bobHistory[0].valueChange).toBeLessThan(-1700);
|
|
297
|
+
expect(
|
|
298
|
+
bobHistory[0].outputs.some(
|
|
299
|
+
(output) => output.address === charlie.getDepositAddress()
|
|
300
|
+
)
|
|
301
|
+
).toBe(true);
|
|
302
|
+
expect(
|
|
303
|
+
bobHistory[1].inputs.some(
|
|
304
|
+
(input) => input.address === alice.getDepositAddress()
|
|
305
|
+
)
|
|
306
|
+
).toBe(true);
|
|
250
307
|
}
|
|
251
308
|
});
|