Commit Graph

214 Commits

Author SHA1 Message Date
Andrew Poelstra 92c3b2459c script: fix macro for future rustc changes 2016-02-18 17:56:51 +00:00
Andrew Poelstra b88d04f0bc Add serde impls for all Transaction types
Bump version number; introduce rust-jsonrpc dependency
2016-02-10 03:37:24 +00:00
Andrew Poelstra 56b7e7d3f4 Add ntxid support 2015-12-21 11:07:37 -06:00
Andrew Poelstra 16f5878a03 Add a bunch of Ord/PartialOrd impls for stuff 2015-12-20 15:38:02 -06:00
Andrew Poelstra e05e6d2215 [BREAKING CHANGE] Drop UtxoSet
This code was unmaintained, is unlikely to work on the majority of systems
(since it holds the whole utxoset in RAM, and not in a terribly efficient
manner), and has a dependency on `eventual` which has been broken for a
long time.

The library no longer compiles on nightly because of this, and without any
known usecases for `UtxoSet`, nor good ability to test it, I'm simply
removing the code.

I recommend anyone who cares about this extracts the code from the previous
commit and creates a new crate. It should be more featureful anyway, e.g.
support a backing store.
2015-12-19 20:13:59 -06:00
Andrew Poelstra 45ef239a34 Add unsigned Decimal type 2015-12-19 20:13:59 -06:00
Andrew Poelstra 5c69d44397 Add Hash derived impls for all the transaction types 2015-12-19 20:13:59 -06:00
Andrew Poelstra 52b4263539 Remove comment about refcounted pointers; there are no refcounted pointers 2015-12-19 20:13:59 -06:00
Andrew Poelstra c1993a12c6 Add TxOutRef type to blockdata::transaction; don't use it anywhere in the library itself
This is just a convenience type for the (txid, vout) pairs that get produced
a lot in Bitcoin code. To the best of my knowledge there is nowhere this can
be used in the actual library (in particular, TxOutRef.index is a usize for
convenience while TxIn.prev_index is a u32 for correct consensus encoding,
so there is not redundancy here).
2015-12-19 20:13:59 -06:00
Andrew Poelstra e393d0ec3b Add useful Debug/Display for Script 2015-12-19 20:13:59 -06:00
Nicholas Alan Cardin e72e01dfa3 Fix decoding of Pong message 2015-12-17 23:47:40 -05:00
Andrew Poelstra a7c2dc6bb6 Add some accessors to the `Privkey` structure 2015-12-02 10:58:18 -06:00
Andrew Poelstra 1bbd492da6 Add nonnegative() utility function to Decimal 2015-11-30 14:23:15 -06:00
Andrew Poelstra 2962eb9d44 Add Display impl for Decimal 2015-11-30 14:08:45 -06:00
Andrew Poelstra a9cd31ccba Add addition and subtraction impls to Decimal 2015-11-30 14:03:57 -06:00
Andrew Poelstra 21ccd713ba Add helper from_hex() function for Sha256dHash 2015-11-30 11:03:04 -06:00
Andrew Poelstra 950e756316 Add formatters for Sha256dHash 2015-11-30 09:19:53 -06:00
Andrew Poelstra 76729f33ca Fix `Decimal` serialization of negative numbers 2015-11-30 09:13:48 -06:00
Andrew Poelstra a8ffce4904 Fix Script de/serialization (version -> 0.4.4) 2015-11-30 07:11:24 -06:00
Julius Naperkowski 8c707c5bef Added support for mempool messages 2015-11-23 00:58:09 +01:00
Andrew Poelstra e58f536c31 Add `Decimal` type for de/serializing values 2015-11-22 10:51:19 -06:00
Andrew Poelstra c3c6983789 Replace serde_json with strason in tests 2015-11-22 09:46:05 -06:00
Wladimir J. van der Laan 404176a5ee Fix data leak in CommandString::consensus_encode
A fixed buffer of 12 bytes was unsafely copied from the bytes of a
string - if the string was shorter than that, memory from outside would
leak into the packet.

Replace the unsafe copy by a safe loop. Also add a panic if
an attempt is made to use a command string longer than 12 bytes.
2015-11-08 01:14:10 +01:00
Andrew Poelstra 66eb08aab5 [BREAKING CHANGE] Make `script::Builder` implement the actual Builder pattern
Rather than having methods taking &mut self, have them consume self
and return another Builder, so that methods can be chained.

