btc

package
v4.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2018 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SignTransaction

func SignTransaction(
	keystores keystore.Keystores,
	txProposal *maketx.TxProposal,
	previousOutputs map[wire.OutPoint]*transactions.SpendableOutput,
	getAddress func(blockchain.ScriptHashHex) *addresses.AccountAddress,
	log *logrus.Entry,
) error

SignTransaction signs all inputs. It assumes all outputs spent belong to this wallet. previousOutputs must contain all outputs which are spent by the transaction.

Types

type Account

type Account struct {
	locker.Locker
	// contains filtered or unexported fields
}

Account is a account whose addresses are derived from an xpub.

func NewAccount

func NewAccount(
	coin *Coin,
	dbFolder string,
	code string,
	name string,
	getSigningConfiguration func() (*signing.Configuration, error),
	keystores keystore.Keystores,
	onEvent func(Event),
	log *logrus.Entry,
) *Account

NewAccount creats a new Account.

func (*Account) Balance

func (account *Account) Balance() *transactions.Balance

Balance wraps transaction.Transactions.Balance()

func (*Account) Close

func (account *Account) Close()

Close stops the account.

func (*Account) Code

func (account *Account) Code() string

Code returns the code of the account.

func (*Account) Coin

func (account *Account) Coin() *Coin

Coin returns the coin of the account.

func (*Account) ConvertToLegacyAddress

func (account *Account) ConvertToLegacyAddress(scriptHashHex blockchain.ScriptHashHex) (btcutil.Address, error)

ConvertToLegacyAddress converts a ltc p2sh address to the legacy format (starting with '3'). Returns an error for non litecoin p2sh accounts.

func (*Account) FeeTargets

func (account *Account) FeeTargets() ([]*FeeTarget, FeeTargetCode)

FeeTargets returns the fee targets and the default fee target.

func (*Account) GetUnusedReceiveAddresses

func (account *Account) GetUnusedReceiveAddresses() []*addresses.AccountAddress

GetUnusedReceiveAddresses returns a number of unused addresses.

func (*Account) HeadersStatus

func (account *Account) HeadersStatus() (*headers.Status, error)

HeadersStatus returns the status of the headers.

func (*Account) Info

func (account *Account) Info() *Info

Info returns account info, such as the signing configuration (xpubs).

func (*Account) Init

func (account *Account) Init() error

Init initializes the account.

func (*Account) InitialSyncDone

func (account *Account) InitialSyncDone() bool

InitialSyncDone indicates whether the account has loaded and finished the initial sync of the addresses.

func (*Account) Keystores

func (account *Account) Keystores() keystore.Keystores

Keystores returns the keystores of the account.

func (*Account) MarshalJSON

func (account *Account) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Account) Offline

func (account *Account) Offline() bool

Offline returns true if the account is disconnected from the blockchain.

func (*Account) SendTx

func (account *Account) SendTx(
	recipientAddress string,
	amount SendAmount,
	feeTargetCode FeeTargetCode,
	selectedUTXOs map[wire.OutPoint]struct{},
) error

SendTx creates, signs and sends tx which sends `amount` to the recipient.

func (*Account) SpendableOutputs

func (account *Account) SpendableOutputs() []*SpendableOutput

SpendableOutputs returns the utxo set, sorted by the value descending.

func (*Account) String

func (account *Account) String() string

String returns a representation of the account for logging.

func (*Account) Transactions

func (account *Account) Transactions() []*transactions.TxInfo

Transactions wraps transaction.Transactions.Transactions()

func (*Account) TxProposal

func (account *Account) TxProposal(
	recipientAddress string,
	amount SendAmount,
	feeTargetCode FeeTargetCode,
	selectedUTXOs map[wire.OutPoint]struct{},
) (
	btcutil.Amount, btcutil.Amount, btcutil.Amount, error)

TxProposal creates a tx from the relevant input and returns information about it for display in the UI (the output amount and the fee). At the same time, it validates the input.

