|
1 | 1 | import { NetworkType } from '@bitgo/statics'; |
2 | 2 | import EthereumCommon from '@ethereumjs/common'; |
3 | | -import { recoverTransaction } from '@celo/wallet-base'; |
4 | | -import * as ethers from 'ethers'; |
5 | | -import BigNumber from 'bignumber.js'; |
6 | | -import { ETHTransactionType, LegacyTxData } from '@bitgo/sdk-coin-eth'; |
7 | | -import { InvalidTransactionError, ParseTransactionError } from '@bitgo/sdk-core'; |
| 3 | +import { InvalidTransactionError } from '@bitgo/sdk-core'; |
8 | 4 | import { mainnetCommon, testnetCommon } from './resources'; |
9 | 5 |
|
10 | | -/** |
11 | | - * Celo transaction deserialization based on code |
12 | | - * from @celo/contractkit/lib/utils/signing-utils |
13 | | - * github: https://github.com/celo-org/celo-monorepo/tree/master/packages/contractkit |
14 | | - * |
15 | | - * @param {string} serializedTx the serialized transaction |
16 | | - * @returns {LegacyTxData} the deserialized transaction |
17 | | - */ |
18 | | -export function deserialize(serializedTx: string): LegacyTxData { |
19 | | - try { |
20 | | - const decodedTx = ethers.utils.RLP.decode(serializedTx); |
21 | | - decodedTx.splice(3, 3); // remove unused feeCurrency, gatewayFeeRecipient and gatewayFee |
22 | | - const [nonce, gasPrice, gasLimit, to, value, data, v, r, s] = decodedTx; |
23 | | - let chainId = v; |
24 | | - let from; |
25 | | - if (r !== '0x' && s !== '0x') { |
26 | | - const [tx, sender] = recoverTransaction(serializedTx); |
27 | | - from = sender; |
28 | | - chainId = tx.chainId; |
29 | | - } |
30 | | - const celoTx: LegacyTxData = { |
31 | | - _type: ETHTransactionType.LEGACY, |
32 | | - nonce: nonce.toLowerCase() === '0x' ? 0 : parseInt(nonce, 16), |
33 | | - gasPrice: gasPrice.toLowerCase() === '0x' ? '0' : new BigNumber(gasPrice, 16).toString(), |
34 | | - gasLimit: gasLimit.toLowerCase() === '0x' ? '0' : new BigNumber(gasLimit, 16).toString(), |
35 | | - value: value.toLowerCase() === '0x' ? '0' : new BigNumber(value, 16).toString(), |
36 | | - data, |
37 | | - chainId, |
38 | | - from, |
39 | | - v, |
40 | | - r, |
41 | | - s, |
42 | | - }; |
43 | | - |
44 | | - if (to !== '0x') { |
45 | | - celoTx.to = to; |
46 | | - } |
47 | | - |
48 | | - return celoTx; |
49 | | - } catch { |
50 | | - throw new ParseTransactionError('Invalid serialized transaction'); |
51 | | - } |
52 | | -} |
53 | | - |
54 | 6 | const commons: Map<NetworkType, EthereumCommon> = new Map<NetworkType, EthereumCommon>([ |
55 | 7 | [NetworkType.MAINNET, mainnetCommon], |
56 | 8 | [NetworkType.TESTNET, testnetCommon], |
|
0 commit comments