Bump major version number.
2015-11-04 11:04:54 -06:00
Andrew Poelstra 5e03adc9aa Changes for cargo-clippy warnings 2015-10-28 11:27:23 -05:00
Andrew Poelstra 8daf06cc1d Update for latest libsecp: normalize signatures and use "lax DER" parsing 2015-10-26 14:39:25 -05:00
Andrew Poelstra 67c0b8fba7 More Error implementations 2015-10-25 12:55:48 -05:00
Andrew Poelstra 34edf48b93 Implement Error for base58 error type 2015-10-25 10:16:05 -05:00
Andrew Poelstra 3491c5057e Make contracthashtool check that the number of keys matches the template's requirement
This is easy to satisfy given that the template-to-script code takes a
slice of keys. Just do &keys[..n_keys] if you have too many keys. (If
you have too few you're SOL no matter what.) This way we can catch
likely configuration errors without putting much of a burden on users
who legitimately have more keys than the template requires.

Also add a method required_keys() to Template so that users can check
how many keys they ought to have.
2015-10-25 08:37:32 -05:00
Andrew Poelstra 8defba2fb3 Expose ability to tweak secret keys for contract hash 2015-10-14 22:50:06 -05:00
Andrew Poelstra fdc854edd9 Remove Script() from LowerHex impl of Script
This is easy for downstream to add, not easy for them to remove. Plus scripts
have a pretty recognizable form and are usually obvious from context anyway.
2015-10-14 22:31:12 -05:00
Andrew Poelstra 38d2ef5d73 Add `from_script` method to Address for generating P2SH addresses 2015-10-14 22:24:09 -05:00
Andrew Poelstra ed34bb30f1 Add support for deserializing a script into a contracthash template
This is something Matt's contracthashtool does, so to copy its functionality
I need to support it. And it also seems generally useful.
2015-10-14 22:01:26 -05:00
Andrew Poelstra c1f81ea3c3 Add support for WIF private keys as well as addresses 2015-10-14 19:25:43 -05:00
Andrew Poelstra 16e2a3519b Implement basic contract-hash support
Does not do stuff like validating the form of contracts, since this seems like
more of an application thing. Does not even distinguish a "nonce", just assumes
the contract has whatever uniqueness is needed baked in.
2015-10-14 15:29:19 -05:00
Andrew Poelstra dba71d9253 [BREAKING CHANGE] Minor library updates
Breaking changes are:
    opcode::All::from_u8 is now From<u8>
    script::Builder::from_vec is now From<Vec<u8>>
    script::Script::from_vec is now From<Vec<u8>>
2015-10-14 09:14:09 -05:00
Andrew Poelstra eeb4655886 More updates for RFC 1214 2015-09-20 16:44:05 -05:00
Andrew Poelstra c67608a435 Remove `Sized` requirement from ConsensusEncodable 2015-09-20 15:34:13 -05:00
Andrew Poelstra 14db7ee902 Fix for rustc RFC 1214; also add missing docs 2015-09-20 15:30:18 -05:00
Andrew Poelstra 00421970a1 Fix for serde changes 2015-09-20 13:10:20 -05:00
Andrew Poelstra 99a4845719 Get library building on stable 2015-09-20 12:22:39 -05:00
Andrew Poelstra 2320f099c1 Remove broken wallet components
This was a fairly small change and gets all unit tests to pass.
2015-09-19 13:39:39 -05:00
Andrew Poelstra adaf50a408 *** ALL TESTS PASS WITH RUSTC HEAD ***
There is still a lot of work to do modernizing the library, but the code
compiles cleanly with all unit tests passing now. Probably not much can
be done now until wizards-wallet is in better shape and the library is
actually in use.
2015-05-10 14:32:26 -05:00
Andrew Poelstra 4b1b1c4a74 Fix endianness problems with new librustc ipv6 addresses 2015-05-10 13:08:38 -05:00
Andrew Poelstra 2975c91e37 Remove pile of undefined (and bitrotted) code 2015-05-10 11:12:37 -05:00
Andrew Poelstra b21acd440e Get compiling for secp256k1 changes 2015-04-13 22:40:32 -05:00
Andrew Poelstra 17e27ec09f *** IT COMPILES ON RUSTC NIGHTLY ***
Many unit test failures, but this is progress.
2015-04-10 20:55:59 -05:00
Andrew Poelstra 3117f95b62 Checkpoint commit: into warnings! 2015-04-10 18:15:57 -05:00
Andrew Poelstra 1d78dccb9e Checkpoint commit -- we're onto move errors :D 2015-04-10 13:34:31 -05:00
Andrew Poelstra e658ffaeea Rename ScriptBuilder to Builder as per rustc rfc PR 1036 2015-04-09 23:23:56 -05:00
Andrew Poelstra 5350207ff3 Remove hamcrest; add rust-serde (not compiling right now) 2015-04-09 23:23:53 -05:00
Andrew Poelstra e5a3e84c41 Checkpoint commit (nope, not yet to small commit sizes :))
This is mostly fixing compile errors in `cargo test`. We are down
to 3 in `cargo build` and 14 in `cargo test`, at least for this
round.
2015-04-08 17:23:45 -05:00
Andrew Poelstra 08a20f8764 Checkpoint commit
Work is stalled on some other library work (to give better lifetime
requirements on `eventual::Future` and avoid some unsafety), so
committing here.

