From 9ab748ab709ff60610bacfc7cf5d6221349993c3 Mon Sep 17 00:00:00 2001 From: 0o-de-lally <> Date: Tue, 5 Dec 2023 12:58:01 -0500 Subject: [PATCH] Squashed commit of the following: commit 9cf0768080f81013117fbd2519eaa79db4a4f2e3 Author: 0o-de-lally <> Date: Tue Dec 5 12:31:58 2023 -0500 extra attempt to parse v5 address on transfer commit 37d60ebdef19acb432f6a4e817bebd999904c724 Author: 0o-de-lally <> Date: Tue Dec 5 12:04:29 2023 -0500 update dep: keyring commit 51d09340d08509b408a89e88d013d90323b5e1b5 Author: 0o-de-lally <> Date: Tue Dec 5 11:40:38 2023 -0500 miner progress bar FML commit 086bc5ea340aae3d15b5dcd9cbe16cf214dd53c2 Author: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> Date: Sat Dec 2 20:12:22 2023 -0500 lint commit e51ea6dd34942e98bc3f6c32624bf0a1bebbbf25 Author: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> Date: Sat Dec 2 20:11:24 2023 -0500 don't destroy miner interval when leaving miner page --- src-tauri/Cargo.lock | 4 ++-- src-tauri/Cargo.toml | 2 +- src-tauri/src/commands/tx.rs | 16 ++++++++++++++-- src-tauri/src/key_manager.rs | 9 ++++----- src/components/miner/ToggleMiner.svelte | 22 ++-------------------- src/components/txs/Transactions.svelte | 6 +----- src/modules/accountActions.ts | 7 ++++++- src/modules/carpeNotify.ts | 2 +- src/modules/miner_invoke.ts | 4 ---- src/modules/miner_toggle.ts | 13 ++++++++++++- src/modules/tick.ts | 1 + src/style/global.scss | 10 +++++++++- 12 files changed, 53 insertions(+), 43 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index eae14050..c1f7901e 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -6037,9 +6037,9 @@ dependencies = [ [[package]] name = "keyring" -version = "0.10.4" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a49a8b156a663b0b6898a845f056dd2502d8f0b3bde9686b59cfb4fdbc1d4777" +checksum = "ba264b266563c1363dcce004776cbf198d7422a4262f77f4ca285bf26ae30955" dependencies = [ "byteorder", "secret-service", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 19162279..815afdbb 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -38,7 +38,7 @@ url = { version = "2.2.2", features = ["serde"] } # only in carpe directories = "5.0.1" -keyring = "0.10.1" +keyring = "^1.2" simplelog = { version = "^0.11.0", features = ["paris"] } tauri = { version = "^1.5.2", features = ["api-all", "updater"] } diff --git a/src-tauri/src/commands/tx.rs b/src-tauri/src/commands/tx.rs index 161262fe..a0442480 100644 --- a/src-tauri/src/commands/tx.rs +++ b/src-tauri/src/commands/tx.rs @@ -1,4 +1,6 @@ //! transaction scripts +use std::str::FromStr; + use crate::key_manager::{get_private_key, inject_private_key_to_cfg}; use crate::{carpe_error::CarpeError, configs::get_cfg}; @@ -13,13 +15,23 @@ fn make_account_key(address: &AccountAddress) -> anyhow::Result { #[tauri::command(async)] pub async fn coin_transfer( _sender: AccountAddress, - receiver: AccountAddress, + receiver: &str, amount: u64, ) -> Result<(), CarpeError> { + // NOTE: unsure Serde was catching all cases check serialization + let receiver_account = match AccountAddress::from_str(receiver) { + Ok(a) => a, + Err(e) => { + dbg!(e); + // try prepending + AccountAddress::from_str(&format!("0x{}", receiver))? + } + }; + let mut config = get_cfg()?; inject_private_key_to_cfg(&mut config)?; let mut sender = Sender::from_app_cfg(&config, None).await?; - sender.transfer(receiver, amount as f64, false).await?; + sender.transfer(receiver_account, amount as f64, false).await?; Ok(()) } diff --git a/src-tauri/src/key_manager.rs b/src-tauri/src/key_manager.rs index f9386d39..2d5901ba 100644 --- a/src-tauri/src/key_manager.rs +++ b/src-tauri/src/key_manager.rs @@ -8,7 +8,6 @@ use libra_types::exports::AccountAddress; use libra_types::legacy_types::app_cfg::AppCfg; use anyhow::{anyhow, bail}; -use keyring::KeyringError; use libra_types::exports::{Ed25519PrivateKey, Ed25519PublicKey, KeyPair}; use crate::carpe_error::{CarpeError, ErrorCat, E_KEY_NOT_REGISTERED}; @@ -18,7 +17,7 @@ const KEYRING_APP_NAME: &str = "carpe"; /// overwrite then delete pub fn erase_keyring_address(address: AccountAddress) -> anyhow::Result<()> { let addr_str = &address.to_string(); - let kr = keyring::Keyring::new(KEYRING_APP_NAME, addr_str); + let kr = keyring::Entry::new(KEYRING_APP_NAME, addr_str); let bytes = &[0u8, 64]; let encoded = hex::encode(bytes); @@ -28,8 +27,8 @@ pub fn erase_keyring_address(address: AccountAddress) -> anyhow::Result<()> { Ok(()) } /// send the encoded private key to OS keyring -pub fn set_private_key(ol_address: &str, key: Ed25519PrivateKey) -> Result<(), KeyringError> { - let kr = keyring::Keyring::new(KEYRING_APP_NAME, ol_address); +pub fn set_private_key(ol_address: &str, key: Ed25519PrivateKey) -> Result<(), keyring::Error> { + let kr = keyring::Entry::new(KEYRING_APP_NAME, ol_address); let bytes: &[u8] = &(key.to_bytes()); let encoded = hex::encode(bytes); @@ -40,7 +39,7 @@ pub fn set_private_key(ol_address: &str, key: Ed25519PrivateKey) -> Result<(), K /// retrieve a private key from OS keyring pub fn get_private_key(address: &AccountAddress) -> Result { let ol_address = address.to_string(); - let kr = keyring::Keyring::new(KEYRING_APP_NAME, &ol_address); + let kr = keyring::Entry::new(KEYRING_APP_NAME, &ol_address); match kr.get_password() { Ok(s) => { let ser = hex::decode(s)?; diff --git a/src/components/miner/ToggleMiner.svelte b/src/components/miner/ToggleMiner.svelte index 9aed5af6..1c2e21c3 100644 --- a/src/components/miner/ToggleMiner.svelte +++ b/src/components/miner/ToggleMiner.svelte @@ -1,30 +1,12 @@