Fixed reward account creation in ScriptContext

This commit is contained in:
alessandrokonrad 2023-01-05 12:26:59 +01:00 committed by Lucas
parent 542962a2ea
commit 3aba9baba5
4 changed files with 21 additions and 7 deletions

View File

@ -8,7 +8,7 @@ N/A
### Changed
N/A
- **uplc**: Reward accounts are now correctly turned into script credentials in ScriptContext.
### Removed

View File

@ -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(),
);

View File

@ -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<Certificate>,
pub wdrl: Vec<(RewardAccount, Coin)>,
pub wdrl: Vec<(Address, Coin)>,
pub valid_range: TimeRange,
pub signatories: Vec<AddrKeyhash>,
pub data: Vec<(DatumHash, PlutusData)>,
@ -55,7 +56,7 @@ pub struct TxInfoV2 {
pub fee: Value,
pub mint: MintValue,
pub dcert: Vec<Certificate>,
pub wdrl: Withdrawals,
pub wdrl: KeyValuePairs<Address, Coin>,
pub valid_range: TimeRange,
pub signatories: Vec<AddrKeyhash>,
pub redeemers: KeyValuePairs<ScriptPurpose, Redeemer>,

View File

@ -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!(),
}
}