drk: Notify the user about changes in their wallet.

This commit is contained in:
parazyd
2022-12-20 18:22:34 +01:00
parent 034bd2fd4f
commit be260674ce
5 changed files with 62 additions and 2 deletions

34
Cargo.lock generated
View File

@@ -1583,6 +1583,7 @@ dependencies = [
"darkfi-money-contract",
"darkfi-sdk",
"darkfi-serial",
"play",
"prettytable-rs",
"rand",
"serde_json",
@@ -2739,6 +2740,17 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389"
[[package]]
name = "mpg123-sys"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75c26239d85c1423091c109fcdabbcfaac868576dc018b0e959137217907610"
dependencies = [
"bitflags",
"libc",
"pkg-config",
]
[[package]]
name = "native-tls"
version = "0.2.11"
@@ -2923,6 +2935,17 @@ version = "6.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
[[package]]
name = "out123-sys"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5da977be7c4b44e2ad26be779aafc1761a89bd2ee6e363770bb71eb67a00d2e5"
dependencies = [
"libc",
"mpg123-sys",
"pkg-config",
]
[[package]]
name = "parking"
version = "2.0.0"
@@ -3080,6 +3103,17 @@ version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
[[package]]
name = "play"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c570085654588139e9ea2f452fe7dcb78d576da4f1c04d58b98b32fc42744ff0"
dependencies = [
"libc",
"mpg123-sys",
"out123-sys",
]
[[package]]
name = "plotters"
version = "0.3.4"

View File

@@ -26,3 +26,4 @@ signal-hook-async-std = "0.2.2"
signal-hook = "0.3.14"
sqlx = {version = "0.6.2", features = ["runtime-async-std-native-tls", "sqlite"]}
url = "2.3.1"
play = "0.5.3"

View File

@@ -15,8 +15,9 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use std::process::exit;
use std::{path::Path, process::exit};
use async_std::{fs::File, io::WriteExt};
use darkfi::{util::parse::decode_base10, Result};
use darkfi_sdk::crypto::TokenId;
@@ -58,3 +59,20 @@ pub fn parse_token_pair(s: &str) -> Result<(TokenId, TokenId)> {
Ok((tok0.unwrap(), tok1.unwrap()))
}
/// Fun police go away
pub async fn kaching() -> Result<()> {
const WALLET_MP3: &[u8] = include_bytes!("../wallet.mp3");
const MP3_DROP: &str = "/tmp/wallet.mp3";
if !Path::new(MP3_DROP).exists() {
let mut f = File::create(MP3_DROP).await?;
f.write_all(WALLET_MP3).await?;
}
if let Err(_) = play::play(MP3_DROP) {
return Ok(())
}
Ok(())
}

View File

@@ -51,6 +51,7 @@ use signal_hook_async_std::Signals;
use url::Url;
use super::Drk;
use crate::cli_util::kaching;
impl Drk {
/// Subscribes to darkfid's JSON-RPC notification endpoint that serves
@@ -234,7 +235,7 @@ impl Drk {
);
eprintln!("Found {} OwnCoin(s) in block", owncoins.len());
for owncoin in owncoins {
for owncoin in &owncoins {
eprintln!("Owncoin: {:?}", owncoin.coin);
let params = json!([
query,
@@ -277,6 +278,12 @@ impl Drk {
let req = JsonRequest::new("wallet.exec_sql", params);
let _ = self.rpc_client.request(req).await?;
if !owncoins.is_empty() {
if let Err(_) = kaching().await {
return Ok(())
}
}
Ok(())
}

BIN
bin/drk/wallet.mp3 Normal file

Binary file not shown.