lntypes

package
v0.18.4-beta.rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const HashSize = 32

HashSize of array used to store hashes.

View Source
const PreimageSize = 32

PreimageSize of array used to store preimagees.

Variables

This section is empty.

Functions

func Max

func Max[N Number](op1 N, op2 N) N

Max returns the greater of the two inputs.

func Min

func Min[N Number](op1 N, op2 N) N

Min returns the lesser of the two inputs.

Types

type ChannelParty

type ChannelParty uint8

ChannelParty is a type used to have an unambiguous description of which node is being referred to. This eliminates the need to describe as "local" or "remote" using bool.

const (
	// Local is a ChannelParty constructor that is used to refer to the
	// node that is running.
	Local ChannelParty = iota

	// Remote is a ChannelParty constructor that is used to refer to the
	// node on the other end of the peer connection.
	Remote
)

func (ChannelParty) CounterParty

func (p ChannelParty) CounterParty() ChannelParty

CounterParty inverts the role of the ChannelParty.

func (ChannelParty) IsLocal

func (p ChannelParty) IsLocal() bool

IsLocal returns true if the ChannelParty is Local.

func (ChannelParty) IsRemote

func (p ChannelParty) IsRemote() bool

IsRemote returns true if the ChannelParty is Remote.

func (ChannelParty) String

func (p ChannelParty) String() string

String provides a string representation of ChannelParty (useful for logging).

type Dual

type Dual[A any] struct {
	// Local is the value tracked for the Local ChannelParty.
	Local A

	// Remote is the value tracked for the Remote ChannelParty.
	Remote A
}

Dual represents a structure when we are tracking the same parameter for both the Local and Remote parties.

func MapDual

func MapDual[A, B any](d Dual[A], f func(A) B) Dual[B]

MapDual applies the function argument to both the Local and Remote fields of the Dual[A] and returns a Dual[B] with that function applied.

func (*Dual[A]) GetForParty

func (d *Dual[A]) GetForParty(p ChannelParty) A

GetForParty gives Dual an access method that takes a ChannelParty as an argument. It is included for ergonomics in cases where the ChannelParty is in a variable and which party determines how we want to access the Dual.

func (*Dual[A]) ModifyForParty

func (d *Dual[A]) ModifyForParty(p ChannelParty, f func(A) A) A

ModifyForParty applies the function argument to the given ChannelParty field and returns a new copy of the Dual.

func (*Dual[A]) SetForParty

func (d *Dual[A]) SetForParty(p ChannelParty, value A)

SetForParty sets the value in the Dual for the given ChannelParty. This returns a copy of the original value.

type Hash

type Hash [HashSize]byte

Hash is used in several of the lightning messages and common structures. It typically represents a payment hash.

var ZeroHash Hash

ZeroHash is a predefined hash containing all zeroes.

func MakeHash

func MakeHash(newHash []byte) (Hash, error)

MakeHash returns a new Hash from a byte slice. An error is returned if the number of bytes passed in is not HashSize.

func MakeHashFromStr

func MakeHashFromStr(newHash string) (Hash, error)

MakeHashFromStr creates a Hash from a hex hash string.

func (Hash) String

func (hash Hash) String() string

String returns the Hash as a hexadecimal string.

type Number

type Number interface {
	constraints.Integer | constraints.Float
}

Number defines a type constraint for numbers.

type Preimage

type Preimage [PreimageSize]byte

Preimage is used in several of the lightning messages and common structures. It represents a payment preimage.

func MakePreimage

func MakePreimage(newPreimage []byte) (Preimage, error)

MakePreimage returns a new Preimage from a bytes slice. An error is returned if the number of bytes passed in is not PreimageSize.

func MakePreimageFromStr

func MakePreimageFromStr(newPreimage string) (Preimage, error)

MakePreimageFromStr creates a Preimage from a hex preimage string.

func (*Preimage) Hash

func (p *Preimage) Hash() Hash

Hash returns the sha256 hash of the preimage.

func (*Preimage) Matches

func (p *Preimage) Matches(h Hash) bool

Matches returns whether this preimage is the preimage of the given hash.

func (Preimage) String

func (p Preimage) String() string

String returns the Preimage as a hexadecimal string.

type VByte

type VByte uint64

VByte defines a unit to express the transaction size. One virtual byte is 1/4th of a weight unit. The tx virtual bytes is calculated using `TxWeight / 4`.

func (VByte) String

func (vb VByte) String() string

String returns the string representation of the virtual byte.

func (VByte) ToWU

func (vb VByte) ToWU() WeightUnit

ToWU converts a value expressed in virtual bytes to weight units.

type WeightUnit

type WeightUnit uint64

WeightUnit defines a unit to express the transaction size. One weight unit is 1/4_000_000 of the max block size. The tx weight is calculated using `Base tx size * 3 + Total tx size`.

  • Base tx size is size of the transaction serialized without the witness data.
  • Total tx size is the transaction size in bytes serialized according #BIP144.

func (WeightUnit) String

func (wu WeightUnit) String() string

String returns the string representation of the weight unit.

func (WeightUnit) ToVB

func (wu WeightUnit) ToVB() VByte

ToVB converts a value expressed in weight units to virtual bytes.

Jump to

Keyboard shortcuts

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