1
0
mirror of https://github.com/romanz/electrs.git synced 2024-11-19 09:54:09 +01:00

Update rust-bitcoin to 0.15.1 and re-generate Cargo.lock

This commit is contained in:
Roman Zeyde 2018-11-10 21:38:58 +02:00
parent fbc5ed63fa
commit 6e5ec37091
12 changed files with 810 additions and 192 deletions

918
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -43,5 +43,5 @@ url = "1.0"
lru-cache = "0.1.1" lru-cache = "0.1.1"
[dependencies.bitcoin] [dependencies.bitcoin]
version = "0.14.1" version = "0.15.1"
features = ["serde"] features = ["serde"]

View File

@ -1,15 +0,0 @@
extern crate electrs;
#[macro_use]
extern crate log;
use electrs::config::Config;
use electrs::notify;
fn main() {
let _ = Config::from_args();
let rx = notify::run().into_receiver();
for blockhash in rx.iter() {
info!("block {}", blockhash.be_hex_string())
}
}

View File

@ -1,8 +1,6 @@
use bitcoin::blockdata::block::Block; use bitcoin::blockdata::block::Block;
use bitcoin::network::serialize::BitcoinHash; use bitcoin::consensus::encode::{deserialize, Decodable};
use bitcoin::network::serialize::SimpleDecoder; use bitcoin::util::hash::{BitcoinHash, Sha256dHash};
use bitcoin::network::serialize::{deserialize, RawDecoder};
use bitcoin::util::hash::Sha256dHash;
use libc; use libc;
use std::collections::HashSet; use std::collections::HashSet;
use std::fs; use std::fs;
@ -118,11 +116,9 @@ fn parse_blocks(blob: Vec<u8>, magic: u32) -> Result<Vec<Block>> {
let mut blocks = vec![]; let mut blocks = vec![];
let max_pos = blob.len() as u64; let max_pos = blob.len() as u64;
while cursor.position() < max_pos { while cursor.position() < max_pos {
let mut decoder = RawDecoder::new(cursor); match u32::consensus_decode(&mut cursor) {
match decoder.read_u32() {
Ok(value) => { Ok(value) => {
if magic != value { if magic != value {
cursor = decoder.into_inner();
cursor cursor
.seek(SeekFrom::Current(-3)) .seek(SeekFrom::Current(-3))
.expect("failed to seek back"); .expect("failed to seek back");
@ -131,9 +127,7 @@ fn parse_blocks(blob: Vec<u8>, magic: u32) -> Result<Vec<Block>> {
} }
Err(_) => break, // EOF Err(_) => break, // EOF
}; };
let block_size = decoder.read_u32().chain_err(|| "no block size")?; let block_size = u32::consensus_decode(&mut cursor).chain_err(|| "no block size")?;
cursor = decoder.into_inner();
let start = cursor.position() as usize; let start = cursor.position() as usize;
cursor cursor
.seek(SeekFrom::Current(block_size as i64)) .seek(SeekFrom::Current(block_size as i64))

View File

@ -1,9 +1,9 @@
use base64; use base64;
use bitcoin::blockdata::block::{Block, BlockHeader}; use bitcoin::blockdata::block::{Block, BlockHeader};
use bitcoin::blockdata::transaction::Transaction; use bitcoin::blockdata::transaction::Transaction;
use bitcoin::consensus::encode::{deserialize, serialize};
use bitcoin::network::constants::Network; use bitcoin::network::constants::Network;
use bitcoin::network::serialize::BitcoinHash; use bitcoin::util::hash::BitcoinHash;
use bitcoin::network::serialize::{deserialize, serialize};
use bitcoin::util::hash::Sha256dHash; use bitcoin::util::hash::Sha256dHash;
use glob; use glob;
use hex; use hex;
@ -558,7 +558,7 @@ impl Daemon {
} }
pub fn broadcast(&self, tx: &Transaction) -> Result<Sha256dHash> { pub fn broadcast(&self, tx: &Transaction) -> Result<Sha256dHash> {
let tx = hex::encode(serialize(tx).unwrap()); let tx = hex::encode(serialize(tx));
let txid = self.request("sendrawtransaction", json!([tx]))?; let txid = self.request("sendrawtransaction", json!([tx]))?;
Ok( Ok(
Sha256dHash::from_hex(txid.as_str().chain_err(|| "non-string txid")?) Sha256dHash::from_hex(txid.as_str().chain_err(|| "non-string txid")?)

View File

@ -1,8 +1,8 @@
use bincode; use bincode;
use bitcoin::blockdata::block::{Block, BlockHeader}; use bitcoin::blockdata::block::{Block, BlockHeader};
use bitcoin::blockdata::transaction::{Transaction, TxIn, TxOut}; use bitcoin::blockdata::transaction::{Transaction, TxIn, TxOut};
use bitcoin::network::serialize::BitcoinHash; use bitcoin::consensus::encode::{deserialize, serialize};
use bitcoin::network::serialize::{deserialize, serialize}; use bitcoin::util::hash::BitcoinHash;
use bitcoin::util::hash::Sha256dHash; use bitcoin::util::hash::Sha256dHash;
use crypto::digest::Digest; use crypto::digest::Digest;
use crypto::sha2::Sha256; use crypto::sha2::Sha256;
@ -227,7 +227,7 @@ pub fn index_transaction(txn: &Transaction, height: usize, blockhash: &Sha256dHa
} }
// Persist transaction ID and confirmed height // Persist transaction ID and confirmed height
rows.push(TxRow::new(&txid, height as u32, blockhash).to_row()); rows.push(TxRow::new(&txid, height as u32, blockhash).to_row());
rows.push(RawTxRow::new(&txid, serialize(txn).unwrap()).to_row()); // @TODO avoid re-serialization rows.push(RawTxRow::new(&txid, serialize(txn)).to_row()); // @TODO avoid re-serialization
} }
pub fn index_block(block: &Block, height: usize) -> Vec<Row> { pub fn index_block(block: &Block, height: usize) -> Vec<Row> {
@ -243,7 +243,7 @@ pub fn index_block(block: &Block, height: usize) -> Vec<Row> {
code: b'B', code: b'B',
hash: full_hash(&blockhash[..]), hash: full_hash(&blockhash[..]),
}).unwrap(), }).unwrap(),
value: serialize(&block.header).unwrap(), value: serialize(&block.header),
}); });
// Persist block metadata (size, number of txs and sum of txs weight) // Persist block metadata (size, number of txs and sum of txs weight)
@ -276,7 +276,7 @@ pub fn last_indexed_block(blockhash: &Sha256dHash) -> Row {
// Store last indexed block (i.e. all previous blocks were indexed) // Store last indexed block (i.e. all previous blocks were indexed)
Row { Row {
key: b"L".to_vec(), key: b"L".to_vec(),
value: serialize(blockhash).unwrap(), value: serialize(blockhash),
} }
} }

