diff --git a/crates/tx3-cardano/src/coercion.rs b/crates/tx3-cardano/src/coercion.rs index b10c59b1..c2f1f17c 100644 --- a/crates/tx3-cardano/src/coercion.rs +++ b/crates/tx3-cardano/src/coercion.rs @@ -130,8 +130,23 @@ pub fn expr_into_reward_account( ) -> Result { let address = expr_into_address(expr, network)?; - let hash_bytes = match address { - pallas::ledger::addresses::Address::Shelley(x) => x.delegation().to_vec(), + let reward_bytes = match address { + pallas::ledger::addresses::Address::Shelley(x) => { + let payload = match x.delegation() { + pallas::ledger::addresses::ShelleyDelegationPart::Key(h) => { + pallas::ledger::addresses::StakePayload::Stake(*h) + } + pallas::ledger::addresses::ShelleyDelegationPart::Script(h) => { + pallas::ledger::addresses::StakePayload::Script(*h) + } + _ => { + return Err(Error::FormatError( + "can't convert address delegation to reward account".to_string(), + )) + } + }; + pallas::ledger::addresses::StakeAddress::new(x.network(), payload).to_vec() + } pallas::ledger::addresses::Address::Stake(x) => x.to_vec(), _ => { return Err(Error::FormatError( @@ -140,7 +155,7 @@ pub fn expr_into_reward_account( } }; - Ok(primitives::RewardAccount::from(hash_bytes)) + Ok(primitives::RewardAccount::from(reward_bytes)) } pub fn expr_into_stake_credential( diff --git a/crates/tx3-cardano/src/compile/mod.rs b/crates/tx3-cardano/src/compile/mod.rs index 7b8a86e0..366c0bcd 100644 --- a/crates/tx3-cardano/src/compile/mod.rs +++ b/crates/tx3-cardano/src/compile/mod.rs @@ -756,7 +756,7 @@ fn compile_withdrawal_redeemers( let redeemers = tx .adhoc .iter() - .filter(|x| x.name.as_str() == "withdraw") + .filter(|x| x.name.as_str() == "withdrawal") .map(|adhoc| compile_single_withdrawal_redeemer(adhoc, compiled_body, network)) .filter_map(|x| x.transpose()) .collect::, _>>()?; diff --git a/crates/tx3-cardano/src/tests.rs b/crates/tx3-cardano/src/tests.rs index f6f4e4f0..94ea1edf 100644 --- a/crates/tx3-cardano/src/tests.rs +++ b/crates/tx3-cardano/src/tests.rs @@ -513,6 +513,30 @@ async fn min_utxo_test() { ); } +#[pollster::test] +async fn withdrawal_redeemer_test() { + let mut compiler = test_compiler(None); + let utxos = wildcard_utxos(None); + let protocol = load_protocol("withdrawal"); + + let tx = protocol.tir("transfer").unwrap().clone(); + + let args = BTreeMap::from([ + arg_value!("sender", "address", "addr1qx0rs5qrvx9qkndwu0w88t0xghgy3f53ha76kpx8uf496m9rn2ursdm3r0fgf5pmm4lpufshl8lquk5yykg4pd00hp6quf2hh2"), + arg_value!("receiver", "address", "addr1qx0rs5qrvx9qkndwu0w88t0xghgy3f53ha76kpx8uf496m9rn2ursdm3r0fgf5pmm4lpufshl8lquk5yykg4pd00hp6quf2hh2"), + arg_value!("quantity", "int", 100_000_000), + ]); + + let tx = test_compile(tx, &args, &mut compiler, utxos); + + println!("{}", hex::encode(&tx.payload)); + + assert_eq!( + hex::encode(tx.hash), + "3aac7067d10d022a364b4ce8723edca7a3f55911da698f198511bab78fcf46d8" + ); +} + #[pollster::test] async fn min_utxo_compiler_op_test() { let compiler = test_compiler(None);