Skip to content

Commit

Permalink
add function to get blockchain id from warp precompile (#2633)
Browse files Browse the repository at this point in the history
* add function to get blockchain id from warp precompile

* empty commit

* address PR comments
  • Loading branch information
felipemadero authored Feb 26, 2025
1 parent 0809cdd commit 7fcef28
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/precompiles/precompiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
32 changes: 32 additions & 0 deletions pkg/precompiles/warp.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 7fcef28

Please sign in to comment.