diff --git a/packages/caver-core-method/src/index.js b/packages/caver-core-method/src/index.js index dbd70669..22d9838d 100644 --- a/packages/caver-core-method/src/index.js +++ b/packages/caver-core-method/src/index.js @@ -38,6 +38,7 @@ const POLLINGTIMEOUT = AVERAGE_BLOCK_TIME * TIMEOUTBLOCK // ~average block time const TransactionDecoder = require('../../caver-transaction/src/transactionDecoder/transactionDecoder') const { TX_TYPE_STRING } = require('../../caver-transaction/src/transactionHelper/transactionHelper') +const { resolveRawKeyToAccountKey } = require('../../caver-klay/caver-klay-accounts/src/transactionType/account') function Method(options) { // call, name should be existed to create a method. @@ -427,6 +428,9 @@ const buildSendRequestFunc = (defer, sendSignedTx, sendTxCallback) => (payload, } } else if (key === 'codeFormat') { tx[key] = utils.hexToNumber(payload.params[0][key]) + } else if (key === 'key' && _.isObject(payload.params[0][key])) { + // If key field is `AccountForUpdate`, resolve this to raw encoded account key string. + tx.key = resolveRawKeyToAccountKey(payload.params[0]) } else if (key === 'account') { tx.key = payload.params[0][key].getRLPEncodingAccountKey() } else if (key === 'chainId') { diff --git a/packages/caver-klay/caver-klay-accounts/src/transactionType/account.js b/packages/caver-klay/caver-klay-accounts/src/transactionType/account.js index 210bf4f5..bf098852 100644 --- a/packages/caver-klay/caver-klay-accounts/src/transactionType/account.js +++ b/packages/caver-klay/caver-klay-accounts/src/transactionType/account.js @@ -243,4 +243,5 @@ module.exports = { rlpEncodeForFeeDelegatedAccountUpdate, rlpEncodeForFeeDelegatedAccountUpdateWithRatio, parseAccountKey, + resolveRawKeyToAccountKey, } diff --git a/packages/caver-transaction/src/transactionHelper/transactionHelper.js b/packages/caver-transaction/src/transactionHelper/transactionHelper.js index deeaf9c3..0932ac69 100644 --- a/packages/caver-transaction/src/transactionHelper/transactionHelper.js +++ b/packages/caver-transaction/src/transactionHelper/transactionHelper.js @@ -175,6 +175,36 @@ const TX_TYPE_TAG = { '0x7802': TX_TYPE_STRING.TxTypeEthereumDynamicFee, } +const TX_TYPE_TAG_LEGACY_TX_TYPES = { + ACCOUNT_UPDATE: TX_TYPE_TAG.TxTypeAccountUpdate, + FEE_DELEGATED_ACCOUNT_UPDATE: TX_TYPE_TAG.TxTypeFeeDelegatedAccountUpdate, + FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO: TX_TYPE_TAG.TxTypeFeeDelegatedAccountUpdateWithRatio, + + VALUE_TRANFSER: TX_TYPE_TAG.TxTypeValueTransfer, + FEE_DELEGATED_VALUE_TRANSFER: TX_TYPE_TAG.TxTypeFeeDelegatedValueTransfer, + FEE_DELEGATED_VALUE_TRANSFER_WITH_RATIO: TX_TYPE_TAG.TxTypeFeeDelegatedValueTransferWithRatio, + + VALUE_TRANSFER_MEMO: TX_TYPE_TAG.TxTypeValueTransferMemo, + FEE_DELEGATED_VALUE_TRANSFER_MEMO: TX_TYPE_TAG.TxTypeFeeDelegatedValueTransferMemo, + FEE_DELEGATED_VALUE_TRANSFER_MEMO_WITH_RATIO: TX_TYPE_TAG.TxTypeFeeDelegatedValueTransferMemoWithRatio, + + SMART_CONTRACT_DEPLOY: TX_TYPE_TAG.TxTypeSmartContractDeploy, + FEE_DELEGATED_SMART_CONTRACT_DEPLOY: TX_TYPE_TAG.TxTypeFeeDelegatedSmartContractDeploy, + FEE_DELEGATED_SMART_CONTRACT_DEPLOY_WITH_RATIO: TX_TYPE_TAG.TxTypeFeeDelegatedSmartContractDeployWithRatio, + + SMART_CONTRACT_EXECUTION: TX_TYPE_TAG.TxTypeSmartContractExecution, + FEE_DELEGATED_SMART_CONTRACT_EXECUTION: TX_TYPE_TAG.TxTypeFeeDelegatedSmartContractExecution, + FEE_DELEGATED_SMART_CONTRACT_EXECUTION_WITH_RATIO: TX_TYPE_TAG.TxTypeFeeDelegatedSmartContractExecutionWithRatio, + + CANCEL: TX_TYPE_TAG.TxTypeCancel, + FEE_DELEGATED_CANCEL: TX_TYPE_TAG.TxTypeFeeDelegatedCancel, + FEE_DELEGATED_CANCEL_WITH_RATIO: TX_TYPE_TAG.TxTypeFeeDelegatedCancelWithRatio, + + CHAIN_DATA_ANCHORING: TX_TYPE_TAG.TxTypeChainDataAnchoring, + FEE_DELEGATED_CHAIN_DATA_ANCHORING: TX_TYPE_TAG.TxTypeFeeDelegatedChainDataAnchoring, + FEE_DELEGATED_CHAIN_DATA_ANCHORING_WITH_RATIO: TX_TYPE_TAG.TxTypeFeeDelegatedChainDataAnchoringWithRatio, +} + const CODE_FORMAT = { EVM: '0x0', } @@ -186,7 +216,12 @@ const CODE_FORMAT = { * @return {number} */ const getTypeInt = type => { - return utils.hexToNumber(TX_TYPE_TAG[type]) + let typeInt = TX_TYPE_TAG[type] + // If type int cannot be found from TX_TYPE_TAG, means old type string. + if (typeInt === undefined) { + typeInt = TX_TYPE_TAG_LEGACY_TX_TYPES[type] + } + return utils.hexToNumber(typeInt) } /** diff --git a/test/personal.js b/test/personal.js index d7aa3cf4..1d988638 100644 --- a/test/personal.js +++ b/test/personal.js @@ -136,6 +136,28 @@ describe('Personal RPC test', () => { expect(receipt.type).to.equals('TxTypeLegacyTransaction') }).timeout(50000) + // sendTransaction with account update tx + it('CAVERJS-UNIT-ETC-404: sendTransaction should format a transaction to send tx with account in Node.', async () => { + try { + // If account is already existed in node, return error. + const address = await caver.klay.personal.importRawKey(senderPrvKey, password) + expect(address.toLowerCase()).to.equals(senderAddress.toLowerCase()) + } catch (e) {} + + const receipt = await caver.klay.personal.sendTransaction( + { + type: 'ACCOUNT_UPDATE', + from: senderAddress, + key: caver.klay.accounts.createAccountForUpdateWithLegacyKey(senderAddress), + gas: 900000, + }, + password + ) + console.log(receipt) + expect(receipt).not.to.be.null + expect(receipt.type).to.equals('TxTypeAccountUpdate') + }).timeout(50000) + // signTransaction it('CAVERJS-UNIT-ETC-088: signTransaction should send a signed transaction using an account in the node.', async () => { const testAccount = caver.klay.accounts.create()