Skip to content

Commit

Permalink
fix(claimer): fix duplicate checker verification
Browse files Browse the repository at this point in the history
  • Loading branch information
GMKrieger committed Nov 14, 2023
1 parent 086047a commit 316c866
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
34 changes: 22 additions & 12 deletions offchain/authority-claimer/src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

use async_trait::async_trait;
use contracts::authority::Authority;
use contracts::history::History;
use ethers::{
self,
abi::AbiEncode,
contract::ContractError,
providers::{Http, HttpRateLimitRetryPolicy, Provider, RetryClient},
types::{H160, U256},
};
Expand Down Expand Up @@ -37,16 +38,14 @@ pub trait DuplicateChecker: Debug {

#[derive(Debug)]
pub struct DefaultDuplicateChecker {
authority: Authority<Provider<RetryClient<Http>>>,
history: History<Provider<RetryClient<Http>>>,
}

#[derive(Debug, Snafu)]
pub enum DuplicateCheckerError {
#[snafu(display("invalid provider URL"))]
ContractError {
source: ethers::contract::ContractError<
ethers::providers::Provider<RetryClient<Http>>,
>,
source: ContractError<ethers::providers::Provider<RetryClient<Http>>>,
},

#[snafu(display("parser error"))]
Expand All @@ -56,7 +55,7 @@ pub enum DuplicateCheckerError {
impl DefaultDuplicateChecker {
pub fn new(
http_endpoint: String,
authority_address: Address,
history_address: Address,
) -> Result<Self, DuplicateCheckerError> {
let http = Http::new(Url::parse(&http_endpoint).context(ParseSnafu)?);

Expand All @@ -69,12 +68,10 @@ impl DefaultDuplicateChecker {

let provider = Arc::new(Provider::new(retry_client));

let authority = Authority::new(
H160(authority_address.inner().to_owned()),
provider,
);
let history =
History::new(H160(history_address.inner().to_owned()), provider);

Ok(Self { authority })
Ok(Self { history })
}
}

Expand All @@ -90,8 +87,21 @@ impl DuplicateChecker for DefaultDuplicateChecker {
let proof_context =
U256([rollups_claim.epoch_index, 0, 0, 0]).encode().into();

let claims = self
.history
.new_claim_to_history_filter()
.query()
.await
.context(ContractSnafu)?;

info!(">>>>>>>>> CLAIMS {:?}", claims);

// for claim in claims {
// info!(">>>>>>>>> {:?}", claim.claim);
// }

match self
.authority
.history
.get_claim(H160(dapp_address.inner().to_owned()), proof_context)
.block(ethers::types::BlockNumber::Latest)
.call()
Expand Down
2 changes: 1 addition & 1 deletion offchain/authority-claimer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub async fn run(config: Config) -> Result<(), Box<dyn Error>> {
trace!("Creating the duplicate checker");
let duplicate_checker = DefaultDuplicateChecker::new(
config.tx_manager_config.provider_http_endpoint.clone(),
config.blockchain_config.authority_address.clone(),
config.blockchain_config.history_address.clone(),
)?;

// Creating the transaction sender.
Expand Down

0 comments on commit 316c866

Please sign in to comment.