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

Compact Slate - Compact Version Field #377

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
cdedef1
WIP add support for sending compact slates
yeastplume Mar 13, 2020
98603a9
add repopulate_tx function to internal API
yeastplume Mar 17, 2020
2ebae92
first pass at compacted slate working
yeastplume Mar 17, 2020
d9784cf
move slate compaction to separate function
yeastplume Mar 17, 2020
c00266a
test fixes
yeastplume Mar 19, 2020
7b173df
support compact slate inits in invoice workflow
yeastplume Mar 19, 2020
f6da7b0
add compress flags to send and invoice
yeastplume Mar 19, 2020
1d6a536
attempting to remove is_compact and assume all V4 slates begin as com…
yeastplume Mar 20, 2020
4a45c7d
attempting to calculate offsets when full tx data isn't available
yeastplume Mar 23, 2020
11d7872
update calc_commit to use participant blind data
yeastplume Mar 26, 2020
ea551ea
update doctests for compact slates
yeastplume Mar 26, 2020
8c80ffd
start to remove unneeded fields from serialization
yeastplume Mar 26, 2020
47e3c03
make num_participants optional
yeastplume Mar 26, 2020
56c022c
remove other_version from slate
yeastplume Mar 26, 2020
2ea52fc
Merge branch 'master' into compact_slate_send
yeastplume Mar 26, 2020
b3a60b3
use grin master branch
yeastplume Mar 26, 2020
562067a
remove message field
yeastplume Mar 26, 2020
386de9a
lock height assumed to be 0 if it doesn't exist
yeastplume Mar 30, 2020
b025ec5
don't serialise receiver signature when null
yeastplume Mar 30, 2020
c2bcab8
don't serialize payment_info if not needed
yeastplume Apr 2, 2020
d35362c
remove participant id from participant info
yeastplume Apr 2, 2020
6305eb5
add note on id field
yeastplume Apr 2, 2020
e0a6870
fix finalize and receive doctests
yeastplume Apr 8, 2020
ee2c9a8
finalize_tx tests, init_send_tx tests
yeastplume Apr 8, 2020
8ba5023
doctests for process_invoice_tx, retrieve_tx, tx_lock_outputs
yeastplume Apr 8, 2020
c85a6ca
finished test changes
yeastplume Apr 8, 2020
ee6df2f
change serialization of version info, remove unneeded traits from ver…
yeastplume Apr 15, 2020
091be5f
text fixes and retain internal version_info name
yeastplume Apr 15, 2020
5365ce0
rest of doctest fixes
yeastplume Apr 15, 2020
94aac52
remove SlateVersionProbe and replace with enum deserialization
yeastplume Apr 15, 2020
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
491 changes: 243 additions & 248 deletions Cargo.lock

Large diffs are not rendered by default.

67 changes: 2 additions & 65 deletions api/src/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,57 +268,6 @@ where
)
}

/// Verifies all messages in the slate match their public keys.
///
/// The option messages themselves are part of the `participant_data` field within the slate.
/// Messages are signed with the same key used to sign for the paricipant's inputs, and can thus be
/// verified with the public key found in the `public_blind_excess` field. This function is a
/// simple helper to returns whether all signatures in the participant data match their public
/// keys.
///
/// # Arguments
///
/// * `slate` - The transaction [`Slate`](../grin_wallet_libwallet/slate/struct.Slate.html).
///
/// # Returns
/// * `Ok(())` if successful and the signatures validate
/// * or [`libwallet::Error`](../grin_wallet_libwallet/struct.Error.html) if an error is encountered.
///
/// # Example
/// Set up as in [`new`](struct.Foreign.html#method.new) method above.
/// ```
/// # grin_wallet_api::doctest_helper_setup_doc_env_foreign!(wallet, wallet_config);
///
/// let mut api_foreign = Foreign::new(wallet.clone(), None, None);
///
/// # let slate = Slate::blank(2);
/// // Receive a slate via some means
///
/// let res = api_foreign.verify_slate_messages(&slate);
///
/// if let Err(e) = res {
/// // Messages don't validate, likely return an error
/// // ...
/// } else {
/// // Slate messages are fine
/// }
///
///
/// ```

