bt

package module
v2.4.6 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: ISC Imports: 19 Imported by: 10

README ΒΆ

πŸš€ go-bt

The go-to Bitcoin Transaction (BT) GoLang library (Forked from libsv/go-bt)

CIΒ /Β CD QualityΒ &Β Security DocsΒ &Β Meta Community
Latest Release
Build Status
CodeQL
SonarCloud
Go Report Card
Code Coverage
OpenSSF Scorecard
Security policy
Go version
Go docs
AGENTS.md rules
Makefile Supported
Dependabot
Contributors
Last commit
Sponsor

πŸ—‚οΈ Table of Contents


🧩 What's Inside

  • Full-featured Bitcoin transactions and transaction manipulation/functionality
  • Auto-fee calculations for change outputs
  • Transaction fee calculation and related checks
  • Interfaced signing/unlocking of transaction inputs for easy adaptation/customization and extendability for any use case
  • Bitcoin Transaction Script functionality
    • Bitcoin script engine (interpreter)
    • P2PKH (base58 addresses)
    • Data (OP_RETURN)
    • BIP276

πŸ“¦ Installation

go-bt requires a supported release of Go.

go get -u github.com/bsv-blockchain/go-bt/v2

πŸ“š Documentation

For more information around the technical aspects of Bitcoin, please see the updated Bitcoin Wiki


Repository Features
  • Continuous Integration on Autopilot with GitHub Actions – every push is built, tested, and reported in minutes.
  • Pull‑Request Flow That Merges Itself thanks to auto‑merge and hands‑free Dependabot auto‑merge.
  • One‑Command Builds powered by battle‑tested Make targets for linting, testing, releases, and more.
  • First‑Class Dependency Management using native Go Modules.
  • Uniform Code Style via gofumpt plus zero‑noise linting with golangci‑lint.
  • Confidence‑Boosting Tests with testify, the Go race detector, crystal‑clear HTML coverage snapshots, and automatic uploads to Codecov.
  • Hands‑Free Releases delivered by GoReleaser whenever you create a new Tag.
  • Relentless Dependency & Vulnerability Scans via Dependabot, Nancy, and govulncheck.
  • Security Posture by Default with CodeQL, OpenSSF Scorecard, and secret‑leak detection via gitleaks.
  • Automatic Syndication to pkg.go.dev on every release for instant godoc visibility.
  • Polished Community Experience using rich templates for Issues & PRs.
  • All the Right Meta Files (LICENSE, CONTRIBUTING.md, CODE_OF_CONDUCT.md, SUPPORT.md, SECURITY.md) pre‑filled and ready.
  • Code Ownership clarified through a CODEOWNERS file, keeping reviews fast and focused.
  • Zero‑Noise Dev Environments with tuned editor settings (.editorconfig) plus curated ignore files for VS Code, Docker, and Git.
  • Label Sync Magic: your repo labels stay in lock‑step with .github/labels.yml.
  • Friendly First PR Workflow – newcomers get a warm welcome thanks to a dedicated workflow.
  • Standards‑Compliant Docs adhering to the standard‑readme spec.
  • Instant Cloud Workspaces via Gitpod – spin up a fully configured dev environment with automatic linting and tests.
  • Out‑of‑the‑Box VS Code Happiness with a preconfigured Go workspace and .vscode folder with all the right settings.
  • Optional Release Broadcasts to your community via Slack, Discord, or Twitter – plug in your webhook.
  • AI Compliance Playbook – machine‑readable guidelines (AGENTS.md, CLAUDE.md, .cursorrules, sweep.yaml) keep ChatGPT, Claude, Cursor & Sweep aligned with your repo’s rules.
  • Pre-commit Hooks for Consistency powered by pre-commit and the .pre-commit-config.yaml fileβ€”run the same formatting, linting, and tests before every commit, just like CI.
  • Automated Hook Updates keep the .pre-commit-config.yaml current via a weekly workflow.
  • DevContainers for Instant Onboarding – Launch a ready-to-code environment in seconds with VS Code DevContainers and the included .devcontainer.json config.
Library Deployment

This project uses goreleaser for streamlined binary and library deployment to GitHub. To get started, install it via:

brew install goreleaser

The release process is defined in the .goreleaser.yml configuration file.

To generate a snapshot (non-versioned) release for testing purposes, run:

make release-snap

Then create and push a new Git tag using:

make tag version=x.y.z

This process ensures consistent, repeatable releases with properly versioned artifacts and citation metadata.

Makefile Commands

View all makefile commands

make help

List of all current commands:

bench                 ## Run all benchmarks in the Go application
build-go              ## Build the Go application (locally)
citation              ## Update version in CITATION.cff (use version=X.Y.Z)
clean-mods            ## Remove all the Go mod cache
coverage              ## Show test coverage
diff                  ## Show git diff and fail if uncommitted changes exist
fumpt                 ## Run fumpt to format Go code
generate              ## Run go generate in the base of the repo
godocs                ## Trigger GoDocs tag sync
govulncheck-install   ## Install govulncheck (pass VERSION= to override)
govulncheck           ## Scan for vulnerabilities
help                  ## Display this help message
install-go            ## Install using go install with specific version
install-releaser      ## Install GoReleaser
install-stdlib        ## Install the Go standard library for the host platform
install-template      ## Kick-start a fresh copy of go-template (run once!)
install               ## Install the application binary
lint-version          ## Show the golangci-lint version
lint                  ## Run the golangci-lint application (install if not found)
loc                   ## Total lines of code table
mod-download          ## Download Go module dependencies
mod-tidy              ## Clean up go.mod and go.sum
pre-build             ## Pre-build all packages to warm cache
release-snap          ## Build snapshot binaries
release-test          ## Run release dry-run (no publish)
release               ## Run production release (requires github_token)
tag-remove            ## Remove local and remote tag (use version=X.Y.Z)
tag-update            ## Force-update tag to current commit (use version=X.Y.Z)
tag                   ## Create and push a new tag (use version=X.Y.Z)
test-ci-no-race       ## CI test suite without race detector
test-ci               ## CI test runs tests with race detection and coverage (no lint - handled separately)
test-cover-race       ## Runs unit tests with race detector and outputs coverage
test-cover            ## Unit tests with coverage (no race)
test-fuzz             ## Run fuzz tests only (no unit tests)
test-no-lint          ## Run only tests (no lint)
test-parallel         ## Run tests in parallel (faster for large repos)
test-race             ## Unit tests with race detector (no coverage)
test-short            ## Run tests excluding integration tests (no lint)
test                  ## Default testing uses lint + unit tests (fast)
uninstall             ## Uninstall the Go binary
update-linter         ## Upgrade golangci-lint (macOS only)
update-releaser       ## Reinstall GoReleaser
update                ## Update dependencies
vet-parallel          ## Run go vet in parallel (faster for large repos)
vet                   ## Run go vet only on your module packages
GitHub Workflows
πŸŽ›οΈ The Workflow Control Center

All GitHub Actions workflows in this repository are powered by a single configuration file: .env.shared – your one-stop shop for tweaking CI/CD behavior without touching a single YAML file! 🎯

