fix; first refactor

This commit is contained in:
Oleksandr Pravdyvyi 2025-10-23 17:33:25 +03:00
parent d7089eac96
commit 4e36ae4679
No known key found for this signature in database
GPG Key ID: 9F8955C63C443871
16 changed files with 202 additions and 135 deletions

View File

@ -46,6 +46,7 @@ bip39 = "2.2.0"
hmac-sha512 = "1.1.7" hmac-sha512 = "1.1.7"
chrono = "0.4.41" chrono = "0.4.41"
borsh = "1.5.7" borsh = "1.5.7"
base58 = "0.2.0"
rocksdb = { version = "0.21.0", default-features = false, features = [ rocksdb = { version = "0.21.0", default-features = false, features = [
"snappy", "snappy",

View File

@ -15,7 +15,8 @@ rs_merkle.workspace = true
sha2.workspace = true sha2.workspace = true
log.workspace = true log.workspace = true
elliptic-curve.workspace = true elliptic-curve.workspace = true
hex.workspace = true base58.workspace = true
hex = "0.4.3"
nssa-core = { path = "../nssa/core", features = ["host"] } nssa-core = { path = "../nssa/core", features = ["host"] }
borsh.workspace = true borsh.workspace = true

View File

@ -1,3 +1,4 @@
use base58::ToBase58;
use borsh::{BorshDeserialize, BorshSerialize}; use borsh::{BorshDeserialize, BorshSerialize};
use k256::ecdsa::{Signature, SigningKey, VerifyingKey}; use k256::ecdsa::{Signature, SigningKey, VerifyingKey};
use log::info; use log::info;
@ -125,7 +126,7 @@ impl From<OwnedUTXO> for OwnedUTXOForPublication {
fn from(value: OwnedUTXO) -> Self { fn from(value: OwnedUTXO) -> Self {
Self { Self {
hash: hex::encode(value.hash), hash: hex::encode(value.hash),
owner: hex::encode(value.owner), owner: value.owner.to_base58(),
amount: value.amount, amount: value.amount,
} }
} }
@ -150,7 +151,7 @@ impl ActionData {
ActionData::MintMoneyPublicTx(action) => { ActionData::MintMoneyPublicTx(action) => {
format!( format!(
"Account {:?} minted {:?} balance", "Account {:?} minted {:?} balance",
hex::encode(action.acc), action.acc.to_base58(),
action.amount action.amount
) )
} }
@ -160,14 +161,14 @@ impl ActionData {
action action
.receiver_data .receiver_data
.into_iter() .into_iter()
.map(|(amount, rec)| (amount, hex::encode(rec))) .map(|(amount, rec)| (amount, rec.to_base58()))
.collect::<Vec<_>>() .collect::<Vec<_>>()
) )
} }
ActionData::SendMoneyShieldedTx(action) => { ActionData::SendMoneyShieldedTx(action) => {
format!( format!(
"Shielded send from {:?} for {:?} balance", "Shielded send from {:?} for {:?} balance",
hex::encode(action.acc_sender), action.acc_sender.to_base58(),
action.amount action.amount
) )
} }

View File

@ -7,7 +7,7 @@ use nssa_core::{NullifierPublicKey, encryption::shared_key_derivation::Secp256k1
use wallet::{ use wallet::{
Command, SubcommandReturnValue, WalletCore, Command, SubcommandReturnValue, WalletCore,
cli::{ cli::{
account::{AccountSubcommand, FetchSubcommand, RegisterSubcommand}, account::{AccountSubcommand, FetchSubcommand, NewSubcommand},
native_token_transfer_program::{ native_token_transfer_program::{
NativeTokenTransferProgramSubcommand, NativeTokenTransferProgramSubcommandPrivate, NativeTokenTransferProgramSubcommand, NativeTokenTransferProgramSubcommandPrivate,
NativeTokenTransferProgramSubcommandShielded, NativeTokenTransferProgramSubcommandShielded,
@ -40,7 +40,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
#[test_suite_fn] #[test_suite_fn]
pub async fn test_success() { pub async fn test_success() {
info!("test_success"); info!("test_success");
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Public { let command = Command::AuthTransfer(NativeTokenTransferProgramSubcommand::Public {
from: ACC_SENDER.to_string(), from: ACC_SENDER.to_string(),
to: ACC_RECEIVER.to_string(), to: ACC_RECEIVER.to_string(),
amount: 100, amount: 100,
@ -77,7 +77,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
#[test_suite_fn] #[test_suite_fn]
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::Account(AccountSubcommand::Register(RegisterSubcommand::Public {})); let command = Command::Account(AccountSubcommand::New(NewSubcommand::Public {}));
let wallet_config = fetch_config().await.unwrap(); let wallet_config = fetch_config().await.unwrap();
@ -101,7 +101,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
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(NativeTokenTransferProgramSubcommand::Public { let command = Command::AuthTransfer(NativeTokenTransferProgramSubcommand::Public {
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,
@ -134,7 +134,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
#[test_suite_fn] #[test_suite_fn]
pub async fn test_failure() { pub async fn test_failure() {
info!("test_failure"); info!("test_failure");
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Public { let command = Command::AuthTransfer(NativeTokenTransferProgramSubcommand::Public {
from: ACC_SENDER.to_string(), from: ACC_SENDER.to_string(),
to: ACC_RECEIVER.to_string(), to: ACC_RECEIVER.to_string(),
amount: 1000000, amount: 1000000,
@ -173,7 +173,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
#[test_suite_fn] #[test_suite_fn]
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(NativeTokenTransferProgramSubcommand::Public { let command = Command::AuthTransfer(NativeTokenTransferProgramSubcommand::Public {
from: ACC_SENDER.to_string(), from: ACC_SENDER.to_string(),
to: ACC_RECEIVER.to_string(), to: ACC_RECEIVER.to_string(),
amount: 100, amount: 100,
@ -206,7 +206,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
info!("First TX Success!"); info!("First TX Success!");
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Public { let command = Command::AuthTransfer(NativeTokenTransferProgramSubcommand::Public {
from: ACC_SENDER.to_string(), from: ACC_SENDER.to_string(),
to: ACC_RECEIVER.to_string(), to: ACC_RECEIVER.to_string(),
amount: 100, amount: 100,
@ -264,20 +264,20 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
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::Account(AccountSubcommand::Register( wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
RegisterSubcommand::Public {}, NewSubcommand::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::Account(AccountSubcommand::Register( wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
RegisterSubcommand::Public {}, NewSubcommand::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::Account(AccountSubcommand::Register( wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
RegisterSubcommand::Public {}, NewSubcommand::Public {},
))) )))
.await .await
.unwrap(); .unwrap();
@ -311,7 +311,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
name: "A NAME".to_string(), name: "A NAME".to_string(),
total_supply: 37, total_supply: 37,
}); });
wallet::execute_subcommand(Command::TokenProgram(subcommand)) wallet::execute_subcommand(Command::Token(subcommand))
.await .await
.unwrap(); .unwrap();
info!("Waiting for next block creation"); info!("Waiting for next block creation");
@ -365,7 +365,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
recipient_addr: recipient_addr.to_string(), recipient_addr: recipient_addr.to_string(),
balance_to_move: 7, balance_to_move: 7,
}); });
wallet::execute_subcommand(Command::TokenProgram(subcommand)) wallet::execute_subcommand(Command::Token(subcommand))
.await .await
.unwrap(); .unwrap();
info!("Waiting for next block creation"); info!("Waiting for next block creation");
@ -416,8 +416,8 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
// 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::Account(AccountSubcommand::Register( } = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
RegisterSubcommand::Public {}, NewSubcommand::Public {},
))) )))
.await .await
.unwrap() .unwrap()
@ -426,8 +426,8 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
}; };
// 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(Command::Account(AccountSubcommand::Register( wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
RegisterSubcommand::Private {}, NewSubcommand::Private {},
))) )))
.await .await
.unwrap() .unwrap()
@ -437,8 +437,8 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
// 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::Account(AccountSubcommand::Register( } = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
RegisterSubcommand::Private {}, NewSubcommand::Private {},
))) )))
.await .await
.unwrap() .unwrap()
@ -456,7 +456,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
}, },
); );
wallet::execute_subcommand(Command::TokenProgram(subcommand)) wallet::execute_subcommand(Command::Token(subcommand))
.await .await
.unwrap(); .unwrap();
@ -501,7 +501,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
}, },
); );
wallet::execute_subcommand(Command::TokenProgram(subcommand)) wallet::execute_subcommand(Command::Token(subcommand))
.await .await
.unwrap(); .unwrap();
@ -532,7 +532,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
}, },
); );
wallet::execute_subcommand(Command::TokenProgram(subcommand)) wallet::execute_subcommand(Command::Token(subcommand))
.await .await
.unwrap(); .unwrap();
@ -564,8 +564,8 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
// 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::Account(AccountSubcommand::Register( } = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
RegisterSubcommand::Public {}, NewSubcommand::Public {},
))) )))
.await .await
.unwrap() .unwrap()
@ -574,8 +574,8 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
}; };
// 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(Command::Account(AccountSubcommand::Register( wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
RegisterSubcommand::Private {}, NewSubcommand::Private {},
))) )))
.await .await
.unwrap() .unwrap()
@ -585,8 +585,8 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
// 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::Account(AccountSubcommand::Register( } = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
RegisterSubcommand::Private {}, NewSubcommand::Private {},
))) )))
.await .await
.unwrap() .unwrap()
@ -604,7 +604,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
}, },
); );
wallet::execute_subcommand(Command::TokenProgram(subcommand)) wallet::execute_subcommand(Command::Token(subcommand))
.await .await
.unwrap(); .unwrap();
@ -657,7 +657,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
); );
let SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash } = let SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash } =
wallet::execute_subcommand(Command::TokenProgram(subcommand)) wallet::execute_subcommand(Command::Token(subcommand))
.await .await
.unwrap() .unwrap()
else { else {
@ -700,8 +700,8 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
// 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::Account(AccountSubcommand::Register( } = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
RegisterSubcommand::Public {}, NewSubcommand::Public {},
))) )))
.await .await
.unwrap() .unwrap()
@ -710,8 +710,8 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
}; };
// Create new account for the token supply holder (public) // Create new account for the token supply holder (public)
let SubcommandReturnValue::RegisterAccount { addr: supply_addr } = let SubcommandReturnValue::RegisterAccount { addr: supply_addr } =
wallet::execute_subcommand(Command::Account(AccountSubcommand::Register( wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
RegisterSubcommand::Public {}, NewSubcommand::Public {},
))) )))
.await .await
.unwrap() .unwrap()
@ -721,8 +721,8 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
// 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::Account(AccountSubcommand::Register( } = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
RegisterSubcommand::Private {}, NewSubcommand::Private {},
))) )))
.await .await
.unwrap() .unwrap()
@ -739,7 +739,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
total_supply: 37, total_supply: 37,
}); });
wallet::execute_subcommand(Command::TokenProgram(subcommand)) wallet::execute_subcommand(Command::Token(subcommand))
.await .await
.unwrap(); .unwrap();
@ -774,7 +774,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
}, },
); );
wallet::execute_subcommand(Command::TokenProgram(subcommand)) wallet::execute_subcommand(Command::Token(subcommand))
.await .await
.unwrap(); .unwrap();
@ -800,7 +800,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
}, },
); );
wallet::execute_subcommand(Command::TokenProgram(subcommand)) wallet::execute_subcommand(Command::Token(subcommand))
.await .await
.unwrap(); .unwrap();
@ -827,8 +827,8 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
// 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::Account(AccountSubcommand::Register( } = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
RegisterSubcommand::Public {}, NewSubcommand::Public {},
))) )))
.await .await
.unwrap() .unwrap()
@ -837,8 +837,8 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
}; };
// 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(Command::Account(AccountSubcommand::Register( wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
RegisterSubcommand::Private {}, NewSubcommand::Private {},
))) )))
.await .await
.unwrap() .unwrap()
@ -848,8 +848,8 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
// 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::Account(AccountSubcommand::Register( } = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
RegisterSubcommand::Public {}, NewSubcommand::Public {},
))) )))
.await .await
.unwrap() .unwrap()
@ -867,7 +867,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
}, },
); );
wallet::execute_subcommand(Command::TokenProgram(subcommand)) wallet::execute_subcommand(Command::Token(subcommand))
.await .await
.unwrap(); .unwrap();
@ -912,7 +912,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
}, },
); );
wallet::execute_subcommand(Command::TokenProgram(subcommand)) wallet::execute_subcommand(Command::Token(subcommand))
.await .await
.unwrap(); .unwrap();
@ -938,7 +938,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
}, },
); );
wallet::execute_subcommand(Command::TokenProgram(subcommand)) wallet::execute_subcommand(Command::Token(subcommand))
.await .await
.unwrap(); .unwrap();
@ -962,7 +962,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
let from: Address = ACC_SENDER_PRIVATE.parse().unwrap(); let from: Address = ACC_SENDER_PRIVATE.parse().unwrap();
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::AuthTransfer(NativeTokenTransferProgramSubcommand::Private(
NativeTokenTransferProgramSubcommandPrivate::PrivateOwned { NativeTokenTransferProgramSubcommandPrivate::PrivateOwned {
from: from.to_string(), from: from.to_string(),
to: to.to_string(), to: to.to_string(),
@ -1000,7 +1000,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
let to_npk_string = hex::encode(to_npk.0); let to_npk_string = hex::encode(to_npk.0);
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::AuthTransfer(NativeTokenTransferProgramSubcommand::Private(
NativeTokenTransferProgramSubcommandPrivate::PrivateForeign { NativeTokenTransferProgramSubcommandPrivate::PrivateForeign {
from: from.to_string(), from: from.to_string(),
to_npk: to_npk_string, to_npk: to_npk_string,
@ -1044,7 +1044,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
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::Account(AccountSubcommand::Register(RegisterSubcommand::Private {})); let command = Command::Account(AccountSubcommand::New(NewSubcommand::Private {}));
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 {
@ -1065,7 +1065,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
.cloned() .cloned()
.unwrap(); .unwrap();
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Private( let command = Command::AuthTransfer(NativeTokenTransferProgramSubcommand::Private(
NativeTokenTransferProgramSubcommandPrivate::PrivateForeign { 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),
@ -1115,7 +1115,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
let from: Address = ACC_SENDER_PRIVATE.parse().unwrap(); let from: Address = ACC_SENDER_PRIVATE.parse().unwrap();
let command = Command::Account(AccountSubcommand::Register(RegisterSubcommand::Private {})); let command = Command::Account(AccountSubcommand::New(NewSubcommand::Private {}));
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 {
@ -1136,7 +1136,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
.cloned() .cloned()
.unwrap(); .unwrap();
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Private( let command = Command::AuthTransfer(NativeTokenTransferProgramSubcommand::Private(
NativeTokenTransferProgramSubcommandPrivate::PrivateForeign { 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),
@ -1184,7 +1184,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
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(NativeTokenTransferProgramSubcommand::Deshielded { let command = Command::AuthTransfer(NativeTokenTransferProgramSubcommand::Deshielded {
from: from.to_string(), from: from.to_string(),
to: to.to_string(), to: to.to_string(),
amount: 100, amount: 100,
@ -1230,7 +1230,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
info!("test_success_shielded_transfer_to_another_owned_account"); info!("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::AuthTransfer(NativeTokenTransferProgramSubcommand::Shielded(
NativeTokenTransferProgramSubcommandShielded::ShieldedOwned { NativeTokenTransferProgramSubcommandShielded::ShieldedOwned {
from: from.to_string(), from: from.to_string(),
to: to.to_string(), to: to.to_string(),
@ -1274,7 +1274,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
let to_ipk = Secp256k1Point::from_scalar(to_npk.0); let to_ipk = Secp256k1Point::from_scalar(to_npk.0);
let from: Address = ACC_SENDER.parse().unwrap(); let from: Address = ACC_SENDER.parse().unwrap();
let command = Command::Transfer(NativeTokenTransferProgramSubcommand::Shielded( let command = Command::AuthTransfer(NativeTokenTransferProgramSubcommand::Shielded(
NativeTokenTransferProgramSubcommandShielded::ShieldedForeign { NativeTokenTransferProgramSubcommandShielded::ShieldedForeign {
from: from.to_string(), from: from.to_string(),
to_npk: to_npk_string, to_npk: to_npk_string,
@ -1318,7 +1318,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
let pinata_addr = "cafe".repeat(16); let pinata_addr = "cafe".repeat(16);
let pinata_prize = 150; let pinata_prize = 150;
let solution = 989106; let solution = 989106;
let command = Command::PinataProgram(PinataProgramSubcommand::Public( let command = Command::Pinata(PinataProgramSubcommand::Public(
PinataProgramSubcommandPublic::Claim { PinataProgramSubcommandPublic::Claim {
pinata_addr: pinata_addr.clone(), pinata_addr: pinata_addr.clone(),
winner_addr: ACC_SENDER.to_string(), winner_addr: ACC_SENDER.to_string(),
@ -1446,7 +1446,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
let pinata_prize = 150; let pinata_prize = 150;
let solution = 989106; let solution = 989106;
let command = Command::PinataProgram(PinataProgramSubcommand::Private( let command = Command::Pinata(PinataProgramSubcommand::Private(
PinataProgramSubcommandPrivate::ClaimPrivateOwned { 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(),
@ -1512,8 +1512,8 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
// 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(Command::Account(AccountSubcommand::Register( wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
RegisterSubcommand::Private {}, NewSubcommand::Private {},
))) )))
.await .await
.unwrap() .unwrap()
@ -1521,7 +1521,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
panic!("invalid subcommand return value"); panic!("invalid subcommand return value");
}; };
let command = Command::PinataProgram(PinataProgramSubcommand::Private( let command = Command::Pinata(PinataProgramSubcommand::Private(
PinataProgramSubcommandPrivate::ClaimPrivateOwned { PinataProgramSubcommandPrivate::ClaimPrivateOwned {
pinata_addr: pinata_addr.clone(), pinata_addr: pinata_addr.clone(),
winner_addr: winner_addr.to_string(), winner_addr: winner_addr.to_string(),

View File

@ -9,7 +9,8 @@ serde.workspace = true
k256.workspace = true k256.workspace = true
sha2.workspace = true sha2.workspace = true
rand.workspace = true rand.workspace = true
hex.workspace = true base58.workspace = true
hex = "0.4.3"
aes-gcm.workspace = true aes-gcm.workspace = true
bip39.workspace = true bip39.workspace = true
hmac-sha512.workspace = true hmac-sha512.workspace = true

View File

@ -55,6 +55,7 @@ impl KeyChain {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use aes_gcm::aead::OsRng; use aes_gcm::aead::OsRng;
use base58::ToBase58;
use k256::AffinePoint; use k256::AffinePoint;
use k256::elliptic_curve::group::GroupEncoding; use k256::elliptic_curve::group::GroupEncoding;
use rand::RngCore; use rand::RngCore;
@ -119,7 +120,7 @@ mod tests {
println!("======Public data======"); println!("======Public data======");
println!(); println!();
println!("Address{:?}", hex::encode(address.value())); println!("Address{:?}", address.value().to_base58());
println!( println!(
"Nulifier public key {:?}", "Nulifier public key {:?}",
hex::encode(nullifer_public_key.to_byte_array()) hex::encode(nullifer_public_key.to_byte_array())

View File

@ -10,8 +10,9 @@ thiserror = { version = "2.0.12", optional = true }
bytemuck = { version = "1.13", optional = true } bytemuck = { version = "1.13", optional = true }
chacha20 = { version = "0.9", default-features = false } chacha20 = { version = "0.9", default-features = false }
k256 = { version = "0.13.3", optional = true } k256 = { version = "0.13.3", optional = true }
hex = { version = "0.4.3", optional = true } base58 = { version = "0.2.0", optional = true }
anyhow = { version = "1.0.98", optional = true }
[features] [features]
default = [] default = []
host = ["thiserror", "bytemuck", "k256", "hex"] host = ["thiserror", "bytemuck", "k256", "base58", "anyhow"]

View File

@ -3,6 +3,9 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "host")] #[cfg(feature = "host")]
use std::{fmt::Display, str::FromStr}; use std::{fmt::Display, str::FromStr};
#[cfg(feature = "host")]
use base58::{FromBase58, ToBase58};
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] #[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
#[cfg_attr( #[cfg_attr(
any(feature = "host", test), any(feature = "host", test),
@ -31,8 +34,8 @@ impl AsRef<[u8]> for Address {
#[cfg(feature = "host")] #[cfg(feature = "host")]
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum AddressError { pub enum AddressError {
#[error("invalid hex")] #[error("invalid base58")]
InvalidHex(#[from] hex::FromHexError), InvalidBase58(#[from] anyhow::Error),
#[error("invalid length: expected 32 bytes, got {0}")] #[error("invalid length: expected 32 bytes, got {0}")]
InvalidLength(usize), InvalidLength(usize),
} }
@ -41,7 +44,9 @@ pub enum AddressError {
impl FromStr for Address { impl FromStr for Address {
type Err = AddressError; type Err = AddressError;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
let bytes = hex::decode(s)?; let bytes = s
.from_base58()
.map_err(|err| anyhow::anyhow!("Invalid base58 err {err:?}"))?;
if bytes.len() != 32 { if bytes.len() != 32 {
return Err(AddressError::InvalidLength(bytes.len())); return Err(AddressError::InvalidLength(bytes.len()));
} }
@ -54,7 +59,7 @@ impl FromStr for Address {
#[cfg(feature = "host")] #[cfg(feature = "host")]
impl Display for Address { impl Display for Address {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", hex::encode(self.value)) write!(f, "{}", self.value.to_base58())
} }
} }
@ -74,7 +79,7 @@ mod tests {
fn parse_invalid_hex() { fn parse_invalid_hex() {
let hex_str = "zz".repeat(32); // invalid hex chars let hex_str = "zz".repeat(32); // invalid hex chars
let result = hex_str.parse::<Address>().unwrap_err(); let result = hex_str.parse::<Address>().unwrap_err();
assert!(matches!(result, AddressError::InvalidHex(_))); assert!(matches!(result, AddressError::InvalidBase58(_)));
} }
#[test] #[test]

View File

@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
hex.workspace = true base58.workspace = true
anyhow.workspace = true anyhow.workspace = true
serde.workspace = true serde.workspace = true
rand.workspace = true rand.workspace = true

View File

@ -204,6 +204,7 @@ impl SequencerCore {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use base58::{FromBase58, ToBase58};
use common::test_utils::sequencer_sign_key_for_testing; use common::test_utils::sequencer_sign_key_for_testing;
use crate::config::AccountInitialData; use crate::config::AccountInitialData;
@ -237,23 +238,23 @@ mod tests {
} }
fn setup_sequencer_config() -> SequencerConfig { fn setup_sequencer_config() -> SequencerConfig {
let acc1_addr = vec![ let acc1_addr: Vec<u8> = vec![
208, 122, 210, 232, 75, 39, 250, 0, 194, 98, 240, 161, 238, 160, 255, 53, 202, 9, 115, 208, 122, 210, 232, 75, 39, 250, 0, 194, 98, 240, 161, 238, 160, 255, 53, 202, 9, 115,
84, 126, 106, 16, 111, 114, 241, 147, 194, 220, 131, 139, 68, 84, 126, 106, 16, 111, 114, 241, 147, 194, 220, 131, 139, 68,
]; ];
let acc2_addr = vec![ let acc2_addr: Vec<u8> = vec![
231, 174, 119, 197, 239, 26, 5, 153, 147, 68, 175, 73, 159, 199, 138, 23, 5, 57, 141, 231, 174, 119, 197, 239, 26, 5, 153, 147, 68, 175, 73, 159, 199, 138, 23, 5, 57, 141,
98, 237, 6, 207, 46, 20, 121, 246, 222, 248, 154, 57, 188, 98, 237, 6, 207, 46, 20, 121, 246, 222, 248, 154, 57, 188,
]; ];
let initial_acc1 = AccountInitialData { let initial_acc1 = AccountInitialData {
addr: hex::encode(acc1_addr), addr: acc1_addr.to_base58(),
balance: 10000, balance: 10000,
}; };
let initial_acc2 = AccountInitialData { let initial_acc2 = AccountInitialData {
addr: hex::encode(acc2_addr), addr: acc2_addr.to_base58(),
balance: 20000, balance: 20000,
}; };
@ -288,11 +289,17 @@ mod tests {
assert_eq!(sequencer.sequencer_config.max_num_tx_in_block, 10); assert_eq!(sequencer.sequencer_config.max_num_tx_in_block, 10);
assert_eq!(sequencer.sequencer_config.port, 8080); assert_eq!(sequencer.sequencer_config.port, 8080);
let acc1_addr = hex::decode(config.initial_accounts[0].addr.clone()) let acc1_addr = config.initial_accounts[0]
.addr
.clone()
.from_base58()
.unwrap() .unwrap()
.try_into() .try_into()
.unwrap(); .unwrap();
let acc2_addr = hex::decode(config.initial_accounts[1].addr.clone()) let acc2_addr = config.initial_accounts[1]
.addr
.clone()
.from_base58()
.unwrap() .unwrap()
.try_into() .try_into()
.unwrap(); .unwrap();
@ -314,23 +321,23 @@ mod tests {
#[test] #[test]
fn test_start_different_intial_accounts_balances() { fn test_start_different_intial_accounts_balances() {
let acc1_addr = vec![ let acc1_addr: Vec<u8> = vec![
27, 132, 197, 86, 123, 18, 100, 64, 153, 93, 62, 213, 170, 186, 5, 101, 215, 30, 24, 27, 132, 197, 86, 123, 18, 100, 64, 153, 93, 62, 213, 170, 186, 5, 101, 215, 30, 24,
52, 96, 72, 25, 255, 156, 23, 245, 233, 213, 221, 7, 143, 52, 96, 72, 25, 255, 156, 23, 245, 233, 213, 221, 7, 143,
]; ];
let acc2_addr = vec![ let acc2_addr: Vec<u8> = vec![
77, 75, 108, 209, 54, 16, 50, 202, 155, 210, 174, 185, 217, 0, 170, 77, 69, 217, 234, 77, 75, 108, 209, 54, 16, 50, 202, 155, 210, 174, 185, 217, 0, 170, 77, 69, 217, 234,
216, 10, 201, 66, 51, 116, 196, 81, 167, 37, 77, 7, 102, 216, 10, 201, 66, 51, 116, 196, 81, 167, 37, 77, 7, 102,
]; ];
let initial_acc1 = AccountInitialData { let initial_acc1 = AccountInitialData {
addr: hex::encode(acc1_addr), addr: acc1_addr.to_base58(),
balance: 10000, balance: 10000,
}; };
let initial_acc2 = AccountInitialData { let initial_acc2 = AccountInitialData {
addr: hex::encode(acc2_addr), addr: acc2_addr.to_base58(),
balance: 20000, balance: 20000,
}; };
@ -339,11 +346,17 @@ mod tests {
let config = setup_sequencer_config_variable_initial_accounts(initial_accounts); let config = setup_sequencer_config_variable_initial_accounts(initial_accounts);
let sequencer = SequencerCore::start_from_config(config.clone()); let sequencer = SequencerCore::start_from_config(config.clone());
let acc1_addr = hex::decode(config.initial_accounts[0].addr.clone()) let acc1_addr = config.initial_accounts[0]
.addr
.clone()
.from_base58()
.unwrap() .unwrap()
.try_into() .try_into()
.unwrap(); .unwrap();
let acc2_addr = hex::decode(config.initial_accounts[1].addr.clone()) let acc2_addr = config.initial_accounts[1]
.addr
.clone()
.from_base58()
.unwrap() .unwrap()
.try_into() .try_into()
.unwrap(); .unwrap();
@ -386,11 +399,17 @@ mod tests {
common_setup(&mut sequencer); common_setup(&mut sequencer);
let acc1 = hex::decode(sequencer.sequencer_config.initial_accounts[0].addr.clone()) let acc1 = sequencer.sequencer_config.initial_accounts[0]
.addr
.clone()
.from_base58()
.unwrap() .unwrap()
.try_into() .try_into()
.unwrap(); .unwrap();
let acc2 = hex::decode(sequencer.sequencer_config.initial_accounts[1].addr.clone()) let acc2 = sequencer.sequencer_config.initial_accounts[1]
.addr
.clone()
.from_base58()
.unwrap() .unwrap()
.try_into() .try_into()
.unwrap(); .unwrap();
@ -412,11 +431,17 @@ mod tests {
common_setup(&mut sequencer); common_setup(&mut sequencer);
let acc1 = hex::decode(sequencer.sequencer_config.initial_accounts[0].addr.clone()) let acc1 = sequencer.sequencer_config.initial_accounts[0]
.addr
.clone()
.from_base58()
.unwrap() .unwrap()
.try_into() .try_into()
.unwrap(); .unwrap();
let acc2 = hex::decode(sequencer.sequencer_config.initial_accounts[1].addr.clone()) let acc2 = sequencer.sequencer_config.initial_accounts[1]
.addr
.clone()
.from_base58()
.unwrap() .unwrap()
.try_into() .try_into()
.unwrap(); .unwrap();
@ -448,11 +473,17 @@ mod tests {
common_setup(&mut sequencer); common_setup(&mut sequencer);
let acc1 = hex::decode(sequencer.sequencer_config.initial_accounts[0].addr.clone()) let acc1 = sequencer.sequencer_config.initial_accounts[0]
.addr
.clone()
.from_base58()
.unwrap() .unwrap()
.try_into() .try_into()
.unwrap(); .unwrap();
let acc2 = hex::decode(sequencer.sequencer_config.initial_accounts[1].addr.clone()) let acc2 = sequencer.sequencer_config.initial_accounts[1]
.addr
.clone()
.from_base58()
.unwrap() .unwrap()
.try_into() .try_into()
.unwrap(); .unwrap();
@ -484,11 +515,17 @@ mod tests {
common_setup(&mut sequencer); common_setup(&mut sequencer);
let acc1 = hex::decode(sequencer.sequencer_config.initial_accounts[0].addr.clone()) let acc1 = sequencer.sequencer_config.initial_accounts[0]
.addr
.clone()
.from_base58()
.unwrap() .unwrap()
.try_into() .try_into()
.unwrap(); .unwrap();
let acc2 = hex::decode(sequencer.sequencer_config.initial_accounts[1].addr.clone()) let acc2 = sequencer.sequencer_config.initial_accounts[1]
.addr
.clone()
.from_base58()
.unwrap() .unwrap()
.try_into() .try_into()
.unwrap(); .unwrap();
@ -576,11 +613,17 @@ mod tests {
common_setup(&mut sequencer); common_setup(&mut sequencer);
let acc1 = hex::decode(sequencer.sequencer_config.initial_accounts[0].addr.clone()) let acc1 = sequencer.sequencer_config.initial_accounts[0]
.addr
.clone()
.from_base58()
.unwrap() .unwrap()
.try_into() .try_into()
.unwrap(); .unwrap();
let acc2 = hex::decode(sequencer.sequencer_config.initial_accounts[1].addr.clone()) let acc2 = sequencer.sequencer_config.initial_accounts[1]
.addr
.clone()
.from_base58()
.unwrap() .unwrap()
.try_into() .try_into()
.unwrap(); .unwrap();
@ -618,11 +661,17 @@ mod tests {
common_setup(&mut sequencer); common_setup(&mut sequencer);
let acc1 = hex::decode(sequencer.sequencer_config.initial_accounts[0].addr.clone()) let acc1 = sequencer.sequencer_config.initial_accounts[0]
.addr
.clone()
.from_base58()
.unwrap() .unwrap()
.try_into() .try_into()
.unwrap(); .unwrap();
let acc2 = hex::decode(sequencer.sequencer_config.initial_accounts[1].addr.clone()) let acc2 = sequencer.sequencer_config.initial_accounts[1]
.addr
.clone()
.from_base58()
.unwrap() .unwrap()
.try_into() .try_into()
.unwrap(); .unwrap();

View File

@ -10,7 +10,8 @@ log.workspace = true
serde.workspace = true serde.workspace = true
actix-cors.workspace = true actix-cors.workspace = true
futures.workspace = true futures.workspace = true
hex.workspace = true base58.workspace = true
hex = "0.4.3"
tempfile.workspace = true tempfile.workspace = true
base64.workspace = true base64.workspace = true

View File

@ -1,6 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use actix_web::Error as HttpError; use actix_web::Error as HttpError;
use base58::FromBase58;
use base64::{Engine, engine::general_purpose}; use base64::{Engine, engine::general_purpose};
use nssa::{self, program::Program}; use nssa::{self, program::Program};
use sequencer_core::config::AccountInitialData; use sequencer_core::config::AccountInitialData;
@ -163,8 +164,10 @@ impl JsonHandler {
/// The address must be a valid hex string of the correct length. /// The address must be a valid hex string of the correct length.
async fn process_get_account_balance(&self, request: Request) -> Result<Value, RpcErr> { async fn process_get_account_balance(&self, request: Request) -> Result<Value, RpcErr> {
let get_account_req = GetAccountBalanceRequest::parse(Some(request.params))?; let get_account_req = GetAccountBalanceRequest::parse(Some(request.params))?;
let address_bytes = hex::decode(get_account_req.address) let address_bytes = get_account_req
.map_err(|_| RpcError::invalid_params("invalid hex".to_string()))?; .address
.from_base58()
.map_err(|_| RpcError::invalid_params("invalid base58".to_string()))?;
let address = nssa::Address::new( let address = nssa::Address::new(
address_bytes address_bytes
.try_into() .try_into()
@ -312,6 +315,7 @@ mod tests {
use std::sync::Arc; use std::sync::Arc;
use crate::{JsonHandler, rpc_handler}; use crate::{JsonHandler, rpc_handler};
use base58::ToBase58;
use base64::{Engine, engine::general_purpose}; use base64::{Engine, engine::general_purpose};
use common::{ use common::{
rpc_primitives::RpcPollingConfig, test_utils::sequencer_sign_key_for_testing, rpc_primitives::RpcPollingConfig, test_utils::sequencer_sign_key_for_testing,
@ -329,23 +333,23 @@ mod tests {
fn sequencer_config_for_tests() -> SequencerConfig { fn sequencer_config_for_tests() -> SequencerConfig {
let tempdir = tempdir().unwrap(); let tempdir = tempdir().unwrap();
let home = tempdir.path().to_path_buf(); let home = tempdir.path().to_path_buf();
let acc1_addr = vec![ let acc1_addr: Vec<u8> = vec![
208, 122, 210, 232, 75, 39, 250, 0, 194, 98, 240, 161, 238, 160, 255, 53, 202, 9, 115, 208, 122, 210, 232, 75, 39, 250, 0, 194, 98, 240, 161, 238, 160, 255, 53, 202, 9, 115,
84, 126, 106, 16, 111, 114, 241, 147, 194, 220, 131, 139, 68, 84, 126, 106, 16, 111, 114, 241, 147, 194, 220, 131, 139, 68,
]; ];
let acc2_addr = vec![ let acc2_addr: Vec<u8> = vec![
231, 174, 119, 197, 239, 26, 5, 153, 147, 68, 175, 73, 159, 199, 138, 23, 5, 57, 141, 231, 174, 119, 197, 239, 26, 5, 153, 147, 68, 175, 73, 159, 199, 138, 23, 5, 57, 141,
98, 237, 6, 207, 46, 20, 121, 246, 222, 248, 154, 57, 188, 98, 237, 6, 207, 46, 20, 121, 246, 222, 248, 154, 57, 188,
]; ];
let initial_acc1 = AccountInitialData { let initial_acc1 = AccountInitialData {
addr: hex::encode(acc1_addr), addr: acc1_addr.to_base58(),
balance: 10000, balance: 10000,
}; };
let initial_acc2 = AccountInitialData { let initial_acc2 = AccountInitialData {
addr: hex::encode(acc2_addr), addr: acc2_addr.to_base58(),
balance: 20000, balance: 20000,
}; };

View File

@ -16,7 +16,8 @@ nssa-core = { path = "../nssa/core" }
base64.workspace = true base64.workspace = true
bytemuck = "1.23.2" bytemuck = "1.23.2"
borsh.workspace = true borsh.workspace = true
hex.workspace = true base58.workspace = true
hex = "0.4.3"
rand.workspace = true rand.workspace = true
[dependencies.key_protocol] [dependencies.key_protocol]

View File

@ -1,6 +1,7 @@
use std::str::FromStr; use std::str::FromStr;
use anyhow::Result; use anyhow::Result;
use base58::ToBase58;
use clap::Subcommand; use clap::Subcommand;
use common::transaction::NSSATransaction; use common::transaction::NSSATransaction;
use nssa::Address; use nssa::Address;
@ -18,9 +19,9 @@ pub enum AccountSubcommand {
///Fetch ///Fetch
#[command(subcommand)] #[command(subcommand)]
Fetch(FetchSubcommand), Fetch(FetchSubcommand),
///Register ///New
#[command(subcommand)] #[command(subcommand)]
Register(RegisterSubcommand), New(NewSubcommand),
} }
///Represents generic getter CLI subcommand ///Represents generic getter CLI subcommand
@ -72,7 +73,7 @@ pub enum FetchSubcommand {
///Represents generic register CLI subcommand ///Represents generic register CLI subcommand
#[derive(Subcommand, Debug, Clone)] #[derive(Subcommand, Debug, Clone)]
pub enum RegisterSubcommand { pub enum NewSubcommand {
///Register new public account ///Register new public account
Public {}, Public {},
///Register new private account ///Register new private account
@ -190,13 +191,13 @@ impl WalletSubcommand for FetchSubcommand {
} }
} }
impl WalletSubcommand for RegisterSubcommand { impl WalletSubcommand for NewSubcommand {
async fn handle_subcommand( async fn handle_subcommand(
self, self,
wallet_core: &mut WalletCore, wallet_core: &mut WalletCore,
) -> Result<SubcommandReturnValue> { ) -> Result<SubcommandReturnValue> {
match self { match self {
RegisterSubcommand::Public {} => { NewSubcommand::Public {} => {
let addr = wallet_core.create_new_account_public(); let addr = wallet_core.create_new_account_public();
println!("Generated new account with addr {addr}"); println!("Generated new account with addr {addr}");
@ -207,7 +208,7 @@ impl WalletSubcommand for RegisterSubcommand {
Ok(SubcommandReturnValue::RegisterAccount { addr }) Ok(SubcommandReturnValue::RegisterAccount { addr })
} }
RegisterSubcommand::Private {} => { NewSubcommand::Private {} => {
let addr = wallet_core.create_new_account_private(); let addr = wallet_core.create_new_account_private();
let (key, _) = wallet_core let (key, _) = wallet_core
@ -216,8 +217,8 @@ impl WalletSubcommand for RegisterSubcommand {
.get_private_account(&addr) .get_private_account(&addr)
.unwrap(); .unwrap();
println!("Generated new account with addr {addr}"); println!("Generated new account with addr {}", addr.to_bytes().to_base58());
println!("With npk {}", hex::encode(&key.nullifer_public_key)); println!("With npk {}", hex::encode(&key.nullifer_public_key.0));
println!( println!(
"With ipk {}", "With ipk {}",
hex::encode(key.incoming_viewing_public_key.to_bytes()) hex::encode(key.incoming_viewing_public_key.to_bytes())
@ -245,8 +246,8 @@ impl WalletSubcommand for AccountSubcommand {
AccountSubcommand::Fetch(fetch_subcommand) => { AccountSubcommand::Fetch(fetch_subcommand) => {
fetch_subcommand.handle_subcommand(wallet_core).await fetch_subcommand.handle_subcommand(wallet_core).await
} }
AccountSubcommand::Register(register_subcommand) => { AccountSubcommand::New(new_subcommand) => {
register_subcommand.handle_subcommand(wallet_core).await new_subcommand.handle_subcommand(wallet_core).await
} }
} }
} }

View File

@ -6,12 +6,12 @@ use crate::{SubcommandReturnValue, WalletCore, cli::WalletSubcommand};
///Represents generic chain CLI subcommand ///Represents generic chain CLI subcommand
#[derive(Subcommand, Debug, Clone)] #[derive(Subcommand, Debug, Clone)]
pub enum ChainSubcommand { pub enum ChainSubcommand {
GetLatestBlockId {}, CurrentBlockId {},
GetBlockAtId { Block {
#[arg(short, long)] #[arg(short, long)]
id: u64, id: u64,
}, },
GetTransactionAtHash { Transaction {
#[arg(short, long)] #[arg(short, long)]
hash: String, hash: String,
}, },
@ -23,17 +23,17 @@ impl WalletSubcommand for ChainSubcommand {
wallet_core: &mut WalletCore, wallet_core: &mut WalletCore,
) -> Result<SubcommandReturnValue> { ) -> Result<SubcommandReturnValue> {
match self { match self {
ChainSubcommand::GetLatestBlockId {} => { ChainSubcommand::CurrentBlockId {} => {
let latest_block_res = wallet_core.sequencer_client.get_last_block().await?; let latest_block_res = wallet_core.sequencer_client.get_last_block().await?;
println!("Last block id is {}", latest_block_res.last_block); println!("Last block id is {}", latest_block_res.last_block);
} }
ChainSubcommand::GetBlockAtId { id } => { ChainSubcommand::Block { id } => {
let block_res = wallet_core.sequencer_client.get_block(id).await?; let block_res = wallet_core.sequencer_client.get_block(id).await?;
println!("Last block id is {:#?}", block_res.block); println!("Last block id is {:#?}", block_res.block);
} }
ChainSubcommand::GetTransactionAtHash { hash } => { ChainSubcommand::Transaction { hash } => {
let tx_res = wallet_core let tx_res = wallet_core
.sequencer_client .sequencer_client
.get_transaction_by_hash(hash) .get_transaction_by_hash(hash)

View File

@ -193,19 +193,19 @@ impl WalletCore {
pub enum Command { pub enum Command {
///Transfer command ///Transfer command
#[command(subcommand)] #[command(subcommand)]
Transfer(NativeTokenTransferProgramSubcommand), AuthTransfer(NativeTokenTransferProgramSubcommand),
///Chain command ///Chain command
#[command(subcommand)] #[command(subcommand)]
Chain(ChainSubcommand), ChainInfo(ChainSubcommand),
///Chain command ///Chain command
#[command(subcommand)] #[command(subcommand)]
Account(AccountSubcommand), Account(AccountSubcommand),
///Pinata command ///Pinata command
#[command(subcommand)] #[command(subcommand)]
PinataProgram(PinataProgramSubcommand), Pinata(PinataProgramSubcommand),
///Token command ///Token command
#[command(subcommand)] #[command(subcommand)]
TokenProgram(TokenProgramSubcommand), Token(TokenProgramSubcommand),
AuthenticatedTransferInitializePublicAccount {}, AuthenticatedTransferInitializePublicAccount {},
// Check the wallet can connect to the node and builtin local programs // Check the wallet can connect to the node and builtin local programs
// match the remote versions // match the remote versions
@ -237,12 +237,12 @@ pub async fn execute_subcommand(command: Command) -> Result<SubcommandReturnValu
let mut wallet_core = WalletCore::start_from_config_update_chain(wallet_config).await?; let mut wallet_core = WalletCore::start_from_config_update_chain(wallet_config).await?;
let subcommand_ret = match command { let subcommand_ret = match command {
Command::Transfer(transfer_subcommand) => { Command::AuthTransfer(transfer_subcommand) => {
transfer_subcommand transfer_subcommand
.handle_subcommand(&mut wallet_core) .handle_subcommand(&mut wallet_core)
.await? .await?
} }
Command::Chain(chain_subcommand) => { Command::ChainInfo(chain_subcommand) => {
chain_subcommand.handle_subcommand(&mut wallet_core).await? chain_subcommand.handle_subcommand(&mut wallet_core).await?
} }
Command::Account(account_subcommand) => { Command::Account(account_subcommand) => {
@ -250,7 +250,7 @@ pub async fn execute_subcommand(command: Command) -> Result<SubcommandReturnValu
.handle_subcommand(&mut wallet_core) .handle_subcommand(&mut wallet_core)
.await? .await?
} }
Command::PinataProgram(pinata_subcommand) => { Command::Pinata(pinata_subcommand) => {
pinata_subcommand pinata_subcommand
.handle_subcommand(&mut wallet_core) .handle_subcommand(&mut wallet_core)
.await? .await?
@ -304,7 +304,7 @@ pub async fn execute_subcommand(command: Command) -> Result<SubcommandReturnValu
SubcommandReturnValue::RegisterAccount { addr } SubcommandReturnValue::RegisterAccount { addr }
} }
Command::TokenProgram(token_subcommand) => { Command::Token(token_subcommand) => {
token_subcommand.handle_subcommand(&mut wallet_core).await? token_subcommand.handle_subcommand(&mut wallet_core).await?
} }
}; };