Skip to content

Commit

Permalink
fix network
Browse files Browse the repository at this point in the history
  • Loading branch information
sukantoraymond committed May 23, 2024
1 parent 1afa484 commit fc31e10
Show file tree
Hide file tree
Showing 5 changed files with 252 additions and 4 deletions.
24 changes: 24 additions & 0 deletions avalanche/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,34 @@ package avalanche

type NetworkKind int64

const (
Undefined NetworkKind = iota
Mainnet
Fuji
Local
Devnet
)

func (nk NetworkKind) String() string {
switch nk {
case Mainnet:
return "Mainnet"
case Fuji:
return "Fuji"
case Local:
return "Local Network"
case Devnet:
return "Devnet"
}
return "invalid network"
}

type Network struct {
Kind NetworkKind

ID uint32

Endpoint string
}

var UndefinedNetwork = Network{}
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ go 1.21.9

toolchain go1.21.10

require github.com/ava-labs/avalanchego v1.11.5
require (
github.com/ava-labs/avalanchego v1.11.5
github.com/ava-labs/subnet-evm v0.6.4
github.com/ava-labs/teleporter v1.0.0
)

require (
github.com/DataDog/zstd v1.5.2 // indirect
Expand Down
6 changes: 3 additions & 3 deletions multisig/multisig.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package multisig

import (
"github.com/ava-labs/avalanche-tooling-sdk-go/network"
"avalanche-tooling-sdk-go/avalanche"

Check failure on line 6 in multisig/multisig.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `gofumpt`-ed (gofumpt)
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/wallet/subnet/primary"
Expand Down Expand Up @@ -69,8 +69,8 @@ func (*PChainMultisig) GetKind() PChainTxKind {
return Invalid
}

func (*PChainMultisig) GetNetwork() (network.Network, error) {
return nil, nil
func (*PChainMultisig) GetNetwork() (avalanche.Network, error) {
return avalanche.UndefinedNetwork, nil
}

func (*PChainMultisig) GetSubnetID() (ids.ID, error) {
Expand Down
82 changes: 82 additions & 0 deletions network/multisig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package multisig

import (
"github.com/ava-labs/avalanche-tooling-sdk-go/network"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/wallet/subnet/primary"
)

type PChainTxKind int

const (
Invalid = iota
CreateBlockchain
TransferSubnetOwnership
)

type PChainMultisig struct {
_ *txs.Tx
}

func New(_ *txs.Tx) *PChainMultisig {
return nil
}

func (*PChainMultisig) ToBytes() ([]byte, error) {
return nil, nil
}

func (*PChainMultisig) FromBytes(_ []byte) error {
return nil
}

func (*PChainMultisig) ToFile(_ string) error {
return nil
}

func (*PChainMultisig) FromFile(_ string) error {
return nil
}

func (*PChainMultisig) Sign(_ *primary.Wallet) error {
return nil
}

func (*PChainMultisig) Commit() error {
return nil
}

func (*PChainMultisig) IsReadyToCommit() error {
return nil
}

func (*PChainMultisig) GetRemainingSigners() ([]ids.ID, error) {
return nil, nil
}

func (*PChainMultisig) GetAuthSigners() ([]ids.ID, error) {
return nil, nil
}

func (*PChainMultisig) GetFeeSigners() ([]ids.ID, error) {
return nil, nil
}

func (*PChainMultisig) GetKind() PChainTxKind {
return Invalid
}

func (*PChainMultisig) GetNetwork() (network.Network, error) {
return nil, nil
}

func (*PChainMultisig) GetSubnetID() (ids.ID, error) {
return ids.Empty, nil
}

func (*PChainMultisig) GetSubnetOwners() ([]ids.ID, int, error) {
return nil, 0, nil
}
138 changes: 138 additions & 0 deletions subnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ package subnet

import (
"avalanche-tooling-sdk-go/avalanche"
"bytes"
"encoding/json"
"fmt"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/coreth/core"
"github.com/ava-labs/coreth/utils"
"github.com/ava-labs/subnet-evm/params"
"math/big"
"time"
)

type SubnetParams struct {
Expand Down Expand Up @@ -124,3 +132,133 @@ func New(client *avalanche.BaseApp, subnetParams *SubnetParams) *Subnet {
}
return &subnet
}

func createEvmGenesis(
subnetName string,
subnetEVMVersion string,
rpcVersion int,
subnetEVMChainID uint64,
subnetEVMTokenSymbol string,
useSubnetEVMDefaults bool,
useWarp bool,
teleporterInfo *teleporter.Info,

Check failure on line 144 in subnet/subnet.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: teleporter (typecheck)
) ([]byte, error) {
genesis := core.Genesis{}
genesis.Timestamp = *utils.TimeToNewUint64(time.Now())

conf := params.SubnetEVMDefaultChainConfig
conf.NetworkUpgrades = params.NetworkUpgrades{}

const (
descriptorsState = "descriptors"
feeState = "fee"
airdropState = "airdrop"
precompilesState = "precompiles"
)

var (
chainID *big.Int
tokenSymbol string

Check failure on line 161 in subnet/subnet.go

View workflow job for this annotation

GitHub Actions / Lint

tokenSymbol declared and not used (typecheck)
allocation core.GenesisAlloc
//direction statemachine.StateDirection
err error
)

//subnetEvmState, err := statemachine.NewStateMachine(
// []string{descriptorsState, feeState, airdropState, precompilesState},
//)
//if err != nil {
// return nil, err
//}
//for subnetEvmState.Running() {
// switch subnetEvmState.CurrentState() {
// case descriptorsState:
// chainID, tokenSymbol, direction, err = getDescriptors(
// app,
// subnetEVMChainID,
// subnetEVMTokenSymbol,
// )
// case feeState:
// *conf, direction, err = GetFeeConfig(*conf, app, useSubnetEVMDefaults)
// case airdropState:
// allocation, direction, err = getAllocation(
// app,
// subnetName,
// defaultEvmAirdropAmount,
// oneAvax,
// fmt.Sprintf("Amount to airdrop (in %s units)", tokenSymbol),
// useSubnetEVMDefaults,
// )
// if teleporterInfo != nil {
// allocation = addTeleporterAddressToAllocations(
// allocation,
// teleporterInfo.FundedAddress,
// teleporterInfo.FundedBalance,
// )
// }
// case precompilesState:
// *conf, direction, err = getPrecompiles(*conf, app, &genesis.Timestamp, useSubnetEVMDefaults, useWarp)
// if teleporterInfo != nil {
// *conf = addTeleporterAddressesToAllowLists(
// *conf,
// teleporterInfo.FundedAddress,
// teleporterInfo.MessengerDeployerAddress,
// teleporterInfo.RelayerAddress,
// )
// }
// default:
// err = errors.New("invalid creation stage")
// }
// if err != nil {
// return nil, nil, err
// }
// subnetEvmState.NextState(direction)
//}

if conf != nil && conf.GenesisPrecompiles[txallowlist.ConfigKey] != nil {

Check failure on line 218 in subnet/subnet.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: txallowlist (typecheck)
allowListCfg, ok := conf.GenesisPrecompiles[txallowlist.ConfigKey].(*txallowlist.Config)

Check failure on line 219 in subnet/subnet.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: txallowlist (typecheck)
if !ok {
return nil, fmt.Errorf(
"expected config of type txallowlist.AllowListConfig, but got %T",
allowListCfg,
)
}

if err := ensureAdminsHaveBalance(

Check failure on line 227 in subnet/subnet.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: ensureAdminsHaveBalance (typecheck)
allowListCfg.AdminAddresses,
allocation); err != nil {
return nil, nil, err
}
}

conf.ChainID = chainID

genesis.Alloc = allocation
genesis.Config = conf
genesis.Difficulty = Difficulty

Check failure on line 238 in subnet/subnet.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: Difficulty (typecheck)
genesis.GasLimit = conf.FeeConfig.GasLimit.Uint64()

jsonBytes, err := genesis.MarshalJSON()
if err != nil {
return nil, err
}

var prettyJSON bytes.Buffer
err = json.Indent(&prettyJSON, jsonBytes, "", " ")
if err != nil {
return nil, err
}

//sc := &models.Sidecar{
// Name: subnetName,
// VM: models.SubnetEvm,
// VMVersion: subnetEVMVersion,
// RPCVersion: rpcVersion,
// Subnet: subnetName,
// TokenSymbol: tokenSymbol,
// TokenName: tokenSymbol + " Token",
//}

//return prettyJSON.Bytes(), sc, nil
return prettyJSON.Bytes(), nil
}

0 comments on commit fc31e10

Please sign in to comment.