runestone

package module
v0.0.0-...-a36ade2 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

README

Runestone Golang library

Bitcoin Rune protocol golang implement library.

How to use

go get github.com/bxelab/runestone@latest
Etching

Define a new Rune named STUDYZY.GMAIL.COM

func testEtching() {
	runeName := "STUDYZY.GMAIL.COM"
	symbol := '曾'
	myRune, err := runestone.SpacedRuneFromString(runeName)
	if err != nil {
		fmt.Println(err)
		return
	}
	amt := uint128.From64(666666)
	ca := uint128.From64(21000000)
	etching := &runestone.Etching{
		Rune:    &myRune.Rune,
		Spacers: &myRune.Spacers,
		Symbol:  &symbol,
		Terms: &runestone.Terms{
			Amount: &amt,
			Cap:    &ca,
		},
	}
	r := runestone.Runestone{Etching: etching}
	data, err := r.Encipher()
	if err != nil {
		fmt.Println(err)
	}
	fmt.Printf("Etching data: 0x%x\n", data)
	dataString, _ := txscript.DisasmString(data)
	fmt.Printf("Etching Script: %s\n", dataString)
}
Mint
func testMint() {
	runeIdStr := "2609649:946"
	runeId, _ := runestone.RuneIdFromString(runeIdStr)
	r := runestone.Runestone{Mint: runeId}
	data, err := r.Encipher()
	if err != nil {
		fmt.Println(err)
	}
	fmt.Printf("Mint Rune[%s] data: 0x%x\n", runeIdStr, data)
	dataString, _ := txscript.DisasmString(data)
	fmt.Printf("Mint Script: %s\n", dataString)
}
Decode
func testDecode() {
	data, _ := hex.DecodeString("140114001600") //Mint UNCOMMON•GOODS
	var tx wire.MsgTx
	builder := txscript.NewScriptBuilder()
	// Push opcode OP_RETURN
	builder.AddOp(txscript.OP_RETURN)
	// Push MAGIC_NUMBER
	builder.AddOp(runestone.MAGIC_NUMBER)
	// Push payload
	builder.AddData(data)
	pkScript, _ := builder.Script()
	txOut := wire.NewTxOut(0, pkScript)
	tx.AddTxOut(txOut)
	r := &runestone.Runestone{}
	artifact, err := r.Decipher(&tx)
	if err != nil {
		fmt.Println(err)
		return
	}
	a, _ := json.Marshal(artifact)
	fmt.Printf("Artifact: %s\n", string(a))
}
Reference:

Documentation

Overview

Package runestone is an open-source implementation of the Bitcoin Rune protocol in Go.

The runestone project aims to provide a robust, efficient, and easy-to-use library for developers to interact with the Rune protocol. It covers various aspects of the protocol, such as transaction handling, block validation, and network communication.

Features:

  • Rune protocol implementation: This package contains a complete implementation of the Rune protocol, allowing developers to build and interact with Bitcoin Rune applications easily.
  • Modular design: The package is designed with modularity in mind, making it easy to extend and customize for specific use cases.
  • Efficient and performant: The Go language offers excellent performance and efficient memory usage, making this package suitable for use in high-performance applications.
  • Well-documented and tested: The package includes comprehensive documentation and test coverage, ensuring its reliability and ease of use.

Getting started: To start using the runestone package, simply import it into your Go project:

``` go get github.com/bxelab/runestone ```

You can then use the various components provided by the package to interact with the Rune protocol, such as creating transactions, validating blocks, and communicating with other nodes on the network.

For more information and examples, please refer to the package documentation and the project's GitHub repository.

Contributions and feedback are welcome! If you encounter any issues or have suggestions for improvements, please open an issue on the project's GitHub repository or submit a pull request.

Index

Constants

View Source
const (
	MaxDivisibility = 38
	MaxSpacers      = 0b00000111_11111111_11111111_11111111
)
View Source
const (
	MAGIC_NUMBER         = txscript.OP_13
	COMMIT_CONFIRMATIONS = 6
)
View Source
const SUBSIDY_HALVING_INTERVAL uint32 = 210_000

Variables

