@leofcoin/chain 1.4.90 → 1.4.92

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.
@@ -2219,7 +2219,7 @@ class State extends Contract {
2219
2219
  #loadBlockTransactions = (transactions) => Promise.all(transactions.map((transaction) => new TransactionMessage(transaction)));
2220
2220
  #getLastTransactions = async () => {
2221
2221
  let lastTransactions = (await Promise.all(this.#blocks.filter(block => block.loaded).slice(-128)
2222
- .map(block => this.#loadBlockTransactions(block))))
2222
+ .map(block => this.#loadBlockTransactions(block.transactions))))
2223
2223
  .reduce((all, transactions) => [...all, ...transactions], []);
2224
2224
  return Promise.all(lastTransactions.map(transaction => transaction.hash()));
2225
2225
  };
@@ -2233,8 +2233,8 @@ class State extends Contract {
2233
2233
  if (block && !block.loaded) {
2234
2234
  if (block.index === 0)
2235
2235
  this.#loaded = true;
2236
- block.transactions = await this.#loadBlockTransactions(block.transactions);
2237
- for (const transaction of block.transactions) {
2236
+ const transactions = await this.#loadBlockTransactions([...block.transactions] || []);
2237
+ for (const transaction of transactions) {
2238
2238
  const lastTransactions = await this.#getLastTransactions();
2239
2239
  const hash = await transaction.hash();
2240
2240
  if (poolTransactionKeys.includes(hash))
@@ -2242,23 +2242,25 @@ class State extends Contract {
2242
2242
  if (lastTransactions.includes(hash)) {
2243
2243
  console.log('removing invalid block');
2244
2244
  await globalThis.blockStore.delete(await (await new BlockMessage(block)).hash());
2245
+ blocks.splice(block.index - 1);
2245
2246
  return this.#loadBlocks(blocks);
2246
2247
  }
2247
2248
  try {
2248
- await this.#machine.execute(transaction.to, transaction.method, transaction.params);
2249
- if (transaction.to === nativeToken$2) {
2249
+ await this.#machine.execute(transaction.decoded.to, transaction.decoded.method, transaction.decoded.params);
2250
+ if (transaction.decoded.to === nativeToken$2) {
2250
2251
  this.#nativeCalls += 1;
2251
- if (transaction.method === 'burn')
2252
+ if (transaction.decoded.method === 'burn')
2252
2253
  this.#nativeBurns += 1;
2253
- if (transaction.method === 'mint')
2254
+ if (transaction.decoded.method === 'mint')
2254
2255
  this.#nativeMints += 1;
2255
- if (transaction.method === 'transfer')
2256
+ if (transaction.decoded.method === 'transfer')
2256
2257
  this.#nativeTransfers += 1;
2257
2258
  }
2258
2259
  this.#totalTransactions += 1;
2259
2260
  }
2260
2261
  catch (error) {
2261
- await globalThis.transactionPoolStore.delete(transaction.hash ? transaction.hash : await (new TransactionMessage(transaction)).hash());
2262
+ console.log(error);
2263
+ await globalThis.transactionPoolStore.delete(hash);
2262
2264
  console.log('removing invalid transaction');
2263
2265
  console.log(error);
2264
2266
  return false;
@@ -2282,7 +2284,6 @@ class State extends Contract {
2282
2284
  clearTimeout(timeout);
2283
2285
  if (promises.length > 0) {
2284
2286
  promises = promises.map(async ({ value }) => {
2285
- console.log(value);
2286
2287
  const node = await new globalThis.peernet.protos['peernet-response'](value.result);
2287
2288
  return { value: node.decoded.response, peer: value.peer };
2288
2289
  });
@@ -2685,7 +2686,6 @@ class Chain extends State {
2685
2686
  // block.reward = block.reward.toString()
2686
2687
  // block.fees = block.fees.toString()
2687
2688
  try {
2688
- console.log(block.transactions);
2689
2689
  block.transactions = await Promise.all(block.transactions
2690
2690
  .map(async (transaction) => {
2691
2691
  await globalThis.transactionPoolStore.delete(await transaction.hash());
package/exports/chain.js CHANGED
@@ -839,7 +839,7 @@ class State extends Contract {
839
839
  #loadBlockTransactions = (transactions) => Promise.all(transactions.map((transaction) => new TransactionMessage(transaction)));
840
840
  #getLastTransactions = async () => {
841
841
  let lastTransactions = (await Promise.all(this.#blocks.filter(block => block.loaded).slice(-128)
842
- .map(block => this.#loadBlockTransactions(block))))
842
+ .map(block => this.#loadBlockTransactions(block.transactions))))
843
843
  .reduce((all, transactions) => [...all, ...transactions], []);
844
844
  return Promise.all(lastTransactions.map(transaction => transaction.hash()));
845
845
  };
@@ -853,8 +853,8 @@ class State extends Contract {
853
853
  if (block && !block.loaded) {
854
854
  if (block.index === 0)
855
855
  this.#loaded = true;
856
- block.transactions = await this.#loadBlockTransactions(block.transactions);
857
- for (const transaction of block.transactions) {
856
+ const transactions = await this.#loadBlockTransactions([...block.transactions] || []);
857
+ for (const transaction of transactions) {
858
858
  const lastTransactions = await this.#getLastTransactions();
859
859
  const hash = await transaction.hash();
860
860
  if (poolTransactionKeys.includes(hash))
@@ -862,23 +862,25 @@ class State extends Contract {
862
862
  if (lastTransactions.includes(hash)) {
863
863
  console.log('removing invalid block');
864
864
  await globalThis.blockStore.delete(await (await new BlockMessage(block)).hash());
865
+ blocks.splice(block.index - 1);
865
866
  return this.#loadBlocks(blocks);
866
867
  }
867
868
  try {
868
- await this.#machine.execute(transaction.to, transaction.method, transaction.params);
869
- if (transaction.to === nativeToken) {
869
+ await this.#machine.execute(transaction.decoded.to, transaction.decoded.method, transaction.decoded.params);
870
+ if (transaction.decoded.to === nativeToken) {
870
871
  this.#nativeCalls += 1;
871
- if (transaction.method === 'burn')
872
+ if (transaction.decoded.method === 'burn')
872
873
  this.#nativeBurns += 1;
873
- if (transaction.method === 'mint')
874
+ if (transaction.decoded.method === 'mint')
874
875
  this.#nativeMints += 1;
875
- if (transaction.method === 'transfer')
876
+ if (transaction.decoded.method === 'transfer')
876
877
  this.#nativeTransfers += 1;
877
878
  }
878
879
  this.#totalTransactions += 1;
879
880
  }
880
881
  catch (error) {
881
- await globalThis.transactionPoolStore.delete(transaction.hash ? transaction.hash : await (new TransactionMessage(transaction)).hash());
882
+ console.log(error);
883
+ await globalThis.transactionPoolStore.delete(hash);
882
884
  console.log('removing invalid transaction');
883
885
  console.log(error);
884
886
  return false;
@@ -902,7 +904,6 @@ class State extends Contract {
902
904
  clearTimeout(timeout);
903
905
  if (promises.length > 0) {
904
906
  promises = promises.map(async ({ value }) => {
905
- console.log(value);
906
907
  const node = await new globalThis.peernet.protos['peernet-response'](value.result);
907
908
  return { value: node.decoded.response, peer: value.peer };
908
909
  });
@@ -1305,7 +1306,6 @@ class Chain extends State {
1305
1306
  // block.reward = block.reward.toString()
1306
1307
  // block.fees = block.fees.toString()
1307
1308
  try {
1308
- console.log(block.transactions);
1309
1309
  block.transactions = await Promise.all(block.transactions
1310
1310
  .map(async (transaction) => {
1311
1311
  await globalThis.transactionPoolStore.delete(await transaction.hash());
@@ -1,2 +1,22 @@
1
1
  export type Address = base58String;
2
2
  export type BlockHash = base58String;
3
+ interface Transaction {
4
+ to: Address;
5
+ from: Address;
6
+ method: String;
7
+ params: string[];
8
+ nonce: Number;
9
+ }
10
+ interface RawTransaction extends Transaction {
11
+ timestamp: Number;
12
+ }
13
+ export declare type BlockInMemory = {
14
+ index: number;
15
+ transactions: RawTransaction[];
16
+ loaded?: Boolean;
17
+ };
18
+ export declare type RawBlock = {
19
+ index: number;
20
+ transactions: RawTransaction[];
21
+ };
22
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.4.90",
3
+ "version": "1.4.92",
4
4
  "description": "Official javascript implementation",
5
5
  "exports": {
6
6
  "./node": "./exports/node.js",