@leofcoin/chain 1.7.118 → 1.7.120
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 +36 -34
- package/exports/chain.js +26 -24
- package/exports/contract.d.ts +0 -1
- package/package.json +1 -1
package/exports/browser/chain.js
CHANGED
|
@@ -1129,7 +1129,7 @@ var hasRequiredRe;
|
|
|
1129
1129
|
function requireRe () {
|
|
1130
1130
|
if (hasRequiredRe) return re.exports;
|
|
1131
1131
|
hasRequiredRe = 1;
|
|
1132
|
-
(function (module, exports) {
|
|
1132
|
+
(function (module, exports$1) {
|
|
1133
1133
|
|
|
1134
1134
|
const {
|
|
1135
1135
|
MAX_SAFE_COMPONENT_LENGTH,
|
|
@@ -1137,14 +1137,14 @@ function requireRe () {
|
|
|
1137
1137
|
MAX_LENGTH,
|
|
1138
1138
|
} = requireConstants();
|
|
1139
1139
|
const debug = requireDebug();
|
|
1140
|
-
exports = module.exports = {};
|
|
1140
|
+
exports$1 = module.exports = {};
|
|
1141
1141
|
|
|
1142
1142
|
// The actual regexps go on exports.re
|
|
1143
|
-
const re = exports.re = [];
|
|
1144
|
-
const safeRe = exports.safeRe = [];
|
|
1145
|
-
const src = exports.src = [];
|
|
1146
|
-
const safeSrc = exports.safeSrc = [];
|
|
1147
|
-
const t = exports.t = {};
|
|
1143
|
+
const re = exports$1.re = [];
|
|
1144
|
+
const safeRe = exports$1.safeRe = [];
|
|
1145
|
+
const src = exports$1.src = [];
|
|
1146
|
+
const safeSrc = exports$1.safeSrc = [];
|
|
1147
|
+
const t = exports$1.t = {};
|
|
1148
1148
|
let R = 0;
|
|
1149
1149
|
|
|
1150
1150
|
const LETTERDASHNUMBER = '[a-zA-Z0-9-]';
|
|
@@ -1308,7 +1308,7 @@ function requireRe () {
|
|
|
1308
1308
|
createToken('LONETILDE', '(?:~>?)');
|
|
1309
1309
|
|
|
1310
1310
|
createToken('TILDETRIM', `(\\s*)${src[t.LONETILDE]}\\s+`, true);
|
|
1311
|
-
exports.tildeTrimReplace = '$1~';
|
|
1311
|
+
exports$1.tildeTrimReplace = '$1~';
|
|
1312
1312
|
|
|
1313
1313
|
createToken('TILDE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
|
|
1314
1314
|
createToken('TILDELOOSE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
|
|
@@ -1318,7 +1318,7 @@ function requireRe () {
|
|
|
1318
1318
|
createToken('LONECARET', '(?:\\^)');
|
|
1319
1319
|
|
|
1320
1320
|
createToken('CARETTRIM', `(\\s*)${src[t.LONECARET]}\\s+`, true);
|
|
1321
|
-
exports.caretTrimReplace = '$1^';
|
|
1321
|
+
exports$1.caretTrimReplace = '$1^';
|
|
1322
1322
|
|
|
1323
1323
|
createToken('CARET', `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
|
|
1324
1324
|
createToken('CARETLOOSE', `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
|
|
@@ -1331,7 +1331,7 @@ function requireRe () {
|
|
|
1331
1331
|
// it modifies, so that `> 1.2.3` ==> `>1.2.3`
|
|
1332
1332
|
createToken('COMPARATORTRIM', `(\\s*)${src[t.GTLT]
|
|
1333
1333
|
}\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
|
|
1334
|
-
exports.comparatorTrimReplace = '$1$2$3';
|
|
1334
|
+
exports$1.comparatorTrimReplace = '$1$2$3';
|
|
1335
1335
|
|
|
1336
1336
|
// Something like `1.2.3 - 1.2.4`
|
|
1337
1337
|
// Note that these all use the loose form, because they'll be
|
|
@@ -3993,7 +3993,6 @@ class Contract extends Transaction {
|
|
|
3993
3993
|
constructor(config) {
|
|
3994
3994
|
super(config);
|
|
3995
3995
|
}
|
|
3996
|
-
async init() { }
|
|
3997
3996
|
/**
|
|
3998
3997
|
*
|
|
3999
3998
|
* @param {Address} creator
|
|
@@ -4794,19 +4793,27 @@ class State extends Contract {
|
|
|
4794
4793
|
#knownBlocksHandler;
|
|
4795
4794
|
async init() {
|
|
4796
4795
|
this.jobber = new Jobber(this.resolveTimeout);
|
|
4797
|
-
if (super.init)
|
|
4798
|
-
await super.init();
|
|
4799
4796
|
await globalThis.peernet.addRequestHandler('lastBlock', this.#lastBlockHandler);
|
|
4800
4797
|
await globalThis.peernet.addRequestHandler('knownBlocks', this.#knownBlocksHandler);
|
|
4801
4798
|
await globalThis.peernet.addRequestHandler('chainState', this.#chainStateHandler);
|
|
4799
|
+
let localBlockHash;
|
|
4800
|
+
let blockMessage;
|
|
4801
|
+
let localBlock;
|
|
4802
4802
|
try {
|
|
4803
|
-
await globalThis.chainStore.has('lastBlock');
|
|
4803
|
+
const rawBlock = await globalThis.chainStore.has('lastBlock');
|
|
4804
|
+
if (rawBlock) {
|
|
4805
|
+
localBlockHash = new TextDecoder().decode(await globalThis.chainStore.get('lastBlock'));
|
|
4806
|
+
blockMessage = await globalThis.peernet.get(localBlockHash, 'block');
|
|
4807
|
+
blockMessage = await new BlockMessage(blockMessage);
|
|
4808
|
+
localBlock = { ...blockMessage.decoded, hash: localBlockHash };
|
|
4809
|
+
}
|
|
4810
|
+
else {
|
|
4811
|
+
localBlock = { index: 0, hash: '0x0', previousHash: '0x0' };
|
|
4812
|
+
}
|
|
4804
4813
|
}
|
|
4805
4814
|
catch {
|
|
4806
|
-
|
|
4815
|
+
localBlock = { index: 0, hash: '0x0', previousHash: '0x0' };
|
|
4807
4816
|
}
|
|
4808
|
-
globalThis.pubsub.publish('lastBlock', await this.lastBlock);
|
|
4809
|
-
// load local blocks
|
|
4810
4817
|
try {
|
|
4811
4818
|
this.knownBlocks = await blockStore.keys();
|
|
4812
4819
|
}
|
|
@@ -4815,14 +4822,7 @@ class State extends Contract {
|
|
|
4815
4822
|
throw error;
|
|
4816
4823
|
}
|
|
4817
4824
|
try {
|
|
4818
|
-
|
|
4819
|
-
try {
|
|
4820
|
-
const localBlock = await globalThis.chainStore.get('lastBlock');
|
|
4821
|
-
localBlockHash = new TextDecoder().decode(localBlock);
|
|
4822
|
-
}
|
|
4823
|
-
catch (error) { }
|
|
4824
|
-
if (localBlockHash && localBlockHash !== '0x0') {
|
|
4825
|
-
const blockMessage = new BlockMessage(await peernet.get(localBlockHash, 'block'));
|
|
4825
|
+
if (localBlock.hash && localBlock.hash !== '0x0') {
|
|
4826
4826
|
try {
|
|
4827
4827
|
const states = {
|
|
4828
4828
|
lastBlock: JSON.parse(new TextDecoder().decode(await globalThis.stateStore.get('lastBlock')))
|
|
@@ -5032,15 +5032,17 @@ class State extends Contract {
|
|
|
5032
5032
|
}
|
|
5033
5033
|
async #syncChain(lastBlock) {
|
|
5034
5034
|
try {
|
|
5035
|
-
if (this.knownBlocks?.length === Number(lastBlock.index) + 1) {
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
}
|
|
5035
|
+
// if (this.knownBlocks?.length === Number(lastBlock.index) + 1) {
|
|
5036
|
+
// let promises = []
|
|
5037
|
+
// promises = await Promise.allSettled(
|
|
5038
|
+
// this.knownBlocks.map(async (address) => {
|
|
5039
|
+
// const has = await globalThis.peernet.has(address)
|
|
5040
|
+
// return { has, address }
|
|
5041
|
+
// })
|
|
5042
|
+
// )
|
|
5043
|
+
// promises = promises.filter(({ status, value }) => status === 'fulfilled' && !value.has)
|
|
5044
|
+
// await Promise.allSettled(promises.map(({ value }) => this.getAndPutBlock(value.address)))
|
|
5045
|
+
// }
|
|
5044
5046
|
const localBlock = await this.lastBlock;
|
|
5045
5047
|
if (!localBlock || Number(localBlock.index) < Number(lastBlock.index)) {
|
|
5046
5048
|
// TODO: check if valid
|
package/exports/chain.js
CHANGED
|
@@ -222,7 +222,6 @@ class Contract extends Transaction {
|
|
|
222
222
|
constructor(config) {
|
|
223
223
|
super(config);
|
|
224
224
|
}
|
|
225
|
-
async init() { }
|
|
226
225
|
/**
|
|
227
226
|
*
|
|
228
227
|
* @param {Address} creator
|
|
@@ -921,19 +920,27 @@ class State extends Contract {
|
|
|
921
920
|
#knownBlocksHandler;
|
|
922
921
|
async init() {
|
|
923
922
|
this.jobber = new Jobber(this.resolveTimeout);
|
|
924
|
-
if (super.init)
|
|
925
|
-
await super.init();
|
|
926
923
|
await globalThis.peernet.addRequestHandler('lastBlock', this.#lastBlockHandler);
|
|
927
924
|
await globalThis.peernet.addRequestHandler('knownBlocks', this.#knownBlocksHandler);
|
|
928
925
|
await globalThis.peernet.addRequestHandler('chainState', this.#chainStateHandler);
|
|
926
|
+
let localBlockHash;
|
|
927
|
+
let blockMessage;
|
|
928
|
+
let localBlock;
|
|
929
929
|
try {
|
|
930
|
-
await globalThis.chainStore.has('lastBlock');
|
|
930
|
+
const rawBlock = await globalThis.chainStore.has('lastBlock');
|
|
931
|
+
if (rawBlock) {
|
|
932
|
+
localBlockHash = new TextDecoder().decode(await globalThis.chainStore.get('lastBlock'));
|
|
933
|
+
blockMessage = await globalThis.peernet.get(localBlockHash, 'block');
|
|
934
|
+
blockMessage = await new BlockMessage(blockMessage);
|
|
935
|
+
localBlock = { ...blockMessage.decoded, hash: localBlockHash };
|
|
936
|
+
}
|
|
937
|
+
else {
|
|
938
|
+
localBlock = { index: 0, hash: '0x0', previousHash: '0x0' };
|
|
939
|
+
}
|
|
931
940
|
}
|
|
932
941
|
catch {
|
|
933
|
-
|
|
942
|
+
localBlock = { index: 0, hash: '0x0', previousHash: '0x0' };
|
|
934
943
|
}
|
|
935
|
-
globalThis.pubsub.publish('lastBlock', await this.lastBlock);
|
|
936
|
-
// load local blocks
|
|
937
944
|
try {
|
|
938
945
|
this.knownBlocks = await blockStore.keys();
|
|
939
946
|
}
|
|
@@ -942,14 +949,7 @@ class State extends Contract {
|
|
|
942
949
|
throw error;
|
|
943
950
|
}
|
|
944
951
|
try {
|
|
945
|
-
|
|
946
|
-
try {
|
|
947
|
-
const localBlock = await globalThis.chainStore.get('lastBlock');
|
|
948
|
-
localBlockHash = new TextDecoder().decode(localBlock);
|
|
949
|
-
}
|
|
950
|
-
catch (error) { }
|
|
951
|
-
if (localBlockHash && localBlockHash !== '0x0') {
|
|
952
|
-
const blockMessage = new BlockMessage(await peernet.get(localBlockHash, 'block'));
|
|
952
|
+
if (localBlock.hash && localBlock.hash !== '0x0') {
|
|
953
953
|
try {
|
|
954
954
|
const states = {
|
|
955
955
|
lastBlock: JSON.parse(new TextDecoder().decode(await globalThis.stateStore.get('lastBlock')))
|
|
@@ -1159,15 +1159,17 @@ class State extends Contract {
|
|
|
1159
1159
|
}
|
|
1160
1160
|
async #syncChain(lastBlock) {
|
|
1161
1161
|
try {
|
|
1162
|
-
if (this.knownBlocks?.length === Number(lastBlock.index) + 1) {
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
}
|
|
1162
|
+
// if (this.knownBlocks?.length === Number(lastBlock.index) + 1) {
|
|
1163
|
+
// let promises = []
|
|
1164
|
+
// promises = await Promise.allSettled(
|
|
1165
|
+
// this.knownBlocks.map(async (address) => {
|
|
1166
|
+
// const has = await globalThis.peernet.has(address)
|
|
1167
|
+
// return { has, address }
|
|
1168
|
+
// })
|
|
1169
|
+
// )
|
|
1170
|
+
// promises = promises.filter(({ status, value }) => status === 'fulfilled' && !value.has)
|
|
1171
|
+
// await Promise.allSettled(promises.map(({ value }) => this.getAndPutBlock(value.address)))
|
|
1172
|
+
// }
|
|
1171
1173
|
const localBlock = await this.lastBlock;
|
|
1172
1174
|
if (!localBlock || Number(localBlock.index) < Number(lastBlock.index)) {
|
|
1173
1175
|
// TODO: check if valid
|
package/exports/contract.d.ts
CHANGED