diff --git a/pkg/precompiles/precompiles.go b/pkg/precompiles/precompiles.go index 336bc49c1..43cafd74a 100644 --- a/pkg/precompiles/precompiles.go +++ b/pkg/precompiles/precompiles.go @@ -5,7 +5,11 @@ package precompiles import ( _ "embed" - "github.com/ethereum/go-ethereum/common" + "github.com/ava-labs/subnet-evm/precompile/contracts/nativeminter" + "github.com/ava-labs/subnet-evm/precompile/contracts/warp" ) -var NativeMinterPrecompile = common.HexToAddress("0x0200000000000000000000000000000000000001") +var ( + NativeMinterPrecompile = nativeminter.ContractAddress + WarpPrecompile = warp.ContractAddress +) diff --git a/pkg/precompiles/warp.go b/pkg/precompiles/warp.go new file mode 100644 index 000000000..7ae068600 --- /dev/null +++ b/pkg/precompiles/warp.go @@ -0,0 +1,32 @@ +// Copyright (C) 2022, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. +package precompiles + +import ( + _ "embed" + "fmt" + + "github.com/ava-labs/avalanche-cli/pkg/contract" + "github.com/ava-labs/avalanchego/ids" +) + +func WarpPrecompileGetBlockchainID( + rpcURL string, +) (ids.ID, error) { + out, err := contract.CallToMethod( + rpcURL, + WarpPrecompile, + "getBlockchainID()->(bytes32)", + ) + if err != nil { + return ids.Empty, err + } + if len(out) == 0 { + return ids.Empty, fmt.Errorf("error at getBlockchainID call: no return value") + } + received, ok := out[0].([32]byte) + if !ok { + return ids.Empty, fmt.Errorf("error at getBlockchainID call, expected ids.ID, got %T", out[0]) + } + return received, nil +}