api: ethrpc: fix eth_getCode, eth_getTransactionReceipt (#9530)
This commit is contained in:
parent
56b238980b
commit
e17e92775c
@ -778,7 +778,7 @@ type FullNode interface {
|
||||
EthGetTransactionByBlockHashAndIndex(ctx context.Context, blkHash EthHash, txIndex EthUint64) (EthTx, error) //perm:read
|
||||
EthGetTransactionByBlockNumberAndIndex(ctx context.Context, blkNum EthUint64, txIndex EthUint64) (EthTx, error) //perm:read
|
||||
|
||||
EthGetCode(ctx context.Context, address EthAddress) (EthBytes, error) //perm:read
|
||||
EthGetCode(ctx context.Context, address EthAddress, blkOpt string) (EthBytes, error) //perm:read
|
||||
EthGetStorageAt(ctx context.Context, address EthAddress, position EthBytes, blkParam string) (EthBytes, error) //perm:read
|
||||
EthGetBalance(ctx context.Context, address EthAddress, blkParam string) (EthBigInt, error) //perm:read
|
||||
EthChainId(ctx context.Context) (EthUint64, error) //perm:read
|
||||
|
@ -1087,18 +1087,18 @@ func (mr *MockFullNodeMockRecorder) EthGetBlockTransactionCountByNumber(arg0, ar
|
||||
}
|
||||
|
||||
// EthGetCode mocks base method.
|
||||
func (m *MockFullNode) EthGetCode(arg0 context.Context, arg1 api.EthAddress) (api.EthBytes, error) {
|
||||
func (m *MockFullNode) EthGetCode(arg0 context.Context, arg1 api.EthAddress, arg2 string) (api.EthBytes, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "EthGetCode", arg0, arg1)
|
||||
ret := m.ctrl.Call(m, "EthGetCode", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].(api.EthBytes)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// EthGetCode indicates an expected call of EthGetCode.
|
||||
func (mr *MockFullNodeMockRecorder) EthGetCode(arg0, arg1 interface{}) *gomock.Call {
|
||||
func (mr *MockFullNodeMockRecorder) EthGetCode(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EthGetCode", reflect.TypeOf((*MockFullNode)(nil).EthGetCode), arg0, arg1)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EthGetCode", reflect.TypeOf((*MockFullNode)(nil).EthGetCode), arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
// EthGetStorageAt mocks base method.
|
||||
|
@ -242,7 +242,7 @@ type FullNodeStruct struct {
|
||||
|
||||
EthGetBlockTransactionCountByNumber func(p0 context.Context, p1 EthUint64) (EthUint64, error) `perm:"read"`
|
||||
|
||||
EthGetCode func(p0 context.Context, p1 EthAddress) (EthBytes, error) `perm:"read"`
|
||||
EthGetCode func(p0 context.Context, p1 EthAddress, p2 string) (EthBytes, error) `perm:"read"`
|
||||
|
||||
EthGetStorageAt func(p0 context.Context, p1 EthAddress, p2 EthBytes, p3 string) (EthBytes, error) `perm:"read"`
|
||||
|
||||
@ -1960,14 +1960,14 @@ func (s *FullNodeStub) EthGetBlockTransactionCountByNumber(p0 context.Context, p
|
||||
return *new(EthUint64), ErrNotSupported
|
||||
}
|
||||
|
||||
func (s *FullNodeStruct) EthGetCode(p0 context.Context, p1 EthAddress) (EthBytes, error) {
|
||||
func (s *FullNodeStruct) EthGetCode(p0 context.Context, p1 EthAddress, p2 string) (EthBytes, error) {
|
||||
if s.Internal.EthGetCode == nil {
|
||||
return *new(EthBytes), ErrNotSupported
|
||||
}
|
||||
return s.Internal.EthGetCode(p0, p1)
|
||||
return s.Internal.EthGetCode(p0, p1, p2)
|
||||
}
|
||||
|
||||
func (s *FullNodeStub) EthGetCode(p0 context.Context, p1 EthAddress) (EthBytes, error) {
|
||||
func (s *FullNodeStub) EthGetCode(p0 context.Context, p1 EthAddress, p2 string) (EthBytes, error) {
|
||||
return *new(EthBytes), ErrNotSupported
|
||||
}
|
||||
|
||||
|
@ -2372,7 +2372,8 @@ Perms: read
|
||||
Inputs:
|
||||
```json
|
||||
[
|
||||
"0x0707070707070707070707070707070707070707"
|
||||
"0x0707070707070707070707070707070707070707",
|
||||
"string value"
|
||||
]
|
||||
```
|
||||
|
||||
|
@ -42,7 +42,7 @@ type EthModuleAPI interface {
|
||||
EthGetTransactionReceipt(ctx context.Context, txHash api.EthHash) (*api.EthTxReceipt, error)
|
||||
EthGetTransactionByBlockHashAndIndex(ctx context.Context, blkHash api.EthHash, txIndex api.EthUint64) (api.EthTx, error)
|
||||
EthGetTransactionByBlockNumberAndIndex(ctx context.Context, blkNum api.EthUint64, txIndex api.EthUint64) (api.EthTx, error)
|
||||
EthGetCode(ctx context.Context, address api.EthAddress) (api.EthBytes, error)
|
||||
EthGetCode(ctx context.Context, address api.EthAddress, blkOpt string) (api.EthBytes, error)
|
||||
EthGetStorageAt(ctx context.Context, address api.EthAddress, position api.EthBytes, blkParam string) (api.EthBytes, error)
|
||||
EthGetBalance(ctx context.Context, address api.EthAddress, blkParam string) (api.EthBigInt, error)
|
||||
EthChainId(ctx context.Context) (api.EthUint64, error)
|
||||
@ -189,22 +189,22 @@ func (a *EthModule) EthGetTransactionReceipt(ctx context.Context, txHash api.Eth
|
||||
|
||||
msgLookup, err := a.StateAPI.StateSearchMsg(ctx, types.EmptyTSK, cid, api.LookbackNoLimit, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
tx, err := a.ethTxFromFilecoinMessageLookup(ctx, msgLookup)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
replay, err := a.StateAPI.StateReplay(ctx, types.EmptyTSK, cid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
receipt, err := api.NewEthTxReceipt(tx, msgLookup, replay)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil
|
||||
}
|
||||
return &receipt, nil
|
||||
}
|
||||
@ -218,7 +218,7 @@ func (a *EthModule) EthGetTransactionByBlockNumberAndIndex(ctx context.Context,
|
||||
}
|
||||
|
||||
// EthGetCode returns string value of the compiled bytecode
|
||||
func (a *EthModule) EthGetCode(ctx context.Context, ethAddr api.EthAddress) (api.EthBytes, error) {
|
||||
func (a *EthModule) EthGetCode(ctx context.Context, ethAddr api.EthAddress, blkOpt string) (api.EthBytes, error) {
|
||||
to, err := ethAddr.ToFilecoinAddress()
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("cannot get Filecoin address: %w", err)
|
||||
@ -642,12 +642,23 @@ func (a *EthModule) ethTxFromFilecoinMessageLookup(ctx context.Context, msgLooku
|
||||
return api.EthTx{}, err
|
||||
}
|
||||
|
||||
tsCid, err := msgLookup.TipSet.Cid()
|
||||
ts, err := a.Chain.LoadTipSet(ctx, msgLookup.TipSet)
|
||||
if err != nil {
|
||||
return api.EthTx{}, err
|
||||
}
|
||||
|
||||
blkHash, err := api.EthHashFromCid(tsCid)
|
||||
// This tx is located in the parent tipset
|
||||
parentTs, err := a.Chain.LoadTipSet(ctx, ts.Parents())
|
||||
if err != nil {
|
||||
return api.EthTx{}, err
|
||||
}
|
||||
|
||||
parentTsCid, err := parentTs.Key().Cid()
|
||||
if err != nil {
|
||||
return api.EthTx{}, err
|
||||
}
|
||||
|
||||
blkHash, err := api.EthHashFromCid(parentTsCid)
|
||||
if err != nil {
|
||||
return api.EthTx{}, err
|
||||
}
|
||||
@ -700,7 +711,7 @@ func (a *EthModule) ethTxFromFilecoinMessageLookup(ctx context.Context, msgLooku
|
||||
ChainID: api.EthUint64(build.Eip155ChainId),
|
||||
Hash: txHash,
|
||||
BlockHash: blkHash,
|
||||
BlockNumber: api.EthUint64(msgLookup.Height),
|
||||
BlockNumber: api.EthUint64(parentTs.Height()),
|
||||
From: fromEthAddr,
|
||||
To: toAddr,
|
||||
Value: api.EthBigInt(msg.Value),
|
||||
|
Loading…
Reference in New Issue
Block a user