From ea2d4ce751641b0e584845abfcd7cf89d0184402 Mon Sep 17 00:00:00 2001 From: H Date: Thu, 28 Nov 2024 15:51:19 +0800 Subject: [PATCH] fix: add type to core space tx and fix type format (#1443) * fix: add type to core space tx and fix type format * chore: version check --- .yarn/versions/11720844.yml | 11 ++++++++ .../middlewares/validate-rpc-params.js | 7 ++++- packages/rpcs/cfx_signTransaction/index.js | 27 ++++++++++++------- 3 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 .yarn/versions/11720844.yml diff --git a/.yarn/versions/11720844.yml b/.yarn/versions/11720844.yml new file mode 100644 index 00000000..f90f2767 --- /dev/null +++ b/.yarn/versions/11720844.yml @@ -0,0 +1,11 @@ +releases: + "@fluent-wallet/cfx_send-transaction": patch + "@fluent-wallet/cfx_sign-transaction": patch + "@fluent-wallet/rpc-engine": patch + "@fluent-wallet/wallet_send-transaction": patch + "@fluent-wallet/wallet_send-transaction-with-action": patch + browser-extension: patch + helios-background: patch + +declined: + - helios diff --git a/packages/rpc-engine/middlewares/validate-rpc-params.js b/packages/rpc-engine/middlewares/validate-rpc-params.js index d07b6257..80f184c6 100644 --- a/packages/rpc-engine/middlewares/validate-rpc-params.js +++ b/packages/rpc-engine/middlewares/validate-rpc-params.js @@ -34,8 +34,13 @@ export default defMiddleware(({tx: {map, comp}}) => ({ const {params, method} = req const {schemas, Err} = rpcStore[method] // TODO: add a preprocess middleware to transform req params for more compatibilities - if (method === 'eth_sendTransaction' && isArray(params)) + if ( + (method === 'eth_sendTransaction' || + method === 'cfx_sendTransaction') && + isArray(params) + ) { params[0] = preprocessTx(params[0]) + } if (schemas.input) { if (!validate(schemas.input, params, {netId: req.network.netId})) { throw Err.InvalidParams( diff --git a/packages/rpcs/cfx_signTransaction/index.js b/packages/rpcs/cfx_signTransaction/index.js index 9b07d2e7..ab1c8a53 100644 --- a/packages/rpcs/cfx_signTransaction/index.js +++ b/packages/rpcs/cfx_signTransaction/index.js @@ -88,6 +88,16 @@ export const permissions = { db: ['findAddress'], } +// conflux js sdk +// hex type must be integer +function formatTx(tx) { + const newTx = {...tx} + + if (newTx.type && typeof newTx.type === 'string') { + newTx.type = parseInt(tx.type, 16) + } + return newTx +} export const main = async args => { const { app, @@ -153,6 +163,11 @@ export const main = async args => { } else { newTx.type = ETH_TX_TYPES.LEGACY } + } else { + // if there has type, we need check is v1.x ledger app + if (isV1LedgerAPP) { + newTx.type = ETH_TX_TYPES.LEGACY + } } // tx without to must have data (deploy contract) @@ -228,17 +243,11 @@ export const main = async args => { ).toHexString() } - // change the type to number - - if (newTx.type && typeof newTx.type === 'string') { - newTx.type = Number.parseInt(newTx.type, 16) - } - let raw if (fromAddr.account.accountGroup.vault.type === 'hw') { if (dryRun) { raw = cfxSignTransaction( - newTx, + formatTx(newTx), '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef', network.netId, ) @@ -246,7 +255,7 @@ export const main = async args => { raw = await signWithHardwareWallet({ args, accountId: fromAddr.account.eid, - tx: newTx, + tx: formatTx(newTx), addressId: fromAddr.eid, device: fromAddr.account.accountGroup.vault.device, }) @@ -259,7 +268,7 @@ export const main = async args => { if (dryRun) pk = '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' - raw = cfxSignTransaction(newTx, pk, network.netId) + raw = cfxSignTransaction(formatTx(newTx), pk, network.netId) } if (returnTxMeta) {