Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
format code
Browse files Browse the repository at this point in the history
Tranduy1dol authored and zk-steve committed Aug 12, 2024
1 parent a9ae2ef commit e487d53
Showing 5 changed files with 59 additions and 122 deletions.
146 changes: 39 additions & 107 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -58,7 +58,9 @@ stark_evm_adapter = "0.1.1"
hex = "0.4"
itertools = "0.13.0"
mockall = "0.12.1"
testcontainers = "0.18.0"
testcontainers = "0.21.1"
jemallocator = { package = "tikv-jemallocator", version = "0.5.4" }
aptos-testcontainer = { path = "../aptos-testcontainer" }

# Cairo VM
cairo-vm = { git = "https://github.com/lambdaclass/cairo-vm", features = [
2 changes: 2 additions & 0 deletions crates/da-clients/aptos/Cargo.toml
Original file line number Diff line number Diff line change
@@ -6,10 +6,12 @@ edition.workspace = true
[dependencies]
alloy = { workspace = true }
aptos-sdk = { workspace = true }
aptos-testcontainer = { workspace = true }
async-trait = { workspace = true }
c-kzg = { workspace = true }
color-eyre = { workspace = true }
da-client-interface = { workspace = true }
dotenvy = { workspace = true }
lazy_static = { workspace = true }
tokio = { workspace = true }
utils = { workspace = true }
14 changes: 3 additions & 11 deletions crates/da-clients/aptos/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
use std::path::Path;
use std::str::FromStr;

use aptos_sdk::crypto::ed25519::Ed25519PrivateKey;
use aptos_sdk::crypto::ValidCryptoMaterialStringExt;
use aptos_sdk::rest_client::Client;
use aptos_sdk::types::chain_id::ChainId;
use aptos_sdk::types::{AccountKey, LocalAccount};
use async_trait::async_trait;
use c_kzg::KzgSettings;
use dotenvy::dotenv;

use da_client_interface::DaConfig;
use utils::env_utils::get_env_var_or_panic;

use crate::helper::from_private_key;
use crate::AptosDaClient;

#[derive(Clone, Debug)]
pub struct AptosDaConfig {
pub node_url: String,
pub private_key: String,
pub account_address: String,
pub module_address: String,
pub chain_id: String,
pub trusted_setup: String,
@@ -31,21 +28,16 @@ impl DaConfig<AptosDaClient> for AptosDaConfig {
dotenv().expect("Failed to load .env file");
let node_url = get_env_var_or_panic("APTOS_NODE_URL");
let private_key = get_env_var_or_panic("APTOS_PRIVATE_KEY");
let account_address = get_env_var_or_panic("APTOS_ACCOUNT_ADDRESS");
let module_address = get_env_var_or_panic("APTOS_MODULE_ADDRESS");
let chain_id = get_env_var_or_panic("APTOS_CHAIN_ID");
let trusted_setup = get_env_var_or_panic("APTOS_CRS_PATH");

Self { chain_id, node_url, private_key, account_address, module_address, trusted_setup }
Self { chain_id, node_url, private_key, module_address, trusted_setup }
}

async fn build_client(&self) -> AptosDaClient {
let client = Client::new(self.node_url.parse().unwrap());
let private_key =
Ed25519PrivateKey::from_encoded_string(&self.private_key).expect("Failed to parse private key");
let account_key = AccountKey::from(private_key);
let account_address = self.account_address.parse().expect("Invalid account address");
let account = LocalAccount::new(account_address, account_key, 0);
let account = from_private_key(&self.private_key, 0).unwrap();
let module_address = self.module_address.parse().expect("Invalid module address");
let chain_id = ChainId::from_str(&self.chain_id).expect("Invalid chain id");
let trusted_setup =
15 changes: 12 additions & 3 deletions crates/da-clients/aptos/src/helper.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::time::SystemTime;

use alloy::hex;
use aptos_sdk::crypto::ed25519::Ed25519PrivateKey;
use aptos_sdk::transaction_builder::TransactionBuilder;
use aptos_sdk::types::chain_id::ChainId;
use aptos_sdk::types::transaction::{SignedTransaction, TransactionPayload};
use aptos_sdk::types::LocalAccount;
use aptos_sdk::types::{AccountKey, LocalAccount};
use std::time::SystemTime;

pub(crate) fn build_transaction(
payload: TransactionPayload,
@@ -23,3 +24,11 @@ pub(crate) fn build_transaction(
.build();
sender.sign_transaction(tx)
}

pub(crate) fn from_private_key(private_key: &str, sequencer_number: u64) -> color_eyre::Result<LocalAccount> {
let key = AccountKey::from_private_key(Ed25519PrivateKey::try_from(
hex::decode(private_key.trim_start_matches("0x"))?.as_ref(),
)?);
let address = key.authentication_key().account_address();
Ok(LocalAccount::new(address, key, sequencer_number))
}

0 comments on commit e487d53

Please sign in to comment.