@leofcoin/chain 1.7.54 → 1.7.65

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.
@@ -19,14 +19,14 @@ export default class Chain extends VersionControl {
19
19
  sendTransaction(transaction: any): Promise<{
20
20
  hash: any;
21
21
  data: any;
22
- fee: string | 0 | import("@ethersproject/bignumber").BigNumber;
22
+ fee: string | bigint | 0;
23
23
  wait: Promise<unknown>;
24
24
  message: any;
25
25
  }>;
26
26
  addContract(transaction: any, contractMessage: any): Promise<{
27
27
  hash: any;
28
28
  data: any;
29
- fee: string | 0 | import("@ethersproject/bignumber").BigNumber;
29
+ fee: string | bigint | 0;
30
30
  wait: Promise<unknown>;
31
31
  message: any;
32
32
  }>;
package/exports/chain.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import '@vandeurenglenn/debug';
2
- import { formatBytes, formatUnits, parseUnits } from '@leofcoin/utils';
2
+ import { formatBytes, jsonStringifyBigInt, jsonParseBigInt, formatUnits, parseUnits } from '@leofcoin/utils';
3
3
  import { TransactionMessage, BlockMessage, ContractMessage, 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';
@@ -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: {},
@@ -366,7 +366,7 @@ class Machine {
366
366
  }
367
367
  }
368
368
  else if (data.question === 'peers') {
369
- this.worker.postMessage({ id: data.id, input: peernet.peers });
369
+ this.worker.postMessage({ id: data.id, input: peernet.connections ? peernet.peers : [] });
370
370
  }
371
371
  else {
372
372
  this.worker.postMessage({ id: data.id, input: data.input });
@@ -429,9 +429,9 @@ class Machine {
429
429
  await Promise.all(promises);
430
430
  }
431
431
  const tasks = [
432
- stateStore.put('lastBlock', JSON.stringify(await this.lastBlock)),
433
- stateStore.put('states', JSON.stringify(state)),
434
- stateStore.put('accounts', JSON.stringify(accounts)),
432
+ stateStore.put('lastBlock', JSON.stringify(await this.lastBlock, jsonStringifyBigInt)),
433
+ stateStore.put('states', JSON.stringify(state, jsonStringifyBigInt)),
434
+ stateStore.put('accounts', JSON.stringify(accounts, jsonStringifyBigInt)),
435
435
  stateStore.put('info', JSON.stringify({
436
436
  nativeCalls: await this.nativeCalls,
437
437
  nativeMints: await this.nativeMints,
@@ -442,7 +442,7 @@ class Machine {
442
442
  totalMintAmount: await this.totalMintAmount,
443
443
  totalTransferAmount: await this.totalTransferAmount,
444
444
  totalBlocks: await blockStore.length
445
- }))
445
+ }, jsonStringifyBigInt))
446
446
  // accountsStore.clear()
447
447
  ];
448
448
  await Promise.all(tasks);
@@ -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')));
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')));
484
- const info = JSON.parse(new TextDecoder().decode(await stateStore.get('info')));
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
  }
