Skip to content

Commit

Permalink
add support for mixed transactions, including those with SCIs in them
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Mar 11, 2023
1 parent dd24518 commit 752a29d
Show file tree
Hide file tree
Showing 12 changed files with 742 additions and 37 deletions.
47 changes: 33 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ members = [
"util/telemetry",
"util/test-helper",
"util/test-vector",
"util/u64-ratio",
"util/uri",
"util/vec-map",
"util/zip-exact",
Expand Down
64 changes: 63 additions & 1 deletion mobilecoind/api/proto/mobilecoind_api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,20 @@ enum TxStatus {
}

// Structure used in specifying the list of outputs when generating a transaction.
// Here the token id is implied from context, and matches the fee token id.
message Outlay {
uint64 value = 1;
external.PublicAddress receiver = 2;
}

// Structure used in specifying the list of outputs in a transaction.
// Here the token id is explicit.
message OutlayV2 {
uint64 value = 1;
external.PublicAddress receiver = 2;
uint64 token_id = 3;
}

// Structure used to refer to a TxOut in the ledger that is presumed to be spendable.
// The structure is annotated with extra information needed to spend the TxOut in a payment, calculated using the private keys that control the TxOut.
message UnspentTxOut {
Expand Down Expand Up @@ -142,14 +151,24 @@ message UnspentTxOut {
bytes monitor_id = 10;
}

// Structure used to refer to an SCI that we want to add to a transaction.
// The structure has additional information -- if it's a partial fill SCI, we need to know the partial fill amount.
message SciForTx {
/// The signed input we want to add
external.SignedContingentInput sci = 1;

/// If it's a partial fill SCI, the value we wish to fill it for
uint64 partial_fill_value = 2;
}

// Structure used to refer to a prepared transaction
message TxProposal {
// List of inputs being spent.
repeated UnspentTxOut input_list = 1;

// List of outputs being created.
// This excludes the fee output.
repeated Outlay outlay_list = 2;
repeated OutlayV2 outlay_list = 2;

// The actual transaction object.
// Together with the private view/spend keys, this structure contains all information in existence about the transaction.
Expand Down Expand Up @@ -493,12 +512,55 @@ message GenerateTxRequest {

// Token id to use for the transaction.
uint64 token_id = 7;

// List of SCIs to be added to the transaction
repeated SciForTx scis = 8;
}

message GenerateTxResponse {
TxProposal tx_proposal = 1;
}

// Generate a transaction proposal object with mixed token types.
// Notes:
// - Sum of inputs needs to be greater than sum of outlays and fee.
// - The set of inputs to use would be chosen automatically by mobilecoind.
// - The fee field could be set to zero, in which case mobilecoind would choose a fee.
// Right now that fee is hardcoded.
message GenerateMixedTxRequest {
// Monitor id sending the funds.
bytes sender_monitor_id = 1;

// Subaddress to return change to.
uint64 change_subaddress = 2;

// List of UnspentTxOuts to be spent by the transaction.
// All UnspentTxOuts must belong to the same sender_monitor_id.
// mobilecoind would choose a subset of these inputs to construct the transaction.
// Total input amount must be >= sum of outlays + fees.
repeated UnspentTxOut input_list = 3;

// List of SCIs to be added to the transaction
repeated SciForTx scis = 4;

// Outputs to be generated by the transaction. This excludes change and fee.
repeated OutlayV2 outlay_list = 5;

// Fee in picoMOB (setting to 0 causes mobilecoind to choose a value).
// The value used can be checked (but not changed) in tx_proposal.tx.prefix.fee
uint64 fee = 6;

// Token id to use for the transaction.
uint64 fee_token_id = 7;

// Tombstone block (setting to 0 causes mobilecoind to choose a value).
// The value used can be checked (but not changed) in tx_proposal.tx.prefix.tombstone_block
uint64 tombstone = 8;
}

message GenerateMixedTxResponse {
TxProposal tx_proposal = 1;
}
// Generate a transaction that merges a few UnspentTxOuts into one, in order to reduce wallet fragmentation.
message GenerateOptimizationTxRequest {
// Monitor Id to operate on.
Expand Down
25 changes: 24 additions & 1 deletion mobilecoind/src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! types.
use crate::{
payments::{Outlay, TxProposal},
payments::{Outlay, SciForTx, TxProposal},
utxo_store::UnspentTxOut,
};
use mc_account_keys::PublicAddress;
Expand Down Expand Up @@ -171,6 +171,29 @@ impl TryFrom<&api::TxProposal> for TxProposal {
}
}

impl From<&SciForTx> for api::SciForTx {
fn from(src: &SciForTx) -> Self {
let mut dst = Self::new();
dst.set_sci((&src.sci).into());
dst.set_partial_fill_value(src.partial_fill_value);
dst
}
}

impl TryFrom<&api::SciForTx> for SciForTx {
type Error = ConversionError;

fn try_from(src: &api::SciForTx) -> Result<Self, Self::Error> {
let sci = src.get_sci().try_into()?;
let partial_fill_value = src.partial_fill_value;

Ok(Self {
sci,
partial_fill_value,
})
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
Loading

0 comments on commit 752a29d

Please sign in to comment.