Andrew Poelstra
3700d100eb
contracthash: add fixed test vector
2019-03-21 21:27:26 +00:00
Andrew Poelstra
9daf7fa9dc
util::key add serde de/serialization
2019-03-21 18:27:42 +00: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
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
Carl Dong
e5b59120c5
Add copyright notice to PSBT-related files
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
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
Carl Dong
2f70c3bc34
Remove extraneous clones in consensus::params
2019-02-20 15:47:31 -05:00
Matt Corallo
084703cba9
Merge pull request #218 from tamasblummer/merkle_root_fix
...
Merkle root calculation and witness commitment check for Block
2019-02-16 19:05:42 -05:00
Carl Dong
d5331e59ed
Merge pull request #233 from stevenroose/derivation-path
...
bip32: Add DerivationPath type
2019-02-15 09:52:59 -05:00
Steven Roose
dce81b623e
bip32: Add additional methods and traits to DerivationPath
...
- From<&[ChildNumber]> (cloning)
- AsRef<[ChildNumber]>
- std::iter::FromIterator<ChildNumber>
- std::iter::IntoIterator<ChildNumber>
- std::ops::Index (returning &[ChildNumber])
Also add two methods:
- child(&self, ChildNumber) -> DerivationPath
- into_child(self, ChildNumber) -> DerivationPath
2019-02-14 11:16:06 +00:00
Steven Roose
1373969805
bip32: Change test vectors to use DerivationPath
2019-02-14 11:09:39 +00:00
Steven Roose
b23de17d55
bip32: Introduce DerivationPath type
...
Implements Display and FromStr for easy usage with serialized types.
2019-02-14 11:09:34 +00:00
Steven Roose
a80cea270a
bip32: ChildNumber constructors return Result
...
They can produce an error if the index is out of range.
2019-02-14 11:08:13 +00:00
Carl Dong
560dfb7c01
Merge pull request #203 from stevenroose/asm
...
Extract the Script assembly creator from fmt::Debug
2019-02-11 17:24:03 -05:00
Carl Dong
a944c7fbd0
key: Use correct error for decoding
...
This change also moves the secp256k1::Error wrapper from util::Error to
consensus::encode::Error, since we do not use it anywhere else. We can
add it back to util::Error once we have instances of secp256k1::Error
that are not related to consensus::encode.
2019-02-11 15:15:03 -05:00
Carl Dong
fc448ba47c
key: Reword and clarify comments
2019-02-11 15:10:20 -05:00
Carl Dong
b3cc3d50ef
Integrate newly-added PublicKey with Address
...
- Switch util::address::Payload::Pubkey variant to wrap
util:🔑 :PublicKey
- Switch util::address::Address::p*k* constructors to use
util:🔑 :PublicKey
- Fix tests for aforementioned switch
- Add convenience methods for util:🔑 :PublicKey to
util:🔑 :PrivateKey conversion
- Switch BIP143 tests to use util:🔑 :PublicKey
2019-02-11 15:10:13 -05:00
Carl Dong
53a6efe33c
Add PublicKey struct encapsulating compressedness
...
- Move util::privkey to util::key
- Add PublicKey struct to util::key
- Implement de/serialization methods for util:🔑 :PublicKey
2019-02-11 14:56:55 -05:00
Carl Dong
60c93c387f
Cleanup util::privkey in preparation for PublicKey
...
- Rename privkey::PrivKey to privkey::PrivateKey
- Remove unnecessary methods for privkey::PrivateKey
- Modify tests to work with above changes
2019-02-11 14:56:49 -05:00
Tamás Blummer
1cd2782122
add BIP157 (Client Side Block Filtering) Messages ( #225 )
...
* add BIP57 (Client Side Block Filtering) Messages
* rabased after https://github.com/rust-bitcoin/rust-bitcoin/pull/215
2019-02-08 13:00:51 +01:00
Steven Roose
f80e882813
Remove Address::p2pk
...
There is no address format for p2pk.
2019-02-07 20:02:21 +00:00
ariard
51971dd533
Fix typos and clarify some comment in blockdata, block, address ( #230 )
2019-02-04 07:30:41 +01:00
Tamas Blummer
d8c93d9935
Implement Witness commitment check for Block. Remove MerkleRoot implementations for types implementing BitcoinHash as
...
it is misleading. MerkleRoot is defined instead for a Block.
2019-02-01 17:46:26 +01:00
Carl Dong
ca72a04dd4
Remove rust-crypto dependency
...
We no longer need rust-crypto after integrating bitcoin_hashes.
2019-01-24 16:27:52 -05:00
Carl Dong
1bbeda87eb
Remove fuzz_util module
...
Not needed anymore as the bitcoin_hashes crate handles this.
2019-01-24 16:27:52 -05:00
Carl Dong
96f9c62b0e
Remove unused internal macro
2019-01-24 16:27:52 -05:00
Carl Dong
c830fb4629
Remove code deprecated by bitcoin_hashes from util::hash
2019-01-24 16:27:52 -05:00
Carl Dong
99f63a8ca4
Convert codebase from util::hash to bitcoin_hashes
...
Also replace unsafe transmute with call to read_u64_into
2019-01-24 16:27:52 -05:00
Carl Dong
45aa709467
Implement En/Decodable for sha256d::Hash
2019-01-24 11:31:07 -05:00
Carl Dong
b88f00c698
Add bitcoin_hashes dependency, rename some features
...
Because features and dependencies share the same namespace, and we want
to pass down the optional dependence on serde to bitcoin_hashes, we need
to rename the feature to something other than serde. Right now only
features can be passed down to dependencies.
Note that we could have also renamed the dependency to something like
serde-dep and kept the same feature name, however, dependency renaming
has only been available since cargo 0.27.0
Features that represent optional dependencies have been prefixed with
'use-'. The travis file has also been modified to conform to this
change.
2019-01-24 11:31:07 -05:00
Carl Dong
b6ec6a0d62
Merge pull request #212 from TheBlueMatt/2019-01-travis-nightly-bench
...
Run cargo bench on rustc nightly in travis
2019-01-23 19:25:44 -05:00
Dimitris Apostolou
132ca5ea95
Fix typos
2019-01-23 14:17:29 -05:00
Tamas Blummer
96be35b1d3
it is annoying to have a difference between debug and print for hash
2019-01-23 14:14:29 -05:00
Matt Corallo
0d7e13b034
Run cargo bench on rustc nightly in travis, remote useless move
2019-01-15 14:06:24 -05:00
Matt Corallo
2ed4b1f246
Merge pull request #208 from sgeisler/hex_bytes
...
Use more performant hex_bytes function
2019-01-15 14:06:00 -05:00
Carl Dong
ff5c4a1806
Bump secp to 0.12
2019-01-15 12:58:54 -05:00
Carl Dong
b2e044f9db
Internalize unnecessarily exported macros
2019-01-15 11:53:31 -05:00
Antoine Riard
96c66292c8
Fix comment on transaction version
2019-01-10 18:29:50 -08:00
Sebastian Geisler
4c29fc0e8d
Add feature gated hex decode benchmark
2019-01-07 17:49:55 -08:00
Sebastian Geisler
7c7ec02ed2
Remove unused Pair iterator and util::iter module
2019-01-03 17:28:36 -08:00
Sebastian Geisler
c6a41651ab
Replace slow hex decoding function with optimized version
...
Fixes #207 .
2019-01-03 17:28:32 -08:00
Steven Roose
a10d5e15b3
Extract the Script assembly creator from fmt::Debug
2018-12-19 21:17:00 +01:00
Andrew Poelstra
5a5158e120
Merge pull request #198 from sgeisler/safe-opcodes
...
Safe opcodes 1.14.0
2018-12-14 16:32:29 +00:00
Sebastian Geisler
a6d204cbda
Fix indentation in opcodes.rs
2018-12-13 15:35:29 -08:00
Andrew Poelstra
bb7ca63776
Merge pull request #196 from sgeisler/separate-fuzzing
...
Move fuzzing code out of utils
2018-12-09 16:33:21 +00:00
Andrew Poelstra
617406228a
add some opcode tests
2018-12-09 16:30:23 +00:00
Sebastian Geisler
9fee72cf20
make opcode PR work with 1.14.0
2018-12-04 15:56:18 -08:00
Sebastian Geisler
79a88e1612
Move fuzzing code out of utils
2018-12-03 16:31:13 -08:00
Sebastian Geisler
e88612d617
add test case and cleanup
2018-12-03 14:51:55 -08:00
Sebastian Geisler
4a27c1369a
avoid heap use when encoding base58
2018-12-03 14:51:53 -08:00
Kaz Wesley
6b67c8cdff
squashme: work around lack of associated constants
2018-11-11 14:58:33 -08:00
Kaz Wesley
45234eb09a
safe implementation of All -> Ordinary
2018-11-11 14:19:25 -08:00
Kaz Wesley
0bfef68851
newtype implementation of opcodes::All
...
Removes unsafety when converting u8 -> All
2018-11-11 14:11:06 -08:00
Nadav Ivgi
18fcab6715
Detect compressed p2pk in script.is_p2pk()
2018-11-08 02:37:27 +02:00
Andrew Poelstra
b8a72448df
Merge pull request #153 from rust-bitcoin/2018-08-segwit-ambiguity
...
transaction: make 0-input de/serialization always use Segwit
2018-11-03 15:29:51 +00:00
Andrew Poelstra
c2146e1bbc
Merge pull request #181 from stevenroose/export-network
...
Export network::constants::Network
2018-10-23 16:18:30 +00:00
Andrew Poelstra
7813c0ae3d
Merge pull request #178 from stevenroose/wif
...
Add explicit WIF methods for Privkey
2018-10-22 15:28:09 +00:00
Steven Roose
5f912bdeae
Implement Debug for PrivKey
...
It returns a fixed string to prevent accidental data leakage.
2018-10-22 00:06:46 +01:00
Steven Roose
f7b95c7533
Add explicit WIF methods for Privkey
2018-10-22 00:05:59 +01:00
Steven Roose
6f4bfe68f3
Export network::constants::Network
2018-10-21 23:28:27 +01:00
Andrew Poelstra
0764673c38
Merge pull request #177 from stevenroose/outpoint-fromstr
...
Implement FromStr for OutPoint
2018-10-18 23:12:47 +00:00
Steven Roose
fefd5d4fe2
Implement FromStr for OutPoint
2018-10-18 12:37:02 +01:00
Andrew Poelstra
11a2783235
add comment expanding on the segwit ambiguity
2018-10-10 02:45:09 +00:00
Andrew Poelstra
a181a523c6
remove special case for 0-input 0-output transaction deserialization
...
This creates two ways to encode an empty transaction; we should use only the
Segwit-enabled one because that's what we do for 0-input non-0-output transactions.
2018-10-10 02:03:08 +00:00
Jeff Barg
1c2564fc08
Added example for creating an address from a public key
...
Added an example to the address rustdoc (addresses https://github.com/rust-bitcoin/rust-bitcoin/issues/160 )
2018-09-29 17:43:28 -04:00
evgeniy.scherbina
bc41772f89
added p2wkh, p2sh-p2wkh tests
2018-09-27 18:54:20 +03:00
Andrew Poelstra
98e39b4383
transaction: make 0-input de/serialization always use Segwit
2018-09-27 13:50:35 +00:00
Carl Dong
c42252c1da
Use default impl for Encoder for Sha256dEncoder
2018-09-25 21:20:24 +08:00
Carl Dong
0f42ca69b0
Move relevant names into consensus::encode
...
- Move network::encodable::* to consensus::encode::*
- Rename Consensus{En,De}codable to {En,De}codable (now under
consensus::encode)
- Move network::serialize::Error to consensus::encode::Error
- Remove Raw{En,De}coder, implement {En,De}coder for T: {Write,Read}
instead
- Move network::serialize::Simple{En,De}coder to
consensus::encode::{En,De}coder
- Rename util::Error::Serialize to util::Error::Encode
- Modify comments to refer to new names
- Modify files to refer to new names
- Expose {En,De}cod{able,er}, {de,}serialize, Params
- Do not return Result for serialize{,_hex} as serializing to a Vec
should never fail
2018-09-25 21:19:35 +08:00
Carl Dong
8e0e4eb55a
Move serialize::BitcoinHash to util: #️⃣ :BitcoinHash
...
- Use Sha256dEncoder for calculating merkle root
- Remove BitcoinHash implementation for Vec<u8>
2018-09-25 21:19:10 +08:00
Carl Dong
97937b1b5f
Move network::consensus_params to consensus::params
2018-09-25 21:13:34 +08:00
Carl Dong
7e9d393d03
Remove low-level networking support
...
- Modify VersionMessage constructor to take in parameters directly that
would have otherwise been extracted from a Socket (now removed)
2018-09-25 21:13:34 +08:00
Carl Dong
7f11766c65
Remove nu_select macro
2018-09-25 21:13:34 +08:00
Thomas Eizinger
50e3a4abf2
Add FromStr for Sha256dHash
...
The FromStr implementation just delegates to the `from_hex` method for
the actual parsing.
2018-09-20 12:18:45 +10:00
Steven Roose
8edfbec1cb
Implement serde serialiation for Address
2018-09-11 18:37:36 +01:00
Andrew Poelstra
849674651f
Merge pull request #157 from rust-bitcoin/2018-08-pub-use
...
`pub use` a ton of stuff at the top level
2018-08-28 17:13:40 +00:00
Andrew Poelstra
97c1773ec9
`pub use` a ton of stuff at the top level
2018-08-28 15:57:46 +00:00
Andrew Poelstra
fe99a88acf
Merge pull request #152 from rust-bitcoin/2018-08-script-ord
...
impl PartialOrd, Ord for Script
2018-08-26 15:38:43 +00:00
Andrew Poelstra
b33aa6fa6c
add unit test for script ordering
2018-08-25 22:09:22 +00:00
Andrew Poelstra
ef642295c5
encodable: reject non-compact VarInts on Vec and Box<[T]> lengths
2018-08-24 20:31:46 +00:00
Andrew Poelstra
f0221fb79b
transaction: reject transactions with Segwit byte set but no witnesses
2018-08-24 19:57:58 +00:00
Andrew Poelstra
68413d306d
impl PartialOrd, Ord for Script
2018-08-24 02:20:37 +00:00
Andrew Poelstra
08db6fe29f
script: let Instructions iterator enforce minimal pushes; remove `IntoIter` impl to force users to choose
2018-08-22 19:55:31 +00:00
Andrew Poelstra
dbefaef25c
Merge pull request #142 from jeandudey/2018-08-decimal-fromstr
...
Implement `FromStr` for `UDecimal`/`Decimal`.
2018-08-22 19:00:02 +00:00