-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathbatcher_payment_service.rs
More file actions
33 lines (25 loc) · 1.03 KB
/
batcher_payment_service.rs
File metadata and controls
33 lines (25 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use std::sync::Arc;
use ethers::{core::k256::ecdsa::SigningKey, prelude::*};
use crate::common::errors::VerificationError;
abigen!(
BatcherPaymentServiceContract,
"abi/BatcherPaymentService.json"
);
pub type BatcherPaymentService = BatcherPaymentServiceContract<Provider<Http>>;
pub type SignerMiddlewareT = SignerMiddleware<Provider<Http>, Wallet<SigningKey>>;
pub type BatcherPaymentServiceWithSigner = BatcherPaymentServiceContract<SignerMiddlewareT>;
pub async fn batcher_payment_service(
provider: Provider<Http>,
contract_address: H160,
) -> Result<BatcherPaymentService, VerificationError> {
let client = Arc::new(provider);
// Verify that the contract has code at the given address
let code = client
.get_code(contract_address, None)
.await
.map_err(|e| VerificationError::EthereumProviderError(e.to_string()))?;
if code.is_empty() {
return Err(VerificationError::EthereumNotAContract(contract_address));
}
Ok(BatcherPaymentService::new(contract_address, client))
}