Skip to content

Commit 88ee667

Browse files
committed
fixup! feat(eth)!: add Eth APIs to /v2, fix minor incompatibilities
1 parent 4d730dc commit 88ee667

File tree

7 files changed

+360
-103
lines changed

7 files changed

+360
-103
lines changed

api/v2api/full.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ type FullNode interface {
4242
// In a case where no selector is provided, an error is returned. The selector
4343
// must be explicitly specified.
4444
//
45-
// For more details, refer to the types.TipSetSelector and
46-
// types.NewTipSetSelector.
45+
// For more details, refer to the types.TipSetSelector.
4746
//
4847
// Example usage:
4948
//

chain/types/ethtypes/eth_types.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (e *EthUint64) UnmarshalJSON(b []byte) error {
7373
*e = EthUint64(eint)
7474
return nil
7575
}
76-
return fmt.Errorf("cannot interpret %s as a hex-encoded uint64, or a number", string(b))
76+
return xerrors.Errorf("cannot interpret %s as a hex-encoded uint64, or a number", string(b))
7777
}
7878

7979
func EthUint64FromHex(s string) (EthUint64, error) {
@@ -257,17 +257,17 @@ func (c *EthCall) ToFilecoinMessage() (*types.Message, error) {
257257
var err error
258258
from, err = (EthAddress{}).ToFilecoinAddress()
259259
if err != nil {
260-
return nil, fmt.Errorf("failed to construct the ethereum system address: %w", err)
260+
return nil, xerrors.Errorf("failed to construct the ethereum system address: %w", err)
261261
}
262262
} else {
263263
// The from address must be translatable to an f4 address.
264264
var err error
265265
from, err = c.From.ToFilecoinAddress()
266266
if err != nil {
267-
return nil, fmt.Errorf("failed to translate sender address (%s): %w", c.From.String(), err)
267+
return nil, xerrors.Errorf("failed to translate sender address (%s): %w", c.From.String(), err)
268268
}
269269
if p := from.Protocol(); p != address.Delegated {
270-
return nil, fmt.Errorf("expected a class 4 address, got: %d: %w", p, err)
270+
return nil, xerrors.Errorf("expected a class 4 address, got: %d", p)
271271
}
272272
}
273273

@@ -276,7 +276,7 @@ func (c *EthCall) ToFilecoinMessage() (*types.Message, error) {
276276
initcode := abi.CborBytes(c.Data)
277277
params2, err := actors.SerializeParams(&initcode)
278278
if err != nil {
279-
return nil, fmt.Errorf("failed to serialize params: %w", err)
279+
return nil, xerrors.Errorf("failed to serialize params: %w", err)
280280
}
281281
params = params2
282282
}
@@ -398,10 +398,10 @@ func EthAddressFromPubKey(pubk []byte) ([]byte, error) {
398398
// but putting this check here for defensiveness), strip the prefix
399399
const pubKeyLen = 65
400400
if len(pubk) != pubKeyLen {
401-
return nil, fmt.Errorf("public key should have %d in length, but got %d", pubKeyLen, len(pubk))
401+
return nil, xerrors.Errorf("public key should have %d in length, but got %d", pubKeyLen, len(pubk))
402402
}
403403
if pubk[0] != 0x04 {
404-
return nil, fmt.Errorf("expected first byte of secp256k1 to be 0x04 (uncompressed)")
404+
return nil, xerrors.Errorf("expected first byte of secp256k1 to be 0x04 (uncompressed)")
405405
}
406406
pubk = pubk[1:]
407407

@@ -523,7 +523,7 @@ func (ea EthAddress) ToFilecoinAddress() (address.Address, error) {
523523
// Ethereum Address Manager.
524524
addr, err := address.NewDelegatedAddress(builtintypes.EthereumAddressManagerActorID, ea[:])
525525
if err != nil {
526-
return address.Undef, fmt.Errorf("failed to translate supplied address (%s) into a "+
526+
return address.Undef, xerrors.Errorf("failed to translate supplied address (%s) into a "+
527527
"Filecoin f4 address: %w", hex.EncodeToString(ea[:]), err)
528528
}
529529
return addr, nil
@@ -600,12 +600,12 @@ func handleHexStringPrefix(s string) string {
600600
func EthHashFromCid(c cid.Cid) (EthHash, error) {
601601
hash, found := bytes.CutPrefix(c.Bytes(), expectedHashPrefix)
602602
if !found {
603-
return EthHash{}, fmt.Errorf("CID does not have the expected prefix")
603+
return EthHash{}, xerrors.Errorf("CID does not have the expected prefix")
604604
}
605605

606606
if len(hash) != EthHashLength {
607607
// this shouldn't be possible since the prefix has the length, but just in case
608-
return EthHash{}, fmt.Errorf("CID hash length is not 32 bytes")
608+
return EthHash{}, xerrors.Errorf("CID hash length is not 32 bytes")
609609
}
610610

611611
var h EthHash
@@ -1101,7 +1101,7 @@ func (e *EthBlockNumberOrHash) UnmarshalJSON(b []byte) error {
11011101
if err != nil {
11021102
return err
11031103
}
1104-
if str == "earliest" || str == "pending" || str == "latest" {
1104+
if str == "earliest" || str == "pending" || str == "latest" || str == "finalized" {
11051105
e.PredefinedBlock = &str
11061106
return nil
11071107
}

0 commit comments

Comments
 (0)