polkadot

package
v5.0.0-...-628dd20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2022 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RtyAtt = retry.Attempts(10)
	RtyDel = retry.Delay(time.Second * 2)
	RtyErr = retry.LastErrorOnly(true)
)
View Source
var DEV_SEED, _ = hex.DecodeString("fac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e")
View Source
var IndexedName = []string{"alice", "bob", "charlie", "dave", "ferdie"}

IndexedName is a slice of the substrate dev key names used for key derivation.

Functions

func DeriveEd25519FromName

func DeriveEd25519FromName(name string) (*p2pCrypto.Ed25519PrivateKey, error)

func DeriveSecp256k1FromName

func DeriveSecp256k1FromName(name string) (*secp256k1.PrivateKey, error)

func DeriveSr25519FromName

func DeriveSr25519FromName(path []string) (*schnorrkel.MiniSecretKey, error)

func EncodeAddressSS58

func EncodeAddressSS58(key []byte) (string, error)

Types

type GetParachainIDResponse

type GetParachainIDResponse struct {
	ParachainID int `json:"para_id"`
}

type ParachainConfig

type ParachainConfig struct {
	ChainID         string
	Bin             string
	Image           ibc.DockerImage
	NumNodes        int
	Flags           []string
	RelayChainFlags []string
}

ParachainConfig is a shared type that allows callers of this module to configure a parachain.

type ParachainNode

type ParachainNode struct {
	TestName string
	Index    int

	NetworkID string

	VolumeName   string
	DockerClient *client.Client
	Image        ibc.DockerImage

	Chain           ibc.Chain
	Bin             string
	NodeKey         p2pcrypto.PrivKey
	ChainID         string
	Flags           []string
	RelayChainFlags []string
	// contains filtered or unexported fields
}

ParachainNode defines the properties required for running a polkadot parachain node.

func (*ParachainNode) Bind

func (pn *ParachainNode) Bind() []string

Bind returns the home folder bind point for running the node.

func (*ParachainNode) CreateNodeContainer

func (pn *ParachainNode) CreateNodeContainer(ctx context.Context) error

CreateNodeContainer assembles a parachain node docker container ready to launch.

func (*ParachainNode) Exec

Exec run a container for a specific job and block until the container exits.

func (*ParachainNode) ExportGenesisState

func (pn *ParachainNode) ExportGenesisState(ctx context.Context) (string, error)

ExportGenesisState exports the genesis state json for the configured chain ID.

func (*ParachainNode) ExportGenesisWasm

func (pn *ParachainNode) ExportGenesisWasm(ctx context.Context) (string, error)

ExportGenesisWasm exports the genesis wasm json for the configured chain ID.

func (*ParachainNode) HostName

func (pn *ParachainNode) HostName() string

HostName returns the docker hostname of the test container.

func (*ParachainNode) MultiAddress

func (pn *ParachainNode) MultiAddress() (string, error)

MultiAddress returns the p2p multiaddr of the node.

func (*ParachainNode) Name

func (pn *ParachainNode) Name() string

Name returns the name of the test node container.

func (*ParachainNode) NodeHome

func (pn *ParachainNode) NodeHome() string

NodeHome returns the working directory within the docker image, the path where the docker volume is mounted.

func (*ParachainNode) ParachainID

func (pn *ParachainNode) ParachainID(ctx context.Context) (int, error)

ParachainID retrieves the node parachain ID.

func (*ParachainNode) PeerID

func (pn *ParachainNode) PeerID() (string, error)

PeerID returns the public key of the node key for p2p.

func (*ParachainNode) RawChainSpecFilePathFull

func (pn *ParachainNode) RawChainSpecFilePathFull() string

RawChainSpecFilePathFull returns the full path to the raw chain spec file within the container.

func (*ParachainNode) RawChainSpecFilePathRelative

func (pn *ParachainNode) RawChainSpecFilePathRelative() string

RawChainSpecFilePathRelative returns the relative path to the raw chain spec file within the container.

func (*ParachainNode) StartContainer

func (pn *ParachainNode) StartContainer(ctx context.Context) error

StartContainer starts the container after it is built by CreateNodeContainer.

func (*ParachainNode) StopContainer

func (pn *ParachainNode) StopContainer(ctx context.Context) error

StopContainer stops the relay chain node container, waiting at most 30 seconds.

type ParachainNodes

type ParachainNodes []*ParachainNode

type PolkadotAuthority

type PolkadotAuthority struct {
	Grandpa            string `json:"grandpa"`
	Babe               string `json:"babe"`
	IMOnline           string `json:"im_online"`
	ParachainValidator string `json:"parachain_validator"`
	AuthorityDiscovery string `json:"authority_discovery"`
	ParaValidator      string `json:"para_validator"`
	ParaAssignment     string `json:"para_assignment"`
	Beefy              string `json:"beefy"`
}

