types

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: ISC Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BtcMainnet SupportedBtcNetwork = "mainnet"
	BtcTestnet SupportedBtcNetwork = "testnet"
	BtcSimnet  SupportedBtcNetwork = "simnet"
	BtcRegtest SupportedBtcNetwork = "regtest"
	BtcSignet  SupportedBtcNetwork = "signet"

	WebsocketMode SupportedSubscriptionMode = "websocket"
	ZmqMode       SupportedSubscriptionMode = "zmq"
)

Variables

View Source
var (
	ErrEmptyCache        = errors.New("empty cache")
	ErrInvalidMaxEntries = errors.New("invalid max entries")
	ErrTooManyEntries    = errors.New("the number of blocks is more than maxEntries")
)

Functions

func GetValidNetParams

func GetValidNetParams() map[string]bool

func GetValidSubscriptionModes

func GetValidSubscriptionModes() map[SupportedSubscriptionMode]bool

func GetWrappedTxs

func GetWrappedTxs(msg *wire.MsgBlock) []*btcutil.Tx

func MustNewMsgInsertBTCSpvProof

func MustNewMsgInsertBTCSpvProof(submitter sdk.AccAddress, proofs []*btcctypes.BTCSpvProof) *btcctypes.MsgInsertBTCSpvProof

MustNewMsgInsertBTCSpvProof returns a MsgInsertBTCSpvProof msg given the submitter address and SPV proofs of two BTC txs

func NewMsgInsertHeader

func NewMsgInsertHeader(prefix string, signer sdk.AccAddress, header *wire.BlockHeader) *btcltypes.MsgInsertHeader

Types

type BTCCache

type BTCCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewBTCCache

func NewBTCCache(maxEntries uint64) (*BTCCache, error)

func (*BTCCache) Add

func (b *BTCCache) Add(ib *IndexedBlock)

Add adds a new block to the cache. Thread-safe.

func (*BTCCache) FindBlock

func (b *BTCCache) FindBlock(blockHeight uint64) *IndexedBlock

FindBlock finds block at the given height in cache

func (*BTCCache) GetAllBlocks

func (b *BTCCache) GetAllBlocks() []*IndexedBlock

GetAllBlocks returns list of all blocks in cache

func (*BTCCache) GetLastBlocks

func (b *BTCCache) GetLastBlocks(stopHeight uint64) ([]*IndexedBlock, error)

GetLastBlocks returns list of blocks between the given stopHeight and the tip of the chain in cache

func (*BTCCache) Init

func (b *BTCCache) Init(ibs []*IndexedBlock) error

func (*BTCCache) RemoveLast

func (b *BTCCache) RemoveLast() error

RemoveLast deletes the last block in cache

func (*BTCCache) Resize added in v0.1.1

func (b *BTCCache) Resize(maxEntries uint64) error

func (*BTCCache) Reverse

func (b *BTCCache) Reverse() error

Reverse reverses the order of blocks in cache in place. Thread-safe.

func (*BTCCache) Size

func (b *BTCCache) Size() uint64

Size returns the size of the cache. Thread-safe.

func (*BTCCache) Tip

func (b *BTCCache) Tip() *IndexedBlock

func (*BTCCache) Trim

func (b *BTCCache) Trim()

Trim trims BTCCache to only keep the latest `maxEntries` blocks, and set `maxEntries` to be the cache size

type BlockEvent

type BlockEvent struct {
	EventType EventType
	Height    int32
	Header    *wire.BlockHeader
}

func NewBlockEvent

func NewBlockEvent(eventType EventType, height int32, header *wire.BlockHeader) *BlockEvent

type CheckpointCache

type CheckpointCache struct {
	Tag     btctxformatter.BabylonTag
	Version btctxformatter.FormatVersion

	// list that contains matched checkpoints
	Checkpoints []*Ckpt

	// map that contains checkpoint segments
	// first key: index of the segment in the checkpoint (0 or 1)
	// second key: hash of the OP_RETURN data in this ckpt segment
	Segments map[uint8]map[string]*CkptSegment
}

func (*CheckpointCache) AddCheckpoint

func (c *CheckpointCache) AddCheckpoint(ckpt *Ckpt)

func (*CheckpointCache) AddSegment