This magical file controls everything from:

  • πŸš€ Go version matrix (test on multiple versions or just one)
  • πŸƒ Runner selection (Ubuntu or macOS, your wallet decides)
  • πŸ”¬ Feature toggles (coverage, fuzzing, linting, race detection)
  • πŸ›‘οΈ Security tool versions (gitleaks, nancy, govulncheck)
  • πŸ€– Auto-merge behaviors (how aggressive should the bots be?)
  • 🏷️ PR management rules (size labels, auto-assignment, welcome messages)

Pro tip: Want to disable code coverage? Just flip ENABLE_CODE_COVERAGE=false in .env.shared and push. No YAML archaeology required!


Workflow Name Description
auto-merge-on-approval.yml Automatically merges PRs after approval and all required checks, following strict rules.
codeql.yml Analyzes code for security vulnerabilities using GitHub CodeQL.
dependabot-auto-merge.yml Automatically merges Dependabot PRs that meet all requirements.
fortress.yml Runs the GoFortress security and testing workflow, including linting, testing, releasing, and vulnerability checks.
pull-request-management.yml Labels PRs by branch prefix, assigns a default user if none is assigned, and welcomes new contributors with a comment.
scorecard.yml Runs OpenSSF Scorecard to assess supply chain security.
stale.yml Warns about (and optionally closes) inactive issues and PRs on a schedule or manual trigger.
sync-labels.yml Keeps GitHub labels in sync with the declarative manifest at .github/labels.yml.
update-python-dependencies.yml Updates Python dependencies for pre-commit hooks in the repository.
update-pre-commit-hooks.yml Automatically update versions for pre-commit hooks
Updating Dependencies

To update all dependencies (Go modules, linters, and related tools), run:

make update

This command ensures all dependencies are brought up to date in a single step, including Go modules and any tools managed by the Makefile. It is the recommended way to keep your development environment and CI in sync with the latest versions.

Pre-commit Hooks

Set up the optional pre-commit hooks to run the same formatting, linting, and tests defined in AGENTS.md before every commit:

pip install pre-commit
pre-commit install

The hooks are configured in .pre-commit-config.yaml and mirror the CI pipeline.


πŸ§ͺ Examples & Tests

All unit tests and examples run via GitHub Actions and use Go version 1.24.x. View the configuration file.

Run all tests (fast):

make test

Run all tests with race detector (slower):

make test-race

⚑ Benchmarks

Run the Go benchmarks:

make bench

Benchmark Results
Benchmark Iterations ns/op B/op allocs/op
[Bytes]-toBytesHelper 4,112,503 280.2 1024 1
[Clone]-clone 4,117,903 291.4 416 13
[ShallowClone]-clone 5,963,280 196.3 296 8

These benchmarks reflect fast, allocation-free lookups for most retrieval functions, ensuring optimal performance in production environments. Performance benchmarks for the core functions in this library, executed on an Apple M1 Max (ARM64).


πŸ› οΈ Code Standards

Read more about this Go project's code standards.


πŸ€– AI Compliance

This project documents expectations for AI assistants using a few dedicated files:

  • AGENTS.md β€” canonical rules for coding style, workflows, and pull requests used by Codex.
  • CLAUDE.md β€” quick checklist for the Claude agent.
  • .cursorrules β€” machine-readable subset of the policies for Cursor and similar tools.
  • sweep.yaml β€” rules for Sweep, a tool for code review and pull request management.

Edit AGENTS.md first when adjusting these policies, and keep the other files in sync within the same pull request.


πŸ‘₯ Maintainers

Siggi
Siggi

🀝 Contributing

View the contributing guidelines and please follow the code of conduct.

How can I help?

All kinds of contributions are welcome πŸ™Œ! The most basic way to show your support is to star 🌟 the project, or to raise issues πŸ’¬. You can also support this project by becoming a sponsor on GitHub πŸ‘

Stars


πŸ“ License

License

Documentation ΒΆ

Overview ΒΆ

Package bt provides functions needed to create and manipulate Bitcoin transactions.

Index ΒΆ

Constants ΒΆ

View Source
const (
	// MaxTxInSequenceNum is the maximum sequence number the sequence field
	// of a transaction input can be.
	MaxTxInSequenceNum uint32 = 0xffffffff

	// MaxPrevOutIndex is the maximum index the index field of a previous
	// outpoint can be.
	MaxPrevOutIndex uint32 = 0xffffffff

	// SequenceLockTimeDisabled is a flag that if set on a transaction
	// input's sequence number, the sequence number will not be interpreted
	// as a relative locktime.
	SequenceLockTimeDisabled = 1 << 31

	// SequenceLockTimeIsSeconds is a flag that if set on a transaction
	// input's sequence number, the relative locktime has units of 512
	// seconds.
	SequenceLockTimeIsSeconds = 1 << 22

	// SequenceLockTimeMask is a mask that extracts the relative locktime
	// when masked against the transaction input sequence number.
	SequenceLockTimeMask = 0x0000ffff
)
View Source
const DefaultSequenceNumber uint32 = 0xFFFFFFFF

DefaultSequenceNumber is the default starting sequence number

View Source
const (
	// DustLimit is the current minimum txo output accepted by miners.
	DustLimit = 1
)
View Source
const OrdinalsPrefix = "ord"

OrdinalsPrefix contains 'ORD' the inscription protocol prefix.

Check the docs here: https://docs.1satordinals.com/

Variables ΒΆ

View Source
var (
	ErrInvalidTxID       = errors.New("invalid TxID")
	ErrTxNil             = errors.New("tx is nil")
	ErrTxTooShort        = errors.New("too short to be a tx - even an empty tx has 10 bytes")
	ErrNLockTimeLength   = errors.New("nLockTime length must be 4 bytes long")
	ErrEmptyValues       = errors.New("empty value or values passed, all arguments are required and cannot be empty")
	ErrUnsupportedScript = errors.New("non-P2PKH input used in the tx - unsupported")
	ErrInvalidScriptType = errors.New("invalid script type")
	ErrNoUnlocker        = errors.New("unlocker not supplied")
)

General errors.

View Source
var (
	ErrInputNoExist  = errors.New("specified input does not exist")
	ErrInputTooShort = errors.New("input length too short")

	// ErrInputSatsZero is returned when the input Satoshi value is not provided.
	ErrInputSatsZero = errors.New("input satoshi value is not provided")
)

Sentinel errors reported by inputs.

View Source
var (
	ErrOutputNoExist  = errors.New("specified output does not exist")
	ErrOutputTooShort = errors.New("output length too short")
)

Sentinel errors reported by outputs.

View Source
var (
	ErrEmptyPreviousTxID     = errors.New("'PreviousTxID' not supplied")
	ErrEmptyPreviousTxScript = errors.New("'PreviousTxScript' not supplied")
)

Sentinel errors reported by signature hash.

View Source
var (
	ErrFeeQuotesNotInit = errors.New("feeQuotes have not been setup, call NewFeeQuotes")
	ErrMinerNoQuotes    = errors.New("miner has no quotes stored")
	ErrFeeTypeNotFound  = errors.New("feetype not found")
	ErrFeeQuoteNotInit  = errors.New("feeQuote has not been initialised, call NewFeeQuote()")
	ErrUnknownFeeType   = errors.New("unknown fee type")
)

