common

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

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

Go to latest
Published: Dec 27, 2024 License: MIT Imports: 23 Imported by: 12

Documentation

Index

Constants

View Source
const (
	SEQUENCE_LOCKTIME_MASK         = 0x0000ffff
	SEQUENCE_LOCKTIME_TYPE_FLAG    = 1 << 22
	SEQUENCE_LOCKTIME_GRANULARITY  = 9
	SECONDS_MOD                    = 1 << SEQUENCE_LOCKTIME_GRANULARITY
	SECONDS_MAX                    = SEQUENCE_LOCKTIME_MASK << SEQUENCE_LOCKTIME_GRANULARITY
	SEQUENCE_LOCKTIME_DISABLE_FLAG = 1 << 31

	SECONDS_PER_BLOCK = 10 * 60 // 10 minutes

)
View Source
const MutinyNetBlockTime = time.Second * 30

Variables

View Source
var Bitcoin = Network{
	Name: "bitcoin",
	Addr: "ark",
}
View Source
var BitcoinRegTest = Network{
	Name: "regtest",
	Addr: BitcoinTestNet.Addr,
}
View Source
var BitcoinSigNet = Network{
	Name: "signet",
	Addr: BitcoinTestNet.Addr,
}
View Source
var BitcoinTestNet = Network{
	Name: "testnet",
	Addr: "tark",
}
View Source
var ConnectorTxSize = (&input.TxWeightEstimator{}).
	AddTaprootKeySpendInput(txscript.SigHashDefault).
	AddP2TROutput().
	AddP2TROutput().
	VSize()
View Source
var CovenantTreeTxSize = TreeTxSize * 2

liquid node size is 2x the bitcoin node size (avoid min-relay-fee issues with the low fee rate on liquid)

View Source
var (
	ErrWrongDescriptor = errors.New("wrong descriptor, cannot parse vtxo script")
)
View Source
var Liquid = Network{
	Name: "liquid",
	Addr: "ark",
}
View Source
var LiquidRegTest = Network{
	Name: "liquidregtest",
	Addr: LiquidTestNet.Addr,
}
View Source
var LiquidTestNet = Network{
	Name: "liquidtestnet",
	Addr: "tark",
}
View Source
var MutinyNetChallenge = []byte{
	0x51, 0x21, 0x02, 0xf7, 0x56, 0x1d, 0x20, 0x8d, 0xd9, 0xae, 0x99, 0xbf,
	0x49, 0x72, 0x73, 0xe1, 0x6f, 0x38, 0x9b, 0xdb, 0xd6, 0xc4, 0x74, 0x2d,
	0xdb, 0x8e, 0x6b, 0x21, 0x6e, 0x64, 0xfa, 0x29, 0x28, 0xad, 0x8f, 0x51,
	0xae,
}
View Source
var TreeTxSize = (&input.TxWeightEstimator{}).
	AddTaprootKeySpendInput(txscript.SigHashDefault).
	AddP2TROutput().
	AddP2TROutput().
	VSize()

Functions

func AppDataDir

func AppDataDir(appName string, roaming bool) string

AppDataDir returns an operating system specific directory to be used for storing application data for an application.

The appName parameter is the name of the application the data directory is being requested for. This function will prepend a period to the appName for POSIX style operating systems since that is standard practice. An empty appName or one with a single dot is treated as requesting the current directory so only "." will be returned. Further, the first character of appName will be made lowercase for POSIX style operating systems and uppercase for Mac and Windows since that is standard practice.

The roaming parameter only applies to Windows where it specifies the roaming application data profile (%APPDATA%) should be used instead of the local one (%LOCALAPPDATA%) that is used by default.

Example results:

dir := AppDataDir("myapp", false)
 POSIX (Linux/BSD): ~/.myapp
 Mac OS: $HOME/Library/Application Support/Myapp
 Windows: %LOCALAPPDATA%\Myapp
 Plan 9: $home/myapp

func BIP68Sequence

func BIP68Sequence(locktime RelativeLocktime) (uint32, error)

func ComputeForfeitTxFee

