Documentation
¶
Index ¶
Constants ¶
const EstimatedInputSizeForP2PKH = 148
EstimatedInputSizeForP2PKH is the estimated size increase when adding and unlocking P2PKH input to transaction. 32 bytes txID + 4 bytes vout index + 1 byte script length + 107 bytes script pub key + 4 bytes nSequence
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Address ¶
type Address struct { Address string `gorm:"type:char(34);primaryKey"` CreatedAt time.Time UpdatedAt time.Time DeletedAt gorm.DeletedAt `gorm:"index"` CustomInstructions datatypes.JSONSlice[CustomInstruction] UserID string User *User `gorm:"foreignKey:UserID"` }
Address represents a user's (bitcoin) addresses.
type CustomInstruction ¶
CustomInstruction represents a custom instruction how to unlock a UTXO.
type Operation ¶
type Operation struct { TxID string `gorm:"primaryKey"` UserID string `gorm:"primaryKey"` CreatedAt time.Time Counterparty string Type string Value int64 User *User `gorm:"foreignKey:UserID"` Transaction *TrackedTransaction `gorm:"foreignKey:TxID"` }
Operation represents a user's operation on a transaction.
type Paymail ¶
type Paymail struct { gorm.Model Alias string Domain string PublicName string AvatarURL string UserID string User *User `gorm:"foreignKey:UserID"` }
Paymail represents a paymail address
type TrackedOutput ¶
type TrackedOutput struct { TxID string `gorm:"primaryKey"` Vout uint32 `gorm:"primaryKey"` SpendingTX string `gorm:"type:char(64)"` UserID string Satoshis bsv.Satoshis CreatedAt time.Time UpdatedAt time.Time }
TrackedOutput represents an output of a transaction.
func (*TrackedOutput) IsSpent ¶
func (o *TrackedOutput) IsSpent() bool
IsSpent returns true if the output is spent.
func (*TrackedOutput) Outpoint ¶
func (o *TrackedOutput) Outpoint() *bsv.Outpoint
Outpoint returns bsv.Outpoint object which identifies the output.
type TrackedTransaction ¶
type TrackedTransaction struct { ID string `gorm:"type:char(64);primaryKey"` TxStatus TxStatus CreatedAt time.Time UpdatedAt time.Time Data []*Data `gorm:"foreignKey:TxID"` Inputs []*TrackedOutput `gorm:"foreignKey:SpendingTX"` Outputs []*TrackedOutput `gorm:"foreignKey:TxID"` // contains filtered or unexported fields }
TrackedTransaction represents a transaction in the database.
func (*TrackedTransaction) AddInputs ¶
func (t *TrackedTransaction) AddInputs(inputs ...*TrackedOutput)
AddInputs adds inputs to the transaction.
func (*TrackedTransaction) AfterCreate ¶
func (t *TrackedTransaction) AfterCreate(tx *gorm.DB) error
AfterCreate is a hook that is called after creating the transaction. It is responsible for adding new (User's) UTXOs and removing spent UTXOs.
func (*TrackedTransaction) CreateDataOutput ¶
func (t *TrackedTransaction) CreateDataOutput(data *Data, userID string)
CreateDataOutput prepares a new Data output and adds it to the transaction.
func (*TrackedTransaction) CreateP2PKHOutput ¶
func (t *TrackedTransaction) CreateP2PKHOutput(output *TrackedOutput, customInstructions datatypes.JSONSlice[CustomInstruction])
CreateP2PKHOutput prepares a new P2PKH output and adds it to the transaction.
type TxStatus ¶
type TxStatus string
TxStatus represents possible statuses of stored transaction model
type User ¶
type User struct { ID string `gorm:"type:char(34);primaryKey"` CreatedAt time.Time UpdatedAt time.Time PubKey string Paymails []*Paymail `gorm:"foreignKey:UserID"` Addresses []*Address `gorm:"foreignKey:UserID"` }
User represents a user in the database
func (*User) BeforeCreate ¶
BeforeCreate is a gorm hook that is called before creating a new user
type UserUTXO ¶
type UserUTXO struct { UserID string `gorm:"primaryKey;uniqueIndex:idx_window,sort:asc,priority:1"` TxID string `gorm:"primaryKey;uniqueIndex:idx_window,sort:asc,priority:4"` Vout uint32 `gorm:"primaryKey;uniqueIndex:idx_window,sort:asc,priority:5"` Satoshis uint64 // EstimatedInputSize is the estimated size increase when adding and unlocking this UTXO to a transaction. EstimatedInputSize uint64 Bucket string `gorm:"check:chk_not_data_bucket,bucket <> 'data'"` CreatedAt time.Time `gorm:"uniqueIndex:idx_window,sort:asc,priority:3"` // TouchedAt is the time when the UTXO was last touched (selected for preparing transaction outline) - used for prioritizing UTXO selection. TouchedAt time.Time `gorm:"uniqueIndex:idx_window,sort:asc,priority:2"` // CustomInstructions is the list of instructions for unlocking given UTXO (it should be understood by client). CustomInstructions datatypes.JSONSlice[CustomInstruction] }
UserUTXO is a table holding user's Unspent Transaction Outputs (UTXOs).
func NewP2PKHUserUTXO ¶
func NewP2PKHUserUTXO(output *TrackedOutput, customInstructions datatypes.JSONSlice[CustomInstruction]) *UserUTXO
NewP2PKHUserUTXO creates a new UserUTXO instance for a P2PKH output based on the given output and custom instructions.