Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions Cargo.lock

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

14 changes: 10 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
resolver = "2"

members = [
"crates/aptos-rust-sdk",
"crates/aptos-rust-sdk-types",
"crates/aptos-crypto",
"crates/aptos-crypto-derive",
"crates/aptos-rust-sdk",
"crates/aptos-rust-sdk-types",
"crates/aptos-txn-worker",
"crates/examples"
]

Expand All @@ -15,10 +16,11 @@ members = [
#
# For more, see the "Conditional compilation for tests" section in documentation/coding_guidelines.md.
default-members = [
"crates/aptos-crypto",
"crates/aptos-crypto-derive",
"crates/aptos-rust-sdk",
"crates/aptos-rust-sdk-types",
"crates/aptos-crypto",
"crates/aptos-crypto-derive"
"crates/aptos-txn-worker",
]

# All workspace members should inherit these keys
Expand Down Expand Up @@ -47,6 +49,7 @@ anyhow = "1.0.97"
arbitrary = { version = "1.4.1", features = ["derive"] }
ark-bn254 = "0.5.0"
ark-ff = "0.5.0"
async-trait = "0.1.88"
base64 = "0.22.1"
bcs = { git = "https://github.com/aptos-labs/bcs.git", rev = "d31fab9d81748e2594be5cd5cdf845786a30562d" }
bitvec = "1.0.1"
Expand Down Expand Up @@ -93,8 +96,11 @@ static_assertions = "1.1.0"
syn = { version = "1.0.109", features = ["derive", "extra-traits"] }
thiserror = "2.0.12"
tiny-keccak = { version = "2.0.2", features = ["keccak", "sha3"] }
tracing = "0.1.41"
trybuild = "1.0.104"
tokio = { version = "1.44.1", features = ["full"] }
tokio-util = { version = "0.7.9", features = ["rt"] }
tokio-test = "0.4.3"
typenum = "1.18.0"
url = { version = "2.5.4", features = ["serde"] }

Expand Down
38 changes: 37 additions & 1 deletion crates/aptos-rust-sdk-types/src/api_types/account.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
use super::transaction_authenticator::AuthenticationKey;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use std::{fmt::Debug, str::FromStr};

#[derive(Debug)]
pub struct Account {
pub sequence_number: u64,
pub authentication_key: AuthenticationKey,
}

impl<'de> Deserialize<'de> for Account {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
#[derive(Deserialize)]
struct RawAccount {
sequence_number: String,
authentication_key: String,
}

let raw = RawAccount::deserialize(deserializer)?;

let sequence_number = raw.sequence_number.parse::<u64>().map_err(|e| {
serde::de::Error::custom(format!("Failed to parse sequence_number: {}", e))
})?;

let authentication_key =
AuthenticationKey::from_str(&raw.authentication_key).map_err(|e| {
serde::de::Error::custom(format!("Failed to parse authentication_key: {}", e))
})?;

Ok(Account {
sequence_number,
authentication_key,
})
}
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AccountResource {
Expand Down
33 changes: 31 additions & 2 deletions crates/aptos-rust-sdk-types/src/api_types/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,36 @@ pub struct RawTransaction {
chain_id: ChainId,
}

impl RawTransaction {
pub fn get_sender(&self) -> AccountAddress {
self.sender
}

pub fn get_sequence_number(&self) -> u64 {
self.sequence_number
}

pub fn get_payload(&self) -> &TransactionPayload {
&self.payload
}

pub fn get_max_gas_amount(&self) -> u64 {
self.max_gas_amount
}

pub fn get_gas_unit_price(&self) -> u64 {
self.gas_unit_price
}

pub fn get_expiration_timestamp_secs(&self) -> u64 {
self.expiration_timestamp_secs
}

pub fn get_chain_id(&self) -> ChainId {
self.chain_id
}
}

/// Different kinds of transactions.
#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
pub enum TransactionPayload {
Expand Down Expand Up @@ -253,7 +283,7 @@ impl GenerateSigningMessage for RawTransactionWithData {
message.extend(hash);
message.extend(bytes);
Ok(message)
}
}
}

impl SignedTransaction {
Expand Down Expand Up @@ -319,7 +349,6 @@ impl GenerateSigningMessage for RawTransaction {
message.extend(bytes);
Ok(message)
}

}

impl EntryFunction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ impl FromStr for AuthenticationKey {
!s.is_empty(),
"authentication key string should not be empty.",
);
let s = if s.starts_with("0x") { &s[2..] } else { s };
let bytes_out = ::hex::decode(s)?;
let key = AuthenticationKey::try_from(bytes_out.as_slice())?;
Ok(key)
Expand Down
21 changes: 20 additions & 1 deletion crates/aptos-rust-sdk/src/client/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,31 @@ const TESTNET_INDEXER_URL: &str = "https://api.testnet.aptoslabs.com";
const DEVNET_INDEXER_URL: &str = "https://api.devnet.aptoslabs.com";
const LOCAL_INDEXER_URL: &str = "http://127.0.0.1:8090";

const TESTNET_FAUCET_URL: &str = "https://faucet.testnet.aptoslabs.com";
const DEVNET_FAUCET_URL: &str = "https://faucet.devnet.aptoslabs.com";
const LOCAL_FAUCET_URL: &str = "http://127.0.0.1:8081";

/// An immutable definition of a network configuration
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct AptosNetwork {
name: &'static str,
rest_url: Url,
indexer_url: Url,
faucet_url: Option<Url>,
}

impl AptosNetwork {
pub const fn new(name: &'static str, rest_url: Url, indexer_url: Url) -> AptosNetwork {
pub const fn new(
name: &'static str,
rest_url: Url,
indexer_url: Url,
faucet_url: Option<Url>,
) -> AptosNetwork {
AptosNetwork {
name,
rest_url,
indexer_url,
faucet_url,
}
}

Expand All @@ -32,6 +43,7 @@ impl AptosNetwork {
"mainnet",
Url::parse(MAINNET_REST_URL).unwrap(),
Url::parse(MAINNET_INDEXER_URL).unwrap(),
None,
)
}

Expand All @@ -40,6 +52,7 @@ impl AptosNetwork {
"testnet",
Url::parse(TESTNET_REST_URL).unwrap(),
Url::parse(TESTNET_INDEXER_URL).unwrap(),
Some(Url::parse(TESTNET_FAUCET_URL).unwrap()),
)
}

Expand All @@ -48,6 +61,7 @@ impl AptosNetwork {
"devnet",
Url::parse(DEVNET_REST_URL).unwrap(),
Url::parse(DEVNET_INDEXER_URL).unwrap(),
Some(Url::parse(DEVNET_FAUCET_URL).unwrap()),
)
}

Expand All @@ -56,6 +70,7 @@ impl AptosNetwork {
"localnet",
Url::parse(LOCAL_REST_URL).unwrap(),
Url::parse(LOCAL_INDEXER_URL).unwrap(),
Some(Url::parse(LOCAL_FAUCET_URL).unwrap()),
)
}

Expand All @@ -70,4 +85,8 @@ impl AptosNetwork {
pub fn indexer_url(&self) -> &Url {
&self.indexer_url
}

pub fn faucet_url(&self) -> Option<&Url> {
self.faucet_url.as_ref()
}
}
Loading