@leofcoin/chain 1.5.62 → 1.5.64
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/{_polyfill-node.child_process-JsWeMPst.js → _polyfill-node.child_process-rc1HO9Xs.js} +46 -47
- package/exports/browser/{_polyfill-node.url-0PWARF9f.js → _polyfill-node.url-1q06MepH.js} +1 -1
- package/exports/browser/{browser-dc41c03f-8RoAu8QY.js → browser-1GyRaZxg-C9SpI6hG.js} +2 -2
- package/exports/browser/chain.js +98 -62
- package/exports/browser/{client-f193279c-xoTAp1Bg.js → client-UOCjJBGl-pbv-pTHd.js} +18 -14
- package/exports/browser/{index-fd97ecae-DMIypRPM.js → index-K4Kwju30-vS3fNpxy.js} +2 -2
- package/exports/browser/{index-81687e93-rKzKdyEa.js → index-ub31QSed-EMPr2oeb.js} +2 -2
- package/exports/browser/{messages-cccb78db-bQaa1gST.js → messages-guyZfse6-JeAlT5Nb.js} +2 -2
- package/exports/browser/{node-browser-cqEqYlW7.js → node-browser-0Ly80awM.js} +625 -609
- package/exports/browser/node-browser.js +2 -2
- package/exports/browser/workers/block-worker.js +1 -4
- package/exports/browser/workers/machine-worker.js +61 -34
- package/exports/browser/workers/{worker-Suy0gj0S.js → worker-hbo9s9AT.js} +47 -59
- package/exports/chain.d.ts +1 -0
- package/exports/chain.js +63 -52
- package/exports/workers/block-worker.js +1 -4
- package/exports/workers/machine-worker.js +61 -34
- package/exports/workers/{worker-Suy0gj0S.js → worker-hbo9s9AT.js} +47 -59
- package/package.json +4 -3
- /package/exports/browser/{browser-2c73e2ef-AyxSBUXj.js → browser-AyxSBUXj-AyxSBUXj.js} +0 -0
- /package/exports/browser/{qr-scanner-worker.min-c002e984-RaSiJc_R.js → qr-scanner-worker.min-RaSiJc_R-RaSiJc_R.js} +0 -0
|
@@ -14499,56 +14499,55 @@ class ValidatorMessage extends FormatInterface {
|
|
|
14499
14499
|
}
|
|
14500
14500
|
|
|
14501
14501
|
var proto$4 = {
|
|
14502
|
-
|
|
14503
|
-
|
|
14504
|
-
|
|
14505
|
-
|
|
14506
|
-
|
|
14507
|
-
|
|
14508
|
-
|
|
14502
|
+
index: Number(),
|
|
14503
|
+
previousHash: String(),
|
|
14504
|
+
timestamp: Number(),
|
|
14505
|
+
reward: BigNumber.from(0),
|
|
14506
|
+
fees: BigNumber.from(0),
|
|
14507
|
+
transactions: new Uint8Array(),
|
|
14508
|
+
validators: new Uint8Array()
|
|
14509
14509
|
};
|
|
14510
14510
|
|
|
14511
14511
|
class BlockMessage extends FormatInterface {
|
|
14512
|
-
|
|
14513
|
-
|
|
14514
|
-
|
|
14515
|
-
|
|
14516
|
-
|
|
14517
|
-
|
|
14518
|
-
|
|
14519
|
-
|
|
14520
|
-
|
|
14521
|
-
|
|
14522
|
-
|
|
14523
|
-
|
|
14524
|
-
|
|
14525
|
-
|
|
14526
|
-
|
|
14527
|
-
|
|
14528
|
-
|
|
14529
|
-
|
|
14530
|
-
|
|
14531
|
-
|
|
14532
|
-
|
|
14533
|
-
|
|
14534
|
-
|
|
14535
|
-
|
|
14536
|
-
|
|
14537
|
-
|
|
14538
|
-
|
|
14539
|
-
|
|
14540
|
-
|
|
14541
|
-
|
|
14542
|
-
|
|
14543
|
-
|
|
14544
|
-
|
|
14545
|
-
|
|
14546
|
-
|
|
14547
|
-
|
|
14548
|
-
|
|
14549
|
-
|
|
14550
|
-
|
|
14551
|
-
}
|
|
14512
|
+
get messageName() {
|
|
14513
|
+
return 'BlockMessage'
|
|
14514
|
+
}
|
|
14515
|
+
constructor(buffer) {
|
|
14516
|
+
if (buffer instanceof BlockMessage) return buffer
|
|
14517
|
+
const name = 'block-message';
|
|
14518
|
+
super(buffer, proto$4, { name });
|
|
14519
|
+
}
|
|
14520
|
+
encode(decoded) {
|
|
14521
|
+
decoded = decoded || this.decoded;
|
|
14522
|
+
const validators = [];
|
|
14523
|
+
const transactions = [];
|
|
14524
|
+
for (const validator of decoded.validators) {
|
|
14525
|
+
if (validator instanceof ValidatorMessage) validators.push(validator.encode());
|
|
14526
|
+
else validators.push(new ValidatorMessage(validator).encode());
|
|
14527
|
+
}
|
|
14528
|
+
for (const transaction of decoded.transactions) {
|
|
14529
|
+
if (transaction instanceof TransactionMessage) transactions.push(transaction.encode());
|
|
14530
|
+
else transactions.push(new TransactionMessage(transaction).encode());
|
|
14531
|
+
}
|
|
14532
|
+
return super.encode({
|
|
14533
|
+
...decoded,
|
|
14534
|
+
validators: index$5(validators),
|
|
14535
|
+
transactions: index$5(transactions)
|
|
14536
|
+
})
|
|
14537
|
+
}
|
|
14538
|
+
decode(encoded) {
|
|
14539
|
+
encoded = encoded || this.encoded;
|
|
14540
|
+
super.decode(encoded);
|
|
14541
|
+
// @ts-ignore
|
|
14542
|
+
this.decoded.transactions = index$4(this.decoded.transactions).map(
|
|
14543
|
+
(transaction) => new TransactionMessage(transaction).decoded
|
|
14544
|
+
);
|
|
14545
|
+
// @ts-ignore
|
|
14546
|
+
this.decoded.validators = index$4(this.decoded.validators).map(
|
|
14547
|
+
(validator) => new ValidatorMessage(validator).decoded
|
|
14548
|
+
);
|
|
14549
|
+
return this.decoded
|
|
14550
|
+
}
|
|
14552
14551
|
}
|
|
14553
14552
|
|
|
14554
14553
|
var proto$3 = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { g as getDefaultExportFromCjs } from './node-browser-
|
|
2
|
-
import './_polyfill-node.child_process-
|
|
1
|
+
import { g as getDefaultExportFromCjs } from './node-browser-0Ly80awM.js';
|
|
2
|
+
import './_polyfill-node.child_process-rc1HO9Xs.js';
|
|
3
3
|
|
|
4
4
|
var global;
|
|
5
5
|
var hasRequiredGlobal;
|
package/exports/browser/chain.js
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
|
-
import { c as BigNumber, L as Logger, v as version$1, h as hexZeroPad, i as isBigNumberish, d as arrayify, e as isBytes, T as TransactionMessage, t as toBase58, C as ContractMessage, R as RawTransactionMessage, f as getDefaultExportFromCjs, B as BlockMessage, a as BWMessage, b as BWRequestMessage } from './_polyfill-node.child_process-
|
|
1
|
+
import { c as BigNumber, L as Logger, v as version$1, h as hexZeroPad, i as isBigNumberish, d as arrayify, e as isBytes, T as TransactionMessage, t as toBase58, C as ContractMessage, R as RawTransactionMessage, f as getDefaultExportFromCjs, B as BlockMessage, a as BWMessage, b as BWRequestMessage } from './_polyfill-node.child_process-rc1HO9Xs.js';
|
|
2
|
+
|
|
3
|
+
if (!globalThis.DEBUG) {
|
|
4
|
+
let DEBUG = [];
|
|
5
|
+
if (globalThis.localStorage) {
|
|
6
|
+
DEBUG = globalThis.localStorage.getItem('DEBUG');
|
|
7
|
+
globalThis.DEBUG = DEBUG ? DEBUG.split(',') : [DEBUG];
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const debug$5 = (target, text) => {
|
|
12
|
+
if (!globalThis.DEBUG && globalThis.DEBUG.length === 0) return;
|
|
13
|
+
if (
|
|
14
|
+
globalThis.DEBUG === 'true' ||
|
|
15
|
+
globalThis.DEBUG === true ||
|
|
16
|
+
globalThis.DEBUG?.indexOf(target) !== -1 ||
|
|
17
|
+
globalThis.DEBUG?.indexOf('*') !== -1
|
|
18
|
+
)
|
|
19
|
+
if (text) console.log('\x1b[34m\x1b[1m%s', `${target}: ${text}`, '\x1b[0m');
|
|
20
|
+
else console.log('\x1b[34m\x1b[1m%s', `${target}`, '\x1b[0m');
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
if (!globalThis.debug) {
|
|
24
|
+
globalThis.debug = debug$5;
|
|
25
|
+
|
|
26
|
+
globalThis.createDebugger = (target) => (text) => debug$5(target, text);
|
|
27
|
+
}
|
|
2
28
|
|
|
3
29
|
const logger$1 = new Logger(version$1);
|
|
4
30
|
const _constructorGuard = {};
|
|
@@ -506,7 +532,7 @@ var constants$1 = {
|
|
|
506
532
|
FLAG_LOOSE: 0b010,
|
|
507
533
|
};
|
|
508
534
|
|
|
509
|
-
const debug$
|
|
535
|
+
const debug$4 = (
|
|
510
536
|
typeof process === 'object' &&
|
|
511
537
|
process.env &&
|
|
512
538
|
process.env.NODE_DEBUG &&
|
|
@@ -514,7 +540,7 @@ const debug$1 = (
|
|
|
514
540
|
) ? (...args) => console.error('SEMVER', ...args)
|
|
515
541
|
: () => {};
|
|
516
542
|
|
|
517
|
-
var debug_1 = debug$
|
|
543
|
+
var debug_1 = debug$4;
|
|
518
544
|
|
|
519
545
|
(function (module, exports) {
|
|
520
546
|
const {
|
|
@@ -773,7 +799,7 @@ var identifiers$1 = {
|
|
|
773
799
|
rcompareIdentifiers,
|
|
774
800
|
};
|
|
775
801
|
|
|
776
|
-
const debug = debug_1;
|
|
802
|
+
const debug$3 = debug_1;
|
|
777
803
|
const { MAX_LENGTH, MAX_SAFE_INTEGER } = constants$1;
|
|
778
804
|
const { safeRe: re$1, t: t$1 } = reExports;
|
|
779
805
|
|
|
@@ -800,7 +826,7 @@ let SemVer$d = class SemVer {
|
|
|
800
826
|
)
|
|
801
827
|
}
|
|
802
828
|
|
|
803
|
-
debug('SemVer', version, options);
|
|
829
|
+
debug$3('SemVer', version, options);
|
|
804
830
|
this.options = options;
|
|
805
831
|
this.loose = !!options.loose;
|
|
806
832
|
// this isn't actually relevant for versions, but keep it so that we
|
|
@@ -864,7 +890,7 @@ let SemVer$d = class SemVer {
|
|
|
864
890
|
}
|
|
865
891
|
|
|
866
892
|
compare (other) {
|
|
867
|
-
debug('SemVer.compare', this.version, this.options, other);
|
|
893
|
+
debug$3('SemVer.compare', this.version, this.options, other);
|
|
868
894
|
if (!(other instanceof SemVer)) {
|
|
869
895
|
if (typeof other === 'string' && other === this.version) {
|
|
870
896
|
return 0
|
|
@@ -909,7 +935,7 @@ let SemVer$d = class SemVer {
|
|
|
909
935
|
do {
|
|
910
936
|
const a = this.prerelease[i];
|
|
911
937
|
const b = other.prerelease[i];
|
|
912
|
-
debug('prerelease compare', i, a, b);
|
|
938
|
+
debug$3('prerelease compare', i, a, b);
|
|
913
939
|
if (a === undefined && b === undefined) {
|
|
914
940
|
return 0
|
|
915
941
|
} else if (b === undefined) {
|
|
@@ -933,7 +959,7 @@ let SemVer$d = class SemVer {
|
|
|
933
959
|
do {
|
|
934
960
|
const a = this.build[i];
|
|
935
961
|
const b = other.build[i];
|
|
936
|
-
debug('prerelease compare', i, a, b);
|
|
962
|
+
debug$3('prerelease compare', i, a, b);
|
|
937
963
|
if (a === undefined && b === undefined) {
|
|
938
964
|
return 0
|
|
939
965
|
} else if (b === undefined) {
|
|
@@ -3778,7 +3804,7 @@ class EasyWorker {
|
|
|
3778
3804
|
this.worker = new Worker(url, {...options});
|
|
3779
3805
|
} else {
|
|
3780
3806
|
return new Promise(async (resolve, reject) => {
|
|
3781
|
-
const {fork} = await import('./_polyfill-node.child_process-
|
|
3807
|
+
const {fork} = await import('./_polyfill-node.child_process-rc1HO9Xs.js').then(function (n) { return n._; });
|
|
3782
3808
|
this.worker = fork(url, ['easy-worker-child'], options);
|
|
3783
3809
|
resolve(this);
|
|
3784
3810
|
})
|
|
@@ -3859,6 +3885,7 @@ const isResolveError = (error) => error.name === 'ResolveError';
|
|
|
3859
3885
|
const isExecutionError = (error) => error.name === 'ExecutionError';
|
|
3860
3886
|
|
|
3861
3887
|
// import State from './state'
|
|
3888
|
+
const debug$2 = globalThis.createDebugger('leofcoin/machine');
|
|
3862
3889
|
class Machine {
|
|
3863
3890
|
#contracts = {};
|
|
3864
3891
|
#nonces = {};
|
|
@@ -3898,7 +3925,7 @@ class Machine {
|
|
|
3898
3925
|
break;
|
|
3899
3926
|
}
|
|
3900
3927
|
case 'debug': {
|
|
3901
|
-
|
|
3928
|
+
debug$2(data.message);
|
|
3902
3929
|
break;
|
|
3903
3930
|
}
|
|
3904
3931
|
case 'error': {
|
|
@@ -3924,7 +3951,7 @@ class Machine {
|
|
|
3924
3951
|
pubsub.subscribe('machine.ready', machineReady);
|
|
3925
3952
|
let pre;
|
|
3926
3953
|
try {
|
|
3927
|
-
const importee = await import('./_polyfill-node.url-
|
|
3954
|
+
const importee = await import('./_polyfill-node.url-1q06MepH.js');
|
|
3928
3955
|
const url = importee.default;
|
|
3929
3956
|
if (url)
|
|
3930
3957
|
pre = url.fileURLToPath(new URL('.', import.meta.url));
|
|
@@ -4173,6 +4200,7 @@ class Jobber {
|
|
|
4173
4200
|
}
|
|
4174
4201
|
}
|
|
4175
4202
|
|
|
4203
|
+
const debug$1 = globalThis.createDebugger('leofcoin/state');
|
|
4176
4204
|
class State extends Contract {
|
|
4177
4205
|
#resolveErrored;
|
|
4178
4206
|
#lastResolvedTime;
|
|
@@ -4269,7 +4297,7 @@ class State extends Contract {
|
|
|
4269
4297
|
this.#getLastTransactions = async () => {
|
|
4270
4298
|
let lastTransactions = (await Promise.all((await this.blocks)
|
|
4271
4299
|
.filter((block) => block.loaded)
|
|
4272
|
-
.slice(-
|
|
4300
|
+
.slice(-24)
|
|
4273
4301
|
.map((block) => this.#loadBlockTransactions(block.transactions)))).reduce((all, transactions) => [...all, ...transactions], []);
|
|
4274
4302
|
return Promise.all(lastTransactions.map((transaction) => transaction.hash()));
|
|
4275
4303
|
};
|
|
@@ -4327,10 +4355,15 @@ class State extends Contract {
|
|
|
4327
4355
|
}
|
|
4328
4356
|
}
|
|
4329
4357
|
async updateState(message) {
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4358
|
+
try {
|
|
4359
|
+
const hash = await message.hash();
|
|
4360
|
+
// await this.state.updateState(message)
|
|
4361
|
+
await globalThis.chainStore.put('lastBlock', hash);
|
|
4362
|
+
globalThis.pubsub.publish('lastBlock', message.encoded);
|
|
4363
|
+
}
|
|
4364
|
+
catch (error) {
|
|
4365
|
+
console.error(error);
|
|
4366
|
+
}
|
|
4334
4367
|
}
|
|
4335
4368
|
getLatestBlock() {
|
|
4336
4369
|
// @ts-ignore
|
|
@@ -4366,7 +4399,7 @@ class State extends Contract {
|
|
|
4366
4399
|
this.#totalSize += size;
|
|
4367
4400
|
this.#blocks[index - 1] = { hash, ...block.decoded };
|
|
4368
4401
|
this.#blockHashMap.set(hash, index);
|
|
4369
|
-
|
|
4402
|
+
debug$1(`resolved block: ${hash} @${index} ${formatBytes(size)}`);
|
|
4370
4403
|
globalThis.pubsub.publish('block-resolved', { hash, index });
|
|
4371
4404
|
this.#lastResolved = this.#blocks[index - 1];
|
|
4372
4405
|
this.#lastResolvedTime = Date.now();
|
|
@@ -4504,7 +4537,7 @@ class State extends Contract {
|
|
|
4504
4537
|
await this.resolveBlock(lastBlock.hash);
|
|
4505
4538
|
console.log('ok');
|
|
4506
4539
|
let blocksSynced = localIndex > 0 ? (localIndex > index ? localIndex - index : index + -localIndex) : index;
|
|
4507
|
-
|
|
4540
|
+
debug$1(`synced ${blocksSynced} ${blocksSynced > 1 ? 'blocks' : 'block'}`);
|
|
4508
4541
|
const blocks = this.#blocks;
|
|
4509
4542
|
const start = blocks.length - blocksSynced;
|
|
4510
4543
|
if (this.#machine) {
|
|
@@ -4636,7 +4669,7 @@ class State extends Contract {
|
|
|
4636
4669
|
this.#blocks[block.index - 1].loaded = true;
|
|
4637
4670
|
await this.#machine.addLoadedBlock(block);
|
|
4638
4671
|
// @ts-ignore
|
|
4639
|
-
|
|
4672
|
+
debug$1(`loaded block: ${block.hash} @${block.index}`);
|
|
4640
4673
|
globalThis.pubsub.publish('block-loaded', { ...block });
|
|
4641
4674
|
}
|
|
4642
4675
|
}
|
|
@@ -4647,7 +4680,7 @@ class State extends Contract {
|
|
|
4647
4680
|
return new Promise(async (resolve, reject) => {
|
|
4648
4681
|
const timeout = setTimeout(() => {
|
|
4649
4682
|
resolve([{ index: 0, hash: '0x0' }]);
|
|
4650
|
-
|
|
4683
|
+
debug$1('sync timed out');
|
|
4651
4684
|
}, this.requestTimeout);
|
|
4652
4685
|
promises = await Promise.allSettled(promises);
|
|
4653
4686
|
promises = promises.filter(({ status }) => status === 'fulfilled');
|
|
@@ -4731,7 +4764,7 @@ class VersionControl extends State {
|
|
|
4731
4764
|
}
|
|
4732
4765
|
|
|
4733
4766
|
globalThis.BigNumber = BigNumber;
|
|
4734
|
-
const
|
|
4767
|
+
const debug = globalThis.createDebugger('leofcoin/chain');
|
|
4735
4768
|
// check if browser or local
|
|
4736
4769
|
class Chain extends VersionControl {
|
|
4737
4770
|
#state;
|
|
@@ -4758,7 +4791,7 @@ class Chain extends VersionControl {
|
|
|
4758
4791
|
const transaction = new TransactionMessage(message);
|
|
4759
4792
|
await transaction.hash();
|
|
4760
4793
|
// if (await transactionPoolStore.has(hash)) await transactionPoolStore.delete(hash)
|
|
4761
|
-
|
|
4794
|
+
debug(`added ${transaction}`);
|
|
4762
4795
|
};
|
|
4763
4796
|
// @ts-ignore
|
|
4764
4797
|
return this.#init();
|
|
@@ -4881,7 +4914,6 @@ class Chain extends VersionControl {
|
|
|
4881
4914
|
const transactionsToGet = [];
|
|
4882
4915
|
for (const key of transactionsInPool) {
|
|
4883
4916
|
!transactions.includes(key) &&
|
|
4884
|
-
!ignorelist.includes(key) &&
|
|
4885
4917
|
transactionsToGet.push(transactionPoolStore.put(key, await peernet.get(key, 'transaction')));
|
|
4886
4918
|
}
|
|
4887
4919
|
return Promise.all(transactionsToGet);
|
|
@@ -4890,7 +4922,10 @@ class Chain extends VersionControl {
|
|
|
4890
4922
|
const peer = peernet.getConnection(peerId);
|
|
4891
4923
|
// todo handle version changes
|
|
4892
4924
|
// for now just do nothing if version doesn't match
|
|
4893
|
-
|
|
4925
|
+
debug(`peer connected with version ${peer.version}`);
|
|
4926
|
+
if (peer.version !== this.version) {
|
|
4927
|
+
debug(`versions don't match`);
|
|
4928
|
+
}
|
|
4894
4929
|
if (!peer.version || peer.version !== this.version)
|
|
4895
4930
|
return;
|
|
4896
4931
|
const lastBlock = await this.#makeRequest(peer, 'lastBlock');
|
|
@@ -4933,7 +4968,6 @@ class Chain extends VersionControl {
|
|
|
4933
4968
|
}
|
|
4934
4969
|
}
|
|
4935
4970
|
async #addBlock(block) {
|
|
4936
|
-
console.log({ block });
|
|
4937
4971
|
const blockMessage = await new BlockMessage(block);
|
|
4938
4972
|
const hash = await blockMessage.hash();
|
|
4939
4973
|
await Promise.all(blockMessage.decoded.transactions
|
|
@@ -4950,7 +4984,7 @@ class Chain extends VersionControl {
|
|
|
4950
4984
|
await globalThis.blockStore.put(hash, blockMessage.encoded);
|
|
4951
4985
|
if ((await this.lastBlock).index < Number(blockMessage.decoded.index))
|
|
4952
4986
|
await this.updateState(blockMessage);
|
|
4953
|
-
|
|
4987
|
+
debug(`added block: ${hash}`);
|
|
4954
4988
|
let promises = [];
|
|
4955
4989
|
let contracts = [];
|
|
4956
4990
|
for (let transaction of blockMessage.decoded.transactions) {
|
|
@@ -5008,16 +5042,41 @@ class Chain extends VersionControl {
|
|
|
5008
5042
|
if ((await this.hasTransactionToHandle()) && !this.#runningEpoch && this.#participating)
|
|
5009
5043
|
await this.#runEpoch();
|
|
5010
5044
|
}
|
|
5045
|
+
async #handleTransaction(transaction, latestTransactions, block) {
|
|
5046
|
+
const hash = await transaction.hash();
|
|
5047
|
+
const doubleTransactions = [];
|
|
5048
|
+
if (latestTransactions.includes(hash)) {
|
|
5049
|
+
doubleTransactions.push(hash);
|
|
5050
|
+
}
|
|
5051
|
+
if (doubleTransactions.length > 0) {
|
|
5052
|
+
await globalThis.transactionPoolStore.delete(hash);
|
|
5053
|
+
await globalThis.peernet.publish('invalid-transaction', hash);
|
|
5054
|
+
return;
|
|
5055
|
+
}
|
|
5056
|
+
// if (timestamp + this.#slotTime > Date.now()) {
|
|
5057
|
+
try {
|
|
5058
|
+
const result = await this.#executeTransaction({ ...transaction.decoded, hash });
|
|
5059
|
+
block.transactions.push(transaction);
|
|
5060
|
+
block.fees = block.fees.add(await calculateFee(transaction.decoded));
|
|
5061
|
+
await globalThis.accountsStore.put(transaction.decoded.from, new TextEncoder().encode(String(transaction.decoded.nonce)));
|
|
5062
|
+
}
|
|
5063
|
+
catch (e) {
|
|
5064
|
+
console.log('vvvvvv');
|
|
5065
|
+
console.log({ e });
|
|
5066
|
+
console.log(hash);
|
|
5067
|
+
peernet.publish('invalid-transaction', hash);
|
|
5068
|
+
console.log(await globalThis.transactionPoolStore.keys());
|
|
5069
|
+
console.log(await globalThis.transactionPoolStore.has(e.hash));
|
|
5070
|
+
await globalThis.transactionPoolStore.delete(e.hash);
|
|
5071
|
+
console.log(await globalThis.transactionPoolStore.has(e.hash));
|
|
5072
|
+
}
|
|
5073
|
+
}
|
|
5011
5074
|
// todo filter tx that need to wait on prev nonce
|
|
5012
5075
|
async #createBlock(limit = this.transactionLimit) {
|
|
5013
5076
|
// vote for transactions
|
|
5014
5077
|
if ((await globalThis.transactionPoolStore.size()) === 0)
|
|
5015
5078
|
return;
|
|
5016
5079
|
let transactions = await globalThis.transactionPoolStore.values(this.transactionLimit);
|
|
5017
|
-
for (const hash of await globalThis.transactionPoolStore.keys()) {
|
|
5018
|
-
if (ignorelist.includes(hash))
|
|
5019
|
-
await globalThis.transactionPoolStore.delete(hash);
|
|
5020
|
-
}
|
|
5021
5080
|
if (Object.keys(transactions)?.length === 0)
|
|
5022
5081
|
return;
|
|
5023
5082
|
const timestamp = Date.now();
|
|
@@ -5030,39 +5089,16 @@ class Chain extends VersionControl {
|
|
|
5030
5089
|
reward: parseUnits('150'),
|
|
5031
5090
|
index: 0
|
|
5032
5091
|
};
|
|
5092
|
+
const latestTransactions = await this.machine.latestTransactions();
|
|
5033
5093
|
// exclude failing tx
|
|
5034
5094
|
transactions = await this.promiseTransactions(transactions);
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
}
|
|
5043
|
-
if (doubleTransactions.length > 0) {
|
|
5044
|
-
await globalThis.transactionPoolStore.delete(hash);
|
|
5045
|
-
await globalThis.peernet.publish('invalid-transaction', hash);
|
|
5046
|
-
return;
|
|
5047
|
-
}
|
|
5048
|
-
// if (timestamp + this.#slotTime > Date.now()) {
|
|
5049
|
-
try {
|
|
5050
|
-
const result = await this.#executeTransaction({ ...transaction.decoded, hash });
|
|
5051
|
-
block.transactions.push(transaction);
|
|
5052
|
-
block.fees = block.fees.add(await calculateFee(transaction.decoded));
|
|
5053
|
-
await globalThis.accountsStore.put(transaction.decoded.from, new TextEncoder().encode(String(transaction.decoded.nonce)));
|
|
5054
|
-
}
|
|
5055
|
-
catch (e) {
|
|
5056
|
-
console.log('vvvvvv');
|
|
5057
|
-
console.log({ e });
|
|
5058
|
-
console.log(hash);
|
|
5059
|
-
peernet.publish('invalid-transaction', hash);
|
|
5060
|
-
console.log(await globalThis.transactionPoolStore.keys());
|
|
5061
|
-
console.log(await globalThis.transactionPoolStore.has(e.hash));
|
|
5062
|
-
await globalThis.transactionPoolStore.delete(e.hash);
|
|
5063
|
-
console.log(await globalThis.transactionPoolStore.has(e.hash));
|
|
5064
|
-
}
|
|
5065
|
-
}
|
|
5095
|
+
const priority = transactions.filter((transaction) => transaction.priority);
|
|
5096
|
+
await Promise.all(priority
|
|
5097
|
+
.sort((a, b) => a.nonce - b.nonce)
|
|
5098
|
+
.map((transaction) => this.#handleTransaction(transaction, latestTransactions, block)));
|
|
5099
|
+
await Promise.all(transactions
|
|
5100
|
+
.filter((transaction) => !transaction.priority)
|
|
5101
|
+
.map((transaction) => this.#handleTransaction(transaction, latestTransactions, block)));
|
|
5066
5102
|
// don't add empty block
|
|
5067
5103
|
if (block.transactions.length === 0)
|
|
5068
5104
|
return;
|
|
@@ -5129,7 +5165,7 @@ class Chain extends VersionControl {
|
|
|
5129
5165
|
await globalThis.peernet.put(hash, blockMessage.encoded, 'block');
|
|
5130
5166
|
await this.updateState(blockMessage);
|
|
5131
5167
|
await this.machine.addLoadedBlock({ ...blockMessage.decoded, loaded: true, hash: await blockMessage.hash() });
|
|
5132
|
-
|
|
5168
|
+
debug(`created block: ${hash} @${block.index}`);
|
|
5133
5169
|
globalThis.peernet.publish('add-block', blockMessage.encoded);
|
|
5134
5170
|
globalThis.pubsub.publish('add-block', blockMessage.decoded);
|
|
5135
5171
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as LittlePubSub } from './node-browser-
|
|
2
|
-
import './_polyfill-node.child_process-
|
|
1
|
+
import { L as LittlePubSub } from './node-browser-0Ly80awM.js';
|
|
2
|
+
import './_polyfill-node.child_process-rc1HO9Xs.js';
|
|
3
3
|
|
|
4
4
|
class Api {
|
|
5
5
|
_pubsub;
|
|
@@ -206,7 +206,7 @@ class SocketRequestClient {
|
|
|
206
206
|
const init = async () => {
|
|
207
207
|
// @ts-ignore
|
|
208
208
|
if (!globalThis.WebSocket)
|
|
209
|
-
globalThis.WebSocket = (await import('./browser-
|
|
209
|
+
globalThis.WebSocket = (await import('./browser-1GyRaZxg-C9SpI6hG.js').then(function (n) { return n.b; })).default.w3cwebsocket;
|
|
210
210
|
const client = new WebSocket(this.#url, this.#protocol);
|
|
211
211
|
client.onmessage = this.onmessage;
|
|
212
212
|
client.onerror = this.onerror;
|
|
@@ -280,12 +280,15 @@ const iceServers = [
|
|
|
280
280
|
credential: 'openrelayproject'
|
|
281
281
|
}
|
|
282
282
|
];
|
|
283
|
-
const SimplePeer = (await import('./index-
|
|
283
|
+
const SimplePeer = (await import('./index-K4Kwju30-vS3fNpxy.js').then(function (n) { return n.i; })).default;
|
|
284
284
|
class Peer extends SimplePeer {
|
|
285
285
|
peerId;
|
|
286
286
|
channelName;
|
|
287
287
|
version;
|
|
288
288
|
bw = { up: 0, down: 0 };
|
|
289
|
+
get connected() {
|
|
290
|
+
return super.connected;
|
|
291
|
+
}
|
|
289
292
|
constructor(options) {
|
|
290
293
|
const { from, to, initiator, trickle, config, version } = options;
|
|
291
294
|
const channelName = initiator ? `${from}:${to}` : `${to}:${from}`;
|
|
@@ -356,6 +359,7 @@ class Peer extends SimplePeer {
|
|
|
356
359
|
}
|
|
357
360
|
}
|
|
358
361
|
|
|
362
|
+
const debug = globalThis.createDebugger('@peernet/swarm/client');
|
|
359
363
|
class Client {
|
|
360
364
|
#peerId;
|
|
361
365
|
#connections = {};
|
|
@@ -404,7 +408,7 @@ class Client {
|
|
|
404
408
|
async _init() {
|
|
405
409
|
// reconnectJob()
|
|
406
410
|
if (!globalThis.RTCPeerConnection)
|
|
407
|
-
globalThis.wrtc = (await import('./browser-
|
|
411
|
+
globalThis.wrtc = (await import('./browser-AyxSBUXj-AyxSBUXj.js').then(function (n) { return n.b; })).default;
|
|
408
412
|
for (const star of this.starsConfig) {
|
|
409
413
|
try {
|
|
410
414
|
const client = new SocketRequestClient(star, this.networkVersion);
|
|
@@ -421,16 +425,16 @@ class Client {
|
|
|
421
425
|
throw new Error(`No star available to connect`);
|
|
422
426
|
}
|
|
423
427
|
}
|
|
424
|
-
if (globalThis.
|
|
425
|
-
globalThis.addEventListener('beforeunload', async () => this.close());
|
|
426
|
-
}
|
|
427
|
-
else {
|
|
428
|
+
if (globalThis.process?.versions?.node) {
|
|
428
429
|
process.on('SIGINT', async () => {
|
|
429
430
|
process.stdin.resume();
|
|
430
431
|
await this.close();
|
|
431
432
|
process.exit();
|
|
432
433
|
});
|
|
433
434
|
}
|
|
435
|
+
else {
|
|
436
|
+
globalThis.addEventListener('beforeunload', async () => this.close());
|
|
437
|
+
}
|
|
434
438
|
}
|
|
435
439
|
setupStarListeners(star) {
|
|
436
440
|
star.pubsub.subscribe('peer:joined', (id) => this.#peerJoined(id, star));
|
|
@@ -470,7 +474,7 @@ class Client {
|
|
|
470
474
|
}
|
|
471
475
|
}
|
|
472
476
|
}
|
|
473
|
-
|
|
477
|
+
debug(`star ${id} left`);
|
|
474
478
|
};
|
|
475
479
|
#peerLeft = (peer, star) => {
|
|
476
480
|
const id = peer.peerId || peer;
|
|
@@ -478,7 +482,7 @@ class Client {
|
|
|
478
482
|
this.#connections[id].destroy();
|
|
479
483
|
delete this.#connections[id];
|
|
480
484
|
}
|
|
481
|
-
|
|
485
|
+
debug(`peer ${id} left`);
|
|
482
486
|
};
|
|
483
487
|
#createRTCPeerConnection = (peerId, star, version, initiator = false) => {
|
|
484
488
|
const peer = new Peer({
|
|
@@ -502,7 +506,7 @@ class Client {
|
|
|
502
506
|
}
|
|
503
507
|
// RTCPeerConnection
|
|
504
508
|
this.#createRTCPeerConnection(peerId, star, version, true);
|
|
505
|
-
|
|
509
|
+
debug(`peer ${peerId} joined`);
|
|
506
510
|
};
|
|
507
511
|
#inComingSignal = async ({ from, signal, channelName, version }, star) => {
|
|
508
512
|
if (version !== this.version) {
|
|
@@ -538,10 +542,10 @@ class Client {
|
|
|
538
542
|
peer.destroy();
|
|
539
543
|
delete this.#connections[peer.peerId];
|
|
540
544
|
}
|
|
541
|
-
|
|
545
|
+
debug(`closed ${peer.peerId}'s connection`);
|
|
542
546
|
};
|
|
543
547
|
#peerConnect = (peer) => {
|
|
544
|
-
|
|
548
|
+
debug(`${peer.peerId} connected`);
|
|
545
549
|
globalThis.pubsub.publishVerbose(this.#connectEvent, peer.peerId);
|
|
546
550
|
};
|
|
547
551
|
#noticeMessage = (message, id, from, peer) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as inherits_browserExports, c as commonjsGlobal, g as getDefaultExportFromCjs, r as require$$3 } from './node-browser-
|
|
2
|
-
import './_polyfill-node.child_process-
|
|
1
|
+
import { i as inherits_browserExports, c as commonjsGlobal, g as getDefaultExportFromCjs, r as require$$3 } from './node-browser-0Ly80awM.js';
|
|
2
|
+
import './_polyfill-node.child_process-rc1HO9Xs.js';
|
|
3
3
|
|
|
4
4
|
var browser$2 = {exports: {}};
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-
|
|
2
|
-
import './_polyfill-node.child_process-
|
|
1
|
+
import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-0Ly80awM.js';
|
|
2
|
+
import './_polyfill-node.child_process-rc1HO9Xs.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @params {String} network
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { F as FormatInterface } from './node-browser-
|
|
2
|
-
import './_polyfill-node.child_process-
|
|
1
|
+
import { F as FormatInterface } from './node-browser-0Ly80awM.js';
|
|
2
|
+
import './_polyfill-node.child_process-rc1HO9Xs.js';
|
|
3
3
|
|
|
4
4
|
var proto$b = {
|
|
5
5
|
data: new Uint8Array(),
|