Coder Social home page Coder Social logo

bitcoin-da's Introduction

bitcoin-da:

This package provides a reader / writer interface to bitcoin.

Example:

// ExampleRelayer_Read tests that reading data from the blockchain works as
// expected.
func ExampleRelayer_Read() {
	// Example usage
	relayer, err := bitcoinda.NewRelayer(bitcoinda.Config{
		Host:         "localhost:18332",
		User:         "rpcuser",
		Pass:         "rpcpass",
		HTTPPostMode: true,
		DisableTLS:   true,
	})
	if err != nil {
		fmt.Println(err)
		return
	}
	_, err = relayer.Write([]byte("rollkit-btc: gm"))
	if err != nil {
		fmt.Println(err)
		return
	}
	// TODO: either mock or generate block
	// We're assuming the prev tx was mined at height 146
	height := uint64(146)
	blobs, err := relayer.Read(height)
	if err != nil {
		fmt.Println(err)
		return
	}
	for _, blob := range blobs {
		got, err := hex.DecodeString(fmt.Sprintf("%x", blob))
		if err != nil {
			fmt.Println(err)
			return
		}
		fmt.Println(string(got))
	}
	// Output: rollkit-btc: gm
}

Tests:

Running the tests requires a local regtest node.

bitcoind -chain=regtest -rpcport=18332 -rpcuser=rpcuser -rpcpassword=rpcpass -fallbackfee=0.000001 -txindex=1

bitcoin-cli -regtest -rpcport=18332 -rpcuser=rpcuser -rpcpassword=rpcpass createwallet w1

export COINBASE=$(bitcoin-cli -regtest -rpcport=18332 -rpcuser=rpcuser -rpcpassword=rpcpass getnewaddress)

bitcoin-cli -regtest -rpcport=18332 -rpcuser=rpcuser -rpcpassword=rpcpass generatetoaddress 101 $COINBASE

Idle for a while till coinbase coins mature.

=== RUN   ExampleRelayer_Write
--- PASS: ExampleRelayer_Write (0.13s)
=== RUN   ExampleRelayer_Read
--- PASS: ExampleRelayer_Read (0.10s)
PASS
ok      github.com/rollkit/bitcoin-da   0.375s

Writer:

A commit transaction containing a taproot with one leaf script

OP_FALSE
OP_IF
  "roll" marker
  <embedded data>
OP_ENDIF
<pubkey>
OP_CHECKSIG

is used to create a new bech32m address and is sent an output.

A reveal transaction then posts the embedded data on chain and spends the commit output.

Reader:

The address of the reveal transaction is implicity used as a namespace.

Clients may call listunspent on the reveal transaction address to get a list of transactions and read the embedded data from the first witness input.

Spec:

For more details, read the spec

bitcoin-da's People

Contributors

tuxcanfly avatar msevey avatar

Stargazers

Ganesh Prasad Kumble avatar  avatar  avatar Emmanuel T Odeke avatar Junho Yeo avatar  avatar Zorrot Chen avatar shane.stars avatar George Qing avatar Philip Glazman avatar  avatar Peter Pan avatar Shane | Side avatar codingcat avatar  avatar Qalqi avatar Peyton Randolph avatar Ian Culp avatar  avatar V.O.T avatar GITSRC avatar Nik B avatar logan avatar Nordau avatar pia avatar porco avatar bt3gl avatar bc1p avatar HangL avatar  avatar JW Rami avatar AK avatar jengener avatar ₿rat avatar Dimitar9 avatar Mark Odayan avatar Alien Coder avatar Etch avatar GianfrancoBazzani avatar 0xYYY avatar 22388o⚡️  avatar Stone Gao avatar Pratham Prasoon avatar HAOYUatHZ avatar  avatar rms rob avatar Roman Hossain Shaon avatar @RandyMcMillan avatar 开来超 avatar 3for avatar Shun Kakinoki avatar sam avatar  avatar 0x3639 avatar Rootul P avatar Gabriel Beaudoin avatar WakiyamaP avatar CHAMI Rachid avatar Hlib Kanunnikov avatar

Watchers

 avatar Tomasz Zdybał avatar  avatar Ismail Khoffi avatar Yarik Bratashchuk avatar Ganesha Upadhyaya avatar Manav Aggarwal avatar Kostas Georgiou avatar 3for avatar

bitcoin-da's Issues

docs: spec

The spec should be improved to cover additional cases with examples. Things like OP_DROP being the separator used to identify where the embedded data ends should be explained. There should be a way to handle a OP_DROP literal in the embedded data.

feat: namespaces

Right now the read path is scanning all transactions matching the script template we're using in the write path. So it's sort of permissionless but we don't have a namespaces yet. We could support namespaces by having an address derive from the namespace and updating the read path to accept the namespace, this also improves the reliability of the read path as it doesn't have to do template matching on the witness script, which is a bit flaky.

config: cleanup

Some variables that should be configurable but are currently hardcoded:

  • network
  • amounts
  • key pairs
  • rpc config

These should be configurable by callers of the library.

ci: docker

There needs to be a docker image which runs bitcoind in the background so that CI can automate tests.

writer: break into 520B chunks

The writer should break the embedded data into 520 byte chunks so that the data fits into the push data on the spendable tap script. The remaining N % 520 byte chunks can be pushed last.

writer: reveal tx

The writer should construct a reveal tx which spends the commit output by publishing a witness script containing the embedded data.

writer: commit tx

The writer should create a new commit transaction, containing a taproot output committing to the embedded data, which should be spendable by a configurable address that publishes the embedded data on chain.

reader: read data

The reader should take a configurable address, get a list of unspent outputs and read the witness to return embedded data.

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.