There are only three errors left in this round :)

Also all the indenting is done, so there should be no more massive
rewrite commits. Depending how invasive the lifetime-error fixes
are, I may even be able to do sanely sized commits from here on.
2015-04-07 17:52:58 -05:00
Andrew Poelstra 200e0fe8e3 Checkpoint commit
27 files changed, 3944 insertions(+), 3812 deletions(-) :} I've
started doing whitespace changes as well, I want everything to
be 4-space tabs from now on.
2015-04-06 20:51:11 -05:00
Andrew Poelstra 811df8a713 Giant collection of fixes ... we are into lifetime errors now :) 2015-04-05 19:10:37 -05:00
Andrew Poelstra 7b89c15ed5 More changes, incl. dropping DumbHasher in favor of SipHasher
only json stuff left in this round of compiler errors :)
2015-04-05 14:43:44 -05:00
Andrew Poelstra 7738722ab5 Checkpoint commit; tons of disorganized changes for rustc
BTW after all this is done I'm gonna indent the entire codebase...
so `git blame` is gonna be totally broken anyway, hence my
capricious cadence of commits.
2015-04-05 12:58:49 -05:00
Andrew Poelstra 160f2f9ea6 Drop ThinVec, many other changes toward updating for librustc 2015-04-04 22:13:19 -05:00
Andrew Poelstra 7a2cfe95e7 Minor fixes to namespaces 2015-04-04 13:56:30 -05:00
Andrew Poelstra a62a7d736c Several more changes for librustc changes 2015-04-04 13:08:49 -05:00
Andrew Poelstra 467f76a37d MemReader/MemWriter become Cursor, other rustc changes 2015-04-04 12:56:40 -05:00
Andrew Poelstra f1aed644c6 More misc cleanup for rustc changes 2015-03-26 14:21:48 -05:00
Andrew Poelstra 0bf5809674 Add time crate 2015-03-26 11:53:49 -05:00
Andrew Poelstra 6db25db975 Bunch of error type changes 2015-03-26 11:52:20 -05:00
Andrew Poelstra 719f616218 Some more renames for librustc changes 2015-03-26 10:44:49 -05:00
Andrew Poelstra 11dbc717c4 Show -> Debug 2015-03-26 10:35:31 -05:00
Andrew Poelstra df065c143b fix attributes for compiler changes 2015-03-26 10:31:19 -05:00
Andrew Poelstra 2101e4a56d Rename bitcoin-secp256k1-rs to secp256k1 2015-03-26 10:08:36 -05:00
Andrew Poelstra c3377032f8 Many syntax changes for rustc, incomplete 2015-01-18 17:39:51 -06:00
Andrew Poelstra 97bfbe790b Add a `clone` to script sat-checker to satisfy new soundness rules
This was actually a soundness bug waiting to happen fwiw...but I'm
still not so happy about it.
2014-09-11 08:03:36 -05:00
Andrew Poelstra e0c9844ff2 Make UtxoSet store (height, txo) pairs rather than just the raw txo
Will take some experimentation to see if this is what I want the API
to be, if the memory usage is acceptable, etc.

This will force a total reindex for wizards-wallet users.

[breaking-change]
2014-09-10 19:58:58 -05:00
Andrew Poelstra 184721db61 Add wallet balance-checking support 2014-09-10 07:19:12 -05:00
Andrew Poelstra ef11e8273b Destroy socket listener on error rather than trying to reconnect; add #derivings
Reconnecting an existing socket simply was not working; the Rust socket
did not expose any methods for reconnection, so I simply tried calling
connect() again. As near as I can tell, this was a no-op --- which makes
sense because both the sending and receiving threads had their own copy
of the Socket, and it's not clear what the synchronization behaviour
should have been.