View File

@ -49,7 +49,6 @@ pub mod fake;
pub mod index; pub mod index;
pub mod mempool; pub mod mempool;
pub mod metrics; pub mod metrics;
pub mod notify;
pub mod query; pub mod query;
pub mod rpc; pub mod rpc;
pub mod signal; pub mod signal;

View File

@ -1,3 +1,5 @@
// TODO: network::socket::Socket needs to be reimplemented.
use bitcoin::network::constants::Network; use bitcoin::network::constants::Network;
use bitcoin::network::message::NetworkMessage; use bitcoin::network::message::NetworkMessage;
use bitcoin::network::message_blockdata::InvType; use bitcoin::network::message_blockdata::InvType;

View File

@ -1,6 +1,6 @@
use bitcoin::blockdata::block::Block; use bitcoin::blockdata::block::Block;
use bitcoin::blockdata::transaction::Transaction; use bitcoin::blockdata::transaction::Transaction;
use bitcoin::network::serialize::{serialize,deserialize}; use bitcoin::consensus::encode::{serialize, deserialize};
use bitcoin::util::hash::Sha256dHash; use bitcoin::util::hash::Sha256dHash;
use crypto::digest::Digest; use crypto::digest::Digest;
use crypto::sha2::Sha256; use crypto::sha2::Sha256;
@ -450,7 +450,7 @@ impl Query {
// Get raw transaction from txstore or the in-memory mempool Tracker // Get raw transaction from txstore or the in-memory mempool Tracker
pub fn tx_get_raw(&self, txid: &Sha256dHash) -> Option<Bytes> { pub fn tx_get_raw(&self, txid: &Sha256dHash) -> Option<Bytes> {
rawtxrow_by_txid(self.app.read_store(), txid).map(|row| row.rawtx) rawtxrow_by_txid(self.app.read_store(), txid).map(|row| row.rawtx)
.or_else(|| self.tracker.read().unwrap().get_txn(&txid).map(|tx| serialize(&tx).expect("cannot serialize tx from mempool"))) .or_else(|| self.tracker.read().unwrap().get_txn(&txid).map(|tx| serialize(&tx)))
} }
// Public API for transaction retrieval (for Electrum RPC) // Public API for transaction retrieval (for Electrum RPC)

View File

@ -1,6 +1,6 @@
use bitcoin::util::hash::{Sha256dHash,HexError}; use bitcoin::util::hash::{Sha256dHash,HexError};
use bitcoin::network::serialize::serialize; use bitcoin::consensus::encode::{self, serialize};
use bitcoin::{Script,network,BitcoinHash}; use bitcoin::{Script, BitcoinHash};
use config::Config; use config::Config;
use bitcoin::{TxIn,TxOut,Transaction}; use bitcoin::{TxIn,TxOut,Transaction};
use bitcoin::util::address::Address; use bitcoin::util::address::Address;
@ -80,7 +80,7 @@ impl From<Transaction> for TransactionValue {
fn from(tx: Transaction) -> Self { fn from(tx: Transaction) -> Self {
let vin = tx.input.iter().map(|el| TxInValue::from(el.clone())).collect(); let vin = tx.input.iter().map(|el| TxInValue::from(el.clone())).collect();
let vout = tx.output.iter().map(|el| TxOutValue::from(el.clone())).collect(); let vout = tx.output.iter().map(|el| TxOutValue::from(el.clone())).collect();
let bytes = serialize(&tx).unwrap(); let bytes = serialize(&tx);
TransactionValue { TransactionValue {
txid: tx.txid(), txid: tx.txid(),
@ -594,8 +594,8 @@ impl From<serde_json::Error> for HttpError {
HttpError::generic() HttpError::generic()
} }
} }
impl From<network::serialize::Error> for HttpError { impl From<encode::Error> for HttpError {
fn from(_e: network::serialize::Error) -> Self { fn from(_e: encode::Error) -> Self {
//HttpError::from(e.description().to_string()) //HttpError::from(e.description().to_string())
HttpError::generic() HttpError::generic()
} }

View File

@ -1,5 +1,5 @@
use bitcoin::blockdata::transaction::Transaction; use bitcoin::blockdata::transaction::Transaction;
use bitcoin::network::serialize::{deserialize, serialize}; use bitcoin::consensus::encode::{deserialize, serialize};
use bitcoin::util::address::Address; use bitcoin::util::address::Address;
use bitcoin::util::hash::Sha256dHash; use bitcoin::util::hash::Sha256dHash;
use error_chain::ChainedError; use error_chain::ChainedError;
@ -99,7 +99,7 @@ impl Connection {
fn blockchain_headers_subscribe(&mut self) -> Result<Value> { fn blockchain_headers_subscribe(&mut self) -> Result<Value> {
let entry = self.query.get_best_header()?; let entry = self.query.get_best_header()?;
let hex_header = hex::encode(serialize(entry.header()).unwrap()); let hex_header = hex::encode(serialize(entry.header()));
let result = json!({"hex": hex_header, "height": entry.height()}); let result = json!({"hex": hex_header, "height": entry.height()});
self.last_header_entry = Some(entry); self.last_header_entry = Some(entry);
Ok(result) Ok(result)
@ -133,7 +133,7 @@ impl Connection {
.query .query
.get_headers(&heights) .get_headers(&heights)
.into_iter() .into_iter()
.map(|entry| hex::encode(&serialize(entry.header()).unwrap())) .map(|entry| hex::encode(&serialize(entry.header())))
.collect(); .collect();
Ok(json!({ Ok(json!({
"count": headers.len(), "count": headers.len(),
@ -156,13 +156,13 @@ impl Connection {
let height = usize_from_value(params.get(0), "missing height")?; let height = usize_from_value(params.get(0), "missing height")?;
let entries = self.query.get_headers(&[height]); let entries = self.query.get_headers(&[height]);
let block = self.query.get_block(&entries.get(0).unwrap().hash()); let block = self.query.get_block(&entries.get(0).unwrap().hash());
let block_hex = hex::encode(serialize(&block.unwrap()).unwrap()); let block_hex = hex::encode(serialize(&block.unwrap()));
Ok(json!({"hex": &block_hex})) Ok(json!({"hex": &block_hex}))
} }
fn blockchain_block_get(&self, params: &[Value]) -> Result<Value> { fn blockchain_block_get(&self, params: &[Value]) -> Result<Value> {
let block_hash = hash_from_value(params.get(0)).chain_err(|| "bad block_hash")?; let block_hash = hash_from_value(params.get(0)).chain_err(|| "bad block_hash")?;
let block = self.query.get_block(&block_hash); let block = self.query.get_block(&block_hash);
let block_hex = hex::encode(serialize(&block.unwrap()).unwrap()); let block_hex = hex::encode(serialize(&block.unwrap()));
Ok(json!({"hex": &block_hex})) Ok(json!({"hex": &block_hex}))
} }
@ -347,7 +347,7 @@ impl Connection {
let entry = self.query.get_best_header()?; let entry = self.query.get_best_header()?;
if *last_entry != entry { if *last_entry != entry {
*last_entry = entry; *last_entry = entry;
let hex_header = hex::encode(serialize(last_entry.header()).unwrap()); let hex_header = hex::encode(serialize(last_entry.header()));
let header = json!({"hex": hex_header, "height": last_entry.height()}); let header = json!({"hex": hex_header, "height": last_entry.height()});
result.push(json!({ result.push(json!({
"jsonrpc": "2.0", "jsonrpc": "2.0",

View File

@ -1,6 +1,6 @@
use bitcoin::blockdata::block::{Block, BlockHeader}; use bitcoin::blockdata::block::{Block, BlockHeader};
use bitcoin::network::serialize::{BitcoinHash, serialize}; use bitcoin::consensus::encode::serialize;
use bitcoin::util::hash::Sha256dHash; use bitcoin::util::hash::{BitcoinHash, Sha256dHash};
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt; use std::fmt;
use std::iter::FromIterator; use std::iter::FromIterator;
@ -75,7 +75,7 @@ impl<'a> From<&'a Block> for BlockMeta {
fn from(block: &'a Block) -> BlockMeta { fn from(block: &'a Block) -> BlockMeta {
BlockMeta { BlockMeta {
tx_count: block.txdata.len() as u32, tx_count: block.txdata.len() as u32,
size: serialize(block).unwrap().len() as u32, size: serialize(block).len() as u32,
weight: block.txdata.iter().map(|tx| tx.get_weight() as u32).sum(), weight: block.txdata.iter().map(|tx| tx.get_weight() as u32).sum(),
} }
} }