avail

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ApplicationKey is the App Key that distincts Optimistic EVM Rollup data in Avail.
	ApplicationKey = "op-evm"

	// CallCreateApplicationKey is the RPC API call for creating a new AppID on Avail.
	CallCreateApplicationKey = "DataAvailability.create_application_key"
)
View Source
const (
	// BlobMagic is required to be present in a `Batch` read from Avail.
	BlobMagic = byte(0b10101010)

	// MaxBlobSize defines the maximum length for stored data in a blob.
	MaxBlobSize = 1 << 24 // 2^24 = 16MB
)
View Source
const (
	// 1 AVL == 10^18 Avail fractions.
	AVL = 1_000_000_000_000_000_000
)
View Source
const (
	// CallSubmitData is the RPC API call for submitting extrinsic data to Avail.
	CallSubmitData = "DataAvailability.submit_data"
)

Variables

View Source
var (
	// DefaultAppID is the Avail application ID.
	DefaultAppID = types.NewUCompactFromUInt(0)

	// ErrAppIDNotFound is the error returned when the AppID is not found.
	ErrAppIDNotFound = errors.New("AppID not found")
)
View Source
var (
	// ErrDataTooLong is the error returned when the data length exceeds the maximum limit.
	ErrDataTooLong = errors.New("data length exceeds maximum limit")

	// ErrInvalidBlobMagic is the error returned when the blob magic byte is invalid.
	ErrInvalidBlobMagic = errors.New("invalid blob magic")
)
View Source
var ErrNoExtrinsicFound = errors.New("no compatible extrinsic found")

Error returned when no compatible extrinsic is found in Avail block's extrinsic data

View Source
var ErrUnsupportedClient = errors.New("unsupported client")

ErrUnsupportedClient indicates that the client is not supported.

Functions

func AccountExistsFromMnemonic

func AccountExistsFromMnemonic(client Client, filePath string) (bool, error)

AccountExistsFromMnemonic checks if an Avail account exists on the blockchain using the provided mnemonic phrase. It takes a client and the file path of the mnemonic phrase, and returns a boolean indicating if the account exists and an error if there is an issue.

func AccountFromFile

func AccountFromFile(filePath string) (signature.KeyringPair, error)

AccountFromFile reads an Avail account from a file containing the mnemonic phrase. It returns the generated key pair and an error if there is an issue.

func BlockFromAvail

func BlockFromAvail(avail_blk *types.SignedBlock, appID types.UCompact, callIdx types.CallIndex, logger hclog.Logger) ([]*edge_types.Block, error)

BlockFromAvail converts Avail blocks into Edge blocks. It takes an Avail block, appID, callIdx, and logger as parameters. It returns a slice of Edge blocks or an error if conversion fails.

func CreateApplicationKey

func CreateApplicationKey(client Client, applicationKey string, signingKeyPair signature.KeyringPair) (types.UCompact, error)

CreateApplicationKey creates a new application key on the blockchain. It takes a client, the application key string, and the signing key pair. It returns the AppID and an error if there is an issue.

func DepositBalance

func DepositBalance(client Client, account signature.KeyringPair, amount, nonceIncrement uint64) error

DepositBalance deposits a specified amount of Avail tokens from the specified account to the specified recipient. It takes a client, the account key pair, the amount to deposit, and the nonce increment. It returns an error if there is an issue.

func EnsureApplicationKeyExists

func EnsureApplicationKeyExists(client Client, applicationKey string, signingKeyPair signature.KeyringPair) (types.UCompact, error)

EnsureApplicationKeyExists checks if the application key exists on the blockchain. If it doesn't exist, it creates a new application key. It takes a client, the application key string, and the signing key pair. It returns the AppID and an error if there is an issue.

func FindCallIndex

func FindCallIndex(client Client) (types.CallIndex, error)

FindCallIndex finds the call index for CallSubmitData in the Avail network.

Parameters:

  • client: The Avail client.

Return:

  • types.CallIndex: The call index for CallSubmitData.
  • error: An error if the call index retrieval fails.

func GetBalance

func GetBalance(client Client, account signature.KeyringPair) (*big.Int, error)

GetBalance retrieves the Avail token balance of the specified account. It takes a client and the account key pair, and returns the account balance as a *big.Int and an error if there is an issue.

func NewAccount

func NewAccount() (signature.KeyringPair, error)

NewAccount generates a new Avail account by creating a mnemonic phrase and deriving the key pair. It returns the generated key pair and an error if there is an issue.

func NewAccountFromMnemonic

func NewAccountFromMnemonic(mnemonic string) (signature.KeyringPair, error)

NewAccountFromMnemonic generates an Avail account using the provided mnemonic phrase. It returns the generated key pair and an error if there is an issue.

func QueryAppID