pub fn verify_slate_messages(&self, slate: &Slate) -> Result<(), Error> {
if let Some(m) = self.middleware.as_ref() {
let mut w_lock = self.wallet_inst.lock();
let w = w_lock.lc_provider()?.wallet_inst()?;
m(
ForeignCheckMiddlewareFn::VerifySlateMessages,
w.w2n_client().get_version_info(),
Some(slate),
)?;
}
foreign::verify_slate_messages(slate)
}

/// Recieve a tranaction created by another party, returning the modified
/// [`Slate`](../grin_wallet_libwallet/slate/struct.Slate.html) object, modified with
/// the recipient's output for the transaction amount, and public signature data. This slate can
Expand All @@ -340,12 +289,6 @@ where
/// excess value).
/// * `dest_acct_name` - The name of the account into which the slate should be received. If
/// `None`, the default account is used.
/// * `message` - An optional participant message to include alongside the recipient's public
/// ParticipantData within the slate. This message will include a signature created with the
/// recipient's private excess value, and will be publically verifiable. Note this message is for
/// the convenience of the participants during the exchange; it is not included in the final
/// transaction sent to the chain. The message will be truncated to 256 characters.
/// Validation of this message is optional.
///
/// # Returns
/// * a result containing:
Expand All @@ -367,20 +310,15 @@ where
///
/// // . . .
/// // Obtain a sent slate somehow
/// let result = api_foreign.receive_tx(&slate, None, None);
/// let result = api_foreign.receive_tx(&slate, None);
///
/// if let Ok(slate) = result {
/// // Send back to recipient somehow
/// // ...
/// }
/// ```

