database

package
v0.0.0-...-b785d8f Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressAssociation

type AddressAssociation struct {
	// Chain is the name of the payment origin chain
	Chain Chain `db:"chain"`
	// BIP-44
	AddressIndex     uint32    `db:"address_index"`
	Address          string    `db:"address"`
	StellarPublicKey string    `db:"stellar_public_key"`
	CreatedAt        time.Time `db:"created_at"`
}

type Chain

type Chain string
const (
	ChainBitcoin  Chain = "bitcoin"
	ChainEthereum Chain = "ethereum"
)

func (*Chain) Scan

func (s *Chain) Scan(src interface{}) error

Scan implements database/sql.Scanner interface

type Database

type Database interface {
	// CreateAddressAssociation creates Bitcoin/Ethereum-Stellar association. `addressIndex`
	// is the chain (Bitcoin/Ethereum) address derivation index (BIP-32).
	CreateAddressAssociation(chain Chain, stellarAddress, address string, addressIndex uint32) error
	// GetAssociationByChainAddress searches for previously saved Bitcoin/Ethereum-Stellar association.
	// Should return nil if not found.
	GetAssociationByChainAddress(chain Chain, address string) (*AddressAssociation, error)
	// GetAssociationByStellarPublicKey searches for previously saved Bitcoin/Ethereum-Stellar association.
	// Should return nil if not found.
	GetAssociationByStellarPublicKey(stellarPublicKey string) (*AddressAssociation, error)
	// AddProcessedTransaction adds a transaction to database as processed. This
	// should return `true` and no error if transaction processing has already started/finished.
	AddProcessedTransaction(chain Chain, transactionID, receivingAddress string) (alreadyProcessing bool, err error)
	// IncrementAddressIndex returns the current value of index used for `chain` key
	// derivation and then increments it. This operation must be atomic so this function
	// should never return the same value more than once.
	IncrementAddressIndex(chain Chain) (uint32, error)

	// ResetBlockCounters changes last processed bitcoin and ethereum block to default value.
	// Used in stress tests.
	ResetBlockCounters() error

	// AddRecoveryTransaction inserts recovery account ID and transaction envelope
	AddRecoveryTransaction(sourceAccount string, txEnvelope string) error
}

type MockDatabase

type MockDatabase struct {
	mock.Mock
}

MockDatabase is a mockable database.

func (*MockDatabase) AddProcessedTransaction

func (m *MockDatabase) AddProcessedTransaction(chain Chain, transactionID, receivingAddress string) (alreadyProcessing bool, err error)

func (*MockDatabase) AddRecoveryTransaction

func (m *MockDatabase) AddRecoveryTransaction(sourceAccount string, txEnvelope string) error

func (*MockDatabase) CreateAddressAssociation

func (m *MockDatabase) CreateAddressAssociation(chain Chain, stellarAddress, address string, addressIndex uint32) error

func (*MockDatabase) GetAssociationByChainAddress

func (m *MockDatabase) GetAssociationByChainAddress(chain Chain, address string) (*AddressAssociation, error)

func (*MockDatabase) GetAssociationByStellarPublicKey

func (m *MockDatabase) GetAssociationByStellarPublicKey(stellarPublicKey string) (*AddressAssociation, error)

func (*MockDatabase) IncrementAddressIndex

func (m *MockDatabase) IncrementAddressIndex(chain Chain) (uint32, error)

func (*MockDatabase) ResetBlockCounters

func (m *MockDatabase) ResetBlockCounters() error

type PostgresDatabase

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

func (*PostgresDatabase) AddEvent

func (d *PostgresDatabase) AddEvent(event sse.Event) error

AddEvent adds a new server-sent event to the storage.

func (*PostgresDatabase) AddProcessedTransaction

func (d *PostgresDatabase) AddProcessedTransaction(chain Chain, transactionID, receivingAddress string) (bool, error)

func (*PostgresDatabase) AddRecoveryTransaction

func (d *PostgresDatabase) AddRecoveryTransaction(sourceAccount string, txEnvelope string) error

func (*PostgresDatabase) CreateAddressAssociation

func (d *PostgresDatabase) CreateAddressAssociation(chain Chain, stellarAddress, address string, addressIndex uint32) error

func (*PostgresDatabase) GetAssociationByChainAddress

func (d *PostgresDatabase) GetAssociationByChainAddress(chain Chain, address string) (*AddressAssociation, error)

func (*PostgresDatabase) GetAssociationByStellarPublicKey

func (d *PostgresDatabase) GetAssociationByStellarPublicKey(stellarPublicKey string) (*AddressAssociation, error)

func (*PostgresDatabase) GetBitcoinBlockToProcess

func (d *PostgresDatabase) GetBitcoinBlockToProcess() (uint64, error)

func (*PostgresDatabase) GetEthereumBlockToProcess

func (d *PostgresDatabase) GetEthereumBlockToProcess() (uint64, error)

func (*PostgresDatabase) GetEventsSinceID

func (d *PostgresDatabase) GetEventsSinceID(id int64) (int64, []sse.Event, error)

GetEventsSinceID returns all events since `id`. Used to load and publish all broadcasted events. It returns the last event ID, list of events or error. If `id` is equal `-1`:

  • it should return the last event ID and empty list if at least one event has been broadcasted.
  • it should return `0` if no events have been broadcasted.

func (*PostgresDatabase) IncrementAddressIndex

func (d *PostgresDatabase) IncrementAddressIndex(chain Chain) (uint32, error)

func (*PostgresDatabase) Open

func (d *PostgresDatabase) Open(dsn string) error

func (*PostgresDatabase) QueueAdd

func (d *PostgresDatabase) QueueAdd(tx queue.Transaction) error

QueueAdd implements queue.Queue interface. If element already exists in a queue, it should return nil.

func (*PostgresDatabase) QueuePool

func (d *PostgresDatabase) QueuePool() (*queue.Transaction, error)

QueuePool receives and removes the head of this queue. Returns nil if no elements found. QueuePool implements queue.Queue interface.

func (*PostgresDatabase) ResetBlockCounters

func (d *PostgresDatabase) ResetBlockCounters() error

func (*PostgresDatabase) SaveLastProcessedBitcoinBlock

func (d *PostgresDatabase) SaveLastProcessedBitcoinBlock(block uint64) error

func (*PostgresDatabase) SaveLastProcessedEthereumBlock

func (d *PostgresDatabase) SaveLastProcessedEthereumBlock(block uint64) error

Jump to

Keyboard shortcuts

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