Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint and more API fields #24

Merged
merged 5 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions mobilecoind-json/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ fn pay_address_code(
let mut req = mc_mobilecoind_api::PayAddressCodeRequest::new();
req.set_sender_monitor_id(monitor_id);
req.set_sender_subaddress_index(subaddress_index);
req.set_b58_code(transfer.receiver_b58_address_code.clone());
req.set_amount(amount);
req.set_receiver_b58_code(transfer.receiver_b58_address_code.clone());
req.set_value(amount);
req.set_max_input_utxo_value(max_input_utxo_value);

let resp = state
Expand Down Expand Up @@ -518,7 +518,8 @@ fn check_receiver_transfer_status(
) -> Result<Json<JsonStatusResponse>, String> {
let mut receiver_receipt = mc_mobilecoind_api::ReceiverTxReceipt::new();
let mut tx_out_public_key = CompressedRistretto::new();
tx_out_public_key.set_data(hex::decode(&receipt.tx_public_key).map_err(|err| format!("{}", err))?);
tx_out_public_key
.set_data(hex::decode(&receipt.tx_public_key).map_err(|err| format!("{}", err))?);
receiver_receipt.set_tx_out_public_key(tx_out_public_key);
receiver_receipt
.set_tx_out_hash(hex::decode(&receipt.tx_out_hash).map_err(|err| format!("{}", err))?);
Expand Down
73 changes: 45 additions & 28 deletions mobilecoind/api/proto/mobilecoind_api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,10 @@ message AddMonitorRequest {
string name = 5;
}
message AddMonitorResponse {
// A hash of the monitor's public keys and subaddress range
bytes monitor_id = 1;

// False if the monitor already existed prior to the call, True if the monitor was created
bool is_new = 2;
}

Expand All @@ -282,7 +285,7 @@ message GetMonitorStatusResponse {
MonitorStatus status = 1;
}

// Get a list of UnspentTxOuts for a given monitor and subadddress index.
// Get a list of UnspentTxOuts for a given monitor and subaddress index.
message GetUnspentTxOutListRequest {
bytes monitor_id = 1;
uint64 subaddress_index = 2;
Expand Down Expand Up @@ -310,7 +313,7 @@ message GetAccountKeyResponse {
external.AccountKey account_key = 1;
}

// Get the public address for a given monitor and subadddress index.
// Get the public address for a given monitor and subaddress index.
message GetPublicAddressRequest {
bytes monitor_id = 1;
uint64 subaddress_index = 2;
Expand Down Expand Up @@ -344,8 +347,9 @@ message CreateRequestCodeResponse {
string b58_code = 1;
}

// Decode a base-58 encoded "MobileCoin Transfer Code" into entropy/tx_out_public_key/memo.
// This code provides a mobile client with everything required to construct a self-payment, allowing funds to be withdrawn from a gift card.
// Decode a base-58 encoded "MobileCoin Transfer Code" into entropy, tx_out_public_key, and memo.
// This code provides a client with everything required to construct a self-payment,
// allowing funds to be withdrawn from a gift card. The UTXO is included for convenience.
message ParseTransferCodeRequest {
string b58_code = 1;
}
Expand All @@ -356,7 +360,7 @@ message ParseTransferCodeResponse {
UnspentTxOut utxo = 4;
}

// Encode entropy/tx_out_public_key/memo into a base-58 "MobileCoin Transfer Code".
// Encode entropy, tx_out_public_key, and memo into a base-58 "MobileCoin Transfer Code".
message CreateTransferCodeRequest {
bytes entropy = 1;
external.CompressedRistretto tx_out_public_key = 2;
Expand Down Expand Up @@ -388,10 +392,10 @@ message CreateAddressCodeResponse {

// Generate a transaction proposal object.
// 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.
// - All inputs must belong to sender_monitor_id
// - Sum of inputs >= sum of outlays and fee.
// - The subset of inputs used is chosen automatically by mobilecoind.
// - If fee field is zero, mobilecoind will automatically choose a fee.
message GenerateTxRequest {
// Monitor id sending the funds.
bytes sender_monitor_id = 1;
Expand All @@ -400,9 +404,6 @@ message GenerateTxRequest {
uint64 change_subaddress_index = 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;

// Outputs to be generated by the transaction. This excludes change and fee.
Expand All @@ -427,6 +428,14 @@ message GenerateOptimizationTxRequest {

// Subaddress to operate on.
uint64 subaddress_index = 2;

// 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 = 3;

// 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 = 4;
}
message GenerateOptimizationTxResponse {
TxProposal tx_proposal = 1;
Expand Down Expand Up @@ -456,7 +465,7 @@ message GenerateTransferCodeTxRequest {
// The value used can be checked (but not changed) in tx_proposal.tx.prefix.tombstone_block
uint64 tombstone = 6;

// The memo to be included in the Transfer Code
// The memo to include in the Transfer Code
string memo = 7;
}
message GenerateTransferCodeTxResponse {
Expand All @@ -476,21 +485,28 @@ message GenerateTransferCodeTxResponse {
string b58_code = 5;
}

// Generate a transaction without a monitor, requires an account key and
// a list of UnspentTxOuts. All coins (minus the fee) are transferred to
// a single recipient. Used for temporary accounts like gift codes.
// Generate a transaction without using a monitor.
// Notes:
// - Requires an account key and a list of UTXOs owned by the account key
// - All coins (minus the fee) are transferred to a single recipient
// - Useful for withdrawing all funds from temporary accounts (transfer/gift codes).
message GenerateTxFromTxOutListRequest {
// Account key that owns the transactions
external.AccountKey account_key = 1;
// Account key that owns the TxOuts to transfer
external.AccountKey sender_account_key = 1;

// List of TxOuts to spend
// List of TxOuts to transfer
repeated UnspentTxOut input_list = 2;

// Address to transfer coins to
external.PublicAddress public_address = 3;
// Receiver's Public Address
external.PublicAddress receiver_public_address = 3;

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

// 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 = 5;
}
message GenerateTxFromTxOutListResponse {
TxProposal tx_proposal = 1;
Expand Down Expand Up @@ -621,15 +637,16 @@ message GetBalanceResponse {
uint64 balance = 1;
}

// Build and submit a simple payment and return any change to the Sender's subaddress.
// Build and submit a simple payment from a monitor_id/subaddress_index.
// Returns any change back to the same subaddress.
message SendPaymentRequest {
// Monitor id sending the funds.
bytes sender_monitor_id = 1;

// Subaddress the funds are coming from.
uint64 sender_subaddress_index = 2;

// Outputs to be generated by the transaction. This excludes change and fee.
// Outputs (Receiver/Value pairs) to be generated. This excludes fee and any change.
repeated Outlay outlay_list = 3;

// Fee in picoMOB (setting to 0 causes mobilecoind to choose a value).
Expand Down Expand Up @@ -664,11 +681,11 @@ message PayAddressCodeRequest {
// Subaddress the funds are coming from.
uint64 sender_subaddress_index = 2;

// Base-58 encoded "MobileCoin Address Code"
string b58_code = 3;
// receiver's base-58 encoded address
string receiver_b58_code = 3;

// Amount to pay
uint64 amount = 4;
// Total value to transfer in picoMOB
uint64 value = 4;

// 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
Expand Down
33 changes: 15 additions & 18 deletions mobilecoind/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ impl<T: BlockchainConnection + UserTxConnection + 'static> ServiceApi<T> {
&mut self,
request: mc_mobilecoind_api::GenerateTxFromTxOutListRequest,
) -> Result<mc_mobilecoind_api::GenerateTxFromTxOutListResponse, RpcStatus> {
let proto_account_key = request.account_key.as_ref().ok_or_else(|| {
let proto_account_key = request.sender_account_key.as_ref().ok_or_else(|| {
RpcStatus::new(
RpcStatusCode::INVALID_ARGUMENT,
Some("account_key".to_string()),
Expand All @@ -722,7 +722,7 @@ impl<T: BlockchainConnection + UserTxConnection + 'static> ServiceApi<T> {
})
.collect::<Result<Vec<UnspentTxOut>, RpcStatus>>()?;

let public_address = PublicAddress::try_from(request.get_public_address())
let public_address = PublicAddress::try_from(request.get_receiver_public_address())
.map_err(|err| rpc_internal_error("PublicAddress.try_from", err, &self.logger))?;

let tx_proposal = self
Expand Down Expand Up @@ -1156,15 +1156,12 @@ impl<T: BlockchainConnection + UserTxConnection + 'static> ServiceApi<T> {
&self.logger,
)
})?;
let tx_public_key =
RistrettoPublic::try_from(request.get_receipt().get_tx_out_public_key())
.map_err(|err| {
rpc_internal_error(
"RistrettoPublic.try_from",
err,
&self.logger,
)
})?;
let tx_public_key = RistrettoPublic::try_from(
request.get_receipt().get_tx_out_public_key()
)
.map_err(|err| {
rpc_internal_error("RistrettoPublic.try_from", err, &self.logger)
})?;
let view_private_key = monitor_data.account_key.view_private_key();

if request.get_receipt().get_confirmation_number().len() != 32 {
Expand Down Expand Up @@ -1428,7 +1425,7 @@ impl<T: BlockchainConnection + UserTxConnection + 'static> ServiceApi<T> {
request: mc_mobilecoind_api::PayAddressCodeRequest,
) -> Result<mc_mobilecoind_api::SendPaymentResponse, RpcStatus> {
// Sanity check.
if request.get_amount() == 0 {
if request.get_value() == 0 {
return Err(RpcStatus::new(
RpcStatusCode::INVALID_ARGUMENT,
Some("amount".to_string()),
Expand All @@ -1437,13 +1434,13 @@ impl<T: BlockchainConnection + UserTxConnection + 'static> ServiceApi<T> {

// Try and decode the address code.
let mut parse_address_code_request = mc_mobilecoind_api::ParseAddressCodeRequest::new();
parse_address_code_request.set_b58_code(request.get_b58_code().to_owned());
parse_address_code_request.set_b58_code(request.get_receiver_b58_code().to_owned());
let parse_address_code_response =
self.parse_address_code_impl(parse_address_code_request)?;

// Forward to SendPayment
let mut outlay = mc_mobilecoind_api::Outlay::new();
outlay.set_value(request.get_amount());
outlay.set_value(request.get_value());
outlay.set_public_address(parse_address_code_response.get_public_address().clone());

let mut send_payment_request = mc_mobilecoind_api::SendPaymentRequest::new();
Expand Down Expand Up @@ -2966,15 +2963,15 @@ mod test {
// Build a request to transfer the first two TxOuts
let tx_utxos = utxos[0..2].to_vec();
let mut request = mc_mobilecoind_api::GenerateTxFromTxOutListRequest::new();
request.set_account_key((&sender).into());
request.set_sender_account_key((&sender).into());
request.set_input_list(RepeatedField::from_vec(
tx_utxos
.iter()
.map(mc_mobilecoind_api::UnspentTxOut::from)
.collect(),
));
let receiver = AccountKey::random(&mut rng);
request.set_public_address((&receiver.default_subaddress()).into());
request.set_receiver_public_address((&receiver.default_subaddress()).into());
request.set_fee(MINIMUM_FEE);

let response = client.generate_tx_from_tx_out_list(&request).unwrap();
Expand Down Expand Up @@ -3593,8 +3590,8 @@ mod test {
let mut request = mc_mobilecoind_api::PayAddressCodeRequest::new();
request.set_sender_monitor_id(monitor_id.to_vec());
request.set_sender_subaddress_index(0);
request.set_b58_code(b58_code);
request.set_amount(1234);
request.set_receiver_b58_code(b58_code);
request.set_value(1234);

let response = client.pay_address_code(&request).unwrap();

Expand Down