Sentinel errors reported by the fees.

View Source
var (
	// ErrNoUTXO signals the UTXOGetterFunc has reached the end of its input.
	ErrNoUTXO = errors.New("no remaining utxos")

	// ErrInsufficientFunds insufficient funds provided for funding
	ErrInsufficientFunds = errors.New("insufficient funds provided")
)

Sentinel errors reported by the Fund.

View Source
var (
	ErrDummyInput            = errors.New("failed to add dummy input 0")
	ErrInsufficientUTXOs     = errors.New("need at least 2 utxos")
	ErrInsufficientUTXOValue = errors.New("need at least 1 utxos which is > ordinal price")
	ErrUTXOInputMismatch     = errors.New("utxo and input mismatch")
	ErrInvalidSellOffer      = errors.New("invalid sell offer (partially signed tx)")
	ErrEmptyScripts          = errors.New("at least one of needed scripts is empty")
	ErrInsufficientFees      = errors.New("fee paid not enough with new locking script")
)

Sentinel errors reported by PSBTs.

View Source
var (

	// ErrInsufficientInputs is returned when the total inputted satoshis are less than the outputted satoshis.
	ErrInsufficientInputs = errors.New("satoshis inputted to the tx are less than the outputted satoshis")
)

Sentinel errors reported by change.

View Source
var (
	// ErrOutputsNotEmpty is returned when the transaction outputs are not empty
	ErrOutputsNotEmpty = errors.New("transaction outputs must be empty to avoid messing with Ordinal ordering scheme")
)

Sentinel errors reported by ordinal inscriptions.

Functions ΒΆ

func IsValidTxID ΒΆ

func IsValidTxID(txid *chainhash.Hash) bool

IsValidTxID will check that the txid bytes are valid.

A txid should be of 32 bytes length.

func LittleEndianBytes ΒΆ

func LittleEndianBytes(v uint32, l uint32) []byte

LittleEndianBytes returns a byte array in little endian from an unsigned integer of 32 bytes.

func ReverseBytes ΒΆ

func ReverseBytes(a []byte) []byte

ReverseBytes reverses the bytes (little endian/big endian). This is used when computing merkle trees in Bitcoin, for example.

Types ΒΆ

type ExtendedTx ΒΆ

type ExtendedTx struct {
	*Tx
}

ExtendedTx wraps a *bt.Tx and provides a method to convert it back to *bt.Tx.

func (*ExtendedTx) ToTx ΒΆ

func (etx *ExtendedTx) ToTx() *Tx

ToTx returns the underlying *bt.Tx from the ExtendedTx.

type Fee ΒΆ

type Fee struct {
	FeeType   FeeType `json:"-"` // standard || data
	MiningFee FeeUnit `json:"miningFee"`
	RelayFee  FeeUnit `json:"relayFee"` // Fee for retaining Tx in secondary mempool
}

Fee displays the MiningFee as well as the RelayFee for a specific FeeType, for example 'standard' or 'data' see https://github.com/bitcoin-sv-specs/brfc-misc/tree/master/feespec

type FeeQuote ΒΆ

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

FeeQuote contains a thread safe map of fees for standard and data fees as well as an expiry time for a specific miner.

This can be used if you are only dealing with a single miner and know you will always be using a single miner. FeeQuote will store the fees for a single miner and can be passed to transactions to calculate fees when creating change outputs.

If you are dealing with quotes from multiple miners, use the FeeQuotes structure above.

NewFeeQuote() should be called to get a new instance of a FeeQuote.

When expiry expires ie Expired() == true then you should fetch new quotes from a MAPI server and call AddQuote with the fee information.

func NewFeeQuote ΒΆ

func NewFeeQuote() *FeeQuote

NewFeeQuote will set up and return a new FeeQuotes struct which contains default fees when initially setup. You would then pass this data structure to a singleton struct via injection for reading. If you are only getting quotes from one miner, you can use this directly instead of using the NewFeeQuotes() method which is for storing multiple miner quotes.

fq := NewFeeQuote()

The fees have an expiry time which, when initially setup, has expiry of now.UTC. This allows you to check for fq.Expired() and if true fetch a new set of fees from a MAPI server. This means the first check will always fetch the latest fees. If you want to just use default fees always, you can ignore the expired method and simply call the fq.Fee() method. https://github.com/bitcoin-sv-specs/brfc-merchantapi#payload

A basic example of usage is shown below:

func Fee(ft bt.FeeType) *bt.Fee{
   // you would not call this every time - this is just an example
   // you'd call this at app startup and store it / pass to a struct
   fq := NewFeeQuote()

   // fq setup with defaultFees
   if !fq.Expired() {
      // not expired, just return fee we have cached
      return fe.Fee(ft)
   }

   // cache expired, fetch new quotes
   var stdFee *bt.Fee
   var dataFee *bt.Fee

   // fetch quotes from MAPI server

   fq.AddQuote(bt.FeeTypeStandard, stdFee)
   fq.AddQuote(bt.FeeTypeData, dataFee)

   // MAPI returns a quote expiry
   exp, _ := time.Parse(time.RFC3339, resp.Quote.ExpirationTime)
   fq.UpdateExpiry(exp)
   return fe.Fee(ft)
}

It will set the expiry time to now.UTC which when expires will indicate that new quotes should be fetched from a MAPI server.

func (*FeeQuote) AddQuote ΒΆ

func (f *FeeQuote) AddQuote(ft FeeType, fee *Fee) *FeeQuote

AddQuote will add a new set of quotes for a feetype or update an existing quote if it already exists.

func (*FeeQuote) Expired ΒΆ

func (f *FeeQuote) Expired() bool

Expired will return true if the expiry time is before UTC now, this means we need to fetch fresh quotes from a MAPI server.

func (*FeeQuote) Expiry ΒΆ

func (f *FeeQuote) Expiry() time.Time

Expiry will return the expiry timestamp for the `bt.FeeQuote` in a threadsafe manner.

func (*FeeQuote) Fee ΒΆ

func (f *FeeQuote) Fee(t FeeType) (*Fee, error)

Fee will return a fee by type if found, nil and an error if not.

func (*FeeQuote) MarshalJSON ΒΆ

func (f *FeeQuote) MarshalJSON() ([]byte, error)

MarshalJSON will convert the FeeQuote to a json object with the format as shown:

 {
	 "data": {
		 "miningFee": {
			 "satoshis": 5,
			 "bytes": 2
		 },
		 "relayFee": {
			 "satoshis": 8,
			 "bytes": 4
		 }
	 },
	 "standard": {
		 "miningFee": {
			 "satoshis": 100,
			 "bytes": 10
		 },
		 "relayFee": {
			 "satoshis": 10,
			 "bytes": 5
		 }
	 }
 }

func (*FeeQuote) UnmarshalJSON ΒΆ

func (f *FeeQuote) UnmarshalJSON(body []byte) error

UnmarshalJSON will convert a JSON encoded FeeQuote back into a fee quote type, the expected JSON format is shown above in the MarshalJSON function. If the fee type supplied is unknown, an ErrUnknownFeeType will be returned.

