Skip to content

Commit 82e9c57

Browse files
committed
Add transaction worker
1 parent 6cb9a8d commit 82e9c57

File tree

13 files changed

+1510
-45
lines changed

13 files changed

+1510
-45
lines changed

Cargo.lock

Lines changed: 93 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
resolver = "2"
33

44
members = [
5-
"crates/aptos-rust-sdk",
6-
"crates/aptos-rust-sdk-types",
75
"crates/aptos-crypto",
86
"crates/aptos-crypto-derive",
7+
"crates/aptos-rust-sdk",
8+
"crates/aptos-rust-sdk-types",
9+
"crates/aptos-txn-worker",
910
"crates/examples"
1011
]
1112

@@ -15,10 +16,11 @@ members = [
1516
#
1617
# For more, see the "Conditional compilation for tests" section in documentation/coding_guidelines.md.
1718
default-members = [
19+
"crates/aptos-crypto",
20+
"crates/aptos-crypto-derive",
1821
"crates/aptos-rust-sdk",
1922
"crates/aptos-rust-sdk-types",
20-
"crates/aptos-crypto",
21-
"crates/aptos-crypto-derive"
23+
"crates/aptos-txn-worker",
2224
]
2325

2426
# All workspace members should inherit these keys
@@ -47,6 +49,7 @@ anyhow = "1.0.97"
4749
arbitrary = { version = "1.4.1", features = ["derive"] }
4850
ark-bn254 = "0.5.0"
4951
ark-ff = "0.5.0"
52+
async-trait = "0.1.88"
5053
base64 = "0.22.1"
5154
bcs = { git = "https://github.com/aptos-labs/bcs.git", rev = "d31fab9d81748e2594be5cd5cdf845786a30562d" }
5255
bitvec = "1.0.1"
@@ -93,8 +96,10 @@ static_assertions = "1.1.0"
9396
syn = { version = "1.0.109", features = ["derive", "extra-traits"] }
9497
thiserror = "2.0.12"
9598
tiny-keccak = { version = "2.0.2", features = ["keccak", "sha3"] }
99+
tracing = "0.1.41"
96100
trybuild = "1.0.104"
97101
tokio = { version = "1.44.1", features = ["full"] }
102+
tokio-util = { version = "0.7.9", features = ["rt"] }
98103
typenum = "1.18.0"
99104
url = { version = "2.5.4", features = ["serde"] }
100105

crates/aptos-rust-sdk-types/src/api_types/account.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,41 @@
1+
use super::transaction_authenticator::AuthenticationKey;
12
use serde::{Deserialize, Serialize};
2-
use std::fmt::Debug;
3+
use std::{fmt::Debug, str::FromStr};
4+
5+
#[derive(Debug)]
6+
pub struct Account {
7+
pub sequence_number: u64,
8+
pub authentication_key: AuthenticationKey,
9+
}
10+
11+
impl<'de> Deserialize<'de> for Account {
12+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
13+
where
14+
D: serde::Deserializer<'de>,
15+
{
16+
#[derive(Deserialize)]
17+
struct RawAccount {
18+
sequence_number: String,
19+
authentication_key: String,
20+
}
21+
22+
let raw = RawAccount::deserialize(deserializer)?;
23+
24+
let sequence_number = raw.sequence_number.parse::<u64>().map_err(|e| {
25+
serde::de::Error::custom(format!("Failed to parse sequence_number: {}", e))
26+
})?;
27+
28+
let authentication_key =
29+
AuthenticationKey::from_str(&raw.authentication_key).map_err(|e| {
30+
serde::de::Error::custom(format!("Failed to parse authentication_key: {}", e))
31+
})?;
32+
33+
Ok(Account {
34+
sequence_number,
35+
authentication_key,
36+
})
37+
}
38+
}
339

440
#[derive(Debug, Serialize, Deserialize)]
541
pub struct AccountResource {

crates/aptos-rust-sdk-types/src/api_types/transaction.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,36 @@ pub struct RawTransaction {
131131
chain_id: ChainId,
132132
}
133133

134+
impl RawTransaction {
135+
pub fn get_sender(&self) -> AccountAddress {
136+
self.sender
137+
}
138+
139+
pub fn get_sequence_number(&self) -> u64 {
140+
self.sequence_number
141+
}
142+
143+
pub fn get_payload(&self) -> &TransactionPayload {
144+
&self.payload
145+
}
146+
147+
pub fn get_max_gas_amount(&self) -> u64 {
148+
self.max_gas_amount
149+
}
150+
151+
pub fn get_gas_unit_price(&self) -> u64 {
152+
self.gas_unit_price
153+
}
154+
155+
pub fn get_expiration_timestamp_secs(&self) -> u64 {
156+
self.expiration_timestamp_secs
157+
}
158+
159+
pub fn get_chain_id(&self) -> ChainId {
160+
self.chain_id
161+
}
162+
}
163+
134164
/// Different kinds of transactions.
135165
#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
136166
pub enum TransactionPayload {
@@ -264,6 +294,46 @@ impl SignedTransaction {
264294
}
265295
}
266296

297+
/// Create a new signed transaction with a fee payer. Use this as the fee payer, if
298+
/// you are just creating a transaction to be signed by a fee payer later, use
299+
/// `new_for_future_fee_payer`.
300+
pub fn new_as_fee_payer(
301+
raw_txn: RawTransaction,
302+
sender: AccountAuthenticator,
303+
secondary_signer_addresses: Vec<AccountAddress>,
304+
secondary_signers: Vec<AccountAuthenticator>,
305+
fee_payer_address: AccountAddress,
306+
fee_payer_authenticator: AccountAuthenticator,
307+
) -> Self {
308+
let authenticator = TransactionAuthenticator::FeePayer {
309+
sender,
310+
secondary_signer_addresses,
311+
secondary_signers,
312+
fee_payer: FeePayerAuthenticator {
313+
address: fee_payer_address,
314+
// This gets ignored for the gas station use case.
315+
authenticator: fee_payer_authenticator,
316+
},
317+
};
318+
SignedTransaction::new(raw_txn, authenticator)
319+
}
320+
321+
/// Create a new signed transaction, indicating that a fee payer will be set later.
322+
/// If you want to actually sign as a fee payer, use `new_as_fee_payer`.
323+
pub fn new_for_future_fee_payer(raw_txn: RawTransaction, sender: AccountAuthenticator) -> Self {
324+
let authenticator = TransactionAuthenticator::FeePayer {
325+
sender,
326+
secondary_signer_addresses: vec![],
327+
secondary_signers: vec![],
328+
fee_payer: FeePayerAuthenticator {
329+
address: AccountAddress::ZERO,
330+
// This gets ignored for the future fee payer use case.
331+
authenticator: AccountAuthenticator::NoAuthenticator { },
332+
},
333+
};
334+
SignedTransaction::new(raw_txn, authenticator)
335+
}
336+
267337
pub fn raw_txn(&self) -> &RawTransaction {
268338
&self.raw_txn
269339
}

0 commit comments

Comments
 (0)