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.
Files changed (41) hide show
  1. package/dist/index.html +1 -1
  2. package/dist/{mainnet-2.3.15.js → mainnet-2.4.0.js} +15 -5
  3. package/dist/module/history/electrumTransformer.d.ts +11 -3
  4. package/dist/module/history/electrumTransformer.d.ts.map +1 -1
  5. package/dist/module/history/electrumTransformer.js +199 -195
  6. package/dist/module/history/electrumTransformer.js.map +1 -1
  7. package/dist/module/history/interface.d.ts +19 -13
  8. package/dist/module/history/interface.d.ts.map +1 -1
  9. package/dist/module/interface.d.ts +10 -1
  10. package/dist/module/interface.d.ts.map +1 -1
  11. package/dist/module/interface.js.map +1 -1
  12. package/dist/module/network/ElectrumNetworkProvider.d.ts +8 -6
  13. package/dist/module/network/ElectrumNetworkProvider.d.ts.map +1 -1
  14. package/dist/module/network/ElectrumNetworkProvider.js +28 -6
  15. package/dist/module/network/ElectrumNetworkProvider.js.map +1 -1
  16. package/dist/module/network/NetworkProvider.d.ts +8 -3
  17. package/dist/module/network/NetworkProvider.d.ts.map +1 -1
  18. package/dist/module/util/header.d.ts +3 -0
  19. package/dist/module/util/header.d.ts.map +1 -0
  20. package/dist/module/util/header.js +13 -0
  21. package/dist/module/util/header.js.map +1 -0
  22. package/dist/module/util/index.d.ts +1 -0
  23. package/dist/module/util/index.d.ts.map +1 -1
  24. package/dist/module/util/index.js +1 -0
  25. package/dist/module/util/index.js.map +1 -1
  26. package/dist/module/wallet/Wif.d.ts +27 -6
  27. package/dist/module/wallet/Wif.d.ts.map +1 -1
  28. package/dist/module/wallet/Wif.js +29 -7
  29. package/dist/module/wallet/Wif.js.map +1 -1
  30. package/dist/tsconfig.tsbuildinfo +1 -1
  31. package/package.json +1 -1
  32. package/src/history/electrumTransformer.test.ts +112 -55
  33. package/src/history/electrumTransformer.ts +279 -284
  34. package/src/history/interface.ts +19 -13
  35. package/src/interface.ts +11 -1
  36. package/src/network/ElectrumNetworkProvider.ts +58 -11
  37. package/src/network/NetworkProvider.ts +13 -3
  38. package/src/util/header.test.ts +34 -0
  39. package/src/util/header.ts +16 -0
  40. package/src/util/index.ts +1 -0
  41. 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.transactions[0].value).toBe(-2100);
60
- expect(bobHistory.transactions[0].to).toBe(alice.getDepositAddress());
61
- expect(bobHistory.transactions[0].from).toBe(bob.getDepositAddress());
62
- expect(bobHistory.transactions[1].value).toBe(-2100);
63
- expect(bobHistory.transactions[1].from).toBe(bob.getDepositAddress());
64
- expect(bobHistory.transactions[1].to).toBe(charlie.getDepositAddress());
65
- expect(bobHistory.transactions[2].value).toBe(31000);
66
- expect(bobHistory.transactions[2].balance).toBe(31000);
67
- expect(bobHistory.transactions[2].fee).toBe(0);
68
- expect(bobHistory.transactions[2].from).toBe(alice.getDepositAddress());
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.transactions[2].value).toBe(31000);
129
- expect(bobHistory.transactions[2].fee).toBe(0);
130
- expect(bobHistory.transactions[2].from).toBe(alice.getDepositAddress());
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.transactions.length).toBe(4);
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.transactions[0].value).toBe(-2100);
190
- expect(bobHistory.transactions[0].to).toBe(alice.getDepositAddress());
191
- expect(bobHistory.transactions[1].value).toBe(-2100);
192
- expect(bobHistory.transactions[1].to).toBe(alice.getDepositAddress());
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.transactions[0].value).toBeLessThan(-1700);
248
- expect(bobHistory.transactions[0].to).toBe(charlie.getDepositAddress());
249
- expect(bobHistory.transactions[1].from).toBe(alice.getDepositAddress());
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
  });