WithdrawConfirm

This commit is contained in:
debris 2017-08-13 16:15:14 +02:00
parent 0a54434a42
commit 7115b649ef
4 changed files with 33 additions and 4 deletions

View File

@ -18,7 +18,7 @@ enum DepositRelayState<T: Transport> {
future: JoinAll<Vec<CallResult<H256, T::Out>>>,
block: u64,
},
/// All deposits from given block has been relayed.
/// All deposits till given block has been relayed.
Yield(Option<u64>),
}

View File

@ -10,7 +10,7 @@ use database::Database;
use error::Error;
use self::deposit_relay::{DepositRelay, create_deposit_relay};
use self::withdraw_relay::WithdrawRelay;
use self::withdraw_confirm::WithdrawConfirm;
use self::withdraw_confirm::{WithdrawConfirm, create_withdraw_confirm};
#[derive(Clone, Copy)]
pub enum BridgeChecked {
@ -28,7 +28,7 @@ pub fn create_bridge<T: Transport + Clone>(app: Arc<App<T>>, init: &Database) ->
Bridge {
deposit_relay: create_deposit_relay(app.clone(), init),
withdraw_relay: { unimplemented!(); },
withdraw_confirm: { unimplemented!(); },
withdraw_confirm: create_withdraw_confirm(app.clone(), init),
state: BridgeStatus::Wait,
}
}

View File

@ -8,22 +8,44 @@ use web3::types::{H256, H520, Address, TransactionRequest};
use api::{self, LogStream};
use app::App;
use contracts::KovanWithdraw;
use database::Database;
use error::{Error, ErrorKind};
pub enum WithdrawConfirmState<T: Transport> {
/// State of withdraw confirmation.
enum WithdrawConfirmState<T: Transport> {
/// Withdraw confirm is waiting for logs.
Wait,
/// Signing withdraws.
SignWithraws {
withdraws: Vec<KovanWithdraw>,
future: JoinAll<Vec<CallResult<H520, T::Out>>>,
block: u64,
},
/// Confirming withdraws.
ConfirmWithdraws {
future: JoinAll<Vec<CallResult<H256, T::Out>>>,
block: u64,
},
/// All withdraws till given block has been confirmed.
Yield(Option<u64>),
}
pub fn create_withdraw_confirm<T: Transport + Clone>(app: Arc<App<T>>, init: &Database) -> WithdrawConfirm<T> {
let logs_init = api::LogStreamInit {
after: init.checked_withdraw_confirm,
poll_interval: app.config.testnet.poll_interval,
confirmations: app.config.testnet.required_confirmations,
filter: app.testnet_bridge().withdraws_filter(init.testnet_contract_address.clone()),
};
WithdrawConfirm {
logs: api::log_stream(app.connections.testnet.clone(), logs_init),
testnet_contract: init.testnet_contract_address.clone(),
state: WithdrawConfirmState::Wait,
app,
}
}
pub struct WithdrawConfirm<T: Transport> {
app: Arc<App<T>>,
logs: LogStream<T>,

View File

@ -45,6 +45,13 @@ impl<'a> KovanBridge<'a> {
Ok(result)
}
pub fn withdraws_filter(&self, address: Address) -> FilterBuilder {
let event = self.0.event("Withdraw").expect("to find event `Withdraw`");
FilterBuilder::default()
.address(vec![address])
.topics(Some(vec![H256(event.signature())]), None, None, None)
}
pub fn withdraw_from_log(&self, log: Log) -> Result<KovanWithdraw, Error> {
let event = self.0.event("Withdraw").expect("to find event `Withdraw`");
let mut decoded = event.decode_log(