pub fn receive_tx(
&self,
slate: &Slate,
dest_acct_name: Option<&str>,
message: Option<String>,
) -> Result<Slate, Error> {
pub fn receive_tx(&self, slate: &Slate, dest_acct_name: Option<&str>) -> Result<Slate, Error> {
let mut w_lock = self.wallet_inst.lock();
let w = w_lock.lc_provider()?.wallet_inst()?;
if let Some(m) = self.middleware.as_ref() {
Expand All @@ -395,7 +333,6 @@ where
(&self.keychain_mask).as_ref(),
slate,
dest_acct_name,
message,
self.doctest_mode,
)
}
Expand Down
259 changes: 35 additions & 224 deletions api/src/foreign_rpc.rs

Large diffs are not rendered by default.

89 changes: 17 additions & 72 deletions api/src/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ where
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// api_owner.tx_lock_outputs(None, &slate, 0);
/// api_owner.tx_lock_outputs(None, &slate);
/// }
/// ```

Expand Down Expand Up @@ -670,7 +670,7 @@ where
let comm_adapter = create_sender(&sa.method, &sa.dest, tor_config_lock.clone())
.map_err(|e| ErrorKind::GenericError(format!("{}", e)))?;
slate = comm_adapter.send_tx(&slate)?;
self.tx_lock_outputs(keychain_mask, &slate, 0)?;
self.tx_lock_outputs(keychain_mask, &slate)?;
let slate = match sa.finalize {
true => self.finalize_tx(keychain_mask, &slate)?,
false => slate,
Expand Down Expand Up @@ -847,19 +847,18 @@ where
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// api_owner.tx_lock_outputs(None, &slate, 0);
/// api_owner.tx_lock_outputs(None, &slate);
/// }
/// ```

pub fn tx_lock_outputs(
&self,
keychain_mask: Option<&SecretKey>,
slate: &Slate,
participant_id: usize,
) -> Result<(), Error> {
let mut w_lock = self.wallet_inst.lock();
let w = w_lock.lc_provider()?.wallet_inst()?;
owner::tx_lock_outputs(&mut **w, keychain_mask, slate, participant_id)
owner::tx_lock_outputs(&mut **w, keychain_mask, slate)
}

/// Finalizes a transaction, after all parties
Expand Down Expand Up @@ -911,7 +910,7 @@ where
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// let res = api_owner.tx_lock_outputs(None, &slate, 0);
/// let res = api_owner.tx_lock_outputs(None, &slate);
/// //
/// // Retrieve slate back from recipient
/// //
Expand Down Expand Up @@ -971,7 +970,7 @@ where
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// let res = api_owner.tx_lock_outputs(None, &slate, 0);
/// let res = api_owner.tx_lock_outputs(None, &slate);
/// //
/// // Retrieve slate back from recipient
/// //
Expand Down Expand Up @@ -1043,7 +1042,7 @@ where
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// let res = api_owner.tx_lock_outputs(None, &slate, 0);
/// let res = api_owner.tx_lock_outputs(None, &slate);
/// //
/// // We didn't get the slate back, or something else went wrong
/// //
Expand Down Expand Up @@ -1116,70 +1115,6 @@ where
owner::get_stored_tx(&**w, tx_log_entry)
}

/// Verifies all messages in the slate match their public keys.
///
/// The optional messages themselves are part of the `participant_data` field within the slate.
/// Messages are signed with the same key used to sign for the paricipant's inputs, and can thus be
/// verified with the public key found in the `public_blind_excess` field. This function is a
/// simple helper to returns whether all signatures in the participant data match their public
/// keys.
///
/// # Arguments
///
/// * `keychain_mask` - Wallet secret mask to XOR against the stored wallet seed before using, if
/// being used.
/// * `slate` - The transaction [`Slate`](../grin_wallet_libwallet/slate/struct.Slate.html).
///
/// # Returns
/// * `Ok(())` if successful and the signatures validate
/// * or [`libwallet::Error`](../grin_wallet_libwallet/struct.Error.html) if an error is encountered.
///
/// # Example
/// Set up as in [`new`](struct.Owner.html#method.new) method above.
/// ```
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
///
/// let mut api_owner = Owner::new(wallet.clone(), None);
/// let args = InitTxArgs {
/// src_acct_name: None,
/// amount: 2_000_000_000,
/// minimum_confirmations: 10,
/// max_outputs: 500,
/// num_change_outputs: 1,
/// selection_strategy_is_use_all: false,
/// message: Some("Just verify messages".to_owned()),
/// ..Default::default()
/// };
/// let result = api_owner.init_send_tx(
/// None,
/// args,
/// );
///
/// if let Ok(slate) = result {
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// let res = api_owner.tx_lock_outputs(None, &slate, 0);
/// //
/// // Retrieve slate back from recipient
/// //
/// let res = api_owner.verify_slate_messages(None, &slate);
/// }
/// ```
pub fn verify_slate_messages(
&self,
keychain_mask: Option<&SecretKey>,
slate: &Slate,
) -> Result<(), Error> {
{
let mut w_lock = self.wallet_inst.lock();
let w = w_lock.lc_provider()?.wallet_inst()?;
// Test keychain mask, to keep API consistent
let _ = w.keychain(keychain_mask)?;
}
owner::verify_slate_messages(slate)
}

/// Scans the entire UTXO set from the node, identify which outputs belong to the given wallet
/// update the wallet state to be consistent with what's currently in the UTXO set.
///
Expand Down Expand Up @@ -2149,6 +2084,16 @@ where
) -> Result<(bool, bool), Error> {
owner::verify_payment_proof(self.wallet_inst.clone(), keychain_mask, proof)
}

/// Return my participant data
// TODO: This will be removed once state is added to slate
pub fn context_is_invoice(
&self,
keychain_mask: Option<&SecretKey>,
slate: &Slate,
) -> Result<bool, Error> {
owner::context_is_invoice(self.wallet_inst.clone(), keychain_mask, slate)
}
}

#[doc(hidden)]
Expand Down
Loading