Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
haiyizxx committed Aug 30, 2023
1 parent f873d9a commit d7a03ef
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
6 changes: 3 additions & 3 deletions ampd/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use serde::Deserialize;

use crate::broadcaster;
use crate::evm::{deserialize_evm_chain_configs, EvmChainConfig};
use crate::handlers::multisig::MultisigConfig;
use crate::tofnd::Config as TofndConfig;
use crate::types::TMAddress;
use crate::url::Url;
use crate::ECDSASigningKey;

Expand All @@ -19,7 +19,7 @@ pub struct Config {
#[serde(with = "hex")]
pub private_key: ECDSASigningKey,
pub event_buffer_cap: usize,
pub multisig_contract: Option<TMAddress>,
pub multisig: Option<MultisigConfig>,
}

impl Default for Config {
Expand All @@ -32,7 +32,7 @@ impl Default for Config {
tofnd_config: TofndConfig::default(),
private_key: ECDSASigningKey::random(),
event_buffer_cap: 100000,
multisig_contract: None,
multisig: None,
}
}
}
Expand Down
21 changes: 19 additions & 2 deletions ampd/src/handlers/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ use cosmrs::cosmwasm::MsgExecuteContract;
use cosmwasm_std::{HexBinary, Uint64};
use ecdsa::VerifyingKey;
use error_stack::{IntoReport, ResultExt};
use hex::FromHex;
use hex::{encode, FromHex};
use serde::de::Error as DeserializeError;
use serde::{Deserialize, Deserializer};
use tracing::info;

use events::Error::EventTypeMismatch;
use events_derive;
Expand All @@ -23,6 +24,11 @@ use crate::tofnd::MessageDigest;
use crate::types::PublicKey;
use crate::types::TMAddress;

#[derive(Debug, Deserialize)]
pub struct MultisigConfig {
pub address: TMAddress,
}

#[derive(Debug, Deserialize)]
#[try_from("wasm-signing_started")]
struct SigningStartedEvent {
Expand Down Expand Up @@ -137,6 +143,12 @@ where
return Ok(());
}

info!(
session_id = session_id,
msg = encode(&msg),
"get signing request",
);

return match pub_keys.get(&self.worker) {
Some(pub_key) => {
let signature = self
Expand All @@ -145,11 +157,16 @@ where
.await
.change_context(Error::Sign)?;

info!(signature = encode(&signature), "ready to submit signature");

self.broadcast_signature(session_id, signature).await?;

Ok(())
}
None => Ok(()),
None => {
info!("worker is not a participant");
Ok(())
}
};
}
}
Expand Down
11 changes: 6 additions & 5 deletions ampd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use queue::queued_broadcaster::{QueuedBroadcaster, QueuedBroadcasterDriver};
use report::Error;
use state::StateUpdater;
use tofnd::grpc::{MultisigClient, SharableEcdsaClient};
use handlers::multisig::MultisigConfig;
use types::TMAddress;

mod broadcaster;
Expand Down Expand Up @@ -47,7 +48,7 @@ pub async fn run(cfg: Config, state_path: PathBuf) -> Result<(), Error> {
tofnd_config,
private_key,
event_buffer_cap,
multisig_contract,
multisig,
} = cfg;

let tm_client =
Expand Down Expand Up @@ -102,7 +103,7 @@ pub async fn run(cfg: Config, state_path: PathBuf) -> Result<(), Error> {
)
.configure_evm_chains(&worker, evm_chains)
.await?
.configure_multisig(&worker, multisig_contract)
.configure_multisig(&worker, multisig)
.await
.run()
.await
Expand Down Expand Up @@ -186,14 +187,14 @@ where
async fn configure_multisig(
mut self,
worker: &TMAddress,
multisig: Option<TMAddress>,
multisig: Option<MultisigConfig>,
) -> App<T> {
if let Some(address) = multisig {
if let Some(config) = multisig {
self.register_handler(
"multisig-handler",
handlers::multisig::Handler::new(
worker.clone(),
address,
config.address,
self.broadcaster.client(),
self.ecdsa_client.clone(),
),
Expand Down
6 changes: 6 additions & 0 deletions ampd/src/tofnd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ impl From<[u8; 32]> for MessageDigest {
MessageDigest(digest)
}
}

impl AsRef<[u8]> for MessageDigest {
fn as_ref(&self) -> &[u8] {
&self.0
}
}

0 comments on commit d7a03ef

Please sign in to comment.