bitcoin

package
v0.0.0-...-8f31e64 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Unset        = "UNSET"
	Economical   = "ECONOMICAL"
	Conservative = "CONSERVATIVE"
)
View Source
const BitSymbol = "μ₿"

BitSymbol is the symbol for 0.000001 BTC.

View Source
const Confirmations = 3
View Source
const CurrencyCode = "BTC"
View Source
const MillibitSymbol = "m₿"

MillibitSymbol is the symbol for 0.001 BTC.

View Source
const Scheme = "bitcoin"

Scheme is the URI scheme.

View Source
const Symbol = "₿"
View Source
const TransferMethod = "bitcoin"

Variables

This section is empty.

Functions

func ValidateAddress

func ValidateAddress(arg string) (bool, error)

ValidateAddress validates addresses using a naive Regular Expression pattern matching.

Types

type Adapterer

type Adapterer interface {
	GetBalance(wallet string) (*librefund.Money, error)
	GetNewAddress(wallet string) (Address, error)
	EnsureWalletExists(wallet string) error
	Transfer(txs []librefund.Transaction) error
	UpdateTransactions(wallet string) error
	NotifyTransactionUpdate(newTX <-chan librefund.TransactionID, lastCompleted *TransactionID) error
	ValidateAddress(arg string) (bool, error)
}

type Address

type Address string

Address is a Bitcoin address.

func MustAddress

func MustAddress(arg string) *Address

MustAddress returns an address, panicing if its invalid.

func NewAddress

func NewAddress(arg string) (Address, error)

NewAddress returns a validated Address.

func (*Address) String

func (a *Address) String() string

func (*Address) UnmarshalText

func (a *Address) UnmarshalText(arg []byte) error

type Bitcoin

type Bitcoin decimal.Decimal

func MustBitcoin

func MustBitcoin(arg string) *Bitcoin

func NewBitcoin

func NewBitcoin(arg *librefund.Money) (*Bitcoin, error)

func ParseBitcoin

func ParseBitcoin(arg string) (*Bitcoin, error)

func (*Bitcoin) Decimal

func (b *Bitcoin) Decimal() *decimal.Decimal

func (*Bitcoin) Satoshis

func (b *Bitcoin) Satoshis() *Satoshis

func (*Bitcoin) String

func (b *Bitcoin) String() string

func (*Bitcoin) UnmarshalJSON

func (b *Bitcoin) UnmarshalJSON(buf []byte) error

type BitcoinClient

type BitcoinClient struct {
	Config librefund.Config
	// contains filtered or unexported fields
}

func NewClient

func NewClient(cfg librefund.Config) *BitcoinClient

func (*BitcoinClient) CreateWallet

func (b *BitcoinClient) CreateWallet(name string) (*CreateWalletResp, error)

func (*BitcoinClient) EstimateSmartFee

func (b *BitcoinClient) EstimateSmartFee(target int) (*EstimateSmartFeeResp, error)

func (*BitcoinClient) GetBalance

func (b *BitcoinClient) GetBalance(wallet string) (*Bitcoin, error)

func (*BitcoinClient) GetNewAddress

func (b *BitcoinClient) GetNewAddress(wallet string) (Address, error)

func (*BitcoinClient) ListTransactions

func (b *BitcoinClient) ListTransactions(
	wallet string,
	count int,
	skip int,
) ([]ListTransactionRecord, error)

func (*BitcoinClient) ListWallets

func (b *BitcoinClient) ListWallets() ([]string, error)

ListWallets ...

func (*BitcoinClient) LoadWallet

func (b *BitcoinClient) LoadWallet(wallet string) error

LoadWallet ...

func (*BitcoinClient) SendToAddress

func (b *BitcoinClient) SendToAddress(
	wallet string,
	arg SendToAddressOpts,
) (string, error)

SendToAddress ...

func (*BitcoinClient) SetLogger

func (b *BitcoinClient) SetLogger(log librefund.Logger)