func (*Account) VerifyAddress

func (account *Account) VerifyAddress(scriptHashHex blockchain.ScriptHashHex) (bool, error)

VerifyAddress verifies a receive address on a keystore. Returns false, nil if no secure output exists.

type Coin

type Coin struct {
	observable.Implementation
	// contains filtered or unexported fields
}

Coin models a Bitcoin-related coin.

func NewCoin

func NewCoin(
	name string,
	unit string,
	net *chaincfg.Params,
	dbFolder string,
	servers []*rpc.ServerInfo,
	blockExplorerTxPrefix string,
	ratesUpdater coinpkg.RatesUpdater,
) *Coin

NewCoin creates a new coin with the given parameters.

func (*Coin) Blockchain

func (coin *Coin) Blockchain() blockchain.Interface

Blockchain connects to a blockchain backend.

func (*Coin) FormatAmount

func (coin *Coin) FormatAmount(amount int64) string

FormatAmount implements coin.Coin.

func (*Coin) FormatAmountAsJSON

func (coin *Coin) FormatAmountAsJSON(amount int64) coinpkg.FormattedAmount

FormatAmountAsJSON implements coin.Coin.

func (*Coin) Headers

func (coin *Coin) Headers() *headers.Headers

Headers returns the coin headers.

func (*Coin) Init

func (coin *Coin) Init()

Init initializes the coin - blockchain and headers.

func (*Coin) Name

func (coin *Coin) Name() string

Name returns the coin's name.

func (*Coin) Net

func (coin *Coin) Net() *chaincfg.Params

Net returns the coin's network params.

func (*Coin) RatesUpdater

func (coin *Coin) RatesUpdater() coinpkg.RatesUpdater

RatesUpdater returns current exchange rates.

func (*Coin) String

func (coin *Coin) String() string

func (*Coin) Unit

func (coin *Coin) Unit() string

Unit implements coin.Coin.

type Event

type Event string

Event instances are sent to the onEvent callback of the wallet.

const (
	// EventStatusChanged is fired when the status changes. Check the status using Initialized().
	EventStatusChanged Event = "statusChanged"

	// EventSyncStarted is fired when syncing with the blockchain starts. This happens in the very
	// beginning for the initial sync, and repeatedly afterwards when the wallet is updated (new
	// transactions, confirmations, etc.).
	EventSyncStarted Event = "syncstarted"

	// EventSyncDone follows EventSyncStarted.
	EventSyncDone Event = "syncdone"

	// EventHeadersSynced is fired when the headers finished syncing.
	EventHeadersSynced Event = "headersSynced"

	// EventFeeTargetsChanged is fired when the fee targets change.
	EventFeeTargetsChanged Event = "feeTargetsChanged"
)

type FeeTarget

type FeeTarget struct {
	// Blocks is the target number of blocks in which the transaction should be confirmed.
	Blocks int

	// Code is the identifier for the UI.
	Code FeeTargetCode

	// FeeRatePerKb is the fee rate needed for this target. Can be nil until populated.
	FeeRatePerKb *btcutil.Amount
}

FeeTarget contains the fee rate for a specific fee target.

type FeeTargetCode

type FeeTargetCode string

FeeTargetCode models the code of a fee target. See the constants below.

const (
	// FeeTargetCodeLow is the low priority fee target.
	FeeTargetCodeLow FeeTargetCode = "low"

	// FeeTargetCodeEconomy is the economy priority fee target.
	FeeTargetCodeEconomy FeeTargetCode = "economy"

	// FeeTargetCodeNormal is the normal priority fee target.
	FeeTargetCodeNormal FeeTargetCode = "normal"

	// FeeTargetCodeHigh is the high priority fee target.
	FeeTargetCodeHigh FeeTargetCode = "high"
)

func NewFeeTargetCode

func NewFeeTargetCode(code string, log *logrus.Entry) (FeeTargetCode, error)

