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

Various fixes + updates to contract RSR + SRS flows #70

Merged
merged 2 commits into from
Nov 23, 2023
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
428 changes: 252 additions & 176 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async-std = "1.6.2"
isahc = { version = "0.9.6", features = ["json"] }
image = "0.23.8"
opener = "0.4.1"
chrono = { version = "0.4", features = ['serde'] }
chrono = { version = "0.4.11", features = ["serde"] }
log = "0.4"
timeago = "0.2.1"
isolang = "1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ isahc = { version = "1.1.0", features = ["json"] }
zip = "0.5.10"
glob = "0.3.0"
once_cell = "1.6.0"
chrono = { version = "0.4", features = ['serde'] }
chrono = { version = "0.4.11", features = ['serde'] }
log = "0.4"
walkdir = "2.3"
retry = "1.2"
Expand Down
8 changes: 4 additions & 4 deletions crates/core/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ pub use global::ChainTypes;
pub use grin_wallet_impls::HTTPNodeClient;
pub use grin_wallet_libwallet::{
InitTxArgs, RetrieveTxQueryArgs, RetrieveTxQuerySortOrder, Slate, SlateState, Slatepack,
SlatepackAddress, StatusMessage, TxLogEntry, TxLogEntryType, WalletInfo,
SlatepackAddress, StatusMessage, TxLogEntry, TxLogEntryType, WalletInfo,
};

pub use grin_wallet_libwallet::contract::types::{
ContractNewArgsAPI, ContractRevokeArgsAPI, ContractSetupArgsAPI,
ContractNewArgsAPI, ContractRevokeArgsAPI, ContractSetupArgsAPI, ProofArgs
};

use crate::error::GrinWalletInterfaceError;
Expand Down Expand Up @@ -90,7 +90,7 @@ pub type WalletInterfaceHttpNodeClient = WalletInterface<

