storage

package
v0.0.0-...-71c933f Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KEYSETS_BUCKET        = "keysets"
	PROOFS_BUCKET         = "proofs"
	PENDING_PROOFS_BUCKET = "pending_proofs"
	MINT_QUOTES_BUCKET    = "mint_quotes"
	MELT_QUOTES_BUCKET    = "melt_quotes"
	INVOICES_BUCKET       = "invoices"
	SEED_BUCKET           = "seed"
	MNEMONIC_KEY          = "mnemonic"
)

Variables

View Source
var (
	ProofNotFound         = errors.New("proof not found")
	KeysetMintURLNotFound = errors.New("keyset with mint url not found")
)

Functions

This section is empty.

Types

type BoltDB

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

func InitBolt

func InitBolt(path string) (*BoltDB, error)

func (*BoltDB) AddPendingProofs

func (db *BoltDB) AddPendingProofs(proofs cashu.Proofs) error

func (*BoltDB) AddPendingProofsByQuoteId

func (db *BoltDB) AddPendingProofsByQuoteId(proofs cashu.Proofs, quoteId string) error

func (*BoltDB) Close

func (db *BoltDB) Close() error

func (*BoltDB) DeletePendingProofs

func (db *BoltDB) DeletePendingProofs(Ys []string) error

func (*BoltDB) DeletePendingProofsByQuoteId

func (db *BoltDB) DeletePendingProofsByQuoteId(quoteId string) error

func (*BoltDB) DeleteProof

func (db *BoltDB) DeleteProof(secret string) error

func (*BoltDB) GetInvoice

func (db *BoltDB) GetInvoice(paymentHash string) *Invoice

func (*BoltDB) GetInvoiceByQuoteId

func (db *BoltDB) GetInvoiceByQuoteId(quoteId string) *Invoice

func (*BoltDB) GetInvoices

func (db *BoltDB) GetInvoices() []Invoice

func (*BoltDB) GetKeyset

func (db *BoltDB) GetKeyset(keysetId string) *crypto.WalletKeyset

func (*BoltDB) GetKeysetCounter

func (db *BoltDB) GetKeysetCounter(keysetId string) uint32

func (*BoltDB) GetKeysets

func (db *BoltDB) GetKeysets() crypto.KeysetsMap

func (*BoltDB) GetMeltQuoteById

func (db *BoltDB) GetMeltQuoteById(id string) *MeltQuote

func (*BoltDB) GetMeltQuotes

func (db *BoltDB) GetMeltQuotes() []MeltQuote

func (*BoltDB) GetMintQuoteById

func (db *BoltDB) GetMintQuoteById(id string) *MintQuote

func (*BoltDB) GetMintQuotes

func (db *BoltDB) GetMintQuotes() []MintQuote

func (*BoltDB) GetMnemonic

func (db *BoltDB) GetMnemonic() string

func (*BoltDB) GetPendingProofs

func (db *BoltDB) GetPendingProofs() []DBProof

func (*BoltDB) GetPendingProofsByQuoteId

func (db *BoltDB) GetPendingProofsByQuoteId(quoteId string) []DBProof

func (*BoltDB) GetProofs

func (db *BoltDB) GetProofs() cashu.Proofs

return all proofs from db

func (*BoltDB) GetProofsByKeysetId

func (db *BoltDB) GetProofsByKeysetId(id string) cashu.Proofs

func (*BoltDB) GetSeed

func (db *BoltDB) GetSeed() []byte

func (*BoltDB) IncrementKeysetCounter

func (db *BoltDB) IncrementKeysetCounter(keysetId string, num uint32) error

func (*BoltDB) MigrateInvoicesToQuotes

func (db *BoltDB) MigrateInvoicesToQuotes() error

func (*BoltDB) SaveInvoice

func (db *BoltDB) SaveInvoice(invoice Invoice) error

func (*BoltDB) SaveKeyset

func (db *BoltDB) SaveKeyset(keyset *crypto.WalletKeyset) error

NOTE: Keysets are stored in nested buckets by mint URL. I.e a keyset with mint URL http://mint.com will create a bucket inside the KEYSETS_BUCKET named by the mint URL and inside this bucket, save the keysets by keyset id

