aboutsummaryrefslogtreecommitdiff
path: root/plugin/evm/vm.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/evm/vm.go')
-rw-r--r--plugin/evm/vm.go45
1 files changed, 42 insertions, 3 deletions
diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go
index 53dc349..c7c7ca0 100644
--- a/plugin/evm/vm.go
+++ b/plugin/evm/vm.go
@@ -140,7 +140,8 @@ func init() {
type VM struct {
ctx *snow.Context
- CLIConfig CommandLineConfig
+ CLIConfig CommandLineConfig
+ encodingManager formatting.EncodingManager
chainID *big.Int
networkID uint64
@@ -221,6 +222,12 @@ func (vm *VM) Initialize(
return vm.CLIConfig.ParsingError
}
+ encodingManager, err := formatting.NewEncodingManager(formatting.CB58Encoding)
+ if err != nil {
+ return fmt.Errorf("problem creating encoding manager: %w", err)
+ }
+ vm.encodingManager = encodingManager
+
if len(fxs) > 0 {
return errUnsupportedFXs
}
@@ -228,8 +235,7 @@ func (vm *VM) Initialize(
vm.ctx = ctx
vm.chaindb = Database{db}
g := new(core.Genesis)
- err := json.Unmarshal(b, g)
- if err != nil {
+ if err := json.Unmarshal(b, g); err != nil {
return err
}
@@ -519,6 +525,10 @@ func (vm *VM) CreateHandlers() map[string]*commonEng.HTTPHandler {
handler.RegisterName("net", &NetAPI{vm})
enabledAPIs = append(enabledAPIs, "net")
}
+ if vm.CLIConfig.Web3APIEnabled {
+ handler.RegisterName("web3", &Web3API{})
+ enabledAPIs = append(enabledAPIs, "web3")
+ }
log.Info(fmt.Sprintf("Enabled APIs: %s", strings.Join(enabledAPIs, ", ")))
@@ -918,6 +928,35 @@ func (vm *VM) GetAcceptedNonce(address common.Address) (uint64, error) {
return state.GetNonce(address), nil
}
+// ParseLocalAddress takes in an address for this chain and produces the ID
+func (vm *VM) ParseLocalAddress(addrStr string) (ids.ShortID, error) {
+ chainID, addr, err := vm.ParseAddress(addrStr)
+ if err != nil {
+ return ids.ShortID{}, err
+ }
+ if !chainID.Equals(vm.ctx.ChainID) {
+ return ids.ShortID{}, fmt.Errorf("expected chainID to be %q but was %q",
+ vm.ctx.ChainID, chainID)
+ }
+ return addr, nil
+}
+
+// FormatLocalAddress takes in a raw address and produces the formatted address
+func (vm *VM) FormatLocalAddress(addr ids.ShortID) (string, error) {
+ return vm.FormatAddress(vm.ctx.ChainID, addr)
+}
+
+// FormatAddress takes in a chainID and a raw address and produces the formatted
+// address
+func (vm *VM) FormatAddress(chainID ids.ID, addr ids.ShortID) (string, error) {
+ chainIDAlias, err := vm.ctx.BCLookup.PrimaryAlias(chainID)
+ if err != nil {
+ return "", err
+ }
+ hrp := constants.GetHRP(vm.ctx.NetworkID)
+ return formatting.FormatAddress(chainIDAlias, hrp, addr.Bytes())
+}
+
// ParseEthAddress parses [addrStr] and returns an Ethereum address
func ParseEthAddress(addrStr string) (common.Address, error) {
if !common.IsHexAddress(addrStr) {