bob

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: MIT Imports: 10 Imported by: 5

README

go-bob

Go library for working with BOB formatted transactions

Release Build Status Report Go
Mergify Status Sponsor Donate


Table of Contents


Installation

go-bob requires a supported release of Go.

go get -u github.com/bitcoinschema/go-bob

Documentation

View the generated documentation

GoDoc

Features
Package Dependencies
Library Deployment

goreleaser for easy binary or library deployment to GitHub and can be installed via: brew install goreleaser.

The .goreleaser.yml file is used to configure goreleaser.

Use make release-snap to create a snapshot version of the release, and finally make release to ship to production.

Makefile Commands

View all makefile commands

make help

List of all current commands:

all                   Runs multiple commands
clean                 Remove previous builds and any test cache data
clean-mods            Remove all the Go mod cache
coverage              Shows the test coverage
diff                  Show the git diff
generate              Runs the go generate command in the base of the repo
godocs                Sync the latest tag with GoDocs
help                  Show this help message
install               Install the application
install-go            Install the application (Using Native Go)
install-releaser      Install the GoReleaser application
lint                  Run the golangci-lint application (install if not found)
release               Full production release (creates release in GitHub)
release               Runs common.release then runs godocs
release-snap          Test the full release (build binaries)
release-test          Full production test release (everything except deploy)
replace-version       Replaces the version in HTML/JS (pre-deploy)
tag                   Generate a new tag and push (tag version=0.0.0)
tag-remove            Remove a tag if found (tag-remove version=0.0.0)
tag-update            Update an existing tag to current commit (tag-update version=0.0.0)
test                  Runs lint and ALL tests
test-ci               Runs all tests via CI (exports coverage)
test-ci-no-race       Runs all tests via CI (no race) (exports coverage)
test-ci-short         Runs unit tests via CI (exports coverage)
test-no-lint          Runs just tests
test-short            Runs vet, lint and tests (excludes integration tests)
test-unit             Runs tests and outputs coverage
uninstall             Uninstall the application (and remove files)
update-linter         Update the golangci-lint package (macOS only)
vet                   Run the Go vet application

Examples & Tests

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

Run all tests (including integration tests)

make test

Run tests (excluding integration tests)

make test-short

Benchmarks

Run the Go benchmarks:

make bench

Code Standards

Read more about this Go project's code standards.


Usage

Checkout all the examples!

// Split BOB formatted NDJSON stream from Bitbus by line
line, err := reader.ReadBytes('\n')
if err == io.EOF {
  break
}

bobTx, err = bobData.NewFromBytes(line)
if err != nil {
  return err
}

BOB Tx will be of this type:

type Tx struct {
    In   []Input  `json:"in"`
    Out  []Output `json:"out"`
    ID   string   `json:"_id"`
    Tx   TxInfo   `json:"tx"`
    Blk  Blk      `json:"blk"`
    Lock uint32   `json:"lock"`
}
BOB Helpers
bobTx, err = NewFromBytes(tx)

BOB from bt.Tx

bobTx, err = NewFromTx(line)

BOB from raw tx string

bobTx, err := bob.NewFromRawTxString(rawTxString)

BOB to libsv.Transaction

tx, err = bobTx.ToTx()

BOB to string

tx, err = bobTx.ToString()

BOB to raw tx string

tx, err = bobTx.ToRawTxString()

Maintainers

MrZ MrZ
Satchmo MrZ

Contributing

View the contributing guidelines and 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 👏 or by making a bitcoin donation to ensure this journey continues indefinitely! 🚀


License

License

Documentation

Overview

Package bob is a library for working with BOB formatted transactions

Specs: https://bob.planaria.network/

If you have any suggestions or comments, please feel free to open an issue on this GitHub repository!

