Skip to content

Commit

Permalink
fix: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 committed Apr 30, 2024
1 parent 7edef68 commit 0d34144
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,6 @@ cargo run -- account-balance --interval 2.0 -c polygon -a 0x75be52afd54a13b6c984

# Example attestation

http://127.0.0.1:8080/erc20/api/attestation/sepolia/0x1d542735c2be213e64e3eff427efad256d27ac1dc9fabb6e5507d2e89cdd1717

http://deposit.dev.golem.network:15555/erc20/api/attestation/sepolia/0xeb9b088871155d0ae32f382de5a42d0a64e946f512b722698f4ae6b32164f92d
http://deposit.dev.golem.network:15555/erc20/api/attestation/sepolia/0xc8b0ceee393cdcf313945d20b3bd45a01b0ccf2484309b669da2d4da9266b4d5
2 changes: 1 addition & 1 deletion crates/erc20_payment_lib/config-payments.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ currency-symbol = "ETH"
priority-fee = 0.000001
max-fee-per-gas = 20.0
transaction-timeout = 100
attestation-contract = { address = "0x357458739f90461b99789350868cd7cf330dd7ee" }
attestation-contract = { address = "0x4200000000000000000000000000000000000021" }
schema-registry-contract = { address = "0x4200000000000000000000000000000000000020" }
token = { address = "0x1200000000000000000000000000000000000021", symbol = "GLM" }
confirmation-blocks = 0
Expand Down
9 changes: 6 additions & 3 deletions crates/erc20_payment_lib/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub async fn get_schema_details(
))?;

let decoded = decoded[0].clone().into_tuple().unwrap();
log::info!("Decoded attestation: {:?}", decoded);
log::info!("Decoded attestation schema: {:?}", decoded);
let schema = AttestationSchema {
uid: H256::from_slice(decoded[0].clone().into_fixed_bytes().unwrap().as_slice()),
resolver: decoded[1].clone().into_address().unwrap(),
Expand Down Expand Up @@ -177,7 +177,7 @@ pub async fn get_attestation_details(
web3: Arc<Web3RpcPool>,
uid: H256,
eas_contract_address: Address,
) -> Result<Attestation, PaymentError> {
) -> Result<Option<Attestation>, PaymentError> {
let res = web3
.eth_call(
CallRequest {
Expand Down Expand Up @@ -214,6 +214,9 @@ pub async fn get_attestation_details(
))?;

let decoded = decoded[0].clone().into_tuple().unwrap();
if decoded[0] == ethabi::Token::FixedBytes(vec![0; 32]) {
return Ok(None);
}
log::info!("Decoded attestation: {:?}", decoded);
let attestation = Attestation {
uid: H256::from_slice(decoded[0].clone().into_fixed_bytes().unwrap().as_slice()),
Expand All @@ -229,7 +232,7 @@ pub async fn get_attestation_details(
data: Bytes::from(decoded[9].clone().into_bytes().unwrap()),
};

Ok(attestation)
Ok(Some(attestation))
}

pub async fn get_deposit_details(
Expand Down
20 changes: 11 additions & 9 deletions crates/erc20_payment_lib/src/server/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,13 @@ pub async fn check_attestation(
log::info!("Querying attestation contract: {:#x}", contract.address);

let attestation = match get_attestation_details(web3.clone(), uid, contract.address).await {
Ok(attestation) => attestation,
Ok(Some(attestation)) => attestation,
Ok(None) => {
return Err(ErrorBadRequest(format!(
"Attestation with uid: {:#x} not found on chain {}",
uid, chain_name
)));
}
Err(e) => {
log::error!("Failed to get attestation details: {}", e);
return Err(ErrorBadRequest(format!(
Expand Down Expand Up @@ -1343,17 +1349,13 @@ pub async fn check_attestation(
)))?
);

let items = attestation_schema
.schema
.split(",")
.into_iter()
.collect::<Vec<&str>>();
let items = attestation_schema.schema.split(',').collect::<Vec<&str>>();
log::debug!("There are {} items in the schema", items.len());
let mut param_types = Vec::new();
let mut param_names = Vec::new();

for item in items {
let items2 = item.trim().split(" ").into_iter().collect::<Vec<&str>>();
let items2 = item.trim().split(' ').collect::<Vec<&str>>();
if items2.len() != 2 {
log::error!("Invalid item in schema: {}", item);
return Err(ErrorBadRequest(format!("Invalid item in schema: {}", item)));
Expand Down Expand Up @@ -1385,13 +1387,13 @@ pub async fn check_attestation(
});
}

return Ok(web::Json(AttestationCheckResult {
Ok(web::Json(AttestationCheckResult {
chain_id: chain.chain_id as u64,
chain: chain_name.to_string(),
attestation,
schema: attestation_schema,
params: decoded_items,
}));
}))
}

pub fn runtime_web_scope(
Expand Down
9 changes: 8 additions & 1 deletion src/actions/attestation/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ pub async fn check_attestation_local(
log::info!("Querying attestation contract: {:#x}", contract.address);

let attestation = match get_attestation_details(web3.clone(), uid, contract.address).await {
Ok(attestation) => attestation,
Ok(Some(attestation)) => attestation,
Ok(None) => {
return Err(err_custom_create!(
"Attestation with uid: {:#x} not found on chain {}",
uid,
options.chain_name
));
}
Err(e) => {
log::error!("Failed to get attestation details: {}", e);
return Err(err_custom_create!(
Expand Down

0 comments on commit 0d34144

Please sign in to comment.