From 7b0444e2fce33500d90b9aaa918a4454e2f65653 Mon Sep 17 00:00:00 2001 From: "myarbrough@oreilly.com" Date: Wed, 19 Nov 2014 06:16:52 -0800 Subject: [PATCH] Made changes to ch03.asciidoc --- ch03.asciidoc | 68 +++++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/ch03.asciidoc b/ch03.asciidoc index 54e8dbc5..5c19f1db 100644 --- a/ch03.asciidoc +++ b/ch03.asciidoc @@ -697,14 +697,15 @@ $ bitcoin-cli gettransaction 9ca8f969bd3ef5ec2a8685660fdbf7a8bd365524c2e1fc66c30 ---- [source,json] ----- +++++ + { "amount" : 0.05000000, "confirmations" : 1, - "blockhash" : "000000000000000051d2e759c63a26e247f185ecb7926ed7a6624bc31c2a717b", + "blockhash" : "000000000000000051d2e759c63a26e247f185ecb7926ed7a6624bc31c2a717b", "blockindex" : 18, "blocktime" : 1392660808, - "txid" : "9ca8f969bd3ef5ec2a8685660fdbf7a8bd365524c2e1fc66c309acbae2c14ae3", + "txid" : "9ca8f969bd3ef5ec2a8685660fdbf7a8bd365524c2e1fc66c309acbae2c14ae3", "time" : 1392660908, "timereceived" : 1392660908, "details" : [ @@ -716,7 +717,8 @@ $ bitcoin-cli gettransaction 9ca8f969bd3ef5ec2a8685660fdbf7a8bd365524c2e1fc66c30 } ] } ----- + +++++ Here, we see the new information in the entries +blockhash+ (the hash of the block in which the transaction was included), and +blockindex+ with value 18 (indicating that our transaction was the 18th transaction in that block). @@ -733,19 +735,21 @@ Commands: +getblock+, +getblockhash+ ((("bitcoin-cli command line helper","getblock command")))((("bitcoin-cli command line helper","getblockhash command")))((("blocks","exploring")))((("getblock command (bitcoin-cli)")))((("getblockhash command (bitcoin-cli)")))Now that we know which block our transaction was included in, we can query that block. We use the +getblock+ command with the block hash as the parameter: ----- -$ bitcoin-cli getblock 000000000000000051d2e759c63a26e247f185ecb7926ed7a6624bc31c2a717b true ----- +++++ + +$ bitcoin-cli getblock 000000000000000051d2e759c63a26e247f185ecb7926ed7a6624bc31c2a717b true + +++++ -[source,json] ----- +++++ + { - "hash" : "000000000000000051d2e759c63a26e247f185ecb7926ed7a6624bc31c2a717b", + "hash" : "000000000000000051d2e759c63a26e247f185ecb7926ed7a6624bc31c2a717b", "confirmations" : 2, "size" : 248758, "height" : 286384, "version" : 2, - "merkleroot" : "9891747e37903016c3b77c7a0ef10acf467c530de52d84735bd55538719f9916", + "merkleroot" : "9891747e37903016c3b77c7a0ef10acf467c530de52d84735bd55538719f9916", "tx" : [ "46e130ab3c67d31d2b2c7f8fbc1ca71604a72e6bc504c8a35f777286c6d89bf0", "2d5625725b66d6c1da88b80b41e8c07dc5179ae2553361c96b14bcf1ce2c3868", @@ -774,37 +778,42 @@ $ bitcoin-cli getblock 000000000000000051d2e759c63a26e247f185ecb7926ed7a6624bc31 "nonce" : 3888130470, "bits" : "19015f53", "difficulty" : 3129573174.52228737, - "chainwork" : "000000000000000000000000000000000000000000001931d1658fc04879e466", - "previousblockhash" : "0000000000000000177e61d5f6ba6b9450e0dade9f39c257b4d48b4941ac77e7", - "nextblockhash" : "0000000000000001239d2c3bf7f4c68a4ca673e434702a57da8fe0d829a92eb6" + "chainwork" : "000000000000000000000000000000000000000000001931d1658fc04879e466", + "previousblockhash" : "0000000000000000177e61d5f6ba6b9450e0dade9f39c257b4d48b4941ac77e7", + "nextblockhash" : "0000000000000001239d2c3bf7f4c68a4ca673e434702a57da8fe0d829a92eb6" } ----- + +++++ The block contains 367 transactions and as you can see, the 18th transaction listed (+9ca8f9...+) is the txid of the one crediting 50 millibits to our address. The +height+ entry tells us this is the 286384th block in the block chain. We can also retrieve a block by its block height using the +getblockhash+ command, which takes the block height as the parameter and returns the block hash for that block: ----- -$ bitcoin-cli getblockhash 0 -000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f ----- +++++ + +$ bitcoin-cli getblockhash 0000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f + +++++ Here, we retrieve the block hash of the "genesis block," the first block mined by Satoshi Nakamoto, at height zero. Retrieving this block shows: ----- -$ bitcoin-cli getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f ----- -[source,json] ----- +++++ + +$ bitcoin-cli getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f + +++++ + +++++ + { - "hash" : "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f", + "hash" : "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f", "confirmations" : 286388, "size" : 285, "height" : 0, "version" : 1, - "merkleroot" : "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b", + "merkleroot" : "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b", "tx" : [ "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b" ], @@ -812,10 +821,11 @@ $ bitcoin-cli getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60 "nonce" : 2083236893, "bits" : "1d00ffff", "difficulty" : 1.00000000, - "chainwork" : "0000000000000000000000000000000000000000000000000000000100010001", - "nextblockhash" : "00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048" + "chainwork" : "0000000000000000000000000000000000000000000000000000000100010001", + "nextblockhash" : "00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048" } ----- + +++++ The +getblock+, +getblockhash+, and +gettransaction+ commands can be used to explore the block chain database, programmatically.