@leofcoin/chain 1.5.11 → 1.5.13
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/browser-store.js +4 -3
- package/exports/browser/chain.js +55 -46
- package/exports/browser/{index-9c85cd32-ab3cf058.js → index-329e0324-67daaccb.js} +2 -2
- package/exports/browser/{index-b32f624f.js → index-e8f03811.js} +155 -144
- package/exports/browser/{messages-b66f5393-8ba2fe1a.js → messages-000b7f84-fd07a3bf.js} +2 -2
- package/exports/browser/{node-browser-3364f1f2.js → node-browser-505084de.js} +230 -252
- package/exports/browser/node-browser.js +2 -2
- package/exports/browser/workers/block-worker.js +159 -148
- package/exports/browser/workers/machine-worker.js +159 -148
- package/exports/chain.d.ts +72 -0
- package/exports/chain.js +41 -29
- package/exports/contract.d.ts +45 -0
- package/exports/{types/machine.d.ts → machine.d.ts} +3 -3
- package/exports/node.js +1 -0
- package/exports/{types/state.d.ts → state.d.ts} +2 -2
- package/exports/{types/transaction.d.ts → transaction.d.ts} +2 -1
- package/exports/{types/typer.d.ts → typer.d.ts} +1 -1
- package/exports/workers/block-worker.js +159 -148
- package/exports/workers/machine-worker.js +159 -148
- package/package.json +18 -3
- package/exports/types/contract.d.ts +0 -31
- /package/exports/{types/config → config}/config.d.ts +0 -0
- /package/exports/{types/config → config}/main.d.ts +0 -0
- /package/exports/{types/config → config}/protocol.d.ts +0 -0
- /package/exports/{types/consensus → consensus}/consensus.d.ts +0 -0
- /package/exports/{types/consensus → consensus}/helpers/sort-transactions.d.ts +0 -0
- /package/exports/{types/fee → fee}/config.d.ts +0 -0
- /package/exports/{types/jobs → jobs}/jobber.d.ts +0 -0
- /package/exports/{types/machine-state.d.ts → machine-state.d.ts} +0 -0
- /package/exports/{types/node-browser.d.ts → node-browser.d.ts} +0 -0
- /package/exports/{types/node.d.ts → node.d.ts} +0 -0
- /package/exports/{types/protocol.d.ts → protocol.d.ts} +0 -0
- /package/exports/{types/sync-controller.d.ts → sync-controller.d.ts} +0 -0
- /package/exports/{types/types.d.ts → types.d.ts} +0 -0
|
@@ -401,13 +401,14 @@ class BrowerStore {
|
|
|
401
401
|
});
|
|
402
402
|
}
|
|
403
403
|
toKeyPath(key) {
|
|
404
|
-
if (
|
|
404
|
+
if (key instanceof KeyPath)
|
|
405
405
|
key = new KeyPath(key);
|
|
406
|
-
return key.toString(
|
|
406
|
+
return key.toString();
|
|
407
407
|
}
|
|
408
408
|
toKeyValue(value) {
|
|
409
|
-
if (
|
|
409
|
+
if (value instanceof KeyValue)
|
|
410
410
|
value = new KeyValue(value);
|
|
411
|
+
// @ts-ignore
|
|
411
412
|
return value.uint8Array;
|
|
412
413
|
}
|
|
413
414
|
async get(key) {
|
package/exports/browser/chain.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BigNumber, L as Logger, v as version$1, h as hexZeroPad, i as isBigNumberish, a as arrayify, b as isBytes, C as ContractMessage, T as TransactionMessage, t as toBase58, R as RawTransactionMessage, c as BlockMessage, d as BWMessage, e as BWRequestMessage } from './index-
|
|
1
|
+
import { B as BigNumber, L as Logger, v as version$1, h as hexZeroPad, i as isBigNumberish, a as arrayify, b as isBytes, C as ContractMessage, T as TransactionMessage, t as toBase58, R as RawTransactionMessage, c as BlockMessage, d as BWMessage, e as BWRequestMessage } from './index-e8f03811.js';
|
|
2
2
|
|
|
3
3
|
const logger$1 = new Logger(version$1);
|
|
4
4
|
const _constructorGuard = {};
|
|
@@ -389,15 +389,14 @@ function parseUnits(value, unitName) {
|
|
|
389
389
|
}
|
|
390
390
|
|
|
391
391
|
const byteFormats = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
392
|
-
|
|
393
392
|
const formatBytes = (bytes, decimals = 2) => {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
393
|
+
if (bytes === 0)
|
|
394
|
+
return '0 Bytes';
|
|
395
|
+
if (decimals < 0)
|
|
396
|
+
decimals = 0;
|
|
397
|
+
const k = 1024;
|
|
398
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
399
|
+
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(decimals))} ${byteFormats[i]}`;
|
|
401
400
|
};
|
|
402
401
|
|
|
403
402
|
var contractFactory$1 = "IHNY2GQHKQLQTSDQ5CRDWDDILC34U5LGP4ONJESURDTOZ3NZWJZ3KEUGCVU";
|
|
@@ -457,18 +456,16 @@ const calculateFee = async (transaction, format = false) => {
|
|
|
457
456
|
};
|
|
458
457
|
const createTransactionHash = async (transaction) => {
|
|
459
458
|
const isRawTransactionMessage = transaction instanceof RawTransactionMessage;
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
return (await transaction.peernetHash).digest;
|
|
459
|
+
let message;
|
|
460
|
+
if (!isRawTransactionMessage)
|
|
461
|
+
message = await new RawTransactionMessage(transaction instanceof TransactionMessage ? transaction.decoded : transaction);
|
|
462
|
+
else
|
|
463
|
+
message = transaction;
|
|
464
|
+
return (await message.peernetHash).digest;
|
|
467
465
|
};
|
|
468
466
|
const signTransaction = async (transaction, wallet) => {
|
|
469
467
|
const signature = toBase58(await wallet.sign(await createTransactionHash(transaction)));
|
|
470
|
-
|
|
471
|
-
return signedTransaction;
|
|
468
|
+
return { ...transaction, signature };
|
|
472
469
|
};
|
|
473
470
|
|
|
474
471
|
const limit = 1800;
|
|
@@ -548,7 +545,9 @@ class Transaction extends Protocol {
|
|
|
548
545
|
transactions = await this.promiseTransactions(transactions);
|
|
549
546
|
transactions = transactions.filter(tx => tx.decoded.from === address);
|
|
550
547
|
transactions = await this.promiseTransactionsContent(transactions);
|
|
548
|
+
// @ts-ignore
|
|
551
549
|
if (this.lastBlock?.hash && transactions.length === 0 && this.lastBlock.hash !== '0x0') {
|
|
550
|
+
// @ts-ignore
|
|
552
551
|
let block = await peernet.get(this.lastBlock.hash, 'block');
|
|
553
552
|
block = await new BlockMessage(block);
|
|
554
553
|
// for (let tx of block.decoded?.transactions) {
|
|
@@ -612,6 +611,9 @@ class Transaction extends Protocol {
|
|
|
612
611
|
return true;
|
|
613
612
|
return false;
|
|
614
613
|
}
|
|
614
|
+
async createTransactionMessage(transaction, signature) {
|
|
615
|
+
return new TransactionMessage({ ...transaction, signature });
|
|
616
|
+
}
|
|
615
617
|
async createTransaction(transaction) {
|
|
616
618
|
return {
|
|
617
619
|
from: transaction.from,
|
|
@@ -704,17 +706,25 @@ class Contract extends Transaction {
|
|
|
704
706
|
* @param {Array} parameters
|
|
705
707
|
* @returns
|
|
706
708
|
*/
|
|
707
|
-
async deployContract(contract, constructorParameters = []) {
|
|
708
|
-
const message = await createContractMessage(
|
|
709
|
+
async deployContract(signer, contract, constructorParameters = []) {
|
|
710
|
+
const message = await createContractMessage(await signer.address, contract, constructorParameters);
|
|
711
|
+
return this.deployContractMessage(signer, message);
|
|
712
|
+
}
|
|
713
|
+
async deployContractMessage(signer, message) {
|
|
709
714
|
try {
|
|
710
|
-
await contractStore.put(await message.hash(), message.encoded);
|
|
715
|
+
await globalThis.contractStore.put(await message.hash(), message.encoded);
|
|
711
716
|
}
|
|
712
717
|
catch (error) {
|
|
713
718
|
throw error;
|
|
714
719
|
}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
720
|
+
let transaction = {
|
|
721
|
+
from: await signer.address,
|
|
722
|
+
to: addresses.contractFactory,
|
|
723
|
+
method: 'registerContract',
|
|
724
|
+
params: [await message.hash()]
|
|
725
|
+
};
|
|
726
|
+
transaction = await signTransaction(await this.createTransaction(transaction), signer);
|
|
727
|
+
return this.sendTransaction(transaction);
|
|
718
728
|
}
|
|
719
729
|
}
|
|
720
730
|
|
|
@@ -809,8 +819,7 @@ class Machine {
|
|
|
809
819
|
// @ts-ignore
|
|
810
820
|
return this.#init(blocks);
|
|
811
821
|
}
|
|
812
|
-
|
|
813
|
-
#createMessage(sender = globalThis.peernet.selectedAccount) {
|
|
822
|
+
#createMessage(sender = peernet.selectedAccount) {
|
|
814
823
|
return {
|
|
815
824
|
sender,
|
|
816
825
|
call: this.execute,
|
|
@@ -1012,7 +1021,7 @@ class Machine {
|
|
|
1012
1021
|
* @returns Promise
|
|
1013
1022
|
*/
|
|
1014
1023
|
async deleteAll() {
|
|
1015
|
-
let hashes = await globalThis.contractStore.
|
|
1024
|
+
let hashes = await globalThis.contractStore.keys();
|
|
1016
1025
|
hashes = Object.keys(hashes).map(hash => this.delete(hash));
|
|
1017
1026
|
return Promise.all(hashes);
|
|
1018
1027
|
}
|
|
@@ -1247,6 +1256,7 @@ class State extends Contract {
|
|
|
1247
1256
|
return new globalThis.peernet.protos['peernet-response']({ response: { blocks: this.#blocks.map((block) => block.hash) } });
|
|
1248
1257
|
}
|
|
1249
1258
|
getLatestBlock() {
|
|
1259
|
+
// @ts-ignore
|
|
1250
1260
|
return this.#getLatestBlock();
|
|
1251
1261
|
}
|
|
1252
1262
|
async getAndPutBlock(hash) {
|
|
@@ -1257,7 +1267,7 @@ class State extends Contract {
|
|
|
1257
1267
|
const { index } = block.decoded;
|
|
1258
1268
|
if (this.#blocks[index - 1] && this.#blocks[index - 1].hash !== block.hash)
|
|
1259
1269
|
throw `invalid block ${hash} @${index}`;
|
|
1260
|
-
if (!await globalThis.peernet.has(hash
|
|
1270
|
+
if (!await globalThis.peernet.has(hash))
|
|
1261
1271
|
await globalThis.peernet.put(hash, block.encoded, 'block');
|
|
1262
1272
|
}
|
|
1263
1273
|
return block;
|
|
@@ -1400,7 +1410,7 @@ class State extends Contract {
|
|
|
1400
1410
|
if (this.knownBlocks?.length === Number(lastBlock.index) + 1) {
|
|
1401
1411
|
let promises = [];
|
|
1402
1412
|
promises = await Promise.allSettled(this.knownBlocks.map(async (address) => {
|
|
1403
|
-
const has = await globalThis.peernet.has(address
|
|
1413
|
+
const has = await globalThis.peernet.has(address);
|
|
1404
1414
|
return { has, address };
|
|
1405
1415
|
}));
|
|
1406
1416
|
promises = promises.filter(({ status, value }) => status === 'fulfilled' && !value.has);
|
|
@@ -1430,6 +1440,7 @@ class State extends Contract {
|
|
|
1430
1440
|
let data = await new globalThis.peernet.protos['peernet-request']({ request: 'lastBlock' });
|
|
1431
1441
|
let node = await globalThis.peernet.prepareMessage(data);
|
|
1432
1442
|
for (const peer of globalThis.peernet?.connections) {
|
|
1443
|
+
// @ts-ignore
|
|
1433
1444
|
if (peer.connected && peer.version === this.version) {
|
|
1434
1445
|
const task = async () => {
|
|
1435
1446
|
try {
|
|
@@ -1443,6 +1454,7 @@ class State extends Contract {
|
|
|
1443
1454
|
promises.push(task());
|
|
1444
1455
|
}
|
|
1445
1456
|
}
|
|
1457
|
+
// @ts-ignore
|
|
1446
1458
|
promises = await this.promiseRequests(promises);
|
|
1447
1459
|
let latest = { index: 0, hash: '0x0', previousHash: '0x0' };
|
|
1448
1460
|
promises = promises.sort((a, b) => b.index - a.index);
|
|
@@ -1487,7 +1499,7 @@ class State extends Contract {
|
|
|
1487
1499
|
if (lastTransactions.includes(hash)) {
|
|
1488
1500
|
console.log('removing invalid block');
|
|
1489
1501
|
await globalThis.blockStore.delete(await (await new BlockMessage(block)).hash());
|
|
1490
|
-
blocks.splice(block.index
|
|
1502
|
+
blocks.splice(block.index);
|
|
1491
1503
|
return this.#loadBlocks(blocks);
|
|
1492
1504
|
}
|
|
1493
1505
|
try {
|
|
@@ -1513,6 +1525,7 @@ class State extends Contract {
|
|
|
1513
1525
|
}
|
|
1514
1526
|
}
|
|
1515
1527
|
this.#blocks[block.index - 1].loaded = true;
|
|
1528
|
+
// @ts-ignore
|
|
1516
1529
|
globalThis.debug(`loaded block: ${block.hash} @${block.index}`);
|
|
1517
1530
|
globalThis.pubsub.publish('block-loaded', { ...block });
|
|
1518
1531
|
}
|
|
@@ -1560,7 +1573,7 @@ class State extends Contract {
|
|
|
1560
1573
|
}
|
|
1561
1574
|
|
|
1562
1575
|
globalThis.BigNumber = BigNumber;
|
|
1563
|
-
const ignorelist = [
|
|
1576
|
+
const ignorelist = [];
|
|
1564
1577
|
// check if browser or local
|
|
1565
1578
|
class Chain extends State {
|
|
1566
1579
|
#state;
|
|
@@ -1634,7 +1647,9 @@ class Chain extends State {
|
|
|
1634
1647
|
message: nameServiceMessage
|
|
1635
1648
|
}];
|
|
1636
1649
|
await Promise.all(contracts.map(async ({ address, message }) => {
|
|
1650
|
+
// @ts-ignore
|
|
1637
1651
|
message = await new ContractMessage(Uint8Array.from(message.split(',').map(string => Number(string))));
|
|
1652
|
+
// @ts-ignore
|
|
1638
1653
|
await globalThis.contractStore.put(address, message.encoded);
|
|
1639
1654
|
}));
|
|
1640
1655
|
console.log('handle native contracts');
|
|
@@ -1766,20 +1781,24 @@ class Chain extends State {
|
|
|
1766
1781
|
async #addBlock(block) {
|
|
1767
1782
|
const blockMessage = await new BlockMessage(block);
|
|
1768
1783
|
await Promise.all(blockMessage.decoded.transactions
|
|
1769
|
-
|
|
1784
|
+
// @ts-ignore
|
|
1785
|
+
.map(async (transaction) => transactionPoolStore.delete(transaction.hash)));
|
|
1770
1786
|
const hash = await blockMessage.hash();
|
|
1771
1787
|
await globalThis.blockStore.put(hash, blockMessage.encoded);
|
|
1772
|
-
if (this.lastBlock.index < blockMessage.decoded.index)
|
|
1788
|
+
if (this.lastBlock.index < Number(blockMessage.decoded.index))
|
|
1773
1789
|
await this.updateState(blockMessage);
|
|
1774
1790
|
globalThis.debug(`added block: ${hash}`);
|
|
1775
1791
|
let promises = [];
|
|
1776
1792
|
let contracts = [];
|
|
1777
1793
|
for (let transaction of blockMessage.decoded.transactions) {
|
|
1778
1794
|
// await transactionStore.put(transaction.hash, transaction.encoded)
|
|
1795
|
+
// @ts-ignore
|
|
1779
1796
|
const index = contracts.indexOf(transaction.to);
|
|
1797
|
+
// @ts-ignore
|
|
1780
1798
|
if (index === -1)
|
|
1781
1799
|
contracts.push(transaction.to);
|
|
1782
|
-
// Todo: go trough all accounts
|
|
1800
|
+
// Todo: go trough all accounts
|
|
1801
|
+
// @ts-ignore
|
|
1783
1802
|
promises.push(this.#executeTransaction(transaction));
|
|
1784
1803
|
}
|
|
1785
1804
|
try {
|
|
@@ -1905,7 +1924,7 @@ class Chain extends State {
|
|
|
1905
1924
|
const peer = peers[validator];
|
|
1906
1925
|
if (peer && peer.connected && peer.version === this.version) {
|
|
1907
1926
|
let data = await new BWRequestMessage();
|
|
1908
|
-
const node = await globalThis.peernet.prepareMessage(
|
|
1927
|
+
const node = await globalThis.peernet.prepareMessage(data.encoded);
|
|
1909
1928
|
try {
|
|
1910
1929
|
const bw = await peer.request(node.encoded);
|
|
1911
1930
|
block.validators.push({
|
|
@@ -2010,9 +2029,7 @@ class Chain extends State {
|
|
|
2010
2029
|
return {
|
|
2011
2030
|
sender,
|
|
2012
2031
|
call: this.call,
|
|
2013
|
-
staticCall: this.staticCall
|
|
2014
|
-
delegate: this.delegate,
|
|
2015
|
-
staticDelegate: this.staticDelegate
|
|
2032
|
+
staticCall: this.staticCall
|
|
2016
2033
|
};
|
|
2017
2034
|
}
|
|
2018
2035
|
/**
|
|
@@ -2042,14 +2059,6 @@ class Chain extends State {
|
|
|
2042
2059
|
globalThis.msg = this.#createMessage();
|
|
2043
2060
|
return this.machine.get(contract, method, parameters);
|
|
2044
2061
|
}
|
|
2045
|
-
delegate(contract, method, parameters) {
|
|
2046
|
-
globalThis.msg = this.#createMessage();
|
|
2047
|
-
return this.machine.execute(contract, method, parameters);
|
|
2048
|
-
}
|
|
2049
|
-
staticDelegate(contract, method, parameters) {
|
|
2050
|
-
globalThis.msg = this.#createMessage();
|
|
2051
|
-
return this.machine.get(contract, method, parameters);
|
|
2052
|
-
}
|
|
2053
2062
|
mint(to, amount) {
|
|
2054
2063
|
return this.call(addresses.nativeToken, 'mint', [to, amount]);
|
|
2055
2064
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-
|
|
2
|
-
import './index-
|
|
1
|
+
import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-505084de.js';
|
|
2
|
+
import './index-e8f03811.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @params {String} network
|