Skip to content

Commit

Permalink
feat: EthAPI: Add EthAddressToFilecoinAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Feb 16, 2023
1 parent 2dd2edc commit 1d0a524
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,11 @@ workflows:
suite: itest-eth_account_abstraction
target: "./itests/eth_account_abstraction_test.go"

- test:
name: test-itest-eth_api
suite: itest-eth_api
target: "./itests/eth_api_test.go"

- test:
name: test-itest-eth_balance
suite: itest-eth_balance
Expand Down
2 changes: 2 additions & 0 deletions api/api_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,8 @@ type FullNode interface {
//
// EthAccounts will always return [] since we don't expect Lotus to manage private keys
EthAccounts(ctx context.Context) ([]ethtypes.EthAddress, error) //perm:read
// EthAddressToFilecoinAddress converts an EthAddress into an f410 Filecoin Address
EthAddressToFilecoinAddress(ctx context.Context, ethAddress ethtypes.EthAddress) (address.Address, error) //perm:read
// EthBlockNumber returns the height of the latest (heaviest) TipSet
EthBlockNumber(ctx context.Context) (ethtypes.EthUint64, error) //perm:read
// EthGetBlockTransactionCountByNumber returns the number of messages in the TipSet
Expand Down
15 changes: 15 additions & 0 deletions api/mocks/mock_full.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions api/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified build/openrpc/full.json.gz
Binary file not shown.
Binary file modified build/openrpc/gateway.json.gz
Binary file not shown.
Binary file modified build/openrpc/miner.json.gz
Binary file not shown.
Binary file modified build/openrpc/worker.json.gz
Binary file not shown.
16 changes: 16 additions & 0 deletions documentation/en/api-v1-unstable-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
* [CreateBackup](#CreateBackup)
* [Eth](#Eth)
* [EthAccounts](#EthAccounts)
* [EthAddressToFilecoinAddress](#EthAddressToFilecoinAddress)
* [EthBlockNumber](#EthBlockNumber)
* [EthCall](#EthCall)
* [EthChainId](#EthChainId)
Expand Down Expand Up @@ -2262,6 +2263,21 @@ Response:
]
```

### EthAddressToFilecoinAddress
EthAddressToFilecoinAddress converts an EthAddress into an f410 Filecoin Address


Perms: read

Inputs:
```json
[
"0x5cbeecf99d3fdb3f25e309cc264f240bb0664031"
]
```

Response: `"f01234"`

### EthBlockNumber
EthBlockNumber returns the height of the latest (heaviest) TipSet

Expand Down
1 change: 1 addition & 0 deletions gateway/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type TargetAPI interface {
StateVMCirculatingSupplyInternal(context.Context, types.TipSetKey) (api.CirculatingSupply, error)
WalletBalance(context.Context, address.Address) (types.BigInt, error)

EthAddressToFilecoinAddress(ctx context.Context, ethAddress ethtypes.EthAddress) (address.Address, error)
EthBlockNumber(ctx context.Context) (ethtypes.EthUint64, error)
EthGetBlockTransactionCountByNumber(ctx context.Context, blkNum ethtypes.EthUint64) (ethtypes.EthUint64, error)
EthGetBlockTransactionCountByHash(ctx context.Context, blkHash ethtypes.EthHash) (ethtypes.EthUint64, error)
Expand Down
47 changes: 47 additions & 0 deletions itests/eth_api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package itests

import (
"context"
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/filecoin-project/go-state-types/builtin"

"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/types/ethtypes"
"github.com/filecoin-project/lotus/chain/wallet/key"
"github.com/filecoin-project/lotus/itests/kit"
)

func TestEthAddressToFilecoinAddress(t *testing.T) {
client, _, _ := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC())

ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

secpKey, err := key.GenerateKey(types.KTDelegated)
require.NoError(t, err)

filecoinKeyAddr, err := client.WalletImport(ctx, &secpKey.KeyInfo)
require.NoError(t, err)

ethAddr, err := ethtypes.EthAddressFromFilecoinAddress(filecoinKeyAddr)
require.NoError(t, err)

apiFilAddr, err := client.EthAddressToFilecoinAddress(ctx, ethAddr)
require.NoError(t, err)

require.Equal(t, filecoinKeyAddr, apiFilAddr)

filecoinIdArr := builtin.StorageMarketActorAddr
ethAddr, err = ethtypes.EthAddressFromFilecoinAddress(filecoinIdArr)
require.NoError(t, err)

apiFilAddr, err = client.EthAddressToFilecoinAddress(ctx, ethAddr)
require.NoError(t, err)

require.Equal(t, filecoinIdArr, apiFilAddr)

}
5 changes: 5 additions & 0 deletions node/impl/full/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/ipfs/go-cid"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-jsonrpc"

"github.com/filecoin-project/lotus/api"
Expand All @@ -16,6 +17,10 @@ var ErrModuleDisabled = errors.New("module disabled, enable with Fevm.EnableEthR

type EthModuleDummy struct{}

func (e *EthModuleDummy) EthAddressToFilecoinAddress(ctx context.Context, ethAddress ethtypes.EthAddress) (address.Address, error) {
return address.Undef, ErrModuleDisabled
}

func (e *EthModuleDummy) EthGetMessageCidByTransactionHash(ctx context.Context, txHash *ethtypes.EthHash) (*cid.Cid, error) {
return nil, ErrModuleDisabled
}
Expand Down
4 changes: 4 additions & 0 deletions node/impl/full/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ func (a *EthModule) EthAccounts(context.Context) ([]ethtypes.EthAddress, error)
return []ethtypes.EthAddress{}, nil
}

func (a *EthAPI) EthAddressToFilecoinAddress(ctx context.Context, ethAddress ethtypes.EthAddress) (address.Address, error) {
return ethAddress.ToFilecoinAddress()
}

func (a *EthModule) countTipsetMsgs(ctx context.Context, ts *types.TipSet) (int, error) {
blkMsgs, err := a.Chain.BlockMsgsForTipset(ctx, ts)
if err != nil {
Expand Down

0 comments on commit 1d0a524

Please sign in to comment.