pub struct WalletInterface<L, C>
where
L: WalletLCProvider<'static, C, keychain::ExtKeychain> + 'static,
L: WalletLCProvider<'static, C, grin_keychain::keychain::ExtKeychain> + 'static,
C: NodeClient + 'static + Clone,
{
pub chain_type: Option<grin_core::global::ChainTypes>,
Expand Down Expand Up @@ -585,7 +585,7 @@ where
if let Some(o) = &w.owner_api {
let slate = o.contract_sign(None, &slate, &args)?;
if send_to_chain_if_ready {
if slate.state == SlateState::Standard3 || slate.state == SlateState::Standard3 {
if slate.state == SlateState::Standard3 || slate.state == SlateState::Invoice3 {
o.post_tx(None, &slate, false)?;
return Ok((slate.clone(), None));
}
Expand Down
1 change: 1 addition & 0 deletions locale/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@
"tx-reception-instruction": "If you agree to this transaction, press 'Sign' below, then return the resulting transaction to the sender for completion.",
"tx-reception-instruction-2": "This transaction will not be completed until the sender has finalized it and posted it to the chain",
"tx-s1-finalization-1": "You are finalizing an agreement to pay [AMOUNT] Grin",
"tx-i1-finalization-1": "You are finalizing an agreement to receive [AMOUNT] Grin",
"tx-s1-finalization-2": "Along with a mining fee of [AMOUNT]",
"tx-s1-finalization-3": "This will complete the transaction and post it to the chain, at which point it becomes irreversible.",
"tx-s1-finalization-self-send": "You are self-sending [AMOUNT] Grin",
Expand Down
1 change: 1 addition & 0 deletions locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@
"tx-reception-instruction": "If you agree to this transaction, press 'Sign' below, then return the resulting transaction to the sender for completion.",
"tx-reception-instruction-2": "This transaction will not be completed until the sender has finalized it and posted it to the chain",
"tx-s1-finalization-1": "You are finalizing an agreement to pay [AMOUNT] Grin",
"tx-i1-finalization-1": "You are finalizing an agreement to receive [AMOUNT] Grin",
"tx-s1-finalization-2": "Along with a mining fee of [AMOUNT] Grin",
"tx-s1-finalization-3": "This will complete the transaction and post it to the chain, at which point it becomes irreversible.",
"tx-s1-finalization-self-send": "You are self-sending [AMOUNT] Grin",
Expand Down
4 changes: 2 additions & 2 deletions src/gui/element/wallet/operation/apply_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ pub fn data_container<'a>(config: &'a Config, state: &'a StateContainer) -> Cont

instruction_col = instruction_col.push(instruction_row);

if state.can_continue {
/*if state.can_continue {
let decrypted_tx_label = Text::new(localized_string("pasted-slatepack-details"))
.size(DEFAULT_SUB_HEADER_FONT_SIZE)
.horizontal_alignment(alignment::Horizontal::Left);
Expand All @@ -335,7 +335,7 @@ pub fn data_container<'a>(config: &'a Config, state: &'a StateContainer) -> Cont
instruction_col = instruction_col
.push(Space::new(Length::Fixed(0.0), Length::Fixed(unit_spacing)))
.push(decrypted_tx_label_container)
}
}*/

let mut slatepack_area = Column::new();
if state.can_continue {
Expand Down
72 changes: 54 additions & 18 deletions src/gui/element/wallet/operation/apply_tx_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use async_std::prelude::FutureExt;
use grin_gui_core::{
config::{Config, TxMethod},
wallet::{
ContractNewArgsAPI, ContractSetupArgsAPI, Slate, SlateState, Slatepack, TxLogEntry,
TxLogEntryType,
ContractNewArgsAPI, ContractSetupArgsAPI, ProofArgs, Slate, SlateState, Slatepack,
TxLogEntry, TxLogEntryType,
},
};
use grin_gui_widgets::widget::header;
Expand Down Expand Up @@ -169,15 +169,16 @@ pub fn handle_message<'a>(
}
}
} else {
let sp_sending_address = match &slatepack.sender {
None => "None".to_string(),
Some(s) => s.to_string(),
let (sp_sending_address, sender_pub_key) = match &slatepack.sender {
None => ("None".to_string(), None),
Some(s) => (s.to_string(), Some(s.pub_key)),
};

// Can we just dumbly do opposite here?
let net_change = match slate.state {
SlateState::Standard1 | SlateState::Invoice1 => Some(-(slate.amount as i64)),
SlateState::Standard2 | SlateState::Invoice2 => None,
SlateState::Standard1 => Some(slate.amount as i64),
SlateState::Standard2 => None,
SlateState::Invoice1 => Some(-(slate.amount as i64)),
SlateState::Invoice2 => None,
_ => {
log::error!("Slate state not yet supported");
return Ok(Command::none());
Expand All @@ -187,15 +188,30 @@ pub fn handle_message<'a>(
// Should be a simplified context flow here, where we can be recipient or sender!
let mut args = ContractSetupArgsAPI {
net_change,
proof_args: ProofArgs {
sender_address: sender_pub_key,
..Default::default()
},
..Default::default()
};
state.is_signing = true;

if slate.state == SlateState::Invoice1 {
args = ContractSetupArgsAPI {
net_change,
..Default::default()
};
}

if slate.state == SlateState::Invoice2 {
args = ContractSetupArgsAPI {
..Default::default()
};
};

if state.is_self_send {
debug!("SLATE STATE SELF_SEND: {}", slate.state);
let fut = move || {
WalletInterface::post_tx(w, out_slate)
};
let fut = move || WalletInterface::post_tx(w, out_slate);
return Ok(Command::perform(fut(), |r| {
match r.context("Failed to Progress Transaction") {
Ok((slate, enc_slate)) => {
Expand All @@ -220,6 +236,7 @@ pub fn handle_message<'a>(
}));
} else {
let fut = move || {
debug!("SIGN ARGS: {:?}", args);
WalletInterface::contract_sign(w, out_slate, args, sp_sending_address, true)
};

Expand Down Expand Up @@ -344,11 +361,11 @@ pub fn data_container<'a>(config: &'a Config, state: &'a StateContainer) -> Cont
SlateState::Standard2 => {
let mut fee = String::default();
other_wallet_label = localized_string("tx-recipient-name");
reception_instruction_2 =
parse_info_strings(&localized_string("tx-s1-finalization-3"), &fee);
if let Some(tx) = tx_log_entry {
(amount, fee) = parse_abs_tx_amount_fee(tx, !state.is_self_send);
}
reception_instruction_2 =
parse_info_strings(&localized_string("tx-s1-finalization-3"), &fee);
reception_instruction_1 =
parse_info_strings(&localized_string("tx-s1-finalization-2"), &fee);
let amt_stmt = parse_info_strings(&localized_string("tx-s1-finalization-1"), &amount);
Expand All @@ -361,27 +378,46 @@ pub fn data_container<'a>(config: &'a Config, state: &'a StateContainer) -> Cont
if config.tx_method == TxMethod::Contracts {
state_text = match slate.state {
SlateState::Standard1 => {
other_wallet_label = localized_string("tx-recipient-name");
parse_info_strings(&localized_string("tx-sending"), &amount)
other_wallet_label = localized_string("tx-sender-name");
parse_info_strings(&localized_string("tx-reception"), &amount)
}
SlateState::Standard2 => {
let mut fee = String::default();
other_wallet_label = localized_string("tx-sender-name");
reception_instruction_2 =
parse_info_strings(&localized_string("tx-s1-finalization-3"), &fee);
if let Some(tx) = tx_log_entry {
(amount, fee) = parse_abs_tx_amount_fee(tx, !state.is_self_send);
}
reception_instruction_2 =
parse_info_strings(&localized_string("tx-s1-finalization-3"), &fee);
reception_instruction_1 =
parse_info_strings(&localized_string("tx-s1-finalization-2"), &fee);
let amt_stmt = match state.is_self_send {
true => parse_info_strings(&localized_string("tx-s1-finalization-self-send"), &amount),
true => parse_info_strings(
&localized_string("tx-s1-finalization-self-send"),
&amount,
),
false => parse_info_strings(&localized_string("tx-s1-finalization-1"), &amount),
};

amt_stmt
}
SlateState::Standard3 => "This transaction is finalised - Standard Workflow".to_owned(),
SlateState::Invoice1 => {
other_wallet_label = localized_string("tx-recipient-name");
parse_info_strings(&localized_string("tx-sending"), &amount)
}
SlateState::Invoice2 => {
let mut fee = String::default();
other_wallet_label = localized_string("tx-sender-name");
if let Some(tx) = tx_log_entry {
(amount, fee) = parse_abs_tx_amount_fee(tx, false);
}
reception_instruction_2 = localized_string("tx-s1-finalization-3");
reception_instruction_1 = "".to_owned();
//parse_info_strings(&localized_string("tx-s1-finalization-2"), &fee);

parse_info_strings(&localized_string("tx-i1-finalization-1"), &amount)
}
_ => state_text,
};

Expand Down
16 changes: 13 additions & 3 deletions src/gui/element/wallet/operation/create_tx_contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use async_std::prelude::FutureExt;
use grin_gui_core::{
config::Config,
error::GrinWalletInterfaceError,
wallet::{ContractNewArgsAPI, ContractSetupArgsAPI, Slatepack, TxLogEntry, TxLogEntryType},
wallet::{ContractNewArgsAPI, ContractSetupArgsAPI, Slatepack, TxLogEntry, TxLogEntryType, SlatepackAddress},
};
use grin_gui_widgets::widget::header;
use iced_aw::Card;
Expand Down Expand Up @@ -189,7 +189,16 @@ pub fn handle_message<'a>(
..Default::default()
};

if state.contribution_choice == ContributionChoice::Credit || state.is_self_send {
if state.contribution_choice == ContributionChoice::Credit {
debug!("CREDITOR ADDRESS: {}", state.recipient_address_value);
let res:Result<SlatepackAddress, _> = state.recipient_address_value.as_str().try_into();
if let Ok(creditor_address) = res {
args.setup_args.proof_args.sender_address = Some(creditor_address.pub_key);
debug!("CREDITOR ADDRESS: {:?}", args.setup_args.proof_args.sender_address);
}
}

if state.is_self_send || state.contribution_choice == ContributionChoice::Debit {
if let Some(a) = &grin_gui.wallet_state.operation_state.home_state.address {
args.setup_args.proof_args.sender_address = Some(a.pub_key);
}
Expand Down Expand Up @@ -226,6 +235,7 @@ pub fn handle_message<'a>(

return Ok(Command::perform(fut(), |r| match r {
Ok((enc_slate, unenc_slate)) => Message::Interaction(

Interaction::WalletOperationCreateTxContractsViewInteraction(
LocalViewInteraction::TxCreatedOk(enc_slate, unenc_slate),
),
Expand All @@ -248,7 +258,7 @@ pub fn handle_message<'a>(
}
}
LocalViewInteraction::TxCreatedOk(unencrypted_slate, encrypted_slate) => {
log::debug!("{:?}", encrypted_slate);
log::debug!("{}", unencrypted_slate);
grin_gui
.wallet_state
.operation_state
Expand Down
46 changes: 26 additions & 20 deletions src/gui/element/wallet/setup/wallet_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,22 +292,20 @@ pub fn data_container<'a>(
let header_row = Row::new().push(title_container);

let header_container = Container::new(header_row).padding(iced::Padding::from([
0, // top
0, // right
0, // top
0, // right
DEFAULT_PADDING as u16, // bottom
0, // left
0, // left
]));

let password_column = {
let password_input = TextInput::new(
&localized_string("password")[..],
&state.password_state.input_value,
/*|s| {
Interaction::WalletSetupWalletViewInteraction(LocalViewInteraction::PasswordInput(
s,
))
},*/
)
.on_input(|s| {
Interaction::WalletSetupWalletViewInteraction(LocalViewInteraction::PasswordInput(s))
})
.on_submit(Interaction::WalletSetupWalletViewInteraction(
LocalViewInteraction::PasswordInputEnterPressed,
))
Expand All @@ -322,12 +320,12 @@ pub fn data_container<'a>(
let repeat_password_input = TextInput::new(
&localized_string("password-repeat")[..],
&state.password_state.repeat_input_value,
/*|s| {
Interaction::WalletSetupWalletViewInteraction(
LocalViewInteraction::PasswordRepeatInput(s),
)
},*/
)
.on_input(|s| {
Interaction::WalletSetupWalletViewInteraction(
LocalViewInteraction::PasswordRepeatInput(s),
)
})
.on_submit(Interaction::WalletSetupWalletViewInteraction(
LocalViewInteraction::PasswordRepeatInputEnterPressed,
))
Expand Down Expand Up @@ -369,8 +367,8 @@ pub fn data_container<'a>(
let description = Text::new(localized_string("setup-grin-wallet-enter-password"))
.size(DEFAULT_FONT_SIZE)
.horizontal_alignment(alignment::Horizontal::Center);
let description_container = Container::new(description)
.style(grin_gui_core::theme::ContainerStyle::NormalBackground);
let description_container =
Container::new(description).style(grin_gui_core::theme::ContainerStyle::NormalBackground);

let mut restore_from_seed_column = {
let checkbox = Checkbox::new(
Expand Down Expand Up @@ -415,9 +413,12 @@ pub fn data_container<'a>(
};

// ** start hideable restore from seed section
let seed_input: Element<Interaction> = TextInput::new("seed", &state.seed_input_value/*, |s| {
Interaction::WalletSetupWalletViewInteraction(LocalViewInteraction::SeedInput(s))
}*/)
let seed_input: Element<Interaction> = TextInput::new(
"seed",
&state.seed_input_value, /*, |s| {
Interaction::WalletSetupWalletViewInteraction(LocalViewInteraction::SeedInput(s))
}*/
)
.size(DEFAULT_FONT_SIZE)
.padding(6)
.width(Length::Fixed(200.0))
Expand Down Expand Up @@ -446,8 +447,10 @@ pub fn data_container<'a>(
let display_name_input = TextInput::new(
default_display_name,
&state.advanced_options_state.display_name_value,
/*|s| Interaction::WalletSetupWalletViewInteraction(LocalViewInteraction::DisplayName(s)),*/
)
.on_input(|s| {
Interaction::WalletSetupWalletViewInteraction(LocalViewInteraction::DisplayName(s))
})
.size(DEFAULT_FONT_SIZE)
.padding(6)
.width(Length::Fixed(200.0))
Expand Down Expand Up @@ -485,7 +488,10 @@ pub fn data_container<'a>(

let folder_select_row = Row::new()
.push(folder_select_button.map(Message::Interaction))
.push(Space::new(Length::Fixed(DEFAULT_PADDING), Length::Fixed(0.0)))
.push(Space::new(
Length::Fixed(DEFAULT_PADDING),
Length::Fixed(0.0),
))
.push(current_tld_column);

let display_name_input: Element<Interaction> = display_name_input.into();
Expand Down