NewFeeTargetCode checks if the code is valid and returns a FeeTargetCode in that case.

type Info

type Info struct {
	SigningConfiguration *signing.Configuration `json:"signingConfiguration"`
}

Info holds account information.

type Interface

type Interface interface {
	Info() *Info
	Code() string
	Coin() *Coin
	Init() error
	InitialSyncDone() bool
	Offline() bool
	Close()
	Transactions() []*transactions.TxInfo
	Balance() *transactions.Balance
	SendTx(string, SendAmount, FeeTargetCode, map[wire.OutPoint]struct{}) error
	FeeTargets() ([]*FeeTarget, FeeTargetCode)
	TxProposal(string, SendAmount, FeeTargetCode, map[wire.OutPoint]struct{}) (
		btcutil.Amount, btcutil.Amount, btcutil.Amount, error)
	GetUnusedReceiveAddresses() []*addresses.AccountAddress
	VerifyAddress(blockchain.ScriptHashHex) (bool, error)
	ConvertToLegacyAddress(blockchain.ScriptHashHex) (btcutil.Address, error)
	Keystores() keystore.Keystores
	HeadersStatus() (*headers.Status, error)
	SpendableOutputs() []*SpendableOutput
}

Interface is the API of a Account.

type ProposedTransaction

type ProposedTransaction struct {
	TXProposal      *maketx.TxProposal
	PreviousOutputs map[wire.OutPoint]*transactions.SpendableOutput
	GetAddress      func(blockchain.ScriptHashHex) *addresses.AccountAddress
	// Signatures collects the signatures (signatures[transactionInput][cosignerIndex]).
	Signatures [][]*btcec.Signature
	SigHashes  *txscript.TxSigHashes
}

ProposedTransaction contains all the info needed to sign a btc transaction.

type RatesUpdater

type RatesUpdater struct {
	observable.Implementation
	// contains filtered or unexported fields
}

RatesUpdater implements coin.RatesUpdater.

func NewRatesUpdater

func NewRatesUpdater() *RatesUpdater

NewRatesUpdater returns a new rates updater.

func (*RatesUpdater) Last

func (updater *RatesUpdater) Last() map[string]map[string]float64

Last returns the last rates for a given coin and fiat or nil if not available.

type SendAmount

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

SendAmount is either a concrete amount, or "all"/"max".

func NewSendAmount

func NewSendAmount(amount btcutil.Amount) (SendAmount, error)

NewSendAmount creates a new SendAmount based on a concrete amount.

func NewSendAmountAll

func NewSendAmountAll() SendAmount

NewSendAmountAll creates a new Sendall-amount.

type SpendableOutput

type SpendableOutput struct {
	*transactions.SpendableOutput
	OutPoint wire.OutPoint
}

SpendableOutput is an unspent coin.

type Status

type Status string

Status indicates the connection and initialization status.

const (
	// AccountSynced indicates that the account is synced.
	AccountSynced Status = "accountSynced"

	// AccountNotSynced indicates that the account is initialized, but not yet fully synced.
	AccountNotSynced Status = "accountNotSynced"

	// AccountDisabled indicates that the account has not yet been initialized.
	AccountDisabled Status = "accountDisabled"

	// OfflineMode indicates that the connection to the blockchain network could not be established.
	OfflineMode Status = "offlineMode"
)

type TxValidationError

type TxValidationError string

TxValidationError represents errors in the tx proposal input data.

func (TxValidationError) Error

func (err TxValidationError) Error() string

Directories

Path Synopsis
mocks
Code generated by mockery v1.0.0.
Code generated by mockery v1.0.0.
client
Package client implements an Electrum JSON RPC client.
Package client implements an Electrum JSON RPC client.
mocks
Code generated by mockery v1.0.0.
Code generated by mockery v1.0.0.
Package maketx provides transaction creation code for wallets.
Package maketx provides transaction creation code for wallets.

Jump to

Keyboard shortcuts

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