func (*BitcoinClient) SetTXFee

func (b *BitcoinClient) SetTXFee(
	amount *Bitcoin,
) (bool, error)

SetTXFee sets the transaction fee.

func (*BitcoinClient) ValidateAddress

func (b *BitcoinClient) ValidateAddress(
	address string,
) (*ValidateAddressResponse, error)

ValidateAddress ...

type BitcoinPaymentFailed

type BitcoinPaymentFailed struct {
	Event     string    `json:"event"`
	CreatedAt time.Time `json:"createdAt"`

	PaymentID string `json:"paymentId"`
}

func (*BitcoinPaymentFailed) Name

func (s *BitcoinPaymentFailed) Name() string

func (*BitcoinPaymentFailed) New

func (s *BitcoinPaymentFailed) New() interface{}

type BitcoinPaymentPaid

type BitcoinPaymentPaid struct {
	Event     string    `json:"event"`
	CreatedAt time.Time `json:"createdAt"`

	PaymentID string `json:"paymentId"`
}

func (*BitcoinPaymentPaid) Name

func (s *BitcoinPaymentPaid) Name() string

func (*BitcoinPaymentPaid) New

func (s *BitcoinPaymentPaid) New() interface{}

type BitcoinPaymentRefunded

type BitcoinPaymentRefunded struct {
	Event     string    `json:"event"`
	CreatedAt time.Time `json:"createdAt"`

	PaymentID    string `json:"paymentId"`
	RefundAmount *librefund.Money
}

func (*BitcoinPaymentRefunded) Name

func (s *BitcoinPaymentRefunded) Name() string

func (*BitcoinPaymentRefunded) New

func (s *BitcoinPaymentRefunded) New() interface{}

type BitcoinPaymentStarted

type BitcoinPaymentStarted struct {
	Event     string    `json:"event"`
	CreatedAt time.Time `json:"createdAt"`

	Amount         *librefund.Money `json:"amount"`
	FulfillmentURL string           `json:"fulfillmentUrl"`
	PaymentID      string           `json:"paymentId"`
	ReceiveAddress Address          `json:"receiveAddress"`
	ReturnAddress  Address          `json:"returnAddress"`
}

func (*BitcoinPaymentStarted) Name

func (s *BitcoinPaymentStarted) Name() string

func (*BitcoinPaymentStarted) New

func (s *BitcoinPaymentStarted) New() interface{}

type BitcoinStub

type BitcoinStub struct {
	WalletBalance *librefund.Money
}

func (*BitcoinStub) EnsureWalletExists

func (s *BitcoinStub) EnsureWalletExists(wallet string) error

func (*BitcoinStub) GetBalance

func (s *BitcoinStub) GetBalance(wallet string) (*librefund.Money, error)

func (*BitcoinStub) GetNewAddress

func (s *BitcoinStub) GetNewAddress(wallet string) (Address, error)

func (*BitcoinStub) NotifyTransactionUpdate

func (s *BitcoinStub) NotifyTransactionUpdate(newTX <-chan librefund.TransactionID, lastCompleted *TransactionID) error

func (*BitcoinStub) Transfer

func (s *BitcoinStub) Transfer(txs []librefund.Transaction) error

func (*BitcoinStub) UpdateTransactions

func (s *BitcoinStub) UpdateTransactions(wallet string) error

func (*BitcoinStub) ValidateBitcoinAddress

func (s *BitcoinStub) ValidateBitcoinAddress(arg string) (bool, error)

type CreateWalletResp

type CreateWalletResp struct {
	Name    string `json:"name"`
	Warning string `json:"warning"`
}

type EstimateSmartFeeResp

type EstimateSmartFeeResp struct {
	// FeeRate is BTC/kB
	FeeRate *Bitcoin
	Errors  []string
	Blocks  int
}

type GetTransactionDetails

type GetTransactionDetails struct {
	Address   string
	Category  string
	Amount    *Bitcoin
	Fee       *Bitcoin
	Label     string
	Vout      int
	Abandoned bool
}

