btc

package
v4.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2018 License: Apache-2.0 Imports: 34 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.

func XPubVersionForScriptType

func XPubVersionForScriptType(coin *Coin, scriptType signing.ScriptType) [4]byte

XPubVersionForScriptType returns the xpub version bytes for the given coin and script type.

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 creates a new account.

func (*Account) Balance

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

Balance implements the interface.

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

Coin returns the coin of the account.

func (*Account) ConvertToLegacyAddress

func (account *Account) ConvertToLegacyAddress(addressID string) (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() []coin.Address

GetUnusedReceiveAddresses returns a number of unused addresses.

func (*Account) Info

func (account *Account) Info() *Info

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

func (*Account) Initialize

func (account *Account) Initialize() error

Initialize initializes the account.

func (*Account) Initialized

func (account *Account) Initialized() bool

Initialized 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) Name

func (account *Account) Name() string

Name returns the name of the account.

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 coin.SendAmount,
	feeTargetCode FeeTargetCode,
	selectedUTXOs map[wire.OutPoint]struct{},
	_ []byte,
) 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() []coin.Transaction

Transactions wraps transaction.Transactions.Transactions()

func (*Account) TxProposal

func (account *Account) TxProposal(
	recipientAddress string,
	amount coin.SendAmount,
	feeTargetCode FeeTargetCode,
	selectedUTXOs map[wire.OutPoint]struct{},
	_ []byte,
) (
	coin.Amount, coin.Amount, coin.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(addressID string) (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(
	code string,
	unit string,
	net *chaincfg.Params,
	dbFolder string,
	servers []*rpc.ServerInfo,
	blockExplorerTxPrefix string,
) *Coin

NewCoin creates a new coin with the given parameters.

func (*Coin) BlockExplorerTransactionURLPrefix

func (coin *Coin) BlockExplorerTransactionURLPrefix() string

BlockExplorerTransactionURLPrefix implements coin.Coin.

func (*Coin) Blockchain

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

Blockchain connects to a blockchain backend.

func (*Coin) Code

func (coin *Coin) Code() string

Code implements coin.Coin.

func (*Coin) FormatAmount

func (coin *Coin) FormatAmount(amount coinpkg.Amount) string

FormatAmount implements coin.Coin.

func (*Coin) Headers

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

Headers returns the coin headers.

func (*Coin) Initialize

func (coin *Coin) Initialize()

Initialize implements coin.Coin.

func (*Coin) Net

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

Net returns the coin's network params.

func (*Coin) String

func (coin *Coin) String() string

func (*Coin) ToUnit

func (coin *Coin) ToUnit(amount coinpkg.Amount) float64

ToUnit implements coin.Coin.

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) (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 is a identifier for the account (to identify the account in databases, apis, etc.).
	Code() string
	Coin() coin.Coin
	// Name returns a human readable long name.
	Name() string
	// Initialize only starts the initialization, the account is not initialized right afterwards.
	Initialize() error
	Initialized() bool
	Offline() bool
	Close()
	Transactions() []coin.Transaction
	Balance() *coin.Balance
	// Creates, signs and broadcasts a transaction. Returns keystore.ErrSigningAborted on user
	// abort.
	SendTx(string, coin.SendAmount, FeeTargetCode, map[wire.OutPoint]struct{}, []byte) error
	FeeTargets() ([]*FeeTarget, FeeTargetCode)
	TxProposal(string, coin.SendAmount, FeeTargetCode, map[wire.OutPoint]struct{}, []byte) (
		coin.Amount, coin.Amount, coin.Amount, error)
	GetUnusedReceiveAddresses() []coin.Address
	VerifyAddress(addressID string) (bool, error)
	ConvertToLegacyAddress(addressID string) (btcutil.Address, error)
	Keystores() keystore.Keystores
	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 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"
)

Directories

Path Synopsis
db
client
Package client implements an Electrum JSON RPC client.
Package client implements an Electrum JSON RPC client.
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