From 288978a1ddfa00a26945bd0967fab117ad2ef0cd Mon Sep 17 00:00:00 2001 From: Brian Corbin Date: Fri, 17 Nov 2023 16:51:09 -0800 Subject: [PATCH] Update mirror endpoints (#936) --- full-service/src/db/txo.rs | 10 +++++++++ full-service/src/json_rpc/v2/api/request.rs | 1 - full-service/src/json_rpc/v2/api/wallet.rs | 3 +-- full-service/src/service/memo.rs | 25 +++++++++------------ mirror/src/private/main.rs | 1 + 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/full-service/src/db/txo.rs b/full-service/src/db/txo.rs index 572581f10..cb1f062bb 100644 --- a/full-service/src/db/txo.rs +++ b/full-service/src/db/txo.rs @@ -741,6 +741,8 @@ pub trait TxoModel { /// If we created the txo, it would be the address at which we received it. Otherwise, /// it will require a lookup of who we sent it to in the transaction_txo_outputs table fn recipient_public_address(&self, conn: Conn) -> Result, WalletDbError>; + + fn account(&self, conn: Conn) -> Result, WalletDbError>; } impl TxoModel for Txo { @@ -2150,6 +2152,14 @@ impl TxoModel for Txo { _ => Ok(None), } } + + fn account(&self, conn: Conn) -> Result, WalletDbError> { + Ok(self + .account_id + .as_ref() + .map(|account_id| Account::get(&AccountID(account_id.to_string()), conn)) + .transpose()?) + } } fn add_authenticated_memo_to_database( diff --git a/full-service/src/json_rpc/v2/api/request.rs b/full-service/src/json_rpc/v2/api/request.rs index 989cb8eff..020f0cdf9 100644 --- a/full-service/src/json_rpc/v2/api/request.rs +++ b/full-service/src/json_rpc/v2/api/request.rs @@ -273,7 +273,6 @@ pub enum JsonCommandRequest { confirmation: String, }, validate_sender_memo { - account_id: String, txo_id: String, sender_address: String, }, diff --git a/full-service/src/json_rpc/v2/api/wallet.rs b/full-service/src/json_rpc/v2/api/wallet.rs index 62842c3c3..42a1904ce 100644 --- a/full-service/src/json_rpc/v2/api/wallet.rs +++ b/full-service/src/json_rpc/v2/api/wallet.rs @@ -1435,12 +1435,11 @@ where JsonCommandResponse::validate_confirmation { validated: result } } JsonCommandRequest::validate_sender_memo { - account_id, txo_id, sender_address, } => { let result = service - .validate_sender_memo(&AccountID(account_id), &txo_id, &sender_address) + .validate_sender_memo(&txo_id, &sender_address) .map_err(format_error)?; JsonCommandResponse::validate_sender_memo { validated: result } } diff --git a/full-service/src/service/memo.rs b/full-service/src/service/memo.rs index aaa0fd55b..391d42861 100644 --- a/full-service/src/service/memo.rs +++ b/full-service/src/service/memo.rs @@ -1,15 +1,10 @@ use crate::{ - db::{ - account::{AccountID, AccountModel}, - models::Account, - WalletDbError, - }, + db::{account::AccountModel, models::Txo, txo::TxoModel, WalletDbError}, service::ledger::{LedgerService, LedgerServiceError}, util::b58::{b58_decode_public_address, B58Error}, WalletService, }; use displaydoc::Display; -use mc_account_keys::AccountKey; use mc_connection::{BlockchainConnection, UserTxConnection}; use mc_crypto_keys::RistrettoPublic; use mc_fog_report_validation::FogPubkeyResolver; @@ -80,7 +75,6 @@ impl From for MemoServiceError { pub trait MemoService { fn validate_sender_memo( &self, - account_id: &AccountID, txo_id_hex: &str, sender_address: &str, ) -> Result; @@ -93,7 +87,6 @@ where { fn validate_sender_memo( &self, - account_id: &AccountID, txo_id_hex: &str, sender_address: &str, ) -> Result { @@ -102,13 +95,17 @@ where let mut pooled_conn = self.get_pooled_conn()?; let conn = pooled_conn.deref_mut(); - let account = Account::get(account_id, conn)?; - let account_key: AccountKey = mc_util_serial::decode(&account.account_key)?; + let txo = Txo::get(txo_id_hex, conn)?; + let Some(account) = txo.account(conn)? else { + return Ok(false); + }; + + let account_key = account.account_key()?; - let txo = self.get_txo_object(txo_id_hex)?; + let tx_out = self.get_txo_object(txo_id_hex)?; let shared_secret = - account.get_shared_secret(&RistrettoPublic::try_from(&txo.public_key)?)?; - let memo_payload = match txo.e_memo { + account.get_shared_secret(&RistrettoPublic::try_from(&tx_out.public_key)?)?; + let memo_payload = match tx_out.e_memo { Some(e_memo) => e_memo.decrypt(&shared_secret), None => UnusedMemo.into(), }; @@ -118,7 +115,7 @@ where .validate( &sender_address, account_key.view_private_key(), - &txo.public_key, + &tx_out.public_key, ) .into()), Ok(_) => Err(MemoServiceError::InvalidMemoTypeForValidation), diff --git a/mirror/src/private/main.rs b/mirror/src/private/main.rs index d173f2303..fed70dfd2 100644 --- a/mirror/src/private/main.rs +++ b/mirror/src/private/main.rs @@ -40,6 +40,7 @@ const SUPPORTED_ENDPOINTS: &[&str] = &[ "get_transaction_log", "get_wallet_status", "validate_confirmation", + "validate_sender_memo", "verify_address", "get_txos", "get_all_accounts",