Skip to content

Commit

Permalink
fix: tx
Browse files Browse the repository at this point in the history
  • Loading branch information
zk-steve authored and Draply committed Sep 16, 2024
1 parent 8ecc0ca commit 221c958
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 64 deletions.
85 changes: 73 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ tokio = { version = "1.39.3", features = ["macros", "rt-multi-thread"] }
url = { version = "2.4.0", features = ["serde"] }

[dev-dependencies]
aptos-testcontainer = { git = "https://github.com/sota-zk-labs/aptos-testcontainer.git", tag = "v0.1.0", features = [
"testing",
] }
aptos-testcontainer = { version = "0.1.2", features = ["testing"] }

[patch.crates-io]
merlin = { git = "https://github.com/aptos-labs/merlin" }
Expand Down
2 changes: 1 addition & 1 deletion contracts/navori
59 changes: 30 additions & 29 deletions src/contracts_caller/gps/verify_proof_and_register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use aptos_sdk::move_types::value::{serialize_values, MoveValue};
use aptos_sdk::rest_client::aptos_api_types::MoveType;
use aptos_sdk::rest_client::error::RestError;
use aptos_sdk::types::transaction::{EntryFunction, TransactionPayload};
use log::{debug, error, info};
use log::{debug, info};

use crate::config::AppConfig;
use crate::contracts_caller::gps::types::verify_proof_and_register::VerifyProofAndRegisterData;
use crate::contracts_caller::transaction_helper::{build_transaction, get_event_from_transaction};
use crate::error::CoreError::TransactionNotSucceed;
use crate::error::CoreError::{FlowNotFinished, TransactionNotSucceed};

pub async fn verify_proof_and_register(
config: &AppConfig,
Expand Down Expand Up @@ -115,42 +115,43 @@ pub async fn verify_proof_and_register(
.wait_for_transaction(&pending_transaction)
.await?
.into_inner();
let transaction_info = transaction.transaction_info()?;
ensure!(
transaction_info.success,
TransactionNotSucceed(format!("{}; hash: {}", name, transaction_info.hash))
);
info!(
"{} finished: id={}; hash={}; gas={}",
name,
transaction_info.version,
transaction_info.hash.to_string(),
transaction_info.gas_used,
);
Ok::<_, anyhow::Error>(transaction)
Ok::<_, anyhow::Error>((name, transaction))
})
})
.collect::<Vec<_>>();

let mut transactions = Vec::with_capacity(results.len());
for handle in results {
transactions.push(handle.await??);
let (name, transaction) = handle.await??;
let transaction_info = transaction.transaction_info()?;
ensure!(
transaction_info.success,
TransactionNotSucceed(format!("{}; hash: {}", name, transaction_info.hash))
);
info!(
"{} finished: id={}; hash={}; gas={}",
name,
transaction_info.version,
transaction_info.hash.to_string(),
transaction_info.gas_used,
);
transactions.push(transaction);
}

let last_transaction = transactions.last().unwrap();

// Get the event from the last transaction
if let Some(last_transaction) = transactions.last() {
let event = get_event_from_transaction(
last_transaction,
MoveType::from_str(&format!(
"{}::{}::VparFinished",
config.module_address, module_name
))?,
);
let event = get_event_from_transaction(
last_transaction,
MoveType::from_str(&format!(
"{}::{}::VparFinished",
config.module_address, module_name
))?,
);
ensure!(
event.is_ok(),
FlowNotFinished("verify_proof_and_register".to_string())
);

info!("Verify_proof_and_register {}", event.is_ok());
if event.is_err() {
error!("Some things went wrong!");
}
}
Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub async fn register_continuous_memory_page(
MoveValue::Vector(values),
MoveValue::U256(U256::from_str(&data.z)?),
MoveValue::U256(U256::from_str(&data.alpha)?),
MoveValue::U256(U256::from_str(&data.prime)?),
]),
));
let tx = build_transaction(payload, &config.account, config.chain_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@ pub async fn register_continuous_page_batch(
) -> anyhow::Result<()> {
let ContinuousMemoryPage {
z,
alpha,
prime,
values: _,
start_addr: _,
alpha, ..
} = data.memory_page_entries.first().unwrap();

let z = MoveValue::U256(U256::from_str(z)?);
let alpha = MoveValue::U256(U256::from_str(alpha)?);
let prime = MoveValue::U256(U256::from_str(prime)?);

let mut converted_data = data
.memory_page_entries
Expand Down Expand Up @@ -80,7 +76,6 @@ pub async fn register_continuous_page_batch(

let txs = chunks.into_iter().enumerate().map(|(i, chunk)| {
let (chunk_start_addr, chunk_values): (Vec<_>, Vec<_>) = chunk.into_iter().unzip();

let payload = TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
config.module_address,
Expand All @@ -93,7 +88,6 @@ pub async fn register_continuous_page_batch(
MoveValue::Vector(chunk_values),
z.clone(),
alpha.clone(),
prime.clone(),
]),
));
let tx = build_transaction(payload, &config.account, config.chain_id);
Expand Down
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pub enum CoreError {
#[error("transaction not succeed {0}")]
TransactionNotSucceed(String),

#[error("flow not finished {0}")]
FlowNotFinished(String),

#[error("not found")]
NotFound,

Expand Down
Loading

0 comments on commit 221c958

Please sign in to comment.