Skip to content

Commit

Permalink
readme: example
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxcanfly committed Feb 28, 2023
1 parent 3eb8171 commit 7d05de2
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,26 @@ This package provides a reader / writer interface to bitcoin.
Example:
========

// ExampleWrite tests that writing data to the blockchain works as expected.
func ExampleWrite() {
// ExampleRead tests that reading data from the blockchain works as expected.
func ExampleRead() {
// Example usage
fmt.Println("writing...")
_, err := rollkitbtc.Write([]byte("rollkit-btc: gm"))
hash, err := rollkitbtc.Write([]byte("rollkit-btc: gm"))
if err != nil {
fmt.Println(err)
return
}
fmt.Println("done")
// Output: writing...
// done
}

// ExampleRead tests that reading data from the blockchain works as expected.
func ExampleRead() {
// Example usage
fmt.Println("writing...")
hash, err := rollkitbtc.Write([]byte("rollkit-btc: gm"))
bytes, err := rollkitbtc.Read(hash)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("reading...")
_, err = rollkitbtc.Read(hash)
got, err := hex.DecodeString(fmt.Sprintf("%x", bytes))
if err != nil {
fmt.Println(err)
return
}
// fmt.Println(expected, got[1:16])
fmt.Println("done")
// Output: writing...
// reading...
// done
fmt.Println(string(got))
// Output: rollkit-btc: gm
}

Tests:
Expand Down

0 comments on commit 7d05de2

Please sign in to comment.