gbitcoin

package
v0.0.0-...-721c341 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 16 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertBtc

func ConvertBtc(btc float64) uint64

func ReadCookieFile

func ReadCookieFile(path string) (username, password string, err error)

Types

type AddrType

type AddrType int
const (
	Bech32 AddrType = iota
	P2shSegwit
	Legacy
)

func (AddrType) String

func (a AddrType) String() string

type Bip9Fork

type Bip9Fork struct {
	// defined, started, locked_in, active, failed, ??
	Status      string     `json:"status"`
	StartTime   int        `json:"start_time"`
	Timeout     uint64     `json:"timeout"`
	SinceHeight uint32     `json:"since"`
	Statistics  *Bip9Stats `json:"statistics,omitempty"`
}

type Bip9Stats

type Bip9Stats struct {
	Period    uint32 `json:"period"`
	Threshold uint32 `json:"threshold"`
	Elapsed   uint32 `json:"elapsed"`
	Count     uint32 `json:"count"`
	Possible  bool   `json:"possible"`
}

type Bitcoin

type Bitcoin struct {
	CookiePath string
	// contains filtered or unexported fields
}

func NewBitcoin

func NewBitcoin(username, password, cookiePath string) *Bitcoin

func (*Bitcoin) CreateRawTx

func (b *Bitcoin) CreateRawTx(ins []*TxIn, outs []*TxOut, locktime *uint32, replaceable *bool) (string, error)

func (*Bitcoin) DecodeRawTx

func (b *Bitcoin) DecodeRawTx(txstring string) (*Tx, error)

func (*Bitcoin) Echo

func (b *Bitcoin) Echo() error

func (*Bitcoin) Endpoint

func (b *Bitcoin) Endpoint() string

func (*Bitcoin) EstimateFee

func (b *Bitcoin) EstimateFee(blocks uint32, mode string) (*FeeResponse, error)

func (*Bitcoin) FundRawTx

func (b *Bitcoin) FundRawTx(txstring string) (*FundRawResult, error)

Defaults to a segwit transaction

func (*Bitcoin) FundRawWithOptions

func (b *Bitcoin) FundRawWithOptions(txstring string, options *FundRawOptions, iswitness *bool) (*FundRawResult, error)

func (*Bitcoin) GenerateToAddress

func (b *Bitcoin) GenerateToAddress(address string, numBlocks uint) ([]string, error)

func (*Bitcoin) GetBlockHash

func (b *Bitcoin) GetBlockHash(height uint32) (string, error)

func (*Bitcoin) GetBlockHeader

func (b *Bitcoin) GetBlockHeader(blockHash string) (*GetBlockHeaderRes, error)

func (*Bitcoin) GetBlockHeight

func (b *Bitcoin) GetBlockHeight() (uint64, error)

func (*Bitcoin) GetChainInfo

func (b *Bitcoin) GetChainInfo() (*ChainInfo, error)

func (*Bitcoin) GetMempoolInfo

func (b *Bitcoin) GetMempoolInfo() (*MempoolInfo, error)

func (*Bitcoin) GetNewAddress

func (b *Bitcoin) GetNewAddress(addrType AddrType) (string, error)

func (*Bitcoin) GetRawBlock

func (b *Bitcoin) GetRawBlock(blockhash string) (string, error)

fetches raw block hex-string

func (*Bitcoin) GetRawtransaction

func (b *Bitcoin) GetRawtransaction(txId string) (string, error)

func (*Bitcoin) GetRawtransactionWithBlockHash

func (b *Bitcoin) GetRawtransactionWithBlockHash(txId string, blockHash string) (string, error)

func (*Bitcoin) GetTxOut

func (b *Bitcoin) GetTxOut(txid string, vout uint32) (*TxOutResp, error)

func (*Bitcoin) NextId

func (b *Bitcoin) NextId() *jrpc2.Id

for now, use a counter as the id for requests

func (*Bitcoin) Ping

func (b *Bitcoin) Ping() (bool, error)