@@ -1732,7 +1740,7 @@ class Chain extends VersionControl {
1732
1740
  const result = await this.#executeTransaction({ ...transaction.decoded, hash });
1733
1741
  if (block) {
1734
1742
  block.transactions.push(hash);
1735
- block.fees = block.fees.add(await calculateFee(transaction.decoded));
1743
+ block.fees = block.fees += await calculateFee(transaction.decoded);
1736
1744
  }
1737
1745
  await globalThis.accountsStore.put(transaction.decoded.from, new TextEncoder().encode(String(transaction.decoded.nonce)));
1738
1746
  await transactionStore.put(hash, await transaction.encode());
@@ -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();
@@ -1820,8 +1828,8 @@ class Chain extends VersionControl {
1820
1828
  }
1821
1829
  block.validators = block.validators.map((validator) => {
1822
1830
  validator.reward = block.fees;
1823
- validator.reward = validator.reward.add(block.reward);
1824
- validator.reward = validator.reward.div(block.validators.length);
1831
+ validator.reward += block.reward;
1832
+ validator.reward /= BigInt(block.validators.length);
1825
1833
  delete validator.bw;
1826
1834
  return validator;
1827
1835
  });
@@ -31,14 +31,14 @@ export default class Contract extends Transaction {
31
31
  deployContract(signer: MultiWallet, contract: any, constructorParameters?: any[]): Promise<{
32
32
  hash: any;
33
33
  data: any;
34
- fee: string | 0 | import("@ethersproject/bignumber").BigNumber;
34
+ fee: string | bigint | 0;
35
35
  wait: Promise<unknown>;
36
36
  message: any;
37
37
  }>;
38
38
  deployContractMessage(signer: any, message: any): Promise<{
39
39
  hash: any;
40
40
  data: any;
41
- fee: string | 0 | import("@ethersproject/bignumber").BigNumber;
41
+ fee: string | bigint | 0;
42
42
  wait: Promise<unknown>;
43
43
  message: any;
44
44
  }>;
@@ -0,0 +1,4 @@
1
+ export default class Contract {
2
+ constructor(address: any, ABI: any, provider: any, config: any);
3
+ proxy(): this;
4
+ }
package/exports/node.js CHANGED
@@ -20,7 +20,7 @@ class Node {
20
20
  network: 'leofcoin:peach',
21
21
  networkName: 'leofcoin:peach',
22
22
  networkVersion: 'peach',
23
- version: '1.2.1',
23
+ version: '0.1.0',
24
24
  stars: networks.leofcoin.peach.stars,
25
25
  autoStart: false
26
26
  }, password) {
@@ -34,7 +34,7 @@ export default class Transaction extends Protocol {
34
34
  sendTransaction(message: any): Promise<{
35
35
  hash: any;
36
36
  data: any;
37
- fee: string | 0 | import("@ethersproject/bignumber").BigNumber;
37
+ fee: string | bigint | 0;
38
38
  wait: Promise<unknown>;
39
39
  message: any;
40
40
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.7.54",
3
+ "version": "1.7.65",
4
4
  "description": "Official javascript implementation",
5
5
  "private": false,
6
6
  "exports": {
@@ -49,30 +49,30 @@
49
49
  "author": "",
50
50
  "license": "MIT",
51
51
  "devDependencies": {
52
- "@rollup/plugin-commonjs": "^26.0.1",
52
+ "@rollup/plugin-commonjs": "^28.0.0",
53
53
  "@rollup/plugin-json": "^6.1.0",
54
- "@rollup/plugin-node-resolve": "^15.2.3",
55
- "@rollup/plugin-typescript": "^11.1.6",
54
+ "@rollup/plugin-node-resolve": "^15.3.0",
55
+ "@rollup/plugin-typescript": "^12.1.0",
56
56
  "@types/semver": "^7.5.8",
57
57
  "@vandeurenglenn/debug": "^1.2.5",
58
- "rollup": "^4.22.2",
58
+ "rollup": "^4.23.0",
59
59
  "rollup-plugin-modify": "^3.0.0",
60
60
  "tape": "^5.9.0",
61
61
  "tslib": "^2.7.0"
62
62
  },
63
63
  "dependencies": {
64
- "@leofcoin/addresses": "^1.0.38",
65
- "@leofcoin/contracts": "^0.1.13",
66
- "@leofcoin/crypto": "^0.2.24",
67
- "@leofcoin/errors": "^1.0.19",
68
- "@leofcoin/lib": "^1.2.63",
69
- "@leofcoin/messages": "^1.4.33",
64
+ "@leofcoin/addresses": "^1.0.44",
65
+ "@leofcoin/contracts": "^0.1.14",
66
+ "@leofcoin/crypto": "^0.2.28",
67
+ "@leofcoin/errors": "^1.0.23",
68
+ "@leofcoin/lib": "^1.2.67",
69
+ "@leofcoin/messages": "^1.4.37",
70
70
  "@leofcoin/multi-wallet": "^3.1.8",
71
- "@leofcoin/networks": "^1.1.18",
71
+ "@leofcoin/networks": "^1.1.22",
72
72
  "@leofcoin/peernet": "^1.1.80",
73
73
  "@leofcoin/storage": "^3.5.32",
74
- "@leofcoin/utils": "^1.1.30",
75
- "@leofcoin/workers": "^1.5.14",
74
+ "@leofcoin/utils": "^1.1.36",
75
+ "@leofcoin/workers": "^1.5.19",
76
76
  "@vandeurenglenn/base58": "^1.1.9",
77
77
  "@vandeurenglenn/easy-worker": "^1.0.2",
78
78
  "semver": "^7.6.3"
@@ -1,188 +0,0 @@
1
- import { g as getDefaultExportFromCjs } from './node-browser-CuHuGNar.js';
2
- import './index-jJAWNcIz.js';
3
-
4
- var global;
5
- var hasRequiredGlobal;
6
-
7
- function requireGlobal () {
8
- if (hasRequiredGlobal) return global;
9
- hasRequiredGlobal = 1;
10
- var naiveFallback = function () {
11
- if (typeof self === "object" && self) return self;
12
- if (typeof window === "object" && window) return window;
13
- throw new Error("Unable to resolve global `this`");
14
- };
15
-
16
- global = (function () {
17
- if (this) return this;
18
-
19
- // Unexpected strict mode (may happen if e.g. bundled into ESM module)
20
-
21
- // Fallback to standard globalThis if available
22
- if (typeof globalThis === "object" && globalThis) return globalThis;
23
-
24
- // Thanks @mathiasbynens -> https://mathiasbynens.be/notes/globalthis
25
- // In all ES5+ engines global object inherits from Object.prototype
26
- // (if you approached one that doesn't please report)
27
- try {
28
- Object.defineProperty(Object.prototype, "__global__", {
29
- get: function () { return this; },
30
- configurable: true
31
- });
32
- } catch (error) {
33
- // Unfortunate case of updates to Object.prototype being restricted
34
- // via preventExtensions, seal or freeze
35
- return naiveFallback();
36
- }
37
- try {
38
- // Safari case (window.__global__ works, but __global__ does not)
39
- if (!__global__) return naiveFallback();
40
- return __global__;
41
- } finally {
42
- delete Object.prototype.__global__;
43
- }
44
- })();
45
- return global;
46
- }
47
-
48
- var name = "websocket";
49
- var description = "Websocket Client & Server Library implementing the WebSocket protocol as specified in RFC 6455.";
50
- var keywords = [
51
- "websocket",
52
- "websockets",
53
- "socket",
54
- "networking",
55
- "comet",
56
- "push",
57
- "RFC-6455",
58
- "realtime",
59
- "server",
60
- "client"
61
- ];
62
- var author = "Brian McKelvey <theturtle32@gmail.com> (https://github.com/theturtle32)";
63
- var contributors = [
64
- "Iñaki Baz Castillo <ibc@aliax.net> (http://dev.sipdoc.net)"
65
- ];
66
- var version$1 = "1.0.35";
67
- var repository = {
68
- type: "git",
69
- url: "https://github.com/theturtle32/WebSocket-Node.git"
70
- };
71
- var homepage = "https://github.com/theturtle32/WebSocket-Node";
72
- var engines = {
73
- node: ">=4.0.0"
74
- };
75
- var dependencies = {
76
- bufferutil: "^4.0.1",
77
- debug: "^2.2.0",
78
- "es5-ext": "^0.10.63",
79
- "typedarray-to-buffer": "^3.1.5",
80
- "utf-8-validate": "^5.0.2",
81
- yaeti: "^0.0.6"
82
- };
83
- var devDependencies = {
84
- "buffer-equal": "^1.0.0",
85
- gulp: "^4.0.2",
86
- "gulp-jshint": "^2.0.4",
87
- "jshint-stylish": "^2.2.1",
88
- jshint: "^2.0.0",
89
- tape: "^4.9.1"
90
- };
91
- var config = {
92
- verbose: false
93
- };
94
- var scripts = {
95
- test: "tape test/unit/*.js",
96
- gulp: "gulp"
97
- };
98
- var main = "index";
99
- var directories = {
100
- lib: "./lib"
101
- };
102
- var browser$3 = "lib/browser.js";
103
- var license = "Apache-2.0";
104
- var require$$0 = {
105
- name: name,
106
- description: description,
107
- keywords: keywords,
108
- author: author,
109
- contributors: contributors,
110
- version: version$1,
111
- repository: repository,
112
- homepage: homepage,
113
- engines: engines,
114
- dependencies: dependencies,
115
- devDependencies: devDependencies,
116
- config: config,
117
- scripts: scripts,
118
- main: main,
119
- directories: directories,
120
- browser: browser$3,
121
- license: license
122
- };
123
-
124
- var version = require$$0.version;
125
-
126
- var _globalThis;
127
- if (typeof globalThis === 'object') {
128
- _globalThis = globalThis;
129
- } else {
130
- try {
131
- _globalThis = requireGlobal();
132
- } catch (error) {
133
- } finally {
134
- if (!_globalThis && typeof window !== 'undefined') { _globalThis = window; }
135
- if (!_globalThis) { throw new Error('Could not determine global this'); }
136
- }
137
- }
138
-
139
- var NativeWebSocket = _globalThis.WebSocket || _globalThis.MozWebSocket;
140
- var websocket_version = version;
141
-
142
-
143
- /**
144
- * Expose a W3C WebSocket class with just one or two arguments.
145
- */
146
- function W3CWebSocket(uri, protocols) {
147
- var native_instance;
148
-
149
- if (protocols) {
150
- native_instance = new NativeWebSocket(uri, protocols);
151
- }
152
- else {
153
- native_instance = new NativeWebSocket(uri);
154
- }
155
-
156
- /**
157
- * 'native_instance' is an instance of nativeWebSocket (the browser's WebSocket
158
- * class). Since it is an Object it will be returned as it is when creating an
159
- * instance of W3CWebSocket via 'new W3CWebSocket()'.
160
- *
161
- * ECMAScript 5: http://bclary.com/2004/11/07/#a-13.2.2
162
- */
163
- return native_instance;
164
- }
165
- if (NativeWebSocket) {
166
- ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED'].forEach(function(prop) {
167
- Object.defineProperty(W3CWebSocket, prop, {
168
- get: function() { return NativeWebSocket[prop]; }
169
- });
170
- });
171
- }
172
-
173
- /**
174
- * Module exports.
175
- */
176
- var browser = {
177
- 'w3cwebsocket' : NativeWebSocket ? W3CWebSocket : null,
178
- 'version' : websocket_version
179
- };
180
-
181
- var browser$1 = /*@__PURE__*/getDefaultExportFromCjs(browser);
182
-
183
- var browser$2 = /*#__PURE__*/Object.freeze({
184
- __proto__: null,
185
- default: browser$1
186
- });
187
-
188
- export { browser$2 as b };
@@ -1,25 +0,0 @@
1
- var browser$1 = {};
2
-
3
- browser$1.MediaStream = window.MediaStream;
4
- browser$1.MediaStreamTrack = window.MediaStreamTrack;
5
- browser$1.RTCDataChannel = window.RTCDataChannel;
6
- browser$1.RTCDataChannelEvent = window.RTCDataChannelEvent;
7
- browser$1.RTCDtlsTransport = window.RTCDtlsTransport;
8
- browser$1.RTCIceCandidate = window.RTCIceCandidate;
9
- browser$1.RTCIceTransport = window.RTCIceTransport;
10
- browser$1.RTCPeerConnection = window.RTCPeerConnection;
11
- browser$1.RTCPeerConnectionIceEvent = window.RTCPeerConnectionIceEvent;
12
- browser$1.RTCRtpReceiver = window.RTCRtpReceiver;
13
- browser$1.RTCRtpSender = window.RTCRtpSender;
14
- browser$1.RTCRtpTransceiver = window.RTCRtpTransceiver;
15
- browser$1.RTCSctpTransport = window.RTCSctpTransport;
16
- browser$1.RTCSessionDescription = window.RTCSessionDescription;
17
- browser$1.getUserMedia = window.getUserMedia;
18
- browser$1.mediaDevices = navigator.mediaDevices;
19
-
20
- var browser = /*#__PURE__*/Object.freeze({
21
- __proto__: null,
22
- default: browser$1
23
- });
24
-
25
- export { browser as b };