From 96360f905ae1865cae5099e30dec9d99c04d1796 Mon Sep 17 00:00:00 2001 From: Dmitry Osipov Date: Fri, 26 Apr 2024 15:18:27 +0300 Subject: [PATCH 1/2] use transferAllowDeath instead of transfer method --- server/package.json | 10 +- server/src/helpers/construct-tx.ts | 42 ++-- server/src/helpers/extrinsics.ts | 9 +- server/src/types/enums.ts | 6 +- yarn.lock | 392 +++++++++++++++++++++++++++-- 5 files changed, 405 insertions(+), 54 deletions(-) diff --git a/server/package.json b/server/package.json index 8b6a3fb..8161e98 100644 --- a/server/package.json +++ b/server/package.json @@ -23,12 +23,12 @@ ], "private": true, "dependencies": { - "@polkadot/api": "10.11.2", - "@polkadot/types": "10.11.2", - "@polkadot/types-codec": "10.11.2", + "@polkadot/api": "11.0.2", + "@polkadot/types": "11.0.2", + "@polkadot/types-codec": "11.0.2", "@polkadot/util": "12.6.2", - "@substrate/txwrapper-core": "7.2.0", - "@substrate/txwrapper-polkadot": "7.2.0", + "@substrate/txwrapper-core": "7.4.0", + "@substrate/txwrapper-polkadot": "7.4.0", "body-parser": "1.20.2", "camelcase": "6.3.0", "commander": "^11.0.0", diff --git a/server/src/helpers/construct-tx.ts b/server/src/helpers/construct-tx.ts index b2b1210..59e24c4 100644 --- a/server/src/helpers/construct-tx.ts +++ b/server/src/helpers/construct-tx.ts @@ -16,7 +16,7 @@ export interface TxParams { tip: number; specVersion: number; transactionVersion: number; - disableKeepAlive: boolean, + disableKeepAlive: boolean; networkIdent: GearNetworkIdentifier; } @@ -36,28 +36,28 @@ export function constructTx({ }: TxParams) { const args = { dest: { id: toAddress }, value }; const info = { - address: deriveAddress(fromAddress, ss58Format), - blockHash, - blockNumber, - eraPeriod, - nonce, - tip, - genesisHash: genesis, - metadataRpc: metadataRpc, - specVersion, - transactionVersion, - }; + address: deriveAddress(fromAddress, ss58Format), + blockHash, + blockNumber, + eraPeriod, + nonce, + tip, + genesisHash: genesis, + metadataRpc: metadataRpc, + specVersion, + transactionVersion, + }; const options = { - metadataRpc: metadataRpc, - registry, - }; + metadataRpc: metadataRpc, + registry, + }; const unsigned = disableKeepAlive - ? methods.balances.transfer(args, info, options) + ? methods.balances.transferAllowDeath(args, info, options) : methods.balances.transferKeepAlive(args, info, options); const loggedUnsignedTx = unsigned; - loggedUnsignedTx.metadataRpc = "0x...truncated..."; - logger.info('[constructTx] Generated unsigned tx', { tx: loggedUnsignedTx }) + loggedUnsignedTx.metadataRpc = '0x...truncated...'; + logger.info('[constructTx] Generated unsigned tx', { tx: loggedUnsignedTx }); const { method, version, address } = unsigned; const unsignedTx = stringToHex(JSON.stringify({ method, version, address, nonce, era: unsigned.era })); @@ -78,7 +78,7 @@ export function constructSignedTx(unsigned: any, signature: string, { registry } header[0] = 0; const sigWithHeader = u8aConcat(header, sigU8a); const tx = JSON.parse(hexToString(unsigned)); - + const extrinsic = registry.createType('Extrinsic', tx, { version: tx.version }); extrinsic.addSignature(tx.address, sigWithHeader, tx); return extrinsic.toHex(); @@ -93,12 +93,12 @@ export function parseTransaction( ? decode(transaction, { registry, metadataRpc }) : decode(JSON.parse(hexToString(transaction)), { registry, metadataRpc }); - tx.metadataRpc = "0x...truncated..."; + tx.metadataRpc = '0x...truncated...'; logger.info(`[parseTransaction] Decoded transaction`, { signed: signed, encoded_tx: transaction, - decoded_tx: tx + decoded_tx: tx, }); const source = tx.address; diff --git a/server/src/helpers/extrinsics.ts b/server/src/helpers/extrinsics.ts index 63ef8cd..f251843 100644 --- a/server/src/helpers/extrinsics.ts +++ b/server/src/helpers/extrinsics.ts @@ -3,6 +3,11 @@ import { AnyTuple } from '@polkadot/types-codec/types'; import { TxMethodLC, TxSectionLC } from '../types'; +const TRANSFER_METHODS: string[] = [ + TxMethodLC.TRANSFER, + TxMethodLC.TRANSFER_KEEP_ALIVE, + TxMethodLC.TRANSFER_ALLOW_DEATH, +]; + export const isTransferTx = ({ method: { method, section } }: GenericExtrinsic) => - section.toLowerCase() === TxSectionLC.BALANCES && - (method.toLowerCase() === TxMethodLC.TRANSFER || method.toLowerCase() === TxMethodLC.TRANSFER_KEEP_ALIVE); + section.toLowerCase() === TxSectionLC.BALANCES && TRANSFER_METHODS.includes(method.toLocaleLowerCase()); diff --git a/server/src/types/enums.ts b/server/src/types/enums.ts index 065c19b..5279525 100644 --- a/server/src/types/enums.ts +++ b/server/src/types/enums.ts @@ -20,7 +20,7 @@ export enum EventMethodsLC { TRANSFER = 'transfer', BALANCE_SET = 'balanceset', TRANSACTION_FEE_PAID = 'transactionfeepaid', - DUST_LOST = 'dustlost' + DUST_LOST = 'dustlost', } export enum EventSectionLC { @@ -38,7 +38,7 @@ export enum OpType { RESERVE_REPATRIATED = 'ReserveRepatriated', BALANCE_SET = 'BalanceSet', TRANSACTION_FEE_PAID = 'TransactionFeePaid', - DUST_LOST = 'DustLost' + DUST_LOST = 'DustLost', } export const opTypes = Object.values(OpType); @@ -50,4 +50,6 @@ export enum TxSectionLC { export enum TxMethodLC { TRANSFER = 'transfer', TRANSFER_KEEP_ALIVE = 'transferkeepalive', + TRANSFER_ALLOW_DEATH = 'transferallowdeath', + TRANSFER_ALL = 'transferall', } diff --git a/yarn.lock b/yarn.lock index 29864e9..9d9d00e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1837,6 +1837,13 @@ __metadata: languageName: node linkType: hard +"@noble/hashes@npm:^1.3.1": + version: 1.4.0 + resolution: "@noble/hashes@npm:1.4.0" + checksum: 8ba816ae26c90764b8c42493eea383716396096c5f7ba6bea559993194f49d80a73c081f315f4c367e51bd2d5891700bcdfa816b421d24ab45b41cb03e4f3342 + languageName: node + linkType: hard + "@nodelib/fs.scandir@npm:2.1.5": version: 2.1.5 resolution: "@nodelib/fs.scandir@npm:2.1.5" @@ -1880,6 +1887,70 @@ __metadata: languageName: node linkType: hard +"@polkadot-api/json-rpc-provider-proxy@npm:0.0.1": + version: 0.0.1 + resolution: "@polkadot-api/json-rpc-provider-proxy@npm:0.0.1" + checksum: cf8daf52ff6d92f26c6027f13ef5fbef9e512626e0225bc8408b79002cfd34fc17c5f2d856beebcb01aa5f84c93ccc8272f9264dc8349b7f6cb63845b30119b5 + languageName: node + linkType: hard + +"@polkadot-api/json-rpc-provider@npm:0.0.1": + version: 0.0.1 + resolution: "@polkadot-api/json-rpc-provider@npm:0.0.1" + checksum: 1f315bdadcba7def7145011132e6127b983c6f91f976be217ad7d555bb96a67f3a270fe4a46e427531822c5d54d353d84a6439d112a99cdfc07013d3b662ee3c + languageName: node + linkType: hard + +"@polkadot-api/metadata-builders@npm:0.0.1": + version: 0.0.1 + resolution: "@polkadot-api/metadata-builders@npm:0.0.1" + dependencies: + "@polkadot-api/substrate-bindings": 0.0.1 + "@polkadot-api/utils": 0.0.1 + checksum: 7cf69e583e64f0ea1b90b141d9f61c4b0ba445daf87d4eba25bfcaa629c95cf4bbe6d89f5263dc495189fae0795c45810a004a2a8fbf59ece01ae71e1e049f17 + languageName: node + linkType: hard + +"@polkadot-api/observable-client@npm:0.1.0": + version: 0.1.0 + resolution: "@polkadot-api/observable-client@npm:0.1.0" + dependencies: + "@polkadot-api/metadata-builders": 0.0.1 + "@polkadot-api/substrate-bindings": 0.0.1 + "@polkadot-api/substrate-client": 0.0.1 + "@polkadot-api/utils": 0.0.1 + peerDependencies: + rxjs: ">=7.8.0" + checksum: 694ee405f40ce47eb8d23dd2fc68359a5016c54ac530893a76e772a2d6a1a7c09c3a11d772b7c196af4faa29e98a443849334b97c6bf91af616990b4c7834caa + languageName: node + linkType: hard + +"@polkadot-api/substrate-bindings@npm:0.0.1": + version: 0.0.1 + resolution: "@polkadot-api/substrate-bindings@npm:0.0.1" + dependencies: + "@noble/hashes": ^1.3.1 + "@polkadot-api/utils": 0.0.1 + "@scure/base": ^1.1.1 + scale-ts: ^1.6.0 + checksum: fc49e49ffe749fc6fab49eee1d10d47fcd1fa3a9b6ca4e7bbde4e9741b9e062cd4e9271fd86a2525095ff36bf33b95d57c51efb88635bb60b2c77fa9e83b2cd6 + languageName: node + linkType: hard + +"@polkadot-api/substrate-client@npm:0.0.1": + version: 0.0.1 + resolution: "@polkadot-api/substrate-client@npm:0.0.1" + checksum: 13dc05f1fce0d00241b48d262d691a740c65b107800cdfdf8d800333e9b3950932ce50a88bf65810892e43103bf57d1541c71538e68aa27b9aba55b389835b91 + languageName: node + linkType: hard + +"@polkadot-api/utils@npm:0.0.1": + version: 0.0.1 + resolution: "@polkadot-api/utils@npm:0.0.1" + checksum: 11e67019cbf6dd39997d772edf14296c1b156d7a59c7726ce117b438ee85a5e50e305514a2a93cba87fdce1380fcf045931f2fb959df3a43bb327e77ac876148 + languageName: node + linkType: hard + "@polkadot/api-augment@npm:10.11.2": version: 10.11.2 resolution: "@polkadot/api-augment@npm:10.11.2" @@ -1895,6 +1966,21 @@ __metadata: languageName: node linkType: hard +"@polkadot/api-augment@npm:11.0.2": + version: 11.0.2 + resolution: "@polkadot/api-augment@npm:11.0.2" + dependencies: + "@polkadot/api-base": 11.0.2 + "@polkadot/rpc-augment": 11.0.2 + "@polkadot/types": 11.0.2 + "@polkadot/types-augment": 11.0.2 + "@polkadot/types-codec": 11.0.2 + "@polkadot/util": ^12.6.2 + tslib: ^2.6.2 + checksum: 5da64a991f5eb81eba12afc412a4b7b7d324fe76f2ad5610e7bfab60276c2750fe4c0e27c1e321cdcb9aa4f0fea480c80dff217a5178e5b9fde113bd29e97f49 + languageName: node + linkType: hard + "@polkadot/api-base@npm:10.11.2": version: 10.11.2 resolution: "@polkadot/api-base@npm:10.11.2" @@ -1908,6 +1994,19 @@ __metadata: languageName: node linkType: hard +"@polkadot/api-base@npm:11.0.2": + version: 11.0.2 + resolution: "@polkadot/api-base@npm:11.0.2" + dependencies: + "@polkadot/rpc-core": 11.0.2 + "@polkadot/types": 11.0.2 + "@polkadot/util": ^12.6.2 + rxjs: ^7.8.1 + tslib: ^2.6.2 + checksum: 7a7f30031be9261262413bba1765f40f60c0f0890475b1ff7789c0b628d8531808588091b46f9420e82aee4935045ddf359fd39280a7530a5550ac588fefe6bc + languageName: node + linkType: hard + "@polkadot/api-derive@npm:10.11.2": version: 10.11.2 resolution: "@polkadot/api-derive@npm:10.11.2" @@ -1926,7 +2025,25 @@ __metadata: languageName: node linkType: hard -"@polkadot/api@npm:10.11.2, @polkadot/api@npm:^10.11.2": +"@polkadot/api-derive@npm:11.0.2": + version: 11.0.2 + resolution: "@polkadot/api-derive@npm:11.0.2" + dependencies: + "@polkadot/api": 11.0.2 + "@polkadot/api-augment": 11.0.2 + "@polkadot/api-base": 11.0.2 + "@polkadot/rpc-core": 11.0.2 + "@polkadot/types": 11.0.2 + "@polkadot/types-codec": 11.0.2 + "@polkadot/util": ^12.6.2 + "@polkadot/util-crypto": ^12.6.2 + rxjs: ^7.8.1 + tslib: ^2.6.2 + checksum: 80fd722cca61c774ff0ebc315ae960626b24ae7085e02b8f25715fb177f3c812a6bd2978dcff272aa6f2c191885e358108577af86e852c3abf0c1b8f9c18509d + languageName: node + linkType: hard + +"@polkadot/api@npm:10.11.2": version: 10.11.2 resolution: "@polkadot/api@npm:10.11.2" dependencies: @@ -1951,7 +2068,32 @@ __metadata: languageName: node linkType: hard -"@polkadot/keyring@npm:^12.6.1, @polkadot/keyring@npm:^12.6.2": +"@polkadot/api@npm:11.0.2, @polkadot/api@npm:^11.0.2": + version: 11.0.2 + resolution: "@polkadot/api@npm:11.0.2" + dependencies: + "@polkadot/api-augment": 11.0.2 + "@polkadot/api-base": 11.0.2 + "@polkadot/api-derive": 11.0.2 + "@polkadot/keyring": ^12.6.2 + "@polkadot/rpc-augment": 11.0.2 + "@polkadot/rpc-core": 11.0.2 + "@polkadot/rpc-provider": 11.0.2 + "@polkadot/types": 11.0.2 + "@polkadot/types-augment": 11.0.2 + "@polkadot/types-codec": 11.0.2 + "@polkadot/types-create": 11.0.2 + "@polkadot/types-known": 11.0.2 + "@polkadot/util": ^12.6.2 + "@polkadot/util-crypto": ^12.6.2 + eventemitter3: ^5.0.1 + rxjs: ^7.8.1 + tslib: ^2.6.2 + checksum: 32d230f2e02bfacb9a81b7928e5d483d5ad7073cb5698269928c20f79e001a17b38e8563eaf34ec4f43095b20a34d1ca7bcb6f91782d32a80906ab5509f4a420 + languageName: node + linkType: hard + +"@polkadot/keyring@npm:^12.6.2": version: 12.6.2 resolution: "@polkadot/keyring@npm:12.6.2" dependencies: @@ -1989,6 +2131,19 @@ __metadata: languageName: node linkType: hard +"@polkadot/rpc-augment@npm:11.0.2": + version: 11.0.2 + resolution: "@polkadot/rpc-augment@npm:11.0.2" + dependencies: + "@polkadot/rpc-core": 11.0.2 + "@polkadot/types": 11.0.2 + "@polkadot/types-codec": 11.0.2 + "@polkadot/util": ^12.6.2 + tslib: ^2.6.2 + checksum: ab5b8c6faaeafc7bedc973820e717a93ed5715aeae4412ff7d6359391961bbd7d2d24e7b46f6926617a135a5659c352f4c3a7fd3cff70a11269be26bcf9ab255 + languageName: node + linkType: hard + "@polkadot/rpc-core@npm:10.11.2": version: 10.11.2 resolution: "@polkadot/rpc-core@npm:10.11.2" @@ -2003,6 +2158,20 @@ __metadata: languageName: node linkType: hard +"@polkadot/rpc-core@npm:11.0.2": + version: 11.0.2 + resolution: "@polkadot/rpc-core@npm:11.0.2" + dependencies: + "@polkadot/rpc-augment": 11.0.2 + "@polkadot/rpc-provider": 11.0.2 + "@polkadot/types": 11.0.2 + "@polkadot/util": ^12.6.2 + rxjs: ^7.8.1 + tslib: ^2.6.2 + checksum: 100cfbd87b4088f4bd56fb1927c475038855158742b211faf210a722390f1721a7fcf15697f7af9c6c3a92b96bec35d48d9c52c6d8a9db6f367f5a1a665e4b0c + languageName: node + linkType: hard + "@polkadot/rpc-provider@npm:10.11.2": version: 10.11.2 resolution: "@polkadot/rpc-provider@npm:10.11.2" @@ -2027,6 +2196,30 @@ __metadata: languageName: node linkType: hard +"@polkadot/rpc-provider@npm:11.0.2": + version: 11.0.2 + resolution: "@polkadot/rpc-provider@npm:11.0.2" + dependencies: + "@polkadot/keyring": ^12.6.2 + "@polkadot/types": 11.0.2 + "@polkadot/types-support": 11.0.2 + "@polkadot/util": ^12.6.2 + "@polkadot/util-crypto": ^12.6.2 + "@polkadot/x-fetch": ^12.6.2 + "@polkadot/x-global": ^12.6.2 + "@polkadot/x-ws": ^12.6.2 + "@substrate/connect": 0.8.10 + eventemitter3: ^5.0.1 + mock-socket: ^9.3.1 + nock: ^13.5.0 + tslib: ^2.6.2 + dependenciesMeta: + "@substrate/connect": + optional: true + checksum: e6354d7e34e51ec551e9de10a3450d7498ceb6a067d714d1cfaedce5586d03d3e7c6ea0ecd0bd1b1cf8090fa20379987fd67e31975cda62b0d0b7dd248a9e5dd + languageName: node + linkType: hard + "@polkadot/types-augment@npm:10.11.2": version: 10.11.2 resolution: "@polkadot/types-augment@npm:10.11.2" @@ -2039,6 +2232,18 @@ __metadata: languageName: node linkType: hard +"@polkadot/types-augment@npm:11.0.2": + version: 11.0.2 + resolution: "@polkadot/types-augment@npm:11.0.2" + dependencies: + "@polkadot/types": 11.0.2 + "@polkadot/types-codec": 11.0.2 + "@polkadot/util": ^12.6.2 + tslib: ^2.6.2 + checksum: fe8ddf90ca9d4438a0e7012500ce6acb0de17decb77b23f91c30644decc2694c1ae04dcac10ec3d934df597de014f63583e31c7a847f9431a217a19f3c0ec9de + languageName: node + linkType: hard + "@polkadot/types-codec@npm:10.11.2": version: 10.11.2 resolution: "@polkadot/types-codec@npm:10.11.2" @@ -2050,6 +2255,17 @@ __metadata: languageName: node linkType: hard +"@polkadot/types-codec@npm:11.0.2": + version: 11.0.2 + resolution: "@polkadot/types-codec@npm:11.0.2" + dependencies: + "@polkadot/util": ^12.6.2 + "@polkadot/x-bigint": ^12.6.2 + tslib: ^2.6.2 + checksum: ff991126a092a012f800b83ba82b9d1560b4fe74781ca1fc3c74f4b4ff0b98819fa6af909eabb753781eae8c897b83fd7e01efc699a96148aed765b60e70ef37 + languageName: node + linkType: hard + "@polkadot/types-create@npm:10.11.2": version: 10.11.2 resolution: "@polkadot/types-create@npm:10.11.2" @@ -2061,6 +2277,17 @@ __metadata: languageName: node linkType: hard +"@polkadot/types-create@npm:11.0.2": + version: 11.0.2 + resolution: "@polkadot/types-create@npm:11.0.2" + dependencies: + "@polkadot/types-codec": 11.0.2 + "@polkadot/util": ^12.6.2 + tslib: ^2.6.2 + checksum: b1c22b5270b0e7e63ddcf9c9bef7ca56db862f4f31dfd039b78ba7d5c249c068b58c84419bbe2315eabf48454db612a668557fed630e9c386656b9658eeff5ab + languageName: node + linkType: hard + "@polkadot/types-known@npm:10.11.2": version: 10.11.2 resolution: "@polkadot/types-known@npm:10.11.2" @@ -2075,6 +2302,20 @@ __metadata: languageName: node linkType: hard +"@polkadot/types-known@npm:11.0.2": + version: 11.0.2 + resolution: "@polkadot/types-known@npm:11.0.2" + dependencies: + "@polkadot/networks": ^12.6.2 + "@polkadot/types": 11.0.2 + "@polkadot/types-codec": 11.0.2 + "@polkadot/types-create": 11.0.2 + "@polkadot/util": ^12.6.2 + tslib: ^2.6.2 + checksum: 4b087c69c1103625ad170905da7bdfa51be754e3127aaf70c6c6ed5edae8c91d99fd4a046c956f0598c13f595bfc1b7942932a89b8c61a566bb01fd953631ba6 + languageName: node + linkType: hard + "@polkadot/types-support@npm:10.11.2": version: 10.11.2 resolution: "@polkadot/types-support@npm:10.11.2" @@ -2085,6 +2326,16 @@ __metadata: languageName: node linkType: hard +"@polkadot/types-support@npm:11.0.2": + version: 11.0.2 + resolution: "@polkadot/types-support@npm:11.0.2" + dependencies: + "@polkadot/util": ^12.6.2 + tslib: ^2.6.2 + checksum: cb453682888e553e1fe10a72acde66182121b025a52f9096f2a1ca7233fc61213a532c5baf755cf6bfb25e7e4354fb1ec6244f19974a29e0a083e4268da05021 + languageName: node + linkType: hard + "@polkadot/types@npm:10.11.2": version: 10.11.2 resolution: "@polkadot/types@npm:10.11.2" @@ -2101,6 +2352,22 @@ __metadata: languageName: node linkType: hard +"@polkadot/types@npm:11.0.2": + version: 11.0.2 + resolution: "@polkadot/types@npm:11.0.2" + dependencies: + "@polkadot/keyring": ^12.6.2 + "@polkadot/types-augment": 11.0.2 + "@polkadot/types-codec": 11.0.2 + "@polkadot/types-create": 11.0.2 + "@polkadot/util": ^12.6.2 + "@polkadot/util-crypto": ^12.6.2 + rxjs: ^7.8.1 + tslib: ^2.6.2 + checksum: 5debd49b5509eee97ae7a8146cb6b1af5849eff6506a160882fca01aec73116fb221870d086ce2532692253c1b3fd27bfbaf3d99c6cdccbbe1cdb9f2f99997ad + languageName: node + linkType: hard + "@polkadot/util-crypto@npm:12.6.2, @polkadot/util-crypto@npm:^12.6.2": version: 12.6.2 resolution: "@polkadot/util-crypto@npm:12.6.2" @@ -2290,6 +2557,13 @@ __metadata: languageName: node linkType: hard +"@scure/base@npm:^1.1.1": + version: 1.1.6 + resolution: "@scure/base@npm:1.1.6" + checksum: d6deaae91deba99e87939af9e55d80edba302674983f32bba57f942e22b1726a83c62dc50d8f4370a5d5d35a212dda167fb169f4b0d0c297488d8604608fc3d3 + languageName: node + linkType: hard + "@scure/base@npm:^1.1.5": version: 1.1.5 resolution: "@scure/base@npm:1.1.5" @@ -2349,6 +2623,20 @@ __metadata: languageName: node linkType: hard +"@substrate/connect-extension-protocol@npm:^2.0.0": + version: 2.0.0 + resolution: "@substrate/connect-extension-protocol@npm:2.0.0" + checksum: a7c6ff3fefc0784f28b1d253514c1d2951684fe3d06392dfd70299fa2184fbe040d2bd6e0f113e30a1920920b649d43668aa4565847778ab3334c7e445e880cf + languageName: node + linkType: hard + +"@substrate/connect-known-chains@npm:^1.1.4": + version: 1.1.4 + resolution: "@substrate/connect-known-chains@npm:1.1.4" + checksum: 235c732509391f12525ec740dbb8b8d4c5f56b7c7e71216c933e12974e0ad4f9664f7248a6d6db8b687c1c9fca9105398113ac7fd39515163ab6a9d5f7eba737 + languageName: node + linkType: hard + "@substrate/connect@npm:0.7.35": version: 0.7.35 resolution: "@substrate/connect@npm:0.7.35" @@ -2359,6 +2647,35 @@ __metadata: languageName: node linkType: hard +"@substrate/connect@npm:0.8.10": + version: 0.8.10 + resolution: "@substrate/connect@npm:0.8.10" + dependencies: + "@substrate/connect-extension-protocol": ^2.0.0 + "@substrate/connect-known-chains": ^1.1.4 + "@substrate/light-client-extension-helpers": ^0.0.6 + smoldot: 2.0.22 + checksum: 2ed22ff5eefc547f9c3a7547f166b20c844372802cf406e6511844ed2f813b091f515611a720847e1b78848af1156d5cba403c9423c4ad32e4009daf014150bc + languageName: node + linkType: hard + +"@substrate/light-client-extension-helpers@npm:^0.0.6": + version: 0.0.6 + resolution: "@substrate/light-client-extension-helpers@npm:0.0.6" + dependencies: + "@polkadot-api/json-rpc-provider": 0.0.1 + "@polkadot-api/json-rpc-provider-proxy": 0.0.1 + "@polkadot-api/observable-client": 0.1.0 + "@polkadot-api/substrate-client": 0.0.1 + "@substrate/connect-extension-protocol": ^2.0.0 + "@substrate/connect-known-chains": ^1.1.4 + rxjs: ^7.8.1 + peerDependencies: + smoldot: 2.x + checksum: a0cc169e6edf56cdbfd839a32487e31ad0bcb4cc9d4d50bac632c16f95d6ebf54638b268c1f7b8e651482e201f38411139a90071bc91268a2c01e5b50f39f338 + languageName: node + linkType: hard + "@substrate/ss58-registry@npm:^1.44.0": version: 1.44.0 resolution: "@substrate/ss58-registry@npm:1.44.0" @@ -2366,33 +2683,33 @@ __metadata: languageName: node linkType: hard -"@substrate/txwrapper-core@npm:7.2.0, @substrate/txwrapper-core@npm:^7.2.0": - version: 7.2.0 - resolution: "@substrate/txwrapper-core@npm:7.2.0" +"@substrate/txwrapper-core@npm:7.4.0, @substrate/txwrapper-core@npm:^7.4.0": + version: 7.4.0 + resolution: "@substrate/txwrapper-core@npm:7.4.0" dependencies: - "@polkadot/api": ^10.11.2 - "@polkadot/keyring": ^12.6.1 + "@polkadot/api": ^11.0.2 + "@polkadot/keyring": ^12.6.2 memoizee: 0.4.15 - checksum: bfed75a34d51777289d411e4d79365b7aec997cef52ef3936fc11605ef7d9df2d10fb66be1d01b653f472440c3098b8d5e3125cbb44eeaedc3d7d4b1ad4bc0c5 + checksum: 884f44e6ef0d0fb71a9cc7b3040bdf38a0975f0c8a7249f569b0d9f3684988fbed79c228ade90f16670030b7d384e6e1f126061a6e53ffb57a01ffcccc33953f languageName: node linkType: hard -"@substrate/txwrapper-polkadot@npm:7.2.0": - version: 7.2.0 - resolution: "@substrate/txwrapper-polkadot@npm:7.2.0" +"@substrate/txwrapper-polkadot@npm:7.4.0": + version: 7.4.0 + resolution: "@substrate/txwrapper-polkadot@npm:7.4.0" dependencies: - "@substrate/txwrapper-core": ^7.2.0 - "@substrate/txwrapper-substrate": ^7.2.0 - checksum: efbd0bc3f0c4130b0d968d4ea93339eae5021b63fd2328c4651fea627ee9839961d9c004c36aa09733993eb98bdc09cd3ff1c088d8821aa06044abe52e23b74e + "@substrate/txwrapper-core": ^7.4.0 + "@substrate/txwrapper-substrate": ^7.4.0 + checksum: c1b5f67f9007e6063ddf5b2683526b3e27779f44a3f204382aed0903dd3bcc160070c97cb4013d1a6d22c2d9da719d97fef426864f0665a935d4f77c61af226c languageName: node linkType: hard -"@substrate/txwrapper-substrate@npm:^7.2.0": - version: 7.2.0 - resolution: "@substrate/txwrapper-substrate@npm:7.2.0" +"@substrate/txwrapper-substrate@npm:^7.4.0": + version: 7.4.0 + resolution: "@substrate/txwrapper-substrate@npm:7.4.0" dependencies: - "@substrate/txwrapper-core": ^7.2.0 - checksum: ea4601f478adaf675961d21e0d74f5063010a272654524b040aefca55b1e0b90225bbe9ead822e45e9a6ce4a45a632fd3657a1e12e5b164a927b4566d1fbe039 + "@substrate/txwrapper-core": ^7.4.0 + checksum: 496c05a058989955110d4e71a7f1f7fea0f7256c50a20095bdf9113d65b0e365f89e643a01dae9a32f966b8a9ef26b3f919808013654810a3847959806b694eb languageName: node linkType: hard @@ -6029,6 +6346,17 @@ __metadata: languageName: node linkType: hard +"nock@npm:^13.5.0": + version: 13.5.4 + resolution: "nock@npm:13.5.4" + dependencies: + debug: ^4.1.0 + json-stringify-safe: ^5.0.1 + propagate: ^2.0.0 + checksum: d31f924e34c87ae985edfb7b5a56e8a4dcfc3a072334ceb6d686326581f93090b3e23492663a64ce61b8df4f365b113231d926bc300bcfe9e5eb309c3e4b8628 + languageName: node + linkType: hard + "node-domexception@npm:^1.0.0": version: 1.0.0 resolution: "node-domexception@npm:1.0.0" @@ -6758,12 +7086,12 @@ __metadata: version: 0.0.0-use.local resolution: "rosetta-api@workspace:server" dependencies: - "@polkadot/api": 10.11.2 - "@polkadot/types": 10.11.2 - "@polkadot/types-codec": 10.11.2 + "@polkadot/api": 11.0.2 + "@polkadot/types": 11.0.2 + "@polkadot/types-codec": 11.0.2 "@polkadot/util": 12.6.2 - "@substrate/txwrapper-core": 7.2.0 - "@substrate/txwrapper-polkadot": 7.2.0 + "@substrate/txwrapper-core": 7.4.0 + "@substrate/txwrapper-polkadot": 7.4.0 "@typescript-eslint/eslint-plugin": latest "@typescript-eslint/parser": ^6.2.0 axios: ^1.4.0 @@ -6901,6 +7229,13 @@ __metadata: languageName: node linkType: hard +"scale-ts@npm:^1.6.0": + version: 1.6.0 + resolution: "scale-ts@npm:1.6.0" + checksum: 2cd6d3e31ea78621fe2e068eedc3beb6a3cfc338c9033f04ec3e355b4b08e134febad655c54a80272a50737136a27436f9d14d6525b126e621a3b77524111056 + languageName: node + linkType: hard + "semver@npm:^5.6.0": version: 5.7.2 resolution: "semver@npm:5.7.2" @@ -7089,6 +7424,15 @@ __metadata: languageName: node linkType: hard +"smoldot@npm:2.0.22": + version: 2.0.22 + resolution: "smoldot@npm:2.0.22" + dependencies: + ws: ^8.8.1 + checksum: 383bc6a5481190d64302fad56e9e4120a484885aee5543b268887de425708f04e8b3b3b69893333dfd9fd0e596f006afaa7c7ee5ff260c5d2be929c60302d385 + languageName: node + linkType: hard + "smoldot@npm:2.0.7": version: 2.0.7 resolution: "smoldot@npm:2.0.7" From 6c80922b6c80500e9a50f0f7cf3266a4a0c718af Mon Sep 17 00:00:00 2001 From: Dmitry Osipov Date: Tue, 21 May 2024 14:52:23 +0400 Subject: [PATCH 2/2] include transfer_all tx into transaction list even if it failed --- server/src/helpers/extrinsics.ts | 1 + server/src/helpers/transaction.ts | 98 ++++++++++++++++--------------- 2 files changed, 53 insertions(+), 46 deletions(-) diff --git a/server/src/helpers/extrinsics.ts b/server/src/helpers/extrinsics.ts index f251843..b84d4ba 100644 --- a/server/src/helpers/extrinsics.ts +++ b/server/src/helpers/extrinsics.ts @@ -7,6 +7,7 @@ const TRANSFER_METHODS: string[] = [ TxMethodLC.TRANSFER, TxMethodLC.TRANSFER_KEEP_ALIVE, TxMethodLC.TRANSFER_ALLOW_DEATH, + TxMethodLC.TRANSFER_ALL ]; export const isTransferTx = ({ method: { method, section } }: GenericExtrinsic) => diff --git a/server/src/helpers/transaction.ts b/server/src/helpers/transaction.ts index ecf05d7..4be17a5 100644 --- a/server/src/helpers/transaction.ts +++ b/server/src/helpers/transaction.ts @@ -2,7 +2,7 @@ import { AccountIdentifier, Amount, Operation, OperationIdentifier } from 'roset import { EventRecord } from '@polkadot/types/interfaces'; import { BN } from '@polkadot/util'; -import { OperationsParams, OperationStatus, OpType } from '../types'; +import { OperationsParams, OperationStatus, OpType, TxMethodLC } from '../types'; import { u128, Vec } from '@polkadot/types-codec'; import { GenericExtrinsic } from '@polkadot/types'; import { AnyTuple } from '@polkadot/types-codec/types'; @@ -38,7 +38,12 @@ export async function getOperations( const dest = tx.args[0].toJSON()['id']; if (src && dest) { - const amount = new BN(tx.args[1].toString()); + let amount = null; + + if (tx.method.method.toLocaleLowerCase() !== TxMethodLC.TRANSFER_ALL) { + amount = new BN(tx.args[1].toString()); + } + operations.push( Operation.constructFromObject({ operation_identifier: new OperationIdentifier(operations.length), @@ -61,39 +66,41 @@ export async function getOperations( } } - var transactionFeeFromAddress = null - var transactionFeeAmount = null + var transactionFeeFromAddress = null; + var transactionFeeAmount = null; for (const event of events) { - const { event: { data } } = event; + const { + event: { data }, + } = event; if (isTransactionFeePaidEvent(event)) { - transactionFeeFromAddress = data[0].toString() - transactionFeeAmount = (data[1] as u128) - + transactionFeeFromAddress = data[0].toString(); + transactionFeeAmount = data[1] as u128; + const transactionFeeDebitOperation = Operation.constructFromObject({ - operation_identifier: new OperationIdentifier(operations.length), - type: OpType.TRANSACTION_FEE_PAID, - status: OperationStatus.SUCCESS, - account: new AccountIdentifier(transactionFeeFromAddress), - amount: new Amount(transactionFeeAmount.toBn().clone().neg().toString(), currency), - }) + operation_identifier: new OperationIdentifier(operations.length), + type: OpType.TRANSACTION_FEE_PAID, + status: OperationStatus.SUCCESS, + account: new AccountIdentifier(transactionFeeFromAddress), + amount: new Amount(transactionFeeAmount.toBn().clone().neg().toString(), currency), + }); operations.push(transactionFeeDebitOperation); break; } } - var transactionFeeWithdrawSkipped = false + var transactionFeeWithdrawSkipped = false; for (const event of events) { const { event: { data }, } = event; if (isTransferEvent(event)) { - const debitAccount = data[0].toString() - const creditAccount = data[1].toString() - const amount = (data[2] as u128).toBn() + const debitAccount = data[0].toString(); + const creditAccount = data[1].toString(); + const amount = (data[2] as u128).toBn(); operations.push( Operation.constructFromObject({ @@ -102,7 +109,6 @@ export async function getOperations( status: opStatus, account: new AccountIdentifier(debitAccount), amount: new Amount(amount.clone().neg().toString(), currency), - }), ); @@ -116,70 +122,70 @@ export async function getOperations( related_operations: [new OperationIdentifier(operations.length - 1)], }), ); - + continue; } if (isWithdrawEvent(event)) { - const account = data[0].toString() - const amount = (data[1] as u128) - + const account = data[0].toString(); + const amount = data[1] as u128; + const withdrawOperation = Operation.constructFromObject({ operation_identifier: new OperationIdentifier(operations.length), type: OpType.WITHDRAW, status: OperationStatus.SUCCESS, account: new AccountIdentifier(account), amount: new Amount(amount.toBn().clone().neg().toString(), currency), - }) + }); + + if (!transactionFeeWithdrawSkipped) { + const accountsMatch = account === transactionFeeFromAddress; + const amountsMatch = amount.eq(transactionFeeAmount); - if(!transactionFeeWithdrawSkipped) { - const accountsMatch = account === transactionFeeFromAddress - const amountsMatch = amount.eq(transactionFeeAmount) - if (accountsMatch && amountsMatch) { - transactionFeeWithdrawSkipped = true + transactionFeeWithdrawSkipped = true; continue; } } operations.push(withdrawOperation); - + continue; } if (isDepositEvent(event)) { - const account = data[0].toString() - const amount = data[1] as u128 - + const account = data[0].toString(); + const amount = data[1] as u128; + const depositOperation = Operation.constructFromObject({ operation_identifier: new OperationIdentifier(operations.length), type: OpType.DEPOSIT, status: OperationStatus.SUCCESS, account: new AccountIdentifier(account), amount: new Amount(amount.toString(), currency), - }) + }); operations.push(depositOperation); } if (isDustLostEvent(event)) { - const account = data[0].toString() - const amount = data[1] as u128 - + const account = data[0].toString(); + const amount = data[1] as u128; + const dustLostOperation = Operation.constructFromObject({ operation_identifier: new OperationIdentifier(operations.length), type: OpType.DUST_LOST, status: OperationStatus.SUCCESS, account: new AccountIdentifier(account), amount: new Amount(amount.toString(), currency), - }) + }); operations.push(dustLostOperation); } if (isReservedEvent(event)) { - const account = data[0].toString() - const amount = (data[1] as u128).toBn() + const account = data[0].toString(); + const amount = (data[1] as u128).toBn(); operations.push( Operation.constructFromObject({ @@ -194,8 +200,8 @@ export async function getOperations( } if (isUnreservedEvent(event)) { - const account = data[0].toString() - const amount = (data[1] as u128).toBn() + const account = data[0].toString(); + const amount = (data[1] as u128).toBn(); operations.push( Operation.constructFromObject({ @@ -210,8 +216,8 @@ export async function getOperations( } if (isReserveRepatrEvent(event)) { - const account = data[1].toString() - const amount = (data[2] as u128).toBn() + const account = data[1].toString(); + const amount = (data[2] as u128).toBn(); operations.push( Operation.constructFromObject({ @@ -230,7 +236,7 @@ export async function getOperations( const balance = new BN(await api.getBalanceAtBlock(acc, parentBlockHash)['balance']); const setBalanceAmount = (data[1] as u128).toBn(); const amount = setBalanceAmount.sub(balance).toString(); - + operations.push( Operation.constructFromObject({ operation_identifier: new OperationIdentifier(operations.length), @@ -268,7 +274,7 @@ export function getTxsAndEvents( for (const e of events) { if (e.phase.isApplyExtrinsic) { const txIndex = e.phase.asApplyExtrinsic.toNumber(); - + if (isBalanceEvent(e.event.section) || isTransactionPaymentEvent(e.event.section)) { if (txIndex in txIndexEvents) { txIndexEvents[txIndex].events.push(e);