Skip to content

Commit

Permalink
fix(api): eth/id address conversion (#9511)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien authored and vyzo committed Nov 9, 2022
1 parent e109be4 commit 420bd34
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions api/eth_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,11 @@ func (a *EthAddress) UnmarshalJSON(b []byte) error {
}

func (a EthAddress) ToFilecoinAddress() (address.Address, error) {
expectedPrefix := [12]byte{0xff}
if !bytes.Equal(a[:12], expectedPrefix[:]) {
// TODO: handle f4 once we've added support to go-address.
return address.Address{}, xerrors.Errorf("not a valid id-in-eth address: %s", a)
}
id := binary.BigEndian.Uint64(a[12:])
return address.NewIDAddress(id)
}
Expand All @@ -291,12 +296,9 @@ func EthAddressFromFilecoinIDAddress(addr address.Address) (EthAddress, error) {
if err != nil {
return EthAddress{}, err
}
buf := make([]byte, ETH_ADDRESS_LENGTH)
buf[0] = 0xff
binary.BigEndian.PutUint64(buf[12:], id)

var ethaddr EthAddress
copy(ethaddr[:], buf)
ethaddr[0] = 0xff
binary.BigEndian.PutUint64(ethaddr[12:], id)
return ethaddr, nil
}

Expand Down

0 comments on commit 420bd34

Please sign in to comment.