Skip to content

Commit

Permalink
Update mirror endpoints (#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
briancorbin authored Nov 18, 2023
1 parent 38b2b37 commit 288978a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
10 changes: 10 additions & 0 deletions full-service/src/db/txo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<PublicAddress>, WalletDbError>;

fn account(&self, conn: Conn) -> Result<Option<Account>, WalletDbError>;
}

impl TxoModel for Txo {
Expand Down Expand Up @@ -2150,6 +2152,14 @@ impl TxoModel for Txo {
_ => Ok(None),
}
}

fn account(&self, conn: Conn) -> Result<Option<Account>, 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(
Expand Down
1 change: 0 additions & 1 deletion full-service/src/json_rpc/v2/api/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ pub enum JsonCommandRequest {
confirmation: String,
},
validate_sender_memo {
account_id: String,
txo_id: String,
sender_address: String,
},
Expand Down
3 changes: 1 addition & 2 deletions full-service/src/json_rpc/v2/api/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down
25 changes: 11 additions & 14 deletions full-service/src/service/memo.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -80,7 +75,6 @@ impl From<MemoDecodingError> for MemoServiceError {
pub trait MemoService {
fn validate_sender_memo(
&self,
account_id: &AccountID,
txo_id_hex: &str,
sender_address: &str,
) -> Result<bool, MemoServiceError>;
Expand All @@ -93,7 +87,6 @@ where
{
fn validate_sender_memo(
&self,
account_id: &AccountID,
txo_id_hex: &str,
sender_address: &str,
) -> Result<bool, MemoServiceError> {
Expand All @@ -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(),
};
Expand All @@ -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),
Expand Down
1 change: 1 addition & 0 deletions mirror/src/private/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 288978a

Please sign in to comment.