func (*Bitcoin) Request

func (b *Bitcoin) Request(m jrpc2.Method, resp interface{}) error

Request takes a raw request and issues an RPC call to bitcoind.

func (*Bitcoin) SendRawTx

func (b *Bitcoin) SendRawTx(txstring string) (string, error)

func (*Bitcoin) SendToAddress

func (b *Bitcoin) SendToAddress(address, amount string) (string, error)

func (*Bitcoin) SetTimeout

func (b *Bitcoin) SetTimeout(secs uint)

func (*Bitcoin) StartUp

func (b *Bitcoin) StartUp(host, bitcoinDir string, port uint) error

type BlockVerbosity

type BlockVerbosity uint16
const (
	RawBlock BlockVerbosity = iota
	Json_TxId
	Json_TxData
)

FIXME: support options other than just raw block data

type ChainInfo

type ChainInfo struct {
	Chain                string               `json:"chain"`
	Blocks               uint32               `json:"blocks"`
	Headers              uint32               `json:"headers"`
	BestBlockHash        string               `json:"bestblockhash"`
	Difficulty           float64              `json:"difficulty"`
	MedianTime           uint64               `json:"mediantime"`
	VerificationProgress float64              `json:"verificationprogress"`
	InitialBlockDownload bool                 `json:"initialblockdownload"`
	ChainWork            string               `json:"chainwork"`
	SizeOnDisk           uint64               `json:"size_on_disk"`
	Pruned               bool                 `json:"pruned"`
	SoftForks            []*Fork              `json:"softforks"`
	Bip9SoftForks        map[string]*Bip9Fork `json:"softforks"`
	Warnings             string               `json:"warnings"`
}

type CreateRawTransactionReq

type CreateRawTransactionReq struct {
	Ins         []*TxIn           `json:"inputs"`
	Outs        []json.RawMessage `json:"outputs"`
	Locktime    *uint32           `json:"locktime,omitempty"`
	Replaceable *bool             `json:"replaceable,omitempty"`
}

func (*CreateRawTransactionReq) Name

func (r *CreateRawTransactionReq) Name() string

type DecodeRawTransactionReq

type DecodeRawTransactionReq struct {
	TxString  string `json:"hexstring"`
	IsWitness *bool  `json:"iswitness,omitempty"`
}

func (*DecodeRawTransactionReq) Name

func (r *DecodeRawTransactionReq) Name() string

type EchoRequest

type EchoRequest struct {
}

func (*EchoRequest) Name

func (r *EchoRequest) Name() string

type EstimateFeeRequest

type EstimateFeeRequest struct {
	Blocks uint32 `json:"conf_target"`
	Mode   string `json:"estimate_mode,omitempty"`
}

func (*EstimateFeeRequest) Name

func (r *EstimateFeeRequest) Name() string

type FeeResponse

type FeeResponse struct {
	FeeRate float64  `json:"feerate,omitempty"`
	Errors  []string `json:"errors,omitempty"`
	Blocks  uint32   `json:"blocks"`
}

func (*FeeResponse) SatPerKb

func (fr *FeeResponse) SatPerKb() uint64

type Fork

type Fork struct {
	Id      string     `json:"id"`
	Version uint       `json:"version"`
	Reject  *RejectObj `json:"reject"`
}

type FundRawOptions

type FundRawOptions struct {
	ChangeAddress   string `json:"changeAddress,omitempty"`
	ChangePosition  *uint  `json:"changePosition,omitempty"`
	ChangeType      string `json:"change_type,omitempty"`
	IncludeWatching *bool  `json:"includeWatching,omitempty"`
	LockUnspents    *bool  `json:"lockUnspents,omitempty"`
	FeeRate         string `json:"feeRate,omitempty"`
	// The fee will be equally deducted from the amount of each specified output.
	// Those recipients will receive less bitcoins than you enter in their
	//   corresponding amount field.
	// If no outputs are specified here, the sender pays the fee.
	// array values: The zero-based output index to deduct fee from,
	//   before a change output is added.
	SubtractFeeFromOutputs []uint `json:"subtractFeeFromOutputs,omitempty"`
	Replaceable            *bool  `json:"replaceable,omitempty"`
	ConfirmationTarget     uint   `json:"conf_target,omitempty"`
	EstimateMode           string `json:"estimate_mode,omitempty"`
}

