Broadcast new process
This commit is contained in:
parent
4839c95e93
commit
6fc08f3fdd
@ -50,7 +50,7 @@ fn parse_initial_tx(init_tx: &str) -> Result<InitialTx> {
|
|||||||
|
|
||||||
// Handle the case where `init_tx` is a new transaction
|
// Handle the case where `init_tx` is a new transaction
|
||||||
fn handle_initial_transaction(tx: Transaction, commit_msg: &CommitMessage) -> Result<OutPoint> {
|
fn handle_initial_transaction(tx: Transaction, commit_msg: &CommitMessage) -> Result<OutPoint> {
|
||||||
let root_commitment = OutPoint::new(tx.txid(), 0);
|
let process_id = OutPoint::new(tx.txid(), 0);
|
||||||
|
|
||||||
// Validation tokens must be empty for the initial transaction
|
// Validation tokens must be empty for the initial transaction
|
||||||
if !commit_msg.validation_tokens.is_empty() {
|
if !commit_msg.validation_tokens.is_empty() {
|
||||||
@ -78,8 +78,7 @@ fn handle_initial_transaction(tx: Transaction, commit_msg: &CommitMessage) -> Re
|
|||||||
|
|
||||||
let merkle_root_bin = pcd_commitment.create_merkle_tree()?.root().unwrap();
|
let merkle_root_bin = pcd_commitment.create_merkle_tree()?.root().unwrap();
|
||||||
|
|
||||||
match handle_member_list(pcd_commitment, &parsed_roles, root_commitment) {
|
if let Ok(pairing_process_id) = handle_member_list(pcd_commitment, &parsed_roles, process_id) {
|
||||||
Ok(pairing_process_id) => {
|
|
||||||
dump_cached_members()?;
|
dump_cached_members()?;
|
||||||
// Send a handshake message to every connected client
|
// Send a handshake message to every connected client
|
||||||
if let Some(new_member) = lock_members().unwrap().get(&pairing_process_id) {
|
if let Some(new_member) = lock_members().unwrap().get(&pairing_process_id) {
|
||||||
@ -108,14 +107,11 @@ fn handle_initial_transaction(tx: Transaction, commit_msg: &CommitMessage) -> Re
|
|||||||
} else {
|
} else {
|
||||||
log::error!("Failed to find new member with process id {}", pairing_process_id);
|
log::error!("Failed to find new member with process id {}", pairing_process_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
Err(e) => log::error!("{}", e)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut new_process = Process::new(root_commitment);
|
let mut new_process = Process::new(process_id);
|
||||||
let init_state = ProcessState {
|
let init_state = ProcessState {
|
||||||
commited_in: root_commitment,
|
commited_in: process_id,
|
||||||
encrypted_pcd: roles_only_map,
|
encrypted_pcd: roles_only_map,
|
||||||
pcd_commitment: commit_msg.pcd_commitment.clone(),
|
pcd_commitment: commit_msg.pcd_commitment.clone(),
|
||||||
state_id: merkle_root_bin.to_lower_hex_string(),
|
state_id: merkle_root_bin.to_lower_hex_string(),
|
||||||
@ -126,17 +122,41 @@ fn handle_initial_transaction(tx: Transaction, commit_msg: &CommitMessage) -> Re
|
|||||||
|
|
||||||
// Cache the process
|
// Cache the process
|
||||||
lock_processes()?.insert(
|
lock_processes()?.insert(
|
||||||
root_commitment,
|
process_id,
|
||||||
new_process,
|
new_process.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Dump to disk
|
// Dump to disk
|
||||||
dump_cached_processes()?;
|
dump_cached_processes()?;
|
||||||
|
|
||||||
// Add to frozen UTXOs
|
// Add to frozen UTXOs
|
||||||
lock_freezed_utxos()?.insert(root_commitment);
|
lock_freezed_utxos()?.insert(process_id);
|
||||||
|
|
||||||
Ok(root_commitment)
|
// Send an update to all connected client
|
||||||
|
let our_sp_address = WALLET
|
||||||
|
.get()
|
||||||
|
.ok_or(Error::msg("Wallet not initialized"))?
|
||||||
|
.get_wallet()?
|
||||||
|
.get_client()
|
||||||
|
.get_receiving_address();
|
||||||
|
let mut new_process_map = HashMap::new();
|
||||||
|
new_process_map.insert(process_id, new_process);
|
||||||
|
let init_msg = HandshakeMessage::new(
|
||||||
|
our_sp_address,
|
||||||
|
OutPointMemberMap(HashMap::new()),
|
||||||
|
OutPointProcessMap(new_process_map),
|
||||||
|
);
|
||||||
|
|
||||||
|
if let Err(e) = broadcast_message(
|
||||||
|
AnkFlag::Handshake,
|
||||||
|
format!("{}", init_msg.to_string()),
|
||||||
|
BroadcastType::ToAll
|
||||||
|
)
|
||||||
|
{
|
||||||
|
log::error!("Failed to send handshake message: {}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(process_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static MEMBERLIST: OnceLock<Mutex<HashMap<OutPoint, Member>>> = OnceLock::new();
|
pub static MEMBERLIST: OnceLock<Mutex<HashMap<OutPoint, Member>>> = OnceLock::new();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user