Parse block heights as hex

This commit is contained in:
Ian Davis 2022-11-16 12:08:48 +00:00
parent 41bf2a0297
commit 8134d2f05b
3 changed files with 15 additions and 7 deletions

View File

@ -47,6 +47,14 @@ func (e *EthUint64) UnmarshalJSON(b []byte) error {
return nil return nil
} }
func EthUint64FromHex(s string) (EthUint64, error) {
parsedInt, err := strconv.ParseUint(strings.Replace(s, "0x", "", -1), 16, 64)
if err != nil {
return EthUint64(0), err
}
return EthUint64(parsedInt), nil
}
type EthBigInt big.Int type EthBigInt big.Int
var EthBigIntZero = EthBigInt{Int: big.Zero().Int} var EthBigIntZero = EthBigInt{Int: big.Zero().Int}

View File

@ -533,10 +533,10 @@ func TestEthGetLogsAll(t *testing.T) {
} }
require.Equal(iterations, len(received), "all messages on chain") require.Equal(iterations, len(received), "all messages on chain")
ts, err := client.ChainHead(ctx) head, err := client.ChainHead(ctx)
require.NoError(err) require.NoError(err)
actor, err := client.StateGetActor(ctx, idAddr, ts.Key()) actor, err := client.StateGetActor(ctx, idAddr, head.Key())
require.NoError(err) require.NoError(err)
require.NotNil(actor.Address) require.NotNil(actor.Address)
ethContractAddr, err := api.EthAddressFromFilecoinAddress(*actor.Address) ethContractAddr, err := api.EthAddressFromFilecoinAddress(*actor.Address)
@ -552,12 +552,12 @@ func TestEthGetLogsAll(t *testing.T) {
// get logs // get logs
res, err := client.EthGetLogs(ctx, &api.EthFilterSpec{ res, err := client.EthGetLogs(ctx, &api.EthFilterSpec{
FromBlock: pstring("0"), FromBlock: pstring("0x0"),
}) })
require.NoError(err) require.NoError(err)
// expect to have seen iteration number of events // expect to have all messages sent
require.Equal(iterations, len(res.Results)) require.Equal(len(received), len(res.Results))
for _, r := range res.Results { for _, r := range res.Results {
// since response is a union and Go doesn't support them well, go-jsonrpc won't give us typed results // since response is a union and Go doesn't support them well, go-jsonrpc won't give us typed results

View File

@ -951,7 +951,7 @@ func (e *EthEvent) installEthFilterSpec(ctx context.Context, filterSpec *api.Eth
} else if *filterSpec.FromBlock == "pending" { } else if *filterSpec.FromBlock == "pending" {
return nil, api.ErrNotSupported return nil, api.ErrNotSupported
} else { } else {
epoch, err := strconv.ParseUint(*filterSpec.FromBlock, 10, 64) epoch, err := api.EthUint64FromHex(*filterSpec.FromBlock)
if err != nil { if err != nil {
return nil, xerrors.Errorf("invalid epoch") return nil, xerrors.Errorf("invalid epoch")
} }
@ -966,7 +966,7 @@ func (e *EthEvent) installEthFilterSpec(ctx context.Context, filterSpec *api.Eth
} else if *filterSpec.ToBlock == "pending" { } else if *filterSpec.ToBlock == "pending" {
return nil, api.ErrNotSupported return nil, api.ErrNotSupported
} else { } else {
epoch, err := strconv.ParseUint(*filterSpec.ToBlock, 10, 64) epoch, err := api.EthUint64FromHex(*filterSpec.FromBlock)
if err != nil { if err != nil {
return nil, xerrors.Errorf("invalid epoch") return nil, xerrors.Errorf("invalid epoch")
} }