View Source
var (
	ErrSeparator   = errors.New("missing separator")
	ErrBlock       = func(err string) error { return fmt.Errorf("invalid Block height:%s", err) }
	ErrTransaction = func(err string) error { return fmt.Errorf("invalid Transaction index:%s", err) }
)
View Source
var (
	ErrCharacter = func(c rune) error {
		return fmt.Errorf("invalid character `%c`", c)
	}
	ErrDoubleSpacer   = errors.New("double spacer")
	ErrLeadingSpacer  = errors.New("leading spacer")
	ErrTrailingSpacer = errors.New("trailing spacer")
)
View Source
var ErrNone = errors.New("none")
View Source
var RESERVED = Uint128FromString("6402364363415443603228541259936211926")
View Source
var STEPS = []uint128.Uint128{
	Uint128FromString("0"),
	Uint128FromString("26"),
	Uint128FromString("702"),
	Uint128FromString("18278"),
	Uint128FromString("475254"),
	Uint128FromString("12356630"),
	Uint128FromString("321272406"),
	Uint128FromString("8353082582"),
	Uint128FromString("217180147158"),
	Uint128FromString("5646683826134"),
	Uint128FromString("146813779479510"),
	Uint128FromString("3817158266467286"),
	Uint128FromString("99246114928149462"),
	Uint128FromString("2580398988131886038"),
	Uint128FromString("67090373691429037014"),
	Uint128FromString("1744349715977154962390"),
	Uint128FromString("45353092615406029022166"),
	Uint128FromString("1179180408000556754576342"),
	Uint128FromString("30658690608014475618984918"),
	Uint128FromString("797125955808376366093607894"),
	Uint128FromString("20725274851017785518433805270"),
	Uint128FromString("538857146126462423479278937046"),
	Uint128FromString("14010285799288023010461252363222"),
	Uint128FromString("364267430781488598271992561443798"),
	Uint128FromString("9470953200318703555071806597538774"),
	Uint128FromString("246244783208286292431866971536008150"),
	Uint128FromString("6402364363415443603228541259936211926"),
	Uint128FromString("166461473448801533683942072758341510102"),
}

Functions

func Decode

func Decode(encoded []byte) *big.Int

func Encode

func Encode(n *big.Int) []byte

func EncodeChar

func EncodeChar(r rune) []byte

func EncodeUint128

func EncodeUint128(n uint128.Uint128) []byte

func EncodeUint32

func EncodeUint32(n uint32) []byte

func EncodeUint64

func EncodeUint64(n uint64) []byte

func EncodeUint8

func EncodeUint8(n uint8) []byte

func FirstRuneHeight

func FirstRuneHeight(network wire.BitcoinNet) uint32

func TagTake

func TagTake[T any](t Tag, fields map[Tag][]uint128.Uint128, with func([]uint128.Uint128) (*T, error), n ...int) (*T, error)

func Uint128FromString

func Uint128FromString(s string) uint128.Uint128

Types

type Artifact

type Artifact struct {
	Cenotaph  *Cenotaph
	Runestone *Runestone
}

func (*Artifact) Mint

func (a *Artifact) Mint() *RuneId

type Cenotaph

type Cenotaph struct {
	Etching *Rune
	Flaw    *Flaw
	Mint    *RuneId
}

type Edict

type Edict struct {
	ID     RuneId
	Amount uint128.Uint128
	Output uint32
}

func EdictFromIntegers

func EdictFromIntegers(tx *wire.MsgTx, id RuneId, amount uint128.Uint128, output uint128.Uint128) (*Edict, error)

type Error

type Error struct {
	Character rune
	Range     bool
}

func (Error) Error

func (e Error) Error() string

type Etching

type Etching struct {
	Divisibility *uint8
	Premine      *uint128.Uint128
	Rune         *Rune
	Spacers      *uint32
	Symbol       *rune
	Terms        *Terms
	Turbo        bool
}

func (*Etching) Supply

func (e *Etching) Supply() *uint128.Uint128

type Flag

type Flag uint8
const (
	FlagEtching  Flag = 0
	FlagTerms    Flag = 1
	FlagCenotaph Flag = 127
	FlagTurbo    Flag = 2
)

func (Flag) Mask

func (f Flag) Mask() uint128.Uint128

func (Flag) Set

func (f Flag) Set(flags *uint128.Uint128)

func (Flag) Take

