bitcoin

package
v0.0.0-...-7e6829a Latest Latest
Warning

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

Go to latest
Published: May 21, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BTC_FEE               = 330
	PAYMENT_GATE_SETTINGS = settings.LoadPaymentGateSettings()
)

Functions

func ConfigureRouter

func ConfigureRouter(router *web.Router)

func GetRecommenedFee

func GetRecommenedFee() (int, error)

func GetUnspentBitcoinTransactions

func GetUnspentBitcoinTransactions(w BitcoinWallet) ([]insight.Tx, error)

func PushBitcoinTransaction

func PushBitcoinTransaction(rawtx string) error

func SanitizeBitcoinAddress

func SanitizeBitcoinAddress(inputAddress, privateKey, outputAddress string)

SanitizeBitcoinAddress is a utility function used to 'sanitize' or consolidate an address with large number of unspent inputs. Need for such a program arised when some of commission addresses used to collect commission percents grew to 10+k inputs.

func SetupViews

func SetupViews()

func SweepBitcoinWallet

func SweepBitcoinWallet(addressFrom string, addressTo string)

func SweepCommissionAndPremiumBitcoinWallets

func SweepCommissionAndPremiumBitcoinWallets(addressTo string)

func TaskUpdateBitcoinTransactionFee

func TaskUpdateBitcoinTransactionFee()

func TaskUpdateBitcoinWalletBalances

func TaskUpdateBitcoinWalletBalances()

func UpdateBTCTransactionFee

func UpdateBTCTransactionFee()

func UpdateBitcoinWalletBalances

func UpdateBitcoinWalletBalances()

func UpdatePremiumBitcoinWalletBalances

func UpdatePremiumBitcoinWalletBalances()

func ViewCreateBitcoinWallet

func ViewCreateBitcoinWallet(w web.ResponseWriter, r *web.Request)

func ViewCreateMultisigBitcoinWallet

func ViewCreateMultisigBitcoinWallet(w web.ResponseWriter, r *web.Request)

func ViewEstimateFeeFromMultipleBitcoinWalletsWithAmountSplit

func ViewEstimateFeeFromMultipleBitcoinWalletsWithAmountSplit(w web.ResponseWriter, r *web.Request)

func ViewListBitcoinWalletsWithPositiveBalance

func ViewListBitcoinWalletsWithPositiveBalance(w web.ResponseWriter, r *web.Request)

func ViewSendFromMultipleBitcoinWalletsWithAmountSplit

func ViewSendFromMultipleBitcoinWalletsWithAmountSplit(w web.ResponseWriter, r *web.Request)

func ViewSendFromSingleBitcoinWalletWithPercentSplit

func ViewSendFromSingleBitcoinWalletWithPercentSplit(w web.ResponseWriter, r *web.Request)

func ViewShowBitcoinWallet

func ViewShowBitcoinWallet(w web.ResponseWriter, r *web.Request)

func ViewTableListBitcoinWalletsWithPositiveBalance

func ViewTableListBitcoinWalletsWithPositiveBalance(w web.ResponseWriter, r *web.Request)

func ViewUpdateBitcoinWallets

func ViewUpdateBitcoinWallets(w web.ResponseWriter, r *web.Request)

func ViewUpdatePremiumBitcoinWallets

func ViewUpdatePremiumBitcoinWallets(w web.ResponseWriter, r *web.Request)

Types

type BTCPayment

type BTCPayment struct {
	Address string  `json:"address"`
	Percent float64 `json:"percent"`
	Amount  float64 `json:"amount"`
}

type BTCPaymentResult

type BTCPaymentResult struct {
	Fee            int                `json:"fee"`
	RawTransaction string             `json:"rawTransaction"`
	Outputs        []insight.TxOutput `json:"outputs"`
	Hash           string             `json:"hash"`
	Error          *string            `json:"error"`
	Description    string             `json:"description"`
}

func BuildRawBitcoinTransaction

func BuildRawBitcoinTransaction(
	outputs []insight.TxOutput,
	utxoSet []insight.UtxoSet,
	feePerByte int,
	feeOutput int,
	feeOnly bool,
) (BTCPaymentResult, error)

type BitcoinWallet

type BitcoinWallet struct {
	PublicKey             string `json:"address" gorm:"primary_key"`
	PublicKeyUncompressed string `json:"address_uncompressed" sql:"unique_index"`

	PrivateKey string `json:"private_key,omitempty" sql:"type:varchar(1024)"`
	WIF        string `json:"-" sql:"type:varchar(1024)" gorm:"column:w_i_f"`
	WIFC       string `json:"-" sql:"type:varchar(1024)" gorm:"column:w_i_f_c"`

	// Multisig
	BuyerPublicKey    string `json:"buyer_public_key"`
	SellerPublicKey   string `json:"seller_public_key"`
	MultisigPublicKey string `json:"multisig_public_key"`
	MultisigAddress   string `json:"multisig_address"`

	Type string `json:"type"`

	CreatedAt *time.Time `json:"created_at,omitempty" gorm:"index"`
	UpdatedAt *time.Time `json:"updated_at,omitempty" gorm:"index"`
	DeletedAt *time.Time `json:"deleted_at,omitempty" gorm:"index"`
}

func CreateBitcoinWallet

func CreateBitcoinWallet(tp string) (BitcoinWallet, error)

