Skip to content

Commit

Permalink
Specify Subaddress for Sender Memo Credential (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
briancorbin authored Nov 10, 2022
1 parent e1cda43 commit dbd6de7
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 47 deletions.
10 changes: 5 additions & 5 deletions full-service/src/db/transaction_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ mod tests {
.unwrap();
builder.set_tombstone(0).unwrap();
builder.select_txos(&conn, None).unwrap();
let unsigned_tx_proposal = builder.build(TransactionMemo::RTH, &conn).unwrap();
let unsigned_tx_proposal = builder.build(TransactionMemo::RTH(None), &conn).unwrap();
let tx_proposal = unsigned_tx_proposal.sign(&account_key).unwrap();

// Log submitted transaction from tx_proposal
Expand Down Expand Up @@ -769,7 +769,7 @@ mod tests {

builder.set_tombstone(0).unwrap();
builder.select_txos(&conn, None).unwrap();
let unsigned_tx_proposal = builder.build(TransactionMemo::RTH, &conn).unwrap();
let unsigned_tx_proposal = builder.build(TransactionMemo::RTH(None), &conn).unwrap();
let tx_proposal = unsigned_tx_proposal.sign(&account_key).unwrap();

let tx_log = TransactionLog::log_submitted(
Expand Down Expand Up @@ -848,7 +848,7 @@ mod tests {
.unwrap();
builder.set_tombstone(0).unwrap();
builder.select_txos(&conn, None).unwrap();
let unsigned_tx_proposal = builder.build(TransactionMemo::RTH, &conn).unwrap();
let unsigned_tx_proposal = builder.build(TransactionMemo::RTH(None), &conn).unwrap();
let tx_proposal = unsigned_tx_proposal.sign(&account_key).unwrap();

// Log submitted transaction from tx_proposal
Expand Down Expand Up @@ -946,7 +946,7 @@ mod tests {
.unwrap();
builder.set_tombstone(0).unwrap();
builder.select_txos(&conn, None).unwrap();
let unsigned_tx_proposal = builder.build(TransactionMemo::RTH, &conn).unwrap();
let unsigned_tx_proposal = builder.build(TransactionMemo::RTH(None), &conn).unwrap();
let tx_proposal = unsigned_tx_proposal.sign(&account_key).unwrap();

assert_eq!(
Expand Down Expand Up @@ -1013,7 +1013,7 @@ mod tests {
.unwrap();
builder.set_tombstone(0).unwrap();
builder.select_txos(&conn, None).unwrap();
let unsigned_tx_proposal = builder.build(TransactionMemo::RTH, &conn).unwrap();
let unsigned_tx_proposal = builder.build(TransactionMemo::RTH(None), &conn).unwrap();
let tx_proposal = unsigned_tx_proposal.sign(&account_key).unwrap();

// Log submitted transaction from tx_proposal
Expand Down
2 changes: 1 addition & 1 deletion full-service/src/db/txo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2186,7 +2186,7 @@ mod tests {
.unwrap();
builder.select_txos(&conn, None).unwrap();
builder.set_tombstone(0).unwrap();
let unsigned_tx_proposal = builder.build(TransactionMemo::RTH, &conn).unwrap();
let unsigned_tx_proposal = builder.build(TransactionMemo::RTH(None), &conn).unwrap();
let proposal = unsigned_tx_proposal.sign(&sender_account_key).unwrap();

// Sleep to make sure that the foreign keys exist
Expand Down
4 changes: 2 additions & 2 deletions full-service/src/json_rpc/v1/api/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ where
tombstone_block,
max_spendable_value,
comment,
TransactionMemo::RTH,
TransactionMemo::RTH(None),
None,
)
.map_err(format_error)?;
Expand Down Expand Up @@ -279,7 +279,7 @@ where
Some(Mob::ID.to_string()),
tombstone_block,
max_spendable_value,
TransactionMemo::RTH,
TransactionMemo::RTH(None),
None,
)
.map_err(format_error)?;
Expand Down
2 changes: 2 additions & 0 deletions full-service/src/json_rpc/v2/api/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub enum JsonCommandRequest {
max_spendable_value: Option<String>,
comment: Option<String>,
block_version: Option<String>,
sender_memo_credential_subaddress_index: Option<String>,
},
build_burn_transaction {
account_id: String,
Expand All @@ -77,6 +78,7 @@ pub enum JsonCommandRequest {
tombstone_block: Option<String>,
max_spendable_value: Option<String>,
block_version: Option<String>,
sender_memo_credential_subaddress_index: Option<String>,
},
build_unsigned_burn_transaction {
account_id: String,
Expand Down
14 changes: 12 additions & 2 deletions full-service/src/json_rpc/v2/api/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ where
max_spendable_value,
comment,
block_version,
sender_memo_credential_subaddress_index,
} => {
// The user can specify a list of addresses and values,
// or a single address and a single value.
Expand All @@ -161,6 +162,10 @@ where
None => None,
};

let sender_memo_credential_subaddress_index = sender_memo_credential_subaddress_index
.map(|i| i.parse::<u64>().map_err(format_error))
.transpose()?;

let (transaction_log, associated_txos, value_map, tx_proposal) = service
.build_sign_and_submit_transaction(
&account_id,
Expand All @@ -171,7 +176,7 @@ where
tombstone_block,
max_spendable_value,
comment,
TransactionMemo::RTH,
TransactionMemo::RTH(sender_memo_credential_subaddress_index),
block_version,
)
.map_err(format_error)?;
Expand Down Expand Up @@ -249,6 +254,7 @@ where
tombstone_block,
max_spendable_value,
block_version,
sender_memo_credential_subaddress_index,
} => {
// The user can specify a list of addresses and values,
// or a single address and a single value.
Expand All @@ -265,6 +271,10 @@ where
None => None,
};

let sender_memo_credential_subaddress_index = sender_memo_credential_subaddress_index
.map(|i| i.parse::<u64>().map_err(format_error))
.transpose()?;

let tx_proposal = service
.build_and_sign_transaction(
&account_id,
Expand All @@ -274,7 +284,7 @@ where
fee_token_id,
tombstone_block,
max_spendable_value,
TransactionMemo::RTH,
TransactionMemo::RTH(sender_memo_credential_subaddress_index),
block_version,
)
.map_err(format_error)?;
Expand Down
2 changes: 1 addition & 1 deletion full-service/src/service/gift_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ where
None,
tombstone_block.map(|t| t.to_string()),
max_spendable_value.map(|f| f.to_string()),
TransactionMemo::RTH,
TransactionMemo::RTH(None),
None,
)?;

Expand Down
8 changes: 4 additions & 4 deletions full-service/src/service/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ mod tests {
None,
None,
None,
TransactionMemo::RTH,
TransactionMemo::RTH(None),
None,
)
.expect("Could not build transaction");
Expand Down Expand Up @@ -549,7 +549,7 @@ mod tests {
None,
None,
None,
TransactionMemo::RTH,
TransactionMemo::RTH(None),
None,
)
.expect("Could not build transaction");
Expand Down Expand Up @@ -673,7 +673,7 @@ mod tests {
None,
None,
None,
TransactionMemo::RTH,
TransactionMemo::RTH(None),
None,
)
.expect("Could not build transaction");
Expand Down Expand Up @@ -814,7 +814,7 @@ mod tests {
None,
None,
None,
TransactionMemo::RTH,
TransactionMemo::RTH(None),
None,
)
.expect("Could not build transaction");
Expand Down
Loading

0 comments on commit dbd6de7

Please sign in to comment.