backend

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2019 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrIncorrectGenesisBlock means electrum is set-up to for wrong currency
	ErrIncorrectGenesisBlock = errors.New("Incorrect genesis block")
	// ErrIncompatibleVersion means electrum server version is not compatible with electrum client lib
	ErrIncompatibleVersion = errors.New("Incompatible version")
	// ErrFailedNegotiateVersion means electrum server doesn't support version(s) used by the electrum client lib
	ErrFailedNegotiateVersion = errors.New("Failed negotiate version")
)

Functions

This section is empty.

Types

type AddrResponse

type AddrResponse struct {
	Address  *deriver.Address
	TxHashes []string
}

AddrResponse lists transaction hashes for a given address

func (*AddrResponse) HasTransactions

func (r *AddrResponse) HasTransactions() bool

HasTransactions returns true if the Response contains any transactions

type Backend

type Backend interface {
	ChainHeight() uint32

	AddrRequest(addr *deriver.Address)
	AddrResponses() <-chan *AddrResponse
	TxRequest(txHash string)
	TxResponses() <-chan *TxResponse
	BlockRequest(height uint32)
	BlockResponses() <-chan *BlockResponse

	Finish()
}

Backend is an interface which abstracts different types of backends.

The Backends are responsible for fetching all the transactions related to an address. For each transaction, the Backend must grab: - the height - the raw transaction bytes

In addition, the backend must know the chain height. The backend is allowed to fetch this value once (at startup) and cache it.

In general, we tried to keep the backends minimal and move as much (common) logic as possible into the accounter.

There are a few differences between Electrum and Btcd (and potentially any other Backend we decide to add in the future). For instance, Electrum returns the block height when fetching all the transactions for a given address, but Btcd doesn't. On the other hand, Btcd returns the raw transaction information right away but Electrum requires additional requests.

Because of these differences, the Backend exposes a Finish() method. This method allows the Accounter to wait until the Backend is done with any additional requests. In theory, we could forgo the Finish() method and have the Accounter read from the TxResponses channel until it has all the data it needs. This would require the Accounter to maintain its own set of transactions.

type BlockResponse

type BlockResponse struct {
	Height    uint32
	Timestamp time.Time
}

type BtcdBackend

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

BtcdBackend wraps Btcd node and its API to provide a simple balance and transaction history information for a given address. BtcdBackend implements Backend interface.

func NewBtcdBackend

func NewBtcdBackend(host, port, user, pass string, network Network) (*BtcdBackend, error)

NewBtcdBackend returns a new BtcdBackend structs or errors.

