db

package
v0.0.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	gorm.Model
	WalletName   string
	AccountIndex uint   // indicates the wallet account this is a part of
	AddressIndex uint   // indicates the subaddress index
	BaseAddress  string // indicates the base wallet account address
	Address      string `gorm:"unique"` // this is the wallet account subaddress
	Balance      uint
	Scheduled    uint // indicates if it is scheduled, 0 = false, 1 = true
	Spent        uint // indicates if it has been spent, 0 = false, 1 = true
}

Address specifies an address, its balance and the wallet it came from

type Client

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

Client provides a wrapper around the gorm client connecting to a sqlite3 database

func NewClient

func NewClient(l *zap.Logger, dbPath string) (*Client, error)

NewClient returns a new database clients

func (*Client) AddAddress

func (c *Client) AddAddress(walletName, address, baseAddress string, accountIndex, addressIndex, balance uint64) error

AddAddress is used to store an address into the database, if a previous record with this address exists it will be overwritten

func (*Client) AddTransaction

func (c *Client) AddTransaction(sourceAddress, txMetadata, metaDataHash string, sendTime time.Time) error

AddTransaction is used to store a transaction that we need to relay

func (*Client) Close

func (c *Client) Close() error

Close is used to shutdown the database

func (*Client) DeleteTransaction

func (c *Client) DeleteTransaction(sourceAddress, txHash, metaDataHash string) error

DeleteTransaction is used to remove transaction data from our database we do this once the transaction has been confirmed and to purge evidence of the churn

func (*Client) Destroy

func (c *Client) Destroy() error

Destroy is used to tear down tbales if they exist

func (*Client) GetAddress

func (c *Client) GetAddress(address string) (*Address, error)

GetAddress returns the given address if it exists

func (*Client) GetAddresses

func (c *Client) GetAddresses() ([]Address, error)

GetAddresses returns all known addresses

func (*Client) GetRelayedTransactions

func (c *Client) GetRelayedTransactions() ([]Transfer, error)

GetRelayedTransactions returns all currently relayed transactions

func (*Client) GetSendableTransactions

func (c *Client) GetSendableTransactions() ([]Transfer, error)

GetSendableTransactions returns all transactions we can relay

func (*Client) GetTransaction

func (c *Client) GetTransaction(sourceAddress, metaDataHash string) (*Transfer, error)

GetTransaction returns the first matching transaction

func (*Client) GetTransactions

func (c *Client) GetTransactions() ([]Transfer, error)

GetTransactions returns all known transactions

func (*Client) GetUnrelayedTransactions

func (c *Client) GetUnrelayedTransactions() ([]Transfer, error)

GetUnrelayedTransactions returns transactinos which have been scheduled but not yet relayed

func (*Client) GetUnscheduledAddresses

func (c *Client) GetUnscheduledAddresses() ([]Address, error)

GetUnscheduledAddresses returns all unscheduled addresses

func (*Client) ScheduleTransaction

func (c *Client) ScheduleTransaction(sourceAddress, txMetadata, metadataHash string, sendTime time.Time) error

ScheduleTransaction is used to persist transaction metadata information to disk, marking the associated address as being scheduled. This means anytime during startup, we can reschedule transactions in case the program exists with pending transactions

func (*Client) SetScheduled

func (c *Client) SetScheduled(address string, scheduled uint) error

SetScheduled marks an address as having a scheduled transaction

func (*Client) SetTxHash

func (c *Client) SetTxHash(sourceAddress, metaDataHash, txHash string) error

SetTxHash sets the transaction hash for the corresponding churn

func (*Client) SetTxSpent

func (c *Client) SetTxSpent(sourceAddress, metaDataHash string, spent uint) error

SetTxSpent sets the spent field on a transfer entry

func (*Client) Setup

func (c *Client) Setup() error

Setup is used to create the existing tables

type Transfer

type Transfer struct {
	gorm.Model
	SourceAddress  string    // the sending address
	TxMetadata     string    // the transaction metadata we use to relay
	TxMetadataHash string    // sha256 hash of TxMetadata
	TxHash         string    // the hash of the transaction once relayed
	SendTime       time.Time // the time at which we will relay the transaction
	Spent          uint      // indicates if the tx is spent (ie broadcasted), 0 = false 1 = true
}

Transfer is a single transfer to churn an address

Jump to

Keyboard shortcuts

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