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