|
| 1 | +use crate::hyperware::process::hyperwallet as wit; |
| 2 | +use serde::de::{self}; |
| 3 | +use serde::ser::Serialize; |
| 4 | +use serde::Deserialize; |
| 5 | + |
| 6 | +// Create a macro to generate stub implementations for request/response types |
| 7 | +macro_rules! impl_stub_serde { |
| 8 | + ($type:ty, $name:literal) => { |
| 9 | + impl Serialize for $type { |
| 10 | + fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> |
| 11 | + where |
| 12 | + S: serde::ser::Serializer, |
| 13 | + { |
| 14 | + // For now, serialize as debug representation |
| 15 | + let json_val = serde_json::json!({ |
| 16 | + "type": $name, |
| 17 | + "data": format!("{:?}", self) |
| 18 | + }); |
| 19 | + json_val.serialize(serializer) |
| 20 | + } |
| 21 | + } |
| 22 | + |
| 23 | + impl<'a> Deserialize<'a> for $type { |
| 24 | + fn deserialize<D>(deserializer: D) -> Result<$type, D::Error> |
| 25 | + where |
| 26 | + D: serde::de::Deserializer<'a>, |
| 27 | + { |
| 28 | + // The hyperwallet service is sending the response wrapped in a debug format |
| 29 | + // We need to deserialize the actual JSON payload |
| 30 | + let val = serde_json::Value::deserialize(deserializer)?; |
| 31 | + |
| 32 | + // Try normal JSON deserialization first |
| 33 | + match serde_json::from_value(val.clone()) { |
| 34 | + Ok(result) => Ok(result), |
| 35 | + Err(_) => { |
| 36 | + // If that fails, it might be wrapped in the debug format |
| 37 | + // For now, we can't parse debug format strings back to structs |
| 38 | + // This is a fundamental issue with the hyperwallet service |
| 39 | + Err(de::Error::custom(format!( |
| 40 | + "{} cannot be deserialized from debug format. The hyperwallet service needs to be fixed to return proper JSON.", |
| 41 | + $name |
| 42 | + ))) |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + }; |
| 48 | +} |
| 49 | + |
| 50 | +// Request types |
| 51 | +impl_stub_serde!( |
| 52 | + wit::UpdateSpendingLimitsRequest, |
| 53 | + "UpdateSpendingLimitsRequest" |
| 54 | +); |
| 55 | +impl_stub_serde!(wit::ImportWalletRequest, "ImportWalletRequest"); |
| 56 | +impl_stub_serde!(wit::DeleteWalletRequest, "DeleteWalletRequest"); |
| 57 | +impl_stub_serde!(wit::RenameWalletRequest, "RenameWalletRequest"); |
| 58 | +impl_stub_serde!(wit::ExportWalletRequest, "ExportWalletRequest"); |
| 59 | +impl_stub_serde!(wit::GetWalletInfoRequest, "GetWalletInfoRequest"); |
| 60 | +impl_stub_serde!(wit::SendEthRequest, "SendEthRequest"); |
| 61 | +impl_stub_serde!(wit::SendTokenRequest, "SendTokenRequest"); |
| 62 | +impl_stub_serde!(wit::ApproveTokenRequest, "ApproveTokenRequest"); |
| 63 | +impl_stub_serde!(wit::GetBalanceRequest, "GetBalanceRequest"); |
| 64 | +impl_stub_serde!(wit::GetTokenBalanceRequest, "GetTokenBalanceRequest"); |
| 65 | +impl_stub_serde!(wit::CallContractRequest, "CallContractRequest"); |
| 66 | +impl_stub_serde!(wit::SignTransactionRequest, "SignTransactionRequest"); |
| 67 | +impl_stub_serde!(wit::SignMessageRequest, "SignMessageRequest"); |
| 68 | +impl_stub_serde!( |
| 69 | + wit::BuildAndSignUserOperationForPaymentRequest, |
| 70 | + "BuildAndSignUserOperationForPaymentRequest" |
| 71 | +); |
| 72 | +impl_stub_serde!( |
| 73 | + wit::SubmitUserOperationRequest, |
| 74 | + "SubmitUserOperationRequest" |
| 75 | +); |
| 76 | +impl_stub_serde!( |
| 77 | + wit::GetUserOperationReceiptRequest, |
| 78 | + "GetUserOperationReceiptRequest" |
| 79 | +); |
| 80 | +impl_stub_serde!( |
| 81 | + wit::GetTransactionHistoryRequest, |
| 82 | + "GetTransactionHistoryRequest" |
| 83 | +); |
| 84 | +impl_stub_serde!(wit::EstimateGasRequest, "EstimateGasRequest"); |
| 85 | + |
| 86 | +// Response types |
| 87 | +impl_stub_serde!(wit::UnlockWalletResponse, "UnlockWalletResponse"); |
| 88 | +impl_stub_serde!(wit::CreateWalletResponse, "CreateWalletResponse"); |
| 89 | +impl_stub_serde!(wit::ImportWalletResponse, "ImportWalletResponse"); |
| 90 | +impl_stub_serde!(wit::DeleteWalletResponse, "DeleteWalletResponse"); |
| 91 | +impl_stub_serde!(wit::ExportWalletResponse, "ExportWalletResponse"); |
| 92 | +impl_stub_serde!(wit::ListWalletsResponse, "ListWalletsResponse"); |
| 93 | +impl_stub_serde!(wit::GetWalletInfoResponse, "GetWalletInfoResponse"); |
| 94 | +impl_stub_serde!(wit::GetBalanceResponse, "GetBalanceResponse"); |
| 95 | +impl_stub_serde!(wit::GetTokenBalanceResponse, "GetTokenBalanceResponse"); |
| 96 | +impl_stub_serde!(wit::SendEthResponse, "SendEthResponse"); |
| 97 | +impl_stub_serde!(wit::SendTokenResponse, "SendTokenResponse"); |
| 98 | +impl_stub_serde!(wit::BuildAndSignUserOperationResponse,"BuildAndSignUserOperationResponse"); |
| 99 | +impl_stub_serde!(wit::SubmitUserOperationResponse,"SubmitUserOperationResponse"); |
| 100 | +impl_stub_serde!(wit::UserOperationReceiptResponse,"UserOperationReceiptResponse"); |
| 101 | + |
| 102 | +// Other request types |
| 103 | +impl_stub_serde!(wit::GetTransactionReceiptRequest,"GetTransactionReceiptRequest"); |
| 104 | +impl_stub_serde!(wit::BuildUserOperationRequest, "BuildUserOperationRequest"); |
| 105 | +impl_stub_serde!(wit::SignUserOperationRequest, "SignUserOperationRequest"); |
| 106 | +impl_stub_serde!(wit::BuildAndSignUserOperationRequest,"BuildAndSignUserOperationRequest"); |
| 107 | +impl_stub_serde!(wit::EstimateUserOperationGasRequest,"EstimateUserOperationGasRequest"); |
| 108 | +impl_stub_serde!(wit::ConfigurePaymasterRequest, "ConfigurePaymasterRequest"); |
| 109 | +impl_stub_serde!(wit::ExecuteViaTbaRequest, "ExecuteViaTbaRequest"); |
| 110 | +impl_stub_serde!(wit::CheckTbaOwnershipRequest, "CheckTbaOwnershipRequest"); |
| 111 | +impl_stub_serde!(wit::SetupTbaDelegationRequest, "SetupTbaDelegationRequest"); |
| 112 | +impl_stub_serde!(wit::CreateNoteRequest, "CreateNoteRequest"); |
| 113 | +impl_stub_serde!(wit::ReadNoteRequest, "ReadNoteRequest"); |
| 114 | +impl_stub_serde!(wit::ResolveIdentityRequest, "ResolveIdentityRequest"); |
| 115 | +impl_stub_serde!(wit::SetupDelegationRequest, "SetupDelegationRequest"); |
| 116 | +impl_stub_serde!(wit::VerifyDelegationRequest, "VerifyDelegationRequest"); |
| 117 | +impl_stub_serde!(wit::MintEntryRequest, "MintEntryRequest"); |
| 118 | + |
| 119 | +// Other response types |
| 120 | +impl_stub_serde!(wit::CreateNoteResponse, "CreateNoteResponse"); |
| 121 | +impl_stub_serde!(wit::ExecuteViaTbaResponse, "ExecuteViaTbaResponse"); |
| 122 | +impl_stub_serde!(wit::CheckTbaOwnershipResponse, "CheckTbaOwnershipResponse"); |
| 123 | + |
| 124 | +// Other types that may need serde |
| 125 | +impl_stub_serde!(wit::Balance, "Balance"); |
| 126 | +impl_stub_serde!(wit::Wallet, "Wallet"); |
| 127 | +impl_stub_serde!(wit::WalletSpendingLimits, "WalletSpendingLimits"); |
0 commit comments