Giter Site home page Giter Site logo

go-bpu's Introduction

go-bpu

Transform Bitcoin Transactions into Virtual Procedure Call Units (Bitcoin Processing Unit)

bpu

Release Build Status Go
Mergify Status Sponsor Donate

Transforms raw transactions to BOB format. Port from the original bpu library by unwriter

Since this is intended to be used by low level transaction parsers dependencies are kept to a bare minimum. It does not include the RPC client functionality that connects to a node to get a raw tx. It's designed to be a fast raw tx to BOB processor.

There is also a Typescript version which does include the originally RPC functionality.

Installation

go-bpu requires a supported release of Go.

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

Documentation

View the generated documentation

GoDoc


Usage

Split Config

var separator = "|"
var l = bpu.IncludeL
var opReturn = uint8(106)
var opFalse = uint8(0)

var splitConfig = []SplitConfig{
	{
		Token: &Token{
			Op: &opReturn,
		},
		Include: &l,
	},
	{
		Token: &Token{
			Op: &opFalse,
		},
		Include: &l,
	},
	{
		Token: &Token{
			S: &separator,
		},
    Require: &opFalse,
	},
}

bpuTx, err := Parse(ParseConfig{RawTxHex: &sampleTx, SplitConfig: splitConfig, Mode: *bpu.Shallow})
if err != nil {
  fmt.Println(err)
}

Transaction Source

You can either use SplitConfig.RawTxHex and set by hex string, or use SplitConfig.Tx to set by bt.Tx.


Transform Function

You can pass an optional Transform function to bpu.Parse. Function should look something like this:

var splitTransform Transform = func(o Cell, c string) (to *Cell, e error) {
	// if the buffer is larger than 512 bytes,
	// replace the key with "l" prepended attribute
	to = &o
	bytes, err := hex.DecodeString(c)
	if err != nil {
		return nil, err
	}
	if len(bytes) > 512 {
		to.LS = to.S
		to.LB = to.B
		to.S = nil
		to.B = nil
	}
	return to, nil
}

More Usage details

See the Typescript library README for more examples of split configuration options, transformation, and a look at the output.


Errata

The original BPU library used bsv (javascript) v1.5 to determine if a script chunk was a valid opcode. At the time, the bsv library supported a limited number of OP codes (inherited from limitations imposed by Bitcoin core). In this version all opcodes are recognized which surfaces a new issue where fields previously available would be missing if the data is now recognized as an opcode.

Previously, BPU would omit the op and ops fields for non opcode data, while recognized opcodes would omit the s, b and h fields. To solve the issue of missing fields that happen to be opcodes, all keys are included if the recognized pushdata is also in the Printable ASCII range.


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! ๐Ÿš€

Stars


License

License

go-bpu's People

Contributors

rohenaz avatar dependabot[bot] avatar mrz1836 avatar mergify[bot] avatar icellan avatar

Stargazers

 avatar

Watchers

 avatar  avatar Kostas Georgiou avatar

Forkers

shruggr

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.