@leofcoin/chain 1.5.25 → 1.5.26
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 +82 -63
- package/exports/browser/{index-73138caf.js → index-055d5584.js} +2 -2
- package/exports/browser/{index-329e0324-835f93a9.js → index-329e0324-f8858eb6.js} +2 -2
- package/exports/browser/{messages-000b7f84-b6b8b755.js → messages-000b7f84-2f945543.js} +2 -2
- package/exports/browser/{node-browser-19707bf6.js → node-browser-ccafb3fc.js} +6 -4
- package/exports/browser/node-browser.js +2 -2
- package/exports/browser/workers/block-worker.js +32 -28
- package/exports/browser/workers/machine-worker.js +222 -233
- package/exports/browser/workers/{worker-0f66935f.js → worker-5b02efbe.js} +2 -2
- package/exports/chain.js +71 -52
- package/exports/contract.d.ts +1 -1
- package/exports/node.js +3 -1
- package/exports/transaction.d.ts +2 -2
- package/exports/version-control.d.ts +1 -1
- package/exports/workers/block-worker.js +32 -28
- package/exports/workers/machine-worker.js +222 -233
- package/exports/workers/{worker-0f66935f.js → worker-5b02efbe.js} +2 -2
- package/package.json +2 -1
package/exports/browser/chain.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BigNumber, L as Logger, v as version$1, h as hexZeroPad, i as isBigNumberish, a as arrayify, b as isBytes, T as TransactionMessage, t as toBase58, C as ContractMessage, R as RawTransactionMessage, c as BlockMessage, d as BWMessage, e as BWRequestMessage } from './index-
|
|
1
|
+
import { B as BigNumber, L as Logger, v as version$1, h as hexZeroPad, i as isBigNumberish, a as arrayify, b as isBytes, T as TransactionMessage, t as toBase58, C as ContractMessage, R as RawTransactionMessage, c as BlockMessage, d as BWMessage, e as BWRequestMessage } from './index-055d5584.js';
|
|
2
2
|
|
|
3
3
|
const logger$1 = new Logger(version$1);
|
|
4
4
|
const _constructorGuard = {};
|
|
@@ -410,15 +410,15 @@ var addresses$1 = {
|
|
|
410
410
|
validators: validators$1
|
|
411
411
|
};
|
|
412
412
|
|
|
413
|
-
const contractFactory$2 = addresses$1.contractFactory;
|
|
414
|
-
const nameService$2 = addresses$1.nameService;
|
|
415
|
-
const nativeToken$2 = addresses$1.nativeToken;
|
|
416
|
-
const validators$2 = addresses$1.validators;
|
|
417
|
-
var addresses = {
|
|
418
|
-
contractFactory: contractFactory$2,
|
|
419
|
-
nameService: nameService$2,
|
|
420
|
-
nativeToken: nativeToken$2,
|
|
421
|
-
validators: validators$2
|
|
413
|
+
const contractFactory$2 = addresses$1.contractFactory;
|
|
414
|
+
const nameService$2 = addresses$1.nameService;
|
|
415
|
+
const nativeToken$2 = addresses$1.nativeToken;
|
|
416
|
+
const validators$2 = addresses$1.validators;
|
|
417
|
+
var addresses = {
|
|
418
|
+
contractFactory: contractFactory$2,
|
|
419
|
+
nameService: nameService$2,
|
|
420
|
+
nativeToken: nativeToken$2,
|
|
421
|
+
validators: validators$2
|
|
422
422
|
};
|
|
423
423
|
|
|
424
424
|
var contractFactory = "237,198,141,3,53,89,84,113,119,88,110,55,76,101,103,89,119,65,109,100,117,75,88,119,116,83,52,118,52,100,97,114,113,66,84,81,82,76,90,106,50,57,117,106,112,114,98,104,52,119,121,76,106,112,56,50,87,106,173,5,99,108,97,115,115,32,70,97,99,116,111,114,121,123,35,110,97,109,101,61,34,65,114,116,79,110,108,105,110,101,67,111,110,116,114,97,99,116,70,97,99,116,111,114,121,34,59,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,61,48,59,35,99,111,110,116,114,97,99,116,115,61,91,93,59,99,111,110,115,116,114,117,99,116,111,114,40,115,116,97,116,101,41,123,115,116,97,116,101,38,38,40,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,61,115,116,97,116,101,46,99,111,110,116,114,97,99,116,115,44,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,61,115,116,97,116,101,46,116,111,116,97,108,67,111,110,116,114,97,99,116,115,41,125,103,101,116,32,115,116,97,116,101,40,41,123,114,101,116,117,114,110,123,116,111,116,97,108,67,111,110,116,114,97,99,116,115,58,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,44,99,111,110,116,114,97,99,116,115,58,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,125,125,103,101,116,32,110,97,109,101,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,110,97,109,101,125,103,101,116,32,99,111,110,116,114,97,99,116,115,40,41,123,114,101,116,117,114,110,91,46,46,46,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,93,125,103,101,116,32,116,111,116,97,108,67,111,110,116,114,97,99,116,115,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,125,105,115,82,101,103,105,115,116,101,114,101,100,40,97,100,100,114,101,115,115,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,46,105,110,99,108,117,100,101,115,40,97,100,100,114,101,115,115,41,125,97,115,121,110,99,32,114,101,103,105,115,116,101,114,67,111,110,116,114,97,99,116,40,97,100,100,114,101,115,115,41,123,105,102,40,97,119,97,105,116,32,109,115,103,46,115,116,97,116,105,99,67,97,108,108,40,97,100,100,114,101,115,115,44,34,104,97,115,82,111,108,101,34,44,91,109,115,103,46,115,101,110,100,101,114,44,34,79,87,78,69,82,34,93,41,44,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,46,105,110,99,108,117,100,101,115,40,97,100,100,114,101,115,115,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,97,108,114,101,97,100,121,32,114,101,103,105,115,116,101,114,101,100,34,41,59,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,43,61,49,44,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,46,112,117,115,104,40,97,100,100,114,101,115,115,41,125,125,114,101,116,117,114,110,32,70,97,99,116,111,114,121,59,2,91,93";
|
|
@@ -503,11 +503,11 @@ class Transaction extends Protocol {
|
|
|
503
503
|
return new Promise(async (resolve, reject) => {
|
|
504
504
|
let size = 0;
|
|
505
505
|
const _transactions = [];
|
|
506
|
-
await Promise.all(transactions
|
|
507
|
-
.map(async (tx) => {
|
|
506
|
+
await Promise.all(transactions.map(async (tx) => {
|
|
508
507
|
tx = await new TransactionMessage(tx);
|
|
509
508
|
size += tx.encoded.length;
|
|
510
|
-
if (!formatBytes(size).includes('MB') ||
|
|
509
|
+
if (!formatBytes(size).includes('MB') ||
|
|
510
|
+
(formatBytes(size).includes('MB') && Number(formatBytes(size).split(' MB')[0]) <= 0.75))
|
|
511
511
|
_transactions.push({ ...tx.decoded, hash: await tx.hash() });
|
|
512
512
|
else
|
|
513
513
|
resolve(_transactions);
|
|
@@ -521,7 +521,7 @@ class Transaction extends Protocol {
|
|
|
521
521
|
* @returns {TransactionMessage}
|
|
522
522
|
*/
|
|
523
523
|
async promiseTransactions(transactions) {
|
|
524
|
-
transactions = await Promise.all(transactions.map(tx => new TransactionMessage(tx.encoded || tx)));
|
|
524
|
+
transactions = await Promise.all(transactions.map((tx) => new TransactionMessage(tx.encoded || tx)));
|
|
525
525
|
return transactions;
|
|
526
526
|
}
|
|
527
527
|
/**
|
|
@@ -530,7 +530,7 @@ class Transaction extends Protocol {
|
|
|
530
530
|
* @returns {Object} {transaction.decoded, transaction.hash}
|
|
531
531
|
*/
|
|
532
532
|
async promiseTransactionsContent(transactions) {
|
|
533
|
-
transactions = await Promise.all(transactions.map(tx => new Promise(async (resolve, reject) => {
|
|
533
|
+
transactions = await Promise.all(transactions.map((tx) => new Promise(async (resolve, reject) => {
|
|
534
534
|
resolve({ ...tx.decoded, hash: await tx.hash() });
|
|
535
535
|
})));
|
|
536
536
|
return transactions;
|
|
@@ -543,7 +543,7 @@ class Transaction extends Protocol {
|
|
|
543
543
|
async #getNonceFallback(address) {
|
|
544
544
|
let transactions = await globalThis.transactionPoolStore.values();
|
|
545
545
|
transactions = await this.promiseTransactions(transactions);
|
|
546
|
-
transactions = transactions.filter(tx => tx.decoded.from === address);
|
|
546
|
+
transactions = transactions.filter((tx) => tx.decoded.from === address);
|
|
547
547
|
transactions = await this.promiseTransactionsContent(transactions);
|
|
548
548
|
// @ts-ignore
|
|
549
549
|
if (this.lastBlock?.hash && transactions.length === 0 && this.lastBlock.hash !== '0x0') {
|
|
@@ -554,11 +554,11 @@ class Transaction extends Protocol {
|
|
|
554
554
|
// tx = await peernet.get(tx, 'transaction')
|
|
555
555
|
// transactions.push(new TransactionMessage(tx))
|
|
556
556
|
// }
|
|
557
|
-
transactions = transactions.filter(tx => tx.from === address);
|
|
557
|
+
transactions = transactions.filter((tx) => tx.from === address);
|
|
558
558
|
while (transactions.length === 0 && block.decoded.index !== 0 && block.decoded.previousHash !== '0x0') {
|
|
559
559
|
block = await globalThis.blockStore.get(block.decoded.previousHash);
|
|
560
560
|
block = await new BlockMessage(block);
|
|
561
|
-
transactions = block.decoded.transactions.filter(tx => tx.from === address);
|
|
561
|
+
transactions = block.decoded.transactions.filter((tx) => tx.from === address);
|
|
562
562
|
}
|
|
563
563
|
}
|
|
564
564
|
if (transactions.length === 0)
|
|
@@ -572,7 +572,7 @@ class Transaction extends Protocol {
|
|
|
572
572
|
* @returns {Number} nonce
|
|
573
573
|
*/
|
|
574
574
|
async getNonce(address) {
|
|
575
|
-
if (!await globalThis.accountsStore.has(address)) {
|
|
575
|
+
if (!(await globalThis.accountsStore.has(address))) {
|
|
576
576
|
const nonce = await this.#getNonceFallback(address);
|
|
577
577
|
await globalThis.accountsStore.put(address, new TextEncoder().encode(String(nonce)));
|
|
578
578
|
}
|
|
@@ -581,7 +581,7 @@ class Transaction extends Protocol {
|
|
|
581
581
|
nonce = new TextDecoder().decode(nonce);
|
|
582
582
|
let transactions = await globalThis.transactionPoolStore.values();
|
|
583
583
|
transactions = await this.promiseTransactions(transactions);
|
|
584
|
-
transactions = transactions.filter(tx => tx.decoded.from === address);
|
|
584
|
+
transactions = transactions.filter((tx) => tx.decoded.from === address);
|
|
585
585
|
transactions = await this.promiseTransactionsContent(transactions);
|
|
586
586
|
for (const transaction of transactions) {
|
|
587
587
|
if (transaction.nonce > nonce)
|
|
@@ -598,7 +598,7 @@ class Transaction extends Protocol {
|
|
|
598
598
|
throw new Error(`a transaction with the same nonce already exists`);
|
|
599
599
|
let transactions = await globalThis.transactionPoolStore.values();
|
|
600
600
|
transactions = await this.promiseTransactions(transactions);
|
|
601
|
-
transactions = transactions.filter(tx => tx.decoded.from === address);
|
|
601
|
+
transactions = transactions.filter((tx) => tx.decoded.from === address);
|
|
602
602
|
for (const transaction of transactions) {
|
|
603
603
|
if (transaction.decoded.nonce > nonce)
|
|
604
604
|
throw new Error(`a transaction with a higher nonce already exists`);
|
|
@@ -677,8 +677,7 @@ class Contract extends Transaction {
|
|
|
677
677
|
constructor() {
|
|
678
678
|
super();
|
|
679
679
|
}
|
|
680
|
-
async init() {
|
|
681
|
-
}
|
|
680
|
+
async init() { }
|
|
682
681
|
/**
|
|
683
682
|
*
|
|
684
683
|
* @param {Address} creator
|
|
@@ -728,7 +727,7 @@ class Contract extends Transaction {
|
|
|
728
727
|
}
|
|
729
728
|
}
|
|
730
729
|
|
|
731
|
-
const randombytes = strength => crypto.getRandomValues(new Uint8Array(strength));
|
|
730
|
+
const randombytes = (strength) => crypto.getRandomValues(new Uint8Array(strength));
|
|
732
731
|
|
|
733
732
|
class EasyWorker {
|
|
734
733
|
#messageEvent = 'message'
|
|
@@ -899,7 +898,10 @@ class Machine {
|
|
|
899
898
|
// browser env
|
|
900
899
|
pre = './';
|
|
901
900
|
}
|
|
902
|
-
this.worker = await new EasyWorker(pre + 'workers/machine-worker.js', {
|
|
901
|
+
this.worker = await new EasyWorker(pre + 'workers/machine-worker.js', {
|
|
902
|
+
serialization: 'advanced',
|
|
903
|
+
type: 'module'
|
|
904
|
+
});
|
|
903
905
|
this.worker.onmessage(this.#onmessage.bind(this));
|
|
904
906
|
// const blocks = await blockStore.values()
|
|
905
907
|
const contracts = await Promise.all([
|
|
@@ -925,7 +927,7 @@ class Machine {
|
|
|
925
927
|
return new Promise((resolve, reject) => {
|
|
926
928
|
// @ts-ignore
|
|
927
929
|
const id = randombytes(20).toString('hex');
|
|
928
|
-
const onmessage = message => {
|
|
930
|
+
const onmessage = (message) => {
|
|
929
931
|
pubsub.unsubscribe(id, onmessage);
|
|
930
932
|
if (message?.error)
|
|
931
933
|
reject(message.error);
|
|
@@ -957,7 +959,7 @@ class Machine {
|
|
|
957
959
|
if (await this.has(parameters[0]))
|
|
958
960
|
throw new Error(`duplicate contract @${parameters[0]}`);
|
|
959
961
|
let message;
|
|
960
|
-
if (!await globalThis.contractStore.has(parameters[0])) {
|
|
962
|
+
if (!(await globalThis.contractStore.has(parameters[0]))) {
|
|
961
963
|
message = await peernet.get(parameters[0], 'contract');
|
|
962
964
|
message = await new ContractMessage(message);
|
|
963
965
|
await globalThis.contractStore.put(await message.hash(), message.encoded);
|
|
@@ -966,7 +968,7 @@ class Machine {
|
|
|
966
968
|
message = await globalThis.contractStore.get(parameters[0]);
|
|
967
969
|
message = await new ContractMessage(message);
|
|
968
970
|
}
|
|
969
|
-
if (!await this.has(await message.hash()))
|
|
971
|
+
if (!(await this.has(await message.hash())))
|
|
970
972
|
await this.#runContract(message);
|
|
971
973
|
}
|
|
972
974
|
}
|
|
@@ -976,7 +978,7 @@ class Machine {
|
|
|
976
978
|
return new Promise((resolve, reject) => {
|
|
977
979
|
// @ts-ignore
|
|
978
980
|
const id = randombytes(20).toString('hex');
|
|
979
|
-
const onmessage = message => {
|
|
981
|
+
const onmessage = (message) => {
|
|
980
982
|
pubsub.unsubscribe(id, onmessage);
|
|
981
983
|
if (message?.error)
|
|
982
984
|
reject(new ExecutionError(message.error));
|
|
@@ -998,7 +1000,7 @@ class Machine {
|
|
|
998
1000
|
get(contract, method, parameters) {
|
|
999
1001
|
return new Promise((resolve, reject) => {
|
|
1000
1002
|
const id = randombytes(20).toString();
|
|
1001
|
-
const onmessage = message => {
|
|
1003
|
+
const onmessage = (message) => {
|
|
1002
1004
|
pubsub.unsubscribe(id, onmessage);
|
|
1003
1005
|
resolve(message);
|
|
1004
1006
|
};
|
|
@@ -1018,7 +1020,7 @@ class Machine {
|
|
|
1018
1020
|
return new Promise((resolve, reject) => {
|
|
1019
1021
|
// @ts-ignore
|
|
1020
1022
|
const id = randombytes(20).toString('hex');
|
|
1021
|
-
const onmessage = message => {
|
|
1023
|
+
const onmessage = (message) => {
|
|
1022
1024
|
pubsub.unsubscribe(id, onmessage);
|
|
1023
1025
|
if (message?.error)
|
|
1024
1026
|
reject(message.error);
|
|
@@ -1044,7 +1046,7 @@ class Machine {
|
|
|
1044
1046
|
*/
|
|
1045
1047
|
async deleteAll() {
|
|
1046
1048
|
let hashes = await globalThis.contractStore.keys();
|
|
1047
|
-
hashes = Object.keys(hashes).map(hash => this.delete(hash));
|
|
1049
|
+
hashes = Object.keys(hashes).map((hash) => this.delete(hash));
|
|
1048
1050
|
return Promise.all(hashes);
|
|
1049
1051
|
}
|
|
1050
1052
|
}
|
|
@@ -1199,20 +1201,27 @@ class State extends Contract {
|
|
|
1199
1201
|
*/
|
|
1200
1202
|
this.#totalTransactions = 0;
|
|
1201
1203
|
this.#chainStateHandler = () => {
|
|
1202
|
-
return new globalThis.peernet.protos['peernet-response']({
|
|
1204
|
+
return new globalThis.peernet.protos['peernet-response']({
|
|
1205
|
+
response: this.#chainState
|
|
1206
|
+
});
|
|
1203
1207
|
};
|
|
1204
1208
|
this.#lastBlockHandler = async () => {
|
|
1205
|
-
return new globalThis.peernet.protos['peernet-response']({
|
|
1209
|
+
return new globalThis.peernet.protos['peernet-response']({
|
|
1210
|
+
response: { hash: this.#lastBlock?.hash, index: this.#lastBlock?.index }
|
|
1211
|
+
});
|
|
1206
1212
|
};
|
|
1207
1213
|
this.#knownBlocksHandler = async () => {
|
|
1208
|
-
return new globalThis.peernet.protos['peernet-response']({
|
|
1214
|
+
return new globalThis.peernet.protos['peernet-response']({
|
|
1215
|
+
response: { blocks: this.#blocks.map((block) => block.hash) }
|
|
1216
|
+
});
|
|
1209
1217
|
};
|
|
1210
1218
|
this.#loadBlockTransactions = (transactions) => Promise.all(transactions.map((transaction) => new TransactionMessage(transaction)));
|
|
1211
1219
|
this.#getLastTransactions = async () => {
|
|
1212
|
-
let lastTransactions = (await Promise.all(this.#blocks
|
|
1213
|
-
.
|
|
1214
|
-
.
|
|
1215
|
-
|
|
1220
|
+
let lastTransactions = (await Promise.all(this.#blocks
|
|
1221
|
+
.filter((block) => block.loaded)
|
|
1222
|
+
.slice(-128)
|
|
1223
|
+
.map((block) => this.#loadBlockTransactions(block.transactions)))).reduce((all, transactions) => [...all, ...transactions], []);
|
|
1224
|
+
return Promise.all(lastTransactions.map((transaction) => transaction.hash()));
|
|
1216
1225
|
};
|
|
1217
1226
|
}
|
|
1218
1227
|
async clearPool() {
|
|
@@ -1250,7 +1259,10 @@ class State extends Contract {
|
|
|
1250
1259
|
if (localBlock && localBlock !== '0x0') {
|
|
1251
1260
|
localBlock = await globalThis.peernet.get(localBlock, 'block');
|
|
1252
1261
|
localBlock = await new BlockMessage(localBlock);
|
|
1253
|
-
this.#lastBlock = {
|
|
1262
|
+
this.#lastBlock = {
|
|
1263
|
+
...localBlock.decoded,
|
|
1264
|
+
hash: await localBlock.hash()
|
|
1265
|
+
};
|
|
1254
1266
|
}
|
|
1255
1267
|
else {
|
|
1256
1268
|
if (globalThis.peernet?.connections.length > 0) {
|
|
@@ -1303,7 +1315,7 @@ class State extends Contract {
|
|
|
1303
1315
|
const { index } = block.decoded;
|
|
1304
1316
|
if (this.#blocks[index - 1] && this.#blocks[index - 1].hash !== block.hash)
|
|
1305
1317
|
throw `invalid block ${hash} @${index}`;
|
|
1306
|
-
if (!await globalThis.peernet.has(hash))
|
|
1318
|
+
if (!(await globalThis.peernet.has(hash)))
|
|
1307
1319
|
await globalThis.peernet.put(hash, block.encoded, 'block');
|
|
1308
1320
|
}
|
|
1309
1321
|
return block;
|
|
@@ -1405,8 +1417,7 @@ class State extends Contract {
|
|
|
1405
1417
|
// console.log(e);
|
|
1406
1418
|
}
|
|
1407
1419
|
}
|
|
1408
|
-
destroyResolveJob() {
|
|
1409
|
-
}
|
|
1420
|
+
destroyResolveJob() { }
|
|
1410
1421
|
async syncChain(lastBlock) {
|
|
1411
1422
|
if (!this.shouldSync)
|
|
1412
1423
|
return;
|
|
@@ -1465,7 +1476,7 @@ class State extends Contract {
|
|
|
1465
1476
|
console.log('ok');
|
|
1466
1477
|
let blocksSynced = localIndex > 0 ? (localIndex > index ? localIndex - index : index + -localIndex) : index;
|
|
1467
1478
|
globalThis.debug(`synced ${blocksSynced} ${blocksSynced > 1 ? 'blocks' : 'block'}`);
|
|
1468
|
-
const start =
|
|
1479
|
+
const start = this.#blocks.length - blocksSynced;
|
|
1469
1480
|
if (this.#machine)
|
|
1470
1481
|
await this.#loadBlocks(this.blocks.slice(start));
|
|
1471
1482
|
await this.updateState(new BlockMessage(this.#blocks[this.#blocks.length - 1]));
|
|
@@ -1478,7 +1489,9 @@ class State extends Contract {
|
|
|
1478
1489
|
}
|
|
1479
1490
|
async #getLatestBlock() {
|
|
1480
1491
|
let promises = [];
|
|
1481
|
-
let data = await new globalThis.peernet.protos['peernet-request']({
|
|
1492
|
+
let data = await new globalThis.peernet.protos['peernet-request']({
|
|
1493
|
+
request: 'lastBlock'
|
|
1494
|
+
});
|
|
1482
1495
|
let node = await globalThis.peernet.prepareMessage(data);
|
|
1483
1496
|
for (const peer of globalThis.peernet?.connections) {
|
|
1484
1497
|
// @ts-ignore
|
|
@@ -1510,7 +1523,9 @@ class State extends Contract {
|
|
|
1510
1523
|
latest = { ...message.decoded, hash };
|
|
1511
1524
|
const peer = promises[0].peer;
|
|
1512
1525
|
if (peer.connected && peer.version === this.version) {
|
|
1513
|
-
let data = await new globalThis.peernet.protos['peernet-request']({
|
|
1526
|
+
let data = await new globalThis.peernet.protos['peernet-request']({
|
|
1527
|
+
request: 'knownBlocks'
|
|
1528
|
+
});
|
|
1514
1529
|
let node = await globalThis.peernet.prepareMessage(data);
|
|
1515
1530
|
let message = await peer.request(node);
|
|
1516
1531
|
message = await new globalThis.peernet.protos['peernet-response'](message);
|
|
@@ -1615,7 +1630,7 @@ class State extends Contract {
|
|
|
1615
1630
|
if (this.#resolveErrored ||
|
|
1616
1631
|
this.#syncState === 'errored' ||
|
|
1617
1632
|
this.#syncState === 'connectionless' ||
|
|
1618
|
-
!this.canSync && this.#lastResolvedTime + this.resolveTimeout > Date.now())
|
|
1633
|
+
(!this.canSync && this.#lastResolvedTime + this.resolveTimeout > Date.now()))
|
|
1619
1634
|
return true;
|
|
1620
1635
|
return false;
|
|
1621
1636
|
}
|
|
@@ -1635,7 +1650,7 @@ class VersionControl extends State {
|
|
|
1635
1650
|
super();
|
|
1636
1651
|
}
|
|
1637
1652
|
async init() {
|
|
1638
|
-
super.init && await super.init();
|
|
1653
|
+
super.init && (await super.init());
|
|
1639
1654
|
console.log('init');
|
|
1640
1655
|
try {
|
|
1641
1656
|
const version = await globalThis.chainStore.get('version');
|
|
@@ -1717,29 +1732,34 @@ class Chain extends VersionControl {
|
|
|
1717
1732
|
console.error(error);
|
|
1718
1733
|
}
|
|
1719
1734
|
const end = Date.now();
|
|
1720
|
-
console.log((
|
|
1735
|
+
console.log((end - start) / 1000 + ' s');
|
|
1721
1736
|
if (await this.hasTransactionToHandle())
|
|
1722
1737
|
return this.#runEpoch();
|
|
1723
1738
|
this.#runningEpoch = false;
|
|
1724
1739
|
// if (await this.hasTransactionToHandle() && !this.#runningEpoch) return this.#runEpoch()
|
|
1725
1740
|
}
|
|
1726
1741
|
async #setup() {
|
|
1727
|
-
const contracts = [
|
|
1742
|
+
const contracts = [
|
|
1743
|
+
{
|
|
1728
1744
|
address: addresses.contractFactory,
|
|
1729
1745
|
message: contractFactoryMessage
|
|
1730
|
-
},
|
|
1746
|
+
},
|
|
1747
|
+
{
|
|
1731
1748
|
address: addresses.nativeToken,
|
|
1732
1749
|
message: nativeTokenMessage
|
|
1733
|
-
},
|
|
1750
|
+
},
|
|
1751
|
+
{
|
|
1734
1752
|
address: addresses.validators,
|
|
1735
1753
|
message: validatorsMessage
|
|
1736
|
-
},
|
|
1754
|
+
},
|
|
1755
|
+
{
|
|
1737
1756
|
address: addresses.nameService,
|
|
1738
1757
|
message: nameServiceMessage
|
|
1739
|
-
}
|
|
1758
|
+
}
|
|
1759
|
+
];
|
|
1740
1760
|
await Promise.all(contracts.map(async ({ address, message }) => {
|
|
1741
1761
|
// @ts-ignore
|
|
1742
|
-
message = await new ContractMessage(Uint8Array.from(message.split(',').map(string => Number(string))));
|
|
1762
|
+
message = await new ContractMessage(Uint8Array.from(message.split(',').map((string) => Number(string))));
|
|
1743
1763
|
// @ts-ignore
|
|
1744
1764
|
await globalThis.contractStore.put(address, message.encoded);
|
|
1745
1765
|
}));
|
|
@@ -1761,7 +1781,7 @@ class Chain extends VersionControl {
|
|
|
1761
1781
|
return new BWMessage(globalThis.peernet.client.bw) || { up: 0, down: 0 };
|
|
1762
1782
|
});
|
|
1763
1783
|
// await globalThis.peernet.addRequestHandler('peerId', () => {
|
|
1764
|
-
// let node =
|
|
1784
|
+
// let node =
|
|
1765
1785
|
// globalThis.peernet.protos['peernet-response']({response: node.encoded})
|
|
1766
1786
|
// })
|
|
1767
1787
|
await globalThis.peernet.addRequestHandler('transactionPool', this.#transactionPoolHandler.bind(this));
|
|
@@ -1817,7 +1837,7 @@ class Chain extends VersionControl {
|
|
|
1817
1837
|
return;
|
|
1818
1838
|
const lastBlock = await this.#makeRequest(peer, 'lastBlock');
|
|
1819
1839
|
const higherThenCurrentLocal = lastBlock.index > this.lastBlock?.index;
|
|
1820
|
-
const peerTransactionPool = higherThenCurrentLocal && await this.getPeerTransactionPool(peer) || [];
|
|
1840
|
+
const peerTransactionPool = (higherThenCurrentLocal && (await this.getPeerTransactionPool(peer))) || [];
|
|
1821
1841
|
if (Object.keys(lastBlock).length > 0) {
|
|
1822
1842
|
if (!this.lastBlock || higherThenCurrentLocal) {
|
|
1823
1843
|
this.knownBlocks = await this.#makeRequest(peer, 'knownBlocks');
|
|
@@ -1906,7 +1926,7 @@ class Chain extends VersionControl {
|
|
|
1906
1926
|
// peerReputation(peerId)
|
|
1907
1927
|
// {bandwith: {up, down}, uptime}
|
|
1908
1928
|
this.#participating = true;
|
|
1909
|
-
if (!await this.staticCall(addresses.validators, 'has', [address])) {
|
|
1929
|
+
if (!(await this.staticCall(addresses.validators, 'has', [address]))) {
|
|
1910
1930
|
const rawTransaction = {
|
|
1911
1931
|
from: address,
|
|
1912
1932
|
to: addresses.validators,
|
|
@@ -1918,13 +1938,13 @@ class Chain extends VersionControl {
|
|
|
1918
1938
|
const transaction = await signTransaction(rawTransaction, globalThis.peernet.identity);
|
|
1919
1939
|
await this.sendTransaction(transaction);
|
|
1920
1940
|
}
|
|
1921
|
-
if (await this.hasTransactionToHandle() && !this.#runningEpoch && this.#participating)
|
|
1941
|
+
if ((await this.hasTransactionToHandle()) && !this.#runningEpoch && this.#participating)
|
|
1922
1942
|
await this.#runEpoch();
|
|
1923
1943
|
}
|
|
1924
1944
|
// todo filter tx that need to wait on prev nonce
|
|
1925
1945
|
async #createBlock(limit = this.transactionLimit) {
|
|
1926
1946
|
// vote for transactions
|
|
1927
|
-
if (await globalThis.transactionPoolStore.size() === 0)
|
|
1947
|
+
if ((await globalThis.transactionPoolStore.size()) === 0)
|
|
1928
1948
|
return;
|
|
1929
1949
|
let transactions = await globalThis.transactionPoolStore.values(this.transactionLimit);
|
|
1930
1950
|
for (const hash of await globalThis.transactionPoolStore.keys()) {
|
|
@@ -2017,7 +2037,7 @@ class Chain extends VersionControl {
|
|
|
2017
2037
|
}
|
|
2018
2038
|
}
|
|
2019
2039
|
}
|
|
2020
|
-
block.validators = block.validators.map(validator => {
|
|
2040
|
+
block.validators = block.validators.map((validator) => {
|
|
2021
2041
|
validator.reward = block.fees;
|
|
2022
2042
|
validator.reward = validator.reward.add(block.reward);
|
|
2023
2043
|
validator.reward = validator.reward.div(block.validators.length);
|
|
@@ -2035,8 +2055,7 @@ class Chain extends VersionControl {
|
|
|
2035
2055
|
// block.reward = block.reward.toString()
|
|
2036
2056
|
// block.fees = block.fees.toString()
|
|
2037
2057
|
try {
|
|
2038
|
-
block.transactions = await Promise.all(block.transactions
|
|
2039
|
-
.map(async (transaction) => {
|
|
2058
|
+
block.transactions = await Promise.all(block.transactions.map(async (transaction) => {
|
|
2040
2059
|
await globalThis.transactionPoolStore.delete(await transaction.hash());
|
|
2041
2060
|
return transaction.decoded;
|
|
2042
2061
|
}));
|
|
@@ -5638,9 +5638,9 @@ class BlockMessage extends FormatInterface {
|
|
|
5638
5638
|
encoded = encoded || this.encoded;
|
|
5639
5639
|
super.decode(encoded);
|
|
5640
5640
|
// @ts-ignore
|
|
5641
|
-
this.decoded.transactions = index$4(this.decoded.transactions).map(transaction => new TransactionMessage(transaction).decoded);
|
|
5641
|
+
this.decoded.transactions = index$4(this.decoded.transactions).map((transaction) => new TransactionMessage(transaction).decoded);
|
|
5642
5642
|
// @ts-ignore
|
|
5643
|
-
this.decoded.validators = index$4(this.decoded.validators).map(validator => new ValidatorMessage(validator).decoded);
|
|
5643
|
+
this.decoded.validators = index$4(this.decoded.validators).map((validator) => new ValidatorMessage(validator).decoded);
|
|
5644
5644
|
return this.decoded;
|
|
5645
5645
|
}
|
|
5646
5646
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-
|
|
2
|
-
import './index-
|
|
1
|
+
import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-ccafb3fc.js';
|
|
2
|
+
import './index-055d5584.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @params {String} network
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ContractMessage, T as TransactionMessage, c as BlockMessage, d as BWMessage, e as BWRequestMessage, V as ValidatorMessage } from './index-
|
|
1
|
+
import { C as ContractMessage, T as TransactionMessage, c as BlockMessage, d as BWMessage, e as BWRequestMessage, V as ValidatorMessage } from './index-055d5584.js';
|
|
2
2
|
|
|
3
3
|
var nodeConfig = async (config = {
|
|
4
4
|
network: 'leofcoin:peach',
|
|
@@ -20216,7 +20216,7 @@ class Identity {
|
|
|
20216
20216
|
this.selectedAccount = new TextDecoder().decode(selected);
|
|
20217
20217
|
}
|
|
20218
20218
|
else {
|
|
20219
|
-
const importee = await import(/* webpackChunkName: "generate-account" */ './index-329e0324-
|
|
20219
|
+
const importee = await import(/* webpackChunkName: "generate-account" */ './index-329e0324-f8858eb6.js');
|
|
20220
20220
|
const { identity, accounts } = await importee.default(password, this.network);
|
|
20221
20221
|
await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
|
|
20222
20222
|
await globalThis.walletStore.put('version', String(1));
|
|
@@ -20407,7 +20407,7 @@ class Peernet {
|
|
|
20407
20407
|
this.root = options.root;
|
|
20408
20408
|
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
|
|
20409
20409
|
// FolderMessageResponse
|
|
20410
|
-
} = await import(/* webpackChunkName: "messages" */ './messages-000b7f84-
|
|
20410
|
+
} = await import(/* webpackChunkName: "messages" */ './messages-000b7f84-2f945543.js');
|
|
20411
20411
|
/**
|
|
20412
20412
|
* proto Object containing protos
|
|
20413
20413
|
* @type {Object}
|
|
@@ -20971,7 +20971,9 @@ class Node {
|
|
|
20971
20971
|
networkVersion: 'peach',
|
|
20972
20972
|
stars: networks.leofcoin.peach.stars
|
|
20973
20973
|
}, password) {
|
|
20974
|
-
this.#node = globalThis.Peernet
|
|
20974
|
+
this.#node = globalThis.Peernet
|
|
20975
|
+
? await new globalThis.Peernet(config, password)
|
|
20976
|
+
: await new Peernet(config, password);
|
|
20975
20977
|
await nodeConfig(config);
|
|
20976
20978
|
globalThis.pubsub.subscribe('chain:ready', async () => {
|
|
20977
20979
|
if (!this.#node.autoStart) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { N as default } from './node-browser-
|
|
2
|
-
import './index-
|
|
1
|
+
export { N as default } from './node-browser-ccafb3fc.js';
|
|
2
|
+
import './index-055d5584.js';
|
|
@@ -1,29 +1,33 @@
|
|
|
1
|
-
import { E as EasyWorker, B as BigNumber, a as BlockMessage, f as formatBytes } from './worker-
|
|
1
|
+
import { E as EasyWorker, B as BigNumber, a as BlockMessage, f as formatBytes } from './worker-5b02efbe.js';
|
|
2
2
|
|
|
3
|
-
const worker = new EasyWorker();
|
|
4
|
-
|
|
5
|
-
globalThis.BigNumber = BigNumber;
|
|
6
|
-
globalThis.contracts = {};
|
|
7
|
-
|
|
8
|
-
const run = async (blocks) => {
|
|
9
|
-
blocks = await Promise.all(blocks.map(block => new BlockMessage(block)));
|
|
10
|
-
blocks = blocks.sort((a, b) => a.decoded.timestamp - b.decoded.timestamp);
|
|
11
|
-
|
|
12
|
-
blocks = await Promise.all(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
3
|
+
const worker = new EasyWorker();
|
|
4
|
+
|
|
5
|
+
globalThis.BigNumber = BigNumber;
|
|
6
|
+
globalThis.contracts = {};
|
|
7
|
+
|
|
8
|
+
const run = async (blocks) => {
|
|
9
|
+
blocks = await Promise.all(blocks.map((block) => new BlockMessage(block)));
|
|
10
|
+
blocks = blocks.sort((a, b) => a.decoded.timestamp - b.decoded.timestamp);
|
|
11
|
+
|
|
12
|
+
blocks = await Promise.all(
|
|
13
|
+
blocks.map(
|
|
14
|
+
(block) =>
|
|
15
|
+
new Promise(async (resolve, reject) => {
|
|
16
|
+
// todo: tx worker or nah?
|
|
17
|
+
await block.encode();
|
|
18
|
+
const size = block.encoded.length || block.encoded.byteLength;
|
|
19
|
+
console.log(`loaded block: ${await block.hash()} @${block.decoded.index} ${formatBytes(size)}`);
|
|
20
|
+
// todo we don't want this, need shared state
|
|
21
|
+
resolve(block.decoded);
|
|
22
|
+
})
|
|
23
|
+
)
|
|
24
|
+
);
|
|
25
|
+
return blocks
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const tasks = async (blocks) => {
|
|
29
|
+
blocks = await run(blocks);
|
|
30
|
+
worker.postMessage(blocks);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
worker.onmessage((data) => tasks(data));
|