@leofcoin/chain 1.4.80 → 1.4.82

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/chain.js CHANGED
@@ -83,7 +83,7 @@ class Transaction extends Protocol {
83
83
  transactions = transactions.filter(tx => tx.decoded.from === address);
84
84
  transactions = await this.promiseTransactionsContent(transactions);
85
85
  if (this.lastBlock?.hash && transactions.length === 0 && this.lastBlock.hash !== '0x0') {
86
- let block = await peernet.get(this.lastBlock.hash);
86
+ let block = await peernet.get(this.lastBlock.hash, 'block');
87
87
  block = await new BlockMessage(block);
88
88
  // for (let tx of block.decoded?.transactions) {
89
89
  // tx = await peernet.get(tx, 'transaction')
@@ -163,18 +163,24 @@ class Transaction extends Protocol {
163
163
  throw new Error(`transaction not signed`);
164
164
  if (message.decoded.nonce === undefined)
165
165
  throw new Error(`nonce required`);
166
+ await this.validateNonce(message.decoded.from, message.decoded.nonce);
167
+ // todo check if signature is valid
168
+ const hash = await message.hash();
166
169
  try {
167
- await this.validateNonce(message.decoded.from, message.decoded.nonce);
168
- // todo check if signature is valid
169
- const hash = await message.hash();
170
170
  let data;
171
171
  const wait = new Promise(async (resolve, reject) => {
172
172
  if (pubsub.subscribers[`transaction.completed.${hash}`]) {
173
173
  const result = pubsub.subscribers[`transaction.completed.${hash}`].value;
174
+ if (result.status !== 'fulfilled') {
175
+ await transactionPoolStore.delete(hash);
176
+ }
174
177
  result.status === 'fulfilled' ? resolve(result.hash) : reject({ hash: result.hash, error: result.error });
175
178
  }
176
179
  else {
177
180
  const completed = async (result) => {
181
+ if (result.status !== 'fulfilled') {
182
+ await transactionPoolStore.delete(hash);
183
+ }
178
184
  result.status === 'fulfilled' ? resolve(result.hash) : reject({ hash: result.hash, error: result.error });
179
185
  setTimeout(async () => {
180
186
  pubsub.unsubscribe(`transaction.completed.${hash}`, completed);
@@ -189,6 +195,8 @@ class Transaction extends Protocol {
189
195
  return { hash, data, fee: await calculateFee(message.decoded), wait, message };
190
196
  }
191
197
  catch (error) {
198
+ console.log('remo');
199
+ await transactionPoolStore.delete(hash);
192
200
  throw error;
193
201
  }
194
202
  }
@@ -198,269 +206,250 @@ class Transaction extends Protocol {
198
206
  * @extends {Transaction}
199
207
  */
200
208
  class Contract extends Transaction {
201
- constructor() {
202
- super();
203
- }
204
-
205
- async init() {
206
-
207
- }
208
-
209
- /**
210
- *
211
- * @param {Address} creator
212
- * @param {String} contract
213
- * @param {Array} constructorParameters
214
- * @returns lib.createContractMessage
215
- */
216
- async createContractMessage(creator, contract, constructorParameters = []) {
217
- return createContractMessage(creator, contract, constructorParameters)
218
- }
219
-
220
- /**
221
- *
222
- * @param {Address} creator
223
- * @param {String} contract
224
- * @param {Array} constructorParameters
225
- * @returns {Address}
226
- */
227
- async createContractAddress(creator, contract, constructorParameters = []) {
228
- contract = await this.createContractMessage(creator, contract, constructorParameters);
229
- return contract.hash()
230
- }
231
-
232
- /**
233
- *
234
- * @param {String} contract
235
- * @param {Array} parameters
236
- * @returns
237
- */
238
- async deployContract(contract, constructorParameters = []) {
239
- const message = await createContractMessage(peernet.selectedAccount, contract, constructorParameters);
240
- try {
241
- await contractStore.put(await message.hash(), message.encoded);
242
- } catch (error) {
243
- throw error
244
- }
245
- return this.createTransactionFrom(peernet.selectedAccount, addresses.contractFactory, 'registerContract', [await message.hash()])
246
- }
247
-
248
- async deployContractMessage(message) {
249
-
250
- }
251
-
252
-
209
+ constructor() {
210
+ super();
211
+ }
212
+ async init() {
213
+ }
214
+ /**
215
+ *
216
+ * @param {Address} creator
217
+ * @param {String} contract
218
+ * @param {Array} constructorParameters
219
+ * @returns lib.createContractMessage
220
+ */
221
+ async createContractMessage(creator, contract, constructorParameters = []) {
222
+ return createContractMessage(creator, contract, constructorParameters);
223
+ }
224
+ /**
225
+ *
226
+ * @param {Address} creator
227
+ * @param {String} contract
228
+ * @param {Array} constructorParameters
229
+ * @returns {Address}
230
+ */
231
+ async createContractAddress(creator, contract, constructorParameters = []) {
232
+ contract = await this.createContractMessage(creator, contract, constructorParameters);
233
+ return contract.hash();
234
+ }
235
+ /**
236
+ *
237
+ * @param {String} contract
238
+ * @param {Array} parameters
239
+ * @returns
240
+ */
241
+ async deployContract(contract, constructorParameters = []) {
242
+ const message = await createContractMessage(peernet.selectedAccount, contract, constructorParameters);
243
+ try {
244
+ await contractStore.put(await message.hash(), message.encoded);
245
+ }
246
+ catch (error) {
247
+ throw error;
248
+ }
249
+ return this.createTransactionFrom(peernet.selectedAccount, addresses.contractFactory, 'registerContract', [await message.hash()]);
250
+ }
251
+ async deployContractMessage(message) {
252
+ }
253
253
  }
254
254
 
255
255
  // import State from './state'
256
-
257
256
  class Machine {
258
- #contracts = {}
259
- #nonces = {}
260
- lastBlock = {index: 0, hash: '0x0', previousHash: '0x0'}
261
-
262
- constructor(blocks) {
263
- return this.#init(blocks)
264
- }
265
-
266
- #createMessage(sender = peernet.selectedAccount) {
267
- return {
268
- sender,
269
- call: this.execute,
270
- staticCall: this.get.bind(this)
257
+ #contracts = {};
258
+ #nonces = {};
259
+ lastBlock = { index: 0, hash: '0x0', previousHash: '0x0' };
260
+ constructor(blocks) {
261
+ return this.#init(blocks);
271
262
  }
272
- }
273
-
274
- async #onmessage(data) {
275
- switch (data.type) {
276
- case 'contractError': {
277
- console.warn(`removing contract ${await data.hash()}`);
278
- await contractStore.delete(await data.hash());
279
- break
280
- }
281
-
282
- case 'initError': {
283
- console.error(`init error: ${data.message}`);
284
- break
285
- }
286
-
287
- case 'executionError': {
288
- // console.warn(`error executing transaction ${data.message}`);
289
- pubsub.publish(data.id, {error: data.message});
290
- break
291
- }
292
-
293
- case 'debug': {
294
- for (const message of data.messages) debug(message);
295
- break
296
- }
297
- case 'machine-ready': {
298
- this.lastBlock = data.lastBlock;
299
- pubsub.publish('machine.ready', true);
300
- break
301
- }
302
- case 'response': {
303
- pubsub.publish(data.id, data.value || false);
304
- break
305
- }
306
- }
307
-
308
- }
309
-
310
- async #init(blocks) {
311
- return new Promise(async (resolve) => {
312
- const machineReady = () => {
313
- pubsub.unsubscribe('machine.ready', machineReady);
314
- resolve(this);
315
- };
316
- pubsub.subscribe('machine.ready', machineReady);
317
-
318
- this.worker = await new EasyWorker('node_modules/@leofcoin/workers/src/machine-worker.js', {serialization: 'advanced', type:'module'});
319
- this.worker.onmessage(this.#onmessage.bind(this));
320
- // const blocks = await blockStore.values()
321
- const contracts = await Promise.all([
322
- contractStore.get(contractFactory),
323
- contractStore.get(nativeToken),
324
- contractStore.get(validators),
325
- contractStore.get(nameService)
326
- ]);
327
-
328
- const message = {
329
- type: 'init',
330
- input: {
331
- contracts,
332
- blocks,
333
- peerid: peernet.peerId
334
- }
335
- };
336
- this.worker.postMessage(message);
337
- })
338
-
339
- }
340
-
341
- async #runContract(contractMessage) {
342
- const hash = await contractMessage.hash();
343
- return new Promise((resolve, reject) => {
344
- const id = randombytes(20).toString('hex');
345
- const onmessage = message => {
346
- pubsub.unsubscribe(id, onmessage);
347
- if (message?.error) reject(message.error);
348
- else resolve(message);
349
- };
350
- pubsub.subscribe(id, onmessage);
351
- this.worker.postMessage({
352
- type: 'run',
353
- id,
354
- input: {
355
- decoded: contractMessage.decoded,
356
- encoded: contractMessage.encoded,
357
- hash
358
- }
359
- });
360
- })
361
-
362
- }
363
-
364
- /**
365
- *
366
- * @param {Address} contract
367
- * @param {String} method
368
- * @param {Array} parameters
369
- * @returns Promise<message>
370
- */
371
- async execute(contract, method, parameters) {
372
- try {
373
- if (contract === contractFactory && method === 'registerContract') {
374
- if (await this.has(parameters[0])) throw new Error(`duplicate contract @${parameters[0]}`)
375
- let message;
376
- if (!await contractStore.has(parameters[0])) {
377
- message = await peernet.get(parameters[0], 'contract');
378
- message = await new ContractMessage(message);
379
- await contractStore.put(await message.hash(), message.encoded);
380
- }
381
- if (!message) {
382
- message = await contractStore.get(parameters[0]);
383
- message = await new ContractMessage(message);
384
- }
385
- if (!await this.has(await message.hash())) await this.#runContract(message);
386
- }
387
- } catch (error) {
388
- throw new Error(`contract deployment failed for ${parameters[0]}\n${error.message}`)
389
- }
390
- return new Promise((resolve, reject) => {
391
- const id = randombytes(20).toString('hex');
392
- const onmessage = message => {
393
- pubsub.unsubscribe(id, onmessage);
394
- if (message?.error) reject(message.error);
395
- else resolve(message);
396
- };
397
- pubsub.subscribe(id, onmessage);
398
- this.worker.postMessage({
399
- type: 'execute',
400
- id,
401
- input: {
402
- contract,
403
- method,
404
- params: parameters
263
+ #createMessage(sender = peernet.selectedAccount) {
264
+ return {
265
+ sender,
266
+ call: this.execute,
267
+ staticCall: this.get.bind(this)
268
+ };
269
+ }
270
+ async #onmessage(data) {
271
+ switch (data.type) {
272
+ case 'contractError': {
273
+ console.warn(`removing contract ${await data.hash()}`);
274
+ await contractStore.delete(await data.hash());
275
+ break;
276
+ }
277
+ case 'initError': {
278
+ console.error(`init error: ${data.message}`);
279
+ break;
280
+ }
281
+ case 'executionError': {
282
+ // console.warn(`error executing transaction ${data.message}`);
283
+ pubsub.publish(data.id, { error: data.message });
284
+ break;
285
+ }
286
+ case 'debug': {
287
+ for (const message of data.messages)
288
+ debug(message);
289
+ break;
290
+ }
291
+ case 'machine-ready': {
292
+ this.lastBlock = data.lastBlock;
293
+ pubsub.publish('machine.ready', true);
294
+ break;
295
+ }
296
+ case 'response': {
297
+ pubsub.publish(data.id, data.value || false);
298
+ break;
299
+ }
405
300
  }
406
- });
407
- })
408
-
409
- }
410
-
411
- get(contract, method, parameters) {
412
- return new Promise((resolve, reject) => {
413
- const id = randombytes(20).toString();
414
- const onmessage = message => {
415
- pubsub.unsubscribe(id, onmessage);
416
- resolve(message);
417
- };
418
- pubsub.subscribe(id, onmessage);
419
- this.worker.postMessage({
420
- type: 'get',
421
- id,
422
- input: {
423
- contract,
424
- method,
425
- params: parameters
301
+ }
302
+ async #init(blocks) {
303
+ return new Promise(async (resolve) => {
304
+ const machineReady = () => {
305
+ pubsub.unsubscribe('machine.ready', machineReady);
306
+ resolve(this);
307
+ };
308
+ pubsub.subscribe('machine.ready', machineReady);
309
+ this.worker = await new EasyWorker('node_modules/@leofcoin/workers/src/machine-worker.js', { serialization: 'advanced', type: 'module' });
310
+ this.worker.onmessage(this.#onmessage.bind(this));
311
+ // const blocks = await blockStore.values()
312
+ const contracts = await Promise.all([
313
+ contractStore.get(contractFactory),
314
+ contractStore.get(nativeToken),
315
+ contractStore.get(validators),
316
+ contractStore.get(nameService)
317
+ ]);
318
+ const message = {
319
+ type: 'init',
320
+ input: {
321
+ contracts,
322
+ blocks,
323
+ peerid: peernet.peerId
324
+ }
325
+ };
326
+ this.worker.postMessage(message);
327
+ });
328
+ }
329
+ async #runContract(contractMessage) {
330
+ const hash = await contractMessage.hash();
331
+ return new Promise((resolve, reject) => {
332
+ const id = randombytes(20).toString('hex');
333
+ const onmessage = message => {
334
+ pubsub.unsubscribe(id, onmessage);
335
+ if (message?.error)
336
+ reject(message.error);
337
+ else
338
+ resolve(message);
339
+ };
340
+ pubsub.subscribe(id, onmessage);
341
+ this.worker.postMessage({
342
+ type: 'run',
343
+ id,
344
+ input: {
345
+ decoded: contractMessage.decoded,
346
+ encoded: contractMessage.encoded,
347
+ hash
348
+ }
349
+ });
350
+ });
351
+ }
352
+ /**
353
+ *
354
+ * @param {Address} contract
355
+ * @param {String} method
356
+ * @param {Array} parameters
357
+ * @returns Promise<message>
358
+ */
359
+ async execute(contract, method, parameters) {
360
+ try {
361
+ if (contract === contractFactory && method === 'registerContract') {
362
+ if (await this.has(parameters[0]))
363
+ throw new Error(`duplicate contract @${parameters[0]}`);
364
+ let message;
365
+ if (!await contractStore.has(parameters[0])) {
366
+ message = await peernet.get(parameters[0], 'contract');
367
+ message = await new ContractMessage(message);
368
+ await contractStore.put(await message.hash(), message.encoded);
369
+ }
370
+ if (!message) {
371
+ message = await contractStore.get(parameters[0]);
372
+ message = await new ContractMessage(message);
373
+ }
374
+ if (!await this.has(await message.hash()))
375
+ await this.#runContract(message);
376
+ }
426
377
  }
427
- });
428
- })
429
- }
430
-
431
-
432
- async has(address) {
433
- return new Promise((resolve, reject) => {
434
- const id = randombytes(20).toString('hex');
435
- const onmessage = message => {
436
- pubsub.unsubscribe(id, onmessage);
437
- if (message?.error) reject(message.error);
438
- else resolve(message);
439
- };
440
- pubsub.subscribe(id, onmessage);
441
- this.worker.postMessage({
442
- type: 'has',
443
- id,
444
- input: {
445
- address
378
+ catch (error) {
379
+ throw new Error(`contract deployment failed for ${parameters[0]}\n${error.message}`);
446
380
  }
447
- });
448
- })
449
- }
450
-
451
- async delete(hash) {
452
- return contractStore.delete(hash)
453
- }
454
-
455
- /**
456
- *
457
- * @returns Promise
458
- */
459
- async deleteAll() {
460
- let hashes = await contractStore.get();
461
- hashes = Object.keys(hashes).map(hash => this.delete(hash));
462
- return Promise.all(hashes)
463
- }
381
+ return new Promise((resolve, reject) => {
382
+ const id = randombytes(20).toString('hex');
383
+ const onmessage = message => {
384
+ pubsub.unsubscribe(id, onmessage);
385
+ if (message?.error)
386
+ reject(message.error);
387
+ else
388
+ resolve(message);
389
+ };
390
+ pubsub.subscribe(id, onmessage);
391
+ this.worker.postMessage({
392
+ type: 'execute',
393
+ id,
394
+ input: {
395
+ contract,
396
+ method,
397
+ params: parameters
398
+ }
399
+ });
400
+ });
401
+ }
402
+ get(contract, method, parameters) {
403
+ return new Promise((resolve, reject) => {
404
+ const id = randombytes(20).toString();
405
+ const onmessage = message => {
406
+ pubsub.unsubscribe(id, onmessage);
407
+ resolve(message);
408
+ };
409
+ pubsub.subscribe(id, onmessage);
410
+ this.worker.postMessage({
411
+ type: 'get',
412
+ id,
413
+ input: {
414
+ contract,
415
+ method,
416
+ params: parameters
417
+ }
418
+ });
419
+ });
420
+ }
421
+ async has(address) {
422
+ return new Promise((resolve, reject) => {
423
+ const id = randombytes(20).toString('hex');
424
+ const onmessage = message => {
425
+ pubsub.unsubscribe(id, onmessage);
426
+ if (message?.error)
427
+ reject(message.error);
428
+ else
429
+ resolve(message);
430
+ };
431
+ pubsub.subscribe(id, onmessage);
432
+ this.worker.postMessage({
433
+ type: 'has',
434
+ id,
435
+ input: {
436
+ address
437
+ }
438
+ });
439
+ });
440
+ }
441
+ async delete(hash) {
442
+ return contractStore.delete(hash);
443
+ }
444
+ /**
445
+ *
446
+ * @returns Promise
447
+ */
448
+ async deleteAll() {
449
+ let hashes = await contractStore.get();
450
+ hashes = Object.keys(hashes).map(hash => this.delete(hash));
451
+ return Promise.all(hashes);
452
+ }
464
453
  }
465
454
 
466
455
  class Jobber {
@@ -596,9 +585,17 @@ class State extends Contract {
596
585
  }
597
586
  catch (error) {
598
587
  console.log({ e: error });
588
+ console.log({ e: error });
599
589
  }
600
590
  globalThis.pubsub.publish('lastBlock', this.lastBlock);
601
591
  // load local blocks
592
+ try {
593
+ this.knownBlocks = await blockStore.keys();
594
+ }
595
+ catch (error) {
596
+ console.error(error);
597
+ throw error;
598
+ }
602
599
  await this.resolveBlocks();
603
600
  this.#machine = await new Machine(this.#blocks);
604
601
  await this.#loadBlocks(this.#blocks);
@@ -844,6 +841,8 @@ class State extends Contract {
844
841
  this.#totalTransactions += 1;
845
842
  }
846
843
  catch (error) {
844
+ await globalThis.transactionPoolStore.delete(transaction.hash ? transaction.hash : await (new TransactionMessage(transaction)).hash());
845
+ console.log('removing invalid transaction');
847
846
  console.log(error);
848
847
  return false;
849
848
  }
@@ -897,6 +896,7 @@ class State extends Contract {
897
896
  }
898
897
 
899
898
  globalThis.BigNumber = BigNumber;
899
+ const ignorelist = ['BA5XUACBBBAT653LT3GHP2Z5SUHVCA42BP6IBFBJACHOZIHHR4DUPG2XMB', 'BA5XUACK6K5XA5P4BHRZ4SZT6FCLO6GLGCLUAD62WBPVLFK73RHZZUFLEG'];
900
900
  // check if browser or local
901
901
  class Chain extends State {
902
902
  #state;
@@ -939,6 +939,7 @@ class Chain extends State {
939
939
  }
940
940
  catch (error) {
941
941
  console.error(error);
942
+ console.log('ttttt');
942
943
  }
943
944
  const end = Date.now();
944
945
  console.log(((end - start) / 1000) + ' s');
@@ -969,7 +970,7 @@ class Chain extends State {
969
970
  console.log('handle native contracts');
970
971
  // handle native contracts
971
972
  }
972
- async #clearPool() {
973
+ async clearPool() {
973
974
  await globalThis.transactionPoolStore.clear();
974
975
  }
975
976
  async #init() {
@@ -1018,7 +1019,7 @@ class Chain extends State {
1018
1019
  globalThis.pubsub.subscribe('peer:connected', this.#peerConnected.bind(this));
1019
1020
  // todo some functions rely on state
1020
1021
  await super.init();
1021
- globalThis.globalThis.pubsub.publish('chain:ready', true);
1022
+ globalThis.pubsub.publish('chain:ready', true);
1022
1023
  return this;
1023
1024
  }
1024
1025
  async #invalidTransaction(hash) {
@@ -1053,9 +1054,10 @@ class Chain extends State {
1053
1054
  console.log({ transactionsInPool });
1054
1055
  const transactionsToGet = [];
1055
1056
  for (const key of transactionsInPool) {
1056
- if (!transactions.includes(key))
1057
- transactionsToGet.push(transactionPoolStore.put(key, (await peernet.get(key))));
1057
+ if (!transactions.includes(key) && !ignorelist.includes(key))
1058
+ transactionsToGet.push(transactionPoolStore.put(key, (await peernet.get(key, 'transaction'))));
1058
1059
  }
1060
+ console.log(await transactionPoolStore.keys());
1059
1061
  await Promise.all(transactionsToGet);
1060
1062
  if (Object.keys(lastBlock).length > 0) {
1061
1063
  if (!this.lastBlock || !this.blocks[this.blocks.length - 1]?.loaded || lastBlock && lastBlock.index > this.lastBlock?.index || !this.loaded && !this.resolving) {
@@ -1085,7 +1087,7 @@ class Chain extends State {
1085
1087
  return result || 'no state change';
1086
1088
  }
1087
1089
  catch (error) {
1088
- console.log({ error });
1090
+ await transactionPoolStore.delete(hash);
1089
1091
  globalThis.peernet.publish('invalid-transaction', hash);
1090
1092
  globalThis.pubsub.publish(`transaction.completed.${hash}`, { status: 'fail', hash, error: error });
1091
1093
  throw { error, hash, from, to, params, nonce };
@@ -1127,6 +1129,9 @@ class Chain extends State {
1127
1129
  globalThis.pubsub.publish('block-processed', blockMessage.decoded);
1128
1130
  }
1129
1131
  catch (error) {
1132
+ console.log(error.hash);
1133
+ console.log('errrrr');
1134
+ await transactionPoolStore.delete(error.hash);
1130
1135
  console.log({ e: error });
1131
1136
  }
1132
1137
  }
@@ -1159,6 +1164,10 @@ class Chain extends State {
1159
1164
  if (await globalThis.transactionPoolStore.size() === 0)
1160
1165
  return;
1161
1166
  let transactions = await globalThis.transactionPoolStore.values(this.transactionLimit);
1167
+ for (const hash of await globalThis.transactionPoolStore.keys()) {
1168
+ if (ignorelist.includes(hash))
1169
+ await globalThis.transactionPoolStore.delete(hash);
1170
+ }
1162
1171
  if (Object.keys(transactions)?.length === 0)
1163
1172
  return;
1164
1173
  const timestamp = Date.now();
@@ -1174,6 +1183,7 @@ class Chain extends State {
1174
1183
  // exclude failing tx
1175
1184
  transactions = await this.promiseTransactions(transactions);
1176
1185
  transactions = transactions.sort((a, b) => a.nonce - b.nonce);
1186
+ console.log({ transactions });
1177
1187
  for (let transaction of transactions) {
1178
1188
  const hash = await transaction.hash();
1179
1189
  const doubleTransactions = [];
@@ -1187,21 +1197,25 @@ class Chain extends State {
1187
1197
  if (doubleTransactions.length > 0) {
1188
1198
  await globalThis.transactionPoolStore.delete(hash);
1189
1199
  await globalThis.peernet.publish('invalid-transaction', hash);
1200
+ return;
1190
1201
  }
1191
- else {
1192
- // if (timestamp + this.#slotTime > Date.now()) {
1193
- try {
1194
- const result = await this.#executeTransaction({ ...transaction.decoded, hash });
1195
- block.transactions.push(transaction);
1196
- block.fees = block.fees.add(await calculateFee(transaction.decoded));
1197
- await globalThis.accountsStore.put(transaction.decoded.from, new TextEncoder().encode(String(transaction.decoded.nonce)));
1198
- }
1199
- catch (e) {
1200
- console.log({ e });
1201
- console.log(hash);
1202
- await globalThis.transactionPoolStore.delete(hash);
1203
- }
1204
- // }
1202
+ // if (timestamp + this.#slotTime > Date.now()) {
1203
+ try {
1204
+ const result = await this.#executeTransaction({ ...transaction.decoded, hash });
1205
+ console.log({ result });
1206
+ block.transactions.push(transaction);
1207
+ block.fees = block.fees.add(await calculateFee(transaction.decoded));
1208
+ await globalThis.accountsStore.put(transaction.decoded.from, new TextEncoder().encode(String(transaction.decoded.nonce)));
1209
+ }
1210
+ catch (e) {
1211
+ console.log('vvvvvv');
1212
+ console.log({ e });
1213
+ console.log(hash);
1214
+ peernet.publish('invalid-transaction', hash);
1215
+ console.log(await globalThis.transactionPoolStore.keys());
1216
+ console.log(await globalThis.transactionPoolStore.has(e.hash));
1217
+ await globalThis.transactionPoolStore.delete(e.hash);
1218
+ console.log(await globalThis.transactionPoolStore.has(e.hash));
1205
1219
  }
1206
1220
  }
1207
1221
  // don't add empty block
@@ -1275,6 +1289,7 @@ class Chain extends State {
1275
1289
  }
1276
1290
  catch (error) {
1277
1291
  console.log(error);
1292
+ console.log('eeeee');
1278
1293
  throw new Error(`invalid block ${block}`);
1279
1294
  }
1280
1295
  // data = await this.machine.execute(to, method, params)
@@ -1293,6 +1308,7 @@ class Chain extends State {
1293
1308
  }
1294
1309
  catch (e) {
1295
1310
  console.log(e);
1311
+ console.log('rrrrr');
1296
1312
  globalThis.peernet.publish('invalid-transaction', hash);
1297
1313
  throw new Error('invalid transaction');
1298
1314
  }
@@ -1322,7 +1338,7 @@ class Chain extends State {
1322
1338
  * @param {Address} sender
1323
1339
  * @returns {globalMessage}
1324
1340
  */
1325
- #createMessage(sender = globalThis.globalThis.peernet.selectedAccount) {
1341
+ #createMessage(sender = globalThis.peernet.selectedAccount) {
1326
1342
  return {
1327
1343
  sender,
1328
1344
  call: this.call,