func (*FeeQuote) UpdateExpiry ΒΆ

func (f *FeeQuote) UpdateExpiry(exp time.Time)

UpdateExpiry will update the expiry time of the quotes, this will be used when you fetch a fresh set of quotes from a MAPI server which should return an expiration time.

type FeeQuotes ΒΆ

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

FeeQuotes contains a list of miners and the current fees for each miner as well as their expiry.

This can be used when getting fees from multiple miners, and you want to use the cheapest, for example.

Usage setup should be calling NewFeeQuotes(minerName).

func NewFeeQuotes ΒΆ

func NewFeeQuotes(minerName string) *FeeQuotes

NewFeeQuotes will set up default feeQuotes for the minerName supplied, i.e., TAAL etc.

func (*FeeQuotes) AddMiner ΒΆ

func (f *FeeQuotes) AddMiner(minerName string, quote *FeeQuote) *FeeQuotes

AddMiner will add a new miner to the quote map with the provided feeQuote. If you just want to add default fees, use the AddMinerWithDefault method.

func (*FeeQuotes) AddMinerWithDefault ΒΆ

func (f *FeeQuotes) AddMinerWithDefault(minerName string) *FeeQuotes

AddMinerWithDefault will add a new miner to the quotes map with default fees and immediate expiry.

func (*FeeQuotes) Fee ΒΆ

func (f *FeeQuotes) Fee(minerName string, feeType FeeType) (*Fee, error)

Fee is a convenience method for quickly getting a fee by type and miner name. If the miner has no fees, an ErrMinerNoQuotes error will be returned. If the feeType cannot be found, an ErrFeeTypeNotFound error will be returned.

func (*FeeQuotes) Quote ΒΆ

func (f *FeeQuotes) Quote(minerName string) (*FeeQuote, error)

Quote will return all fees for a miner. If no fees are found, an ErrMinerNoQuotes error is returned.

func (*FeeQuotes) UpdateMinerFees ΒΆ

func (f *FeeQuotes) UpdateMinerFees(minerName string, feeType FeeType, fee *Fee) (*FeeQuote, error)

UpdateMinerFees a convenience method to update a fee quote from a FeeQuotes struct directly. This will update the miner feeType with the provided fee. Useful after receiving new quotes from mapi.

type FeeType ΒΆ

type FeeType string

FeeType is used to specify which type of fee is used depending on the type of tx data (e.g.: standard bytes or data bytes).

const (
	// FeeTypeStandard is the fee type for standard tx parts
	FeeTypeStandard FeeType = "standard"

	// FeeTypeData is the fee type for data tx parts
	FeeTypeData FeeType = "data"
)

type FeeUnit ΒΆ

type FeeUnit struct {
	Satoshis int `json:"satoshis"` // Fee in satoshis of the amount of Bytes
	Bytes    int `json:"bytes"`    // Number of bytes that the Fee covers
}

FeeUnit displays the amount of Satoshis needed for a specific amount of Bytes in a transaction see https://github.com/bitcoin-sv-specs/brfc-misc/tree/master/feespec

type Input ΒΆ

type Input struct {
	PreviousTxSatoshis uint64
	PreviousTxScript   *bscript.Script
	UnlockingScript    *bscript.Script
	PreviousTxOutIndex uint32
	SequenceNumber     uint32
	// contains filtered or unexported fields
}

Input is a representation of a transaction input

DO NOT CHANGE ORDER - Optimized for memory via maligned

func (*Input) Bytes ΒΆ

func (i *Input) Bytes(clearLockingScript bool, intoBytes ...[]byte) []byte

Bytes encodes the Input into a hex byte array.

func (*Input) ExtendedBytes ΒΆ

func (i *Input) ExtendedBytes(clearLockingScript bool, intoBytes ...[]byte) []byte

ExtendedBytes encodes the Input into a hex byte array, including the EF transaction format information.

func (*Input) MarshalJSON ΒΆ

func (i *Input) MarshalJSON() ([]byte, error)

MarshalJSON will convert an input to json, expanding upon the input struct to add additional fields.

func (*Input) PreviousTxID ΒΆ

func (i *Input) PreviousTxID() []byte

PreviousTxID will return the PreviousTxID if set.

func (*Input) PreviousTxIDAdd ΒΆ

func (i *Input) PreviousTxIDAdd(txIDHash *chainhash.Hash) error

PreviousTxIDAdd will add the supplied txID bytes to the Input if it isn't a valid transaction id an ErrInvalidTxID error will be returned.

func (*Input) PreviousTxIDAddStr ΒΆ

func (i *Input) PreviousTxIDAddStr(txID string) error

PreviousTxIDAddStr will validate and add the supplied txID string to the Input, if it isn't a valid transaction id an ErrInvalidTxID error will be returned.

func (*Input) PreviousTxIDChainHash ΒΆ

func (i *Input) PreviousTxIDChainHash() *chainhash.Hash

PreviousTxIDChainHash returns the PreviousTxID as a chainhash.Hash.

func (*Input) PreviousTxIDStr ΒΆ

func (i *Input) PreviousTxIDStr() string

PreviousTxIDStr returns the Previous TxID as a hex string.

func (*Input) ReadFrom ΒΆ

func (i *Input) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads from the `io.Reader` into the `bt.Input`.

func (*Input) ReadFromExtended ΒΆ

func (i *Input) ReadFromExtended(r io.Reader) (int64, error)

ReadFromExtended reads the `io.Reader` into the `bt.Input` when the reader is consuming an extended format transaction.

func (*Input) String ΒΆ

func (i *Input) String() string

String implements the Stringer interface and returns a string representation of a transaction input.

func (*Input) UnmarshalJSON ΒΆ

func (i *Input) UnmarshalJSON(b []byte) error

UnmarshalJSON will convert a JSON input to an input.

type Output ΒΆ

type Output struct {
	Satoshis      uint64          `json:"satoshis"`
	LockingScript *bscript.Script `json:"locking_script"`
}

Output is a representation of a transaction output

func CreateOpReturnOutput ΒΆ

func CreateOpReturnOutput(data [][]byte) (*Output, error)

CreateOpReturnOutput creates a new Output with OP_FALSE OP_RETURN and then uses OP_PUSHDATA format to encode the multiple byte arrays passed in.

func (*Output) Bytes ΒΆ

func (o *Output) Bytes(inBytes ...[]byte) []byte

Bytes encodes the Output into a byte array.

func (*Output) BytesForSigHash ΒΆ

func (o *Output) BytesForSigHash() []byte

BytesForSigHash returns the proper serialization of an output to be hashed and signed (sighash).

func (*Output) LockingScriptHexString ΒΆ

func (o *Output) LockingScriptHexString() string

LockingScriptHexString returns the locking script of an output encoded as a hex string.

func (*Output) MarshalJSON ΒΆ

func (o *Output) MarshalJSON() ([]byte, error)

MarshalJSON will serialize an output to json.

func (*Output) NodeJSON ΒΆ

func (o *Output) NodeJSON() interface{}