PolkadotAuthority is used when constructing the validator authorities in the substrate chain spec.

type PolkadotChain

type PolkadotChain struct {
	RelayChainNodes RelayChainNodes
	ParachainNodes  []ParachainNodes
	// contains filtered or unexported fields
}

PolkadotChain implements the ibc.Chain interface for substrate chains.

func NewPolkadotChain

func NewPolkadotChain(log *zap.Logger, testName string, chainConfig ibc.ChainConfig, numRelayChainNodes int, parachains []ParachainConfig) *PolkadotChain

NewPolkadotChain returns an uninitialized PolkadotChain, which implements the ibc.Chain interface.

func (*PolkadotChain) Acknowledgements

func (c *PolkadotChain) Acknowledgements(ctx context.Context, height uint64) ([]ibc.PacketAcknowledgement, error)

Acknowledgements returns all acknowledgements in a block at height. Implements Chain interface.

func (*PolkadotChain) Config

func (c *PolkadotChain) Config() ibc.ChainConfig

Config fetches the chain configuration. Implements Chain interface.

func (*PolkadotChain) CreateKey

func (c *PolkadotChain) CreateKey(ctx context.Context, keyName string) error

CreateKey creates a test key in the "user" node (either the first fullnode or the first validator if no fullnodes). Implements Chain interface.

func (*PolkadotChain) Exec

func (c *PolkadotChain) Exec(ctx context.Context, cmd []string, env []string) ([]byte, []byte, error)

Exec runs an arbitrary command using Chain's docker environment. Implements Chain interface.

func (*PolkadotChain) ExportState

func (c *PolkadotChain) ExportState(ctx context.Context, height int64) (string, error)

ExportState exports the chain state at specific height. Implements Chain interface.

func (*PolkadotChain) GetAddress

func (c *PolkadotChain) GetAddress(ctx context.Context, keyName string) ([]byte, error)

GetAddress fetches the bech32 address for a test key on the "user" node (either the first fullnode or the first validator if no fullnodes). Implements Chain interface.

func (*PolkadotChain) GetBalance

func (c *PolkadotChain) GetBalance(ctx context.Context, address string, denom string) (int64, error)

GetBalance fetches the current balance for a specific account address and denom. Implements Chain interface.

func (*PolkadotChain) GetGRPCAddress

func (c *PolkadotChain) GetGRPCAddress() string

GetGRPCAddress retrieves the grpc address that can be reached by other containers in the docker network. Implements Chain interface.

func (*PolkadotChain) GetGasFeesInNativeDenom

func (c *PolkadotChain) GetGasFeesInNativeDenom(gasPaid int64) int64

GetGasFeesInNativeDenom gets the fees in native denom for an amount of spent gas. Implements Chain interface.

func (*PolkadotChain) GetHostGRPCAddress

func (c *PolkadotChain) GetHostGRPCAddress() string

GetHostGRPCAddress returns the grpc address that can be reached by processes on the host machine. Note that this will not return a valid value until after Start returns. Implements Chain interface.

func (*PolkadotChain) GetHostRPCAddress

func (c *PolkadotChain) GetHostRPCAddress() string

GetHostRPCAddress returns the rpc address that can be reached by processes on the host machine. Note that this will not return a valid value until after Start returns. Implements Chain interface.

func (*PolkadotChain) GetRPCAddress

func (c *PolkadotChain) GetRPCAddress() string

GetRPCAddress retrieves the rpc address that can be reached by other containers in the docker network. Implements Chain interface.

func (*PolkadotChain) Height

func (c *PolkadotChain) Height(ctx context.Context) (uint64, error)

Height returns the current block height or an error if unable to get current height. Implements Chain interface.

func (*PolkadotChain) HomeDir

func (c *PolkadotChain) HomeDir() string

HomeDir is the home directory of a node running in a docker container. Therefore, this maps to the container's filesystem (not the host). Implements Chain interface.

func (*PolkadotChain) Initialize

func (c *PolkadotChain) Initialize(ctx context.Context, testName string, cli *client.Client, networkID string) error

Initialize initializes node structs so that things like initializing keys can be done before starting the chain. Implements Chain interface.

func (*PolkadotChain) RecoverKey

func (c *PolkadotChain) RecoverKey(ctx context.Context, name, mnemonic string) error

RecoverKey recovers an existing user from a given mnemonic. Implements Chain interface.

func (*PolkadotChain) SendFunds

func (c *PolkadotChain) SendFunds(ctx context.Context, keyName string, amount ibc.WalletAmount) error

SendFunds sends funds to a wallet from a user account. Implements Chain interface.

func (*PolkadotChain) SendIBCTransfer

func (c *PolkadotChain) SendIBCTransfer(ctx context.Context, channelID, keyName string, amount ibc.WalletAmount, timeout *ibc.IBCTimeout) (ibc.Tx, error)

SendIBCTransfer sends an IBC transfer returning a transaction or an error if the transfer failed. Implements Chain interface.

