Documentation
¶
Index ¶
- Constants
- Variables
- func AccountExistsFromMnemonic(client Client, filePath string) (bool, error)
- func AccountFromFile(filePath string) (signature.KeyringPair, error)
- func BlockFromAvail(avail_blk *types.SignedBlock, appID types.UCompact, callIdx types.CallIndex, ...) ([]*edge_types.Block, error)
- func CreateApplicationKey(client Client, applicationKey string, signingKeyPair signature.KeyringPair) (types.UCompact, error)
- func DepositBalance(client Client, account signature.KeyringPair, amount, nonceIncrement uint64) error
- func EnsureApplicationKeyExists(client Client, applicationKey string, signingKeyPair signature.KeyringPair) (types.UCompact, error)
- func FindCallIndex(client Client) (types.CallIndex, error)
- func GetBalance(client Client, account signature.KeyringPair) (*big.Int, error)
- func NewAccount() (signature.KeyringPair, error)
- func NewAccountFromMnemonic(mnemonic string) (signature.KeyringPair, error)
- func QueryAppID(client Client, applicationKey string) (types.UCompact, error)
- type Blob
- type BlockDataHandler
- type BlockDataWatcher
- type BlockStream
- type Client
- type DummyBlockSource
- type Result
- type SearchFunc
- type Sender
Constants ¶
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" )
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 )
const (
// 1 AVL == 10^18 Avail fractions.
AVL = 1_000_000_000_000_000_000
)
const (
// CallSubmitData is the RPC API call for submitting extrinsic data to Avail.
CallSubmitData = "DataAvailability.submit_data"
)
Variables ¶
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") )
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") )
var ErrNoExtrinsicFound = errors.New("no compatible extrinsic found")
Error returned when no compatible extrinsic is found in Avail block's extrinsic data
var ErrUnsupportedClient = errors.New("unsupported client")
ErrUnsupportedClient indicates that the client is not supported.
Functions ¶
func AccountExistsFromMnemonic ¶
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 ¶
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 ¶
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.
Types ¶
type Blob ¶
Blob is a wrapper type for data that is stored in Avail.
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.
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.
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 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.