NodeJSON returns a wrapped *bt.Output for marshaling/unmarshalling into a node output format.

Marshaling usage example:

bb, err := json.Marshal(output.NodeJSON())

Unmarshalling usage example:

output := &bt.Output{}
if err := json.Unmarshal(bb, output.NodeJSON()); err != nil {}

func (*Output) ReadFrom ΒΆ

func (o *Output) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads from the `io.Reader` into the `bt.Output`.

func (*Output) String ΒΆ

func (o *Output) String() string

func (*Output) UnmarshalJSON ΒΆ

func (o *Output) UnmarshalJSON(b []byte) error

UnmarshalJSON will convert a json serialized output to a bt Output.

type Tx ΒΆ

type Tx struct {
	Inputs   []*Input  `json:"inputs"`
	Outputs  []*Output `json:"outputs"`
	Version  uint32    `json:"version"`
	LockTime uint32    `json:"locktime"`
	// contains filtered or unexported fields
}

Tx wraps a bitcoin transaction

DO NOT CHANGE ORDER - Optimized memory via malign

func NewTx ΒΆ

func NewTx() *Tx

NewTx creates a new transaction object with default values.

func NewTxFromBytes ΒΆ

func NewTxFromBytes(b []byte) (*Tx, error)

NewTxFromBytes takes an array of bytes, constructs a Tx and returns it. This function assumes that the byte slice contains exactly 1 transaction.

func NewTxFromStream ΒΆ

func NewTxFromStream(b []byte) (*Tx, int, error)

NewTxFromStream takes an array of bytes and constructs a Tx from it, returning the Tx and the bytes used. Despite the name, this is not reading a stream in the true sense: it is a byte slice that contains many transactions one after another.

func NewTxFromString ΒΆ

func NewTxFromString(str string) (*Tx, error)

NewTxFromString takes a toBytesHelper string representation of a bitcoin transaction and returns a Tx object.

func (*Tx) AddHashPuzzleOutput ΒΆ

func (tx *Tx) AddHashPuzzleOutput(secret, publicKeyHash string, satoshis uint64) error

AddHashPuzzleOutput makes an output to a hash puzzle + PKH with a value.

func (*Tx) AddOpReturnOutput ΒΆ

func (tx *Tx) AddOpReturnOutput(data []byte) error

AddOpReturnOutput creates a new Output with OP_FALSE OP_RETURN and then the data passed in encoded as hex.

func (*Tx) AddOpReturnPartsOutput ΒΆ

func (tx *Tx) AddOpReturnPartsOutput(data [][]byte) error

AddOpReturnPartsOutput creates a new Output with OP_FALSE OP_RETURN and then uses OP_PUSHDATA format to encode the multiple byte arrays passed in.

func (*Tx) AddOutput ΒΆ

func (tx *Tx) AddOutput(output *Output)

AddOutput adds a new output to the transaction.

func (*Tx) AddP2PKHInputsFromTx ΒΆ

func (tx *Tx) AddP2PKHInputsFromTx(pvsTx *Tx, matchPK []byte) error

AddP2PKHInputsFromTx will add all Outputs of given previous transaction that match a specific public key to your transaction.

func (*Tx) AddP2PKHOutputFromAddress ΒΆ

func (tx *Tx) AddP2PKHOutputFromAddress(addr string, satoshis uint64) error

AddP2PKHOutputFromAddress makes an output to a PKH with a value.

func (*Tx) AddP2PKHOutputFromBip32ExtKey ΒΆ

func (tx *Tx) AddP2PKHOutputFromBip32ExtKey(privKey *bip32.ExtendedKey, satoshis uint64) (string, error)

AddP2PKHOutputFromBip32ExtKey generated a random P2PKH output script from a provided *bip32.ExtendedKey, and add it to the receiving tx. The derviation path used is returned.

func (*Tx) AddP2PKHOutputFromPubKeyBytes ΒΆ

func (tx *Tx) AddP2PKHOutputFromPubKeyBytes(publicKeyBytes []byte, satoshis uint64) error

AddP2PKHOutputFromPubKeyBytes makes an output to a PKH with a value.

func (*Tx) AddP2PKHOutputFromPubKeyHashStr ΒΆ

func (tx *Tx) AddP2PKHOutputFromPubKeyHashStr(publicKeyHash string, satoshis uint64) error

AddP2PKHOutputFromPubKeyHashStr makes an output to a PKH with a value.

func (*Tx) AddP2PKHOutputFromPubKeyStr ΒΆ

func (tx *Tx) AddP2PKHOutputFromPubKeyStr(publicKey string, satoshis uint64) error

AddP2PKHOutputFromPubKeyStr makes an output to a PKH with a value.

func (*Tx) AddP2PKHOutputFromScript ΒΆ

func (tx *Tx) AddP2PKHOutputFromScript(script *bscript.Script, satoshis uint64) error

AddP2PKHOutputFromScript makes an output to a P2PKH script paid to the provided locking script with a value.

func (*Tx) Bytes ΒΆ

func (tx *Tx) Bytes() []byte

Bytes encodes the transaction into a byte array. See https://chainquery.com/bitcoin-cli/decoderawtransaction

func (*Tx) BytesWithClearedInputs ΒΆ

func (tx *Tx) BytesWithClearedInputs(index int, lockingScript []byte) []byte

BytesWithClearedInputs encodes the transaction into a byte array but clears its Inputs first. This is used when signing transactions.

func (*Tx) CalcInputPreimage ΒΆ

func (tx *Tx) CalcInputPreimage(inputNumber uint32, sigHashFlag sighash.Flag) ([]byte, error)

CalcInputPreimage serializes the transaction based on the input index and the SIGHASH flag and returns the preimage before double hashing (SHA256d).

see https://github.com/bitcoin-sv/bitcoin-sv/blob/master/doc/abc/replay-protected-sighash.md#digest-algorithm

func (*Tx) CalcInputPreimageLegacy ΒΆ

func (tx *Tx) CalcInputPreimageLegacy(inputNumber uint32, shf sighash.Flag) ([]byte, error)

CalcInputPreimageLegacy serializes the transaction based on the input index and the SIGHASH flag and returns the preimage before double hashing (SHA256d), in the legacy format.

see https://wiki.bitcoinsv.io/index.php/Legacy_Sighash_Algorithm

func (*Tx) CalcInputSignatureHash ΒΆ

func (tx *Tx) CalcInputSignatureHash(inputNumber uint32, sigHashFlag sighash.Flag) ([]byte, error)

CalcInputSignatureHash serialized the transaction and returns the hash digest to be signed. BitCoin (SV) uses a different signature hashing algorithm after the UAHF fork for replay protection.

see https://github.com/bitcoin-sv/bitcoin-sv/blob/master/doc/abc/replay-protected-sighash.md#digest-algorithm

func (*Tx) Change ΒΆ

func (tx *Tx) Change(s *bscript.Script, f *FeeQuote) error

Change calculates the number of fees needed to cover the transaction

and adds the leftover change in a new output using the script provided.

func (*Tx) ChangeToAddress ΒΆ

func (tx *Tx) ChangeToAddress(addr string, f *FeeQuote) error

