2014-07-18 13:56:17 +00:00
|
|
|
[package]
|
2014-07-18 19:07:10 +00:00
|
|
|
name = "bitcoin"
|
2019-03-19 15:35:29 +00:00
|
|
|
version = "0.18.0"
|
2014-07-18 13:56:17 +00:00
|
|
|
authors = ["Andrew Poelstra <apoelstra@wpsoftware.net>"]
|
2015-05-20 18:14:21 +00:00
|
|
|
license = "CC0-1.0"
|
2018-03-05 19:44:44 +00:00
|
|
|
homepage = "https://github.com/rust-bitcoin/rust-bitcoin/"
|
|
|
|
repository = "https://github.com/rust-bitcoin/rust-bitcoin/"
|
2018-04-11 19:13:43 +00:00
|
|
|
documentation = "https://docs.rs/bitcoin/"
|
2015-05-20 18:14:21 +00:00
|
|
|
description = "General purpose library for using and interoperating with Bitcoin and other cryptocurrencies."
|
|
|
|
keywords = [ "crypto", "bitcoin" ]
|
|
|
|
readme = "README.md"
|
|
|
|
|
2014-08-19 01:04:32 +00:00
|
|
|
[lib]
|
2014-07-18 13:56:17 +00:00
|
|
|
name = "bitcoin"
|
|
|
|
path = "src/lib.rs"
|
|
|
|
|
2018-03-10 14:35:49 +00:00
|
|
|
[features]
|
2019-01-15 23:34:48 +00:00
|
|
|
fuzztarget = ["secp256k1/fuzztarget", "bitcoin_hashes/fuzztarget"]
|
|
|
|
serde-decimal = ["use-serde", "strason"]
|
2019-01-07 21:43:23 +00:00
|
|
|
unstable = []
|
2019-03-19 14:49:27 +00:00
|
|
|
use-serde = ["serde", "serde_test", "bitcoin_hashes/serde"]
|
2018-03-10 14:35:49 +00:00
|
|
|
|
2015-03-26 15:44:49 +00:00
|
|
|
[dependencies]
|
2019-03-04 21:13:11 +00:00
|
|
|
bitcoin-bech32 = "0.9.0"
|
2018-12-07 03:45:43 +00:00
|
|
|
byteorder = "1.2"
|
2015-09-20 17:36:57 +00:00
|
|
|
rand = "0.3"
|
2019-01-15 23:34:48 +00:00
|
|
|
bitcoin_hashes = "0.3"
|
2018-08-12 20:06:06 +00:00
|
|
|
bitcoinconsensus = { version = "0.16", optional = true }
|
2015-03-26 15:44:49 +00:00
|
|
|
|
Better RawNewtorkMessage deserealization from IO stream (#231)
Follow-up to https://github.com/rust-bitcoin/rust-bitcoin/pull/229
While working with remote peers over the network it is required to deserealize RawNetworkMessage from `TCPStream` to read the incoming messages. These messages can be partial – or one TCP packet can contain few of them. To make the library usable for such use cases, I have implemented the required functionality and covered it with unit tests.
Sample usage:
```rust
fn run() -> Result<(), Error> {
// Opening stream to the remote bitcoind peer
let mut stream = TcpStream::connect(SocketAddr::from(([37, 187, 0, 47], 8333));
let start = SystemTime::now();
// Constructing and sending `version` message to get some messages back from the remote peer
let since_the_epoch = start.duration_since(UNIX_EPOCH)
.expect("Time went backwards");
let version_msg = message::RawNetworkMessage {
magic: constants::Network::Bitcoin.magic(),
payload: message::NetworkMessage::Version(message_network::VersionMessage::new(
0,
since_the_epoch.as_secs() as i64,
address::Address::new(receiver, 0),
address::Address::new(receiver, 0),
0,
String::from("macx0r"),
0
))
};
stream.write(encode::serialize(&version_msg).as_slice())?;
// Receiving incoming messages
let mut buffer = vec![];
loop {
let result = StreamReader::new(&mut stream, None).read_messages();
if let Err(err) = result {
stream.shutdown(Shutdown::Both)?;
return Err(Error::DataError(err))
}
for msg in result.unwrap() {
println!("Received message: {:?}", msg.payload);
}
}
}
```
Sample output is the following:
```
Received message: Version(VersionMessage { version: 70015, services: 1037, timestamp: 1548637162, receiver: Address {services: 0, address: [0, 0, 0, 0, 0, 65535, 23536, 35968], port: 33716}, sender: Address {services: 1037, address: [0, 0, 0, 0, 0, 0, 0, 0], port: 0}, nonce: 1370726880972892633, user_agent: "/Satoshi:0.17.99/", start_height: 560412, relay: true })
Received message: Verack
Received message: Alert([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 127, 0, 0, 0, 0, 255, 255, 255, 127, 254, 255, 255, 127, 1, 255, 255, 255, 127, 0, 0, 0, 0, 255, 255, 255, 127, 0, 255, 255, 255, 127, 0, 47, 85, 82, 71, 69, 78, 84, 58, 32, 65, 108, 101, 114, 116, 32, 107, 101, 121, 32, 99, 111, 109, 112, 114, 111, 109, 105, 115, 101, 100, 44, 32, 117, 112, 103, 114, 97, 100, 101, 32, 114, 101, 113, 117, 105, 114, 101, 100, 0])
```
Working sample code can be found here: https://github.com/dr-orlovsky/bitcoinbigdata-netlistener
2019-02-27 21:41:28 +00:00
|
|
|
[dev-dependencies]
|
|
|
|
tempfile = "3"
|
|
|
|
|
2018-08-20 16:37:19 +00:00
|
|
|
[dependencies.serde]
|
|
|
|
version = "1"
|
|
|
|
optional = true
|
|
|
|
|
2019-03-19 14:49:27 +00:00
|
|
|
[dependencies.serde_test]
|
|
|
|
version = "1"
|
|
|
|
optional = true
|
|
|
|
|
2018-08-20 16:37:19 +00:00
|
|
|
[dependencies.strason]
|
|
|
|
version = "0.4"
|
|
|
|
optional = true
|
|
|
|
default-features = false
|
|
|
|
|
2018-07-24 18:43:03 +00:00
|
|
|
[dependencies.hex]
|
2018-08-22 22:11:46 +00:00
|
|
|
version = "=0.3.2"
|
2018-07-24 18:43:03 +00:00
|
|
|
|
2018-02-18 15:45:35 +00:00
|
|
|
[dependencies.secp256k1]
|
2019-01-15 17:05:41 +00:00
|
|
|
version = "0.12"
|
2018-03-21 22:06:51 +00:00
|
|
|
features = [ "rand" ]
|