Skip to content

Commit 9753574

Browse files
committed
Add transaction worker
1 parent 6de4b3c commit 9753574

File tree

14 files changed

+1520
-57
lines changed

14 files changed

+1520
-57
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: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use crate::api_types::write_set::WriteSet;
1010
use aptos_crypto_derive::{BCSCryptoHash, CryptoHasher};
1111
use serde::{Deserialize, Serialize};
1212

13+
use super::transaction_authenticator::{AccountAuthenticator, FeePayerAuthenticator};
14+
1315
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
1416
pub enum TransactionData {
1517
/// A committed transaction
@@ -124,6 +126,36 @@ pub struct RawTransaction {
124126
chain_id: ChainId,
125127
}
126128

129+
impl RawTransaction {
130+
pub fn get_sender(&self) -> AccountAddress {
131+
self.sender
132+
}
133+
134+
pub fn get_sequence_number(&self) -> u64 {
135+
self.sequence_number
136+
}
137+
138+
pub fn get_payload(&self) -> &TransactionPayload {
139+
&self.payload
140+
}
141+
142+
pub fn get_max_gas_amount(&self) -> u64 {
143+
self.max_gas_amount
144+
}
145+
146+
pub fn get_gas_unit_price(&self) -> u64 {
147+
self.gas_unit_price
148+
}
149+
150+
pub fn get_expiration_timestamp_secs(&self) -> u64 {
151+
self.expiration_timestamp_secs
152+
}
153+
154+
pub fn get_chain_id(&self) -> ChainId {
155+
self.chain_id
156+
}
157+
}
158+
127159
/// Different kinds of transactions.
128160
#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
129161
pub enum TransactionPayload {
@@ -219,6 +251,46 @@ impl SignedTransaction {
219251
}
220252
}
221253

254+
/// Create a new signed transaction with a fee payer. Use this as the fee payer, if
255+
/// you are just creating a transaction to be signed by a fee payer later, use
256+
/// `new_for_future_fee_payer`.
257+
pub fn new_as_fee_payer(
258+
raw_txn: RawTransaction,
259+
sender: AccountAuthenticator,
260+
secondary_signer_addresses: Vec<AccountAddress>,
261+
secondary_signers: Vec<AccountAuthenticator>,
262+
fee_payer_address: AccountAddress,
263+
fee_payer_authenticator: AccountAuthenticator,
264+
) -> Self {
265+
let authenticator = TransactionAuthenticator::FeePayer {
266+
sender,
267+
secondary_signer_addresses,
268+
secondary_signers,
269+
fee_payer: FeePayerAuthenticator {
270+
address: fee_payer_address,
271+
// This gets ignored for the gas station use case.
272+
authenticator: fee_payer_authenticator,
273+
},
274+
};
275+
SignedTransaction::new(raw_txn, authenticator)
276+
}
277+
278+
/// Create a new signed transaction, indicating that a fee payer will be set later.
279+
/// If you want to actually sign as a fee payer, use `new_as_fee_payer`.
280+
pub fn new_for_future_fee_payer(raw_txn: RawTransaction, sender: AccountAuthenticator) -> Self {
281+
let authenticator = TransactionAuthenticator::FeePayer {
282+
sender,
283+
secondary_signer_addresses: vec![],
284+
secondary_signers: vec![],
285+
fee_payer: FeePayerAuthenticator {
286+
address: AccountAddress::ZERO,
287+
// This gets ignored for the future fee payer use case.
288+
authenticator: AccountAuthenticator::NoAuthenticator { },
289+
},
290+
};
291+
SignedTransaction::new(raw_txn, authenticator)
292+
}
293+
222294
pub fn raw_txn(&self) -> &RawTransaction {
223295
&self.raw_txn
224296
}

0 commit comments

Comments
 (0)