func (*PolkadotChain) Start

func (c *PolkadotChain) Start(testName string, ctx context.Context, additionalGenesisWallets ...ibc.WalletAmount) error

Start sets up everything needed (validators, gentx, fullnodes, peering, additional accounts) for chain to start from genesis. Implements Chain interface.

func (*PolkadotChain) Timeouts

func (c *PolkadotChain) Timeouts(ctx context.Context, height uint64) ([]ibc.PacketTimeout, error)

Timeouts returns all timeouts in a block at height. Implements Chain interface.

type PolkadotParachainSpec

type PolkadotParachainSpec struct {
	GenesisHead    string `json:"genesis_head"`
	ValidationCode string `json:"validation_code"`
	Parachain      bool   `json:"parachain"`
}

PolkadotParachainSpec is used when constructing substrate chain spec for parachains.

type RelayChainNode

type RelayChainNode struct {
	TestName string
	Index    int

	NetworkID string

	VolumeName   string
	DockerClient *client.Client
	Image        ibc.DockerImage

	Chain             ibc.Chain
	NodeKey           p2pCrypto.PrivKey
	AccountKey        *schnorrkel.MiniSecretKey
	StashKey          *schnorrkel.MiniSecretKey
	Ed25519PrivateKey p2pCrypto.PrivKey
	EcdsaPrivateKey   secp256k1.PrivateKey
	// contains filtered or unexported fields
}

RelayChainNode defines the properties required for running a polkadot relay chain node.

func (*RelayChainNode) AccountAddress

func (p *RelayChainNode) AccountAddress() (string, error)

AccountAddress returns the ss58 encoded account address.

func (*RelayChainNode) Bind

func (p *RelayChainNode) Bind() []string

Bind returns the home folder bind point for running the node.

func (*RelayChainNode) ChainSpecFilePathContainer

func (p *RelayChainNode) ChainSpecFilePathContainer() string

ChainSpecFilePathContainer returns the relative path to the chain spec file within the container.

func (*RelayChainNode) CreateNodeContainer

func (p *RelayChainNode) CreateNodeContainer(ctx context.Context) error

CreateNodeContainer assembles a relay chain node docker container ready to launch.

func (*RelayChainNode) EcdsaAddress

func (p *RelayChainNode) EcdsaAddress() (string, error)

EcdsaAddress returns the ss58 encoded secp256k1 address.

func (*RelayChainNode) Exec

Exec runs a container for a specific job and blocks until the container exits.

func (*RelayChainNode) GenerateChainSpec

func (p *RelayChainNode) GenerateChainSpec(ctx context.Context) error

GenerateChainSpec builds the chain spec for the configured chain ID.

func (*RelayChainNode) GenerateChainSpecRaw

func (p *RelayChainNode) GenerateChainSpecRaw(ctx context.Context) error

GenerateChainSpecRaw builds the raw chain spec from the generated chain spec for the configured chain ID.

func (*RelayChainNode) GrandpaAddress

func (p *RelayChainNode) GrandpaAddress() (string, error)

GrandpaAddress returns the ss58 encoded grandpa (consensus) address.

func (*RelayChainNode) HostName

func (p *RelayChainNode) HostName() string

HostName returns the docker hostname of the test container.

func (*RelayChainNode) MultiAddress

func (p *RelayChainNode) MultiAddress() (string, error)

MultiAddress returns the p2p multiaddr of the node.

func (*RelayChainNode) Name

func (p *RelayChainNode) Name() string

Name returns the name of the test node.

func (*RelayChainNode) NodeHome

func (p *RelayChainNode) NodeHome() string

NodeHome returns the working directory within the docker image, the path where the docker volume is mounted.

func (*RelayChainNode) PeerID

func (p *RelayChainNode) PeerID() (string, error)

PeerID returns the public key of the node key for p2p.

func (*RelayChainNode) RawChainSpecFilePathFull

func (p *RelayChainNode) RawChainSpecFilePathFull() string

RawChainSpecFilePathFull returns the full path to the raw chain spec file within the container.

func (*RelayChainNode) RawChainSpecFilePathRelative

func (p *RelayChainNode) RawChainSpecFilePathRelative() string

RawChainSpecFilePathRelative returns the relative path to the raw chain spec file within the container.

func (*RelayChainNode) StartContainer

func (p *RelayChainNode) StartContainer(ctx context.Context) error

StartContainer starts the container after it is built by CreateNodeContainer.

func (*RelayChainNode) StashAddress

func (p *RelayChainNode) StashAddress() (string, error)

StashAddress returns the ss58 encoded stash address.

func (*RelayChainNode) StopContainer

func (p *RelayChainNode) StopContainer(ctx context.Context) error

StopContainer stops the relay chain node container, waiting at most 30 seconds.

type RelayChainNodes

type RelayChainNodes []*RelayChainNode

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL