@leofcoin/chain 1.5.69 → 1.6.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/exports/browser/chain.js +8 -17
- package/exports/chain.js +8 -17
- package/exports/state.d.ts +1 -1
- package/package.json +8 -8
package/exports/browser/chain.js
CHANGED
|
@@ -4432,7 +4432,6 @@ class State extends Contract {
|
|
|
4432
4432
|
}
|
|
4433
4433
|
this.#machine = await new Machine(this.#blocks);
|
|
4434
4434
|
const lastBlock = await this.#machine.lastBlock;
|
|
4435
|
-
console.log({ lastBlock });
|
|
4436
4435
|
if (lastBlock.hash !== '0x0') {
|
|
4437
4436
|
this.updateState(new BlockMessage(lastBlock));
|
|
4438
4437
|
}
|
|
@@ -4450,14 +4449,13 @@ class State extends Contract {
|
|
|
4450
4449
|
async updateState(message) {
|
|
4451
4450
|
try {
|
|
4452
4451
|
const hash = await message.hash();
|
|
4453
|
-
// await this.state.updateState(message)
|
|
4454
4452
|
await globalThis.chainStore.put('lastBlock', hash);
|
|
4455
4453
|
globalThis.pubsub.publish('lastBlock', message.encoded);
|
|
4454
|
+
await this.#machine.updateState();
|
|
4456
4455
|
}
|
|
4457
4456
|
catch (error) {
|
|
4458
4457
|
console.error(error);
|
|
4459
4458
|
}
|
|
4460
|
-
await this.#machine.updateState();
|
|
4461
4459
|
}
|
|
4462
4460
|
getLatestBlock() {
|
|
4463
4461
|
// @ts-ignore
|
|
@@ -5067,17 +5065,17 @@ class Chain extends VersionControl {
|
|
|
5067
5065
|
await Promise.all(blockMessage.decoded.transactions
|
|
5068
5066
|
// @ts-ignore
|
|
5069
5067
|
.map(async (transaction) => {
|
|
5068
|
+
// @ts-ignore
|
|
5070
5069
|
let hash = transaction.hash;
|
|
5071
5070
|
if (!hash) {
|
|
5072
5071
|
hash = await new TransactionMessage(transaction).hash();
|
|
5072
|
+
// @ts-ignore
|
|
5073
5073
|
transaction.hash = hash;
|
|
5074
5074
|
}
|
|
5075
5075
|
(await transactionPoolStore.has(hash)) && (await transactionPoolStore.delete(hash));
|
|
5076
5076
|
return transaction;
|
|
5077
5077
|
}));
|
|
5078
5078
|
await globalThis.blockStore.put(hash, blockMessage.encoded);
|
|
5079
|
-
if ((await this.lastBlock).index < Number(blockMessage.decoded.index))
|
|
5080
|
-
await this.updateState(blockMessage);
|
|
5081
5079
|
debug(`added block: ${hash}`);
|
|
5082
5080
|
let promises = [];
|
|
5083
5081
|
let contracts = [];
|
|
@@ -5098,13 +5096,10 @@ class Chain extends VersionControl {
|
|
|
5098
5096
|
globalThis.pubsub.publish('account-transaction-processed', transaction);
|
|
5099
5097
|
await globalThis.accountsStore.put(transaction.from, String(transaction.nonce));
|
|
5100
5098
|
}
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
// console.log(state);
|
|
5106
|
-
// }
|
|
5107
|
-
// await this.machine.addLoadedBlock({ ...blockMessage.decoded, loaded: true, hash: await blockMessage.hash() })
|
|
5099
|
+
if ((await this.lastBlock).index < Number(blockMessage.decoded.index)) {
|
|
5100
|
+
await this.machine.addLoadedBlock({ ...blockMessage.decoded, loaded: true, hash: await blockMessage.hash() });
|
|
5101
|
+
await this.updateState(blockMessage);
|
|
5102
|
+
}
|
|
5108
5103
|
globalThis.pubsub.publish('block-processed', blockMessage.decoded);
|
|
5109
5104
|
}
|
|
5110
5105
|
catch (error) {
|
|
@@ -5259,15 +5254,13 @@ class Chain extends VersionControl {
|
|
|
5259
5254
|
let blockMessage = await new BlockMessage(block);
|
|
5260
5255
|
const hash = await blockMessage.hash();
|
|
5261
5256
|
await globalThis.peernet.put(hash, blockMessage.encoded, 'block');
|
|
5262
|
-
await this.updateState(blockMessage);
|
|
5263
5257
|
await this.machine.addLoadedBlock({ ...blockMessage.decoded, loaded: true, hash: await blockMessage.hash() });
|
|
5258
|
+
await this.updateState(blockMessage);
|
|
5264
5259
|
debug(`created block: ${hash} @${block.index}`);
|
|
5265
5260
|
globalThis.peernet.publish('add-block', blockMessage.encoded);
|
|
5266
5261
|
globalThis.pubsub.publish('add-block', blockMessage.decoded);
|
|
5267
5262
|
}
|
|
5268
5263
|
catch (error) {
|
|
5269
|
-
console.log(error);
|
|
5270
|
-
console.log('eeeee');
|
|
5271
5264
|
throw new Error(`invalid block ${block}`);
|
|
5272
5265
|
}
|
|
5273
5266
|
// data = await this.machine.execute(to, method, params)
|
|
@@ -5285,8 +5278,6 @@ class Chain extends VersionControl {
|
|
|
5285
5278
|
this.#runEpoch();
|
|
5286
5279
|
}
|
|
5287
5280
|
catch (e) {
|
|
5288
|
-
console.log(e);
|
|
5289
|
-
console.log('rrrrr');
|
|
5290
5281
|
globalThis.peernet.publish('invalid-transaction', hash);
|
|
5291
5282
|
throw new Error('invalid transaction');
|
|
5292
5283
|
}
|
package/exports/chain.js
CHANGED
|
@@ -800,7 +800,6 @@ class State extends Contract {
|
|
|
800
800
|
}
|
|
801
801
|
this.#machine = await new Machine(this.#blocks);
|
|
802
802
|
const lastBlock = await this.#machine.lastBlock;
|
|
803
|
-
console.log({ lastBlock });
|
|
804
803
|
if (lastBlock.hash !== '0x0') {
|
|
805
804
|
this.updateState(new BlockMessage(lastBlock));
|
|
806
805
|
}
|
|
@@ -818,14 +817,13 @@ class State extends Contract {
|
|
|
818
817
|
async updateState(message) {
|
|
819
818
|
try {
|
|
820
819
|
const hash = await message.hash();
|
|
821
|
-
// await this.state.updateState(message)
|
|
822
820
|
await globalThis.chainStore.put('lastBlock', hash);
|
|
823
821
|
globalThis.pubsub.publish('lastBlock', message.encoded);
|
|
822
|
+
await this.#machine.updateState();
|
|
824
823
|
}
|
|
825
824
|
catch (error) {
|
|
826
825
|
console.error(error);
|
|
827
826
|
}
|
|
828
|
-
await this.#machine.updateState();
|
|
829
827
|
}
|
|
830
828
|
getLatestBlock() {
|
|
831
829
|
// @ts-ignore
|
|
@@ -1435,17 +1433,17 @@ class Chain extends VersionControl {
|
|
|
1435
1433
|
await Promise.all(blockMessage.decoded.transactions
|
|
1436
1434
|
// @ts-ignore
|
|
1437
1435
|
.map(async (transaction) => {
|
|
1436
|
+
// @ts-ignore
|
|
1438
1437
|
let hash = transaction.hash;
|
|
1439
1438
|
if (!hash) {
|
|
1440
1439
|
hash = await new TransactionMessage(transaction).hash();
|
|
1440
|
+
// @ts-ignore
|
|
1441
1441
|
transaction.hash = hash;
|
|
1442
1442
|
}
|
|
1443
1443
|
(await transactionPoolStore.has(hash)) && (await transactionPoolStore.delete(hash));
|
|
1444
1444
|
return transaction;
|
|
1445
1445
|
}));
|
|
1446
1446
|
await globalThis.blockStore.put(hash, blockMessage.encoded);
|
|
1447
|
-
if ((await this.lastBlock).index < Number(blockMessage.decoded.index))
|
|
1448
|
-
await this.updateState(blockMessage);
|
|
1449
1447
|
debug(`added block: ${hash}`);
|
|
1450
1448
|
let promises = [];
|
|
1451
1449
|
let contracts = [];
|
|
@@ -1466,13 +1464,10 @@ class Chain extends VersionControl {
|
|
|
1466
1464
|
globalThis.pubsub.publish('account-transaction-processed', transaction);
|
|
1467
1465
|
await globalThis.accountsStore.put(transaction.from, String(transaction.nonce));
|
|
1468
1466
|
}
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
// console.log(state);
|
|
1474
|
-
// }
|
|
1475
|
-
// await this.machine.addLoadedBlock({ ...blockMessage.decoded, loaded: true, hash: await blockMessage.hash() })
|
|
1467
|
+
if ((await this.lastBlock).index < Number(blockMessage.decoded.index)) {
|
|
1468
|
+
await this.machine.addLoadedBlock({ ...blockMessage.decoded, loaded: true, hash: await blockMessage.hash() });
|
|
1469
|
+
await this.updateState(blockMessage);
|
|
1470
|
+
}
|
|
1476
1471
|
globalThis.pubsub.publish('block-processed', blockMessage.decoded);
|
|
1477
1472
|
}
|
|
1478
1473
|
catch (error) {
|
|
@@ -1627,15 +1622,13 @@ class Chain extends VersionControl {
|
|
|
1627
1622
|
let blockMessage = await new BlockMessage(block);
|
|
1628
1623
|
const hash = await blockMessage.hash();
|
|
1629
1624
|
await globalThis.peernet.put(hash, blockMessage.encoded, 'block');
|
|
1630
|
-
await this.updateState(blockMessage);
|
|
1631
1625
|
await this.machine.addLoadedBlock({ ...blockMessage.decoded, loaded: true, hash: await blockMessage.hash() });
|
|
1626
|
+
await this.updateState(blockMessage);
|
|
1632
1627
|
debug(`created block: ${hash} @${block.index}`);
|
|
1633
1628
|
globalThis.peernet.publish('add-block', blockMessage.encoded);
|
|
1634
1629
|
globalThis.pubsub.publish('add-block', blockMessage.decoded);
|
|
1635
1630
|
}
|
|
1636
1631
|
catch (error) {
|
|
1637
|
-
console.log(error);
|
|
1638
|
-
console.log('eeeee');
|
|
1639
1632
|
throw new Error(`invalid block ${block}`);
|
|
1640
1633
|
}
|
|
1641
1634
|
// data = await this.machine.execute(to, method, params)
|
|
@@ -1653,8 +1646,6 @@ class Chain extends VersionControl {
|
|
|
1653
1646
|
this.#runEpoch();
|
|
1654
1647
|
}
|
|
1655
1648
|
catch (e) {
|
|
1656
|
-
console.log(e);
|
|
1657
|
-
console.log('rrrrr');
|
|
1658
1649
|
globalThis.peernet.publish('invalid-transaction', hash);
|
|
1659
1650
|
throw new Error('invalid transaction');
|
|
1660
1651
|
}
|
package/exports/state.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export default class State extends Contract {
|
|
|
38
38
|
*/
|
|
39
39
|
clearAll(): Promise<void>;
|
|
40
40
|
init(): Promise<void>;
|
|
41
|
-
updateState(message:
|
|
41
|
+
updateState(message: BlockMessage): Promise<void>;
|
|
42
42
|
getLatestBlock(): Promise<BlockMessage['decoded']>;
|
|
43
43
|
getAndPutBlock(hash: string): Promise<BlockMessage>;
|
|
44
44
|
resolveBlock(hash: any): any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/chain",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Official javascript implementation",
|
|
5
5
|
"private": false,
|
|
6
6
|
"exports": {
|
|
@@ -74,17 +74,17 @@
|
|
|
74
74
|
"wireit": "^0.9.5"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@leofcoin/addresses": "^1.0.
|
|
78
|
-
"@leofcoin/errors": "^1.0.
|
|
79
|
-
"@leofcoin/lib": "^1.2.
|
|
80
|
-
"@leofcoin/messages": "^1.4.
|
|
77
|
+
"@leofcoin/addresses": "^1.0.20",
|
|
78
|
+
"@leofcoin/errors": "^1.0.4",
|
|
79
|
+
"@leofcoin/lib": "^1.2.40",
|
|
80
|
+
"@leofcoin/messages": "^1.4.10",
|
|
81
81
|
"@leofcoin/multi-wallet": "^2.1.1",
|
|
82
|
-
"@leofcoin/networks": "^1.1.
|
|
82
|
+
"@leofcoin/networks": "^1.1.3",
|
|
83
83
|
"@leofcoin/peernet": "^1.1.73",
|
|
84
84
|
"@leofcoin/peernet-swarm": "^1.0.0",
|
|
85
85
|
"@leofcoin/storage": "^3.0.6",
|
|
86
|
-
"@leofcoin/utils": "^1.1.
|
|
87
|
-
"@leofcoin/workers": "^1.4.
|
|
86
|
+
"@leofcoin/utils": "^1.1.15",
|
|
87
|
+
"@leofcoin/workers": "^1.4.15",
|
|
88
88
|
"@netpeer/p2pt-swarm": "^1.3.5",
|
|
89
89
|
"@netpeer/swarm": "^0.8.9",
|
|
90
90
|
"@vandeurenglenn/base32": "^1.1.0",
|