@leofcoin/chain 1.3.1 → 1.3.4
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/demo/chain.browser.js +17 -13
- package/demo/peernet-swarm.browser.js +8 -9
- package/demo/workers/machine-worker.js +30 -11
- package/dist/browser/workers/machine-worker.js +18 -12
- package/dist/chain.js +149 -134
- package/dist/contracts/factory.js +1 -1
- package/dist/contracts/{nameService.js → name-service.js} +1 -1
- package/dist/contracts/native-token.js +1 -0
- package/dist/contracts/validators.js +1 -1
- package/dist/module/chain.js +146 -131
- package/dist/module/workers/machine-worker.js +18 -12
- package/dist/standards/token.js +1 -1
- package/dist/workers/machine-worker.js +1 -1
- package/package.json +20 -2
- package/rollup.config.js +4 -4
- package/src/chain.js +112 -102
- package/src/contracts/factory.js +58 -15
- package/src/contracts/{nameService.js → name-service.js} +3 -5
- package/src/contracts/{nativeToken.js → native-token.js} +2 -2
- package/src/contracts/{powerToken.js → power-token.js} +1 -1
- package/src/contracts/proxies/{factoryProxy.js → factory-proxy.js} +1 -1
- package/src/contracts/proxies/{nameServiceProxy.js → name-service-proxy.js} +1 -1
- package/src/contracts/proxies/{nativeTokenProxy.js → native-token-proxy.js} +1 -1
- package/src/contracts/proxies/{validatorsProxy.js → validators-proxy.js} +1 -1
- package/src/contracts/proxies/{votingProxy.js → voting-proxy.js} +1 -1
- package/src/contracts/{proxyManager.js → proxy-manager.js} +1 -1
- package/src/contracts/validators.js +35 -25
- package/src/fee/config.js +1 -1
- package/src/machine.js +34 -29
- package/src/standards/{proxyManager.js → proxy-manager.js} +0 -0
- package/src/standards/{Proxy.js → proxy.js} +4 -8
- package/src/standards/roles.js +7 -5
- package/src/standards/voting.js +1 -0
- package/src/transactions/transaction.js +1 -3
- package/src/transactions/validator.js +1 -1
- package/src/typer.js +1 -1
- package/dist/865.browser.js +0 -10
- package/dist/chain.browser.js +0 -59741
- package/dist/contracts/nativeToken.js +0 -1
- package/dist/generate-account.browser.js +0 -50
- package/dist/messages.browser.js +0 -328
- package/dist/multi-wallet.browser.js +0 -15
- package/dist/node.browser.js +0 -9858
- package/dist/pako.browser.js +0 -6900
- package/dist/peernet-swarm.browser.js +0 -840
- package/dist/storage.browser.js +0 -3724
- package/dist/wrtc.browser.js +0 -28
- package/src/standards/Voting.js +0 -3
package/demo/chain.browser.js
CHANGED
|
@@ -58565,8 +58565,8 @@ class Machine {
|
|
|
58565
58565
|
#nonces = {}
|
|
58566
58566
|
lastBlock = {index: 0, hash: '0x0', previousHash: '0x0'}
|
|
58567
58567
|
|
|
58568
|
-
constructor() {
|
|
58569
|
-
return this.#init()
|
|
58568
|
+
constructor(blocks) {
|
|
58569
|
+
return this.#init(blocks)
|
|
58570
58570
|
}
|
|
58571
58571
|
|
|
58572
58572
|
#createMessage(sender = peernet.selectedAccount) {
|
|
@@ -58603,7 +58603,7 @@ class Machine {
|
|
|
58603
58603
|
|
|
58604
58604
|
}
|
|
58605
58605
|
|
|
58606
|
-
async #init() {
|
|
58606
|
+
async #init(blocks) {
|
|
58607
58607
|
return new Promise(async (resolve) => {
|
|
58608
58608
|
pubsub.subscribe('machine.ready', () => {
|
|
58609
58609
|
resolve(this);
|
|
@@ -58612,7 +58612,7 @@ class Machine {
|
|
|
58612
58612
|
this.worker = await new EasyWorker((0,path_browserify.join)(chain_dirname, './workers/machine-worker.js'), {serialization: 'advanced', type:'module'});
|
|
58613
58613
|
this.worker.onmessage(this.#onmessage.bind(this));
|
|
58614
58614
|
|
|
58615
|
-
const blocks = await blockStore.values()
|
|
58615
|
+
// const blocks = await blockStore.values()
|
|
58616
58616
|
const contracts = await Promise.all([
|
|
58617
58617
|
contractStore.get(contractFactory$1),
|
|
58618
58618
|
contractStore.get(nativeToken$1),
|
|
@@ -59052,7 +59052,7 @@ class Chain {
|
|
|
59052
59052
|
const initialized = await contractStore.has(addresses.contractFactory);
|
|
59053
59053
|
if (!initialized) await this.#setup();
|
|
59054
59054
|
|
|
59055
|
-
|
|
59055
|
+
|
|
59056
59056
|
this.utils = { BigNumber: BigNumber, formatUnits: formatUnits, parseUnits: parseUnits };
|
|
59057
59057
|
|
|
59058
59058
|
try {
|
|
@@ -59096,6 +59096,11 @@ class Chain {
|
|
|
59096
59096
|
|
|
59097
59097
|
// load local blocks
|
|
59098
59098
|
await this.resolveBlocks();
|
|
59099
|
+
this.#machine = await new Machine(this.#blocks);
|
|
59100
|
+
// for (const block of this.#blocks) {
|
|
59101
|
+
// block.loaded = true
|
|
59102
|
+
// }
|
|
59103
|
+
await this.#loadBlocks(this.#blocks);
|
|
59099
59104
|
return this
|
|
59100
59105
|
}
|
|
59101
59106
|
|
|
@@ -59122,8 +59127,8 @@ class Chain {
|
|
|
59122
59127
|
debug(`synced ${blocksSynced} ${blocksSynced > 1 ? 'blocks' : 'block'}`);
|
|
59123
59128
|
|
|
59124
59129
|
this.#blocks.length;
|
|
59125
|
-
(this.#blocks.length) - blocksSynced;
|
|
59126
|
-
await this.#loadBlocks(this
|
|
59130
|
+
const start = (this.#blocks.length) - blocksSynced;
|
|
59131
|
+
await this.#loadBlocks(this.blocks.slice(start));
|
|
59127
59132
|
this.#lastBlock = this.#blocks[this.#blocks.length - 1];
|
|
59128
59133
|
const message = await new BlockMessage(this.lastBlock);
|
|
59129
59134
|
await blockStore.put(await message.hash, message.encoded);
|
|
@@ -59155,9 +59160,9 @@ async resolveBlock(hash) {
|
|
|
59155
59160
|
if (!await peernet.has(hash, 'block')) await peernet.put(hash, block.encoded, 'block');
|
|
59156
59161
|
const size = block.encoded.length || block.encoded.byteLength;
|
|
59157
59162
|
block = {...block.decoded, hash};
|
|
59158
|
-
if (this.#blocks[block.index]) throw `invalid block ${hash} @${block.index}`
|
|
59163
|
+
if (this.#blocks[block.index] && this.#blocks[block.index].hash !== block.hash) throw `invalid block ${hash} @${block.index}`
|
|
59159
59164
|
this.#blocks[block.index] = block;
|
|
59160
|
-
console.log(`
|
|
59165
|
+
console.log(`resolved block: ${hash} @${block.index} ${formatBytes(size)}`);
|
|
59161
59166
|
if (block.previousHash !== '0x0') {
|
|
59162
59167
|
return this.resolveBlock(block.previousHash)
|
|
59163
59168
|
}
|
|
@@ -59171,7 +59176,7 @@ async resolveBlock(hash) {
|
|
|
59171
59176
|
if (hash && hash !== '0x0')
|
|
59172
59177
|
await this.resolveBlock(hash);
|
|
59173
59178
|
this.#lastBlock = this.#blocks[this.#blocks.length - 1];
|
|
59174
|
-
|
|
59179
|
+
|
|
59175
59180
|
} catch (e) {
|
|
59176
59181
|
await chainStore.put('lastBlock', new TextEncoder().encode('0x0'));
|
|
59177
59182
|
return this.resolveBlocks()
|
|
@@ -59190,7 +59195,8 @@ async resolveBlock(hash) {
|
|
|
59190
59195
|
console.log(e);
|
|
59191
59196
|
}
|
|
59192
59197
|
}
|
|
59193
|
-
block.loaded = true;
|
|
59198
|
+
this.#blocks[block.index].loaded = true;
|
|
59199
|
+
console.log(`loaded block: ${block.hash} @${block.index}`);
|
|
59194
59200
|
// let message = await peernet.get(block.hash, 'block')
|
|
59195
59201
|
|
|
59196
59202
|
// const compressed = pako.deflate(message);
|
|
@@ -59242,8 +59248,6 @@ async resolveBlock(hash) {
|
|
|
59242
59248
|
// transaction = new TransactionMessage(transaction)
|
|
59243
59249
|
// return transaction
|
|
59244
59250
|
// }
|
|
59245
|
-
|
|
59246
|
-
console.log(blockMessage);
|
|
59247
59251
|
await Promise.all(blockMessage.decoded.transactions
|
|
59248
59252
|
.map(async transaction => transactionPoolStore.delete(await transaction.hash)));
|
|
59249
59253
|
const hash = await blockMessage.hash;
|
|
@@ -436,7 +436,7 @@ class Peer {
|
|
|
436
436
|
this.#connection.ondatachannel = (message) => {
|
|
437
437
|
message.channel.onopen = () => {
|
|
438
438
|
this.#connected = true
|
|
439
|
-
|
|
439
|
+
// debug(`peer:connected ${this}`)
|
|
440
440
|
pubsub.publish('peer:connected', this)
|
|
441
441
|
}
|
|
442
442
|
message.channel.onclose = () => this.close.bind(this)
|
|
@@ -473,7 +473,7 @@ class Peer {
|
|
|
473
473
|
}
|
|
474
474
|
|
|
475
475
|
_handleMessage(peerId, message) {
|
|
476
|
-
|
|
476
|
+
// debug(`incoming message from ${peerId}`)
|
|
477
477
|
|
|
478
478
|
message = JSON.parse(new TextDecoder().decode(message.data))
|
|
479
479
|
// allow sharding (multiple peers share data)
|
|
@@ -515,7 +515,7 @@ class Peer {
|
|
|
515
515
|
|
|
516
516
|
|
|
517
517
|
if (message.candidate) {
|
|
518
|
-
debug(`incoming candidate ${this.#channelName}`)
|
|
518
|
+
// debug(`incoming candidate ${this.#channelName}`)
|
|
519
519
|
// debug(message.candidate.candidate)
|
|
520
520
|
this.remoteAddress = message.candidate.address
|
|
521
521
|
this.remotePort = message.candidate.port
|
|
@@ -526,14 +526,14 @@ class Peer {
|
|
|
526
526
|
try {
|
|
527
527
|
if (message.sdp) {
|
|
528
528
|
if (message.sdp.type === 'offer') {
|
|
529
|
-
debug(`incoming offer ${this.#channelName}`)
|
|
529
|
+
// debug(`incoming offer ${this.#channelName}`)
|
|
530
530
|
await this.#connection.setRemoteDescription(new wrtc.RTCSessionDescription(message.sdp))
|
|
531
531
|
const answer = await this.#connection.createAnswer();
|
|
532
532
|
await this.#connection.setLocalDescription(answer)
|
|
533
533
|
this._sendMessage({'sdp': this.#connection.localDescription})
|
|
534
534
|
}
|
|
535
535
|
if (message.sdp.type === 'answer') {
|
|
536
|
-
debug(`incoming answer ${this.#channelName}`)
|
|
536
|
+
// debug(`incoming answer ${this.#channelName}`)
|
|
537
537
|
await this.#connection.setRemoteDescription(new wrtc.RTCSessionDescription(message.sdp))
|
|
538
538
|
}
|
|
539
539
|
}
|
|
@@ -543,7 +543,7 @@ class Peer {
|
|
|
543
543
|
}
|
|
544
544
|
|
|
545
545
|
close() {
|
|
546
|
-
|
|
546
|
+
// debug(`closing ${this.peerId}`)
|
|
547
547
|
this.#connected = false
|
|
548
548
|
this.#channel?.close()
|
|
549
549
|
this.#connection?.close()
|
|
@@ -578,11 +578,10 @@ class Client {
|
|
|
578
578
|
this.starJoined = this.starJoined.bind(this)
|
|
579
579
|
this.networkVersion = networkVersion
|
|
580
580
|
|
|
581
|
-
this._init(
|
|
581
|
+
this._init(stars)
|
|
582
582
|
}
|
|
583
583
|
|
|
584
|
-
async _init(
|
|
585
|
-
this.network = network
|
|
584
|
+
async _init(stars = []) {
|
|
586
585
|
this.starsConfig = stars
|
|
587
586
|
// reconnectJob()
|
|
588
587
|
|
|
@@ -11723,6 +11723,11 @@ var __webpack_exports__ = {};
|
|
|
11723
11723
|
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
|
11724
11724
|
!function() {
|
|
11725
11725
|
|
|
11726
|
+
// EXPORTS
|
|
11727
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
11728
|
+
"T": function() { return /* binding */ unique; }
|
|
11729
|
+
});
|
|
11730
|
+
|
|
11726
11731
|
;// CONCATENATED MODULE: ./node_modules/@vandeurenglenn/base-x/src/base-x.js
|
|
11727
11732
|
// base-x encoding / decoding
|
|
11728
11733
|
// Copyright (c) 2018 base-x contributors
|
|
@@ -13722,6 +13727,9 @@ globalThis.BigNumber = BigNumber;
|
|
|
13722
13727
|
globalThis.peernet = globalThis.peernet || {};
|
|
13723
13728
|
globalThis.contracts = {};
|
|
13724
13729
|
|
|
13730
|
+
const unique = arr => arr.filter((el, pos, arr) => {
|
|
13731
|
+
return arr.indexOf(el) == pos;
|
|
13732
|
+
});
|
|
13725
13733
|
|
|
13726
13734
|
const get = (contract, method, params) => {
|
|
13727
13735
|
let result;
|
|
@@ -13819,16 +13827,23 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
13819
13827
|
|
|
13820
13828
|
if (blocks?.length > 0) {
|
|
13821
13829
|
const _worker = await new EasyWorker('./block-worker.js', {serialization: 'advanced', type: 'module' });
|
|
13822
|
-
blocks = await _worker.once(blocks);
|
|
13830
|
+
blocks = await _worker.once([blocks[blocks.length - 1]]);
|
|
13823
13831
|
|
|
13824
|
-
|
|
13825
|
-
|
|
13826
|
-
|
|
13827
|
-
|
|
13828
|
-
|
|
13829
|
-
|
|
13830
|
-
|
|
13831
|
-
}
|
|
13832
|
+
// blocks = unique(globalThis.blocks ? globalThis : [], blocks)
|
|
13833
|
+
// for (let i = 0; i < blocks.length; i++) {
|
|
13834
|
+
|
|
13835
|
+
// }
|
|
13836
|
+
// for (const block of blocks) {
|
|
13837
|
+
// await Promise.all(block.decoded.transactions.map(async message => {
|
|
13838
|
+
// if (!block.loaded) {
|
|
13839
|
+
// const {from, to, method, params} = message;
|
|
13840
|
+
// globalThis.msg = createMessage(from);
|
|
13841
|
+
|
|
13842
|
+
// await execute(to, method, params);
|
|
13843
|
+
// block.loaded = true
|
|
13844
|
+
// }
|
|
13845
|
+
// }));
|
|
13846
|
+
// }
|
|
13832
13847
|
|
|
13833
13848
|
if (blocks.length > 0) {
|
|
13834
13849
|
lastBlock = blocks[blocks.length - 1].decoded;
|
|
@@ -13839,15 +13854,15 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
13839
13854
|
hash: await lastBlock.hash
|
|
13840
13855
|
};
|
|
13841
13856
|
}
|
|
13857
|
+
globalThis.blocks = blocks;
|
|
13842
13858
|
}
|
|
13843
13859
|
|
|
13844
13860
|
|
|
13845
13861
|
|
|
13846
13862
|
|
|
13847
13863
|
worker.postMessage({type: 'machine-ready', lastBlock});
|
|
13848
|
-
_worker.terminate();
|
|
13849
13864
|
|
|
13850
|
-
worker.postMessage(blocks);
|
|
13865
|
+
// worker.postMessage({blocks});
|
|
13851
13866
|
};
|
|
13852
13867
|
|
|
13853
13868
|
const tasks = async (e) => {
|
|
@@ -13901,4 +13916,8 @@ const tasks = async (e) => {
|
|
|
13901
13916
|
|
|
13902
13917
|
worker.onmessage(data => tasks(data));
|
|
13903
13918
|
|
|
13919
|
+
|
|
13920
|
+
|
|
13904
13921
|
}();
|
|
13922
|
+
var __webpack_exports__unique = __webpack_exports__.T;
|
|
13923
|
+
export { __webpack_exports__unique as unique };
|
|
@@ -13722,7 +13722,6 @@ globalThis.BigNumber = BigNumber;
|
|
|
13722
13722
|
globalThis.peernet = globalThis.peernet || {};
|
|
13723
13723
|
globalThis.contracts = {};
|
|
13724
13724
|
|
|
13725
|
-
|
|
13726
13725
|
const get = (contract, method, params) => {
|
|
13727
13726
|
let result;
|
|
13728
13727
|
if (params?.length > 0) {
|
|
@@ -13819,16 +13818,23 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
13819
13818
|
|
|
13820
13819
|
if (blocks?.length > 0) {
|
|
13821
13820
|
const _worker = await new EasyWorker('./block-worker.js', {serialization: 'advanced', type: 'module' });
|
|
13822
|
-
blocks = await _worker.once(blocks);
|
|
13821
|
+
blocks = await _worker.once([blocks[blocks.length - 1]]);
|
|
13823
13822
|
|
|
13824
|
-
|
|
13825
|
-
|
|
13826
|
-
|
|
13827
|
-
|
|
13828
|
-
|
|
13829
|
-
|
|
13830
|
-
|
|
13831
|
-
}
|
|
13823
|
+
// blocks = unique(globalThis.blocks ? globalThis : [], blocks)
|
|
13824
|
+
// for (let i = 0; i < blocks.length; i++) {
|
|
13825
|
+
|
|
13826
|
+
// }
|
|
13827
|
+
// for (const block of blocks) {
|
|
13828
|
+
// await Promise.all(block.decoded.transactions.map(async message => {
|
|
13829
|
+
// if (!block.loaded) {
|
|
13830
|
+
// const {from, to, method, params} = message;
|
|
13831
|
+
// globalThis.msg = createMessage(from);
|
|
13832
|
+
|
|
13833
|
+
// await execute(to, method, params);
|
|
13834
|
+
// block.loaded = true
|
|
13835
|
+
// }
|
|
13836
|
+
// }));
|
|
13837
|
+
// }
|
|
13832
13838
|
|
|
13833
13839
|
if (blocks.length > 0) {
|
|
13834
13840
|
lastBlock = blocks[blocks.length - 1].decoded;
|
|
@@ -13839,15 +13845,15 @@ const _init = async ({ contracts, blocks, peerid })=> {
|
|
|
13839
13845
|
hash: await lastBlock.hash
|
|
13840
13846
|
};
|
|
13841
13847
|
}
|
|
13848
|
+
globalThis.blocks = blocks;
|
|
13842
13849
|
}
|
|
13843
13850
|
|
|
13844
13851
|
|
|
13845
13852
|
|
|
13846
13853
|
|
|
13847
13854
|
worker.postMessage({type: 'machine-ready', lastBlock});
|
|
13848
|
-
_worker.terminate();
|
|
13849
13855
|
|
|
13850
|
-
worker.postMessage(blocks);
|
|
13856
|
+
// worker.postMessage({blocks});
|
|
13851
13857
|
};
|
|
13852
13858
|
|
|
13853
13859
|
const tasks = async (e) => {
|