polkadot

package
v4.0.0-...-4a095f1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: Apache-2.0 Imports: 35 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.

View Source
var IndexedUri = []string{"//Alice", "//Bob", "//Charlie", "//Dave", "//Ferdie"}

Functions

func BytesToHex

func BytesToHex(b []byte) string

func DecodeAddressSS58

func DecodeAddressSS58(address string) ([]byte, error)

Decodes an address to public key, refactored from https://github.com/subscan-explorer/subscan-essentials

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)

func GetBalance

func GetBalance(api *gsrpc.SubstrateAPI, address string) (int64, error)

GetBalance fetches the current balance for a specific account address using the SubstrateAPI

func IntInSlice

func IntInSlice(a int, list []int) bool

func NewMnemonic

func NewMnemonic() (string, error)

func SendFundsTx

func SendFundsTx(api *gsrpc.SubstrateAPI, senderKeypair signature.KeyringPair, amount ibc.WalletAmount) (gstypes.Hash, error)

SendFundsTx sends funds to a wallet using the SubstrateAPI

Types

type AccountInfo

type AccountInfo struct {
	Nonce       gstypes.U32
	Consumers   gstypes.U32
	Providers   gstypes.U32
	Sufficients gstypes.U32
	Data        struct {
		Free       gstypes.U128
		Reserved   gstypes.U128
		MiscFrozen gstypes.U128
		FreeFrozen gstypes.U128
	}
}

AccountInfo contains information of an account

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) GenerateDefaultChainSpec

func (pn *ParachainNode) GenerateDefaultChainSpec(ctx context.Context) ([]byte, error)

GenerateDefaultChainSpec runs build-spec to get the default chain spec into something malleable

func (*ParachainNode) GenerateParachainGenesisFile

func (pn *ParachainNode) GenerateParachainGenesisFile(ctx context.Context, additionalGenesisWallets ...ibc.WalletAmount) ([]byte, error)

GenerateParachainGenesisFile creates the default chain spec, modifies it and returns it. The modified chain spec is then written to each Parachain node

func (*ParachainNode) GetBalance

func (pn *ParachainNode) GetBalance(ctx context.Context, address string, denom string) (int64, error)

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) ParachainChainSpecFileName

func (pn *ParachainNode) ParachainChainSpecFileName() string

ParachainChainSpecFileName returns the relative path to the chain spec file within the parachain container.

func (*ParachainNode) ParachainChainSpecFilePathFull

func (pn *ParachainNode) ParachainChainSpecFilePathFull() string

ParachainChainSpecFilePathFull returns the full path to the chain spec file within the parachain container

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) RawRelayChainSpecFilePathFull

func (pn *ParachainNode) RawRelayChainSpecFilePathFull() string

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

func (*ParachainNode) RawRelayChainSpecFilePathRelative

func (pn *ParachainNode) RawRelayChainSpecFilePathRelative() string

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

func (*ParachainNode) SendFunds

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

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

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) BuildRelayerWallet

func (c *PolkadotChain) BuildRelayerWallet(ctx context.Context, keyName string) (ibc.Wallet, error)

BuildRelayerWallet will return a Polkadot wallet populated with the mnemonic so that the wallet can be restored in the relayer node using the mnemonic. After it is built, that address is included in genesis with some funds.

func (*PolkadotChain) BuildWallet

func (c *PolkadotChain) BuildWallet(ctx context.Context, keyName string, mnemonic string) (ibc.Wallet, error)

BuildWallet will return a Polkadot wallet If mnemonic != "", it will restore using that mnemonic If mnemonic == "", it will create a new key

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) GetKeyringPair

func (c *PolkadotChain) GetKeyringPair(keyName string) (signature.KeyringPair, error)

GetKeyringPair returns the keyring pair from the keyring using keyName

func (*PolkadotChain) GetPublicKey

func (c *PolkadotChain) GetPublicKey(keyName string) ([]byte, error)

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, keyName, 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 string,
	keyName string,
	amount ibc.WalletAmount,
	options ibc.TransferOptions,
) (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 PolkadotWallet

type PolkadotWallet struct {
	// contains filtered or unexported fields
}

func NewWallet

func NewWallet(keyname string, address []byte, mnemonic string, chainCfg ibc.ChainConfig) *PolkadotWallet

func (*PolkadotWallet) Address

func (w *PolkadotWallet) Address() []byte

Get Address TODO Change to SS58

func (*PolkadotWallet) FormattedAddress

func (w *PolkadotWallet) FormattedAddress() string

func (*PolkadotWallet) KeyName

func (w *PolkadotWallet) KeyName() string

func (*PolkadotWallet) Mnemonic

func (w *PolkadotWallet) Mnemonic() string

Get mnemonic, only used for relayer wallets

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
	AccountKeyName    string
	StashKeyName      string
	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) 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) GetBalance

func (p *RelayChainNode) 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 (*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) SendFunds

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

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

func (*RelayChainNode) StartContainer

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

StartContainer starts the container after it is built by CreateNodeContainer.

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