ChangeToAddress calculates the number of fees needed to cover the transaction and adds the leftover change in a new P2PKH output using the address provided.

func (*Tx) ChangeToExistingOutput ΒΆ

func (tx *Tx) ChangeToExistingOutput(index uint, f *FeeQuote) error

ChangeToExistingOutput will calculate fees and add them to an output at the index specified (0 based). If an invalid index is supplied and error is returned.

func (*Tx) Clone ΒΆ

func (tx *Tx) Clone() *Tx

Clone returns a clone of the tx

func (*Tx) CloneTx ΒΆ

func (tx *Tx) CloneTx() *Tx

CloneTx returns a clone of the tx by bytes

func (*Tx) EstimateFeesPaid ΒΆ

func (tx *Tx) EstimateFeesPaid(fees *FeeQuote) (*TxFees, error)

EstimateFeesPaid will estimate how big the tx will be when finalized by estimating input unlocking scripts that have not yet been filled including the individual fee types (std/data/etc.).

func (*Tx) EstimateIsFeePaidEnough ΒΆ

func (tx *Tx) EstimateIsFeePaidEnough(fees *FeeQuote) (bool, error)

EstimateIsFeePaidEnough will calculate the fees that this transaction is paying including the individual fee types (std/data/etc.), and will add 107 bytes to the unlocking script of any unsigned inputs (only P2PKH for now) found to give a final size estimate of the tx size for fee calculation.

func (*Tx) EstimateSize ΒΆ

func (tx *Tx) EstimateSize() (int, error)

EstimateSize will return the size of tx in bytes and will add 107 bytes to the unlocking script of any unsigned inputs (only P2PKH for now) found to give a final size estimate of the tx size.

func (*Tx) EstimateSizeWithTypes ΒΆ

func (tx *Tx) EstimateSizeWithTypes() (*TxSize, error)

EstimateSizeWithTypes will return the size of tx in bytes, including the different data types (std/data/etc.), and will add 107 bytes to the unlocking script of any unsigned inputs (only P2PKH for now) found to give a final size estimate of the tx size.

func (*Tx) ExtendedBytes ΒΆ

func (tx *Tx) ExtendedBytes() []byte

ExtendedBytes outputs the transaction into a byte array in extended format (with PreviousTxSatoshis and PreviousTXScript included)

func (*Tx) FillAllInputs ΒΆ

func (tx *Tx) FillAllInputs(ctx context.Context, ug UnlockerGetter) error

FillAllInputs is used to sign all inputs. It takes an UnlockerGetter interface as a parameter so that different unlocking implementations can be used to sign the transaction - for example local/external signing, or P2PKH/contract signing.

Given this signs inputs and outputs, sighash `ALL|FORKID` is used.

func (*Tx) FillInput ΒΆ

func (tx *Tx) FillInput(ctx context.Context, unlocker Unlocker, params UnlockerParams) error

FillInput is used to unlock the transaction at a specific input index. It takes an Unlocker interface as a parameter so that different unlocking implementations can be used to unlock the transaction - for example local or external unlocking (hardware wallet), or signature / non-signature based.

func (*Tx) From ΒΆ

func (tx *Tx) From(prevTxID string, vout uint32, prevTxLockingScript string, satoshis uint64) error

From adds a new input to the transaction from the specified UTXO fields, using the default finalized sequence number (0xFFFFFFFF). If you want a different nSeq, change it manually afterward.

func (*Tx) FromUTXOs ΒΆ

func (tx *Tx) FromUTXOs(utxos ...*UTXO) error

FromUTXOs adds a new input to the transaction from the specified *bt.UTXO fields, using the default finalized sequence number (0xFFFFFFFF). If you want a different nSeq, change it manually afterward.

func (*Tx) Fund ΒΆ

func (tx *Tx) Fund(ctx context.Context, fq *FeeQuote, next UTXOGetterFunc) error

Fund continuously calls the provided bt.UTXOGetterFunc, adding each returned input as an input via tx.From(...), until it is estimated that inputs cover the outputs + fees.

After completion, the receiver is ready for `Change(...)` to be called, and then be signed. Note, this function works under the assumption that receiver *bt.Tx already has all the outputs which need covered.

If insufficient utxos are provided from the UTXOGetterFunc, a bt.ErrInsufficientFunds is returned.

Example usage:

if err := tx.Fund(ctx, bt.NewFeeQuote(), func(ctx context.Context, deficit satoshis) ([]*bt.UTXO, error) {
    utxos := make([]*bt.UTXO, 0)
    for _, f := range funds {
        deficit -= satoshis
        utxos := append(utxos, &bt.UTXO{
            TxID: f.TxID,
            Vout: f.Vout,
            LockingScript: f.Script,
            Satoshis: f.Satoshis,
        })
        if deficit == 0 {
            return utxos, nil
        }
    }
    return nil, bt.ErrNoUTXO
}); err != nil {
    if errors.Is(err, bt.ErrInsufficientFunds) { /* handle */ }
    return err
}

func (*Tx) HasDataOutputs ΒΆ

func (tx *Tx) HasDataOutputs() bool

HasDataOutputs returns true if the transaction has at least one data (OP_RETURN) output in it.

func (*Tx) InputCount ΒΆ

func (tx *Tx) InputCount() int

InputCount returns the number of transaction Inputs.

func (*Tx) InputIdx ΒΆ

func (tx *Tx) InputIdx(i int) *Input

InputIdx will return the input at the specified index.

This will consume an overflow error and simply return nil if the input isn't found at the index.

func (*Tx) Inscribe ΒΆ

func (tx *Tx) Inscribe(ia *bscript.InscriptionArgs) error

Inscribe adds an output to the transaction with an inscription.

func (*Tx) InscribeSpecificOrdinal ΒΆ

func (tx *Tx) InscribeSpecificOrdinal(ia *bscript.InscriptionArgs, inputIdx uint32, satoshiIdx uint64,
	extraOutputScript *bscript.Script,
) error

InscribeSpecificOrdinal gives you the functionality to choose a specific ordinal from the inputs to inscribe.

You need to provide the input and Satoshi range indices in order to specify the ordinal you would like to inscribe, along with the change addresses to be used for the rest of the Satoshis.

One output will be created with the extra Satoshis and then another output will be created with 1 Satoshi with the inscription in it.

func (*Tx) InsertInputUnlockingScript ΒΆ

func (tx *Tx) InsertInputUnlockingScript(index uint32, s *bscript.Script) error

InsertInputUnlockingScript applies a script to the transaction at a specific index in unlocking script field.

func (*Tx) IsCoinbase ΒΆ

func (tx *Tx) IsCoinbase() bool

IsCoinbase determines if this transaction is a coinbase by checking if the tx input is a standard coinbase input.

func (*Tx) IsExtended ΒΆ

func (tx *Tx) IsExtended() bool

IsExtended checks if the transaction is in extended format.

func (*Tx) IsFeePaidEnough ΒΆ

func (tx *Tx) IsFeePaidEnough(fees *FeeQuote) (bool, error)

IsFeePaidEnough will calculate the fees that this transaction is paying including the individual fee types (std/data/etc.).