func QueryAppID(client Client, applicationKey string) (types.UCompact, error)

QueryAppID retrieves the AppID associated with the application key. It takes a client and the application key string. It returns the AppID and an error if there is an issue.

Types

type Blob

type Blob struct {
	Magic byte
	Data  []byte
}

Blob is a wrapper type for data that is stored in Avail.

func (*Blob) Decode

func (b *Blob) Decode(d scale.Decoder) error

Decode decodes the blob data from the provided scale.Decoder.

func (*Blob) Encode

func (b *Blob) Encode(e scale.Encoder) error

Encode encodes the blob data into the provided scale.Encoder.

type BlockDataHandler

type BlockDataHandler interface {
	// HandleData is called when block data is received.
	HandleData(bs []byte) error

	// HandleError is called when an error occurs during block processing.
	HandleError(err error)
}

BlockDataHandler is an interface for handling Avail block data.

type BlockDataWatcher

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

BlockDataWatcher watches for new Avail blocks and filters extrinsics with embedded `Blob` data. It invokes the handler with the decoded `Blob`.

func NewBlockDataWatcher

func NewBlockDataWatcher(client Client, appID types.UCompact, handler BlockDataHandler) (*BlockDataWatcher, error)

NewBlockDataWatcher creates and starts a new BlockDataWatcher. It takes a client of type Client, an appID of type types.UCompact, and a handler of type BlockDataHandler. It returns a pointer to the BlockDataWatcher instance and an error if any.

func (*BlockDataWatcher) Start

func (bw *BlockDataWatcher) Start() error

Start starts the BlockDataWatcher and begins processing blocks. It returns an error if the watcher fails to start.

func (*BlockDataWatcher) Stop

func (bw *BlockDataWatcher) Stop()

Stop stops active watcher.

type BlockStream

type BlockStream interface {
	// Chan returns the channel on which the signed blocks are received.
	Chan() <-chan *types.SignedBlock

	// Close closes the block stream.
	Close()
}

BlockStream represents a stream of Avail blocks.

type Client

type Client interface {
	// BlockStream creates a new Avail block stream, starting from the specified block height offset.
	BlockStream(offset uint64) BlockStream

	// GenesisHash returns the genesis hash of the Avail network.
	GenesisHash() types.Hash

	// GetLatestHeader retrieves the latest header from the Avail network.
	GetLatestHeader() (*types.Header, error)

	// SearchBlock searches for a block at the specified offset using the provided search function.
	SearchBlock(offset int64, searchFunc SearchFunc) (*types.SignedBlock, error)
}

Client is an abstraction on Avail JSON-RPC client.

func NewClient

func NewClient(url string, logger hclog.Logger) (Client, error)

NewClient constructs a new Avail Client for the specified URL.

Parameters:

  • url: The URL of the Avail JSON-RPC server.
  • logger: The logger instance.

Return:

  • Client: The Avail client instance.
  • error: An error if the client initialization fails.

type DummyBlockSource

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

DummyBlockSource is a dummy block source that generates dummy blocks with incremented block numbers.

func (*DummyBlockSource) DummyBlock

func (dbs *DummyBlockSource) DummyBlock(appID types.UCompact, callIdx types.CallIndex, extrinsics ...types.Extrinsic) *types.SignedBlock

DummyBlock generates a dummy block with the specified application ID, call index, and extrinsics.

Parameters:

  • appID: The application ID for the block.
  • callIdx: The call index for the block.
  • extrinsics: Optional extrinsics to include in the block.

Return:

  • *types.SignedBlock: The generated dummy block.

type Result

type Result struct{}

Result represents the final result of block data submission.

type SearchFunc

type SearchFunc func(*types.SignedBlock) (int64, bool, error)

SearchFunc is an interface to function that determines seek offset based on current Avail block. The function returns the next block number to continue search from, a boolean whether the searched block was found or an error if something went wrong.

type Sender

type Sender interface {
	// Send sends a block to Avail without waiting for any status response.
	Send(blk *edgetypes.Block) error
	// SendAndWaitForStatus sends a block to Avail and waits for the specified extrinsic status.
	SendAndWaitForStatus(blk *edgetypes.Block, status types.ExtrinsicStatus) error
}

Sender is an interface for sending blocks to Avail.

func NewBlackholeSender

func NewBlackholeSender() Sender

NewBlackholeSender constructs an Avail block data sender that ignores sent blocks - i.e. blackholes them.

func NewSender

func NewSender(client Client, appID types.UCompact, signingKeyPair signature.KeyringPair) Sender

NewSender constructs a block data sender for Avail. It takes a Client instance, appID of type types.UCompact, and a signingKeyPair of type signature.KeyringPair. It returns a Sender instance.

Jump to

Keyboard shortcuts

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