Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
feat: use sdk.Int for TxData (#208)
Browse files Browse the repository at this point in the history
* feat: use sdk.Int for TxData

* c++

* fix

* fix test

* fix rpc

* lint
  • Loading branch information
fedekunze authored Jun 30, 2021
1 parent 0113b4d commit 86e30e8
Show file tree
Hide file tree
Showing 24 changed files with 388 additions and 1,114 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking

* (proto, evm) [tharsis#207](https://github.com/tharsis/ethermint/issues/207) Replace `big.Int` in favor of `sdk.Int` for `TxData` fields
* (proto, evm) [tharsis#81](https://github.com/tharsis/ethermint/pull/81) gRPC Query and Tx service changes:
* The `TxReceipt`, `TxReceiptsByBlockHeight` endpoints have been removed from the Query service.
* The `ContractAddress`, `Bloom` have been removed from the `MsgEthereumTxResponse` and the
Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ var (
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, // used for secure addition and substraction of balance using module account
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, // used for secure addition and subtraction of balance using module account
}

// module accounts that are allowed to receive tokens
Expand Down
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ paths:
properties:
balance:
type: string
format: int64
description: balance is the balance of the EVM denomination.
code_hash:
type: string
Expand Down Expand Up @@ -71,6 +72,7 @@ paths:
properties:
balance:
type: string
format: int64
description: balance is the balance of the EVM denomination.
description: >-
QueryBalanceResponse is the response type for the Query/Balance
Expand Down Expand Up @@ -10577,6 +10579,7 @@ definitions:
properties:
balance:
type: string
format: int64
description: balance is the balance of the EVM denomination.
code_hash:
type: string
Expand All @@ -10593,6 +10596,7 @@ definitions:
properties:
balance:
type: string
format: int64
description: balance is the balance of the EVM denomination.
description: >-
QueryBalanceResponse is the response type for the Query/Balance RPC
Expand Down
20 changes: 0 additions & 20 deletions client/keys/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,6 @@ func printKeyInfo(w io.Writer, keyInfo cryptokeyring.Info, bechKeyOut bechKeyOut
}
}

func printInfos(w io.Writer, infos []cryptokeyring.Info, output string) {
kos, err := cryptokeyring.MkAccKeysOutput(infos)
if err != nil {
panic(err)
}

switch output {
case OutputFormatText:
printTextInfos(w, kos)

case OutputFormatJSON:
out, err := keys.KeysCdc.MarshalJSON(kos)
if err != nil {
panic(err)
}

fmt.Fprintf(w, "%s", out)
}
}

func printTextInfos(w io.Writer, kos []cryptokeyring.KeyOutput) {
out, err := yaml.Marshal(&kos)
if err != nil {
Expand Down
48 changes: 5 additions & 43 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@

- [ethermint/evm/v1alpha1/evm.proto](#ethermint/evm/v1alpha1/evm.proto)
- [AccessTuple](#ethermint.evm.v1alpha1.AccessTuple)
- [BytesList](#ethermint.evm.v1alpha1.BytesList)
- [ChainConfig](#ethermint.evm.v1alpha1.ChainConfig)
- [Log](#ethermint.evm.v1alpha1.Log)
- [Params](#ethermint.evm.v1alpha1.Params)
- [State](#ethermint.evm.v1alpha1.State)
- [TransactionLogs](#ethermint.evm.v1alpha1.TransactionLogs)
- [TxData](#ethermint.evm.v1alpha1.TxData)
- [TxReceipt](#ethermint.evm.v1alpha1.TxReceipt)
- [TxResult](#ethermint.evm.v1alpha1.TxResult)

- [ethermint/evm/v1alpha1/genesis.proto](#ethermint/evm/v1alpha1/genesis.proto)
Expand Down Expand Up @@ -137,21 +135,6 @@ AccessTuple is the element type of an access list.



<a name="ethermint.evm.v1alpha1.BytesList"></a>

### BytesList



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `bytes` | [bytes](#bytes) | repeated | |






<a name="ethermint.evm.v1alpha1.ChainConfig"></a>

### ChainConfig
Expand Down Expand Up @@ -278,12 +261,12 @@ solely as intended in Ethereum abiding by the protocol.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `chain_id` | [bytes](#bytes) | | destination EVM chain ID |
| `chain_id` | [string](#string) | | destination EVM chain ID |
| `nonce` | [uint64](#uint64) | | nonce corresponds to the account nonce (transaction sequence). |
| `gas_price` | [bytes](#bytes) | | price defines the unsigned integer value of the gas price in bytes. |
| `gas_price` | [string](#string) | | gas price defines the value for each gas unit |
| `gas` | [uint64](#uint64) | | gas defines the gas limit defined for the transaction. |
| `to` | [string](#string) | | hex formatted address of the recipient |
| `value` | [bytes](#bytes) | | value defines the unsigned integer value of the transaction amount. |
| `value` | [string](#string) | | value defines the unsigned integer value of the transaction amount. |
| `input` | [bytes](#bytes) | | input defines the data payload bytes of the transaction. |
| `accesses` | [AccessTuple](#ethermint.evm.v1alpha1.AccessTuple) | repeated | |
| `v` | [bytes](#bytes) | | v defines the signature value |
Expand All @@ -295,27 +278,6 @@ solely as intended in Ethereum abiding by the protocol.



<a name="ethermint.evm.v1alpha1.TxReceipt"></a>

### TxReceipt
TxReceipt defines the receipt type stored in KV for each EVM transaction.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `hash` | [string](#string) | | |
| `from` | [string](#string) | | |
| `data` | [TxData](#ethermint.evm.v1alpha1.TxData) | | |
| `result` | [TxResult](#ethermint.evm.v1alpha1.TxResult) | | |
| `index` | [uint64](#uint64) | | |
| `block_height` | [uint64](#uint64) | | |
| `block_hash` | [string](#string) | | |






<a name="ethermint.evm.v1alpha1.TxResult"></a>

### TxResult
Expand Down Expand Up @@ -428,7 +390,7 @@ QueryAccountResponse is the response type for the Query/Account RPC method.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `balance` | [string](#string) | | balance is the balance of the EVM denomination. |
| `balance` | [int64](#int64) | | balance is the balance of the EVM denomination. |
| `code_hash` | [string](#string) | | code hash is the hex-formatted code bytes from the EOA. |
| `nonce` | [uint64](#uint64) | | nonce is the account's sequence number. |

Expand Down Expand Up @@ -460,7 +422,7 @@ QueryBalanceResponse is the response type for the Query/Balance RPC method.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `balance` | [string](#string) | | balance is the balance of the EVM denomination. |
| `balance` | [int64](#int64) | | balance is the balance of the EVM denomination. |



Expand Down
14 changes: 2 additions & 12 deletions ethereum/rpc/namespaces/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,7 @@ func (e *PublicAPI) GetBalance(address common.Address, blockNum rpctypes.BlockNu
return nil, err
}

val, err := ethermint.UnmarshalBigInt(res.Balance)
if err != nil {
return nil, err
}

return (*hexutil.Big)(val), nil
return (*hexutil.Big)(big.NewInt(res.Balance)), nil
}

// GetStorageAt returns the contract storage at the given address, block number, and key.
Expand Down Expand Up @@ -997,15 +992,10 @@ func (e *PublicAPI) GetProof(address common.Address, storageKeys []string, block
accProofStr = proof.String()
}

balance, err := ethermint.UnmarshalBigInt(res.Balance)
if err != nil {
return nil, err
}

return &rpctypes.AccountResult{
Address: address,
AccountProof: []string{accProofStr},
Balance: (*hexutil.Big)(balance),
Balance: (*hexutil.Big)(big.NewInt(res.Balance)),
CodeHash: common.HexToHash(res.CodeHash),
Nonce: hexutil.Uint64(res.Nonce),
StorageHash: common.Hash{}, // NOTE: Ethermint doesn't have a storage hash. TODO: implement?
Expand Down
9 changes: 6 additions & 3 deletions ethereum/rpc/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types"

sdk "github.com/cosmos/cosmos-sdk/types"

evmtypes "github.com/tharsis/ethermint/x/evm/types"
)

Expand Down Expand Up @@ -100,7 +103,7 @@ func (args *SendTxArgs) ToTransaction() *evmtypes.MsgEthereumTx {
}

if args.ChainID != nil {
data.ChainID = args.ChainID.ToInt().Bytes()
data.ChainID = sdk.NewIntFromBigInt(args.ChainID.ToInt())
}

if args.Nonce != nil {
Expand All @@ -112,11 +115,11 @@ func (args *SendTxArgs) ToTransaction() *evmtypes.MsgEthereumTx {
}

if args.GasPrice != nil {
data.GasPrice = args.GasPrice.ToInt().Bytes()
data.GasPrice = sdk.NewIntFromBigInt(args.GasPrice.ToInt())
}

if args.Value != nil {
data.Amount = args.Value.ToInt().Bytes()
data.Amount = sdk.NewIntFromBigInt(args.Value.ToInt())
}

if args.To != nil {
Expand Down
10 changes: 8 additions & 2 deletions ethereum/rpc/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,15 @@ func NewTransactionFromData(
}

rpcTx := &RPCTransaction{
Type: hexutil.Uint64(txData.Type()),
From: from,
Gas: hexutil.Uint64(txData.GasLimit),
GasPrice: (*hexutil.Big)(new(big.Int).SetBytes(txData.GasPrice)),
GasPrice: (*hexutil.Big)(txData.GasPrice.BigInt()),
Hash: txHash,
Input: hexutil.Bytes(txData.Input),
Nonce: hexutil.Uint64(txData.Nonce),
To: to,
Value: (*hexutil.Big)(new(big.Int).SetBytes(txData.Amount)),
Value: (*hexutil.Big)(txData.Amount.BigInt()),
V: (*hexutil.Big)(new(big.Int).SetBytes(txData.V)),
R: (*hexutil.Big)(new(big.Int).SetBytes(txData.R)),
S: (*hexutil.Big)(new(big.Int).SetBytes(txData.S)),
Expand All @@ -293,5 +294,10 @@ func NewTransactionFromData(
rpcTx.TransactionIndex = (*hexutil.Uint64)(&index)
}

if txData.Type() == ethtypes.AccessListTxType {
rpcTx.Accesses = txData.Accesses.ToEthAccessList()
rpcTx.ChainID = (*hexutil.Big)(txData.ChainID.BigInt())
}

return rpcTx, nil
}
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ require (
github.com/xlab/closer v0.0.0-20190328110542-03326addb7c2
github.com/xlab/suplog v1.3.0
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect
google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84
google.golang.org/genproto v0.0.0-20210629200056-84d6f6074151
google.golang.org/grpc v1.38.0
google.golang.org/protobuf v1.27.0 // indirect
gopkg.in/yaml.v2 v2.4.0
nhooyr.io/websocket v1.8.7 // indirect
)
Expand Down
10 changes: 5 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down Expand Up @@ -1473,8 +1473,8 @@ google.golang.org/genproto v0.0.0-20210310155132-4ce2db91004e/go.mod h1:FWY/as6D
google.golang.org/genproto v0.0.0-20210319143718-93e7006c17a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A=
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0=
google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84 h1:R1r5J0u6Cx+RNl/6mezTw6oA14cmKC96FeUwL6A9bd4=
google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24=
google.golang.org/genproto v0.0.0-20210629200056-84d6f6074151 h1:H/uPzsolsGjhl3CVT6Wb7bK+mf+hmkEvUVu+FBKyNlc=
google.golang.org/genproto v0.0.0-20210629200056-84d6f6074151/go.mod h1:yiaVoXHpRzHGyxV3o4DktVWY4mSUErTKaeEOq6C3t3U=
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
Expand Down Expand Up @@ -1518,8 +1518,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
google.golang.org/protobuf v1.25.1-0.20200805231151-a709e31e5d12/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.0 h1:KhgSLlr/moiqjv0qUsSnLvdUL7NH7PHW8aZGn7Jpjko=
google.golang.org/protobuf v1.27.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/bsm/ratelimit.v1 v1.0.0-20160220154919-db14e161995a/go.mod h1:KF9sEfUPAXdG8Oev9e99iLGnl2uJMjc5B+4y3O7x610=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
39 changes: 16 additions & 23 deletions proto/ethermint/evm/v1alpha1/evm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,6 @@ message Log {
bool removed = 9;
}

// TxReceipt defines the receipt type stored in KV for each EVM transaction.
message TxReceipt {
option (gogoproto.goproto_getters) = false;

string hash = 1;
string from = 2;
TxData data = 3;
TxResult result = 4;
uint64 index = 5;
uint64 block_height = 6;
string block_hash = 7;
}

// TxResult stores results of Tx execution.
message TxResult {
option (gogoproto.goproto_getters) = false;
Expand Down Expand Up @@ -216,17 +203,29 @@ message TxData {
option (gogoproto.goproto_getters) = false;

// destination EVM chain ID
bytes chain_id = 1 [(gogoproto.customname) = "ChainID", (gogoproto.jsontag) = "chainID"];
string chain_id = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.customname) = "ChainID",
(gogoproto.jsontag) = "chainID",
(gogoproto.nullable) = false
];
// nonce corresponds to the account nonce (transaction sequence).
uint64 nonce = 2;
// price defines the unsigned integer value of the gas price in bytes.
bytes gas_price = 3 [(gogoproto.customname) = "GasPrice"];
// gas price defines the value for each gas unit
string gas_price = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// gas defines the gas limit defined for the transaction.
uint64 gas = 4 [(gogoproto.customname) = "GasLimit"];
// hex formatted address of the recipient
string to = 5;
// value defines the unsigned integer value of the transaction amount.
bytes value = 6 [(gogoproto.customname) = "Amount"];
string value = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.customname) = "Amount",
(gogoproto.nullable) = false
];
// input defines the data payload bytes of the transaction.
bytes input = 7;
repeated AccessTuple accesses = 8
Expand All @@ -239,12 +238,6 @@ message TxData {
bytes s = 11;
}

message BytesList {
option (gogoproto.goproto_getters) = false;

repeated bytes bytes = 1;
}

// AccessTuple is the element type of an access list.
message AccessTuple {
option (gogoproto.goproto_getters) = false;
Expand Down
4 changes: 2 additions & 2 deletions proto/ethermint/evm/v1alpha1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ message QueryAccountRequest {
// QueryAccountResponse is the response type for the Query/Account RPC method.
message QueryAccountResponse {
// balance is the balance of the EVM denomination.
string balance = 1;
int64 balance = 1;
// code hash is the hex-formatted code bytes from the EOA.
string code_hash = 2;
// nonce is the account's sequence number.
Expand Down Expand Up @@ -136,7 +136,7 @@ message QueryBalanceRequest {
// QueryBalanceResponse is the response type for the Query/Balance RPC method.
message QueryBalanceResponse {
// balance is the balance of the EVM denomination.
string balance = 1;
int64 balance = 1;
}

// QueryStorageRequest is the request type for the Query/Storage RPC method.
Expand Down
Loading

0 comments on commit 86e30e8

Please sign in to comment.