type GetTransactionResult

type GetTransactionResult struct {
	Amount            *Bitcoin
	Fee               *Bitcoin
	Confirmations     int
	BlockHash         string
	BlockIndex        int
	BlockTime         int
	TxID              string
	Time              int
	TimeReceived      int
	Bip125Replaceable string `json:"bip125-replaceable"`
	Comment           string
	Details           []GetTransactionDetails
	Hex               string
}

type ListTransactionRecord

type ListTransactionRecord struct {
	Address       Address
	Category      string
	Amount        Bitcoin
	Label         string
	Vout          int
	Confirmations int
	BlockHash     string
	BlockHeight   int
	BlockIndex    int
	BlockTime     int
	TXID          string
	// Wallet conflicts
	Time              int
	TimeReceived      int
	Bip125Replaceable string `json:"bip125-replaceable"`
}

type Params

type Params struct {
	ReturnAddress Address `schema:"returnAddress"`
}

Params are this Gateway's specific parameters for creating orders.

type PaymentGateway

type PaymentGateway struct {
	Config librefund.Config
	Client clienter
	// contains filtered or unexported fields
}

func NewPaymentGateway

func NewPaymentGateway(
	cfg librefund.Config,
	eventLog *librefund.EventLog,
) (*PaymentGateway, error)

func (*PaymentGateway) GetLastPayments

func (s *PaymentGateway) GetLastPayments(
	from int, amount int,
) ([]*payment.Payment, error)

func (*PaymentGateway) GetPayment

func (s *PaymentGateway) GetPayment(paymentID string) (*payment.Payment, error)

func (*PaymentGateway) GetPaymentInfo

func (s *PaymentGateway) GetPaymentInfo(paymentID string) (*PaymentInfo, error)

func (*PaymentGateway) GetReceiveAddress

func (s *PaymentGateway) GetReceiveAddress(paymentID string) (Address, error)

func (*PaymentGateway) IsAwaitingConfirmation

func (s *PaymentGateway) IsAwaitingConfirmation(
	paymentID string,
) bool

func (*PaymentGateway) PaymentURL

func (s *PaymentGateway) PaymentURL(
	paymentID string,
) (string, error)

func (*PaymentGateway) RefundPayment

func (s *PaymentGateway) RefundPayment(
	paymentID string,
	req *payment.RefundRequest,
) (*payment.RefundResponse, error)

func (*PaymentGateway) SetLogger

func (s *PaymentGateway) SetLogger(log librefund.Logger)

func (*PaymentGateway) Start

func (s *PaymentGateway) Start() error

func (*PaymentGateway) StartPayment

func (s *PaymentGateway) StartPayment(
	req *payment.PaymentRequest,
) (*payment.PaymentResponse, error)

func (*PaymentGateway) Stop

func (s *PaymentGateway) Stop()

func (*PaymentGateway) TransferMethod

func (s *PaymentGateway) TransferMethod() string

func (*PaymentGateway) ValidateAddress

func (s *PaymentGateway) ValidateAddress(
	arg string,
) (bool, error)

ValidateBitcoinAddress validates addresses using a naive Regular Expression pattern matching.

type PaymentInfo

type PaymentInfo struct {
	Amount                 *librefund.Money      `json:"amount"`
	FulfillmentURL         string                `json:"fulfillmentUrl"`
	ID                     string                `json:"id"`
	ReceiveAddress         Address               `json:"receiveAddress"`
	RefundAmount           *librefund.Money      `json:"refundAmount"`
	ReturnAddress          Address               `json:"returnAddress"`
	Status                 payment.PaymentStatus `json:"status"`
	IsAwaitingConfirmation bool                  `json:"isAwaitingConfirmation"`
}

type PaymentStore

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

func NewPaymentStore

func NewPaymentStore(
	eventLog *librefund.EventLog,
) *PaymentStore

