Skip to content

Commit

Permalink
fix: add type to core space tx and fix type format (#1443)
Browse files Browse the repository at this point in the history
* fix: add type to core space tx and fix type format

* chore: version check
  • Loading branch information
iosh authored Nov 28, 2024
1 parent 66d012e commit ea2d4ce
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
11 changes: 11 additions & 0 deletions .yarn/versions/11720844.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion packages/rpc-engine/middlewares/validate-rpc-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
27 changes: 18 additions & 9 deletions packages/rpcs/cfx_signTransaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -228,25 +243,19 @@ 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,
)
} else {
raw = await signWithHardwareWallet({
args,
accountId: fromAddr.account.eid,
tx: newTx,
tx: formatTx(newTx),
addressId: fromAddr.eid,
device: fromAddr.account.accountGroup.vault.device,
})
Expand All @@ -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) {
Expand Down

0 comments on commit ea2d4ce

Please sign in to comment.