fix(primitives): Fix round-trip decoding of move_instantaneous_reward struct (#64)
This commit is contained in:
parent
54f3454f58
commit
f0c0887390
2 changed files with 14 additions and 11 deletions
|
|
@ -5,7 +5,7 @@
|
||||||
use minicbor::{bytes::ByteVec, data::Tag};
|
use minicbor::{bytes::ByteVec, data::Tag};
|
||||||
use minicbor_derive::{Decode, Encode};
|
use minicbor_derive::{Decode, Encode};
|
||||||
use pallas_crypto::hash::Hash;
|
use pallas_crypto::hash::Hash;
|
||||||
use std::{collections::BTreeMap, ops::Deref};
|
use std::ops::Deref;
|
||||||
|
|
||||||
use crate::utils::{KeyValuePairs, MaybeIndefArray};
|
use crate::utils::{KeyValuePairs, MaybeIndefArray};
|
||||||
|
|
||||||
|
|
@ -220,7 +220,7 @@ impl minicbor::encode::Encode for InstantaneousRewardSource {
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, PartialOrd)]
|
#[derive(Debug, PartialEq, PartialOrd)]
|
||||||
pub enum InstantaneousRewardTarget {
|
pub enum InstantaneousRewardTarget {
|
||||||
StakeCredentials(BTreeMap<StakeCredential, i64>),
|
StakeCredentials(KeyValuePairs<StakeCredential, i64>),
|
||||||
OtherAccountingPot(Coin),
|
OtherAccountingPot(Coin),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -229,7 +229,7 @@ impl<'b> minicbor::decode::Decode<'b> for InstantaneousRewardTarget {
|
||||||
let datatype = d.datatype()?;
|
let datatype = d.datatype()?;
|
||||||
|
|
||||||
match datatype {
|
match datatype {
|
||||||
minicbor::data::Type::Map => {
|
minicbor::data::Type::Map | minicbor::data::Type::MapIndef => {
|
||||||
let a = d.decode()?;
|
let a = d.decode()?;
|
||||||
Ok(Self::StakeCredentials(a))
|
Ok(Self::StakeCredentials(a))
|
||||||
}
|
}
|
||||||
|
|
@ -420,7 +420,7 @@ impl minicbor::encode::Encode for StakeCredential {
|
||||||
}
|
}
|
||||||
StakeCredential::Scripthash(a) => {
|
StakeCredential::Scripthash(a) => {
|
||||||
e.array(2)?;
|
e.array(2)?;
|
||||||
e.encode(0)?;
|
e.encode(1)?;
|
||||||
e.encode(a)?;
|
e.encode(a)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -441,8 +441,8 @@ pub enum Certificate {
|
||||||
cost: Coin,
|
cost: Coin,
|
||||||
margin: UnitInterval,
|
margin: UnitInterval,
|
||||||
reward_account: RewardAccount,
|
reward_account: RewardAccount,
|
||||||
pool_owners: Vec<AddrKeyhash>,
|
pool_owners: MaybeIndefArray<AddrKeyhash>,
|
||||||
relays: Vec<Relay>,
|
relays: MaybeIndefArray<Relay>,
|
||||||
pool_metadata: Option<PoolMetadata>,
|
pool_metadata: Option<PoolMetadata>,
|
||||||
},
|
},
|
||||||
PoolRetirement(PoolKeyhash, Epoch),
|
PoolRetirement(PoolKeyhash, Epoch),
|
||||||
|
|
@ -586,7 +586,7 @@ impl minicbor::encode::Encode for Certificate {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Certificate::MoveInstantaneousRewardsCert(a) => {
|
Certificate::MoveInstantaneousRewardsCert(a) => {
|
||||||
e.array(3)?;
|
e.array(2)?;
|
||||||
e.u16(6)?;
|
e.u16(6)?;
|
||||||
e.encode(a)?;
|
e.encode(a)?;
|
||||||
|
|
||||||
|
|
@ -612,7 +612,7 @@ pub enum Language {
|
||||||
PlutusV1,
|
PlutusV1,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type CostModel = Vec<i32>;
|
pub type CostModel = MaybeIndefArray<i32>;
|
||||||
|
|
||||||
pub type CostMdls = KeyValuePairs<Language, CostModel>;
|
pub type CostMdls = KeyValuePairs<Language, CostModel>;
|
||||||
|
|
||||||
|
|
@ -650,7 +650,7 @@ pub struct ProtocolParamUpdate {
|
||||||
#[n(13)]
|
#[n(13)]
|
||||||
pub extra_entropy: Option<Nonce>,
|
pub extra_entropy: Option<Nonce>,
|
||||||
#[n(14)]
|
#[n(14)]
|
||||||
pub protocol_version: Option<Vec<ProtocolVersion>>,
|
pub protocol_version: Option<MaybeIndefArray<ProtocolVersion>>,
|
||||||
#[n(16)]
|
#[n(16)]
|
||||||
pub min_pool_cost: Option<Coin>,
|
pub min_pool_cost: Option<Coin>,
|
||||||
#[n(17)]
|
#[n(17)]
|
||||||
|
|
@ -686,7 +686,7 @@ pub enum TransactionBodyComponent {
|
||||||
Outputs(MaybeIndefArray<TransactionOutput>),
|
Outputs(MaybeIndefArray<TransactionOutput>),
|
||||||
Fee(u64),
|
Fee(u64),
|
||||||
Ttl(u64),
|
Ttl(u64),
|
||||||
Certificates(Vec<Certificate>),
|
Certificates(MaybeIndefArray<Certificate>),
|
||||||
Withdrawals(KeyValuePairs<RewardAccount, Coin>),
|
Withdrawals(KeyValuePairs<RewardAccount, Coin>),
|
||||||
Update(Update),
|
Update(Update),
|
||||||
AuxiliaryDataHash(ByteVec),
|
AuxiliaryDataHash(ByteVec),
|
||||||
|
|
@ -1218,7 +1218,7 @@ pub struct AlonzoAuxiliaryData {
|
||||||
#[n(1)]
|
#[n(1)]
|
||||||
pub native_scripts: Option<MaybeIndefArray<NativeScript>>,
|
pub native_scripts: Option<MaybeIndefArray<NativeScript>>,
|
||||||
#[n(2)]
|
#[n(2)]
|
||||||
pub plutus_scripts: Option<Vec<PlutusScript>>,
|
pub plutus_scripts: Option<MaybeIndefArray<PlutusScript>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
|
@ -1420,6 +1420,8 @@ mod tests {
|
||||||
// peculiar block with overflow crash
|
// peculiar block with overflow crash
|
||||||
// https://github.com/txpipe/oura/issues/113
|
// https://github.com/txpipe/oura/issues/113
|
||||||
include_str!("test_data/test14.block"),
|
include_str!("test_data/test14.block"),
|
||||||
|
// peculiar block with many move-instantaneous-rewards certs
|
||||||
|
include_str!("test_data/test15.block"),
|
||||||
];
|
];
|
||||||
|
|
||||||
for (idx, block_str) in test_blocks.iter().enumerate() {
|
for (idx, block_str) in test_blocks.iter().enumerate() {
|
||||||
|
|
|
||||||
1
pallas-primitives/src/alonzo/test_data/test15.block
Normal file
1
pallas-primitives/src/alonzo/test_data/test15.block
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue