Documentation ¶
Index ¶
- Constants
- Variables
- func ExtractPushData(version uint16, pkScript []byte) ([]byte, error)
- type BitcoinDA
- func (b *BitcoinDA) Commit(ctx context.Context, daBlobs []da.Blob, ns da.Namespace) ([]da.Commitment, error)
- func (b *BitcoinDA) Get(ctx context.Context, ids []da.ID, ns da.Namespace) ([]da.Blob, error)
- func (b *BitcoinDA) GetIDs(ctx context.Context, height uint64, ns da.Namespace) ([]da.ID, error)
- func (b *BitcoinDA) GetProofs(ctx context.Context, daIDs []da.ID, ns da.Namespace) ([]da.Proof, error)
- func (b *BitcoinDA) MaxBlobSize(ctx context.Context) (uint64, error)
- func (b *BitcoinDA) Submit(ctx context.Context, daBlobs []da.Blob, gasPrice float64, ns da.Namespace) ([]da.ID, error)
- func (b *BitcoinDA) Validate(ctx context.Context, ids []da.ID, daProofs []da.Proof, ns da.Namespace) ([]bool, error)
- type Config
- type Relayer
Examples ¶
Constants ¶
const DefaultMaxBytes = 1048576
DefaultMaxBytes is the default max blob size
Variables ¶
var PROTOCOL_ID = []byte{0x72, 0x6f, 0x6c, 0x6c}
PROTOCOL_ID allows data identification by looking at the first few bytes
Functions ¶
Types ¶
type BitcoinDA ¶
type BitcoinDA struct {
// contains filtered or unexported fields
}
BitcoinDA is a Data Availability layer for Bitcoin.
func NewBitcoinDA ¶
NewBitcoinDA creates a new BitcoinDA.
func (*BitcoinDA) Commit ¶
func (b *BitcoinDA) Commit(ctx context.Context, daBlobs []da.Blob, ns da.Namespace) ([]da.Commitment, error)
Commit creates a Commitment for each given Blob.
func (*BitcoinDA) GetProofs ¶
func (b *BitcoinDA) GetProofs(ctx context.Context, daIDs []da.ID, ns da.Namespace) ([]da.Proof, error)
GetProofs returns the inclusion proofs for the given IDs.
func (*BitcoinDA) MaxBlobSize ¶
MaxBlobSize returns the max blob size
type Relayer ¶
type Relayer struct {
// contains filtered or unexported fields
}
Relayer is a bitcoin client wrapper which provides reader and writer methods to write binary blobs to the blockchain.
func NewRelayer ¶
NewRelayer returns a new relayer. It can error if there's an RPC connection error with the connection config.
func (Relayer) Read ¶
Example ¶
ExampleRelayer_Read tests that reading data from the blockchain works as expected.
package main import ( "encoding/hex" "fmt" bitcoinda "github.com/rollkit/bitcoin-da" ) func main() { // 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
func (Relayer) ReadTransaction ¶
ReadTransaction reads a transaction from the blockchain given a hash.
func (Relayer) Write ¶
Example ¶
ExampleRelayer_Write tests that writing data to the blockchain works as expected.
package main import ( "fmt" bitcoinda "github.com/rollkit/bitcoin-da" ) func main() { // 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 } fmt.Println("Writing...") _, err = relayer.Write([]byte("rollkit-btc: gm")) if err != nil { fmt.Println(err) return } fmt.Println("done") }
Output: Writing... done