forked from cerc-io/laconicd-deprecated
remove duplicate query in receipts (#273)
* logs tests * updates * String() * remove extra query, add comments * test fixes * lint * lint
This commit is contained in:
@@ -110,11 +110,11 @@ func (st StateTransition) TransitionDb(ctx sdk.Context) (*ExecutionResult, error
|
||||
evm := st.newEVM(ctx, csdb, gasLimit, gasPrice.BigInt())
|
||||
|
||||
var (
|
||||
ret []byte
|
||||
leftOverGas uint64
|
||||
addr common.Address
|
||||
recipientLog string
|
||||
senderRef = vm.AccountRef(st.Sender)
|
||||
ret []byte
|
||||
leftOverGas uint64
|
||||
contractAddress common.Address
|
||||
recipientLog string
|
||||
senderRef = vm.AccountRef(st.Sender)
|
||||
)
|
||||
|
||||
// Get nonce of account outside of the EVM
|
||||
@@ -125,13 +125,13 @@ func (st StateTransition) TransitionDb(ctx sdk.Context) (*ExecutionResult, error
|
||||
// create contract or execute call
|
||||
switch contractCreation {
|
||||
case true:
|
||||
ret, addr, leftOverGas, err = evm.Create(senderRef, st.Payload, gasLimit, st.Amount)
|
||||
recipientLog = fmt.Sprintf("contract address %s", addr)
|
||||
ret, contractAddress, leftOverGas, err = evm.Create(senderRef, st.Payload, gasLimit, st.Amount)
|
||||
recipientLog = fmt.Sprintf("contract address %s", contractAddress.String())
|
||||
default:
|
||||
// Increment the nonce for the next transaction (just for evm state transition)
|
||||
csdb.SetNonce(st.Sender, csdb.GetNonce(st.Sender)+1)
|
||||
ret, leftOverGas, err = evm.Call(senderRef, *st.Recipient, st.Payload, gasLimit, st.Amount)
|
||||
recipientLog = fmt.Sprintf("recipient address %s", st.Recipient)
|
||||
recipientLog = fmt.Sprintf("recipient address %s", st.Recipient.String())
|
||||
}
|
||||
|
||||
gasConsumed := gasLimit - leftOverGas
|
||||
@@ -172,12 +172,15 @@ func (st StateTransition) TransitionDb(ctx sdk.Context) (*ExecutionResult, error
|
||||
}
|
||||
|
||||
// Encode all necessary data into slice of bytes to return in sdk result
|
||||
resultData := &ResultData{
|
||||
Address: addr,
|
||||
Bloom: bloomFilter,
|
||||
Logs: logs,
|
||||
Ret: ret,
|
||||
TxHash: *st.TxHash,
|
||||
resultData := ResultData{
|
||||
Bloom: bloomFilter,
|
||||
Logs: logs,
|
||||
Ret: ret,
|
||||
TxHash: *st.TxHash,
|
||||
}
|
||||
|
||||
if contractCreation {
|
||||
resultData.ContractAddress = contractAddress
|
||||
}
|
||||
|
||||
resBz, err := EncodeResultData(resultData)
|
||||
@@ -186,7 +189,7 @@ func (st StateTransition) TransitionDb(ctx sdk.Context) (*ExecutionResult, error
|
||||
}
|
||||
|
||||
resultLog := fmt.Sprintf(
|
||||
"executed EVM state transition; sender address %s; %s", st.Sender, recipientLog,
|
||||
"executed EVM state transition; sender address %s; %s", st.Sender.String(), recipientLog,
|
||||
)
|
||||
|
||||
executionResult := &ExecutionResult{
|
||||
|
||||
+21
-9
@@ -3,6 +3,7 @@ package types
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strings"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -53,27 +54,38 @@ func rlpHash(x interface{}) (hash ethcmn.Hash) {
|
||||
|
||||
// ResultData represents the data returned in an sdk.Result
|
||||
type ResultData struct {
|
||||
Address ethcmn.Address `json:"address"`
|
||||
Bloom ethtypes.Bloom `json:"bloom"`
|
||||
Logs []*ethtypes.Log `json:"logs"`
|
||||
Ret []byte `json:"ret"`
|
||||
TxHash ethcmn.Hash `json:"tx_hash"`
|
||||
ContractAddress ethcmn.Address `json:"contract_address"`
|
||||
Bloom ethtypes.Bloom `json:"bloom"`
|
||||
Logs []*ethtypes.Log `json:"logs"`
|
||||
Ret []byte `json:"ret"`
|
||||
TxHash ethcmn.Hash `json:"tx_hash"`
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer interface.
|
||||
func (rd ResultData) String() string {
|
||||
return strings.TrimSpace(fmt.Sprintf(`ResultData:
|
||||
ContractAddress: %s
|
||||
Bloom: %s
|
||||
Logs: %v
|
||||
Ret: %v
|
||||
TxHash: %s
|
||||
`, rd.ContractAddress.String(), rd.Bloom.Big().String(), rd.Logs, rd.Ret, rd.TxHash.String()))
|
||||
}
|
||||
|
||||
// EncodeResultData takes all of the necessary data from the EVM execution
|
||||
// and returns the data as a byte slice encoded with amino
|
||||
func EncodeResultData(data *ResultData) ([]byte, error) {
|
||||
func EncodeResultData(data ResultData) ([]byte, error) {
|
||||
return ModuleCdc.MarshalBinaryLengthPrefixed(data)
|
||||
}
|
||||
|
||||
// DecodeResultData decodes an amino-encoded byte slice into ResultData
|
||||
func DecodeResultData(in []byte) (ResultData, error) {
|
||||
data := new(ResultData)
|
||||
err := ModuleCdc.UnmarshalBinaryLengthPrefixed(in, data)
|
||||
var data ResultData
|
||||
err := ModuleCdc.UnmarshalBinaryLengthPrefixed(in, &data)
|
||||
if err != nil {
|
||||
return ResultData{}, err
|
||||
}
|
||||
return *data, nil
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// EncodeLogs encodes an array of logs using amino
|
||||
|
||||
@@ -9,13 +9,13 @@ import (
|
||||
)
|
||||
|
||||
func TestEvmDataEncoding(t *testing.T) {
|
||||
addr := ethcmn.HexToAddress("0x12345")
|
||||
addr := ethcmn.HexToAddress("0x5dE8a020088a2D6d0a23c204FFbeD02790466B49")
|
||||
bloom := ethtypes.BytesToBloom([]byte{0x1, 0x3})
|
||||
ret := []byte{0x5, 0x8}
|
||||
|
||||
data := &ResultData{
|
||||
Address: addr,
|
||||
Bloom: bloom,
|
||||
data := ResultData{
|
||||
ContractAddress: addr,
|
||||
Bloom: bloom,
|
||||
Logs: []*ethtypes.Log{{
|
||||
Data: []byte{1, 2, 3, 4},
|
||||
BlockNumber: 17,
|
||||
@@ -28,7 +28,7 @@ func TestEvmDataEncoding(t *testing.T) {
|
||||
|
||||
res, err := DecodeResultData(enc)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, addr, res.Address)
|
||||
require.Equal(t, addr, res.ContractAddress)
|
||||
require.Equal(t, bloom, res.Bloom)
|
||||
require.Equal(t, data.Logs, res.Logs)
|
||||
require.Equal(t, ret, res.Ret)
|
||||
|
||||
Reference in New Issue
Block a user