Skip to content

Commit

Permalink
Update sdk to upstream branch lightmark/account_abstraction-update-ap…
Browse files Browse the repository at this point in the history
…tos-protos (#685)

Co-authored-by: Aptos Bot <[email protected]>
Co-authored-by: Larry Liu <[email protected]>
  • Loading branch information
3 people authored Jan 23, 2025
1 parent 54bbd61 commit d68d37e
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 39 deletions.
43 changes: 16 additions & 27 deletions rust/Cargo.lock

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

10 changes: 5 additions & 5 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ sdk-processor = { path = "sdk-processor" }

ahash = { version = "0.8.7", features = ["serde"] }
anyhow = "1.0.86"
aptos-indexer-processor-sdk = { git = "https://github.com/aptos-labs/aptos-indexer-processor-sdk.git", rev = "a56b641a6aaca60092fcc9bbd98252f3cd703299" }
aptos-indexer-processor-sdk-server-framework = { git = "https://github.com/aptos-labs/aptos-indexer-processor-sdk.git", rev = "a56b641a6aaca60092fcc9bbd98252f3cd703299" }
aptos-protos = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "6116af69aa173ca49e1761daabd6fe103fe2c65e" }
aptos-indexer-test-transactions = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "ef80673093aa4df271ad33c2401421d642e7ff3c" }
aptos-indexer-testing-framework = { git = "https://github.com/aptos-labs/aptos-indexer-processor-sdk.git", rev = "a56b641a6aaca60092fcc9bbd98252f3cd703299" }
aptos-indexer-processor-sdk = { git = "https://github.com/aptos-labs/aptos-indexer-processor-sdk.git", rev = "b79ed8b5864b2a12a1f9c5fd01579462e029b2ae" }
aptos-indexer-processor-sdk-server-framework = { git = "https://github.com/aptos-labs/aptos-indexer-processor-sdk.git", rev = "b79ed8b5864b2a12a1f9c5fd01579462e029b2ae" }
aptos-protos = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "1d8460a995503574ec4e9699d3442d0150d7f3b9" }
aptos-indexer-test-transactions = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "1d8460a995503574ec4e9699d3442d0150d7f3b9" }
aptos-indexer-testing-framework = { git = "https://github.com/aptos-labs/aptos-indexer-processor-sdk.git", rev = "b79ed8b5864b2a12a1f9c5fd01579462e029b2ae" }
async-trait = "0.1.53"
backtrace = "0.3.58"
base64 = "0.13.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use aptos_protos::transaction::v1::{
SingleSender as SingleSenderPb,
};
use serde::{Deserialize, Serialize};
use tracing::warn;

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Signature {
Expand Down Expand Up @@ -79,14 +80,28 @@ impl Signature {
}
}