func ComputeForfeitTxFee(
	feeRate chainfee.SatPerKVByte,
	tapscript *waddrmgr.Tapscript,
	witnessSize int,
	serverScriptClass txscript.ScriptClass,
) (uint64, error)

func ComputeRedeemTxFee

func ComputeRedeemTxFee(
	feeRate chainfee.SatPerKVByte,
	vtxos []VtxoInput,
	numOutputs int,
) (int64, error)

func IsLiquid

func IsLiquid(network Network) bool

func P2TRScript

func P2TRScript(taprootKey *secp256k1.PublicKey) ([]byte, error)

func ValidateConnectors

func ValidateConnectors(roundTx string, connectors []string) error

Types

type AbsoluteLocktime

type AbsoluteLocktime uint32

AbsoluteLocktime represents an nLocktime value it is used as argument to a CheckLocktimeVerify opcode

func (AbsoluteLocktime) IsSeconds

func (l AbsoluteLocktime) IsSeconds() bool

type Address

type Address struct {
	HRP        string
	Server     *secp256k1.PublicKey
	VtxoTapKey *secp256k1.PublicKey
}

Address represents an Ark address with HRP, server public key, and VTXO Taproot public key

func DecodeAddress

func DecodeAddress(addr string) (*Address, error)

DecodeAddress parses a bech32m encoded address string and returns an Address object

func (*Address) Encode

func (a *Address) Encode() (string, error)

Encode converts the address to its bech32m string representation

type Network

type Network struct {
	Name string
	Addr string
}

type RelativeLocktime

type RelativeLocktime struct {
	Type  RelativeLocktimeType
	Value uint32
}

RelativeLocktime represents a BIP68 relative timelock value

func BIP68DecodeSequence

func BIP68DecodeSequence(sequence []byte) (*RelativeLocktime, error)

func (RelativeLocktime) Compare

func (l RelativeLocktime) Compare(other RelativeLocktime) int

func (RelativeLocktime) LessThan

func (l RelativeLocktime) LessThan(other RelativeLocktime) bool

LessThan returns true if this locktime is less than the other locktime

func (RelativeLocktime) Seconds

func (l RelativeLocktime) Seconds() int64

type RelativeLocktimeType

type RelativeLocktimeType uint

RelativeLocktimeType represents a BIP68 relative locktime it is passed as argument to CheckSequenceVerify opcode

const (
	LocktimeTypeSecond RelativeLocktimeType = iota
	LocktimeTypeBlock
)

type TaprootMerkleProof

type TaprootMerkleProof struct {
	ControlBlock []byte
	Script       []byte
}

func BiggestLeafMerkleProof

func BiggestLeafMerkleProof(t TaprootTree) (*TaprootMerkleProof, error)

BiggestLeafMerkleProof returns the leaf with the biggest witness size (for fee estimation) we need this to estimate the fee without knowning the exact leaf that will be spent

type TaprootTree

type TaprootTree interface {
	GetLeaves() []chainhash.Hash
	GetTaprootMerkleProof(leafhash chainhash.Hash) (*TaprootMerkleProof, error)
	GetRoot() chainhash.Hash
}

TaprootTree is an interface wrapping the methods needed to spend a vtxo taproot contract the implementation depends on the chain (liquid or bitcoin)

type VtxoInput

type VtxoInput struct {
	Outpoint    *wire.OutPoint
	Amount      int64
	Tapscript   *waddrmgr.Tapscript
	WitnessSize int
}

type VtxoScript

type VtxoScript[T TaprootTree, C interface{}] interface {
	Validate(server *secp256k1.PublicKey, minLocktime RelativeLocktime) error
	TapTree() (taprootKey *secp256k1.PublicKey, taprootScriptTree T, err error)
	Encode() ([]string, error)
	Decode(scripts []string) error
	SmallestExitDelay() (*RelativeLocktime, error)
	ForfeitClosures() []C
	ExitClosures() []C
}

A vtxo script is defined as a taproot contract with at least 1 forfeit closure (User && Server) and 1 exit closure (A after t). It may also contain others closures implementing specific use cases.

VtxoScript abstracts the taproot complexity behind vtxo contracts. it is compiled, transferred and parsed using descriptor string.

// TODO gather common and tree package to prevent circular dependency and move C generic

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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