index

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package index provides the implementation of Charm type and its associated methods.

Package index provides the implementation of Degree struct and its associated methods.

Package index provides the implementation of Height type and its associated methods.

Package index provides the implementation of Rarity type and its associated methods.

Package index provides the implementation of blockchain reorganization detection.

Package index provides the implementation of the Sat struct and its related functions.

Index

Constants

View Source
const (
	SupplySat     = 2099999997690000
	LastSupplySat = SupplySat - 1
)

Constants representing the total supply of Sat and the last supply of Sat.

View Source
const CycleEpochs uint32 = 6

CycleEpochs is a constant that represents the number of epochs in a cycle.

View Source
const DiffChangeInterval uint32 = 2016

DiffChangeInterval is a constant that represents the interval at which the difficulty changes.

View Source
const SubsidyHalvingInterval uint32 = 210_000

SubsidyHalvingInterval is the interval at which the subsidy halves.

Variables

CharmsAll is a slice of Charm.

View Source
var EpochStartingStats = []Sat{
	0,
	1050000000000000,
	1575000000000000,
	1837500000000000,
	1968750000000000,
	2034375000000000,
	2067187500000000,
	2083593750000000,
	2091796875000000,
	2095898437500000,
	2097949218750000,
	2098974609270000,
	2099487304530000,
	2099743652160000,
	2099871825870000,
	2099935912620000,
	2099967955890000,
	2099983977420000,
	2099991988080000,
	2099995993410000,
	2099997995970000,
	2099998997250000,
	2099999497890000,
	2099999748210000,
	2099999873370000,
	2099999935950000,
	2099999967240000,
	2099999982780000,
	2099999990550000,
	2099999994330000,
	2099999996220000,
	2099999997060000,
	2099999997480000,
	SupplySat,
}

EpochStartingStats is the starting statistics for each epoch.

View Source
var ErrDetectReorg = errors.New("unrecoverable reorg detected")
View Source
var FirstPostSubsidy = Epoch{
	// contains filtered or unexported fields
}

FirstPostSubsidy is the first epoch after the subsidy.

Functions

func WithBatchClient

func WithBatchClient(cli *rpcclient.Client) func(*Options)

WithBatchClient is a function that returns an Option. This Option sets the batchCli field of the Options struct to the provided rpcclient.Client instance.

func WithClient

func WithClient(cli *rpcclient.Client) func(*Options)

WithClient is a function that returns an Option. This Option sets the cli field of the Options struct to the provided rpcclient.Client instance.

func WithDB

func WithDB(db *dao.DB) func(*Options)

WithDB is a function that returns an Option. This Option sets the db field of the Options struct to the provided dao.DB instance.

func WithIndexSats

func WithIndexSats(indexSats string) func(*Options)

WithIndexSats is a function that returns an Option.

func WithIndexSpendSats

func WithIndexSpendSats(indexSpendSats string) func(*Options)

WithIndexSpendSats is a function that returns an Option.

func WithTidbSessionMemLimit

func WithTidbSessionMemLimit(tidbSessionMemLimit int) func(*Options)

Types

type Amount

type Amount float64

Amount represents a float64 value of an amount.

func (Amount) Sat

func (a Amount) Sat() Sat

Sat converts an Amount to Sat. It multiplies the Amount by OneBtc and returns the integer part.

type Charm

type Charm uint16

Charm is a type that represents a charm in the blockchain.

var (
	CharmCoin          Charm = 0  // Represents a coin charm
	CharmCursed        Charm = 1  // Represents a cursed charm
	CharmEpic          Charm = 2  // Represents an epic charm
	CharmLegendary     Charm = 3  // Represents a legendary charm
	CharmLost          Charm = 4  // Represents a lost charm
	CharmNineBall      Charm = 5  // Represents a nine ball charm
	CharmRare          Charm = 6  // Represents a rare charm
	CharmReInscription Charm = 7  // Represents a re-inscription charm
	CharmUnbound       Charm = 8  // Represents an unbound charm
	CharmUncommon      Charm = 9  // Represents an uncommon charm
	CharmVindicated    Charm = 10 // Represents a vindicated charm
)

Define various types of charms as constants of type Charm.

func TitleToCharm

func TitleToCharm(title string) *Charm

TitleToCharm is a function that returns a pointer to a Charm for a given title.

func (*Charm) Flag

func (c *Charm) Flag() uint16

Flag is a method that returns the flag for a charm.

