Skip to content

Commit

Permalink
Adding shared secret to output txo (#926)
Browse files Browse the repository at this point in the history
* Adding shared secret to output txo and storing in DB

* storing shared secret when creating output
  • Loading branch information
briancorbin authored Nov 1, 2023
1 parent 3c7e1a5 commit 4f2ef9b
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 20 deletions.
4 changes: 0 additions & 4 deletions full-service/src/db/transaction_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,14 +592,10 @@ impl TransactionLogModel for TransactionLog {
.execute(conn)?;
}

// TODO - Get each payload txo and add it to the transaction_output_txos
// table for this transactions.
for payload_txo in unsigned_tx_proposal.payload_txos.iter() {
Txo::create_new_output(payload_txo, false, &transaction_log_id, conn)?;
}

// TODO - Get each change txo and add it to the transaction_output_txos
// table for this transaction as change.
for change_txo in unsigned_tx_proposal.change_txos.iter() {
Txo::create_new_output(change_txo, true, &transaction_log_id, conn)?;
}
Expand Down
7 changes: 6 additions & 1 deletion full-service/src/db/txo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,11 @@ impl TxoModel for Txo {

let txo_id = TxoID::from(&output_txo.tx_out);
let encoded_confirmation = mc_util_serial::encode(&output_txo.confirmation_number);

let shared_secret_bytes = output_txo
.shared_secret
.map(|shared_secret| shared_secret.to_bytes().to_vec());

let new_txo = NewTxo {
id: &txo_id.to_string(),
account_id: None,
Expand All @@ -798,7 +803,7 @@ impl TxoModel for Txo {
received_block_index: None,
spent_block_index: None,
confirmation: Some(&encoded_confirmation),
shared_secret: None, // no account id so we don't
shared_secret: shared_secret_bytes.as_deref(),
};

diesel::insert_into(txos::table)
Expand Down
8 changes: 4 additions & 4 deletions full-service/src/json_rpc/v2/api/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ where
None => None,
};

let unsigned_tx_proposal: UnsignedTxProposal = service
let unsigned_tx_proposal: UnsignedTxProposal = (&service
.build_transaction(
&account_id,
&[(
Expand All @@ -372,7 +372,7 @@ where
TransactionMemo::BurnRedemption(memo_data),
block_version,
)
.map_err(format_error)?
.map_err(format_error)?)
.try_into()
.map_err(format_error)?;

Expand Down Expand Up @@ -406,7 +406,7 @@ where
None => None,
};

let unsigned_tx_proposal: UnsignedTxProposal = service
let unsigned_tx_proposal: UnsignedTxProposal = (&service
.build_transaction(
&account_id,
&addresses_and_amounts,
Expand All @@ -418,7 +418,7 @@ where
TransactionMemo::Empty,
block_version,
)
.map_err(format_error)?
.map_err(format_error)?)
.try_into()
.map_err(format_error)?;

Expand Down
27 changes: 20 additions & 7 deletions full-service/src/json_rpc/v2/models/tx_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,43 @@ use protobuf::Message;
use serde_derive::{Deserialize, Serialize};
use std::convert::TryFrom;

#[derive(Deserialize, Serialize, Default, Debug)]
#[derive(Deserialize, Serialize, Default, Debug, PartialEq)]
pub struct UnsignedInputTxo {
pub tx_out_proto: String,
pub amount: AmountJSON,
pub subaddress_index: String,
}

#[derive(Clone, Deserialize, Serialize, Default, Debug)]
#[derive(Clone, Deserialize, Serialize, Default, Debug, PartialEq)]
pub struct InputTxo {
pub tx_out_proto: String,
pub amount: AmountJSON,
pub subaddress_index: String,
pub key_image: String,
}

#[derive(Clone, Deserialize, Serialize, Default, Debug)]
#[derive(Clone, Deserialize, Serialize, Default, Debug, PartialEq)]
pub struct OutputTxo {
pub tx_out_proto: String,
pub amount: AmountJSON,
pub recipient_public_address_b58: String,
pub confirmation_number: String,
pub shared_secret: Option<String>,
}

#[derive(Deserialize, Serialize, Debug, Default)]
#[derive(Deserialize, Serialize, Debug, Default, PartialEq)]
pub struct UnsignedTxProposal {
pub unsigned_tx_proto_bytes_hex: String,
pub unsigned_input_txos: Vec<UnsignedInputTxo>,
pub payload_txos: Vec<OutputTxo>,
pub change_txos: Vec<OutputTxo>,
}

impl TryFrom<crate::service::models::tx_proposal::UnsignedTxProposal> for UnsignedTxProposal {
impl TryFrom<&crate::service::models::tx_proposal::UnsignedTxProposal> for UnsignedTxProposal {
type Error = String;

fn try_from(
src: crate::service::models::tx_proposal::UnsignedTxProposal,
src: &crate::service::models::tx_proposal::UnsignedTxProposal,
) -> Result<Self, Self::Error> {
let unsigned_input_txos = src
.unsigned_input_txos
Expand All @@ -67,6 +68,9 @@ impl TryFrom<crate::service::models::tx_proposal::UnsignedTxProposal> for Unsign
&output_txo.recipient_public_address,
)?,
confirmation_number: hex::encode(output_txo.confirmation_number.as_ref()),
shared_secret: output_txo
.shared_secret
.map(|shared_secret| hex::encode(shared_secret.to_bytes())),
})
})
.collect::<Result<Vec<OutputTxo>, B58Error>>()
Expand All @@ -83,6 +87,9 @@ impl TryFrom<crate::service::models::tx_proposal::UnsignedTxProposal> for Unsign
&output_txo.recipient_public_address,
)?,
confirmation_number: hex::encode(output_txo.confirmation_number.as_ref()),
shared_secret: output_txo
.shared_secret
.map(|shared_secret| hex::encode(shared_secret.to_bytes())),
})
})
.collect::<Result<Vec<OutputTxo>, B58Error>>()
Expand All @@ -103,7 +110,7 @@ impl TryFrom<crate::service::models::tx_proposal::UnsignedTxProposal> for Unsign
}
}

#[derive(Clone, Deserialize, Serialize, Default, Debug)]
#[derive(Clone, Deserialize, Serialize, Default, Debug, PartialEq)]
pub struct TxProposal {
pub input_txos: Vec<InputTxo>,
pub payload_txos: Vec<OutputTxo>,
Expand Down Expand Up @@ -139,6 +146,9 @@ impl TryFrom<&crate::service::models::tx_proposal::TxProposal> for TxProposal {
&output_txo.recipient_public_address,
)?,
confirmation_number: hex::encode(output_txo.confirmation_number.as_ref()),
shared_secret: output_txo
.shared_secret
.map(|shared_secret| hex::encode(shared_secret.to_bytes())),
})
})
.collect::<Result<Vec<OutputTxo>, B58Error>>()
Expand All @@ -155,6 +165,9 @@ impl TryFrom<&crate::service::models::tx_proposal::TxProposal> for TxProposal {
&output_txo.recipient_public_address,
)?,
confirmation_number: hex::encode(output_txo.confirmation_number.as_ref()),
shared_secret: output_txo
.shared_secret
.map(|shared_secret| hex::encode(shared_secret.to_bytes())),
})
})
.collect::<Result<Vec<OutputTxo>, B58Error>>()
Expand Down
Loading

0 comments on commit 4f2ef9b

Please sign in to comment.