@leofcoin/chain 1.5.15 → 1.5.17
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/LICENSE +88 -88
- package/README.md +4 -4
- package/exports/browser/chain.js +49 -36
- package/exports/browser/{index-329e0324-71fa9c50.js → index-329e0324-e2a4f639.js} +2 -2
- package/exports/browser/{index-e8f03811.js → index-5e385ee1.js} +9 -8
- package/exports/browser/{messages-000b7f84-88d5e15b.js → messages-000b7f84-ef0adf20.js} +2 -2
- package/exports/browser/{node-browser-af58f01b.js → node-browser-01f26631.js} +12 -12
- package/exports/browser/node-browser.js +2 -2
- package/exports/browser/workers/block-worker.js +33 -32
- package/exports/browser/workers/machine-worker.js +243 -242
- package/exports/chain.js +10 -4
- package/exports/workers/block-worker.js +33 -32
- package/exports/workers/machine-worker.js +243 -242
- package/package.json +105 -105
package/exports/chain.js
CHANGED
|
@@ -4,7 +4,7 @@ import addresses, { contractFactory, nativeToken, validators, nameService } from
|
|
|
4
4
|
import { calculateFee, createContractMessage, signTransaction, contractFactoryMessage, nativeTokenMessage, validatorsMessage, nameServiceMessage } from '@leofcoin/lib';
|
|
5
5
|
import { randombytes } from '@leofcoin/crypto';
|
|
6
6
|
import EasyWorker from '@vandeurenglenn/easy-worker';
|
|
7
|
-
import { isResolveError, ResolveError } from '@leofcoin/errors';
|
|
7
|
+
import { ContractDeploymentError, ExecutionError, isResolveError, ResolveError, isExecutionError } from '@leofcoin/errors';
|
|
8
8
|
|
|
9
9
|
const limit = 1800;
|
|
10
10
|
const transactionLimit = 1800;
|
|
@@ -407,7 +407,7 @@ class Machine {
|
|
|
407
407
|
}
|
|
408
408
|
}
|
|
409
409
|
catch (error) {
|
|
410
|
-
throw new
|
|
410
|
+
throw new ContractDeploymentError(`contract deployment failed for ${parameters[0]}\n${error.message}`);
|
|
411
411
|
}
|
|
412
412
|
return new Promise((resolve, reject) => {
|
|
413
413
|
// @ts-ignore
|
|
@@ -415,7 +415,7 @@ class Machine {
|
|
|
415
415
|
const onmessage = message => {
|
|
416
416
|
pubsub.unsubscribe(id, onmessage);
|
|
417
417
|
if (message?.error)
|
|
418
|
-
reject(message.error);
|
|
418
|
+
reject(new ExecutionError(message.error));
|
|
419
419
|
else
|
|
420
420
|
resolve(message);
|
|
421
421
|
};
|
|
@@ -942,7 +942,7 @@ class State extends Contract {
|
|
|
942
942
|
if (lastTransactions.includes(hash)) {
|
|
943
943
|
console.log('removing invalid block');
|
|
944
944
|
await globalThis.blockStore.delete(await (await new BlockMessage(block)).hash());
|
|
945
|
-
blocks.splice(block.index);
|
|
945
|
+
blocks.splice(block.index - 1, 1);
|
|
946
946
|
return this.#loadBlocks(blocks);
|
|
947
947
|
}
|
|
948
948
|
try {
|
|
@@ -963,6 +963,12 @@ class State extends Contract {
|
|
|
963
963
|
console.log(error);
|
|
964
964
|
await globalThis.transactionPoolStore.delete(hash);
|
|
965
965
|
console.log('removing invalid transaction');
|
|
966
|
+
if (isExecutionError(error)) {
|
|
967
|
+
console.log('removing invalid block');
|
|
968
|
+
await globalThis.blockStore.delete(await (await new BlockMessage(block)).hash());
|
|
969
|
+
blocks.splice(block.index - 1, 1);
|
|
970
|
+
return this.#loadBlocks(blocks);
|
|
971
|
+
}
|
|
966
972
|
console.log(error);
|
|
967
973
|
return false;
|
|
968
974
|
}
|
|
@@ -5894,21 +5894,21 @@ class BlockMessage extends FormatInterface {
|
|
|
5894
5894
|
const name = 'block-message';
|
|
5895
5895
|
super(buffer, proto, { name });
|
|
5896
5896
|
}
|
|
5897
|
-
encode() {
|
|
5898
|
-
|
|
5897
|
+
encode(decoded) {
|
|
5898
|
+
decoded = decoded || this.decoded;
|
|
5899
5899
|
const validators = [];
|
|
5900
5900
|
const transactions = [];
|
|
5901
5901
|
for (const validator of decoded.validators) {
|
|
5902
5902
|
if (validator instanceof ValidatorMessage)
|
|
5903
|
-
validators.push(validator.
|
|
5903
|
+
validators.push(validator.encode());
|
|
5904
5904
|
else
|
|
5905
|
-
validators.push(new ValidatorMessage(validator).
|
|
5905
|
+
validators.push(new ValidatorMessage(validator).encode());
|
|
5906
5906
|
}
|
|
5907
5907
|
for (const transaction of decoded.transactions) {
|
|
5908
5908
|
if (transaction instanceof TransactionMessage)
|
|
5909
|
-
transactions.push(transaction.
|
|
5909
|
+
transactions.push(transaction.encode());
|
|
5910
5910
|
else
|
|
5911
|
-
transactions.push(new TransactionMessage(transaction).
|
|
5911
|
+
transactions.push(new TransactionMessage(transaction).encode());
|
|
5912
5912
|
}
|
|
5913
5913
|
return super.encode({
|
|
5914
5914
|
...decoded,
|
|
@@ -5916,8 +5916,9 @@ class BlockMessage extends FormatInterface {
|
|
|
5916
5916
|
transactions: index$5(transactions)
|
|
5917
5917
|
});
|
|
5918
5918
|
}
|
|
5919
|
-
decode() {
|
|
5920
|
-
|
|
5919
|
+
decode(encoded) {
|
|
5920
|
+
encoded = encoded || this.encoded;
|
|
5921
|
+
super.decode(encoded);
|
|
5921
5922
|
// @ts-ignore
|
|
5922
5923
|
this.decoded.transactions = index$4(this.decoded.transactions).map(transaction => new TransactionMessage(transaction).decoded);
|
|
5923
5924
|
// @ts-ignore
|
|
@@ -6019,28 +6020,28 @@ class EasyWorker {
|
|
|
6019
6020
|
}
|
|
6020
6021
|
}
|
|
6021
6022
|
|
|
6022
|
-
const worker = new EasyWorker();
|
|
6023
|
-
|
|
6024
|
-
globalThis.BigNumber = BigNumber;
|
|
6025
|
-
globalThis.contracts = {};
|
|
6026
|
-
|
|
6027
|
-
const run = async (blocks) => {
|
|
6028
|
-
blocks = await Promise.all(blocks.map(block => new BlockMessage(block)));
|
|
6029
|
-
blocks = blocks.sort((a, b) => a.decoded.timestamp - b.decoded.timestamp);
|
|
6030
|
-
|
|
6031
|
-
blocks = await Promise.all(blocks.map(block => new Promise(async (resolve, reject) => {
|
|
6032
|
-
// todo: tx worker or nah?
|
|
6033
|
-
const size = block.encoded.length || block.encoded.byteLength;
|
|
6034
|
-
console.log(`loaded block: ${await block.hash()} @${block.decoded.index} ${formatBytes(size)}`);
|
|
6035
|
-
resolve(block);
|
|
6036
|
-
})));
|
|
6037
|
-
return blocks
|
|
6038
|
-
};
|
|
6039
|
-
|
|
6040
|
-
const tasks = async blocks => {
|
|
6041
|
-
blocks = await run(blocks);
|
|
6042
|
-
worker.postMessage(blocks);
|
|
6043
|
-
};
|
|
6044
|
-
|
|
6045
|
-
|
|
6023
|
+
const worker = new EasyWorker();
|
|
6024
|
+
|
|
6025
|
+
globalThis.BigNumber = BigNumber;
|
|
6026
|
+
globalThis.contracts = {};
|
|
6027
|
+
|
|
6028
|
+
const run = async (blocks) => {
|
|
6029
|
+
blocks = await Promise.all(blocks.map(block => new BlockMessage(block)));
|
|
6030
|
+
blocks = blocks.sort((a, b) => a.decoded.timestamp - b.decoded.timestamp);
|
|
6031
|
+
|
|
6032
|
+
blocks = await Promise.all(blocks.map(block => new Promise(async (resolve, reject) => {
|
|
6033
|
+
// todo: tx worker or nah?
|
|
6034
|
+
const size = block.encoded.length || block.encoded.byteLength;
|
|
6035
|
+
console.log(`loaded block: ${await block.hash()} @${block.decoded.index} ${formatBytes(size)}`);
|
|
6036
|
+
resolve(block);
|
|
6037
|
+
})));
|
|
6038
|
+
return blocks
|
|
6039
|
+
};
|
|
6040
|
+
|
|
6041
|
+
const tasks = async blocks => {
|
|
6042
|
+
blocks = await run(blocks);
|
|
6043
|
+
worker.postMessage(blocks);
|
|
6044
|
+
};
|
|
6045
|
+
|
|
6046
|
+
|
|
6046
6047
|
worker.onmessage(data => tasks(data));
|