From 7c012eaa957108def0287abc27f6ac302dac2a53 Mon Sep 17 00:00:00 2001 From: Esteban Ordano Date: Mon, 24 Nov 2014 13:40:24 -0300 Subject: [PATCH] Block.md content. Remove blockheader doc --- docs/Block.md | 50 +++++++++++++++++++++++++++++++++++++++++++++ docs/Blockheader.md | 1 - docs/Transaction.md | 1 + 3 files changed, 51 insertions(+), 1 deletion(-) delete mode 100644 docs/Blockheader.md diff --git a/docs/Block.md b/docs/Block.md index 2d45d23..b35642e 100644 --- a/docs/Block.md +++ b/docs/Block.md @@ -1 +1,51 @@ # Block + +A Block instance represents the information on a block in the bitcoin network. +Note that creating it takes some computing power, as the tree of transactions +is created or verified. + +Given a hexa or base64 string representation of the serialization of a block +with its transactions, you can instantiate a Block instance. It will calculate +and check the merkle root hash (if enough data is provided), but transactions +won't neccesarily be valid spends, and this class won't validate them. A binary +representation as a `Buffer` instance is also valid input for a Block's +constructor. + +```javascript +assert(Block.isValidHeader(data); +assert(Block.isValidBlock(data); + +var block = new Block(hexaEncodedBlock); +assert(block.id && block.hash && block.id === block.hash); +assert(block.version === Block.CurrentVersion); +assert(block.prevHash); +assert(block.timestamp); +assert(block.nonce); +assert(block.size); +assert(block.transactions[0] instanceof Transaction); +``` + +## Navigating through transactions + +The set of transactions in a block can be explored by iterating on the block's +`transactions` member. + +```javascript +for (var transaction in block.transactions) { + // ... +} +``` + +It is also possible to explore a block's Merkle tree of transaction hashes. +Head to the [Merkle tree](./DataStructures.html#MerkleTree) documentation for +more information: + +```javascript +var root = block.tree.root; +assert(root instanceof bitcore.DataStructures.MerkleTree.Node); +assert(root.hash === block.id); +assert(root.isLeaf === false); +assert(root.left instanceof bitcore.DataStructures.MerkleTree.Node); +assert(root.right instanceof bitcore.DataStructures.MerkleTree.Node); +assert(root.left.left.left.left.content === block.transactions[0]); +``` diff --git a/docs/Blockheader.md b/docs/Blockheader.md deleted file mode 100644 index 253fb3d..0000000 --- a/docs/Blockheader.md +++ /dev/null @@ -1 +0,0 @@ -# Blockheader diff --git a/docs/Transaction.md b/docs/Transaction.md index cddee12..f8d6333 100644 --- a/docs/Transaction.md +++ b/docs/Transaction.md @@ -49,6 +49,7 @@ You can take a look at the javadocs for the [Transaction class here](link missing). This document will go over the expected high level use cases. * from(utxo) +* fromMultisig(utxo, pubkeys, threshold) * change(address) * fee(amount) * usingStrategy(strategy)