From 2eedd19bc8c06546af2777bab5b14a730c52d091 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 26 May 2022 13:56:00 +1000 Subject: [PATCH] Run cargo +nightly fmt Add a `rustfmt` configuration file setting a bunch of configuration options. All options that are not the default value include a comment with the default value. Run `cargo +nightly fmt`. No other changes made. --- examples/bip32.rs | 18 +- examples/handshake.rs | 7 +- rustfmt.toml | 78 +++- src/blockdata/block.rs | 110 +++--- src/blockdata/constants.rs | 174 ++++----- src/blockdata/mod.rs | 3 +- src/blockdata/opcodes.rs | 609 ++++++++++++++++--------------- src/blockdata/script.rs | 493 ++++++++++++++----------- src/blockdata/transaction.rs | 412 +++++++++++++-------- src/blockdata/witness.rs | 43 +-- src/consensus/encode.rs | 258 ++++++++----- src/consensus/mod.rs | 5 +- src/consensus/params.rs | 2 +- src/internal_macros.rs | 50 ++- src/lib.rs | 82 ++--- src/network/address.rs | 228 ++++++++---- src/network/constants.rs | 12 +- src/network/message.rs | 278 ++++++++------ src/network/message_blockdata.rs | 35 +- src/network/message_bloom.rs | 4 +- src/network/message_network.rs | 46 +-- src/network/mod.rs | 7 +- src/network/stream_reader.rs | 58 ++- src/policy.rs | 3 +- src/serde_utils.rs | 44 ++- src/util/address.rs | 253 ++++++------- src/util/amount.rs | 283 ++++++++------ src/util/base58.rs | 67 ++-- src/util/bip143.rs | 67 ++-- src/util/bip158.rs | 210 +++++++---- src/util/bip32.rs | 214 ++++++----- src/util/ecdsa.rs | 40 +- src/util/endian.rs | 42 ++- src/util/hash.rs | 29 +- src/util/key.rs | 111 +++--- src/util/merkleblock.rs | 66 ++-- src/util/misc.rs | 117 +++--- src/util/mod.rs | 22 +- src/util/psbt/error.rs | 47 ++- src/util/psbt/macros.rs | 16 +- src/util/psbt/map/global.rs | 101 ++--- src/util/psbt/map/input.rs | 97 ++--- src/util/psbt/map/mod.rs | 8 +- src/util/psbt/map/output.rs | 63 ++-- src/util/psbt/mod.rs | 198 +++++----- src/util/psbt/raw.rs | 37 +- src/util/psbt/serialize.rs | 116 +++--- src/util/schnorr.rs | 34 +- src/util/sighash.rs | 238 ++++++------ src/util/taproot.rs | 263 ++++++++----- src/util/uint.rs | 197 +++++++--- 51 files changed, 3515 insertions(+), 2480 deletions(-) diff --git a/examples/bip32.rs b/examples/bip32.rs index 6dfd38891f..8ebdd84552 100644 --- a/examples/bip32.rs +++ b/examples/bip32.rs @@ -1,17 +1,14 @@ extern crate bitcoin; -use std::{env, process}; use std::str::FromStr; +use std::{env, process}; +use bitcoin::hashes::hex::FromHex; +use bitcoin::secp256k1::ffi::types::AlignedType; use bitcoin::secp256k1::Secp256k1; -use bitcoin::PublicKey; -use bitcoin::util::bip32::ExtendedPrivKey; -use bitcoin::util::bip32::ExtendedPubKey; -use bitcoin::util::bip32::DerivationPath; -use bitcoin::util::bip32::ChildNumber; use bitcoin::util::address::Address; -use bitcoin::secp256k1::ffi::types::AlignedType; -use bitcoin::hashes::hex::FromHex; +use bitcoin::util::bip32::{ChildNumber, DerivationPath, ExtendedPrivKey, ExtendedPubKey}; +use bitcoin::PublicKey; fn main() { // This example derives root xprv from a 32-byte seed, @@ -55,10 +52,7 @@ fn main() { // generate first receiving address at m/0/0 // manually creating indexes this time let zero = ChildNumber::from_normal_idx(0).unwrap(); - let public_key = xpub.derive_pub(&secp, &vec![zero, zero]) - .unwrap() - .public_key; + let public_key = xpub.derive_pub(&secp, &vec![zero, zero]).unwrap().public_key; let address = Address::p2wpkh(&PublicKey::new(public_key), network).unwrap(); println!("First receiving address: {}", address); - } diff --git a/examples/handshake.rs b/examples/handshake.rs index 9c4cf0462a..8852b04231 100644 --- a/examples/handshake.rs +++ b/examples/handshake.rs @@ -1,9 +1,9 @@ extern crate bitcoin; +use std::io::{BufReader, Write}; use std::net::{IpAddr, Ipv4Addr, Shutdown, SocketAddr, TcpStream}; use std::time::{SystemTime, UNIX_EPOCH}; use std::{env, process}; -use std::io::{Write, BufReader}; use bitcoin::consensus::{encode, Decodable}; use bitcoin::network::{address, constants, message, message_network}; @@ -80,10 +80,7 @@ fn build_version_message(address: SocketAddr) -> message::NetworkMessage { let services = constants::ServiceFlags::NONE; // "standard UNIX timestamp in seconds" - let timestamp = SystemTime::now() - .duration_since(UNIX_EPOCH) - .expect("Time error") - .as_secs(); + let timestamp = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time error").as_secs(); // "The network address of the node receiving this message" let addr_recv = address::Address::new(&address, constants::ServiceFlags::NONE); diff --git a/rustfmt.toml b/rustfmt.toml index c7ad93bafe..d8d6fd7dc9 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1,77 @@ -disable_all_formatting = true +max_width = 100 # Default 100 +hard_tabs = false +tab_spaces = 4 +newline_style = "Auto" +indent_style = "Block" +use_small_heuristics = "Default" +fn_call_width = 80 # Default 60 +attr_fn_like_width = 80 # Default 70 +struct_lit_width = 50 # Default 18 +struct_variant_width = 80 # Default 35 +array_width = 80 # Default 60 +chain_width = 80 # Default 60 +single_line_if_else_max_width = 80 # Default 50 +wrap_comments = false +format_code_in_doc_comments = false +comment_width = 100 # Default 80 +normalize_comments = false +normalize_doc_attributes = false +license_template_path = "" +format_strings = false +format_macro_matchers = false +format_macro_bodies = true +hex_literal_case = "Preserve" +empty_item_single_line = true +struct_lit_single_line = true +fn_single_line = false +where_single_line = false +imports_indent = "Block" +imports_layout = "Mixed" +imports_granularity = "Module" # Default "Preserve" +group_imports = "StdExternalCrate" # Default "Preserve" +reorder_imports = true +reorder_modules = true +reorder_impl_items = false +type_punctuation_density = "Wide" +space_before_colon = false +space_after_colon = true +spaces_around_ranges = false +binop_separator = "Front" +remove_nested_parens = true +combine_control_expr = true +overflow_delimited_expr = false +struct_field_align_threshold = 0 +enum_discrim_align_threshold = 0 +match_arm_blocks = false # Default true +match_arm_leading_pipes = "Never" +force_multiline_blocks = false +fn_args_layout = "Tall" +brace_style = "SameLineWhere" +control_brace_style = "AlwaysSameLine" +trailing_semicolon = true +trailing_comma = "Vertical" +match_block_trailing_comma = false +blank_lines_upper_bound = 1 +blank_lines_lower_bound = 0 +edition = "2015" +version = "One" +inline_attribute_width = 0 +format_generated_files = true +merge_derives = true +use_try_shorthand = false +use_field_init_shorthand = false +force_explicit_abi = true +condense_wildcard_suffixes = false +color = "Auto" +required_version = "1.4.38" +unstable_features = false +disable_all_formatting = false +skip_children = false +hide_parse_errors = false +error_on_line_overflow = false +error_on_unformatted = false +report_todo = "Never" +report_fixme = "Never" +ignore = [] +emit_mode = "Files" +make_backup = false diff --git a/src/blockdata/block.rs b/src/blockdata/block.rs index 06a532981f..7475cdb208 100644 --- a/src/blockdata/block.rs +++ b/src/blockdata/block.rs @@ -20,22 +20,20 @@ //! these blocks and the blockchain. //! -use crate::prelude::*; - use core::fmt; -use crate::util; -use crate::util::Error::{BlockBadTarget, BlockBadProofOfWork}; -use crate::util::hash::bitcoin_merkle_root; -use crate::hashes::{Hash, HashEngine}; -use crate::hash_types::{Wtxid, BlockHash, TxMerkleNode, WitnessMerkleNode, WitnessCommitment}; -use crate::util::uint::Uint256; -use crate::consensus::encode::Encodable; -use crate::network::constants::Network; -use crate::blockdata::transaction::Transaction; use crate::blockdata::constants::{max_target, WITNESS_SCALE_FACTOR}; use crate::blockdata::script; -use crate::VarInt; +use crate::blockdata::transaction::Transaction; +use crate::consensus::encode::Encodable; +use crate::hash_types::{BlockHash, TxMerkleNode, WitnessCommitment, WitnessMerkleNode, Wtxid}; +use crate::hashes::{Hash, HashEngine}; +use crate::network::constants::Network; +use crate::prelude::*; +use crate::util::hash::bitcoin_merkle_root; +use crate::util::uint::Uint256; +use crate::util::Error::{BlockBadProofOfWork, BlockBadTarget}; +use crate::{util, VarInt}; /// A block header, which contains all the block's information except /// the actual transactions @@ -140,7 +138,11 @@ impl BlockHeader { let mut ret = [0u64; 4]; util::endian::bytes_to_u64_slice_le(block_hash.as_inner(), &mut ret); let hash = &Uint256(ret); - if hash <= target { Ok(block_hash) } else { Err(BlockBadProofOfWork) } + if hash <= target { + Ok(block_hash) + } else { + Err(BlockBadProofOfWork) + } } /// Returns the total work of the block. @@ -163,7 +165,7 @@ pub struct Block { /// The block header pub header: BlockHeader, /// List of transactions contained in the block - pub txdata: Vec + pub txdata: Vec, } impl_consensus_encoding!(Block, header, txdata); @@ -200,15 +202,21 @@ impl Block { } // Commitment is in the last output that starts with magic bytes. - if let Some(pos) = coinbase.output.iter() - .rposition(|o| o.script_pubkey.len () >= 38 && o.script_pubkey[0..6] == MAGIC) + if let Some(pos) = coinbase + .output + .iter() + .rposition(|o| o.script_pubkey.len() >= 38 && o.script_pubkey[0..6] == MAGIC) { - let commitment = WitnessCommitment::from_slice(&coinbase.output[pos].script_pubkey.as_bytes()[6..38]).unwrap(); + let commitment = WitnessCommitment::from_slice( + &coinbase.output[pos].script_pubkey.as_bytes()[6..38], + ) + .unwrap(); // Witness reserved value is in coinbase input witness. let witness_vec: Vec<_> = coinbase.input[0].witness.iter().collect(); if witness_vec.len() == 1 && witness_vec[0].len() == 32 { if let Some(witness_root) = self.witness_root() { - return commitment == Self::compute_witness_commitment(&witness_root, witness_vec[0]); + return commitment + == Self::compute_witness_commitment(&witness_root, witness_vec[0]); } } } @@ -229,7 +237,10 @@ impl Block { } /// Computes the witness commitment for the block's transaction list. - pub fn compute_witness_commitment(witness_root: &WitnessMerkleNode, witness_reserved_value: &[u8]) -> WitnessCommitment { + pub fn compute_witness_commitment( + witness_root: &WitnessMerkleNode, + witness_reserved_value: &[u8], + ) -> WitnessCommitment { let mut encoder = WitnessCommitment::engine(); witness_root.consensus_encode(&mut encoder).expect("engines don't error"); encoder.input(witness_reserved_value); @@ -323,9 +334,8 @@ impl Block { full[0..b.len()].copy_from_slice(b); Ok(util::endian::slice_to_u64_le(&full)) } - script::Instruction::PushBytes(b) if b.len() > 8 => { - Err(Bip34Error::UnexpectedPush(b.to_vec())) - } + script::Instruction::PushBytes(b) if b.len() > 8 => + Err(Bip34Error::UnexpectedPush(b.to_vec())), _ => Err(Bip34Error::NotPresent), } } @@ -368,13 +378,12 @@ impl std::error::Error for Bip34Error { #[cfg(test)] mod tests { - use crate::hashes::hex::FromHex; - use crate::blockdata::block::{Block, BlockHeader}; use crate::consensus::encode::{deserialize, serialize}; - use crate::util::uint::Uint256; - use crate::util::Error::{BlockBadTarget, BlockBadProofOfWork}; + use crate::hashes::hex::FromHex; use crate::network::constants::Network; + use crate::util::uint::Uint256; + use crate::util::Error::{BlockBadProofOfWork, BlockBadTarget}; #[test] fn test_coinbase_and_bip34() { @@ -387,7 +396,6 @@ mod tests { assert_eq!(block.bip34_block_height(), Ok(100_000)); - // block with 9-byte bip34 push let bad_hex = "0200000035ab154183570282ce9afc0b494c9fc6a3cfea05aa8c1add2ecc56490000000038ba3d78e4500a5a7570dbe61960398add4410d278b21cd9708e6d9743f374d544fc055227f1001c29c1ea3b0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff3d09a08601112233445566000427f1001c046a510100522cfabe6d6d0000000000000000000068692066726f6d20706f6f6c7365727665726aac1eeeed88ffffffff0100f2052a010000001976a914912e2b234f941f30b18afbb4fa46171214bf66c888ac00000000"; let bad: Block = deserialize(&Vec::::from_hex(bad_hex).unwrap()).unwrap(); @@ -402,8 +410,12 @@ mod tests { let some_block = Vec::from_hex("010000004ddccd549d28f385ab457e98d1b11ce80bfea2c5ab93015ade4973e400000000bf4473e53794beae34e64fccc471dace6ae544180816f89591894e0f417a914cd74d6e49ffff001d323b3a7b0201000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0804ffff001d026e04ffffffff0100f2052a0100000043410446ef0102d1ec5240f0d061a4246c1bdef63fc3dbab7733052fbbf0ecd8f41fc26bf049ebb4f9527f374280259e7cfa99c48b0e3f39c51347a19a5819651503a5ac00000000010000000321f75f3139a013f50f315b23b0c9a2b6eac31e2bec98e5891c924664889942260000000049483045022100cb2c6b346a978ab8c61b18b5e9397755cbd17d6eb2fe0083ef32e067fa6c785a02206ce44e613f31d9a6b0517e46f3db1576e9812cc98d159bfdaf759a5014081b5c01ffffffff79cda0945903627c3da1f85fc95d0b8ee3e76ae0cfdc9a65d09744b1f8fc85430000000049483045022047957cdd957cfd0becd642f6b84d82f49b6cb4c51a91f49246908af7c3cfdf4a022100e96b46621f1bffcf5ea5982f88cef651e9354f5791602369bf5a82a6cd61a62501fffffffffe09f5fe3ffbf5ee97a54eb5e5069e9da6b4856ee86fc52938c2f979b0f38e82000000004847304402204165be9a4cbab8049e1af9723b96199bfd3e85f44c6b4c0177e3962686b26073022028f638da23fc003760861ad481ead4099312c60030d4cb57820ce4d33812a5ce01ffffffff01009d966b01000000434104ea1feff861b51fe3f5f8a3b12d0f4712db80e919548a80839fc47c6a21e66d957e9c5d8cd108c7a2d2324bad71f9904ac0ae7336507d785b17a2c115e427a32fac00000000").unwrap(); let cutoff_block = Vec::from_hex("010000004ddccd549d28f385ab457e98d1b11ce80bfea2c5ab93015ade4973e400000000bf4473e53794beae34e64fccc471dace6ae544180816f89591894e0f417a914cd74d6e49ffff001d323b3a7b0201000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0804ffff001d026e04ffffffff0100f2052a0100000043410446ef0102d1ec5240f0d061a4246c1bdef63fc3dbab7733052fbbf0ecd8f41fc26bf049ebb4f9527f374280259e7cfa99c48b0e3f39c51347a19a5819651503a5ac00000000010000000321f75f3139a013f50f315b23b0c9a2b6eac31e2bec98e5891c924664889942260000000049483045022100cb2c6b346a978ab8c61b18b5e9397755cbd17d6eb2fe0083ef32e067fa6c785a02206ce44e613f31d9a6b0517e46f3db1576e9812cc98d159bfdaf759a5014081b5c01ffffffff79cda0945903627c3da1f85fc95d0b8ee3e76ae0cfdc9a65d09744b1f8fc85430000000049483045022047957cdd957cfd0becd642f6b84d82f49b6cb4c51a91f49246908af7c3cfdf4a022100e96b46621f1bffcf5ea5982f88cef651e9354f5791602369bf5a82a6cd61a62501fffffffffe09f5fe3ffbf5ee97a54eb5e5069e9da6b4856ee86fc52938c2f979b0f38e82000000004847304402204165be9a4cbab8049e1af9723b96199bfd3e85f44c6b4c0177e3962686b26073022028f638da23fc003760861ad481ead4099312c60030d4cb57820ce4d33812a5ce01ffffffff01009d966b01000000434104ea1feff861b51fe3f5f8a3b12d0f4712db80e919548a80839fc47c6a21e66d957e9c5d8cd108c7a2d2324bad71f9904ac0ae7336507d785b17a2c115e427a32fac").unwrap(); - let prevhash = Vec::from_hex("4ddccd549d28f385ab457e98d1b11ce80bfea2c5ab93015ade4973e400000000").unwrap(); - let merkle = Vec::from_hex("bf4473e53794beae34e64fccc471dace6ae544180816f89591894e0f417a914c").unwrap(); + let prevhash = + Vec::from_hex("4ddccd549d28f385ab457e98d1b11ce80bfea2c5ab93015ade4973e400000000") + .unwrap(); + let merkle = + Vec::from_hex("bf4473e53794beae34e64fccc471dace6ae544180816f89591894e0f417a914c") + .unwrap(); let work = Uint256([0x100010001u64, 0, 0, 0]); let decode: Result = deserialize(&some_block); @@ -420,7 +432,10 @@ mod tests { assert_eq!(real_decode.header.bits, 486604799); 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.validate_pow(&real_decode.header.target()).unwrap(), + real_decode.block_hash() + ); assert_eq!(real_decode.header.difficulty(Network::Bitcoin), 1); // [test] TODO: check the transaction data @@ -441,13 +456,17 @@ mod tests { let decode: Result = deserialize(&segwit_block); - let prevhash = Vec::from_hex("2aa2f2ca794ccbd40c16e2f3333f6b8b683f9e7179b2c4d74906000000000000").unwrap(); - let merkle = Vec::from_hex("10bc26e70a2f672ad420a6153dd0c28b40a6002c55531bfc99bf8994a8e8f67e").unwrap(); + let prevhash = + Vec::from_hex("2aa2f2ca794ccbd40c16e2f3333f6b8b683f9e7179b2c4d74906000000000000") + .unwrap(); + let merkle = + Vec::from_hex("10bc26e70a2f672ad420a6153dd0c28b40a6002c55531bfc99bf8994a8e8f67e") + .unwrap(); let work = Uint256([0x257c3becdacc64u64, 0, 0, 0]); assert!(decode.is_ok()); let real_decode = decode.unwrap(); - assert_eq!(real_decode.header.version, 0x20000000); // VERSIONBITS but no bits set + assert_eq!(real_decode.header.version, 0x20000000); // VERSIONBITS but no bits set assert_eq!(serialize(&real_decode.header.prev_blockhash), prevhash); assert_eq!(serialize(&real_decode.header.merkle_root), merkle); assert_eq!(real_decode.header.merkle_root, real_decode.compute_merkle_root().unwrap()); @@ -455,7 +474,10 @@ mod tests { assert_eq!(real_decode.header.bits, 0x1a06d450); assert_eq!(real_decode.header.nonce, 1879759182); 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.validate_pow(&real_decode.header.target()).unwrap(), + real_decode.block_hash() + ); assert_eq!(real_decode.header.difficulty(Network::Testnet), 2456598); // [test] TODO: check the transaction data @@ -486,13 +508,17 @@ mod tests { #[test] fn validate_pow_test() { let some_header = Vec::from_hex("010000004ddccd549d28f385ab457e98d1b11ce80bfea2c5ab93015ade4973e400000000bf4473e53794beae34e64fccc471dace6ae544180816f89591894e0f417a914cd74d6e49ffff001d323b3a7b").unwrap(); - let some_header: BlockHeader = deserialize(&some_header).expect("Can't deserialize correct block header"); - assert_eq!(some_header.validate_pow(&some_header.target()).unwrap(), some_header.block_hash()); + let some_header: BlockHeader = + deserialize(&some_header).expect("Can't deserialize correct block header"); + assert_eq!( + some_header.validate_pow(&some_header.target()).unwrap(), + some_header.block_hash() + ); // test with zero target match some_header.validate_pow(&Uint256::default()) { Err(BlockBadTarget) => (), - _ => assert!(false) + _ => assert!(false), } // test with modified header @@ -500,7 +526,7 @@ mod tests { invalid_header.version = invalid_header.version + 1; match invalid_header.validate_pow(&invalid_header.target()) { Err(BlockBadProofOfWork) => (), - _ => assert!(false) + _ => assert!(false), } } @@ -508,7 +534,8 @@ mod tests { fn compact_roundrtip_test() { let some_header = Vec::from_hex("010000004ddccd549d28f385ab457e98d1b11ce80bfea2c5ab93015ade4973e400000000bf4473e53794beae34e64fccc471dace6ae544180816f89591894e0f417a914cd74d6e49ffff001d323b3a7b").unwrap(); - let header: BlockHeader = deserialize(&some_header).expect("Can't deserialize correct block header"); + let header: BlockHeader = + deserialize(&some_header).expect("Can't deserialize correct block header"); assert_eq!(header.bits, BlockHeader::compact_target_from_u256(&header.target())); } @@ -516,11 +543,12 @@ mod tests { #[cfg(all(test, feature = "unstable"))] mod benches { + use test::{black_box, Bencher}; + use super::Block; - use crate::EmptyWrite; use crate::consensus::{deserialize, Encodable}; - use test::{black_box, Bencher}; use crate::network::stream_reader::StreamReader; + use crate::EmptyWrite; #[bench] #[allow(deprecated)] diff --git a/src/blockdata/constants.rs b/src/blockdata/constants.rs index 1586c7e7a4..218e75aae0 100644 --- a/src/blockdata/constants.rs +++ b/src/blockdata/constants.rs @@ -19,18 +19,16 @@ //! single transaction. //! -use crate::prelude::*; - use core::default::Default; -use crate::hashes::hex::{self, HexIterator}; -use crate::hashes::sha256d; -use crate::blockdata::opcodes; -use crate::blockdata::script; -use crate::blockdata::transaction::{OutPoint, Transaction, TxOut, TxIn}; use crate::blockdata::block::{Block, BlockHeader}; +use crate::blockdata::transaction::{OutPoint, Transaction, TxIn, TxOut}; use crate::blockdata::witness::Witness; +use crate::blockdata::{opcodes, script}; +use crate::hashes::hex::{self, HexIterator}; +use crate::hashes::sha256d; use crate::network::constants::Network; +use crate::prelude::*; use crate::util::uint::Uint256; /// The maximum allowable sequence number @@ -87,10 +85,11 @@ fn bitcoin_genesis_tx() -> Transaction { }; // Inputs - let in_script = script::Builder::new().push_scriptint(486604799) - .push_scriptint(4) - .push_slice(b"The Times 03/Jan/2009 Chancellor on brink of second bailout for banks") - .into_script(); + let in_script = script::Builder::new() + .push_scriptint(486604799) + .push_scriptint(4) + .push_slice(b"The Times 03/Jan/2009 Chancellor on brink of second bailout for banks") + .into_script(); ret.input.push(TxIn { previous_output: OutPoint::null(), script_sig: in_script, @@ -106,10 +105,7 @@ fn bitcoin_genesis_tx() -> Transaction { .push_slice(script_bytes.unwrap().as_slice()) .push_opcode(opcodes::all::OP_CHECKSIG) .into_script(); - ret.output.push(TxOut { - value: 50 * COIN_VALUE, - script_pubkey: out_script - }); + ret.output.push(TxOut { value: 50 * COIN_VALUE, script_pubkey: out_script }); // end ret @@ -121,70 +117,63 @@ pub fn genesis_block(network: Network) -> Block { let hash: sha256d::Hash = txdata[0].txid().into(); let merkle_root = hash.into(); match network { - Network::Bitcoin => { - Block { - header: BlockHeader { - version: 1, - prev_blockhash: Default::default(), - merkle_root, - time: 1231006505, - bits: 0x1d00ffff, - nonce: 2083236893 - }, - txdata, - } - } - Network::Testnet => { - Block { - header: BlockHeader { - version: 1, - prev_blockhash: Default::default(), - merkle_root, - time: 1296688602, - bits: 0x1d00ffff, - nonce: 414098458 - }, - txdata, - } - } - Network::Signet => { - Block { - header: BlockHeader { - version: 1, - prev_blockhash: Default::default(), - merkle_root, - time: 1598918400, - bits: 0x1e0377ae, - nonce: 52613770 - }, - txdata, - } - } - Network::Regtest => { - Block { - header: BlockHeader { - version: 1, - prev_blockhash: Default::default(), - merkle_root, - time: 1296688602, - bits: 0x207fffff, - nonce: 2 - }, - txdata, - } - } + Network::Bitcoin => Block { + header: BlockHeader { + version: 1, + prev_blockhash: Default::default(), + merkle_root, + time: 1231006505, + bits: 0x1d00ffff, + nonce: 2083236893, + }, + txdata, + }, + Network::Testnet => Block { + header: BlockHeader { + version: 1, + prev_blockhash: Default::default(), + merkle_root, + time: 1296688602, + bits: 0x1d00ffff, + nonce: 414098458, + }, + txdata, + }, + Network::Signet => Block { + header: BlockHeader { + version: 1, + prev_blockhash: Default::default(), + merkle_root, + time: 1598918400, + bits: 0x1e0377ae, + nonce: 52613770, + }, + txdata, + }, + Network::Regtest => Block { + header: BlockHeader { + version: 1, + prev_blockhash: Default::default(), + merkle_root, + time: 1296688602, + bits: 0x207fffff, + nonce: 2, + }, + txdata, + }, } } #[cfg(test)] mod test { use core::default::Default; - use crate::hashes::hex::FromHex; - use crate::network::constants::Network; + use crate::blockdata::constants::{ + bitcoin_genesis_tx, genesis_block, COIN_VALUE, MAX_SEQUENCE, + }; use crate::consensus::encode::serialize; - use crate::blockdata::constants::{genesis_block, bitcoin_genesis_tx}; - use crate::blockdata::constants::{MAX_SEQUENCE, COIN_VALUE}; + use crate::hashes::hex::FromHex; + use crate::network::constants::Network; #[test] fn bitcoin_genesis_first_transaction() { @@ -204,8 +193,10 @@ mod test { assert_eq!(gen.output[0].value, 50 * COIN_VALUE); assert_eq!(gen.lock_time, 0); - assert_eq!(format!("{:x}", gen.wtxid()), - "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b".to_string()); + assert_eq!( + format!("{:x}", gen.wtxid()), + "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b".to_string() + ); } #[test] @@ -214,13 +205,17 @@ mod test { assert_eq!(gen.header.version, 1); assert_eq!(gen.header.prev_blockhash, Default::default()); - assert_eq!(format!("{:x}", gen.header.merkle_root), - "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b".to_string()); + assert_eq!( + format!("{:x}", gen.header.merkle_root), + "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b".to_string() + ); assert_eq!(gen.header.time, 1231006505); assert_eq!(gen.header.bits, 0x1d00ffff); assert_eq!(gen.header.nonce, 2083236893); - assert_eq!(format!("{:x}", gen.header.block_hash()), - "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f".to_string()); + assert_eq!( + format!("{:x}", gen.header.block_hash()), + "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f".to_string() + ); } #[test] @@ -228,13 +223,17 @@ mod test { let gen = genesis_block(Network::Testnet); assert_eq!(gen.header.version, 1); assert_eq!(gen.header.prev_blockhash, Default::default()); - assert_eq!(format!("{:x}", gen.header.merkle_root), - "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b".to_string()); + assert_eq!( + format!("{:x}", gen.header.merkle_root), + "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b".to_string() + ); assert_eq!(gen.header.time, 1296688602); assert_eq!(gen.header.bits, 0x1d00ffff); assert_eq!(gen.header.nonce, 414098458); - assert_eq!(format!("{:x}", gen.header.block_hash()), - "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943".to_string()); + assert_eq!( + format!("{:x}", gen.header.block_hash()), + "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943".to_string() + ); } #[test] @@ -242,13 +241,16 @@ mod test { let gen = genesis_block(Network::Signet); assert_eq!(gen.header.version, 1); assert_eq!(gen.header.prev_blockhash, Default::default()); - assert_eq!(format!("{:x}", gen.header.merkle_root), - "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b".to_string()); + assert_eq!( + format!("{:x}", gen.header.merkle_root), + "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b".to_string() + ); assert_eq!(gen.header.time, 1598918400); assert_eq!(gen.header.bits, 0x1e0377ae); assert_eq!(gen.header.nonce, 52613770); - assert_eq!(format!("{:x}", gen.header.block_hash()), - "00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6".to_string()); + assert_eq!( + format!("{:x}", gen.header.block_hash()), + "00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6".to_string() + ); } } - diff --git a/src/blockdata/mod.rs b/src/blockdata/mod.rs index 48f80ef8b7..e410cdaaea 100644 --- a/src/blockdata/mod.rs +++ b/src/blockdata/mod.rs @@ -18,10 +18,9 @@ //! transactions which make up the Bitcoin system. //! +pub mod block; pub mod constants; pub mod opcodes; pub mod script; pub mod transaction; -pub mod block; pub mod witness; - diff --git a/src/blockdata/opcodes.rs b/src/blockdata/opcodes.rs index ef1b054b00..81efe23a5d 100644 --- a/src/blockdata/opcodes.rs +++ b/src/blockdata/opcodes.rs @@ -20,11 +20,14 @@ #![allow(non_camel_case_types)] -#[cfg(feature = "serde")] use serde; +use core::convert::From; +use core::fmt; -#[cfg(feature = "serde")] use crate::prelude::*; +#[cfg(feature = "serde")] +use serde; -use core::{fmt, convert::From}; +#[cfg(feature = "serde")] +use crate::prelude::*; // Note: I am deliberately not implementing PartialOrd or Ord on the // opcode enum. If you want to check ranges of opcodes, etc., @@ -41,535 +44,536 @@ pub mod all { use super::All; /// Push an empty array onto the stack. - pub const OP_PUSHBYTES_0: All = All {code: 0x00}; + pub const OP_PUSHBYTES_0: All = All { code: 0x00 }; /// Push the next byte as an array onto the stack. - pub const OP_PUSHBYTES_1: All = All {code: 0x01}; + pub const OP_PUSHBYTES_1: All = All { code: 0x01 }; /// Push the next 2 bytes as an array onto the stack. - pub const OP_PUSHBYTES_2: All = All {code: 0x02}; + pub const OP_PUSHBYTES_2: All = All { code: 0x02 }; /// Push the next 2 bytes as an array onto the stack. - pub const OP_PUSHBYTES_3: All = All {code: 0x03}; + pub const OP_PUSHBYTES_3: All = All { code: 0x03 }; /// Push the next 4 bytes as an array onto the stack. - pub const OP_PUSHBYTES_4: All = All {code: 0x04}; + pub const OP_PUSHBYTES_4: All = All { code: 0x04 }; /// Push the next 5 bytes as an array onto the stack. - pub const OP_PUSHBYTES_5: All = All {code: 0x05}; + pub const OP_PUSHBYTES_5: All = All { code: 0x05 }; /// Push the next 6 bytes as an array onto the stack. - pub const OP_PUSHBYTES_6: All = All {code: 0x06}; + pub const OP_PUSHBYTES_6: All = All { code: 0x06 }; /// Push the next 7 bytes as an array onto the stack. - pub const OP_PUSHBYTES_7: All = All {code: 0x07}; + pub const OP_PUSHBYTES_7: All = All { code: 0x07 }; /// Push the next 8 bytes as an array onto the stack. - pub const OP_PUSHBYTES_8: All = All {code: 0x08}; + pub const OP_PUSHBYTES_8: All = All { code: 0x08 }; /// Push the next 9 bytes as an array onto the stack. - pub const OP_PUSHBYTES_9: All = All {code: 0x09}; + pub const OP_PUSHBYTES_9: All = All { code: 0x09 }; /// Push the next 10 bytes as an array onto the stack. - pub const OP_PUSHBYTES_10: All = All {code: 0x0a}; + pub const OP_PUSHBYTES_10: All = All { code: 0x0a }; /// Push the next 11 bytes as an array onto the stack. - pub const OP_PUSHBYTES_11: All = All {code: 0x0b}; + pub const OP_PUSHBYTES_11: All = All { code: 0x0b }; /// Push the next 12 bytes as an array onto the stack. - pub const OP_PUSHBYTES_12: All = All {code: 0x0c}; + pub const OP_PUSHBYTES_12: All = All { code: 0x0c }; /// Push the next 13 bytes as an array onto the stack. - pub const OP_PUSHBYTES_13: All = All {code: 0x0d}; + pub const OP_PUSHBYTES_13: All = All { code: 0x0d }; /// Push the next 14 bytes as an array onto the stack. - pub const OP_PUSHBYTES_14: All = All {code: 0x0e}; + pub const OP_PUSHBYTES_14: All = All { code: 0x0e }; /// Push the next 15 bytes as an array onto the stack. - pub const OP_PUSHBYTES_15: All = All {code: 0x0f}; + pub const OP_PUSHBYTES_15: All = All { code: 0x0f }; /// Push the next 16 bytes as an array onto the stack. - pub const OP_PUSHBYTES_16: All = All {code: 0x10}; + pub const OP_PUSHBYTES_16: All = All { code: 0x10 }; /// Push the next 17 bytes as an array onto the stack. - pub const OP_PUSHBYTES_17: All = All {code: 0x11}; + pub const OP_PUSHBYTES_17: All = All { code: 0x11 }; /// Push the next 18 bytes as an array onto the stack. - pub const OP_PUSHBYTES_18: All = All {code: 0x12}; + pub const OP_PUSHBYTES_18: All = All { code: 0x12 }; /// Push the next 19 bytes as an array onto the stack. - pub const OP_PUSHBYTES_19: All = All {code: 0x13}; + pub const OP_PUSHBYTES_19: All = All { code: 0x13 }; /// Push the next 20 bytes as an array onto the stack. - pub const OP_PUSHBYTES_20: All = All {code: 0x14}; + pub const OP_PUSHBYTES_20: All = All { code: 0x14 }; /// Push the next 21 bytes as an array onto the stack. - pub const OP_PUSHBYTES_21: All = All {code: 0x15}; + pub const OP_PUSHBYTES_21: All = All { code: 0x15 }; /// Push the next 22 bytes as an array onto the stack. - pub const OP_PUSHBYTES_22: All = All {code: 0x16}; + pub const OP_PUSHBYTES_22: All = All { code: 0x16 }; /// Push the next 23 bytes as an array onto the stack. - pub const OP_PUSHBYTES_23: All = All {code: 0x17}; + pub const OP_PUSHBYTES_23: All = All { code: 0x17 }; /// Push the next 24 bytes as an array onto the stack. - pub const OP_PUSHBYTES_24: All = All {code: 0x18}; + pub const OP_PUSHBYTES_24: All = All { code: 0x18 }; /// Push the next 25 bytes as an array onto the stack. - pub const OP_PUSHBYTES_25: All = All {code: 0x19}; + pub const OP_PUSHBYTES_25: All = All { code: 0x19 }; /// Push the next 26 bytes as an array onto the stack. - pub const OP_PUSHBYTES_26: All = All {code: 0x1a}; + pub const OP_PUSHBYTES_26: All = All { code: 0x1a }; /// Push the next 27 bytes as an array onto the stack. - pub const OP_PUSHBYTES_27: All = All {code: 0x1b}; + pub const OP_PUSHBYTES_27: All = All { code: 0x1b }; /// Push the next 28 bytes as an array onto the stack. - pub const OP_PUSHBYTES_28: All = All {code: 0x1c}; + pub const OP_PUSHBYTES_28: All = All { code: 0x1c }; /// Push the next 29 bytes as an array onto the stack. - pub const OP_PUSHBYTES_29: All = All {code: 0x1d}; + pub const OP_PUSHBYTES_29: All = All { code: 0x1d }; /// Push the next 30 bytes as an array onto the stack. - pub const OP_PUSHBYTES_30: All = All {code: 0x1e}; + pub const OP_PUSHBYTES_30: All = All { code: 0x1e }; /// Push the next 31 bytes as an array onto the stack. - pub const OP_PUSHBYTES_31: All = All {code: 0x1f}; + pub const OP_PUSHBYTES_31: All = All { code: 0x1f }; /// Push the next 32 bytes as an array onto the stack. - pub const OP_PUSHBYTES_32: All = All {code: 0x20}; + pub const OP_PUSHBYTES_32: All = All { code: 0x20 }; /// Push the next 33 bytes as an array onto the stack. - pub const OP_PUSHBYTES_33: All = All {code: 0x21}; + pub const OP_PUSHBYTES_33: All = All { code: 0x21 }; /// Push the next 34 bytes as an array onto the stack. - pub const OP_PUSHBYTES_34: All = All {code: 0x22}; + pub const OP_PUSHBYTES_34: All = All { code: 0x22 }; /// Push the next 35 bytes as an array onto the stack. - pub const OP_PUSHBYTES_35: All = All {code: 0x23}; + pub const OP_PUSHBYTES_35: All = All { code: 0x23 }; /// Push the next 36 bytes as an array onto the stack. - pub const OP_PUSHBYTES_36: All = All {code: 0x24}; + pub const OP_PUSHBYTES_36: All = All { code: 0x24 }; /// Push the next 37 bytes as an array onto the stack. - pub const OP_PUSHBYTES_37: All = All {code: 0x25}; + pub const OP_PUSHBYTES_37: All = All { code: 0x25 }; /// Push the next 38 bytes as an array onto the stack. - pub const OP_PUSHBYTES_38: All = All {code: 0x26}; + pub const OP_PUSHBYTES_38: All = All { code: 0x26 }; /// Push the next 39 bytes as an array onto the stack. - pub const OP_PUSHBYTES_39: All = All {code: 0x27}; + pub const OP_PUSHBYTES_39: All = All { code: 0x27 }; /// Push the next 40 bytes as an array onto the stack. - pub const OP_PUSHBYTES_40: All = All {code: 0x28}; + pub const OP_PUSHBYTES_40: All = All { code: 0x28 }; /// Push the next 41 bytes as an array onto the stack. - pub const OP_PUSHBYTES_41: All = All {code: 0x29}; + pub const OP_PUSHBYTES_41: All = All { code: 0x29 }; /// Push the next 42 bytes as an array onto the stack. - pub const OP_PUSHBYTES_42: All = All {code: 0x2a}; + pub const OP_PUSHBYTES_42: All = All { code: 0x2a }; /// Push the next 43 bytes as an array onto the stack. - pub const OP_PUSHBYTES_43: All = All {code: 0x2b}; + pub const OP_PUSHBYTES_43: All = All { code: 0x2b }; /// Push the next 44 bytes as an array onto the stack. - pub const OP_PUSHBYTES_44: All = All {code: 0x2c}; + pub const OP_PUSHBYTES_44: All = All { code: 0x2c }; /// Push the next 45 bytes as an array onto the stack. - pub const OP_PUSHBYTES_45: All = All {code: 0x2d}; + pub const OP_PUSHBYTES_45: All = All { code: 0x2d }; /// Push the next 46 bytes as an array onto the stack. - pub const OP_PUSHBYTES_46: All = All {code: 0x2e}; + pub const OP_PUSHBYTES_46: All = All { code: 0x2e }; /// Push the next 47 bytes as an array onto the stack. - pub const OP_PUSHBYTES_47: All = All {code: 0x2f}; + pub const OP_PUSHBYTES_47: All = All { code: 0x2f }; /// Push the next 48 bytes as an array onto the stack. - pub const OP_PUSHBYTES_48: All = All {code: 0x30}; + pub const OP_PUSHBYTES_48: All = All { code: 0x30 }; /// Push the next 49 bytes as an array onto the stack. - pub const OP_PUSHBYTES_49: All = All {code: 0x31}; + pub const OP_PUSHBYTES_49: All = All { code: 0x31 }; /// Push the next 50 bytes as an array onto the stack. - pub const OP_PUSHBYTES_50: All = All {code: 0x32}; + pub const OP_PUSHBYTES_50: All = All { code: 0x32 }; /// Push the next 51 bytes as an array onto the stack. - pub const OP_PUSHBYTES_51: All = All {code: 0x33}; + pub const OP_PUSHBYTES_51: All = All { code: 0x33 }; /// Push the next 52 bytes as an array onto the stack. - pub const OP_PUSHBYTES_52: All = All {code: 0x34}; + pub const OP_PUSHBYTES_52: All = All { code: 0x34 }; /// Push the next 53 bytes as an array onto the stack. - pub const OP_PUSHBYTES_53: All = All {code: 0x35}; + pub const OP_PUSHBYTES_53: All = All { code: 0x35 }; /// Push the next 54 bytes as an array onto the stack. - pub const OP_PUSHBYTES_54: All = All {code: 0x36}; + pub const OP_PUSHBYTES_54: All = All { code: 0x36 }; /// Push the next 55 bytes as an array onto the stack. - pub const OP_PUSHBYTES_55: All = All {code: 0x37}; + pub const OP_PUSHBYTES_55: All = All { code: 0x37 }; /// Push the next 56 bytes as an array onto the stack. - pub const OP_PUSHBYTES_56: All = All {code: 0x38}; + pub const OP_PUSHBYTES_56: All = All { code: 0x38 }; /// Push the next 57 bytes as an array onto the stack. - pub const OP_PUSHBYTES_57: All = All {code: 0x39}; + pub const OP_PUSHBYTES_57: All = All { code: 0x39 }; /// Push the next 58 bytes as an array onto the stack. - pub const OP_PUSHBYTES_58: All = All {code: 0x3a}; + pub const OP_PUSHBYTES_58: All = All { code: 0x3a }; /// Push the next 59 bytes as an array onto the stack. - pub const OP_PUSHBYTES_59: All = All {code: 0x3b}; + pub const OP_PUSHBYTES_59: All = All { code: 0x3b }; /// Push the next 60 bytes as an array onto the stack. - pub const OP_PUSHBYTES_60: All = All {code: 0x3c}; + pub const OP_PUSHBYTES_60: All = All { code: 0x3c }; /// Push the next 61 bytes as an array onto the stack. - pub const OP_PUSHBYTES_61: All = All {code: 0x3d}; + pub const OP_PUSHBYTES_61: All = All { code: 0x3d }; /// Push the next 62 bytes as an array onto the stack. - pub const OP_PUSHBYTES_62: All = All {code: 0x3e}; + pub const OP_PUSHBYTES_62: All = All { code: 0x3e }; /// Push the next 63 bytes as an array onto the stack. - pub const OP_PUSHBYTES_63: All = All {code: 0x3f}; + pub const OP_PUSHBYTES_63: All = All { code: 0x3f }; /// Push the next 64 bytes as an array onto the stack. - pub const OP_PUSHBYTES_64: All = All {code: 0x40}; + pub const OP_PUSHBYTES_64: All = All { code: 0x40 }; /// Push the next 65 bytes as an array onto the stack. - pub const OP_PUSHBYTES_65: All = All {code: 0x41}; + pub const OP_PUSHBYTES_65: All = All { code: 0x41 }; /// Push the next 66 bytes as an array onto the stack. - pub const OP_PUSHBYTES_66: All = All {code: 0x42}; + pub const OP_PUSHBYTES_66: All = All { code: 0x42 }; /// Push the next 67 bytes as an array onto the stack. - pub const OP_PUSHBYTES_67: All = All {code: 0x43}; + pub const OP_PUSHBYTES_67: All = All { code: 0x43 }; /// Push the next 68 bytes as an array onto the stack. - pub const OP_PUSHBYTES_68: All = All {code: 0x44}; + pub const OP_PUSHBYTES_68: All = All { code: 0x44 }; /// Push the next 69 bytes as an array onto the stack. - pub const OP_PUSHBYTES_69: All = All {code: 0x45}; + pub const OP_PUSHBYTES_69: All = All { code: 0x45 }; /// Push the next 70 bytes as an array onto the stack. - pub const OP_PUSHBYTES_70: All = All {code: 0x46}; + pub const OP_PUSHBYTES_70: All = All { code: 0x46 }; /// Push the next 71 bytes as an array onto the stack. - pub const OP_PUSHBYTES_71: All = All {code: 0x47}; + pub const OP_PUSHBYTES_71: All = All { code: 0x47 }; /// Push the next 72 bytes as an array onto the stack. - pub const OP_PUSHBYTES_72: All = All {code: 0x48}; + pub const OP_PUSHBYTES_72: All = All { code: 0x48 }; /// Push the next 73 bytes as an array onto the stack. - pub const OP_PUSHBYTES_73: All = All {code: 0x49}; + pub const OP_PUSHBYTES_73: All = All { code: 0x49 }; /// Push the next 74 bytes as an array onto the stack. - pub const OP_PUSHBYTES_74: All = All {code: 0x4a}; + pub const OP_PUSHBYTES_74: All = All { code: 0x4a }; /// Push the next 75 bytes as an array onto the stack. - pub const OP_PUSHBYTES_75: All = All {code: 0x4b}; + pub const OP_PUSHBYTES_75: All = All { code: 0x4b }; /// Read the next byte as N; push the next N bytes as an array onto the stack. - pub const OP_PUSHDATA1: All = All {code: 0x4c}; + pub const OP_PUSHDATA1: All = All { code: 0x4c }; /// Read the next 2 bytes as N; push the next N bytes as an array onto the stack. - pub const OP_PUSHDATA2: All = All {code: 0x4d}; + pub const OP_PUSHDATA2: All = All { code: 0x4d }; /// Read the next 4 bytes as N; push the next N bytes as an array onto the stack. - pub const OP_PUSHDATA4: All = All {code: 0x4e}; + pub const OP_PUSHDATA4: All = All { code: 0x4e }; /// Push the array `0x81` onto the stack. - pub const OP_PUSHNUM_NEG1: All = All {code: 0x4f}; + pub const OP_PUSHNUM_NEG1: All = All { code: 0x4f }; /// Synonym for OP_RETURN. - pub const OP_RESERVED: All = All {code: 0x50}; + pub const OP_RESERVED: All = All { code: 0x50 }; /// Push the array `0x01` onto the stack. - pub const OP_PUSHNUM_1: All = All {code: 0x51}; + pub const OP_PUSHNUM_1: All = All { code: 0x51 }; /// Push the array `0x02` onto the stack. - pub const OP_PUSHNUM_2: All = All {code: 0x52}; + pub const OP_PUSHNUM_2: All = All { code: 0x52 }; /// Push the array `0x03` onto the stack. - pub const OP_PUSHNUM_3: All = All {code: 0x53}; + pub const OP_PUSHNUM_3: All = All { code: 0x53 }; /// Push the array `0x04` onto the stack. - pub const OP_PUSHNUM_4: All = All {code: 0x54}; + pub const OP_PUSHNUM_4: All = All { code: 0x54 }; /// Push the array `0x05` onto the stack. - pub const OP_PUSHNUM_5: All = All {code: 0x55}; + pub const OP_PUSHNUM_5: All = All { code: 0x55 }; /// Push the array `0x06` onto the stack. - pub const OP_PUSHNUM_6: All = All {code: 0x56}; + pub const OP_PUSHNUM_6: All = All { code: 0x56 }; /// Push the array `0x07` onto the stack. - pub const OP_PUSHNUM_7: All = All {code: 0x57}; + pub const OP_PUSHNUM_7: All = All { code: 0x57 }; /// Push the array `0x08` onto the stack. - pub const OP_PUSHNUM_8: All = All {code: 0x58}; + pub const OP_PUSHNUM_8: All = All { code: 0x58 }; /// Push the array `0x09` onto the stack. - pub const OP_PUSHNUM_9: All = All {code: 0x59}; + pub const OP_PUSHNUM_9: All = All { code: 0x59 }; /// Push the array `0x0a` onto the stack. - pub const OP_PUSHNUM_10: All = All {code: 0x5a}; + pub const OP_PUSHNUM_10: All = All { code: 0x5a }; /// Push the array `0x0b` onto the stack. - pub const OP_PUSHNUM_11: All = All {code: 0x5b}; + pub const OP_PUSHNUM_11: All = All { code: 0x5b }; /// Push the array `0x0c` onto the stack. - pub const OP_PUSHNUM_12: All = All {code: 0x5c}; + pub const OP_PUSHNUM_12: All = All { code: 0x5c }; /// Push the array `0x0d` onto the stack. - pub const OP_PUSHNUM_13: All = All {code: 0x5d}; + pub const OP_PUSHNUM_13: All = All { code: 0x5d }; /// Push the array `0x0e` onto the stack. - pub const OP_PUSHNUM_14: All = All {code: 0x5e}; + pub const OP_PUSHNUM_14: All = All { code: 0x5e }; /// Push the array `0x0f` onto the stack. - pub const OP_PUSHNUM_15: All = All {code: 0x5f}; + pub const OP_PUSHNUM_15: All = All { code: 0x5f }; /// Push the array `0x10` onto the stack. - pub const OP_PUSHNUM_16: All = All {code: 0x60}; + pub const OP_PUSHNUM_16: All = All { code: 0x60 }; /// Does nothing. - pub const OP_NOP: All = All {code: 0x61}; + pub const OP_NOP: All = All { code: 0x61 }; /// Synonym for OP_RETURN. - pub const OP_VER: All = All {code: 0x62}; + pub const OP_VER: All = All { code: 0x62 }; /// Pop and execute the next statements if a nonzero element was popped. - pub const OP_IF: All = All {code: 0x63}; + pub const OP_IF: All = All { code: 0x63 }; /// Pop and execute the next statements if a zero element was popped. - pub const OP_NOTIF: All = All {code: 0x64}; + pub const OP_NOTIF: All = All { code: 0x64 }; /// Fail the script unconditionally, does not even need to be executed. - pub const OP_VERIF: All = All {code: 0x65}; + pub const OP_VERIF: All = All { code: 0x65 }; /// Fail the script unconditionally, does not even need to be executed. - pub const OP_VERNOTIF: All = All {code: 0x66}; + pub const OP_VERNOTIF: All = All { code: 0x66 }; /// Execute statements if those after the previous OP_IF were not, and vice-versa. /// If there is no previous OP_IF, this acts as a RETURN. - pub const OP_ELSE: All = All {code: 0x67}; + pub const OP_ELSE: All = All { code: 0x67 }; /// Pop and execute the next statements if a zero element was popped. - pub const OP_ENDIF: All = All {code: 0x68}; + pub const OP_ENDIF: All = All { code: 0x68 }; /// If the top value is zero or the stack is empty, fail; otherwise, pop the stack. - pub const OP_VERIFY: All = All {code: 0x69}; + pub const OP_VERIFY: All = All { code: 0x69 }; /// Fail the script immediately. (Must be executed.). - pub const OP_RETURN: All = All {code: 0x6a}; + pub const OP_RETURN: All = All { code: 0x6a }; /// Pop one element from the main stack onto the alt stack. - pub const OP_TOALTSTACK: All = All {code: 0x6b}; + pub const OP_TOALTSTACK: All = All { code: 0x6b }; /// Pop one element from the alt stack onto the main stack. - pub const OP_FROMALTSTACK: All = All {code: 0x6c}; + pub const OP_FROMALTSTACK: All = All { code: 0x6c }; /// Drops the top two stack items. - pub const OP_2DROP: All = All {code: 0x6d}; + pub const OP_2DROP: All = All { code: 0x6d }; /// Duplicates the top two stack items as AB -> ABAB. - pub const OP_2DUP: All = All {code: 0x6e}; + pub const OP_2DUP: All = All { code: 0x6e }; /// Duplicates the two three stack items as ABC -> ABCABC. - pub const OP_3DUP: All = All {code: 0x6f}; + pub const OP_3DUP: All = All { code: 0x6f }; /// Copies the two stack items of items two spaces back to /// the front, as xxAB -> ABxxAB. - pub const OP_2OVER: All = All {code: 0x70}; + pub const OP_2OVER: All = All { code: 0x70 }; /// Moves the two stack items four spaces back to the front, /// as xxxxAB -> ABxxxx. - pub const OP_2ROT: All = All {code: 0x71}; + pub const OP_2ROT: All = All { code: 0x71 }; /// Swaps the top two pairs, as ABCD -> CDAB. - pub const OP_2SWAP: All = All {code: 0x72}; + pub const OP_2SWAP: All = All { code: 0x72 }; /// Duplicate the top stack element unless it is zero. - pub const OP_IFDUP: All = All {code: 0x73}; + pub const OP_IFDUP: All = All { code: 0x73 }; /// Push the current number of stack items onto the stack. - pub const OP_DEPTH: All = All {code: 0x74}; + pub const OP_DEPTH: All = All { code: 0x74 }; /// Drops the top stack item. - pub const OP_DROP: All = All {code: 0x75}; + pub const OP_DROP: All = All { code: 0x75 }; /// Duplicates the top stack item. - pub const OP_DUP: All = All {code: 0x76}; + pub const OP_DUP: All = All { code: 0x76 }; /// Drops the second-to-top stack item. - pub const OP_NIP: All = All {code: 0x77}; + pub const OP_NIP: All = All { code: 0x77 }; /// Copies the second-to-top stack item, as xA -> AxA. - pub const OP_OVER: All = All {code: 0x78}; + pub const OP_OVER: All = All { code: 0x78 }; /// Pop the top stack element as N. Copy the Nth stack element to the top. - pub const OP_PICK: All = All {code: 0x79}; + pub const OP_PICK: All = All { code: 0x79 }; /// Pop the top stack element as N. Move the Nth stack element to the top. - pub const OP_ROLL: All = All {code: 0x7a}; + pub const OP_ROLL: All = All { code: 0x7a }; /// Rotate the top three stack items, as [top next1 next2] -> [next2 top next1]. - pub const OP_ROT: All = All {code: 0x7b}; + pub const OP_ROT: All = All { code: 0x7b }; /// Swap the top two stack items. - pub const OP_SWAP: All = All {code: 0x7c}; + pub const OP_SWAP: All = All { code: 0x7c }; /// Copy the top stack item to before the second item, as [top next] -> [top next top]. - pub const OP_TUCK: All = All {code: 0x7d}; + pub const OP_TUCK: All = All { code: 0x7d }; /// Fail the script unconditionally, does not even need to be executed. - pub const OP_CAT: All = All {code: 0x7e}; + pub const OP_CAT: All = All { code: 0x7e }; /// Fail the script unconditionally, does not even need to be executed. - pub const OP_SUBSTR: All = All {code: 0x7f}; + pub const OP_SUBSTR: All = All { code: 0x7f }; /// Fail the script unconditionally, does not even need to be executed. - pub const OP_LEFT: All = All {code: 0x80}; + pub const OP_LEFT: All = All { code: 0x80 }; /// Fail the script unconditionally, does not even need to be executed. - pub const OP_RIGHT: All = All {code: 0x81}; + pub const OP_RIGHT: All = All { code: 0x81 }; /// Pushes the length of the top stack item onto the stack. - pub const OP_SIZE: All = All {code: 0x82}; + pub const OP_SIZE: All = All { code: 0x82 }; /// Fail the script unconditionally, does not even need to be executed. - pub const OP_INVERT: All = All {code: 0x83}; + pub const OP_INVERT: All = All { code: 0x83 }; /// Fail the script unconditionally, does not even need to be executed. - pub const OP_AND: All = All {code: 0x84}; + pub const OP_AND: All = All { code: 0x84 }; /// Fail the script unconditionally, does not even need to be executed. - pub const OP_OR: All = All {code: 0x85}; + pub const OP_OR: All = All { code: 0x85 }; /// Fail the script unconditionally, does not even need to be executed. - pub const OP_XOR: All = All {code: 0x86}; + pub const OP_XOR: All = All { code: 0x86 }; /// Pushes 1 if the inputs are exactly equal, 0 otherwise. - pub const OP_EQUAL: All = All {code: 0x87}; + pub const OP_EQUAL: All = All { code: 0x87 }; /// Returns success if the inputs are exactly equal, failure otherwise. - pub const OP_EQUALVERIFY: All = All {code: 0x88}; + pub const OP_EQUALVERIFY: All = All { code: 0x88 }; /// Synonym for OP_RETURN. - pub const OP_RESERVED1: All = All {code: 0x89}; + pub const OP_RESERVED1: All = All { code: 0x89 }; /// Synonym for OP_RETURN. - pub const OP_RESERVED2: All = All {code: 0x8a}; + pub const OP_RESERVED2: All = All { code: 0x8a }; /// Increment the top stack element in place. - pub const OP_1ADD: All = All {code: 0x8b}; + pub const OP_1ADD: All = All { code: 0x8b }; /// Decrement the top stack element in place. - pub const OP_1SUB: All = All {code: 0x8c}; + pub const OP_1SUB: All = All { code: 0x8c }; /// Fail the script unconditionally, does not even need to be executed. - pub const OP_2MUL: All = All {code: 0x8d}; + pub const OP_2MUL: All = All { code: 0x8d }; /// Fail the script unconditionally, does not even need to be executed. - pub const OP_2DIV: All = All {code: 0x8e}; + pub const OP_2DIV: All = All { code: 0x8e }; /// Multiply the top stack item by -1 in place. - pub const OP_NEGATE: All = All {code: 0x8f}; + pub const OP_NEGATE: All = All { code: 0x8f }; /// Absolute value the top stack item in place. - pub const OP_ABS: All = All {code: 0x90}; + pub const OP_ABS: All = All { code: 0x90 }; /// Map 0 to 1 and everything else to 0, in place. - pub const OP_NOT: All = All {code: 0x91}; + pub const OP_NOT: All = All { code: 0x91 }; /// Map 0 to 0 and everything else to 1, in place. - pub const OP_0NOTEQUAL: All = All {code: 0x92}; + pub const OP_0NOTEQUAL: All = All { code: 0x92 }; /// Pop two stack items and push their sum. - pub const OP_ADD: All = All {code: 0x93}; + pub const OP_ADD: All = All { code: 0x93 }; /// Pop two stack items and push the second minus the top. - pub const OP_SUB: All = All {code: 0x94}; + pub const OP_SUB: All = All { code: 0x94 }; /// Fail the script unconditionally, does not even need to be executed. - pub const OP_MUL: All = All {code: 0x95}; + pub const OP_MUL: All = All { code: 0x95 }; /// Fail the script unconditionally, does not even need to be executed. - pub const OP_DIV: All = All {code: 0x96}; + pub const OP_DIV: All = All { code: 0x96 }; /// Fail the script unconditionally, does not even need to be executed. - pub const OP_MOD: All = All {code: 0x97}; + pub const OP_MOD: All = All { code: 0x97 }; /// Fail the script unconditionally, does not even need to be executed. - pub const OP_LSHIFT: All = All {code: 0x98}; + pub const OP_LSHIFT: All = All { code: 0x98 }; /// Fail the script unconditionally, does not even need to be executed. - pub const OP_RSHIFT: All = All {code: 0x99}; + pub const OP_RSHIFT: All = All { code: 0x99 }; /// Pop the top two stack items and push 1 if both are nonzero, else push 0. - pub const OP_BOOLAND: All = All {code: 0x9a}; + pub const OP_BOOLAND: All = All { code: 0x9a }; /// Pop the top two stack items and push 1 if either is nonzero, else push 0. - pub const OP_BOOLOR: All = All {code: 0x9b}; + pub const OP_BOOLOR: All = All { code: 0x9b }; /// Pop the top two stack items and push 1 if both are numerically equal, else push 0. - pub const OP_NUMEQUAL: All = All {code: 0x9c}; + pub const OP_NUMEQUAL: All = All { code: 0x9c }; /// Pop the top two stack items and return success if both are numerically equal, else return failure. - pub const OP_NUMEQUALVERIFY: All = All {code: 0x9d}; + pub const OP_NUMEQUALVERIFY: All = All { code: 0x9d }; /// Pop the top two stack items and push 0 if both are numerically equal, else push 1. - pub const OP_NUMNOTEQUAL: All = All {code: 0x9e}; + pub const OP_NUMNOTEQUAL: All = All { code: 0x9e }; /// Pop the top two items; push 1 if the second is less than the top, 0 otherwise. - pub const OP_LESSTHAN : All = All {code: 0x9f}; + pub const OP_LESSTHAN: All = All { code: 0x9f }; /// Pop the top two items; push 1 if the second is greater than the top, 0 otherwise. - pub const OP_GREATERTHAN : All = All {code: 0xa0}; + pub const OP_GREATERTHAN: All = All { code: 0xa0 }; /// Pop the top two items; push 1 if the second is <= the top, 0 otherwise. - pub const OP_LESSTHANOREQUAL : All = All {code: 0xa1}; + pub const OP_LESSTHANOREQUAL: All = All { code: 0xa1 }; /// Pop the top two items; push 1 if the second is >= the top, 0 otherwise. - pub const OP_GREATERTHANOREQUAL : All = All {code: 0xa2}; + pub const OP_GREATERTHANOREQUAL: All = All { code: 0xa2 }; /// Pop the top two items; push the smaller. - pub const OP_MIN: All = All {code: 0xa3}; + pub const OP_MIN: All = All { code: 0xa3 }; /// Pop the top two items; push the larger. - pub const OP_MAX: All = All {code: 0xa4}; + pub const OP_MAX: All = All { code: 0xa4 }; /// Pop the top three items; if the top is >= the second and < the third, push 1, otherwise push 0. - pub const OP_WITHIN: All = All {code: 0xa5}; + pub const OP_WITHIN: All = All { code: 0xa5 }; /// Pop the top stack item and push its RIPEMD160 hash. - pub const OP_RIPEMD160: All = All {code: 0xa6}; + pub const OP_RIPEMD160: All = All { code: 0xa6 }; /// Pop the top stack item and push its SHA1 hash. - pub const OP_SHA1: All = All {code: 0xa7}; + pub const OP_SHA1: All = All { code: 0xa7 }; /// Pop the top stack item and push its SHA256 hash. - pub const OP_SHA256: All = All {code: 0xa8}; + pub const OP_SHA256: All = All { code: 0xa8 }; /// Pop the top stack item and push its RIPEMD(SHA256) hash. - pub const OP_HASH160: All = All {code: 0xa9}; + pub const OP_HASH160: All = All { code: 0xa9 }; /// Pop the top stack item and push its SHA256(SHA256) hash. - pub const OP_HASH256: All = All {code: 0xaa}; + pub const OP_HASH256: All = All { code: 0xaa }; /// Ignore this and everything preceding when deciding what to sign when signature-checking. - pub const OP_CODESEPARATOR: All = All {code: 0xab}; + pub const OP_CODESEPARATOR: All = All { code: 0xab }; /// pushing 1/0 for success/failure. - pub const OP_CHECKSIG: All = All {code: 0xac}; + pub const OP_CHECKSIG: All = All { code: 0xac }; /// returning success/failure. - pub const OP_CHECKSIGVERIFY: All = All {code: 0xad}; + pub const OP_CHECKSIGVERIFY: All = All { code: 0xad }; /// Pop N, N pubkeys, M, M signatures, a dummy (due to bug in reference code), and verify that all M signatures are valid. /// Push 1 for "all valid", 0 otherwise. - pub const OP_CHECKMULTISIG: All = All {code: 0xae}; + pub const OP_CHECKMULTISIG: All = All { code: 0xae }; /// Like the above but return success/failure. - pub const OP_CHECKMULTISIGVERIFY: All = All {code: 0xaf}; + pub const OP_CHECKMULTISIGVERIFY: All = All { code: 0xaf }; /// Does nothing. - pub const OP_NOP1: All = All {code: 0xb0}; + pub const OP_NOP1: All = All { code: 0xb0 }; /// - pub const OP_CLTV: All = All {code: 0xb1}; + pub const OP_CLTV: All = All { code: 0xb1 }; /// - pub const OP_CSV: All = All {code: 0xb2}; + pub const OP_CSV: All = All { code: 0xb2 }; /// Does nothing. - pub const OP_NOP4: All = All {code: 0xb3}; + pub const OP_NOP4: All = All { code: 0xb3 }; /// Does nothing. - pub const OP_NOP5: All = All {code: 0xb4}; + pub const OP_NOP5: All = All { code: 0xb4 }; /// Does nothing. - pub const OP_NOP6: All = All {code: 0xb5}; + pub const OP_NOP6: All = All { code: 0xb5 }; /// Does nothing. - pub const OP_NOP7: All = All {code: 0xb6}; + pub const OP_NOP7: All = All { code: 0xb6 }; /// Does nothing. - pub const OP_NOP8: All = All {code: 0xb7}; + pub const OP_NOP8: All = All { code: 0xb7 }; /// Does nothing. - pub const OP_NOP9: All = All {code: 0xb8}; + pub const OP_NOP9: All = All { code: 0xb8 }; /// Does nothing. - pub const OP_NOP10: All = All {code: 0xb9}; + pub const OP_NOP10: All = All { code: 0xb9 }; // Every other opcode acts as OP_RETURN /// OP_CHECKSIGADD post tapscript. - pub const OP_CHECKSIGADD: All = All {code: 0xba}; + pub const OP_CHECKSIGADD: All = All { code: 0xba }; /// Synonym for OP_RETURN. - pub const OP_RETURN_187: All = All {code: 0xbb}; + pub const OP_RETURN_187: All = All { code: 0xbb }; /// Synonym for OP_RETURN. - pub const OP_RETURN_188: All = All {code: 0xbc}; + pub const OP_RETURN_188: All = All { code: 0xbc }; /// Synonym for OP_RETURN. - pub const OP_RETURN_189: All = All {code: 0xbd}; + pub const OP_RETURN_189: All = All { code: 0xbd }; /// Synonym for OP_RETURN. - pub const OP_RETURN_190: All = All {code: 0xbe}; + pub const OP_RETURN_190: All = All { code: 0xbe }; /// Synonym for OP_RETURN. - pub const OP_RETURN_191: All = All {code: 0xbf}; + pub const OP_RETURN_191: All = All { code: 0xbf }; /// Synonym for OP_RETURN. - pub const OP_RETURN_192: All = All {code: 0xc0}; + pub const OP_RETURN_192: All = All { code: 0xc0 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_193: All = All {code: 0xc1}; + pub const OP_RETURN_193: All = All { code: 0xc1 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_194: All = All {code: 0xc2}; + pub const OP_RETURN_194: All = All { code: 0xc2 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_195: All = All {code: 0xc3}; + pub const OP_RETURN_195: All = All { code: 0xc3 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_196: All = All {code: 0xc4}; + pub const OP_RETURN_196: All = All { code: 0xc4 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_197: All = All {code: 0xc5}; + pub const OP_RETURN_197: All = All { code: 0xc5 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_198: All = All {code: 0xc6}; + pub const OP_RETURN_198: All = All { code: 0xc6 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_199: All = All {code: 0xc7}; + pub const OP_RETURN_199: All = All { code: 0xc7 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_200: All = All {code: 0xc8}; + pub const OP_RETURN_200: All = All { code: 0xc8 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_201: All = All {code: 0xc9}; + pub const OP_RETURN_201: All = All { code: 0xc9 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_202: All = All {code: 0xca}; + pub const OP_RETURN_202: All = All { code: 0xca }; /// Synonym for OP_RETURN. - pub const OP_RETURN_203: All = All {code: 0xcb}; + pub const OP_RETURN_203: All = All { code: 0xcb }; /// Synonym for OP_RETURN. - pub const OP_RETURN_204: All = All {code: 0xcc}; + pub const OP_RETURN_204: All = All { code: 0xcc }; /// Synonym for OP_RETURN. - pub const OP_RETURN_205: All = All {code: 0xcd}; + pub const OP_RETURN_205: All = All { code: 0xcd }; /// Synonym for OP_RETURN. - pub const OP_RETURN_206: All = All {code: 0xce}; + pub const OP_RETURN_206: All = All { code: 0xce }; /// Synonym for OP_RETURN. - pub const OP_RETURN_207: All = All {code: 0xcf}; + pub const OP_RETURN_207: All = All { code: 0xcf }; /// Synonym for OP_RETURN. - pub const OP_RETURN_208: All = All {code: 0xd0}; + pub const OP_RETURN_208: All = All { code: 0xd0 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_209: All = All {code: 0xd1}; + pub const OP_RETURN_209: All = All { code: 0xd1 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_210: All = All {code: 0xd2}; + pub const OP_RETURN_210: All = All { code: 0xd2 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_211: All = All {code: 0xd3}; + pub const OP_RETURN_211: All = All { code: 0xd3 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_212: All = All {code: 0xd4}; + pub const OP_RETURN_212: All = All { code: 0xd4 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_213: All = All {code: 0xd5}; + pub const OP_RETURN_213: All = All { code: 0xd5 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_214: All = All {code: 0xd6}; + pub const OP_RETURN_214: All = All { code: 0xd6 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_215: All = All {code: 0xd7}; + pub const OP_RETURN_215: All = All { code: 0xd7 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_216: All = All {code: 0xd8}; + pub const OP_RETURN_216: All = All { code: 0xd8 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_217: All = All {code: 0xd9}; + pub const OP_RETURN_217: All = All { code: 0xd9 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_218: All = All {code: 0xda}; + pub const OP_RETURN_218: All = All { code: 0xda }; /// Synonym for OP_RETURN. - pub const OP_RETURN_219: All = All {code: 0xdb}; + pub const OP_RETURN_219: All = All { code: 0xdb }; /// Synonym for OP_RETURN. - pub const OP_RETURN_220: All = All {code: 0xdc}; + pub const OP_RETURN_220: All = All { code: 0xdc }; /// Synonym for OP_RETURN. - pub const OP_RETURN_221: All = All {code: 0xdd}; + pub const OP_RETURN_221: All = All { code: 0xdd }; /// Synonym for OP_RETURN. - pub const OP_RETURN_222: All = All {code: 0xde}; + pub const OP_RETURN_222: All = All { code: 0xde }; /// Synonym for OP_RETURN. - pub const OP_RETURN_223: All = All {code: 0xdf}; + pub const OP_RETURN_223: All = All { code: 0xdf }; /// Synonym for OP_RETURN. - pub const OP_RETURN_224: All = All {code: 0xe0}; + pub const OP_RETURN_224: All = All { code: 0xe0 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_225: All = All {code: 0xe1}; + pub const OP_RETURN_225: All = All { code: 0xe1 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_226: All = All {code: 0xe2}; + pub const OP_RETURN_226: All = All { code: 0xe2 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_227: All = All {code: 0xe3}; + pub const OP_RETURN_227: All = All { code: 0xe3 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_228: All = All {code: 0xe4}; + pub const OP_RETURN_228: All = All { code: 0xe4 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_229: All = All {code: 0xe5}; + pub const OP_RETURN_229: All = All { code: 0xe5 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_230: All = All {code: 0xe6}; + pub const OP_RETURN_230: All = All { code: 0xe6 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_231: All = All {code: 0xe7}; + pub const OP_RETURN_231: All = All { code: 0xe7 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_232: All = All {code: 0xe8}; + pub const OP_RETURN_232: All = All { code: 0xe8 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_233: All = All {code: 0xe9}; + pub const OP_RETURN_233: All = All { code: 0xe9 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_234: All = All {code: 0xea}; + pub const OP_RETURN_234: All = All { code: 0xea }; /// Synonym for OP_RETURN. - pub const OP_RETURN_235: All = All {code: 0xeb}; + pub const OP_RETURN_235: All = All { code: 0xeb }; /// Synonym for OP_RETURN. - pub const OP_RETURN_236: All = All {code: 0xec}; + pub const OP_RETURN_236: All = All { code: 0xec }; /// Synonym for OP_RETURN. - pub const OP_RETURN_237: All = All {code: 0xed}; + pub const OP_RETURN_237: All = All { code: 0xed }; /// Synonym for OP_RETURN. - pub const OP_RETURN_238: All = All {code: 0xee}; + pub const OP_RETURN_238: All = All { code: 0xee }; /// Synonym for OP_RETURN. - pub const OP_RETURN_239: All = All {code: 0xef}; + pub const OP_RETURN_239: All = All { code: 0xef }; /// Synonym for OP_RETURN. - pub const OP_RETURN_240: All = All {code: 0xf0}; + pub const OP_RETURN_240: All = All { code: 0xf0 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_241: All = All {code: 0xf1}; + pub const OP_RETURN_241: All = All { code: 0xf1 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_242: All = All {code: 0xf2}; + pub const OP_RETURN_242: All = All { code: 0xf2 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_243: All = All {code: 0xf3}; + pub const OP_RETURN_243: All = All { code: 0xf3 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_244: All = All {code: 0xf4}; + pub const OP_RETURN_244: All = All { code: 0xf4 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_245: All = All {code: 0xf5}; + pub const OP_RETURN_245: All = All { code: 0xf5 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_246: All = All {code: 0xf6}; + pub const OP_RETURN_246: All = All { code: 0xf6 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_247: All = All {code: 0xf7}; + pub const OP_RETURN_247: All = All { code: 0xf7 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_248: All = All {code: 0xf8}; + pub const OP_RETURN_248: All = All { code: 0xf8 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_249: All = All {code: 0xf9}; + pub const OP_RETURN_249: All = All { code: 0xf9 }; /// Synonym for OP_RETURN. - pub const OP_RETURN_250: All = All {code: 0xfa}; + pub const OP_RETURN_250: All = All { code: 0xfa }; /// Synonym for OP_RETURN. - pub const OP_RETURN_251: All = All {code: 0xfb}; + pub const OP_RETURN_251: All = All { code: 0xfb }; /// Synonym for OP_RETURN. - pub const OP_RETURN_252: All = All {code: 0xfc}; + pub const OP_RETURN_252: All = All { code: 0xfc }; /// Synonym for OP_RETURN. - pub const OP_RETURN_253: All = All {code: 0xfd}; + pub const OP_RETURN_253: All = All { code: 0xfd }; /// Synonym for OP_RETURN. - pub const OP_RETURN_254: All = All {code: 0xfe}; + pub const OP_RETURN_254: All = All { code: 0xfe }; /// Synonym for OP_RETURN. - pub const OP_INVALIDOPCODE: All = All {code: 0xff}; + pub const OP_INVALIDOPCODE: All = All { code: 0xff }; } impl fmt::Debug for All { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str("OP_")?; match *self { - All {code: x} if x <= 75 => write!(f, "PUSHBYTES_{}", self.code), + All { code: x } if x <= 75 => write!(f, "PUSHBYTES_{}", self.code), all::OP_PUSHDATA1 => write!(f, "PUSHDATA1"), all::OP_PUSHDATA2 => write!(f, "PUSHDATA2"), all::OP_PUSHDATA4 => write!(f, "PUSHDATA4"), all::OP_PUSHNUM_NEG1 => write!(f, "PUSHNUM_NEG1"), all::OP_RESERVED => write!(f, "RESERVED"), - All {code: x} if x >= all::OP_PUSHNUM_1.code && x <= all::OP_PUSHNUM_16.code => write!(f, "PUSHNUM_{}", x - all::OP_PUSHNUM_1.code + 1), + All { code: x } if x >= all::OP_PUSHNUM_1.code && x <= all::OP_PUSHNUM_16.code => + write!(f, "PUSHNUM_{}", x - all::OP_PUSHNUM_1.code + 1), all::OP_NOP => write!(f, "NOP"), all::OP_VER => write!(f, "VER"), all::OP_IF => write!(f, "IF"), @@ -651,10 +655,11 @@ impl fmt::Debug for All { all::OP_CHECKMULTISIGVERIFY => write!(f, "CHECKMULTISIGVERIFY"), all::OP_CLTV => write!(f, "CLTV"), all::OP_CSV => write!(f, "CSV"), - All {code: x} if (all::OP_NOP1.code..=all::OP_NOP10.code).contains(&x) => write!(f, "NOP{}", x - all::OP_NOP1.code + 1), + All { code: x } if (all::OP_NOP1.code..=all::OP_NOP10.code).contains(&x) => + write!(f, "NOP{}", x - all::OP_NOP1.code + 1), all::OP_INVALIDOPCODE => write!(f, "INVALIDOPCODE"), all::OP_CHECKSIGADD => write!(f, "CHECKSIGADD"), - All {code: x} => write!(f, "RETURN_{}", x), + All { code: x } => write!(f, "RETURN_{}", x), } } } @@ -681,23 +686,35 @@ impl All { (OP_VERIF, _) | (OP_VERNOTIF, _) | (OP_INVALIDOPCODE, _) => Class::IllegalOp, // 15 opcodes illegal in Legacy context - (OP_CAT, ctx) | (OP_SUBSTR, ctx) - | (OP_LEFT, ctx) | (OP_RIGHT, ctx) + (OP_CAT, ctx) + | (OP_SUBSTR, ctx) + | (OP_LEFT, ctx) + | (OP_RIGHT, ctx) | (OP_INVERT, ctx) - | (OP_AND, ctx) | (OP_OR, ctx) | (OP_XOR, ctx) - | (OP_2MUL, ctx) | (OP_2DIV, ctx) - | (OP_MUL, ctx) | (OP_DIV, ctx) | (OP_MOD, ctx) - | (OP_LSHIFT, ctx) | (OP_RSHIFT, ctx) if ctx == ClassifyContext::Legacy => Class::IllegalOp, + | (OP_AND, ctx) + | (OP_OR, ctx) + | (OP_XOR, ctx) + | (OP_2MUL, ctx) + | (OP_2DIV, ctx) + | (OP_MUL, ctx) + | (OP_DIV, ctx) + | (OP_MOD, ctx) + | (OP_LSHIFT, ctx) + | (OP_RSHIFT, ctx) + if ctx == ClassifyContext::Legacy => + Class::IllegalOp, // 87 opcodes of SuccessOp class only in TapScript context (op, ClassifyContext::TapScript) - if op.code == 80 || op.code == 98 || - (op.code >= 126 && op.code <= 129) || - (op.code >= 131 && op.code <= 134) || - (op.code >= 137 && op.code <= 138) || - (op.code >= 141 && op.code <= 142) || - (op.code >= 149 && op.code <= 153) || - (op.code >= 187 && op.code <= 254) => Class::SuccessOp, + if op.code == 80 + || op.code == 98 + || (op.code >= 126 && op.code <= 129) + || (op.code >= 131 && op.code <= 134) + || (op.code >= 137 && op.code <= 138) + || (op.code >= 141 && op.code <= 142) + || (op.code >= 149 && op.code <= 153) + || (op.code >= 187 && op.code <= 254) => + Class::SuccessOp, // 11 opcodes of NoOp class (OP_NOP, _) => Class::NoOp, @@ -707,9 +724,9 @@ impl All { (OP_RETURN, _) => Class::ReturnOp, // 4 opcodes operating equally to `OP_RETURN` only in Legacy context - (OP_RESERVED, ctx) - | (OP_RESERVED1, ctx) | (OP_RESERVED2, ctx) - | (OP_VER, ctx) if ctx == ClassifyContext::Legacy => Class::ReturnOp, + (OP_RESERVED, ctx) | (OP_RESERVED1, ctx) | (OP_RESERVED2, ctx) | (OP_VER, ctx) + if ctx == ClassifyContext::Legacy => + Class::ReturnOp, // 71 opcodes operating equally to `OP_RETURN` only in Legacy context (op, ClassifyContext::Legacy) if op.code >= OP_CHECKSIGADD.code => Class::ReturnOp, @@ -722,9 +739,8 @@ impl All { (OP_PUSHNUM_NEG1, _) => Class::PushNum(-1), // 16 opcodes of PushNum class - (op, _) if op.code >= OP_PUSHNUM_1.code && op.code <= OP_PUSHNUM_16.code => { - Class::PushNum(1 + self.code as i32 - OP_PUSHNUM_1.code as i32) - }, + (op, _) if op.code >= OP_PUSHNUM_1.code && op.code <= OP_PUSHNUM_16.code => + Class::PushNum(1 + self.code as i32 - OP_PUSHNUM_1.code as i32), // 76 opcodes of PushBytes class (op, _) if op.code <= OP_PUSHBYTES_75.code => Class::PushBytes(self.code as u32), @@ -744,7 +760,7 @@ impl All { impl From for All { #[inline] fn from(b: u8) -> All { - All {code: b} + All { code: b } } } @@ -786,7 +802,7 @@ pub enum Class { /// Does nothing. NoOp, /// Any opcode not covered above. - Ordinary(Ordinary) + Ordinary(Ordinary), } display_from_debug!(Class); @@ -879,22 +895,31 @@ mod tests { assert_eq!(s1, s2); assert_eq!(s1, stringify!($op)); assert!($unique.insert(s1)); - } + }; } #[test] fn classify_test() { let op174 = all::OP_CHECKMULTISIG; - assert_eq!(op174.classify(ClassifyContext::Legacy), Class::Ordinary(Ordinary::OP_CHECKMULTISIG)); + assert_eq!( + op174.classify(ClassifyContext::Legacy), + Class::Ordinary(Ordinary::OP_CHECKMULTISIG) + ); assert_eq!(op174.classify(ClassifyContext::TapScript), Class::ReturnOp); let op175 = all::OP_CHECKMULTISIGVERIFY; - assert_eq!(op175.classify(ClassifyContext::Legacy), Class::Ordinary(Ordinary::OP_CHECKMULTISIGVERIFY)); + assert_eq!( + op175.classify(ClassifyContext::Legacy), + Class::Ordinary(Ordinary::OP_CHECKMULTISIGVERIFY) + ); assert_eq!(op175.classify(ClassifyContext::TapScript), Class::ReturnOp); let op186 = all::OP_CHECKSIGADD; assert_eq!(op186.classify(ClassifyContext::Legacy), Class::ReturnOp); - assert_eq!(op186.classify(ClassifyContext::TapScript), Class::Ordinary(Ordinary::OP_CHECKSIGADD)); + assert_eq!( + op186.classify(ClassifyContext::TapScript), + Class::Ordinary(Ordinary::OP_CHECKSIGADD) + ); let op187 = all::OP_RETURN_187; assert_eq!(op187.classify(ClassifyContext::Legacy), Class::ReturnOp); @@ -1063,10 +1088,10 @@ mod tests { roundtrip!(unique, OP_NUMEQUAL); roundtrip!(unique, OP_NUMEQUALVERIFY); roundtrip!(unique, OP_NUMNOTEQUAL); - roundtrip!(unique, OP_LESSTHAN ); - roundtrip!(unique, OP_GREATERTHAN ); - roundtrip!(unique, OP_LESSTHANOREQUAL ); - roundtrip!(unique, OP_GREATERTHANOREQUAL ); + roundtrip!(unique, OP_LESSTHAN); + roundtrip!(unique, OP_GREATERTHAN); + roundtrip!(unique, OP_LESSTHANOREQUAL); + roundtrip!(unique, OP_GREATERTHANOREQUAL); roundtrip!(unique, OP_MIN); roundtrip!(unique, OP_MAX); roundtrip!(unique, OP_WITHIN); diff --git a/src/blockdata/script.rs b/src/blockdata/script.rs index 17b209a9b5..f49b605373 100644 --- a/src/blockdata/script.rs +++ b/src/blockdata/script.rs @@ -23,28 +23,29 @@ //! This module provides the structures and functions needed to support scripts. //! -use crate::prelude::*; - -use crate::io; -use core::{fmt, default::Default}; +#[cfg(feature = "bitcoinconsensus")] +use core::convert::From; +use core::default::Default; +use core::fmt; use core::ops::Index; -#[cfg(feature = "serde")] use serde; +#[cfg(feature = "bitcoinconsensus")] +use bitcoinconsensus; +use secp256k1::{Secp256k1, Verification, XOnlyPublicKey}; +#[cfg(feature = "serde")] +use serde; -use crate::hash_types::{PubkeyHash, WPubkeyHash, ScriptHash, WScriptHash}; use crate::blockdata::opcodes; use crate::consensus::{encode, Decodable, Encodable}; -use crate::hashes::{Hash, hex}; +use crate::hash_types::{PubkeyHash, ScriptHash, WPubkeyHash, WScriptHash}; +use crate::hashes::{hex, Hash}; use crate::policy::DUST_RELAY_TX_FEE; -#[cfg(feature="bitcoinconsensus")] use bitcoinconsensus; -#[cfg(feature="bitcoinconsensus")] use core::convert::From; -use crate::OutPoint; - -use crate::util::key::PublicKey; +use crate::prelude::*; +use crate::schnorr::{TapTweak, TweakedPublicKey, UntweakedPublicKey}; use crate::util::address::WitnessVersion; +use crate::util::key::PublicKey; use crate::util::taproot::{LeafVersion, TapBranchHash, TapLeafHash}; -use secp256k1::{Secp256k1, Verification, XOnlyPublicKey}; -use crate::schnorr::{TapTweak, TweakedPublicKey, UntweakedPublicKey}; +use crate::{io, OutPoint}; /// A Bitcoin script. #[derive(Clone, Default, PartialOrd, Ord, PartialEq, Eq, Hash)] @@ -103,7 +104,7 @@ impl fmt::UpperHex for Script { impl hex::FromHex for Script { fn from_byte_iter(iter: I) -> Result where - I: Iterator> + ExactSizeIterator + DoubleEndedIterator, + I: Iterator> + ExactSizeIterator + DoubleEndedIterator, { Vec::from_byte_iter(iter).map(|v| Script(Box::<[u8]>::from(v))) } @@ -150,7 +151,7 @@ pub enum Error { /// Can not find the spent output UnknownSpentOutput(OutPoint), /// Can not serialize the spending transaction - SerializationError + SerializationError, } /// A [`bitcoinconsensus::Error`] alias. Exists to enable the compiler to ensure `bitcoinconsensus` @@ -180,7 +181,8 @@ impl fmt::Display for Error { Error::NumericOverflow => "numeric overflow (number on stack larger than 4 bytes)", Error::BitcoinConsensus(ref _n) => "bitcoinconsensus verification failed", Error::UnknownSpentOutput(ref _point) => "unknown spent output Transaction::verify()", - Error::SerializationError => "can not serialize the spending transaction in Transaction::verify()", + Error::SerializationError => + "can not serialize the spending transaction in Transaction::verify()", }; f.write_str(str) } @@ -228,7 +230,9 @@ impl From for Error { } /// Helper to encode an integer in script format fn build_scriptint(n: i64) -> Vec { - if n == 0 { return vec![] } + if n == 0 { + return vec![]; + } let neg = n < 0; @@ -268,11 +272,14 @@ fn build_scriptint(n: i64) -> Vec { /// This is basically a ranged type implementation. pub fn read_scriptint(v: &[u8]) -> Result { let len = v.len(); - if len == 0 { return Ok(0); } - if len > 4 { return Err(Error::NumericOverflow); } + if len == 0 { + return Ok(0); + } + if len > 4 { + return Err(Error::NumericOverflow); + } - let (mut ret, sh) = v.iter() - .fold((0, 0), |(acc, sh), n| (acc + ((*n as i64) << sh), sh + 8)); + let (mut ret, sh) = v.iter().fold((0, 0), |(acc, sh), n| (acc + ((*n as i64) << sh), sh + 8)); if v[len - 1] & 0x80 != 0 { ret &= (1 << (sh - 1)) - 1; ret = -ret; @@ -330,7 +337,9 @@ fn read_uint_iter(data: &mut ::core::slice::Iter<'_, u8>, size: usize) -> Result impl Script { /// Creates a new empty script. - pub fn new() -> Script { Script(vec![].into_boxed_slice()) } + pub fn new() -> Script { + Script(vec![].into_boxed_slice()) + } /// Generates P2PK-type of scriptPubkey. pub fn new_p2pk(pubkey: &PublicKey) -> Script { @@ -384,7 +393,11 @@ impl Script { /// Generates P2TR for script spending path using an internal public key and some optional /// script tree merkle root. - pub fn new_v1_p2tr(secp: &Secp256k1, internal_key: UntweakedPublicKey, merkle_root: Option) -> Script { + pub fn new_v1_p2tr( + secp: &Secp256k1, + internal_key: UntweakedPublicKey, + merkle_root: Option, + ) -> Script { let (output_key, _) = internal_key.tap_tweak(secp, merkle_root); Script::new_witness_program(WitnessVersion::V1, &output_key.serialize()) } @@ -396,10 +409,7 @@ impl Script { /// Generates P2WSH-type of scriptPubkey with a given hash of the redeem script. pub fn new_witness_program(version: WitnessVersion, program: &[u8]) -> Script { - Builder::new() - .push_opcode(version.into()) - .push_slice(program) - .into_script() + Builder::new().push_opcode(version.into()).push_slice(program).into_script() } /// Generates OP_RETURN-type of scriptPubkey for the given data. @@ -421,19 +431,29 @@ impl Script { } /// Returns the length in bytes of the script. - pub fn len(&self) -> usize { self.0.len() } + pub fn len(&self) -> usize { + self.0.len() + } /// Returns whether the script is the empty script. - pub fn is_empty(&self) -> bool { self.0.is_empty() } + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } /// Returns the script data as a byte slice. - pub fn as_bytes(&self) -> &[u8] { &*self.0 } + pub fn as_bytes(&self) -> &[u8] { + &*self.0 + } /// Returns a copy of the script data. - pub fn to_bytes(&self) -> Vec { self.0.clone().into_vec() } + pub fn to_bytes(&self) -> Vec { + self.0.clone().into_vec() + } /// Converts the script into a byte vector. - pub fn into_bytes(self) -> Vec { self.0.into_vec() } + pub fn into_bytes(self) -> Vec { + self.0.into_vec() + } /// Computes the P2SH output corresponding to this redeem script. pub fn to_p2sh(&self) -> Script { @@ -446,7 +466,7 @@ impl Script { /// [BIP143]: pub fn p2wpkh_script_code(&self) -> Option