Skip to content

Commit 796b535

Browse files
committed
Add transaction worker
1 parent 6cb9a8d commit 796b535

File tree

13 files changed

+1471
-47
lines changed

13 files changed

+1471
-47
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: 31 additions & 2 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 {
@@ -253,7 +283,7 @@ impl GenerateSigningMessage for RawTransactionWithData {
253283
message.extend(hash);
254284
message.extend(bytes);
255285
Ok(message)
256-
}
286+
}
257287
}
258288

259289
impl SignedTransaction {
@@ -319,7 +349,6 @@ impl GenerateSigningMessage for RawTransaction {
319349
message.extend(bytes);
320350
Ok(message)
321351
}
322-
323352
}
324353

325354
impl EntryFunction {

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

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,19 @@ pub enum TransactionAuthenticator {
5656
sender: AccountAuthenticator,
5757
secondary_signer_addresses: Vec<AccountAddress>,
5858
secondary_signers: Vec<AccountAuthenticator>,
59-
fee_payer_address: AccountAddress,
60-
fee_payer_signer: AccountAuthenticator,
59+
fee_payer: FeePayerAuthenticator,
6160
},
6261
SingleSender {
6362
sender: AccountAuthenticator,
6463
},
6564
}
6665

66+
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
67+
pub struct FeePayerAuthenticator {
68+
pub address: AccountAddress,
69+
pub authenticator: AccountAuthenticator,
70+
}
71+
6772
impl TransactionAuthenticator {
6873
/// Create a single-signature ed25519 authenticator
6974
pub fn ed25519(public_key: Ed25519PublicKey, signature: Ed25519Signature) -> Self {
@@ -72,21 +77,18 @@ impl TransactionAuthenticator {
7277
signature,
7378
}
7479
}
75-
7680
/// Create a (optional) multi-agent fee payer authenticator
7781
pub fn fee_payer(
7882
sender: AccountAuthenticator,
7983
secondary_signer_addresses: Vec<AccountAddress>,
8084
secondary_signers: Vec<AccountAuthenticator>,
81-
fee_payer_address: AccountAddress,
82-
fee_payer_signer: AccountAuthenticator,
85+
fee_payer: FeePayerAuthenticator,
8386
) -> Self {
8487
Self::FeePayer {
8588
sender,
8689
secondary_signer_addresses,
8790
secondary_signers,
88-
fee_payer_address,
89-
fee_payer_signer,
91+
fee_payer,
9092
}
9193
}
9294

@@ -242,25 +244,9 @@ impl TransactionAuthenticator {
242244
sender: _,
243245
secondary_signer_addresses: _,
244246
secondary_signers: _,
245-
fee_payer_address,
247+
fee_payer,
246248
..
247-
} => Some(*fee_payer_address),
248-
}
249-
}
250-
251-
pub fn fee_payer_signer(&self) -> Option<AccountAuthenticator> {
252-
match self {
253-
Self::Ed25519 { .. }
254-
| Self::MultiAgent { .. }
255-
| Self::SingleSender { .. }
256-
| Self::MultiEd25519 { .. } => None,
257-
Self::FeePayer {
258-
sender: _,
259-
secondary_signer_addresses: _,
260-
secondary_signers: _,
261-
fee_payer_address: _,
262-
fee_payer_signer,
263-
} => Some(fee_payer_signer.clone()),
249+
} => Some(fee_payer.address),
264250
}
265251
}
266252

@@ -275,9 +261,6 @@ impl TransactionAuthenticator {
275261
let mut account_authenticators: Vec<AccountAuthenticator> = vec![];
276262
account_authenticators.push(self.sender());
277263
account_authenticators.extend(self.secondary_signers());
278-
if let Some(fee_payer) = self.fee_payer_signer() {
279-
account_authenticators.push(fee_payer);
280-
}
281264
account_authenticators
282265
}
283266
}
@@ -338,8 +321,7 @@ impl fmt::Display for TransactionAuthenticator {
338321
sender,
339322
secondary_signer_addresses,
340323
secondary_signers,
341-
fee_payer_address,
342-
fee_payer_signer,
324+
fee_payer,
343325
} => {
344326
let mut sec_addrs: String = "".to_string();
345327
for sec_addr in secondary_signer_addresses {
@@ -356,9 +338,8 @@ impl fmt::Display for TransactionAuthenticator {
356338
\tsender: {}\n\
357339
\tsecondary signer addresses: {}\n\
358340
\tsecondary signers: {}\n\n
359-
\tfee payer address: {}\n\n
360-
\tfee payer signer: {}]",
361-
sender, sec_addrs, sec_signers, fee_payer_address, fee_payer_signer,
341+
\tfee payer address: {}]",
342+
sender, sec_addrs, sec_signers, fee_payer.address,
362343
)
363344
}
364345
Self::MultiAgent {
@@ -615,7 +596,7 @@ impl fmt::Display for AccountAuthenticator {
615596
"AccountAuthenticator[scheme id: {:?}, public key: {}, signature: {}]",
616597
self.scheme(),
617598
hex::encode(self.public_key_bytes()),
618-
hex::encode(self.signature_bytes())
599+
hex::encode(self.signature_bytes()),
619600
)
620601
}
621602
}
@@ -645,6 +626,8 @@ impl FromStr for AuthenticationKey {
645626
type Err = anyhow::Error;
646627

647628
fn from_str(s: &str) -> Result<Self, anyhow::Error> {
629+
// Trim 0x from the start if present.
630+
let s = if s.starts_with("0x") { &s[2..] } else { s };
648631
ensure!(
649632
!s.is_empty(),
650633
"authentication key string should not be empty.",

0 commit comments

Comments
 (0)