Skip to content

Commit d46c887

Browse files
Format Rust code using rustfmt
1 parent 3e5ec41 commit d46c887

2 files changed

Lines changed: 77 additions & 51 deletions

File tree

src/hyperwallet_client/api.rs

Lines changed: 72 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -379,20 +379,20 @@ pub fn build_and_sign_user_operation_for_payment(
379379
"call_data": call_data,
380380
"use_paymaster": use_paymaster,
381381
});
382-
382+
383383
if let Some(v) = value {
384384
params["value"] = serde_json::Value::String(v.to_string());
385385
}
386-
386+
387387
if let Some(pwd) = password {
388388
params["password"] = serde_json::Value::String(pwd.to_string());
389389
}
390-
390+
391391
// Pass metadata through to hyperwallet
392392
if let Some(meta) = metadata {
393393
params["metadata"] = serde_json::Value::Object(meta);
394394
}
395-
395+
396396
let request = build_request(
397397
our,
398398
session_info,
@@ -424,37 +424,43 @@ pub fn build_and_sign_user_operation(
424424
"call_data": call_data,
425425
"use_paymaster": use_paymaster,
426426
});
427-
427+
428428
if let Some(v) = value {
429429
params["value"] = serde_json::Value::String(v.to_string());
430430
}
431-
431+
432432
if let Some(pwd) = password {
433433
params["password"] = serde_json::Value::String(pwd.to_string());
434434
}
435-
435+
436436
// Create metadata with Circle paymaster configuration if using paymaster
437437
if use_paymaster {
438438
let mut metadata = serde_json::Map::new();
439-
439+
440440
// Always add Circle paymaster metadata for gasless transactions
441441
// These constants should be defined somewhere accessible
442-
metadata.insert("paymaster_address".to_string(),
443-
serde_json::json!("0x2Ac3c1d3e24b45c6C310534Bc2Dd84B5ed576335")); // Base Circle paymaster
442+
metadata.insert(
443+
"paymaster_address".to_string(),
444+
serde_json::json!("0x2Ac3c1d3e24b45c6C310534Bc2Dd84B5ed576335"),
445+
); // Base Circle paymaster
444446
metadata.insert("is_circle_paymaster".to_string(), serde_json::json!(true));
445-
metadata.insert("paymaster_verification_gas".to_string(),
446-
serde_json::json!("0x30000")); // 196608
447-
metadata.insert("paymaster_post_op_gas".to_string(),
448-
serde_json::json!("0x20000")); // 131072
449-
447+
metadata.insert(
448+
"paymaster_verification_gas".to_string(),
449+
serde_json::json!("0x30000"),
450+
); // 196608
451+
metadata.insert(
452+
"paymaster_post_op_gas".to_string(),
453+
serde_json::json!("0x20000"),
454+
); // 131072
455+
450456
// Add TBA address if provided - tells hyperwallet to use TBA as sender
451457
if let Some(tba) = tba_address {
452458
metadata.insert("tba_address".to_string(), serde_json::json!(tba));
453459
}
454-
460+
455461
params["metadata"] = serde_json::Value::Object(metadata);
456462
}
457-
463+
458464
let request = build_request(
459465
our,
460466
session_info,
@@ -537,7 +543,7 @@ pub fn execute_gasless_payment(
537543
) -> Result<serde_json::Value, HyperwalletClientError> {
538544
// Step 1: Initialize session if needed (you might want to cache this)
539545
let session = super::initialize(our, super::HandshakeConfig::new())?;
540-
546+
541547
// Step 2: Build and sign UserOperation
542548
let signed_data = build_and_sign_user_operation(
543549
our,
@@ -551,20 +557,26 @@ pub fn execute_gasless_payment(
551557
password,
552558
chain_id,
553559
)?;
554-
560+
555561
// Step 3: Extract signed UserOperation and entry point
556-
let signed_user_op = signed_data.get("signed_user_operation")
557-
.ok_or_else(|| HyperwalletClientError::ServerError(
558-
super::types::OperationError::internal_error("Missing signed_user_operation in response")
559-
))?
562+
let signed_user_op = signed_data
563+
.get("signed_user_operation")
564+
.ok_or_else(|| {
565+
HyperwalletClientError::ServerError(super::types::OperationError::internal_error(
566+
"Missing signed_user_operation in response",
567+
))
568+
})?
560569
.clone();
561-
562-
let entry_point = signed_data.get("entry_point")
570+
571+
let entry_point = signed_data
572+
.get("entry_point")
563573
.and_then(|e| e.as_str())
564-
.ok_or_else(|| HyperwalletClientError::ServerError(
565-
super::types::OperationError::internal_error("Missing entry_point in response")
566-
))?;
567-
574+
.ok_or_else(|| {
575+
HyperwalletClientError::ServerError(super::types::OperationError::internal_error(
576+
"Missing entry_point in response",
577+
))
578+
})?;
579+
568580
// Step 4: Submit UserOperation
569581
let user_op_hash = submit_user_operation(
570582
our,
@@ -574,10 +586,10 @@ pub fn execute_gasless_payment(
574586
None, // Use default bundler
575587
chain_id,
576588
)?;
577-
589+
578590
// Step 5: Get receipt (you might want to add polling with timeout)
579591
let receipt = get_user_operation_receipt(our, &session, &user_op_hash, chain_id)?;
580-
592+
581593
Ok(receipt)
582594
}
583595

@@ -603,7 +615,7 @@ pub fn build_and_sign_gasless_payment(
603615
"paymaster_post_op_gas": "0x493e0"
604616
}
605617
});
606-
618+
607619
let request = build_request(
608620
our,
609621
session_info,
@@ -624,20 +636,33 @@ pub fn submit_gasless_payment(
624636
chain_id: Option<u64>,
625637
) -> Result<String, HyperwalletClientError> {
626638
// Extract signed UserOperation and entry point from the build response
627-
let signed_user_op = signed_user_op_response.get("signed_user_operation")
628-
.ok_or_else(|| HyperwalletClientError::ServerError(
629-
super::types::OperationError::internal_error("Missing signed_user_operation in response")
630-
))?
639+
let signed_user_op = signed_user_op_response
640+
.get("signed_user_operation")
641+
.ok_or_else(|| {
642+
HyperwalletClientError::ServerError(super::types::OperationError::internal_error(
643+
"Missing signed_user_operation in response",
644+
))
645+
})?
631646
.clone();
632-
633-
let entry_point = signed_user_op_response.get("entry_point")
647+
648+
let entry_point = signed_user_op_response
649+
.get("entry_point")
634650
.and_then(|e| e.as_str())
635-
.ok_or_else(|| HyperwalletClientError::ServerError(
636-
super::types::OperationError::internal_error("Missing entry_point in response")
637-
))?;
638-
651+
.ok_or_else(|| {
652+
HyperwalletClientError::ServerError(super::types::OperationError::internal_error(
653+
"Missing entry_point in response",
654+
))
655+
})?;
656+
639657
// Submit using the extracted data
640-
submit_user_operation(our, session_info, signed_user_op, entry_point, None, chain_id)
658+
submit_user_operation(
659+
our,
660+
session_info,
661+
signed_user_op,
662+
entry_point,
663+
None,
664+
chain_id,
665+
)
641666
}
642667

643668
/// Get receipt with proper transaction hash extraction.
@@ -648,14 +673,15 @@ pub fn get_payment_receipt(
648673
chain_id: Option<u64>,
649674
) -> Result<(String, serde_json::Value), HyperwalletClientError> {
650675
let receipt = get_user_operation_receipt(our, session_info, user_op_hash, chain_id)?;
651-
676+
652677
// Extract transaction hash if available
653-
let tx_hash = receipt.get("receipt")
678+
let tx_hash = receipt
679+
.get("receipt")
654680
.and_then(|r| r.get("transactionHash"))
655681
.and_then(|h| h.as_str())
656682
.unwrap_or(user_op_hash) // Fallback to user op hash
657683
.to_string();
658-
684+
659685
Ok((tx_hash, receipt))
660686
}
661687

src/hyperwallet_client/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ pub mod api;
1111
pub mod types;
1212

1313
pub use api::{
14-
approve_token, build_and_sign_gasless_payment, build_and_sign_user_operation,
15-
build_and_sign_user_operation_for_payment, check_tba_ownership, create_note, create_wallet,
14+
approve_token, build_and_sign_gasless_payment, build_and_sign_user_operation,
15+
build_and_sign_user_operation_for_payment, check_tba_ownership, create_note, create_wallet,
1616
delete_wallet, execute_gasless_payment, execute_via_tba, get_balance, get_payment_receipt,
17-
get_token_balance, get_user_operation_receipt, get_wallet_info, import_wallet, list_wallets,
18-
rename_wallet, resolve_identity, send_eth, send_token, set_wallet_limits, submit_gasless_payment,
19-
submit_user_operation, unlock_wallet,
17+
get_token_balance, get_user_operation_receipt, get_wallet_info, import_wallet, list_wallets,
18+
rename_wallet, resolve_identity, send_eth, send_token, set_wallet_limits,
19+
submit_gasless_payment, submit_user_operation, unlock_wallet,
2020
};
2121
pub use types::{
2222
Balance, HandshakeConfig, Operation, OperationCategory, OperationError, ProcessPermissions,

0 commit comments

Comments
 (0)