diff --git a/packages/neuron-wallet/src/controllers/multisig.ts b/packages/neuron-wallet/src/controllers/multisig.ts index ea41a69bb1..d9211d06fd 100644 --- a/packages/neuron-wallet/src/controllers/multisig.ts +++ b/packages/neuron-wallet/src/controllers/multisig.ts @@ -5,6 +5,7 @@ import { t } from 'i18next' import { computeScriptHash as scriptToHash } from '@ckb-lumos/base/lib/utils' import { scriptToAddress, addressToScript } from '../utils/scriptAndAddress' import { ResponseCode } from '../utils/const' +import { parseMultisigTxJsonFromCkbCli } from '../utils/multisig' import MultisigConfig from '../database/chain/entities/multisig-config' import MultisigConfigModel from '../models/multisig-config' import MultisigService from '../services/multisig' @@ -214,7 +215,12 @@ export default class MultisigController { } const tx = result.json const lockHash = scriptToHash(addressToScript(fullPayload)) - if (tx.transaction.inputs.every(v => v.lockHash !== lockHash)) { + + if (tx.transaction && tx?.multisig_configs) { + tx.transaction = parseMultisigTxJsonFromCkbCli(tx) + } + + if (tx.transaction.inputs.every(v => v.lockHash && v.lockHash !== lockHash)) { ShowGlobalDialogSubject.next({ type: 'failed', title: t('common.error'), @@ -226,7 +232,7 @@ export default class MultisigController { } return { status: ResponseCode.Success, - result: result?.json, + result: tx, } } } diff --git a/packages/neuron-wallet/src/models/offline-sign.ts b/packages/neuron-wallet/src/models/offline-sign.ts index 2fd73a0d93..934f5d3ad9 100644 --- a/packages/neuron-wallet/src/models/offline-sign.ts +++ b/packages/neuron-wallet/src/models/offline-sign.ts @@ -44,6 +44,7 @@ export interface OfflineSignJSON { description?: string asset_account?: AssetAccount multisig_configs?: MultisigConfigs + signatures?: Signatures } export default class OfflineSign implements OfflineSignProps { diff --git a/packages/neuron-wallet/src/utils/hump.ts b/packages/neuron-wallet/src/utils/hump.ts new file mode 100644 index 0000000000..b618c5f918 --- /dev/null +++ b/packages/neuron-wallet/src/utils/hump.ts @@ -0,0 +1,25 @@ +export function hump(param: any) { + Object.keys(param).map(key => { + let item = param[key] + if (item instanceof Object || item instanceof Array) { + hump(item) + } + if (humpString(key) !== key) { + param[humpString(key)] = param[key] + delete param[key] + } + }) + return param +} + +export function humpString(key: string) { + let keyArr = key.split('_') + for (let i = 0; i < keyArr.length; i++) { + if (i !== 0) { + keyArr[i] = keyArr[i][0].toUpperCase() + keyArr[i].substr(1) + } + } + return keyArr.join('') +} + +export default { hump, humpString } diff --git a/packages/neuron-wallet/src/utils/multisig.ts b/packages/neuron-wallet/src/utils/multisig.ts index 4ef4e7c058..6254f6bb74 100644 --- a/packages/neuron-wallet/src/utils/multisig.ts +++ b/packages/neuron-wallet/src/utils/multisig.ts @@ -2,6 +2,12 @@ import { computeScriptHash as scriptToHash } from '@ckb-lumos/base/lib/utils' import Multisig from '../models/multisig' import MultisigConfigModel from '../models/multisig-config' import { Signatures, SignStatus } from '../models/offline-sign' +import { OfflineSignJSON } from 'src/models/offline-sign' +import Transaction from '../models/chain/transaction' +import SystemScriptInfo from '../models/system-script-info' +import Input from '../models/chain/input' +import { hump } from './hump' +import { DepType } from '../models/chain/cell-dep' export const getMultisigStatus = (multisigConfig: MultisigConfigModel, signatures: Signatures) => { const multisigLockHash = scriptToHash( @@ -27,6 +33,39 @@ export const getMultisigStatus = (multisigConfig: MultisigConfigModel, signature return SignStatus.Signed } +export const parseMultisigTxJsonFromCkbCli = (tx: OfflineSignJSON): Transaction => { + const { multisig_configs } = tx + const txObj = hump(tx.transaction) + + if (multisig_configs) { + const args = Object.keys(multisig_configs)[0] + const lock = SystemScriptInfo.generateMultiSignScript(args) + + txObj.inputs.forEach((input: Input) => { + if (!input?.lock) { + input.lock = lock + } + }) + } + + if (!tx.transaction?.signatures && tx?.signatures) { + tx.transaction.signatures = tx.signatures + delete tx.signatures + } + + if (tx.transaction.cellDeps) { + tx.transaction.cellDeps.forEach(item => { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-expect-error + if (item.depType === 'dep_group') { + item.depType = DepType.DepGroup + } + }) + } + return txObj +} + export default { getMultisigStatus, + parseMultisigTxJsonFromCkbCli, }