@leofcoin/chain 1.1.11 → 1.1.12
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/{dist/workers/block-worker.js → block-worker.js} +0 -0
- package/demo/chain.browser.js +37 -38
- package/demo/node.browser.js +2 -12
- package/demo/pako.browser.js +670 -501
- package/demo/peernet-swarm.browser.js +8 -12
- package/demo/workers/block-worker.js +1 -2
- package/demo/workers/machine-worker.js +2 -4
- package/demo/workers/pool-worker.js +1 -2
- package/demo/workers/transaction-worker.js +1 -2
- package/dist/browser/workers/block-worker.js +1 -2
- package/dist/browser/workers/machine-worker.js +2 -4
- package/dist/browser/workers/pool-worker.js +1 -2
- package/dist/browser/workers/transaction-worker.js +1 -2
- package/dist/chain.browser.js +37 -38
- package/dist/chain.js +36 -36
- package/dist/module/chain.js +36 -36
- package/dist/module/workers/machine-worker.js +2 -2
- package/dist/node.browser.js +2 -12
- package/dist/pako.browser.js +670 -501
- package/dist/peernet-swarm.browser.js +8 -12
- package/dist/workers/machine-worker.js +1 -1
- package/package.json +2 -2
- package/rollup.config.js +1 -1
- package/src/chain.js +30 -34
- package/src/machine.js +5 -1
- package/test/chain.js +17 -2
- package/demo/865.machine-worker.js +0 -10
- package/demo/chain.js +0 -1209
- package/demo/machine-worker.js +0 -17624
- package/demo/node.js +0 -1
- package/demo/workers/workers/865.js +0 -10
- package/demo/workers/workers/block-worker.js +0 -13200
- package/demo/workers/workers/machine-worker.js +0 -13904
- package/demo/workers/workers/pool-worker.js +0 -8504
- package/demo/workers/workers/transaction-worker.js +0 -8496
|
File without changes
|
package/demo/chain.browser.js
CHANGED
|
@@ -56165,8 +56165,7 @@ module.exports = JSON.parse('{"2.16.840.1.101.3.4.1.1":"aes-128-ecb","2.16.840.1
|
|
|
56165
56165
|
/******/ script.parentNode && script.parentNode.removeChild(script);
|
|
56166
56166
|
/******/ doneFns && doneFns.forEach(function(fn) { return fn(event); });
|
|
56167
56167
|
/******/ if(prev) return prev(event);
|
|
56168
|
-
/******/ }
|
|
56169
|
-
/******/ ;
|
|
56168
|
+
/******/ };
|
|
56170
56169
|
/******/ var timeout = setTimeout(onScriptComplete.bind(null, undefined, { type: 'timeout', target: script }), 120000);
|
|
56171
56170
|
/******/ script.onerror = onScriptComplete.bind(null, script.onerror);
|
|
56172
56171
|
/******/ script.onload = onScriptComplete.bind(null, script.onload);
|
|
@@ -58595,7 +58594,7 @@ class Machine {
|
|
|
58595
58594
|
break
|
|
58596
58595
|
case 'machine-ready':
|
|
58597
58596
|
this.lastBlock = data.lastBlock;
|
|
58598
|
-
pubsub.publish('machine.ready');
|
|
58597
|
+
pubsub.publish('machine.ready', true);
|
|
58599
58598
|
break
|
|
58600
58599
|
case 'response':
|
|
58601
58600
|
pubsub.publish(data.id, data.value);
|
|
@@ -58716,6 +58715,10 @@ class Machine {
|
|
|
58716
58715
|
return contractStore.delete(hash)
|
|
58717
58716
|
}
|
|
58718
58717
|
|
|
58718
|
+
/**
|
|
58719
|
+
*
|
|
58720
|
+
* @returns Promise
|
|
58721
|
+
*/
|
|
58719
58722
|
async deleteAll() {
|
|
58720
58723
|
let hashes = await contractStore.get();
|
|
58721
58724
|
hashes = Object.keys(hashes).map(hash => this.delete(hash));
|
|
@@ -59036,8 +59039,7 @@ class Chain {
|
|
|
59036
59039
|
}, {index: 0, hash: '0x0'});
|
|
59037
59040
|
// get lastblock
|
|
59038
59041
|
if (promises.hash && promises.hash !== '0x0') {
|
|
59039
|
-
|
|
59040
|
-
console.log({localBlock});
|
|
59042
|
+
await peernet.get(promises.hash);
|
|
59041
59043
|
}
|
|
59042
59044
|
|
|
59043
59045
|
|
|
@@ -59052,22 +59054,7 @@ class Chain {
|
|
|
59052
59054
|
|
|
59053
59055
|
this.#machine = await new Machine();
|
|
59054
59056
|
this.utils = { BigNumber: BigNumber, formatUnits: formatUnits, parseUnits: parseUnits };
|
|
59055
|
-
|
|
59056
|
-
await peernet.addRequestHandler('bw-request-message', () => {
|
|
59057
|
-
|
|
59058
|
-
return new BWMessage(peernet.client.bw) || { up: 0, down: 0 }
|
|
59059
|
-
});
|
|
59060
|
-
|
|
59061
|
-
await peernet.addRequestHandler('lastBlock', this.#lastBlockHandler.bind(this));
|
|
59062
|
-
|
|
59063
|
-
peernet.subscribe('add-block', this.#addBlock.bind(this));
|
|
59064
|
-
|
|
59065
|
-
peernet.subscribe('add-transaction', this.#addTransaction.bind(this));
|
|
59066
|
-
|
|
59067
|
-
peernet.subscribe('validator:timeout', this.#validatorTimeout.bind(this));
|
|
59068
|
-
|
|
59069
|
-
pubsub.subscribe('peer:connected', this.#peerConnected.bind(this));
|
|
59070
|
-
|
|
59057
|
+
|
|
59071
59058
|
try {
|
|
59072
59059
|
let localBlock;
|
|
59073
59060
|
try {
|
|
@@ -59077,17 +59064,11 @@ class Chain {
|
|
|
59077
59064
|
localBlock = await chainStore.get('lastBlock');
|
|
59078
59065
|
}
|
|
59079
59066
|
localBlock = new TextDecoder().decode(localBlock);
|
|
59080
|
-
|
|
59081
59067
|
if (localBlock && localBlock !== '0x0') {
|
|
59082
|
-
localBlock = await peernet.get(localBlock);
|
|
59068
|
+
localBlock = await peernet.get(localBlock, 'block');
|
|
59083
59069
|
localBlock = await new BlockMessage(localBlock);
|
|
59084
59070
|
this.#lastBlock = {...localBlock.decoded, hash: await localBlock.hash};
|
|
59085
|
-
} else
|
|
59086
|
-
// todo remove when network is running
|
|
59087
|
-
// recovering chain (not needed if multiple peers are online)
|
|
59088
|
-
this.#lastBlock = this.#machine.lastBlock;
|
|
59089
|
-
await chainStore.put('lastBlock', this.#lastBlock.hash);
|
|
59090
|
-
} else {
|
|
59071
|
+
} else {
|
|
59091
59072
|
await this.#sync();
|
|
59092
59073
|
}
|
|
59093
59074
|
} catch (e) {
|
|
@@ -59096,8 +59077,25 @@ class Chain {
|
|
|
59096
59077
|
|
|
59097
59078
|
// this.#setup()
|
|
59098
59079
|
}
|
|
59080
|
+
|
|
59081
|
+
await peernet.addRequestHandler('bw-request-message', () => {
|
|
59082
|
+
|
|
59083
|
+
return new BWMessage(peernet.client.bw) || { up: 0, down: 0 }
|
|
59084
|
+
});
|
|
59085
|
+
|
|
59086
|
+
await peernet.addRequestHandler('lastBlock', this.#lastBlockHandler.bind(this));
|
|
59087
|
+
|
|
59088
|
+
peernet.subscribe('add-block', this.#addBlock.bind(this));
|
|
59089
|
+
|
|
59090
|
+
peernet.subscribe('add-transaction', this.#addTransaction.bind(this));
|
|
59091
|
+
|
|
59092
|
+
peernet.subscribe('validator:timeout', this.#validatorTimeout.bind(this));
|
|
59093
|
+
|
|
59094
|
+
pubsub.subscribe('peer:connected', this.#peerConnected.bind(this));
|
|
59095
|
+
|
|
59096
|
+
|
|
59099
59097
|
// load local blocks
|
|
59100
|
-
|
|
59098
|
+
await this.resolveBlocks();
|
|
59101
59099
|
return this
|
|
59102
59100
|
}
|
|
59103
59101
|
|
|
@@ -59115,7 +59113,7 @@ class Chain {
|
|
|
59115
59113
|
response = await new globalThis.peernet.protos['peernet-response'](response);
|
|
59116
59114
|
let lastBlock = response.decoded.response;
|
|
59117
59115
|
|
|
59118
|
-
if (!this.lastBlock || this.lastBlock.index < lastBlock.index) {
|
|
59116
|
+
if (!this.lastBlock || Number(this.lastBlock.index) < Number(lastBlock.index)) {
|
|
59119
59117
|
// TODO: check if valid
|
|
59120
59118
|
const localIndex = this.lastBlock ? this.lastBlock.index : 0;
|
|
59121
59119
|
const index = lastBlock.index;
|
|
@@ -59157,7 +59155,8 @@ async resolveBlock(hash) {
|
|
|
59157
59155
|
if (!await peernet.has(hash, 'block')) await peernet.put(hash, block.encoded, 'block');
|
|
59158
59156
|
const size = block.encoded.length || block.encoded.byteLength;
|
|
59159
59157
|
block = {...block.decoded, hash};
|
|
59160
|
-
this.#blocks[block.index
|
|
59158
|
+
if (this.#blocks[block.index]) throw `invalid block ${hash} @${block.index}`
|
|
59159
|
+
this.#blocks[block.index] = block;
|
|
59161
59160
|
console.log(`loaded block: ${hash} @${block.index} ${formatBytes(size)}`);
|
|
59162
59161
|
if (block.previousHash !== '0x0') {
|
|
59163
59162
|
return this.resolveBlock(block.previousHash)
|
|
@@ -59166,11 +59165,11 @@ async resolveBlock(hash) {
|
|
|
59166
59165
|
|
|
59167
59166
|
async resolveBlocks() {
|
|
59168
59167
|
try {
|
|
59169
|
-
|
|
59170
59168
|
const localBlock = await chainStore.get('lastBlock');
|
|
59171
59169
|
const hash = new TextDecoder().decode(localBlock);
|
|
59170
|
+
|
|
59172
59171
|
if (hash && hash !== '0x0')
|
|
59173
|
-
await this.resolveBlock(
|
|
59172
|
+
await this.resolveBlock(hash);
|
|
59174
59173
|
this.#lastBlock = this.#blocks[this.#blocks.length - 1];
|
|
59175
59174
|
await this.#loadBlocks(this.#blocks);
|
|
59176
59175
|
} catch (e) {
|
|
@@ -59227,7 +59226,7 @@ async resolveBlock(hash) {
|
|
|
59227
59226
|
}
|
|
59228
59227
|
|
|
59229
59228
|
async #addBlock(block) {
|
|
59230
|
-
console.log(block);
|
|
59229
|
+
// console.log(block);
|
|
59231
59230
|
const blockMessage = await new BlockMessage(new Uint8Array(Object.values(block)));
|
|
59232
59231
|
// if (!Buffer.isBuffer(block)) block = Buffer.from(block, 'hex')
|
|
59233
59232
|
// const transactionJob = async transaction => {
|
|
@@ -59253,7 +59252,7 @@ async resolveBlock(hash) {
|
|
|
59253
59252
|
|
|
59254
59253
|
await blockStore.put(hash, blockMessage.encoded);
|
|
59255
59254
|
|
|
59256
|
-
if (this.lastBlock.index < blockMessage.decoded.index) this.#updateState(blockMessage);
|
|
59255
|
+
if (this.lastBlock.index < blockMessage.decoded.index) await this.#updateState(blockMessage);
|
|
59257
59256
|
debug(`added block: ${hash}`);
|
|
59258
59257
|
let promises = [];
|
|
59259
59258
|
let contracts = [];
|
|
@@ -59449,8 +59448,8 @@ async resolveBlock(hash) {
|
|
|
59449
59448
|
const hash = await blockMessage.hash;
|
|
59450
59449
|
|
|
59451
59450
|
|
|
59452
|
-
await
|
|
59453
|
-
this.#updateState(blockMessage);
|
|
59451
|
+
await peernet.put(hash, blockMessage.encoded, 'block');
|
|
59452
|
+
await this.#updateState(blockMessage);
|
|
59454
59453
|
debug(`created block: ${hash}`);
|
|
59455
59454
|
|
|
59456
59455
|
peernet.publish('add-block', blockMessage.encoded);
|
package/demo/node.browser.js
CHANGED
|
@@ -8341,8 +8341,7 @@ module.exports = function (value) {
|
|
|
8341
8341
|
/******/ script.parentNode && script.parentNode.removeChild(script);
|
|
8342
8342
|
/******/ doneFns && doneFns.forEach(function(fn) { return fn(event); });
|
|
8343
8343
|
/******/ if(prev) return prev(event);
|
|
8344
|
-
/******/ }
|
|
8345
|
-
/******/ ;
|
|
8344
|
+
/******/ };
|
|
8346
8345
|
/******/ var timeout = setTimeout(onScriptComplete.bind(null, undefined, { type: 'timeout', target: script }), 120000);
|
|
8347
8346
|
/******/ script.onerror = onScriptComplete.bind(null, script.onerror);
|
|
8348
8347
|
/******/ script.onload = onScriptComplete.bind(null, script.onload);
|
|
@@ -9159,7 +9158,7 @@ class Peernet {
|
|
|
9159
9158
|
this.peerId = this.id;
|
|
9160
9159
|
|
|
9161
9160
|
pubsub.subscribe('peer:connected', async (peer) => {
|
|
9162
|
-
console.log(peer);
|
|
9161
|
+
// console.log(peer);
|
|
9163
9162
|
// console.log({connected: peer.id, as: this._getPeerId(peer.id) });
|
|
9164
9163
|
// peer.on('peernet.data', async (message) => {
|
|
9165
9164
|
// const id = message.id
|
|
@@ -9269,7 +9268,6 @@ class Peernet {
|
|
|
9269
9268
|
const walk = async peer => {
|
|
9270
9269
|
const node = await this.prepareMessage(data);
|
|
9271
9270
|
let result = await peer.request(node.encoded);
|
|
9272
|
-
console.log({result});
|
|
9273
9271
|
result = new Uint8Array(Object.values(result));
|
|
9274
9272
|
const proto = await protoFor(result);
|
|
9275
9273
|
if (proto.name !== 'peernet-dht-response') throw dhtError(proto.name)
|
|
@@ -9616,14 +9614,6 @@ class Peernet {
|
|
|
9616
9614
|
get Buffer() {
|
|
9617
9615
|
return Buffer
|
|
9618
9616
|
}
|
|
9619
|
-
// async block(index) {
|
|
9620
|
-
// const _values = []
|
|
9621
|
-
// for (const peer of this.peers) {
|
|
9622
|
-
// const value = await peer.request({type: 'block', index})
|
|
9623
|
-
// console.log(value);
|
|
9624
|
-
// }
|
|
9625
|
-
//
|
|
9626
|
-
// }
|
|
9627
9617
|
}
|
|
9628
9618
|
globalThis.Peernet = Peernet;
|
|
9629
9619
|
|