Skip to content

Commit da319b2

Browse files
committed
fmt..
2 parents 7e43a65 + d46c887 commit da319b2

1 file changed

Lines changed: 72 additions & 46 deletions

File tree

src/hyperwallet_client/api.rs

Lines changed: 72 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -380,20 +380,20 @@ pub fn build_and_sign_user_operation_for_payment(
380380
"call_data": call_data,
381381
"use_paymaster": use_paymaster,
382382
});
383-
383+
384384
if let Some(v) = value {
385385
params["value"] = serde_json::Value::String(v.to_string());
386386
}
387-
387+
388388
if let Some(pwd) = password {
389389
params["password"] = serde_json::Value::String(pwd.to_string());
390390
}
391-
391+
392392
// Pass metadata through to hyperwallet
393393
if let Some(meta) = metadata {
394394
params["metadata"] = serde_json::Value::Object(meta);
395395
}
396-
396+
397397
let request = build_request(
398398
our,
399399
session_info,
@@ -425,37 +425,43 @@ pub fn build_and_sign_user_operation(
425425
"call_data": call_data,
426426
"use_paymaster": use_paymaster,
427427
});
428-
428+
429429
if let Some(v) = value {
430430
params["value"] = serde_json::Value::String(v.to_string());
431431
}
432-
432+
433433
if let Some(pwd) = password {
434434
params["password"] = serde_json::Value::String(pwd.to_string());
435435
}
436-
436+
437437
// Create metadata with Circle paymaster configuration if using paymaster
438438
if use_paymaster {
439439
let mut metadata = serde_json::Map::new();
440-
440+
441441
// Always add Circle paymaster metadata for gasless transactions
442442
// These constants should be defined somewhere accessible
443-
metadata.insert("paymaster_address".to_string(),
444-
serde_json::json!("0x2Ac3c1d3e24b45c6C310534Bc2Dd84B5ed576335")); // Base Circle paymaster
443+
metadata.insert(
444+
"paymaster_address".to_string(),
445+
serde_json::json!("0x2Ac3c1d3e24b45c6C310534Bc2Dd84B5ed576335"),
446+
); // Base Circle paymaster
445447
metadata.insert("is_circle_paymaster".to_string(), serde_json::json!(true));
446-
metadata.insert("paymaster_verification_gas".to_string(),
447-
serde_json::json!("0x30000")); // 196608
448-
metadata.insert("paymaster_post_op_gas".to_string(),
449-
serde_json::json!("0x20000")); // 131072
450-
448+
metadata.insert(
449+
"paymaster_verification_gas".to_string(),
450+
serde_json::json!("0x30000"),
451+
); // 196608
452+
metadata.insert(
453+
"paymaster_post_op_gas".to_string(),
454+
serde_json::json!("0x20000"),
455+
); // 131072
456+
451457
// Add TBA address if provided - tells hyperwallet to use TBA as sender
452458
if let Some(tba) = tba_address {
453459
metadata.insert("tba_address".to_string(), serde_json::json!(tba));
454460
}
455-
461+
456462
params["metadata"] = serde_json::Value::Object(metadata);
457463
}
458-
464+
459465
let request = build_request(
460466
our,
461467
session_info,
@@ -538,7 +544,7 @@ pub fn execute_gasless_payment(
538544
) -> Result<serde_json::Value, HyperwalletClientError> {
539545
// Step 1: Initialize session if needed (you might want to cache this)
540546
let session = super::initialize(our, super::HandshakeConfig::new())?;
541-
547+
542548
// Step 2: Build and sign UserOperation
543549
let signed_data = build_and_sign_user_operation(
544550
our,
@@ -552,20 +558,26 @@ pub fn execute_gasless_payment(
552558
password,
553559
chain_id,
554560
)?;
555-
561+
556562
// Step 3: Extract signed UserOperation and entry point
557-
let signed_user_op = signed_data.get("signed_user_operation")
558-
.ok_or_else(|| HyperwalletClientError::ServerError(
559-
super::types::OperationError::internal_error("Missing signed_user_operation in response")
560-
))?
563+
let signed_user_op = signed_data
564+
.get("signed_user_operation")
565+
.ok_or_else(|| {
566+
HyperwalletClientError::ServerError(super::types::OperationError::internal_error(
567+
"Missing signed_user_operation in response",
568+
))
569+
})?
561570
.clone();
562-
563-
let entry_point = signed_data.get("entry_point")
571+
572+
let entry_point = signed_data
573+
.get("entry_point")
564574
.and_then(|e| e.as_str())
565-
.ok_or_else(|| HyperwalletClientError::ServerError(
566-
super::types::OperationError::internal_error("Missing entry_point in response")
567-
))?;
568-
575+
.ok_or_else(|| {
576+
HyperwalletClientError::ServerError(super::types::OperationError::internal_error(
577+
"Missing entry_point in response",
578+
))
579+
})?;
580+
569581
// Step 4: Submit UserOperation
570582
let user_op_hash = submit_user_operation(
571583
our,
@@ -575,10 +587,10 @@ pub fn execute_gasless_payment(
575587
None, // Use default bundler
576588
chain_id,
577589
)?;
578-
590+
579591
// Step 5: Get receipt (you might want to add polling with timeout)
580592
let receipt = get_user_operation_receipt(our, &session, &user_op_hash, chain_id)?;
581-
593+
582594
Ok(receipt)
583595
}
584596

@@ -604,7 +616,7 @@ pub fn build_and_sign_gasless_payment(
604616
"paymaster_post_op_gas": "0x493e0"
605617
}
606618
});
607-
619+
608620
let request = build_request(
609621
our,
610622
session_info,
@@ -625,20 +637,33 @@ pub fn submit_gasless_payment(
625637
chain_id: Option<u64>,
626638
) -> Result<String, HyperwalletClientError> {
627639
// Extract signed UserOperation and entry point from the build response
628-
let signed_user_op = signed_user_op_response.get("signed_user_operation")
629-
.ok_or_else(|| HyperwalletClientError::ServerError(
630-
super::types::OperationError::internal_error("Missing signed_user_operation in response")
631-
))?
640+
let signed_user_op = signed_user_op_response
641+
.get("signed_user_operation")
642+
.ok_or_else(|| {
643+
HyperwalletClientError::ServerError(super::types::OperationError::internal_error(
644+
"Missing signed_user_operation in response",
645+
))
646+
})?
632647
.clone();
633-
634-
let entry_point = signed_user_op_response.get("entry_point")
648+
649+
let entry_point = signed_user_op_response
650+
.get("entry_point")
635651
.and_then(|e| e.as_str())
636-
.ok_or_else(|| HyperwalletClientError::ServerError(
637-
super::types::OperationError::internal_error("Missing entry_point in response")
638-
))?;
639-
652+
.ok_or_else(|| {
653+
HyperwalletClientError::ServerError(super::types::OperationError::internal_error(
654+
"Missing entry_point in response",
655+
))
656+
})?;
657+
640658
// Submit using the extracted data
641-
submit_user_operation(our, session_info, signed_user_op, entry_point, None, chain_id)
659+
submit_user_operation(
660+
our,
661+
session_info,
662+
signed_user_op,
663+
entry_point,
664+
None,
665+
chain_id,
666+
)
642667
}
643668

644669
/// Get receipt with proper transaction hash extraction.
@@ -649,14 +674,15 @@ pub fn get_payment_receipt(
649674
chain_id: Option<u64>,
650675
) -> Result<(String, serde_json::Value), HyperwalletClientError> {
651676
let receipt = get_user_operation_receipt(our, session_info, user_op_hash, chain_id)?;
652-
677+
653678
// Extract transaction hash if available
654-
let tx_hash = receipt.get("receipt")
679+
let tx_hash = receipt
680+
.get("receipt")
655681
.and_then(|r| r.get("transactionHash"))
656682
.and_then(|h| h.as_str())
657683
.unwrap_or(user_op_hash) // Fallback to user op hash
658684
.to_string();
659-
685+
660686
Ok((tx_hash, receipt))
661687
}
662688

0 commit comments

Comments
 (0)