transaction

package
v0.1.7-0...-7628261 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PaymentTxn uint16 = 0
	MintTxn    uint16 = 1
	SweepTxn   uint16 = 2
	TestingTxn uint16 = 3
)

Variables

View Source
var (
	NumWalletsInLedger = prometheus.NewGauge(prometheus.GaugeOpts{
		Name: "num_wallets_in_ledger",
		Help: "Number of wallets in the Ledger.",
	})
	NumUtxosInWallets = prometheus.NewGauge(prometheus.GaugeOpts{
		Name: "num_utxos_in_wallets",
		Help: "Net number of UTXOs in all wallets.",
	})
	TxnsOutputsTotalFinalized = prometheus.NewCounter(prometheus.CounterOpts{
		Name: "casanova_txns_outputs_finalized_total",
		Help: "Total output transactions finalized.",
	})
)

Functions

func Compare

func Compare(l, r CD) int

func UtxoLength

func UtxoLength() uint64

Types

type CD

type CD interface {
	Source() crypto.WalletAddress
	CheckNumber() uint16
	Uint64() uint64
	Length() uint16
	MarshalBinary() ([]byte, error)
	// contains filtered or unexported methods
}

func UnmarshalCD

func UnmarshalCD(data []byte) (CD, error)

NB(chuck): Kinda dumb, but we can't have an UnmarshalBinary([]byte) error interface function for a CD. That would require changing the CD interface from being an interface to {MintCD, PaymentCD, SweepCD} to being an interface to {*MintCD, *PaymentCD, *SweepCD} (since UnmarshalBinary must have a pointer receiver). This changes all the Consensus stuff because we could no longer readily store/lookup CDs in maps or check them for equality, due to the fact that we'd be comparing pointers instead of structs.

type ConcurrentFinalized

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

func (*ConcurrentFinalized) Add

func (cfin *ConcurrentFinalized) Add(txn Transaction)

func (*ConcurrentFinalized) Length

func (cfin *ConcurrentFinalized) Length() int

func (*ConcurrentFinalized) Range

func (cfin *ConcurrentFinalized) Range(f func(tid ids.TransactionId, txn Transaction) bool)

type ConcurrentTxnLog

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

func (*ConcurrentTxnLog) Add

func (ctl *ConcurrentTxnLog) Add(tids ...ids.TransactionId)

type IncrLedger

type IncrLedger struct {
	TxnLog_    *ConcurrentTxnLog
	Finalized_ *ConcurrentFinalized
	Parent_    Ledger
	Child_     Ledger

	Wg sync.WaitGroup
	// contains filtered or unexported fields
}

func NewIncrLedger

func NewIncrLedger(parent Ledger) *IncrLedger

func (*IncrLedger) AllInputsExist

func (ledger *IncrLedger) AllInputsExist(txn Transaction) bool

func (*IncrLedger) Balance

func (ledger *IncrLedger) Balance(walletAddr crypto.WalletAddress) uint64

func (*IncrLedger) CheckNumber

func (ledger *IncrLedger) CheckNumber(walletAddr crypto.WalletAddress) uint16

func (*IncrLedger) Child

func (ledger *IncrLedger) Child() Ledger

func (*IncrLedger) Compact

func (ledger *IncrLedger) Compact(compacted Ledger)

See the more comprehensive description of the Compact routine detailed for the SSLedger. In short, this function compacts the receiver, ledger, into the argument. The function is only defined for an argument of type SSLedger.

func (*IncrLedger) ExpectedCheckNumber

func (ledger *IncrLedger) ExpectedCheckNumber(walletAddr crypto.WalletAddress) uint16

func (*IncrLedger) HeaderLength

func (ledger *IncrLedger) HeaderLength() uint64

func (*IncrLedger) IsValid

func (ledger *IncrLedger) IsValid(txn Transaction) error

func (*IncrLedger) Length

func (ledger *IncrLedger) Length() uint64

func (*IncrLedger) MarshalBinary