pub fn get_signature_type(t: &TransactionSignaturePb) -> String {
pub fn get_signature_type(t: &TransactionSignaturePb, transaction_version: i64) -> String {
if t.signature.is_none() {
warn!(
transaction_version = transaction_version,
"Transaction signature is unknown"
);
return String::from("unknown");
}
match t.signature.as_ref().unwrap() {
SignatureEnum::Ed25519(_) => String::from("ed25519_signature"),
SignatureEnum::MultiEd25519(_) => String::from("multi_ed25519_signature"),
SignatureEnum::MultiAgent(_) => String::from("multi_agent_signature"),
SignatureEnum::FeePayer(_) => String::from("fee_payer_signature"),
SignatureEnum::SingleSender(sender) => {
let account_signature = sender.sender.as_ref().unwrap();
if account_signature.signature.is_none() {
warn!(
transaction_version = transaction_version,
"Transaction signature is unknown"
);
return String::from("unknown");
}
let signature = account_signature.signature.as_ref().unwrap();
match signature {
AccountSignatureEnum::Ed25519(_) => String::from("ed25519_signature"),
Expand All @@ -99,6 +114,7 @@ impl Signature {
AccountSignatureEnum::MultiKeySignature(_) => {
String::from("multi_key_signature")
},
AccountSignatureEnum::Abstraction(_) => String::from("abstraction_signature"),
}
},
}
Expand Down Expand Up @@ -145,6 +161,29 @@ impl Signature {
}
}

fn parse_abstraction_signature(
sender: &String,
transaction_version: i64,
transaction_block_height: i64,
is_sender_primary: bool,
multi_agent_index: i64,
override_address: Option<&String>,
) -> Self {
let signer = standardize_address(override_address.unwrap_or(sender));
Self {
txn_version: transaction_version,
transaction_block_height,
signer,
is_sender_primary,
type_: String::from("abstraction_signature"),
public_key: "Not implemented".into(),
threshold: 1,
signature: "Not implemented".into(),
multi_agent_index,
multi_sig_index: 0,
}
}

fn parse_multi_ed25519_signature(
s: &MultiEd25519SignaturePb,
sender: &String,
Expand Down Expand Up @@ -263,6 +302,13 @@ impl Signature {
multi_agent_index: i64,
override_address: Option<&String>,
) -> Vec<Self> {
if s.signature.is_none() {
warn!(
transaction_version = transaction_version,
"Transaction signature is unknown"
);
return vec![];
}
let signature = s.signature.as_ref().unwrap();
match signature {
AccountSignatureEnum::Ed25519(sig) => vec![Self::parse_ed25519_signature(
Expand Down Expand Up @@ -303,6 +349,14 @@ impl Signature {
multi_agent_index,
override_address,
),
AccountSignatureEnum::Abstraction(_sig) => vec![Self::parse_abstraction_signature(
sender,
transaction_version,
transaction_block_height,
is_sender_primary,
multi_agent_index,
override_address,
)],
}
}

Expand Down Expand Up @@ -494,6 +548,13 @@ impl Signature {
transaction_version: i64,
transaction_block_height: i64,
) -> Vec<Self> {
if s.sender.is_none() {
warn!(
transaction_version = transaction_version,
"Transaction signature is unknown"
);
return vec![];
}
let signature = s.sender.as_ref().unwrap();
match signature.signature.as_ref() {
Some(AccountSignatureEnum::SingleKeySignature(s)) => {
Expand Down Expand Up @@ -534,6 +595,16 @@ impl Signature {
0,
None,
),
Some(AccountSignatureEnum::Abstraction(_sig)) => {
vec![Self::parse_abstraction_signature(
sender,
transaction_version,
transaction_block_height,
true,
0,
None,
)]
},
None => vec![],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl UserTransaction {
.unwrap()
.signature
.as_ref()
.map(Signature::get_signature_type)
.map(|s| Signature::get_signature_type(s, version))
.unwrap_or_default(),
sender: standardize_address(&user_request.sender),
sequence_number: user_request.sequence_number as i64,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use aptos_protos::transaction::v1::{
account_signature::Signature as AccountSignature, signature::Signature, transaction::TxnData,
Transaction,
};
use tracing::warn;

trait AuthKeyScheme {
const SCHEME: u8;
Expand Down Expand Up @@ -253,7 +254,7 @@ impl SignatureInfo {
}
}

fn from_transaction_signature(signature: &Signature) -> Option<Self> {
fn from_transaction_signature(signature: &Signature, transaction_version: i64) -> Option<Self> {
let info = match signature {
Signature::Ed25519(sig) => Self::ed25519(sig.public_key.clone()),
Signature::MultiEd25519(sigs) => {
Expand All @@ -265,7 +266,13 @@ impl SignatureInfo {
},
Signature::SingleSender(single_sender) => {
let account_signature = single_sender.sender.as_ref().unwrap();

if account_signature.signature.is_none() {
warn!(
transaction_version = transaction_version,
"Transaction signature is unknown"
);
return None;
}
let signature_info = match account_signature.signature.as_ref().unwrap() {
AccountSignature::Ed25519(sig) => Self::ed25519(sig.public_key.clone()),
AccountSignature::MultiEd25519(sigs) => {
Expand Down Expand Up @@ -301,6 +308,7 @@ impl SignatureInfo {
.collect::<Vec<_>>();
Self::multi_key(threshold, prefixes, public_keys, verified)
},
AccountSignature::Abstraction(_sig) => return None,
};
signature_info
},
Expand All @@ -322,6 +330,7 @@ pub fn parse_account_restoration_models_from_transaction(
TxnData::User(user_txn) => user_txn,
_ => return None,
};
let txn_version = txn.version as i64;
let address = user_txn.request.as_ref()?.sender.clone();
let signature_info = SignatureInfo::from_transaction_signature(
user_txn
Expand All @@ -331,9 +340,9 @@ pub fn parse_account_restoration_models_from_transaction(
.as_ref()?
.signature
.as_ref()?,
txn_version,
)?;
let auth_key = signature_info.auth_key().unwrap_or_default();
let txn_version = txn.version as i64;

let auth_key_account_address = AuthKeyAccountAddress {
auth_key: auth_key.clone(),
Expand Down
Loading

0 comments on commit d68d37e

Please sign in to comment.