[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 := ""
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,
)

@ -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
}

Loading…
Cancel
Save