db

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: LGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package db implements the APIs for interacting with our disk persisted key-value store.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

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

Database is the persistent datastore used by swapd.

func NewDatabase

func NewDatabase(cfg *chaindb.Config) (*Database, error)

NewDatabase returns a new *Database.

func (*Database) ClearAllOffers

func (db *Database) ClearAllOffers() error

ClearAllOffers clears all offers from the database.

func (*Database) Close

func (db *Database) Close() error

Close flushes and closes the database.

func (*Database) DeleteOffer

func (db *Database) DeleteOffer(id types.Hash) error

DeleteOffer deletes an offer from the database.

func (*Database) GetAllOffers

func (db *Database) GetAllOffers() ([]*types.Offer, error)

GetAllOffers returns all offers in the database.

func (*Database) GetAllSwaps

func (db *Database) GetAllSwaps() ([]*swap.Info, error)

GetAllSwaps returns all swaps in the database.

func (*Database) GetOffer

func (db *Database) GetOffer(id types.Hash) (*types.Offer, error)

GetOffer returns the given offer from the db, if it exists. Returns the error chaindb.ErrKeyNotFound if the entry does not exist.

func (*Database) GetSwap

func (db *Database) GetSwap(id types.Hash) (*swap.Info, error)

GetSwap returns a swap with the given ID, if it exists. Returns the error chaindb.ErrKeyNotFound if the entry does not exist.

func (*Database) HasSwap

func (db *Database) HasSwap(id types.Hash) (bool, error)

HasSwap returns whether the db contains a swap with the given ID.

func (*Database) PutOffer

func (db *Database) PutOffer(offer *types.Offer) error

PutOffer puts an offer in the database.

func (*Database) PutSwap

func (db *Database) PutSwap(s *swap.Info) error

PutSwap puts the given swap in the database. If a swap with the same ID is already in the database, it overwrites it.

func (*Database) RecoveryDB

func (db *Database) RecoveryDB() *RecoveryDB

RecoveryDB ...

type EthereumSwapInfo

type EthereumSwapInfo struct {
	// StartNumber the block number of the `newSwap` transaction. The same for
	// both maker/taker.
	StartNumber *big.Int `json:"startNumber" validate:"required"`

	// SwapID is the swap ID used by the swap contract; not the same as the
	// swap/offer ID used by swapd. It's the hash of the ABI encoded
	// `contracts.SwapCreatorSwap` struct.
	SwapID types.Hash `json:"swapID" validate:"required"`

	// Swap is the `Swap` structure inside SwapCreator.sol.
	Swap *contracts.SwapCreatorSwap `json:"swap" validate:"required"`

	// SwapCreatorAddr is the address of the contract on which the swap was created.
	SwapCreatorAddr ethcommon.Address `json:"swapCreatorAddr" validate:"required"`
}

EthereumSwapInfo represents information required on the Ethereum side in case of recovery

type RecoveryDB

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

RecoveryDB contains information about ongoing swaps required for recovery in case of shutdown.

func (*RecoveryDB) DeleteSwap

func (db *RecoveryDB) DeleteSwap(_ types.Hash) error

DeleteSwap deletes all recovery info from the db for the given swap. TODO: this is currently unimplemented

func (*RecoveryDB) GetContractSwapInfo

func (db *RecoveryDB) GetContractSwapInfo(id types.Hash) (*EthereumSwapInfo, error)

GetContractSwapInfo returns the contract swap ID (a hash of the `SwapCreatorSwap` structure) and and contract swap structure for the given swap ID.

func (*RecoveryDB) GetCounterpartySwapKeys

func (db *RecoveryDB) GetCounterpartySwapKeys(id types.Hash) (*mcrypto.PublicKey, *mcrypto.PrivateViewKey, error)

GetCounterpartySwapKeys is called during recovery to retrieve the counterparty's swap keys.

func (*RecoveryDB) GetCounterpartySwapPrivateKey

func (db *RecoveryDB) GetCounterpartySwapPrivateKey(id types.Hash) (*mcrypto.PrivateSpendKey, error)

GetCounterpartySwapPrivateKey returns the counterparty's swap private key, if it exists.

func (*RecoveryDB) GetNewSwapTxHash added in v0.3.0

func (db *RecoveryDB) GetNewSwapTxHash(id types.Hash) (types.Hash, error)

GetNewSwapTxHash returns the newSwap transaction hash for the given swap ID.

func (*RecoveryDB) GetSwapPrivateKey

func (db *RecoveryDB) GetSwapPrivateKey(id types.Hash) (*mcrypto.PrivateSpendKey, error)

GetSwapPrivateKey returns the swap private key share, if it exists.

func (*RecoveryDB) GetSwapRelayerInfo

func (db *RecoveryDB) GetSwapRelayerInfo(id types.Hash) (*types.OfferExtra, error)

GetSwapRelayerInfo ...

func (*RecoveryDB) PutContractSwapInfo

func (db *RecoveryDB) PutContractSwapInfo(id types.Hash, info *EthereumSwapInfo) error

PutContractSwapInfo stores the given contract swap ID (which is not the same as the daemon swap ID, but is instead a hash of the `SwapCreatorSwap` structure) and contract swap structure for the given swap ID.

func (*RecoveryDB) PutCounterpartySwapKeys

func (db *RecoveryDB) PutCounterpartySwapKeys(id types.Hash, sk *mcrypto.PublicKey, vk *mcrypto.PrivateViewKey) error

PutCounterpartySwapKeys is used to store the counterparty's swap keys.

func (*RecoveryDB) PutCounterpartySwapPrivateKey

func (db *RecoveryDB) PutCounterpartySwapPrivateKey(id types.Hash, kp *mcrypto.PrivateSpendKey) error

PutCounterpartySwapPrivateKey stores the counterparty's swap private key for the given swap ID.

func (*RecoveryDB) PutNewSwapTxHash added in v0.3.0

func (db *RecoveryDB) PutNewSwapTxHash(id types.Hash, txHash types.Hash) error

PutNewSwapTxHash stores the newSwap transaction hash for the given swap ID.

func (*RecoveryDB) PutSwapPrivateKey

func (db *RecoveryDB) PutSwapPrivateKey(id types.Hash, sk *mcrypto.PrivateSpendKey) error

PutSwapPrivateKey stores the given ephemeral swap private key share for the given swap ID.

func (*RecoveryDB) PutSwapRelayerInfo

func (db *RecoveryDB) PutSwapRelayerInfo(id types.Hash, info *types.OfferExtra) error

PutSwapRelayerInfo ...

Jump to

Keyboard shortcuts

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