func CreateMultisigBitcoinWallet

func CreateMultisigBitcoinWallet(buyerPublicKey, sellerPublicKey string) (BitcoinWallet, error)

func FindAllBitcoinWallets

func FindAllBitcoinWallets() ([]BitcoinWallet, error)

func FindBitcoinWalletByPublicKey

func FindBitcoinWalletByPublicKey(publicKey string) (*BitcoinWallet, error)

func FindPremiumBitcoinWallets

func FindPremiumBitcoinWallets() ([]BitcoinWallet, error)

func ImportBitcoinWallet

func ImportBitcoinWallet(tp, wif string) (BitcoinWallet, error)

func (BitcoinWallet) BuildTransactionFromMultipleInputsAndSingleOutput

func (w BitcoinWallet) BuildTransactionFromMultipleInputsAndSingleOutput(txs []insight.Tx, outputAddress string, feeOnly bool) (BTCPaymentResult, error)

func (BitcoinWallet) CurrentBalance

func (w BitcoinWallet) CurrentBalance() (*BitcoinWalletBalance, error)

func (BitcoinWallet) Remove

func (w BitcoinWallet) Remove() error

func (BitcoinWallet) Save

func (w BitcoinWallet) Save() error

func (BitcoinWallet) SaveToDatabase

func (w BitcoinWallet) SaveToDatabase() error

func (BitcoinWallet) SendWithPercentSplit

func (w BitcoinWallet) SendWithPercentSplit(payments []BTCPayment) (BTCPaymentResult, error)

func (BitcoinWallet) UpdateBalance

func (w BitcoinWallet) UpdateBalance() (*BitcoinWalletBalance, error)

func (BitcoinWallet) Validate

func (w BitcoinWallet) Validate() error

type BitcoinWalletBalance

type BitcoinWalletBalance struct {
	ID                             int     `json:"id" gorm:"primary_key"`
	PublicKey                      string  `json:"address" gorm:"index"`
	Balance                        float64 `json:"balance"`
	BalanceTxApperances            int     `json:"txApperances"`
	UnconfirmedBalance             float64 `json:"unconfirmedBalance"`
	UnconfirmedBalanceTxApperances int     `json:"unconfirmedTxApperances"`

	CreatedAt *time.Time `json:"created_at" gorm:"index"`
	UpdatedAt *time.Time `json:"updated_at" gorm:"index"`
	DeletedAt *time.Time `json:"deleted_at" gorm:"index"`

	BitcoinWallet BitcoinWallet `json:"-" gorm:"ForeignKey:PublicKey;AssociationForeignKey:PublicKey"`
}

func FindAllBitcoinWalletBalances

func FindAllBitcoinWalletBalances() ([]BitcoinWalletBalance, error)

func FindBitcoinWalletsWithNonZeroBalance

func FindBitcoinWalletsWithNonZeroBalance() ([]BitcoinWalletBalance, error)

func FindBitcoinWalletsWithNonZeroBalanceByType

func FindBitcoinWalletsWithNonZeroBalanceByType(tp string) ([]BitcoinWalletBalance, error)

func GetBitcoinWalletBalance

func GetBitcoinWalletBalance(w BitcoinWallet) (*BitcoinWalletBalance, error)

func (BitcoinWalletBalance) DisplayBitcoinWallet

func (w BitcoinWalletBalance) DisplayBitcoinWallet() DisplayBitcoinWallet

func (BitcoinWalletBalance) Remove

func (w BitcoinWalletBalance) Remove() error

func (BitcoinWalletBalance) Save

func (w BitcoinWalletBalance) Save() error

type BitcoinWallets

type BitcoinWallets []BitcoinWallet

func (BitcoinWallets) BuildTransactionWithAmountSplit

func (wts BitcoinWallets) BuildTransactionWithAmountSplit(payments []BTCPayment, feeOnly bool) (BTCPaymentResult, error)

func (BitcoinWallets) BuildTransactionWithPercentSplit

func (wts BitcoinWallets) BuildTransactionWithPercentSplit(
	payments []BTCPayment,
	txfeeOnly bool,
) (BTCPaymentResult, error)

func (BitcoinWallets) SendWithAmountSplit

func (wts BitcoinWallets) SendWithAmountSplit(payments []BTCPayment) (BTCPaymentResult, error)

func (BitcoinWallets) SendWithPercentSplit

func (wts BitcoinWallets) SendWithPercentSplit(payments []BTCPayment) (BTCPaymentResult, error)

type DisplayBitcoinWallet

type DisplayBitcoinWallet struct {
	PublicKey             string     `json:"address"`
	Balance               float64    `json:"balance"`
	UnconfirmedBalance    float64    `json:"unconfirmed_balance"`
	IsConfirmed           bool       `json:"-"`
	NumberOfConfirmations int        `json:"-"`
	Type                  string     `json:"type"`
	CreatedAt             *time.Time `json:"created_at"`
	UpdatedAt             *time.Time `json:"updated_at"`
}

type ViewListBitcoinWalletsWithPositiveBalanceResponse

type ViewListBitcoinWalletsWithPositiveBalanceResponse struct {
	DisplayBitcoinWallets []DisplayBitcoinWallet `json:"wallets"`
	SummaryBalance        float64                `json:"balance"`
}

Jump to

Keyboard shortcuts

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