func (*BoltDB) SaveMeltQuote

func (db *BoltDB) SaveMeltQuote(quote MeltQuote) error

func (*BoltDB) SaveMintQuote

func (db *BoltDB) SaveMintQuote(quote MintQuote) error

func (*BoltDB) SaveMnemonicSeed

func (db *BoltDB) SaveMnemonicSeed(mnemonic string, seed []byte)

func (*BoltDB) SaveProofs

func (db *BoltDB) SaveProofs(proofs cashu.Proofs) error

func (*BoltDB) UpdateKeysetMintURL

func (db *BoltDB) UpdateKeysetMintURL(oldURL, newURL string) error

UpdateKeysetMintURL creates a new bucket named with newURL. It will then iterate over all the keysets that were stored in the oldURL bucket and copy them over to the new bucket with newURL. It also needs to change the MintURL field for each keyset.

type DBProof

type DBProof struct {
	Y      string           `json:"y"`
	Amount uint64           `json:"amount"`
	Id     string           `json:"id"`
	Secret string           `json:"secret"`
	C      string           `json:"C"`
	DLEQ   *cashu.DLEQProof `json:"dleq,omitempty"`
	// set if pending proofs are tied to a melt quote
	MeltQuoteId string `json:"quote_id"`
}

type Invoice

type Invoice struct {
	TransactionType QuoteType
	// mint or melt quote id
	Id string
	// mint that issued quote
	Mint           string
	QuoteAmount    uint64
	InvoiceAmount  uint64
	PaymentRequest string
	PaymentHash    string
	Preimage       string
	CreatedAt      int64
	Paid           bool
	SettledAt      int64
	QuoteExpiry    uint64
}

type MeltQuote

type MeltQuote struct {
	QuoteId        string
	Mint           string
	Method         string
	State          nut05.State
	Unit           string
	PaymentRequest string
	Amount         uint64
	FeeReserve     uint64
	Preimage       string
	CreatedAt      int64
	SettledAt      int64
	QuoteExpiry    uint64
}

type MintQuote

type MintQuote struct {
	QuoteId        string
	Mint           string
	Method         string
	State          nut04.State
	Unit           string
	PaymentRequest string
	Amount         uint64
	CreatedAt      int64
	SettledAt      int64
	QuoteExpiry    uint64
	PrivateKey     *secp256k1.PrivateKey
}

func (*MintQuote) MarshalJSON

func (mq *MintQuote) MarshalJSON() ([]byte, error)

func (*MintQuote) UnmarshalJSON

func (mq *MintQuote) UnmarshalJSON(data []byte) error

type QuoteType

type QuoteType int
const (
	Mint QuoteType = iota + 1
	Melt
)

func (QuoteType) String

func (quote QuoteType) String() string

type WalletDB

type WalletDB interface {
	SaveMnemonicSeed(string, []byte)
	GetSeed() []byte
	GetMnemonic() string

	SaveProofs(cashu.Proofs) error
	GetProofs() cashu.Proofs
	GetProofsByKeysetId(string) cashu.Proofs
	DeleteProof(string) error

	AddPendingProofs(cashu.Proofs) error
	AddPendingProofsByQuoteId(cashu.Proofs, string) error
	GetPendingProofs() []DBProof
	GetPendingProofsByQuoteId(string) []DBProof
	DeletePendingProofs([]string) error
	DeletePendingProofsByQuoteId(string) error

	SaveKeyset(*crypto.WalletKeyset) error
	GetKeysets() crypto.KeysetsMap
	GetKeyset(string) *crypto.WalletKeyset
	IncrementKeysetCounter(string, uint32) error
	GetKeysetCounter(string) uint32
	UpdateKeysetMintURL(oldURL, newURL string) error

	SaveMintQuote(MintQuote) error
	GetMintQuotes() []MintQuote
	GetMintQuoteById(string) *MintQuote

	SaveMeltQuote(MeltQuote) error
	GetMeltQuotes() []MeltQuote
	GetMeltQuoteById(string) *MeltQuote

	Close() error
}

Jump to

Keyboard shortcuts

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