BtcdBackend is meants to connect to a personal Btcd node (because public nodes don't expose the API we need). There's no TLS support. If your node is not co-located with Beancounter, we recommend wrapping your connection in a ssh or other secure tunnel.

func (*BtcdBackend) AddrRequest

func (b *BtcdBackend) AddrRequest(addr *deriver.Address)

AddrRequest schedules a request to the backend to lookup information related to the given address.

func (*BtcdBackend) AddrResponses

func (b *BtcdBackend) AddrResponses() <-chan *AddrResponse

AddrResponses exposes a channel that allows to consume backend's responses to address requests created with AddrRequest()

func (*BtcdBackend) BlockRequest

func (b *BtcdBackend) BlockRequest(height uint32)

func (*BtcdBackend) BlockResponses

func (b *BtcdBackend) BlockResponses() <-chan *BlockResponse

func (*BtcdBackend) ChainHeight

func (b *BtcdBackend) ChainHeight() uint32

func (*BtcdBackend) Finish

func (b *BtcdBackend) Finish()

Finish informs the backend to stop doing its work.

func (*BtcdBackend) TxRequest

func (b *BtcdBackend) TxRequest(txHash string)

TxRequest schedules a request to the backend to lookup information related to the given transaction hash.

func (*BtcdBackend) TxResponses

func (b *BtcdBackend) TxResponses() <-chan *TxResponse

TxResponses exposes a channel that allows to consume backend's responses to address requests created with addrrequest(). if an address has any transactions then they will be sent to this channel by the backend.

type ElectrumBackend

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

ElectrumBackend wraps Electrum node and its API to provide a simple balance and transaction history information for a given address. ElectrumBackend implements Backend interface.

func NewElectrumBackend

func NewElectrumBackend(addr, port string, network Network) (*ElectrumBackend, error)

NewElectrumBackend returns a new ElectrumBackend structs or errors. Initially connects to 1 node. A background job handles connecting to additional peers. The background job fails if there are no peers left.

func (*ElectrumBackend) AddrRequest

func (eb *ElectrumBackend) AddrRequest(addr *deriver.Address)

AddrRequest schedules a request to the backend to lookup information related to the given address.

func (*ElectrumBackend) AddrResponses

func (eb *ElectrumBackend) AddrResponses() <-chan *AddrResponse

AddrResponses exposes a channel that allows to consume backend's responses to address requests created with AddrRequest()

func (*ElectrumBackend) BlockRequest

func (eb *ElectrumBackend) BlockRequest(height uint32)

func (*ElectrumBackend) BlockResponses

func (eb *ElectrumBackend) BlockResponses() <-chan *BlockResponse

func (*ElectrumBackend) ChainHeight

func (eb *ElectrumBackend) ChainHeight() uint32

func (*ElectrumBackend) Finish

func (eb *ElectrumBackend) Finish()

Finish informs the backend to stop doing its work.

func (*ElectrumBackend) TxRequest

func (eb *ElectrumBackend) TxRequest(txHash string)

TxRequest schedules a request to the backend to lookup information related to the given transaction hash.

func (*ElectrumBackend) TxResponses

func (eb *ElectrumBackend) TxResponses() <-chan *TxResponse

TxResponses exposes a channel that allows to consume backend's responses to address requests created with AddrRequest(). If an address has any transactions then they will be sent to this channel by the backend.

type FixtureBackend

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

FixtureBackend loads data from a file that was previously recorded by RecorderBackend

func NewFixtureBackend

func NewFixtureBackend(filepath string) (*FixtureBackend, error)

NewFixtureBackend returns a new FixtureBackend structs or errors.

func (*FixtureBackend) AddrRequest

func (fb *FixtureBackend) AddrRequest(addr *deriver.Address)

AddrRequest schedules a request to the backend to lookup information related to the given address.

func (*FixtureBackend) AddrResponses

func (fb *FixtureBackend) AddrResponses() <-chan *AddrResponse

AddrResponses exposes a channel that allows to consume backend's responses to address requests created with AddrRequest()

func (*FixtureBackend) BlockRequest

func (fb *FixtureBackend) BlockRequest(height uint32)

func (*FixtureBackend) BlockResponses

func (fb *FixtureBackend) BlockResponses() <-chan *BlockResponse

func (*FixtureBackend) ChainHeight

func (fb *FixtureBackend) ChainHeight() uint32

func (*FixtureBackend) Finish

func (fb *FixtureBackend) Finish()

Finish informs the backend to stop doing its work.

func (*FixtureBackend) TxRequest

func (fb *FixtureBackend) TxRequest(txHash string)

TxRequest schedules a request to the backend to lookup information related to the given transaction hash.

func (*FixtureBackend) TxResponses

func (fb *FixtureBackend) TxResponses() <-chan *TxResponse

TxResponses exposes a channel that allows to consume backend's responses to address requests created with addrrequest(). if an address has any transactions then they will be sent to this channel by the backend.

type RecorderBackend

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

RecorderBackend wraps Btcd node and its API to provide a simple balance and transaction history information for a given address. RecorderBackend implements Backend interface.

func NewRecorderBackend

func NewRecorderBackend(b Backend, filepath string) (*RecorderBackend, error)

NewRecorderBackend returns a new RecorderBackend structs or errors. RecorderBackend passes requests to another backend and ten records address and transaction responses to a file. The file can later be used by a FixtureBackend to reply those responses.

func (*RecorderBackend) AddrRequest

func (rb *RecorderBackend) AddrRequest(addr *deriver.Address)

AddrRequest schedules a request to the backend to lookup information related to the given address.

func (*RecorderBackend) AddrResponses

func (rb *RecorderBackend) AddrResponses() <-chan *AddrResponse

AddrResponses exposes a channel that allows to consume backend's responses to address requests created with AddrRequest()

func (*RecorderBackend) BlockRequest

func (rb *RecorderBackend) BlockRequest(height uint32)

func (*RecorderBackend) BlockResponses

func (rb *RecorderBackend) BlockResponses() <-chan *BlockResponse

func (*RecorderBackend) ChainHeight

func (rb *RecorderBackend) ChainHeight() uint32

func (*RecorderBackend) Finish

func (rb *RecorderBackend) Finish()

Finish informs the backend to stop doing its work.

func (*RecorderBackend) TxRequest

func (rb *RecorderBackend) TxRequest(txHash string)

TxRequest schedules a request to the backend to lookup information related to the given transaction hash.

func (*RecorderBackend) TxResponses

func (rb *RecorderBackend) TxResponses() <-chan *TxResponse

TxResponses exposes a channel that allows to consume backend's responses to address requests created with addrrequest(). if an address has any transactions then they will be sent to this channel by the backend.

type TxResponse

type TxResponse struct {
	Hash   string
	Height int64
	Hex    string
}

TxResponse contains raw transaction, transaction hash and a block height in which it was confirmed.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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