func (f Flag) Take(flags *uint128.Uint128) bool

type Flaw

type Flaw int
const (
	EdictOutput Flaw = iota
	EdictRuneId
	InvalidScript
	Opcode
	SupplyOverflow
	TrailingIntegers
	TruncatedField
	UnrecognizedEvenTag
	UnrecognizedFlag
	Varint
)

func FlawP

func FlawP(f Flaw) *Flaw

func NewFlaw

func NewFlaw(s string) Flaw

func (Flaw) Error

func (f Flaw) Error() error

func (Flaw) String

func (f Flaw) String() string

type Message

type Message struct {
	Flaw   *Flaw
	Edicts []Edict
	Fields map[Tag][]uint128.Uint128
}

func MessageFromIntegers

func MessageFromIntegers(tx *wire.MsgTx, payload []uint128.Uint128) (*Message, error)

type Payload

type Payload struct {
	Valid   []byte
	Invalid Flaw
}

type Rune

type Rune struct {
	Value uint128.Uint128
}

func MinimumAtHeight

func MinimumAtHeight(chain wire.BitcoinNet, height uint64) Rune

func NewRune

func NewRune(value uint128.Uint128) Rune

func Reserved

func Reserved(block uint64, tx uint32) Rune

func RuneFromString

func RuneFromString(s string) (*Rune, error)

func (Rune) Commitment

func (r Rune) Commitment() []byte

func (Rune) IsReserved

func (r Rune) IsReserved() bool

func (Rune) MarshalJSON

func (r Rune) MarshalJSON() ([]byte, error)

MarshalJSON json marshal

func (Rune) N

func (r Rune) N() uint128.Uint128

func (Rune) String

func (r Rune) String() string

type RuneId

type RuneId struct {
	Block uint64
	Tx    uint32
}

func NewRuneId

func NewRuneId(block uint64, tx uint32) (*RuneId, error)

func RuneIdFromString

func RuneIdFromString(s string) (*RuneId, error)

func (RuneId) Cmp

func (r RuneId) Cmp(other RuneId) int

func (RuneId) Delta

func (r RuneId) Delta(next RuneId) (uint64, uint32, error)

func (RuneId) Next

func (r RuneId) Next(block uint128.Uint128, tx uint128.Uint128) (*RuneId, error)

func (RuneId) String

func (r RuneId) String() string

type Runestone

type Runestone struct {
	Edicts  []Edict
	Etching *Etching
	Mint    *RuneId
	Pointer *uint32
}

func (*Runestone) Decipher

func (r *Runestone) Decipher(transaction *wire.MsgTx) (*Artifact, error)

func (*Runestone) Encipher

func (r *Runestone) Encipher() ([]byte, error)

type SpacedRune

type SpacedRune struct {
	Rune    Rune
	Spacers uint32
}

func NewSpacedRune

func NewSpacedRune(r Rune, spacers uint32) *SpacedRune

func SpacedRuneFromString

func SpacedRuneFromString(s string) (*SpacedRune, error)

func (*SpacedRune) String

func (sr *SpacedRune) String() string

type Tag

type Tag uint8
const (
	TagBody         Tag = 0
	TagFlags        Tag = 2
	TagRune         Tag = 4
	TagPremine      Tag = 6
	TagCap          Tag = 8
	TagAmount       Tag = 10
	TagHeightStart  Tag = 12
	TagHeightEnd    Tag = 14
	TagOffsetStart  Tag = 16
	TagOffsetEnd    Tag = 18
	TagMint         Tag = 20
	TagPointer      Tag = 22
	TagCenotaph     Tag = 126
	TagDivisibility Tag = 1
	TagSpacers      Tag = 3
	TagSymbol       Tag = 5
	TagNop          Tag = 127
)

func NewTag

func NewTag(u uint128.Uint128) Tag

func (Tag) Byte

func (tag Tag) Byte() byte

func (Tag) Encode

func (t Tag) Encode(values []uint128.Uint128, payload *[]byte)

func (Tag) String

func (tag Tag) String() string

type Terms

type Terms struct {
	Amount *uint128.Uint128
	Cap    *uint128.Uint128
	Height [2]*uint64
	Offset [2]*uint64
}

Jump to

Keyboard shortcuts

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