Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
Tranduy1dol committed Aug 19, 2024
1 parent 49c0999 commit f116fa2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion crates/settlement-clients/aptos/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::time::SystemTime;

use aptos_sdk::transaction_builder::TransactionBuilder;
use aptos_sdk::types::chain_id::ChainId;
use aptos_sdk::types::LocalAccount;
use aptos_sdk::types::transaction::{SignedTransaction, TransactionPayload};
use aptos_sdk::types::LocalAccount;

pub(crate) fn build_transaction(
payload: TransactionPayload,
Expand Down
42 changes: 22 additions & 20 deletions crates/settlement-clients/aptos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use aptos_sdk::move_types::account_address::AccountAddress;
use aptos_sdk::move_types::identifier::Identifier;
use aptos_sdk::move_types::language_storage::ModuleId;
use aptos_sdk::move_types::u256::U256;
use aptos_sdk::move_types::value::{MoveValue, serialize_values};
use aptos_sdk::move_types::value::{serialize_values, MoveValue};
use aptos_sdk::rest_client::aptos_api_types::{EntryFunctionId, ViewRequest};
use aptos_sdk::rest_client::Client;
use aptos_sdk::types::chain_id::ChainId;
use aptos_sdk::types::LocalAccount;
use aptos_sdk::types::transaction::{EntryFunction, TransactionPayload};
use aptos_sdk::types::LocalAccount;
use async_trait::async_trait;
use color_eyre::eyre;
use mockall::automock;
Expand Down Expand Up @@ -56,20 +56,6 @@ impl SettlementClient for AptosSettlementClient {
unimplemented!("hee-hee")
}

#[allow(unused)]
async fn update_state_with_blobs(
&self,
program_output: Vec<[u8; 32]>,
state_diff: Vec<Vec<u8>>,
) -> color_eyre::Result<String> {
unimplemented!("hee-hee")
}

#[allow(unused)]
async fn wait_for_tx_finality(&self, tx_hash: &str) -> color_eyre::Result<()> {
unimplemented!("hee-hee")
}

async fn update_state_calldata(
&self,
program_output: Vec<[u8; 32]>,
Expand Down Expand Up @@ -107,6 +93,15 @@ impl SettlementClient for AptosSettlementClient {
Ok(tx.transaction_info().unwrap().hash.to_string())
}

#[allow(unused)]
async fn update_state_with_blobs(
&self,
program_output: Vec<[u8; 32]>,
state_diff: Vec<Vec<u8>>,
) -> color_eyre::Result<String> {
unimplemented!("hee-hee")
}

async fn update_state_blobs(
&self,
program_output: Vec<[u8; 32]>,
Expand Down Expand Up @@ -142,7 +137,7 @@ impl SettlementClient for AptosSettlementClient {
async fn verify_tx_inclusion(&self, tx_hash: &str) -> eyre::Result<SettlementVerificationStatus> {
let client = self.client.clone();

let hash = HashValue::from_str(tx_hash.strip_prefix("0x").expect("Hash bullshit!")).unwrap();
let hash = HashValue::from_str(tx_hash.strip_prefix("0x").unwrap())?;
let txn = client.get_transaction_by_hash(hash).await?;

let response = txn.into_inner();
Expand All @@ -152,6 +147,11 @@ impl SettlementClient for AptosSettlementClient {
}
}

#[allow(unused)]
async fn wait_for_tx_finality(&self, tx_hash: &str) -> color_eyre::Result<()> {
unimplemented!("hee-hee")
}

async fn get_last_settled_block(&self) -> eyre::Result<u64> {
let client = &self.client;
let request = ViewRequest {
Expand All @@ -171,8 +171,7 @@ impl SettlementClient for AptosSettlementClient {
let response = client.view(&request, None).await?.into_inner();

let block_number = response.first().unwrap().as_str().unwrap();
eprintln!("block_number = {:#?}", block_number);
Ok(block_number.parse::<u64>().unwrap())
Ok(block_number.parse::<u64>()?)
}
}

Expand All @@ -187,9 +186,9 @@ mod test {

use settlement_client_interface::{SettlementClient, SettlementVerificationStatus};

use crate::{AptosSettlementClient, STARKNET_VALIDITY};
use crate::config::AptosSettlementConfig;
use crate::helper::build_transaction;
use crate::{AptosSettlementClient, STARKNET_VALIDITY};

use super::*;

Expand Down Expand Up @@ -297,6 +296,9 @@ mod test {
let verify_inclusion = settlement_client.verify_tx_inclusion(result.as_str()).await.unwrap();
eprintln!("verify_inclusion = {:#?}", verify_inclusion);
assert_eq!(verify_inclusion, SettlementVerificationStatus::Verified);

let block_number = settlement_client.get_last_settled_block().await.unwrap();
eprintln!("block_number = {:#?}", block_number);
Ok(())
})
})
Expand Down

0 comments on commit f116fa2

Please sign in to comment.