func (ledger *IncrLedger) MarshalBinary() ([]byte, error)

func (*IncrLedger) Parent

func (ledger *IncrLedger) Parent() Ledger

func (*IncrLedger) ProcessQueued

func (ledger *IncrLedger) ProcessQueued() error

*IncrLedger.ProcessQueued attempts to process all transactions that failed to process initially with *IncrLedger.QueueFinalized. Some or all of the transactions in the list may just require that they be processed in a particular order (e.g. sequential checknumbers from the same wallet, or a transaction that spends a UTXO generated by another transaction in the list). It continues re-attempting processing of each transaction until no more can be processed. At that point it returns a composite error message for each of the failed transactions.

func (*IncrLedger) QueueFinalized

func (ledger *IncrLedger) QueueFinalized(txns ...Transaction)

*IncrLedger.QueueFinalized checks if the transactions in the provided list are valid, and if so attempts to process them. If an error is encountered in either of these processes, the transaction is queued to be re-attempted, as it may just need another finalized transaction to process first.

func (*IncrLedger) SetChild

func (ledger *IncrLedger) SetChild(child Ledger)

func (*IncrLedger) SetParent

func (ledger *IncrLedger) SetParent(parent Ledger)

func (*IncrLedger) TxnLog

func (ledger *IncrLedger) TxnLog() []ids.TransactionId

func (*IncrLedger) TxnLogLength

func (ledger *IncrLedger) TxnLogLength() uint64

func (*IncrLedger) UnmarshalBinary

func (ledger *IncrLedger) UnmarshalBinary(data []byte) error

func (*IncrLedger) UpdateTxnLog

func (ledger *IncrLedger) UpdateTxnLog(txns ...Transaction)

func (*IncrLedger) Utxos

func (ledger *IncrLedger) Utxos(walletAddr crypto.WalletAddress) []Utxo

func (*IncrLedger) Wait

func (ledger *IncrLedger) Wait()

func (*IncrLedger) WalletMapsLength

func (ledger *IncrLedger) WalletMapsLength() uint64

func (*IncrLedger) WalletState

func (ledger *IncrLedger) WalletState(wal crypto.WalletAddress) (*walletState, bool)

NB(chuck): Use this function for reading only. If the returned *ledgerMap was found in THIS ledger, it COULD be written to - but for safety the writeableWalletState(..) function should be used instead if that's the intent.

type Ledger

type Ledger interface {
	WalletState(crypto.WalletAddress) (*walletState, bool)
	Utxos(crypto.WalletAddress) []Utxo
	TxnLog() []ids.TransactionId
	Parent() Ledger
	Child() Ledger

	Balance(crypto.WalletAddress) uint64
	CheckNumber(crypto.WalletAddress) uint16
	ExpectedCheckNumber(crypto.WalletAddress) uint16
	IsValid(Transaction) error

	QueueFinalized(...Transaction)
	ProcessQueued() error
	Wait()
	SetParent(Ledger)
	SetChild(Ledger)

	Compact(Ledger)

	Length() uint64
	MarshalBinary() ([]byte, error)
	UnmarshalBinary([]byte) error
}

func UnmarshalLedger

func UnmarshalLedger(data []byte) (Ledger, error)

type LedgerType

type LedgerType uint8
const (
	SSLEDGER   LedgerType = 0
	INCRLEDGER LedgerType = 1
)

type Mint

type Mint struct {
	// TODO(leaf): Document the wire format.
	Src             crypto.WalletAddress
	CheckNumber_    uint16
	Output_         MintOutput
	Hash_           *TransactionHash
	Bytes           []byte
	Sig             crypto.Signature
	ConflictDomain_ *MintCD
	TxnId_          ids.TransactionId
}

func (Mint) CheckNumber

func (mint Mint) CheckNumber() uint16

func (*Mint) ConflictDomain

func (mint *Mint) ConflictDomain() CD

func (Mint) Data

func (mint Mint) Data() []byte

func (*Mint) HasValidOutput

func (mint *Mint) HasValidOutput() bool

