wait for transfer/withdraw txs to be verified
@@ -355,7 +355,20 @@ async fn wait_for_verify(sent_txs: SentTransactions, timeout: Duration) {
}
}
}
- // let tx_hashes = sent_txs.tx_hashes.lock().unwrap();
+ let tx_hashes = sent_txs.tx_hashes.lock().unwrap();
+ for hash in tx_hashes.iter() {
+ loop {
+ let verified = tx_info(hash.clone())
+ .await
+ .expect("[wait_for_verify] call tx_info");
+ if verified {
+ break;
+ }
+ if start.elapsed() > timeout {
+ panic!("[wait_for_verify] timeout")
+ }
+ }
+ }
}
#[derive(Serialize)]
@@ -404,3 +417,50 @@ async fn ethop_info(serial_id: u64) -> Result<(bool, bool), failure::Error> {
let verified = block["verified"].as_bool().unwrap();
Ok((executed, verified))
}
+
+#[derive(Serialize)]
+struct TxInfo {
+ id: String,
+ method: String,
+ jsonrpc: String,
+ params: Vec<TxHash>,
+}
+
+impl TxInfo {
+ fn new(h: TxHash) -> Self {
+ Self {
+ id: "4".to_owned(),
+ method: "tx_info".to_owned(),
+ jsonrpc: "2.0".to_owned(),
+ params: vec![h],
+ }
+ }
+}
+
+// requests and returns whether transaction is verified or not.
+async fn tx_info(tx_hash: TxHash) -> Result<bool, failure::Error> {
+ let msg = TxInfo::new(tx_hash);
+
+ let client = reqwest::Client::new();
+ let mut res = client
+ .post("http://localhost:3030")
+ .json(&msg)
+ .send()
+ .expect("failed to send ethop_info");
+ if res.status() != reqwest::StatusCode::OK {
+ failure::bail!("non-ok response: {}", res.status());
+ }
+ let reply: Output = res.json().unwrap();
+ let ret = match reply {
+ Output::Success(v) => v.result,
+ Output::Failure(v) => panic!("{}", v.error),
+ };
+ let obj = ret.as_object().unwrap();
+ let executed = obj["executed"].as_bool().unwrap();
+ if !executed {
+ return Ok(false);
+ }
+ let block = obj["block"].as_object().unwrap();
+ let verified = block["verified"].as_bool().unwrap();
+ Ok(verified)
+}
