bitcoin

package
v1.35.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IdMismatch = errors.New("Ids do not match!")
View Source
var IsTest = false
View Source
var JsonRpcMessage = `{"jsonrpc":"%s","id":%v,"method":"%s","params":%s}`
View Source
var JsonRpcVersion = "1.0"
View Source
var SatoshiPerByte = int64(200)

The steps notated in the variable names here relate to the steps outlined in https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses

View Source
var WeRequireAdditionalFunds = errors.New("Wallet address contains insufficient funds")

Errors

Functions

func CalculateFee

func CalculateFee(inputs, outputs int, feePerByte int64) int64

func CreateRawTransaction

func CreateRawTransaction(inputs []Input, outputs []Output) ([]byte, error)
NOTE: This function presumes you're doing a pay to public key hash

* transaction and using a single script to authenticate the entire thing. More * complex stuff will come later.

func CreateScriptPubKey

func CreateScriptPubKey(publicKeyBase58 string) ([]byte, error)

func CreateTransaction

func CreateTransaction(client BitcoinClient, origins []Origin, destinations []Destination, sender Sender, feePerByte int64) ([]byte, error)

func GenerateKeyPair

func GenerateKeyPair() (string, string, error)

func GetRawTransactionSignature

func GetRawTransactionSignature(rawTransaction []byte, pk string) ([]byte, error)

func PubKeyToAddress

func PubKeyToAddress(pubKey string, testNet bool) (string, []byte, error)

func Test

func Test(b bool) bool

Flip to Universal Test Mode

Types

type BitcoinClient

type BitcoinClient struct {
	IsTest   bool
	Commands []string
	Username string
	Password string
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, host, username, password string) BitcoinClient

New creates a new RPC client based on the provided connection configuration details. The notification handlers parameter may be nil if you are not interested in receiving notifications and will be ignored if the configuration is set to run in HTTP POST mode.

func (*BitcoinClient) GetRawTransaction

func (btcc *BitcoinClient) GetRawTransaction(txId string) (*JsonRpcResponse, error)

func (BitcoinClient) Post

func (c BitcoinClient) Post(jsonRpcCommand string, id int64) (*JsonRpcResponse, error)

func (*BitcoinClient) SendRawTransaction

func (btcc *BitcoinClient) SendRawTransaction(rawTransaction []byte) (string, error)

func (BitcoinClient) Test

func (c BitcoinClient) Test(b bool) bool

Flip to Test Mode

type Destination

type Destination struct {
	Value   int64
	Address string
}

A Destination is the boiled-back simplistic form of a Bitcoin Output, denoting only the basics - where you want the money to end up, and how much of it you want there.

type GetRawTransactionResponseError

type GetRawTransactionResponseError struct {
	Code    int
	Message string
}

type GetRawTransactionResponseResult

type GetRawTransactionResponseResult struct {
	Txid      string
	Hash      string
	Version   int
	Size      int
	Vsize     int
	Locktime  int
	Vin       []GetRawTransactionResponseResultInput
	Vout      []GetRawTransactionResponseResultOutput
	Hex       string
	Blockhash string
	Time      int64
	Blocktime int64
}

type GetRawTransactionResponseResultInput

type GetRawTransactionResponseResultInput struct {
	Txid        string
	Vout        int
	Scriptsig   GetRawTransactionResponseResultInputSig
	Txinwitness []string
	Sequence    int64
}

type GetRawTransactionResponseResultInputSig

type GetRawTransactionResponseResultInputSig struct {
	Asm string
	Hex string
}

type GetRawTransactionResponseResultOutput

type GetRawTransactionResponseResultOutput struct {
	N            int
	Value        float64
	Scriptpubkey GetRawTransactionResponseResultOutputScriptPubKey
}

type GetRawTransactionResponseResultOutputScriptPubKey

type GetRawTransactionResponseResultOutputScriptPubKey struct {
	Asm        string
	Hex        string
	ReqSigs    int
	ScriptType string `json:"type"`
	Addresses  []string
}

type Input

type Input struct {
	TxId        string
	OutputIndex int
	ScriptSig   []byte // This is not to be confused with the 'Script' of the Output. This is the key to the Script's lock.
}

An Input is a slightly more complete form of a Bitcoin Input, denoting everything the base algorithms need to do their job.

func OriginToInput

func OriginToInput(o Origin) Input

type JsonRpcError

type JsonRpcError struct {
	Code    int64  `json:"code"`
	Message string `json:"message"`
}

type JsonRpcResponse

type JsonRpcResponse struct {
	Id             int64         `json:"id"`
	JsonRpcVersion string        `json:"jsonrpc"`
	Result         ej.RawMessage `json:"result"`
	Error          JsonRpcError  `json:"error"`
}

type Origin

type Origin struct {
	TxId        string
	OutputIndex int
}

An Origin is the boiled-back simpistic form of a Bitcoin Input, denoting only the basics - where you want the money to come from.

func InputToOrigin

func InputToOrigin(in Input) Origin

func OriginsWithAmountToOrigins

func OriginsWithAmountToOrigins(oris []OriginWithAmount) []Origin

type OriginWithAmount

type OriginWithAmount struct {
	Origin
	Amount int64
}

An OriginWithAmount is the boiled-back simpistic form of a Bitcoin Input, denoting where you want the money to come from and the amount.

func GetBitcoinTransactions

func GetBitcoinTransactions(ctx context.Context, address string) ([]OriginWithAmount, error)

func PruneOriginsWithAmount

func PruneOriginsWithAmount(oris []OriginWithAmount, amount int64) ([]OriginWithAmount, error)

type Output

type Output struct {
	Value  int64
	Script []byte
}

An Output is a slightly more complete from of a Bitcoin Output, denoting everything the base algorithms need to do their job.

func DestinationToOutput

func DestinationToOutput(d Destination) Output

type Sender

type Sender struct {
	PrivateKey string
	PublicKey  string
	Address    string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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