func (*Mint) Hash

func (mint *Mint) Hash() TransactionHash

func (*Mint) Inputs

func (mint *Mint) Inputs() []Utxo

func (*Mint) IsSlashable

func (mint *Mint) IsSlashable() bool

A mint is slashable if it was never valid and never will be (unlike the check for if it's valid, which is a determination that might change with time)

func (Mint) IsValid

func (mint Mint) IsValid() bool

TODO(chuck): Stub

func (Mint) Length

func (mint Mint) Length() uint16

func (Mint) MarshalBinary

func (mint Mint) MarshalBinary() ([]byte, error)

func (Mint) MarshalSignedBinary

func (mint Mint) MarshalSignedBinary(wallet crypto.Wallet) ([]byte, error)

func (Mint) Output

func (mint Mint) Output(n int) (TransactionOutput, error)

func (*Mint) SetId

func (mint *Mint) SetId(tid ids.TransactionId)

func (Mint) Source

func (mint Mint) Source() crypto.WalletAddress

func (*Mint) TxnId

func (mint *Mint) TxnId() ids.TransactionId

func (Mint) Type

func (mint Mint) Type() uint16

func (*Mint) UnmarshalBinary

func (mint *Mint) UnmarshalBinary(data []byte) error

func (*Mint) UnmarshalSignedBinary

func (mint *Mint) UnmarshalSignedBinary(wallet crypto.Wallet, data []byte) error

func (Mint) Value

func (mint Mint) Value() Mint

type MintCD

type MintCD struct {
	fmt.Stringer
	Source_      crypto.WalletAddress
	CheckNumber_ uint16
	Numeric      uint64
}

func (MintCD) CheckNumber

func (mint MintCD) CheckNumber() uint16

func (MintCD) Length

func (mint MintCD) Length() uint16

func (MintCD) MarshalBinary

func (mint MintCD) MarshalBinary() ([]byte, error)

func (MintCD) Source

func (mint MintCD) Source() crypto.WalletAddress

func (MintCD) String

func (mint MintCD) String() string

func (MintCD) Uint64

func (mint MintCD) Uint64() uint64

type MintOutput

type MintOutput struct {
	Amount_ uint64
	Dest_   crypto.WalletAddress
}

func (MintOutput) Amount

func (out MintOutput) Amount() uint64

func (MintOutput) Dest

func (out MintOutput) Dest() crypto.WalletAddress

func (MintOutput) Length

func (pout MintOutput) Length() uint16

type Payment

type Payment struct {
	// NB(leaf): The wire format here is as follows:
	//    Source:			32 bytes
	//    CheckNumber:		 2 bytes
	//    NumOutputs:  		 2 bytes
	//    Outputs:          40 bytes/ea
	Src          crypto.WalletAddress
	CheckNumber_ uint16

	Inputs_  []Utxo
	Outputs_ []PaymentOutput

	Hash_           *TransactionHash
	Bytes           []byte
	Sig             crypto.Signature
	ConflictDomain_ *PaymentCD
	TxnId_          ids.TransactionId
}

func (Payment) CheckNumber

func (pmt Payment) CheckNumber() uint16

func (*Payment) ConflictDomain

func (pmt *Payment) ConflictDomain() CD

func (Payment) Data

func (pmt Payment) Data() []byte

func (*Payment) HasValidOutput

func (pmt *Payment) HasValidOutput() bool

func (*Payment) Hash

func (pmt *Payment) Hash() TransactionHash

func (*Payment) Inputs

func (pmt *Payment) Inputs() []Utxo

func (*Payment) IsSlashable

func (pmt *Payment) IsSlashable() bool

A payment is slashable if it was never valid and never will be (unlike the check for if it's valid, which is a determination that might change with time)

func (Payment) IsValid

func (pmt Payment) IsValid() bool

func (Payment) Length

func (pmt Payment) Length() uint16

func (Payment) MarshalBinary

func (pmt Payment) MarshalBinary() ([]byte, error)

func (Payment) MarshalSignedBinary

func (pmt Payment) MarshalSignedBinary(wallet crypto.Wallet) ([]byte, error)

func (Payment) Output

func (pmt Payment) Output(n int) (TransactionOutput, error)

func (*Payment) SetId

func (pmt *Payment) SetId(tid ids.TransactionId)

func (Payment) Source

func (pmt Payment) Source() crypto.WalletAddress

func (*Payment) TxnId

func (pmt *Payment) TxnId() ids.TransactionId

func (Payment) Type

func (pmt Payment) Type() uint16

func (*Payment) UnmarshalBinary

func (pmt *Payment) UnmarshalBinary(data []byte) error

func (*Payment) UnmarshalSignedBinary

func (pmt *Payment) UnmarshalSignedBinary(wallet crypto.Wallet, data []byte) error

func (Payment) Value

func (pmt Payment) Value() Payment

type PaymentCD

type PaymentCD struct {
	fmt.Stringer
	Source_      crypto.WalletAddress
	CheckNumber_ uint16
	Numeric      uint64
}

func (PaymentCD) CheckNumber

func (pmt PaymentCD) CheckNumber() uint16

func (PaymentCD) Length

func (pmt PaymentCD) Length() uint16

func (PaymentCD) MarshalBinary

func (pmt PaymentCD) MarshalBinary() ([]byte, error)

func (PaymentCD) Source

func (pmt PaymentCD) Source() crypto.WalletAddress

func (PaymentCD) String

func (pmt PaymentCD) String() string

func (PaymentCD) Uint64

func (pmt PaymentCD) Uint64() uint64

type PaymentOutput

type PaymentOutput struct {
	Amount_ uint64
	Dest_   crypto.WalletAddress
}

func (PaymentOutput) Amount

func (out PaymentOutput) Amount() uint64

func (PaymentOutput) Dest

func (out PaymentOutput) Dest() crypto.WalletAddress

func (PaymentOutput) Length

func (pout PaymentOutput) Length() uint16

type SSLedger

type SSLedger struct {
	TxnLog_     []ids.TransactionId
	SpentUtxos_ []Utxo
	Child_      Ledger
	Height_     uint64
	// contains filtered or unexported fields
}

func NewSSLedger

func NewSSLedger(height uint64) *SSLedger

func (*SSLedger) Balance

func (l *SSLedger) Balance(w crypto.WalletAddress) uint64

func (*SSLedger) CheckNumber

func (l *SSLedger) CheckNumber(w crypto.WalletAddress) uint16

func (*SSLedger) Child

func (l *SSLedger) Child() Ledger

func (*SSLedger) Compact

func (ssl *SSLedger) Compact(l Ledger)

NB(chuck): There is some overloading of terminology here (hence the switch statement) that makes this confusing. There are two compaction "processes", one which is the full compaction (i.e., go back to the last SSLedger and compact all ledgers since then into one new SSLedger), and individual ledger compaction (i.e. compact this one ledger - whatever its type - into one SSLedger). The general usage of Compact:

  • ssl.Compact(IncrLedger): Go back to the last SSLedger and compact forward into the provided empty ssl (full compaction).
  • ssl.Compact(SSLedger): Copy ssl into SSLedger.
  • incr.Compact(SSLedger): Copy incr into SSLedger.
  • incr.Compact(IncrLedger): undefined

Thus, generally Compact works as source.Compact(target) with the exception of ssl.Compact(IncrLedger), which traverses back to the last SSLedger and runs individual ledger.Compact(ssl) on each ledger to merge them into ssl.

func (*SSLedger) ExpectedCheckNumber

func (l *SSLedger) ExpectedCheckNumber(w crypto.WalletAddress) uint16

func (*SSLedger) HeaderLength

func (ledger *SSLedger) HeaderLength() uint64

func (*SSLedger) IsValid

func (ledger *SSLedger) IsValid(txn Transaction) error

func (*SSLedger) Length

func (ledger *SSLedger) Length() uint64

func (*SSLedger) MarshalBinary

func (ledger *SSLedger) MarshalBinary() ([]byte, error)

func (*SSLedger) Parent

func (l *SSLedger) Parent() Ledger

func (*SSLedger) ProcessQueued

func (ledger *SSLedger) ProcessQueued() error

func (*SSLedger) QueueFinalized

func (ledger *SSLedger) QueueFinalized(_ ...Transaction)

func (*SSLedger) SetChild

func (l *SSLedger) SetChild(child Ledger)

func (*SSLedger) SetParent

func (l *SSLedger) SetParent(_ Ledger)

func (*SSLedger) TxnLog

func (l *SSLedger) TxnLog() []ids.TransactionId

func (*SSLedger) TxnLogLength

func (ledger *SSLedger) TxnLogLength() uint64

func (*SSLedger) UnmarshalBinary

func (ledger *SSLedger) UnmarshalBinary(data []byte) error

func (*SSLedger) Utxos

func (l *SSLedger) Utxos(w crypto.WalletAddress) []Utxo

func (*SSLedger) Wait

func (ledger *SSLedger) Wait()

func (*SSLedger) WalletMapsLength

func (ledger *SSLedger) WalletMapsLength() uint64

func (*SSLedger) WalletState

func (l *SSLedger) WalletState(w crypto.WalletAddress) (*walletState, bool)

type Sweep

type Sweep struct {
	// NB(leaf): The wire format here is as follows:
	//    Source:			32 bytes
	//    CheckNumber:		 2 bytes
	//    NumInputs:  		 2 bytes
	//    Inputs:           34 bytes/ea
	//    Output:           40 bytes
	//    Signature:        64 bytes
	Src             crypto.WalletAddress
	CheckNumber_    uint16
	Inputs_         []Utxo
	Output_         SweepOutput
	Hash_           *TransactionHash
	Bytes           []byte
	Sig             crypto.Signature
	ConflictDomain_ *SweepCD
	TxnId_          ids.TransactionId
}

func (Sweep) CheckNumber

func (sweep Sweep) CheckNumber() uint16

func (*Sweep) ConflictDomain

func (sweep *Sweep) ConflictDomain() CD

func (Sweep) Data

func (sweep Sweep) Data() []byte

func (*Sweep) HasValidOutput

func (sweep *Sweep) HasValidOutput() bool

func (*Sweep) Hash

func (sweep *Sweep) Hash() TransactionHash

func (*Sweep) Inputs

func (sweep *Sweep) Inputs() []Utxo

func (*Sweep) IsSlashable

func (sweep *Sweep) IsSlashable() bool

A sweep is slashable if it was never valid and never will be (unlike the check for if it's valid, which is a determination that might change with time)

func (Sweep) IsValid

func (sweep Sweep) IsValid() bool

TODO(chuck): we probably want more robust checks to ensure that the sweep isn't zero-value. As-is this relies on there being no zero-valued UTXOs in the system to begin with.

func (Sweep) Length

func (sweep Sweep) Length() uint16

func (Sweep) MarshalBinary

func (sweep Sweep) MarshalBinary() ([]byte, error)

func (Sweep) MarshalSignedBinary

func (sweep Sweep) MarshalSignedBinary(wallet crypto.Wallet) ([]byte, error)

func (Sweep) Output

func (sweep Sweep) Output(n int) (TransactionOutput, error)

func (*Sweep) SetId

func (sweep *Sweep) SetId(tid ids.TransactionId)

func (Sweep) Source

func (sweep Sweep) Source() crypto.WalletAddress

func (*Sweep) TxnId

func (sweep *Sweep) TxnId() ids.TransactionId

func (Sweep) Type

func (sweep Sweep) Type() uint16

func (*Sweep) UnmarshalBinary

func (sweep *Sweep) UnmarshalBinary(data []byte) error

func (*Sweep) UnmarshalSignedBinary

func (sweep *Sweep) UnmarshalSignedBinary(wallet crypto.Wallet, data []byte) error

func (Sweep) Value

func (sweep Sweep) Value() Sweep

type SweepCD

type SweepCD struct {
	fmt.Stringer
	Source_      crypto.WalletAddress
	CheckNumber_ uint16
	Numeric      uint64
}

func (SweepCD) CheckNumber

func (s SweepCD) CheckNumber() uint16

func (SweepCD) Length

func (sweep SweepCD) Length() uint16

func (SweepCD) MarshalBinary

func (sweep SweepCD) MarshalBinary() ([]byte, error)

func (SweepCD) Source

func (s SweepCD) Source() crypto.WalletAddress

func (SweepCD) String

func (s SweepCD) String() string

func (SweepCD) Uint64

func (sweep SweepCD) Uint64() uint64

type SweepOutput

type SweepOutput struct {
	Amount_ uint64
	Dest_   crypto.WalletAddress
}

func (SweepOutput) Amount

func (out SweepOutput) Amount() uint64

func (SweepOutput) Dest

func (out SweepOutput) Dest() crypto.WalletAddress

func (SweepOutput) Length

func (pout SweepOutput) Length() uint16

type T

type T interface {
	// contains filtered or unexported methods
}

type Transaction

type Transaction interface {
	Type() uint16
	Length() uint16
	ConflictDomain() CD
	Data() []byte
	Source() crypto.WalletAddress
	Output(n int) (TransactionOutput, error)
	Hash() TransactionHash
	IsValid() bool
	IsSlashable() bool
	HasValidOutput() bool
	CheckNumber() uint16
	Inputs() []Utxo
	TxnId() ids.TransactionId
	SetId(ids.TransactionId)

	MarshalBinary() ([]byte, error)
	MarshalSignedBinary(crypto.Wallet) ([]byte, error)
	UnmarshalBinary([]byte) error
	UnmarshalSignedBinary(crypto.Wallet, []byte) error
}

func UnmarshalTxn

func UnmarshalTxn(data []byte) (Transaction, error)

type TransactionHash

type TransactionHash [crypto.HASH_SIZE]byte

func HashTransaction

func HashTransaction(t Transaction) TransactionHash

func (TransactionHash) Equal

func (TransactionHash) Greater

func (l TransactionHash) Greater(r TransactionHash) bool

func (TransactionHash) IsEmpty

func (th TransactionHash) IsEmpty() bool

func (TransactionHash) Lesser

func (l TransactionHash) Lesser(r TransactionHash) bool

func (TransactionHash) Short

func (h TransactionHash) Short() []byte

type TransactionOutput

type TransactionOutput interface {
	Amount() uint64
	Dest() crypto.WalletAddress
}

type Utxo

type Utxo struct {
	fmt.Stringer
	TxnId  ids.TransactionId
	Output uint16
	Amount uint64
}

func UnmarshalUtxo

func UnmarshalUtxo(data []byte) (Utxo, error)

func (Utxo) MarshalBinary

func (u Utxo) MarshalBinary() ([]byte, error)

func (Utxo) String

func (u Utxo) String() string

type WalletStates

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

func (*WalletStates) Add

func (ws *WalletStates) Add(wal crypto.WalletAddress, state *walletState) *walletState

func (*WalletStates) Get

func (ws *WalletStates) Get(wal crypto.WalletAddress) (*walletState, bool)

func (*WalletStates) Index

func (ws *WalletStates) Index(wal crypto.WalletAddress) uint64

func (*WalletStates) Length

func (ws *WalletStates) Length() int

type WalletStatesSequence

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

func (*WalletStatesSequence) Add

func (wss *WalletStatesSequence) Add(wal crypto.WalletAddress, state *walletState) *walletState

func (*WalletStatesSequence) Get

func (wss *WalletStatesSequence) Get(wal crypto.WalletAddress) (*walletState, bool)

func (*WalletStatesSequence) Length

func (wss *WalletStatesSequence) Length() int

Jump to

Keyboard shortcuts

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