func (c *CheckpointCache) AddSegment(ckptSeg *CkptSegment) error

func (*CheckpointCache) HasCheckpoints

func (c *CheckpointCache) HasCheckpoints() bool

func (*CheckpointCache) Match

func (c *CheckpointCache) Match()

TODO: generalise to NumExpectedProofs > 2 TODO: optimise the complexity by hashmap

func (*CheckpointCache) NumCheckpoints

func (c *CheckpointCache) NumCheckpoints() int

func (*CheckpointCache) NumSegments

func (c *CheckpointCache) NumSegments() int

func (*CheckpointCache) PopEarliestCheckpoint

func (c *CheckpointCache) PopEarliestCheckpoint() *Ckpt

type CheckpointInfo

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

type Ckpt

type Ckpt struct {
	Segments []*CkptSegment
	Epoch    uint64
}

func NewCkpt

func NewCkpt(ckptSeg1 *CkptSegment, ckptSeg2 *CkptSegment, epochNumber uint64) *Ckpt

func (*Ckpt) MustGenSPVProofs

func (ckpt *Ckpt) MustGenSPVProofs() []*btcctypes.BTCSpvProof

type CkptSegment

type CkptSegment struct {
	*btctxformatter.BabylonData
	TxIdx      int
	AssocBlock *IndexedBlock
}

CkptSegment is a segment of the Babylon checkpoint, including - Data: actual OP_RETURN data excluding the Babylon header - Index: index of the segment in the checkpoint - TxIdx: index of the tx in AssocBlock - AssocBlock: pointer to the block that contains the tx that carries the ckpt segment

type EventType

type EventType int
const (
	// BlockDisconnected indicates the associated block was disconnected
	// from the main chain.
	BlockDisconnected EventType = iota

	// BlockConnected indicates the associated block was connected to the
	// main chain.
	BlockConnected
)

type IndexedBlock

type IndexedBlock struct {
	Height int32
	Header *wire.BlockHeader
	Txs    []*btcutil.Tx
}

IndexedBlock is a BTC block with some extra information compared to wire.MsgBlock, including: - block height - txHash, txHashWitness, txIndex for each Tx These are necessary for generating Merkle proof (and thus the `MsgInsertBTCSpvProof` message in babylon) of a certain tx

func NewIndexedBlock

func NewIndexedBlock(height int32, header *wire.BlockHeader, txs []*btcutil.Tx) *IndexedBlock

func NewIndexedBlockFromMsgBlock

func NewIndexedBlockFromMsgBlock(height int32, block *wire.MsgBlock) *IndexedBlock

func (*IndexedBlock) BlockHash

func (ib *IndexedBlock) BlockHash() chainhash.Hash

func (*IndexedBlock) GenSPVProof

func (ib *IndexedBlock) GenSPVProof(txIdx int) (*btcctypes.BTCSpvProof, error)

GenSPVProof generates a Merkle proof of a certain tx with index txIdx

func (*IndexedBlock) MsgBlock

func (ib *IndexedBlock) MsgBlock() *wire.MsgBlock

type SentCheckpoints

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

func NewSentCheckpoints

func NewSentCheckpoints(interval uint) SentCheckpoints

func (*SentCheckpoints) Add

func (sc *SentCheckpoints) Add(epoch uint64, txid1 *chainhash.Hash, txid2 *chainhash.Hash)

Add adds a newly sent checkpoint info

func (*SentCheckpoints) ShouldSend

func (sc *SentCheckpoints) ShouldSend(epoch uint64) bool

ShouldSend returns true if 1. no checkpoint was sent for the epoch 2. the last sent time is outdated by resendIntervalSeconds

type SupportedBtcNetwork

type SupportedBtcNetwork string

func (SupportedBtcNetwork) String

func (c SupportedBtcNetwork) String() string

type SupportedSubscriptionMode

type SupportedSubscriptionMode string

func (SupportedSubscriptionMode) String

func (c SupportedSubscriptionMode) String() string

type UTXO

type UTXO struct {
	TxID     *chainhash.Hash
	Vout     uint32
	ScriptPK []byte
	Amount   btcutil.Amount
	Addr     btcutil.Address
}

Jump to

Keyboard shortcuts

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