Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions crates/trp/src/methods.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use jsonrpsee::types::Params;
use pallas::{codec::utils::NonEmptySet, ledger::primitives::conway::VKeyWitness};
use pallas::{
codec::utils::NonEmptySet,
ledger::primitives::conway::{VKeyWitness, WitnessSet},
};
use std::sync::Arc;

use tx3_resolver::trp::{ResolveParams, SubmitParams, SubmitResponse, SubmitWitness, TxEnvelope};
use tx3_resolver::{trp::{ResolveParams, SubmitResponse, SubmitParams, WitnessInput, TxEnvelope}};

Check failure on line 8 in crates/trp/src/methods.rs

View workflow job for this annotation

GitHub Actions / Check Build

unresolved import `tx3_resolver::trp::WitnessInput`

use dolos_core::{facade::receive_tx, Domain, MempoolAwareUtxoStore, StateStore as _};

Expand Down Expand Up @@ -39,15 +42,32 @@
})
}

fn apply_witnesses(original: &[u8], witnesses: &[SubmitWitness]) -> Result<Vec<u8>, Error> {
fn apply_witnesses(original: &[u8], witnesses: &[WitnessInput]) -> Result<Vec<u8>, Error> {
let tx = pallas::ledger::traverse::MultiEraTx::decode(original)?;

let mut tx = tx.as_conway().ok_or(Error::UnsupportedTxEra)?.to_owned();

let map_witness = |witness: &SubmitWitness| VKeyWitness {
vkey: Vec::<u8>::from(witness.key.clone()).into(),
signature: Vec::<u8>::from(witness.signature.clone()).into(),
};
let mut new_vkeys = Vec::new();

for witness in witnesses {
match witness {
WitnessInput::Object(w) => {
new_vkeys.push(VKeyWitness {
vkey: Vec::<u8>::from(w.key.clone()).into(),
signature: Vec::<u8>::from(w.signature.clone()).into(),
});
}
WitnessInput::Hex(h) => {
let bytes = hex::decode(h).map_err(|_| Error::InternalError("Invalid witness hex".into()))?;
let witness_set: WitnessSet = pallas::codec::minicbor::decode(&bytes)
.map_err(|_| Error::InternalError("Invalid witness set cbor".into()))?;

if let Some(vkeys) = witness_set.vkeywitness {
new_vkeys.extend(vkeys.to_vec());
}
}
}
}

let mut witness_set = tx.transaction_witness_set.unwrap();

Expand All @@ -57,9 +77,7 @@
.flat_map(|x| x.iter())
.cloned();

let new = witnesses.iter().map(map_witness);

let all: Vec<_> = old.chain(new).collect();
let all: Vec<_> = old.chain(new_vkeys).collect();

witness_set.vkeywitness = NonEmptySet::from_vec(all);

Expand Down
Loading