type FundRawResult

type FundRawResult struct {
	TxString string  `json:"hex"`
	Fee      float64 `json:"fee"`
	// Position of the added change output, or -1
	ChangePosition int `json:"chanepos"`
}

func (*FundRawResult) HasChange

func (f *FundRawResult) HasChange() bool

type FundRawTransactionReq

type FundRawTransactionReq struct {
	TxString  string          `json:"hexstring"`
	Options   *FundRawOptions `json:"options,omitempty"`
	IsWitness *bool           `json:"iswitness,omitempty"`
}

func (*FundRawTransactionReq) Name

func (r *FundRawTransactionReq) Name() string

type GenerateToAddrRequest

type GenerateToAddrRequest struct {
	NumBlocks uint   `json:"nblocks"`
	Address   string `json:"address"`
	MaxTries  uint   `json:"maxtries,omitempty"`
}

func (*GenerateToAddrRequest) Name

func (r *GenerateToAddrRequest) Name() string

type GetBlockChainInfoRequest

type GetBlockChainInfoRequest struct{}

func (*GetBlockChainInfoRequest) Name

func (r *GetBlockChainInfoRequest) Name() string

type GetBlockCountReq

type GetBlockCountReq struct{}

func (*GetBlockCountReq) Name

func (r *GetBlockCountReq) Name() string

type GetBlockHashRequest

type GetBlockHashRequest struct {
	BlockHeight uint32 `json:"height"`
}

func (*GetBlockHashRequest) Name

func (r *GetBlockHashRequest) Name() string

type GetBlockHeaderReq

type GetBlockHeaderReq struct {
	BlockHash string
	Verbose   bool
}

func (*GetBlockHeaderReq) Name

func (r *GetBlockHeaderReq) Name() string

type GetBlockHeaderRes

type GetBlockHeaderRes struct {
	Hash              string  `json:"hash"`
	Confirmations     uint32  `json:"confirmations"`
	Height            uint32  `json:"height"`
	Version           uint32  `json:"version"`
	VersionHex        string  `json:"versionHex"`
	Merkleroot        string  `json:"merkleroot"`
	Time              uint64  `json:"time"`
	Mediantime        uint64  `json:"mediantime"`
	Nonce             uint32  `json:"nonce"`
	Bits              string  `json:"bits"`
	Difficulty        float64 `json:"difficulty"`
	Chainwork         string  `json:"chainwork"`
	NTx               uint32  `json:"nTx"`
	Previousblockhash string  `json:"previousblockhash"`
	Nextblockhash     string  `json:"nextblockhash"`
}

type GetBlockRequest

type GetBlockRequest struct {
	BlockHash string `json:"blockhash"`
	// valid options: 0,1,2
	Verbosity BlockVerbosity `json:"verbosity"`
}

func (*GetBlockRequest) Name

func (r *GetBlockRequest) Name() string

type GetMempoolInfoReq

type GetMempoolInfoReq struct{}

func (*GetMempoolInfoReq) Name

func (r *GetMempoolInfoReq) Name() string

type GetNewAddressRequest

type GetNewAddressRequest struct {
	Label       string `json:"label,omitempty"`
	AddressType string `json:"address_type,omitempty"`
}

func (*GetNewAddressRequest) Name

func (r *GetNewAddressRequest) Name() string

type GetRawTransactionReq

type GetRawTransactionReq struct {
	TxId      string `json:"txid"`
	Blockhash string `json:"blockhash,omitempty"`
}

func (*GetRawTransactionReq) Name

func (r *GetRawTransactionReq) Name() string

type GetTxOutRequest

