diff --git a/CHANGELOG.md b/CHANGELOG.md index b742b01e..7e4b4691 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ N/A ### Changed -N/A +- **uplc**: Reward accounts are now correctly turned into script credentials in ScriptContext. ### Removed diff --git a/crates/uplc/src/tx/eval.rs b/crates/uplc/src/tx/eval.rs index 2ff5daaa..ad9ccdcf 100644 --- a/crates/uplc/src/tx/eval.rs +++ b/crates/uplc/src/tx/eval.rs @@ -312,7 +312,8 @@ fn get_tx_info_v1( .clone() .into_iter() .sorted() - .collect(); + .map(|(reward_account, coin)| (Address::from_bytes(&reward_account).unwrap(), coin)) + .collect_vec(); let valid_range = slot_range_to_posix_time_range( TimeRange { @@ -388,6 +389,7 @@ fn get_tx_info_v2( .clone() .into_iter() .sorted() + .map(|(reward_account, coin)| (Address::from_bytes(&reward_account).unwrap(), coin)) .collect(), ); diff --git a/crates/uplc/src/tx/script_context.rs b/crates/uplc/src/tx/script_context.rs index 50cb46e2..a5d82476 100644 --- a/crates/uplc/src/tx/script_context.rs +++ b/crates/uplc/src/tx/script_context.rs @@ -1,8 +1,9 @@ +use pallas_addresses::Address; use pallas_codec::utils::KeyValuePairs; use pallas_crypto::hash::Hash; use pallas_primitives::babbage::{ - AddrKeyhash, Certificate, Coin, DatumHash, PlutusData, PolicyId, Redeemer, RewardAccount, - StakeCredential, TransactionInput, TransactionOutput, Value, Withdrawals, + AddrKeyhash, Certificate, Coin, DatumHash, PlutusData, PolicyId, Redeemer, StakeCredential, + TransactionInput, TransactionOutput, Value, }; use serde::Deserialize; @@ -40,7 +41,7 @@ pub struct TxInfoV1 { pub fee: Value, pub mint: MintValue, pub dcert: Vec, - pub wdrl: Vec<(RewardAccount, Coin)>, + pub wdrl: Vec<(Address, Coin)>, pub valid_range: TimeRange, pub signatories: Vec, pub data: Vec<(DatumHash, PlutusData)>, @@ -55,7 +56,7 @@ pub struct TxInfoV2 { pub fee: Value, pub mint: MintValue, pub dcert: Vec, - pub wdrl: Withdrawals, + pub wdrl: KeyValuePairs, pub valid_range: TimeRange, pub signatories: Vec, pub redeemers: KeyValuePairs, diff --git a/crates/uplc/src/tx/to_plutus_data.rs b/crates/uplc/src/tx/to_plutus_data.rs index 76878c6c..bf435552 100644 --- a/crates/uplc/src/tx/to_plutus_data.rs +++ b/crates/uplc/src/tx/to_plutus_data.rs @@ -1,4 +1,4 @@ -use pallas_addresses::{Address, ShelleyDelegationPart, ShelleyPaymentPart}; +use pallas_addresses::{Address, ShelleyDelegationPart, ShelleyPaymentPart, StakePayload}; use pallas_codec::utils::{AnyUInt, Bytes, Int, KeyValuePairs}; use pallas_crypto::hash::Hash; use pallas_primitives::babbage::{AssetName, BigInt, Constr, Mint, PlutusData, ScriptRef}; @@ -85,6 +85,17 @@ impl ToPlutusData for Address { wrap_multiple_with_constr(0, vec![payment_part_plutus_data, stake_part_plutus_data]) } + Address::Stake(stake_address) => { + // This is right now only used in Withdrawals (Reward account) + match stake_address.payload() { + StakePayload::Stake(stake_keyhash) => { + StakeCredential::AddrKeyhash(*stake_keyhash).to_plutus_data() + } + StakePayload::Script(script_hash) => { + StakeCredential::Scripthash(*script_hash).to_plutus_data() + } + } + } _ => unreachable!(), } }