[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 <dvandermaden0@berkeley.edu>

* [rosetta] Fix re-delegation amount

Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
pull/3435/head
Daniel Van Der Maden 4 years ago committed by GitHub
parent fea096b0f9
commit e165c4d55c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      rosetta/services/construction_check.go
  2. 14
      rosetta/services/tx_operation.go

@ -240,16 +240,17 @@ func (s *ConstructAPI) ConstructionMetadata(
evmErrorMsg := "" evmErrorMsg := ""
evmReturn := hexutil.Bytes{} evmReturn := hexutil.Bytes{}
if !isStakingOperation(options.OperationType) && if len(data) > 0 && (options.OperationType == common.ContractCreationOperation ||
options.OperationType != common.ContractCreationOperation && options.OperationType == common.NativeTransferOperation) {
len(data) > 0 {
gas := hexutil.Uint64(estGasUsed) gas := hexutil.Uint64(estGasUsed)
callArgs := rpc.CallArgs{ callArgs := rpc.CallArgs{
From: senderAddr, From: senderAddr,
To: &contractAddress,
Data: &data, Data: &data,
Gas: &gas, Gas: &gas,
} }
if options.OperationType == common.NativeTransferOperation {
callArgs.To = &contractAddress
}
evmExe, err := rpc.DoEVMCall( evmExe, err := rpc.DoEVMCall(
ctx, s.hmy, callArgs, ethRpc.LatestBlockNumber, vm.Config{}, rpc.CallTimeout, s.hmy.RPCGasCap, ctx, s.hmy, callArgs, ethRpc.LatestBlockNumber, vm.Config{}, rpc.CallTimeout, s.hmy.RPCGasCap,
) )

@ -158,20 +158,16 @@ func getAmountFromDelegateMessage(receipt *hmytypes.Receipt, data []byte) (*type
}) })
} }
stkAmount := stkMsg.Amount deductedAmt := stkMsg.Amount
logs := hmytypes.FindLogsWithTopic(receipt, staking.DelegateTopic) logs := hmytypes.FindLogsWithTopic(receipt, staking.DelegateTopic)
for _, log := range logs { for _, log := range logs {
if len(log.Data) > ethcommon.AddressLength { if len(log.Data) > ethcommon.AddressLength && log.Address == stkMsg.DelegatorAddress {
validatorAddress := ethcommon.BytesToAddress(log.Data[:ethcommon.AddressLength]) // Remove re-delegation amount as funds were never credited to account's balance.
if log.Address == stkMsg.DelegatorAddress && stkMsg.ValidatorAddress == validatorAddress { deductedAmt = new(big.Int).Sub(deductedAmt, new(big.Int).SetBytes(log.Data[ethcommon.AddressLength:]))
// 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
}
} }
} }
return &types.Amount{ return &types.Amount{
Value: negativeBigValue(stkAmount), Value: negativeBigValue(deductedAmt),
Currency: &common.NativeCurrency, Currency: &common.NativeCurrency,
}, nil }, nil
} }

Loading…
Cancel
Save