@leofcoin/chain 1.6.11 → 1.6.13
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/exports/browser/{browser-Ei0BXMlu-9eQR3AGp.js → browser-Ei0BXMlu-_DPyExz0.js} +2 -2
- package/exports/browser/chain.js +736 -683
- package/exports/browser/{client-A009z8av-DavUUkay.js → client-A009z8av-Dw6NYFQr.js} +4 -4
- package/exports/browser/{index-Bz6K16zr.js → index--C9N9ZXK.js} +42 -52
- package/exports/browser/{index-G74WLzL7-d1Vs_wqe.js → index-G74WLzL7-BZ6_sy39.js} +2 -2
- package/exports/browser/{index-YQrIDBUQ-CbL47K_x.js → index-YQrIDBUQ-CqYDmtzG.js} +2 -2
- package/exports/browser/{messages-lWRTai7t-Cs3eU5Cb.js → messages-lWRTai7t-3F-6Qszg.js} +2 -2
- package/exports/browser/{node-browser-CC3grAN3.js → node-browser-DRoVQRWp.js} +4 -4
- package/exports/browser/node-browser.js +2 -2
- package/exports/browser/workers/block-worker.js +1 -1
- package/exports/browser/workers/machine-worker.js +66 -28
- package/exports/browser/workers/{worker-CFrwP8cD.js → worker-Cqj1ERFr.js} +38 -48
- package/exports/chain.js +62 -26
- package/exports/machine.d.ts +11 -0
- package/exports/workers/block-worker.js +1 -1
- package/exports/workers/machine-worker.js +66 -28
- package/exports/workers/{worker-CFrwP8cD.js → worker-Cqj1ERFr.js} +38 -48
- package/package.json +13 -13
package/exports/chain.js
CHANGED
|
@@ -282,7 +282,15 @@ class Machine {
|
|
|
282
282
|
index: 0,
|
|
283
283
|
hash: ''
|
|
284
284
|
},
|
|
285
|
-
accounts: {}
|
|
285
|
+
accounts: {},
|
|
286
|
+
info: {
|
|
287
|
+
nativeCalls: 0,
|
|
288
|
+
nativeMints: 0,
|
|
289
|
+
nativeBurns: 0,
|
|
290
|
+
nativeTransfers: 0,
|
|
291
|
+
totalTransactions: 0,
|
|
292
|
+
totalBlocks: 0
|
|
293
|
+
}
|
|
286
294
|
};
|
|
287
295
|
// @ts-ignore
|
|
288
296
|
return this.#init(blocks);
|
|
@@ -338,8 +346,8 @@ class Machine {
|
|
|
338
346
|
break;
|
|
339
347
|
}
|
|
340
348
|
case 'ask': {
|
|
341
|
-
if (data.question === 'contract') {
|
|
342
|
-
const input = await peernet.get(data.input,
|
|
349
|
+
if (data.question === 'contract' || data.question === 'transaction') {
|
|
350
|
+
const input = await peernet.get(data.input, data.question);
|
|
343
351
|
this.worker.postMessage({ id: data.id, input });
|
|
344
352
|
}
|
|
345
353
|
}
|
|
@@ -376,7 +384,18 @@ class Machine {
|
|
|
376
384
|
const tasks = [
|
|
377
385
|
stateStore.put('lastBlock', JSON.stringify(await this.lastBlock)),
|
|
378
386
|
stateStore.put('states', JSON.stringify(state)),
|
|
379
|
-
stateStore.put('accounts', JSON.stringify(accounts))
|
|
387
|
+
stateStore.put('accounts', JSON.stringify(accounts)),
|
|
388
|
+
stateStore.put('info', JSON.stringify({
|
|
389
|
+
nativeCalls: this.nativeCalls,
|
|
390
|
+
nativeMints: this.nativeMints,
|
|
391
|
+
nativeBurns: this.nativeBurns,
|
|
392
|
+
nativeTransfers: this.nativeTransfers,
|
|
393
|
+
totalTransactions: this.totalTransactions,
|
|
394
|
+
totalBurnAmount: this.totalBurnAmount,
|
|
395
|
+
totaMintAmount: this.totaMintAmount,
|
|
396
|
+
totalTransferAmount: this.totalTransferAmount,
|
|
397
|
+
totalBlocks: await blockStore.length
|
|
398
|
+
}))
|
|
380
399
|
// accountsStore.clear()
|
|
381
400
|
];
|
|
382
401
|
await Promise.all(tasks);
|
|
@@ -415,9 +434,19 @@ class Machine {
|
|
|
415
434
|
this.states.states = JSON.parse(new TextDecoder().decode(await stateStore.get('states')));
|
|
416
435
|
try {
|
|
417
436
|
this.states.accounts = JSON.parse(new TextDecoder().decode(await stateStore.get('accounts')));
|
|
437
|
+
this.states.info = JSON.parse(new TextDecoder().decode(await stateStore.get('info')));
|
|
418
438
|
}
|
|
419
439
|
catch {
|
|
420
440
|
this.states.accounts = {};
|
|
441
|
+
// todo try fetching info from fully synced peer
|
|
442
|
+
this.states.info = {
|
|
443
|
+
nativeCalls: 0,
|
|
444
|
+
nativeMints: 0,
|
|
445
|
+
nativeBurns: 0,
|
|
446
|
+
nativeTransfers: 0,
|
|
447
|
+
totalTransactions: 0,
|
|
448
|
+
totalBlocks: 0
|
|
449
|
+
};
|
|
421
450
|
}
|
|
422
451
|
console.log({ balances: this.states.states[addresses.nativeToken].balances });
|
|
423
452
|
}
|
|
@@ -428,6 +457,7 @@ class Machine {
|
|
|
428
457
|
fromState: this.states.lastBlock.index > 0,
|
|
429
458
|
lastBlock: this.states.lastBlock,
|
|
430
459
|
state: this.states.states,
|
|
460
|
+
info: this.states.info,
|
|
431
461
|
// @ts-ignore
|
|
432
462
|
peerid: peernet.peerId
|
|
433
463
|
}
|
|
@@ -593,6 +623,15 @@ class Machine {
|
|
|
593
623
|
get totalBlocks() {
|
|
594
624
|
return this.#askWorker('totalBlocks');
|
|
595
625
|
}
|
|
626
|
+
get totalBurnAmount() {
|
|
627
|
+
return this.#askWorker('totalBurnAmount');
|
|
628
|
+
}
|
|
629
|
+
get totaMintAmount() {
|
|
630
|
+
return this.#askWorker('totaMintAmount');
|
|
631
|
+
}
|
|
632
|
+
get totalTransferAmount() {
|
|
633
|
+
return this.#askWorker('totalTransferAmount');
|
|
634
|
+
}
|
|
596
635
|
getBlocks(from, to) {
|
|
597
636
|
return this.#askWorker('blocks', { from, to });
|
|
598
637
|
}
|
|
@@ -1418,9 +1457,11 @@ class Chain extends VersionControl {
|
|
|
1418
1457
|
else if (!this.knownBlocks)
|
|
1419
1458
|
this.knownBlocks = await this.#makeRequest(peer, 'knownBlocks');
|
|
1420
1459
|
}
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1460
|
+
setTimeout(async () => {
|
|
1461
|
+
const peerTransactionPool = (higherThenCurrentLocal && (await this.getPeerTransactionPool(peer))) || [];
|
|
1462
|
+
if (this.#participating && peerTransactionPool.length > 0)
|
|
1463
|
+
return this.#runEpoch();
|
|
1464
|
+
}, 3000);
|
|
1424
1465
|
}
|
|
1425
1466
|
#epochTimeout;
|
|
1426
1467
|
async #transactionPoolHandler() {
|
|
@@ -1449,27 +1490,25 @@ class Chain extends VersionControl {
|
|
|
1449
1490
|
async #addBlock(block) {
|
|
1450
1491
|
const blockMessage = await new BlockMessage(block);
|
|
1451
1492
|
const hash = await blockMessage.hash();
|
|
1452
|
-
await Promise.all(blockMessage.decoded.transactions
|
|
1453
|
-
// @ts-ignore
|
|
1454
|
-
.map(async (transaction) => {
|
|
1493
|
+
const transactionsMessages = await Promise.all(blockMessage.decoded.transactions
|
|
1455
1494
|
// @ts-ignore
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
hash = await new TransactionMessage(transaction).hash();
|
|
1459
|
-
// @ts-ignore
|
|
1460
|
-
transaction.hash = hash;
|
|
1461
|
-
}
|
|
1495
|
+
.map(async (hash) => {
|
|
1496
|
+
let data;
|
|
1462
1497
|
if (!(await transactionStore.has(hash))) {
|
|
1463
|
-
|
|
1498
|
+
data = await peernet.get(hash, 'transaction');
|
|
1499
|
+
transactionStore.put(hash, data);
|
|
1500
|
+
}
|
|
1501
|
+
else {
|
|
1502
|
+
data = transactionStore.get(hash);
|
|
1464
1503
|
}
|
|
1465
1504
|
(await transactionPoolStore.has(hash)) && (await transactionPoolStore.delete(hash));
|
|
1466
|
-
return
|
|
1505
|
+
return new TransactionMessage(data).decode();
|
|
1467
1506
|
}));
|
|
1468
1507
|
await globalThis.blockStore.put(hash, blockMessage.encoded);
|
|
1469
1508
|
debug(`added block: ${hash}`);
|
|
1470
1509
|
let promises = [];
|
|
1471
1510
|
let contracts = [];
|
|
1472
|
-
for (let transaction of
|
|
1511
|
+
for (let transaction of transactionsMessages) {
|
|
1473
1512
|
// await transactionStore.put(transaction.hash, transaction.encoded)
|
|
1474
1513
|
if (!contracts.includes(transaction.to)) {
|
|
1475
1514
|
contracts.push(transaction.to);
|
|
@@ -1481,7 +1520,7 @@ class Chain extends VersionControl {
|
|
|
1481
1520
|
try {
|
|
1482
1521
|
promises = await Promise.allSettled(promises);
|
|
1483
1522
|
const noncesByAddress = {};
|
|
1484
|
-
for (let transaction of
|
|
1523
|
+
for (let transaction of transactionsMessages) {
|
|
1485
1524
|
globalThis.pubsub.publish('transaction-processed', transaction);
|
|
1486
1525
|
if (transaction.to === globalThis.peernet.selectedAccount)
|
|
1487
1526
|
globalThis.pubsub.publish('account-transaction-processed', transaction);
|
|
@@ -1528,7 +1567,7 @@ class Chain extends VersionControl {
|
|
|
1528
1567
|
async #handleTransaction(transaction, latestTransactions, block) {
|
|
1529
1568
|
const hash = await transaction.hash();
|
|
1530
1569
|
const doubleTransactions = [];
|
|
1531
|
-
if (latestTransactions.includes(hash)) {
|
|
1570
|
+
if (latestTransactions.includes(hash) || transactionStore.has(hash)) {
|
|
1532
1571
|
doubleTransactions.push(hash);
|
|
1533
1572
|
}
|
|
1534
1573
|
if (doubleTransactions.length > 0) {
|
|
@@ -1539,7 +1578,7 @@ class Chain extends VersionControl {
|
|
|
1539
1578
|
// if (timestamp + this.#slotTime > Date.now()) {
|
|
1540
1579
|
try {
|
|
1541
1580
|
const result = await this.#executeTransaction({ ...transaction.decoded, hash });
|
|
1542
|
-
block.transactions.push(
|
|
1581
|
+
block.transactions.push(hash);
|
|
1543
1582
|
block.fees = block.fees.add(await calculateFee(transaction.decoded));
|
|
1544
1583
|
await globalThis.accountsStore.put(transaction.decoded.from, new TextEncoder().encode(String(transaction.decoded.nonce)));
|
|
1545
1584
|
}
|
|
@@ -1644,10 +1683,7 @@ class Chain extends VersionControl {
|
|
|
1644
1683
|
// block.reward = block.reward.toString()
|
|
1645
1684
|
// block.fees = block.fees.toString()
|
|
1646
1685
|
try {
|
|
1647
|
-
|
|
1648
|
-
await globalThis.transactionPoolStore.delete(await transaction.hash());
|
|
1649
|
-
return transaction.decoded;
|
|
1650
|
-
}));
|
|
1686
|
+
await Promise.all(block.transactions.map(async (transaction) => await globalThis.transactionPoolStore.delete(transaction)));
|
|
1651
1687
|
let blockMessage = await new BlockMessage(block);
|
|
1652
1688
|
const hash = await blockMessage.hash();
|
|
1653
1689
|
await globalThis.peernet.put(hash, blockMessage.encoded, 'block');
|
package/exports/machine.d.ts
CHANGED
|
@@ -9,6 +9,14 @@ export default class Machine {
|
|
|
9
9
|
hash: string;
|
|
10
10
|
};
|
|
11
11
|
accounts: {};
|
|
12
|
+
info: {
|
|
13
|
+
nativeCalls: number;
|
|
14
|
+
nativeMints: number;
|
|
15
|
+
nativeBurns: number;
|
|
16
|
+
nativeTransfers: number;
|
|
17
|
+
totalTransactions: number;
|
|
18
|
+
totalBlocks: number;
|
|
19
|
+
};
|
|
12
20
|
};
|
|
13
21
|
constructor(blocks: any);
|
|
14
22
|
updateState(): Promise<void>;
|
|
@@ -30,6 +38,9 @@ export default class Machine {
|
|
|
30
38
|
get blocks(): Promise<[]>;
|
|
31
39
|
get lastBlock(): Promise<any>;
|
|
32
40
|
get totalBlocks(): Promise<any>;
|
|
41
|
+
get totalBurnAmount(): Promise<any>;
|
|
42
|
+
get totaMintAmount(): Promise<any>;
|
|
43
|
+
get totalTransferAmount(): Promise<any>;
|
|
33
44
|
getBlocks(from?: any, to?: any): Promise<[]>;
|
|
34
45
|
getBlock(index: any): Promise<any>;
|
|
35
46
|
addLoadedBlock(block: any): Promise<any>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as EasyWorker, B as BigNumber, C as ContractMessage, T as TransactionMessage } from './worker-
|
|
1
|
+
import { E as EasyWorker, B as BigNumber, C as ContractMessage, T as TransactionMessage } from './worker-Cqj1ERFr.js';
|
|
2
2
|
|
|
3
3
|
const byteFormats = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
4
4
|
const formatBytes = (bytes, decimals = 2) => {
|
|
@@ -117,6 +117,10 @@ let nativeMints = 0;
|
|
|
117
117
|
let nativeTransfers = 0;
|
|
118
118
|
let totalTransactions = 0;
|
|
119
119
|
|
|
120
|
+
let totalBurnAmount = 0;
|
|
121
|
+
let totalMintAmount = 0;
|
|
122
|
+
let totalTransferAmount = 0;
|
|
123
|
+
|
|
120
124
|
let blocks = [];
|
|
121
125
|
let contracts = {};
|
|
122
126
|
const _ = {};
|
|
@@ -146,7 +150,9 @@ const get = ({ contract, method, params }) => {
|
|
|
146
150
|
return result
|
|
147
151
|
};
|
|
148
152
|
|
|
149
|
-
const resolveContract = (
|
|
153
|
+
const resolveContract = (hash) => askFor('contract', hash);
|
|
154
|
+
|
|
155
|
+
const resolveTransaction = (hash) => askFor('transaction', hash);
|
|
150
156
|
|
|
151
157
|
const respond = (id, value) => {
|
|
152
158
|
worker.postMessage({
|
|
@@ -223,9 +229,18 @@ const _executeTransaction = async (transaction) => {
|
|
|
223
229
|
await _.execute({ contract: to, method, params });
|
|
224
230
|
if (to === nativeToken$2) {
|
|
225
231
|
nativeCalls += 1;
|
|
226
|
-
if (method === 'burn')
|
|
227
|
-
|
|
228
|
-
|
|
232
|
+
if (method === 'burn') {
|
|
233
|
+
nativeBurns += 1;
|
|
234
|
+
totalBurnAmount += params[0];
|
|
235
|
+
}
|
|
236
|
+
if (method === 'mint') {
|
|
237
|
+
nativeMints += 1;
|
|
238
|
+
totalMintAmount += params[0];
|
|
239
|
+
}
|
|
240
|
+
if (method === 'transfer') {
|
|
241
|
+
nativeTransfers += 1;
|
|
242
|
+
totalTransferAmount += params[0];
|
|
243
|
+
}
|
|
229
244
|
}
|
|
230
245
|
totalTransactions += 1;
|
|
231
246
|
|
|
@@ -241,10 +256,19 @@ const _executeTransaction = async (transaction) => {
|
|
|
241
256
|
};
|
|
242
257
|
|
|
243
258
|
_.init = async (message) => {
|
|
244
|
-
let { peerid, fromState, state } = message;
|
|
259
|
+
let { peerid, fromState, state, info } = message;
|
|
245
260
|
globalThis.peerid = peerid;
|
|
246
261
|
console.log({ fromState });
|
|
247
262
|
if (fromState) {
|
|
263
|
+
nativeCalls = info.nativeCalls;
|
|
264
|
+
nativeBurns = info.nativeBurns;
|
|
265
|
+
nativeMints = info.nativeMints;
|
|
266
|
+
nativeTransfers = info.nativeTransfers;
|
|
267
|
+
totalTransactions = info.totalTransactions;
|
|
268
|
+
totalBurnAmount = info.totalBurnAmount;
|
|
269
|
+
totalMintAmount = info.totalMintAmount;
|
|
270
|
+
totalTransferAmount = info.totalTransferAmount;
|
|
271
|
+
|
|
248
272
|
lastBlock = message.lastBlock;
|
|
249
273
|
const setState = async (address, state) => {
|
|
250
274
|
const contractBytes = await resolveContract(address);
|
|
@@ -284,23 +308,23 @@ _.init = async (message) => {
|
|
|
284
308
|
);
|
|
285
309
|
console.log({ blocks: message.blocks });
|
|
286
310
|
if (message.blocks?.length > 0) {
|
|
287
|
-
let pre
|
|
288
|
-
|
|
289
|
-
try {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
} catch {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
311
|
+
// let pre
|
|
312
|
+
|
|
313
|
+
// try {
|
|
314
|
+
// const importee = await import('url')
|
|
315
|
+
// const url = importee.default
|
|
316
|
+
// if (url) pre = url.fileURLToPath(new URL('.', import.meta.url))
|
|
317
|
+
// } catch {
|
|
318
|
+
// // browser env
|
|
319
|
+
// pre = './'
|
|
320
|
+
// }
|
|
297
321
|
|
|
298
|
-
let _worker = await new EasyWorker(pre + 'block-worker.js', {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
})
|
|
302
|
-
blocks = await _worker.once(message.blocks)
|
|
303
|
-
_worker = null
|
|
322
|
+
// let _worker = await new EasyWorker(pre + 'block-worker.js', {
|
|
323
|
+
// serialization: 'advanced',
|
|
324
|
+
// type: 'module'
|
|
325
|
+
// })
|
|
326
|
+
// blocks = await _worker.once(message.blocks)
|
|
327
|
+
// _worker = null
|
|
304
328
|
// blocks = unique(globalThis.blocks ? globalThis : [], blocks)
|
|
305
329
|
// for (let i = 0; i < blocks.length; i++) {
|
|
306
330
|
|
|
@@ -311,20 +335,25 @@ _.init = async (message) => {
|
|
|
311
335
|
// this means contracts will be restored from this state
|
|
312
336
|
// this also means devs NEED to make sure the state can be restored
|
|
313
337
|
// on contract deploy an error will be thrown if state wasn't recoverable
|
|
314
|
-
if (block.index
|
|
338
|
+
if (block.index >= blocks.length - 24) {
|
|
315
339
|
const transactionCount = blocks[block.index - 1].transactions.length;
|
|
316
340
|
latestTransactions.splice(-(transactionCount - 1), latestTransactions.length);
|
|
317
341
|
}
|
|
318
342
|
|
|
319
343
|
if (!block.loaded && !fromState) {
|
|
320
|
-
const
|
|
344
|
+
const transactions = await Promise.all(
|
|
345
|
+
block.transactions.map(async (transaction) =>
|
|
346
|
+
new TransactionMessage(await resolveTransaction(transaction)).decode()
|
|
347
|
+
)
|
|
348
|
+
);
|
|
349
|
+
const priority = transactions.filter((transaction) => transaction.priority)?.sort((a, b) => a.nonce - b.nonce);
|
|
321
350
|
if (priority.length > 0)
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
351
|
+
for (const transaction of priority) {
|
|
352
|
+
await _executeTransaction(transaction);
|
|
353
|
+
}
|
|
325
354
|
|
|
326
355
|
await Promise.all(
|
|
327
|
-
|
|
356
|
+
transactions
|
|
328
357
|
.filter((transaction) => !transaction.priority)
|
|
329
358
|
.map(async (transaction) => _executeTransaction(transaction))
|
|
330
359
|
);
|
|
@@ -418,6 +447,15 @@ worker.onmessage(({ id, type, input }) => {
|
|
|
418
447
|
case 'nativeTransfers':
|
|
419
448
|
respond(id, nativeTransfers);
|
|
420
449
|
break
|
|
450
|
+
case 'totalBurnAmount':
|
|
451
|
+
respond(id, totalBurnAmount);
|
|
452
|
+
break
|
|
453
|
+
case 'totalMintAmount':
|
|
454
|
+
respond(id, totalMintAmount);
|
|
455
|
+
break
|
|
456
|
+
case 'totalTransferAmount':
|
|
457
|
+
respond(id, totalTransferAmount);
|
|
458
|
+
break
|
|
421
459
|
case 'totalTransfers':
|
|
422
460
|
respond(id, totalTransfers);
|
|
423
461
|
break
|
|
@@ -12379,37 +12379,6 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface {
|
|
|
12379
12379
|
const FormatInterface = FormatInterface$1;
|
|
12380
12380
|
|
|
12381
12381
|
var proto$3 = {
|
|
12382
|
-
timestamp: Number(),
|
|
12383
|
-
from: String(),
|
|
12384
|
-
to: String(),
|
|
12385
|
-
method: String(),
|
|
12386
|
-
params: Array(),
|
|
12387
|
-
signature: String(),
|
|
12388
|
-
'nonce?': Number(),
|
|
12389
|
-
'dependsOn?': Array(),
|
|
12390
|
-
'priority?': Boolean()
|
|
12391
|
-
};
|
|
12392
|
-
|
|
12393
|
-
class TransactionMessage extends FormatInterface {
|
|
12394
|
-
get messageName() {
|
|
12395
|
-
return 'TransactionMessage';
|
|
12396
|
-
}
|
|
12397
|
-
constructor(buffer) {
|
|
12398
|
-
if (buffer instanceof TransactionMessage)
|
|
12399
|
-
return buffer;
|
|
12400
|
-
const name = 'transaction-message';
|
|
12401
|
-
super(buffer, proto$3, { name });
|
|
12402
|
-
}
|
|
12403
|
-
beforeHashing(decoded) {
|
|
12404
|
-
decoded = super.beforeHashing(decoded);
|
|
12405
|
-
delete decoded.signature;
|
|
12406
|
-
delete decoded.priority;
|
|
12407
|
-
delete decoded.dependsOn;
|
|
12408
|
-
return decoded;
|
|
12409
|
-
}
|
|
12410
|
-
}
|
|
12411
|
-
|
|
12412
|
-
var proto$2 = {
|
|
12413
12382
|
address: String(),
|
|
12414
12383
|
reward: BigNumber.from(0)
|
|
12415
12384
|
};
|
|
@@ -12422,17 +12391,17 @@ class ValidatorMessage extends FormatInterface {
|
|
|
12422
12391
|
if (buffer instanceof ValidatorMessage)
|
|
12423
12392
|
return buffer;
|
|
12424
12393
|
const name = 'validator-message';
|
|
12425
|
-
super(buffer, proto$
|
|
12394
|
+
super(buffer, proto$3, { name });
|
|
12426
12395
|
}
|
|
12427
12396
|
}
|
|
12428
12397
|
|
|
12429
|
-
var proto$
|
|
12398
|
+
var proto$2 = {
|
|
12430
12399
|
index: Number(),
|
|
12431
12400
|
previousHash: String(),
|
|
12432
12401
|
timestamp: Number(),
|
|
12433
12402
|
reward: BigNumber.from(0),
|
|
12434
12403
|
fees: BigNumber.from(0),
|
|
12435
|
-
transactions:
|
|
12404
|
+
transactions: Array(),
|
|
12436
12405
|
validators: new Uint8Array()
|
|
12437
12406
|
};
|
|
12438
12407
|
|
|
@@ -12444,42 +12413,32 @@ class BlockMessage extends FormatInterface {
|
|
|
12444
12413
|
if (buffer instanceof BlockMessage)
|
|
12445
12414
|
return buffer;
|
|
12446
12415
|
const name = 'block-message';
|
|
12447
|
-
super(buffer, proto$
|
|
12416
|
+
super(buffer, proto$2, { name });
|
|
12448
12417
|
}
|
|
12449
12418
|
encode(decoded) {
|
|
12450
12419
|
decoded = decoded || this.decoded;
|
|
12451
12420
|
const validators = [];
|
|
12452
|
-
const transactions = [];
|
|
12453
12421
|
for (const validator of decoded.validators) {
|
|
12454
12422
|
if (validator instanceof ValidatorMessage)
|
|
12455
12423
|
validators.push(validator.encode());
|
|
12456
12424
|
else
|
|
12457
12425
|
validators.push(new ValidatorMessage(validator).encode());
|
|
12458
12426
|
}
|
|
12459
|
-
for (const transaction of decoded.transactions) {
|
|
12460
|
-
if (transaction instanceof TransactionMessage)
|
|
12461
|
-
transactions.push(transaction.encode());
|
|
12462
|
-
else
|
|
12463
|
-
transactions.push(new TransactionMessage(transaction).encode());
|
|
12464
|
-
}
|
|
12465
12427
|
return super.encode({
|
|
12466
12428
|
...decoded,
|
|
12467
|
-
validators: index$5(validators)
|
|
12468
|
-
transactions: index$5(transactions)
|
|
12429
|
+
validators: index$5(validators)
|
|
12469
12430
|
});
|
|
12470
12431
|
}
|
|
12471
12432
|
decode(encoded) {
|
|
12472
12433
|
encoded = encoded || this.encoded;
|
|
12473
12434
|
super.decode(encoded);
|
|
12474
12435
|
// @ts-ignore
|
|
12475
|
-
this.decoded.transactions = index$4(this.decoded.transactions).map((transaction) => new TransactionMessage(transaction).decoded);
|
|
12476
|
-
// @ts-ignore
|
|
12477
12436
|
this.decoded.validators = index$4(this.decoded.validators).map((validator) => new ValidatorMessage(validator).decoded);
|
|
12478
12437
|
return this.decoded;
|
|
12479
12438
|
}
|
|
12480
12439
|
}
|
|
12481
12440
|
|
|
12482
|
-
var proto = {
|
|
12441
|
+
var proto$1 = {
|
|
12483
12442
|
creator: String(),
|
|
12484
12443
|
contract: new Uint8Array(),
|
|
12485
12444
|
constructorParameters: Array()
|
|
@@ -12492,7 +12451,38 @@ class ContractMessage extends FormatInterface {
|
|
|
12492
12451
|
constructor(buffer) {
|
|
12493
12452
|
if (buffer instanceof ContractMessage)
|
|
12494
12453
|
return buffer;
|
|
12495
|
-
super(buffer, proto, { name: 'contract-message' });
|
|
12454
|
+
super(buffer, proto$1, { name: 'contract-message' });
|
|
12455
|
+
}
|
|
12456
|
+
}
|
|
12457
|
+
|
|
12458
|
+
var proto = {
|
|
12459
|
+
timestamp: Number(),
|
|
12460
|
+
from: String(),
|
|
12461
|
+
to: String(),
|
|
12462
|
+
method: String(),
|
|
12463
|
+
params: Array(),
|
|
12464
|
+
signature: String(),
|
|
12465
|
+
'nonce?': Number(),
|
|
12466
|
+
'dependsOn?': Array(),
|
|
12467
|
+
'priority?': Boolean()
|
|
12468
|
+
};
|
|
12469
|
+
|
|
12470
|
+
class TransactionMessage extends FormatInterface {
|
|
12471
|
+
get messageName() {
|
|
12472
|
+
return 'TransactionMessage';
|
|
12473
|
+
}
|
|
12474
|
+
constructor(buffer) {
|
|
12475
|
+
if (buffer instanceof TransactionMessage)
|
|
12476
|
+
return buffer;
|
|
12477
|
+
const name = 'transaction-message';
|
|
12478
|
+
super(buffer, proto, { name });
|
|
12479
|
+
}
|
|
12480
|
+
beforeHashing(decoded) {
|
|
12481
|
+
decoded = super.beforeHashing(decoded);
|
|
12482
|
+
delete decoded.signature;
|
|
12483
|
+
delete decoded.priority;
|
|
12484
|
+
delete decoded.dependsOn;
|
|
12485
|
+
return decoded;
|
|
12496
12486
|
}
|
|
12497
12487
|
}
|
|
12498
12488
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/chain",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.13",
|
|
4
4
|
"description": "Official javascript implementation",
|
|
5
5
|
"private": false,
|
|
6
6
|
"exports": {
|
|
@@ -55,25 +55,25 @@
|
|
|
55
55
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
56
56
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
57
57
|
"@types/semver": "^7.5.8",
|
|
58
|
-
"@vandeurenglenn/debug": "^1.2.
|
|
59
|
-
"rollup": "^4.
|
|
58
|
+
"@vandeurenglenn/debug": "^1.2.3",
|
|
59
|
+
"rollup": "^4.16.4",
|
|
60
60
|
"rollup-plugin-modify": "^3.0.0",
|
|
61
61
|
"tape": "^5.7.5",
|
|
62
62
|
"tslib": "^2.6.2"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@leofcoin/addresses": "^1.0.
|
|
65
|
+
"@leofcoin/addresses": "^1.0.23",
|
|
66
66
|
"@leofcoin/contracts": "^0.1.9",
|
|
67
|
-
"@leofcoin/crypto": "^0.2.
|
|
68
|
-
"@leofcoin/errors": "^1.0.
|
|
69
|
-
"@leofcoin/lib": "^1.2.
|
|
70
|
-
"@leofcoin/messages": "^1.4.
|
|
71
|
-
"@leofcoin/multi-wallet": "^3.1.
|
|
72
|
-
"@leofcoin/networks": "^1.1.
|
|
67
|
+
"@leofcoin/crypto": "^0.2.12",
|
|
68
|
+
"@leofcoin/errors": "^1.0.7",
|
|
69
|
+
"@leofcoin/lib": "^1.2.43",
|
|
70
|
+
"@leofcoin/messages": "^1.4.13",
|
|
71
|
+
"@leofcoin/multi-wallet": "^3.1.8",
|
|
72
|
+
"@leofcoin/networks": "^1.1.6",
|
|
73
73
|
"@leofcoin/peernet": "^1.1.77",
|
|
74
|
-
"@leofcoin/storage": "^3.5.
|
|
75
|
-
"@leofcoin/utils": "^1.1.
|
|
76
|
-
"@leofcoin/workers": "^1.4.
|
|
74
|
+
"@leofcoin/storage": "^3.5.28",
|
|
75
|
+
"@leofcoin/utils": "^1.1.18",
|
|
76
|
+
"@leofcoin/workers": "^1.4.19",
|
|
77
77
|
"@vandeurenglenn/base58": "^1.1.9",
|
|
78
78
|
"@vandeurenglenn/easy-worker": "^1.0.2",
|
|
79
79
|
"semver": "^7.6.0"
|