Skip to content

Commit 996295c

Browse files
committed
Use BigInt where i32 and i64 is not enough
1 parent 4f220b1 commit 996295c

File tree

2 files changed

+47
-30
lines changed

2 files changed

+47
-30
lines changed

pallas-hardano/src/display/haskell_display.rs

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::{
22
collections::{BTreeSet, HashMap},
3-
fmt::format,
43
net::Ipv6Addr,
54
ops::Deref,
65
};
@@ -20,11 +19,11 @@ use pallas_crypto::hash::{Hash, Hasher};
2019
use pallas_network::miniprotocols::{
2120
handshake::NetworkMagic,
2221
localstate::queries_v16::{
23-
primitives::Bytes, Anchor, AssetName, BoundedBytes, Constitution, CostModel, CostModels,
24-
DRep, DRepVotingThresholds, DatumHash, DatumOption, ExUnitPrices, FieldedRewardAccount,
25-
GovAction, GovActionId, PParamsUpdate, PlutusData, PolicyId, PoolMetadata,
26-
PoolVotingThresholds, ProposalProcedure, ProtocolVersion, RationalNumber, Relay,
27-
ScriptHash, TransactionInput, TransactionOutput, Value, Vote,
22+
primitives::Bytes, Anchor, AssetName, BigInt, BoundedBytes, Constitution, CostModel,
23+
CostModels, DRep, DRepVotingThresholds, DatumHash, DatumOption, ExUnitPrices,
24+
FieldedRewardAccount, GovAction, GovActionId, PParamsUpdate, PlutusData, PolicyId,
25+
PoolMetadata, PoolVotingThresholds, ProposalProcedure, ProtocolVersion, RationalNumber,
26+
Relay, ScriptHash, TransactionInput, TransactionOutput, Value, Vote,
2827
},
2928
localtxsubmission::{
3029
primitives::{
@@ -351,8 +350,8 @@ impl HaskellDisplay for UtxoFailure {
351350
),
352351
MaxTxSizeUTxO(actual, max) => format!(
353352
"(MaxTxSizeUTxO {} {})",
354-
actual.to_haskell_str_p(),
355-
max.to_haskell_str_p()
353+
actual.to_haskell_str(),
354+
max.to_haskell_str()
356355
),
357356
InputSetEmptyUTxO => "InputSetEmptyUTxO".to_string(),
358357
FeeTooSmallUTxO(required, provided) => format!(
@@ -1076,6 +1075,20 @@ impl HaskellDisplay for i64 {
10761075
}
10771076
}
10781077

1078+
impl HaskellDisplay for i128 {
1079+
fn to_haskell_str(&self) -> String {
1080+
self.to_string()
1081+
}
1082+
1083+
fn to_haskell_str_p(&self) -> String {
1084+
if *self >= 0 {
1085+
self.to_string()
1086+
} else {
1087+
format!("({})", self)
1088+
}
1089+
}
1090+
}
1091+
10791092
impl HaskellDisplay for u8 {
10801093
fn to_haskell_str(&self) -> String {
10811094
format!("{}", self)
@@ -1534,6 +1547,25 @@ impl HaskellDisplay for u64 {
15341547
}
15351548
}
15361549

1550+
impl HaskellDisplay for BigInt {
1551+
fn to_haskell_str(&self) -> String {
1552+
use BigInt::*;
1553+
1554+
match self {
1555+
Int(i) => {
1556+
let value: i128 = i.0.into();
1557+
value.to_haskell_str_p()
1558+
},
1559+
BigNInt(bb) => {
1560+
format!("BigNInt {}", bb.to_haskell_str_p())
1561+
}
1562+
BigUInt(bb) => {
1563+
format!("BigUInt {}", bb.to_haskell_str_p())
1564+
}
1565+
}
1566+
}
1567+
}
1568+
15371569
impl HaskellDisplay for String {
15381570
fn to_haskell_str(&self) -> String {
15391571
self.as_text()
@@ -2093,21 +2125,12 @@ impl AsDatumHash for DatumHash {
20932125

20942126
impl HaskellDisplay for PlutusData {
20952127
fn to_haskell_str(&self) -> String {
2096-
use pallas_network::miniprotocols::localstate::queries_v16::BigInt as Big;
20972128
use PlutusData::*;
20982129

20992130
match self {
21002131
Constr(constr) => constr.fields.to_haskell_str(),
21012132
Map(key_value_pairs) => key_value_pairs.to_haskell_str().to_string(),
2102-
BigInt(big_int) => match big_int {
2103-
Big::Int(i) => format!("BigInt Int {}", i.to_haskell_str()),
2104-
Big::BigNInt(bb) => {
2105-
format!("BigNInt {}", bb.to_haskell_str())
2106-
}
2107-
Big::BigUInt(bb) => {
2108-
format!("BigUInt {}", bb.to_haskell_str())
2109-
}
2110-
},
2133+
BigInt(big_int) => big_int.to_haskell_str(),
21112134
BoundedBytes(bb) => bb.to_haskell_str(),
21122135
Array(arr) => format!("Array {}", arr.to_haskell_str()),
21132136
}
@@ -2141,7 +2164,7 @@ where
21412164

21422165
impl HaskellDisplay for Int {
21432166
fn to_haskell_str(&self) -> String {
2144-
format!("Int {}", self.0)
2167+
format!("{}", self.0)
21452168
}
21462169
}
21472170

pallas-network/src/miniprotocols/localtxsubmission/protocol.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::primitives::{Certificate, Credential, Language, StakeCredential, Voter};
22
use crate::miniprotocols::localstate::queries_v16::{
3-
Anchor, GovAction, GovActionId, PolicyId, ProposalProcedure, ProtocolVersion, ScriptHash,
4-
TransactionInput, TransactionOutput, Value, Vote, FieldedRewardAccount};
3+
Anchor, BigInt, FieldedRewardAccount, GovAction, GovActionId, PolicyId, ProposalProcedure, ProtocolVersion, ScriptHash,
4+
TransactionInput, TransactionOutput, Value, Vote, };
55
pub use crate::miniprotocols::localstate::queries_v16::{Coin, ExUnits, TaggedSet};
66
use pallas_codec::minicbor::{self, Decode, Encode};
77
use pallas_codec::utils::{AnyUInt, Bytes, NonEmptyKeyValuePairs, Nullable, Set};
@@ -259,9 +259,7 @@ impl From<Network> for u8 {
259259
}
260260
#[derive(Debug, Decode, Encode, Clone, Eq, PartialEq)]
261261
#[cbor(transparent)]
262-
pub struct DeltaCoin(#[n(0)] pub i32);
263-
264-
262+
pub struct DeltaCoin(#[n(0)] pub BigInt);
265263

266264
pub type Slot = u64;
267265

@@ -285,7 +283,7 @@ pub enum UtxoFailure {
285283
#[n(2)]
286284
OutsideValidityIntervalUTxO(#[n(0)] ValidityInterval, #[n(1)] Slot),
287285
#[n(3)]
288-
MaxTxSizeUTxO(#[n(0)] i64, #[n(1)] i64),
286+
MaxTxSizeUTxO(#[n(0)] BigInt, #[n(1)] BigInt),
289287
#[n(4)]
290288
InputSetEmptyUTxO,
291289
#[n(5)]
@@ -315,7 +313,7 @@ pub enum UtxoFailure {
315313
#[n(17)]
316314
OutsideForecast(#[n(0)] Slot),
317315
#[n(18)]
318-
TooManyCollateralInputs(#[n(0)] u16, #[n(1)] u16),
316+
TooManyCollateralInputs(#[n(0)] u64, #[n(1)] u64),
319317
#[n(19)]
320318
NoCollateralInputs,
321319
#[n(20)]
@@ -440,11 +438,7 @@ pub enum ConwayLedgerFailure {
440438
#[cbor(flat)]
441439
pub enum ConwayCertsPredFailure {
442440
#[n(0)]
443-
<<<<<<< HEAD
444-
WithdrawalsNotInRewardsCERTS(#[n(0)] OHashMap<DisplayRewardAccount, DisplayCoin>),
445-
=======
446441
WithdrawalsNotInRewardsCERTS(#[n(0)] OHashMap<FieldedRewardAccount, DisplayCoin>),
447-
>>>>>>> ff7db11 (Match ProposalProcedure ordering with Haskell implementation)
448442
#[n(1)]
449443
CertFailure(#[n(0)] ConwayCertPredFailure),
450444
}

0 commit comments

Comments
 (0)