func (*Charm) Icon

func (c *Charm) Icon() string

Icon is a method that returns the corresponding icon for a charm. It uses a switch statement to determine the charm type and returns a string representing the icon. If the charm type is not recognized, it returns an empty string.

func (*Charm) IsSet

func (c *Charm) IsSet(charms uint16) bool

IsSet is a method that checks if a charm is set in a set of charms. It takes a uint16 as a parameter and returns a bool. The method checks if the bit at the position of the charm in the set of charms is set. If the bit is set, it returns true. Otherwise, it returns false.

func (*Charm) Set

func (c *Charm) Set(charms *uint16)

Set is a method that sets a charm in a set of charms. It takes a pointer to a uint16 as a parameter. The method sets the bit at the position of the charm in the set of charms.

func (*Charm) Title

func (c *Charm) Title() string

Title is a method that returns the titles of all charms in the Charms slice. It returns a slice of strings.

type Charms

type Charms []Charm

func (Charms) Titles

func (cs Charms) Titles(charms uint16) []string

Titles is a method that generates a list of titles for a given set of charms. It takes an uint16 representing a set of charms as a parameter. The method iterates over the Charms slice and checks if each charm is set in the given set of charms. If a charm is set, its title is appended to the list of titles. The method returns a slice of strings representing the titles of the set charms.

type Curse

type Curse int

Curse represents the type of curse that can be applied to an inscription.

const (
	CurseDuplicateField        Curse = 1
	CurseIncompleteField       Curse = 2
	CurseNotAtOffsetZero       Curse = 3
	CurseNotInFirstInput       Curse = 4
	CursePointer               Curse = 5
	CursePushNum               Curse = 6
	CurseReInscription         Curse = 7
	CurseStutter               Curse = 8
	CurseUnrecognizedEvenField Curse = 9
)

These constants represent the different types of curses that can be applied to an inscription.

type Degree

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

Degree is a struct that represents a degree in the blockchain. It contains four fields: - hour: the number of hours in the degree, calculated as the height divided by the product of CycleEpochs and SubsidyHalvingInterval. - minute: the number of minutes in the degree, calculated as the height modulo SubsidyHalvingInterval. - second: the number of seconds in the degree, calculated as the height modulo DiffChangeInterval. - third: the third part of the degree, obtained from the Sat struct.

func NewDegreeFromSat

func NewDegreeFromSat(sat *Sat) *Degree

NewDegreeFromSat is a function that creates a Degree from a Sat. It takes a pointer to a Sat as a parameter and returns a pointer to a Degree. The function first gets the height from the Sat. It then calculates the hour, minute, and second fields of the Degree using the height. It also gets the third field of the Degree from the Sat. Finally, it creates a Degree with the calculated fields and returns it.

type Envelope

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

Envelope represents an envelope in a transaction. It is a struct that contains the following fields: - input: an integer that represents the index of the input in the transaction. - offset: an integer that represents the offset of the envelope in the transaction. - pushNum: a boolean that indicates whether the envelope is a push number envelope. - stutter: a boolean that indicates whether the envelope is stuttered. - payload: a pointer to an Inscription struct that represents the payload of the envelope.

type Envelopes

type Envelopes []*Envelope

Envelopes is a slice of pointers to Envelope.

func EnvelopeFromRawEnvelope

func EnvelopeFromRawEnvelope(raw RawEnvelopes) Envelopes

EnvelopeFromRawEnvelope is a function that creates envelopes from raw envelopes. It takes a slice of pointers to RawEnvelope as a parameter and returns a slice of pointers to Envelope. The function iterates over each raw envelope in the slice. For each raw envelope, it creates an envelope. If the envelope is not nil, it appends the envelope to the slice of envelopes. After iterating over all raw envelopes, it returns the slice of envelopes.

func ParsedEnvelopFromTransaction

func ParsedEnvelopFromTransaction(tx *wire.MsgTx) Envelopes

ParsedEnvelopFromTransaction parses envelopes from a transaction.

type Epoch

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

Epoch represents a period in the blockchain.

func NewEpochFrom

func NewEpochFrom(height *Height) *Epoch

NewEpochFrom creates a new epoch from a given height.

func NewEpochFromSat

func NewEpochFromSat(sat Sat) *Epoch

NewEpochFromSat creates a new epoch from a given sat.

func (*Epoch) StartingHeight

func (e *Epoch) StartingHeight() Height

StartingHeight returns the starting height of the epoch.

func (*Epoch) StartingSat

func (e *Epoch) StartingSat() Sat

StartingSat returns the starting sat of the epoch.

func (*Epoch) Subsidy

func (e *Epoch) Subsidy() uint64

Subsidy returns the subsidy for the epoch.

type ErrRecoverable

type ErrRecoverable struct {
	Height uint32
	Depth  uint32
}

func (*ErrRecoverable) Error

func (r *ErrRecoverable) Error() string

type Flotsam

type Flotsam struct {
	// InscriptionId is a pointer to the unique identifier of the inscription.
	InscriptionId *tables.InscriptionId

	// Offset is the position of the inscription within the transaction.
	Offset uint64

	// Origin is the source of the inscription. It can be either new or old.
	Origin Origin
}

Flotsam represents a floating inscription.

type Height

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

Height is a struct that represents a height in the blockchain. It contains a single field, height, which is an uint32.

func NewHeight

func NewHeight(height uint32) *Height

NewHeight is a function that creates a Height. It takes an uint32 as a parameter and returns a pointer to a Height. The function creates a Height with the given height and returns it.

func (*Height) N

func (h *Height) N() uint32

N is a method that gets the height of a Height. It takes no parameters and returns an uint32. The method returns the height of the Height.

func (*Height) StartingSat

func (h *Height) StartingSat() Sat

StartingSat is a method that gets the starting Sat of a Height.

func (*Height) Subsidy

func (h *Height) Subsidy() uint64

Subsidy is a method that gets the subsidy of a Height. It takes no parameters and returns an uint64. The method creates an Epoch from the Height and gets the subsidy of the Epoch. It then returns the subsidy.

type Indexer

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

Indexer is a struct that holds the configuration options and state for the Indexer.

func NewIndexer

func NewIndexer(opts ...Option) *Indexer

NewIndexer is a function that returns a pointer to a new Indexer instance. It takes a variadic number of Option functions as arguments, which are used to set the configuration options for the Indexer.

func (*Indexer) BatchRpcClient

func (idx *Indexer) BatchRpcClient() *rpcclient.Client

BatchRpcClient is a method that returns a pointer to the rpcclient.Client instance associated with the Indexer. This client is used for making batch RPC calls to the Bitcoin node.

func (*Indexer) Begin

func (idx *Indexer) Begin() *dao.DB

Begin is a method that starts a new transaction and returns a pointer to the dao.DB instance associated with the transaction.

func (*Indexer) DB

func (idx *Indexer) DB() *dao.DB

DB is a method that returns a pointer to the dao.DB instance associated with the Indexer.

func (*Indexer) RpcClient

func (idx *Indexer) RpcClient() *rpcclient.Client

RpcClient is a method that returns a pointer to the rpcclient.Client instance associated with the Indexer. This client is used for making RPC calls to the Bitcoin node.

func (*Indexer) Start

func (idx *Indexer) Start()

Start is a method that starts the Indexer.

func (*Indexer) Stop

func (idx *Indexer) Stop()

func (*Indexer) UpdateIndex

func (idx *Indexer) UpdateIndex() error

UpdateIndex is a method that updates the index of the blockchain. It fetches blocks from the blockchain, starting from the current height of the indexer, and indexes them. If the indexer is configured to index satoshis, it flushes the satoshi range cache to the database. It also updates various statistics related to the indexing process. The method returns an error if there is any issue during the indexing process.

type InscriptionUpdater

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

InscriptionUpdater is responsible for updating inscriptions.

type Option

type Option func(*Options)

Option is a function type that takes a pointer to an Options struct.

type Options

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

Options is a struct that holds configuration options for the Indexer.

type Origin

type Origin struct {
	New *OriginNew
	Old *OriginOld
}

Origin represents the origin of an inscription.

It is a struct that contains two pointers, one to an OriginNew and one to an OriginOld. These pointers represent the new and old origins of an inscription respectively. Only one of these pointers should be non-nil at a time, depending on whether the inscription is new or old.

Fields:

New (*OriginNew): A pointer to an OriginNew struct, representing a new origin of an inscription.
Old (*OriginOld): A pointer to an OriginOld struct, representing an old origin of an inscription.

type OriginNew

