@leofcoin/chain 1.4.92 → 1.4.93
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 +84 -879
- package/exports/browser/{index-fd1bc5f0.js → index-b32f624f.js} +1 -1
- package/exports/browser/{index-ed6cbdf7-cced6308.js → index-ed6cbdf7-8662153e.js} +2 -2
- package/exports/browser/{messages-35d069e1-0b6352ff.js → messages-35d069e1-7ad3a4bb.js} +2 -2
- package/exports/browser/{node-browser-e89e6592.js → node-browser-b56b946d.js} +17 -6
- package/exports/browser/node-browser.js +2 -2
- package/exports/chain.js +83 -44
- package/exports/node.js +1 -0
- package/exports/types/state.d.ts +2 -0
- package/package.json +2 -7
|
@@ -6081,4 +6081,4 @@ class RawTransactionMessage extends FormatInterface {
|
|
|
6081
6081
|
}
|
|
6082
6082
|
}
|
|
6083
6083
|
|
|
6084
|
-
export { BigNumber as B, ContractMessage as C, Logger as L, RawTransactionMessage as R, TransactionMessage as T, ValidatorMessage as V, arrayify as a, isBytes as b, BlockMessage as c, BWMessage as d, BWRequestMessage as e,
|
|
6084
|
+
export { BigNumber as B, ContractMessage as C, Logger as L, RawTransactionMessage as R, TransactionMessage as T, ValidatorMessage as V, arrayify as a, isBytes as b, BlockMessage as c, BWMessage as d, BWRequestMessage as e, hexZeroPad as h, isBigNumberish as i, toBase58 as t, version as v };
|
|
@@ -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-b56b946d.js';
|
|
2
|
+
import './index-b32f624f.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-b32f624f.js';
|
|
2
2
|
|
|
3
3
|
var nodeConfig = async (config = {
|
|
4
4
|
network: 'leofcoin:peach',
|
|
@@ -20166,7 +20166,7 @@ class Identity {
|
|
|
20166
20166
|
globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
|
|
20167
20167
|
}
|
|
20168
20168
|
else {
|
|
20169
|
-
const importee = await import(/* webpackChunkName: "generate-account" */ './index-ed6cbdf7-
|
|
20169
|
+
const importee = await import(/* webpackChunkName: "generate-account" */ './index-ed6cbdf7-8662153e.js');
|
|
20170
20170
|
const { identity, accounts } = await importee.default(password, this.network);
|
|
20171
20171
|
await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
|
|
20172
20172
|
await globalThis.walletStore.put('version', String(1));
|
|
@@ -20345,7 +20345,7 @@ class Peernet {
|
|
|
20345
20345
|
this.root = options.root;
|
|
20346
20346
|
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
|
|
20347
20347
|
// FolderMessageResponse
|
|
20348
|
-
} = await import(/* webpackChunkName: "messages" */ './messages-35d069e1-
|
|
20348
|
+
} = await import(/* webpackChunkName: "messages" */ './messages-35d069e1-7ad3a4bb.js');
|
|
20349
20349
|
/**
|
|
20350
20350
|
* proto Object containing protos
|
|
20351
20351
|
* @type {Object}
|
|
@@ -20873,15 +20873,26 @@ class Peernet {
|
|
|
20873
20873
|
}
|
|
20874
20874
|
globalThis.Peernet = Peernet;
|
|
20875
20875
|
|
|
20876
|
+
// todo only one star needed, no need to have one for each network
|
|
20877
|
+
// unless we change anything to the star protocoll
|
|
20878
|
+
// version diferences should be handled in the chain
|
|
20879
|
+
// maybe a good way to handle could be in p2pt-swarm
|
|
20876
20880
|
var networks = {
|
|
20877
20881
|
leofcoin: {
|
|
20878
20882
|
mainnet: {
|
|
20879
|
-
|
|
20880
|
-
|
|
20883
|
+
// ports don't really matter since it is favorable to have it begind a ngninx proxy but if we change something to the proto it's easier maybe?
|
|
20884
|
+
port: 44444,
|
|
20885
|
+
// todo a versionhash would be nice to have as a double check?
|
|
20886
|
+
versionHash: '0',
|
|
20887
|
+
// a short description identifying the version
|
|
20888
|
+
description: 'Main net current version',
|
|
20889
|
+
stars: ['wss://star.leofcoin.org'] // todo webrtc and bittorent stars
|
|
20881
20890
|
},
|
|
20882
20891
|
peach: {
|
|
20883
20892
|
port: 44444,
|
|
20884
|
-
|
|
20893
|
+
description: 'Main testnet: latest step before merging into main',
|
|
20894
|
+
versionHash: '1',
|
|
20895
|
+
stars: ['wss://star.leofcoin.org'] // todo webrtc and bittorent stars
|
|
20885
20896
|
}
|
|
20886
20897
|
}
|
|
20887
20898
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { N as default } from './node-browser-
|
|
2
|
-
import './index-
|
|
1
|
+
export { N as default } from './node-browser-b56b946d.js';
|
|
2
|
+
import './index-b32f624f.js';
|
package/exports/chain.js
CHANGED
|
@@ -2,7 +2,6 @@ import { formatBytes, BigNumber, formatUnits, parseUnits } from '@leofcoin/utils
|
|
|
2
2
|
import { TransactionMessage, BlockMessage, ContractMessage, BWMessage, BWRequestMessage } from '@leofcoin/messages';
|
|
3
3
|
import addresses, { contractFactory, nativeToken, validators, nameService } from '@leofcoin/addresses';
|
|
4
4
|
import { calculateFee, createContractMessage, contractFactoryMessage, nativeTokenMessage, validatorsMessage, nameServiceMessage, signTransaction } from '@leofcoin/lib';
|
|
5
|
-
import PQueue from 'p-queue';
|
|
6
5
|
import { randombytes } from '@leofcoin/crypto';
|
|
7
6
|
import EasyWorker from '@vandeurenglenn/easy-worker';
|
|
8
7
|
|
|
@@ -11,8 +10,9 @@ const transactionLimit = 1800;
|
|
|
11
10
|
const requestTimeout = 30000;
|
|
12
11
|
const syncTimeout = 30000;
|
|
13
12
|
class Protocol {
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
constructor() {
|
|
14
|
+
this.resolveTimeout = 30000;
|
|
15
|
+
}
|
|
16
16
|
get limit() {
|
|
17
17
|
return limit;
|
|
18
18
|
}
|
|
@@ -254,11 +254,12 @@ class Contract extends Transaction {
|
|
|
254
254
|
|
|
255
255
|
// import State from './state'
|
|
256
256
|
class Machine {
|
|
257
|
-
|
|
258
|
-
#
|
|
259
|
-
#nonces = {};
|
|
260
|
-
lastBlock = { index: 0, hash: '0x0', previousHash: '0x0' };
|
|
257
|
+
#contracts;
|
|
258
|
+
#nonces;
|
|
261
259
|
constructor(blocks) {
|
|
260
|
+
this.#contracts = {};
|
|
261
|
+
this.#nonces = {};
|
|
262
|
+
this.lastBlock = { index: 0, hash: '0x0', previousHash: '0x0' };
|
|
262
263
|
// @ts-ignore
|
|
263
264
|
return this.#init(blocks);
|
|
264
265
|
}
|
|
@@ -472,10 +473,8 @@ class Machine {
|
|
|
472
473
|
}
|
|
473
474
|
|
|
474
475
|
class Jobber {
|
|
475
|
-
timeout;
|
|
476
|
-
busy = false;
|
|
477
|
-
stop;
|
|
478
476
|
constructor(timeout) {
|
|
477
|
+
this.busy = false;
|
|
479
478
|
this.timeout = timeout;
|
|
480
479
|
}
|
|
481
480
|
add(fn) {
|
|
@@ -497,24 +496,22 @@ class Jobber {
|
|
|
497
496
|
}
|
|
498
497
|
}
|
|
499
498
|
|
|
500
|
-
new PQueue({ concurrency: 1, throwOnTimeout: true });
|
|
501
499
|
class State extends Contract {
|
|
502
500
|
#resolveErrored;
|
|
503
501
|
#lastResolvedTime;
|
|
504
502
|
#lastResolved;
|
|
505
|
-
#resolving
|
|
506
|
-
#resolveErrorCount
|
|
503
|
+
#resolving;
|
|
504
|
+
#resolveErrorCount;
|
|
507
505
|
#syncState;
|
|
508
506
|
#lastBlockInQue;
|
|
509
|
-
#syncErrorCount
|
|
510
|
-
#blockHashMap
|
|
511
|
-
#chainSyncing
|
|
512
|
-
#lastBlock
|
|
513
|
-
#blocks
|
|
514
|
-
|
|
515
|
-
#totalSize = 0;
|
|
507
|
+
#syncErrorCount;
|
|
508
|
+
#blockHashMap;
|
|
509
|
+
#chainSyncing;
|
|
510
|
+
#lastBlock;
|
|
511
|
+
#blocks;
|
|
512
|
+
#totalSize;
|
|
516
513
|
#machine;
|
|
517
|
-
#loaded
|
|
514
|
+
#loaded;
|
|
518
515
|
get blockHashMap() {
|
|
519
516
|
return this.#blockHashMap.entries();
|
|
520
517
|
}
|
|
@@ -527,26 +524,26 @@ class State extends Contract {
|
|
|
527
524
|
/**
|
|
528
525
|
* amount the native token has been iteracted with
|
|
529
526
|
*/
|
|
530
|
-
#nativeCalls
|
|
527
|
+
#nativeCalls;
|
|
531
528
|
/**
|
|
532
529
|
* amount the native token has been iteracted with
|
|
533
530
|
*/
|
|
534
|
-
#nativeTransfers
|
|
531
|
+
#nativeTransfers;
|
|
535
532
|
/**
|
|
536
533
|
* amount of native token burned
|
|
537
534
|
* {Number}
|
|
538
535
|
*/
|
|
539
|
-
#nativeBurns
|
|
536
|
+
#nativeBurns;
|
|
540
537
|
/**
|
|
541
538
|
* amount of native tokens minted
|
|
542
539
|
* {Number}
|
|
543
540
|
*/
|
|
544
|
-
#nativeMints
|
|
541
|
+
#nativeMints;
|
|
545
542
|
/**
|
|
546
543
|
* total amount of transactions
|
|
547
544
|
* {Number}
|
|
548
545
|
*/
|
|
549
|
-
#totalTransactions
|
|
546
|
+
#totalTransactions;
|
|
550
547
|
get nativeMints() {
|
|
551
548
|
return this.#nativeMints;
|
|
552
549
|
}
|
|
@@ -576,6 +573,46 @@ class State extends Contract {
|
|
|
576
573
|
}
|
|
577
574
|
constructor() {
|
|
578
575
|
super();
|
|
576
|
+
this.#resolving = false;
|
|
577
|
+
this.#resolveErrorCount = 0;
|
|
578
|
+
this.#syncErrorCount = 0;
|
|
579
|
+
this.#blockHashMap = new Map();
|
|
580
|
+
this.#chainSyncing = false;
|
|
581
|
+
this.#lastBlock = { index: 0, hash: '0x0', previousHash: '0x0' };
|
|
582
|
+
this.#blocks = [];
|
|
583
|
+
this.knownBlocks = [];
|
|
584
|
+
this.#totalSize = 0;
|
|
585
|
+
this.#loaded = false;
|
|
586
|
+
/**
|
|
587
|
+
* amount the native token has been iteracted with
|
|
588
|
+
*/
|
|
589
|
+
this.#nativeCalls = 0;
|
|
590
|
+
/**
|
|
591
|
+
* amount the native token has been iteracted with
|
|
592
|
+
*/
|
|
593
|
+
this.#nativeTransfers = 0;
|
|
594
|
+
/**
|
|
595
|
+
* amount of native token burned
|
|
596
|
+
* {Number}
|
|
597
|
+
*/
|
|
598
|
+
this.#nativeBurns = 0;
|
|
599
|
+
/**
|
|
600
|
+
* amount of native tokens minted
|
|
601
|
+
* {Number}
|
|
602
|
+
*/
|
|
603
|
+
this.#nativeMints = 0;
|
|
604
|
+
/**
|
|
605
|
+
* total amount of transactions
|
|
606
|
+
* {Number}
|
|
607
|
+
*/
|
|
608
|
+
this.#totalTransactions = 0;
|
|
609
|
+
this.#loadBlockTransactions = (transactions) => Promise.all(transactions.map((transaction) => new TransactionMessage(transaction)));
|
|
610
|
+
this.#getLastTransactions = async () => {
|
|
611
|
+
let lastTransactions = (await Promise.all(this.#blocks.filter(block => block.loaded).slice(-128)
|
|
612
|
+
.map(block => this.#loadBlockTransactions(block.transactions))))
|
|
613
|
+
.reduce((all, transactions) => [...all, ...transactions], []);
|
|
614
|
+
return Promise.all(lastTransactions.map(transaction => transaction.hash()));
|
|
615
|
+
};
|
|
579
616
|
}
|
|
580
617
|
async init() {
|
|
581
618
|
this.jobber = new Jobber(30000);
|
|
@@ -739,7 +776,6 @@ class State extends Contract {
|
|
|
739
776
|
catch (error) {
|
|
740
777
|
console.error(error);
|
|
741
778
|
}
|
|
742
|
-
// await queue.clear()
|
|
743
779
|
this.#chainSyncing = true;
|
|
744
780
|
if (!lastBlock)
|
|
745
781
|
lastBlock = await this.#getLatestBlock();
|
|
@@ -836,13 +872,8 @@ class State extends Contract {
|
|
|
836
872
|
}
|
|
837
873
|
return latest;
|
|
838
874
|
}
|
|
839
|
-
#loadBlockTransactions
|
|
840
|
-
#getLastTransactions
|
|
841
|
-
let lastTransactions = (await Promise.all(this.#blocks.filter(block => block.loaded).slice(-128)
|
|
842
|
-
.map(block => this.#loadBlockTransactions(block.transactions))))
|
|
843
|
-
.reduce((all, transactions) => [...all, ...transactions], []);
|
|
844
|
-
return Promise.all(lastTransactions.map(transaction => transaction.hash()));
|
|
845
|
-
};
|
|
875
|
+
#loadBlockTransactions;
|
|
876
|
+
#getLastTransactions;
|
|
846
877
|
/**
|
|
847
878
|
*
|
|
848
879
|
* @param {Block[]} blocks
|
|
@@ -854,8 +885,8 @@ class State extends Contract {
|
|
|
854
885
|
if (block.index === 0)
|
|
855
886
|
this.#loaded = true;
|
|
856
887
|
const transactions = await this.#loadBlockTransactions([...block.transactions] || []);
|
|
888
|
+
const lastTransactions = await this.#getLastTransactions();
|
|
857
889
|
for (const transaction of transactions) {
|
|
858
|
-
const lastTransactions = await this.#getLastTransactions();
|
|
859
890
|
const hash = await transaction.hash();
|
|
860
891
|
if (poolTransactionKeys.includes(hash))
|
|
861
892
|
await globalThis.transactionPoolStore.delete(hash);
|
|
@@ -938,18 +969,25 @@ const ignorelist = ['BA5XUACBBBAT653LT3GHP2Z5SUHVCA42BP6IBFBJACHOZIHHR4DUPG2XMB'
|
|
|
938
969
|
// check if browser or local
|
|
939
970
|
class Chain extends State {
|
|
940
971
|
#state;
|
|
941
|
-
#slotTime
|
|
942
|
-
id;
|
|
943
|
-
utils = {};
|
|
972
|
+
#slotTime;
|
|
944
973
|
/** {Address[]} */
|
|
945
|
-
#validators
|
|
974
|
+
#validators;
|
|
946
975
|
/** {Boolean} */
|
|
947
|
-
#runningEpoch
|
|
948
|
-
#participants
|
|
949
|
-
#participating
|
|
950
|
-
#jail
|
|
976
|
+
#runningEpoch;
|
|
977
|
+
#participants;
|
|
978
|
+
#participating;
|
|
979
|
+
#jail;
|
|
951
980
|
constructor() {
|
|
952
981
|
super();
|
|
982
|
+
this.#slotTime = 10000;
|
|
983
|
+
this.utils = {};
|
|
984
|
+
/** {Address[]} */
|
|
985
|
+
this.#validators = [];
|
|
986
|
+
/** {Boolean} */
|
|
987
|
+
this.#runningEpoch = false;
|
|
988
|
+
this.#participants = [];
|
|
989
|
+
this.#participating = false;
|
|
990
|
+
this.#jail = [];
|
|
953
991
|
// @ts-ignore
|
|
954
992
|
return this.#init();
|
|
955
993
|
}
|
|
@@ -1193,7 +1231,7 @@ class Chain extends State {
|
|
|
1193
1231
|
await this.#runEpoch();
|
|
1194
1232
|
}
|
|
1195
1233
|
// todo filter tx that need to wait on prev nonce
|
|
1196
|
-
async #createBlock(limit =
|
|
1234
|
+
async #createBlock(limit = this.transactionLimit) {
|
|
1197
1235
|
// vote for transactions
|
|
1198
1236
|
if (await globalThis.transactionPoolStore.size() === 0)
|
|
1199
1237
|
return;
|
|
@@ -1250,6 +1288,7 @@ class Chain extends State {
|
|
|
1250
1288
|
console.log(await globalThis.transactionPoolStore.has(e.hash));
|
|
1251
1289
|
}
|
|
1252
1290
|
}
|
|
1291
|
+
console.log(block.transactions.length);
|
|
1253
1292
|
// don't add empty block
|
|
1254
1293
|
if (block.transactions.length === 0)
|
|
1255
1294
|
return;
|
package/exports/node.js
CHANGED
|
@@ -18,6 +18,7 @@ class Node {
|
|
|
18
18
|
this.#node = globalThis.Peernet ? await new globalThis.Peernet(config, password) : await new Peernet(config, password);
|
|
19
19
|
await nodeConfig(config);
|
|
20
20
|
globalThis.pubsub.subscribe('chain:ready', () => {
|
|
21
|
+
// when autostart is false the node will only be started after the chain is ready (this is here so we can just use node for communication)
|
|
21
22
|
if (!this.#node.autoStart)
|
|
22
23
|
this.#node.start();
|
|
23
24
|
});
|
package/exports/types/state.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { BlockMessage } from '@leofcoin/messages';
|
|
2
2
|
import Contract from './contract.js';
|
|
3
3
|
import Machine from './machine.js';
|
|
4
|
+
import Jobber from './jobs/jobber.js';
|
|
4
5
|
import { BlockHash } from './types.js';
|
|
5
6
|
declare type SyncState = 'syncing' | 'synced' | 'errored' | 'connectionless';
|
|
6
7
|
export default class State extends Contract {
|
|
7
8
|
#private;
|
|
8
9
|
knownBlocks: BlockHash[];
|
|
10
|
+
jobber: Jobber;
|
|
9
11
|
get blockHashMap(): IterableIterator<[any, any]>;
|
|
10
12
|
get loaded(): boolean;
|
|
11
13
|
get resolving(): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/chain",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.93",
|
|
4
4
|
"description": "Official javascript implementation",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./node": "./exports/node.js",
|
|
@@ -22,12 +22,7 @@
|
|
|
22
22
|
"demo": "jsproject --serve ./ --port 5478 --open demo",
|
|
23
23
|
"test": "node --openssl-legacy-provider test",
|
|
24
24
|
"pack": "webpack",
|
|
25
|
-
"build": "
|
|
26
|
-
},
|
|
27
|
-
"wireit": {
|
|
28
|
-
"build": {
|
|
29
|
-
"command": "rollup -c --silent error --cache true"
|
|
30
|
-
}
|
|
25
|
+
"build": "rollup -c"
|
|
31
26
|
},
|
|
32
27
|
"np": {
|
|
33
28
|
"yarn": false,
|