-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add wallet stub to collectibles app (#3589)
- Loading branch information
Byron Hambly
authored
Nov 18, 2021
1 parent
0c47bc8
commit dfc3b92
Showing
26 changed files
with
856 additions
and
145 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
applications/tari_collectibles/src-tauri/migrations/2021-11-15-124424_wallet/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-- This file should undo anything in `up.sql` |
6 changes: 6 additions & 0 deletions
6
applications/tari_collectibles/src-tauri/migrations/2021-11-15-124424_wallet/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-- Your SQL goes here | ||
create table wallets ( | ||
id blob not null primary key, | ||
name text, | ||
cipher_seed blob not null unique | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
applications/tari_collectibles/src-tauri/src/commands/wallets/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Copyright 2021. The Tari Project | ||
// | ||
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | ||
// following conditions are met: | ||
// | ||
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following | ||
// disclaimer. | ||
// | ||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the | ||
// following disclaimer in the documentation and/or other materials provided with the distribution. | ||
// | ||
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote | ||
// products derived from this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
use crate::{ | ||
app_state::ConcurrentAppState, | ||
models::{NewWallet, Wallet, WalletInfo}, | ||
storage::{CollectiblesStorage, WalletsTableGateway}, | ||
}; | ||
use tari_key_manager::{ | ||
cipher_seed::CipherSeed, | ||
mnemonic::{Mnemonic, MnemonicLanguage}, | ||
}; | ||
use uuid::Uuid; | ||
|
||
#[tauri::command] | ||
pub(crate) async fn wallets_create( | ||
name: Option<String>, | ||
passphrase: Option<String>, | ||
state: tauri::State<'_, ConcurrentAppState>, | ||
) -> Result<Wallet, String> { | ||
let new_wallet = NewWallet { | ||
name, | ||
cipher_seed: CipherSeed::new(), | ||
}; | ||
|
||
let result = state | ||
.create_db() | ||
.await | ||
.map_err(|e| format!("Could not connect to DB: {}", e))? | ||
.wallets() | ||
.insert(new_wallet, passphrase) | ||
.map_err(|e| format!("Could not save wallet: {}", e))?; | ||
Ok(result) | ||
} | ||
|
||
#[tauri::command] | ||
pub(crate) async fn wallets_list( | ||
state: tauri::State<'_, ConcurrentAppState>, | ||
) -> Result<Vec<WalletInfo>, String> { | ||
let db = state | ||
.create_db() | ||
.await | ||
.map_err(|e| format!("Could not connect to DB: {}", e))?; | ||
|
||
let result = db | ||
.wallets() | ||
.list() | ||
.map_err(|e| format!("Could list wallets from DB: {}", e))?; | ||
Ok(result) | ||
} | ||
|
||
#[tauri::command] | ||
pub(crate) async fn wallets_find( | ||
id: String, | ||
passphrase: Option<String>, | ||
state: tauri::State<'_, ConcurrentAppState>, | ||
) -> Result<Wallet, String> { | ||
let db = state | ||
.create_db() | ||
.await | ||
.map_err(|e| format!("Could not connect to DB: {}", e))?; | ||
|
||
let uuid = Uuid::parse_str(&id).map_err(|e| format!("Failed to parse UUID: {}", e))?; | ||
|
||
let result = db | ||
.wallets() | ||
.find(uuid, passphrase) | ||
.map_err(|e| e.to_string())?; | ||
|
||
Ok(result) | ||
} | ||
|
||
#[tauri::command] | ||
pub(crate) async fn wallets_seed_words( | ||
id: String, | ||
passphrase: Option<String>, | ||
state: tauri::State<'_, ConcurrentAppState>, | ||
) -> Result<Vec<String>, String> { | ||
let db = state | ||
.create_db() | ||
.await | ||
.map_err(|e| format!("Could not connect to DB: {}", e))?; | ||
|
||
let uuid = Uuid::parse_str(&id).map_err(|e| format!("Failed to parse UUID: {}", e))?; | ||
|
||
let wallet = db | ||
.wallets() | ||
.find(uuid, passphrase.clone()) | ||
.map_err(|e| e.to_string())?; | ||
|
||
let seed_words = wallet | ||
.cipher_seed | ||
.to_mnemonic(&MnemonicLanguage::English, passphrase) | ||
.map_err(|e| format!("Failed to convert cipher seed to seed words: {}", e))?; | ||
|
||
Ok(seed_words) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
applications/tari_collectibles/src-tauri/src/models/wallet.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2021. The Tari Project | ||
// | ||
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | ||
// following conditions are met: | ||
// | ||
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following | ||
// disclaimer. | ||
// | ||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the | ||
// following disclaimer in the documentation and/or other materials provided with the distribution. | ||
// | ||
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote | ||
// products derived from this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
use serde::{Deserialize, Serialize}; | ||
use tari_key_manager::cipher_seed::CipherSeed; | ||
use uuid::Uuid; | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
pub struct Wallet { | ||
pub id: Uuid, | ||
pub name: Option<String>, | ||
pub cipher_seed: CipherSeed, | ||
} | ||
|
||
pub struct NewWallet { | ||
pub name: Option<String>, | ||
pub cipher_seed: CipherSeed, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
pub struct WalletInfo { | ||
pub id: Uuid, | ||
pub name: Option<String>, | ||
} | ||
|
||
impl From<Wallet> for WalletInfo { | ||
fn from(wallet: Wallet) -> Self { | ||
WalletInfo { | ||
id: wallet.id, | ||
name: wallet.name, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.