dal

package
v0.0.0-...-7c6c014 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BitcoinTx

type BitcoinTx struct {
	// SrId is a ika sign request ID
	SrID      uint64          `json:"sr_id"`
	Status    BitcoinTxStatus `json:"status"`
	BtcTxID   []byte          `json:"btc_sr_id"`
	Timestamp int64           `json:"time"`
	Note      string          `json:"note"`
}

BitcoinTx represents a row in the `bitcoin_txs` table.

type BitcoinTxInfo

type BitcoinTxInfo struct {
	TxID    uint64          `json:"sr_id"`
	BtcTxID []byte          `json:"btc_sr_id"`
	Status  BitcoinTxStatus `json:"status"`
}

BitcoinTxInfo holds the relevant information for a Bitcoin transaction.

type BitcoinTxStatus

type BitcoinTxStatus byte

BitcoinTxStatus represents the different states of a bitcoin transaction.

const (
	Pending BitcoinTxStatus = iota
	Broadcasted
	Confirmed
)

Bitcoin transaction status constants

type DB

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

DB holds the database connection and provides methods for interacting with it.

func NewDB

func NewDB(dbPath string) (*DB, error)

NewDB creates a new DB instance

func (DB) Close

func (db DB) Close() error

Close closes the db connection

func (*DB) GetBitcoinTx

func (db *DB) GetBitcoinTx(signRequestID uint64, btcTxID []byte) (*BitcoinTx, error)

GetBitcoinTx retrieves a Bitcoin transaction by its primary key (sr_id and btc_sr_id).

func (*DB) GetBitcoinTxsToBroadcast

func (db *DB) GetBitcoinTxsToBroadcast() ([]IkaSignRequest, error)

GetBitcoinTxsToBroadcast retrieves IkaSignRequests that have been signed by IKA and are due to be broadcasted to bitcoin.

This function checks for the following conditions: - The IkaSignRequest must have a final signature (final_sig IS NOT NULL). - There must be no corresponding entry in the bitcoin_txs table, OR - There must be only one corresponding entry in the bitcoin_txs table with a status of "Pending".

The reason for checking these conditions is that we cannot have a Bitcoin transaction hash (btc_tx_id) before the first broadcast attempt.

func (*DB) GetBroadcastedBitcoinTxsInfo

func (db *DB) GetBroadcastedBitcoinTxsInfo() ([]BitcoinTxInfo, error)

GetBroadcastedBitcoinTxsInfo queries Bitcoin transactions that has been braodcasted but not confirmed. that do not have a "Confirmed" status.

func (DB) GetIkaSignRequestByID

func (db DB) GetIkaSignRequestByID(id uint64) (*IkaSignRequest, error)

GetIkaSignRequestByID retrives a signature request by its id

func (*DB) GetIkaSignRequestWithStatus

func (db *DB) GetIkaSignRequestWithStatus(id uint64) (*IkaSignRequest, IkaTxStatus, error)

GetIkaSignRequestWithStatus retrieves an IkaSignRequest with its associated IkaTx status.

func (*DB) GetIkaTx

func (db *DB) GetIkaTx(signRequestID uint64, ikaTxID string) (*IkaTx, error)

GetIkaTx retrieves an Ika transaction by its primary key (sr_id and ika_sr_id).

func (*DB) GetPendingIkaSignRequests

func (db *DB) GetPendingIkaSignRequests() ([]IkaSignRequest, error)

GetPendingIkaSignRequests retrieves IkaSignRequests that need to be signed.

func (*DB) InitDB

func (db *DB) InitDB() error

InitDB initializes the database and creates the tables.

func (*DB) InsertBtcTx

func (db *DB) InsertBtcTx(tx BitcoinTx) error

InsertBtcTx inserts a new Bitcoin transaction into the database.

func (*DB) InsertIkaSignRequest

func (db *DB) InsertIkaSignRequest(signReq IkaSignRequest) error

InsertIkaSignRequest inserts a new transaction into the database

func (*DB) InsertIkaTx

func (db *DB) InsertIkaTx(tx IkaTx) error

InsertIkaTx inserts a new Ika transaction into the database.

func (*DB) UpdateBitcoinTxToConfirmed

func (db *DB) UpdateBitcoinTxToConfirmed(id uint64, txID []byte) error

UpdateBitcoinTxToConfirmed updates the bitcoin transaction to `Confirmed`.

func (*DB) UpdateIkaSignRequestFinalSig

func (db *DB) UpdateIkaSignRequestFinalSig(id uint64, finalSig Signature) error

UpdateIkaSignRequestFinalSig updates the final signature of an IkaSignRequest in the database.

type IkaSignRequest

type IkaSignRequest struct {
	ID        uint64    `json:"id"`
	Payload   Payload   `json:"payload"`
	DWalletID string    `json:"dwallet_id"`
	UserSig   string    `json:"user_sig"`
	FinalSig  Signature `json:"final_sig"`
	Timestamp int64     `json:"time"`
}

IkaSignRequest represents a row in the `ika_sign_requests` table.

type IkaTx

type IkaTx struct {
	// SrId is a ika sign request ID
	SrID      uint64      `json:"sr_id"`
	Status    IkaTxStatus `json:"status"`
	IkaTxID   string      `json:"ika_sr_id"`
	Timestamp int64       `json:"time"`
	Note      string      `json:"note"`
}

IkaTx represents a row in the `ika_txs` table.

type IkaTxStatus

type IkaTxStatus byte

IkaTxStatus represents the different states of a native transaction.

const (
	Success IkaTxStatus = iota
	Failed
)

Ika transaction status constants

type Payload

type Payload = []byte

Payload is an alias for []byte, representing a single payload to be singed.

type Signature

type Signature = []byte

Signature is an alias for []byte, representing the final signature.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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