@leofcoin/chain 1.7.55 → 1.7.66

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/chain.js CHANGED
@@ -280,7 +280,7 @@ class Machine {
280
280
  this.states = {
281
281
  states: {},
282
282
  lastBlock: {
283
- index: 0,
283
+ index: -1,
284
284
  hash: ''
285
285
  },
286
286
  accounts: {},
@@ -429,7 +429,7 @@ class Machine {
429
429
  await Promise.all(promises);
430
430
  }
431
431
  const tasks = [
432
- stateStore.put('lastBlock', JSON.stringify(await this.lastBlock)),
432
+ stateStore.put('lastBlock', JSON.stringify(await this.lastBlock, jsonStringifyBigInt)),
433
433
  stateStore.put('states', JSON.stringify(state, jsonStringifyBigInt)),
434
434
  stateStore.put('accounts', JSON.stringify(accounts, jsonStringifyBigInt)),
435
435
  stateStore.put('info', JSON.stringify({
@@ -476,16 +476,22 @@ class Machine {
476
476
  type: 'module'
477
477
  });
478
478
  this.worker.onmessage(this.#onmessage.bind(this));
479
+ let rawLastBlock;
480
+ let rawStates;
481
+ let rawAccounts;
482
+ let rawInfo;
479
483
  if (await stateStore.has('lastBlock')) {
480
- this.states.lastBlock = JSON.parse(new TextDecoder().decode(await stateStore.get('lastBlock')));
481
- this.states.states = JSON.parse(new TextDecoder().decode(await stateStore.get('states')), jsonParseBigInt);
484
+ const decoder = new TextDecoder();
485
+ const decode = (param) => decoder.decode(param);
486
+ rawLastBlock = decode(await stateStore.get('lastBlock'));
487
+ this.states.lastBlock = JSON.parse(rawLastBlock, jsonParseBigInt);
482
488
  try {
483
- this.states.accounts = JSON.parse(new TextDecoder().decode(await stateStore.get('accounts')), jsonParseBigInt);
484
- const info = JSON.parse(new TextDecoder().decode(await stateStore.get('info')), jsonParseBigInt);
485
- // for (const key in info) {
486
- // info[key] = BigInt(info[key])
487
- // }
488
- this.states.info = info;
489
+ rawStates = decode(await stateStore.get('states'));
490
+ rawAccounts = decode(await stateStore.get('accounts'));
491
+ rawInfo = decode(await stateStore.get('info'));
492
+ this.states.states = JSON.parse(rawStates, jsonParseBigInt);
493
+ this.states.accounts = JSON.parse(rawAccounts, jsonParseBigInt);
494
+ this.states.info = JSON.parse(rawInfo, jsonParseBigInt);
489
495
  }
490
496
  catch (error) {
491
497
  console.error(error);
@@ -502,16 +508,18 @@ class Machine {
502
508
  totalTransactions: BigInt(0),
503
509
  totalBlocks: BigInt(0)
504
510
  };
511
+ rawInfo = JSON.stringify(this.states.info, jsonStringifyBigInt);
512
+ await stateStore.put('info', new TextEncoder().encode(rawInfo));
505
513
  }
506
514
  }
507
515
  const message = {
508
516
  type: 'init',
509
517
  input: {
510
518
  blocks,
511
- fromState: this.states.lastBlock.index > 0,
512
- lastBlock: this.states.lastBlock,
513
- state: this.states.states,
514
- info: this.states.info,
519
+ fromState: this.states.lastBlock?.index >= 0,
520
+ lastBlock: rawLastBlock,
521
+ state: rawStates,
522
+ info: rawInfo,
515
523
  // @ts-ignore
516
524
  peerid: peernet.peerId
517
525
  }
@@ -1764,7 +1772,7 @@ class Chain extends VersionControl {
1764
1772
  fees: BigInt(0),
1765
1773
  timestamp,
1766
1774
  previousHash: '',
1767
- reward: parseUnits('150'),
1775
+ reward: BigInt(150),
1768
1776
  index: 0
1769
1777
  };
1770
1778
  const latestTransactions = await this.machine.latestTransactions();
@@ -1821,7 +1829,7 @@ class Chain extends VersionControl {
1821
1829
  block.validators = block.validators.map((validator) => {
1822
1830
  validator.reward = block.fees;
1823
1831
  validator.reward += block.reward;
1824
- validator.reward /= block.validators.length;
1832
+ validator.reward /= BigInt(block.validators.length);
1825
1833
  delete validator.bw;
1826
1834
  return validator;
1827
1835
  });
@@ -0,0 +1,4 @@
1
+ export default class Contract {
2
+ constructor(address: any, ABI: any, provider: any, config: any);
3
+ proxy(): this;
4
+ }
@@ -1,4 +1,4 @@
1
- import { E as EasyWorker, B as BlockMessage } from './worker-2Vk145X_-2Vk145X_.js';
1
+ import { E as EasyWorker, B as BlockMessage } from './worker-4K8uC3xq-4K8uC3xq.js';
2
2
 
3
3
  const worker = new EasyWorker();
4
4
 
@@ -1,4 +1,61 @@
1
- import { E as EasyWorker, C as ContractMessage, T as TransactionMessage } from './worker-2Vk145X_-2Vk145X_.js';
1
+ import { E as EasyWorker, C as ContractMessage, T as TransactionMessage } from './worker-4K8uC3xq-4K8uC3xq.js';
2
+
3
+ /* Do NOT modify this file; see /src.ts/_admin/update-version.ts */
4
+ /**
5
+ * The current version of Ethers.
6
+ */
7
+ ["NFD", "NFC", "NFKD", "NFKC"].reduce((accum, form) => {
8
+ try {
9
+ // General test for normalize
10
+ /* c8 ignore start */
11
+ if ("test".normalize(form) !== "test") {
12
+ throw new Error("bad");
13
+ }
14
+ ;
15
+ /* c8 ignore stop */
16
+ if (form === "NFD") {
17
+ const check = String.fromCharCode(0xe9).normalize("NFD");
18
+ const expected = String.fromCharCode(0x65, 0x0301);
19
+ /* c8 ignore start */
20
+ if (check !== expected) {
21
+ throw new Error("broken");
22
+ }
23
+ /* c8 ignore stop */
24
+ }
25
+ accum.push(form);
26
+ }
27
+ catch (error) { }
28
+ return accum;
29
+ }, []);
30
+
31
+ /**
32
+ * Some mathematic operations.
33
+ *
34
+ * @_subsection: api/utils:Math Helpers [about-maths]
35
+ */
36
+ BigInt(0);
37
+ BigInt(1);
38
+
39
+ /**
40
+ * The **FixedNumber** class permits using values with decimal places,
41
+ * using fixed-pont math.
42
+ *
43
+ * Fixed-point math is still based on integers under-the-hood, but uses an
44
+ * internal offset to store fractional components below, and each operation
45
+ * corrects for this after each operation.
46
+ *
47
+ * @_section: api/utils/fixed-point-math:Fixed-Point Maths [about-fixed-point-math]
48
+ */
49
+ BigInt(-1);
50
+ BigInt(0);
51
+ BigInt(1);
52
+ BigInt(5);
53
+ // Constant to pull zeros from for multipliers
54
+ let Zeros = "0000";
55
+ while (Zeros.length < 80) {
56
+ Zeros += Zeros;
57
+ }
58
+ const jsonParseBigInt = (key, value) => typeof value === 'object' && value.$bigint ? BigInt(value.$bigint) : value;
2
59
 
3
60
  const byteFormats = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
4
61
  const formatBytes = (bytes, decimals = 2) => {
@@ -263,22 +320,22 @@ const _ = {
263
320
  nativeCalls += 1n;
264
321
  if (method === 'burn') {
265
322
  nativeBurns = nativeBurns += 1n;
266
- totalBurnAmount = totalBurnAmount += params[1];
323
+ totalBurnAmount += BigInt(params[1]);
267
324
  }
268
325
  if (method === 'mint') {
269
326
  nativeMints = nativeMints += 1n;
270
- totalMintAmount = totalMintAmount += params[1];
327
+ totalMintAmount += BigInt(params[1]);
271
328
  }
272
329
  if (method === 'transfer') {
273
330
  nativeTransfers = nativeTransfers += 1n;
274
- totalTransferAmount = totalTransferAmount += params[2];
275
- }
276
- if (method === 'transferFrom') {
277
- nativeTransfers = nativeTransfers += 1n;
278
- totalTransferAmount = totalTransferAmount += params[1];
331
+ totalTransferAmount += BigInt(params[2]);
279
332
  }
333
+ // if (method === 'transferFrom') {
334
+ // nativeTransfers = nativeTransfers += 1n
335
+ // totalTransferAmount += params[1]
336
+ // }
280
337
  }
281
- totalTransactions = totalTransactions += 1n;
338
+ totalTransactions += 1n;
282
339
  // state.put(result)
283
340
  return result;
284
341
  }
@@ -293,6 +350,10 @@ const _ = {
293
350
  },
294
351
  init: async (message) => {
295
352
  let { peerid, fromState, state, info } = message;
353
+ if (info)
354
+ info = JSON.parse(info, jsonParseBigInt);
355
+ if (state)
356
+ state = JSON.parse(state, jsonParseBigInt);
296
357
  globalThis.peerid = peerid;
297
358
  console.log({ fromState, info });
298
359
  nativeCalls = BigInt(info?.nativeCalls ?? 0);
@@ -305,7 +366,9 @@ const _ = {
305
366
  totalTransferAmount = BigInt(info?.totalTransferAmount ?? 0);
306
367
  totalBlocks = BigInt(info?.totalBlocks ?? 0);
307
368
  if (fromState) {
308
- lastBlock = message.lastBlock;
369
+ if (message.lastBlock) {
370
+ lastBlock = JSON.parse(message.lastBlock, jsonParseBigInt);
371
+ }
309
372
  const setState = async (address, state) => {
310
373
  const contractBytes = await resolveContract(address);
311
374
  if (contractBytes === address) {