diff --git a/Cargo.lock b/Cargo.lock index 2a38f01b87..c71c9e8559 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -446,6 +446,16 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "base58ck" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f" +dependencies = [ + "bitcoin-internals 0.3.0", + "bitcoin_hashes 0.14.0", +] + [[package]] name = "base64" version = "0.13.1" @@ -466,15 +476,15 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bech32" -version = "0.9.1" +version = "0.10.0-beta" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" +checksum = "98f7eed2b2781a6f0b5c903471d48e15f56fb4e1165df8a9a2337fd1a59d45ea" [[package]] name = "bech32" -version = "0.10.0-beta" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98f7eed2b2781a6f0b5c903471d48e15f56fb4e1165df8a9a2337fd1a59d45ea" +checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" [[package]] name = "bip322" @@ -503,30 +513,34 @@ dependencies = [ [[package]] name = "bitcoin" -version = "0.30.2" +version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1945a5048598e4189e239d3f809b19bdad4845c4b2ba400d304d2dcf26d2c462" +checksum = "6c85783c2fe40083ea54a33aa2f0ba58831d90fcd190f5bdc47e74e84d2a96ae" dependencies = [ - "bech32 0.9.1", - "bitcoin-private", - "bitcoin_hashes 0.12.0", + "bech32 0.10.0-beta", + "bitcoin-internals 0.2.0", + "bitcoin_hashes 0.13.0", + "hex-conservative 0.1.2", "hex_lit", - "secp256k1 0.27.0", - "serde", + "secp256k1 0.28.2", ] [[package]] name = "bitcoin" -version = "0.31.2" +version = "0.32.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c85783c2fe40083ea54a33aa2f0ba58831d90fcd190f5bdc47e74e84d2a96ae" +checksum = "0032b0e8ead7074cda7fc4f034409607e3f03a6f71d66ade8a307f79b4d99e73" dependencies = [ - "bech32 0.10.0-beta", - "bitcoin-internals", - "bitcoin_hashes 0.13.0", - "hex-conservative 0.1.2", + "base58ck", + "bech32 0.11.0", + "bitcoin-internals 0.3.0", + "bitcoin-io", + "bitcoin-units", + "bitcoin_hashes 0.14.0", + "hex-conservative 0.2.1", "hex_lit", - "secp256k1 0.28.2", + "secp256k1 0.29.1", + "serde", ] [[package]] @@ -536,24 +550,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9425c3bf7089c983facbae04de54513cce73b41c7f9ff8c845b54e7bc64ebbfb" [[package]] -name = "bitcoin-io" -version = "0.1.2" +name = "bitcoin-internals" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "340e09e8399c7bd8912f495af6aa58bea0c9214773417ffaa8f6460f93aaee56" +checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2" +dependencies = [ + "serde", +] [[package]] -name = "bitcoin-private" -version = "0.1.0" +name = "bitcoin-io" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73290177011694f38ec25e165d0387ab7ea749a4b81cd4c80dae5988229f7a57" +checksum = "340e09e8399c7bd8912f495af6aa58bea0c9214773417ffaa8f6460f93aaee56" [[package]] -name = "bitcoin_hashes" -version = "0.12.0" +name = "bitcoin-units" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d7066118b13d4b20b23645932dfb3a81ce7e29f95726c2036fa33cd7b092501" +checksum = "5285c8bcaa25876d07f37e3d30c303f2609179716e11d688f51e8f1fe70063e2" dependencies = [ - "bitcoin-private", + "bitcoin-internals 0.3.0", "serde", ] @@ -563,7 +580,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1930a4dabfebb8d7d9992db18ebe3ae2876f0a305fab206fd168df931ede293b" dependencies = [ - "bitcoin-internals", + "bitcoin-internals 0.2.0", "hex-conservative 0.1.2", ] @@ -575,15 +592,15 @@ checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16" dependencies = [ "bitcoin-io", "hex-conservative 0.2.1", + "serde", ] [[package]] name = "bitcoincore-rpc" -version = "0.17.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6c0ee9354e3dac217db4cb1dd31941073a87fe53c86bcf3eb2b8bc97f00a08" +checksum = "aedd23ae0fd321affb4bbbc36126c6f49a32818dc6b979395d24da8c9d4e80ee" dependencies = [ - "bitcoin-private", "bitcoincore-rpc-json", "jsonrpc", "log", @@ -593,12 +610,11 @@ dependencies = [ [[package]] name = "bitcoincore-rpc-json" -version = "0.17.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d30ce6f40fb0a2e8d98522796219282504b7a4b14e2b4c26139a7bea6aec6586" +checksum = "d8909583c5fab98508e80ef73e5592a651c954993dc6b7739963257d19f0e71a" dependencies = [ - "bitcoin 0.30.2", - "bitcoin-private", + "bitcoin 0.32.3", "serde", "serde_json", ] @@ -1944,11 +1960,12 @@ dependencies = [ [[package]] name = "jsonrpc" -version = "0.14.1" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8128f36b47411cd3f044be8c1f5cc0c9e24d1d1bfdc45f0a57897b32513053f2" +checksum = "3662a38d341d77efecb73caf01420cfa5aa63c0253fd7bc05289ef9f6616e1bf" dependencies = [ "base64 0.13.1", + "minreq", "serde", "serde_json", ] @@ -2115,23 +2132,23 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniscript" -version = "10.2.0" +version = "11.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d371924f9eb7aa860ab395baaaa0bcdfa81a32f330b538c4e2c04617b2722fe3" +checksum = "3127e10529a57a8f7fa9b1332c4c2f72baadaca6777798f910dff3c922620b14" dependencies = [ - "bitcoin 0.30.2", - "bitcoin-private", + "bech32 0.10.0-beta", + "bitcoin 0.31.2", + "bitcoin-internals 0.2.0", ] [[package]] name = "miniscript" -version = "11.2.0" +version = "12.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3127e10529a57a8f7fa9b1332c4c2f72baadaca6777798f910dff3c922620b14" +checksum = "add2d4aee30e4291ce5cffa3a322e441ff4d4bc57b38c8d9bf0e94faa50ab626" dependencies = [ - "bech32 0.10.0-beta", - "bitcoin 0.31.2", - "bitcoin-internals", + "bech32 0.11.0", + "bitcoin 0.32.3", ] [[package]] @@ -2143,6 +2160,17 @@ dependencies = [ "adler2", ] +[[package]] +name = "minreq" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "763d142cdff44aaadd9268bebddb156ef6c65a0e13486bb81673cf2d8739f9b0" +dependencies = [ + "log", + "serde", + "serde_json", +] + [[package]] name = "mio" version = "1.0.2" @@ -2160,7 +2188,7 @@ name = "mockcore" version = "0.0.1" dependencies = [ "base64 0.22.1", - "bitcoin 0.30.2", + "bitcoin 0.32.3", "hex", "jsonrpc-core", "jsonrpc-derive", @@ -2410,7 +2438,7 @@ dependencies = [ "base64 0.22.1", "bip322", "bip39", - "bitcoin 0.30.2", + "bitcoin 0.32.3", "bitcoincore-rpc", "boilerplate", "brotli", @@ -2434,7 +2462,7 @@ dependencies = [ "log", "mime", "mime_guess", - "miniscript 10.2.0", + "miniscript 12.2.0", "mockcore", "mp4", "nix", @@ -2467,11 +2495,10 @@ dependencies = [ [[package]] name = "ord-bitcoincore-rpc" -version = "0.17.2" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16b622f69d68d7201d5186615978aca36ceb7e7c57d7771491d3e261c64ff4d8" +checksum = "a00065be964ca4b401bc998e473423b1c5e8dbffb9c30f206e83e651e605ef76" dependencies = [ - "bitcoin-private", "jsonrpc", "log", "ord-bitcoincore-rpc-json", @@ -2481,21 +2508,20 @@ dependencies = [ [[package]] name = "ord-bitcoincore-rpc-json" -version = "0.17.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb35088f918c775bc27fa79e372d034892b216fb7900aeedd6e06654879ad33" +checksum = "2b521de9d7b3171464565f244207af17f6d1b54085d46dd43162cf56e2ef5a9e" dependencies = [ - "bitcoin 0.30.2", - "bitcoin-private", + "bitcoin 0.32.3", "serde", "serde_json", ] [[package]] name = "ordinals" -version = "0.0.10" +version = "0.0.11" dependencies = [ - "bitcoin 0.30.2", + "bitcoin 0.32.3", "derive_more", "pretty_assertions", "serde", @@ -3216,40 +3242,40 @@ dependencies = [ [[package]] name = "secp256k1" -version = "0.27.0" +version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25996b82292a7a57ed3508f052cfff8640d38d32018784acd714758b43da9c8f" +checksum = "d24b59d129cdadea20aea4fb2352fa053712e5d713eee47d700cd4b2bc002f10" dependencies = [ - "bitcoin_hashes 0.12.0", - "rand", - "secp256k1-sys 0.8.1", - "serde", + "bitcoin_hashes 0.13.0", + "secp256k1-sys 0.9.2", ] [[package]] name = "secp256k1" -version = "0.28.2" +version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24b59d129cdadea20aea4fb2352fa053712e5d713eee47d700cd4b2bc002f10" +checksum = "9465315bc9d4566e1724f0fffcbcc446268cb522e60f9a27bcded6b19c108113" dependencies = [ - "bitcoin_hashes 0.13.0", - "secp256k1-sys 0.9.2", + "bitcoin_hashes 0.14.0", + "rand", + "secp256k1-sys 0.10.1", + "serde", ] [[package]] name = "secp256k1-sys" -version = "0.8.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70a129b9e9efbfb223753b9163c4ab3b13cff7fd9c7f010fbac25ab4099fa07e" +checksum = "e5d1746aae42c19d583c3c1a8c646bfad910498e2051c551a7f2e3c0c9fbb7eb" dependencies = [ "cc", ] [[package]] name = "secp256k1-sys" -version = "0.9.2" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d1746aae42c19d583c3c1a8c646bfad910498e2051c551a7f2e3c0c9fbb7eb" +checksum = "d4387882333d3aa8cb20530a17c69a3752e97837832f34f6dccc760e715001d9" dependencies = [ "cc", ] diff --git a/Cargo.toml b/Cargo.toml index e865fcf49c..40f425f062 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,8 @@ axum-server = "0.5.0" base64 = "0.22.0" bip322 = "0.0.7" bip39 = "2.0.0" -bitcoin = { version = "0.30.1", features = ["rand"] } +bitcoin = { version = "0.32.3", features = ["rand"] } +bitcoincore-rpc = "0.19.0" boilerplate = { version = "1.0.0", features = ["axum"] } brotli = "7.0.0" chrono = { version = "0.4.19", features = ["serde"] } @@ -46,10 +47,9 @@ lazy_static = "1.4.0" log = "0.4.14" mime = "0.3.16" mime_guess = "2.0.4" -miniscript = "10.0.0" +miniscript = "12.0.0" mp4 = "0.14.0" -bitcoincore-rpc = "0.17.0" -ordinals = { version = "0.0.10", path = "crates/ordinals" } +ordinals = { version = "0.0.11", path = "crates/ordinals" } redb = "2.1.1" ref-cast = "1.0.23" regex = "1.6.0" diff --git a/crates/mockcore/Cargo.toml b/crates/mockcore/Cargo.toml index da1bb55709..50cd155cdd 100644 --- a/crates/mockcore/Cargo.toml +++ b/crates/mockcore/Cargo.toml @@ -8,13 +8,13 @@ homepage = "https://github.com/ordinals/ord" repository = "https://github.com/ordinals/ord" [dependencies] -bitcoin = { version = "0.30.0", features = ["serde", "rand"] } +bitcoin = { version = "0.32.3", features = ["serde", "rand"] } base64 = "0.22.0" hex = "0.4.3" jsonrpc-core = "18.0.0" jsonrpc-derive = "18.0.0" jsonrpc-http-server = "18.0.0" -ord-bitcoincore-rpc = "0.17.2" +ord-bitcoincore-rpc = "0.19.0" reqwest = { version = "0.12.8", features = ["blocking"] } serde = { version = "1.0.137", features = ["derive"] } serde_json = { version = "1.0.81" } diff --git a/crates/mockcore/src/lib.rs b/crates/mockcore/src/lib.rs index e4a12c1545..4414513daa 100644 --- a/crates/mockcore/src/lib.rs +++ b/crates/mockcore/src/lib.rs @@ -6,8 +6,7 @@ use { address::{Address, NetworkUnchecked}, amount::SignedAmount, block::Header, - blockdata::constants::COIN_VALUE, - blockdata::{block::Version, script}, + blockdata::{script, transaction::Version}, consensus::encode::{deserialize, serialize}, hash_types::{BlockHash, TxMerkleNode}, hashes::Hash, @@ -17,15 +16,15 @@ use { Wtxid, }, bitcoincore_rpc::json::{ - Bip125Replaceable, CreateRawTransactionInput, Descriptor, EstimateMode, FeeRatePercentiles, + Bip125Replaceable, CreateRawTransactionInput, EstimateMode, FeeRatePercentiles, FinalizePsbtResult, GetBalancesResult, GetBalancesResultEntry, GetBlockHeaderResult, GetBlockStatsResult, GetBlockchainInfoResult, GetDescriptorInfoResult, GetNetworkInfoResult, GetRawTransactionResult, GetRawTransactionResultVout, GetRawTransactionResultVoutScriptPubKey, GetTransactionResult, GetTransactionResultDetail, GetTransactionResultDetailCategory, GetTxOutResult, GetWalletInfoResult, ImportDescriptors, ImportMultiResult, - ListDescriptorsResult, ListTransactionResult, ListUnspentResultEntry, ListWalletDirItem, - ListWalletDirResult, LoadWalletResult, SignRawTransactionInput, SignRawTransactionResult, - Timestamp, WalletProcessPsbtResult, WalletTxInfo, + ListTransactionResult, ListUnspentResultEntry, ListWalletDirItem, ListWalletDirResult, + LoadWalletResult, SignRawTransactionInput, SignRawTransactionResult, Timestamp, + WalletProcessPsbtResult, WalletTxInfo, }, jsonrpc_core::{IoHandler, Value}, jsonrpc_http_server::{CloseHandle, ServerBuilder}, @@ -43,10 +42,28 @@ use { tempfile::TempDir, }; +const COIN_VALUE: u64 = 100_000_000; + mod api; mod server; mod state; +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +pub struct Descriptor { + pub desc: String, + pub timestamp: Timestamp, + pub active: bool, + pub internal: Option, + pub range: Option<(u64, u64)>, + pub next: Option, +} + +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +pub struct ListDescriptorsResult { + pub wallet_name: String, + pub descriptors: Vec, +} + pub fn builder() -> Builder { Builder { fail_lock_unspent: false, diff --git a/crates/mockcore/src/server.rs b/crates/mockcore/src/server.rs index bd62aab5b4..10b7b299d6 100644 --- a/crates/mockcore/src/server.rs +++ b/crates/mockcore/src/server.rs @@ -2,7 +2,7 @@ use { super::*, base64::Engine, bitcoin::{consensus::Decodable, psbt::Psbt, Witness}, - std::io::Cursor, + bitcoincore_rpc::json::StringOrStringArray, }; pub(crate) struct Server { @@ -50,13 +50,7 @@ impl Api for Server { fn get_blockchain_info(&self) -> Result { Ok(GetBlockchainInfoResult { - chain: String::from(match self.network { - Network::Bitcoin => "main", - Network::Testnet => "test", - Network::Signet => "signet", - Network::Regtest => "regtest", - _ => panic!(), - }), + chain: self.network, blocks: 0, headers: 0, best_block_hash: self.state().hashes[0], @@ -71,7 +65,7 @@ impl Api for Server { automatic_pruning: None, prune_target_size: None, softforks: HashMap::new(), - warnings: String::new(), + warnings: StringOrStringArray::String(String::new()), }) } @@ -91,7 +85,7 @@ impl Api for Server { relay_fee: Amount::from_sat(0), incremental_fee: Amount::from_sat(0), local_addresses: Vec::new(), - warnings: String::new(), + warnings: StringOrStringArray::String(String::new()), }) } @@ -136,7 +130,7 @@ impl Api for Server { nonce: 0, previous_block_hash: None, time: 0, - version: Version::ONE, + version: bitcoin::blockdata::block::Version::ONE, version_hex: Some(vec![0, 0, 0, 0]), }) .unwrap(), @@ -164,7 +158,7 @@ impl Api for Server { height, hash: block_hash, confirmations: 0, - version: Version::ONE, + version: bitcoin::block::Version::ONE, version_hex: None, merkle_root: TxMerkleNode::all_zeros(), time: 0, @@ -263,7 +257,7 @@ impl Api for Server { for (height, hash) in state.hashes.iter().enumerate() { for tx in &state.blocks[hash].txdata { - if tx.txid() == txid { + if tx.compute_txid() == txid { confirmations = Some(state.hashes.len() - height); } } @@ -320,7 +314,7 @@ impl Api for Server { assert_eq!(replaceable, None, "replaceable param not supported"); let tx = Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: utxos .iter() @@ -334,7 +328,7 @@ impl Api for Server { output: outs .values() .map(|amount| TxOut { - value: (*amount * COIN_VALUE as f64) as u64, + value: Amount::from_sat((*amount * COIN_VALUE as f64) as u64), script_pubkey: ScriptBuf::new(), }) .collect(), @@ -366,9 +360,9 @@ impl Api for Server { ) -> Result { let options = options.unwrap(); - let mut cursor = Cursor::new(hex::decode(tx).unwrap()); + let mut cursor = bitcoin::io::Cursor::new(hex::decode(tx).unwrap()); - let version = i32::consensus_decode_from_finite_reader(&mut cursor).unwrap(); + let version = Version(i32::consensus_decode_from_finite_reader(&mut cursor).unwrap()); let input = Vec::::consensus_decode_from_finite_reader(&mut cursor).unwrap(); let output = Decodable::consensus_decode_from_finite_reader(&mut cursor).unwrap(); let lock_time = Decodable::consensus_decode_from_finite_reader(&mut cursor).unwrap(); @@ -390,8 +384,8 @@ impl Api for Server { let output_value = transaction .output .iter() - .map(|txout| txout.value) - .sum::(); + .map(|txout| txout.value.to_sat()) + .sum(); let mut utxos = state .utxos @@ -456,7 +450,7 @@ impl Api for Server { if change > 0 { transaction.output.push(TxOut { - value: change, + value: Amount::from_sat(change), script_pubkey: state.new_address(true).into(), }); } @@ -466,7 +460,7 @@ impl Api for Server { let funded_vsize = transaction.vsize() as f64 + 68.0 / 4.0; let funded_kwu = funded_vsize / 1000.0; let fee = (funded_kwu * fee_rate.to_sat() as f64) as u64; - transaction.output.last_mut().unwrap().value -= fee; + transaction.output.last_mut().unwrap().value -= Amount::from_sat(fee); fee } else { 0 @@ -532,7 +526,7 @@ impl Api for Server { state.mempool.push(tx.clone()); - Ok(tx.txid().to_string()) + Ok(tx.compute_txid().to_string()) } fn send_to_address( @@ -573,7 +567,7 @@ impl Api for Server { }; let mut transaction = Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![TxIn { previous_output: *outpoint, @@ -583,12 +577,12 @@ impl Api for Server { }], output: vec![ TxOut { - value: value.to_sat(), - script_pubkey: address.payload.script_pubkey(), + value, + script_pubkey: address.assume_checked_ref().script_pubkey(), }, TxOut { - value: (*utxo_amount - value).to_sat(), - script_pubkey: address.payload.script_pubkey(), + value: *utxo_amount - value, + script_pubkey: address.assume_checked_ref().script_pubkey(), }, ], }; @@ -597,9 +591,9 @@ impl Api for Server { #[allow(clippy::cast_sign_loss)] let fee = (fee_rate.unwrap_or(1.0) * transaction.vsize() as f64).round() as u64; - transaction.output[1].value -= fee; + transaction.output[1].value -= Amount::from_sat(fee); - let txid = transaction.txid(); + let txid = transaction.compute_txid(); state.mempool.push(transaction); @@ -623,7 +617,7 @@ impl Api for Server { 'outer: for (height, hash) in state.hashes.iter().enumerate() { for tx in &state.blocks[hash].txdata { - if tx.txid() == txid { + if tx.compute_txid() == txid { confirmations = Some(state.hashes.len() - height); break 'outer; } @@ -690,7 +684,7 @@ impl Api for Server { .enumerate() .map(|(n, output)| GetRawTransactionResultVout { n: n.try_into().unwrap(), - value: Amount::from_sat(output.value), + value: output.value, script_pub_key: GetRawTransactionResultVoutScriptPubKey { asm: output.script_pubkey.to_asm_string(), hex: output.script_pubkey.clone().into(), @@ -798,7 +792,7 @@ impl Api for Server { ) -> Result { Ok(GetDescriptorInfoResult { descriptor: desc, - checksum: "".into(), + checksum: None, is_range: false, is_solvable: false, has_private_keys: true, @@ -843,7 +837,7 @@ impl Api for Server { .iter() .take(count.unwrap_or(u16::MAX).into()) .map(|(txid, tx)| (*txid, tx)) - .chain(state.mempool.iter().map(|tx| (tx.txid(), tx))) + .chain(state.mempool.iter().map(|tx| (tx.compute_txid(), tx))) .map(|(txid, tx)| ListTransactionResult { info: WalletTxInfo { confirmations: state.get_confirmations(tx), diff --git a/crates/mockcore/src/state.rs b/crates/mockcore/src/state.rs index 1503069c2d..e2678f61a0 100644 --- a/crates/mockcore/src/state.rs +++ b/crates/mockcore/src/state.rs @@ -1,7 +1,7 @@ use { super::*, bitcoin::{ - key::{KeyPair, Secp256k1, XOnlyPublicKey}, + key::{Keypair, Secp256k1, XOnlyPublicKey}, secp256k1::rand, WPubkeyHash, }, @@ -59,7 +59,7 @@ impl State { pub(crate) fn new_address(&mut self, change: bool) -> Address { let secp256k1 = Secp256k1::new(); - let key_pair = KeyPair::new(&secp256k1, &mut rand::thread_rng()); + let key_pair = Keypair::new(&secp256k1, &mut rand::thread_rng()); let (public_key, _parity) = XOnlyPublicKey::from_keypair(&key_pair); let address = Address::p2tr(&secp256k1, public_key, None, self.network); if change { @@ -105,7 +105,7 @@ impl State { #[track_caller] pub(crate) fn mine_block(&mut self, subsidy: u64) -> Block { let coinbase = Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![TxIn { previous_output: OutPoint::null(), @@ -116,7 +116,7 @@ impl State { witness: Witness::new(), }], output: vec![TxOut { - value: subsidy + value: Amount::from_sat(subsidy) + self .mempool .iter() @@ -129,22 +129,24 @@ impl State { [txin.previous_output.vout as usize] .value }) - .sum::() - - tx.output.iter().map(|txout| txout.value).sum::(); - self.transactions.insert(tx.txid(), tx.clone()); + .sum::() + - tx.output.iter().map(|txout| txout.value).sum::(); + self.transactions.insert(tx.compute_txid(), tx.clone()); fee }) - .sum::(), + .sum::(), script_pubkey: self.new_address(false).into(), }], }; - self.transactions.insert(coinbase.txid(), coinbase.clone()); + self + .transactions + .insert(coinbase.compute_txid(), coinbase.clone()); let block = Block { header: Header { - version: Version::ONE, + version: bitcoin::block::Version::ONE, prev_blockhash: *self.hashes.last().unwrap(), merkle_root: TxMerkleNode::all_zeros(), time: self.blocks.len().try_into().unwrap(), @@ -159,7 +161,7 @@ impl State { for tx in block.txdata.iter() { self .txid_to_block_height - .insert(tx.txid(), self.hashes.len().try_into().unwrap()); + .insert(tx.compute_txid(), self.hashes.len().try_into().unwrap()); for input in tx.input.iter() { if !input.previous_output.is_null() { @@ -171,10 +173,10 @@ impl State { if !txout.script_pubkey.is_op_return() { self.utxos.insert( OutPoint { - txid: tx.txid(), + txid: tx.compute_txid(), vout: vout.try_into().unwrap(), }, - Amount::from_sat(txout.value), + txout.value, ); } } @@ -199,9 +201,9 @@ impl State { let mut input = Vec::new(); for (height, tx, vout, witness) in template.inputs.iter() { let tx = &self.blocks.get(&self.hashes[*height]).unwrap().txdata[*tx]; - total_value += tx.output[*vout].value; + total_value += tx.output[*vout].value.to_sat(); input.push(TxIn { - previous_output: OutPoint::new(tx.txid(), *vout as u32), + previous_output: OutPoint::new(tx.compute_txid(), *vout as u32), script_sig: ScriptBuf::new(), sequence: Sequence::MAX, witness: witness.clone(), @@ -222,25 +224,27 @@ impl State { } let mut tx = Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input, output: (0..template.outputs) .map(|i| TxOut { - value: template - .output_values - .get(i) - .cloned() - .unwrap_or(value_per_output), + value: Amount::from_sat( + template + .output_values + .get(i) + .cloned() + .unwrap_or(value_per_output), + ), script_pubkey: if let Some(recipient) = &template.recipient { recipient.script_pubkey() } else if template.p2tr { let secp = Secp256k1::new(); - let keypair = KeyPair::new(&secp, &mut rand::thread_rng()); + let keypair = Keypair::new(&secp, &mut rand::thread_rng()); let internal_key = XOnlyPublicKey::from_keypair(&keypair); - ScriptBuf::new_v1_p2tr(&secp, internal_key.0, None) + ScriptBuf::new_p2tr(&secp, internal_key.0, None) } else { - ScriptBuf::new_v0_p2wpkh(&WPubkeyHash::all_zeros()) + ScriptBuf::new_p2wpkh(&WPubkeyHash::all_zeros()) }, }) .collect(), @@ -250,13 +254,13 @@ impl State { tx.output.insert( template.op_return_index.unwrap_or(tx.output.len()), TxOut { - value: template.op_return_value.unwrap_or_default(), + value: Amount::from_sat(template.op_return_value.unwrap_or_default()), script_pubkey, }, ); } - let txid = tx.txid(); + let txid = tx.compute_txid(); self.mempool.push(tx); diff --git a/crates/ordinals/Cargo.toml b/crates/ordinals/Cargo.toml index 14df27e4d7..9e124ceb96 100644 --- a/crates/ordinals/Cargo.toml +++ b/crates/ordinals/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ordinals" -version = "0.0.10" +version = "0.0.11" edition = "2021" description = "Library for interoperating with ordinals and inscriptions" homepage = "https://github.com/ordinals/ord" @@ -9,7 +9,7 @@ license = "CC0-1.0" rust-version = "1.74.0" [dependencies] -bitcoin = { version = "0.30.1", features = ["rand"] } +bitcoin = { version = "0.32.3", features = ["rand"] } derive_more = { version = "1.0.0", features = ["display", "from_str"] } serde = { version = "1.0.137", features = ["derive"] } serde_with = "3.7.0" diff --git a/crates/ordinals/src/lib.rs b/crates/ordinals/src/lib.rs index 091be18a1c..98b16f0355 100644 --- a/crates/ordinals/src/lib.rs +++ b/crates/ordinals/src/lib.rs @@ -4,9 +4,7 @@ use { bitcoin::{ consensus::{Decodable, Encodable}, - constants::{ - COIN_VALUE, DIFFCHANGE_INTERVAL, MAX_SCRIPT_ELEMENT_SIZE, SUBSIDY_HALVING_INTERVAL, - }, + constants::{DIFFCHANGE_INTERVAL, MAX_SCRIPT_ELEMENT_SIZE, SUBSIDY_HALVING_INTERVAL}, opcodes, script::{self, Instruction}, Network, OutPoint, ScriptBuf, Transaction, @@ -18,7 +16,6 @@ use { cmp, collections::{HashMap, VecDeque}, fmt::{self, Formatter}, - io, num::ParseIntError, ops::{Add, AddAssign, Sub}, }, @@ -32,6 +29,7 @@ pub use { spaced_rune::SpacedRune, terms::Terms, }; +pub const COIN_VALUE: u64 = 100_000_000; pub const CYCLE_EPOCHS: u32 = 6; fn default() -> T { diff --git a/crates/ordinals/src/runestone.rs b/crates/ordinals/src/runestone.rs index 7007d8d8cc..82cb43694b 100644 --- a/crates/ordinals/src/runestone.rs +++ b/crates/ordinals/src/runestone.rs @@ -19,7 +19,7 @@ enum Payload { } impl Runestone { - pub const MAGIC_NUMBER: opcodes::All = opcodes::all::OP_PUSHNUM_13; + pub const MAGIC_NUMBER: opcodes::Opcode = opcodes::all::OP_PUSHNUM_13; pub const COMMIT_CONFIRMATIONS: u16 = 6; pub fn decipher(transaction: &Transaction) -> Option { @@ -252,7 +252,8 @@ mod tests { use { super::*, bitcoin::{ - blockdata::locktime::absolute::LockTime, script::PushBytes, Sequence, TxIn, TxOut, Witness, + blockdata::locktime::absolute::LockTime, script::PushBytes, transaction::Version, Amount, + Sequence, TxIn, TxOut, Witness, }, pretty_assertions::assert_eq, }; @@ -274,10 +275,10 @@ mod tests { .push_opcode(Runestone::MAGIC_NUMBER) .push_slice(payload) .into_script(), - value: 0, + value: Amount::from_sat(0), }], lock_time: LockTime::ZERO, - version: 2, + version: Version(2), }) .unwrap() } @@ -299,10 +300,10 @@ mod tests { input: Vec::new(), output: vec![TxOut { script_pubkey: ScriptBuf::from_bytes(vec![opcodes::all::OP_PUSHBYTES_4.to_u8()]), - value: 0, + value: Amount::from_sat(0), }], lock_time: LockTime::ZERO, - version: 2, + version: Version(2), }), None, ); @@ -315,7 +316,7 @@ mod tests { input: Vec::new(), output: Vec::new(), lock_time: LockTime::ZERO, - version: 2, + version: Version(2), }), None, ); @@ -328,10 +329,10 @@ mod tests { input: Vec::new(), output: vec![TxOut { script_pubkey: script::Builder::new().push_slice([]).into_script(), - value: 0 + value: Amount::from_sat(0), }], lock_time: LockTime::ZERO, - version: 2, + version: Version(2), }), None, ); @@ -346,10 +347,10 @@ mod tests { script_pubkey: script::Builder::new() .push_opcode(opcodes::all::OP_RETURN) .into_script(), - value: 0 + value: Amount::from_sat(0), }], lock_time: LockTime::ZERO, - version: 2, + version: Version(2), }), None, ); @@ -365,10 +366,10 @@ mod tests { .push_opcode(opcodes::all::OP_RETURN) .push_slice(b"FOOO") .into_script(), - value: 0 + value: Amount::from_sat(0), }], lock_time: LockTime::ZERO, - version: 2, + version: Version(2), }), None, ); @@ -389,10 +390,10 @@ mod tests { input: Vec::new(), output: vec![TxOut { script_pubkey: ScriptBuf::from_bytes(script_pubkey), - value: 0, + value: Amount::from_sat(0), }], lock_time: LockTime::ZERO, - version: 2, + version: Version(2), }), Some(Payload::Invalid(Flaw::InvalidScript)) ); @@ -408,10 +409,10 @@ mod tests { .push_opcode(Runestone::MAGIC_NUMBER) .push_slice([128]) .into_script(), - value: 0, + value: Amount::from_sat(0), }], lock_time: LockTime::ZERO, - version: 2, + version: Version(2), }) .unwrap(); } @@ -432,7 +433,7 @@ mod tests { .push_slice::<&PushBytes>(varint::encode(1).as_slice().try_into().unwrap()) .push_slice([2, 0]) .into_script(), - value: 0, + value: Amount::from_sat(0), }, TxOut { script_pubkey: script::Builder::new() @@ -443,11 +444,11 @@ mod tests { .push_slice::<&PushBytes>(varint::encode(2).as_slice().try_into().unwrap()) .push_slice([3, 0]) .into_script(), - value: 0, + value: Amount::from_sat(0), }, ], lock_time: LockTime::ZERO, - version: 2, + version: Version(2), }) .unwrap(), Artifact::Cenotaph(Cenotaph { @@ -468,10 +469,10 @@ mod tests { .push_opcode(Runestone::MAGIC_NUMBER) .push_opcode(opcodes::all::OP_PUSHNUM_1) .into_script(), - value: 0, + value: Amount::from_sat(0), },], lock_time: LockTime::ZERO, - version: 2, + version: Version(2), }) .unwrap(), Artifact::Cenotaph(Cenotaph { @@ -491,10 +492,10 @@ mod tests { .push_opcode(opcodes::all::OP_RETURN) .push_opcode(Runestone::MAGIC_NUMBER) .into_script(), - value: 0 + value: Amount::from_sat(0), }], lock_time: LockTime::ZERO, - version: 2, + version: Version(2), }) .unwrap(), Artifact::Runestone(Runestone::default()), @@ -520,7 +521,7 @@ mod tests { output: vec![ TxOut { script_pubkey: ScriptBuf::from_bytes(script_pubkey), - value: 0, + value: Amount::from_sat(0), }, TxOut { script_pubkey: script::Builder::new() @@ -528,11 +529,11 @@ mod tests { .push_opcode(Runestone::MAGIC_NUMBER) .push_slice(payload) .into_script(), - value: 0, + value: Amount::from_sat(0), }, ], lock_time: LockTime::ZERO, - version: 2, + version: Version(2), }) .unwrap(), Artifact::Runestone(Runestone { @@ -759,10 +760,10 @@ mod tests { .push_opcode(Runestone::MAGIC_NUMBER) .push_slice([128]) .into_script(), - value: 0, + value: Amount::from_sat(0), }], lock_time: LockTime::ZERO, - version: 2, + version: Version(2), }) .unwrap(), Artifact::Cenotaph(Cenotaph { @@ -1292,10 +1293,10 @@ mod tests { .push_slice::<&PushBytes>(varint::encode(2).as_slice().try_into().unwrap()) .push_slice::<&PushBytes>(varint::encode(0).as_slice().try_into().unwrap()) .into_script(), - value: 0 + value: Amount::from_sat(0), }], lock_time: LockTime::ZERO, - version: 2, + version: Version(2), }) .unwrap(), Artifact::Runestone(Runestone { @@ -1325,7 +1326,7 @@ mod tests { output: vec![ TxOut { script_pubkey: ScriptBuf::new(), - value: 0, + value: Amount::from_sat(0), }, TxOut { script_pubkey: script::Builder::new() @@ -1333,11 +1334,11 @@ mod tests { .push_opcode(Runestone::MAGIC_NUMBER) .push_slice(payload) .into_script(), - value: 0 + value: Amount::from_sat(0), } ], lock_time: LockTime::ZERO, - version: 2, + version: Version(2), }) .unwrap(), Artifact::Runestone(Runestone { @@ -1366,7 +1367,7 @@ mod tests { .push_opcode(opcodes::all::OP_RETURN) .push_slice(b"FOO") .into_script(), - value: 0, + value: Amount::from_sat(0), }, TxOut { script_pubkey: script::Builder::new() @@ -1374,11 +1375,11 @@ mod tests { .push_opcode(Runestone::MAGIC_NUMBER) .push_slice(payload) .into_script(), - value: 0 + value: Amount::from_sat(0), } ], lock_time: LockTime::ZERO, - version: 2, + version: Version(2), }) .unwrap(), Artifact::Runestone(Runestone { @@ -1656,10 +1657,10 @@ mod tests { input: Vec::new(), output: vec![TxOut { script_pubkey, - value: 0, + value: Amount::from_sat(0), }], lock_time: LockTime::ZERO, - version: 2, + version: Version(2), }; let Payload::Valid(payload) = Runestone::payload(&transaction).unwrap() else { @@ -2028,7 +2029,7 @@ mod tests { fn invalid_scripts_in_op_returns_without_magic_number_are_ignored() { assert_eq!( Runestone::decipher(&Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![TxIn { previous_output: OutPoint::null(), @@ -2041,7 +2042,7 @@ mod tests { opcodes::all::OP_RETURN.to_u8(), opcodes::all::OP_PUSHBYTES_4.to_u8(), ]), - value: 0, + value: Amount::from_sat(0), }], }), None @@ -2049,7 +2050,7 @@ mod tests { assert_eq!( Runestone::decipher(&Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![TxIn { previous_output: OutPoint::null(), @@ -2063,11 +2064,11 @@ mod tests { opcodes::all::OP_RETURN.to_u8(), opcodes::all::OP_PUSHBYTES_4.to_u8(), ]), - value: 0, + value: Amount::from_sat(0), }, TxOut { script_pubkey: Runestone::default().encipher(), - value: 0, + value: Amount::from_sat(0), } ], }) @@ -2080,7 +2081,7 @@ mod tests { fn invalid_scripts_in_op_returns_with_magic_number_produce_cenotaph() { assert_eq!( Runestone::decipher(&Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![TxIn { previous_output: OutPoint::null(), @@ -2094,7 +2095,7 @@ mod tests { Runestone::MAGIC_NUMBER.to_u8(), opcodes::all::OP_PUSHBYTES_4.to_u8(), ]), - value: 0, + value: Amount::from_sat(0), }], }) .unwrap(), @@ -2143,12 +2144,12 @@ mod tests { assert_eq!( Runestone::decipher(&Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: default(), output: vec![TxOut { script_pubkey: script_pubkey.into(), - value: 0, + value: Amount::from_sat(0), },], }) .unwrap(), @@ -2162,7 +2163,7 @@ mod tests { for i in 79..=u8::MAX { assert_eq!( Runestone::decipher(&Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: default(), output: vec![TxOut { @@ -2172,7 +2173,7 @@ mod tests { i ] .into(), - value: 0, + value: Amount::from_sat(0), },], }) .unwrap(), diff --git a/crates/ordinals/src/sat_point.rs b/crates/ordinals/src/sat_point.rs index e08f337145..17bf4a2f51 100644 --- a/crates/ordinals/src/sat_point.rs +++ b/crates/ordinals/src/sat_point.rs @@ -34,14 +34,17 @@ impl Display for SatPoint { } impl Encodable for SatPoint { - fn consensus_encode(&self, s: &mut S) -> Result { + fn consensus_encode( + &self, + s: &mut S, + ) -> Result { let len = self.outpoint.consensus_encode(s)?; Ok(len + self.offset.consensus_encode(s)?) } } impl Decodable for SatPoint { - fn consensus_decode( + fn consensus_decode( d: &mut D, ) -> Result { Ok(SatPoint { diff --git a/src/api.rs b/src/api.rs index dc30628e75..5c7254797d 100644 --- a/src/api.rs +++ b/src/api.rs @@ -185,7 +185,7 @@ impl Output { script_pubkey: tx_out.script_pubkey, spent, transaction: outpoint.txid, - value: tx_out.value, + value: tx_out.value.to_sat(), } } } diff --git a/src/chain.rs b/src/chain.rs index e8ff2a2d10..da0e3d7d5c 100644 --- a/src/chain.rs +++ b/src/chain.rs @@ -61,7 +61,7 @@ impl Chain { pub(crate) fn genesis_coinbase_outpoint(self) -> OutPoint { OutPoint { - txid: self.genesis_block().coinbase().unwrap().txid(), + txid: self.genesis_block().coinbase().unwrap().compute_txid(), vout: 0, } } diff --git a/src/error.rs b/src/error.rs index f6f9396e2d..e33d0689f1 100644 --- a/src/error.rs +++ b/src/error.rs @@ -5,12 +5,12 @@ use super::*; pub enum SnafuError { #[snafu(display("Failed to parse address `{}`", input))] AddressParse { - source: bitcoin::address::Error, + source: bitcoin::address::error::ParseError, input: String, }, #[snafu(display("Failed to parse hash `{}`", input))] HashParse { - source: bitcoin::hashes::hex::Error, + source: bitcoin::hex::HexToArrayError, input: String, }, #[snafu(display("Failed to parse inscription ID `{}`", input))] @@ -47,7 +47,7 @@ pub enum SnafuError { UnrecognizedRepresentation { input: String }, #[snafu(display("Unrecognized outgoing amount: `{}`", input))] AmountParse { - source: bitcoin::amount::ParseAmountError, + source: ::Err, input: String, }, #[snafu(display("Unrecognized outgoing: `{}`", input))] @@ -57,7 +57,9 @@ pub enum SnafuError { #[snafu(display("Invalid chain `{}`", chain))] InvalidChain { chain: String }, #[snafu(display("Failed to convert script to address: {}", source))] - AddressConversion { source: bitcoin::address::Error }, + AddressConversion { + source: bitcoin::address::FromScriptError, + }, #[snafu(display("{err}"))] Anyhow { err: anyhow::Error }, #[snafu(display("environment variable `{variable}` not valid unicode: `{}`", value.to_string_lossy()))] diff --git a/src/index.rs b/src/index.rs index 7e7966206f..dc0a57da4f 100644 --- a/src/index.rs +++ b/src/index.rs @@ -440,7 +440,7 @@ impl Index { }; Ok(Self { - genesis_block_coinbase_txid: genesis_block_coinbase_transaction.txid(), + genesis_block_coinbase_txid: genesis_block_coinbase_transaction.compute_txid(), client, database, durability, @@ -2121,7 +2121,7 @@ impl Index { sat: entry.sat, satpoint, timestamp: timestamp(entry.timestamp.into()).timestamp(), - value: output.as_ref().map(|o| o.value), + value: output.as_ref().map(|o| o.value.to_sat()), }, output, inscription, @@ -2343,7 +2343,7 @@ impl Index { indexed = true; TxOut { - value, + value: Amount::from_sat(value), script_pubkey: ScriptBuf::new(), } } else { @@ -2528,7 +2528,7 @@ mod tests { #[test] fn list_second_coinbase_transaction() { let context = Context::builder().arg("--index-sats").build(); - let txid = context.mine_blocks(1)[0].txdata[0].txid(); + let txid = context.mine_blocks(1)[0].txdata[0].compute_txid(); assert_eq!( context.index.list(OutPoint::new(txid, 0)).unwrap().unwrap(), &[(50 * COIN_VALUE, 100 * COIN_VALUE)], @@ -2596,7 +2596,7 @@ mod tests { ..default() }; let txid = context.core.broadcast_tx(fee_paying_tx); - let coinbase_txid = context.mine_blocks(1)[0].txdata[0].txid(); + let coinbase_txid = context.mine_blocks(1)[0].txdata[0].compute_txid(); assert_eq!( context.index.list(OutPoint::new(txid, 0)).unwrap().unwrap(), @@ -2636,7 +2636,7 @@ mod tests { context.core.broadcast_tx(first_fee_paying_tx); context.core.broadcast_tx(second_fee_paying_tx); - let coinbase_txid = context.mine_blocks(1)[0].txdata[0].txid(); + let coinbase_txid = context.mine_blocks(1)[0].txdata[0].compute_txid(); assert_eq!( context @@ -2708,7 +2708,7 @@ mod tests { ..default() }); context.mine_blocks(1); - let txid = context.core.tx(1, 0).txid(); + let txid = context.core.tx(1, 0).compute_txid(); assert_matches!(context.index.list(OutPoint::new(txid, 0)).unwrap(), None); } @@ -2766,7 +2766,7 @@ mod tests { context.index.find(Sat(50 * COIN_VALUE)).unwrap().unwrap(), SatPoint { outpoint: OutPoint { - txid: tx.txid(), + txid: tx.compute_txid(), vout: 0, }, offset: 0, @@ -3049,7 +3049,7 @@ mod tests { ..default() }); - let coinbase_tx = context.mine_blocks(1)[0].txdata[0].txid(); + let coinbase_tx = context.mine_blocks(1)[0].txdata[0].compute_txid(); context.index.assert_inscription_location( inscription_id, @@ -3084,7 +3084,7 @@ mod tests { ..default() }); - let coinbase_tx = context.mine_blocks(1)[0].txdata[0].txid(); + let coinbase_tx = context.mine_blocks(1)[0].txdata[0].compute_txid(); context.index.assert_inscription_location( inscription_id, @@ -3112,7 +3112,7 @@ mod tests { }); let inscription_id = InscriptionId { txid, index: 0 }; - let coinbase_tx = context.mine_blocks(1)[0].txdata[0].txid(); + let coinbase_tx = context.mine_blocks(1)[0].txdata[0].compute_txid(); context.index.assert_inscription_location( inscription_id, @@ -5914,7 +5914,7 @@ mod tests { inscription_id, SatPoint { outpoint: OutPoint { - txid: blocks[0].txdata[0].txid(), + txid: blocks[0].txdata[0].compute_txid(), vout: 0, }, offset: 50 * COIN_VALUE, @@ -5945,7 +5945,7 @@ mod tests { inscription_id, SatPoint { outpoint: OutPoint { - txid: blocks[0].txdata[0].txid(), + txid: blocks[0].txdata[0].compute_txid(), vout: 0, }, offset: 50 * COIN_VALUE, @@ -6193,7 +6193,7 @@ mod tests { assert!(!context .index .is_output_spent(OutPoint { - txid: context.core.tx(1, 0).txid(), + txid: context.core.tx(1, 0).compute_txid(), vout: 0, }) .unwrap()); @@ -6208,7 +6208,7 @@ mod tests { assert!(context .index .is_output_spent(OutPoint { - txid: context.core.tx(1, 0).txid(), + txid: context.core.tx(1, 0).compute_txid(), vout: 0, }) .unwrap()); @@ -6233,7 +6233,7 @@ mod tests { assert!(context .index .is_output_in_active_chain(OutPoint { - txid: context.core.tx(1, 0).txid(), + txid: context.core.tx(1, 0).compute_txid(), vout: 0, }) .unwrap()); @@ -6241,7 +6241,7 @@ mod tests { assert!(!context .index .is_output_in_active_chain(OutPoint { - txid: context.core.tx(1, 0).txid(), + txid: context.core.tx(1, 0).compute_txid(), vout: 1, }) .unwrap()); @@ -6282,7 +6282,7 @@ mod tests { .unwrap(); let first_address_second_output = OutPoint { - txid: transaction.txid(), + txid: transaction.compute_txid(), vout: 1, }; @@ -6290,7 +6290,7 @@ mod tests { context.index.get_address_info(&first_address).unwrap(), [ OutPoint { - txid: transaction.txid(), + txid: transaction.compute_txid(), vout: 0 }, first_address_second_output @@ -6322,7 +6322,7 @@ mod tests { assert_eq!( context.index.get_address_info(&second_address).unwrap(), [OutPoint { - txid: transaction.txid(), + txid: transaction.compute_txid(), vout: 0 }] ); diff --git a/src/index/entry.rs b/src/index/entry.rs index 268bf81f9e..464cae34ff 100644 --- a/src/index/entry.rs +++ b/src/index/entry.rs @@ -18,11 +18,10 @@ impl Entry for Header { } fn store(self) -> Self::Value { - let mut buffer = Cursor::new([0; 80]); + let mut buffer = [0; 80]; let len = self - .consensus_encode(&mut buffer) + .consensus_encode(&mut buffer.as_mut_slice()) .expect("in-memory writers don't error"); - let buffer = buffer.into_inner(); debug_assert_eq!(len, buffer.len()); buffer } @@ -422,7 +421,7 @@ impl Entry for OutPoint { type Value = OutPointValue; fn load(value: Self::Value) -> Self { - Decodable::consensus_decode(&mut Cursor::new(value)).unwrap() + Decodable::consensus_decode(&mut bitcoin::io::Cursor::new(value)).unwrap() } fn store(self) -> Self::Value { @@ -438,7 +437,7 @@ impl Entry for SatPoint { type Value = SatPointValue; fn load(value: Self::Value) -> Self { - Decodable::consensus_decode(&mut Cursor::new(value)).unwrap() + Decodable::consensus_decode(&mut bitcoin::io::Cursor::new(value)).unwrap() } fn store(self) -> Self::Value { diff --git a/src/index/testing.rs b/src/index/testing.rs index ae4f02a823..27af8ede60 100644 --- a/src/index/testing.rs +++ b/src/index/testing.rs @@ -31,10 +31,12 @@ impl ContextBuilder { ]; let options = Options::try_parse_from(command.into_iter().chain(self.args)).unwrap(); + let index = Index::open_with_event_sender( &Settings::from_options(options).or_defaults().unwrap(), self.event_sender, )?; + index.update().unwrap(); Ok(Context { diff --git a/src/index/updater.rs b/src/index/updater.rs index f1f62cc557..d60fa73b3b 100644 --- a/src/index/updater.rs +++ b/src/index/updater.rs @@ -24,7 +24,7 @@ impl From for BlockData { .txdata .into_iter() .map(|transaction| { - let txid = transaction.txid(); + let txid = transaction.compute_txid(); (transaction, txid) }) .collect(), @@ -570,7 +570,7 @@ impl<'index> Updater<'index> { })?; let mut entry = UtxoEntryBuf::new(); - entry.push_value(txout.value, self.index); + entry.push_value(txout.value.to_sat(), self.index); if self.index.index_addresses { entry.push_script_pubkey(txout.script_pubkey.as_bytes(), self.index); } @@ -625,7 +625,7 @@ impl<'index> Updater<'index> { input_sat_ranges = None; for (vout, txout) in tx.output.iter().enumerate() { - output_utxo_entries[vout].push_value(txout.value, self.index); + output_utxo_entries[vout].push_value(txout.value.to_sat(), self.index); } } @@ -758,7 +758,7 @@ impl<'index> Updater<'index> { txid, }; - let mut remaining = output.value; + let mut remaining = output.value.to_sat(); while remaining > 0 { let range = pending_input_sat_range.take().unwrap_or_else(|| { SatRange::load( @@ -775,7 +775,7 @@ impl<'index> Updater<'index> { &range.0, &SatPoint { outpoint, - offset: output.value - remaining, + offset: output.value.to_sat() - remaining, } .store(), )?; diff --git a/src/index/updater/inscription_updater.rs b/src/index/updater/inscription_updater.rs index 59e4738889..0d808c226c 100644 --- a/src/index/updater/inscription_updater.rs +++ b/src/index/updater/inscription_updater.rs @@ -74,7 +74,11 @@ impl<'a, 'tx> InscriptionUpdater<'a, 'tx> { let mut inscribed_offsets = BTreeMap::new(); let jubilant = self.height >= index.settings.chain().jubilee_height(); let mut total_input_value = 0; - let total_output_value = tx.output.iter().map(|txout| txout.value).sum::(); + let total_output_value = tx + .output + .iter() + .map(|txout| txout.value.to_sat()) + .sum::(); let envelopes = ParsedEnvelope::from_transaction(tx); let has_new_inscriptions = !envelopes.is_empty(); @@ -272,7 +276,7 @@ impl<'a, 'tx> InscriptionUpdater<'a, 'tx> { let mut new_locations = Vec::new(); let mut output_value = 0; for (vout, txout) in tx.output.iter().enumerate() { - let end = output_value + txout.value; + let end = output_value + txout.value.to_sat(); while let Some(flotsam) = inscriptions.peek() { if flotsam.offset >= end { diff --git a/src/index/updater/rune_updater.rs b/src/index/updater/rune_updater.rs index 6eef345a8a..36bbdcb72c 100644 --- a/src/index/updater/rune_updater.rs +++ b/src/index/updater/rune_updater.rs @@ -438,7 +438,7 @@ impl<'a, 'tx, 'client> RuneUpdater<'a, 'tx, 'client> { let taproot = tx_info.vout[input.previous_output.vout.into_usize()] .script_pub_key .script()? - .is_v1_p2tr(); + .is_p2tr(); if !taproot { continue; diff --git a/src/inscriptions/envelope.rs b/src/inscriptions/envelope.rs index 242d09f8c9..a8c7b8788c 100644 --- a/src/inscriptions/envelope.rs +++ b/src/inscriptions/envelope.rs @@ -261,7 +261,7 @@ mod tests { fn parse(witnesses: &[Witness]) -> Vec { ParsedEnvelope::from_transaction(&Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: witnesses .iter() @@ -885,7 +885,7 @@ mod tests { #[test] fn pushnum_opcodes_are_parsed_correctly() { - const PUSHNUMS: &[(opcodes::All, u8)] = &[ + const PUSHNUMS: &[(opcodes::Opcode, u8)] = &[ (opcodes::all::OP_PUSHNUM_NEG1, 0x81), (opcodes::all::OP_PUSHNUM_1, 1), (opcodes::all::OP_PUSHNUM_2, 2), diff --git a/src/inscriptions/inscription_id.rs b/src/inscriptions/inscription_id.rs index 92fc0a844f..29e30a29c7 100644 --- a/src/inscriptions/inscription_id.rs +++ b/src/inscriptions/inscription_id.rs @@ -47,7 +47,7 @@ pub enum ParseError { Character(char), Length(usize), Separator(char), - Txid(bitcoin::hashes::hex::Error), + Txid(bitcoin::hex::HexToArrayError), Index(std::num::ParseIntError), } diff --git a/src/lib.rs b/src/lib.rs index b6274c1d39..9fd522800c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,8 +41,10 @@ use { consensus::{self, Decodable, Encodable}, hash_types::{BlockHash, TxMerkleNode}, hashes::Hash, - script, Amount, Block, Network, OutPoint, Script, ScriptBuf, Sequence, Transaction, TxIn, - TxOut, Txid, Witness, + script, + transaction::Version, + Amount, Block, Network, OutPoint, Script, ScriptBuf, Sequence, Transaction, TxIn, TxOut, Txid, + Witness, }, bitcoincore_rpc::{Client, RpcApi}, chrono::{DateTime, TimeZone, Utc}, @@ -64,7 +66,7 @@ use { std::{ backtrace::BacktraceStatus, cmp, - collections::{BTreeMap, BTreeSet, HashMap, HashSet}, + collections::{BTreeMap, BTreeSet, HashSet}, env, ffi::OsString, fmt::{self, Display, Formatter}, diff --git a/src/outgoing.rs b/src/outgoing.rs index 8bb17803a1..5d38de941e 100644 --- a/src/outgoing.rs +++ b/src/outgoing.rs @@ -215,7 +215,10 @@ mod tests { ); case("0 btc", Outgoing::Amount("0 btc".parse().unwrap())); - case("1.2 btc", Outgoing::Amount("1.2 btc".parse().unwrap())); + case( + "1.20000000 btc", + Outgoing::Amount("1.2 btc".parse().unwrap()), + ); case( "0:XY•Z", diff --git a/src/settings.rs b/src/settings.rs index a368a97e0a..7cc5ffb1ff 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -429,9 +429,9 @@ impl Settings { let rpc_chain = loop { match client.get_blockchain_info() { Ok(blockchain_info) => { - break match blockchain_info.chain.as_str() { - "main" => Chain::Mainnet, - "test" => Chain::Testnet, + break match blockchain_info.chain.to_string().as_str() { + "bitcoin" => Chain::Mainnet, + "testnet" => Chain::Testnet, "regtest" => Chain::Regtest, "signet" => Chain::Signet, other => bail!("Bitcoin RPC server on unknown chain: {other}"), diff --git a/src/subcommand/decode.rs b/src/subcommand/decode.rs index ebe8a557f3..2e28d6e8dc 100644 --- a/src/subcommand/decode.rs +++ b/src/subcommand/decode.rs @@ -77,9 +77,9 @@ impl Decode { .bitcoin_rpc_client(None)? .get_raw_transaction(&txid, None)? } else if let Some(file) = self.file { - Transaction::consensus_decode(&mut fs::File::open(file)?)? + Transaction::consensus_decode(&mut io::BufReader::new(fs::File::open(file)?))? } else { - Transaction::consensus_decode(&mut io::stdin())? + Transaction::consensus_decode(&mut io::BufReader::new(io::stdin()))? }; let inscriptions = ParsedEnvelope::from_transaction(&transaction); diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 9701d26bcd..afce59054e 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -1077,7 +1077,7 @@ impl Server { id: inscription_id, number: entry.inscription_number, output: satpoint.outpoint, - value: output.as_ref().map(|o| o.value), + value: output.as_ref().map(|o| o.value.to_sat()), sat: entry.sat, satpoint, timestamp: timestamp(entry.timestamp.into()).timestamp(), @@ -2826,7 +2826,7 @@ mod tests { .index_sats() .build(); - let txid = server.mine_blocks(1)[0].txdata[0].txid(); + let txid = server.mine_blocks(1)[0].txdata[0].compute_txid(); server.assert_redirect( &format!("/search/{txid}:0:0"), @@ -4092,7 +4092,7 @@ mod tests { let test_server = TestServer::new(); let coinbase_tx = test_server.mine_blocks(1)[0].txdata[0].clone(); - let txid = coinbase_tx.txid(); + let txid = coinbase_tx.compute_txid(); test_server.assert_response_regex( format!("/tx/{txid}"), diff --git a/src/subcommand/wallet/balance.rs b/src/subcommand/wallet/balance.rs index 192904a069..bda1b72cf5 100644 --- a/src/subcommand/wallet/balance.rs +++ b/src/subcommand/wallet/balance.rs @@ -32,7 +32,7 @@ pub(crate) fn run(wallet: Wallet) -> SubcommandResult { let is_runic = !rune_balances.is_empty(); if is_ordinal { - ordinal += txout.value; + ordinal += txout.value.to_sat(); } if is_runic { @@ -48,11 +48,11 @@ pub(crate) fn run(wallet: Wallet) -> SubcommandResult { scale: pile.divisibility, }); } - runic += txout.value; + runic += txout.value.to_sat(); } if !is_ordinal && !is_runic { - cardinal += txout.value; + cardinal += txout.value.to_sat(); } if is_ordinal && is_runic { diff --git a/src/subcommand/wallet/batch_command.rs b/src/subcommand/wallet/batch_command.rs index 6a5d6b7cc5..5da34d6348 100644 --- a/src/subcommand/wallet/batch_command.rs +++ b/src/subcommand/wallet/batch_command.rs @@ -22,7 +22,10 @@ impl Batch { let (inscriptions, reveal_satpoints, postages, destinations) = batchfile.inscriptions( &wallet, utxos, - parent_info.iter().map(|info| info.tx_out.value).collect(), + parent_info + .iter() + .map(|info| info.tx_out.value.to_sat()) + .collect(), self.shared.compress, )?; diff --git a/src/subcommand/wallet/cardinals.rs b/src/subcommand/wallet/cardinals.rs index 6b7413c78a..bceeba421c 100644 --- a/src/subcommand/wallet/cardinals.rs +++ b/src/subcommand/wallet/cardinals.rs @@ -25,7 +25,7 @@ pub(crate) fn run(wallet: Wallet) -> SubcommandResult { } else { Some(CardinalUtxo { output: *output, - amount: txout.value, + amount: txout.value.to_sat(), }) } }) diff --git a/src/subcommand/wallet/inscriptions.rs b/src/subcommand/wallet/inscriptions.rs index e726fefb7f..2f235678a2 100644 --- a/src/subcommand/wallet/inscriptions.rs +++ b/src/subcommand/wallet/inscriptions.rs @@ -25,7 +25,7 @@ pub(crate) fn run(wallet: Wallet) -> SubcommandResult { location: *location, inscription: *inscription, explorer: format!("{explorer}{inscription}"), - postage: txout.value, + postage: txout.value.to_sat(), }) } } diff --git a/src/subcommand/wallet/mint.rs b/src/subcommand/wallet/mint.rs index 9a5ce1a083..99fb51f3fe 100644 --- a/src/subcommand/wallet/mint.rs +++ b/src/subcommand/wallet/mint.rs @@ -53,9 +53,9 @@ impl Mint { }; ensure!( - destination.script_pubkey().dust_value() <= postage, + destination.script_pubkey().minimal_non_dust() <= postage, "postage below dust limit of {}sat", - destination.script_pubkey().dust_value().to_sat() + destination.script_pubkey().minimal_non_dust().to_sat() ); let runestone = Runestone { @@ -72,17 +72,17 @@ impl Mint { ); let unfunded_transaction = Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: Vec::new(), output: vec![ TxOut { script_pubkey, - value: 0, + value: Amount::from_sat(0), }, TxOut { script_pubkey: destination.script_pubkey(), - value: postage.to_sat(), + value: postage, }, ], }; diff --git a/src/subcommand/wallet/outputs.rs b/src/subcommand/wallet/outputs.rs index 06acfd4a97..c3923123e3 100644 --- a/src/subcommand/wallet/outputs.rs +++ b/src/subcommand/wallet/outputs.rs @@ -32,7 +32,7 @@ impl Outputs { outputs.push(Output { output: *output, - amount: txout.value, + amount: txout.value.to_sat(), sat_ranges, }); } diff --git a/src/subcommand/wallet/pending.rs b/src/subcommand/wallet/pending.rs index 5eeeaa7e88..efb9a04b04 100644 --- a/src/subcommand/wallet/pending.rs +++ b/src/subcommand/wallet/pending.rs @@ -18,7 +18,7 @@ impl Pending { PendingOutput { rune: spaced_rune, - commit: entry.commit.txid(), + commit: entry.commit.compute_txid(), } }) .collect::>(); diff --git a/src/subcommand/wallet/send.rs b/src/subcommand/wallet/send.rs index 8ec204dcd2..b3557f245f 100644 --- a/src/subcommand/wallet/send.rs +++ b/src/subcommand/wallet/send.rs @@ -92,12 +92,12 @@ impl Send { wallet.lock_non_cardinal_outputs()?; let unfunded_transaction = Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut { script_pubkey: destination.script_pubkey(), - value: amount.to_sat(), + value: amount, }], }; @@ -252,7 +252,7 @@ impl Send { }; let unfunded_transaction = Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: inputs .into_iter() @@ -267,21 +267,21 @@ impl Send { vec![ TxOut { script_pubkey: runestone.encipher(), - value: 0, + value: Amount::from_sat(0), }, TxOut { script_pubkey: wallet.get_change_address()?.script_pubkey(), - value: postage.to_sat(), + value: postage, }, TxOut { script_pubkey: destination.script_pubkey(), - value: postage.to_sat(), + value: postage, }, ] } else { vec![TxOut { script_pubkey: destination.script_pubkey(), - value: postage.to_sat(), + value: postage, }] }, }; diff --git a/src/templates/output.rs b/src/templates/output.rs index 7bcd0c7009..31af3ca034 100644 --- a/src/templates/output.rs +++ b/src/templates/output.rs @@ -31,7 +31,7 @@ mod tests { chain: Chain::Mainnet, inscriptions: Vec::new(), outpoint: outpoint(1), - output: TxOut { value: 3, script_pubkey: ScriptBuf::new_p2pkh(&PubkeyHash::all_zeros()), }, + output: TxOut { value: Amount::from_sat(3), script_pubkey: ScriptBuf::new_p2pkh(&PubkeyHash::all_zeros()), }, runes: BTreeMap::new(), sat_ranges: Some(vec![(0, 1), (1, 3)]), spent: false, @@ -63,7 +63,7 @@ mod tests { inscriptions: Vec::new(), outpoint: outpoint(1), output: TxOut { - value: 1, + value: Amount::from_sat(1), script_pubkey: script::Builder::new().push_int(0).into_script(), }, runes: BTreeMap::new(), @@ -90,7 +90,7 @@ mod tests { chain: Chain::Mainnet, inscriptions: Vec::new(), outpoint: outpoint(1), - output: TxOut { value: 3, script_pubkey: ScriptBuf::new_p2pkh(&PubkeyHash::all_zeros()), }, + output: TxOut { value: Amount::from_sat(3), script_pubkey: ScriptBuf::new_p2pkh(&PubkeyHash::all_zeros()), }, runes: BTreeMap::new(), sat_ranges: Some(vec![(0, 1), (1, 3)]), spent: true, @@ -121,7 +121,7 @@ mod tests { chain: Chain::Mainnet, inscriptions: Vec::new(), outpoint: outpoint(1), - output: TxOut { value: 3, script_pubkey: ScriptBuf::new_p2pkh(&PubkeyHash::all_zeros()), }, + output: TxOut { value: Amount::from_sat(3), script_pubkey: ScriptBuf::new_p2pkh(&PubkeyHash::all_zeros()), }, runes: BTreeMap::new(), sat_ranges: None, spent: false, @@ -149,7 +149,7 @@ mod tests { inscriptions: vec![inscription_id(1)], outpoint: outpoint(1), output: TxOut { - value: 3, + value: Amount::from_sat(3), script_pubkey: ScriptBuf::new_p2pkh(&PubkeyHash::all_zeros()), }, runes: BTreeMap::new(), @@ -178,7 +178,7 @@ mod tests { inscriptions: Vec::new(), outpoint: outpoint(1), output: TxOut { - value: 3, + value: Amount::from_sat(3), script_pubkey: ScriptBuf::new_p2pkh(&PubkeyHash::all_zeros()), }, runes: vec![( diff --git a/src/templates/transaction.rs b/src/templates/transaction.rs index b62e6efafd..3cdffce40a 100644 --- a/src/templates/transaction.rs +++ b/src/templates/transaction.rs @@ -22,7 +22,7 @@ mod tests { #[test] fn html() { let transaction = Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![TxIn { sequence: Default::default(), @@ -32,24 +32,24 @@ mod tests { }], output: vec![ TxOut { - value: 50 * COIN_VALUE, + value: Amount::from_sat(50 * COIN_VALUE), script_pubkey: script::Builder::new().push_int(0).into_script(), }, TxOut { - value: 50 * COIN_VALUE, + value: Amount::from_sat(50 * COIN_VALUE), script_pubkey: script::Builder::new().push_int(1).into_script(), }, ], }; - let txid = transaction.txid(); + let txid = transaction.compute_txid(); pretty_assert_eq!( TransactionHtml { chain: Chain::Mainnet, etching: None, inscription_count: 0, - txid: transaction.txid(), + txid: transaction.compute_txid(), transaction, }.to_string(), format!( diff --git a/src/test.rs b/src/test.rs index 868e036e43..f4aa2c1176 100644 --- a/src/test.rs +++ b/src/test.rs @@ -2,10 +2,10 @@ pub(crate) use { super::*, bitcoin::{ blockdata::script::{PushBytes, PushBytesBuf}, - constants::COIN_VALUE, opcodes, WPubkeyHash, }, mockcore::TransactionTemplate, + ordinals::COIN_VALUE, pretty_assertions::assert_eq as pretty_assert_eq, std::iter, tempfile::TempDir, @@ -75,7 +75,7 @@ pub(crate) fn tx_in(previous_output: OutPoint) -> TxIn { pub(crate) fn tx_out(value: u64, address: Address) -> TxOut { TxOut { - value, + value: Amount::from_sat(value), script_pubkey: address.script_pubkey(), } } @@ -132,7 +132,7 @@ pub(crate) fn envelope(payload: &[&[u8]]) -> Witness { pub(crate) fn default_address(chain: Chain) -> Address { Address::from_script( - &ScriptBuf::new_v0_p2wpkh(&WPubkeyHash::all_zeros()), + &ScriptBuf::new_p2wpkh(&WPubkeyHash::all_zeros()), chain.network(), ) .unwrap() diff --git a/src/wallet.rs b/src/wallet.rs index 85c664d94d..b169e3d6da 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -4,7 +4,7 @@ use { batch::ParentInfo, bitcoin::secp256k1::{All, Secp256k1}, bitcoin::{ - bip32::{ChildNumber, DerivationPath, ExtendedPrivKey, Fingerprint}, + bip32::{ChildNumber, DerivationPath, Fingerprint, Xpriv}, psbt::Psbt, }, bitcoincore_rpc::bitcoincore_rpc_json::{ImportDescriptors, Timestamp}, @@ -334,13 +334,13 @@ impl Wallet { Ok( if let Some(commit_tx) = self .bitcoin_client() - .get_transaction(&commit.txid(), Some(true)) + .get_transaction(&commit.compute_txid(), Some(true)) .into_option()? { let current_confirmations = u32::try_from(commit_tx.info.confirmations)?; if self .bitcoin_client() - .get_tx_out(&commit.txid(), 0, Some(true))? + .get_tx_out(&commit.compute_txid(), 0, Some(true))? .is_none() { Maturity::CommitSpent(commit_tx.info.txid) @@ -367,7 +367,7 @@ impl Wallet { eprintln!( "Waiting for rune {} commitment {} to mature…", rune, - entry.commit.txid() + entry.commit.compute_txid() ); let mut pending_confirmations: u32 = Runestone::COMMIT_CONFIRMATIONS.into(); @@ -417,7 +417,7 @@ impl Wallet { Err(err) => { return Err(anyhow!( "Failed to send reveal transaction: {err}\nCommit tx {} will be recovered once mined", - entry.commit.txid() + entry.commit.compute_txid() )) } }; @@ -497,7 +497,7 @@ impl Wallet { let secp = Secp256k1::new(); - let master_private_key = ExtendedPrivKey::new_master(network, &seed)?; + let master_private_key = Xpriv::new_master(network, &seed)?; let fingerprint = master_private_key.fingerprint(&secp); @@ -529,7 +529,7 @@ impl Wallet { settings: &Settings, secp: &Secp256k1, origin: (Fingerprint, DerivationPath), - derived_private_key: ExtendedPrivKey, + derived_private_key: Xpriv, change: bool, ) -> Result { let secret_key = DescriptorSecretKey::XPrv(DescriptorXKey { @@ -543,7 +543,7 @@ impl Wallet { let public_key = secret_key.to_public(secp)?; - let mut key_map = HashMap::new(); + let mut key_map = BTreeMap::new(); key_map.insert(public_key.clone(), secret_key); let descriptor = miniscript::descriptor::Descriptor::new_tr(public_key, None)?; @@ -759,7 +759,7 @@ impl Wallet { )? .psbt; - (unsigned_transaction.txid(), psbt) + (unsigned_transaction.compute_txid(), psbt) } else { let psbt = self .bitcoin_client() @@ -789,11 +789,11 @@ impl Wallet { let Some(txout) = unspent_outputs.get(&txin.previous_output) else { panic!("input {} not found in utxos", txin.previous_output); }; - fee += txout.value; + fee += txout.value.to_sat(); } for txout in unsigned_transaction.output.iter() { - fee = fee.checked_sub(txout.value).unwrap(); + fee = fee.checked_sub(txout.value.to_sat()).unwrap(); } Ok((txid, psbt, fee)) diff --git a/src/wallet/batch.rs b/src/wallet/batch.rs index aa82d70f78..665dc989ac 100644 --- a/src/wallet/batch.rs +++ b/src/wallet/batch.rs @@ -3,7 +3,7 @@ use { bitcoin::{ blockdata::{opcodes, script}, key::PrivateKey, - key::{TapTweak, TweakedKeyPair, TweakedPublicKey, UntweakedKeyPair}, + key::{TapTweak, TweakedKeypair, TweakedPublicKey, UntweakedKeypair}, policy::MAX_STANDARD_TX_WEIGHT, secp256k1::{self, constants::SCHNORR_SIGNATURE_SIZE, rand, Secp256k1, XOnlyPublicKey}, sighash::{Prevouts, SighashCache, TapSighashType}, @@ -113,8 +113,8 @@ mod tests { let fee = Amount::from_sat((1.0 * (reveal_tx.vsize() as f64)).ceil() as u64); assert_eq!( - reveal_tx.output[0].value, - 20000 - fee.to_sat() - (20000 - commit_tx.output[0].value), + reveal_tx.output[0].value.to_sat(), + 20000 - fee.to_sat() - (20000 - commit_tx.output[0].value.to_sat()), ); } @@ -314,7 +314,7 @@ mod tests { .reduce(|acc, i| acc + i) .unwrap(); - assert_eq!(reveal_value, 20_000 - fee); + assert_eq!(reveal_value.to_sat(), 20_000 - fee); let fee = FeeRate::try_from(fee_rate) .unwrap() @@ -322,8 +322,8 @@ mod tests { .to_sat(); assert_eq!( - reveal_tx.output[0].value, - 20_000 - fee - (20_000 - commit_tx.output[0].value), + reveal_tx.output[0].value.to_sat(), + 20_000 - fee - (20_000 - commit_tx.output[0].value.to_sat()), ); } @@ -345,7 +345,7 @@ mod tests { }, tx_out: TxOut { script_pubkey: change(0).script_pubkey(), - value: 10000, + value: Amount::from_sat(10000), }, }; @@ -402,15 +402,14 @@ mod tests { .reduce(|acc, i| acc + i) .unwrap(); - assert_eq!(reveal_value, 20_000 - fee); + assert_eq!(reveal_value.to_sat(), 20_000 - fee); let sig_vbytes = 16; let fee = FeeRate::try_from(fee_rate) .unwrap() - .fee(reveal_tx.vsize() + sig_vbytes) - .to_sat(); + .fee(reveal_tx.vsize() + sig_vbytes); - assert_eq!(fee, commit_tx.output[0].value - reveal_tx.output[1].value,); + assert_eq!(fee, commit_tx.output[0].value - reveal_tx.output[1].value); assert_eq!( reveal_tx.output[0].script_pubkey, parent_info.destination.script_pubkey() @@ -489,7 +488,7 @@ mod tests { .reduce(|acc, i| acc + i) .unwrap(); - assert_eq!(reveal_value, 20_000 - fee); + assert_eq!(reveal_value.to_sat(), 20_000 - fee); let fee = FeeRate::try_from(fee_rate) .unwrap() @@ -497,8 +496,8 @@ mod tests { .to_sat(); assert_eq!( - reveal_tx.output[0].value, - 20_000 - fee - (20_000 - commit_tx.output[0].value), + reveal_tx.output[0].value.to_sat(), + 20_000 - fee - (20_000 - commit_tx.output[0].value.to_sat()), ); } @@ -576,7 +575,7 @@ mod tests { ) .unwrap(); - assert!(reveal_tx.size() >= MAX_STANDARD_TX_WEIGHT as usize); + assert!(reveal_tx.total_size() >= MAX_STANDARD_TX_WEIGHT as usize); } #[test] @@ -597,7 +596,7 @@ mod tests { }, tx_out: TxOut { script_pubkey: change(0).script_pubkey(), - value: 10000, + value: Amount::from_sat(10000), }, }; @@ -667,12 +666,12 @@ mod tests { .reduce(|acc, i| acc + i) .unwrap(); - assert_eq!(reveal_value, 50_000 - fee); + assert_eq!(reveal_value.to_sat(), 50_000 - fee); let sig_vbytes = 16; - let fee = fee_rate.fee(reveal_tx.vsize() + sig_vbytes).to_sat(); + let fee = fee_rate.fee(reveal_tx.vsize() + sig_vbytes); - assert_eq!(fee, commit_tx.output[0].value - reveal_tx.output[1].value,); + assert_eq!(fee, commit_tx.output[0].value - reveal_tx.output[1].value); assert_eq!( reveal_tx.output[0].script_pubkey, parent_info.destination.script_pubkey() @@ -710,7 +709,7 @@ mod tests { }, tx_out: TxOut { script_pubkey: change(0).script_pubkey(), - value: 10_000, + value: Amount::from_sat(10_000), }, }; @@ -803,7 +802,7 @@ mod tests { .reduce(|acc, i| acc + i) .unwrap(); - assert_eq!(reveal_value, 50_000 - fee); + assert_eq!(reveal_value.to_sat(), 50_000 - fee); assert_eq!( reveal_tx.output[0].script_pubkey, @@ -838,7 +837,7 @@ mod tests { }, tx_out: TxOut { script_pubkey: change(0).script_pubkey(), - value: 10000, + value: Amount::from_sat(10000), }, }; @@ -915,7 +914,7 @@ mod tests { }, tx_out: TxOut { script_pubkey: change(0).script_pubkey(), - value: 10000, + value: Amount::from_sat(10000), }, }; @@ -1068,7 +1067,7 @@ mod tests { assert!(reveal_tx .output .iter() - .all(|output| output.value == TARGET_POSTAGE.to_sat())); + .all(|output| output.value == TARGET_POSTAGE)); } #[test] @@ -1089,7 +1088,7 @@ mod tests { }, tx_out: TxOut { script_pubkey: change(0).script_pubkey(), - value: 10000, + value: Amount::from_sat(10000), }, }; @@ -1176,7 +1175,7 @@ mod tests { .reduce(|acc, i| acc + i) .unwrap(); - assert_eq!(reveal_value, 50_000 - fee); + assert_eq!(reveal_value.to_sat(), 50_000 - fee); assert_eq!( reveal_tx.output[0].script_pubkey, diff --git a/src/wallet/batch/file.rs b/src/wallet/batch/file.rs index 8f1050d02e..1bbfda4e52 100644 --- a/src/wallet/batch/file.rs +++ b/src/wallet/batch/file.rs @@ -158,19 +158,15 @@ impl File { txout.value } else { - self - .postage - .map(Amount::from_sat) - .unwrap_or(TARGET_POSTAGE) - .to_sat() + self.postage.map(Amount::from_sat).unwrap_or(TARGET_POSTAGE) }; - pointer += postage; + pointer += postage.to_sat(); if self.mode == Mode::SameSat && i > 0 { continue; } else { - postages.push(Amount::from_sat(postage)); + postages.push(postage); } } diff --git a/src/wallet/batch/plan.rs b/src/wallet/batch/plan.rs index ce49ee600e..9f844ca845 100644 --- a/src/wallet/batch/plan.rs +++ b/src/wallet/batch/plan.rs @@ -78,9 +78,9 @@ impl Plan { let reveal_psbt = Psbt::from_unsigned_tx(Self::remove_witnesses(reveal_tx.clone()))?; return Ok(Some(Box::new(self.output( - commit_tx.txid(), + commit_tx.compute_txid(), Some(commit_psbt), - reveal_tx.txid(), + reveal_tx.compute_txid(), false, Some(base64::engine::general_purpose::STANDARD.encode(reveal_psbt.serialize())), total_fees, @@ -102,11 +102,11 @@ impl Plan { .iter() .enumerate() .map(|(vout, output)| SignRawTransactionInput { - txid: commit_tx.txid(), + txid: commit_tx.compute_txid(), vout: vout.try_into().unwrap(), script_pub_key: output.script_pubkey.clone(), redeem_script: None, - amount: Some(Amount::from_sat(output.value)), + amount: Some(output.value), }) .collect::>(), ), @@ -142,9 +142,9 @@ impl Plan { &commit, &reveal, self.output( - commit.txid(), + commit.compute_txid(), None, - reveal.txid(), + reveal.compute_txid(), false, None, total_fees, @@ -322,7 +322,7 @@ impl Plan { utxos .iter() .find(|(outpoint, txout)| { - txout.value > 0 + txout.value.to_sat() > 0 && !inscribed_utxos.contains(outpoint) && !locked_utxos.contains(outpoint) && !runic_utxos.contains(outpoint) @@ -364,7 +364,7 @@ impl Plan { } let secp256k1 = Secp256k1::new(); - let key_pair = UntweakedKeyPair::new(&secp256k1, &mut rand::thread_rng()); + let key_pair = UntweakedKeypair::new(&secp256k1, &mut rand::thread_rng()); let (public_key, _parity) = XOnlyPublicKey::from_keypair(&key_pair); let reveal_script = Inscription::append_batch_reveal_script( @@ -386,7 +386,7 @@ impl Plan { let commit_tx_address = Address::p2tr_tweaked(taproot_spend_info.output_key(), chain.network()); - let total_postage = self.postages.iter().map(|amount| amount.to_sat()).sum(); + let total_postage = self.postages.clone().into_iter().sum(); let mut reveal_inputs = Vec::new(); let mut reveal_outputs = Vec::new(); @@ -417,7 +417,7 @@ impl Plan { reveal_outputs.push(TxOut { script_pubkey: destination.script_pubkey(), value: match self.mode { - Mode::SeparateOutputs | Mode::SatPoints => self.postages[i].to_sat(), + Mode::SeparateOutputs | Mode::SatPoints => self.postages[i], Mode::SharedOutput | Mode::SameSat => total_postage, }, }); @@ -438,7 +438,7 @@ impl Plan { reveal_outputs.push(TxOut { script_pubkey: reveal_change.into(), - value: TARGET_POSTAGE.to_sat(), + value: TARGET_POSTAGE, }); vout = Some(output); @@ -490,7 +490,7 @@ impl Plan { reveal_outputs.push(TxOut { script_pubkey, - value: 0, + value: Amount::from_sat(0), }); rune = Some((destination, etching.rune, vout)); @@ -515,7 +515,7 @@ impl Plan { let mut target_value = reveal_fee; if self.mode != Mode::SatPoints { - target_value += Amount::from_sat(total_postage); + target_value += total_postage; } if premine > 0 { @@ -544,7 +544,7 @@ impl Plan { .expect("should find sat commit/inscription output"); reveal_inputs[commit_input] = OutPoint { - txid: unsigned_commit_tx.txid(), + txid: unsigned_commit_tx.compute_txid(), vout: vout.try_into().unwrap(), }; @@ -560,7 +560,7 @@ impl Plan { for output in reveal_tx.output.iter() { ensure!( - output.value >= output.script_pubkey.dust_value().to_sat(), + output.value >= output.script_pubkey.minimal_non_dust(), "commit transaction output would be dust" ); } @@ -590,8 +590,8 @@ impl Plan { ) .expect("signature hash should compute"); - let sig = secp256k1.sign_schnorr( - &secp256k1::Message::from_slice(sighash.as_ref()) + let signature = secp256k1.sign_schnorr( + &secp256k1::Message::from_digest_slice(sighash.as_ref()) .expect("should be cryptographically secure hash"), &key_pair, ); @@ -602,8 +602,8 @@ impl Plan { witness.push( Signature { - sig, - hash_ty: TapSighashType::Default, + signature, + sighash_type: TapSighashType::Default, } .to_vec(), ); @@ -655,7 +655,7 @@ impl Plan { let rune = rune.map(|(destination, rune, vout)| RuneInfo { destination: destination.map(|destination| uncheck(&destination)), location: vout.map(|vout| OutPoint { - txid: reveal_tx.txid(), + txid: reveal_tx.compute_txid(), vout, }), rune, @@ -671,7 +671,7 @@ impl Plan { }) } - fn backup_recovery_key(wallet: &Wallet, recovery_key_pair: TweakedKeyPair) -> Result { + fn backup_recovery_key(wallet: &Wallet, recovery_key_pair: TweakedKeypair) -> Result { let recovery_private_key = PrivateKey::new( recovery_key_pair.to_inner().secret_key(), wallet.chain().network(), @@ -684,7 +684,11 @@ impl Plan { let response = wallet .bitcoin_client() .import_descriptors(ImportDescriptors { - descriptor: format!("rawtr({})#{}", recovery_private_key.to_wif(), info.checksum), + descriptor: format!( + "rawtr({})#{}", + recovery_private_key.to_wif(), + info.checksum.unwrap_or_default() + ), timestamp: Timestamp::Now, active: Some(false), range: None, @@ -727,7 +731,7 @@ impl Plan { .collect(), output, lock_time: LockTime::ZERO, - version: 2, + version: Version(2), }; let fee = { @@ -758,8 +762,9 @@ impl Plan { tx.input .iter() .map(|txin| utxos.get(&txin.previous_output).unwrap().value) - .sum::() - .checked_sub(tx.output.iter().map(|txout| txout.value).sum::()) + .sum::() + .checked_sub(tx.output.iter().map(|txout| txout.value).sum::()) .unwrap() + .to_sat() } } diff --git a/src/wallet/batch/transactions.rs b/src/wallet/batch/transactions.rs index 28e3a1628f..b54129c4ca 100644 --- a/src/wallet/batch/transactions.rs +++ b/src/wallet/batch/transactions.rs @@ -5,7 +5,7 @@ pub(crate) struct Transactions { pub(crate) rune: Option, pub(crate) commit_tx: Transaction, pub(crate) commit_vout: usize, - pub(crate) recovery_key_pair: TweakedKeyPair, + pub(crate) recovery_key_pair: TweakedKeypair, pub(crate) reveal_tx: Transaction, pub(crate) total_fees: u64, } diff --git a/src/wallet/entry.rs b/src/wallet/entry.rs index 223c9302df..98599937e3 100644 --- a/src/wallet/entry.rs +++ b/src/wallet/entry.rs @@ -43,7 +43,7 @@ mod tests { #[test] fn etching_entry() { let commit = Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![TxIn { previous_output: OutPoint::null(), @@ -55,7 +55,7 @@ mod tests { }; let reveal = Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![TxIn { previous_output: OutPoint::null(), diff --git a/src/wallet/transaction_builder.rs b/src/wallet/transaction_builder.rs index 2e0dbe3780..eb411c1df0 100644 --- a/src/wallet/transaction_builder.rs +++ b/src/wallet/transaction_builder.rs @@ -43,7 +43,7 @@ pub enum Error { output_value: Amount, dust_value: Amount, }, - InvalidAddress(bitcoin::address::Error), + InvalidAddress(bitcoin::address::FromScriptError), NotEnoughCardinalUtxos, NotInWallet(SatPoint), OutOfRange(SatPoint, u64), @@ -93,8 +93,8 @@ impl Display for Error { impl std::error::Error for Error {} -impl From for Error { - fn from(source: bitcoin::address::Error) -> Self { +impl From for Error { + fn from(source: bitcoin::address::FromScriptError) -> Self { Self::InvalidAddress(source) } } @@ -120,7 +120,7 @@ pub struct TransactionBuilder { type Result = std::result::Result; impl TransactionBuilder { - const ADDITIONAL_INPUT_VBYTES: usize = 58; + const ADDITIONAL_INPUT_VBYTES: usize = 57; const ADDITIONAL_OUTPUT_VBYTES: usize = 43; const SCHNORR_SIGNATURE_SIZE: usize = 64; pub(crate) const MAX_POSTAGE: Amount = Amount::from_sat(2 * 10_000); @@ -170,7 +170,7 @@ impl TransactionBuilder { } if let Target::Value(output_value) | Target::ExactPostage(output_value) = self.target { - let dust_value = self.recipient.dust_value(); + let dust_value = self.recipient.minimal_non_dust(); if output_value < dust_value { return Err(Error::Dust { @@ -197,7 +197,7 @@ impl TransactionBuilder { .last() .unwrap() .script_pubkey() - .dust_value() + .minimal_non_dust() .to_sat(); for (inscribed_satpoint, inscription_ids) in self.inscriptions.iter().rev() { @@ -217,7 +217,8 @@ impl TransactionBuilder { .amounts .get(&self.outgoing.outpoint) .ok_or(Error::NotInWallet(self.outgoing))? - .value; + .value + .to_sat(); if self.outgoing.offset >= amount { return Err(Error::OutOfRange(self.outgoing, amount - 1)); @@ -227,7 +228,7 @@ impl TransactionBuilder { self.inputs.push(self.outgoing.outpoint); self.outputs.push(TxOut { script_pubkey: self.recipient.clone(), - value: amount, + value: Amount::from_sat(amount), }); tprintln!( @@ -261,10 +262,10 @@ impl TransactionBuilder { .pop() .unwrap_or_else(|| panic!("not enough change addresses")) .script_pubkey(), - value: sat_offset, + value: Amount::from_sat(sat_offset), }, ); - self.outputs.last_mut().expect("no output").value -= sat_offset; + self.outputs.last_mut().expect("no output").value -= Amount::from_sat(sat_offset); } self @@ -279,17 +280,17 @@ impl TransactionBuilder { .last() .unwrap() .script_pubkey() - .dust_value() - .to_sat(); + .minimal_non_dust(); if self.outputs[0].value >= dust_limit { tprintln!("no padding needed"); } else { while self.outputs[0].value < dust_limit { - let (utxo, size) = self.select_cardinal_utxo(dust_limit - self.outputs[0].value, true)?; + let (utxo, size) = + self.select_cardinal_utxo((dust_limit - self.outputs[0].value).to_sat(), true)?; self.inputs.insert(0, utxo); - self.outputs[0].value += size.to_sat(); + self.outputs[0].value += size; tprintln!( "padded alignment output to {} with additional {size} sat input", @@ -306,7 +307,12 @@ impl TransactionBuilder { let estimated_fee = self.estimate_fee(); let min_value = match self.target { - Target::Postage => self.outputs.last().unwrap().script_pubkey.dust_value(), + Target::Postage => self + .outputs + .last() + .unwrap() + .script_pubkey + .minimal_non_dust(), Target::Value(value) | Target::ExactPostage(value) => value, }; @@ -314,9 +320,7 @@ impl TransactionBuilder { .checked_add(estimated_fee) .ok_or(Error::ValueOverflow)?; - if let Some(mut deficit) = - total.checked_sub(Amount::from_sat(self.outputs.last().unwrap().value)) - { + if let Some(mut deficit) = total.checked_sub(self.outputs.last().unwrap().value) { while deficit > Amount::ZERO { let additional_fee = self.fee_rate.fee(Self::ADDITIONAL_INPUT_VBYTES); @@ -332,7 +336,7 @@ impl TransactionBuilder { self.inputs.push(utxo); - self.outputs.last_mut().unwrap().value += value.to_sat(); + self.outputs.last_mut().unwrap().value += value; if benefit > deficit { tprintln!("added {value} sat input to cover {deficit} sat deficit"); @@ -353,7 +357,7 @@ impl TransactionBuilder { let total_output_amount = self .outputs .iter() - .map(|tx_out| Amount::from_sat(tx_out.value)) + .map(|tx_out| tx_out.value) .sum::(); self @@ -378,20 +382,20 @@ impl TransactionBuilder { .last() .unwrap() .script_pubkey() - .dust_value() + .minimal_non_dust() + self .fee_rate .fee(self.estimate_vbytes() + Self::ADDITIONAL_OUTPUT_VBYTES) { tprintln!("stripped {} sats", (value - target).to_sat()); - self.outputs.last_mut().expect("no outputs found").value = target.to_sat(); + self.outputs.last_mut().expect("no outputs found").value = target; self.outputs.push(TxOut { script_pubkey: self .unused_change_addresses .pop() .unwrap_or_else(|| panic!("not enough change addresses")) .script_pubkey(), - value: (value - target).to_sat(), + value: value - target, }); } } @@ -407,7 +411,7 @@ impl TransactionBuilder { let total_output_amount = self .outputs .iter() - .map(|tx_out| Amount::from_sat(tx_out.value)) + .map(|tx_out| tx_out.value) .sum::(); let last_tx_out = self @@ -421,13 +425,13 @@ impl TransactionBuilder { ); assert!( - last_tx_out.value >= fee.to_sat(), + last_tx_out.value >= fee, "invariant: last output can pay fee: {} {}", last_tx_out.value, fee, ); - last_tx_out.value -= fee.to_sat(); + last_tx_out.value -= fee; self } @@ -442,7 +446,7 @@ impl TransactionBuilder { fn estimate_vbytes_with(inputs: usize, outputs: &[TxOut]) -> usize { Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: (0..inputs) .map(|_| TxIn { @@ -463,7 +467,7 @@ impl TransactionBuilder { fn build(self) -> Result { let transaction = Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: self .inputs @@ -483,7 +487,7 @@ impl TransactionBuilder { .amounts .iter() .filter(|(outpoint, txout)| *outpoint == &self.outgoing.outpoint - && self.outgoing.offset < txout.value) + && self.outgoing.offset < txout.value.to_sat()) .count(), 1, "invariant: outgoing sat is contained in utxos" @@ -507,7 +511,7 @@ impl TransactionBuilder { found = true; break; } else { - sat_offset += self.amounts[&tx_in.previous_output].value; + sat_offset += self.amounts[&tx_in.previous_output].value.to_sat(); } } assert!(found, "invariant: outgoing sat is found in inputs"); @@ -515,7 +519,7 @@ impl TransactionBuilder { let mut output_end = 0; let mut found = false; for tx_out in &transaction.output { - output_end += tx_out.value; + output_end += tx_out.value.to_sat(); if output_end > sat_offset { assert_eq!( tx_out.script_pubkey, self.recipient, @@ -558,23 +562,23 @@ impl TransactionBuilder { match self.target { Target::Postage => { assert!( - Amount::from_sat(output.value) <= Self::MAX_POSTAGE + slop, + output.value <= Self::MAX_POSTAGE + slop, "invariant: excess postage is stripped" ); } Target::ExactPostage(postage) => { assert!( - Amount::from_sat(output.value) <= postage + slop, + output.value <= postage + slop, "invariant: excess postage is stripped" ); } Target::Value(value) => { assert!( - Amount::from_sat(output.value).checked_sub(value).unwrap() + output.value.checked_sub(value).unwrap() <= self .change_addresses .iter() - .map(|address| address.script_pubkey().dust_value()) + .map(|address| address.script_pubkey().minimal_non_dust()) .max() .unwrap_or_default() + slop, @@ -596,15 +600,15 @@ impl TransactionBuilder { output.script_pubkey ); } - offset += output.value; + offset += output.value.to_sat(); } let mut actual_fee = Amount::ZERO; for input in &transaction.input { - actual_fee += Amount::from_sat(self.amounts[&input.previous_output].value); + actual_fee += self.amounts[&input.previous_output].value; } for output in &transaction.output { - actual_fee -= Amount::from_sat(output.value); + actual_fee -= output.value; } let mut modified_tx = transaction.clone(); @@ -620,7 +624,7 @@ impl TransactionBuilder { for tx_out in &transaction.output { assert!( - Amount::from_sat(tx_out.value) >= tx_out.script_pubkey.dust_value(), + tx_out.value >= tx_out.script_pubkey.minimal_non_dust(), "invariant: all outputs are above dust limit", ); } @@ -634,7 +638,7 @@ impl TransactionBuilder { if *outpoint == self.outgoing.outpoint { return sat_offset + self.outgoing.offset; } else { - sat_offset += self.amounts[outpoint].value; + sat_offset += self.amounts[outpoint].value.to_sat(); } } @@ -671,7 +675,7 @@ impl TransactionBuilder { continue; } - let current_value = self.amounts[utxo].value; + let current_value = self.amounts[utxo].value.to_sat(); let (_, best_value) = match best_match { Some(prev) => prev, @@ -753,7 +757,7 @@ mod tests { tx_builder.outputs, [TxOut { script_pubkey: recipient(), - value: 100 * COIN_VALUE - 51 * COIN_VALUE + value: Amount::from_sat(100 * COIN_VALUE - 51 * COIN_VALUE) }] ) } @@ -780,15 +784,15 @@ mod tests { outputs: vec![ TxOut { script_pubkey: recipient(), - value: 5_000, + value: Amount::from_sat(5_000), }, TxOut { script_pubkey: change(0).script_pubkey(), - value: 5_000, + value: Amount::from_sat(5_000), }, TxOut { script_pubkey: change(1).script_pubkey(), - value: 1_724, + value: Amount::from_sat(1_724), }, ], target: Target::Postage, @@ -798,7 +802,7 @@ mod tests { pretty_assert_eq!( tx_builder.build(), Ok(Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![tx_in(outpoint(1)), tx_in(outpoint(2)), tx_in(outpoint(3))], output: vec![ @@ -850,7 +854,7 @@ mod tests { ) .build_transaction(), Ok(Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![tx_in(outpoint(1))], output: vec![tx_out(4901, recipient_address())], @@ -904,7 +908,7 @@ mod tests { ) .build_transaction(), Ok(Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![tx_in(outpoint(1)), tx_in(outpoint(2))], output: vec![tx_out(4_950, change(1)), tx_out(4_862, recipient_address())], @@ -981,7 +985,7 @@ mod tests { ) .build_transaction(), Ok(Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![tx_in(outpoint(1)), tx_in(outpoint(2))], output: vec![ @@ -1105,7 +1109,7 @@ mod tests { .select_outgoing() .unwrap(); - builder.outputs[0].value = 0; + builder.outputs[0].value = Amount::from_sat(0); builder.build().unwrap(); } @@ -1129,7 +1133,7 @@ mod tests { ) .build_transaction(), Ok(Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![tx_in(outpoint(1))], output: vec![ @@ -1182,7 +1186,7 @@ mod tests { ) .build_transaction(), Ok(Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![tx_in(outpoint(1))], output: vec![tx_out(3_333, change(1)), tx_out(6_537, recipient_address())], @@ -1212,7 +1216,7 @@ mod tests { ) .build_transaction(), Ok(Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![tx_in(outpoint(2)), tx_in(outpoint(1))], output: vec![ @@ -1353,15 +1357,15 @@ mod tests { outputs: vec![ TxOut { script_pubkey: recipient(), - value: 5_000, + value: Amount::from_sat(5_000), }, TxOut { script_pubkey: recipient(), - value: 5_000, + value: Amount::from_sat(5_000), }, TxOut { script_pubkey: change(1).script_pubkey(), - value: 1_774, + value: Amount::from_sat(1_774), }, ], target: Target::Postage, @@ -1394,15 +1398,15 @@ mod tests { outputs: vec![ TxOut { script_pubkey: recipient(), - value: 5_000, + value: Amount::from_sat(5_000), }, TxOut { script_pubkey: change(0).script_pubkey(), - value: 5_000, + value: Amount::from_sat(5_000), }, TxOut { script_pubkey: change(0).script_pubkey(), - value: 1_774, + value: Amount::from_sat(1_774), }, ], target: Target::Postage, @@ -1515,7 +1519,7 @@ mod tests { pretty_assert_eq!( transaction, Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![tx_in(outpoint(1))], output: vec![tx_out(10_000 - fee.to_sat(), recipient_address())], @@ -1542,7 +1546,7 @@ mod tests { ) .build_transaction(), Ok(Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![tx_in(outpoint(1))], output: vec![tx_out(1000, recipient_address()), tx_out(3870, change(1))], @@ -1572,7 +1576,7 @@ mod tests { ) .build_transaction(), Ok(Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![tx_in(outpoint(1)), tx_in(outpoint(2))], output: vec![tx_out(1500, recipient_address()), tx_out(312, change(1))], @@ -1673,7 +1677,7 @@ mod tests { .unwrap() .assume_checked() .script_pubkey(), - value: 0, + value: Amount::from_sat(0), }], ); assert_eq!(after - before, TransactionBuilder::ADDITIONAL_OUTPUT_VBYTES); @@ -1698,7 +1702,7 @@ mod tests { ) .build_transaction(), Ok(Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![tx_in(outpoint(1))], output: vec![tx_out(901, recipient_address())], @@ -1725,7 +1729,7 @@ mod tests { ) .build_transaction(), Ok(Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![tx_in(outpoint(1))], output: vec![tx_out(20_000, recipient_address())], @@ -1752,7 +1756,7 @@ mod tests { ) .build_transaction(), Ok(Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![tx_in(outpoint(1))], output: vec![tx_out(1005, recipient_address())], @@ -1845,7 +1849,7 @@ mod tests { ) .build_transaction(), Ok(Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![tx_in(outpoint(1))], output: vec![tx_out(1802, recipient_address())], @@ -1872,7 +1876,7 @@ mod tests { ) .build_transaction(), Ok(Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![tx_in(outpoint(1))], output: vec![tx_out(20250, recipient_address())], @@ -1924,7 +1928,7 @@ mod tests { tx_builder.outputs, [TxOut { script_pubkey: recipient(), - value: 3_003 + 3_006 + 3_005 + 3_001 + value: Amount::from_sat(3_003 + 3_006 + 3_005 + 3_001) }] ) } @@ -1976,11 +1980,11 @@ mod tests { [ TxOut { script_pubkey: change(1).script_pubkey(), - value: 101 + 104 + 105 + 1 + value: Amount::from_sat(101 + 104 + 105 + 1) }, TxOut { script_pubkey: recipient(), - value: 19_999 + value: Amount::from_sat(19_999) } ] ) @@ -2079,7 +2083,7 @@ mod tests { pretty_assert_eq!( transaction, Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![tx_in(outpoint(1))], output: vec![ diff --git a/src/wallet/wallet_constructor.rs b/src/wallet/wallet_constructor.rs index fb75db0dff..b9faf1b0bc 100644 --- a/src/wallet/wallet_constructor.rs +++ b/src/wallet/wallet_constructor.rs @@ -175,7 +175,7 @@ impl WalletConstructor { let outpoint = OutPoint::new(utxo.txid, utxo.vout); let txout = TxOut { script_pubkey: utxo.script_pub_key, - value: utxo.amount.to_sat(), + value: utxo.amount, }; (outpoint, txout) @@ -204,7 +204,7 @@ impl WalletConstructor { utxos.insert( OutPoint::new(outpoint.txid, outpoint.vout), TxOut { - value: tx_out.value.to_sat(), + value: tx_out.value, script_pubkey: ScriptBuf::from_bytes(tx_out.script_pub_key.hex), }, ); diff --git a/templates/block.html b/templates/block.html index bf33f2561e..763eac103e 100644 --- a/templates/block.html +++ b/templates/block.html @@ -3,7 +3,7 @@

Block {{ self.height }}

hash
{{self.hash}}
target
{{self.target}}
timestamp
-
size
{{self.block.size()}}
+
size
{{self.block.total_size()}}
weight
{{self.block.weight()}}
%% if self.height.0 > 0 {
previous blockhash
{{self.block.header.prev_blockhash}}
diff --git a/templates/inscription.html b/templates/inscription.html index 30364314c6..cbf3c5e646 100644 --- a/templates/inscription.html +++ b/templates/inscription.html @@ -67,7 +67,7 @@

Inscription {{ self.number }}

{{ address }}
%% }
value
-
{{ output.value }}
+
{{ output.value.to_sat() }}
%% } %% if let Some(sat) = self.sat {
sat
diff --git a/templates/output.html b/templates/output.html index ffbdde4a37..74ce3f6102 100644 --- a/templates/output.html +++ b/templates/output.html @@ -25,7 +25,7 @@

Output {{self.outpoint}}

%% } -
value
{{ self.output.value }}
+
value
{{ self.output.value.to_sat() }}
script pubkey
{{ self.output.script_pubkey.to_asm_string() }}
%% if let Ok(address) = self.chain.address_from_script(&self.output.script_pubkey ) {
address
{{ address }}
diff --git a/templates/transaction.html b/templates/transaction.html index 1818cd939d..d855246fcb 100644 --- a/templates/transaction.html +++ b/templates/transaction.html @@ -28,7 +28,7 @@

{{"Output".tally(self.transaction.output.len())}}

{{ outpoint }}
-
value
{{ output.value }}
+
value
{{ output.value.to_sat() }}
script pubkey
{{ output.script_pubkey.to_asm_string() }}
%% if let Ok(address) = self.chain.address_from_script(&output.script_pubkey) {
address
{{ address }}
diff --git a/tests/decode.rs b/tests/decode.rs index 20f87c7936..bcc900d036 100644 --- a/tests/decode.rs +++ b/tests/decode.rs @@ -1,8 +1,8 @@ use { super::*, bitcoin::{ - absolute::LockTime, consensus::Encodable, opcodes, script, ScriptBuf, Sequence, Transaction, - TxIn, TxOut, Witness, + absolute::LockTime, consensus::Encodable, opcodes, script, transaction::Version, ScriptBuf, + Sequence, Transaction, TxIn, TxOut, Witness, }, ord::{ subcommand::decode::{CompactInscription, CompactOutput, RawOutput}, @@ -28,7 +28,7 @@ fn transaction() -> Vec { witness.push([]); let transaction = Transaction { - version: 2, + version: Version(2), lock_time: LockTime::ZERO, input: vec![TxIn { previous_output: OutPoint::null(), @@ -38,7 +38,7 @@ fn transaction() -> Vec { }], output: vec![TxOut { script_pubkey: Runestone::default().encipher(), - value: 0, + value: Amount::from_sat(0), }], }; diff --git a/tests/json_api.rs b/tests/json_api.rs index 928cd20d4d..8047033127 100644 --- a/tests/json_api.rs +++ b/tests/json_api.rs @@ -88,7 +88,7 @@ fn get_sat_with_inscription_on_common_sat_and_more_inscriptions() { inscribe(&core, &ord); - let txid = core.mine_blocks(1)[0].txdata[0].txid(); + let txid = core.mine_blocks(1)[0].txdata[0].compute_txid(); let Batch { reveal, .. } = CommandBuilder::new(format!( "wallet inscribe --satpoint {}:0:1 --fee-rate 1 --file foo.txt", @@ -445,7 +445,7 @@ fn get_transaction() { let transaction = core.mine_blocks(1)[0].txdata[0].clone(); - let txid = transaction.txid(); + let txid = transaction.compute_txid(); let response = ord.json_request(format!("/tx/{txid}")); diff --git a/tests/lib.rs b/tests/lib.rs index 12e2c620fb..9415443adf 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -4,8 +4,7 @@ use { self::{command_builder::CommandBuilder, expected::Expected, test_server::TestServer}, bitcoin::{ address::{Address, NetworkUnchecked}, - blockdata::constants::COIN_VALUE, - Network, OutPoint, Sequence, Txid, Witness, + Amount, Network, OutPoint, Sequence, Txid, Witness, }, chrono::{DateTime, Utc}, executable_path::executable_path, @@ -16,6 +15,7 @@ use { }, ordinals::{ Artifact, Charm, Edict, Pile, Rarity, Rune, RuneId, Runestone, Sat, SatPoint, SpacedRune, + COIN_VALUE, }, pretty_assertions::assert_eq as pretty_assert_eq, regex::Regex, diff --git a/tests/server.rs b/tests/server.rs index 8a0a86567a..d92e8104d8 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -675,7 +675,7 @@ fn inscription_transactions_are_stored_with_transaction_index() { let (_inscription, reveal) = inscribe(&core, &ord); - let coinbase = core.tx(1, 0).txid(); + let coinbase = core.tx(1, 0).compute_txid(); assert_eq!( ord.request(format!("/tx/{reveal}")).status(), diff --git a/tests/wallet/batch_command.rs b/tests/wallet/batch_command.rs index 4da3159e89..34c9ac0df7 100644 --- a/tests/wallet/batch_command.rs +++ b/tests/wallet/batch_command.rs @@ -608,7 +608,7 @@ fn batch_inscribe_fails_if_invalid_network_destination_address() { .write("batch.yaml", "mode: separate-outputs\ninscriptions:\n- file: inscription.txt\n destination: bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4") .core(&core) .ord(&ord) - .stderr_regex("error: address bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 belongs to network bitcoin which is different from required regtest\n") + .stderr_regex("error: validation error\n\nbecause:\n- address bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 is not valid on regtest\n") .expected_exit_code(1) .run_and_extract_stdout(); } @@ -995,7 +995,7 @@ fn batch_inscribe_with_satpoint() { create_wallet(&core, &ord); - let txid = core.mine_blocks(1)[0].txdata[0].txid(); + let txid = core.mine_blocks(1)[0].txdata[0].compute_txid(); let output = CommandBuilder::new("wallet batch --fee-rate 1 --batch batch.yaml") .write("inscription.txt", "Hello World") @@ -1045,28 +1045,25 @@ fn batch_inscribe_with_fee_rate() { .run_and_deserialize_output::(); let commit_tx = &core.mempool()[0]; - let mut fee = 0; + let mut fee = Amount::ZERO; for input in &commit_tx.input { - fee += core - .get_utxo_amount(&input.previous_output) - .unwrap() - .to_sat(); + fee += core.get_utxo_amount(&input.previous_output).unwrap(); } for output in &commit_tx.output { fee -= output.value; } - let fee_rate = fee as f64 / commit_tx.vsize() as f64; + let fee_rate = fee.to_sat() as f64 / commit_tx.vsize() as f64; pretty_assert_eq!(fee_rate, set_fee_rate); let reveal_tx = &core.mempool()[1]; - let mut fee = 0; + let mut fee = Amount::ZERO; for input in &reveal_tx.input { - fee += &commit_tx.output[input.previous_output.vout as usize].value; + fee += commit_tx.output[input.previous_output.vout as usize].value; } for output in &reveal_tx.output { fee -= output.value; } - let fee_rate = fee as f64 / reveal_tx.vsize() as f64; + let fee_rate = fee.to_sat() as f64 / reveal_tx.vsize() as f64; pretty_assert_eq!(fee_rate, set_fee_rate); assert_eq!( @@ -1168,7 +1165,7 @@ fn batch_inscribe_with_satpoints_with_parent() { let txids = core .mine_blocks(3) .iter() - .map(|block| block.txdata[0].txid()) + .map(|block| block.txdata[0].compute_txid()) .collect::>(); let satpoint_1 = SatPoint { diff --git a/tests/wallet/burn.rs b/tests/wallet/burn.rs index 9824eb2372..140a27dc21 100644 --- a/tests/wallet/burn.rs +++ b/tests/wallet/burn.rs @@ -20,7 +20,7 @@ fn inscriptions_can_be_burned() { .stdout_regex(r".*") .run_and_deserialize_output::(); - let txid = core.mempool()[0].txid(); + let txid = core.mempool()[0].compute_txid(); assert_eq!(txid, output.txid); core.mine_blocks(1); @@ -128,7 +128,7 @@ fn cannot_burn_inscriptions_on_large_utxos() { CommandBuilder::new(format!("wallet burn --fee-rate 1 {inscription}",)) .core(&core) .ord(&ord) - .expected_stderr("error: Cannot burn inscription contained in UTXO exceeding 0.0001 BTC\n") + .expected_stderr("error: Cannot burn inscription contained in UTXO exceeding 0.00010000 BTC\n") .expected_exit_code(1) .run_and_extract_stdout(); } @@ -208,7 +208,7 @@ fn cannot_burn_with_excess_postage() { )) .core(&core) .ord(&ord) - .expected_stderr("error: Postage may not exceed 0.0001 BTC\n") + .expected_stderr("error: Postage may not exceed 0.00010000 BTC\n") .expected_exit_code(1) .run_and_extract_stdout(); } diff --git a/tests/wallet/inscribe.rs b/tests/wallet/inscribe.rs index b65af8fc69..d4adccfddd 100644 --- a/tests/wallet/inscribe.rs +++ b/tests/wallet/inscribe.rs @@ -36,7 +36,7 @@ fn inscribe_works_with_huge_expensive_inscriptions() { create_wallet(&core, &ord); - let txid = core.mine_blocks(1)[0].txdata[0].txid(); + let txid = core.mine_blocks(1)[0].txdata[0].compute_txid(); CommandBuilder::new(format!( "wallet inscribe --file foo.txt --satpoint {txid}:0:0 --fee-rate 10" @@ -54,7 +54,7 @@ fn metaprotocol_appears_on_inscription_page() { create_wallet(&core, &ord); - let txid = core.mine_blocks(1)[0].txdata[0].txid(); + let txid = core.mine_blocks(1)[0].txdata[0].compute_txid(); let inscribe = CommandBuilder::new(format!( "wallet inscribe --file foo.txt --metaprotocol foo --satpoint {txid}:0:0 --fee-rate 10" @@ -257,7 +257,7 @@ fn inscribe_with_optional_satpoint_arg() { create_wallet(&core, &ord); - let txid = core.mine_blocks(1)[0].txdata[0].txid(); + let txid = core.mine_blocks(1)[0].txdata[0].compute_txid(); let Batch { inscriptions, .. } = CommandBuilder::new(format!( "wallet inscribe --file foo.txt --satpoint {txid}:0:10000 --fee-rate 1" @@ -301,31 +301,28 @@ fn inscribe_with_fee_rate() { .run_and_deserialize_output::(); let tx1 = &core.mempool()[0]; - let mut fee = 0; + let mut fee = Amount::ZERO; for input in &tx1.input { - fee += core - .get_utxo_amount(&input.previous_output) - .unwrap() - .to_sat(); + fee += core.get_utxo_amount(&input.previous_output).unwrap(); } for output in &tx1.output { fee -= output.value; } - let fee_rate = fee as f64 / tx1.vsize() as f64; + let fee_rate = fee.to_sat() as f64 / tx1.vsize() as f64; pretty_assert_eq!(fee_rate, 2.0); let tx2 = &core.mempool()[1]; - let mut fee = 0; + let mut fee = Amount::ZERO; for input in &tx2.input { - fee += &tx1.output[input.previous_output.vout as usize].value; + fee += tx1.output[input.previous_output.vout as usize].value; } for output in &tx2.output { fee -= output.value; } - let fee_rate = fee as f64 / tx2.vsize() as f64; + let fee_rate = fee.to_sat() as f64 / tx2.vsize() as f64; pretty_assert_eq!(fee_rate, 2.0); assert_eq!( @@ -355,31 +352,28 @@ fn inscribe_with_commit_fee_rate() { .run_and_deserialize_output::(); let tx1 = &core.mempool()[0]; - let mut fee = 0; + let mut fee = Amount::ZERO; for input in &tx1.input { - fee += core - .get_utxo_amount(&input.previous_output) - .unwrap() - .to_sat(); + fee += core.get_utxo_amount(&input.previous_output).unwrap(); } for output in &tx1.output { fee -= output.value; } - let fee_rate = fee as f64 / tx1.vsize() as f64; + let fee_rate = fee.to_sat() as f64 / tx1.vsize() as f64; pretty_assert_eq!(fee_rate, 2.0); let tx2 = &core.mempool()[1]; - let mut fee = 0; + let mut fee = Amount::ZERO; for input in &tx2.input { - fee += &tx1.output[input.previous_output.vout as usize].value; + fee += tx1.output[input.previous_output.vout as usize].value; } for output in &tx2.output { fee -= output.value; } - let fee_rate = fee as f64 / tx2.vsize() as f64; + let fee_rate = fee.to_sat() as f64 / tx2.vsize() as f64; pretty_assert_eq!(fee_rate, 1.0); } @@ -492,10 +486,10 @@ fn inscribe_to_specific_destination() { .reveal; let reveal_tx = &core.mempool()[1]; // item 0 is the commit, item 1 is the reveal. - assert_eq!(reveal_tx.txid(), txid); + assert_eq!(reveal_tx.compute_txid(), txid); assert_eq!( reveal_tx.output.first().unwrap().script_pubkey, - destination.payload.script_pubkey() + destination.assume_checked_ref().script_pubkey() ); } @@ -515,7 +509,7 @@ fn inscribe_to_address_on_different_network() { .core(&core) .ord(&ord) .expected_exit_code(1) - .stderr_regex("error: address tb1qsgx55dp6gn53tsmyjjv4c2ye403hgxynxs0dnm belongs to network testnet which is different from required bitcoin\n") + .stderr_regex("error: validation error\n\nbecause:\n- address tb1qsgx55dp6gn53tsmyjjv4c2ye403hgxynxs0dnm is not valid on bitcoin\n") .run_and_extract_stdout(); } @@ -674,7 +668,7 @@ fn reinscribe_with_flag() { assert_eq!(core.descriptors().len(), 3); - let txid = core.mine_blocks(1)[0].txdata[2].txid(); + let txid = core.mine_blocks(1)[0].txdata[2].compute_txid(); let request = ord.request(format!("/content/{}", inscribe.inscriptions[0].id)); @@ -726,7 +720,7 @@ fn with_reinscribe_flag_but_not_actually_a_reinscription() { .ord(&ord) .run_and_deserialize_output::(); - let coinbase = core.mine_blocks(1)[0].txdata[0].txid(); + let coinbase = core.mine_blocks(1)[0].txdata[0].compute_txid(); CommandBuilder::new(format!( "wallet inscribe --file orchid.png --fee-rate 1.1 --reinscribe --satpoint {coinbase}:0:0" @@ -910,7 +904,7 @@ fn inscribe_does_not_pick_locked_utxos() { create_wallet(&core, &ord); let coinbase_tx = &core.mine_blocks(1)[0].txdata[0]; - let outpoint = OutPoint::new(coinbase_tx.txid(), 0); + let outpoint = OutPoint::new(coinbase_tx.compute_txid(), 0); core.lock(outpoint); diff --git a/tests/wallet/mint.rs b/tests/wallet/mint.rs index b3541613cd..1efbae6ac9 100644 --- a/tests/wallet/mint.rs +++ b/tests/wallet/mint.rs @@ -329,7 +329,7 @@ fn minting_rune_with_destination() { assert_eq!( core.mempool()[0].output[1].script_pubkey, - destination.payload.script_pubkey() + destination.assume_checked_ref().script_pubkey() ); core.mine_blocks(1); diff --git a/tests/wallet/outputs.rs b/tests/wallet/outputs.rs index f61aa2d2ea..57646e9a0f 100644 --- a/tests/wallet/outputs.rs +++ b/tests/wallet/outputs.rs @@ -9,7 +9,7 @@ fn outputs() { create_wallet(&core, &ord); let coinbase_tx = &core.mine_blocks_with_subsidy(1, 1_000_000)[0].txdata[0]; - let outpoint = OutPoint::new(coinbase_tx.txid(), 0); + let outpoint = OutPoint::new(coinbase_tx.compute_txid(), 0); let amount = coinbase_tx.output[0].value; let output = CommandBuilder::new("wallet outputs") @@ -18,7 +18,7 @@ fn outputs() { .run_and_deserialize_output::>(); assert_eq!(output[0].output, outpoint); - assert_eq!(output[0].amount, amount); + assert_eq!(output[0].amount, amount.to_sat()); assert!(output[0].sat_ranges.is_none()); } @@ -31,7 +31,7 @@ fn outputs_includes_locked_outputs() { create_wallet(&core, &ord); let coinbase_tx = &core.mine_blocks_with_subsidy(1, 1_000_000)[0].txdata[0]; - let outpoint = OutPoint::new(coinbase_tx.txid(), 0); + let outpoint = OutPoint::new(coinbase_tx.compute_txid(), 0); let amount = coinbase_tx.output[0].value; core.lock(outpoint); @@ -42,7 +42,7 @@ fn outputs_includes_locked_outputs() { .run_and_deserialize_output::>(); assert_eq!(output[0].output, outpoint); - assert_eq!(output[0].amount, amount); + assert_eq!(output[0].amount, amount.to_sat()); assert!(output[0].sat_ranges.is_none()); } @@ -55,7 +55,7 @@ fn outputs_includes_unbound_outputs() { create_wallet(&core, &ord); let coinbase_tx = &core.mine_blocks_with_subsidy(1, 1_000_000)[0].txdata[0]; - let outpoint = OutPoint::new(coinbase_tx.txid(), 0); + let outpoint = OutPoint::new(coinbase_tx.compute_txid(), 0); let amount = coinbase_tx.output[0].value; core.lock(outpoint); @@ -66,7 +66,7 @@ fn outputs_includes_unbound_outputs() { .run_and_deserialize_output::>(); assert_eq!(output[0].output, outpoint); - assert_eq!(output[0].amount, amount); + assert_eq!(output[0].amount, amount.to_sat()); assert!(output[0].sat_ranges.is_none()); } @@ -79,7 +79,7 @@ fn outputs_includes_sat_ranges() { create_wallet(&core, &ord); let coinbase_tx = &core.mine_blocks_with_subsidy(1, 1_000_000)[0].txdata[0]; - let outpoint = OutPoint::new(coinbase_tx.txid(), 0); + let outpoint = OutPoint::new(coinbase_tx.compute_txid(), 0); let amount = coinbase_tx.output[0].value; let output = CommandBuilder::new("wallet outputs --ranges") @@ -88,7 +88,7 @@ fn outputs_includes_sat_ranges() { .run_and_deserialize_output::>(); assert_eq!(output[0].output, outpoint); - assert_eq!(output[0].amount, amount); + assert_eq!(output[0].amount, amount.to_sat()); assert_eq!( output[0].sat_ranges, Some(vec!["5000000000-5001000000".to_string()]) diff --git a/tests/wallet/resume.rs b/tests/wallet/resume.rs index 6d1b632f19..830ecaead3 100644 --- a/tests/wallet/resume.rs +++ b/tests/wallet/resume.rs @@ -248,7 +248,7 @@ fn commitment_output_is_locked() { "Waiting for rune AAAAAAAAAAAAA commitment [[:xdigit:]]{64} to mature…\n" ); - let commitment = core.mempool()[0].txid(); + let commitment = core.mempool()[0].compute_txid(); core.mine_blocks(1); diff --git a/tests/wallet/sats.rs b/tests/wallet/sats.rs index 71de77186f..a40fb617ef 100644 --- a/tests/wallet/sats.rs +++ b/tests/wallet/sats.rs @@ -27,7 +27,7 @@ fn sats() { create_wallet(&core, &ord); - let second_coinbase = core.mine_blocks(1)[0].txdata[0].txid(); + let second_coinbase = core.mine_blocks(1)[0].txdata[0].compute_txid(); let output = CommandBuilder::new("--index-sats wallet sats") .core(&core) @@ -46,7 +46,7 @@ fn sats_from_tsv_success() { create_wallet(&core, &ord); - let second_coinbase = core.mine_blocks(1)[0].txdata[0].txid(); + let second_coinbase = core.mine_blocks(1)[0].txdata[0].compute_txid(); let output = CommandBuilder::new("--index-sats wallet sats --tsv foo.tsv") .write("foo.tsv", "nvtcsezkbtg") @@ -103,7 +103,7 @@ fn sats_all() { create_wallet(&core, &ord); - let second_coinbase = core.mine_blocks(1)[0].txdata[0].txid(); + let second_coinbase = core.mine_blocks(1)[0].txdata[0].compute_txid(); let output = CommandBuilder::new("--index-sats wallet sats --all") .core(&core) diff --git a/tests/wallet/send.rs b/tests/wallet/send.rs index 49e1b228b9..630a08d0dd 100644 --- a/tests/wallet/send.rs +++ b/tests/wallet/send.rs @@ -22,7 +22,7 @@ fn inscriptions_can_be_sent() { .stdout_regex(r".*") .run_and_deserialize_output::(); - let txid = core.mempool()[0].txid(); + let txid = core.mempool()[0].compute_txid(); assert_eq!(txid, output.txid); core.mine_blocks(1); @@ -55,7 +55,7 @@ fn send_unknown_inscription() { create_wallet(&core, &ord); - let txid = core.mine_blocks(1)[0].txdata[0].txid(); + let txid = core.mine_blocks(1)[0].txdata[0].compute_txid(); CommandBuilder::new(format!( "wallet send --fee-rate 1 bc1qcqgs2pps4u4yedfyl5pysdjjncs8et5utseepv {txid}i0" @@ -164,7 +164,7 @@ fn send_on_mainnnet_works_with_wallet_named_foo() { let ord = TestServer::spawn_with_server_args(&core, &[], &[]); - let txid = core.mine_blocks(1)[0].txdata[0].txid(); + let txid = core.mine_blocks(1)[0].txdata[0].compute_txid(); CommandBuilder::new("wallet --name foo create") .core(&core) @@ -187,7 +187,7 @@ fn send_addresses_must_be_valid_for_network() { create_wallet(&core, &ord); - let txid = core.mine_blocks_with_subsidy(1, 1_000)[0].txdata[0].txid(); + let txid = core.mine_blocks_with_subsidy(1, 1_000)[0].txdata[0].compute_txid(); CommandBuilder::new(format!( "wallet send --fee-rate 1 tb1q6en7qjxgw4ev8xwx94pzdry6a6ky7wlfeqzunz {txid}:0:0" @@ -195,7 +195,7 @@ fn send_addresses_must_be_valid_for_network() { .core(&core) .ord(&ord) .expected_stderr( - "error: address tb1q6en7qjxgw4ev8xwx94pzdry6a6ky7wlfeqzunz belongs to network testnet which is different from required bitcoin\n", + "error: validation error\n\nbecause:\n- address tb1q6en7qjxgw4ev8xwx94pzdry6a6ky7wlfeqzunz is not valid on bitcoin\n", ) .expected_exit_code(1) .run_and_extract_stdout(); @@ -209,7 +209,7 @@ fn send_on_mainnnet_works_with_wallet_named_ord() { create_wallet(&core, &ord); - let txid = core.mine_blocks_with_subsidy(1, 1_000_000)[0].txdata[0].txid(); + let txid = core.mine_blocks_with_subsidy(1, 1_000_000)[0].txdata[0].compute_txid(); let output = CommandBuilder::new(format!( "wallet send --fee-rate 1 bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 {txid}:0:0" @@ -218,7 +218,7 @@ fn send_on_mainnnet_works_with_wallet_named_ord() { .ord(&ord) .run_and_deserialize_output::(); - assert_eq!(core.mempool()[0].txid(), output.txid); + assert_eq!(core.mempool()[0].compute_txid(), output.txid); } #[test] @@ -229,7 +229,7 @@ fn send_does_not_use_inscribed_sats_as_cardinal_utxos() { create_wallet(&core, &ord); - let txid = core.mine_blocks_with_subsidy(1, 10_000)[0].txdata[0].txid(); + let txid = core.mine_blocks_with_subsidy(1, 10_000)[0].txdata[0].compute_txid(); CommandBuilder::new(format!( "wallet inscribe --satpoint {txid}:0:0 --file degenerate.png --fee-rate 0" )) @@ -238,7 +238,7 @@ fn send_does_not_use_inscribed_sats_as_cardinal_utxos() { .ord(&ord) .run_and_deserialize_output::(); - let txid = core.mine_blocks_with_subsidy(1, 100)[0].txdata[0].txid(); + let txid = core.mine_blocks_with_subsidy(1, 100)[0].txdata[0].compute_txid(); CommandBuilder::new(format!( "wallet send --fee-rate 1 bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 {txid}:0:0" )) @@ -362,7 +362,7 @@ inscriptions: indexed: true, runes: BTreeMap::new(), sat_ranges: Some(vec![(5_000_000_000, 5_000_030_000)]), - script_pubkey: destination.payload.script_pubkey(), + script_pubkey: destination.assume_checked_ref().script_pubkey(), spent: false, transaction: reveal_txid, value: 30_000, @@ -455,19 +455,16 @@ fn send_btc_with_fee_rate() { let tx = &core.mempool()[0]; - let mut fee = 0; + let mut fee = Amount::ZERO; for input in &tx.input { - fee += core - .get_utxo_amount(&input.previous_output) - .unwrap() - .to_sat(); + fee += core.get_utxo_amount(&input.previous_output).unwrap(); } for output in &tx.output { fee -= output.value; } - let fee_rate = fee as f64 / tx.vsize() as f64; + let fee_rate = fee.to_sat() as f64 / tx.vsize() as f64; assert!(f64::abs(fee_rate - 13.3) < 0.1); @@ -479,7 +476,7 @@ fn send_btc_with_fee_rate() { .assume_checked() ); - assert_eq!(tx.output[0].value, 2 * COIN_VALUE); + assert_eq!(tx.output[0].value.to_sat(), 2 * COIN_VALUE); } #[test] @@ -543,18 +540,15 @@ fn wallet_send_with_fee_rate() { .run_and_deserialize_output::(); let tx = &core.mempool()[0]; - let mut fee = 0; + let mut fee = Amount::ZERO; for input in &tx.input { - fee += core - .get_utxo_amount(&input.previous_output) - .unwrap() - .to_sat(); + fee += core.get_utxo_amount(&input.previous_output).unwrap(); } for output in &tx.output { fee -= output.value; } - let fee_rate = fee as f64 / tx.vsize() as f64; + let fee_rate = fee.to_sat() as f64 / tx.vsize() as f64; pretty_assert_eq!(fee_rate, 2.0); } @@ -604,21 +598,18 @@ fn wallet_send_with_fee_rate_and_target_postage() { .run_and_deserialize_output::(); let tx = &core.mempool()[0]; - let mut fee = 0; + let mut fee = Amount::ZERO; for input in &tx.input { - fee += core - .get_utxo_amount(&input.previous_output) - .unwrap() - .to_sat(); + fee += core.get_utxo_amount(&input.previous_output).unwrap(); } for output in &tx.output { fee -= output.value; } - let fee_rate = fee as f64 / tx.vsize() as f64; + let fee_rate = fee.to_sat() as f64 / tx.vsize() as f64; pretty_assert_eq!(fee_rate, 2.0); - pretty_assert_eq!(tx.output[0].value, 77_000); + pretty_assert_eq!(tx.output[0].value.to_sat(), 77_000); } #[test] @@ -630,7 +621,7 @@ fn send_btc_does_not_send_locked_utxos() { create_wallet(&core, &ord); let coinbase_tx = &core.mine_blocks(1)[0].txdata[0]; - let outpoint = OutPoint::new(coinbase_tx.txid(), 0); + let outpoint = OutPoint::new(coinbase_tx.compute_txid(), 0); core.lock(outpoint); @@ -688,7 +679,7 @@ fn sending_rune_that_has_not_been_etched_is_an_error() { create_wallet(&core, &ord); let coinbase_tx = &core.mine_blocks(1)[0].txdata[0]; - let outpoint = OutPoint::new(coinbase_tx.txid(), 0); + let outpoint = OutPoint::new(coinbase_tx.compute_txid(), 0); core.lock(outpoint); @@ -814,8 +805,8 @@ fn sending_rune_with_change_works() { let tx = core.tx_by_id(output.txid); - assert_eq!(tx.output[1].value, 1234); - assert_eq!(tx.output[2].value, 1234); + assert_eq!(tx.output[1].value.to_sat(), 1234); + assert_eq!(tx.output[2].value.to_sat(), 1234); let balances = CommandBuilder::new("--regtest --index-runes balances") .core(&core)