mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-10-17 07:11:36 +02:00
avoid slate copies
This commit is contained in:
@@ -1615,8 +1615,7 @@ where
|
|||||||
C: NodeClient,
|
C: NodeClient,
|
||||||
K: Keychain,
|
K: Keychain,
|
||||||
{
|
{
|
||||||
let mut slate = slate.clone();
|
contract::view(&mut *w, keychain_mask, slate)
|
||||||
contract::view(&mut *w, keychain_mask, &mut slate)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sign transaction contract
|
/// Sign transaction contract
|
||||||
|
|||||||
@@ -92,28 +92,27 @@ where
|
|||||||
C: NodeClient,
|
C: NodeClient,
|
||||||
K: Keychain,
|
K: Keychain,
|
||||||
{
|
{
|
||||||
let sl = slate.clone();
|
contract::utils::verify_not_signed(w, slate.id)?;
|
||||||
contract::utils::verify_not_signed(w, sl.id)?;
|
|
||||||
// Reject terminal and unknown states before setup reserves keys.
|
// Reject terminal and unknown states before setup reserves keys.
|
||||||
contract::slate::next_state(&sl.state)?;
|
contract::slate::next_state(&slate.state)?;
|
||||||
|
|
||||||
// Ensure net_change has been provided
|
// Ensure net_change has been provided
|
||||||
let expected_net_change =
|
let expected_net_change =
|
||||||
contract::utils::get_net_change(existing_context.as_ref(), setup_args.net_change)?;
|
contract::utils::get_net_change(existing_context.as_ref(), setup_args.net_change)?;
|
||||||
if existing_context.is_none() {
|
if existing_context.is_none() {
|
||||||
verify_first_sign_net_change(&sl.state, sl.amount, expected_net_change)?;
|
verify_first_sign_net_change(&slate.state, slate.amount, expected_net_change)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define the values that must be provided in the setup phase at the sign step
|
// Define the values that must be provided in the setup phase at the sign step
|
||||||
let mut setup_args = setup_args.clone();
|
let mut setup_args = setup_args.clone();
|
||||||
setup_args.net_change = Some(expected_net_change);
|
setup_args.net_change = Some(expected_net_change);
|
||||||
setup_args.num_participants = sl.num_participants;
|
setup_args.num_participants = slate.num_participants;
|
||||||
setup_args.add_outputs = true; // we add outputs to the Context in case we haven't done that yet
|
setup_args.add_outputs = true; // we add outputs to the Context in case we haven't done that yet
|
||||||
contract::slate::verify_incoming_own_commitments(w, keychain_mask, &sl)?;
|
contract::slate::verify_incoming_own_commitments(w, keychain_mask, slate)?;
|
||||||
|
|
||||||
// Ensure Setup phase is done and that inputs/outputs have been added to the Context
|
// Ensure Setup phase is done and that inputs/outputs have been added to the Context
|
||||||
let (mut sl, mut context) =
|
let (mut sl, mut context) =
|
||||||
setup::compute(w, keychain_mask, &sl, &setup_args, existing_context)?;
|
setup::compute(w, keychain_mask, slate, &setup_args, existing_context)?;
|
||||||
// Add outputs to the slate, verify the payment proof and sign the slate
|
// Add outputs to the slate, verify the payment proof and sign the slate
|
||||||
contract::slate::add_outputs(w, keychain_mask, &mut sl, &context)?;
|
contract::slate::add_outputs(w, keychain_mask, &mut sl, &context)?;
|
||||||
contract::slate::verify_own_commitments(w, keychain_mask, &sl, &context)?;
|
contract::slate::verify_own_commitments(w, keychain_mask, &sl, &context)?;
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ fn tx_net_change(tx: &TxLogEntry) -> Result<i64, Error> {
|
|||||||
pub fn view<C, K>(
|
pub fn view<C, K>(
|
||||||
w: &mut WalletBackend<C, K>,
|
w: &mut WalletBackend<C, K>,
|
||||||
keychain_mask: Option<&SecretKey>,
|
keychain_mask: Option<&SecretKey>,
|
||||||
slate: &mut Slate,
|
slate: &Slate,
|
||||||
) -> Result<ContractView, Error>
|
) -> Result<ContractView, Error>
|
||||||
where
|
where
|
||||||
C: NodeClient,
|
C: NodeClient,
|
||||||
|
|||||||
+4
-43
@@ -975,47 +975,7 @@ impl Serialize for Slate {
|
|||||||
////// V5
|
////// V5
|
||||||
impl From<Slate> for SlateV5 {
|
impl From<Slate> for SlateV5 {
|
||||||
fn from(slate: Slate) -> SlateV5 {
|
fn from(slate: Slate) -> SlateV5 {
|
||||||
let Slate {
|
Self::from(&slate)
|
||||||
num_participants: num_parts,
|
|
||||||
id,
|
|
||||||
state,
|
|
||||||
tx: _,
|
|
||||||
amount,
|
|
||||||
fee_fields,
|
|
||||||
kernel_features,
|
|
||||||
ttl_cutoff_height: ttl,
|
|
||||||
offset: off,
|
|
||||||
participant_data,
|
|
||||||
version_info,
|
|
||||||
payment_proof,
|
|
||||||
kernel_features_args,
|
|
||||||
} = slate.clone();
|
|
||||||
let participant_data = map_vec!(participant_data, |data| ParticipantDataV5::from(data));
|
|
||||||
let ver = VersionCompatInfoV5::from(&version_info);
|
|
||||||
let payment_proof = match payment_proof {
|
|
||||||
Some(p) => Some(PaymentInfoV5::from(&p)),
|
|
||||||
None => None,
|
|
||||||
};
|
|
||||||
let feat_args = match kernel_features_args {
|
|
||||||
Some(a) => Some(KernelFeaturesArgsV5::from(&a)),
|
|
||||||
None => None,
|
|
||||||
};
|
|
||||||
let sta = SlateStateV5::from(&state);
|
|
||||||
SlateV5 {
|
|
||||||
num_parts,
|
|
||||||
id,
|
|
||||||
sta,
|
|
||||||
coms: (&slate).into(),
|
|
||||||
amt: amount,
|
|
||||||
fee: fee_fields,
|
|
||||||
feat: kernel_features,
|
|
||||||
ttl,
|
|
||||||
off,
|
|
||||||
sigs: participant_data,
|
|
||||||
ver,
|
|
||||||
proof: payment_proof,
|
|
||||||
feat_args,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1191,6 +1151,7 @@ impl From<OutputFeatures> for OutputFeaturesV5 {
|
|||||||
///// V5
|
///// V5
|
||||||
impl From<SlateV5> for Slate {
|
impl From<SlateV5> for Slate {
|
||||||
fn from(slate: SlateV5) -> Slate {
|
fn from(slate: SlateV5) -> Slate {
|
||||||
|
let tx = (&slate).into();
|
||||||
let SlateV5 {
|
let SlateV5 {
|
||||||
num_parts: num_participants,
|
num_parts: num_participants,
|
||||||
id,
|
id,
|
||||||
@@ -1205,7 +1166,7 @@ impl From<SlateV5> for Slate {
|
|||||||
ver,
|
ver,
|
||||||
proof: payment_proof,
|
proof: payment_proof,
|
||||||
feat_args,
|
feat_args,
|
||||||
} = slate.clone();
|
} = slate;
|
||||||
let participant_data = map_vec!(participant_data, |data| ParticipantData::from(data));
|
let participant_data = map_vec!(participant_data, |data| ParticipantData::from(data));
|
||||||
let version_info = VersionCompatInfo::from(&ver);
|
let version_info = VersionCompatInfo::from(&ver);
|
||||||
let payment_proof = match &payment_proof {
|
let payment_proof = match &payment_proof {
|
||||||
@@ -1221,7 +1182,7 @@ impl From<SlateV5> for Slate {
|
|||||||
num_participants,
|
num_participants,
|
||||||
id,
|
id,
|
||||||
state,
|
state,
|
||||||
tx: (&slate).into(),
|
tx,
|
||||||
amount,
|
amount,
|
||||||
fee_fields,
|
fee_fields,
|
||||||
kernel_features,
|
kernel_features,
|
||||||
|
|||||||
Reference in New Issue
Block a user