func (*Tx) MarshalJSON ΒΆ

func (tx *Tx) MarshalJSON() ([]byte, error)

MarshalJSON will serialize a transaction to json.

func (*Tx) NodeJSON ΒΆ

func (tx *Tx) NodeJSON() interface{}

NodeJSON returns a wrapped *bt.Tx for marshaling/unmarshalling into a node tx format.

Marshaling usage example:

bb, err := json.Marshal(tx.NodeJSON())

Unmarshalling usage example:

tx := bt.NewTx()
if err := json.Unmarshal(bb, tx.NodeJSON()); err != nil {}

func (*Tx) OutputCount ΒΆ

func (tx *Tx) OutputCount() int

OutputCount returns the number of transaction Inputs.

func (*Tx) OutputIdx ΒΆ

func (tx *Tx) OutputIdx(i int) *Output

OutputIdx will return the output at the specified index.

This will consume an overflow error and simply return nil if the output isn't found at the index.

func (*Tx) OutputsHash ΒΆ

func (tx *Tx) OutputsHash(n int32) []byte

OutputsHash returns a bytes slice of the requested output, used for generating the txs signature hash. If n is -1, it will create the byte slice from all outputs.

func (*Tx) PayTo ΒΆ

func (tx *Tx) PayTo(script *bscript.Script, satoshis uint64) error

PayTo creates a new P2PKH output from a BitCoin address (base58) and the satoshis amount and adds that to the transaction.

func (*Tx) PayToAddress ΒΆ

func (tx *Tx) PayToAddress(addr string, satoshis uint64) error

PayToAddress creates a new P2PKH output from a BitCoin address (base58) and the satoshis amount and adds that to the transaction.

func (*Tx) PreviousOutHash ΒΆ

func (tx *Tx) PreviousOutHash() []byte

PreviousOutHash returns a byte slice of inputs outpoints, for creating a signature hash

func (*Tx) ReadFrom ΒΆ

func (tx *Tx) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads from the `io.Reader` into the `bt.Tx`.

func (*Tx) SequenceHash ΒΆ

func (tx *Tx) SequenceHash() []byte

SequenceHash returns a byte slice of inputs SequenceNumber, for creating a signature hash

func (*Tx) SerializeBytes ΒΆ added in v2.4.4

func (tx *Tx) SerializeBytes() []byte

SerializeBytes returns the serialized byte representation of the transaction. If the transaction is in extended format, it includes additional data such as PreviousTxSatoshis and PreviousTxScript.

func (*Tx) SetExtended ΒΆ

func (tx *Tx) SetExtended(extended bool)

SetExtended sets the extended flag for the transaction.

func (*Tx) SetTxHash ΒΆ

func (tx *Tx) SetTxHash(hash *chainhash.Hash)

SetTxHash should only be used when the transaction hash is known and the transaction will not change, this can be used to optimize processes that depend on the txid and avoid recalculating it

func (*Tx) ShallowClone ΒΆ

func (tx *Tx) ShallowClone() *Tx

ShallowClone returns a clone of the tx, but only clones the elements of the tx that are mutated in the signing process.

func (*Tx) Size ΒΆ

func (tx *Tx) Size() int

Size will return the size of tx in bytes.

func (*Tx) SizeWithTypes ΒΆ

func (tx *Tx) SizeWithTypes() *TxSize

SizeWithTypes will return the size of tx in bytes and include the different data types (std/data/etc.).

func (*Tx) String ΒΆ

func (tx *Tx) String() string

String encodes the transaction into a hex string.

func (*Tx) ToExtendedTx ΒΆ

func (tx *Tx) ToExtendedTx() *ExtendedTx

ToExtendedTx converts the Tx to an ExtendedTx if it is already extended.

func (*Tx) TotalInputSatoshis ΒΆ

func (tx *Tx) TotalInputSatoshis() (total uint64)

TotalInputSatoshis returns the total Satoshis inputted to the transaction.

func (*Tx) TotalOutputSatoshis ΒΆ

func (tx *Tx) TotalOutputSatoshis() (total uint64)

TotalOutputSatoshis returns the total Satoshis outputted from the transaction.

func (*Tx) TxID ΒΆ

func (tx *Tx) TxID() string

TxID returns the transaction ID of the transaction (which is also the transaction hash).

func (*Tx) TxIDBytes ΒΆ added in v2.3.3

func (tx *Tx) TxIDBytes() []byte

TxIDBytes returns the transaction ID of the transaction as bytes (which is also the transaction hash).

func (*Tx) TxIDChainHash ΒΆ

func (tx *Tx) TxIDChainHash() *chainhash.Hash

TxIDChainHash returns the transaction ID as a chainhash.Hash.

func (*Tx) UnmarshalJSON ΒΆ

func (tx *Tx) UnmarshalJSON(b []byte) error

UnmarshalJSON will unmarshal a transaction that has been marshaled with this library.

type TxFees ΒΆ

type TxFees struct {
	// TotalFeePaid is the total number of fees this tx will pay.
	TotalFeePaid uint64
	// StdFeePaid is the amount of fee to cover the standard inputs and outputs, etc.
	StdFeePaid uint64
	// DataFeePaid is the amount of fee to cover the op_return data outputs.
	DataFeePaid uint64
}

TxFees is returned when CalculateFee is called and contains a breakdown of the fees including the total and the size breakdown of the tx in bytes.

type TxSize ΒΆ

type TxSize struct {
	// TotalBytes are the number of bytes for the entire tx.
	TotalBytes uint64
	// TotalStdBytes are the number of bytes for the tx minus the data bytes.
	TotalStdBytes uint64
	// TotalDataBytes is the size in bytes of the op_return / data outputs.
	TotalDataBytes uint64
}

TxSize contains the size breakdown of a transaction including the breakdown of data bytes vs. standard bytes. This information can be used when calculating fees.

type Txs ΒΆ

type Txs []*Tx

Txs a collection of *bt.Tx.

func (*Txs) NodeJSON ΒΆ

func (tt *Txs) NodeJSON() interface{}

NodeJSON returns a wrapped bt.Txs for marshaling/unmarshalling into a node tx format.

Marshaling usage example:

bb, err := json.Marshal(txs.NodeJSON())

Unmarshalling usage example:

var txs bt.Txs
if err := json.Unmarshal(bb, txs.NodeJSON()); err != nil {}

func (*Txs) ReadFrom ΒΆ

func (tt *Txs) ReadFrom(r io.Reader) (int64, error)

ReadFrom txs from a block in a `bt.Txs`. This assumes a preceding varint detailing the total number of txs that the reader will provide.

type UTXO ΒΆ

type UTXO struct {
	TxIDHash       *chainhash.Hash `json:"txid"`
	Vout           uint32          `json:"vout"`
	LockingScript  *bscript.Script `json:"locking_script"`
	Satoshis       uint64          `json:"satoshis"`
	SequenceNumber uint32          `json:"sequence_number"`
	Unlocker       *Unlocker       `json:"-"`
}

UTXO an unspent transaction output, used for creating inputs

func (*UTXO) LockingScriptHexString ΒΆ

func (u *UTXO) LockingScriptHexString() string

