mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-03-23 18:53:13 +00:00
fix: suggestions added 1
This commit is contained in:
parent
ff448cbb3c
commit
28c1fd39a4
@ -20,7 +20,7 @@ use tokio::task::JoinHandle;
|
|||||||
use wallet::{
|
use wallet::{
|
||||||
Command, SubcommandReturnValue, WalletCore,
|
Command, SubcommandReturnValue, WalletCore,
|
||||||
cli::{
|
cli::{
|
||||||
chain::{ChainSubcommand, FetchSubcommand, RegisterSubcommand},
|
account::{AccountSubcommand, FetchSubcommand, RegisterSubcommand},
|
||||||
native_token_transfer_program::{
|
native_token_transfer_program::{
|
||||||
NativeTokenTransferProgramSubcommand, NativeTokenTransferProgramSubcommandPrivate,
|
NativeTokenTransferProgramSubcommand, NativeTokenTransferProgramSubcommandPrivate,
|
||||||
NativeTokenTransferProgramSubcommandShielded,
|
NativeTokenTransferProgramSubcommandShielded,
|
||||||
@ -112,13 +112,11 @@ pub async fn post_test(residual: (ServerHandle, JoinHandle<Result<()>>, TempDir)
|
|||||||
|
|
||||||
pub async fn test_success() {
|
pub async fn test_success() {
|
||||||
info!("test_success");
|
info!("test_success");
|
||||||
let command = Command::Transfer(
|
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Public {
|
||||||
NativeTokenTransferProgramSubcommand::SendNativeTokenTransferPublic {
|
from: ACC_SENDER.to_string(),
|
||||||
from: ACC_SENDER.to_string(),
|
to: ACC_RECEIVER.to_string(),
|
||||||
to: ACC_RECEIVER.to_string(),
|
amount: 100,
|
||||||
amount: 100,
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
let wallet_config = fetch_config().await.unwrap();
|
let wallet_config = fetch_config().await.unwrap();
|
||||||
|
|
||||||
@ -150,9 +148,7 @@ pub async fn test_success() {
|
|||||||
|
|
||||||
pub async fn test_success_move_to_another_account() {
|
pub async fn test_success_move_to_another_account() {
|
||||||
info!("test_success_move_to_another_account");
|
info!("test_success_move_to_another_account");
|
||||||
let command = Command::Chain(ChainSubcommand::Register(
|
let command = Command::Account(AccountSubcommand::Register(RegisterSubcommand::Public {}));
|
||||||
RegisterSubcommand::RegisterAccountPublic {},
|
|
||||||
));
|
|
||||||
|
|
||||||
let wallet_config = fetch_config().await.unwrap();
|
let wallet_config = fetch_config().await.unwrap();
|
||||||
|
|
||||||
@ -176,13 +172,11 @@ pub async fn test_success_move_to_another_account() {
|
|||||||
panic!("Failed to produce new account, not present in persistent accounts");
|
panic!("Failed to produce new account, not present in persistent accounts");
|
||||||
}
|
}
|
||||||
|
|
||||||
let command = Command::Transfer(
|
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Public {
|
||||||
NativeTokenTransferProgramSubcommand::SendNativeTokenTransferPublic {
|
from: ACC_SENDER.to_string(),
|
||||||
from: ACC_SENDER.to_string(),
|
to: new_persistent_account_addr.clone(),
|
||||||
to: new_persistent_account_addr.clone(),
|
amount: 100,
|
||||||
amount: 100,
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
wallet::execute_subcommand(command).await.unwrap();
|
wallet::execute_subcommand(command).await.unwrap();
|
||||||
|
|
||||||
@ -210,13 +204,11 @@ pub async fn test_success_move_to_another_account() {
|
|||||||
|
|
||||||
pub async fn test_failure() {
|
pub async fn test_failure() {
|
||||||
info!("test_failure");
|
info!("test_failure");
|
||||||
let command = Command::Transfer(
|
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Public {
|
||||||
NativeTokenTransferProgramSubcommand::SendNativeTokenTransferPublic {
|
from: ACC_SENDER.to_string(),
|
||||||
from: ACC_SENDER.to_string(),
|
to: ACC_RECEIVER.to_string(),
|
||||||
to: ACC_RECEIVER.to_string(),
|
amount: 1000000,
|
||||||
amount: 1000000,
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
let wallet_config = fetch_config().await.unwrap();
|
let wallet_config = fetch_config().await.unwrap();
|
||||||
|
|
||||||
@ -250,13 +242,11 @@ pub async fn test_failure() {
|
|||||||
|
|
||||||
pub async fn test_success_two_transactions() {
|
pub async fn test_success_two_transactions() {
|
||||||
info!("test_success_two_transactions");
|
info!("test_success_two_transactions");
|
||||||
let command = Command::Transfer(
|
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Public {
|
||||||
NativeTokenTransferProgramSubcommand::SendNativeTokenTransferPublic {
|
from: ACC_SENDER.to_string(),
|
||||||
from: ACC_SENDER.to_string(),
|
to: ACC_RECEIVER.to_string(),
|
||||||
to: ACC_RECEIVER.to_string(),
|
amount: 100,
|
||||||
amount: 100,
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
let wallet_config = fetch_config().await.unwrap();
|
let wallet_config = fetch_config().await.unwrap();
|
||||||
|
|
||||||
@ -285,13 +275,11 @@ pub async fn test_success_two_transactions() {
|
|||||||
|
|
||||||
info!("First TX Success!");
|
info!("First TX Success!");
|
||||||
|
|
||||||
let command = Command::Transfer(
|
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Public {
|
||||||
NativeTokenTransferProgramSubcommand::SendNativeTokenTransferPublic {
|
from: ACC_SENDER.to_string(),
|
||||||
from: ACC_SENDER.to_string(),
|
to: ACC_RECEIVER.to_string(),
|
||||||
to: ACC_RECEIVER.to_string(),
|
amount: 100,
|
||||||
amount: 100,
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
wallet::execute_subcommand(command).await.unwrap();
|
wallet::execute_subcommand(command).await.unwrap();
|
||||||
|
|
||||||
@ -343,20 +331,20 @@ pub async fn test_success_token_program() {
|
|||||||
let wallet_config = fetch_config().await.unwrap();
|
let wallet_config = fetch_config().await.unwrap();
|
||||||
|
|
||||||
// Create new account for the token definition
|
// Create new account for the token definition
|
||||||
wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register(
|
wallet::execute_subcommand(Command::Account(AccountSubcommand::Register(
|
||||||
RegisterSubcommand::RegisterAccountPublic {},
|
RegisterSubcommand::Public {},
|
||||||
)))
|
)))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
// Create new account for the token supply holder
|
// Create new account for the token supply holder
|
||||||
wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register(
|
wallet::execute_subcommand(Command::Account(AccountSubcommand::Register(
|
||||||
RegisterSubcommand::RegisterAccountPublic {},
|
RegisterSubcommand::Public {},
|
||||||
)))
|
)))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
// Create new account for receiving a token transaction
|
// Create new account for receiving a token transaction
|
||||||
wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register(
|
wallet::execute_subcommand(Command::Account(AccountSubcommand::Register(
|
||||||
RegisterSubcommand::RegisterAccountPublic {},
|
RegisterSubcommand::Public {},
|
||||||
)))
|
)))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -492,8 +480,8 @@ pub async fn test_success_token_program_private_owned() {
|
|||||||
// Create new account for the token definition (public)
|
// Create new account for the token definition (public)
|
||||||
let SubcommandReturnValue::RegisterAccount {
|
let SubcommandReturnValue::RegisterAccount {
|
||||||
addr: definition_addr,
|
addr: definition_addr,
|
||||||
} = wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register(
|
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::Register(
|
||||||
RegisterSubcommand::RegisterAccountPublic {},
|
RegisterSubcommand::Public {},
|
||||||
)))
|
)))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -501,20 +489,18 @@ pub async fn test_success_token_program_private_owned() {
|
|||||||
panic!("invalid subcommand return value");
|
panic!("invalid subcommand return value");
|
||||||
};
|
};
|
||||||
// Create new account for the token supply holder (private)
|
// Create new account for the token supply holder (private)
|
||||||
let SubcommandReturnValue::RegisterAccount { addr: supply_addr } =
|
let SubcommandReturnValue::RegisterAccount { addr: supply_addr } = wallet::execute_subcommand(
|
||||||
wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register(
|
Command::Account(AccountSubcommand::Register(RegisterSubcommand::Private {})),
|
||||||
RegisterSubcommand::RegisterAccountPrivate {},
|
)
|
||||||
)))
|
.await
|
||||||
.await
|
.unwrap() else {
|
||||||
.unwrap()
|
|
||||||
else {
|
|
||||||
panic!("invalid subcommand return value");
|
panic!("invalid subcommand return value");
|
||||||
};
|
};
|
||||||
// Create new account for receiving a token transaction
|
// Create new account for receiving a token transaction
|
||||||
let SubcommandReturnValue::RegisterAccount {
|
let SubcommandReturnValue::RegisterAccount {
|
||||||
addr: recipient_addr,
|
addr: recipient_addr,
|
||||||
} = wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register(
|
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::Register(
|
||||||
RegisterSubcommand::RegisterAccountPrivate {},
|
RegisterSubcommand::Private {},
|
||||||
)))
|
)))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -637,8 +623,8 @@ pub async fn test_success_token_program_private_claiming_path() {
|
|||||||
// Create new account for the token definition (public)
|
// Create new account for the token definition (public)
|
||||||
let SubcommandReturnValue::RegisterAccount {
|
let SubcommandReturnValue::RegisterAccount {
|
||||||
addr: definition_addr,
|
addr: definition_addr,
|
||||||
} = wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register(
|
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::Register(
|
||||||
RegisterSubcommand::RegisterAccountPublic {},
|
RegisterSubcommand::Public {},
|
||||||
)))
|
)))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -646,20 +632,18 @@ pub async fn test_success_token_program_private_claiming_path() {
|
|||||||
panic!("invalid subcommand return value");
|
panic!("invalid subcommand return value");
|
||||||
};
|
};
|
||||||
// Create new account for the token supply holder (private)
|
// Create new account for the token supply holder (private)
|
||||||
let SubcommandReturnValue::RegisterAccount { addr: supply_addr } =
|
let SubcommandReturnValue::RegisterAccount { addr: supply_addr } = wallet::execute_subcommand(
|
||||||
wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register(
|
Command::Account(AccountSubcommand::Register(RegisterSubcommand::Private {})),
|
||||||
RegisterSubcommand::RegisterAccountPrivate {},
|
)
|
||||||
)))
|
.await
|
||||||
.await
|
.unwrap() else {
|
||||||
.unwrap()
|
|
||||||
else {
|
|
||||||
panic!("invalid subcommand return value");
|
panic!("invalid subcommand return value");
|
||||||
};
|
};
|
||||||
// Create new account for receiving a token transaction
|
// Create new account for receiving a token transaction
|
||||||
let SubcommandReturnValue::RegisterAccount {
|
let SubcommandReturnValue::RegisterAccount {
|
||||||
addr: recipient_addr,
|
addr: recipient_addr,
|
||||||
} = wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register(
|
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::Register(
|
||||||
RegisterSubcommand::RegisterAccountPrivate {},
|
RegisterSubcommand::Private {},
|
||||||
)))
|
)))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -740,13 +724,11 @@ pub async fn test_success_token_program_private_claiming_path() {
|
|||||||
info!("Waiting for next block creation");
|
info!("Waiting for next block creation");
|
||||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||||
|
|
||||||
let command = Command::Chain(ChainSubcommand::Fetch(
|
let command = Command::Account(AccountSubcommand::Fetch(FetchSubcommand::PrivateAccount {
|
||||||
FetchSubcommand::FetchPrivateAccount {
|
tx_hash,
|
||||||
tx_hash,
|
acc_addr: recipient_addr.to_string(),
|
||||||
acc_addr: recipient_addr.to_string(),
|
output_id: 1,
|
||||||
output_id: 1,
|
}));
|
||||||
},
|
|
||||||
));
|
|
||||||
|
|
||||||
wallet::execute_subcommand(command).await.unwrap();
|
wallet::execute_subcommand(command).await.unwrap();
|
||||||
|
|
||||||
@ -774,29 +756,27 @@ pub async fn test_success_token_program_shielded_owned() {
|
|||||||
// Create new account for the token definition (public)
|
// Create new account for the token definition (public)
|
||||||
let SubcommandReturnValue::RegisterAccount {
|
let SubcommandReturnValue::RegisterAccount {
|
||||||
addr: definition_addr,
|
addr: definition_addr,
|
||||||
} = wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register(
|
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::Register(
|
||||||
RegisterSubcommand::RegisterAccountPublic {},
|
RegisterSubcommand::Public {},
|
||||||
)))
|
)))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
else {
|
else {
|
||||||
panic!("invalid subcommand return value");
|
panic!("invalid subcommand return value");
|
||||||
};
|
};
|
||||||
// Create new account for the token supply holder (private)
|
// Create new account for the token supply holder (public)
|
||||||
let SubcommandReturnValue::RegisterAccount { addr: supply_addr } =
|
let SubcommandReturnValue::RegisterAccount { addr: supply_addr } = wallet::execute_subcommand(
|
||||||
wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register(
|
Command::Account(AccountSubcommand::Register(RegisterSubcommand::Public {})),
|
||||||
RegisterSubcommand::RegisterAccountPublic {},
|
)
|
||||||
)))
|
.await
|
||||||
.await
|
.unwrap() else {
|
||||||
.unwrap()
|
|
||||||
else {
|
|
||||||
panic!("invalid subcommand return value");
|
panic!("invalid subcommand return value");
|
||||||
};
|
};
|
||||||
// Create new account for receiving a token transaction
|
// Create new account for receiving a token transaction
|
||||||
let SubcommandReturnValue::RegisterAccount {
|
let SubcommandReturnValue::RegisterAccount {
|
||||||
addr: recipient_addr,
|
addr: recipient_addr,
|
||||||
} = wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register(
|
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::Register(
|
||||||
RegisterSubcommand::RegisterAccountPrivate {},
|
RegisterSubcommand::Private {},
|
||||||
)))
|
)))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -899,8 +879,8 @@ pub async fn test_success_token_program_deshielded_owned() {
|
|||||||
// Create new account for the token definition (public)
|
// Create new account for the token definition (public)
|
||||||
let SubcommandReturnValue::RegisterAccount {
|
let SubcommandReturnValue::RegisterAccount {
|
||||||
addr: definition_addr,
|
addr: definition_addr,
|
||||||
} = wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register(
|
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::Register(
|
||||||
RegisterSubcommand::RegisterAccountPublic {},
|
RegisterSubcommand::Public {},
|
||||||
)))
|
)))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -908,20 +888,18 @@ pub async fn test_success_token_program_deshielded_owned() {
|
|||||||
panic!("invalid subcommand return value");
|
panic!("invalid subcommand return value");
|
||||||
};
|
};
|
||||||
// Create new account for the token supply holder (private)
|
// Create new account for the token supply holder (private)
|
||||||
let SubcommandReturnValue::RegisterAccount { addr: supply_addr } =
|
let SubcommandReturnValue::RegisterAccount { addr: supply_addr } = wallet::execute_subcommand(
|
||||||
wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register(
|
Command::Account(AccountSubcommand::Register(RegisterSubcommand::Private {})),
|
||||||
RegisterSubcommand::RegisterAccountPrivate {},
|
)
|
||||||
)))
|
.await
|
||||||
.await
|
.unwrap() else {
|
||||||
.unwrap()
|
|
||||||
else {
|
|
||||||
panic!("invalid subcommand return value");
|
panic!("invalid subcommand return value");
|
||||||
};
|
};
|
||||||
// Create new account for receiving a token transaction
|
// Create new account for receiving a token transaction
|
||||||
let SubcommandReturnValue::RegisterAccount {
|
let SubcommandReturnValue::RegisterAccount {
|
||||||
addr: recipient_addr,
|
addr: recipient_addr,
|
||||||
} = wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register(
|
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::Register(
|
||||||
RegisterSubcommand::RegisterAccountPublic {},
|
RegisterSubcommand::Public {},
|
||||||
)))
|
)))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -1034,7 +1012,7 @@ pub async fn test_success_private_transfer_to_another_owned_account() {
|
|||||||
let to: Address = ACC_RECEIVER_PRIVATE.parse().unwrap();
|
let to: Address = ACC_RECEIVER_PRIVATE.parse().unwrap();
|
||||||
|
|
||||||
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Private(
|
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Private(
|
||||||
NativeTokenTransferProgramSubcommandPrivate::SendNativeTokenTransferPrivateOwnedAccount {
|
NativeTokenTransferProgramSubcommandPrivate::PrivateOwned {
|
||||||
from: from.to_string(),
|
from: from.to_string(),
|
||||||
to: to.to_string(),
|
to: to.to_string(),
|
||||||
amount: 100,
|
amount: 100,
|
||||||
@ -1071,7 +1049,7 @@ pub async fn test_success_private_transfer_to_another_foreign_account() {
|
|||||||
let to_ipk = Secp256k1Point::from_scalar(to_npk.0);
|
let to_ipk = Secp256k1Point::from_scalar(to_npk.0);
|
||||||
|
|
||||||
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Private(
|
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Private(
|
||||||
NativeTokenTransferProgramSubcommandPrivate::SendNativeTokenTransferPrivateForeignAccount {
|
NativeTokenTransferProgramSubcommandPrivate::PrivateForeign {
|
||||||
from: from.to_string(),
|
from: from.to_string(),
|
||||||
to_npk: to_npk_string,
|
to_npk: to_npk_string,
|
||||||
to_ipk: hex::encode(to_ipk.0),
|
to_ipk: hex::encode(to_ipk.0),
|
||||||
@ -1113,9 +1091,7 @@ pub async fn test_success_private_transfer_to_another_owned_account_claiming_pat
|
|||||||
info!("test_success_private_transfer_to_another_owned_account_claiming_path");
|
info!("test_success_private_transfer_to_another_owned_account_claiming_path");
|
||||||
let from: Address = ACC_SENDER_PRIVATE.parse().unwrap();
|
let from: Address = ACC_SENDER_PRIVATE.parse().unwrap();
|
||||||
|
|
||||||
let command = Command::Chain(ChainSubcommand::Register(
|
let command = Command::Account(AccountSubcommand::Register(RegisterSubcommand::Private {}));
|
||||||
RegisterSubcommand::RegisterAccountPrivate {},
|
|
||||||
));
|
|
||||||
|
|
||||||
let sub_ret = wallet::execute_subcommand(command).await.unwrap();
|
let sub_ret = wallet::execute_subcommand(command).await.unwrap();
|
||||||
let SubcommandReturnValue::RegisterAccount { addr: to_addr } = sub_ret else {
|
let SubcommandReturnValue::RegisterAccount { addr: to_addr } = sub_ret else {
|
||||||
@ -1137,7 +1113,7 @@ pub async fn test_success_private_transfer_to_another_owned_account_claiming_pat
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Private(
|
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Private(
|
||||||
NativeTokenTransferProgramSubcommandPrivate::SendNativeTokenTransferPrivateForeignAccount {
|
NativeTokenTransferProgramSubcommandPrivate::PrivateForeign {
|
||||||
from: from.to_string(),
|
from: from.to_string(),
|
||||||
to_npk: hex::encode(to_keys.nullifer_public_key.0),
|
to_npk: hex::encode(to_keys.nullifer_public_key.0),
|
||||||
to_ipk: hex::encode(to_keys.incoming_viewing_public_key.0),
|
to_ipk: hex::encode(to_keys.incoming_viewing_public_key.0),
|
||||||
@ -1152,13 +1128,11 @@ pub async fn test_success_private_transfer_to_another_owned_account_claiming_pat
|
|||||||
|
|
||||||
let tx = fetch_privacy_preserving_tx(&seq_client, tx_hash.clone()).await;
|
let tx = fetch_privacy_preserving_tx(&seq_client, tx_hash.clone()).await;
|
||||||
|
|
||||||
let command = Command::Chain(ChainSubcommand::Fetch(
|
let command = Command::Account(AccountSubcommand::Fetch(FetchSubcommand::PrivateAccount {
|
||||||
FetchSubcommand::FetchPrivateAccount {
|
tx_hash,
|
||||||
tx_hash,
|
acc_addr: to_addr.to_string(),
|
||||||
acc_addr: to_addr.to_string(),
|
output_id: 1,
|
||||||
output_id: 1,
|
}));
|
||||||
},
|
|
||||||
));
|
|
||||||
wallet::execute_subcommand(command).await.unwrap();
|
wallet::execute_subcommand(command).await.unwrap();
|
||||||
let wallet_storage = WalletCore::start_from_config_update_chain(wallet_config)
|
let wallet_storage = WalletCore::start_from_config_update_chain(wallet_config)
|
||||||
.await
|
.await
|
||||||
@ -1187,9 +1161,7 @@ pub async fn test_success_private_transfer_to_another_owned_account_cont_run_pat
|
|||||||
|
|
||||||
let from: Address = ACC_SENDER_PRIVATE.parse().unwrap();
|
let from: Address = ACC_SENDER_PRIVATE.parse().unwrap();
|
||||||
|
|
||||||
let command = Command::Chain(ChainSubcommand::Register(
|
let command = Command::Account(AccountSubcommand::Register(RegisterSubcommand::Private {}));
|
||||||
RegisterSubcommand::RegisterAccountPrivate {},
|
|
||||||
));
|
|
||||||
|
|
||||||
let sub_ret = wallet::execute_subcommand(command).await.unwrap();
|
let sub_ret = wallet::execute_subcommand(command).await.unwrap();
|
||||||
let SubcommandReturnValue::RegisterAccount { addr: to_addr } = sub_ret else {
|
let SubcommandReturnValue::RegisterAccount { addr: to_addr } = sub_ret else {
|
||||||
@ -1211,7 +1183,7 @@ pub async fn test_success_private_transfer_to_another_owned_account_cont_run_pat
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Private(
|
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Private(
|
||||||
NativeTokenTransferProgramSubcommandPrivate::SendNativeTokenTransferPrivateForeignAccount {
|
NativeTokenTransferProgramSubcommandPrivate::PrivateForeign {
|
||||||
from: from.to_string(),
|
from: from.to_string(),
|
||||||
to_npk: hex::encode(to_keys.nullifer_public_key.0),
|
to_npk: hex::encode(to_keys.nullifer_public_key.0),
|
||||||
to_ipk: hex::encode(to_keys.incoming_viewing_public_key.0),
|
to_ipk: hex::encode(to_keys.incoming_viewing_public_key.0),
|
||||||
@ -1257,13 +1229,11 @@ pub async fn test_success_deshielded_transfer_to_another_account() {
|
|||||||
info!("test_success_deshielded_transfer_to_another_account");
|
info!("test_success_deshielded_transfer_to_another_account");
|
||||||
let from: Address = ACC_SENDER_PRIVATE.parse().unwrap();
|
let from: Address = ACC_SENDER_PRIVATE.parse().unwrap();
|
||||||
let to: Address = ACC_RECEIVER.parse().unwrap();
|
let to: Address = ACC_RECEIVER.parse().unwrap();
|
||||||
let command = Command::Transfer(
|
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Deshielded {
|
||||||
NativeTokenTransferProgramSubcommand::SendNativeTokenTransferDeshielded {
|
from: from.to_string(),
|
||||||
from: from.to_string(),
|
to: to.to_string(),
|
||||||
to: to.to_string(),
|
amount: 100,
|
||||||
amount: 100,
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
let wallet_config = fetch_config().await.unwrap();
|
let wallet_config = fetch_config().await.unwrap();
|
||||||
let seq_client = SequencerClient::new(wallet_config.sequencer_addr.clone()).unwrap();
|
let seq_client = SequencerClient::new(wallet_config.sequencer_addr.clone()).unwrap();
|
||||||
@ -1305,7 +1275,7 @@ pub async fn test_success_shielded_transfer_to_another_owned_account() {
|
|||||||
let from: Address = ACC_SENDER.parse().unwrap();
|
let from: Address = ACC_SENDER.parse().unwrap();
|
||||||
let to: Address = ACC_RECEIVER_PRIVATE.parse().unwrap();
|
let to: Address = ACC_RECEIVER_PRIVATE.parse().unwrap();
|
||||||
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Shielded(
|
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Shielded(
|
||||||
NativeTokenTransferProgramSubcommandShielded::SendNativeTokenTransferShielded {
|
NativeTokenTransferProgramSubcommandShielded::ShieldedOwned {
|
||||||
from: from.to_string(),
|
from: from.to_string(),
|
||||||
to: to.to_string(),
|
to: to.to_string(),
|
||||||
amount: 100,
|
amount: 100,
|
||||||
@ -1348,12 +1318,13 @@ pub async fn test_success_shielded_transfer_to_another_foreign_account() {
|
|||||||
let from: Address = ACC_SENDER.parse().unwrap();
|
let from: Address = ACC_SENDER.parse().unwrap();
|
||||||
|
|
||||||
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Shielded(
|
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Shielded(
|
||||||
NativeTokenTransferProgramSubcommandShielded::SendNativeTokenTransferShieldedForeignAccount {
|
NativeTokenTransferProgramSubcommandShielded::ShieldedForeign {
|
||||||
from: from.to_string(),
|
from: from.to_string(),
|
||||||
to_npk: to_npk_string,
|
to_npk: to_npk_string,
|
||||||
to_ipk: hex::encode(to_ipk.0),
|
to_ipk: hex::encode(to_ipk.0),
|
||||||
amount: 100,
|
amount: 100,
|
||||||
}));
|
},
|
||||||
|
));
|
||||||
|
|
||||||
let wallet_config = fetch_config().await.unwrap();
|
let wallet_config = fetch_config().await.unwrap();
|
||||||
|
|
||||||
@ -1390,7 +1361,7 @@ pub async fn test_pinata() {
|
|||||||
let pinata_prize = 150;
|
let pinata_prize = 150;
|
||||||
let solution = 989106;
|
let solution = 989106;
|
||||||
let command = Command::PinataProgram(PinataProgramSubcommand::Public(
|
let command = Command::PinataProgram(PinataProgramSubcommand::Public(
|
||||||
PinataProgramSubcommandPublic::ClaimPinata {
|
PinataProgramSubcommandPublic::Claim {
|
||||||
pinata_addr: pinata_addr.clone(),
|
pinata_addr: pinata_addr.clone(),
|
||||||
winner_addr: ACC_SENDER.to_string(),
|
winner_addr: ACC_SENDER.to_string(),
|
||||||
solution,
|
solution,
|
||||||
@ -1438,7 +1409,7 @@ pub async fn test_pinata_private_receiver() {
|
|||||||
let solution = 989106;
|
let solution = 989106;
|
||||||
|
|
||||||
let command = Command::PinataProgram(PinataProgramSubcommand::Private(
|
let command = Command::PinataProgram(PinataProgramSubcommand::Private(
|
||||||
PinataProgramSubcommandPrivate::ClaimPinataPrivateReceiverOwned {
|
PinataProgramSubcommandPrivate::ClaimPrivateOwned {
|
||||||
pinata_addr: pinata_addr.clone(),
|
pinata_addr: pinata_addr.clone(),
|
||||||
winner_addr: ACC_SENDER_PRIVATE.to_string(),
|
winner_addr: ACC_SENDER_PRIVATE.to_string(),
|
||||||
solution,
|
solution,
|
||||||
@ -1471,13 +1442,11 @@ pub async fn test_pinata_private_receiver() {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.balance;
|
.balance;
|
||||||
|
|
||||||
let command = Command::Chain(ChainSubcommand::Fetch(
|
let command = Command::Account(AccountSubcommand::Fetch(FetchSubcommand::PrivateAccount {
|
||||||
FetchSubcommand::FetchPrivateAccount {
|
tx_hash: tx_hash.clone(),
|
||||||
tx_hash: tx_hash.clone(),
|
acc_addr: ACC_SENDER_PRIVATE.to_string(),
|
||||||
acc_addr: ACC_SENDER_PRIVATE.to_string(),
|
output_id: 0,
|
||||||
output_id: 0,
|
}));
|
||||||
},
|
|
||||||
));
|
|
||||||
wallet::execute_subcommand(command).await.unwrap();
|
wallet::execute_subcommand(command).await.unwrap();
|
||||||
|
|
||||||
let wallet_config = fetch_config().await.unwrap();
|
let wallet_config = fetch_config().await.unwrap();
|
||||||
@ -1503,18 +1472,16 @@ pub async fn test_pinata_private_receiver_new_account() {
|
|||||||
let solution = 989106;
|
let solution = 989106;
|
||||||
|
|
||||||
// Create new account for the token supply holder (private)
|
// Create new account for the token supply holder (private)
|
||||||
let SubcommandReturnValue::RegisterAccount { addr: winner_addr } =
|
let SubcommandReturnValue::RegisterAccount { addr: winner_addr } = wallet::execute_subcommand(
|
||||||
wallet::execute_subcommand(Command::Chain(ChainSubcommand::Register(
|
Command::Account(AccountSubcommand::Register(RegisterSubcommand::Private {})),
|
||||||
RegisterSubcommand::RegisterAccountPrivate {},
|
)
|
||||||
)))
|
.await
|
||||||
.await
|
.unwrap() else {
|
||||||
.unwrap()
|
|
||||||
else {
|
|
||||||
panic!("invalid subcommand return value");
|
panic!("invalid subcommand return value");
|
||||||
};
|
};
|
||||||
|
|
||||||
let command = Command::PinataProgram(PinataProgramSubcommand::Private(
|
let command = Command::PinataProgram(PinataProgramSubcommand::Private(
|
||||||
PinataProgramSubcommandPrivate::ClaimPinataPrivateReceiverOwned {
|
PinataProgramSubcommandPrivate::ClaimPrivateOwned {
|
||||||
pinata_addr: pinata_addr.clone(),
|
pinata_addr: pinata_addr.clone(),
|
||||||
winner_addr: winner_addr.to_string(),
|
winner_addr: winner_addr.to_string(),
|
||||||
solution,
|
solution,
|
||||||
|
|||||||
253
wallet/src/cli/account.rs
Normal file
253
wallet/src/cli/account.rs
Normal file
@ -0,0 +1,253 @@
|
|||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use clap::Subcommand;
|
||||||
|
use common::transaction::NSSATransaction;
|
||||||
|
use nssa::Address;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
SubcommandReturnValue, WalletCore, cli::WalletSubcommand, helperfunctions::HumanReadableAccount,
|
||||||
|
};
|
||||||
|
|
||||||
|
///Represents generic chain CLI subcommand
|
||||||
|
#[derive(Subcommand, Debug, Clone)]
|
||||||
|
pub enum AccountSubcommand {
|
||||||
|
///Get
|
||||||
|
#[command(subcommand)]
|
||||||
|
Get(GetSubcommand),
|
||||||
|
///Fetch
|
||||||
|
#[command(subcommand)]
|
||||||
|
Fetch(FetchSubcommand),
|
||||||
|
///Register
|
||||||
|
#[command(subcommand)]
|
||||||
|
Register(RegisterSubcommand),
|
||||||
|
}
|
||||||
|
|
||||||
|
///Represents generic getter CLI subcommand
|
||||||
|
#[derive(Subcommand, Debug, Clone)]
|
||||||
|
pub enum GetSubcommand {
|
||||||
|
///Get account `addr` balance
|
||||||
|
PublicAccountBalance {
|
||||||
|
#[arg(short, long)]
|
||||||
|
addr: String,
|
||||||
|
},
|
||||||
|
///Get account `addr` nonce
|
||||||
|
PublicAccountNonce {
|
||||||
|
#[arg(short, long)]
|
||||||
|
addr: String,
|
||||||
|
},
|
||||||
|
///Get account at address `addr`
|
||||||
|
PublicAccount {
|
||||||
|
#[arg(short, long)]
|
||||||
|
addr: String,
|
||||||
|
},
|
||||||
|
///Get private account with `addr` from storage
|
||||||
|
PrivateAccount {
|
||||||
|
#[arg(short, long)]
|
||||||
|
addr: String,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
///Represents generic getter CLI subcommand
|
||||||
|
#[derive(Subcommand, Debug, Clone)]
|
||||||
|
pub enum FetchSubcommand {
|
||||||
|
///Fetch transaction by `hash`
|
||||||
|
Tx {
|
||||||
|
#[arg(short, long)]
|
||||||
|
tx_hash: String,
|
||||||
|
},
|
||||||
|
///Claim account `acc_addr` generated in transaction `tx_hash`, using secret `sh_secret` at ciphertext id `ciph_id`
|
||||||
|
PrivateAccount {
|
||||||
|
///tx_hash - valid 32 byte hex string
|
||||||
|
#[arg(long)]
|
||||||
|
tx_hash: String,
|
||||||
|
///acc_addr - valid 32 byte hex string
|
||||||
|
#[arg(long)]
|
||||||
|
acc_addr: String,
|
||||||
|
///output_id - id of the output in the transaction
|
||||||
|
#[arg(long)]
|
||||||
|
output_id: usize,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
///Represents generic register CLI subcommand
|
||||||
|
#[derive(Subcommand, Debug, Clone)]
|
||||||
|
pub enum RegisterSubcommand {
|
||||||
|
///Register new public account
|
||||||
|
Public {},
|
||||||
|
///Register new private account
|
||||||
|
Private {},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WalletSubcommand for GetSubcommand {
|
||||||
|
async fn handle_subcommand(
|
||||||
|
self,
|
||||||
|
wallet_core: &mut WalletCore,
|
||||||
|
) -> Result<SubcommandReturnValue> {
|
||||||
|
match self {
|
||||||
|
GetSubcommand::PublicAccountBalance { addr } => {
|
||||||
|
let addr = Address::from_str(&addr)?;
|
||||||
|
|
||||||
|
let balance = wallet_core.get_account_balance(addr).await?;
|
||||||
|
println!("Accounts {addr} balance is {balance}");
|
||||||
|
|
||||||
|
Ok(SubcommandReturnValue::Empty)
|
||||||
|
}
|
||||||
|
GetSubcommand::PublicAccountNonce { addr } => {
|
||||||
|
let addr = Address::from_str(&addr)?;
|
||||||
|
|
||||||
|
let nonce = wallet_core.get_accounts_nonces(vec![addr]).await?[0];
|
||||||
|
println!("Accounts {addr} nonce is {nonce}");
|
||||||
|
|
||||||
|
Ok(SubcommandReturnValue::Empty)
|
||||||
|
}
|
||||||
|
GetSubcommand::PublicAccount { addr } => {
|
||||||
|
let addr: Address = addr.parse()?;
|
||||||
|
let account = wallet_core.get_account_public(addr).await?;
|
||||||
|
let account_hr: HumanReadableAccount = account.clone().into();
|
||||||
|
println!("{}", serde_json::to_string(&account_hr).unwrap());
|
||||||
|
|
||||||
|
Ok(SubcommandReturnValue::Account(account))
|
||||||
|
}
|
||||||
|
GetSubcommand::PrivateAccount { addr } => {
|
||||||
|
let addr: Address = addr.parse()?;
|
||||||
|
if let Some(account) = wallet_core.get_account_private(&addr) {
|
||||||
|
println!("{}", serde_json::to_string(&account).unwrap());
|
||||||
|
} else {
|
||||||
|
println!("Private account not found.");
|
||||||
|
}
|
||||||
|
Ok(SubcommandReturnValue::Empty)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WalletSubcommand for FetchSubcommand {
|
||||||
|
async fn handle_subcommand(
|
||||||
|
self,
|
||||||
|
wallet_core: &mut WalletCore,
|
||||||
|
) -> Result<SubcommandReturnValue> {
|
||||||
|
match self {
|
||||||
|
FetchSubcommand::Tx { tx_hash } => {
|
||||||
|
let tx_obj = wallet_core
|
||||||
|
.sequencer_client
|
||||||
|
.get_transaction_by_hash(tx_hash)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
println!("Transaction object {tx_obj:#?}");
|
||||||
|
|
||||||
|
Ok(SubcommandReturnValue::Empty)
|
||||||
|
}
|
||||||
|
FetchSubcommand::PrivateAccount {
|
||||||
|
tx_hash,
|
||||||
|
acc_addr,
|
||||||
|
output_id: ciph_id,
|
||||||
|
} => {
|
||||||
|
let acc_addr: Address = acc_addr.parse().unwrap();
|
||||||
|
|
||||||
|
let account_key_chain = wallet_core
|
||||||
|
.storage
|
||||||
|
.user_data
|
||||||
|
.user_private_accounts
|
||||||
|
.get(&acc_addr);
|
||||||
|
|
||||||
|
let Some((account_key_chain, _)) = account_key_chain else {
|
||||||
|
anyhow::bail!("Account not found");
|
||||||
|
};
|
||||||
|
|
||||||
|
let transfer_tx = wallet_core.poll_native_token_transfer(tx_hash).await?;
|
||||||
|
|
||||||
|
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
||||||
|
let to_ebc = tx.message.encrypted_private_post_states[ciph_id].clone();
|
||||||
|
let to_comm = tx.message.new_commitments[ciph_id].clone();
|
||||||
|
let shared_secret =
|
||||||
|
account_key_chain.calculate_shared_secret_receiver(to_ebc.epk);
|
||||||
|
|
||||||
|
let res_acc_to = nssa_core::EncryptionScheme::decrypt(
|
||||||
|
&to_ebc.ciphertext,
|
||||||
|
&shared_secret,
|
||||||
|
&to_comm,
|
||||||
|
ciph_id as u32,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
println!("RES acc to {res_acc_to:#?}");
|
||||||
|
|
||||||
|
println!("Transaction data is {:?}", tx.message);
|
||||||
|
|
||||||
|
wallet_core
|
||||||
|
.storage
|
||||||
|
.insert_private_account_data(acc_addr, res_acc_to);
|
||||||
|
}
|
||||||
|
|
||||||
|
let path = wallet_core.store_persistent_accounts().await?;
|
||||||
|
|
||||||
|
println!("Stored persistent accounts at {path:#?}");
|
||||||
|
|
||||||
|
Ok(SubcommandReturnValue::Empty)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WalletSubcommand for RegisterSubcommand {
|
||||||
|
async fn handle_subcommand(
|
||||||
|
self,
|
||||||
|
wallet_core: &mut WalletCore,
|
||||||
|
) -> Result<SubcommandReturnValue> {
|
||||||
|
match self {
|
||||||
|
RegisterSubcommand::Public {} => {
|
||||||
|
let addr = wallet_core.create_new_account_public();
|
||||||
|
|
||||||
|
println!("Generated new account with addr {addr}");
|
||||||
|
|
||||||
|
let path = wallet_core.store_persistent_accounts().await?;
|
||||||
|
|
||||||
|
println!("Stored persistent accounts at {path:#?}");
|
||||||
|
|
||||||
|
Ok(SubcommandReturnValue::RegisterAccount { addr })
|
||||||
|
}
|
||||||
|
RegisterSubcommand::Private {} => {
|
||||||
|
let addr = wallet_core.create_new_account_private();
|
||||||
|
|
||||||
|
let (key, _) = wallet_core
|
||||||
|
.storage
|
||||||
|
.user_data
|
||||||
|
.get_private_account(&addr)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
println!("Generated new account with addr {addr}");
|
||||||
|
println!("With npk {}", hex::encode(&key.nullifer_public_key));
|
||||||
|
println!(
|
||||||
|
"With ipk {}",
|
||||||
|
hex::encode(key.incoming_viewing_public_key.to_bytes())
|
||||||
|
);
|
||||||
|
|
||||||
|
let path = wallet_core.store_persistent_accounts().await?;
|
||||||
|
|
||||||
|
println!("Stored persistent accounts at {path:#?}");
|
||||||
|
|
||||||
|
Ok(SubcommandReturnValue::RegisterAccount { addr })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WalletSubcommand for AccountSubcommand {
|
||||||
|
async fn handle_subcommand(
|
||||||
|
self,
|
||||||
|
wallet_core: &mut WalletCore,
|
||||||
|
) -> Result<SubcommandReturnValue> {
|
||||||
|
match self {
|
||||||
|
AccountSubcommand::Get(get_subcommand) => {
|
||||||
|
get_subcommand.handle_subcommand(wallet_core).await
|
||||||
|
}
|
||||||
|
AccountSubcommand::Fetch(fetch_subcommand) => {
|
||||||
|
fetch_subcommand.handle_subcommand(wallet_core).await
|
||||||
|
}
|
||||||
|
AccountSubcommand::Register(register_subcommand) => {
|
||||||
|
register_subcommand.handle_subcommand(wallet_core).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,236 +1,20 @@
|
|||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::Subcommand;
|
use clap::Subcommand;
|
||||||
use common::transaction::NSSATransaction;
|
|
||||||
use nssa::Address;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{SubcommandReturnValue, WalletCore, cli::WalletSubcommand};
|
||||||
SubcommandReturnValue, WalletCore, cli::WalletSubcommand, helperfunctions::HumanReadableAccount,
|
|
||||||
};
|
|
||||||
|
|
||||||
///Represents generic chain CLI subcommand
|
///Represents generic chain CLI subcommand
|
||||||
#[derive(Subcommand, Debug, Clone)]
|
#[derive(Subcommand, Debug, Clone)]
|
||||||
pub enum ChainSubcommand {
|
pub enum ChainSubcommand {
|
||||||
///Get
|
GetLatestBlockId {},
|
||||||
#[command(subcommand)]
|
GetBlockAtId {
|
||||||
Get(GetSubcommand),
|
|
||||||
///Fetch
|
|
||||||
#[command(subcommand)]
|
|
||||||
Fetch(FetchSubcommand),
|
|
||||||
///Register
|
|
||||||
#[command(subcommand)]
|
|
||||||
Register(RegisterSubcommand),
|
|
||||||
}
|
|
||||||
|
|
||||||
///Represents generic getter CLI subcommand
|
|
||||||
#[derive(Subcommand, Debug, Clone)]
|
|
||||||
pub enum GetSubcommand {
|
|
||||||
///Get account `addr` balance
|
|
||||||
GetPublicAccountBalance {
|
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
addr: String,
|
id: u64,
|
||||||
},
|
},
|
||||||
///Get account `addr` nonce
|
GetTransactionAtHash {
|
||||||
GetPublicAccountNonce {
|
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
addr: String,
|
hash: String,
|
||||||
},
|
},
|
||||||
///Get account at address `addr`
|
|
||||||
GetPublicAccount {
|
|
||||||
#[arg(short, long)]
|
|
||||||
addr: String,
|
|
||||||
},
|
|
||||||
///Get private account with `addr` from storage
|
|
||||||
GetPrivateAccount {
|
|
||||||
#[arg(short, long)]
|
|
||||||
addr: String,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
///Represents generic getter CLI subcommand
|
|
||||||
#[derive(Subcommand, Debug, Clone)]
|
|
||||||
pub enum FetchSubcommand {
|
|
||||||
///Fetch transaction by `hash`
|
|
||||||
FetchTx {
|
|
||||||
#[arg(short, long)]
|
|
||||||
tx_hash: String,
|
|
||||||
},
|
|
||||||
///Claim account `acc_addr` generated in transaction `tx_hash`, using secret `sh_secret` at ciphertext id `ciph_id`
|
|
||||||
FetchPrivateAccount {
|
|
||||||
///tx_hash - valid 32 byte hex string
|
|
||||||
#[arg(long)]
|
|
||||||
tx_hash: String,
|
|
||||||
///acc_addr - valid 32 byte hex string
|
|
||||||
#[arg(long)]
|
|
||||||
acc_addr: String,
|
|
||||||
///output_id - id of the output in the transaction
|
|
||||||
#[arg(long)]
|
|
||||||
output_id: usize,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
///Represents generic register CLI subcommand
|
|
||||||
#[derive(Subcommand, Debug, Clone)]
|
|
||||||
pub enum RegisterSubcommand {
|
|
||||||
///Register new public account
|
|
||||||
RegisterAccountPublic {},
|
|
||||||
///Register new private account
|
|
||||||
RegisterAccountPrivate {},
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WalletSubcommand for GetSubcommand {
|
|
||||||
async fn handle_subcommand(
|
|
||||||
self,
|
|
||||||
wallet_core: &mut WalletCore,
|
|
||||||
) -> Result<SubcommandReturnValue> {
|
|
||||||
match self {
|
|
||||||
GetSubcommand::GetPublicAccountBalance { addr } => {
|
|
||||||
let addr = Address::from_str(&addr)?;
|
|
||||||
|
|
||||||
let balance = wallet_core.get_account_balance(addr).await?;
|
|
||||||
println!("Accounts {addr} balance is {balance}");
|
|
||||||
|
|
||||||
Ok(SubcommandReturnValue::Empty)
|
|
||||||
}
|
|
||||||
GetSubcommand::GetPublicAccountNonce { addr } => {
|
|
||||||
let addr = Address::from_str(&addr)?;
|
|
||||||
|
|
||||||
let nonce = wallet_core.get_accounts_nonces(vec![addr]).await?[0];
|
|
||||||
println!("Accounts {addr} nonce is {nonce}");
|
|
||||||
|
|
||||||
Ok(SubcommandReturnValue::Empty)
|
|
||||||
}
|
|
||||||
GetSubcommand::GetPublicAccount { addr } => {
|
|
||||||
let addr: Address = addr.parse()?;
|
|
||||||
let account = wallet_core.get_account_public(addr).await?;
|
|
||||||
let account_hr: HumanReadableAccount = account.clone().into();
|
|
||||||
println!("{}", serde_json::to_string(&account_hr).unwrap());
|
|
||||||
|
|
||||||
Ok(SubcommandReturnValue::Account(account))
|
|
||||||
}
|
|
||||||
GetSubcommand::GetPrivateAccount { addr } => {
|
|
||||||
let addr: Address = addr.parse()?;
|
|
||||||
if let Some(account) = wallet_core.get_account_private(&addr) {
|
|
||||||
println!("{}", serde_json::to_string(&account).unwrap());
|
|
||||||
} else {
|
|
||||||
println!("Private account not found.");
|
|
||||||
}
|
|
||||||
Ok(SubcommandReturnValue::Empty)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WalletSubcommand for FetchSubcommand {
|
|
||||||
async fn handle_subcommand(
|
|
||||||
self,
|
|
||||||
wallet_core: &mut WalletCore,
|
|
||||||
) -> Result<SubcommandReturnValue> {
|
|
||||||
match self {
|
|
||||||
FetchSubcommand::FetchTx { tx_hash } => {
|
|
||||||
let tx_obj = wallet_core
|
|
||||||
.sequencer_client
|
|
||||||
.get_transaction_by_hash(tx_hash)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
println!("Transaction object {tx_obj:#?}");
|
|
||||||
|
|
||||||
Ok(SubcommandReturnValue::Empty)
|
|
||||||
}
|
|
||||||
FetchSubcommand::FetchPrivateAccount {
|
|
||||||
tx_hash,
|
|
||||||
acc_addr,
|
|
||||||
output_id: ciph_id,
|
|
||||||
} => {
|
|
||||||
let acc_addr: Address = acc_addr.parse().unwrap();
|
|
||||||
|
|
||||||
let account_key_chain = wallet_core
|
|
||||||
.storage
|
|
||||||
.user_data
|
|
||||||
.user_private_accounts
|
|
||||||
.get(&acc_addr);
|
|
||||||
|
|
||||||
let Some((account_key_chain, _)) = account_key_chain else {
|
|
||||||
anyhow::bail!("Account not found");
|
|
||||||
};
|
|
||||||
|
|
||||||
let transfer_tx = wallet_core.poll_native_token_transfer(tx_hash).await?;
|
|
||||||
|
|
||||||
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
|
||||||
let to_ebc = tx.message.encrypted_private_post_states[ciph_id].clone();
|
|
||||||
let to_comm = tx.message.new_commitments[ciph_id].clone();
|
|
||||||
let shared_secret =
|
|
||||||
account_key_chain.calculate_shared_secret_receiver(to_ebc.epk);
|
|
||||||
|
|
||||||
let res_acc_to = nssa_core::EncryptionScheme::decrypt(
|
|
||||||
&to_ebc.ciphertext,
|
|
||||||
&shared_secret,
|
|
||||||
&to_comm,
|
|
||||||
ciph_id as u32,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
println!("RES acc to {res_acc_to:#?}");
|
|
||||||
|
|
||||||
println!("Transaction data is {:?}", tx.message);
|
|
||||||
|
|
||||||
wallet_core
|
|
||||||
.storage
|
|
||||||
.insert_private_account_data(acc_addr, res_acc_to);
|
|
||||||
}
|
|
||||||
|
|
||||||
let path = wallet_core.store_persistent_accounts().await?;
|
|
||||||
|
|
||||||
println!("Stored persistent accounts at {path:#?}");
|
|
||||||
|
|
||||||
Ok(SubcommandReturnValue::Empty)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WalletSubcommand for RegisterSubcommand {
|
|
||||||
async fn handle_subcommand(
|
|
||||||
self,
|
|
||||||
wallet_core: &mut WalletCore,
|
|
||||||
) -> Result<SubcommandReturnValue> {
|
|
||||||
match self {
|
|
||||||
RegisterSubcommand::RegisterAccountPublic {} => {
|
|
||||||
let addr = wallet_core.create_new_account_public();
|
|
||||||
|
|
||||||
println!("Generated new account with addr {addr}");
|
|
||||||
|
|
||||||
let path = wallet_core.store_persistent_accounts().await?;
|
|
||||||
|
|
||||||
println!("Stored persistent accounts at {path:#?}");
|
|
||||||
|
|
||||||
Ok(SubcommandReturnValue::RegisterAccount { addr })
|
|
||||||
}
|
|
||||||
RegisterSubcommand::RegisterAccountPrivate {} => {
|
|
||||||
let addr = wallet_core.create_new_account_private();
|
|
||||||
|
|
||||||
let (key, _) = wallet_core
|
|
||||||
.storage
|
|
||||||
.user_data
|
|
||||||
.get_private_account(&addr)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
println!("Generated new account with addr {addr}");
|
|
||||||
println!("With npk {}", hex::encode(&key.nullifer_public_key));
|
|
||||||
println!(
|
|
||||||
"With ipk {}",
|
|
||||||
hex::encode(key.incoming_viewing_public_key.to_bytes())
|
|
||||||
);
|
|
||||||
|
|
||||||
let path = wallet_core.store_persistent_accounts().await?;
|
|
||||||
|
|
||||||
println!("Stored persistent accounts at {path:#?}");
|
|
||||||
|
|
||||||
Ok(SubcommandReturnValue::RegisterAccount { addr })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WalletSubcommand for ChainSubcommand {
|
impl WalletSubcommand for ChainSubcommand {
|
||||||
@ -239,15 +23,25 @@ impl WalletSubcommand for ChainSubcommand {
|
|||||||
wallet_core: &mut WalletCore,
|
wallet_core: &mut WalletCore,
|
||||||
) -> Result<SubcommandReturnValue> {
|
) -> Result<SubcommandReturnValue> {
|
||||||
match self {
|
match self {
|
||||||
ChainSubcommand::Get(get_subcommand) => {
|
ChainSubcommand::GetLatestBlockId {} => {
|
||||||
get_subcommand.handle_subcommand(wallet_core).await
|
let latest_block_res = wallet_core.sequencer_client.get_last_block().await?;
|
||||||
|
|
||||||
|
println!("Last block id is {}", latest_block_res.last_block);
|
||||||
}
|
}
|
||||||
ChainSubcommand::Fetch(fetch_subcommand) => {
|
ChainSubcommand::GetBlockAtId { id } => {
|
||||||
fetch_subcommand.handle_subcommand(wallet_core).await
|
let block_res = wallet_core.sequencer_client.get_block(id).await?;
|
||||||
|
|
||||||
|
println!("Last block id is {:#?}", block_res.block);
|
||||||
}
|
}
|
||||||
ChainSubcommand::Register(register_subcommand) => {
|
ChainSubcommand::GetTransactionAtHash { hash } => {
|
||||||
register_subcommand.handle_subcommand(wallet_core).await
|
let tx_res = wallet_core
|
||||||
|
.sequencer_client
|
||||||
|
.get_transaction_by_hash(hash)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
println!("Last block id is {:#?}", tx_res.transaction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(SubcommandReturnValue::Empty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ use anyhow::Result;
|
|||||||
|
|
||||||
use crate::{SubcommandReturnValue, WalletCore};
|
use crate::{SubcommandReturnValue, WalletCore};
|
||||||
|
|
||||||
|
pub mod account;
|
||||||
pub mod chain;
|
pub mod chain;
|
||||||
pub mod native_token_transfer_program;
|
pub mod native_token_transfer_program;
|
||||||
pub mod pinata_program;
|
pub mod pinata_program;
|
||||||
|
|||||||
@ -11,7 +11,7 @@ pub enum NativeTokenTransferProgramSubcommand {
|
|||||||
///Send native token transfer from `from` to `to` for `amount`
|
///Send native token transfer from `from` to `to` for `amount`
|
||||||
///
|
///
|
||||||
/// Public operation
|
/// Public operation
|
||||||
SendNativeTokenTransferPublic {
|
Public {
|
||||||
///from - valid 32 byte hex string
|
///from - valid 32 byte hex string
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
from: String,
|
from: String,
|
||||||
@ -28,7 +28,7 @@ pub enum NativeTokenTransferProgramSubcommand {
|
|||||||
///Send native token transfer from `from` to `to` for `amount`
|
///Send native token transfer from `from` to `to` for `amount`
|
||||||
///
|
///
|
||||||
/// Deshielded operation
|
/// Deshielded operation
|
||||||
SendNativeTokenTransferDeshielded {
|
Deshielded {
|
||||||
///from - valid 32 byte hex string
|
///from - valid 32 byte hex string
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
from: String,
|
from: String,
|
||||||
@ -50,7 +50,7 @@ pub enum NativeTokenTransferProgramSubcommandShielded {
|
|||||||
///Send native token transfer from `from` to `to` for `amount`
|
///Send native token transfer from `from` to `to` for `amount`
|
||||||
///
|
///
|
||||||
/// Shielded operation
|
/// Shielded operation
|
||||||
SendNativeTokenTransferShielded {
|
ShieldedOwned {
|
||||||
///from - valid 32 byte hex string
|
///from - valid 32 byte hex string
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
from: String,
|
from: String,
|
||||||
@ -64,7 +64,7 @@ pub enum NativeTokenTransferProgramSubcommandShielded {
|
|||||||
///Send native token transfer from `from` to `to` for `amount`
|
///Send native token transfer from `from` to `to` for `amount`
|
||||||
///
|
///
|
||||||
/// Shielded operation
|
/// Shielded operation
|
||||||
SendNativeTokenTransferShieldedForeignAccount {
|
ShieldedForeign {
|
||||||
///from - valid 32 byte hex string
|
///from - valid 32 byte hex string
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
from: String,
|
from: String,
|
||||||
@ -86,7 +86,7 @@ pub enum NativeTokenTransferProgramSubcommandPrivate {
|
|||||||
///Send native token transfer from `from` to `to` for `amount`
|
///Send native token transfer from `from` to `to` for `amount`
|
||||||
///
|
///
|
||||||
/// Private operation
|
/// Private operation
|
||||||
SendNativeTokenTransferPrivateOwnedAccount {
|
PrivateOwned {
|
||||||
///from - valid 32 byte hex string
|
///from - valid 32 byte hex string
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
from: String,
|
from: String,
|
||||||
@ -100,7 +100,7 @@ pub enum NativeTokenTransferProgramSubcommandPrivate {
|
|||||||
///Send native token transfer from `from` to `to` for `amount`
|
///Send native token transfer from `from` to `to` for `amount`
|
||||||
///
|
///
|
||||||
/// Private operation
|
/// Private operation
|
||||||
SendNativeTokenTransferPrivateForeignAccount {
|
PrivateForeign {
|
||||||
///from - valid 32 byte hex string
|
///from - valid 32 byte hex string
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
from: String,
|
from: String,
|
||||||
@ -122,84 +122,92 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommandPrivate {
|
|||||||
wallet_core: &mut WalletCore,
|
wallet_core: &mut WalletCore,
|
||||||
) -> Result<SubcommandReturnValue> {
|
) -> Result<SubcommandReturnValue> {
|
||||||
match self {
|
match self {
|
||||||
NativeTokenTransferProgramSubcommandPrivate::SendNativeTokenTransferPrivateOwnedAccount { from, to, amount } => {
|
NativeTokenTransferProgramSubcommandPrivate::PrivateOwned { from, to, amount } => {
|
||||||
let from: Address = from.parse().unwrap();
|
let from: Address = from.parse().unwrap();
|
||||||
let to: Address = to.parse().unwrap();
|
let to: Address = to.parse().unwrap();
|
||||||
|
|
||||||
let to_initialization = wallet_core.check_private_account_initialized(&to).await?;
|
let to_initialization = wallet_core.check_private_account_initialized(&to).await?;
|
||||||
|
|
||||||
let (res, [secret_from, secret_to]) = if let Some(to_proof) = to_initialization {
|
let (res, [secret_from, secret_to]) = if let Some(to_proof) = to_initialization {
|
||||||
wallet_core
|
wallet_core
|
||||||
.send_private_native_token_transfer_owned_account_already_initialized(from, to, amount, to_proof)
|
.send_private_native_token_transfer_owned_account_already_initialized(
|
||||||
.await?
|
from, to, amount, to_proof,
|
||||||
} else {
|
)
|
||||||
wallet_core
|
.await?
|
||||||
.send_private_native_token_transfer_owned_account_not_initialized(from, to, amount)
|
} else {
|
||||||
.await?
|
wallet_core
|
||||||
};
|
.send_private_native_token_transfer_owned_account_not_initialized(
|
||||||
|
from, to, amount,
|
||||||
|
)
|
||||||
|
.await?
|
||||||
|
};
|
||||||
|
|
||||||
println!("Results of tx send is {res:#?}");
|
println!("Results of tx send is {res:#?}");
|
||||||
|
|
||||||
let tx_hash = res.tx_hash;
|
let tx_hash = res.tx_hash;
|
||||||
let transfer_tx = wallet_core
|
let transfer_tx = wallet_core
|
||||||
.poll_native_token_transfer(tx_hash.clone())
|
.poll_native_token_transfer(tx_hash.clone())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
||||||
let acc_decode_data = vec![(secret_from, from), (secret_to, to)];
|
let acc_decode_data = vec![(secret_from, from), (secret_to, to)];
|
||||||
|
|
||||||
wallet_core
|
wallet_core.decode_insert_privacy_preserving_transaction_results(
|
||||||
.decode_insert_privacy_preserving_transaction_results(tx, &acc_decode_data)?;
|
tx,
|
||||||
|
&acc_decode_data,
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let path = wallet_core.store_persistent_accounts().await?;
|
||||||
|
|
||||||
|
println!("Stored persistent accounts at {path:#?}");
|
||||||
|
|
||||||
|
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
|
||||||
}
|
}
|
||||||
|
NativeTokenTransferProgramSubcommandPrivate::PrivateForeign {
|
||||||
|
from,
|
||||||
|
to_npk,
|
||||||
|
to_ipk,
|
||||||
|
amount,
|
||||||
|
} => {
|
||||||
|
let from: Address = from.parse().unwrap();
|
||||||
|
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 path = wallet_core.store_persistent_accounts().await?;
|
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());
|
||||||
|
|
||||||
println!("Stored persistent accounts at {path:#?}");
|
let (res, [secret_from, _]) = wallet_core
|
||||||
|
.send_private_native_token_transfer_outer_account(from, to_npk, to_ipk, amount)
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
|
println!("Results of tx send is {res:#?}");
|
||||||
}
|
|
||||||
NativeTokenTransferProgramSubcommandPrivate::SendNativeTokenTransferPrivateForeignAccount {
|
|
||||||
from,
|
|
||||||
to_npk,
|
|
||||||
to_ipk,
|
|
||||||
amount,
|
|
||||||
} => {
|
|
||||||
let from: Address = from.parse().unwrap();
|
|
||||||
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)?;
|
let tx_hash = res.tx_hash;
|
||||||
let mut to_ipk = [0u8; 33];
|
let transfer_tx = wallet_core
|
||||||
to_ipk.copy_from_slice(&to_ipk_res);
|
.poll_native_token_transfer(tx_hash.clone())
|
||||||
let to_ipk =
|
.await?;
|
||||||
nssa_core::encryption::shared_key_derivation::Secp256k1Point(to_ipk.to_vec());
|
|
||||||
|
|
||||||
let (res, [secret_from, _]) = wallet_core
|
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
||||||
.send_private_native_token_transfer_outer_account(from, to_npk, to_ipk, amount)
|
let acc_decode_data = vec![(secret_from, from)];
|
||||||
.await?;
|
|
||||||
|
|
||||||
println!("Results of tx send is {res:#?}");
|
wallet_core.decode_insert_privacy_preserving_transaction_results(
|
||||||
|
tx,
|
||||||
|
&acc_decode_data,
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
|
||||||
let tx_hash = res.tx_hash;
|
let path = wallet_core.store_persistent_accounts().await?;
|
||||||
let transfer_tx = wallet_core
|
|
||||||
.poll_native_token_transfer(tx_hash.clone())
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
println!("Stored persistent accounts at {path:#?}");
|
||||||
let acc_decode_data = vec![(secret_from, from)];
|
|
||||||
|
|
||||||
wallet_core
|
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
|
||||||
.decode_insert_privacy_preserving_transaction_results(tx, &acc_decode_data)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let path = wallet_core.store_persistent_accounts().await?;
|
|
||||||
|
|
||||||
println!("Stored persistent accounts at {path:#?}");
|
|
||||||
|
|
||||||
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -210,75 +218,79 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommandShielded {
|
|||||||
wallet_core: &mut WalletCore,
|
wallet_core: &mut WalletCore,
|
||||||
) -> Result<SubcommandReturnValue> {
|
) -> Result<SubcommandReturnValue> {
|
||||||
match self {
|
match self {
|
||||||
NativeTokenTransferProgramSubcommandShielded::SendNativeTokenTransferShielded { from, to, amount } => {
|
NativeTokenTransferProgramSubcommandShielded::ShieldedOwned { from, to, amount } => {
|
||||||
let from: Address = from.parse().unwrap();
|
let from: Address = from.parse().unwrap();
|
||||||
let to: Address = to.parse().unwrap();
|
let to: Address = to.parse().unwrap();
|
||||||
|
|
||||||
let to_initialization = wallet_core.check_private_account_initialized(&to).await?;
|
let to_initialization = wallet_core.check_private_account_initialized(&to).await?;
|
||||||
|
|
||||||
let (res, secret) = if let Some(to_proof) = to_initialization {
|
let (res, secret) = if let Some(to_proof) = to_initialization {
|
||||||
wallet_core
|
wallet_core
|
||||||
.send_shielded_native_token_transfer_already_initialized(from, to, amount, to_proof)
|
.send_shielded_native_token_transfer_already_initialized(
|
||||||
.await?
|
from, to, amount, to_proof,
|
||||||
} else {
|
)
|
||||||
wallet_core
|
.await?
|
||||||
.send_shielded_native_token_transfer_not_initialized(from, to, amount)
|
} else {
|
||||||
.await?
|
wallet_core
|
||||||
};
|
.send_shielded_native_token_transfer_not_initialized(from, to, amount)
|
||||||
|
.await?
|
||||||
|
};
|
||||||
|
|
||||||
println!("Results of tx send is {res:#?}");
|
println!("Results of tx send is {res:#?}");
|
||||||
|
|
||||||
let tx_hash = res.tx_hash;
|
let tx_hash = res.tx_hash;
|
||||||
let transfer_tx = wallet_core
|
let transfer_tx = wallet_core
|
||||||
.poll_native_token_transfer(tx_hash.clone())
|
.poll_native_token_transfer(tx_hash.clone())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
||||||
let acc_decode_data = vec![(secret, to)];
|
let acc_decode_data = vec![(secret, to)];
|
||||||
|
|
||||||
wallet_core
|
wallet_core.decode_insert_privacy_preserving_transaction_results(
|
||||||
.decode_insert_privacy_preserving_transaction_results(tx, &acc_decode_data)?;
|
tx,
|
||||||
|
&acc_decode_data,
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let path = wallet_core.store_persistent_accounts().await?;
|
||||||
|
|
||||||
|
println!("Stored persistent accounts at {path:#?}");
|
||||||
|
|
||||||
|
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
|
||||||
}
|
}
|
||||||
|
NativeTokenTransferProgramSubcommandShielded::ShieldedForeign {
|
||||||
|
from,
|
||||||
|
to_npk,
|
||||||
|
to_ipk,
|
||||||
|
amount,
|
||||||
|
} => {
|
||||||
|
let from: Address = from.parse().unwrap();
|
||||||
|
|
||||||
let path = wallet_core.store_persistent_accounts().await?;
|
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);
|
||||||
|
|
||||||
println!("Stored persistent accounts at {path:#?}");
|
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());
|
||||||
|
|
||||||
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
|
let (res, _) = wallet_core
|
||||||
}
|
.send_shielded_native_token_transfer_outer_account(from, to_npk, to_ipk, amount)
|
||||||
NativeTokenTransferProgramSubcommandShielded::SendNativeTokenTransferShieldedForeignAccount {
|
.await?;
|
||||||
from,
|
|
||||||
to_npk,
|
|
||||||
to_ipk,
|
|
||||||
amount,
|
|
||||||
} => {
|
|
||||||
let from: Address = from.parse().unwrap();
|
|
||||||
|
|
||||||
let to_npk_res = hex::decode(to_npk)?;
|
println!("Results of tx send is {res:#?}");
|
||||||
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)?;
|
let tx_hash = res.tx_hash;
|
||||||
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());
|
|
||||||
|
|
||||||
let (res, _) = wallet_core
|
let path = wallet_core.store_persistent_accounts().await?;
|
||||||
.send_shielded_native_token_transfer_outer_account(from, to_npk, to_ipk, amount)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
println!("Results of tx send is {res:#?}");
|
println!("Stored persistent accounts at {path:#?}");
|
||||||
|
|
||||||
let tx_hash = res.tx_hash;
|
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
|
||||||
|
}
|
||||||
let path = wallet_core.store_persistent_accounts().await?;
|
|
||||||
|
|
||||||
println!("Stored persistent accounts at {path:#?}");
|
|
||||||
|
|
||||||
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -295,11 +307,7 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommand {
|
|||||||
NativeTokenTransferProgramSubcommand::Shielded(shielded_subcommand) => {
|
NativeTokenTransferProgramSubcommand::Shielded(shielded_subcommand) => {
|
||||||
shielded_subcommand.handle_subcommand(wallet_core).await
|
shielded_subcommand.handle_subcommand(wallet_core).await
|
||||||
}
|
}
|
||||||
NativeTokenTransferProgramSubcommand::SendNativeTokenTransferDeshielded {
|
NativeTokenTransferProgramSubcommand::Deshielded { from, to, amount } => {
|
||||||
from,
|
|
||||||
to,
|
|
||||||
amount,
|
|
||||||
} => {
|
|
||||||
let from: Address = from.parse().unwrap();
|
let from: Address = from.parse().unwrap();
|
||||||
let to: Address = to.parse().unwrap();
|
let to: Address = to.parse().unwrap();
|
||||||
|
|
||||||
@ -329,11 +337,7 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommand {
|
|||||||
|
|
||||||
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
|
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
|
||||||
}
|
}
|
||||||
NativeTokenTransferProgramSubcommand::SendNativeTokenTransferPublic {
|
NativeTokenTransferProgramSubcommand::Public { from, to, amount } => {
|
||||||
from,
|
|
||||||
to,
|
|
||||||
amount,
|
|
||||||
} => {
|
|
||||||
let from: Address = from.parse().unwrap();
|
let from: Address = from.parse().unwrap();
|
||||||
let to: Address = to.parse().unwrap();
|
let to: Address = to.parse().unwrap();
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ pub enum PinataProgramSubcommand {
|
|||||||
pub enum PinataProgramSubcommandPublic {
|
pub enum PinataProgramSubcommandPublic {
|
||||||
// TODO: Testnet only. Refactor to prevent compilation on mainnet.
|
// TODO: Testnet only. Refactor to prevent compilation on mainnet.
|
||||||
// Claim piñata prize
|
// Claim piñata prize
|
||||||
ClaimPinata {
|
Claim {
|
||||||
///pinata_addr - valid 32 byte hex string
|
///pinata_addr - valid 32 byte hex string
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pinata_addr: String,
|
pinata_addr: String,
|
||||||
@ -39,7 +39,7 @@ pub enum PinataProgramSubcommandPublic {
|
|||||||
pub enum PinataProgramSubcommandPrivate {
|
pub enum PinataProgramSubcommandPrivate {
|
||||||
// TODO: Testnet only. Refactor to prevent compilation on mainnet.
|
// TODO: Testnet only. Refactor to prevent compilation on mainnet.
|
||||||
// Claim piñata prize
|
// Claim piñata prize
|
||||||
ClaimPinataPrivateReceiverOwned {
|
ClaimPrivateOwned {
|
||||||
///pinata_addr - valid 32 byte hex string
|
///pinata_addr - valid 32 byte hex string
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pinata_addr: String,
|
pinata_addr: String,
|
||||||
@ -58,7 +58,7 @@ impl WalletSubcommand for PinataProgramSubcommandPublic {
|
|||||||
wallet_core: &mut WalletCore,
|
wallet_core: &mut WalletCore,
|
||||||
) -> Result<SubcommandReturnValue> {
|
) -> Result<SubcommandReturnValue> {
|
||||||
match self {
|
match self {
|
||||||
PinataProgramSubcommandPublic::ClaimPinata {
|
PinataProgramSubcommandPublic::Claim {
|
||||||
pinata_addr,
|
pinata_addr,
|
||||||
winner_addr,
|
winner_addr,
|
||||||
solution,
|
solution,
|
||||||
@ -84,7 +84,7 @@ impl WalletSubcommand for PinataProgramSubcommandPrivate {
|
|||||||
wallet_core: &mut WalletCore,
|
wallet_core: &mut WalletCore,
|
||||||
) -> Result<SubcommandReturnValue> {
|
) -> Result<SubcommandReturnValue> {
|
||||||
match self {
|
match self {
|
||||||
PinataProgramSubcommandPrivate::ClaimPinataPrivateReceiverOwned {
|
PinataProgramSubcommandPrivate::ClaimPrivateOwned {
|
||||||
pinata_addr,
|
pinata_addr,
|
||||||
winner_addr,
|
winner_addr,
|
||||||
solution,
|
solution,
|
||||||
|
|||||||
@ -18,7 +18,7 @@ use nssa_core::{Commitment, MembershipProof};
|
|||||||
use tokio::io::AsyncWriteExt;
|
use tokio::io::AsyncWriteExt;
|
||||||
|
|
||||||
use crate::cli::{
|
use crate::cli::{
|
||||||
WalletSubcommand, chain::ChainSubcommand,
|
WalletSubcommand, account::AccountSubcommand, chain::ChainSubcommand,
|
||||||
native_token_transfer_program::NativeTokenTransferProgramSubcommand,
|
native_token_transfer_program::NativeTokenTransferProgramSubcommand,
|
||||||
pinata_program::PinataProgramSubcommand,
|
pinata_program::PinataProgramSubcommand,
|
||||||
};
|
};
|
||||||
@ -193,6 +193,9 @@ pub enum Command {
|
|||||||
///Chain command
|
///Chain command
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
Chain(ChainSubcommand),
|
Chain(ChainSubcommand),
|
||||||
|
///Chain command
|
||||||
|
#[command(subcommand)]
|
||||||
|
Account(AccountSubcommand),
|
||||||
///Pinata command
|
///Pinata command
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
PinataProgram(PinataProgramSubcommand),
|
PinataProgram(PinataProgramSubcommand),
|
||||||
@ -234,6 +237,11 @@ pub async fn execute_subcommand(command: Command) -> Result<SubcommandReturnValu
|
|||||||
Command::Chain(chain_subcommand) => {
|
Command::Chain(chain_subcommand) => {
|
||||||
chain_subcommand.handle_subcommand(&mut wallet_core).await?
|
chain_subcommand.handle_subcommand(&mut wallet_core).await?
|
||||||
}
|
}
|
||||||
|
Command::Account(account_subcommand) => {
|
||||||
|
account_subcommand
|
||||||
|
.handle_subcommand(&mut wallet_core)
|
||||||
|
.await?
|
||||||
|
}
|
||||||
Command::PinataProgram(pinata_subcommand) => {
|
Command::PinataProgram(pinata_subcommand) => {
|
||||||
pinata_subcommand
|
pinata_subcommand
|
||||||
.handle_subcommand(&mut wallet_core)
|
.handle_subcommand(&mut wallet_core)
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::Parser;
|
use clap::{CommandFactory, Parser};
|
||||||
use tokio::runtime::Builder;
|
use tokio::runtime::Builder;
|
||||||
use wallet::{Args, execute_continious_run, execute_subcommand};
|
use wallet::{Args, execute_continious_run, execute_subcommand};
|
||||||
|
|
||||||
@ -22,7 +22,8 @@ fn main() -> Result<()> {
|
|||||||
} else if args.continious_run {
|
} else if args.continious_run {
|
||||||
execute_continious_run().await.unwrap();
|
execute_continious_run().await.unwrap();
|
||||||
} else {
|
} else {
|
||||||
println!("NOTHING TO DO");
|
let help = Args::command().render_long_help();
|
||||||
|
println!("{help}");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user