Commit Graph

609 Commits

Author SHA1 Message Date
Matt Corallo 084f82be21 Swap a few more [d]encoders to slice emit/read functions 2019-05-30 11:25:37 -04:00
Matt Corallo 7015b064dd Add slice consensus encode/decode functions and use for short arrays 2019-05-30 11:25:37 -04:00
Andrew Poelstra 4139f2a1ca
Merge pull request #258 from shesek/signed-msg-hash
Implement util::misc::signed_msg_hash()
2019-05-30 14:35:57 +00:00
Andrew Poelstra e0205fc9fa
Merge pull request #260 from TheBlueMatt/2019-05-headers-no-pub-wrapper
Drop LoneHeaders and just use BlockHeader
2019-05-21 20:30:35 +00:00
Matt Corallo 4f96a87475 Drop LoneHeaders and just use BlockHeader
The protocol has a bug where a 0u8 is pushed at the end of each
block header on the wire in headers messages. WHy this bug came
about is unrealted and shouldn't impact API design.
2019-05-17 17:55:02 -04:00
Andrew Poelstra b471a12487
Merge pull request #257 from stevenroose/bip32-increment
bip32: Add increment method to DerivationPath and ChildNumber
2019-05-04 21:25:21 +00:00
Steven Roose bb8520268e
bip32: Add DerivationPathIterator and related methods
Adds methods
- ChildNumber::increment
- DerivationPath::children_from
- DerivationPath::normal_children
- DerivationPath::hardened_children
2019-05-03 17:58:09 +01:00
Andrew Poelstra b75e154dd8
Merge pull request #256 from stevenroose/nit-changelog
Fix nit in CHANGELOG.md
2019-05-02 20:31:42 +00:00
Nadav Ivgi 473b491409
Implement util::misc::signed_msg_hash() 2019-04-28 09:01:42 +03:00
Steven Roose 8f2719016e
Fix nit in CHANGELOG.md 2019-04-26 15:07:18 +01:00
Andrew Poelstra 214345745b
Merge pull request #248 from apoelstra/2019-03-0.18
bump version to 0.18
2019-03-22 15:22:35 +00:00
Andrew Poelstra b9e44e4ffd bump version to 0.18 2019-03-21 23:20:06 +00:00
Andrew Poelstra b94d0fcf24
Merge pull request #247 from apoelstra/2019-03-contracthash
contracthash: use `PublicKey` and `PrivateKey` types; minor cleanups
2019-03-21 23:05:43 +00:00
Andrew Poelstra dc6189dbb2 contracthash: more cleanups 2019-03-21 21:27:26 +00:00
Andrew Poelstra 01a3a9263c contracthash: use `PublicKey` and `PrivateKey` types; minor cleanups 2019-03-21 21:27:26 +00:00
Andrew Poelstra 3700d100eb contracthash: add fixed test vector 2019-03-21 21:27:26 +00:00
Andrew Poelstra cea49b6522
Merge pull request #246 from apoelstra/2019-03-key-serde
util::key add serde de/serialization
2019-03-21 21:26:25 +00:00
Andrew Poelstra 9daf7fa9dc util::key add serde de/serialization 2019-03-21 18:27:42 +00:00
Carl Dong 221e53b13e
Merge pull request #243 from stevenroose/pubkey-serialize
util:🔑 Provide to_bytes() methods for key types
2019-03-06 21:44:02 -05:00
Carl Dong d667e0f894
Merge pull request #244 from stevenroose/bech32-bump
Bump bitcoin-bech32 dependency
2019-03-06 21:43:36 -05:00
Steven Roose 459059622f
util:🔑 Provide to_bytes() methods for key types
These are mainly utility methods around the existing way to serialize
the key types.
2019-03-05 16:07:52 +00:00
Steven Roose 750da89992
Bump bitcoin-bech32 dependency
This makes the Address::Payload::WitnessProgram inner type compatible
with rust-lightning-invoice's Fallback::SegWitProgram's inner type.
This allows specifying fallbacks from addresses.
2019-03-04 21:15:28 +00:00
Andrew Poelstra 08c6435eb7
Merge pull request #242 from apoelstra/2019-03-0.17.1
bump version to 0.17.1
2019-03-04 20:20:38 +00:00
Andrew Poelstra d5c1200590 bump version to 0.17.1 2019-03-04 17:51:38 +00:00
Andrew Poelstra 7e1a6a4ab7
Merge pull request #241 from apoelstra/2019-03-pubkey-string
key: implement ToString and FromStr for PublicKey
2019-03-04 17:47:36 +00:00
Andrew Poelstra 049f75e502 script: add `push_key` function to Builder to allow serializing public keys more easily 2019-03-04 01:32:35 +00:00
Andrew Poelstra 4dbf431ecd key: implement ToString and FromStr for PublicKey 2019-03-04 01:06:19 +00:00
Andrew Poelstra 8aa964ce43
Merge pull request #239 from apoelstra/2019-02-0.17
bump version to 0.17.0
2019-03-01 19:43:51 +00:00
Andrew Poelstra 8e214ffa90 add #231 to CHANGELOG for 0.17.0 2019-03-01 16:13:56 +00:00
Andrew Poelstra c342bf3731 bump version to 0.17.0 2019-02-28 22:02:45 +00:00
Andrew Poelstra 67e4671457
Merge pull request #103 from dongcarl/psbt
BIP174 (de)serialization support
2019-02-28 17:20:37 +00:00
Carl Dong e5b59120c5 Add copyright notice to PSBT-related files 2019-02-28 11:11:55 -05:00
Carl Dong f74ec3e187 Add fuzz testing for PartiallySignedTransaction 2019-02-28 11:11:55 -05:00
Carl Dong bc73b315cb Add test vectors from BIP174 specification
- Add macro for decoding and unwrapping PartiallySignedTransaction from
  hex string
