cleanup docs

This commit is contained in:
debris 2016-12-15 16:03:59 +01:00
parent ff7ead62c3
commit 721a31577b
28 changed files with 106 additions and 50 deletions

View File

@ -764,7 +764,7 @@ mod tests {
use chain::Block;
use super::super::{BlockRef, BlockLocation};
use test_data;
use primitives::Compact;
use primitives::compact::Compact;
#[test]
fn open_store() {

View File

@ -25,6 +25,7 @@ impl Iterator for BlkFile {
}
}
/// Creates iterator over bitcoind database blocks
pub fn open_blk_dir<P>(path: P) -> Result<BlkDir, io::Error> where P: AsRef<path::Path> {
let files = read_blk_dir(path)?.collect::<Result<BTreeSet<_>, _>>()?;
@ -41,6 +42,7 @@ pub fn open_blk_dir<P>(path: P) -> Result<BlkDir, io::Error> where P: AsRef<path
Ok(blk_dir)
}
/// Bitcoind database blocks iterator
pub struct BlkDir {
iter: Box<Iterator<Item = Result<Block, ReaderError>>>,
}

View File

@ -1,3 +1,5 @@
//! Bitcoind blockchain database importer
#[macro_use]
extern crate log;
extern crate primitives;
@ -10,4 +12,4 @@ mod fs;
pub use primitives::{hash, bytes};
pub use blk::{open_blk_file, open_blk_dir};
pub use blk::{open_blk_dir, BlkDir};

View File

@ -1,3 +1,5 @@
//! `AddressHash` with network identifier and format type
//!
//! A Bitcoin address, or simply address, is an identifier of 26-35 alphanumeric characters, beginning with the number 1
//! or 3, that represents a possible destination for a bitcoin payment.
//!
@ -25,6 +27,7 @@ pub enum Type {
P2SH,
}
/// `AddressHash` with network identifier and format type
#[derive(Debug, PartialEq)]
pub struct Address {
/// The type of the address.

View File

@ -1,10 +1,4 @@
//! Bitcoin keys.
//!
//! `Secret` - 32 bytes
//! `Public` - 65 bytes (TODO: make it optionally compressed)
//! `Private` - secret with additional network identifier (and compressed flag?)
//! `AddressHash` - 20 bytes derived from public
//! `Address` - addressh ash with network identifier and format type
extern crate rand;
extern crate rustc_serialize;
@ -15,10 +9,10 @@ extern crate secp256k1;
extern crate bitcrypto as crypto;
extern crate primitives;
mod address;
pub mod display;
pub mod generator;
pub mod keypair;
mod address;
mod display;
mod keypair;
mod error;
mod network;
mod private;
@ -28,19 +22,22 @@ mod signature;
pub use rustc_serialize::hex;
pub use primitives::{hash, bytes};
pub use self::address::{Type, Address};
pub use self::display::DisplayLayout;
pub use self::keypair::KeyPair;
pub use self::error::Error;
pub use self::private::Private;
pub use self::public::Public;
pub use self::signature::{Signature, CompactSignature};
pub use self::network::Network;
pub use address::{Type, Address};
pub use display::DisplayLayout;
pub use keypair::KeyPair;
pub use error::Error;
pub use private::Private;
pub use public::Public;
pub use signature::{Signature, CompactSignature};
pub use network::Network;
use hash::{H160, H256};
/// 20 bytes long hash derived from public `ripemd160(sha256(public))`
pub type AddressHash = H160;
/// 32 bytes long secret key
pub type Secret = H256;
/// 32 bytes long signable message
pub type Message = H256;
lazy_static! {

View File

@ -1,3 +1,5 @@
//! Secret with additional network identifier and format type
use std::fmt;
use std::str::FromStr;
use secp256k1::key;
@ -9,6 +11,7 @@ use hash::H520;
use network::Network;
use {Secret, DisplayLayout, Error, Message, Signature, CompactSignature, SECP256K1};
/// Secret with additional network identifier and format type
#[derive(PartialEq)]
pub struct Private {
/// The network on which this key should be used.

View File

@ -6,8 +6,11 @@ use crypto::dhash160;
use hash::{H264, H520};
use {AddressHash, Error, CompactSignature, Signature, Message, SECP256K1};
/// Secret public key
pub enum Public {
/// Normal version of public key
Normal(H520),
/// Compressed version of public key
Compressed(H264),
}

View File

@ -10,9 +10,7 @@ pub use verification::constants::{MAX_BLOCK_SIZE, MAX_BLOCK_SIGOPS};
const BLOCK_VERSION: u32 = 0x20000000;
const BLOCK_HEADER_SIZE: u32 = 4 + 32 + 32 + 4 + 4 + 4;
/// Block template as described in BIP0022
/// Minimal version
/// [BIP0022](https://github.com/bitcoin/bips/blob/master/bip-0022.mediawiki#block-template-request)
/// Block template as described in [BIP0022](https://github.com/bitcoin/bips/blob/master/bip-0022.mediawiki#block-template-request)
pub struct BlockTemplate {
/// Version
pub version: u32,

View File

@ -85,6 +85,7 @@ pub struct Solution {
}
/// Simple bitcoin cpu miner.
///
/// First it tries to find solution by changing block header nonce.
/// Once all nonce values have been tried, it increases extranonce.
/// Once all of them have been tried (quite unlikely on cpu ;),

View File

@ -14,8 +14,7 @@ const MAX_BITS_MAINNET: u32 = 0x1d00ffff;
const MAX_BITS_TESTNET: u32 = 0x1d00ffff;
const MAX_BITS_REGTEST: u32 = 0x207fffff;
/// Bitcoin network
/// https://bitcoin.org/en/glossary/mainnet
/// Bitcoin [network](https://bitcoin.org/en/glossary/mainnet)
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Magic {
/// The original and main network for Bitcoin transactions, where satoshis have real economic value.

View File

@ -1,6 +1,9 @@
//! Wrapper around `Vec<u8>`
use std::{ops, str, fmt, io, marker};
use hex::{ToHex, FromHex, FromHexError};
/// Wrapper around `Vec<u8>`
#[derive(Default, PartialEq, Clone)]
pub struct Bytes(Vec<u8>);
@ -92,6 +95,7 @@ impl AsMut<[u8]> for Bytes {
}
}
/// Wrapper around `Vec<u8>` which represent associated type
#[derive(Default, PartialEq, Clone)]
pub struct TaggedBytes<T> {
bytes: Bytes,

View File

@ -1,5 +1,8 @@
//! Compact representation of `U256`
use uint::U256;
/// Compact representation of `U256`
#[derive(Debug, PartialEq, Clone, Copy)]
pub struct Compact(u32);

View File

@ -1,3 +1,5 @@
//! Fixed-size hashes
use std::{fmt, ops, cmp, str};
use hex::{ToHex, FromHex, FromHexError};
use std::hash::{Hash, Hasher};

View File

@ -9,8 +9,3 @@ pub mod hash;
pub mod uint;
pub use rustc_serialize::hex;
pub use uint::U256;
pub use hash::{H160, H256};
pub use bytes::Bytes;
pub use compact::Compact;

View File

@ -1,13 +1,17 @@
//! Script builder
use bytes::Bytes;
use {Opcode, Script, Num};
use keys::AddressHash;
/// Script builder
#[derive(Default)]
pub struct Builder {
data: Bytes,
}
impl Builder {
/// Builds p2pkh script pubkey
pub fn build_p2pkh(address: &AddressHash) -> Script {
Builder::default()
.push_opcode(Opcode::OP_DUP)
@ -18,6 +22,7 @@ impl Builder {
.into_script()
}
/// Builds p2sh script pubkey
pub fn build_p2sh(address: &AddressHash) -> Script {
Builder::default()
.push_opcode(Opcode::OP_HASH160)
@ -26,11 +31,13 @@ impl Builder {
.into_script()
}
/// Pushes opcode to the end of script
pub fn push_opcode(mut self, opcode: Opcode) -> Self {
self.data.push(opcode as u8);
self
}
/// Appends bool push operation to the end of script
pub fn push_bool(mut self, value: bool) -> Self {
if value {
self.data.push(Opcode::OP_1 as u8);
@ -40,10 +47,12 @@ impl Builder {
self
}
/// Appends num push operation to the end of script
pub fn push_num(self, num: Num) -> Self {
self.push_data(&num.to_bytes())
}
/// Appends bytes push operation to the end od script
pub fn push_bytes(mut self, bytes: &[u8]) -> Self {
let len = bytes.len();
if len < 1 || len > 75 {
@ -57,6 +66,7 @@ impl Builder {
self
}
/// Appends data push operation to the end of script
pub fn push_data(mut self, data: &[u8]) -> Self {
let len = data.len();
if len < Opcode::OP_PUSHDATA1 as usize {
@ -82,17 +92,20 @@ impl Builder {
self
}
/// Appends `OP_RETURN` operation to the end of script
pub fn return_bytes(mut self, bytes: &[u8]) -> Self {
self.data.push(Opcode::OP_RETURN as u8);
self.data.extend_from_slice(bytes);
self
}
/// Pushes invalid opcode to the end of script
pub fn push_invalid_opcode(mut self) -> Self {
self.data.push(0xff);
self
}
/// Builds final script
pub fn into_script(self) -> Script {
Script::new(self.data)
}

View File

@ -1,6 +1,9 @@
//! Interpreter errors
use std::fmt;
use Opcode;
/// Interpreter errors
#[derive(Debug, PartialEq)]
pub enum Error {
Unknown,

View File

@ -1,5 +1,6 @@
//! Script verification flags.
//! Script interpreter verification flags
/// Script interpreter verification flags
#[derive(Default, Debug, PartialEq)]
pub struct VerificationFlags {
pub none: bool,

View File

@ -3,9 +3,9 @@ use bytes::Bytes;
use keys::{Signature, Public};
use chain::constants::SEQUENCE_LOCKTIME_DISABLE_FLAG;
use crypto::{sha1, sha256, dhash160, dhash256, ripemd160};
use sign::{SignatureVersion, Sighash};
use {
script, Script, Num, VerificationFlags, Opcode, Error,
Sighash, SignatureChecker, SignatureVersion, Stack
script, Script, Num, VerificationFlags, Opcode, Error, SignatureChecker, Stack
};
/// Helper function.
@ -225,6 +225,7 @@ fn cast_to_bool(data: &[u8]) -> bool {
!(last == 0 || last == 0x80)
}
/// Verifies script signature and pubkey
pub fn verify_script(
script_sig: &Script,
script_pubkey: &Script,
@ -286,6 +287,7 @@ pub fn verify_script(
Ok(())
}
/// Evaluautes the script
#[cfg_attr(feature="cargo-clippy", allow(match_same_arms))]
pub fn eval_script(
stack: &mut Stack<Bytes>,
@ -892,9 +894,10 @@ pub fn eval_script(
mod tests {
use bytes::Bytes;
use chain::Transaction;
use sign::SignatureVersion;
use {
Opcode, Script, VerificationFlags, Builder, Error, Num, TransactionInputSigner,
NoopSignatureChecker, SignatureVersion, TransactionSignatureChecker, Stack
NoopSignatureChecker, TransactionSignatureChecker, Stack
};
use super::{eval_script, verify_script, is_public_key};

View File

@ -26,10 +26,7 @@ pub use self::interpreter::{eval_script, verify_script};
pub use self::opcode::Opcode;
pub use self::num::Num;
pub use self::script::{Script, ScriptType, ScriptAddress};
pub use self::sign::{
TransactionInputSigner, UnsignedTransactionInput,
Sighash, SighashBase, SignatureVersion
};
pub use self::sign::{TransactionInputSigner, UnsignedTransactionInput};
pub use self::stack::Stack;
pub use self::verify::{SignatureChecker, NoopSignatureChecker, TransactionSignatureChecker};

View File

@ -1,8 +1,11 @@
//! Script numeric.
//! Script numeric
use std::ops;
use bytes::Bytes;
use Error;
/// Script numeric
///
/// Numeric opcodes (`OP_1ADD`, etc) are restricted to operating on 4-byte integers.
/// The semantics are subtle, though: operands must be in the range [-2^31 +1...2^31 -1],
/// but results may overflow (and are valid as long as they are not used in a subsequent

View File

@ -17,6 +17,7 @@ pub const MAX_PUBKEYS_PER_MULTISIG: usize = 20;
/// Maximum script length in bytes
pub const MAX_SCRIPT_SIZE: usize = 10000;
/// Classified script type
#[derive(PartialEq, Debug)]
pub enum ScriptType {
NonStandard,

View File

@ -1,3 +1,5 @@
//! Transaction signer
use bytes::Bytes;
use keys::KeyPair;
use crypto::dhash256;
@ -27,8 +29,7 @@ impl From<SighashBase> for u32 {
}
#[cfg_attr(feature="cargo-clippy", allow(doc_markdown))]
/// Documentation
/// https://en.bitcoin.it/wiki/OP_CHECKSIG#Procedure_for_Hashtype_SIGHASH_SINGLE
/// Signature hash type. [Documentation](https://en.bitcoin.it/wiki/OP_CHECKSIG#Procedure_for_Hashtype_SIGHASH_SINGLE)
#[derive(Debug, PartialEq, Clone, Copy)]
pub struct Sighash {
pub base: SighashBase,

View File

@ -3,8 +3,10 @@ use chain::constants::{
SEQUENCE_FINAL, SEQUENCE_LOCKTIME_DISABLE_FLAG,
SEQUENCE_LOCKTIME_MASK, SEQUENCE_LOCKTIME_TYPE_FLAG, LOCKTIME_THRESHOLD
};
use {SignatureVersion, Script, TransactionInputSigner, Num};
use sign::SignatureVersion;
use {Script, TransactionInputSigner, Num};
/// Checks transaction signature
pub trait SignatureChecker {
fn check_signature(
&self,

View File

@ -1,5 +1,4 @@
//! A type of variable-length integer commonly used in the Bitcoin P2P protocol and Bitcoin serialized data structures.
//! https://bitcoin.org/en/developer-reference#compactsize-unsigned-integers
//! Variable-length integer commonly used in the Bitcoin [P2P protocol](https://bitcoin.org/en/developer-reference#compactsize-unsigned-integers)
use std::{fmt, io};
use {

View File

@ -3,11 +3,11 @@ extern crate primitives;
mod compact_integer;
mod impls;
pub mod reader;
pub mod stream;
mod reader;
mod stream;
pub use primitives::{hash, bytes, compact};
pub use compact_integer::CompactInteger;
pub use self::reader::{Reader, Deserializable, deserialize, deserialize_iterator, ReadIterator, Error};
pub use self::stream::{Stream, Serializable, serialize, serialized_list_size};
pub use reader::{Reader, Deserializable, deserialize, deserialize_iterator, ReadIterator, Error};
pub use stream::{Stream, Serializable, serialize, serialized_list_size};

View File

@ -1,4 +1,4 @@
//! Stream used for serialization.
//! Stream used for serialization of Bitcoin structures
use std::io::{self, Write};
use std::borrow::Borrow;
use compact_integer::CompactInteger;
@ -26,7 +26,7 @@ pub trait Serializable {
}
}
/// Stream used for serialization.
/// Stream used for serialization of Bitcoin structures
#[derive(Default)]
pub struct Stream {
buffer: Vec<u8>,

20
tools/doc.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
cargo doc --no-deps\
-p bitcrypto\
-p chain\
-p db\
-p ethcore-devtools\
-p import\
-p keys\
-p message\
-p miner\
-p network\
-p pbtc\
-p p2p\
-p primitives\
-p rpc\
-p script\
-p serialization\
-p sync\
-p verification

View File

@ -1,4 +1,5 @@
use primitives::{H256, Compact};
use primitives::hash::H256;
use primitives::compact::Compact;
#[derive(Debug, PartialEq)]
/// All possible verification errors