Add CompactToBig example.

This commit is contained in:
Dave Collins 2014-07-08 02:15:41 -05:00
parent 62c14b7001
commit 1a2baa3099
3 changed files with 21 additions and 8 deletions

View file

@ -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

8
doc.go
View file

@ -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

View file

@ -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
}