Query and bug fixes (#110)

* Fix queries and bugs

* Fix issues from rebasing

* Fix rpc query address
This commit is contained in:
Austin Abell
2019-09-26 11:36:23 -04:00
committed by GitHub
parent 192ce2cc1c
commit 7f1eb4b0cf
9 changed files with 143 additions and 78 deletions
+12 -27
View File
@@ -1,9 +1,8 @@
package types
import (
"math/big"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/ethermint/utils"
ethcmn "github.com/ethereum/go-ethereum/common"
)
@@ -19,7 +18,7 @@ func RegisterAmino(cdc *codec.Codec) {
cdc.RegisterConcrete(EncodableTxData{}, "ethermint/EncodedMessage", nil)
}
// TxData implements the Ethereum transaction data structure. It is used
// EncodableTxData implements the Ethereum transaction data structure. It is used
// solely as intended in Ethereum abiding by the protocol.
type EncodableTxData struct {
AccountNonce uint64 `json:"nonce"`
@@ -47,33 +46,19 @@ func unmarshalAmino(td *EncodableTxData, text string) (err error) {
return cdc.UnmarshalBinaryBare([]byte(text), td)
}
func marshalBigInt(i *big.Int) string {
bz, err := i.MarshalText()
if err != nil {
panic(err)
}
return string(bz)
}
func unmarshalBigInt(s string) (*big.Int, error) {
ret := new(big.Int)
err := ret.UnmarshalText([]byte(s))
return ret, err
}
// MarshalAmino defines custom encoding scheme for TxData
func (td TxData) MarshalAmino() (string, error) {
e := EncodableTxData{
AccountNonce: td.AccountNonce,
Price: marshalBigInt(td.Price),
Price: utils.MarshalBigInt(td.Price),
GasLimit: td.GasLimit,
Recipient: td.Recipient,
Amount: marshalBigInt(td.Amount),
Amount: utils.MarshalBigInt(td.Amount),
Payload: td.Payload,
V: marshalBigInt(td.V),
R: marshalBigInt(td.R),
S: marshalBigInt(td.S),
V: utils.MarshalBigInt(td.V),
R: utils.MarshalBigInt(td.R),
S: utils.MarshalBigInt(td.S),
Hash: td.Hash,
}
@@ -95,7 +80,7 @@ func (td *TxData) UnmarshalAmino(text string) (err error) {
td.Payload = e.Payload
td.Hash = e.Hash
price, err := unmarshalBigInt(e.Price)
price, err := utils.UnmarshalBigInt(e.Price)
if err != nil {
return
}
@@ -105,7 +90,7 @@ func (td *TxData) UnmarshalAmino(text string) (err error) {
td.Price = price
}
amt, err := unmarshalBigInt(e.Amount)
amt, err := utils.UnmarshalBigInt(e.Amount)
if err != nil {
return
}
@@ -115,7 +100,7 @@ func (td *TxData) UnmarshalAmino(text string) (err error) {
td.Amount = amt
}
v, err := unmarshalBigInt(e.V)
v, err := utils.UnmarshalBigInt(e.V)
if err != nil {
return
}
@@ -125,7 +110,7 @@ func (td *TxData) UnmarshalAmino(text string) (err error) {
td.V = v
}
r, err := unmarshalBigInt(e.R)
r, err := utils.UnmarshalBigInt(e.R)
if err != nil {
return
}
@@ -135,7 +120,7 @@ func (td *TxData) UnmarshalAmino(text string) (err error) {
td.R = r
}
s, err := unmarshalBigInt(e.S)
s, err := utils.UnmarshalBigInt(e.S)
if err != nil {
return
}
+8 -7
View File
@@ -7,6 +7,7 @@ import (
"testing"
"github.com/cosmos/ethermint/crypto"
"github.com/cosmos/ethermint/utils"
ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rlp"
"github.com/stretchr/testify/require"
@@ -140,8 +141,8 @@ func TestMsgEthereumTxAmino(t *testing.T) {
func TestMarshalAndUnmarshalInt(t *testing.T) {
i := big.NewInt(3)
m := marshalBigInt(i)
i2, err := unmarshalBigInt(m)
m := utils.MarshalBigInt(i)
i2, err := utils.UnmarshalBigInt(m)
require.NoError(t, err)
require.Equal(t, i, i2)
@@ -152,15 +153,15 @@ func TestMarshalAndUnmarshalData(t *testing.T) {
hash := ethcmn.BigToHash(big.NewInt(2))
e := EncodableTxData{
AccountNonce: 2,
Price: marshalBigInt(big.NewInt(3)),
Price: utils.MarshalBigInt(big.NewInt(3)),
GasLimit: 1,
Recipient: &addr,
Amount: marshalBigInt(big.NewInt(4)),
Amount: utils.MarshalBigInt(big.NewInt(4)),
Payload: []byte("test"),
V: marshalBigInt(big.NewInt(5)),
R: marshalBigInt(big.NewInt(6)),
S: marshalBigInt(big.NewInt(7)),
V: utils.MarshalBigInt(big.NewInt(5)),
R: utils.MarshalBigInt(big.NewInt(6)),
S: utils.MarshalBigInt(big.NewInt(7)),
Hash: &hash,
}
+55
View File
@@ -0,0 +1,55 @@
package types
// QueryResProtocolVersion is response type for protocol version query
type QueryResProtocolVersion struct {
Version string `json:"version"`
}
func (q QueryResProtocolVersion) String() string {
return q.Version
}
// QueryResBalance is response type for balance query
type QueryResBalance struct {
Balance string `json:"balance"`
}
func (q QueryResBalance) String() string {
return q.Balance
}
// QueryResBlockNumber is response type for block number query
type QueryResBlockNumber struct {
Number int64 `json:"blockNumber"`
}
func (q QueryResBlockNumber) String() string {
return string(q.Number)
}
// QueryResStorage is response type for storage query
type QueryResStorage struct {
Value []byte `json:"value"`
}
func (q QueryResStorage) String() string {
return string(q.Value)
}
// QueryResCode is response type for code query
type QueryResCode struct {
Code []byte
}
func (q QueryResCode) String() string {
return string(q.Code)
}
// QueryResNonce is response type for Nonce query
type QueryResNonce struct {
Nonce uint64 `json:"nonce"`
}
func (q QueryResNonce) String() string {
return string(q.Nonce)
}