mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-02 13:23:10 +00:00
feat: refactor
This commit is contained in:
parent
21c3d762f4
commit
6da5a52a04
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -4754,6 +4754,7 @@ dependencies = [
|
||||
"log",
|
||||
"nssa",
|
||||
"nssa_core",
|
||||
"paste",
|
||||
"rand 0.8.5",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
||||
@ -76,6 +76,7 @@ chrono = "0.4.41"
|
||||
borsh = "1.5.7"
|
||||
base58 = "0.2.0"
|
||||
itertools = "0.14.0"
|
||||
paste = "1.0.15"
|
||||
|
||||
rocksdb = { version = "0.24.0", default-features = false, features = [
|
||||
"snappy",
|
||||
|
||||
@ -303,7 +303,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
|
||||
/// This test creates a new token using the token program. After creating the token, the test
|
||||
/// executes a token transfer to a new account.
|
||||
//#[nssa_integration_test]
|
||||
#[nssa_integration_test]
|
||||
pub async fn test_success_token_program() {
|
||||
info!("########## test_success_token_program ##########");
|
||||
let wallet_config = fetch_config().await.unwrap();
|
||||
@ -568,7 +568,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
/// This test creates a new private token using the token program. After creating the token, the
|
||||
/// test executes a private token transfer to a new account. All accounts are private owned
|
||||
/// except definition which is public.
|
||||
//#[nssa_integration_test]
|
||||
#[nssa_integration_test]
|
||||
pub async fn test_success_token_program_private_owned_supply() {
|
||||
info!("########## test_success_token_program_private_owned_supply ##########");
|
||||
let wallet_config = fetch_config().await.unwrap();
|
||||
@ -939,7 +939,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
|
||||
/// This test creates a new private token using the token program. All accounts are private
|
||||
/// owned except supply which is public.
|
||||
//#[nssa_integration_test]
|
||||
#[nssa_integration_test]
|
||||
pub async fn test_success_token_program_private_owned_definition() {
|
||||
info!("########## test_success_token_program_private_owned_definition ##########");
|
||||
let wallet_config = fetch_config().await.unwrap();
|
||||
@ -973,10 +973,16 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
|
||||
// Create new token
|
||||
let subcommand = TokenProgramAgnosticSubcommand::New {
|
||||
definition_account_id: make_private_account_input_from_str(
|
||||
&definition_account_id.to_string(),
|
||||
),
|
||||
supply_account_id: make_public_account_input_from_str(&supply_account_id.to_string()),
|
||||
definition: ArgsDefinitionOwned {
|
||||
definition_account_id: make_private_account_input_from_str(
|
||||
&definition_account_id.to_string(),
|
||||
),
|
||||
},
|
||||
supply: ArgsSupplyOwned {
|
||||
supply_account_id: make_public_account_input_from_str(
|
||||
&supply_account_id.to_string(),
|
||||
),
|
||||
},
|
||||
name: "A NAME".to_string(),
|
||||
total_supply: 37,
|
||||
};
|
||||
@ -1045,12 +1051,18 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
|
||||
// Mint 10 tokens at `recipient_acc_pub`
|
||||
let subcommand = TokenProgramAgnosticSubcommand::Mint {
|
||||
definition: make_private_account_input_from_str(&definition_account_id.to_string()),
|
||||
holder: Some(make_public_account_input_from_str(
|
||||
&recipient_account_id_pub.to_string(),
|
||||
)),
|
||||
holder_npk: None,
|
||||
holder_ipk: None,
|
||||
definition: ArgsDefinitionOwned {
|
||||
definition_account_id: make_private_account_input_from_str(
|
||||
&definition_account_id.to_string(),
|
||||
),
|
||||
},
|
||||
holder: ArgsHolderMaybeUnowned {
|
||||
holder: Some(make_public_account_input_from_str(
|
||||
&recipient_account_id_pub.to_string(),
|
||||
)),
|
||||
holder_npk: None,
|
||||
holder_ipk: None,
|
||||
},
|
||||
amount: 10,
|
||||
};
|
||||
|
||||
@ -1098,12 +1110,18 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
|
||||
// Mint 5 tokens at `recipient_acc_pr`
|
||||
let subcommand = TokenProgramAgnosticSubcommand::Mint {
|
||||
definition: make_private_account_input_from_str(&definition_account_id.to_string()),
|
||||
holder: None,
|
||||
holder_npk: Some(hex::encode(holder_keys.nullifer_public_key.0)),
|
||||
holder_ipk: Some(hex::encode(
|
||||
holder_keys.incoming_viewing_public_key.0.clone(),
|
||||
)),
|
||||
definition: ArgsDefinitionOwned {
|
||||
definition_account_id: make_private_account_input_from_str(
|
||||
&definition_account_id.to_string(),
|
||||
),
|
||||
},
|
||||
holder: ArgsHolderMaybeUnowned {
|
||||
holder: None,
|
||||
holder_npk: Some(hex::encode(holder_keys.nullifer_public_key.0)),
|
||||
holder_ipk: Some(hex::encode(
|
||||
holder_keys.incoming_viewing_public_key.0.clone(),
|
||||
)),
|
||||
},
|
||||
amount: 5,
|
||||
};
|
||||
|
||||
@ -1153,12 +1171,18 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
|
||||
// Mint 5 tokens at `recipient_acc_pr`
|
||||
let subcommand = TokenProgramAgnosticSubcommand::Mint {
|
||||
definition: make_private_account_input_from_str(&definition_account_id.to_string()),
|
||||
holder: Some(make_private_account_input_from_str(
|
||||
&recipient_account_id_pr.to_string(),
|
||||
)),
|
||||
holder_npk: None,
|
||||
holder_ipk: None,
|
||||
definition: ArgsDefinitionOwned {
|
||||
definition_account_id: make_private_account_input_from_str(
|
||||
&definition_account_id.to_string(),
|
||||
),
|
||||
},
|
||||
holder: ArgsHolderMaybeUnowned {
|
||||
holder: Some(make_private_account_input_from_str(
|
||||
&recipient_account_id_pr.to_string(),
|
||||
)),
|
||||
holder_npk: None,
|
||||
holder_ipk: None,
|
||||
},
|
||||
amount: 5,
|
||||
};
|
||||
|
||||
@ -1203,8 +1227,16 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
|
||||
// Burn 5 tokens at `recipient_acc_pub`
|
||||
let subcommand = TokenProgramAgnosticSubcommand::Burn {
|
||||
definition: make_private_account_input_from_str(&definition_account_id.to_string()),
|
||||
holder: make_public_account_input_from_str(&recipient_account_id_pub.to_string()),
|
||||
definition: ArgsDefinitionOwned {
|
||||
definition_account_id: make_private_account_input_from_str(
|
||||
&definition_account_id.to_string(),
|
||||
),
|
||||
},
|
||||
holder: ArgsHolderOwned {
|
||||
holder_account_id: make_public_account_input_from_str(
|
||||
&recipient_account_id_pub.to_string(),
|
||||
),
|
||||
},
|
||||
amount: 5,
|
||||
};
|
||||
|
||||
@ -1246,8 +1278,16 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
|
||||
// Burn 5 tokens at `recipient_acc_pr`
|
||||
let subcommand = TokenProgramAgnosticSubcommand::Burn {
|
||||
definition: make_private_account_input_from_str(&definition_account_id.to_string()),
|
||||
holder: make_private_account_input_from_str(&recipient_account_id_pr.to_string()),
|
||||
definition: ArgsDefinitionOwned {
|
||||
definition_account_id: make_private_account_input_from_str(
|
||||
&definition_account_id.to_string(),
|
||||
),
|
||||
},
|
||||
holder: ArgsHolderOwned {
|
||||
holder_account_id: make_private_account_input_from_str(
|
||||
&recipient_account_id_pr.to_string(),
|
||||
),
|
||||
},
|
||||
amount: 5,
|
||||
};
|
||||
|
||||
@ -1293,7 +1333,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
|
||||
/// This test creates a new private token using the token program. All accounts are private
|
||||
/// owned.
|
||||
//#[nssa_integration_test]
|
||||
#[nssa_integration_test]
|
||||
pub async fn test_success_token_program_private_owned_definition_and_supply() {
|
||||
info!(
|
||||
"########## test_success_token_program_private_owned_definition_and_supply ##########"
|
||||
@ -1329,10 +1369,16 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
|
||||
// Create new token
|
||||
let subcommand = TokenProgramAgnosticSubcommand::New {
|
||||
definition_account_id: make_private_account_input_from_str(
|
||||
&definition_account_id.to_string(),
|
||||
),
|
||||
supply_account_id: make_private_account_input_from_str(&supply_account_id.to_string()),
|
||||
definition: ArgsDefinitionOwned {
|
||||
definition_account_id: make_private_account_input_from_str(
|
||||
&definition_account_id.to_string(),
|
||||
),
|
||||
},
|
||||
supply: ArgsSupplyOwned {
|
||||
supply_account_id: make_private_account_input_from_str(
|
||||
&supply_account_id.to_string(),
|
||||
),
|
||||
},
|
||||
name: "A NAME".to_string(),
|
||||
total_supply: 37,
|
||||
};
|
||||
@ -1393,7 +1439,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
|
||||
/// This test creates a new private token using the token program. After creating the token, the
|
||||
/// test executes a private token transfer to a new account.
|
||||
//#[nssa_integration_test]
|
||||
#[nssa_integration_test]
|
||||
pub async fn test_success_token_program_private_claiming_path() {
|
||||
info!("########## test_success_token_program_private_claiming_path ##########");
|
||||
let wallet_config = fetch_config().await.unwrap();
|
||||
@ -1434,10 +1480,16 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
|
||||
// Create new token
|
||||
let subcommand = TokenProgramAgnosticSubcommand::New {
|
||||
definition_account_id: make_public_account_input_from_str(
|
||||
&definition_account_id.to_string(),
|
||||
),
|
||||
supply_account_id: make_private_account_input_from_str(&supply_account_id.to_string()),
|
||||
definition: ArgsDefinitionOwned {
|
||||
definition_account_id: make_public_account_input_from_str(
|
||||
&definition_account_id.to_string(),
|
||||
),
|
||||
},
|
||||
supply: ArgsSupplyOwned {
|
||||
supply_account_id: make_private_account_input_from_str(
|
||||
&supply_account_id.to_string(),
|
||||
),
|
||||
},
|
||||
name: "A NAME".to_string(),
|
||||
total_supply: 37,
|
||||
};
|
||||
@ -1486,12 +1538,16 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
|
||||
// Transfer 7 tokens from `supply_acc` to the account at account_id `recipient_account_id`
|
||||
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
||||
from: make_private_account_input_from_str(&supply_account_id.to_string()),
|
||||
to: None,
|
||||
to_npk: Some(hex::encode(recipient_keys.nullifer_public_key.0)),
|
||||
to_ipk: Some(hex::encode(
|
||||
recipient_keys.incoming_viewing_public_key.0.clone(),
|
||||
)),
|
||||
from: ArgsSenderOwned {
|
||||
from: make_private_account_input_from_str(&supply_account_id.to_string()),
|
||||
},
|
||||
to: ArgsReceiverMaybeUnowned {
|
||||
to: None,
|
||||
to_npk: Some(hex::encode(recipient_keys.nullifer_public_key.0)),
|
||||
to_ipk: Some(hex::encode(
|
||||
recipient_keys.incoming_viewing_public_key.0.clone(),
|
||||
)),
|
||||
},
|
||||
amount: 7,
|
||||
};
|
||||
|
||||
@ -1529,7 +1585,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
/// This test creates a new public token using the token program. After creating the token, the
|
||||
/// test executes a shielded token transfer to a new account. All accounts are owned except
|
||||
/// definition.
|
||||
//#[nssa_integration_test]
|
||||
#[nssa_integration_test]
|
||||
pub async fn test_success_token_program_shielded_owned() {
|
||||
info!("########## test_success_token_program_shielded_owned ##########");
|
||||
let wallet_config = fetch_config().await.unwrap();
|
||||
@ -1570,10 +1626,16 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
|
||||
// Create new token
|
||||
let subcommand = TokenProgramAgnosticSubcommand::New {
|
||||
definition_account_id: make_public_account_input_from_str(
|
||||
&definition_account_id.to_string(),
|
||||
),
|
||||
supply_account_id: make_public_account_input_from_str(&supply_account_id.to_string()),
|
||||
definition: ArgsDefinitionOwned {
|
||||
definition_account_id: make_public_account_input_from_str(
|
||||
&definition_account_id.to_string(),
|
||||
),
|
||||
},
|
||||
supply: ArgsSupplyOwned {
|
||||
supply_account_id: make_public_account_input_from_str(
|
||||
&supply_account_id.to_string(),
|
||||
),
|
||||
},
|
||||
name: "A NAME".to_string(),
|
||||
total_supply: 37,
|
||||
};
|
||||
@ -1606,12 +1668,16 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
|
||||
// Transfer 7 tokens from `supply_acc` to the account at account_id `recipient_account_id`
|
||||
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
||||
from: make_public_account_input_from_str(&supply_account_id.to_string()),
|
||||
to: Some(make_private_account_input_from_str(
|
||||
&recipient_account_id.to_string(),
|
||||
)),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
from: ArgsSenderOwned {
|
||||
from: make_public_account_input_from_str(&supply_account_id.to_string()),
|
||||
},
|
||||
to: ArgsReceiverMaybeUnowned {
|
||||
to: Some(make_private_account_input_from_str(
|
||||
&recipient_account_id.to_string(),
|
||||
)),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
},
|
||||
amount: 7,
|
||||
};
|
||||
|
||||
@ -1635,12 +1701,16 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
// Transfer additional 7 tokens from `supply_acc` to the account at account_id
|
||||
// `recipient_account_id`
|
||||
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
||||
from: make_public_account_input_from_str(&supply_account_id.to_string()),
|
||||
to: Some(make_private_account_input_from_str(
|
||||
&recipient_account_id.to_string(),
|
||||
)),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
from: ArgsSenderOwned {
|
||||
from: make_public_account_input_from_str(&supply_account_id.to_string()),
|
||||
},
|
||||
to: ArgsReceiverMaybeUnowned {
|
||||
to: Some(make_private_account_input_from_str(
|
||||
&recipient_account_id.to_string(),
|
||||
)),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
},
|
||||
amount: 7,
|
||||
};
|
||||
|
||||
@ -1665,7 +1735,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
/// This test creates a new private token using the token program. After creating the token, the
|
||||
/// test executes a deshielded token transfer to a new account. All accounts are owned
|
||||
/// except definition.
|
||||
//#[nssa_integration_test]
|
||||
#[nssa_integration_test]
|
||||
pub async fn test_success_token_program_deshielded_owned() {
|
||||
info!("########## test_success_token_program_deshielded_owned ##########");
|
||||
let wallet_config = fetch_config().await.unwrap();
|
||||
@ -1706,10 +1776,16 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
|
||||
// Create new token
|
||||
let subcommand = TokenProgramAgnosticSubcommand::New {
|
||||
definition_account_id: make_public_account_input_from_str(
|
||||
&definition_account_id.to_string(),
|
||||
),
|
||||
supply_account_id: make_private_account_input_from_str(&supply_account_id.to_string()),
|
||||
definition: ArgsDefinitionOwned {
|
||||
definition_account_id: make_public_account_input_from_str(
|
||||
&definition_account_id.to_string(),
|
||||
),
|
||||
},
|
||||
supply: ArgsSupplyOwned {
|
||||
supply_account_id: make_private_account_input_from_str(
|
||||
&supply_account_id.to_string(),
|
||||
),
|
||||
},
|
||||
name: "A NAME".to_string(),
|
||||
total_supply: 37,
|
||||
};
|
||||
@ -1752,12 +1828,16 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
|
||||
// Transfer 7 tokens from `supply_acc` to the account at account_id `recipient_account_id`
|
||||
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
||||
from: make_private_account_input_from_str(&supply_account_id.to_string()),
|
||||
to: Some(make_public_account_input_from_str(
|
||||
&recipient_account_id.to_string(),
|
||||
)),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
from: ArgsSenderOwned {
|
||||
from: make_private_account_input_from_str(&supply_account_id.to_string()),
|
||||
},
|
||||
to: ArgsReceiverMaybeUnowned {
|
||||
to: Some(make_public_account_input_from_str(
|
||||
&recipient_account_id.to_string(),
|
||||
)),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
},
|
||||
amount: 7,
|
||||
};
|
||||
|
||||
@ -1781,12 +1861,16 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
||||
// Transfer additional 7 tokens from `supply_acc` to the account at account_id
|
||||
// `recipient_account_id`
|
||||
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
||||
from: make_private_account_input_from_str(&supply_account_id.to_string()),
|
||||
to: Some(make_public_account_input_from_str(
|
||||
&recipient_account_id.to_string(),
|
||||
)),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
from: ArgsSenderOwned {
|
||||
from: make_private_account_input_from_str(&supply_account_id.to_string()),
|
||||
},
|
||||
to: ArgsReceiverMaybeUnowned {
|
||||
to: Some(make_public_account_input_from_str(
|
||||
&recipient_account_id.to_string(),
|
||||
)),
|
||||
to_npk: None,
|
||||
to_ipk: None,
|
||||
},
|
||||
amount: 7,
|
||||
};
|
||||
|
||||
|
||||
@ -27,3 +27,4 @@ sha2.workspace = true
|
||||
futures.workspace = true
|
||||
async-stream = "0.3.6"
|
||||
indicatif = { version = "0.18.3", features = ["improved_unicode"] }
|
||||
paste.workspace = true
|
||||
|
||||
@ -4,6 +4,7 @@ pub mod token;
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::Args;
|
||||
use paste::paste;
|
||||
|
||||
use crate::{
|
||||
PrivacyPreservingAccount,
|
||||
@ -14,184 +15,95 @@ trait ParsePrivacyPreservingAccount {
|
||||
fn parse(&self) -> Result<PrivacyPreservingAccount>;
|
||||
}
|
||||
|
||||
#[derive(Debug, Args, Clone)]
|
||||
pub struct ArgsSenderOwned {
|
||||
/// from - valid 32 byte base58 string with privacy prefix
|
||||
#[arg(long)]
|
||||
pub from: String,
|
||||
}
|
||||
macro_rules! owned_account_name {
|
||||
($classname: ident, $field: ident) => {
|
||||
#[derive(Debug, Args, Clone)]
|
||||
pub struct $classname {
|
||||
/// $field - valid 32 byte base58 string with privacy prefix
|
||||
#[arg(long)]
|
||||
pub $field: String,
|
||||
}
|
||||
|
||||
impl ParsePrivacyPreservingAccount for ArgsSenderOwned {
|
||||
fn parse(&self) -> Result<PrivacyPreservingAccount> {
|
||||
let (account_id, privacy) = parse_addr_with_privacy_prefix(&self.from)?;
|
||||
impl ParsePrivacyPreservingAccount for $classname {
|
||||
fn parse(&self) -> Result<PrivacyPreservingAccount> {
|
||||
let (account_id, privacy) = parse_addr_with_privacy_prefix(&self.$field)?;
|
||||
|
||||
match privacy {
|
||||
AccountPrivacyKind::Public => Ok(PrivacyPreservingAccount::Public(account_id.parse()?)),
|
||||
AccountPrivacyKind::Private => {
|
||||
Ok(PrivacyPreservingAccount::PrivateOwned(account_id.parse()?))
|
||||
match privacy {
|
||||
AccountPrivacyKind::Public => {
|
||||
Ok(PrivacyPreservingAccount::Public(account_id.parse()?))
|
||||
}
|
||||
AccountPrivacyKind::Private => {
|
||||
Ok(PrivacyPreservingAccount::PrivateOwned(account_id.parse()?))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Debug, Args, Clone)]
|
||||
pub struct ArgsReceiverMaybeUnowned {
|
||||
/// to - valid 32 byte base58 string with privacy prefix
|
||||
#[arg(long)]
|
||||
pub to: Option<String>,
|
||||
/// to_npk - valid 32 byte hex string
|
||||
#[arg(long)]
|
||||
pub to_npk: Option<String>,
|
||||
/// to_ipk - valid 33 byte hex string
|
||||
#[arg(long)]
|
||||
pub to_ipk: Option<String>,
|
||||
}
|
||||
owned_account_name!(ArgsSenderOwned, from);
|
||||
owned_account_name!(ArgsDefinitionOwned, definition_account_id);
|
||||
owned_account_name!(ArgsSupplyOwned, supply_account_id);
|
||||
owned_account_name!(ArgsHolderOwned, holder_account_id);
|
||||
|
||||
impl ParsePrivacyPreservingAccount for ArgsReceiverMaybeUnowned {
|
||||
fn parse(&self) -> Result<PrivacyPreservingAccount> {
|
||||
match (&self.to, &self.to_npk, &self.to_ipk) {
|
||||
(None, None, None) => {
|
||||
anyhow::bail!("Provide either account account_id of receiver or their public keys");
|
||||
}
|
||||
(Some(_), Some(_), Some(_)) => {
|
||||
anyhow::bail!(
|
||||
"Provide only one variant: either account account_id of receiver or their public keys"
|
||||
);
|
||||
}
|
||||
(_, Some(_), None) | (_, None, Some(_)) => {
|
||||
anyhow::bail!("List of public keys is uncomplete");
|
||||
}
|
||||
(Some(to), None, None) => ArgsSenderOwned { from: to.clone() }.parse(),
|
||||
(None, Some(to_npk), Some(to_ipk)) => {
|
||||
let to_npk_res = hex::decode(to_npk)?;
|
||||
let mut to_npk = [0; 32];
|
||||
to_npk.copy_from_slice(&to_npk_res);
|
||||
let to_npk = nssa_core::NullifierPublicKey(to_npk);
|
||||
macro_rules! maybe_unowned_account_name {
|
||||
($classname: ident, $field: ident) => {
|
||||
paste! {
|
||||
#[derive(Debug, Args, Clone)]
|
||||
pub struct $classname {
|
||||
/// $field - valid 32 byte base58 string with privacy prefix
|
||||
#[arg(long)]
|
||||
pub $field: Option<String>,
|
||||
/// [<$field _npk>] - valid 32 byte hex string
|
||||
#[arg(long)]
|
||||
pub [<$field _npk>]: Option<String>,
|
||||
/// [<$field _ipk>] - valid 33 byte hex string
|
||||
#[arg(long)]
|
||||
pub [<$field _ipk>]: Option<String>,
|
||||
}
|
||||
|
||||
let to_ipk_res = hex::decode(to_ipk)?;
|
||||
let mut to_ipk = [0u8; 33];
|
||||
to_ipk.copy_from_slice(&to_ipk_res);
|
||||
let to_ipk =
|
||||
nssa_core::encryption::shared_key_derivation::Secp256k1Point(to_ipk.to_vec());
|
||||
impl ParsePrivacyPreservingAccount for $classname {
|
||||
fn parse(&self) -> Result<PrivacyPreservingAccount> {
|
||||
match (&self.$field, &self.[<$field _npk>], &self.[<$field _ipk>]) {
|
||||
(None, None, None) => {
|
||||
anyhow::bail!("Provide either account account_id or their public keys");
|
||||
}
|
||||
(Some(_), Some(_), Some(_)) => {
|
||||
anyhow::bail!(
|
||||
"Provide only one variant: either account account_id or their public keys"
|
||||
);
|
||||
}
|
||||
(_, Some(_), None) | (_, None, Some(_)) => {
|
||||
anyhow::bail!("List of public keys is uncomplete");
|
||||
}
|
||||
(Some($field), None, None) => ArgsSenderOwned {
|
||||
from: $field.clone(),
|
||||
}
|
||||
.parse(),
|
||||
(None, Some([<$field _npk>]), Some([<$field _ipk>])) => {
|
||||
let [<$field _npk_res>] = hex::decode([<$field _npk>])?;
|
||||
let mut [<$field _npk>] = [0; 32];
|
||||
[<$field _npk>].copy_from_slice(&[<$field _npk_res>]);
|
||||
let [<$field _npk>] = nssa_core::NullifierPublicKey([<$field _npk>]);
|
||||
|
||||
Ok(PrivacyPreservingAccount::PrivateForeign {
|
||||
npk: to_npk,
|
||||
ipk: to_ipk,
|
||||
})
|
||||
let [<$field _ipk_res>] = hex::decode([<$field _ipk>])?;
|
||||
let mut [<$field _ipk>] = [0u8; 33];
|
||||
[<$field _ipk>].copy_from_slice(&[<$field _ipk_res>]);
|
||||
let [<$field _ipk>] = nssa_core::encryption::shared_key_derivation::Secp256k1Point(
|
||||
[<$field _ipk>].to_vec(),
|
||||
);
|
||||
|
||||
Ok(PrivacyPreservingAccount::PrivateForeign {
|
||||
npk: [<$field _npk>],
|
||||
ipk: [<$field _ipk>],
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Args, Clone)]
|
||||
pub struct ArgsDefinitionOwned {
|
||||
/// definition_account_id - valid 32 byte base58 string with privacy prefix
|
||||
#[arg(long)]
|
||||
pub definition_account_id: String,
|
||||
}
|
||||
|
||||
impl ParsePrivacyPreservingAccount for ArgsDefinitionOwned {
|
||||
fn parse(&self) -> Result<PrivacyPreservingAccount> {
|
||||
let (account_id, privacy) = parse_addr_with_privacy_prefix(&self.definition_account_id)?;
|
||||
|
||||
match privacy {
|
||||
AccountPrivacyKind::Public => Ok(PrivacyPreservingAccount::Public(account_id.parse()?)),
|
||||
AccountPrivacyKind::Private => {
|
||||
Ok(PrivacyPreservingAccount::PrivateOwned(account_id.parse()?))
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Debug, Args, Clone)]
|
||||
pub struct ArgsSupplyOwned {
|
||||
/// supply_account_id - valid 32 byte base58 string with privacy prefix
|
||||
#[arg(long)]
|
||||
pub supply_account_id: String,
|
||||
}
|
||||
|
||||
impl ParsePrivacyPreservingAccount for ArgsSupplyOwned {
|
||||
fn parse(&self) -> Result<PrivacyPreservingAccount> {
|
||||
let (account_id, privacy) = parse_addr_with_privacy_prefix(&self.supply_account_id)?;
|
||||
|
||||
match privacy {
|
||||
AccountPrivacyKind::Public => Ok(PrivacyPreservingAccount::Public(account_id.parse()?)),
|
||||
AccountPrivacyKind::Private => {
|
||||
Ok(PrivacyPreservingAccount::PrivateOwned(account_id.parse()?))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Args, Clone)]
|
||||
pub struct ArgsHolderOwned {
|
||||
/// holder_account_id - valid 32 byte base58 string with privacy prefix
|
||||
#[arg(long)]
|
||||
pub holder_account_id: String,
|
||||
}
|
||||
|
||||
impl ParsePrivacyPreservingAccount for ArgsHolderOwned {
|
||||
fn parse(&self) -> Result<PrivacyPreservingAccount> {
|
||||
let (account_id, privacy) = parse_addr_with_privacy_prefix(&self.holder_account_id)?;
|
||||
|
||||
match privacy {
|
||||
AccountPrivacyKind::Public => Ok(PrivacyPreservingAccount::Public(account_id.parse()?)),
|
||||
AccountPrivacyKind::Private => {
|
||||
Ok(PrivacyPreservingAccount::PrivateOwned(account_id.parse()?))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Args, Clone)]
|
||||
pub struct ArgsHolderMaybeUnowned {
|
||||
/// holder - valid 32 byte base58 string with privacy prefix
|
||||
#[arg(long)]
|
||||
pub holder: Option<String>,
|
||||
/// holder_npk - valid 32 byte hex string
|
||||
#[arg(long)]
|
||||
pub holder_npk: Option<String>,
|
||||
/// holder_ipk - valid 33 byte hex string
|
||||
#[arg(long)]
|
||||
pub holder_ipk: Option<String>,
|
||||
}
|
||||
|
||||
impl ParsePrivacyPreservingAccount for ArgsHolderMaybeUnowned {
|
||||
fn parse(&self) -> Result<PrivacyPreservingAccount> {
|
||||
match (&self.holder, &self.holder_npk, &self.holder_ipk) {
|
||||
(None, None, None) => {
|
||||
anyhow::bail!("Provide either account account_id of receiver or their public keys");
|
||||
}
|
||||
(Some(_), Some(_), Some(_)) => {
|
||||
anyhow::bail!(
|
||||
"Provide only one variant: either account account_id of receiver or their public keys"
|
||||
);
|
||||
}
|
||||
(_, Some(_), None) | (_, None, Some(_)) => {
|
||||
anyhow::bail!("List of public keys is uncomplete");
|
||||
}
|
||||
(Some(holder), None, None) => ArgsSenderOwned {
|
||||
from: holder.clone(),
|
||||
}
|
||||
.parse(),
|
||||
(None, Some(holder_npk), Some(holder_ipk)) => {
|
||||
let holder_npk_res = hex::decode(holder_npk)?;
|
||||
let mut holder_npk = [0; 32];
|
||||
holder_npk.copy_from_slice(&holder_npk_res);
|
||||
let holder_npk = nssa_core::NullifierPublicKey(holder_npk);
|
||||
|
||||
let holder_ipk_res = hex::decode(holder_ipk)?;
|
||||
let mut holder_ipk = [0u8; 33];
|
||||
holder_ipk.copy_from_slice(&holder_ipk_res);
|
||||
let holder_ipk = nssa_core::encryption::shared_key_derivation::Secp256k1Point(
|
||||
holder_ipk.to_vec(),
|
||||
);
|
||||
|
||||
Ok(PrivacyPreservingAccount::PrivateForeign {
|
||||
npk: holder_npk,
|
||||
ipk: holder_ipk,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
maybe_unowned_account_name!(ArgsReceiverMaybeUnowned, to);
|
||||
maybe_unowned_account_name!(ArgsHolderMaybeUnowned, holder);
|
||||
|
||||
@ -113,9 +113,7 @@ impl WalletSubcommand for AuthTransferSubcommand {
|
||||
let to = receiver.parse()?;
|
||||
|
||||
if from.is_private() || to.is_private() {
|
||||
let mut acc_vector = vec![];
|
||||
acc_vector.push(from);
|
||||
acc_vector.push(to);
|
||||
let acc_vector = vec![from, to];
|
||||
|
||||
let (res, acc_decode_data) = send_privacy_preserving_transaction_unified(
|
||||
wallet_core,
|
||||
|
||||
@ -96,9 +96,7 @@ impl WalletSubcommand for TokenProgramAgnosticSubcommand {
|
||||
let supply = supply.parse()?;
|
||||
|
||||
if definition.is_private() || supply.is_private() {
|
||||
let mut acc_vector = vec![];
|
||||
acc_vector.push(definition);
|
||||
acc_vector.push(supply);
|
||||
let acc_vector = vec![definition, supply];
|
||||
|
||||
let name = name.as_bytes();
|
||||
if name.len() > 6 {
|
||||
@ -165,9 +163,7 @@ impl WalletSubcommand for TokenProgramAgnosticSubcommand {
|
||||
let to = to.parse()?;
|
||||
|
||||
if from.is_private() || to.is_private() {
|
||||
let mut acc_vector = vec![];
|
||||
acc_vector.push(from);
|
||||
acc_vector.push(to);
|
||||
let acc_vector = vec![from, to];
|
||||
|
||||
let (res, acc_decode_data) = send_privacy_preserving_transaction_unified(
|
||||
wallet_core,
|
||||
@ -216,9 +212,7 @@ impl WalletSubcommand for TokenProgramAgnosticSubcommand {
|
||||
let holder = holder.parse()?;
|
||||
|
||||
if definition.is_private() || holder.is_private() {
|
||||
let mut acc_vector = vec![];
|
||||
acc_vector.push(definition);
|
||||
acc_vector.push(holder);
|
||||
let acc_vector = vec![definition, holder];
|
||||
|
||||
let (res, acc_decode_data) = send_privacy_preserving_transaction_unified(
|
||||
wallet_core,
|
||||
@ -270,9 +264,7 @@ impl WalletSubcommand for TokenProgramAgnosticSubcommand {
|
||||
let holder = holder.parse()?;
|
||||
|
||||
if definition.is_private() || holder.is_private() {
|
||||
let mut acc_vector = vec![];
|
||||
acc_vector.push(definition);
|
||||
acc_vector.push(holder);
|
||||
let acc_vector = vec![definition, holder];
|
||||
|
||||
let (res, acc_decode_data) = send_privacy_preserving_transaction_unified(
|
||||
wallet_core,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user