Check to for process updates
This commit is contained in:
parent
089b59136d
commit
b2f7f68726
29
src/api.rs
29
src/api.rs
@ -13,7 +13,7 @@ use rand::{thread_rng, Fill, Rng, RngCore};
|
||||
use sdk_common::aes_gcm::aead::generic_array::GenericArray;
|
||||
use sdk_common::aes_gcm::aes::cipher::ArrayLength;
|
||||
use sdk_common::aes_gcm::Nonce;
|
||||
use sdk_common::log::{debug, warn, info};
|
||||
use sdk_common::log::{self, debug, info, warn};
|
||||
|
||||
use anyhow::Context;
|
||||
use anyhow::Error as AnyhowError;
|
||||
@ -22,7 +22,7 @@ use sdk_common::aes_gcm::aead::{Aead, Payload};
|
||||
use sdk_common::crypto::{
|
||||
encrypt_with_key, AeadCore, Aes256Gcm, AnkSharedSecretHash, KeyInit, AAD,
|
||||
};
|
||||
use sdk_common::process::{lock_processes, Process, ProcessState};
|
||||
use sdk_common::process::{check_tx_for_process_updates, lock_processes, Process, ProcessState};
|
||||
use sdk_common::signature::{AnkHash, AnkMessageHash, AnkValidationNoHash, AnkValidationYesHash, Proof};
|
||||
use sdk_common::sp_client::bitcoin::blockdata::fee_rate;
|
||||
use sdk_common::sp_client::bitcoin::consensus::{deserialize, serialize};
|
||||
@ -635,6 +635,31 @@ fn process_transaction(
|
||||
) -> anyhow::Result<ApiReturn> {
|
||||
let tx = deserialize::<Transaction>(&Vec::from_hex(&tx_hex)?)?;
|
||||
|
||||
// Before anything, check if this transaction spends the tip of a process we know about
|
||||
match check_tx_for_process_updates(&tx) {
|
||||
Ok(outpoint) => {
|
||||
let processes = lock_processes()?;
|
||||
let process = processes.get(&outpoint).unwrap();
|
||||
let new_state = process.get_latest_commited_state().unwrap();
|
||||
let roles = if let Ok(roles) = new_state.encrypted_pcd.extract_roles() { roles } else { HashMap::new() };
|
||||
let diffs = if let Ok(diffs) = create_diffs(process, new_state) { diffs } else { vec![] };
|
||||
let updated_process = UpdatedProcess {
|
||||
commitment_tx: outpoint,
|
||||
current_process: process.clone(),
|
||||
up_to_date_roles: roles,
|
||||
new_diffs: diffs,
|
||||
..Default::default()
|
||||
};
|
||||
let api_return = ApiReturn {
|
||||
updated_process: Some(updated_process),
|
||||
..Default::default()
|
||||
};
|
||||
debug!("Found an update for process {:?}", api_return.updated_process.as_ref().unwrap().commitment_tx);
|
||||
return Ok(api_return);
|
||||
}
|
||||
Err(e) => debug!("Failed to find process update: {}", e)
|
||||
}
|
||||
|
||||
let tweak_data = PublicKey::from_str(&tweak_data_hex)?;
|
||||
|
||||
let updated: HashMap<OutPoint, OwnedOutput>;
|
||||
|
Loading…
x
Reference in New Issue
Block a user