From 15900b21e70354db2a57bbab4c38599822098252 Mon Sep 17 00:00:00 2001 From: yanguoyu <841185308@qq.com> Date: Thu, 14 Jul 2022 14:57:23 +0800 Subject: [PATCH 1/4] fix: Same group cell witness should be 0x. If witness's lock set as 0x. it will be serialized that not equal 0x --- .../src/services/transaction-sender.ts | 3 -- .../services/tx/transaction-sender.test.ts | 41 +++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/packages/neuron-wallet/src/services/transaction-sender.ts b/packages/neuron-wallet/src/services/transaction-sender.ts index 756ee70a78..2c95facbda 100644 --- a/packages/neuron-wallet/src/services/transaction-sender.ts +++ b/packages/neuron-wallet/src/services/transaction-sender.ts @@ -293,9 +293,6 @@ export default class TransactionSender { const lockArgs: string = input.lock!.args! const wit: WitnessArgs | string = tx.witnesses[index] const witnessArgs: WitnessArgs = wit instanceof WitnessArgs ? wit : WitnessArgs.generateEmpty() - if (typeof wit === 'string' && wit.length) { - witnessArgs.lock = wit - } return { witnessArgs, lockHash: input.lockHash!, diff --git a/packages/neuron-wallet/tests/services/tx/transaction-sender.test.ts b/packages/neuron-wallet/tests/services/tx/transaction-sender.test.ts index 8269aa7ed1..63d6bf675e 100644 --- a/packages/neuron-wallet/tests/services/tx/transaction-sender.test.ts +++ b/packages/neuron-wallet/tests/services/tx/transaction-sender.test.ts @@ -983,6 +983,47 @@ describe('TransactionSender Test', () => { expect(res.witnesses[0]).toBe(expectedValue) }) }) + + it(`input cell's length is 2`, async() => { + const addresses = [ + 'ckt1qyq89x5ggpt0a5epm2k2gyxeffwkgfdxeg0s543mh4', + 'ckt1qyqql0vgjyxjxjxknkj6nq8jxa485xsyl66sy7c5f6' + ] + const [multiArgs, multisigConfig] = createMultisigConfig(1, 1, addresses) + const addr = { + walletId: fakeWallet.id, + path: `m/44'/309'/0'/0/0`, + blake160: addressToScript(addresses[0]).args, + version: 'testnet' + } + + const mockGAI = jest.fn() + mockGAI.mockReturnValueOnce([addr]) + transactionSender.getAddressInfos = mockGAI.bind(transactionSender) + const tx = Transaction.fromObject(transcationObject) + tx.inputs[0]!.setLock(SystemScriptInfo.generateMultiSignScript(multiArgs)) + tx.inputs.push( + Input.fromObject({ + previousOutput: OutPoint.fromObject({ + txHash: '0x1879851943fa686af29bed5c95acd566d0244e7b3ca89cf7c435622a5a5b4cb3', + index: '0x0' + }), + since: '0x0', + lock: Script.fromObject({ + args: multiArgs, + codeHash: SystemScriptInfo.MULTI_SIGN_CODE_HASH, + hashType: SystemScriptInfo.MULTI_SIGN_HASH_TYPE + }) + }) + ) + tx.witnesses = ['0x', '0x'] + const res = await transactionSender.signMultisig(fakeWallet.id, tx, '1234', [multisigConfig]) + expect(res.witnesses).toHaveLength(2) + expect(res.witnesses[1]).toBe('0x') + expect(res.witnesses[0]).toBe( + '0x810000001000000081000000810000006d00000000010102729a884056fed321daaca410d94a5d6425a6ca1f0fbd88910d2348d69da5a980f2376a7a1a04feb595163e5edf15f297453a64f3248c69823afcfdaabc6771b088e4f6250e2e2f91136f5c6a9cbf49a79d955644d7381481f3c5c8ab93bcc52a71de4b072e0697c001' + ) + }) }) }) }) From 88fb8d13286e6c3086bcaf12b62afb8722a4a1c6 Mon Sep 17 00:00:00 2001 From: yanguoyu <841185308@qq.com> Date: Thu, 14 Jul 2022 15:11:54 +0800 Subject: [PATCH 2/4] fix: If some unexpected error happen, it should display --- .../neuron-ui/src/components/PasswordRequest/index.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/neuron-ui/src/components/PasswordRequest/index.tsx b/packages/neuron-ui/src/components/PasswordRequest/index.tsx index be548dc745..13008abe64 100644 --- a/packages/neuron-ui/src/components/PasswordRequest/index.tsx +++ b/packages/neuron-ui/src/components/PasswordRequest/index.tsx @@ -25,6 +25,7 @@ import { OfflineSignType, signAndExportTransaction, requestOpenInExplorer, + invokeShowErrorMessage, } from 'services/remote' import { PasswordIncorrectException } from 'exceptions' import DropdownButton from 'widgets/DropdownButton' @@ -152,11 +153,16 @@ const PasswordRequest = () => { break } await sendTransaction({ walletID, tx: generatedTx, description, password, multisigConfig })(dispatch).then( - (res: { result: string; status: number }) => { + (res: { result: string; status: number; message: string | { content: string } }) => { if (isSuccessResponse(res)) { requestOpenInExplorer({ type: 'transaction', key: res.result }) } else if (res.status === ErrorCode.PasswordIncorrect) { throw new PasswordIncorrectException() + } else { + invokeShowErrorMessage({ + title: t('messages.error'), + content: typeof res.message === 'string' ? res.message : res.message.content!, + }) } } ) From cd85ac8e3fd034e229767e67bdb9242998bf7b48 Mon Sep 17 00:00:00 2001 From: yanguoyu <841185308@qq.com> Date: Thu, 14 Jul 2022 14:57:23 +0800 Subject: [PATCH 3/4] fix: Fix send multisig tx when input cell's length is more than 1. same group cell witness should be 0x. If witness's lock set as 0x. it will be serialized that not equal 0x --- .../src/services/transaction-sender.ts | 3 -- .../services/tx/transaction-sender.test.ts | 41 +++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/packages/neuron-wallet/src/services/transaction-sender.ts b/packages/neuron-wallet/src/services/transaction-sender.ts index 756ee70a78..2c95facbda 100644 --- a/packages/neuron-wallet/src/services/transaction-sender.ts +++ b/packages/neuron-wallet/src/services/transaction-sender.ts @@ -293,9 +293,6 @@ export default class TransactionSender { const lockArgs: string = input.lock!.args! const wit: WitnessArgs | string = tx.witnesses[index] const witnessArgs: WitnessArgs = wit instanceof WitnessArgs ? wit : WitnessArgs.generateEmpty() - if (typeof wit === 'string' && wit.length) { - witnessArgs.lock = wit - } return { witnessArgs, lockHash: input.lockHash!, diff --git a/packages/neuron-wallet/tests/services/tx/transaction-sender.test.ts b/packages/neuron-wallet/tests/services/tx/transaction-sender.test.ts index 8269aa7ed1..63d6bf675e 100644 --- a/packages/neuron-wallet/tests/services/tx/transaction-sender.test.ts +++ b/packages/neuron-wallet/tests/services/tx/transaction-sender.test.ts @@ -983,6 +983,47 @@ describe('TransactionSender Test', () => { expect(res.witnesses[0]).toBe(expectedValue) }) }) + + it(`input cell's length is 2`, async() => { + const addresses = [ + 'ckt1qyq89x5ggpt0a5epm2k2gyxeffwkgfdxeg0s543mh4', + 'ckt1qyqql0vgjyxjxjxknkj6nq8jxa485xsyl66sy7c5f6' + ] + const [multiArgs, multisigConfig] = createMultisigConfig(1, 1, addresses) + const addr = { + walletId: fakeWallet.id, + path: `m/44'/309'/0'/0/0`, + blake160: addressToScript(addresses[0]).args, + version: 'testnet' + } + + const mockGAI = jest.fn() + mockGAI.mockReturnValueOnce([addr]) + transactionSender.getAddressInfos = mockGAI.bind(transactionSender) + const tx = Transaction.fromObject(transcationObject) + tx.inputs[0]!.setLock(SystemScriptInfo.generateMultiSignScript(multiArgs)) + tx.inputs.push( + Input.fromObject({ + previousOutput: OutPoint.fromObject({ + txHash: '0x1879851943fa686af29bed5c95acd566d0244e7b3ca89cf7c435622a5a5b4cb3', + index: '0x0' + }), + since: '0x0', + lock: Script.fromObject({ + args: multiArgs, + codeHash: SystemScriptInfo.MULTI_SIGN_CODE_HASH, + hashType: SystemScriptInfo.MULTI_SIGN_HASH_TYPE + }) + }) + ) + tx.witnesses = ['0x', '0x'] + const res = await transactionSender.signMultisig(fakeWallet.id, tx, '1234', [multisigConfig]) + expect(res.witnesses).toHaveLength(2) + expect(res.witnesses[1]).toBe('0x') + expect(res.witnesses[0]).toBe( + '0x810000001000000081000000810000006d00000000010102729a884056fed321daaca410d94a5d6425a6ca1f0fbd88910d2348d69da5a980f2376a7a1a04feb595163e5edf15f297453a64f3248c69823afcfdaabc6771b088e4f6250e2e2f91136f5c6a9cbf49a79d955644d7381481f3c5c8ab93bcc52a71de4b072e0697c001' + ) + }) }) }) }) From 14ebf17be8c2d4aafc4da40c046ec77c5b911676 Mon Sep 17 00:00:00 2001 From: yanguoyu <841185308@qq.com> Date: Thu, 14 Jul 2022 15:11:54 +0800 Subject: [PATCH 4/4] fix: If some unexpected error happen, it should display --- .../neuron-ui/src/components/PasswordRequest/index.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/neuron-ui/src/components/PasswordRequest/index.tsx b/packages/neuron-ui/src/components/PasswordRequest/index.tsx index be548dc745..13008abe64 100644 --- a/packages/neuron-ui/src/components/PasswordRequest/index.tsx +++ b/packages/neuron-ui/src/components/PasswordRequest/index.tsx @@ -25,6 +25,7 @@ import { OfflineSignType, signAndExportTransaction, requestOpenInExplorer, + invokeShowErrorMessage, } from 'services/remote' import { PasswordIncorrectException } from 'exceptions' import DropdownButton from 'widgets/DropdownButton' @@ -152,11 +153,16 @@ const PasswordRequest = () => { break } await sendTransaction({ walletID, tx: generatedTx, description, password, multisigConfig })(dispatch).then( - (res: { result: string; status: number }) => { + (res: { result: string; status: number; message: string | { content: string } }) => { if (isSuccessResponse(res)) { requestOpenInExplorer({ type: 'transaction', key: res.result }) } else if (res.status === ErrorCode.PasswordIncorrect) { throw new PasswordIncorrectException() + } else { + invokeShowErrorMessage({ + title: t('messages.error'), + content: typeof res.message === 'string' ? res.message : res.message.content!, + }) } } )