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

Transaction Slate Creation and display #47

Merged
merged 2 commits into from
Dec 20, 2022
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
35 changes: 26 additions & 9 deletions crates/core/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ use dirs;
pub use global::ChainTypes;
pub use grin_wallet_impls::HTTPNodeClient;
pub use grin_wallet_libwallet::{
InitTxArgs, Slate, StatusMessage, TxLogEntry, TxLogEntryType, WalletInfo, RetrieveTxQueryArgs
InitTxArgs, RetrieveTxQueryArgs, RetrieveTxQuerySortOrder, Slate, SlatepackAddress,
StatusMessage, TxLogEntry, TxLogEntryType, WalletInfo,
};

use crate::error::GrinWalletInterfaceError;
use crate::logger;

use std::convert::TryFrom;

/// Wallet configuration file name
pub const WALLET_CONFIG_FILE_NAME: &str = "grin-wallet.toml";

Expand Down Expand Up @@ -276,7 +279,7 @@ where
logging_config,
None,
)?;

p.create_wallet(
None,
args.recovery_phrase,
Expand Down Expand Up @@ -349,6 +352,23 @@ where
}
}

pub fn encrypt_slatepack(
api: &Owner<L, C, keychain::ExtKeychain>,
dest: &str,
unenc_slate: &Slate,
) -> Result<String, GrinWalletInterfaceError> {
let address = match SlatepackAddress::try_from(dest) {
Ok(a) => Some(a),
Err(_) => None,
};
// encrypt for recipient by default
let recipients = match address.clone() {
Some(a) => vec![a],
None => vec![],
};
Ok(api.create_slatepack_message(None, &unenc_slate, Some(0), recipients)?)
}

pub async fn get_wallet_info(
wallet_interface: Arc<RwLock<WalletInterface<L, C>>>,
) -> Result<(bool, WalletInfo), GrinWalletInterfaceError> {
Expand Down Expand Up @@ -401,14 +421,13 @@ where
pub async fn create_tx(
wallet_interface: Arc<RwLock<WalletInterface<L, C>>>,
init_args: InitTxArgs,
) -> Result<Slate, GrinWalletInterfaceError> {
dest_slatepack_address: String,
) -> Result<String, GrinWalletInterfaceError> {
let w = wallet_interface.write().unwrap();
if let Some(o) = &w.owner_api {
let slate = {
o.init_send_tx(None, init_args)?
};
let slate = { o.init_send_tx(None, init_args)? };
o.tx_lock_outputs(None, &slate)?;
return Ok(slate);
return WalletInterface::encrypt_slatepack(o, &dest_slatepack_address, &slate);
} else {
return Err(GrinWalletInterfaceError::OwnerAPINotInstantiated);
}
Expand All @@ -427,7 +446,6 @@ where
}
}


/*pub async fn tx_lock_outputs(
wallet_interface: Arc<RwLock<WalletInterface<L, C>>>,
init_args: InitTxArgs,
Expand All @@ -447,5 +465,4 @@ where
let mut w = wallet_interface.read().unwrap();
w.owner_api.get_mnemonic(name, password.into())
}*/

}
3 changes: 3 additions & 0 deletions locale/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@
"recipient-address": "Recipient's Slatepack Address",
"create-tx-amount": "Amount",
"cancel-tx": "Cancel",
"tx-create-submit": "Create",
"tx-confirmed": "Confirmed",
"tx-create-success-title": "Transaction Created",
"tx-create-success-desc": "Send this encrypted slate to the recipient via a channel of your choosing",
"tx-unconfirmed": "Not Confirmed",
"tx-list": "Transactions",
"tx-outstanding": "Outstanding",
Expand Down
6 changes: 5 additions & 1 deletion locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@
"tx-id": "Internal ID",
"tx-type": "Type",
"tx-shared-id": "Shared ID",
"tx-create-submit": "Create",
"tx-create-success": "Transaction Created",
"info-confirmed-total": "Confirmed Total",
"info-amount-spendable": "Amount Spendable",
"info-awaiting-confirmation": "Awaiting Confirmation",
Expand All @@ -240,5 +242,7 @@
"tx-outstanding": "Outstanding",
"tx-list": "Transactions",
"tx-recent": "Most Recent",
"tx-details": "Details"
"tx-details": "Details",
"tx-create-success-title": "Encrypted Transaction",
"tx-create-success-desc": "Copy/Paste this encrypted transaction to the recipient via a channel of your choosing"
}
Loading