LockingScriptHexString return the locking script in hex format.

func (*UTXO) MarshalJSON ΒΆ

func (u *UTXO) MarshalJSON() ([]byte, error)

MarshalJSON will serialize an utxo to JSON.

func (*UTXO) NodeJSON ΒΆ

func (u *UTXO) NodeJSON() interface{}

NodeJSON returns a wrapped *bt.UTXO for marshaling/unmarshaling into a node utxo format.

Marshaling usage example:

bb, err := json.Marshal(utxo.NodeJSON())

Unmarshalling usage example:

utxo := &bt.UTXO{}
if err := json.Unmarshal(bb, utxo.NodeJSON()); err != nil {}

func (*UTXO) TxIDStr ΒΆ

func (u *UTXO) TxIDStr() string

TxIDStr return the tx id as a string.

func (*UTXO) UnmarshalJSON ΒΆ

func (u *UTXO) UnmarshalJSON(body []byte) error

UnmarshalJSON will convert a JSON serialized utxo to a bt.UTXO.

type UTXOGetterFunc ΒΆ

type UTXOGetterFunc func(ctx context.Context, deficit uint64) ([]*UTXO, error)

UTXOGetterFunc is used for tx.Fund(...). It provides the amount of satoshis required for funding as `deficit`, and expects []*bt.UTXO to be returned containing utxos of which *bt.Input's can be built. If the returned []*bt.UTXO does not cover the deficit after fee recalculation, then this UTXOGetterFunc is called again, with the newly calculated deficit passed in.

It is expected that bt.ErrNoUTXO will be returned once the utxo source is depleted.

type UTXOs ΒΆ

type UTXOs []*UTXO

UTXOs a collection of *bt.UTXO.

func (*UTXOs) NodeJSON ΒΆ

func (u *UTXOs) NodeJSON() interface{}

NodeJSON returns a wrapped bt.UTXOs for marshaling/unmarshalling into a node utxo format.

Marshaling usage example:

bb, err := json.Marshal(utxos.NodeJSON())

Unmarshalling usage example:

var txs bt.UTXOs
if err := json.Unmarshal(bb, utxos.NodeJSON()); err != nil {}

type Unlocker ΒΆ

type Unlocker interface {
	UnlockingScript(ctx context.Context, tx *Tx, up UnlockerParams) (uscript *bscript.Script, err error)
}

Unlocker interface to allow custom implementations of different unlocking mechanisms. Implement the Unlocker function as shown in LocalUnlocker, for example.

type UnlockerGetter ΒΆ

type UnlockerGetter interface {
	Unlocker(ctx context.Context, lockingScript *bscript.Script) (Unlocker, error)
}

UnlockerGetter interfaces getting an unlocker for a given output/locking script.

type UnlockerParams ΒΆ

type UnlockerParams struct {
	// InputIdx the input to be unlocked. [DEFAULT 0]
	InputIdx uint32
	// SigHashFlags the be applied [DEFAULT ALL|FORKID]
	SigHashFlags sighash.Flag
}

UnlockerParams params used for unlocking an input with a `bt.Unlocker`.

type VarInt ΒΆ

type VarInt uint64

VarInt (variable integer) is a field used in transaction data to indicate the number of upcoming fields, or the length of an upcoming field. See http://learnmeabitcoin.com/glossary/varint

func NewVarIntFromBytes ΒΆ

func NewVarIntFromBytes(bb []byte) (VarInt, int)

NewVarIntFromBytes takes a byte array in VarInt format and returns the decoded unsigned integer value of the length, and it's size in bytes. See http://learnmeabitcoin.com/glossary/varint

func (VarInt) Bytes ΒΆ

func (v VarInt) Bytes() []byte

Bytes take the underlying unsigned integer and return a byte array in VarInt format. See http://learnmeabitcoin.com/glossary/varint

func (VarInt) Length ΒΆ

func (v VarInt) Length() int

Length return the length of the underlying byte representation of the `bt.VarInt`.

func (*VarInt) ReadFrom ΒΆ

func (v *VarInt) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the next varint from the io.Reader and assigned it to itself.

func (VarInt) UpperLimitInc ΒΆ

func (v VarInt) UpperLimitInc() int

UpperLimitInc returns true if a number is at the upper limit of a VarInt and will result in a VarInt length change if incremented. The value returned will indicate how many bytes will be increased if the length

is incremented. -1 will be returned when the upper limit

of VarInt is reached.

Directories ΒΆ

Path Synopsis
Package bscript comment
Package bscript comment
interpreter
Package interpreter implements the bitcoin transaction script language.
Package interpreter implements the bitcoin transaction script language.
interpreter/debug
Package debug comment
Package debug comment
interpreter/errs
Package errs comment
Package errs comment
interpreter/scriptflag
Package scriptflag comment
Package scriptflag comment
Package chainhash provides a type for representing hashes used in the Bitcoin protocol and provides functions for working with them.
Package chainhash provides a type for representing hashes used in the Bitcoin protocol and provides functions for working with them.
examples
create_ordinal_bid command
Package main demonstrates how to create a bid for an ordinal inscription using the go-bt library.
Package main demonstrates how to create a bid for an ordinal inscription using the go-bt library.
create_tx command
Package main demonstrates how to create a transaction using the go-bt library.
Package main demonstrates how to create a transaction using the go-bt library.
create_tx_with_inscription command
Package main demonstrates how to create a transaction with an inscription using the go-bt library.
Package main demonstrates how to create a transaction with an inscription using the go-bt library.
create_tx_with_opreturn command
Package main demonstrates how to create a transaction with an OP_RETURN output using the go-bt library.
Package main demonstrates how to create a transaction with an OP_RETURN output using the go-bt library.
marshal_node_list command
Package main demonstrates how to marshal a list of transactions into a Node JSON format using the go-bt library.
Package main demonstrates how to marshal a list of transactions into a Node JSON format using the go-bt library.
marshal_node_tx command
Package main demonstrates how to marshal a single transaction into a Node JSON format using the go-bt library.
Package main demonstrates how to marshal a single transaction into a Node JSON format using the go-bt library.
read_txs_from_block command
Package main demonstrates how to read transactions from a block file in a memory-efficient way using the go-bt library.
Package main demonstrates how to read transactions from a block file in a memory-efficient way using the go-bt library.
unlocker_getter command
Package main demonstrates how to implement a custom `bt.UnlockerGetter`
Package main demonstrates how to implement a custom `bt.UnlockerGetter`
unmarshal_node_list command
Package main demonstrates how to unmarshal a list of transactions from Node JSON format using the go-bt library.
Package main demonstrates how to unmarshal a list of transactions from Node JSON format using the go-bt library.
unmarshal_node_tx command
Package main demonstrates how to unmarshal a transaction from Node JSON format using the go-bt library.
Package main demonstrates how to unmarshal a transaction from Node JSON format using the go-bt library.
Package ord provides a simple example using the ordinals protocol
Package ord provides a simple example using the ordinals protocol
Package sighash comment
Package sighash comment
testing
data
Package data comment
Package data comment
Package unlocker comment
Package unlocker comment

Jump to

Keyboard shortcuts

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