Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Commit

Permalink
improvements for local setup (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
wainola authored Mar 21, 2022
1 parent f2eb63a commit 1c368e6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
31 changes: 20 additions & 11 deletions chains/evm/cli/local/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import (
"github.com/ChainSafe/chainbridge-core/chains/evm/calls/transactor"
"github.com/ChainSafe/chainbridge-core/chains/evm/calls/transactor/signAndSend"
"github.com/ChainSafe/chainbridge-core/keystore"
"github.com/ChainSafe/chainbridge-core/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/rs/zerolog/log"
)

Expand All @@ -42,6 +44,9 @@ type EVME2EConfig struct {
GenericHandlerAddr common.Address
Erc721Addr common.Address
Erc721HandlerAddr common.Address
ResourceIDERC20 string
ResourceIDERC721 string
ResourceIDGeneric string
}

type E2EClient interface {
Expand Down Expand Up @@ -88,6 +93,12 @@ func PrepareLocalEVME2EEnv(
return EVME2EConfig{}, err
}

resourceIDERC20 := calls.SliceTo32Bytes(common.LeftPadBytes([]byte{0}, 31))

resourceIDGenericHandler := calls.SliceTo32Bytes(common.LeftPadBytes([]byte{1}, 31))

resourceIDERC721 := calls.SliceTo32Bytes(common.LeftPadBytes([]byte{2}, 31))

conf := EVME2EConfig{
BridgeAddr: bridgeContractAddress,

Expand All @@ -99,19 +110,22 @@ func PrepareLocalEVME2EEnv(

Erc721Addr: erc721ContractAddress,
Erc721HandlerAddr: erc721HandlerContractAddress,
ResourceIDERC20: hexutil.Encode(resourceIDERC20[:]),
ResourceIDERC721: hexutil.Encode(resourceIDERC721[:]),
ResourceIDGeneric: hexutil.Encode(resourceIDGenericHandler[:]),
}

err = PrepareErc20EVME2EEnv(bridgeContract, erc20Contract, mintTo, conf)
err = PrepareErc20EVME2EEnv(bridgeContract, erc20Contract, mintTo, conf, resourceIDERC20)
if err != nil {
return EVME2EConfig{}, err
}

err = PrepareErc721EVME2EEnv(bridgeContract, erc721Contract, conf)
err = PrepareErc721EVME2EEnv(bridgeContract, erc721Contract, conf, resourceIDERC721)
if err != nil {
return EVME2EConfig{}, err
}

err = PrepareGenericEVME2EEnv(bridgeContract, conf)
err = PrepareGenericEVME2EEnv(bridgeContract, conf, resourceIDGenericHandler)
if err != nil {
return EVME2EConfig{}, err
}
Expand Down Expand Up @@ -181,10 +195,8 @@ func deployErc721(
}

func PrepareErc20EVME2EEnv(
bridgeContract *bridge.BridgeContract, erc20Contract *erc20.ERC20Contract, mintTo common.Address, conf EVME2EConfig,
bridgeContract *bridge.BridgeContract, erc20Contract *erc20.ERC20Contract, mintTo common.Address, conf EVME2EConfig, resourceID types.ResourceID,
) error {
// Setting resource
resourceID := calls.SliceTo32Bytes(common.LeftPadBytes([]byte{0}, 31))
_, err := bridgeContract.AdminSetResource(
conf.Erc20HandlerAddr, resourceID, conf.Erc20Addr, transactor.TransactOptions{GasLimit: 2000000},
)
Expand Down Expand Up @@ -215,8 +227,7 @@ func PrepareErc20EVME2EEnv(
return nil
}

func PrepareGenericEVME2EEnv(bridgeContract *bridge.BridgeContract, conf EVME2EConfig) error {
resourceID := calls.SliceTo32Bytes(common.LeftPadBytes([]byte{1}, 31))
func PrepareGenericEVME2EEnv(bridgeContract *bridge.BridgeContract, conf EVME2EConfig, resourceID types.ResourceID) error {
_, err := bridgeContract.AdminSetGenericResource(
conf.GenericHandlerAddr,
resourceID,
Expand All @@ -232,9 +243,7 @@ func PrepareGenericEVME2EEnv(bridgeContract *bridge.BridgeContract, conf EVME2EC
return nil
}

func PrepareErc721EVME2EEnv(bridgeContract *bridge.BridgeContract, erc721Contract *erc721.ERC721Contract, conf EVME2EConfig) error {
// Registering resource
resourceID := calls.SliceTo32Bytes(common.LeftPadBytes([]byte{2}, 31))
func PrepareErc721EVME2EEnv(bridgeContract *bridge.BridgeContract, erc721Contract *erc721.ERC721Contract, conf EVME2EConfig, resourceID types.ResourceID) error {
_, err := bridgeContract.AdminSetResource(conf.Erc721HandlerAddr, resourceID, conf.Erc721Addr, transactor.TransactOptions{GasLimit: 2000000})
if err != nil {
return err
Expand Down
12 changes: 12 additions & 0 deletions chains/evm/cli/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ ERC721: %s
ERC721 Handler: %s
Generic Handler: %s
Asset Store: %s
ERC20 resourceId: %s
ERC721 resourceId %s
Generic resourceId %s
- Chain 2 -
Bridge: %s
Expand All @@ -79,6 +82,9 @@ ERC721: %s
ERC721 Handler: %s
Generic Handler: %s
Asset Store: %s
ERC20 resourceId: %s
ERC721 resourceId %s
Generic resourceId %s
===============================================
`,
Expand All @@ -90,6 +96,9 @@ Asset Store: %s
config.Erc721HandlerAddr,
config.GenericHandlerAddr,
config.AssetStoreAddr,
config.ResourceIDERC20,
config.ResourceIDERC721,
config.ResourceIDGeneric,
// config2
config2.BridgeAddr,
config2.Erc20Addr,
Expand All @@ -98,5 +107,8 @@ Asset Store: %s
config.Erc721HandlerAddr,
config2.GenericHandlerAddr,
config2.AssetStoreAddr,
config2.ResourceIDERC20,
config2.ResourceIDERC721,
config2.ResourceIDGeneric,
)
}
4 changes: 2 additions & 2 deletions e2e/evm-evm/docker-compose.e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
- "8546:8546"
environment:
- NODEKEY=98ab333347a12cef869f92b3de44085f9e44891e513bcf1d76a99eecbcdd5e17
- NETWORKID=421
- NETWORKID=1
- MINE=true
entrypoint: "/root/entrypoint.sh"

Expand All @@ -32,7 +32,7 @@ services:
- "8548:8546"
environment:
- NODEKEY=98ab333347a12cef869f92b3de44085f9e44891e513bcf1d76a99eecbcdd5e17
- NETWORKID=420
- NETWORKID=2
- MINE=true
entrypoint: "/root/entrypoint.sh"

Expand Down

0 comments on commit 1c368e6

Please sign in to comment.