From e165c4d55c5bd9897c233b6770a70d183ba5ee70 Mon Sep 17 00:00:00 2001 From: Daniel Van Der Maden Date: Tue, 3 Nov 2020 11:34:31 -0800 Subject: [PATCH] [rosetta] Support EVM pre-process for contract creation txs (#3424) * [rosetta] Support EVM pre-process for contract creation txs Signed-off-by: Daniel Van Der Maden * [rosetta] Fix re-delegation amount Signed-off-by: Daniel Van Der Maden --- rosetta/services/construction_check.go | 9 +++++---- rosetta/services/tx_operation.go | 14 +++++--------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/rosetta/services/construction_check.go b/rosetta/services/construction_check.go index 53d1b5f2a..e38eb6a36 100644 --- a/rosetta/services/construction_check.go +++ b/rosetta/services/construction_check.go @@ -240,16 +240,17 @@ func (s *ConstructAPI) ConstructionMetadata( evmErrorMsg := "" evmReturn := hexutil.Bytes{} - if !isStakingOperation(options.OperationType) && - options.OperationType != common.ContractCreationOperation && - len(data) > 0 { + if len(data) > 0 && (options.OperationType == common.ContractCreationOperation || + options.OperationType == common.NativeTransferOperation) { gas := hexutil.Uint64(estGasUsed) callArgs := rpc.CallArgs{ From: senderAddr, - To: &contractAddress, Data: &data, Gas: &gas, } + if options.OperationType == common.NativeTransferOperation { + callArgs.To = &contractAddress + } evmExe, err := rpc.DoEVMCall( ctx, s.hmy, callArgs, ethRpc.LatestBlockNumber, vm.Config{}, rpc.CallTimeout, s.hmy.RPCGasCap, ) diff --git a/rosetta/services/tx_operation.go b/rosetta/services/tx_operation.go index 682e6645c..8d7f4a28b 100644 --- a/rosetta/services/tx_operation.go +++ b/rosetta/services/tx_operation.go @@ -158,20 +158,16 @@ func getAmountFromDelegateMessage(receipt *hmytypes.Receipt, data []byte) (*type }) } - stkAmount := stkMsg.Amount + deductedAmt := stkMsg.Amount logs := hmytypes.FindLogsWithTopic(receipt, staking.DelegateTopic) for _, log := range logs { - if len(log.Data) > ethcommon.AddressLength { - validatorAddress := ethcommon.BytesToAddress(log.Data[:ethcommon.AddressLength]) - if log.Address == stkMsg.DelegatorAddress && stkMsg.ValidatorAddress == validatorAddress { - // Remove re-delegation amount as funds were never credited to account's balance. - stkAmount = new(big.Int).Sub(stkAmount, new(big.Int).SetBytes(log.Data[ethcommon.AddressLength:])) - break - } + if len(log.Data) > ethcommon.AddressLength && log.Address == stkMsg.DelegatorAddress { + // Remove re-delegation amount as funds were never credited to account's balance. + deductedAmt = new(big.Int).Sub(deductedAmt, new(big.Int).SetBytes(log.Data[ethcommon.AddressLength:])) } } return &types.Amount{ - Value: negativeBigValue(stkAmount), + Value: negativeBigValue(deductedAmt), Currency: &common.NativeCurrency, }, nil }