fix(dao): build errors in plutus_data — or-pattern parens, Int→i128, BoundedBytes AsRef ambiguity
This commit is contained in:
parent
50658ea51b
commit
5c41dbda86
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
|
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))
|
Ok((idx, fields))
|
||||||
}
|
}
|
||||||
other => Err(DaoError::Datum(format!(
|
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> {
|
pub fn as_int(pd: &PlutusData) -> DaoResult<i128> {
|
||||||
match pd {
|
match pd {
|
||||||
PlutusData::BigInt(BigInt::Int(i)) => {
|
PlutusData::BigInt(BigInt::Int(i)) => {
|
||||||
// pallas's BigInt::Int wraps a `minicbor::data::Int` which lossily exposes i64 only.
|
// pallas's BigInt::Int wraps a `minicbor::data::Int`. Convert via
|
||||||
Ok(i128::from(i64::from(*i)))
|
// 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)) => {
|
PlutusData::BigInt(BigInt::BigUInt(b)) => {
|
||||||
let bs = b.as_slice();
|
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>.
|
/// Decode a PlutusData::BoundedBytes into a Vec<u8>.
|
||||||
pub fn as_bytes(pd: &PlutusData) -> DaoResult<Vec<u8>> {
|
pub fn as_bytes(pd: &PlutusData) -> DaoResult<Vec<u8>> {
|
||||||
match pd {
|
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!(
|
other => Err(DaoError::Datum(format!(
|
||||||
"expected BoundedBytes, got {other:?}"
|
"expected BoundedBytes, got {other:?}"
|
||||||
))),
|
))),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue