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 ¶
- Constants
- type Tx
- func (t *Tx) FromBytes(line []byte) error
- func (t *Tx) FromRawTxString(rawTxString string) (err error)
- func (t *Tx) FromString(line string) (err error)
- func (t *Tx) FromTx(tx *transaction.Transaction) error
- func (t *Tx) InputAddresses() (addresses []string)
- func (t *Tx) OutputAddresses() (addresses []string)
- func (t *Tx) ToRawTxString() (string, error)
- func (t *Tx) ToString() (string, error)
- func (t *Tx) ToTx() (*transaction.Transaction, error)
Examples ¶
Constants ¶
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 ¶
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 ¶
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 ¶
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) FromRawTxString ¶
FromRawTxString takes a hex encoded tx string
func (*Tx) FromString ¶
FromString takes a BOB formatted string
func (*Tx) InputAddresses ¶ added in v0.0.13
InputAddresses returns the Bitcoin addresses for the transaction inputs
func (*Tx) OutputAddresses ¶ added in v0.0.13
OutputAddresses returns the Bitcoin addresses for the transaction outputs
func (*Tx) ToRawTxString ¶
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) 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