Instead if the connection fails, we relay this information to the main
thread, wait for an acknowledgement, then simply destroy the listening
thread. The caller can then simply call `start()` again.
2014-09-10 07:15:48 -05:00
Andrew Poelstra 1f41a67194 Make Address public 2014-09-06 11:47:18 -05:00
Andrew Poelstra 2aeb373e73 Fix encode/decode of ChildNumber so that hardened keys do not become normal ones 2014-09-06 11:35:36 -05:00
Andrew Poelstra a240d25611 Wallet support for address creation 2014-09-06 10:30:11 -05:00
Andrew Poelstra 9f56b9c57f Fix wallet serialization to not use "" as a key anywhere
Turns out TOML does not support tables named "", so we instead encode
the accounts list as an array rather than a name-keyed hashmap. This
is fine since the account name is in the account structure itself
anyway.
2014-09-05 11:55:25 -05:00
Andrew Poelstra bc7077fac4 Encodable/Decodable improvements; add `user_enum` macro for string enums 2014-09-05 09:16:22 -05:00
Andrew Poelstra 331e555e4c Use `verify_raw` rather than `verify` to check signatures
`verify` cannot handle illegally padded signatures because it takes an object
of type `Signature`, which is a fixed-size type. This should have been part
of the previous commit --- an important lesson about running the unit tests
before every push!
2014-09-04 20:34:58 -05:00
Andrew Poelstra 20ce3721b7 Fix for upstream 2014-09-04 19:06:52 -05:00
Andrew Poelstra c25862a107 Change UtxoSet to use full TXID as key
Sorry, this is needed to enable proper txid/vout lookups for the address index.
This means any users of wizards-wallet need to rebuild their utxo sets, and
will also mean an increase in RAM usage.
2014-09-02 09:37:31 -05:00
Andrew Poelstra 6250f4fd9c Checkpoint commit -- prefix-filtered address indexing works 2014-09-01 21:37:00 -05:00
Andrew Poelstra 4629472d69 Block in wallet support 2014-09-01 15:11:38 -05:00
Andrew Poelstra f66b4ff6b3 Fix for upstream, add some address generation benchmarks 2014-09-01 09:24:17 -07:00
Andrew Poelstra 931df9f68d Add Address support 2014-08-31 19:24:31 -07:00
Andrew Poelstra 853d644649 Minor cleanup for script analyzer 2014-08-31 19:20:11 -07:00
Andrew Poelstra a8ecf00e35 Fix recursion to carry the execution state stack 2014-08-31 16:55:39 -07:00
Andrew Poelstra 9d283150c9 Fix GT/LT/GTEQ/LTEQ handling to not compare bools
I was trying to do something clever by making sure that the numeric
bounds were consistent with whatever ordering relation we were checking,
AND that the boolean values were also consistent...this is Wrong is the
case of negative numbers, and pointless anyway since I recently fixed
`set_bool_value`, `set_num_lo` and `set_num_hi` to update both numeric
and boolean information if possible, so they will always contain the
same info.
2014-08-31 16:43:26 -07:00
Andrew Poelstra 1515f68748 Minor cleanup of utxoset input checking 2014-08-31 16:35:30 -07:00
Andrew Poelstra d880bd1ccc Ensure execution state stack is empty at the start
We had a single `true` on the execution state stack, which would
allow scripts to have one more OP_ENDIF than they are allowed.
2014-08-31 16:23:47 -07:00
Andrew Poelstra 340b569c73 Add much more agressive provably-false checker
Now unspendable outs are determined by attempting to create a minimal
satisfying input script. If this can't be done, the output is unspendable.
(Unfortunately this "minimal satisfying script" is not (yet) something
that can be shown to the user, since it is more a bundle of constraints
than actual data pushes.)

Current limitations:
  - OP_ADD and friends mean the checker gives the script a free pass.
    There is no fundamental reason for this, I just didn't get to it
    yet.

  - Pubkeys are checked for DER encoding but signatures aren't. This
    is because secp256k1 exposes a method for pubkeys, but not one
    for sigs :). Signatures are loosely length checked.
2014-08-31 16:01:24 -07:00
Andrew Poelstra 8f5c28a533 Fixes for rustc changes 2014-08-30 16:08:38 -07:00
Andrew Poelstra 38f8132067 Fix for upstream 2014-08-28 11:13:33 -07:00
Andrew Poelstra 6bf553c6fe Add BIP32 key support; unify array newtyping; improve base58 trait
Sorry for so many things in one commit ... it was an iterative
process depending as I worked on BIP32 to get the other stuff
working. (And I was too lazy to separate it out after the fact.)

A breaking change by the array newtyping is that Show for Sha256dHash
now outputs the slice Show. You have to use `{:x}` to get the old hex
output.
2014-08-28 09:49:03 -07:00
Andrew Poelstra 4ab69b8a77 script tracer: add `op_count` a running opcode count 2014-08-25 21:39:16 -07:00
Andrew Poelstra 46bffa304c script tracer: Put an obvious "opcode failed" message in the pre-execute stack 2014-08-25 16:09:00 -07:00
Andrew Poelstra 47c346be71 Add base58 decode/encode functionality 2014-08-24 23:03:47 -07:00
Andrew Poelstra 688a77ef38 Rename Hash->Uint functions to denote endianness 2014-08-24 12:28:02 -07:00
Andrew Poelstra 3a921e6b9c Add support for `tx` messages 2014-08-23 16:37:01 -07:00
Andrew Poelstra 4ba533514e Add Default impl to Script 2014-08-23 16:20:46 -07:00