2025-12-16 14:05:34 +02:00
|
|
|
pub mod amm;
|
2025-11-27 22:07:53 +03:00
|
|
|
pub mod native_token_transfer;
|
|
|
|
|
pub mod pinata;
|
|
|
|
|
pub mod token;
|
2025-12-19 18:53:26 +02:00
|
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
use clap::Args;
|
2025-12-23 15:59:23 +02:00
|
|
|
use paste::paste;
|
2025-12-19 18:53:26 +02:00
|
|
|
|
2025-12-22 15:52:42 +02:00
|
|
|
use crate::{
|
|
|
|
|
PrivacyPreservingAccount,
|
|
|
|
|
helperfunctions::{AccountPrivacyKind, parse_addr_with_privacy_prefix},
|
|
|
|
|
};
|
2025-12-19 18:53:26 +02:00
|
|
|
|
2025-12-22 15:52:42 +02:00
|
|
|
trait ParsePrivacyPreservingAccount {
|
|
|
|
|
fn parse(&self) -> Result<PrivacyPreservingAccount>;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-08 08:39:12 +02:00
|
|
|
#[macro_export]
|
2025-12-23 15:59:23 +02:00
|
|
|
macro_rules! owned_account_name {
|
2026-01-15 12:05:35 +02:00
|
|
|
($structname: ident, $field: ident) => {
|
2025-12-23 15:59:23 +02:00
|
|
|
#[derive(Debug, Args, Clone)]
|
2026-01-15 12:05:35 +02:00
|
|
|
pub struct $structname {
|
2025-12-23 15:59:23 +02:00
|
|
|
/// $field - valid 32 byte base58 string with privacy prefix
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
pub $field: String,
|
2025-12-22 15:52:42 +02:00
|
|
|
}
|
2025-12-19 18:53:26 +02:00
|
|
|
|
2026-01-15 12:05:35 +02:00
|
|
|
impl ParsePrivacyPreservingAccount for $structname {
|
2025-12-23 15:59:23 +02:00
|
|
|
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()?))
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-22 15:52:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
2025-12-23 15:59:23 +02:00
|
|
|
};
|
2025-12-22 15:52:42 +02:00
|
|
|
}
|
|
|
|
|
|
2025-12-23 15:59:23 +02:00
|
|
|
owned_account_name!(ArgsSenderOwned, from);
|
|
|
|
|
|
2026-01-08 08:39:12 +02:00
|
|
|
#[macro_export]
|
2025-12-23 15:59:23 +02:00
|
|
|
macro_rules! maybe_unowned_account_name {
|
2026-01-15 12:05:35 +02:00
|
|
|
($structname: ident, $field: ident) => {
|
2025-12-23 15:59:23 +02:00
|
|
|
paste! {
|
|
|
|
|
#[derive(Debug, Args, Clone)]
|
2026-01-15 12:05:35 +02:00
|
|
|
pub struct $structname {
|
2025-12-23 15:59:23 +02:00
|
|
|
/// $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>,
|
2025-12-22 15:52:42 +02:00
|
|
|
}
|
|
|
|
|
|
2026-01-15 12:05:35 +02:00
|
|
|
impl ParsePrivacyPreservingAccount for $structname {
|
2025-12-23 15:59:23 +02:00
|
|
|
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(_)) => {
|
2026-01-15 12:05:35 +02:00
|
|
|
anyhow::bail!("List of public keys is incomplete");
|
2025-12-23 15:59:23 +02:00
|
|
|
}
|
|
|
|
|
(Some($field), None, None) => ArgsSenderOwned {
|
|
|
|
|
from: $field.clone(),
|
|
|
|
|
}
|
|
|
|
|
.parse(),
|
2026-01-15 12:05:35 +02:00
|
|
|
(None, Some(npk), Some(ipk)) => {
|
|
|
|
|
let npk_res = hex::decode(npk)?;
|
|
|
|
|
let mut npk = [0; 32];
|
|
|
|
|
npk.copy_from_slice(&npk_res);
|
|
|
|
|
let npk = nssa_core::NullifierPublicKey(npk);
|
2025-12-23 15:59:23 +02:00
|
|
|
|
2026-01-15 12:05:35 +02:00
|
|
|
let ipk_res = hex::decode(ipk)?;
|
|
|
|
|
let mut ipk = [0u8; 33];
|
|
|
|
|
ipk.copy_from_slice(&ipk_res);
|
|
|
|
|
let ipk = nssa_core::encryption::shared_key_derivation::Secp256k1Point(
|
|
|
|
|
ipk.to_vec(),
|
2025-12-23 15:59:23 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Ok(PrivacyPreservingAccount::PrivateForeign {
|
2026-01-15 12:05:35 +02:00
|
|
|
npk,
|
|
|
|
|
ipk,
|
2025-12-23 15:59:23 +02:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-22 15:52:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-23 15:59:23 +02:00
|
|
|
};
|
2025-12-22 15:52:42 +02:00
|
|
|
}
|
|
|
|
|
|
2025-12-23 15:59:23 +02:00
|
|
|
maybe_unowned_account_name!(ArgsReceiverMaybeUnowned, to);
|