func (*PaymentStore) GetLastPayments

func (s *PaymentStore) GetLastPayments(
	from int, amount int,
) ([]*payment.Payment, error)

func (*PaymentStore) GetPaymentInfo

func (s *PaymentStore) GetPaymentInfo(
	paymentID string,
) (*PaymentInfo, bool)

func (*PaymentStore) GetPaymentInfoByRecvAddr

func (s *PaymentStore) GetPaymentInfoByRecvAddr(
	recvAddr Address,
) (*PaymentInfo, bool)

func (*PaymentStore) PaymentFailed

func (s *PaymentStore) PaymentFailed(
	paymentID string,
) error

func (*PaymentStore) PaymentPaid

func (s *PaymentStore) PaymentPaid(
	paymentID string,
) error

func (*PaymentStore) PaymentRefunded

func (s *PaymentStore) PaymentRefunded(
	paymentID string,
	refundAmount *librefund.Money,
) error

func (*PaymentStore) PaymentStarted

func (s *PaymentStore) PaymentStarted(
	paymentID string,
	amount *librefund.Money,
	fulfillmentURL string,
	recvAddress Address,
	returnAddress Address,
) error

type Satoshis

type Satoshis big.Int

Satohis are the base amount of Bitcoin.

A Bitcoin has 10,000,000 Satoshis

func (*Satoshis) Bitcoins

func (s *Satoshis) Bitcoins() *Bitcoin

func (*Satoshis) Int64

func (s *Satoshis) Int64() int64

func (*Satoshis) String

func (s *Satoshis) String() string

type SendToAddressOpts

type SendToAddressOpts struct {
	// The bitcoin address to send to.
	Address Address `json:"address"`
	// The amount in BTC to send. eg 0.1
	Amount *Bitcoin `json:"amount"`
	// A comment used to store what the transaction is for. This is not
	// part of the transaction, just kept in your wallet.
	Comment *string `json:"comment"`
	// A comment to store the name of the person or organization to which
	// you’re sending the transaction. This is not part of the transaction,
	// just kept in your wallet.
	CommentTo *string `json:"comment_to"`
	// The fee will be deducted from the amount being sent. The recipient
	// will receive less bitcoins than you enter in the amount field.
	SubtractFeeFromAmount *bool `json:"subtract_fee_from_amount"`
	// Allow this transaction to be replaced by a transaction with higher
	// fees via BIP 125.
	Replaceable *bool `json:"replaceable"`
	// Confirmation target (in blocks).
	ConfTarget   *int    `json:"conf_target"`
	EstimateMode *string `json:"estimate_mode"`
}

type SendToAddressResult

type SendToAddressResult struct {
	TxID string `json:"txid"`
}

type TransactionID

type TransactionID string

type TransferID

type TransferID string

type TransferInfo

type TransferInfo struct {
	ReceiveAddress Address `json:"receiveAddress" schema:"receiveAddress"`
	ReturnAddress  Address `json:"returnAddress" schema:"returnAddress"`
}

TransferInfo is the Bitcoin specific information used to track Bitcoin transfers for contributions.

type URI

type URI struct {
	Address Address
	Amount  *decimal.Decimal
	Label   string
	Message string
}

URI is an address for receiving Bitcoin transfers.

func NewURI

func NewURI(
	address Address,
	amount *decimal.Decimal,
	label string,
	msg string,
) URI

func NewURIFromString

func NewURIFromString(arg string) (*URI, error)

func (URI) String

func (s URI) String() string

func (*URI) UnmarshalText

func (s *URI) UnmarshalText(arg []byte) error

type ValidateAddressResponse

type ValidateAddressResponse struct {
	IsValid      bool   `json:"isValid"`
	Address      string `json:"address"`
	ScriptPubKey string `json:"scriptPubKey"`
	IsScript     bool   `json:"isScript"`
	IsWitness    bool   `json:"isWitness"`
}

Jump to

Keyboard shortcuts

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