Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b40025d
transaction refactoring
QuantumExplorer Aug 4, 2022
fe35ed4
more dashification
QuantumExplorer Aug 5, 2022
0feaf7a
more dashification
QuantumExplorer Aug 5, 2022
c32fae6
more refactoring
QuantumExplorer Aug 5, 2022
f664b7e
work on special transactions
QuantumExplorer Aug 5, 2022
9ceb221
implemented all decodeable special transactions
QuantumExplorer Aug 7, 2022
84e4d82
much more work on special transactions
QuantumExplorer Aug 7, 2022
ac7453c
much more work on special transactions
QuantumExplorer Aug 7, 2022
338af0d
more fixes
QuantumExplorer Aug 8, 2022
2d441b2
more fixes
QuantumExplorer Aug 8, 2022
755bfe0
fixed addresses
QuantumExplorer Aug 8, 2022
946fd3c
more work
QuantumExplorer Aug 8, 2022
a69bc4f
added asset lock and credit withdrawal
QuantumExplorer Aug 8, 2022
0e45865
more docs
QuantumExplorer Aug 8, 2022
0570932
small changes
QuantumExplorer Aug 8, 2022
25a48fb
small changes
QuantumExplorer Aug 8, 2022
a69a1dc
serde
QuantumExplorer Aug 8, 2022
ea479d5
a lot more documentation
QuantumExplorer Aug 8, 2022
ad81fbb
a lot more documentation
QuantumExplorer Aug 8, 2022
843ea8a
docs done
QuantumExplorer Aug 8, 2022
1c71f73
derive serve for bls types
fominok Aug 8, 2022
723ebd0
fixed some tests
QuantumExplorer Aug 8, 2022
6f44591
Merge branch 'feat/specialTransactions' of github.com:dashevo/rust-da…
QuantumExplorer Aug 8, 2022
5ae384a
test fixes
QuantumExplorer Aug 8, 2022
e3821e6
more fixes
QuantumExplorer Aug 8, 2022
0336a12
more fixes
QuantumExplorer Aug 8, 2022
aa3c541
tests passing
QuantumExplorer Aug 8, 2022
b5fe289
doc fixes
QuantumExplorer Aug 8, 2022
882ece9
increasing special transaction tests
QuantumExplorer Aug 8, 2022
a75322c
more work on tests
QuantumExplorer Aug 8, 2022
049f56c
tx id working
QuantumExplorer Aug 9, 2022
de865e9
update service test
QuantumExplorer Aug 9, 2022
f223d9a
update registrar test
QuantumExplorer Aug 9, 2022
b3efdaa
fixes
QuantumExplorer Aug 9, 2022
ed3b042
updated readme
QuantumExplorer Aug 9, 2022
9e1d592
small fix
QuantumExplorer Aug 9, 2022
b714c54
remove objc reference
QuantumExplorer Aug 9, 2022
18fb3a9
removed hex requirement
QuantumExplorer Aug 9, 2022
e82f7fe
fix std, no-std modes
qrayven Aug 11, 2022
712bfec
enable compilation for rust < 1.48
qrayven Aug 12, 2022
d243af1
disabling changed tests
qrayven Aug 12, 2022
fb0ec8f
fix addr in embedded tests
qrayven Aug 12, 2022
ebabc65
bump down toolchain for fuzzer
qrayven Aug 12, 2022
ca2f3d5
fix imports in fuzz tests
qrayven Aug 12, 2022
93d1934
changed to swap bytes
QuantumExplorer Aug 13, 2022
0959eac
changed to swap bytes
QuantumExplorer Aug 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing to rust-bitcoin
# Contributing to rust-dashcore

**Heads up about upcoming edition change**

Expand All @@ -8,9 +8,9 @@ There will be a lot of rebasing after the edition change.

:+1::tada: First off, thanks for taking the time to contribute! :tada::+1:

The following is a set of guidelines for contributing to Rust Bitcoin
implementation and other Rust Bitcoin-related projects, which are hosted in the
[Rust Bitcoin Community](https://github.com/rust-bitcoin) on GitHub. These are
The following is a set of guidelines for contributing to Rust Dash Core
Comment thread
QuantumExplorer marked this conversation as resolved.
implementation and other Rust Dash-related projects, which are hosted in the
[Rust Dash Core Community](https://github.com/rust-dashcore) on GitHub. These are
mostly guidelines, not rules. Use your best judgment, and feel free to propose
changes to this document in a pull request.

Expand All @@ -35,7 +35,7 @@ changes to this document in a pull request.

## General

The Rust Bitcoin project operates an open contributor model where anyone is
The Rust Dash Core project operates an open contributor model where anyone is
welcome to contribute towards development in the form of peer review,
documentation, testing and patches.

Expand Down
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "dashcore"
version = "0.29.1"
authors = ["Andrew Poelstra <apoelstra@wpsoftware.net>"]
authors = ["Samuel Westrich <sam@dash.org>", "Anton Suprunchuk <anton@dash.org>"]
license = "CC0-1.0"
homepage = "https://github.com/dashevo/rust-dashcore/"
repository = "https://github.com/dashevo/rust-dashcore/"
documentation = "https://docs.rs/bitcoin/"
description = "General purpose library for using and interoperating with Bitcoin and other cryptocurrencies."
documentation = "https://dashcore.readme.io/docs"
description = "General purpose library for using and interoperating with Dash Core payment chain."
keywords = [ "crypto", "dash" ]
readme = "README.md"
exclude = ["./test_data"]
Expand Down Expand Up @@ -39,6 +39,7 @@ bech32 = { version = "0.8.1", default-features = false }
bitcoin_hashes = { version = "0.10.0", default-features = false }
secp256k1 = { git = "https://github.com/rust-bitcoin/rust-secp256k1", default-features = false, rev="f7cae46fc7733522cb84ef1b1ee1d1ed0cec2fd3" }
core2 = { version = "0.3.0", optional = true, default-features = false }
rustversion = { version="1.0.9"}

base64-compat = { version = "1.0.0", optional = true }
bitcoinconsensus = { version = "0.19.0-3", optional = true }
Expand All @@ -55,6 +56,8 @@ secp256k1 = { git = "https://github.com/rust-bitcoin/rust-secp256k1", features =
bincode = "1.3.1"
# We need to pin ryu (transitive dep from serde_json) to stay compatible with Rust 1.22.0
ryu = "<1.0.5"
bip39 = "1.0.1"
hex = "0.4"

[[example]]
name = "bip32"
Expand Down
76 changes: 17 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
<div align="center">
<h1>Rust Bitcoin</h1>
<h1>Rust Dash</h1>

<img alt="Rust Bitcoin logo by Hunter Trujillo, see license and source files under /logo" src="./logo/rust-bitcoin.png" width="300" />

<p>Library with support for de/serialization, parsing and executing on data-structures
and network messages related to Bitcoin.
and network messages related to Dash Core payment chain.
</p>

<p>
<a href="https://crates.io/crates/bitcoin"><img alt="Crate Info" src="https://img.shields.io/crates/v/bitcoin.svg"/></a>
<a href="https://github.com/rust-bitcoin/rust-bitcoin/blob/master/LICENSE"><img alt="MIT or Apache-2.0 Licensed" src="https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg"/></a>
<a href="https://github.com/rust-bitcoin/rust-bitcoin/actions?query=workflow%3AContinuous%20integration"><img alt="CI Status" src="https://github.com/rust-bitcoin/rust-bitcoin/workflows/Continuous%20integration/badge.svg"></a>
<a href="https://crates.io/crates/dash"><img alt="Crate Info" src="https://img.shields.io/crates/v/dash.svg"/></a>
<a href="https://github.com/dashevo/rust-dashcore/blob/master/LICENSE"><img alt="MIT or Apache-2.0 Licensed" src="https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg"/></a>
<a href="https://github.com/dashevo/rust-dashcore/actions?query=workflow%3AContinuous%20integration"><img alt="CI Status" src="https://github.com/dashevo/rust-dashcore/workflows/Continuous%20integration/badge.svg"></a>
<a href="https://docs.rs/bitcoin"><img alt="API Docs" src="https://img.shields.io/badge/docs.rs-bitcoin-green"/></a>
<a href="https://blog.rust-lang.org/2018/09/13/Rust-1.29.html"><img alt="Rustc Version 1.29+" src="https://img.shields.io/badge/rustc-1.29%2B-lightgrey.svg"/></a>
<a href="https://gnusha.org/bitcoin-rust/"><img alt="Chat on IRC" src="https://img.shields.io/badge/irc-%23bitcoin--rust%20on%20libera.chat-blue"></a>
<img alt="Lines of code" src="https://img.shields.io/tokei/lines/github/rust-bitcoin/rust-bitcoin">
<img alt="Lines of code" src="https://img.shields.io/tokei/lines/github/dashevo/rust-dashcore">
</p>
</div>

**Heads up for contributors: upcoming edition change**

We're currently preparing to bump MSRV and **change the edition to 2018**.
To minimize the churn we recommend you to submit your local WIP changes ASAP.
There will be a lot of rebasing after the edition change.

[Documentation](https://docs.rs/bitcoin/)
[Documentation](https://dashcore.readme.io/docs)

Supports (or should support)

Expand All @@ -35,8 +30,8 @@ Supports (or should support)
* PSBT creation, manipulation, merging and finalization
* Pay-to-contract support as in Appendix A of the [Blockstream sidechains whitepaper](https://www.blockstream.com/sidechains.pdf)

For JSONRPC interaction with Bitcoin Core, it is recommended to use
[rust-bitcoincore-rpc](https://github.com/rust-bitcoin/rust-bitcoincore-rpc).
For JSONRPC interaction with Dash Core, it is recommended to use
[rust-dashcore-rpc](https://github.com/dashevo/rust-dashcore-rpc).

## Known limitations

Expand All @@ -45,10 +40,10 @@ For JSONRPC interaction with Bitcoin Core, it is recommended to use
This library **must not** be used for consensus code (i.e. fully validating
blockchain data). It technically supports doing this, but doing so is very
ill-advised because there are many deviations, known and unknown, between
this library and the Bitcoin Core reference implementation. In a consensus
based cryptocurrency such as Bitcoin it is critical that all parties are
using the same rules to validate data, and this library is simply unable
to implement the same rules as Core.
this library and the Dash Core reference implementation. In a consensus
based cryptocurrency such as Dash it is critical that all parties are
using the same rules to validate data, and this library does not and might
never implement the same rules as Core.

Given the complexity of both C++ and Rust, it is unlikely that this will
ever be fixed, and there are no plans to do so. Of course, patches to
Expand All @@ -57,45 +52,21 @@ fix specific consensus incompatibilities are welcome.
### Support for 16-bit pointer sizes

16-bit pointer sizes are not supported and we can't promise they will be.
If you care about them please let us know, so we can know how large the interest
is and possibly decide to support them.
It will be dependent on rust-bitcoin implementing them first.

## Documentation

Currently can be found on [docs.rs/bitcoin](https://docs.rs/bitcoin/).
Patches to add usage examples and to expand on existing docs would be extremely
appreciated.
Documentation can be found on [dashcore.readme.io/docs](https://dashcore.readme.io/docs).

## Contributing

Contributions are generally welcome. If you intend to make larger changes please
discuss them in an issue before PRing them to avoid duplicate work and
architectural mismatches. If you have any questions or ideas you want to discuss
please join us in
[#bitcoin-rust](https://web.libera.chat/?channel=#bitcoin-rust) on
[libera.chat](https://libera.chat).
architectural mismatches.

## Minimum Supported Rust Version (MSRV)

This library should always compile with any combination of features on **Rust 1.29**.

Because some dependencies have broken the build in minor/patch releases, to
compile with 1.29.0 you will need to run the following version-pinning command:
```
cargo update -p cc --precise "1.0.41" --verbose
```

In order to use the `use-serde` feature or to build the unit tests with 1.29.0,
the following version-pinning commands are also needed:
```
cargo update --package "serde" --precise "1.0.98"
cargo update --package "serde_derive" --precise "1.0.98"
```

For the feature `base64` to work with 1.29.0 we also need to pin `byteorder`:
```
cargo update -p byteorder --precise "1.3.4"
```
This library should always compile with any combination of features on **Rust 1.60**.

## Installing Rust

Expand Down Expand Up @@ -141,19 +112,6 @@ In order to speed up the review process the CI pipeline can be run locally using
skipped when using `act` due to caching being unsupported at this time. We do
not *actively* support `act` but will merge PRs fixing `act` issues.

## Policy on Altcoins/Altchains

Patches which add support for non-Bitcoin cryptocurrencies by adding constants
to existing enums (e.g. to set the network message magic-byte sequence) are
welcome. Anything more involved will be considered on a case-by-case basis,
as the altcoin landscape includes projects which [frequently appear and
disappear, and are poorly designed anyway](https://download.wpsoftware.net/bitcoin/alts.pdf)
and keeping the codebase maintainable is a large priority.

In general, things that improve cross-chain compatibility (e.g. support for
cross-chain atomic swaps) are more likely to be accepted than things which
support only a single blockchain.


## Release Notes

Expand Down
2 changes: 1 addition & 1 deletion embedded/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Output should be something like:
heap size 524288
secp buf size 66240
Seed WIF: L1HKVVLHXiUhecWnwFYF6L3shkf1E12HUmuZTESvBXUdx3yqVP1D
Address: bc1qpx9t9pzzl4qsydmhyt6ctrxxjd4ep549np9993
Address: ds1qpx9t9pzzl4qsydmhyt6ctrxxjd4ep549jaqrtd
```

Note that this heap size is required because of the amount of stack used by libsecp256k1 when initializing a context.
4 changes: 2 additions & 2 deletions embedded/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ fn main() -> ! {

// Derive address
let pubkey = pk.public_key(&secp);
let address = Address::p2wpkh(&pubkey, Network::Bitcoin).unwrap();
let address = Address::p2wpkh(&pubkey, Network::Dash).unwrap();
hprintln!("Address: {}", address).unwrap();

assert_eq!(address.to_string(), "bc1qpx9t9pzzl4qsydmhyt6ctrxxjd4ep549np9993".to_string());
assert_eq!(address.to_string(), "ds1qpx9t9pzzl4qsydmhyt6ctrxxjd4ep549jaqrtd".to_string());
// exit QEMU
// NOTE do not run this on hardware; it can corrupt OpenOCD state
debug::exit(debug::EXIT_SUCCESS);
Expand Down
2 changes: 1 addition & 1 deletion examples/bip32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn main() {
println!("Seed: {}", seed_hex);

// default network as mainnet
let network = dashcore::Network::Bitcoin;
let network = dashcore::Network::Dash;
println!("Network: {:?}", network);

let seed = Vec::from_hex(seed_hex).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions examples/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main() {
let version_message = build_version_message(address);

let first_message = message::RawNetworkMessage {
magic: constants::Network::Bitcoin.magic(),
magic: constants::Network::Dash.magic(),
payload: version_message,
};

Expand All @@ -49,7 +49,7 @@ fn main() {
println!("Received version message: {:?}", reply.payload);

let second_message = message::RawNetworkMessage {
magic: constants::Network::Bitcoin.magic(),
magic: constants::Network::Dash.magic(),
payload: message::NetworkMessage::Verack,
};

Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/deserialize_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn do_test(data: &[u8]) {
assert_eq!(data, &encode::serialize(&script)[..]);

// Check if valid address and if that address roundtrips.
if let Some(addr) = Address::from_script(&script, Network::Bitcoin) {
if let Some(addr) = Address::from_script(&script, Network::Dash) {
assert_eq!(addr.script_pubkey(), script);
}
}
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/outpoint_string.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

extern crate dashcore;

use dashcore::blockdata::transaction::OutPoint;
use dashcore::blockdata::transaction::outpoint::OutPoint;
use dashcore::consensus::encode;

use std::str::FromStr;
Expand Down
2 changes: 1 addition & 1 deletion src/blockdata/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ mod tests {
assert_eq!(real_decode.header.nonce, 2067413810);
assert_eq!(real_decode.header.work(), work);
assert_eq!(real_decode.header.validate_pow(&real_decode.header.target()).unwrap(), real_decode.block_hash());
assert_eq!(real_decode.header.difficulty(Network::Bitcoin), 1);
assert_eq!(real_decode.header.difficulty(Network::Dash), 1);
// [test] TODO: check the transaction data

assert_eq!(real_decode.size(), some_block.len());
Expand Down
42 changes: 23 additions & 19 deletions src/blockdata/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@ use hashes::hex::{self, HexIterator};
use hashes::sha256d;
use blockdata::opcodes;
use blockdata::script;
use blockdata::transaction::{OutPoint, Transaction, TxOut, TxIn};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the problem with use blockdata::transaction::{OutPoint, Transaction, TxOut, TxIn};?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They got moved to their own files.

use blockdata::block::{Block, BlockHeader};
use blockdata::transaction::outpoint::OutPoint;
use blockdata::transaction::txin::TxIn;
use blockdata::transaction::txout::TxOut;
use blockdata::witness::Witness;
use network::constants::Network;
use Transaction;
use util::uint::Uint256;

/// The maximum allowable sequence number
pub const MAX_SEQUENCE: u32 = 0xFFFFFFFF;
/// How many satoshis are in "one bitcoin"
/// How many duffs are in "one dash"
pub const COIN_VALUE: u64 = 100_000_000;
/// How many seconds between blocks we expect on average
pub const TARGET_BLOCK_SPACING: u32 = 600;
Expand All @@ -54,14 +57,14 @@ pub const MIN_TRANSACTION_WEIGHT: u32 = 4 * 60;
pub const WITNESS_SCALE_FACTOR: usize = 4;
/// The maximum allowed number of signature check operations in a block
pub const MAX_BLOCK_SIGOPS_COST: i64 = 80_000;
/// Mainnet (bitcoin) pubkey address prefix.
pub const PUBKEY_ADDRESS_PREFIX_MAIN: u8 = 0; // 0x00
/// Mainnet (bitcoin) script address prefix.
pub const SCRIPT_ADDRESS_PREFIX_MAIN: u8 = 5; // 0x05
/// Test (tesnet, signet, regtest) pubkey address prefix.
pub const PUBKEY_ADDRESS_PREFIX_TEST: u8 = 111; // 0x6f
/// Test (tesnet, signet, regtest) script address prefix.
pub const SCRIPT_ADDRESS_PREFIX_TEST: u8 = 196; // 0xc4
/// Mainnet (dash) pubkey address prefix.
pub const PUBKEY_ADDRESS_PREFIX_MAIN: u8 = 76; // 0x4C
/// Mainnet (dash) script address prefix.
pub const SCRIPT_ADDRESS_PREFIX_MAIN: u8 = 16; // 0x10
/// Test (testnet, devnet, regtest) pubkey address prefix.
pub const PUBKEY_ADDRESS_PREFIX_TEST: u8 = 140; // 0x8C
/// Test (testnet, devnet, regtest) script address prefix.
pub const SCRIPT_ADDRESS_PREFIX_TEST: u8 = 19; // 0x13
/// The maximum allowed script size.
pub const MAX_SCRIPT_ELEMENT_SIZE: usize = 520;
/// How may blocks between halvings.
Expand All @@ -80,13 +83,14 @@ pub fn max_money(_: Network) -> u64 {
}

/// Constructs and returns the coinbase (and only) transaction of the Bitcoin genesis block
fn bitcoin_genesis_tx() -> Transaction {
fn dash_genesis_tx() -> Transaction {
// Base
let mut ret = Transaction {
version: 1,
lock_time: 0,
input: vec![],
output: vec![],
special_transaction_payload: None
};

// Inputs
Expand Down Expand Up @@ -120,11 +124,11 @@ fn bitcoin_genesis_tx() -> Transaction {

/// Constructs and returns the genesis block
pub fn genesis_block(network: Network) -> Block {
let txdata = vec![bitcoin_genesis_tx()];
let txdata = vec![dash_genesis_tx()];
let hash: sha256d::Hash = txdata[0].txid().into();
let merkle_root = hash.into();
match network {
Network::Bitcoin => {
Network::Dash => {
Comment thread
QuantumExplorer marked this conversation as resolved.
Block {
header: BlockHeader {
version: 1,
Expand All @@ -150,7 +154,7 @@ pub fn genesis_block(network: Network) -> Block {
txdata,
}
}
Network::Signet => {
Network::Devnet => {
Comment thread
QuantumExplorer marked this conversation as resolved.
Block {
header: BlockHeader {
version: 1,
Expand Down Expand Up @@ -186,12 +190,12 @@ mod test {

use network::constants::Network;
use consensus::encode::serialize;
use blockdata::constants::{genesis_block, bitcoin_genesis_tx};
use blockdata::constants::{genesis_block, dash_genesis_tx};
use blockdata::constants::{MAX_SEQUENCE, COIN_VALUE};

#[test]
fn bitcoin_genesis_first_transaction() {
let gen = bitcoin_genesis_tx();
let gen = dash_genesis_tx();

assert_eq!(gen.version, 1);
assert_eq!(gen.input.len(), 1);
Expand All @@ -213,7 +217,7 @@ mod test {

#[test]
fn bitcoin_genesis_full_block() {
let gen = genesis_block(Network::Bitcoin);
let gen = genesis_block(Network::Dash);

assert_eq!(gen.header.version, 1);
assert_eq!(gen.header.prev_blockhash, Default::default());
Expand Down Expand Up @@ -241,8 +245,8 @@ mod test {
}

#[test]
fn signet_genesis_full_block() {
let gen = genesis_block(Network::Signet);
fn devnet_genesis_full_block() {
let gen = genesis_block(Network::Devnet);
assert_eq!(gen.header.version, 1);
assert_eq!(gen.header.prev_blockhash, Default::default());
assert_eq!(format!("{:x}", gen.header.merkle_root),
Expand Down
Loading