@leofcoin/chain 1.8.16 → 1.8.17
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 +19 -9
- package/exports/chain.js +19 -9
- package/package.json +1 -1
package/exports/browser/chain.js
CHANGED
|
@@ -963,7 +963,7 @@ function parseUnits(value, unit) {
|
|
|
963
963
|
return FixedNumber.fromString(value, { decimals, width: 512 }).value;
|
|
964
964
|
}
|
|
965
965
|
|
|
966
|
-
const jsonStringifyBigInt = (key, value) => (typeof value === 'bigint' ? { $bigint: value.toString() } : value);
|
|
966
|
+
const jsonStringifyBigInt$1 = (key, value) => (typeof value === 'bigint' ? { $bigint: value.toString() } : value);
|
|
967
967
|
const jsonParseBigInt = (key, value) => typeof value === 'object' && value.$bigint ? BigInt(value.$bigint) : value;
|
|
968
968
|
|
|
969
969
|
const byteFormats = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
@@ -4631,9 +4631,9 @@ class Machine {
|
|
|
4631
4631
|
await Promise.all(promises);
|
|
4632
4632
|
}
|
|
4633
4633
|
const tasks = [
|
|
4634
|
-
stateStore.put('lastBlock', JSON.stringify(await this.lastBlock, jsonStringifyBigInt)),
|
|
4635
|
-
stateStore.put('states', JSON.stringify(state, jsonStringifyBigInt)),
|
|
4636
|
-
stateStore.put('accounts', JSON.stringify(accounts, jsonStringifyBigInt)),
|
|
4634
|
+
stateStore.put('lastBlock', JSON.stringify(await this.lastBlock, jsonStringifyBigInt$1)),
|
|
4635
|
+
stateStore.put('states', JSON.stringify(state, jsonStringifyBigInt$1)),
|
|
4636
|
+
stateStore.put('accounts', JSON.stringify(accounts, jsonStringifyBigInt$1)),
|
|
4637
4637
|
stateStore.put('info', JSON.stringify({
|
|
4638
4638
|
nativeCalls: await this.nativeCalls,
|
|
4639
4639
|
nativeMints: await this.nativeMints,
|
|
@@ -4644,7 +4644,7 @@ class Machine {
|
|
|
4644
4644
|
totalMintAmount: await this.totalMintAmount,
|
|
4645
4645
|
totalTransferAmount: await this.totalTransferAmount,
|
|
4646
4646
|
totalBlocks: await blockStore.length
|
|
4647
|
-
}, jsonStringifyBigInt))
|
|
4647
|
+
}, jsonStringifyBigInt$1))
|
|
4648
4648
|
// accountsStore.clear()
|
|
4649
4649
|
];
|
|
4650
4650
|
await Promise.all(tasks);
|
|
@@ -4710,7 +4710,7 @@ class Machine {
|
|
|
4710
4710
|
totalTransactions: BigInt(0),
|
|
4711
4711
|
totalBlocks: BigInt(0)
|
|
4712
4712
|
};
|
|
4713
|
-
rawInfo = JSON.stringify(this.states.info, jsonStringifyBigInt);
|
|
4713
|
+
rawInfo = JSON.stringify(this.states.info, jsonStringifyBigInt$1);
|
|
4714
4714
|
await stateStore.put('info', new TextEncoder().encode(rawInfo));
|
|
4715
4715
|
}
|
|
4716
4716
|
}
|
|
@@ -4945,7 +4945,7 @@ class Machine {
|
|
|
4945
4945
|
debug$2(`adding loaded block: ${block.index}@${block.hash}`);
|
|
4946
4946
|
if (block.decoded)
|
|
4947
4947
|
block = { ...block.decoded, hash: await block.hash() };
|
|
4948
|
-
return this.#askWorker('addLoadedBlock', JSON.stringify(block, jsonStringifyBigInt));
|
|
4948
|
+
return this.#askWorker('addLoadedBlock', JSON.stringify(block, jsonStringifyBigInt$1));
|
|
4949
4949
|
}
|
|
4950
4950
|
async latestTransactions() {
|
|
4951
4951
|
return this.#askWorker('latestTransactions');
|
|
@@ -4999,6 +4999,11 @@ utils.addCodec({
|
|
|
4999
4999
|
codec: 0x6c626d,
|
|
5000
5000
|
hashAlg: 'keccak-256'
|
|
5001
5001
|
});
|
|
5002
|
+
const jsonStringifyBigInt = (key, value) => {
|
|
5003
|
+
if (typeof value === 'bigint')
|
|
5004
|
+
return value.toString();
|
|
5005
|
+
return value;
|
|
5006
|
+
};
|
|
5002
5007
|
const debug$1 = createDebugger('leofcoin/state');
|
|
5003
5008
|
class State extends Contract {
|
|
5004
5009
|
#resolveErrored;
|
|
@@ -5112,7 +5117,7 @@ class State extends Contract {
|
|
|
5112
5117
|
};
|
|
5113
5118
|
this.#lastBlockHandler = async () => {
|
|
5114
5119
|
return new globalThis.peernet.protos['peernet-response']({
|
|
5115
|
-
response: new LastBlockMessage(await this.lastBlock).
|
|
5120
|
+
response: JSON.stringify(new LastBlockMessage(await this.lastBlock).decoded, jsonStringifyBigInt)
|
|
5116
5121
|
});
|
|
5117
5122
|
};
|
|
5118
5123
|
this.#knownBlocksHandler = async () => {
|
|
@@ -6312,7 +6317,12 @@ class Chain extends VersionControl {
|
|
|
6312
6317
|
try {
|
|
6313
6318
|
let response = await peer.request(node.encoded);
|
|
6314
6319
|
response = await new globalThis.peernet.protos['peernet-response'](new Uint8Array(Object.values(response)));
|
|
6315
|
-
|
|
6320
|
+
let decoded = response.decoded.response;
|
|
6321
|
+
try {
|
|
6322
|
+
decoded = JSON.parse(decoded);
|
|
6323
|
+
}
|
|
6324
|
+
catch { }
|
|
6325
|
+
return decoded;
|
|
6316
6326
|
}
|
|
6317
6327
|
catch (error) {
|
|
6318
6328
|
const peerId = peer?.peerId || peer?.id || peer?.address || 'unknown';
|
package/exports/chain.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createDebugger } from '@vandeurenglenn/debug';
|
|
2
|
-
import { formatBytes, jsonStringifyBigInt, jsonParseBigInt, parseUnits, formatUnits } from '@leofcoin/utils';
|
|
2
|
+
import { formatBytes, jsonStringifyBigInt as jsonStringifyBigInt$1, jsonParseBigInt, parseUnits, formatUnits } from '@leofcoin/utils';
|
|
3
3
|
import { TransactionMessage, BlockMessage, ContractMessage, LastBlockMessage, BWMessage, BWRequestMessage } from '@leofcoin/messages';
|
|
4
4
|
import addresses, { contractFactory } from '@leofcoin/addresses';
|
|
5
5
|
import { calculateFee, createContractMessage, signTransaction, contractFactoryMessage, nativeTokenMessage, validatorsMessage, nameServiceMessage } from '@leofcoin/lib';
|
|
@@ -772,9 +772,9 @@ class Machine {
|
|
|
772
772
|
await Promise.all(promises);
|
|
773
773
|
}
|
|
774
774
|
const tasks = [
|
|
775
|
-
stateStore.put('lastBlock', JSON.stringify(await this.lastBlock, jsonStringifyBigInt)),
|
|
776
|
-
stateStore.put('states', JSON.stringify(state, jsonStringifyBigInt)),
|
|
777
|
-
stateStore.put('accounts', JSON.stringify(accounts, jsonStringifyBigInt)),
|
|
775
|
+
stateStore.put('lastBlock', JSON.stringify(await this.lastBlock, jsonStringifyBigInt$1)),
|
|
776
|
+
stateStore.put('states', JSON.stringify(state, jsonStringifyBigInt$1)),
|
|
777
|
+
stateStore.put('accounts', JSON.stringify(accounts, jsonStringifyBigInt$1)),
|
|
778
778
|
stateStore.put('info', JSON.stringify({
|
|
779
779
|
nativeCalls: await this.nativeCalls,
|
|
780
780
|
nativeMints: await this.nativeMints,
|
|
@@ -785,7 +785,7 @@ class Machine {
|
|
|
785
785
|
totalMintAmount: await this.totalMintAmount,
|
|
786
786
|
totalTransferAmount: await this.totalTransferAmount,
|
|
787
787
|
totalBlocks: await blockStore.length
|
|
788
|
-
}, jsonStringifyBigInt))
|
|
788
|
+
}, jsonStringifyBigInt$1))
|
|
789
789
|
// accountsStore.clear()
|
|
790
790
|
];
|
|
791
791
|
await Promise.all(tasks);
|
|
@@ -851,7 +851,7 @@ class Machine {
|
|
|
851
851
|
totalTransactions: BigInt(0),
|
|
852
852
|
totalBlocks: BigInt(0)
|
|
853
853
|
};
|
|
854
|
-
rawInfo = JSON.stringify(this.states.info, jsonStringifyBigInt);
|
|
854
|
+
rawInfo = JSON.stringify(this.states.info, jsonStringifyBigInt$1);
|
|
855
855
|
await stateStore.put('info', new TextEncoder().encode(rawInfo));
|
|
856
856
|
}
|
|
857
857
|
}
|
|
@@ -1086,7 +1086,7 @@ class Machine {
|
|
|
1086
1086
|
debug$2(`adding loaded block: ${block.index}@${block.hash}`);
|
|
1087
1087
|
if (block.decoded)
|
|
1088
1088
|
block = { ...block.decoded, hash: await block.hash() };
|
|
1089
|
-
return this.#askWorker('addLoadedBlock', JSON.stringify(block, jsonStringifyBigInt));
|
|
1089
|
+
return this.#askWorker('addLoadedBlock', JSON.stringify(block, jsonStringifyBigInt$1));
|
|
1090
1090
|
}
|
|
1091
1091
|
async latestTransactions() {
|
|
1092
1092
|
return this.#askWorker('latestTransactions');
|
|
@@ -1140,6 +1140,11 @@ codecs.addCodec({
|
|
|
1140
1140
|
codec: 0x6c626d,
|
|
1141
1141
|
hashAlg: 'keccak-256'
|
|
1142
1142
|
});
|
|
1143
|
+
const jsonStringifyBigInt = (key, value) => {
|
|
1144
|
+
if (typeof value === 'bigint')
|
|
1145
|
+
return value.toString();
|
|
1146
|
+
return value;
|
|
1147
|
+
};
|
|
1143
1148
|
const debug$1 = createDebugger('leofcoin/state');
|
|
1144
1149
|
class State extends Contract {
|
|
1145
1150
|
#resolveErrored;
|
|
@@ -1253,7 +1258,7 @@ class State extends Contract {
|
|
|
1253
1258
|
};
|
|
1254
1259
|
this.#lastBlockHandler = async () => {
|
|
1255
1260
|
return new globalThis.peernet.protos['peernet-response']({
|
|
1256
|
-
response: new LastBlockMessage(await this.lastBlock).
|
|
1261
|
+
response: JSON.stringify(new LastBlockMessage(await this.lastBlock).decoded, jsonStringifyBigInt)
|
|
1257
1262
|
});
|
|
1258
1263
|
};
|
|
1259
1264
|
this.#knownBlocksHandler = async () => {
|
|
@@ -2453,7 +2458,12 @@ class Chain extends VersionControl {
|
|
|
2453
2458
|
try {
|
|
2454
2459
|
let response = await peer.request(node.encoded);
|
|
2455
2460
|
response = await new globalThis.peernet.protos['peernet-response'](new Uint8Array(Object.values(response)));
|
|
2456
|
-
|
|
2461
|
+
let decoded = response.decoded.response;
|
|
2462
|
+
try {
|
|
2463
|
+
decoded = JSON.parse(decoded);
|
|
2464
|
+
}
|
|
2465
|
+
catch { }
|
|
2466
|
+
return decoded;
|
|
2457
2467
|
}
|
|
2458
2468
|
catch (error) {
|
|
2459
2469
|
const peerId = peer?.peerId || peer?.id || peer?.address || 'unknown';
|