@talismn/sapi 0.0.5 → 0.0.6

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.
@@ -431,27 +431,26 @@ function trailingZeroes(n) {
431
431
  return i;
432
432
  }
433
433
 
434
+ const PERIOD = 64; // validity period in blocks, used for mortal era
435
+
434
436
  const getSignerPayloadJSON = async (chain, palletName, methodName, args, signerConfig, chainInfo) => {
435
437
  const {
436
438
  codec,
437
439
  location
438
440
  } = chain.builder.buildCall(palletName, methodName);
439
441
  const method = polkadotApi.Binary.fromBytes(utils.mergeUint8([new Uint8Array(location), codec.enc(args)]));
440
- const blockNumber = await getStorageValue(chain, "System", "Number", []);
441
- if (blockNumber === null) throw new Error("Block number not found");
442
- const [account, genesisHash, blockHash] = await Promise.all([
443
- // TODO if V15 available, use a runtime call instead : AccountNonceApi/account_nonce
444
- // about nonce https://github.com/paritytech/json-rpc-interface-spec/issues/156
445
- getStorageValue(chain, "System", "Account", [signerConfig.address]), getStorageValue(chain, "System", "BlockHash", [0]), getSendRequestResult(chain, "chain_getBlockHash", [blockNumber], false) // TODO find the right way to fetch this with new RPC api, this is not available in storage yet
446
- ]);
442
+
443
+ // on unstable networks with lots of forks (ex: westend asset hub as of june 2025),
444
+ // using a finalized block as reference for mortality is necessary for txs to get through
445
+ const blockHash = await getSendRequestResult(chain, "chain_getFinalizedHead", [], false);
446
+ const [nonce, genesisHash, blockNumber] = await Promise.all([getSendRequestResult(chain, "system_accountNextIndex", [signerConfig.address], false), getStorageValue(chain, "System", "BlockHash", [0]), getStorageValue(chain, "System", "Number", [], blockHash)]);
447
447
  if (!genesisHash) throw new Error("Genesis hash not found");
448
448
  if (!blockHash) throw new Error("Block hash not found");
449
- const nonce = account ? account.nonce : 0;
450
449
  const era = mortal({
451
- period: 16,
452
- phase: blockNumber % 16
450
+ period: PERIOD,
451
+ phase: blockNumber % PERIOD
453
452
  });
454
- const signedExtensions = chain.metadata.extrinsic.signedExtensions.map(ext => ext.identifier.toString());
453
+ const signedExtensions = chain.metadata.extrinsic.signedExtensions.map(ext => ext.identifier);
455
454
  const basePayload = {
456
455
  address: signerConfig.address,
457
456
  genesisHash: genesisHash.asHex(),
@@ -431,27 +431,26 @@ function trailingZeroes(n) {
431
431
  return i;
432
432
  }
433
433
 
434
+ const PERIOD = 64; // validity period in blocks, used for mortal era
435
+
434
436
  const getSignerPayloadJSON = async (chain, palletName, methodName, args, signerConfig, chainInfo) => {
435
437
  const {
436
438
  codec,
437
439
  location
438
440
  } = chain.builder.buildCall(palletName, methodName);
439
441
  const method = polkadotApi.Binary.fromBytes(utils.mergeUint8([new Uint8Array(location), codec.enc(args)]));
440
- const blockNumber = await getStorageValue(chain, "System", "Number", []);
441
- if (blockNumber === null) throw new Error("Block number not found");
442
- const [account, genesisHash, blockHash] = await Promise.all([
443
- // TODO if V15 available, use a runtime call instead : AccountNonceApi/account_nonce
444
- // about nonce https://github.com/paritytech/json-rpc-interface-spec/issues/156
445
- getStorageValue(chain, "System", "Account", [signerConfig.address]), getStorageValue(chain, "System", "BlockHash", [0]), getSendRequestResult(chain, "chain_getBlockHash", [blockNumber], false) // TODO find the right way to fetch this with new RPC api, this is not available in storage yet
446
- ]);
442
+
443
+ // on unstable networks with lots of forks (ex: westend asset hub as of june 2025),
444
+ // using a finalized block as reference for mortality is necessary for txs to get through
445
+ const blockHash = await getSendRequestResult(chain, "chain_getFinalizedHead", [], false);
446
+ const [nonce, genesisHash, blockNumber] = await Promise.all([getSendRequestResult(chain, "system_accountNextIndex", [signerConfig.address], false), getStorageValue(chain, "System", "BlockHash", [0]), getStorageValue(chain, "System", "Number", [], blockHash)]);
447
447
  if (!genesisHash) throw new Error("Genesis hash not found");
448
448
  if (!blockHash) throw new Error("Block hash not found");
449
- const nonce = account ? account.nonce : 0;
450
449
  const era = mortal({
451
- period: 16,
452
- phase: blockNumber % 16
450
+ period: PERIOD,
451
+ phase: blockNumber % PERIOD
453
452
  });
454
- const signedExtensions = chain.metadata.extrinsic.signedExtensions.map(ext => ext.identifier.toString());
453
+ const signedExtensions = chain.metadata.extrinsic.signedExtensions.map(ext => ext.identifier);
455
454
  const basePayload = {
456
455
  address: signerConfig.address,
457
456
  genesisHash: genesisHash.asHex(),
@@ -425,27 +425,26 @@ function trailingZeroes(n) {
425
425
  return i;
426
426
  }
427
427
 
428
+ const PERIOD = 64; // validity period in blocks, used for mortal era
429
+
428
430
  const getSignerPayloadJSON = async (chain, palletName, methodName, args, signerConfig, chainInfo) => {
429
431
  const {
430
432
  codec,
431
433
  location
432
434
  } = chain.builder.buildCall(palletName, methodName);
433
435
  const method = Binary.fromBytes(mergeUint8([new Uint8Array(location), codec.enc(args)]));
434
- const blockNumber = await getStorageValue(chain, "System", "Number", []);
435
- if (blockNumber === null) throw new Error("Block number not found");
436
- const [account, genesisHash, blockHash] = await Promise.all([
437
- // TODO if V15 available, use a runtime call instead : AccountNonceApi/account_nonce
438
- // about nonce https://github.com/paritytech/json-rpc-interface-spec/issues/156
439
- getStorageValue(chain, "System", "Account", [signerConfig.address]), getStorageValue(chain, "System", "BlockHash", [0]), getSendRequestResult(chain, "chain_getBlockHash", [blockNumber], false) // TODO find the right way to fetch this with new RPC api, this is not available in storage yet
440
- ]);
436
+
437
+ // on unstable networks with lots of forks (ex: westend asset hub as of june 2025),
438
+ // using a finalized block as reference for mortality is necessary for txs to get through
439
+ const blockHash = await getSendRequestResult(chain, "chain_getFinalizedHead", [], false);
440
+ const [nonce, genesisHash, blockNumber] = await Promise.all([getSendRequestResult(chain, "system_accountNextIndex", [signerConfig.address], false), getStorageValue(chain, "System", "BlockHash", [0]), getStorageValue(chain, "System", "Number", [], blockHash)]);
441
441
  if (!genesisHash) throw new Error("Genesis hash not found");
442
442
  if (!blockHash) throw new Error("Block hash not found");
443
- const nonce = account ? account.nonce : 0;
444
443
  const era = mortal({
445
- period: 16,
446
- phase: blockNumber % 16
444
+ period: PERIOD,
445
+ phase: blockNumber % PERIOD
447
446
  });
448
- const signedExtensions = chain.metadata.extrinsic.signedExtensions.map(ext => ext.identifier.toString());
447
+ const signedExtensions = chain.metadata.extrinsic.signedExtensions.map(ext => ext.identifier);
449
448
  const basePayload = {
450
449
  address: signerConfig.address,
451
450
  genesisHash: genesisHash.asHex(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talismn/sapi",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "author": "Talisman",
5
5
  "homepage": "https://talisman.xyz",
6
6
  "license": "GPL-3.0-or-later",
@@ -39,8 +39,8 @@
39
39
  "jest": "^29.7",
40
40
  "ts-jest": "^29.2.5",
41
41
  "typescript": "^5.6.3",
42
- "@talismn/tsconfig": "0.0.2",
43
- "@talismn/eslint-config": "0.0.3"
42
+ "@talismn/eslint-config": "0.0.3",
43
+ "@talismn/tsconfig": "0.0.2"
44
44
  },
45
45
  "eslintConfig": {
46
46
  "root": true,