refactor(interop): use stateful mapper for u5 (#460)
This commit is contained in:
parent
3fabbb2504
commit
37cad70f9c
1 changed files with 8 additions and 16 deletions
|
|
@ -11,10 +11,11 @@ pub use utxorpc_spec::utxorpc::v1alpha as spec;
|
||||||
|
|
||||||
use utxorpc_spec::utxorpc::v1alpha::cardano as u5c;
|
use utxorpc_spec::utxorpc::v1alpha::cardano as u5c;
|
||||||
|
|
||||||
pub trait Context {
|
pub trait Context: Clone {
|
||||||
fn get_spent_tx_output<'a>(tx_hash: Hash<32>, index: u32) -> Option<trv::MultiEraOutput<'a>>;
|
fn get_txo<'a>(&self, tx_hash: Hash<32>, txo_index: u32) -> Option<trv::MultiEraOutput<'a>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Clone)]
|
||||||
pub struct Mapper<C: Context> {
|
pub struct Mapper<C: Context> {
|
||||||
context: Option<C>,
|
context: Option<C>,
|
||||||
}
|
}
|
||||||
|
|
@ -43,20 +44,11 @@ impl<C: Context> Mapper<C> {
|
||||||
|
|
||||||
let redeemer = redeemers.iter().find(|r| (r.index() as u64) == i.index());
|
let redeemer = redeemers.iter().find(|r| (r.index() as u64) == i.index());
|
||||||
|
|
||||||
let as_output = match &self.context {
|
let as_output = self
|
||||||
Some(_) => {
|
.context
|
||||||
let tx_output = C::get_spent_tx_output(*i.hash(), i.index() as u32);
|
.as_ref()
|
||||||
match tx_output {
|
.and_then(|ctx| ctx.get_txo(*i.hash(), i.index() as u32))
|
||||||
Some(output) => Some(self.map_tx_output(&output)),
|
.map(|txo| self.map_tx_output(&txo));
|
||||||
None => panic!(
|
|
||||||
"Failed to fetch transaction output for hash: {:?}, index: {}",
|
|
||||||
i.hash(),
|
|
||||||
i.index()
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
u5c::TxInput {
|
u5c::TxInput {
|
||||||
tx_hash: i.hash().to_vec().into(),
|
tx_hash: i.hash().to_vec().into(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue