@leofcoin/chain 1.7.15 → 1.7.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 +31 -7
- package/exports/chain.js +31 -7
- package/package.json +1 -1
package/exports/browser/chain.js
CHANGED
|
@@ -4568,6 +4568,15 @@ class State extends Contract {
|
|
|
4568
4568
|
}
|
|
4569
4569
|
try {
|
|
4570
4570
|
const block = await this.getAndPutBlock(hash);
|
|
4571
|
+
await Promise.all(block.decoded.transactions.map(async (hash) => {
|
|
4572
|
+
// should be in a transaction store already
|
|
4573
|
+
if (!(await transactionStore.has(hash))) {
|
|
4574
|
+
const data = await peernet.get(hash, 'transaction');
|
|
4575
|
+
await transactionStore.put(hash, data);
|
|
4576
|
+
}
|
|
4577
|
+
;
|
|
4578
|
+
(await transactionPoolStore.has(hash)) && (await transactionPoolStore.delete(hash));
|
|
4579
|
+
}));
|
|
4571
4580
|
index = block.decoded.index;
|
|
4572
4581
|
const size = block.encoded.length > 0 ? block.encoded.length : block.encoded.byteLength;
|
|
4573
4582
|
this.#totalSize += size;
|
|
@@ -5169,7 +5178,7 @@ class Chain extends VersionControl {
|
|
|
5169
5178
|
async #addBlock(block) {
|
|
5170
5179
|
const blockMessage = await new BlockMessage(block);
|
|
5171
5180
|
const hash = await blockMessage.hash();
|
|
5172
|
-
const
|
|
5181
|
+
const transactions = await Promise.all(blockMessage.decoded.transactions
|
|
5173
5182
|
// @ts-ignore
|
|
5174
5183
|
.map(async (hash) => {
|
|
5175
5184
|
let data;
|
|
@@ -5187,19 +5196,34 @@ class Chain extends VersionControl {
|
|
|
5187
5196
|
debug(`added block: ${hash}`);
|
|
5188
5197
|
let promises = [];
|
|
5189
5198
|
let contracts = [];
|
|
5190
|
-
|
|
5191
|
-
|
|
5199
|
+
const normalTransactions = [];
|
|
5200
|
+
const priorityransactions = [];
|
|
5201
|
+
for (const transaction of transactions) {
|
|
5192
5202
|
if (!contracts.includes(transaction.to)) {
|
|
5193
5203
|
contracts.push(transaction.to);
|
|
5194
5204
|
}
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5205
|
+
if (transaction.priority)
|
|
5206
|
+
priorityransactions.push(transaction);
|
|
5207
|
+
else
|
|
5208
|
+
normalTransactions.push(transaction);
|
|
5198
5209
|
}
|
|
5210
|
+
for (const transaction of priorityransactions.sort((a, b) => a.decoded.nonce - b.decoded.nonce)) {
|
|
5211
|
+
await this.#handleTransaction(transaction, [], block);
|
|
5212
|
+
}
|
|
5213
|
+
await Promise.all(normalTransactions.map((transaction) => this.#handleTransaction(transaction, [], block)));
|
|
5214
|
+
// for (let transaction of transactionsMessages) {
|
|
5215
|
+
// // await transactionStore.put(transaction.hash, transaction.encoded)
|
|
5216
|
+
// if (!contracts.includes(transaction.to)) {
|
|
5217
|
+
// contracts.push(transaction.to)
|
|
5218
|
+
// }
|
|
5219
|
+
// // Todo: go trough all accounts
|
|
5220
|
+
// //@ts-ignore
|
|
5221
|
+
// promises.push(this.#executeTransaction(transaction))
|
|
5222
|
+
// }
|
|
5199
5223
|
try {
|
|
5200
5224
|
promises = await Promise.allSettled(promises);
|
|
5201
5225
|
const noncesByAddress = {};
|
|
5202
|
-
for (let transaction of
|
|
5226
|
+
for (let transaction of transactions) {
|
|
5203
5227
|
globalThis.pubsub.publish('transaction-processed', transaction);
|
|
5204
5228
|
if (transaction.to === globalThis.peernet.selectedAccount)
|
|
5205
5229
|
globalThis.pubsub.publish('account-transaction-processed', transaction);
|
package/exports/chain.js
CHANGED
|
@@ -935,6 +935,15 @@ class State extends Contract {
|
|
|
935
935
|
}
|
|
936
936
|
try {
|
|
937
937
|
const block = await this.getAndPutBlock(hash);
|
|
938
|
+
await Promise.all(block.decoded.transactions.map(async (hash) => {
|
|
939
|
+
// should be in a transaction store already
|
|
940
|
+
if (!(await transactionStore.has(hash))) {
|
|
941
|
+
const data = await peernet.get(hash, 'transaction');
|
|
942
|
+
await transactionStore.put(hash, data);
|
|
943
|
+
}
|
|
944
|
+
;
|
|
945
|
+
(await transactionPoolStore.has(hash)) && (await transactionPoolStore.delete(hash));
|
|
946
|
+
}));
|
|
938
947
|
index = block.decoded.index;
|
|
939
948
|
const size = block.encoded.length > 0 ? block.encoded.length : block.encoded.byteLength;
|
|
940
949
|
this.#totalSize += size;
|
|
@@ -1536,7 +1545,7 @@ class Chain extends VersionControl {
|
|
|
1536
1545
|
async #addBlock(block) {
|
|
1537
1546
|
const blockMessage = await new BlockMessage(block);
|
|
1538
1547
|
const hash = await blockMessage.hash();
|
|
1539
|
-
const
|
|
1548
|
+
const transactions = await Promise.all(blockMessage.decoded.transactions
|
|
1540
1549
|
// @ts-ignore
|
|
1541
1550
|
.map(async (hash) => {
|
|
1542
1551
|
let data;
|
|
@@ -1554,19 +1563,34 @@ class Chain extends VersionControl {
|
|
|
1554
1563
|
debug(`added block: ${hash}`);
|
|
1555
1564
|
let promises = [];
|
|
1556
1565
|
let contracts = [];
|
|
1557
|
-
|
|
1558
|
-
|
|
1566
|
+
const normalTransactions = [];
|
|
1567
|
+
const priorityransactions = [];
|
|
1568
|
+
for (const transaction of transactions) {
|
|
1559
1569
|
if (!contracts.includes(transaction.to)) {
|
|
1560
1570
|
contracts.push(transaction.to);
|
|
1561
1571
|
}
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1572
|
+
if (transaction.priority)
|
|
1573
|
+
priorityransactions.push(transaction);
|
|
1574
|
+
else
|
|
1575
|
+
normalTransactions.push(transaction);
|
|
1565
1576
|
}
|
|
1577
|
+
for (const transaction of priorityransactions.sort((a, b) => a.decoded.nonce - b.decoded.nonce)) {
|
|
1578
|
+
await this.#handleTransaction(transaction, [], block);
|
|
1579
|
+
}
|
|
1580
|
+
await Promise.all(normalTransactions.map((transaction) => this.#handleTransaction(transaction, [], block)));
|
|
1581
|
+
// for (let transaction of transactionsMessages) {
|
|
1582
|
+
// // await transactionStore.put(transaction.hash, transaction.encoded)
|
|
1583
|
+
// if (!contracts.includes(transaction.to)) {
|
|
1584
|
+
// contracts.push(transaction.to)
|
|
1585
|
+
// }
|
|
1586
|
+
// // Todo: go trough all accounts
|
|
1587
|
+
// //@ts-ignore
|
|
1588
|
+
// promises.push(this.#executeTransaction(transaction))
|
|
1589
|
+
// }
|
|
1566
1590
|
try {
|
|
1567
1591
|
promises = await Promise.allSettled(promises);
|
|
1568
1592
|
const noncesByAddress = {};
|
|
1569
|
-
for (let transaction of
|
|
1593
|
+
for (let transaction of transactions) {
|
|
1570
1594
|
globalThis.pubsub.publish('transaction-processed', transaction);
|
|
1571
1595
|
if (transaction.to === globalThis.peernet.selectedAccount)
|
|
1572
1596
|
globalThis.pubsub.publish('account-transaction-processed', transaction);
|