type GetTxOutRequest struct {
	TxId           string `json:"txid"`
	Vout           uint32 `json:"n"`
	IncludeMempool bool   `json:"include_mempool"`
}

func (*GetTxOutRequest) Name

func (r *GetTxOutRequest) Name() string

type MempoolInfo

type MempoolInfo struct {
	Loaded           bool    `json:"loaded"`
	Size             uint32  `json:"size"`
	Bytes            uint64  `json:"bytes"`
	Usage            uint32  `json:"usage"`
	MaxMempool       uint32  `json:"maxmempool"`
	MempoolMinFee    float64 `json:"mempoolminfee"`
	MinRelayTxFee    float64 `json:"minrelaytxfee"`
	UnbroadcastCount uint32  `json:"unbroadcastcount"`
}

type OutScript

type OutScript struct {
	Script
	RequiredSigs uint     `json:"reqSigs"`
	Type         string   `json:"type"`
	Addresses    []string `json:"addresses"`
}

type PingRequest

type PingRequest struct{}

func (*PingRequest) Name

func (r *PingRequest) Name() string

type RejectObj

type RejectObj struct {
	Status bool `json:"status"`
}

type Script

type Script struct {
	Asm string `json:"asm"`
	Hex string `json:"hex"`
}

type SendRawTransactionReq

type SendRawTransactionReq struct {
	TxString      string `json:"hexstring"`
	AllowHighFees *bool  `json:"allowhighfees,omitempty"`
}

func (*SendRawTransactionReq) Name

func (r *SendRawTransactionReq) Name() string

type SendToAddrReq

type SendToAddrReq struct {
	Address               string `json:"address"`
	Amount                string `json:"amount"`
	Comment               string `json:"comment,omitempty"`
	CommentTo             string `json:"comment_to,omitempty"`
	SubtractFeeFromAmount bool   `json:"subtractfeefromamount,omitempty"`
	Replaceable           bool   `json:"replaceable,omitempty"`
	ConfirmationTarget    uint   `json:"conf_target,omitempty"`
	FeeEstimateMode       string `json:"estimate_mode,omitempty"`
}

func (*SendToAddrReq) Name

func (r *SendToAddrReq) Name() string

type Tx

type Tx struct {
	TxId        string      `json:"txid"`
	Hash        string      `json:"hash"`
	Size        uint        `json:"size"`
	VirtualSize uint        `json:"vsize"`
	Weight      uint        `json:"weight"`
	Version     uint        `json:"version"`
	Locktime    uint32      `json:"locktime"`
	Inputs      []*TxInput  `json:"vin"`
	Outputs     []*TxOutput `json:"vout"`
}

func (*Tx) FindOutputIndex

func (tx *Tx) FindOutputIndex(address string) (uint32, error)

type TxIn

type TxIn struct {
	TxId     string `json:"txid"`
	Vout     uint   `json:"vout"`
	Sequence uint   `json:"sequence,omitempty"`
}

type TxInput

type TxInput struct {
	TxId            string   `json:"txid"`
	Vout            uint     `json:"vout"`
	ScriptSignature *Script  `json:"scriptSig"`
	TxInWitness     []string `json:"txinwitness,omitempty"`
	Sequence        uint     `json:"sequence"`
}

type TxOut

type TxOut struct {
	Address string
	Satoshi uint64
}

func (*TxOut) Marshal

func (o *TxOut) Marshal() []byte

type TxOutResp

type TxOutResp struct {
	BestBlockHash string     `json:"bestblock"`
	Confirmations uint32     `json:"confirmations"`
	Value         float64    `json:"value"`
	ScriptPubKey  *OutScript `json:"scriptPubKey"`
	Coinbase      bool       `json:"coinbase"`
}

type TxOutput

type TxOutput struct {
	// The value in BTC
	Value        float64    `json:"value"`
	Index        uint       `json:"n"`
	ScriptPubKey *OutScript `json:"scriptPubKey"`
}

Jump to

Keyboard shortcuts

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