diff --git a/README.md b/README.md index d4ea306d..a67182df 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,12 @@ is by no means exhaustive: attempts to insert a duplicate genesis block to illustrate how an invalid block is handled. +* [CompactToBig Example] + (http://godoc.org/github.com/conformal/btcchain#example-CompactToBig) + Demonstrates how to convert the "bits" in a block header which represent the + target difficulty to a big integer and display it using the typical hex + notation. + ## TODO - Increase test coverage diff --git a/doc.go b/doc.go index f9909cb4..75a29f8f 100644 --- a/doc.go +++ b/doc.go @@ -61,14 +61,6 @@ is by no means exhaustive: coins - Insert the block into the block database -Examples - - - ProcessBlock Example - Demonstrates how to create a new chain instance and use ProcessBlock to - attempt to attempt add a block to the chain. This example intentionally - attempts to insert a duplicate genesis block to illustrate how an invalid - block is handled. - Errors Errors returned by this package are either the raw errors provided by underlying diff --git a/example_test.go b/example_test.go index 3f88bf78..0ee7a583 100644 --- a/example_test.go +++ b/example_test.go @@ -57,3 +57,18 @@ func ExampleBlockChain_ProcessBlock() { // Output: // Failed to process block: already have block 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f } + +// This example demonstrates how to convert the "bits" in a block header which +// represent the target difficulty to a big integer and display it using the +// typical hex notation.. +func ExampleCompactToBig() { + // Convert the bits from block 300000 in the main block chain. + bits := uint32(419465580) + targetDifficulty := btcchain.CompactToBig(bits) + + // Display it in hex. + fmt.Printf("%064x\n", targetDifficulty.Bytes()) + + // Output: + // 0000000000000000896c00000000000000000000000000000000000000000000 +}