2019-02-28 11:11:55 -05:00
Carl Dong 39fd567b56 Add Partially Signed Transaction type
- Add merging logic for PartiallySignedTransactions
- Add (en)decoding logic for PartiallySignedTransaction
- Add converting constructor logic from Transaction for
  PartiallySignedTransaction
- Add extracting constructor logic from PartiallySignedTransaction for
  Transaction

Squashed in fixes from stevenroose <stevenroose@gmail.com>

- Prevent PSBT::extract_tx from panicking
- Make PartiallySignedTransaction fields public
2019-02-28 11:11:55 -05:00
Carl Dong badb0f2a77 Add PSBT input data key-value map type
- Implement psbt::Map trait for psbt::Input
- Add (en)decoding logic for psbt::Input

- Implement PSBT (de)serialization trait for relevant psbt::Input types
2019-02-28 11:11:55 -05:00
Carl Dong 9c08dbae47 Add PSBT output data key-value map type
- Implement psbt::Map trait for psbt::Output
- Add (en)decoding logic for psbt::Output

- Implement PSBT (de)serialization trait for relevant psbt::Output types

- Add macro for merging fields for PSBT key-value maps
- Add macro for implementing decoding logic for PSBT key-value maps
- Add convenience macro for implementing both encoding and decoding
  logic for PSBT key-value maps
- Add macro for inserting raw PSBT key-value pairs into PSBT key-value
  maps
- Add macro for getting raw PSBT key-value pairs from PSBT key-value
  maps
2019-02-28 10:54:53 -05:00
Carl Dong 115f8c043c Add PSBT global data key-value map type
- Implement psbt::Map trait for psbt::Global
- Add converting constructor logic from Transaction for psbt::Global
- Add (en)decoding logic for psbt::Global
  - Always deserialize unsigned_tx as non-witness

- Add trait for PSBT (de)serialization
- Implement PSBT (de)serialization trait for relevant psbt::Global types

- Add macros for consensus::encode-backed PSBT (de)serialization
  implementations
- Add macro for implementing encoding logic for PSBT key-value maps
2019-02-28 10:54:53 -05:00
Carl Dong 2715a6e777 Add trait for PSBT key-value maps 2019-02-28 10:54:53 -05:00
Carl Dong 528e39334c Add data types for raw PSBT key-value pairs
- Add (en)decoding logic for said data types
2019-02-28 10:54:53 -05:00
Carl Dong 4fa39c4a3e Add PSBT-specific Error data type
- Implement psbt::Error data type
- Implement conversion from psbt::Error to util::Error
- Create util::psbt module
- Create non-public util::psbt::error module
2019-02-28 10:54:53 -05:00
Andrew Poelstra 919bbeae4a
Merge pull request #238 from apoelstra/2019-02-bip32-keys
Replace `secp256k1` keys with `util::key` keys in BIP32
2019-02-28 13:42:50 +00:00
Andrew Poelstra 4f74ae61c4 bip32: replace rust-secp key types with rust-bitcoin key types
We continue to support only compressed keys when doing key derivation,
but de/serialization of uncompressed keys will now work, and it will
be easier/more consistent to implement PSBT on top of this.
2019-02-27 22:21:40 +00:00
Dr. Maxim Orlovsky 3c21e301aa 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 16:41:28 -05:00
Andrew Poelstra fc47c477ab key: add some missing functionality 2019-02-27 01:56:38 +00:00
Carl Dong 4bf99e79f8
Merge pull request #236 from dongcarl/2019-02-remove-unused-option-decoding
Remove unused Option en/decoding
2019-02-22 10:14:37 -05:00
Carl Dong 04c7f2071d
Merge pull request #235 from dongcarl/2019-02-remove-extraneous-params-clone
Remove extraneous clones in consensus::params
2019-02-21 17:41:08 -05:00
Carl Dong 4c742fbaa1
Merge pull request #237 from dongcarl/2019-02-forbid-unsafe
Forbid unsafe code
2019-02-21 17:37:59 -05:00
Carl Dong 1ad1c11649 Forbid unsafe code 2019-02-20 17:16:21 -05:00
Carl Dong 17c0f4e784 Remove unused Option en/decoding 2019-02-20 17:08:36 -05:00