By BitcoinSchema Organization (https://bitcoinschema.org)

Index

Examples

Constants

View Source
const (
	ProtocolDelimiterAsm  = "OP_SWAP"
	ProtocolDelimiterInt  = 0x7c
	ProtocolDelimiterByte = byte(ProtocolDelimiterInt)
	ProtocolDelimiter     = string(rune(ProtocolDelimiterInt))
)

Protocol delimiter constants OP_SWAP = 0x7c = 124 = "|"

Variables

This section is empty.

Functions

This section is empty.

Types

type Tx

type Tx struct {
	bpu.Tx
}

Tx is a BOB formatted Bitcoin transaction

DO NOT CHANGE ORDER - aligned for memory optimization (malign)

func NewFromBytes

func NewFromBytes(line []byte) (bobTx *Tx, err error)

NewFromBytes creates a new BOB Tx from a NDJSON line representing a BOB transaction, as returned by the bitbus 2 API

Example

ExampleNewFromBytes example using NewFromBytes()

b, err := NewFromBytes([]byte(sampleBobTx))
if err != nil {
	fmt.Printf("error occurred: %s", err.Error())
	return
}
fmt.Printf("found tx: %s", b.Tx.Tx.H)
Output:

found tx: 207eaadc096849e037b8944df21a8bba6d91d8445848db047c0a3f963121e19d

func NewFromRawTxString

func NewFromRawTxString(rawTxString string) (bobTx *Tx, err error)

NewFromRawTxString creates a new BobTx from a hex encoded raw tx string

Example

ExampleNewFromRawTxString example using NewFromRawTxString()

b, err := NewFromRawTxString(rawBobTx)
if err != nil {
	fmt.Printf("error occurred: %s", err.Error())
	return
}
fmt.Printf("found tx: %s", b.Tx.Tx.H)
Output:

found tx: 9ec47d91ff11edb62f337dc828c52e39072d1a5a2f1b180bbfae9c3279d81a7c

func NewFromString

func NewFromString(line string) (bobTx *Tx, err error)

NewFromString creates a new BobTx from a BOB formatted string

Example

ExampleNewFromString example using NewFromString()

b, err := NewFromString(sampleBobTx)
if err != nil {
	fmt.Printf("error occurred: %s", err.Error())
	return
}
fmt.Printf("found tx: %s", b.Tx.Tx.H)
Output:

found tx: 207eaadc096849e037b8944df21a8bba6d91d8445848db047c0a3f963121e19d

func NewFromTx

func NewFromTx(tx *transaction.Transaction) (bobTx *Tx, err error)

NewFromTx creates a new BobTx from a libsv Transaction

Example

ExampleNewFromTx example using NewFromTx()

// Use an example TX
exampleTx := testExampleTx()

var b *Tx
var err error
if b, err = NewFromTx(exampleTx); err != nil {
	fmt.Printf("error occurred: %s", err.Error())
	return
}
fmt.Printf("found tx: %s", b.Tx.Tx.H)
Output:

found tx: f94e4adeac0cee5e9ff9985373622db9524e9f98d465dc024f85aec8acfeaf16

func (*Tx) FromBytes

func (t *Tx) FromBytes(line []byte) error

FromBytes takes a BOB formatted tx string as bytes

func (*Tx) FromRawTxString

func (t *Tx) FromRawTxString(rawTxString string) (err error)

FromRawTxString takes a hex encoded tx string

func (*Tx) FromString

func (t *Tx) FromString(line string) (err error)

FromString takes a BOB formatted string

func (*Tx) FromTx

func (t *Tx) FromTx(tx *transaction.Transaction) error

FromTx takes a bt.Tx

func (*Tx) InputAddresses added in v0.0.13

func (t *Tx) InputAddresses() (addresses []string)

InputAddresses returns the Bitcoin addresses for the transaction inputs

func (*Tx) OutputAddresses added in v0.0.13

func (t *Tx) OutputAddresses() (addresses []string)

OutputAddresses returns the Bitcoin addresses for the transaction outputs

func (*Tx) ToRawTxString

func (t *Tx) ToRawTxString() (string, error)

ToRawTxString converts the BOBTx to a libsv.transaction, and outputs the raw hex

Example

ExampleTx_ToRawTxString example using ToRawTxString()

// Use an example TX
bobTx, err := NewFromString(sampleBobTx)
if err != nil {
	fmt.Printf("error occurred: %s", err.Error())
	return
}

var rawTx string
if rawTx, err = bobTx.ToRawTxString(); err != nil {
	fmt.Printf("error occurred: %s", err.Error())
	return
}

fmt.Printf("found raw tx: %s", rawTx)
Output:

found raw tx: 0100000001f15a9d3c550c14e12ca066ad09edff31432f1e9f45894ecff5b70c8354c81f3d010000006b483045022100f012c3bd3781091aa8e53cab2ffcb90acced8c65500b41086fd225e48c98c1d702200b8ff117b8ecd2b2d7e95551bc5a1b3bbcca8049864479a28bed9dc842a86804412103ef5bb22964d529c0af748d9a6381432f05298e7a66ed2fe22e7975b1502528a7ffffffff0200000000000000001f006a15e4b880e781afe883bde999a4e58d83e5b9b4e69a970635386135393733b30100000000001976a9149c63715c6d1fa6c61b31d2911516e1c3db3bdfa888ac00000000

func (*Tx) ToString

func (t *Tx) ToString() (string, error)

ToString returns a json string of bobTx

func (*Tx) ToTx

func (t *Tx) ToTx() (*transaction.Transaction, error)

ToTx returns a bt.Tx

Example

ExampleTx_ToTx example using ToTx()

// Use an example TX
bobTx, err := NewFromString(sampleBobTx)
if err != nil {
	fmt.Printf("error occurred: %s", err.Error())
	return
}

var tx *transaction.Transaction
if tx, err = bobTx.ToTx(); err != nil {
	fmt.Printf("error occurred: %s", err.Error())
	return
}

fmt.Printf("found tx: %s", tx.TxID())
Output:

found tx: 207eaadc096849e037b8944df21a8bba6d91d8445848db047c0a3f963121e19d

Directories

Path Synopsis
examples
Package test is for testing
Package test is for testing

Jump to

Keyboard shortcuts

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