diff --git a/crates/ordinals/src/runestone.rs b/crates/ordinals/src/runestone.rs index 90af2c4948..4744dd875e 100644 --- a/crates/ordinals/src/runestone.rs +++ b/crates/ordinals/src/runestone.rs @@ -22,23 +22,23 @@ impl Runestone { pub const MAGIC_NUMBER: opcodes::All = opcodes::all::OP_PUSHNUM_13; pub const COMMIT_INTERVAL: u16 = 6; - pub fn decipher(transaction: &Transaction) -> Result, script::Error> { - let payload = match Runestone::payload(transaction)? { + pub fn decipher(transaction: &Transaction) -> Option { + let payload = match Runestone::payload(transaction) { Some(Payload::Valid(payload)) => payload, Some(Payload::Invalid(flaw)) => { - return Ok(Some(Artifact::Cenotaph(Cenotaph { + return Some(Artifact::Cenotaph(Cenotaph { flaws: flaw.into(), ..default() - }))) + })); } - None => return Ok(None), + None => return None, }; let Some(integers) = Runestone::integers(&payload) else { - return Ok(Some(Artifact::Cenotaph(Cenotaph { + return Some(Artifact::Cenotaph(Cenotaph { flaws: Flaw::Varint.into(), ..default() - }))); + })); }; let Message { @@ -110,19 +110,19 @@ impl Runestone { } if flaws != 0 { - return Ok(Some(Artifact::Cenotaph(Cenotaph { + return Some(Artifact::Cenotaph(Cenotaph { flaws, mint, etching: etching.and_then(|etching| etching.rune), - }))); + })); } - Ok(Some(Artifact::Runestone(Self { + Some(Artifact::Runestone(Self { edicts, etching, mint, pointer, - }))) + })) } pub fn encipher(&self) -> ScriptBuf { @@ -189,13 +189,13 @@ impl Runestone { builder.into_script() } - fn payload(transaction: &Transaction) -> Result, script::Error> { + fn payload(transaction: &Transaction) -> Option { // search transaction outputs for payload for output in &transaction.output { let mut instructions = output.script_pubkey.instructions(); // payload starts with OP_RETURN - if instructions.next().transpose()? != Some(Instruction::Op(opcodes::all::OP_RETURN)) { + if instructions.next() != Some(Ok(Instruction::Op(opcodes::all::OP_RETURN))) { continue; } @@ -214,18 +214,18 @@ impl Runestone { payload.extend_from_slice(push.as_bytes()); } Ok(Instruction::Op(_)) => { - return Ok(Some(Payload::Invalid(Flaw::Opcode))); + return Some(Payload::Invalid(Flaw::Opcode)); } Err(_) => { - return Ok(Some(Payload::Invalid(Flaw::InvalidScript))); + return Some(Payload::Invalid(Flaw::InvalidScript)); } } } - return Ok(Some(Payload::Valid(payload))); + return Some(Payload::Valid(payload)); } - Ok(None) + None } fn integers(payload: &[u8]) -> Option> { @@ -275,7 +275,6 @@ mod tests { version: 2, }) .unwrap() - .unwrap() } fn payload(integers: &[u128]) -> Vec { @@ -289,17 +288,19 @@ mod tests { } #[test] - fn decipher_returns_an_error_if_first_opcode_is_malformed() { - assert!(Runestone::decipher(&Transaction { - input: Vec::new(), - output: vec![TxOut { - script_pubkey: ScriptBuf::from_bytes(vec![opcodes::all::OP_PUSHBYTES_4.to_u8()]), - value: 0, - }], - lock_time: LockTime::ZERO, - version: 2, - }) - .is_err()); + fn decipher_returns_none_if_first_opcode_is_malformed() { + assert_eq!( + Runestone::decipher(&Transaction { + input: Vec::new(), + output: vec![TxOut { + script_pubkey: ScriptBuf::from_bytes(vec![opcodes::all::OP_PUSHBYTES_4.to_u8()]), + value: 0, + }], + lock_time: LockTime::ZERO, + version: 2, + }), + None, + ); } #[test] @@ -311,7 +312,7 @@ mod tests { lock_time: LockTime::ZERO, version: 2, }), - Ok(None) + None, ); } @@ -327,7 +328,7 @@ mod tests { lock_time: LockTime::ZERO, version: 2, }), - Ok(None) + None, ); } @@ -345,7 +346,7 @@ mod tests { lock_time: LockTime::ZERO, version: 2, }), - Ok(None) + None, ); } @@ -364,24 +365,10 @@ mod tests { lock_time: LockTime::ZERO, version: 2, }), - Ok(None) + None, ); } - #[test] - fn deciphering_valid_runestone_with_invalid_script_returns_script_error() { - Runestone::decipher(&Transaction { - input: Vec::new(), - output: vec![TxOut { - script_pubkey: ScriptBuf::from_bytes(vec![opcodes::all::OP_PUSHBYTES_4.to_u8()]), - value: 0, - }], - lock_time: LockTime::ZERO, - version: 2, - }) - .unwrap_err(); - } - #[test] fn deciphering_valid_runestone_with_invalid_script_postfix_returns_invalid_payload() { let mut script_pubkey = script::Builder::new() @@ -402,7 +389,7 @@ mod tests { lock_time: LockTime::ZERO, version: 2, }), - Ok(Some(Payload::Invalid(Flaw::InvalidScript))) + Some(Payload::Invalid(Flaw::InvalidScript)) ); } @@ -457,7 +444,6 @@ mod tests { lock_time: LockTime::ZERO, version: 2, }) - .unwrap() .unwrap(), Artifact::Cenotaph(Cenotaph { flaws: Flaw::Opcode.into(), @@ -482,7 +468,6 @@ mod tests { lock_time: LockTime::ZERO, version: 2, }) - .unwrap() .unwrap(), Artifact::Cenotaph(Cenotaph { flaws: Flaw::Opcode.into(), @@ -506,7 +491,6 @@ mod tests { lock_time: LockTime::ZERO, version: 2, }) - .unwrap() .unwrap(), Artifact::Runestone(Runestone::default()), ); @@ -545,7 +529,6 @@ mod tests { lock_time: LockTime::ZERO, version: 2, }) - .unwrap() .unwrap(), Artifact::Runestone(Runestone { mint: Some(RuneId::new(1, 1).unwrap()), @@ -776,7 +759,6 @@ mod tests { lock_time: LockTime::ZERO, version: 2, }) - .unwrap() .unwrap(), Artifact::Cenotaph(Cenotaph { flaws: Flaw::Varint.into(), @@ -1309,7 +1291,6 @@ mod tests { lock_time: LockTime::ZERO, version: 2, }) - .unwrap() .unwrap(), Artifact::Runestone(Runestone { edicts: vec![Edict { @@ -1352,7 +1333,6 @@ mod tests { lock_time: LockTime::ZERO, version: 2, }) - .unwrap() .unwrap(), Artifact::Runestone(Runestone { edicts: vec![Edict { @@ -1394,7 +1374,6 @@ mod tests { lock_time: LockTime::ZERO, version: 2, }) - .unwrap() .unwrap(), Artifact::Runestone(Runestone { edicts: vec![Edict { @@ -1676,7 +1655,7 @@ mod tests { version: 2, }; - let Payload::Valid(payload) = Runestone::payload(&transaction).unwrap().unwrap() else { + let Payload::Valid(payload) = Runestone::payload(&transaction).unwrap() else { panic!("invalid payload") }; @@ -1692,7 +1671,7 @@ mod tests { }; assert_eq!( - Runestone::decipher(&transaction).unwrap().unwrap(), + Runestone::decipher(&transaction).unwrap(), Artifact::Runestone(runestone), ); } @@ -2054,8 +2033,7 @@ mod tests { ]), value: 0, }], - }) - .unwrap(), + }), None ); @@ -2083,7 +2061,6 @@ mod tests { } ], }) - .unwrap() .unwrap(), Artifact::Runestone(Runestone::default()), ); @@ -2110,7 +2087,6 @@ mod tests { value: 0, }], }) - .unwrap() .unwrap(), Artifact::Cenotaph(Cenotaph { flaws: Flaw::InvalidScript.into(), diff --git a/src/index/updater/rune_updater.rs b/src/index/updater/rune_updater.rs index 7eda06ec97..744ff587b9 100644 --- a/src/index/updater/rune_updater.rs +++ b/src/index/updater/rune_updater.rs @@ -18,7 +18,7 @@ pub(super) struct RuneUpdater<'a, 'tx, 'client> { impl<'a, 'tx, 'client> RuneUpdater<'a, 'tx, 'client> { pub(super) fn index_runes(&mut self, tx_index: u32, tx: &Transaction, txid: Txid) -> Result<()> { - let artifact = Runestone::decipher(tx)?; + let artifact = Runestone::decipher(tx); let mut unallocated = self.unallocated(tx)?; diff --git a/src/subcommand/decode.rs b/src/subcommand/decode.rs index d80b5dc32e..a9480f79c4 100644 --- a/src/subcommand/decode.rs +++ b/src/subcommand/decode.rs @@ -84,7 +84,7 @@ impl Decode { let inscriptions = ParsedEnvelope::from_transaction(&transaction); - let runestone = Runestone::decipher(&transaction)?; + let runestone = Runestone::decipher(&transaction); if self.compact { Ok(Some(Box::new(CompactOutput { diff --git a/src/subcommand/wallet/mint.rs b/src/subcommand/wallet/mint.rs index 4512725e42..069c108bf2 100644 --- a/src/subcommand/wallet/mint.rs +++ b/src/subcommand/wallet/mint.rs @@ -80,7 +80,7 @@ impl Mint { assert_eq!( Runestone::decipher(&signed_transaction), - Ok(Some(Artifact::Runestone(runestone))), + Some(Artifact::Runestone(runestone)), ); let transaction = bitcoin_client.send_raw_transaction(&signed_transaction)?; diff --git a/src/subcommand/wallet/send.rs b/src/subcommand/wallet/send.rs index 7357fa9606..3a7fd5ae66 100644 --- a/src/subcommand/wallet/send.rs +++ b/src/subcommand/wallet/send.rs @@ -308,7 +308,7 @@ impl Send { assert_eq!( Runestone::decipher(&unsigned_transaction), - Ok(Some(Artifact::Runestone(runestone))), + Some(Artifact::Runestone(runestone)), ); Ok(unsigned_transaction) diff --git a/src/wallet/batch/plan.rs b/src/wallet/batch/plan.rs index 9ef2444850..1f51127464 100644 --- a/src/wallet/batch/plan.rs +++ b/src/wallet/batch/plan.rs @@ -632,7 +632,7 @@ impl Plan { let total_fees = Self::calculate_fee(&unsigned_commit_tx, &utxos) + Self::calculate_fee(&reveal_tx, &utxos); - match (Runestone::decipher(&reveal_tx).unwrap(), runestone) { + match (Runestone::decipher(&reveal_tx), runestone) { (Some(actual), Some(expected)) => assert_eq!( actual, Artifact::Runestone(expected), diff --git a/tests/wallet/batch_command.rs b/tests/wallet/batch_command.rs index 8c328a7981..2b8293f910 100644 --- a/tests/wallet/batch_command.rs +++ b/tests/wallet/batch_command.rs @@ -1483,7 +1483,7 @@ fn batch_can_etch_rune() { Sequence::from_height(Runestone::COMMIT_INTERVAL) ); - let Artifact::Runestone(runestone) = Runestone::decipher(&reveal).unwrap().unwrap() else { + let Artifact::Runestone(runestone) = Runestone::decipher(&reveal).unwrap() else { panic!(); }; diff --git a/tests/wallet/send.rs b/tests/wallet/send.rs index 478de05b70..7ceeef62de 100644 --- a/tests/wallet/send.rs +++ b/tests/wallet/send.rs @@ -1069,7 +1069,7 @@ fn sending_rune_creates_transaction_with_expected_runestone() { let tx = core.tx_by_id(output.txid); pretty_assert_eq!( - Runestone::decipher(&tx).unwrap().unwrap(), + Runestone::decipher(&tx).unwrap(), Artifact::Runestone(Runestone { pointer: None, etching: None,