type OriginNew struct {
	// Cursed is a boolean flag indicating whether the inscription is cursed.
	Cursed bool

	// Fee is the fee associated with the inscription. It is represented as an int64.
	Fee int64

	// Hidden is a boolean flag indicating whether the inscription is hidden.
	Hidden bool

	// Pointer is an int32 that points to the location of the inscription.
	Pointer []byte

	// ReInscription is a boolean flag indicating whether the inscription is a re-inscription.
	ReInscription bool

	// Unbound is a boolean flag indicating whether the inscription is unbound.
	Unbound bool

	// Inscription is a pointer to the Envelope struct that contains the inscription.
	Inscription *Envelope
}

OriginNew represents a new origin of an inscription.

type OriginOld

type OriginOld struct {
	OldSatPoint tables.SatPointToSequenceNum
}

OriginOld represents an old origin of an inscription.

type Protocol

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

func NewProtocol

func NewProtocol(wtx *dao.DB, entry *tables.Inscriptions) *Protocol

NewProtocol is a function that returns a new protocol.

func (*Protocol) SaveProtocol

func (p *Protocol) SaveProtocol() error

SaveProtocol is a function that saves the protocol.

type PushBytes

type PushBytes []byte

PushBytes represents a slice of bytes to be pushed.

type RangeCaches

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

func NewRangeCaches

func NewRangeCaches() *RangeCaches

func (*RangeCaches) Delete

func (c *RangeCaches) Delete(outpoint string) (*bytes.Buffer, bool)

func (*RangeCaches) Len

func (c *RangeCaches) Len() int

func (*RangeCaches) Range

func (c *RangeCaches) Range(fn func(k string, v *bytes.Buffer))

func (*RangeCaches) Read

func (c *RangeCaches) Read(outpoint string) (*bytes.Buffer, bool)

func (*RangeCaches) Size

func (c *RangeCaches) Size() int

func (*RangeCaches) Write

func (c *RangeCaches) Write(outpoint string, ranges []byte)

type Rarity

type Rarity uint8

Rarity is a type that represents a rarity in the blockchain.

const (
	RarityCommon    Rarity = iota // Represents a common rarity
	RarityUncommon                // Represents an uncommon rarity
	RarityRare                    // Represents a rare rarity
	RarityEpic                    // Represents an epic rarity
	RarityLegendary               // Represents a legendary rarity
	RarityMythic                  // Represents a mythic rarity
)

Define various types of rarities as constants of type Rarity.

func NewRarityFromSat

func NewRarityFromSat(sat *Sat) Rarity

NewRarityFromSat is a function that creates a Rarity from a Sat. It takes a pointer to a Sat as a parameter and returns a Rarity. The function first creates a Degree from the Sat. It then checks the fields of the Degree to determine the rarity. If all fields of the Degree are zero, the rarity is Mythic. If the minute, second, and third fields are zero, the rarity is Legendary. If the minute and third fields are zero, the rarity is Epic. If the second and third fields are zero, the rarity is Rare. If the third field is zero, the rarity is Uncommon. Otherwise, the rarity is Common. Finally, it returns the determined rarity.

type RawEnvelope

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

RawEnvelope represents a raw envelope in a transaction. It is a struct that contains the following fields: - payload: a 2D byte slice that represents the payload of the envelope. - input: an integer that represents the index of the input in the transaction. - offset: an integer that represents the offset of the envelope in the transaction. - pushNum: a boolean that indicates whether the envelope is a push number envelope. - stutter: a boolean that indicates whether the envelope is stuttered.

type RawEnvelopes

type RawEnvelopes []*RawEnvelope

RawEnvelopes is a slice of pointers to RawEnvelope.

func RawEnvelopeFromTransaction

func RawEnvelopeFromTransaction(tx *wire.MsgTx) RawEnvelopes

RawEnvelopeFromTransaction is a function that creates raw envelopes from a transaction. It takes a transaction as a parameter and returns a slice of pointers to RawEnvelope. The function iterates over each input in the transaction. For each input, it creates a Witness and checks if it is a Taproot script. If the Witness is not a Taproot script, it continues to the next input. If the Witness is a Taproot script, it creates a script tokenizer and iterates over the instructions in the script. For each instruction, it creates a raw envelope and checks if the envelope is not nil. If the envelope is not nil, it appends the envelope to the slice of envelopes. If the envelope is nil, it sets the stuttered flag to the value of stutter. After iterating over all inputs and instructions, it returns the slice of envelopes.

type Sat

type Sat uint64

Sat represents a uint64 value of Sat.

func AmountToSat

func AmountToSat(amount float64) Sat

