mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
drk: Implement token mint authority import.
This commit is contained in:
@@ -74,6 +74,9 @@ use wallet_dao::DaoParams;
|
||||
/// Wallet functionality related to Money
|
||||
mod wallet_money;
|
||||
|
||||
/// Wallet functionality related to arbitrary tokens
|
||||
mod wallet_token;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(about = cli_desc!())]
|
||||
struct Args {
|
||||
@@ -1134,7 +1137,18 @@ async fn main() -> Result<()> {
|
||||
},
|
||||
|
||||
Subcmd::Token(cmd) => match cmd {
|
||||
TokenSubcmd::Import => todo!(),
|
||||
TokenSubcmd::Import => {
|
||||
let mut buf = String::new();
|
||||
stdin().read_to_string(&mut buf)?;
|
||||
let mint_authority =
|
||||
SecretKey::from_str(buf.trim()).with_context(|| "Invalid secret key")?;
|
||||
|
||||
let drk = Drk::new(args.endpoint).await?;
|
||||
drk.import_mint_authority(mint_authority).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
TokenSubcmd::GenerateMint => todo!(),
|
||||
TokenSubcmd::List => todo!(),
|
||||
TokenSubcmd::Mint { token, amount, recipient } => todo!(),
|
||||
|
||||
58
bin/drk/src/wallet_token.rs
Normal file
58
bin/drk/src/wallet_token.rs
Normal file
@@ -0,0 +1,58 @@
|
||||
/* This file is part of DarkFi (https://dark.fi)
|
||||
*
|
||||
* Copyright (C) 2020-2023 Dyne.org foundation
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* 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 darkfi::{rpc::jsonrpc::JsonRequest, wallet::walletdb::QueryType, Result};
|
||||
use darkfi_money_contract::client::{
|
||||
MONEY_TOKENS_IS_FROZEN, MONEY_TOKENS_MINT_AUTHORITY, MONEY_TOKENS_TABLE, MONEY_TOKENS_TOKEN_ID,
|
||||
};
|
||||
use darkfi_sdk::crypto::{SecretKey, TokenId};
|
||||
use darkfi_serial::serialize;
|
||||
use serde_json::json;
|
||||
|
||||
use super::Drk;
|
||||
|
||||
impl Drk {
|
||||
/// Import a token mint authority into the wallet
|
||||
pub async fn import_mint_authority(&self, mint_authority: SecretKey) -> Result<()> {
|
||||
let token_id = TokenId::derive(mint_authority);
|
||||
let is_frozen = 0;
|
||||
|
||||
let query = format!(
|
||||
"INSERT INTO {} ({}, {}, {}) VALUES (?1, ?2, ?3);",
|
||||
MONEY_TOKENS_TABLE,
|
||||
MONEY_TOKENS_MINT_AUTHORITY,
|
||||
MONEY_TOKENS_TOKEN_ID,
|
||||
MONEY_TOKENS_IS_FROZEN,
|
||||
);
|
||||
|
||||
let params = json!([
|
||||
query,
|
||||
QueryType::Blob as u8,
|
||||
serialize(&mint_authority),
|
||||
QueryType::Blob as u8,
|
||||
serialize(&token_id),
|
||||
QueryType::Integer as u8,
|
||||
is_frozen,
|
||||
]);
|
||||
|
||||
let req = JsonRequest::new("wallet.exec_sql", params);
|
||||
let _ = self.rpc_client.request(req).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user