fix: contemplate legacy tx outputs in utxo by address query (#386)
This commit is contained in:
parent
7f0e022f1d
commit
3a0514c92b
3 changed files with 75 additions and 17 deletions
|
|
@ -332,3 +332,34 @@ impl<C> minicbor::encode::Encode<C> for RationalNumber {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b, C> minicbor::decode::Decode<'b, C> for TransactionOutput {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
match d.datatype()? {
|
||||
minicbor::data::Type::Map => Ok(TransactionOutput::Current(d.decode_with(ctx)?)),
|
||||
minicbor::data::Type::Array => Ok(TransactionOutput::Legacy(d.decode_with(ctx)?)),
|
||||
_ => Err(minicbor::decode::Error::message(
|
||||
"unknown cbor data type for TransactionOutput enum",
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<C> minicbor::encode::Encode<C> for TransactionOutput {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
TransactionOutput::Current(map) => {
|
||||
e.encode_with(map, ctx)?;
|
||||
}
|
||||
TransactionOutput::Legacy(array) => {
|
||||
e.encode_with(array, ctx)?;
|
||||
}
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -221,15 +221,21 @@ pub type Multiasset<A> = KeyValuePairs<PolicyId, KeyValuePairs<AssetName, A>>;
|
|||
#[derive(Debug, Encode, Decode, PartialEq, Clone)]
|
||||
pub struct UTxOByAddress {
|
||||
#[n(0)]
|
||||
pub utxo: KeyValuePairs<UTxO, Values>,
|
||||
pub utxo: KeyValuePairs<UTxO, TransactionOutput>,
|
||||
}
|
||||
|
||||
// Bytes CDDL -> #6.121([ * #6.121([ *datum ]) ])
|
||||
pub type Datum = (Era, TagWrap<Bytes, 24>);
|
||||
|
||||
#[derive(Debug, Encode, Decode, PartialEq, Clone)]
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub enum TransactionOutput {
|
||||
Current(PostAlonsoTransactionOutput),
|
||||
Legacy(LegacyTransactionOutput),
|
||||
}
|
||||
|
||||
#[derive(Debug, Encode, Decode, PartialEq, Eq, Clone)]
|
||||
#[cbor(map)]
|
||||
pub struct Values {
|
||||
pub struct PostAlonsoTransactionOutput {
|
||||
#[n(0)]
|
||||
pub address: Bytes,
|
||||
|
||||
|
|
@ -238,6 +244,21 @@ pub struct Values {
|
|||
|
||||
#[n(2)]
|
||||
pub inline_datum: Option<Datum>,
|
||||
|
||||
#[n(3)]
|
||||
pub script_ref: Option<TagWrap<Bytes, 24>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Encode, Decode, PartialEq, Eq, Clone)]
|
||||
pub struct LegacyTransactionOutput {
|
||||
#[n(0)]
|
||||
pub address: Bytes,
|
||||
|
||||
#[n(1)]
|
||||
pub amount: Value,
|
||||
|
||||
#[n(2)]
|
||||
pub datum_hash: Option<Hash<32>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Encode, Decode, PartialEq, Clone, StdHash, Eq)]
|
||||
|
|
|
|||
|
|
@ -580,13 +580,16 @@ pub async fn local_state_query_server_and_client_happy_path() {
|
|||
let datum = hex::decode(hex_datum).unwrap().into();
|
||||
let tag = TagWrap::<_, 24>::new(datum);
|
||||
let inline_datum = Some((1_u16, tag));
|
||||
let values = localstate::queries_v16::Values {
|
||||
address: b"addr_test1vr80076l3x5uw6n94nwhgmv7ssgy6muzf47ugn6z0l92rhg2mgtu0"
|
||||
.to_vec()
|
||||
.into(),
|
||||
amount: Value::Coin(lovelace),
|
||||
inline_datum,
|
||||
};
|
||||
let values = localstate::queries_v16::TransactionOutput::Current(
|
||||
localstate::queries_v16::PostAlonsoTransactionOutput {
|
||||
address: b"addr_test1vr80076l3x5uw6n94nwhgmv7ssgy6muzf47ugn6z0l92rhg2mgtu0"
|
||||
.to_vec()
|
||||
.into(),
|
||||
amount: Value::Coin(lovelace),
|
||||
inline_datum,
|
||||
script_ref: None,
|
||||
},
|
||||
);
|
||||
|
||||
let utxo = KeyValuePairs::from(vec![(
|
||||
localstate::queries_v16::UTxO {
|
||||
|
|
@ -795,13 +798,16 @@ pub async fn local_state_query_server_and_client_happy_path() {
|
|||
let datum = hex::decode(hex_datum).unwrap().into();
|
||||
let tag = TagWrap::<_, 24>::new(datum);
|
||||
let inline_datum = Some((1_u16, tag));
|
||||
let values = localstate::queries_v16::Values {
|
||||
address: b"addr_test1vr80076l3x5uw6n94nwhgmv7ssgy6muzf47ugn6z0l92rhg2mgtu0"
|
||||
.to_vec()
|
||||
.into(),
|
||||
amount: Value::Coin(lovelace),
|
||||
inline_datum,
|
||||
};
|
||||
let values = localstate::queries_v16::TransactionOutput::Current(
|
||||
localstate::queries_v16::PostAlonsoTransactionOutput {
|
||||
address: b"addr_test1vr80076l3x5uw6n94nwhgmv7ssgy6muzf47ugn6z0l92rhg2mgtu0"
|
||||
.to_vec()
|
||||
.into(),
|
||||
amount: Value::Coin(lovelace),
|
||||
inline_datum,
|
||||
script_ref: None,
|
||||
},
|
||||
);
|
||||
|
||||
let utxo = KeyValuePairs::from(vec![(
|
||||
localstate::queries_v16::UTxO {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue