api: ethrpc: add missing fields (#9631)
* api: ethrpc: add missing fields * fix make gen
This commit is contained in:
parent
7664e0691c
commit
8a7367f1c9
@ -369,7 +369,7 @@ func init() {
|
|||||||
addExample(ðint)
|
addExample(ðint)
|
||||||
ethaddr, _ := api.EthAddressFromHex("0x5CbEeCF99d3fDB3f25E309Cc264f240bb0664031")
|
ethaddr, _ := api.EthAddressFromHex("0x5CbEeCF99d3fDB3f25E309Cc264f240bb0664031")
|
||||||
addExample(ðaddr)
|
addExample(ðaddr)
|
||||||
ethhash, _ := api.EthHashFromCid(c)
|
ethhash, _ := api.NewEthHashFromCid(c)
|
||||||
addExample(ðhash)
|
addExample(ðhash)
|
||||||
|
|
||||||
ethFeeHistoryReward := [][]api.EthBigInt{}
|
ethFeeHistoryReward := [][]api.EthBigInt{}
|
||||||
|
@ -37,7 +37,6 @@ type EthTx struct {
|
|||||||
Type EthUint64 `json:"type"`
|
Type EthUint64 `json:"type"`
|
||||||
Input EthBytes `json:"input"`
|
Input EthBytes `json:"input"`
|
||||||
Gas EthUint64 `json:"gas"`
|
Gas EthUint64 `json:"gas"`
|
||||||
GasLimit *EthUint64 `json:"gasLimit,omitempty"`
|
|
||||||
MaxFeePerGas EthBigInt `json:"maxFeePerGas"`
|
MaxFeePerGas EthBigInt `json:"maxFeePerGas"`
|
||||||
MaxPriorityFeePerGas EthBigInt `json:"maxPriorityFeePerGas"`
|
MaxPriorityFeePerGas EthBigInt `json:"maxPriorityFeePerGas"`
|
||||||
V EthBytes `json:"v"`
|
V EthBytes `json:"v"`
|
||||||
|
@ -111,6 +111,7 @@ func (e *EthBytes) UnmarshalJSON(b []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type EthBlock struct {
|
type EthBlock struct {
|
||||||
|
Hash EthHash `json:"hash"`
|
||||||
ParentHash EthHash `json:"parentHash"`
|
ParentHash EthHash `json:"parentHash"`
|
||||||
Sha3Uncles EthHash `json:"sha3Uncles"`
|
Sha3Uncles EthHash `json:"sha3Uncles"`
|
||||||
Miner EthAddress `json:"miner"`
|
Miner EthAddress `json:"miner"`
|
||||||
@ -118,16 +119,17 @@ type EthBlock struct {
|
|||||||
TransactionsRoot EthHash `json:"transactionsRoot"`
|
TransactionsRoot EthHash `json:"transactionsRoot"`
|
||||||
ReceiptsRoot EthHash `json:"receiptsRoot"`
|
ReceiptsRoot EthHash `json:"receiptsRoot"`
|
||||||
// TODO: include LogsBloom
|
// TODO: include LogsBloom
|
||||||
Difficulty EthUint64 `json:"difficulty"`
|
Difficulty EthUint64 `json:"difficulty"`
|
||||||
Number EthUint64 `json:"number"`
|
TotalDifficulty EthUint64 `json:"totalDifficulty"`
|
||||||
GasLimit EthUint64 `json:"gasLimit"`
|
Number EthUint64 `json:"number"`
|
||||||
GasUsed EthUint64 `json:"gasUsed"`
|
GasLimit EthUint64 `json:"gasLimit"`
|
||||||
Timestamp EthUint64 `json:"timestamp"`
|
GasUsed EthUint64 `json:"gasUsed"`
|
||||||
Extradata []byte `json:"extraData"`
|
Timestamp EthUint64 `json:"timestamp"`
|
||||||
MixHash EthHash `json:"mixHash"`
|
Extradata []byte `json:"extraData"`
|
||||||
Nonce EthNonce `json:"nonce"`
|
MixHash EthHash `json:"mixHash"`
|
||||||
BaseFeePerGas EthBigInt `json:"baseFeePerGas"`
|
Nonce EthNonce `json:"nonce"`
|
||||||
Size EthUint64 `json:"size"`
|
BaseFeePerGas EthBigInt `json:"baseFeePerGas"`
|
||||||
|
Size EthUint64 `json:"size"`
|
||||||
// can be []EthTx or []string depending on query params
|
// can be []EthTx or []string depending on query params
|
||||||
Transactions []interface{} `json:"transactions"`
|
Transactions []interface{} `json:"transactions"`
|
||||||
Uncles []EthHash `json:"uncles"`
|
Uncles []EthHash `json:"uncles"`
|
||||||
@ -408,7 +410,7 @@ func decodeHexString(s string, length int) ([]byte, error) {
|
|||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func EthHashFromCid(c cid.Cid) (EthHash, error) {
|
func NewEthHashFromCid(c cid.Cid) (EthHash, error) {
|
||||||
return EthHashFromHex(c.Hash().HexString()[8:])
|
return EthHashFromHex(c.Hash().HexString()[8:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ func TestEthHash(t *testing.T) {
|
|||||||
require.Equal(t, h.String(), strings.Replace(hash, `"`, "", -1))
|
require.Equal(t, h.String(), strings.Replace(hash, `"`, "", -1))
|
||||||
|
|
||||||
c := h.ToCid()
|
c := h.ToCid()
|
||||||
h1, err := EthHashFromCid(c)
|
h1, err := NewEthHashFromCid(c)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, h, h1)
|
require.Equal(t, h, h1)
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-address"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEncode(t *testing.T) {
|
func TestEncode(t *testing.T) {
|
||||||
@ -175,16 +177,14 @@ func TestDecodeError(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDecode1(t *testing.T) {
|
func TestDecode1(t *testing.T) {
|
||||||
t.Skip("doesn't really test anything, it just prints stuff...")
|
|
||||||
b := mustDecodeHex("0x02f8758401df5e7680832c8411832c8411830767f89452963ef50e27e06d72d59fcb4f3c2a687be3cfef880de0b6b3a764000080c080a094b11866f453ad85a980e0e8a2fc98cbaeb4409618c7734a7e12ae2f66fd405da042dbfb1b37af102023830ceeee0e703ffba0b8b3afeb8fe59f405eca9ed61072")
|
b := mustDecodeHex("0x02f8758401df5e7680832c8411832c8411830767f89452963ef50e27e06d72d59fcb4f3c2a687be3cfef880de0b6b3a764000080c080a094b11866f453ad85a980e0e8a2fc98cbaeb4409618c7734a7e12ae2f66fd405da042dbfb1b37af102023830ceeee0e703ffba0b8b3afeb8fe59f405eca9ed61072")
|
||||||
decoded, err := ParseEthTxArgs(b)
|
decoded, err := ParseEthTxArgs(b)
|
||||||
require.NoError(t, err)
|
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())
|
addr, err := address.NewFromString("f410fkkld55ioe7qg24wvt7fu6pbknb56ht7pt4zamxa")
|
||||||
|
require.NoError(t, err)
|
||||||
fmt.Printf("%+v\n", decoded)
|
require.Equal(t, sender, addr)
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -2299,6 +2299,7 @@ Inputs:
|
|||||||
Response:
|
Response:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
"hash": "0x0707070707070707070707070707070707070707070707070707070707070707",
|
||||||
"parentHash": "0x0707070707070707070707070707070707070707070707070707070707070707",
|
"parentHash": "0x0707070707070707070707070707070707070707070707070707070707070707",
|
||||||
"sha3Uncles": "0x0707070707070707070707070707070707070707070707070707070707070707",
|
"sha3Uncles": "0x0707070707070707070707070707070707070707070707070707070707070707",
|
||||||
"miner": "0x0707070707070707070707070707070707070707",
|
"miner": "0x0707070707070707070707070707070707070707",
|
||||||
@ -2306,6 +2307,7 @@ Response:
|
|||||||
"transactionsRoot": "0x0707070707070707070707070707070707070707070707070707070707070707",
|
"transactionsRoot": "0x0707070707070707070707070707070707070707070707070707070707070707",
|
||||||
"receiptsRoot": "0x0707070707070707070707070707070707070707070707070707070707070707",
|
"receiptsRoot": "0x0707070707070707070707070707070707070707070707070707070707070707",
|
||||||
"difficulty": "0x5",
|
"difficulty": "0x5",
|
||||||
|
"totalDifficulty": "0x5",
|
||||||
"number": "0x5",
|
"number": "0x5",
|
||||||
"gasLimit": "0x5",
|
"gasLimit": "0x5",
|
||||||
"gasUsed": "0x5",
|
"gasUsed": "0x5",
|
||||||
@ -2340,6 +2342,7 @@ Inputs:
|
|||||||
Response:
|
Response:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
"hash": "0x0707070707070707070707070707070707070707070707070707070707070707",
|
||||||
"parentHash": "0x0707070707070707070707070707070707070707070707070707070707070707",
|
"parentHash": "0x0707070707070707070707070707070707070707070707070707070707070707",
|
||||||
"sha3Uncles": "0x0707070707070707070707070707070707070707070707070707070707070707",
|
"sha3Uncles": "0x0707070707070707070707070707070707070707070707070707070707070707",
|
||||||
"miner": "0x0707070707070707070707070707070707070707",
|
"miner": "0x0707070707070707070707070707070707070707",
|
||||||
@ -2347,6 +2350,7 @@ Response:
|
|||||||
"transactionsRoot": "0x0707070707070707070707070707070707070707070707070707070707070707",
|
"transactionsRoot": "0x0707070707070707070707070707070707070707070707070707070707070707",
|
||||||
"receiptsRoot": "0x0707070707070707070707070707070707070707070707070707070707070707",
|
"receiptsRoot": "0x0707070707070707070707070707070707070707070707070707070707070707",
|
||||||
"difficulty": "0x5",
|
"difficulty": "0x5",
|
||||||
|
"totalDifficulty": "0x5",
|
||||||
"number": "0x5",
|
"number": "0x5",
|
||||||
"gasLimit": "0x5",
|
"gasLimit": "0x5",
|
||||||
"gasUsed": "0x5",
|
"gasUsed": "0x5",
|
||||||
@ -2454,7 +2458,6 @@ Response:
|
|||||||
"type": "0x5",
|
"type": "0x5",
|
||||||
"input": "0x07",
|
"input": "0x07",
|
||||||
"gas": "0x5",
|
"gas": "0x5",
|
||||||
"gasLimit": "0x5",
|
|
||||||
"maxFeePerGas": "0x0",
|
"maxFeePerGas": "0x0",
|
||||||
"maxPriorityFeePerGas": "0x0",
|
"maxPriorityFeePerGas": "0x0",
|
||||||
"v": "0x07",
|
"v": "0x07",
|
||||||
@ -2491,7 +2494,6 @@ Response:
|
|||||||
"type": "0x5",
|
"type": "0x5",
|
||||||
"input": "0x07",
|
"input": "0x07",
|
||||||
"gas": "0x5",
|
"gas": "0x5",
|
||||||
"gasLimit": "0x5",
|
|
||||||
"maxFeePerGas": "0x0",
|
"maxFeePerGas": "0x0",
|
||||||
"maxPriorityFeePerGas": "0x0",
|
"maxPriorityFeePerGas": "0x0",
|
||||||
"v": "0x07",
|
"v": "0x07",
|
||||||
@ -2527,7 +2529,6 @@ Response:
|
|||||||
"type": "0x5",
|
"type": "0x5",
|
||||||
"input": "0x07",
|
"input": "0x07",
|
||||||
"gas": "0x5",
|
"gas": "0x5",
|
||||||
"gasLimit": "0x5",
|
|
||||||
"maxFeePerGas": "0x0",
|
"maxFeePerGas": "0x0",
|
||||||
"maxPriorityFeePerGas": "0x0",
|
"maxPriorityFeePerGas": "0x0",
|
||||||
"v": "0x07",
|
"v": "0x07",
|
||||||
|
@ -136,7 +136,7 @@ func (a *EthModule) EthGetBlockByHash(ctx context.Context, blkHash api.EthHash,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return api.EthBlock{}, xerrors.Errorf("error loading tipset %s: %w", ts, err)
|
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) {
|
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 {
|
if err != nil {
|
||||||
return api.EthBlock{}, xerrors.Errorf("error loading tipset %s: %w", ts, err)
|
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) {
|
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
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
tx, err := a.ethTxFromFilecoinMessageLookup(ctx, msgLookup)
|
tx, err := a.newEthTxFromFilecoinMessageLookup(ctx, msgLookup)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@ -193,7 +193,7 @@ func (a *EthModule) EthGetTransactionReceipt(ctx context.Context, txHash api.Eth
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
tx, err := a.ethTxFromFilecoinMessageLookup(ctx, msgLookup)
|
tx, err := a.newEthTxFromFilecoinMessageLookup(ctx, msgLookup)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 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) {
|
for ts.Height() >= abi.ChainEpoch(oldestBlkHeight) {
|
||||||
// Unfortunately we need to rebuild the full message view so we can
|
// Unfortunately we need to rebuild the full message view so we can
|
||||||
// totalize gas used in the tipset.
|
// totalize gas used in the tipset.
|
||||||
block, err := a.ethBlockFromFilecoinTipSet(ctx, ts, false)
|
block, err := a.newEthBlockFromFilecoinTipSet(ctx, ts, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return api.EthFeeHistory{}, fmt.Errorf("cannot create eth block: %v", err)
|
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 {
|
if err != nil {
|
||||||
return api.EmptyEthHash, err
|
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) {
|
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
|
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())
|
parent, err := a.Chain.LoadTipSet(ctx, ts.Parents())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return api.EthBlock{}, err
|
return api.EthBlock{}, err
|
||||||
@ -642,7 +642,16 @@ func (a *EthModule) ethBlockFromFilecoinTipSet(ctx context.Context, ts *types.Ti
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return api.EthBlock{}, err
|
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 {
|
if err != nil {
|
||||||
return api.EthBlock{}, err
|
return api.EthBlock{}, err
|
||||||
}
|
}
|
||||||
@ -665,13 +674,13 @@ func (a *EthModule) ethBlockFromFilecoinTipSet(ctx context.Context, ts *types.Ti
|
|||||||
gasUsed += msgLookup.Receipt.GasUsed
|
gasUsed += msgLookup.Receipt.GasUsed
|
||||||
|
|
||||||
if fullTxInfo {
|
if fullTxInfo {
|
||||||
tx, err := a.ethTxFromFilecoinMessageLookup(ctx, msgLookup)
|
tx, err := a.newEthTxFromFilecoinMessageLookup(ctx, msgLookup)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return api.EthBlock{}, nil
|
return api.EthBlock{}, nil
|
||||||
}
|
}
|
||||||
block.Transactions = append(block.Transactions, tx)
|
block.Transactions = append(block.Transactions, tx)
|
||||||
} else {
|
} else {
|
||||||
hash, err := api.EthHashFromCid(msg.Cid())
|
hash, err := api.NewEthHashFromCid(msg.Cid())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return api.EthBlock{}, err
|
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.Number = api.EthUint64(ts.Height())
|
||||||
block.ParentHash = parentBlkHash
|
block.ParentHash = parentBlkHash
|
||||||
block.Timestamp = api.EthUint64(ts.Blocks()[0].Timestamp)
|
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)
|
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 {
|
if msgLookup == nil {
|
||||||
return api.EthTx{}, fmt.Errorf("msg does not exist")
|
return api.EthTx{}, fmt.Errorf("msg does not exist")
|
||||||
}
|
}
|
||||||
cid := msgLookup.Message
|
cid := msgLookup.Message
|
||||||
txHash, err := api.EthHashFromCid(cid)
|
txHash, err := api.NewEthHashFromCid(cid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return api.EthTx{}, err
|
return api.EthTx{}, err
|
||||||
}
|
}
|
||||||
@ -758,7 +768,7 @@ func (a *EthModule) ethTxFromFilecoinMessageLookup(ctx context.Context, msgLooku
|
|||||||
return api.EthTx{}, err
|
return api.EthTx{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
blkHash, err := api.EthHashFromCid(parentTsCid)
|
blkHash, err := api.NewEthHashFromCid(parentTsCid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return api.EthTx{}, err
|
return api.EthTx{}, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user