AmountToSat converts a float64 amount to Sat.

func (*Sat) Coin

func (s *Sat) Coin() bool

Coin checks if the Sat is a Coin. It returns true if the Sat is divisible by OneBtc, false otherwise.

func (*Sat) Common

func (s *Sat) Common() bool

func (*Sat) Degree

func (s *Sat) Degree() *Degree

Degree returns the Degree of the Sat.

func (*Sat) Epoch

func (s *Sat) Epoch() *Epoch

Epoch returns the Epoch of the Sat.

func (*Sat) EpochPosition

func (s *Sat) EpochPosition() Sat

EpochPosition returns the position of the Sat in the epoch. It calculates the position by subtracting the starting Sat of the epoch from the Sat.

func (*Sat) Height

func (s *Sat) Height() *Height

Height returns the Height of the Sat. It calculates the Height by adding the starting height of the epoch to the epoch position divided by the epoch subsidy.

func (*Sat) N

func (s *Sat) N() uint64

func (*Sat) NineBall

func (s *Sat) NineBall() bool

NineBall checks if the Sat is a NineBall. It returns true if the Sat is between 50*OneBtc*9 and 50*OneBtc*10, false otherwise.

func (*Sat) Rarity

func (s *Sat) Rarity() Rarity

Rarity returns the Rarity of the Sat.

func (*Sat) Third

func (s *Sat) Third() uint64

Third returns the third of the Sat. It calculates the third by taking the modulus of the epoch position with the epoch subsidy.

type TagType

type TagType int

TagType represents the type of tag in the blockchain.

const (
	TagPointer TagType = iota
	TagUnbound

	TagContentType
	TagParent
	TagMetadata
	TagMetaprotocol
	TagContentEncoding
	TagDelegate
	TagCInsDescription

	TagNop
)

Constants representing the different types of tags.

func TagFromBytes

func TagFromBytes(bs []byte) TagType

TagFromBytes creates a new TagType from a given byte slice. It determines the TagType by comparing the first byte of the slice with the constants.

func (TagType) Bytes

func (t TagType) Bytes() []byte

Bytes returns the byte representation of the TagType. It determines the byte representation by comparing the TagType with the constants.

func (TagType) IsChunked

func (t TagType) IsChunked() bool

IsChunked checks if the TagType is chunked. It returns true if the TagType is TagMetadata, false otherwise.

func (TagType) RemoveField

func (t TagType) RemoveField(fields map[TagType][][]byte) []byte

RemoveField removes a field from a given map of fields. If the TagType is chunked, it removes all values associated with the TagType. If the TagType is not chunked, it removes the first value associated with the TagType. It returns the removed value(s) as a byte slice.

type ValueCache

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

func NewValueCache

func NewValueCache() *ValueCache

func (*ValueCache) Delete

func (c *ValueCache) Delete(outpoint string, height ...uint32)

func (*ValueCache) Len

func (c *ValueCache) Len() int

func (*ValueCache) Range

func (c *ValueCache) Range(fn func(k string, v int64))

func (*ValueCache) Read

func (c *ValueCache) Read(outpoint string) (int64, bool)

func (*ValueCache) Size

func (c *ValueCache) Size() int

func (*ValueCache) Values

func (c *ValueCache) Values() map[string]int64

func (*ValueCache) Write

func (c *ValueCache) Write(outpoint string, value int64)

type Witness

type Witness struct {
	wire.TxWitness // The witness in a transaction
	// contains filtered or unexported fields
}

Witness is a struct that represents a witness in a transaction. It contains two fields: - tokenizer: a pointer to a ScriptTokenizer from the txscript package. This is used to tokenize the script in the witness. - TxWitness: an embedded field from the wire package. This represents the witness in a transaction.

func (*Witness) IsTaprootScript

func (w *Witness) IsTaprootScript() bool

IsTaprootScript checks if the witness is a Taproot script. It first checks if the length of the witness is less than 2, if so it returns false. It then checks if the last element of the witness is an annex, if so it sets the position from last to 3. If the length of the witness is less than the position from last, it returns false. It then creates a script tokenizer from the witness at the position from last and sets the witness's tokenizer to this new tokenizer. It finally returns true, indicating that the witness is a Taproot script.

func (*Witness) ScriptTokenizer

func (w *Witness) ScriptTokenizer() *txscript.ScriptTokenizer

ScriptTokenizer returns the script tokenizer of the witness.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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