@leofcoin/chain 1.7.14 → 1.7.16
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 +29 -14
- package/exports/chain.js +29 -14
- package/package.json +1 -1
package/exports/browser/chain.js
CHANGED
|
@@ -4816,16 +4816,16 @@ class State extends Contract {
|
|
|
4816
4816
|
if (block && !block.loaded) {
|
|
4817
4817
|
try {
|
|
4818
4818
|
let transactions = await this.#loadBlockTransactions([...block.transactions] || []);
|
|
4819
|
-
const lastTransactions = await this.#getLastTransactions()
|
|
4819
|
+
// const lastTransactions = await this.#getLastTransactions()
|
|
4820
4820
|
let priority = [];
|
|
4821
4821
|
for (const transaction of transactions) {
|
|
4822
4822
|
const hash = await transaction.hash();
|
|
4823
|
-
if (lastTransactions.includes(hash)) {
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
}
|
|
4823
|
+
// if (lastTransactions.includes(hash)) {
|
|
4824
|
+
// console.log('removing invalid block')
|
|
4825
|
+
// await globalThis.blockStore.delete(await (await new BlockMessage(block)).hash())
|
|
4826
|
+
// blocks.splice(block.index - 1, 1)
|
|
4827
|
+
// return this.#loadBlocks(blocks)
|
|
4828
|
+
// }
|
|
4829
4829
|
if (transaction.decoded.priority)
|
|
4830
4830
|
priority.push(transaction);
|
|
4831
4831
|
if (poolTransactionKeys.includes(hash))
|
|
@@ -5169,7 +5169,7 @@ class Chain extends VersionControl {
|
|
|
5169
5169
|
async #addBlock(block) {
|
|
5170
5170
|
const blockMessage = await new BlockMessage(block);
|
|
5171
5171
|
const hash = await blockMessage.hash();
|
|
5172
|
-
const
|
|
5172
|
+
const transactions = await Promise.all(blockMessage.decoded.transactions
|
|
5173
5173
|
// @ts-ignore
|
|
5174
5174
|
.map(async (hash) => {
|
|
5175
5175
|
let data;
|
|
@@ -5187,19 +5187,34 @@ class Chain extends VersionControl {
|
|
|
5187
5187
|
debug(`added block: ${hash}`);
|
|
5188
5188
|
let promises = [];
|
|
5189
5189
|
let contracts = [];
|
|
5190
|
-
|
|
5191
|
-
|
|
5190
|
+
const normalTransactions = [];
|
|
5191
|
+
const priorityransactions = [];
|
|
5192
|
+
for (const transaction of transactions) {
|
|
5192
5193
|
if (!contracts.includes(transaction.to)) {
|
|
5193
5194
|
contracts.push(transaction.to);
|
|
5194
5195
|
}
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5196
|
+
if (transaction.priority)
|
|
5197
|
+
priorityransactions.push(transaction);
|
|
5198
|
+
else
|
|
5199
|
+
normalTransactions.push(transaction);
|
|
5198
5200
|
}
|
|
5201
|
+
for (const transaction of priorityransactions.sort((a, b) => a.decoded.nonce - b.decoded.nonce)) {
|
|
5202
|
+
await this.#handleTransaction(transaction, [], block);
|
|
5203
|
+
}
|
|
5204
|
+
await Promise.all(normalTransactions.map((transaction) => this.#handleTransaction(transaction, [], block)));
|
|
5205
|
+
// for (let transaction of transactionsMessages) {
|
|
5206
|
+
// // await transactionStore.put(transaction.hash, transaction.encoded)
|
|
5207
|
+
// if (!contracts.includes(transaction.to)) {
|
|
5208
|
+
// contracts.push(transaction.to)
|
|
5209
|
+
// }
|
|
5210
|
+
// // Todo: go trough all accounts
|
|
5211
|
+
// //@ts-ignore
|
|
5212
|
+
// promises.push(this.#executeTransaction(transaction))
|
|
5213
|
+
// }
|
|
5199
5214
|
try {
|
|
5200
5215
|
promises = await Promise.allSettled(promises);
|
|
5201
5216
|
const noncesByAddress = {};
|
|
5202
|
-
for (let transaction of
|
|
5217
|
+
for (let transaction of transactions) {
|
|
5203
5218
|
globalThis.pubsub.publish('transaction-processed', transaction);
|
|
5204
5219
|
if (transaction.to === globalThis.peernet.selectedAccount)
|
|
5205
5220
|
globalThis.pubsub.publish('account-transaction-processed', transaction);
|
package/exports/chain.js
CHANGED
|
@@ -1183,16 +1183,16 @@ class State extends Contract {
|
|
|
1183
1183
|
if (block && !block.loaded) {
|
|
1184
1184
|
try {
|
|
1185
1185
|
let transactions = await this.#loadBlockTransactions([...block.transactions] || []);
|
|
1186
|
-
const lastTransactions = await this.#getLastTransactions()
|
|
1186
|
+
// const lastTransactions = await this.#getLastTransactions()
|
|
1187
1187
|
let priority = [];
|
|
1188
1188
|
for (const transaction of transactions) {
|
|
1189
1189
|
const hash = await transaction.hash();
|
|
1190
|
-
if (lastTransactions.includes(hash)) {
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
}
|
|
1190
|
+
// if (lastTransactions.includes(hash)) {
|
|
1191
|
+
// console.log('removing invalid block')
|
|
1192
|
+
// await globalThis.blockStore.delete(await (await new BlockMessage(block)).hash())
|
|
1193
|
+
// blocks.splice(block.index - 1, 1)
|
|
1194
|
+
// return this.#loadBlocks(blocks)
|
|
1195
|
+
// }
|
|
1196
1196
|
if (transaction.decoded.priority)
|
|
1197
1197
|
priority.push(transaction);
|
|
1198
1198
|
if (poolTransactionKeys.includes(hash))
|
|
@@ -1536,7 +1536,7 @@ class Chain extends VersionControl {
|
|
|
1536
1536
|
async #addBlock(block) {
|
|
1537
1537
|
const blockMessage = await new BlockMessage(block);
|
|
1538
1538
|
const hash = await blockMessage.hash();
|
|
1539
|
-
const
|
|
1539
|
+
const transactions = await Promise.all(blockMessage.decoded.transactions
|
|
1540
1540
|
// @ts-ignore
|
|
1541
1541
|
.map(async (hash) => {
|
|
1542
1542
|
let data;
|
|
@@ -1554,19 +1554,34 @@ class Chain extends VersionControl {
|
|
|
1554
1554
|
debug(`added block: ${hash}`);
|
|
1555
1555
|
let promises = [];
|
|
1556
1556
|
let contracts = [];
|
|
1557
|
-
|
|
1558
|
-
|
|
1557
|
+
const normalTransactions = [];
|
|
1558
|
+
const priorityransactions = [];
|
|
1559
|
+
for (const transaction of transactions) {
|
|
1559
1560
|
if (!contracts.includes(transaction.to)) {
|
|
1560
1561
|
contracts.push(transaction.to);
|
|
1561
1562
|
}
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1563
|
+
if (transaction.priority)
|
|
1564
|
+
priorityransactions.push(transaction);
|
|
1565
|
+
else
|
|
1566
|
+
normalTransactions.push(transaction);
|
|
1565
1567
|
}
|
|
1568
|
+
for (const transaction of priorityransactions.sort((a, b) => a.decoded.nonce - b.decoded.nonce)) {
|
|
1569
|
+
await this.#handleTransaction(transaction, [], block);
|
|
1570
|
+
}
|
|
1571
|
+
await Promise.all(normalTransactions.map((transaction) => this.#handleTransaction(transaction, [], block)));
|
|
1572
|
+
// for (let transaction of transactionsMessages) {
|
|
1573
|
+
// // await transactionStore.put(transaction.hash, transaction.encoded)
|
|
1574
|
+
// if (!contracts.includes(transaction.to)) {
|
|
1575
|
+
// contracts.push(transaction.to)
|
|
1576
|
+
// }
|
|
1577
|
+
// // Todo: go trough all accounts
|
|
1578
|
+
// //@ts-ignore
|
|
1579
|
+
// promises.push(this.#executeTransaction(transaction))
|
|
1580
|
+
// }
|
|
1566
1581
|
try {
|
|
1567
1582
|
promises = await Promise.allSettled(promises);
|
|
1568
1583
|
const noncesByAddress = {};
|
|
1569
|
-
for (let transaction of
|
|
1584
|
+
for (let transaction of transactions) {
|
|
1570
1585
|
globalThis.pubsub.publish('transaction-processed', transaction);
|
|
1571
1586
|
if (transaction.to === globalThis.peernet.selectedAccount)
|
|
1572
1587
|
globalThis.pubsub.publish('account-transaction-processed', transaction);
|