api: ethrpc: add missing fields (#9631)

* api: ethrpc: add missing fields

* fix make gen
This commit is contained in:
ychiao 2022-11-12 12:44:52 -05:00 committed by GitHub
parent 7664e0691c
commit 8a7367f1c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 49 additions and 37 deletions

View File

@ -369,7 +369,7 @@ func init() {
addExample(&ethint)
ethaddr, _ := api.EthAddressFromHex("0x5CbEeCF99d3fDB3f25E309Cc264f240bb0664031")
addExample(&ethaddr)
ethhash, _ := api.EthHashFromCid(c)
ethhash, _ := api.NewEthHashFromCid(c)
addExample(&ethhash)
ethFeeHistoryReward := [][]api.EthBigInt{}

View File

@ -37,7 +37,6 @@ type EthTx struct {
Type EthUint64 `json:"type"`
Input EthBytes `json:"input"`
Gas EthUint64 `json:"gas"`
GasLimit *EthUint64 `json:"gasLimit,omitempty"`
MaxFeePerGas EthBigInt `json:"maxFeePerGas"`
MaxPriorityFeePerGas EthBigInt `json:"maxPriorityFeePerGas"`
V EthBytes `json:"v"`

View File

@ -111,6 +111,7 @@ func (e *EthBytes) UnmarshalJSON(b []byte) error {
}
type EthBlock struct {
Hash EthHash `json:"hash"`
ParentHash EthHash `json:"parentHash"`
Sha3Uncles EthHash `json:"sha3Uncles"`
Miner EthAddress `json:"miner"`
@ -118,16 +119,17 @@ type EthBlock struct {
TransactionsRoot EthHash `json:"transactionsRoot"`
ReceiptsRoot EthHash `json:"receiptsRoot"`
// TODO: include LogsBloom
Difficulty EthUint64 `json:"difficulty"`
Number EthUint64 `json:"number"`
GasLimit EthUint64 `json:"gasLimit"`
GasUsed EthUint64 `json:"gasUsed"`
Timestamp EthUint64 `json:"timestamp"`
Extradata []byte `json:"extraData"`
MixHash EthHash `json:"mixHash"`
Nonce EthNonce `json:"nonce"`
BaseFeePerGas EthBigInt `json:"baseFeePerGas"`
Size EthUint64 `json:"size"`
Difficulty EthUint64 `json:"difficulty"`
TotalDifficulty EthUint64 `json:"totalDifficulty"`
Number EthUint64 `json:"number"`
GasLimit EthUint64 `json:"gasLimit"`
GasUsed EthUint64 `json:"gasUsed"`
Timestamp EthUint64 `json:"timestamp"`
Extradata []byte `json:"extraData"`
MixHash EthHash `json:"mixHash"`
Nonce EthNonce `json:"nonce"`
BaseFeePerGas EthBigInt `json:"baseFeePerGas"`
Size EthUint64 `json:"size"`
// can be []EthTx or []string depending on query params
Transactions []interface{} `json:"transactions"`
Uncles []EthHash `json:"uncles"`
@ -408,7 +410,7 @@ func decodeHexString(s string, length int) ([]byte, error) {
return b, nil
}
func EthHashFromCid(c cid.Cid) (EthHash, error) {
func NewEthHashFromCid(c cid.Cid) (EthHash, error) {
return EthHashFromHex(c.Hash().HexString()[8:])
}

View File

@ -89,7 +89,7 @@ func TestEthHash(t *testing.T) {
require.Equal(t, h.String(), strings.Replace(hash, `"`, "", -1))
c := h.ToCid()
h1, err := EthHashFromCid(c)
h1, err := NewEthHashFromCid(c)
require.Nil(t, err)
require.Equal(t, h, h1)
}

View File

@ -7,6 +7,8 @@ import (
"testing"
"github.com/stretchr/testify/require"
"github.com/filecoin-project/go-address"
)
func TestEncode(t *testing.T) {
@ -175,16 +177,14 @@ func TestDecodeError(t *testing.T) {
}
func TestDecode1(t *testing.T) {
t.Skip("doesn't really test anything, it just prints stuff...")
b := mustDecodeHex("0x02f8758401df5e7680832c8411832c8411830767f89452963ef50e27e06d72d59fcb4f3c2a687be3cfef880de0b6b3a764000080c080a094b11866f453ad85a980e0e8a2fc98cbaeb4409618c7734a7e12ae2f66fd405da042dbfb1b37af102023830ceeee0e703ffba0b8b3afeb8fe59f405eca9ed61072")
decoded, err := ParseEthTxArgs(b)
require.NoError(t, err)
orig, err := decoded.OriginalRlpMsg()
fmt.Println(hex.EncodeToString(orig))
// correct f4 addr: f410fkkld55ioe7qg24wvt7fu6pbknb56ht7pt4zamxa
sender, err := decoded.Sender()
require.NoError(t, err)
fmt.Println(decoded.Sender())
fmt.Printf("%+v\n", decoded)
addr, err := address.NewFromString("f410fkkld55ioe7qg24wvt7fu6pbknb56ht7pt4zamxa")
require.NoError(t, err)
require.Equal(t, sender, addr)
}

Binary file not shown.

View File

@ -2299,6 +2299,7 @@ Inputs:
Response:
```json
{
"hash": "0x0707070707070707070707070707070707070707070707070707070707070707",
"parentHash": "0x0707070707070707070707070707070707070707070707070707070707070707",
"sha3Uncles": "0x0707070707070707070707070707070707070707070707070707070707070707",
"miner": "0x0707070707070707070707070707070707070707",
@ -2306,6 +2307,7 @@ Response:
"transactionsRoot": "0x0707070707070707070707070707070707070707070707070707070707070707",
"receiptsRoot": "0x0707070707070707070707070707070707070707070707070707070707070707",
"difficulty": "0x5",
"totalDifficulty": "0x5",
"number": "0x5",
"gasLimit": "0x5",
"gasUsed": "0x5",
@ -2340,6 +2342,7 @@ Inputs:
Response:
```json
{
"hash": "0x0707070707070707070707070707070707070707070707070707070707070707",
"parentHash": "0x0707070707070707070707070707070707070707070707070707070707070707",
"sha3Uncles": "0x0707070707070707070707070707070707070707070707070707070707070707",
"miner": "0x0707070707070707070707070707070707070707",
@ -2347,6 +2350,7 @@ Response:
"transactionsRoot": "0x0707070707070707070707070707070707070707070707070707070707070707",
"receiptsRoot": "0x0707070707070707070707070707070707070707070707070707070707070707",
"difficulty": "0x5",
"totalDifficulty": "0x5",
"number": "0x5",
"gasLimit": "0x5",
"gasUsed": "0x5",
@ -2454,7 +2458,6 @@ Response:
"type": "0x5",
"input": "0x07",
"gas": "0x5",
"gasLimit": "0x5",
"maxFeePerGas": "0x0",
"maxPriorityFeePerGas": "0x0",
"v": "0x07",
@ -2491,7 +2494,6 @@ Response:
"type": "0x5",
"input": "0x07",
"gas": "0x5",
"gasLimit": "0x5",
"maxFeePerGas": "0x0",
"maxPriorityFeePerGas": "0x0",
"v": "0x07",
@ -2527,7 +2529,6 @@ Response:
"type": "0x5",
"input": "0x07",
"gas": "0x5",
"gasLimit": "0x5",
"maxFeePerGas": "0x0",
"maxPriorityFeePerGas": "0x0",
"v": "0x07",

View File

@ -136,7 +136,7 @@ func (a *EthModule) EthGetBlockByHash(ctx context.Context, blkHash api.EthHash,
if err != nil {
return api.EthBlock{}, xerrors.Errorf("error loading tipset %s: %w", ts, err)
}
return a.ethBlockFromFilecoinTipSet(ctx, ts, fullTxInfo)
return a.newEthBlockFromFilecoinTipSet(ctx, ts, fullTxInfo)
}
func (a *EthModule) EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxInfo bool) (api.EthBlock, error) {
@ -150,7 +150,7 @@ func (a *EthModule) EthGetBlockByNumber(ctx context.Context, blkNum string, full
if err != nil {
return api.EthBlock{}, xerrors.Errorf("error loading tipset %s: %w", ts, err)
}
return a.ethBlockFromFilecoinTipSet(ctx, ts, fullTxInfo)
return a.newEthBlockFromFilecoinTipSet(ctx, ts, fullTxInfo)
}
func (a *EthModule) EthGetTransactionByHash(ctx context.Context, txHash *api.EthHash) (*api.EthTx, error) {
@ -166,7 +166,7 @@ func (a *EthModule) EthGetTransactionByHash(ctx context.Context, txHash *api.Eth
return nil, nil
}
tx, err := a.ethTxFromFilecoinMessageLookup(ctx, msgLookup)
tx, err := a.newEthTxFromFilecoinMessageLookup(ctx, msgLookup)
if err != nil {
return nil, nil
}
@ -193,7 +193,7 @@ func (a *EthModule) EthGetTransactionReceipt(ctx context.Context, txHash api.Eth
return nil, nil
}
tx, err := a.ethTxFromFilecoinMessageLookup(ctx, msgLookup)
tx, err := a.newEthTxFromFilecoinMessageLookup(ctx, msgLookup)
if err != nil {
return nil, nil
}
@ -412,7 +412,7 @@ func (a *EthModule) EthFeeHistory(ctx context.Context, blkCount api.EthUint64, n
for ts.Height() >= abi.ChainEpoch(oldestBlkHeight) {
// Unfortunately we need to rebuild the full message view so we can
// totalize gas used in the tipset.
block, err := a.ethBlockFromFilecoinTipSet(ctx, ts, false)
block, err := a.newEthBlockFromFilecoinTipSet(ctx, ts, false)
if err != nil {
return api.EthFeeHistory{}, fmt.Errorf("cannot create eth block: %v", err)
}
@ -501,7 +501,7 @@ func (a *EthModule) EthSendRawTransaction(ctx context.Context, rawTx api.EthByte
if err != nil {
return api.EmptyEthHash, err
}
return api.EthHashFromCid(cid)
return api.NewEthHashFromCid(cid)
}
func (a *EthModule) ethCallToFilecoinMessage(ctx context.Context, tx api.EthCall) (*types.Message, error) {
@ -633,7 +633,7 @@ func (a *EthModule) EthCall(ctx context.Context, tx api.EthCall, blkParam string
return api.EthBytes{}, nil
}
func (a *EthModule) ethBlockFromFilecoinTipSet(ctx context.Context, ts *types.TipSet, fullTxInfo bool) (api.EthBlock, error) {
func (a *EthModule) newEthBlockFromFilecoinTipSet(ctx context.Context, ts *types.TipSet, fullTxInfo bool) (api.EthBlock, error) {
parent, err := a.Chain.LoadTipSet(ctx, ts.Parents())
if err != nil {
return api.EthBlock{}, err
@ -642,7 +642,16 @@ func (a *EthModule) ethBlockFromFilecoinTipSet(ctx context.Context, ts *types.Ti
if err != nil {
return api.EthBlock{}, err
}
parentBlkHash, err := api.EthHashFromCid(parentKeyCid)
parentBlkHash, err := api.NewEthHashFromCid(parentKeyCid)
if err != nil {
return api.EthBlock{}, err
}
blkCid, err := ts.Key().Cid()
if err != nil {
return api.EthBlock{}, err
}
blkHash, err := api.NewEthHashFromCid(blkCid)
if err != nil {
return api.EthBlock{}, err
}
@ -665,13 +674,13 @@ func (a *EthModule) ethBlockFromFilecoinTipSet(ctx context.Context, ts *types.Ti
gasUsed += msgLookup.Receipt.GasUsed
if fullTxInfo {
tx, err := a.ethTxFromFilecoinMessageLookup(ctx, msgLookup)
tx, err := a.newEthTxFromFilecoinMessageLookup(ctx, msgLookup)
if err != nil {
return api.EthBlock{}, nil
}
block.Transactions = append(block.Transactions, tx)
} else {
hash, err := api.EthHashFromCid(msg.Cid())
hash, err := api.NewEthHashFromCid(msg.Cid())
if err != nil {
return api.EthBlock{}, err
}
@ -680,6 +689,7 @@ func (a *EthModule) ethBlockFromFilecoinTipSet(ctx context.Context, ts *types.Ti
}
}
block.Hash = blkHash
block.Number = api.EthUint64(ts.Height())
block.ParentHash = parentBlkHash
block.Timestamp = api.EthUint64(ts.Blocks()[0].Timestamp)
@ -732,12 +742,12 @@ func (a *EthModule) lookupEthAddress(ctx context.Context, addr address.Address)
return api.EthAddressFromFilecoinAddress(idAddr)
}
func (a *EthModule) ethTxFromFilecoinMessageLookup(ctx context.Context, msgLookup *api.MsgLookup) (api.EthTx, error) {
func (a *EthModule) newEthTxFromFilecoinMessageLookup(ctx context.Context, msgLookup *api.MsgLookup) (api.EthTx, error) {
if msgLookup == nil {
return api.EthTx{}, fmt.Errorf("msg does not exist")
}
cid := msgLookup.Message
txHash, err := api.EthHashFromCid(cid)
txHash, err := api.NewEthHashFromCid(cid)
if err != nil {
return api.EthTx{}, err
}
@ -758,7 +768,7 @@ func (a *EthModule) ethTxFromFilecoinMessageLookup(ctx context.Context, msgLooku
return api.EthTx{}, err
}
blkHash, err := api.EthHashFromCid(parentTsCid)
blkHash, err := api.NewEthHashFromCid(parentTsCid)
if err != nil {
return api.EthTx{}, err
}