fix(dao): build errors in plutus_data — or-pattern parens, Int→i128, BoundedBytes AsRef ambiguity
This commit is contained in:
parent
41195ece4f
commit
c059c1ff1c
1 changed files with 12 additions and 4 deletions
|
|
@ -69,7 +69,8 @@ pub fn as_constr(pd: &PlutusData) -> DaoResult<(u64, &Vec<PlutusData>)> {
|
|||
c.tag
|
||||
)));
|
||||
};
|
||||
let MaybeIndefArray::Def(ref fields) | MaybeIndefArray::Indef(ref fields) = c.fields;
|
||||
let (MaybeIndefArray::Def(ref fields) | MaybeIndefArray::Indef(ref fields)) =
|
||||
c.fields;
|
||||
Ok((idx, fields))
|
||||
}
|
||||
other => Err(DaoError::Datum(format!(
|
||||
|
|
@ -82,8 +83,10 @@ pub fn as_constr(pd: &PlutusData) -> DaoResult<(u64, &Vec<PlutusData>)> {
|
|||
pub fn as_int(pd: &PlutusData) -> DaoResult<i128> {
|
||||
match pd {
|
||||
PlutusData::BigInt(BigInt::Int(i)) => {
|
||||
// pallas's BigInt::Int wraps a `minicbor::data::Int` which lossily exposes i64 only.
|
||||
Ok(i128::from(i64::from(*i)))
|
||||
// pallas's BigInt::Int wraps a `minicbor::data::Int`. Convert via
|
||||
// i128 (Int → i128 is total since CBOR spec encodes [-2^64, 2^64-1]
|
||||
// — minicbor's Int can't exceed i128's range).
|
||||
Ok(i128::from(*i))
|
||||
}
|
||||
PlutusData::BigInt(BigInt::BigUInt(b)) => {
|
||||
let bs = b.as_slice();
|
||||
|
|
@ -114,7 +117,12 @@ pub fn as_int(pd: &PlutusData) -> DaoResult<i128> {
|
|||
/// Decode a PlutusData::BoundedBytes into a Vec<u8>.
|
||||
pub fn as_bytes(pd: &PlutusData) -> DaoResult<Vec<u8>> {
|
||||
match pd {
|
||||
PlutusData::BoundedBytes(b) => Ok(b.as_ref().clone()),
|
||||
PlutusData::BoundedBytes(b) => {
|
||||
// `BoundedBytes` impls `AsRef<Vec<u8>>` AND `AsRef<[u8]>`, so we
|
||||
// pin the slice variant explicitly to disambiguate.
|
||||
let bs: &[u8] = b.as_ref();
|
||||
Ok(bs.to_vec())
|
||||
}
|
||||
other => Err(DaoError::Datum(format!(
|
||||
"expected BoundedBytes, got {other:?}"
|
||||
))),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue