mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-07 15:53:14 +00:00
refactor: rename Address to AccountId
This commit is contained in:
parent
3355d23218
commit
ea9c659fb1
@ -14,7 +14,7 @@ pub struct HelloRequest {}
|
|||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct RegisterAccountRequest {
|
pub struct RegisterAccountRequest {
|
||||||
pub address: [u8; 32],
|
pub account_id: [u8; 32],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
@ -38,7 +38,7 @@ pub struct GetInitialTestnetAccountsRequest {}
|
|||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct GetAccountBalanceRequest {
|
pub struct GetAccountBalanceRequest {
|
||||||
pub address: String,
|
pub account_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
@ -48,12 +48,12 @@ pub struct GetTransactionByHashRequest {
|
|||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct GetAccountsNoncesRequest {
|
pub struct GetAccountsNoncesRequest {
|
||||||
pub addresses: Vec<String>,
|
pub account_ids: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct GetAccountRequest {
|
pub struct GetAccountRequest {
|
||||||
pub address: String,
|
pub account_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
|||||||
@ -45,9 +45,9 @@ pub struct SequencerRpcResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
///Helperstruct for account serialization
|
/// Helperstruct for account serialization
|
||||||
pub struct AccountInitialData {
|
pub struct AccountInitialData {
|
||||||
///Hex encoded `AccountAddress`
|
/// Hex encoded account id
|
||||||
pub addr: String,
|
pub account_id: String,
|
||||||
pub balance: u64,
|
pub balance: u64,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -91,12 +91,12 @@ impl SequencerClient {
|
|||||||
Ok(resp_deser)
|
Ok(resp_deser)
|
||||||
}
|
}
|
||||||
|
|
||||||
///Get account public balance for `address`. `address` must be a valid hex-string for 32 bytes.
|
///Get account public balance for `account_id`. `account_id` must be a valid hex-string for 32 bytes.
|
||||||
pub async fn get_account_balance(
|
pub async fn get_account_balance(
|
||||||
&self,
|
&self,
|
||||||
address: String,
|
account_id: String,
|
||||||
) -> Result<GetAccountBalanceResponse, SequencerClientError> {
|
) -> Result<GetAccountBalanceResponse, SequencerClientError> {
|
||||||
let block_req = GetAccountBalanceRequest { address };
|
let block_req = GetAccountBalanceRequest { account_id };
|
||||||
|
|
||||||
let req = serde_json::to_value(block_req)?;
|
let req = serde_json::to_value(block_req)?;
|
||||||
|
|
||||||
@ -109,12 +109,12 @@ impl SequencerClient {
|
|||||||
Ok(resp_deser)
|
Ok(resp_deser)
|
||||||
}
|
}
|
||||||
|
|
||||||
///Get accounts nonces for `addresses`. `addresses` must be a list of valid hex-strings for 32 bytes.
|
///Get accounts nonces for `account_ids`. `account_ids` must be a list of valid hex-strings for 32 bytes.
|
||||||
pub async fn get_accounts_nonces(
|
pub async fn get_accounts_nonces(
|
||||||
&self,
|
&self,
|
||||||
addresses: Vec<String>,
|
account_ids: Vec<String>,
|
||||||
) -> Result<GetAccountsNoncesResponse, SequencerClientError> {
|
) -> Result<GetAccountsNoncesResponse, SequencerClientError> {
|
||||||
let block_req = GetAccountsNoncesRequest { addresses };
|
let block_req = GetAccountsNoncesRequest { account_ids };
|
||||||
|
|
||||||
let req = serde_json::to_value(block_req)?;
|
let req = serde_json::to_value(block_req)?;
|
||||||
|
|
||||||
@ -129,9 +129,9 @@ impl SequencerClient {
|
|||||||
|
|
||||||
pub async fn get_account(
|
pub async fn get_account(
|
||||||
&self,
|
&self,
|
||||||
address: String,
|
account_id: String,
|
||||||
) -> Result<GetAccountResponse, SequencerClientError> {
|
) -> Result<GetAccountResponse, SequencerClientError> {
|
||||||
let block_req = GetAccountRequest { address };
|
let block_req = GetAccountRequest { account_id };
|
||||||
|
|
||||||
let req = serde_json::to_value(block_req)?;
|
let req = serde_json::to_value(block_req)?;
|
||||||
|
|
||||||
|
|||||||
@ -35,12 +35,16 @@ pub fn produce_dummy_block(
|
|||||||
|
|
||||||
pub fn produce_dummy_empty_transaction() -> EncodedTransaction {
|
pub fn produce_dummy_empty_transaction() -> EncodedTransaction {
|
||||||
let program_id = nssa::program::Program::authenticated_transfer_program().id();
|
let program_id = nssa::program::Program::authenticated_transfer_program().id();
|
||||||
let addresses = vec![];
|
let account_ids = vec![];
|
||||||
let nonces = vec![];
|
let nonces = vec![];
|
||||||
let instruction_data: u128 = 0;
|
let instruction_data: u128 = 0;
|
||||||
let message =
|
let message = nssa::public_transaction::Message::try_new(
|
||||||
nssa::public_transaction::Message::try_new(program_id, addresses, nonces, instruction_data)
|
program_id,
|
||||||
.unwrap();
|
account_ids,
|
||||||
|
nonces,
|
||||||
|
instruction_data,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
let private_key = nssa::PrivateKey::try_new([1; 32]).unwrap();
|
let private_key = nssa::PrivateKey::try_new([1; 32]).unwrap();
|
||||||
let witness_set = nssa::public_transaction::WitnessSet::for_message(&message, &[&private_key]);
|
let witness_set = nssa::public_transaction::WitnessSet::for_message(&message, &[&private_key]);
|
||||||
|
|
||||||
@ -56,12 +60,16 @@ pub fn create_transaction_native_token_transfer(
|
|||||||
balance_to_move: u128,
|
balance_to_move: u128,
|
||||||
signing_key: nssa::PrivateKey,
|
signing_key: nssa::PrivateKey,
|
||||||
) -> EncodedTransaction {
|
) -> EncodedTransaction {
|
||||||
let addresses = vec![nssa::Address::new(from), nssa::Address::new(to)];
|
let account_ids = vec![nssa::AccountId::new(from), nssa::AccountId::new(to)];
|
||||||
let nonces = vec![nonce];
|
let nonces = vec![nonce];
|
||||||
let program_id = nssa::program::Program::authenticated_transfer_program().id();
|
let program_id = nssa::program::Program::authenticated_transfer_program().id();
|
||||||
let message =
|
let message = nssa::public_transaction::Message::try_new(
|
||||||
nssa::public_transaction::Message::try_new(program_id, addresses, nonces, balance_to_move)
|
program_id,
|
||||||
.unwrap();
|
account_ids,
|
||||||
|
nonces,
|
||||||
|
balance_to_move,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
let witness_set = nssa::public_transaction::WitnessSet::for_message(&message, &[&signing_key]);
|
let witness_set = nssa::public_transaction::WitnessSet::for_message(&message, &[&signing_key]);
|
||||||
|
|
||||||
let nssa_tx = nssa::PublicTransaction::new(message, witness_set);
|
let nssa_tx = nssa::PublicTransaction::new(message, witness_set);
|
||||||
|
|||||||
@ -9,11 +9,11 @@
|
|||||||
"port": 3040,
|
"port": 3040,
|
||||||
"initial_accounts": [
|
"initial_accounts": [
|
||||||
{
|
{
|
||||||
"addr": "BLgCRDXYdQPMMWVHYRFGQZbgeHx9frkipa8GtpG2Syqy",
|
"account_id": "BLgCRDXYdQPMMWVHYRFGQZbgeHx9frkipa8GtpG2Syqy",
|
||||||
"balance": 10000
|
"balance": 10000
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"addr": "Gj1mJy5W7J5pfmLRujmQaLfLMWidNxQ6uwnhb666ZwHw",
|
"account_id": "Gj1mJy5W7J5pfmLRujmQaLfLMWidNxQ6uwnhb666ZwHw",
|
||||||
"balance": 20000
|
"balance": 20000
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
"initial_accounts": [
|
"initial_accounts": [
|
||||||
{
|
{
|
||||||
"Public": {
|
"Public": {
|
||||||
"address": "BLgCRDXYdQPMMWVHYRFGQZbgeHx9frkipa8GtpG2Syqy",
|
"account_id": "BLgCRDXYdQPMMWVHYRFGQZbgeHx9frkipa8GtpG2Syqy",
|
||||||
"pub_sign_key": [
|
"pub_sign_key": [
|
||||||
16,
|
16,
|
||||||
162,
|
162,
|
||||||
@ -47,7 +47,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Public": {
|
"Public": {
|
||||||
"address": "Gj1mJy5W7J5pfmLRujmQaLfLMWidNxQ6uwnhb666ZwHw",
|
"account_id": "Gj1mJy5W7J5pfmLRujmQaLfLMWidNxQ6uwnhb666ZwHw",
|
||||||
"pub_sign_key": [
|
"pub_sign_key": [
|
||||||
113,
|
113,
|
||||||
121,
|
121,
|
||||||
@ -86,7 +86,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Private": {
|
"Private": {
|
||||||
"address": "3oCG8gqdKLMegw4rRfyaMQvuPHpcASt7xwttsmnZLSkw",
|
"account_id": "3oCG8gqdKLMegw4rRfyaMQvuPHpcASt7xwttsmnZLSkw",
|
||||||
"account": {
|
"account": {
|
||||||
"program_owner": [
|
"program_owner": [
|
||||||
0,
|
0,
|
||||||
@ -315,7 +315,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Private": {
|
"Private": {
|
||||||
"address": "AKTcXgJ1xoynta1Ec7y6Jso1z1JQtHqd7aPQ1h9er6xX",
|
"account_id": "AKTcXgJ1xoynta1Ec7y6Jso1z1JQtHqd7aPQ1h9er6xX",
|
||||||
"account": {
|
"account": {
|
||||||
"program_owner": [
|
"program_owner": [
|
||||||
0,
|
0,
|
||||||
|
|||||||
@ -44,12 +44,12 @@ pub const TIME_TO_WAIT_FOR_BLOCK_SECONDS: u64 = 12;
|
|||||||
|
|
||||||
pub const NSSA_PROGRAM_FOR_TEST_DATA_CHANGER: &[u8] = include_bytes!("data_changer.bin");
|
pub const NSSA_PROGRAM_FOR_TEST_DATA_CHANGER: &[u8] = include_bytes!("data_changer.bin");
|
||||||
|
|
||||||
fn make_public_account_input_from_str(addr: &str) -> String {
|
fn make_public_account_input_from_str(account_id: &str) -> String {
|
||||||
format!("Public/{addr}")
|
format!("Public/{account_id}")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_private_account_input_from_str(addr: &str) -> String {
|
fn make_private_account_input_from_str(account_id: &str) -> String {
|
||||||
format!("Private/{addr}")
|
format!("Private/{account_id}")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
@ -174,14 +174,14 @@ mod tests {
|
|||||||
use crate::{make_private_account_input_from_str, make_public_account_input_from_str};
|
use crate::{make_private_account_input_from_str, make_public_account_input_from_str};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn correct_addr_from_prefix() {
|
fn correct_account_id_from_prefix() {
|
||||||
let addr1 = "cafecafe";
|
let account_id1 = "cafecafe";
|
||||||
let addr2 = "deadbeaf";
|
let account_id2 = "deadbeaf";
|
||||||
|
|
||||||
let addr1_pub = make_public_account_input_from_str(addr1);
|
let account_id1_pub = make_public_account_input_from_str(account_id1);
|
||||||
let addr2_priv = make_private_account_input_from_str(addr2);
|
let account_id2_priv = make_private_account_input_from_str(account_id2);
|
||||||
|
|
||||||
assert_eq!(addr1_pub, "Public/cafecafe".to_string());
|
assert_eq!(account_id1_pub, "Public/cafecafe".to_string());
|
||||||
assert_eq!(addr2_priv, "Private/deadbeaf".to_string());
|
assert_eq!(account_id2_priv, "Private/deadbeaf".to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ use std::{
|
|||||||
use actix_web::dev::ServerHandle;
|
use actix_web::dev::ServerHandle;
|
||||||
use common::{PINATA_BASE58, sequencer_client::SequencerClient};
|
use common::{PINATA_BASE58, sequencer_client::SequencerClient};
|
||||||
use log::info;
|
use log::info;
|
||||||
use nssa::{Address, ProgramDeploymentTransaction, program::Program};
|
use nssa::{AccountId, ProgramDeploymentTransaction, program::Program};
|
||||||
use nssa_core::{NullifierPublicKey, encryption::shared_key_derivation::Secp256k1Point};
|
use nssa_core::{NullifierPublicKey, encryption::shared_key_derivation::Secp256k1Point};
|
||||||
use sequencer_runner::startup_sequencer;
|
use sequencer_runner::startup_sequencer;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
@ -96,24 +96,24 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
last_synced_block: _,
|
last_synced_block: _,
|
||||||
} = fetch_persistent_storage().await.unwrap();
|
} = fetch_persistent_storage().await.unwrap();
|
||||||
|
|
||||||
let mut new_persistent_account_addr = String::new();
|
let mut new_persistent_account_id = String::new();
|
||||||
|
|
||||||
for per_acc in persistent_accounts {
|
for per_acc in persistent_accounts {
|
||||||
if (per_acc.address().to_string() != ACC_RECEIVER)
|
if (per_acc.account_id().to_string() != ACC_RECEIVER)
|
||||||
&& (per_acc.address().to_string() != ACC_SENDER)
|
&& (per_acc.account_id().to_string() != ACC_SENDER)
|
||||||
{
|
{
|
||||||
new_persistent_account_addr = per_acc.address().to_string();
|
new_persistent_account_id = per_acc.account_id().to_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if new_persistent_account_addr == String::new() {
|
if new_persistent_account_id == String::new() {
|
||||||
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::AuthTransfer(AuthTransferSubcommand::Send {
|
let command = Command::AuthTransfer(AuthTransferSubcommand::Send {
|
||||||
from: make_public_account_input_from_str(ACC_SENDER),
|
from: make_public_account_input_from_str(ACC_SENDER),
|
||||||
to: Some(make_public_account_input_from_str(
|
to: Some(make_public_account_input_from_str(
|
||||||
&new_persistent_account_addr,
|
&new_persistent_account_id,
|
||||||
)),
|
)),
|
||||||
to_npk: None,
|
to_npk: None,
|
||||||
to_ipk: None,
|
to_ipk: None,
|
||||||
@ -131,7 +131,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let acc_2_balance = seq_client
|
let acc_2_balance = seq_client
|
||||||
.get_account_balance(new_persistent_account_addr)
|
.get_account_balance(new_persistent_account_id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@ -307,29 +307,35 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
last_synced_block: _,
|
last_synced_block: _,
|
||||||
} = fetch_persistent_storage().await.unwrap();
|
} = fetch_persistent_storage().await.unwrap();
|
||||||
|
|
||||||
let mut new_persistent_accounts_addr = Vec::new();
|
let mut new_persistent_accounts_account_id = Vec::new();
|
||||||
|
|
||||||
for per_acc in persistent_accounts {
|
for per_acc in persistent_accounts {
|
||||||
match per_acc {
|
match per_acc {
|
||||||
PersistentAccountData::Public(per_acc) => {
|
PersistentAccountData::Public(per_acc) => {
|
||||||
if (per_acc.address.to_string() != ACC_RECEIVER)
|
if (per_acc.account_id.to_string() != ACC_RECEIVER)
|
||||||
&& (per_acc.address.to_string() != ACC_SENDER)
|
&& (per_acc.account_id.to_string() != ACC_SENDER)
|
||||||
{
|
{
|
||||||
new_persistent_accounts_addr.push(per_acc.address);
|
new_persistent_accounts_account_id.push(per_acc.account_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => continue,
|
_ => continue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let [definition_addr, supply_addr, recipient_addr] = new_persistent_accounts_addr
|
let [
|
||||||
|
definition_account_id,
|
||||||
|
supply_account_id,
|
||||||
|
recipient_account_id,
|
||||||
|
] = new_persistent_accounts_account_id
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("Failed to produce new account, not present in persistent accounts");
|
.expect("Failed to produce new account, not present in persistent accounts");
|
||||||
|
|
||||||
// Create new token
|
// Create new token
|
||||||
let subcommand = TokenProgramAgnosticSubcommand::New {
|
let subcommand = TokenProgramAgnosticSubcommand::New {
|
||||||
definition_addr: make_public_account_input_from_str(&definition_addr.to_string()),
|
definition_account_id: make_public_account_input_from_str(
|
||||||
supply_addr: make_public_account_input_from_str(&supply_addr.to_string()),
|
&definition_account_id.to_string(),
|
||||||
|
),
|
||||||
|
supply_account_id: make_public_account_input_from_str(&supply_account_id.to_string()),
|
||||||
name: "A NAME".to_string(),
|
name: "A NAME".to_string(),
|
||||||
total_supply: 37,
|
total_supply: 37,
|
||||||
};
|
};
|
||||||
@ -343,7 +349,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
|
|
||||||
// Check the status of the token definition account is the expected after the execution
|
// Check the status of the token definition account is the expected after the execution
|
||||||
let definition_acc = seq_client
|
let definition_acc = seq_client
|
||||||
.get_account(definition_addr.to_string())
|
.get_account(definition_account_id.to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.account;
|
.account;
|
||||||
@ -360,7 +366,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
|
|
||||||
// Check the status of the token holding account with the total supply is the expected after the execution
|
// Check the status of the token holding account with the total supply is the expected after the execution
|
||||||
let supply_acc = seq_client
|
let supply_acc = seq_client
|
||||||
.get_account(supply_addr.to_string())
|
.get_account(supply_account_id.to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.account;
|
.account;
|
||||||
@ -373,18 +379,18 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
assert_eq!(supply_acc.data[0], 1);
|
assert_eq!(supply_acc.data[0], 1);
|
||||||
// Bytes from 1 to 33 represent the id of the token this account is associated with.
|
// Bytes from 1 to 33 represent the id of the token this account is associated with.
|
||||||
// In this example, this is a token account of the newly created token, so it is expected
|
// In this example, this is a token account of the newly created token, so it is expected
|
||||||
// to be equal to the address of the token definition account.
|
// to be equal to the account_id of the token definition account.
|
||||||
assert_eq!(&supply_acc.data[1..33], definition_addr.to_bytes());
|
assert_eq!(&supply_acc.data[1..33], definition_account_id.to_bytes());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
u128::from_le_bytes(supply_acc.data[33..].try_into().unwrap()),
|
u128::from_le_bytes(supply_acc.data[33..].try_into().unwrap()),
|
||||||
37
|
37
|
||||||
);
|
);
|
||||||
|
|
||||||
// Transfer 7 tokens from `supply_acc` to the account at address `recipient_addr`
|
// Transfer 7 tokens from `supply_acc` to the account at account_id `recipient_account_id`
|
||||||
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
||||||
from: make_public_account_input_from_str(&supply_addr.to_string()),
|
from: make_public_account_input_from_str(&supply_account_id.to_string()),
|
||||||
to: Some(make_public_account_input_from_str(
|
to: Some(make_public_account_input_from_str(
|
||||||
&recipient_addr.to_string(),
|
&recipient_account_id.to_string(),
|
||||||
)),
|
)),
|
||||||
to_npk: None,
|
to_npk: None,
|
||||||
to_ipk: None,
|
to_ipk: None,
|
||||||
@ -397,9 +403,9 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
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;
|
||||||
|
|
||||||
// Check the status of the account at `supply_addr` is the expected after the execution
|
// Check the status of the account at `supply_account_id` is the expected after the execution
|
||||||
let supply_acc = seq_client
|
let supply_acc = seq_client
|
||||||
.get_account(supply_addr.to_string())
|
.get_account(supply_account_id.to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.account;
|
.account;
|
||||||
@ -408,15 +414,15 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
// First byte equal to 1 means it's a token holding account
|
// First byte equal to 1 means it's a token holding account
|
||||||
assert_eq!(supply_acc.data[0], 1);
|
assert_eq!(supply_acc.data[0], 1);
|
||||||
// Bytes from 1 to 33 represent the id of the token this account is associated with.
|
// Bytes from 1 to 33 represent the id of the token this account is associated with.
|
||||||
assert_eq!(&supply_acc.data[1..33], definition_addr.to_bytes());
|
assert_eq!(&supply_acc.data[1..33], definition_account_id.to_bytes());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
u128::from_le_bytes(supply_acc.data[33..].try_into().unwrap()),
|
u128::from_le_bytes(supply_acc.data[33..].try_into().unwrap()),
|
||||||
30
|
30
|
||||||
);
|
);
|
||||||
|
|
||||||
// Check the status of the account at `recipient_addr` is the expected after the execution
|
// Check the status of the account at `recipient_account_id` is the expected after the execution
|
||||||
let recipient_acc = seq_client
|
let recipient_acc = seq_client
|
||||||
.get_account(recipient_addr.to_string())
|
.get_account(recipient_account_id.to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.account;
|
.account;
|
||||||
@ -426,7 +432,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
// First byte equal to 1 means it's a token holding account
|
// First byte equal to 1 means it's a token holding account
|
||||||
assert_eq!(recipient_acc.data[0], 1);
|
assert_eq!(recipient_acc.data[0], 1);
|
||||||
// Bytes from 1 to 33 represent the id of the token this account is associated with.
|
// Bytes from 1 to 33 represent the id of the token this account is associated with.
|
||||||
assert_eq!(&recipient_acc.data[1..33], definition_addr.to_bytes());
|
assert_eq!(&recipient_acc.data[1..33], definition_account_id.to_bytes());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
u128::from_le_bytes(recipient_acc.data[33..].try_into().unwrap()),
|
u128::from_le_bytes(recipient_acc.data[33..].try_into().unwrap()),
|
||||||
7
|
7
|
||||||
@ -442,7 +448,7 @@ 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,
|
account_id: definition_account_id,
|
||||||
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
||||||
NewSubcommand::Public {},
|
NewSubcommand::Public {},
|
||||||
)))
|
)))
|
||||||
@ -452,18 +458,19 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
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 {
|
||||||
wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
account_id: supply_account_id,
|
||||||
NewSubcommand::Private {},
|
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
||||||
)))
|
NewSubcommand::Private {},
|
||||||
.await
|
)))
|
||||||
.unwrap()
|
.await
|
||||||
|
.unwrap()
|
||||||
else {
|
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,
|
account_id: recipient_account_id,
|
||||||
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
||||||
NewSubcommand::Private {},
|
NewSubcommand::Private {},
|
||||||
)))
|
)))
|
||||||
@ -475,8 +482,10 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
|
|
||||||
// Create new token
|
// Create new token
|
||||||
let subcommand = TokenProgramAgnosticSubcommand::New {
|
let subcommand = TokenProgramAgnosticSubcommand::New {
|
||||||
definition_addr: make_public_account_input_from_str(&definition_addr.to_string()),
|
definition_account_id: make_public_account_input_from_str(
|
||||||
supply_addr: make_private_account_input_from_str(&supply_addr.to_string()),
|
&definition_account_id.to_string(),
|
||||||
|
),
|
||||||
|
supply_account_id: make_private_account_input_from_str(&supply_account_id.to_string()),
|
||||||
name: "A NAME".to_string(),
|
name: "A NAME".to_string(),
|
||||||
total_supply: 37,
|
total_supply: 37,
|
||||||
};
|
};
|
||||||
@ -492,7 +501,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
|
|
||||||
// Check the status of the token definition account is the expected after the execution
|
// Check the status of the token definition account is the expected after the execution
|
||||||
let definition_acc = seq_client
|
let definition_acc = seq_client
|
||||||
.get_account(definition_addr.to_string())
|
.get_account(definition_account_id.to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.account;
|
.account;
|
||||||
@ -513,15 +522,15 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let new_commitment1 = wallet_storage
|
let new_commitment1 = wallet_storage
|
||||||
.get_private_account_commitment(&supply_addr)
|
.get_private_account_commitment(&supply_account_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(verify_commitment_is_in_state(new_commitment1, &seq_client).await);
|
assert!(verify_commitment_is_in_state(new_commitment1, &seq_client).await);
|
||||||
|
|
||||||
// Transfer 7 tokens from `supply_acc` to the account at address `recipient_addr`
|
// Transfer 7 tokens from `supply_acc` to the account at account_id `recipient_account_id`
|
||||||
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
||||||
from: make_private_account_input_from_str(&supply_addr.to_string()),
|
from: make_private_account_input_from_str(&supply_account_id.to_string()),
|
||||||
to: Some(make_private_account_input_from_str(
|
to: Some(make_private_account_input_from_str(
|
||||||
&recipient_addr.to_string(),
|
&recipient_account_id.to_string(),
|
||||||
)),
|
)),
|
||||||
to_npk: None,
|
to_npk: None,
|
||||||
to_ipk: None,
|
to_ipk: None,
|
||||||
@ -541,20 +550,20 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let new_commitment1 = wallet_storage
|
let new_commitment1 = wallet_storage
|
||||||
.get_private_account_commitment(&supply_addr)
|
.get_private_account_commitment(&supply_account_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(verify_commitment_is_in_state(new_commitment1, &seq_client).await);
|
assert!(verify_commitment_is_in_state(new_commitment1, &seq_client).await);
|
||||||
|
|
||||||
let new_commitment2 = wallet_storage
|
let new_commitment2 = wallet_storage
|
||||||
.get_private_account_commitment(&recipient_addr)
|
.get_private_account_commitment(&recipient_account_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(verify_commitment_is_in_state(new_commitment2, &seq_client).await);
|
assert!(verify_commitment_is_in_state(new_commitment2, &seq_client).await);
|
||||||
|
|
||||||
// Transfer additional 7 tokens from `supply_acc` to the account at address `recipient_addr`
|
// Transfer additional 7 tokens from `supply_acc` to the account at account_id `recipient_account_id`
|
||||||
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
||||||
from: make_private_account_input_from_str(&supply_addr.to_string()),
|
from: make_private_account_input_from_str(&supply_account_id.to_string()),
|
||||||
to: Some(make_private_account_input_from_str(
|
to: Some(make_private_account_input_from_str(
|
||||||
&recipient_addr.to_string(),
|
&recipient_account_id.to_string(),
|
||||||
)),
|
)),
|
||||||
to_npk: None,
|
to_npk: None,
|
||||||
to_ipk: None,
|
to_ipk: None,
|
||||||
@ -574,12 +583,12 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let new_commitment1 = wallet_storage
|
let new_commitment1 = wallet_storage
|
||||||
.get_private_account_commitment(&supply_addr)
|
.get_private_account_commitment(&supply_account_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(verify_commitment_is_in_state(new_commitment1, &seq_client).await);
|
assert!(verify_commitment_is_in_state(new_commitment1, &seq_client).await);
|
||||||
|
|
||||||
let new_commitment2 = wallet_storage
|
let new_commitment2 = wallet_storage
|
||||||
.get_private_account_commitment(&recipient_addr)
|
.get_private_account_commitment(&recipient_account_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(verify_commitment_is_in_state(new_commitment2, &seq_client).await);
|
assert!(verify_commitment_is_in_state(new_commitment2, &seq_client).await);
|
||||||
}
|
}
|
||||||
@ -593,7 +602,7 @@ 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,
|
account_id: definition_account_id,
|
||||||
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
||||||
NewSubcommand::Public {},
|
NewSubcommand::Public {},
|
||||||
)))
|
)))
|
||||||
@ -603,18 +612,19 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
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 {
|
||||||
wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
account_id: supply_account_id,
|
||||||
NewSubcommand::Private {},
|
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
||||||
)))
|
NewSubcommand::Private {},
|
||||||
.await
|
)))
|
||||||
.unwrap()
|
.await
|
||||||
|
.unwrap()
|
||||||
else {
|
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,
|
account_id: recipient_account_id,
|
||||||
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
||||||
NewSubcommand::Private {},
|
NewSubcommand::Private {},
|
||||||
)))
|
)))
|
||||||
@ -626,8 +636,10 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
|
|
||||||
// Create new token
|
// Create new token
|
||||||
let subcommand = TokenProgramAgnosticSubcommand::New {
|
let subcommand = TokenProgramAgnosticSubcommand::New {
|
||||||
definition_addr: make_public_account_input_from_str(&definition_addr.to_string()),
|
definition_account_id: make_public_account_input_from_str(
|
||||||
supply_addr: make_private_account_input_from_str(&supply_addr.to_string()),
|
&definition_account_id.to_string(),
|
||||||
|
),
|
||||||
|
supply_account_id: make_private_account_input_from_str(&supply_account_id.to_string()),
|
||||||
name: "A NAME".to_string(),
|
name: "A NAME".to_string(),
|
||||||
total_supply: 37,
|
total_supply: 37,
|
||||||
};
|
};
|
||||||
@ -643,7 +655,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
|
|
||||||
// Check the status of the token definition account is the expected after the execution
|
// Check the status of the token definition account is the expected after the execution
|
||||||
let definition_acc = seq_client
|
let definition_acc = seq_client
|
||||||
.get_account(definition_addr.to_string())
|
.get_account(definition_account_id.to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.account;
|
.account;
|
||||||
@ -664,19 +676,19 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let new_commitment1 = wallet_storage
|
let new_commitment1 = wallet_storage
|
||||||
.get_private_account_commitment(&supply_addr)
|
.get_private_account_commitment(&supply_account_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(verify_commitment_is_in_state(new_commitment1, &seq_client).await);
|
assert!(verify_commitment_is_in_state(new_commitment1, &seq_client).await);
|
||||||
|
|
||||||
let (recipient_keys, _) = wallet_storage
|
let (recipient_keys, _) = wallet_storage
|
||||||
.storage
|
.storage
|
||||||
.user_data
|
.user_data
|
||||||
.get_private_account(&recipient_addr)
|
.get_private_account(&recipient_account_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Transfer 7 tokens from `supply_acc` to the account at address `recipient_addr`
|
// Transfer 7 tokens from `supply_acc` to the account at account_id `recipient_account_id`
|
||||||
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
||||||
from: make_private_account_input_from_str(&supply_addr.to_string()),
|
from: make_private_account_input_from_str(&supply_account_id.to_string()),
|
||||||
to: None,
|
to: None,
|
||||||
to_npk: Some(hex::encode(recipient_keys.nullifer_public_key.0)),
|
to_npk: Some(hex::encode(recipient_keys.nullifer_public_key.0)),
|
||||||
to_ipk: Some(hex::encode(
|
to_ipk: Some(hex::encode(
|
||||||
@ -706,12 +718,12 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let new_commitment1 = wallet_storage
|
let new_commitment1 = wallet_storage
|
||||||
.get_private_account_commitment(&supply_addr)
|
.get_private_account_commitment(&supply_account_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(verify_commitment_is_in_state(new_commitment1, &seq_client).await);
|
assert!(verify_commitment_is_in_state(new_commitment1, &seq_client).await);
|
||||||
|
|
||||||
let new_commitment2 = wallet_storage
|
let new_commitment2 = wallet_storage
|
||||||
.get_private_account_commitment(&recipient_addr)
|
.get_private_account_commitment(&recipient_account_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(verify_commitment_is_in_state(new_commitment2, &seq_client).await);
|
assert!(verify_commitment_is_in_state(new_commitment2, &seq_client).await);
|
||||||
}
|
}
|
||||||
@ -725,7 +737,7 @@ 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,
|
account_id: definition_account_id,
|
||||||
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
||||||
NewSubcommand::Public {},
|
NewSubcommand::Public {},
|
||||||
)))
|
)))
|
||||||
@ -735,18 +747,19 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
panic!("invalid subcommand return value");
|
panic!("invalid subcommand return value");
|
||||||
};
|
};
|
||||||
// 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 {
|
||||||
wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
account_id: supply_account_id,
|
||||||
NewSubcommand::Public {},
|
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
||||||
)))
|
NewSubcommand::Public {},
|
||||||
.await
|
)))
|
||||||
.unwrap()
|
.await
|
||||||
|
.unwrap()
|
||||||
else {
|
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,
|
account_id: recipient_account_id,
|
||||||
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
||||||
NewSubcommand::Private {},
|
NewSubcommand::Private {},
|
||||||
)))
|
)))
|
||||||
@ -758,8 +771,10 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
|
|
||||||
// Create new token
|
// Create new token
|
||||||
let subcommand = TokenProgramAgnosticSubcommand::New {
|
let subcommand = TokenProgramAgnosticSubcommand::New {
|
||||||
definition_addr: make_public_account_input_from_str(&definition_addr.to_string()),
|
definition_account_id: make_public_account_input_from_str(
|
||||||
supply_addr: make_public_account_input_from_str(&supply_addr.to_string()),
|
&definition_account_id.to_string(),
|
||||||
|
),
|
||||||
|
supply_account_id: make_public_account_input_from_str(&supply_account_id.to_string()),
|
||||||
name: "A NAME".to_string(),
|
name: "A NAME".to_string(),
|
||||||
total_supply: 37,
|
total_supply: 37,
|
||||||
};
|
};
|
||||||
@ -775,7 +790,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
|
|
||||||
// Check the status of the token definition account is the expected after the execution
|
// Check the status of the token definition account is the expected after the execution
|
||||||
let definition_acc = seq_client
|
let definition_acc = seq_client
|
||||||
.get_account(definition_addr.to_string())
|
.get_account(definition_account_id.to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.account;
|
.account;
|
||||||
@ -790,11 +805,11 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Transfer 7 tokens from `supply_acc` to the account at address `recipient_addr`
|
// Transfer 7 tokens from `supply_acc` to the account at account_id `recipient_account_id`
|
||||||
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
||||||
from: make_public_account_input_from_str(&supply_addr.to_string()),
|
from: make_public_account_input_from_str(&supply_account_id.to_string()),
|
||||||
to: Some(make_private_account_input_from_str(
|
to: Some(make_private_account_input_from_str(
|
||||||
&recipient_addr.to_string(),
|
&recipient_account_id.to_string(),
|
||||||
)),
|
)),
|
||||||
to_npk: None,
|
to_npk: None,
|
||||||
to_ipk: None,
|
to_ipk: None,
|
||||||
@ -814,15 +829,15 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let new_commitment2 = wallet_storage
|
let new_commitment2 = wallet_storage
|
||||||
.get_private_account_commitment(&recipient_addr)
|
.get_private_account_commitment(&recipient_account_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(verify_commitment_is_in_state(new_commitment2, &seq_client).await);
|
assert!(verify_commitment_is_in_state(new_commitment2, &seq_client).await);
|
||||||
|
|
||||||
// Transfer additional 7 tokens from `supply_acc` to the account at address `recipient_addr`
|
// Transfer additional 7 tokens from `supply_acc` to the account at account_id `recipient_account_id`
|
||||||
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
||||||
from: make_public_account_input_from_str(&supply_addr.to_string()),
|
from: make_public_account_input_from_str(&supply_account_id.to_string()),
|
||||||
to: Some(make_private_account_input_from_str(
|
to: Some(make_private_account_input_from_str(
|
||||||
&recipient_addr.to_string(),
|
&recipient_account_id.to_string(),
|
||||||
)),
|
)),
|
||||||
to_npk: None,
|
to_npk: None,
|
||||||
to_ipk: None,
|
to_ipk: None,
|
||||||
@ -842,7 +857,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let new_commitment2 = wallet_storage
|
let new_commitment2 = wallet_storage
|
||||||
.get_private_account_commitment(&recipient_addr)
|
.get_private_account_commitment(&recipient_account_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(verify_commitment_is_in_state(new_commitment2, &seq_client).await);
|
assert!(verify_commitment_is_in_state(new_commitment2, &seq_client).await);
|
||||||
}
|
}
|
||||||
@ -856,7 +871,7 @@ 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,
|
account_id: definition_account_id,
|
||||||
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
||||||
NewSubcommand::Public {},
|
NewSubcommand::Public {},
|
||||||
)))
|
)))
|
||||||
@ -866,18 +881,19 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
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 {
|
||||||
wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
account_id: supply_account_id,
|
||||||
NewSubcommand::Private {},
|
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
||||||
)))
|
NewSubcommand::Private {},
|
||||||
.await
|
)))
|
||||||
.unwrap()
|
.await
|
||||||
|
.unwrap()
|
||||||
else {
|
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,
|
account_id: recipient_account_id,
|
||||||
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
||||||
NewSubcommand::Public {},
|
NewSubcommand::Public {},
|
||||||
)))
|
)))
|
||||||
@ -889,8 +905,10 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
|
|
||||||
// Create new token
|
// Create new token
|
||||||
let subcommand = TokenProgramAgnosticSubcommand::New {
|
let subcommand = TokenProgramAgnosticSubcommand::New {
|
||||||
definition_addr: make_public_account_input_from_str(&definition_addr.to_string()),
|
definition_account_id: make_public_account_input_from_str(
|
||||||
supply_addr: make_private_account_input_from_str(&supply_addr.to_string()),
|
&definition_account_id.to_string(),
|
||||||
|
),
|
||||||
|
supply_account_id: make_private_account_input_from_str(&supply_account_id.to_string()),
|
||||||
name: "A NAME".to_string(),
|
name: "A NAME".to_string(),
|
||||||
total_supply: 37,
|
total_supply: 37,
|
||||||
};
|
};
|
||||||
@ -906,7 +924,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
|
|
||||||
// Check the status of the token definition account is the expected after the execution
|
// Check the status of the token definition account is the expected after the execution
|
||||||
let definition_acc = seq_client
|
let definition_acc = seq_client
|
||||||
.get_account(definition_addr.to_string())
|
.get_account(definition_account_id.to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.account;
|
.account;
|
||||||
@ -927,15 +945,15 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let new_commitment1 = wallet_storage
|
let new_commitment1 = wallet_storage
|
||||||
.get_private_account_commitment(&supply_addr)
|
.get_private_account_commitment(&supply_account_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(verify_commitment_is_in_state(new_commitment1, &seq_client).await);
|
assert!(verify_commitment_is_in_state(new_commitment1, &seq_client).await);
|
||||||
|
|
||||||
// Transfer 7 tokens from `supply_acc` to the account at address `recipient_addr`
|
// Transfer 7 tokens from `supply_acc` to the account at account_id `recipient_account_id`
|
||||||
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
||||||
from: make_private_account_input_from_str(&supply_addr.to_string()),
|
from: make_private_account_input_from_str(&supply_account_id.to_string()),
|
||||||
to: Some(make_public_account_input_from_str(
|
to: Some(make_public_account_input_from_str(
|
||||||
&recipient_addr.to_string(),
|
&recipient_account_id.to_string(),
|
||||||
)),
|
)),
|
||||||
to_npk: None,
|
to_npk: None,
|
||||||
to_ipk: None,
|
to_ipk: None,
|
||||||
@ -955,15 +973,15 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let new_commitment1 = wallet_storage
|
let new_commitment1 = wallet_storage
|
||||||
.get_private_account_commitment(&supply_addr)
|
.get_private_account_commitment(&supply_account_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(verify_commitment_is_in_state(new_commitment1, &seq_client).await);
|
assert!(verify_commitment_is_in_state(new_commitment1, &seq_client).await);
|
||||||
|
|
||||||
// Transfer additional 7 tokens from `supply_acc` to the account at address `recipient_addr`
|
// Transfer additional 7 tokens from `supply_acc` to the account at account_id `recipient_account_id`
|
||||||
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
||||||
from: make_private_account_input_from_str(&supply_addr.to_string()),
|
from: make_private_account_input_from_str(&supply_account_id.to_string()),
|
||||||
to: Some(make_public_account_input_from_str(
|
to: Some(make_public_account_input_from_str(
|
||||||
&recipient_addr.to_string(),
|
&recipient_account_id.to_string(),
|
||||||
)),
|
)),
|
||||||
to_npk: None,
|
to_npk: None,
|
||||||
to_ipk: None,
|
to_ipk: None,
|
||||||
@ -983,7 +1001,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let new_commitment1 = wallet_storage
|
let new_commitment1 = wallet_storage
|
||||||
.get_private_account_commitment(&supply_addr)
|
.get_private_account_commitment(&supply_account_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(verify_commitment_is_in_state(new_commitment1, &seq_client).await);
|
assert!(verify_commitment_is_in_state(new_commitment1, &seq_client).await);
|
||||||
}
|
}
|
||||||
@ -991,8 +1009,8 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
#[nssa_integration_test]
|
#[nssa_integration_test]
|
||||||
pub async fn test_success_private_transfer_to_another_owned_account() {
|
pub async fn test_success_private_transfer_to_another_owned_account() {
|
||||||
info!("########## test_success_private_transfer_to_another_owned_account ##########");
|
info!("########## test_success_private_transfer_to_another_owned_account ##########");
|
||||||
let from: Address = ACC_SENDER_PRIVATE.parse().unwrap();
|
let from: AccountId = ACC_SENDER_PRIVATE.parse().unwrap();
|
||||||
let to: Address = ACC_RECEIVER_PRIVATE.parse().unwrap();
|
let to: AccountId = ACC_RECEIVER_PRIVATE.parse().unwrap();
|
||||||
|
|
||||||
let command = Command::AuthTransfer(AuthTransferSubcommand::Send {
|
let command = Command::AuthTransfer(AuthTransferSubcommand::Send {
|
||||||
from: make_private_account_input_from_str(&from.to_string()),
|
from: make_private_account_input_from_str(&from.to_string()),
|
||||||
@ -1027,7 +1045,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
#[nssa_integration_test]
|
#[nssa_integration_test]
|
||||||
pub async fn test_success_private_transfer_to_another_foreign_account() {
|
pub async fn test_success_private_transfer_to_another_foreign_account() {
|
||||||
info!("########## test_success_private_transfer_to_another_foreign_account ##########");
|
info!("########## test_success_private_transfer_to_another_foreign_account ##########");
|
||||||
let from: Address = ACC_SENDER_PRIVATE.parse().unwrap();
|
let from: AccountId = ACC_SENDER_PRIVATE.parse().unwrap();
|
||||||
let to_npk = NullifierPublicKey([42; 32]);
|
let to_npk = NullifierPublicKey([42; 32]);
|
||||||
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);
|
||||||
@ -1075,12 +1093,15 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
info!(
|
info!(
|
||||||
"########## test_success_private_transfer_to_another_owned_account_claiming_path ##########"
|
"########## test_success_private_transfer_to_another_owned_account_claiming_path ##########"
|
||||||
);
|
);
|
||||||
let from: Address = ACC_SENDER_PRIVATE.parse().unwrap();
|
let from: AccountId = ACC_SENDER_PRIVATE.parse().unwrap();
|
||||||
|
|
||||||
let command = Command::Account(AccountSubcommand::New(NewSubcommand::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 {
|
||||||
|
account_id: to_account_id,
|
||||||
|
} = sub_ret
|
||||||
|
else {
|
||||||
panic!("FAILED TO REGISTER ACCOUNT");
|
panic!("FAILED TO REGISTER ACCOUNT");
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1094,7 +1115,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
.storage
|
.storage
|
||||||
.user_data
|
.user_data
|
||||||
.user_private_accounts
|
.user_private_accounts
|
||||||
.get(&to_addr)
|
.get(&to_account_id)
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@ -1129,7 +1150,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
assert!(verify_commitment_is_in_state(commitment, &seq_client).await);
|
assert!(verify_commitment_is_in_state(commitment, &seq_client).await);
|
||||||
}
|
}
|
||||||
|
|
||||||
let to_res_acc = wallet_storage.get_account_private(&to_addr).unwrap();
|
let to_res_acc = wallet_storage.get_account_private(&to_account_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(to_res_acc.balance, 100);
|
assert_eq!(to_res_acc.balance, 100);
|
||||||
|
|
||||||
@ -1143,12 +1164,15 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
);
|
);
|
||||||
let continious_run_handle = tokio::spawn(wallet::execute_continious_run());
|
let continious_run_handle = tokio::spawn(wallet::execute_continious_run());
|
||||||
|
|
||||||
let from: Address = ACC_SENDER_PRIVATE.parse().unwrap();
|
let from: AccountId = ACC_SENDER_PRIVATE.parse().unwrap();
|
||||||
|
|
||||||
let command = Command::Account(AccountSubcommand::New(NewSubcommand::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 {
|
||||||
|
account_id: to_account_id,
|
||||||
|
} = sub_ret
|
||||||
|
else {
|
||||||
panic!("FAILED TO REGISTER ACCOUNT");
|
panic!("FAILED TO REGISTER ACCOUNT");
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1162,7 +1186,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
.storage
|
.storage
|
||||||
.user_data
|
.user_data
|
||||||
.user_private_accounts
|
.user_private_accounts
|
||||||
.get(&to_addr)
|
.get(&to_account_id)
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@ -1194,7 +1218,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
assert!(verify_commitment_is_in_state(commitment, &seq_client).await);
|
assert!(verify_commitment_is_in_state(commitment, &seq_client).await);
|
||||||
}
|
}
|
||||||
|
|
||||||
let to_res_acc = wallet_storage.get_account_private(&to_addr).unwrap();
|
let to_res_acc = wallet_storage.get_account_private(&to_account_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(to_res_acc.balance, 100);
|
assert_eq!(to_res_acc.balance, 100);
|
||||||
|
|
||||||
@ -1206,8 +1230,8 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
#[nssa_integration_test]
|
#[nssa_integration_test]
|
||||||
pub async fn test_success_deshielded_transfer_to_another_account() {
|
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: AccountId = ACC_SENDER_PRIVATE.parse().unwrap();
|
||||||
let to: Address = ACC_RECEIVER.parse().unwrap();
|
let to: AccountId = ACC_RECEIVER.parse().unwrap();
|
||||||
|
|
||||||
let command = Command::AuthTransfer(AuthTransferSubcommand::Send {
|
let command = Command::AuthTransfer(AuthTransferSubcommand::Send {
|
||||||
from: make_private_account_input_from_str(&from.to_string()),
|
from: make_private_account_input_from_str(&from.to_string()),
|
||||||
@ -1255,8 +1279,8 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
#[nssa_integration_test]
|
#[nssa_integration_test]
|
||||||
pub async fn test_success_shielded_transfer_to_another_owned_account() {
|
pub async fn test_success_shielded_transfer_to_another_owned_account() {
|
||||||
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: AccountId = ACC_SENDER.parse().unwrap();
|
||||||
let to: Address = ACC_RECEIVER_PRIVATE.parse().unwrap();
|
let to: AccountId = ACC_RECEIVER_PRIVATE.parse().unwrap();
|
||||||
|
|
||||||
let command = Command::AuthTransfer(AuthTransferSubcommand::Send {
|
let command = Command::AuthTransfer(AuthTransferSubcommand::Send {
|
||||||
from: make_public_account_input_from_str(&from.to_string()),
|
from: make_public_account_input_from_str(&from.to_string()),
|
||||||
@ -1300,7 +1324,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
let to_npk = NullifierPublicKey([42; 32]);
|
let to_npk = NullifierPublicKey([42; 32]);
|
||||||
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 from: Address = ACC_SENDER.parse().unwrap();
|
let from: AccountId = ACC_SENDER.parse().unwrap();
|
||||||
|
|
||||||
let command = Command::AuthTransfer(AuthTransferSubcommand::Send {
|
let command = Command::AuthTransfer(AuthTransferSubcommand::Send {
|
||||||
from: make_public_account_input_from_str(&from.to_string()),
|
from: make_public_account_input_from_str(&from.to_string()),
|
||||||
@ -1342,11 +1366,11 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
#[nssa_integration_test]
|
#[nssa_integration_test]
|
||||||
pub async fn test_pinata() {
|
pub async fn test_pinata() {
|
||||||
info!("########## test_pinata ##########");
|
info!("########## test_pinata ##########");
|
||||||
let pinata_addr = PINATA_BASE58;
|
let pinata_account_id = PINATA_BASE58;
|
||||||
let pinata_prize = 150;
|
let pinata_prize = 150;
|
||||||
let solution = 989106;
|
let solution = 989106;
|
||||||
let command = Command::Pinata(PinataProgramAgnosticSubcommand::Claim {
|
let command = Command::Pinata(PinataProgramAgnosticSubcommand::Claim {
|
||||||
to_addr: make_public_account_input_from_str(ACC_SENDER),
|
to_account_id: make_public_account_input_from_str(ACC_SENDER),
|
||||||
solution,
|
solution,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1355,7 +1379,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
let seq_client = SequencerClient::new(wallet_config.sequencer_addr.clone()).unwrap();
|
let seq_client = SequencerClient::new(wallet_config.sequencer_addr.clone()).unwrap();
|
||||||
|
|
||||||
let pinata_balance_pre = seq_client
|
let pinata_balance_pre = seq_client
|
||||||
.get_account_balance(pinata_addr.to_string())
|
.get_account_balance(pinata_account_id.to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.balance;
|
.balance;
|
||||||
@ -1367,7 +1391,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
|
|
||||||
info!("Checking correct balance move");
|
info!("Checking correct balance move");
|
||||||
let pinata_balance_post = seq_client
|
let pinata_balance_post = seq_client
|
||||||
.get_account_balance(pinata_addr.to_string())
|
.get_account_balance(pinata_account_id.to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.balance;
|
.balance;
|
||||||
@ -1403,10 +1427,10 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
// We pass an uninitialized account and we expect after execution to be owned by the data
|
// We pass an uninitialized account and we expect after execution to be owned by the data
|
||||||
// changer program (NSSA account claiming mechanism) with data equal to [0] (due to program logic)
|
// changer program (NSSA account claiming mechanism) with data equal to [0] (due to program logic)
|
||||||
let data_changer = Program::new(bytecode).unwrap();
|
let data_changer = Program::new(bytecode).unwrap();
|
||||||
let address: Address = "11".repeat(16).parse().unwrap();
|
let account_id: AccountId = "11".repeat(16).parse().unwrap();
|
||||||
let message = nssa::public_transaction::Message::try_new(
|
let message = nssa::public_transaction::Message::try_new(
|
||||||
data_changer.id(),
|
data_changer.id(),
|
||||||
vec![address],
|
vec![account_id],
|
||||||
vec![],
|
vec![],
|
||||||
(),
|
(),
|
||||||
)
|
)
|
||||||
@ -1419,7 +1443,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
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 post_state_account = seq_client
|
let post_state_account = seq_client
|
||||||
.get_account(address.to_string())
|
.get_account(account_id.to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.account;
|
.account;
|
||||||
@ -1435,14 +1459,14 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
pub async fn test_authenticated_transfer_initialize_function() {
|
pub async fn test_authenticated_transfer_initialize_function() {
|
||||||
info!("########## test initialize account for authenticated transfer ##########");
|
info!("########## test initialize account for authenticated transfer ##########");
|
||||||
let command = Command::Account(AccountSubcommand::New(NewSubcommand::Public {}));
|
let command = Command::Account(AccountSubcommand::New(NewSubcommand::Public {}));
|
||||||
let SubcommandReturnValue::RegisterAccount { addr } =
|
let SubcommandReturnValue::RegisterAccount { account_id } =
|
||||||
wallet::execute_subcommand(command).await.unwrap()
|
wallet::execute_subcommand(command).await.unwrap()
|
||||||
else {
|
else {
|
||||||
panic!("Error creating account");
|
panic!("Error creating account");
|
||||||
};
|
};
|
||||||
|
|
||||||
let command = Command::AuthTransfer(AuthTransferSubcommand::Init {
|
let command = Command::AuthTransfer(AuthTransferSubcommand::Init {
|
||||||
addr: make_public_account_input_from_str(&addr.to_string()),
|
account_id: make_public_account_input_from_str(&account_id.to_string()),
|
||||||
});
|
});
|
||||||
wallet::execute_subcommand(command).await.unwrap();
|
wallet::execute_subcommand(command).await.unwrap();
|
||||||
|
|
||||||
@ -1450,7 +1474,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
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();
|
||||||
let account = seq_client
|
let account = seq_client
|
||||||
.get_account(addr.to_string())
|
.get_account(account_id.to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.account;
|
.account;
|
||||||
@ -1470,12 +1494,12 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
#[nssa_integration_test]
|
#[nssa_integration_test]
|
||||||
pub async fn test_pinata_private_receiver() {
|
pub async fn test_pinata_private_receiver() {
|
||||||
info!("########## test_pinata_private_receiver ##########");
|
info!("########## test_pinata_private_receiver ##########");
|
||||||
let pinata_addr = PINATA_BASE58;
|
let pinata_account_id = PINATA_BASE58;
|
||||||
let pinata_prize = 150;
|
let pinata_prize = 150;
|
||||||
let solution = 989106;
|
let solution = 989106;
|
||||||
|
|
||||||
let command = Command::Pinata(PinataProgramAgnosticSubcommand::Claim {
|
let command = Command::Pinata(PinataProgramAgnosticSubcommand::Claim {
|
||||||
to_addr: make_private_account_input_from_str(ACC_SENDER_PRIVATE),
|
to_account_id: make_private_account_input_from_str(ACC_SENDER_PRIVATE),
|
||||||
solution,
|
solution,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1484,7 +1508,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
let seq_client = SequencerClient::new(wallet_config.sequencer_addr.clone()).unwrap();
|
let seq_client = SequencerClient::new(wallet_config.sequencer_addr.clone()).unwrap();
|
||||||
|
|
||||||
let pinata_balance_pre = seq_client
|
let pinata_balance_pre = seq_client
|
||||||
.get_account_balance(pinata_addr.to_string())
|
.get_account_balance(pinata_account_id.to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.balance;
|
.balance;
|
||||||
@ -1500,7 +1524,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
|
|
||||||
info!("Checking correct balance move");
|
info!("Checking correct balance move");
|
||||||
let pinata_balance_post = seq_client
|
let pinata_balance_post = seq_client
|
||||||
.get_account_balance(pinata_addr.to_string())
|
.get_account_balance(pinata_account_id.to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.balance;
|
.balance;
|
||||||
@ -1527,23 +1551,24 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
#[nssa_integration_test]
|
#[nssa_integration_test]
|
||||||
pub async fn test_pinata_private_receiver_new_account() {
|
pub async fn test_pinata_private_receiver_new_account() {
|
||||||
info!("########## test_pinata_private_receiver ##########");
|
info!("########## test_pinata_private_receiver ##########");
|
||||||
let pinata_addr = PINATA_BASE58;
|
let pinata_account_id = PINATA_BASE58;
|
||||||
let pinata_prize = 150;
|
let pinata_prize = 150;
|
||||||
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 {
|
||||||
wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
account_id: winner_account_id,
|
||||||
NewSubcommand::Private {},
|
} = wallet::execute_subcommand(Command::Account(AccountSubcommand::New(
|
||||||
)))
|
NewSubcommand::Private {},
|
||||||
.await
|
)))
|
||||||
.unwrap()
|
.await
|
||||||
|
.unwrap()
|
||||||
else {
|
else {
|
||||||
panic!("invalid subcommand return value");
|
panic!("invalid subcommand return value");
|
||||||
};
|
};
|
||||||
|
|
||||||
let command = Command::Pinata(PinataProgramAgnosticSubcommand::Claim {
|
let command = Command::Pinata(PinataProgramAgnosticSubcommand::Claim {
|
||||||
to_addr: make_private_account_input_from_str(&winner_addr.to_string()),
|
to_account_id: make_private_account_input_from_str(&winner_account_id.to_string()),
|
||||||
solution,
|
solution,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1552,7 +1577,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
let seq_client = SequencerClient::new(wallet_config.sequencer_addr.clone()).unwrap();
|
let seq_client = SequencerClient::new(wallet_config.sequencer_addr.clone()).unwrap();
|
||||||
|
|
||||||
let pinata_balance_pre = seq_client
|
let pinata_balance_pre = seq_client
|
||||||
.get_account_balance(pinata_addr.to_string())
|
.get_account_balance(pinata_account_id.to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.balance;
|
.balance;
|
||||||
@ -1564,7 +1589,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
|
|
||||||
info!("Checking correct balance move");
|
info!("Checking correct balance move");
|
||||||
let pinata_balance_post = seq_client
|
let pinata_balance_post = seq_client
|
||||||
.get_account_balance(pinata_addr.to_string())
|
.get_account_balance(pinata_account_id.to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.balance;
|
.balance;
|
||||||
@ -1576,7 +1601,7 @@ pub fn prepare_function_map() -> HashMap<String, TestFunction> {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let new_commitment1 = wallet_storage
|
let new_commitment1 = wallet_storage
|
||||||
.get_private_account_commitment(&winner_addr)
|
.get_private_account_commitment(&winner_account_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(verify_commitment_is_in_state(new_commitment1, &seq_client).await);
|
assert!(verify_commitment_is_in_state(new_commitment1, &seq_client).await);
|
||||||
|
|
||||||
|
|||||||
@ -2,8 +2,7 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use key_protocol::key_management::ephemeral_key_holder::EphemeralKeyHolder;
|
use key_protocol::key_management::ephemeral_key_holder::EphemeralKeyHolder;
|
||||||
use nssa::{
|
use nssa::{
|
||||||
Account, AccountId, Address, PrivacyPreservingTransaction, PrivateKey, PublicKey,
|
Account, AccountId, PrivacyPreservingTransaction, PrivateKey, PublicKey, PublicTransaction,
|
||||||
PublicTransaction,
|
|
||||||
privacy_preserving_transaction::{self as pptx, circuit},
|
privacy_preserving_transaction::{self as pptx, circuit},
|
||||||
program::Program,
|
program::Program,
|
||||||
public_transaction as putx,
|
public_transaction as putx,
|
||||||
@ -15,7 +14,7 @@ use nssa_core::{
|
|||||||
use sequencer_core::config::{AccountInitialData, CommitmentsInitialData, SequencerConfig};
|
use sequencer_core::config::{AccountInitialData, CommitmentsInitialData, SequencerConfig};
|
||||||
|
|
||||||
pub(crate) struct TpsTestManager {
|
pub(crate) struct TpsTestManager {
|
||||||
public_keypairs: Vec<(PrivateKey, Address)>,
|
public_keypairs: Vec<(PrivateKey, AccountId)>,
|
||||||
target_tps: u64,
|
target_tps: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,8 +28,8 @@ impl TpsTestManager {
|
|||||||
private_key_bytes[..8].copy_from_slice(&i.to_le_bytes());
|
private_key_bytes[..8].copy_from_slice(&i.to_le_bytes());
|
||||||
let private_key = PrivateKey::try_new(private_key_bytes).unwrap();
|
let private_key = PrivateKey::try_new(private_key_bytes).unwrap();
|
||||||
let public_key = PublicKey::new_from_private_key(&private_key);
|
let public_key = PublicKey::new_from_private_key(&private_key);
|
||||||
let address = Address::from(&public_key);
|
let account_id = AccountId::from(&public_key);
|
||||||
(private_key, address)
|
(private_key, account_id)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
Self {
|
Self {
|
||||||
@ -78,8 +77,8 @@ impl TpsTestManager {
|
|||||||
let initial_public_accounts = self
|
let initial_public_accounts = self
|
||||||
.public_keypairs
|
.public_keypairs
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(_, addr)| AccountInitialData {
|
.map(|(_, account_id)| AccountInitialData {
|
||||||
addr: addr.to_string(),
|
account_id: account_id.to_string(),
|
||||||
balance: 10,
|
balance: 10,
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|||||||
@ -65,15 +65,18 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_new_os_random() {
|
fn test_new_os_random() {
|
||||||
// Ensure that a new KeyChain instance can be created without errors.
|
// Ensure that a new KeyChain instance can be created without errors.
|
||||||
let address_key_holder = KeyChain::new_os_random();
|
let account_id_key_holder = KeyChain::new_os_random();
|
||||||
|
|
||||||
// Check that key holder fields are initialized with expected types
|
// Check that key holder fields are initialized with expected types
|
||||||
assert_ne!(address_key_holder.nullifer_public_key.as_ref(), &[0u8; 32]);
|
assert_ne!(
|
||||||
|
account_id_key_holder.nullifer_public_key.as_ref(),
|
||||||
|
&[0u8; 32]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_calculate_shared_secret_receiver() {
|
fn test_calculate_shared_secret_receiver() {
|
||||||
let address_key_holder = KeyChain::new_os_random();
|
let account_id_key_holder = KeyChain::new_os_random();
|
||||||
|
|
||||||
// Generate a random ephemeral public key sender
|
// Generate a random ephemeral public key sender
|
||||||
let mut scalar = [0; 32];
|
let mut scalar = [0; 32];
|
||||||
@ -82,7 +85,7 @@ mod tests {
|
|||||||
|
|
||||||
// Calculate shared secret
|
// Calculate shared secret
|
||||||
let _shared_secret =
|
let _shared_secret =
|
||||||
address_key_holder.calculate_shared_secret_receiver(ephemeral_public_key_sender);
|
account_id_key_holder.calculate_shared_secret_receiver(ephemeral_public_key_sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -99,7 +102,7 @@ mod tests {
|
|||||||
|
|
||||||
let public_key = nssa::PublicKey::new_from_private_key(&pub_account_signing_key);
|
let public_key = nssa::PublicKey::new_from_private_key(&pub_account_signing_key);
|
||||||
|
|
||||||
let address = nssa::Address::from(&public_key);
|
let account = nssa::AccountId::from(&public_key);
|
||||||
|
|
||||||
println!("======Prerequisites======");
|
println!("======Prerequisites======");
|
||||||
println!();
|
println!();
|
||||||
@ -120,7 +123,7 @@ mod tests {
|
|||||||
|
|
||||||
println!("======Public data======");
|
println!("======Public data======");
|
||||||
println!();
|
println!();
|
||||||
println!("Address{:?}", address.value().to_base58());
|
println!("Account {:?}", account.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())
|
||||||
|
|||||||
@ -24,7 +24,7 @@ pub type IncomingViewingSecretKey = Scalar;
|
|||||||
pub type OutgoingViewingSecretKey = Scalar;
|
pub type OutgoingViewingSecretKey = Scalar;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
///Private key holder. Produces public keys. Can produce address. Can produce shared secret for recepient.
|
///Private key holder. Produces public keys. Can produce account_id. Can produce shared secret for recepient.
|
||||||
pub struct PrivateKeyHolder {
|
pub struct PrivateKeyHolder {
|
||||||
pub nullifier_secret_key: NullifierSecretKey,
|
pub nullifier_secret_key: NullifierSecretKey,
|
||||||
pub(crate) incoming_viewing_secret_key: IncomingViewingSecretKey,
|
pub(crate) incoming_viewing_secret_key: IncomingViewingSecretKey,
|
||||||
|
|||||||
@ -11,20 +11,21 @@ pub type PublicKey = AffinePoint;
|
|||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct NSSAUserData {
|
pub struct NSSAUserData {
|
||||||
///Map for all user public accounts
|
///Map for all user public accounts
|
||||||
pub pub_account_signing_keys: HashMap<nssa::Address, nssa::PrivateKey>,
|
pub pub_account_signing_keys: HashMap<nssa::AccountId, nssa::PrivateKey>,
|
||||||
///Map for all user private accounts
|
///Map for all user private accounts
|
||||||
pub user_private_accounts: HashMap<nssa::Address, (KeyChain, nssa_core::account::Account)>,
|
pub user_private_accounts: HashMap<nssa::AccountId, (KeyChain, nssa_core::account::Account)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NSSAUserData {
|
impl NSSAUserData {
|
||||||
fn valid_public_key_transaction_pairing_check(
|
fn valid_public_key_transaction_pairing_check(
|
||||||
accounts_keys_map: &HashMap<nssa::Address, nssa::PrivateKey>,
|
accounts_keys_map: &HashMap<nssa::AccountId, nssa::PrivateKey>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let mut check_res = true;
|
let mut check_res = true;
|
||||||
for (addr, key) in accounts_keys_map {
|
for (account_id, key) in accounts_keys_map {
|
||||||
let expected_addr = nssa::Address::from(&nssa::PublicKey::new_from_private_key(key));
|
let expected_account_id =
|
||||||
if &expected_addr != addr {
|
nssa::AccountId::from(&nssa::PublicKey::new_from_private_key(key));
|
||||||
println!("{}, {}", expected_addr, addr);
|
if &expected_account_id != account_id {
|
||||||
|
println!("{}, {}", expected_account_id, account_id);
|
||||||
check_res = false;
|
check_res = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -32,13 +33,13 @@ impl NSSAUserData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn valid_private_key_transaction_pairing_check(
|
fn valid_private_key_transaction_pairing_check(
|
||||||
accounts_keys_map: &HashMap<nssa::Address, (KeyChain, nssa_core::account::Account)>,
|
accounts_keys_map: &HashMap<nssa::AccountId, (KeyChain, nssa_core::account::Account)>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let mut check_res = true;
|
let mut check_res = true;
|
||||||
for (addr, (key, _)) in accounts_keys_map {
|
for (account_id, (key, _)) in accounts_keys_map {
|
||||||
let expected_addr = nssa::Address::from(&key.nullifer_public_key);
|
let expected_account_id = nssa::AccountId::from(&key.nullifer_public_key);
|
||||||
if expected_addr != *addr {
|
if expected_account_id != *account_id {
|
||||||
println!("{}, {}", expected_addr, addr);
|
println!("{}, {}", expected_account_id, account_id);
|
||||||
check_res = false;
|
check_res = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,18 +47,18 @@ impl NSSAUserData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_with_accounts(
|
pub fn new_with_accounts(
|
||||||
accounts_keys: HashMap<nssa::Address, nssa::PrivateKey>,
|
accounts_keys: HashMap<nssa::AccountId, nssa::PrivateKey>,
|
||||||
accounts_key_chains: HashMap<nssa::Address, (KeyChain, nssa_core::account::Account)>,
|
accounts_key_chains: HashMap<nssa::AccountId, (KeyChain, nssa_core::account::Account)>,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
if !Self::valid_public_key_transaction_pairing_check(&accounts_keys) {
|
if !Self::valid_public_key_transaction_pairing_check(&accounts_keys) {
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"Key transaction pairing check not satisfied, there is addresses, which is not derived from keys"
|
"Key transaction pairing check not satisfied, there is account_ids, which is not derived from keys"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !Self::valid_private_key_transaction_pairing_check(&accounts_key_chains) {
|
if !Self::valid_private_key_transaction_pairing_check(&accounts_key_chains) {
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"Key transaction pairing check not satisfied, there is addresses, which is not derived from keys"
|
"Key transaction pairing check not satisfied, there is account_ids, which is not derived from keys"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,51 +70,55 @@ impl NSSAUserData {
|
|||||||
|
|
||||||
/// Generated new private key for public transaction signatures
|
/// Generated new private key for public transaction signatures
|
||||||
///
|
///
|
||||||
/// Returns the address of new account
|
/// Returns the account_id of new account
|
||||||
pub fn generate_new_public_transaction_private_key(&mut self) -> nssa::Address {
|
pub fn generate_new_public_transaction_private_key(&mut self) -> nssa::AccountId {
|
||||||
let private_key = nssa::PrivateKey::new_os_random();
|
let private_key = nssa::PrivateKey::new_os_random();
|
||||||
let address = nssa::Address::from(&nssa::PublicKey::new_from_private_key(&private_key));
|
let account_id =
|
||||||
|
nssa::AccountId::from(&nssa::PublicKey::new_from_private_key(&private_key));
|
||||||
|
|
||||||
self.pub_account_signing_keys.insert(address, private_key);
|
self.pub_account_signing_keys
|
||||||
|
.insert(account_id, private_key);
|
||||||
|
|
||||||
address
|
account_id
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the signing key for public transaction signatures
|
/// Returns the signing key for public transaction signatures
|
||||||
pub fn get_pub_account_signing_key(
|
pub fn get_pub_account_signing_key(
|
||||||
&self,
|
&self,
|
||||||
address: &nssa::Address,
|
account_id: &nssa::AccountId,
|
||||||
) -> Option<&nssa::PrivateKey> {
|
) -> Option<&nssa::PrivateKey> {
|
||||||
self.pub_account_signing_keys.get(address)
|
self.pub_account_signing_keys.get(account_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generated new private key for privacy preserving transactions
|
/// Generated new private key for privacy preserving transactions
|
||||||
///
|
///
|
||||||
/// Returns the address of new account
|
/// Returns the account_id of new account
|
||||||
pub fn generate_new_privacy_preserving_transaction_key_chain(&mut self) -> nssa::Address {
|
pub fn generate_new_privacy_preserving_transaction_key_chain(&mut self) -> nssa::AccountId {
|
||||||
let key_chain = KeyChain::new_os_random();
|
let key_chain = KeyChain::new_os_random();
|
||||||
let address = nssa::Address::from(&key_chain.nullifer_public_key);
|
let account_id = nssa::AccountId::from(&key_chain.nullifer_public_key);
|
||||||
|
|
||||||
self.user_private_accounts
|
self.user_private_accounts.insert(
|
||||||
.insert(address, (key_chain, nssa_core::account::Account::default()));
|
account_id,
|
||||||
|
(key_chain, nssa_core::account::Account::default()),
|
||||||
|
);
|
||||||
|
|
||||||
address
|
account_id
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the signing key for public transaction signatures
|
/// Returns the signing key for public transaction signatures
|
||||||
pub fn get_private_account(
|
pub fn get_private_account(
|
||||||
&self,
|
&self,
|
||||||
address: &nssa::Address,
|
account_id: &nssa::AccountId,
|
||||||
) -> Option<&(KeyChain, nssa_core::account::Account)> {
|
) -> Option<&(KeyChain, nssa_core::account::Account)> {
|
||||||
self.user_private_accounts.get(address)
|
self.user_private_accounts.get(account_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the signing key for public transaction signatures
|
/// Returns the signing key for public transaction signatures
|
||||||
pub fn get_private_account_mut(
|
pub fn get_private_account_mut(
|
||||||
&mut self,
|
&mut self,
|
||||||
address: &nssa::Address,
|
account_id: &nssa::AccountId,
|
||||||
) -> Option<&mut (KeyChain, nssa_core::account::Account)> {
|
) -> Option<&mut (KeyChain, nssa_core::account::Account)> {
|
||||||
self.user_private_accounts.get_mut(address)
|
self.user_private_accounts.get_mut(account_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,12 @@
|
|||||||
use crate::{address::Address, program::ProgramId};
|
use crate::program::ProgramId;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[cfg(feature = "host")]
|
||||||
|
use std::{fmt::Display, str::FromStr};
|
||||||
|
|
||||||
|
#[cfg(feature = "host")]
|
||||||
|
use base58::{FromBase58, ToBase58};
|
||||||
|
|
||||||
pub type Nonce = u128;
|
pub type Nonce = u128;
|
||||||
pub type Data = Vec<u8>;
|
pub type Data = Vec<u8>;
|
||||||
|
|
||||||
@ -14,8 +20,6 @@ pub struct Account {
|
|||||||
pub nonce: Nonce,
|
pub nonce: Nonce,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type AccountId = Address;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
#[cfg_attr(any(feature = "host", test), derive(Debug, PartialEq, Eq))]
|
#[cfg_attr(any(feature = "host", test), derive(Debug, PartialEq, Eq))]
|
||||||
pub struct AccountWithMetadata {
|
pub struct AccountWithMetadata {
|
||||||
@ -35,6 +39,64 @@ impl AccountWithMetadata {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(
|
||||||
|
any(feature = "host", test),
|
||||||
|
derive(Debug, Copy, PartialOrd, Ord, Default)
|
||||||
|
)]
|
||||||
|
pub struct AccountId {
|
||||||
|
value: [u8; 32],
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AccountId {
|
||||||
|
pub fn new(value: [u8; 32]) -> Self {
|
||||||
|
Self { value }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn value(&self) -> &[u8; 32] {
|
||||||
|
&self.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsRef<[u8]> for AccountId {
|
||||||
|
fn as_ref(&self) -> &[u8] {
|
||||||
|
&self.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "host")]
|
||||||
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
pub enum AccountIdError {
|
||||||
|
#[error("invalid base58")]
|
||||||
|
InvalidBase58(#[from] anyhow::Error),
|
||||||
|
#[error("invalid length: expected 32 bytes, got {0}")]
|
||||||
|
InvalidLength(usize),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "host")]
|
||||||
|
impl FromStr for AccountId {
|
||||||
|
type Err = AccountIdError;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
let bytes = s
|
||||||
|
.from_base58()
|
||||||
|
.map_err(|err| anyhow::anyhow!("Invalid base58 err {err:?}"))?;
|
||||||
|
if bytes.len() != 32 {
|
||||||
|
return Err(AccountIdError::InvalidLength(bytes.len()));
|
||||||
|
}
|
||||||
|
let mut value = [0u8; 32];
|
||||||
|
value.copy_from_slice(&bytes);
|
||||||
|
Ok(AccountId { value })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "host")]
|
||||||
|
impl Display for AccountId {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "{}", self.value.to_base58())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::program::DEFAULT_PROGRAM_ID;
|
use crate::program::DEFAULT_PROGRAM_ID;
|
||||||
@ -84,4 +146,32 @@ mod tests {
|
|||||||
assert!(new_acc_with_metadata.is_authorized);
|
assert!(new_acc_with_metadata.is_authorized);
|
||||||
assert_eq!(new_acc_with_metadata.account_id, fingerprint);
|
assert_eq!(new_acc_with_metadata.account_id, fingerprint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_valid_account_id() {
|
||||||
|
let base58_str = "11111111111111111111111111111111";
|
||||||
|
let account_id: AccountId = base58_str.parse().unwrap();
|
||||||
|
assert_eq!(account_id.value, [0u8; 32]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_invalid_base58() {
|
||||||
|
let base58_str = "00".repeat(32); // invalid base58 chars
|
||||||
|
let result = base58_str.parse::<AccountId>().unwrap_err();
|
||||||
|
assert!(matches!(result, AccountIdError::InvalidBase58(_)));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_wrong_length_short() {
|
||||||
|
let base58_str = "11".repeat(31); // 62 chars = 31 bytes
|
||||||
|
let result = base58_str.parse::<AccountId>().unwrap_err();
|
||||||
|
assert!(matches!(result, AccountIdError::InvalidLength(_)));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_wrong_length_long() {
|
||||||
|
let base58_str = "11".repeat(33); // 66 chars = 33 bytes
|
||||||
|
let result = base58_str.parse::<AccountId>().unwrap_err();
|
||||||
|
assert!(matches!(result, AccountIdError::InvalidLength(_)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,98 +0,0 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[cfg(feature = "host")]
|
|
||||||
use std::{fmt::Display, str::FromStr};
|
|
||||||
|
|
||||||
#[cfg(feature = "host")]
|
|
||||||
use base58::{FromBase58, ToBase58};
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
|
|
||||||
#[cfg_attr(
|
|
||||||
any(feature = "host", test),
|
|
||||||
derive(Debug, Copy, PartialOrd, Ord, Default)
|
|
||||||
)]
|
|
||||||
pub struct Address {
|
|
||||||
value: [u8; 32],
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Address {
|
|
||||||
pub fn new(value: [u8; 32]) -> Self {
|
|
||||||
Self { value }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn value(&self) -> &[u8; 32] {
|
|
||||||
&self.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AsRef<[u8]> for Address {
|
|
||||||
fn as_ref(&self) -> &[u8] {
|
|
||||||
&self.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "host")]
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
|
||||||
pub enum AddressError {
|
|
||||||
#[error("invalid base58")]
|
|
||||||
InvalidBase58(#[from] anyhow::Error),
|
|
||||||
#[error("invalid length: expected 32 bytes, got {0}")]
|
|
||||||
InvalidLength(usize),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "host")]
|
|
||||||
impl FromStr for Address {
|
|
||||||
type Err = AddressError;
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
||||||
let bytes = s
|
|
||||||
.from_base58()
|
|
||||||
.map_err(|err| anyhow::anyhow!("Invalid base58 err {err:?}"))?;
|
|
||||||
if bytes.len() != 32 {
|
|
||||||
return Err(AddressError::InvalidLength(bytes.len()));
|
|
||||||
}
|
|
||||||
let mut value = [0u8; 32];
|
|
||||||
value.copy_from_slice(&bytes);
|
|
||||||
Ok(Address { value })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "host")]
|
|
||||||
impl Display for Address {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
write!(f, "{}", self.value.to_base58())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
|
|
||||||
use super::{Address, AddressError};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn parse_valid_address() {
|
|
||||||
let base58_str = "11111111111111111111111111111111";
|
|
||||||
let addr: Address = base58_str.parse().unwrap();
|
|
||||||
assert_eq!(addr.value, [0u8; 32]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn parse_invalid_base58() {
|
|
||||||
let base58_str = "00".repeat(32); // invalid base58 chars
|
|
||||||
let result = base58_str.parse::<Address>().unwrap_err();
|
|
||||||
assert!(matches!(result, AddressError::InvalidBase58(_)));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn parse_wrong_length_short() {
|
|
||||||
let base58_str = "11".repeat(31); // 62 chars = 31 bytes
|
|
||||||
let result = base58_str.parse::<Address>().unwrap_err();
|
|
||||||
assert!(matches!(result, AddressError::InvalidLength(_)));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn parse_wrong_length_long() {
|
|
||||||
let base58_str = "11".repeat(33); // 66 chars = 33 bytes
|
|
||||||
let result = base58_str.parse::<Address>().unwrap_err();
|
|
||||||
assert!(matches!(result, AddressError::InvalidLength(_)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -6,8 +6,6 @@ pub mod encryption;
|
|||||||
mod nullifier;
|
mod nullifier;
|
||||||
pub mod program;
|
pub mod program;
|
||||||
|
|
||||||
pub mod address;
|
|
||||||
|
|
||||||
pub use circuit_io::{PrivacyPreservingCircuitInput, PrivacyPreservingCircuitOutput};
|
pub use circuit_io::{PrivacyPreservingCircuitInput, PrivacyPreservingCircuitOutput};
|
||||||
pub use commitment::{
|
pub use commitment::{
|
||||||
Commitment, CommitmentSetDigest, DUMMY_COMMITMENT, DUMMY_COMMITMENT_HASH, MembershipProof,
|
Commitment, CommitmentSetDigest, DUMMY_COMMITMENT, DUMMY_COMMITMENT_HASH, MembershipProof,
|
||||||
|
|||||||
@ -7,7 +7,7 @@ use nssa_core::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Address, PrivacyPreservingTransaction, PublicKey, Signature,
|
AccountId, PrivacyPreservingTransaction, PublicKey, Signature,
|
||||||
error::NssaError,
|
error::NssaError,
|
||||||
privacy_preserving_transaction::{
|
privacy_preserving_transaction::{
|
||||||
circuit::Proof,
|
circuit::Proof,
|
||||||
@ -48,11 +48,11 @@ impl Message {
|
|||||||
pub(crate) fn to_bytes(&self) -> Vec<u8> {
|
pub(crate) fn to_bytes(&self) -> Vec<u8> {
|
||||||
let mut bytes = MESSAGE_ENCODING_PREFIX.to_vec();
|
let mut bytes = MESSAGE_ENCODING_PREFIX.to_vec();
|
||||||
|
|
||||||
// Public addresses
|
// Public account_ids
|
||||||
let public_addresses_len: u32 = self.public_addresses.len() as u32;
|
let public_account_ids_len: u32 = self.public_account_ids.len() as u32;
|
||||||
bytes.extend_from_slice(&public_addresses_len.to_le_bytes());
|
bytes.extend_from_slice(&public_account_ids_len.to_le_bytes());
|
||||||
for address in &self.public_addresses {
|
for account_id in &self.public_account_ids {
|
||||||
bytes.extend_from_slice(address.value());
|
bytes.extend_from_slice(account_id.value());
|
||||||
}
|
}
|
||||||
// Nonces
|
// Nonces
|
||||||
let nonces_len = self.nonces.len() as u32;
|
let nonces_len = self.nonces.len() as u32;
|
||||||
@ -108,14 +108,14 @@ impl Message {
|
|||||||
|
|
||||||
let mut len_bytes = [0u8; 4];
|
let mut len_bytes = [0u8; 4];
|
||||||
|
|
||||||
// Public addresses
|
// Public account_ids
|
||||||
cursor.read_exact(&mut len_bytes)?;
|
cursor.read_exact(&mut len_bytes)?;
|
||||||
let public_addresses_len = u32::from_le_bytes(len_bytes) as usize;
|
let public_account_ids_len = u32::from_le_bytes(len_bytes) as usize;
|
||||||
let mut public_addresses = Vec::with_capacity(public_addresses_len);
|
let mut public_account_ids = Vec::with_capacity(public_account_ids_len);
|
||||||
for _ in 0..public_addresses_len {
|
for _ in 0..public_account_ids_len {
|
||||||
let mut value = [0u8; 32];
|
let mut value = [0u8; 32];
|
||||||
cursor.read_exact(&mut value)?;
|
cursor.read_exact(&mut value)?;
|
||||||
public_addresses.push(Address::new(value))
|
public_account_ids.push(AccountId::new(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nonces
|
// Nonces
|
||||||
@ -164,7 +164,7 @@ impl Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
public_addresses,
|
public_account_ids,
|
||||||
nonces,
|
nonces,
|
||||||
public_post_states,
|
public_post_states,
|
||||||
encrypted_private_post_states,
|
encrypted_private_post_states,
|
||||||
|
|||||||
@ -5,7 +5,7 @@ use std::io::{Cursor, Read};
|
|||||||
use nssa_core::program::ProgramId;
|
use nssa_core::program::ProgramId;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Address, PublicKey, PublicTransaction, Signature,
|
AccountId, PublicKey, PublicTransaction, Signature,
|
||||||
error::NssaError,
|
error::NssaError,
|
||||||
public_transaction::{Message, WitnessSet},
|
public_transaction::{Message, WitnessSet},
|
||||||
};
|
};
|
||||||
@ -16,7 +16,7 @@ const MESSAGE_ENCODING_PREFIX: &[u8; MESSAGE_ENCODING_PREFIX_LEN] =
|
|||||||
|
|
||||||
impl Message {
|
impl Message {
|
||||||
/// Serializes a `Message` into bytes in the following layout:
|
/// Serializes a `Message` into bytes in the following layout:
|
||||||
/// PREFIX || <program_id> (4 bytes LE) * 8 || addresses_len (4 bytes LE) || addresses (32 bytes * N) || nonces_len (4 bytes LE) || nonces (16 bytes LE * M) || instruction_data_len || instruction_data (4 bytes LE * K)
|
/// PREFIX || <program_id> (4 bytes LE) * 8 || account_ids_len (4 bytes LE) || account_ids (32 bytes * N) || nonces_len (4 bytes LE) || nonces (16 bytes LE * M) || instruction_data_len || instruction_data (4 bytes LE * K)
|
||||||
/// Integers and words are encoded in little-endian byte order, and fields appear in the above order.
|
/// Integers and words are encoded in little-endian byte order, and fields appear in the above order.
|
||||||
pub(crate) fn to_bytes(&self) -> Vec<u8> {
|
pub(crate) fn to_bytes(&self) -> Vec<u8> {
|
||||||
let mut bytes = MESSAGE_ENCODING_PREFIX.to_vec();
|
let mut bytes = MESSAGE_ENCODING_PREFIX.to_vec();
|
||||||
@ -24,12 +24,12 @@ impl Message {
|
|||||||
for word in &self.program_id {
|
for word in &self.program_id {
|
||||||
bytes.extend_from_slice(&word.to_le_bytes());
|
bytes.extend_from_slice(&word.to_le_bytes());
|
||||||
}
|
}
|
||||||
// addresses: Vec<[u8;32]>
|
// account_ids: Vec<[u8;32]>
|
||||||
// serialize length as u32 little endian, then all addresses concatenated
|
// serialize length as u32 little endian, then all account_ids concatenated
|
||||||
let addresses_len = self.addresses.len() as u32;
|
let account_ids_len = self.account_ids.len() as u32;
|
||||||
bytes.extend(&addresses_len.to_le_bytes());
|
bytes.extend(&account_ids_len.to_le_bytes());
|
||||||
for addr in &self.addresses {
|
for account_id in &self.account_ids {
|
||||||
bytes.extend_from_slice(addr.value());
|
bytes.extend_from_slice(account_id.value());
|
||||||
}
|
}
|
||||||
// nonces: Vec<u128>
|
// nonces: Vec<u128>
|
||||||
// serialize length as u32 little endian, then all nonces concatenated in LE
|
// serialize length as u32 little endian, then all nonces concatenated in LE
|
||||||
@ -39,7 +39,7 @@ impl Message {
|
|||||||
bytes.extend(&nonce.to_le_bytes());
|
bytes.extend(&nonce.to_le_bytes());
|
||||||
}
|
}
|
||||||
// instruction_data: Vec<u32>
|
// instruction_data: Vec<u32>
|
||||||
// serialize length as u32 little endian, then all addresses concatenated
|
// serialize length as u32 little endian, then all account_ids concatenated
|
||||||
let instr_len = self.instruction_data.len() as u32;
|
let instr_len = self.instruction_data.len() as u32;
|
||||||
bytes.extend(&instr_len.to_le_bytes());
|
bytes.extend(&instr_len.to_le_bytes());
|
||||||
for word in &self.instruction_data {
|
for word in &self.instruction_data {
|
||||||
@ -68,12 +68,12 @@ impl Message {
|
|||||||
}
|
}
|
||||||
this
|
this
|
||||||
};
|
};
|
||||||
let addresses_len = u32_from_cursor(cursor)?;
|
let account_ids_len = u32_from_cursor(cursor)?;
|
||||||
let mut addresses = Vec::with_capacity(addresses_len as usize);
|
let mut account_ids = Vec::with_capacity(account_ids_len as usize);
|
||||||
for _ in 0..addresses_len {
|
for _ in 0..account_ids_len {
|
||||||
let mut value = [0u8; 32];
|
let mut value = [0u8; 32];
|
||||||
cursor.read_exact(&mut value)?;
|
cursor.read_exact(&mut value)?;
|
||||||
addresses.push(Address::new(value))
|
account_ids.push(AccountId::new(value))
|
||||||
}
|
}
|
||||||
let nonces_len = u32_from_cursor(cursor)?;
|
let nonces_len = u32_from_cursor(cursor)?;
|
||||||
let mut nonces = Vec::with_capacity(nonces_len as usize);
|
let mut nonces = Vec::with_capacity(nonces_len as usize);
|
||||||
@ -90,7 +90,7 @@ impl Message {
|
|||||||
}
|
}
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
program_id,
|
program_id,
|
||||||
addresses,
|
account_ids,
|
||||||
nonces,
|
nonces,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
})
|
})
|
||||||
|
|||||||
@ -18,7 +18,6 @@ mod signature;
|
|||||||
mod state;
|
mod state;
|
||||||
|
|
||||||
pub use nssa_core::account::{Account, AccountId};
|
pub use nssa_core::account::{Account, AccountId};
|
||||||
pub use nssa_core::address::Address;
|
|
||||||
pub use privacy_preserving_transaction::{
|
pub use privacy_preserving_transaction::{
|
||||||
PrivacyPreservingTransaction, circuit::execute_and_prove,
|
PrivacyPreservingTransaction, circuit::execute_and_prove,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -5,7 +5,7 @@ use nssa_core::{
|
|||||||
};
|
};
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
|
|
||||||
use crate::{Address, error::NssaError};
|
use crate::{AccountId, error::NssaError};
|
||||||
|
|
||||||
pub type ViewTag = u8;
|
pub type ViewTag = u8;
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ impl EncryptedAccountData {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct Message {
|
pub struct Message {
|
||||||
pub(crate) public_addresses: Vec<Address>,
|
pub(crate) public_account_ids: Vec<AccountId>,
|
||||||
pub(crate) nonces: Vec<Nonce>,
|
pub(crate) nonces: Vec<Nonce>,
|
||||||
pub(crate) public_post_states: Vec<Account>,
|
pub(crate) public_post_states: Vec<Account>,
|
||||||
pub encrypted_private_post_states: Vec<EncryptedAccountData>,
|
pub encrypted_private_post_states: Vec<EncryptedAccountData>,
|
||||||
@ -54,7 +54,7 @@ pub struct Message {
|
|||||||
|
|
||||||
impl Message {
|
impl Message {
|
||||||
pub fn try_from_circuit_output(
|
pub fn try_from_circuit_output(
|
||||||
public_addresses: Vec<Address>,
|
public_account_ids: Vec<AccountId>,
|
||||||
nonces: Vec<Nonce>,
|
nonces: Vec<Nonce>,
|
||||||
public_keys: Vec<(
|
public_keys: Vec<(
|
||||||
NullifierPublicKey,
|
NullifierPublicKey,
|
||||||
@ -78,7 +78,7 @@ impl Message {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
public_addresses,
|
public_account_ids,
|
||||||
nonces,
|
nonces,
|
||||||
public_post_states: output.public_post_states,
|
public_post_states: output.public_post_states,
|
||||||
encrypted_private_post_states,
|
encrypted_private_post_states,
|
||||||
@ -100,7 +100,7 @@ pub mod tests {
|
|||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Address,
|
AccountId,
|
||||||
privacy_preserving_transaction::message::{EncryptedAccountData, Message},
|
privacy_preserving_transaction::message::{EncryptedAccountData, Message},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ pub mod tests {
|
|||||||
let npk1 = NullifierPublicKey::from(&nsk1);
|
let npk1 = NullifierPublicKey::from(&nsk1);
|
||||||
let npk2 = NullifierPublicKey::from(&nsk2);
|
let npk2 = NullifierPublicKey::from(&nsk2);
|
||||||
|
|
||||||
let public_addresses = vec![Address::new([1; 32])];
|
let public_account_ids = vec![AccountId::new([1; 32])];
|
||||||
|
|
||||||
let nonces = vec![1, 2, 3];
|
let nonces = vec![1, 2, 3];
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ pub mod tests {
|
|||||||
)];
|
)];
|
||||||
|
|
||||||
Message {
|
Message {
|
||||||
public_addresses: public_addresses.clone(),
|
public_account_ids: public_account_ids.clone(),
|
||||||
nonces: nonces.clone(),
|
nonces: nonces.clone(),
|
||||||
public_post_states: public_post_states.clone(),
|
public_post_states: public_post_states.clone(),
|
||||||
encrypted_private_post_states: encrypted_private_post_states.clone(),
|
encrypted_private_post_states: encrypted_private_post_states.clone(),
|
||||||
|
|||||||
@ -8,7 +8,7 @@ use nssa_core::{
|
|||||||
use crate::error::NssaError;
|
use crate::error::NssaError;
|
||||||
use crate::privacy_preserving_transaction::circuit::Proof;
|
use crate::privacy_preserving_transaction::circuit::Proof;
|
||||||
use crate::privacy_preserving_transaction::message::EncryptedAccountData;
|
use crate::privacy_preserving_transaction::message::EncryptedAccountData;
|
||||||
use crate::{Address, V02State};
|
use crate::{AccountId, V02State};
|
||||||
|
|
||||||
use super::message::Message;
|
use super::message::Message;
|
||||||
use super::witness_set::WitnessSet;
|
use super::witness_set::WitnessSet;
|
||||||
@ -30,7 +30,7 @@ impl PrivacyPreservingTransaction {
|
|||||||
pub(crate) fn validate_and_produce_public_state_diff(
|
pub(crate) fn validate_and_produce_public_state_diff(
|
||||||
&self,
|
&self,
|
||||||
state: &V02State,
|
state: &V02State,
|
||||||
) -> Result<HashMap<Address, Account>, NssaError> {
|
) -> Result<HashMap<AccountId, Account>, NssaError> {
|
||||||
let message = &self.message;
|
let message = &self.message;
|
||||||
let witness_set = &self.witness_set;
|
let witness_set = &self.witness_set;
|
||||||
|
|
||||||
@ -41,10 +41,10 @@ impl PrivacyPreservingTransaction {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Check there are no duplicate addresses in the public_addresses list.
|
// 2. Check there are no duplicate account_ids in the public_account_ids list.
|
||||||
if n_unique(&message.public_addresses) != message.public_addresses.len() {
|
if n_unique(&message.public_account_ids) != message.public_account_ids.len() {
|
||||||
return Err(NssaError::InvalidInput(
|
return Err(NssaError::InvalidInput(
|
||||||
"Duplicate addresses found in message".into(),
|
"Duplicate account_ids found in message".into(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,10 +77,10 @@ impl PrivacyPreservingTransaction {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let signer_addresses = self.signer_addresses();
|
let signer_account_ids = self.signer_account_ids();
|
||||||
// Check nonces corresponds to the current nonces on the public state.
|
// Check nonces corresponds to the current nonces on the public state.
|
||||||
for (address, nonce) in signer_addresses.iter().zip(&message.nonces) {
|
for (account_id, nonce) in signer_account_ids.iter().zip(&message.nonces) {
|
||||||
let current_nonce = state.get_account_by_address(address).nonce;
|
let current_nonce = state.get_account_by_id(account_id).nonce;
|
||||||
if current_nonce != *nonce {
|
if current_nonce != *nonce {
|
||||||
return Err(NssaError::InvalidInput("Nonce mismatch".into()));
|
return Err(NssaError::InvalidInput("Nonce mismatch".into()));
|
||||||
}
|
}
|
||||||
@ -88,13 +88,13 @@ impl PrivacyPreservingTransaction {
|
|||||||
|
|
||||||
// Build pre_states for proof verification
|
// Build pre_states for proof verification
|
||||||
let public_pre_states: Vec<_> = message
|
let public_pre_states: Vec<_> = message
|
||||||
.public_addresses
|
.public_account_ids
|
||||||
.iter()
|
.iter()
|
||||||
.map(|address| {
|
.map(|account_id| {
|
||||||
AccountWithMetadata::new(
|
AccountWithMetadata::new(
|
||||||
state.get_account_by_address(address),
|
state.get_account_by_id(account_id),
|
||||||
signer_addresses.contains(address),
|
signer_account_ids.contains(account_id),
|
||||||
*address,
|
*account_id,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
@ -116,7 +116,7 @@ impl PrivacyPreservingTransaction {
|
|||||||
state.check_nullifiers_are_valid(&message.new_nullifiers)?;
|
state.check_nullifiers_are_valid(&message.new_nullifiers)?;
|
||||||
|
|
||||||
Ok(message
|
Ok(message
|
||||||
.public_addresses
|
.public_account_ids
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.zip(message.public_post_states.clone())
|
.zip(message.public_post_states.clone())
|
||||||
@ -131,11 +131,11 @@ impl PrivacyPreservingTransaction {
|
|||||||
&self.witness_set
|
&self.witness_set
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn signer_addresses(&self) -> Vec<Address> {
|
pub(crate) fn signer_account_ids(&self) -> Vec<AccountId> {
|
||||||
self.witness_set
|
self.witness_set
|
||||||
.signatures_and_public_keys()
|
.signatures_and_public_keys()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(_, public_key)| Address::from(public_key))
|
.map(|(_, public_key)| AccountId::from(public_key))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -174,17 +174,17 @@ fn n_unique<T: Eq + Hash>(data: &[T]) -> usize {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
Address, PrivacyPreservingTransaction, PrivateKey, PublicKey,
|
AccountId, PrivacyPreservingTransaction, PrivateKey, PublicKey,
|
||||||
privacy_preserving_transaction::{
|
privacy_preserving_transaction::{
|
||||||
circuit::Proof, message::tests::message_for_tests, witness_set::WitnessSet,
|
circuit::Proof, message::tests::message_for_tests, witness_set::WitnessSet,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
fn keys_for_tests() -> (PrivateKey, PrivateKey, Address, Address) {
|
fn keys_for_tests() -> (PrivateKey, PrivateKey, AccountId, AccountId) {
|
||||||
let key1 = PrivateKey::try_new([1; 32]).unwrap();
|
let key1 = PrivateKey::try_new([1; 32]).unwrap();
|
||||||
let key2 = PrivateKey::try_new([2; 32]).unwrap();
|
let key2 = PrivateKey::try_new([2; 32]).unwrap();
|
||||||
let addr1 = Address::from(&PublicKey::new_from_private_key(&key1));
|
let addr1 = AccountId::from(&PublicKey::new_from_private_key(&key1));
|
||||||
let addr2 = Address::from(&PublicKey::new_from_private_key(&key2));
|
let addr2 = AccountId::from(&PublicKey::new_from_private_key(&key2));
|
||||||
(key1, key2, addr1, addr2)
|
(key1, key2, addr1, addr2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,12 +4,12 @@ use nssa_core::{
|
|||||||
};
|
};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::{Address, error::NssaError, program::Program};
|
use crate::{AccountId, error::NssaError, program::Program};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct Message {
|
pub struct Message {
|
||||||
pub(crate) program_id: ProgramId,
|
pub(crate) program_id: ProgramId,
|
||||||
pub(crate) addresses: Vec<Address>,
|
pub(crate) account_ids: Vec<AccountId>,
|
||||||
pub(crate) nonces: Vec<Nonce>,
|
pub(crate) nonces: Vec<Nonce>,
|
||||||
pub(crate) instruction_data: InstructionData,
|
pub(crate) instruction_data: InstructionData,
|
||||||
}
|
}
|
||||||
@ -17,14 +17,14 @@ pub struct Message {
|
|||||||
impl Message {
|
impl Message {
|
||||||
pub fn try_new<T: Serialize>(
|
pub fn try_new<T: Serialize>(
|
||||||
program_id: ProgramId,
|
program_id: ProgramId,
|
||||||
addresses: Vec<Address>,
|
account_ids: Vec<AccountId>,
|
||||||
nonces: Vec<Nonce>,
|
nonces: Vec<Nonce>,
|
||||||
instruction: T,
|
instruction: T,
|
||||||
) -> Result<Self, NssaError> {
|
) -> Result<Self, NssaError> {
|
||||||
let instruction_data = Program::serialize_instruction(instruction)?;
|
let instruction_data = Program::serialize_instruction(instruction)?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
program_id,
|
program_id,
|
||||||
addresses,
|
account_ids,
|
||||||
nonces,
|
nonces,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
use nssa_core::{
|
use nssa_core::{
|
||||||
account::{Account, AccountWithMetadata},
|
account::{Account, AccountId, AccountWithMetadata},
|
||||||
address::Address,
|
|
||||||
program::{DEFAULT_PROGRAM_ID, validate_execution},
|
program::{DEFAULT_PROGRAM_ID, validate_execution},
|
||||||
};
|
};
|
||||||
use sha2::{Digest, digest::FixedOutput};
|
use sha2::{Digest, digest::FixedOutput};
|
||||||
@ -36,11 +35,11 @@ impl PublicTransaction {
|
|||||||
&self.witness_set
|
&self.witness_set
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn signer_addresses(&self) -> Vec<Address> {
|
pub(crate) fn signer_account_ids(&self) -> Vec<AccountId> {
|
||||||
self.witness_set
|
self.witness_set
|
||||||
.signatures_and_public_keys()
|
.signatures_and_public_keys()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(_, public_key)| Address::from(public_key))
|
.map(|(_, public_key)| AccountId::from(public_key))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,14 +53,14 @@ impl PublicTransaction {
|
|||||||
pub(crate) fn validate_and_produce_public_state_diff(
|
pub(crate) fn validate_and_produce_public_state_diff(
|
||||||
&self,
|
&self,
|
||||||
state: &V02State,
|
state: &V02State,
|
||||||
) -> Result<HashMap<Address, Account>, NssaError> {
|
) -> Result<HashMap<AccountId, Account>, NssaError> {
|
||||||
let message = self.message();
|
let message = self.message();
|
||||||
let witness_set = self.witness_set();
|
let witness_set = self.witness_set();
|
||||||
|
|
||||||
// All addresses must be different
|
// All account_ids must be different
|
||||||
if message.addresses.iter().collect::<HashSet<_>>().len() != message.addresses.len() {
|
if message.account_ids.iter().collect::<HashSet<_>>().len() != message.account_ids.len() {
|
||||||
return Err(NssaError::InvalidInput(
|
return Err(NssaError::InvalidInput(
|
||||||
"Duplicate addresses found in message".into(),
|
"Duplicate account_ids found in message".into(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,10 +78,10 @@ impl PublicTransaction {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let signer_addresses = self.signer_addresses();
|
let signer_account_ids = self.signer_account_ids();
|
||||||
// Check nonces corresponds to the current nonces on the public state.
|
// Check nonces corresponds to the current nonces on the public state.
|
||||||
for (address, nonce) in signer_addresses.iter().zip(&message.nonces) {
|
for (account_id, nonce) in signer_account_ids.iter().zip(&message.nonces) {
|
||||||
let current_nonce = state.get_account_by_address(address).nonce;
|
let current_nonce = state.get_account_by_id(account_id).nonce;
|
||||||
if current_nonce != *nonce {
|
if current_nonce != *nonce {
|
||||||
return Err(NssaError::InvalidInput("Nonce mismatch".into()));
|
return Err(NssaError::InvalidInput("Nonce mismatch".into()));
|
||||||
}
|
}
|
||||||
@ -90,18 +89,18 @@ impl PublicTransaction {
|
|||||||
|
|
||||||
// Build pre_states for execution
|
// Build pre_states for execution
|
||||||
let mut input_pre_states: Vec<_> = message
|
let mut input_pre_states: Vec<_> = message
|
||||||
.addresses
|
.account_ids
|
||||||
.iter()
|
.iter()
|
||||||
.map(|address| {
|
.map(|account_id| {
|
||||||
AccountWithMetadata::new(
|
AccountWithMetadata::new(
|
||||||
state.get_account_by_address(address),
|
state.get_account_by_id(account_id),
|
||||||
signer_addresses.contains(address),
|
signer_account_ids.contains(account_id),
|
||||||
*address,
|
*account_id,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut state_diff: HashMap<Address, Account> = HashMap::new();
|
let mut state_diff: HashMap<AccountId, Account> = HashMap::new();
|
||||||
|
|
||||||
let mut program_id = message.program_id;
|
let mut program_id = message.program_id;
|
||||||
let mut instruction_data = message.instruction_data.clone();
|
let mut instruction_data = message.instruction_data.clone();
|
||||||
@ -189,17 +188,17 @@ pub mod tests {
|
|||||||
use sha2::{Digest, digest::FixedOutput};
|
use sha2::{Digest, digest::FixedOutput};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Address, PrivateKey, PublicKey, PublicTransaction, Signature, V02State,
|
AccountId, PrivateKey, PublicKey, PublicTransaction, Signature, V02State,
|
||||||
error::NssaError,
|
error::NssaError,
|
||||||
program::Program,
|
program::Program,
|
||||||
public_transaction::{Message, WitnessSet},
|
public_transaction::{Message, WitnessSet},
|
||||||
};
|
};
|
||||||
|
|
||||||
fn keys_for_tests() -> (PrivateKey, PrivateKey, Address, Address) {
|
fn keys_for_tests() -> (PrivateKey, PrivateKey, AccountId, AccountId) {
|
||||||
let key1 = PrivateKey::try_new([1; 32]).unwrap();
|
let key1 = PrivateKey::try_new([1; 32]).unwrap();
|
||||||
let key2 = PrivateKey::try_new([2; 32]).unwrap();
|
let key2 = PrivateKey::try_new([2; 32]).unwrap();
|
||||||
let addr1 = Address::from(&PublicKey::new_from_private_key(&key1));
|
let addr1 = AccountId::from(&PublicKey::new_from_private_key(&key1));
|
||||||
let addr2 = Address::from(&PublicKey::new_from_private_key(&key2));
|
let addr2 = AccountId::from(&PublicKey::new_from_private_key(&key2));
|
||||||
(key1, key2, addr1, addr2)
|
(key1, key2, addr1, addr2)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,20 +247,20 @@ pub mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_signer_addresses() {
|
fn test_signer_account_ids() {
|
||||||
let tx = transaction_for_tests();
|
let tx = transaction_for_tests();
|
||||||
let expected_signer_addresses = vec![
|
let expected_signer_account_ids = vec![
|
||||||
Address::new([
|
AccountId::new([
|
||||||
208, 122, 210, 232, 75, 39, 250, 0, 194, 98, 240, 161, 238, 160, 255, 53, 202, 9,
|
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,
|
115, 84, 126, 106, 16, 111, 114, 241, 147, 194, 220, 131, 139, 68,
|
||||||
]),
|
]),
|
||||||
Address::new([
|
AccountId::new([
|
||||||
231, 174, 119, 197, 239, 26, 5, 153, 147, 68, 175, 73, 159, 199, 138, 23, 5, 57,
|
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,
|
141, 98, 237, 6, 207, 46, 20, 121, 246, 222, 248, 154, 57, 188,
|
||||||
]),
|
]),
|
||||||
];
|
];
|
||||||
let signer_addresses = tx.signer_addresses();
|
let signer_account_ids = tx.signer_account_ids();
|
||||||
assert_eq!(signer_addresses, expected_signer_addresses);
|
assert_eq!(signer_account_ids, expected_signer_account_ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -286,7 +285,7 @@ pub mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_address_list_cant_have_duplicates() {
|
fn test_account_id_list_cant_have_duplicates() {
|
||||||
let (key1, _, addr1, _) = keys_for_tests();
|
let (key1, _, addr1, _) = keys_for_tests();
|
||||||
let state = state_for_tests();
|
let state = state_for_tests();
|
||||||
let nonces = vec![0, 0];
|
let nonces = vec![0, 0];
|
||||||
|
|||||||
@ -39,7 +39,7 @@ impl WitnessSet {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::Address;
|
use crate::AccountId;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
@ -49,8 +49,8 @@ mod tests {
|
|||||||
let key2 = PrivateKey::try_new([2; 32]).unwrap();
|
let key2 = PrivateKey::try_new([2; 32]).unwrap();
|
||||||
let pubkey1 = PublicKey::new_from_private_key(&key1);
|
let pubkey1 = PublicKey::new_from_private_key(&key1);
|
||||||
let pubkey2 = PublicKey::new_from_private_key(&key2);
|
let pubkey2 = PublicKey::new_from_private_key(&key2);
|
||||||
let addr1 = Address::from(&pubkey1);
|
let addr1 = AccountId::from(&pubkey1);
|
||||||
let addr2 = Address::from(&pubkey2);
|
let addr2 = AccountId::from(&pubkey2);
|
||||||
let nonces = vec![1, 2];
|
let nonces = vec![1, 2];
|
||||||
let instruction = vec![1, 2, 3, 4];
|
let instruction = vec![1, 2, 3, 4];
|
||||||
let message = Message::try_new([0; 8], vec![addr1, addr2], nonces, instruction).unwrap();
|
let message = Message::try_new([0; 8], vec![addr1, addr2], nonces, instruction).unwrap();
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use nssa_core::address::Address;
|
use nssa_core::account::AccountId;
|
||||||
|
|
||||||
use crate::{PrivateKey, error::NssaError};
|
use crate::{PrivateKey, error::NssaError};
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ impl PublicKey {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&PublicKey> for Address {
|
impl From<&PublicKey> for AccountId {
|
||||||
fn from(key: &PublicKey) -> Self {
|
fn from(key: &PublicKey) -> Self {
|
||||||
const PUBLIC_ACCOUNT_ID_PREFIX: &[u8; 32] = b"/NSSA/v0.2/AccountId/Public/\x00\x00\x00\x00";
|
const PUBLIC_ACCOUNT_ID_PREFIX: &[u8; 32] = b"/NSSA/v0.2/AccountId/Public/\x00\x00\x00\x00";
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use nssa_core::{
|
use nssa_core::{
|
||||||
Commitment, CommitmentSetDigest, DUMMY_COMMITMENT, MembershipProof, Nullifier,
|
Commitment, CommitmentSetDigest, DUMMY_COMMITMENT, MembershipProof, Nullifier,
|
||||||
account::Account, address::Address, program::ProgramId,
|
account::Account, account::AccountId, program::ProgramId,
|
||||||
};
|
};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
@ -58,27 +58,27 @@ impl CommitmentSet {
|
|||||||
type NullifierSet = HashSet<Nullifier>;
|
type NullifierSet = HashSet<Nullifier>;
|
||||||
|
|
||||||
pub struct V02State {
|
pub struct V02State {
|
||||||
public_state: HashMap<Address, Account>,
|
public_state: HashMap<AccountId, Account>,
|
||||||
private_state: (CommitmentSet, NullifierSet),
|
private_state: (CommitmentSet, NullifierSet),
|
||||||
programs: HashMap<ProgramId, Program>,
|
programs: HashMap<ProgramId, Program>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl V02State {
|
impl V02State {
|
||||||
pub fn new_with_genesis_accounts(
|
pub fn new_with_genesis_accounts(
|
||||||
initial_data: &[(Address, u128)],
|
initial_data: &[(AccountId, u128)],
|
||||||
initial_commitments: &[nssa_core::Commitment],
|
initial_commitments: &[nssa_core::Commitment],
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let authenticated_transfer_program = Program::authenticated_transfer_program();
|
let authenticated_transfer_program = Program::authenticated_transfer_program();
|
||||||
let public_state = initial_data
|
let public_state = initial_data
|
||||||
.iter()
|
.iter()
|
||||||
.copied()
|
.copied()
|
||||||
.map(|(address, balance)| {
|
.map(|(account_id, balance)| {
|
||||||
let account = Account {
|
let account = Account {
|
||||||
balance,
|
balance,
|
||||||
program_owner: authenticated_transfer_program.id(),
|
program_owner: authenticated_transfer_program.id(),
|
||||||
..Account::default()
|
..Account::default()
|
||||||
};
|
};
|
||||||
(address, account)
|
(account_id, account)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@ -108,14 +108,14 @@ impl V02State {
|
|||||||
) -> Result<(), NssaError> {
|
) -> Result<(), NssaError> {
|
||||||
let state_diff = tx.validate_and_produce_public_state_diff(self)?;
|
let state_diff = tx.validate_and_produce_public_state_diff(self)?;
|
||||||
|
|
||||||
for (address, post) in state_diff.into_iter() {
|
for (account_id, post) in state_diff.into_iter() {
|
||||||
let current_account = self.get_account_by_address_mut(address);
|
let current_account = self.get_account_by_id_mut(account_id);
|
||||||
|
|
||||||
*current_account = post;
|
*current_account = post;
|
||||||
}
|
}
|
||||||
|
|
||||||
for address in tx.signer_addresses() {
|
for account_id in tx.signer_account_ids() {
|
||||||
let current_account = self.get_account_by_address_mut(address);
|
let current_account = self.get_account_by_id_mut(account_id);
|
||||||
current_account.nonce += 1;
|
current_account.nonce += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,8 +144,8 @@ impl V02State {
|
|||||||
self.private_state.1.extend(new_nullifiers);
|
self.private_state.1.extend(new_nullifiers);
|
||||||
|
|
||||||
// 4. Update public accounts
|
// 4. Update public accounts
|
||||||
for (address, post) in public_state_diff.into_iter() {
|
for (account_id, post) in public_state_diff.into_iter() {
|
||||||
let current_account = self.get_account_by_address_mut(address);
|
let current_account = self.get_account_by_id_mut(account_id);
|
||||||
*current_account = post;
|
*current_account = post;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,13 +161,13 @@ impl V02State {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_account_by_address_mut(&mut self, address: Address) -> &mut Account {
|
fn get_account_by_id_mut(&mut self, account_id: AccountId) -> &mut Account {
|
||||||
self.public_state.entry(address).or_default()
|
self.public_state.entry(account_id).or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_account_by_address(&self, address: &Address) -> Account {
|
pub fn get_account_by_id(&self, account_id: &AccountId) -> Account {
|
||||||
self.public_state
|
self.public_state
|
||||||
.get(address)
|
.get(account_id)
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or(Account::default())
|
.unwrap_or(Account::default())
|
||||||
}
|
}
|
||||||
@ -220,11 +220,11 @@ impl V02State {
|
|||||||
|
|
||||||
// TODO: Testnet only. Refactor to prevent compilation on mainnet.
|
// TODO: Testnet only. Refactor to prevent compilation on mainnet.
|
||||||
impl V02State {
|
impl V02State {
|
||||||
pub fn add_pinata_program(&mut self, address: Address) {
|
pub fn add_pinata_program(&mut self, account_id: AccountId) {
|
||||||
self.insert_program(Program::pinata());
|
self.insert_program(Program::pinata());
|
||||||
|
|
||||||
self.public_state.insert(
|
self.public_state.insert(
|
||||||
address,
|
account_id,
|
||||||
Account {
|
Account {
|
||||||
program_owner: Program::pinata().id(),
|
program_owner: Program::pinata().id(),
|
||||||
balance: 1500,
|
balance: 1500,
|
||||||
@ -242,7 +242,7 @@ pub mod tests {
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Address, PublicKey, PublicTransaction, V02State,
|
PublicKey, PublicTransaction, V02State,
|
||||||
error::NssaError,
|
error::NssaError,
|
||||||
execute_and_prove,
|
execute_and_prove,
|
||||||
privacy_preserving_transaction::{
|
privacy_preserving_transaction::{
|
||||||
@ -261,17 +261,17 @@ pub mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fn transfer_transaction(
|
fn transfer_transaction(
|
||||||
from: Address,
|
from: AccountId,
|
||||||
from_key: PrivateKey,
|
from_key: PrivateKey,
|
||||||
nonce: u128,
|
nonce: u128,
|
||||||
to: Address,
|
to: AccountId,
|
||||||
balance: u128,
|
balance: u128,
|
||||||
) -> PublicTransaction {
|
) -> PublicTransaction {
|
||||||
let addresses = vec![from, to];
|
let account_ids = vec![from, to];
|
||||||
let nonces = vec![nonce];
|
let nonces = vec![nonce];
|
||||||
let program_id = Program::authenticated_transfer_program().id();
|
let program_id = Program::authenticated_transfer_program().id();
|
||||||
let message =
|
let message =
|
||||||
public_transaction::Message::try_new(program_id, addresses, nonces, balance).unwrap();
|
public_transaction::Message::try_new(program_id, account_ids, nonces, balance).unwrap();
|
||||||
let witness_set = public_transaction::WitnessSet::for_message(&message, &[&from_key]);
|
let witness_set = public_transaction::WitnessSet::for_message(&message, &[&from_key]);
|
||||||
PublicTransaction::new(message, witness_set)
|
PublicTransaction::new(message, witness_set)
|
||||||
}
|
}
|
||||||
@ -280,8 +280,8 @@ pub mod tests {
|
|||||||
fn test_new_with_genesis() {
|
fn test_new_with_genesis() {
|
||||||
let key1 = PrivateKey::try_new([1; 32]).unwrap();
|
let key1 = PrivateKey::try_new([1; 32]).unwrap();
|
||||||
let key2 = PrivateKey::try_new([2; 32]).unwrap();
|
let key2 = PrivateKey::try_new([2; 32]).unwrap();
|
||||||
let addr1 = Address::from(&PublicKey::new_from_private_key(&key1));
|
let addr1 = AccountId::from(&PublicKey::new_from_private_key(&key1));
|
||||||
let addr2 = Address::from(&PublicKey::new_from_private_key(&key2));
|
let addr2 = AccountId::from(&PublicKey::new_from_private_key(&key2));
|
||||||
let initial_data = [(addr1, 100u128), (addr2, 151u128)];
|
let initial_data = [(addr1, 100u128), (addr2, 151u128)];
|
||||||
let authenticated_transfers_program = Program::authenticated_transfer_program();
|
let authenticated_transfers_program = Program::authenticated_transfer_program();
|
||||||
let expected_public_state = {
|
let expected_public_state = {
|
||||||
@ -333,25 +333,25 @@ pub mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_account_by_address_non_default_account() {
|
fn test_get_account_by_account_id_non_default_account() {
|
||||||
let key = PrivateKey::try_new([1; 32]).unwrap();
|
let key = PrivateKey::try_new([1; 32]).unwrap();
|
||||||
let addr = Address::from(&PublicKey::new_from_private_key(&key));
|
let account_id = AccountId::from(&PublicKey::new_from_private_key(&key));
|
||||||
let initial_data = [(addr, 100u128)];
|
let initial_data = [(account_id, 100u128)];
|
||||||
let state = V02State::new_with_genesis_accounts(&initial_data, &[]);
|
let state = V02State::new_with_genesis_accounts(&initial_data, &[]);
|
||||||
let expected_account = state.public_state.get(&addr).unwrap();
|
let expected_account = state.public_state.get(&account_id).unwrap();
|
||||||
|
|
||||||
let account = state.get_account_by_address(&addr);
|
let account = state.get_account_by_id(&account_id);
|
||||||
|
|
||||||
assert_eq!(&account, expected_account);
|
assert_eq!(&account, expected_account);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_account_by_address_default_account() {
|
fn test_get_account_by_account_id_default_account() {
|
||||||
let addr2 = Address::new([0; 32]);
|
let addr2 = AccountId::new([0; 32]);
|
||||||
let state = V02State::new_with_genesis_accounts(&[], &[]);
|
let state = V02State::new_with_genesis_accounts(&[], &[]);
|
||||||
let expected_account = Account::default();
|
let expected_account = Account::default();
|
||||||
|
|
||||||
let account = state.get_account_by_address(&addr2);
|
let account = state.get_account_by_id(&addr2);
|
||||||
|
|
||||||
assert_eq!(account, expected_account);
|
assert_eq!(account, expected_account);
|
||||||
}
|
}
|
||||||
@ -368,96 +368,96 @@ pub mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn transition_from_authenticated_transfer_program_invocation_default_account_destination() {
|
fn transition_from_authenticated_transfer_program_invocation_default_account_destination() {
|
||||||
let key = PrivateKey::try_new([1; 32]).unwrap();
|
let key = PrivateKey::try_new([1; 32]).unwrap();
|
||||||
let address = Address::from(&PublicKey::new_from_private_key(&key));
|
let account_id = AccountId::from(&PublicKey::new_from_private_key(&key));
|
||||||
let initial_data = [(address, 100)];
|
let initial_data = [(account_id, 100)];
|
||||||
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]);
|
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]);
|
||||||
let from = address;
|
let from = account_id;
|
||||||
let to = Address::new([2; 32]);
|
let to = AccountId::new([2; 32]);
|
||||||
assert_eq!(state.get_account_by_address(&to), Account::default());
|
assert_eq!(state.get_account_by_id(&to), Account::default());
|
||||||
let balance_to_move = 5;
|
let balance_to_move = 5;
|
||||||
|
|
||||||
let tx = transfer_transaction(from, key, 0, to, balance_to_move);
|
let tx = transfer_transaction(from, key, 0, to, balance_to_move);
|
||||||
state.transition_from_public_transaction(&tx).unwrap();
|
state.transition_from_public_transaction(&tx).unwrap();
|
||||||
|
|
||||||
assert_eq!(state.get_account_by_address(&from).balance, 95);
|
assert_eq!(state.get_account_by_id(&from).balance, 95);
|
||||||
assert_eq!(state.get_account_by_address(&to).balance, 5);
|
assert_eq!(state.get_account_by_id(&to).balance, 5);
|
||||||
assert_eq!(state.get_account_by_address(&from).nonce, 1);
|
assert_eq!(state.get_account_by_id(&from).nonce, 1);
|
||||||
assert_eq!(state.get_account_by_address(&to).nonce, 0);
|
assert_eq!(state.get_account_by_id(&to).nonce, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn transition_from_authenticated_transfer_program_invocation_insuficient_balance() {
|
fn transition_from_authenticated_transfer_program_invocation_insuficient_balance() {
|
||||||
let key = PrivateKey::try_new([1; 32]).unwrap();
|
let key = PrivateKey::try_new([1; 32]).unwrap();
|
||||||
let address = Address::from(&PublicKey::new_from_private_key(&key));
|
let account_id = AccountId::from(&PublicKey::new_from_private_key(&key));
|
||||||
let initial_data = [(address, 100)];
|
let initial_data = [(account_id, 100)];
|
||||||
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]);
|
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]);
|
||||||
let from = address;
|
let from = account_id;
|
||||||
let from_key = key;
|
let from_key = key;
|
||||||
let to = Address::new([2; 32]);
|
let to = AccountId::new([2; 32]);
|
||||||
let balance_to_move = 101;
|
let balance_to_move = 101;
|
||||||
assert!(state.get_account_by_address(&from).balance < balance_to_move);
|
assert!(state.get_account_by_id(&from).balance < balance_to_move);
|
||||||
|
|
||||||
let tx = transfer_transaction(from, from_key, 0, to, balance_to_move);
|
let tx = transfer_transaction(from, from_key, 0, to, balance_to_move);
|
||||||
let result = state.transition_from_public_transaction(&tx);
|
let result = state.transition_from_public_transaction(&tx);
|
||||||
|
|
||||||
assert!(matches!(result, Err(NssaError::ProgramExecutionFailed(_))));
|
assert!(matches!(result, Err(NssaError::ProgramExecutionFailed(_))));
|
||||||
assert_eq!(state.get_account_by_address(&from).balance, 100);
|
assert_eq!(state.get_account_by_id(&from).balance, 100);
|
||||||
assert_eq!(state.get_account_by_address(&to).balance, 0);
|
assert_eq!(state.get_account_by_id(&to).balance, 0);
|
||||||
assert_eq!(state.get_account_by_address(&from).nonce, 0);
|
assert_eq!(state.get_account_by_id(&from).nonce, 0);
|
||||||
assert_eq!(state.get_account_by_address(&to).nonce, 0);
|
assert_eq!(state.get_account_by_id(&to).nonce, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn transition_from_authenticated_transfer_program_invocation_non_default_account_destination() {
|
fn transition_from_authenticated_transfer_program_invocation_non_default_account_destination() {
|
||||||
let key1 = PrivateKey::try_new([1; 32]).unwrap();
|
let key1 = PrivateKey::try_new([1; 32]).unwrap();
|
||||||
let key2 = PrivateKey::try_new([2; 32]).unwrap();
|
let key2 = PrivateKey::try_new([2; 32]).unwrap();
|
||||||
let address1 = Address::from(&PublicKey::new_from_private_key(&key1));
|
let account_id1 = AccountId::from(&PublicKey::new_from_private_key(&key1));
|
||||||
let address2 = Address::from(&PublicKey::new_from_private_key(&key2));
|
let account_id2 = AccountId::from(&PublicKey::new_from_private_key(&key2));
|
||||||
let initial_data = [(address1, 100), (address2, 200)];
|
let initial_data = [(account_id1, 100), (account_id2, 200)];
|
||||||
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]);
|
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]);
|
||||||
let from = address2;
|
let from = account_id2;
|
||||||
let from_key = key2;
|
let from_key = key2;
|
||||||
let to = address1;
|
let to = account_id1;
|
||||||
assert_ne!(state.get_account_by_address(&to), Account::default());
|
assert_ne!(state.get_account_by_id(&to), Account::default());
|
||||||
let balance_to_move = 8;
|
let balance_to_move = 8;
|
||||||
|
|
||||||
let tx = transfer_transaction(from, from_key, 0, to, balance_to_move);
|
let tx = transfer_transaction(from, from_key, 0, to, balance_to_move);
|
||||||
state.transition_from_public_transaction(&tx).unwrap();
|
state.transition_from_public_transaction(&tx).unwrap();
|
||||||
|
|
||||||
assert_eq!(state.get_account_by_address(&from).balance, 192);
|
assert_eq!(state.get_account_by_id(&from).balance, 192);
|
||||||
assert_eq!(state.get_account_by_address(&to).balance, 108);
|
assert_eq!(state.get_account_by_id(&to).balance, 108);
|
||||||
assert_eq!(state.get_account_by_address(&from).nonce, 1);
|
assert_eq!(state.get_account_by_id(&from).nonce, 1);
|
||||||
assert_eq!(state.get_account_by_address(&to).nonce, 0);
|
assert_eq!(state.get_account_by_id(&to).nonce, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn transition_from_sequence_of_authenticated_transfer_program_invocations() {
|
fn transition_from_sequence_of_authenticated_transfer_program_invocations() {
|
||||||
let key1 = PrivateKey::try_new([8; 32]).unwrap();
|
let key1 = PrivateKey::try_new([8; 32]).unwrap();
|
||||||
let address1 = Address::from(&PublicKey::new_from_private_key(&key1));
|
let account_id1 = AccountId::from(&PublicKey::new_from_private_key(&key1));
|
||||||
let key2 = PrivateKey::try_new([2; 32]).unwrap();
|
let key2 = PrivateKey::try_new([2; 32]).unwrap();
|
||||||
let address2 = Address::from(&PublicKey::new_from_private_key(&key2));
|
let account_id2 = AccountId::from(&PublicKey::new_from_private_key(&key2));
|
||||||
let initial_data = [(address1, 100)];
|
let initial_data = [(account_id1, 100)];
|
||||||
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]);
|
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[]);
|
||||||
let address3 = Address::new([3; 32]);
|
let account_id3 = AccountId::new([3; 32]);
|
||||||
let balance_to_move = 5;
|
let balance_to_move = 5;
|
||||||
|
|
||||||
let tx = transfer_transaction(address1, key1, 0, address2, balance_to_move);
|
let tx = transfer_transaction(account_id1, key1, 0, account_id2, balance_to_move);
|
||||||
state.transition_from_public_transaction(&tx).unwrap();
|
state.transition_from_public_transaction(&tx).unwrap();
|
||||||
let balance_to_move = 3;
|
let balance_to_move = 3;
|
||||||
let tx = transfer_transaction(address2, key2, 0, address3, balance_to_move);
|
let tx = transfer_transaction(account_id2, key2, 0, account_id3, balance_to_move);
|
||||||
state.transition_from_public_transaction(&tx).unwrap();
|
state.transition_from_public_transaction(&tx).unwrap();
|
||||||
|
|
||||||
assert_eq!(state.get_account_by_address(&address1).balance, 95);
|
assert_eq!(state.get_account_by_id(&account_id1).balance, 95);
|
||||||
assert_eq!(state.get_account_by_address(&address2).balance, 2);
|
assert_eq!(state.get_account_by_id(&account_id2).balance, 2);
|
||||||
assert_eq!(state.get_account_by_address(&address3).balance, 3);
|
assert_eq!(state.get_account_by_id(&account_id3).balance, 3);
|
||||||
assert_eq!(state.get_account_by_address(&address1).nonce, 1);
|
assert_eq!(state.get_account_by_id(&account_id1).nonce, 1);
|
||||||
assert_eq!(state.get_account_by_address(&address2).nonce, 1);
|
assert_eq!(state.get_account_by_id(&account_id2).nonce, 1);
|
||||||
assert_eq!(state.get_account_by_address(&address3).nonce, 0);
|
assert_eq!(state.get_account_by_id(&account_id3).nonce, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl V02State {
|
impl V02State {
|
||||||
pub fn force_insert_account(&mut self, address: Address, account: Account) {
|
pub fn force_insert_account(&mut self, account_id: AccountId, account: Account) {
|
||||||
self.public_state.insert(address, account);
|
self.public_state.insert(account_id, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Include test programs in the builtin programs map
|
/// Include test programs in the builtin programs map
|
||||||
@ -488,15 +488,15 @@ pub mod tests {
|
|||||||
..Account::default()
|
..Account::default()
|
||||||
};
|
};
|
||||||
self.force_insert_account(
|
self.force_insert_account(
|
||||||
Address::new([255; 32]),
|
AccountId::new([255; 32]),
|
||||||
account_with_default_values_except_balance,
|
account_with_default_values_except_balance,
|
||||||
);
|
);
|
||||||
self.force_insert_account(
|
self.force_insert_account(
|
||||||
Address::new([254; 32]),
|
AccountId::new([254; 32]),
|
||||||
account_with_default_values_except_nonce,
|
account_with_default_values_except_nonce,
|
||||||
);
|
);
|
||||||
self.force_insert_account(
|
self.force_insert_account(
|
||||||
Address::new([253; 32]),
|
AccountId::new([253; 32]),
|
||||||
account_with_default_values_except_data,
|
account_with_default_values_except_data,
|
||||||
);
|
);
|
||||||
self
|
self
|
||||||
@ -508,7 +508,7 @@ pub mod tests {
|
|||||||
balance: 100,
|
balance: 100,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
self.force_insert_account(Address::new([252; 32]), account);
|
self.force_insert_account(AccountId::new([252; 32]), account);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,13 +521,13 @@ pub mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_program_should_fail_if_modifies_nonces() {
|
fn test_program_should_fail_if_modifies_nonces() {
|
||||||
let initial_data = [(Address::new([1; 32]), 100)];
|
let initial_data = [(AccountId::new([1; 32]), 100)];
|
||||||
let mut state =
|
let mut state =
|
||||||
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
||||||
let addresses = vec![Address::new([1; 32])];
|
let account_ids = vec![AccountId::new([1; 32])];
|
||||||
let program_id = Program::nonce_changer_program().id();
|
let program_id = Program::nonce_changer_program().id();
|
||||||
let message =
|
let message =
|
||||||
public_transaction::Message::try_new(program_id, addresses, vec![], ()).unwrap();
|
public_transaction::Message::try_new(program_id, account_ids, vec![], ()).unwrap();
|
||||||
let witness_set = public_transaction::WitnessSet::for_message(&message, &[]);
|
let witness_set = public_transaction::WitnessSet::for_message(&message, &[]);
|
||||||
let tx = PublicTransaction::new(message, witness_set);
|
let tx = PublicTransaction::new(message, witness_set);
|
||||||
|
|
||||||
@ -538,13 +538,13 @@ pub mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_program_should_fail_if_output_accounts_exceed_inputs() {
|
fn test_program_should_fail_if_output_accounts_exceed_inputs() {
|
||||||
let initial_data = [(Address::new([1; 32]), 100)];
|
let initial_data = [(AccountId::new([1; 32]), 100)];
|
||||||
let mut state =
|
let mut state =
|
||||||
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
||||||
let addresses = vec![Address::new([1; 32])];
|
let account_ids = vec![AccountId::new([1; 32])];
|
||||||
let program_id = Program::extra_output_program().id();
|
let program_id = Program::extra_output_program().id();
|
||||||
let message =
|
let message =
|
||||||
public_transaction::Message::try_new(program_id, addresses, vec![], ()).unwrap();
|
public_transaction::Message::try_new(program_id, account_ids, vec![], ()).unwrap();
|
||||||
let witness_set = public_transaction::WitnessSet::for_message(&message, &[]);
|
let witness_set = public_transaction::WitnessSet::for_message(&message, &[]);
|
||||||
let tx = PublicTransaction::new(message, witness_set);
|
let tx = PublicTransaction::new(message, witness_set);
|
||||||
|
|
||||||
@ -555,13 +555,13 @@ pub mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_program_should_fail_with_missing_output_accounts() {
|
fn test_program_should_fail_with_missing_output_accounts() {
|
||||||
let initial_data = [(Address::new([1; 32]), 100)];
|
let initial_data = [(AccountId::new([1; 32]), 100)];
|
||||||
let mut state =
|
let mut state =
|
||||||
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
||||||
let addresses = vec![Address::new([1; 32]), Address::new([2; 32])];
|
let account_ids = vec![AccountId::new([1; 32]), AccountId::new([2; 32])];
|
||||||
let program_id = Program::missing_output_program().id();
|
let program_id = Program::missing_output_program().id();
|
||||||
let message =
|
let message =
|
||||||
public_transaction::Message::try_new(program_id, addresses, vec![], ()).unwrap();
|
public_transaction::Message::try_new(program_id, account_ids, vec![], ()).unwrap();
|
||||||
let witness_set = public_transaction::WitnessSet::for_message(&message, &[]);
|
let witness_set = public_transaction::WitnessSet::for_message(&message, &[]);
|
||||||
let tx = PublicTransaction::new(message, witness_set);
|
let tx = PublicTransaction::new(message, witness_set);
|
||||||
|
|
||||||
@ -572,11 +572,11 @@ pub mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_program_should_fail_if_modifies_program_owner_with_only_non_default_program_owner() {
|
fn test_program_should_fail_if_modifies_program_owner_with_only_non_default_program_owner() {
|
||||||
let initial_data = [(Address::new([1; 32]), 0)];
|
let initial_data = [(AccountId::new([1; 32]), 0)];
|
||||||
let mut state =
|
let mut state =
|
||||||
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
||||||
let address = Address::new([1; 32]);
|
let account_id = AccountId::new([1; 32]);
|
||||||
let account = state.get_account_by_address(&address);
|
let account = state.get_account_by_id(&account_id);
|
||||||
// Assert the target account only differs from the default account in the program owner field
|
// Assert the target account only differs from the default account in the program owner field
|
||||||
assert_ne!(account.program_owner, Account::default().program_owner);
|
assert_ne!(account.program_owner, Account::default().program_owner);
|
||||||
assert_eq!(account.balance, Account::default().balance);
|
assert_eq!(account.balance, Account::default().balance);
|
||||||
@ -584,7 +584,7 @@ pub mod tests {
|
|||||||
assert_eq!(account.data, Account::default().data);
|
assert_eq!(account.data, Account::default().data);
|
||||||
let program_id = Program::program_owner_changer().id();
|
let program_id = Program::program_owner_changer().id();
|
||||||
let message =
|
let message =
|
||||||
public_transaction::Message::try_new(program_id, vec![address], vec![], ()).unwrap();
|
public_transaction::Message::try_new(program_id, vec![account_id], vec![], ()).unwrap();
|
||||||
let witness_set = public_transaction::WitnessSet::for_message(&message, &[]);
|
let witness_set = public_transaction::WitnessSet::for_message(&message, &[]);
|
||||||
let tx = PublicTransaction::new(message, witness_set);
|
let tx = PublicTransaction::new(message, witness_set);
|
||||||
|
|
||||||
@ -599,8 +599,8 @@ pub mod tests {
|
|||||||
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[])
|
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[])
|
||||||
.with_test_programs()
|
.with_test_programs()
|
||||||
.with_non_default_accounts_but_default_program_owners();
|
.with_non_default_accounts_but_default_program_owners();
|
||||||
let address = Address::new([255; 32]);
|
let account_id = AccountId::new([255; 32]);
|
||||||
let account = state.get_account_by_address(&address);
|
let account = state.get_account_by_id(&account_id);
|
||||||
// Assert the target account only differs from the default account in balance field
|
// Assert the target account only differs from the default account in balance field
|
||||||
assert_eq!(account.program_owner, Account::default().program_owner);
|
assert_eq!(account.program_owner, Account::default().program_owner);
|
||||||
assert_ne!(account.balance, Account::default().balance);
|
assert_ne!(account.balance, Account::default().balance);
|
||||||
@ -608,7 +608,7 @@ pub mod tests {
|
|||||||
assert_eq!(account.data, Account::default().data);
|
assert_eq!(account.data, Account::default().data);
|
||||||
let program_id = Program::program_owner_changer().id();
|
let program_id = Program::program_owner_changer().id();
|
||||||
let message =
|
let message =
|
||||||
public_transaction::Message::try_new(program_id, vec![address], vec![], ()).unwrap();
|
public_transaction::Message::try_new(program_id, vec![account_id], vec![], ()).unwrap();
|
||||||
let witness_set = public_transaction::WitnessSet::for_message(&message, &[]);
|
let witness_set = public_transaction::WitnessSet::for_message(&message, &[]);
|
||||||
let tx = PublicTransaction::new(message, witness_set);
|
let tx = PublicTransaction::new(message, witness_set);
|
||||||
|
|
||||||
@ -623,8 +623,8 @@ pub mod tests {
|
|||||||
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[])
|
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[])
|
||||||
.with_test_programs()
|
.with_test_programs()
|
||||||
.with_non_default_accounts_but_default_program_owners();
|
.with_non_default_accounts_but_default_program_owners();
|
||||||
let address = Address::new([254; 32]);
|
let account_id = AccountId::new([254; 32]);
|
||||||
let account = state.get_account_by_address(&address);
|
let account = state.get_account_by_id(&account_id);
|
||||||
// Assert the target account only differs from the default account in nonce field
|
// Assert the target account only differs from the default account in nonce field
|
||||||
assert_eq!(account.program_owner, Account::default().program_owner);
|
assert_eq!(account.program_owner, Account::default().program_owner);
|
||||||
assert_eq!(account.balance, Account::default().balance);
|
assert_eq!(account.balance, Account::default().balance);
|
||||||
@ -632,7 +632,7 @@ pub mod tests {
|
|||||||
assert_eq!(account.data, Account::default().data);
|
assert_eq!(account.data, Account::default().data);
|
||||||
let program_id = Program::program_owner_changer().id();
|
let program_id = Program::program_owner_changer().id();
|
||||||
let message =
|
let message =
|
||||||
public_transaction::Message::try_new(program_id, vec![address], vec![], ()).unwrap();
|
public_transaction::Message::try_new(program_id, vec![account_id], vec![], ()).unwrap();
|
||||||
let witness_set = public_transaction::WitnessSet::for_message(&message, &[]);
|
let witness_set = public_transaction::WitnessSet::for_message(&message, &[]);
|
||||||
let tx = PublicTransaction::new(message, witness_set);
|
let tx = PublicTransaction::new(message, witness_set);
|
||||||
|
|
||||||
@ -647,8 +647,8 @@ pub mod tests {
|
|||||||
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[])
|
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[])
|
||||||
.with_test_programs()
|
.with_test_programs()
|
||||||
.with_non_default_accounts_but_default_program_owners();
|
.with_non_default_accounts_but_default_program_owners();
|
||||||
let address = Address::new([253; 32]);
|
let account_id = AccountId::new([253; 32]);
|
||||||
let account = state.get_account_by_address(&address);
|
let account = state.get_account_by_id(&account_id);
|
||||||
// Assert the target account only differs from the default account in data field
|
// Assert the target account only differs from the default account in data field
|
||||||
assert_eq!(account.program_owner, Account::default().program_owner);
|
assert_eq!(account.program_owner, Account::default().program_owner);
|
||||||
assert_eq!(account.balance, Account::default().balance);
|
assert_eq!(account.balance, Account::default().balance);
|
||||||
@ -656,7 +656,7 @@ pub mod tests {
|
|||||||
assert_ne!(account.data, Account::default().data);
|
assert_ne!(account.data, Account::default().data);
|
||||||
let program_id = Program::program_owner_changer().id();
|
let program_id = Program::program_owner_changer().id();
|
||||||
let message =
|
let message =
|
||||||
public_transaction::Message::try_new(program_id, vec![address], vec![], ()).unwrap();
|
public_transaction::Message::try_new(program_id, vec![account_id], vec![], ()).unwrap();
|
||||||
let witness_set = public_transaction::WitnessSet::for_message(&message, &[]);
|
let witness_set = public_transaction::WitnessSet::for_message(&message, &[]);
|
||||||
let tx = PublicTransaction::new(message, witness_set);
|
let tx = PublicTransaction::new(message, witness_set);
|
||||||
|
|
||||||
@ -667,20 +667,20 @@ pub mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_program_should_fail_if_transfers_balance_from_non_owned_account() {
|
fn test_program_should_fail_if_transfers_balance_from_non_owned_account() {
|
||||||
let initial_data = [(Address::new([1; 32]), 100)];
|
let initial_data = [(AccountId::new([1; 32]), 100)];
|
||||||
let mut state =
|
let mut state =
|
||||||
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
||||||
let sender_address = Address::new([1; 32]);
|
let sender_account_id = AccountId::new([1; 32]);
|
||||||
let receiver_address = Address::new([2; 32]);
|
let receiver_account_id = AccountId::new([2; 32]);
|
||||||
let balance_to_move: u128 = 1;
|
let balance_to_move: u128 = 1;
|
||||||
let program_id = Program::simple_balance_transfer().id();
|
let program_id = Program::simple_balance_transfer().id();
|
||||||
assert_ne!(
|
assert_ne!(
|
||||||
state.get_account_by_address(&sender_address).program_owner,
|
state.get_account_by_id(&sender_account_id).program_owner,
|
||||||
program_id
|
program_id
|
||||||
);
|
);
|
||||||
let message = public_transaction::Message::try_new(
|
let message = public_transaction::Message::try_new(
|
||||||
program_id,
|
program_id,
|
||||||
vec![sender_address, receiver_address],
|
vec![sender_account_id, receiver_account_id],
|
||||||
vec![],
|
vec![],
|
||||||
balance_to_move,
|
balance_to_move,
|
||||||
)
|
)
|
||||||
@ -699,16 +699,16 @@ pub mod tests {
|
|||||||
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[])
|
let mut state = V02State::new_with_genesis_accounts(&initial_data, &[])
|
||||||
.with_test_programs()
|
.with_test_programs()
|
||||||
.with_non_default_accounts_but_default_program_owners();
|
.with_non_default_accounts_but_default_program_owners();
|
||||||
let address = Address::new([255; 32]);
|
let account_id = AccountId::new([255; 32]);
|
||||||
let program_id = Program::data_changer().id();
|
let program_id = Program::data_changer().id();
|
||||||
|
|
||||||
assert_ne!(state.get_account_by_address(&address), Account::default());
|
assert_ne!(state.get_account_by_id(&account_id), Account::default());
|
||||||
assert_ne!(
|
assert_ne!(
|
||||||
state.get_account_by_address(&address).program_owner,
|
state.get_account_by_id(&account_id).program_owner,
|
||||||
program_id
|
program_id
|
||||||
);
|
);
|
||||||
let message =
|
let message =
|
||||||
public_transaction::Message::try_new(program_id, vec![address], vec![], ()).unwrap();
|
public_transaction::Message::try_new(program_id, vec![account_id], vec![], ()).unwrap();
|
||||||
let witness_set = public_transaction::WitnessSet::for_message(&message, &[]);
|
let witness_set = public_transaction::WitnessSet::for_message(&message, &[]);
|
||||||
let tx = PublicTransaction::new(message, witness_set);
|
let tx = PublicTransaction::new(message, witness_set);
|
||||||
|
|
||||||
@ -722,11 +722,11 @@ pub mod tests {
|
|||||||
let initial_data = [];
|
let initial_data = [];
|
||||||
let mut state =
|
let mut state =
|
||||||
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
||||||
let address = Address::new([1; 32]);
|
let account_id = AccountId::new([1; 32]);
|
||||||
let program_id = Program::minter().id();
|
let program_id = Program::minter().id();
|
||||||
|
|
||||||
let message =
|
let message =
|
||||||
public_transaction::Message::try_new(program_id, vec![address], vec![], ()).unwrap();
|
public_transaction::Message::try_new(program_id, vec![account_id], vec![], ()).unwrap();
|
||||||
let witness_set = public_transaction::WitnessSet::for_message(&message, &[]);
|
let witness_set = public_transaction::WitnessSet::for_message(&message, &[]);
|
||||||
let tx = PublicTransaction::new(message, witness_set);
|
let tx = PublicTransaction::new(message, witness_set);
|
||||||
|
|
||||||
@ -742,17 +742,17 @@ pub mod tests {
|
|||||||
.with_test_programs()
|
.with_test_programs()
|
||||||
.with_account_owned_by_burner_program();
|
.with_account_owned_by_burner_program();
|
||||||
let program_id = Program::burner().id();
|
let program_id = Program::burner().id();
|
||||||
let address = Address::new([252; 32]);
|
let account_id = AccountId::new([252; 32]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
state.get_account_by_address(&address).program_owner,
|
state.get_account_by_id(&account_id).program_owner,
|
||||||
program_id
|
program_id
|
||||||
);
|
);
|
||||||
let balance_to_burn: u128 = 1;
|
let balance_to_burn: u128 = 1;
|
||||||
assert!(state.get_account_by_address(&address).balance > balance_to_burn);
|
assert!(state.get_account_by_id(&account_id).balance > balance_to_burn);
|
||||||
|
|
||||||
let message = public_transaction::Message::try_new(
|
let message = public_transaction::Message::try_new(
|
||||||
program_id,
|
program_id,
|
||||||
vec![address],
|
vec![account_id],
|
||||||
vec![],
|
vec![],
|
||||||
balance_to_burn,
|
balance_to_burn,
|
||||||
)
|
)
|
||||||
@ -769,8 +769,8 @@ pub mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TestPublicKeys {
|
impl TestPublicKeys {
|
||||||
pub fn address(&self) -> Address {
|
pub fn account_id(&self) -> AccountId {
|
||||||
Address::from(&PublicKey::new_from_private_key(&self.signing_key))
|
AccountId::from(&PublicKey::new_from_private_key(&self.signing_key))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -816,9 +816,9 @@ pub mod tests {
|
|||||||
state: &V02State,
|
state: &V02State,
|
||||||
) -> PrivacyPreservingTransaction {
|
) -> PrivacyPreservingTransaction {
|
||||||
let sender = AccountWithMetadata::new(
|
let sender = AccountWithMetadata::new(
|
||||||
state.get_account_by_address(&sender_keys.address()),
|
state.get_account_by_id(&sender_keys.account_id()),
|
||||||
true,
|
true,
|
||||||
sender_keys.address(),
|
sender_keys.account_id(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let sender_nonce = sender.account.nonce;
|
let sender_nonce = sender.account.nonce;
|
||||||
@ -841,7 +841,7 @@ pub mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let message = Message::try_from_circuit_output(
|
let message = Message::try_from_circuit_output(
|
||||||
vec![sender_keys.address()],
|
vec![sender_keys.account_id()],
|
||||||
vec![sender_nonce],
|
vec![sender_nonce],
|
||||||
vec![(recipient_keys.npk(), recipient_keys.ivk(), epk)],
|
vec![(recipient_keys.npk(), recipient_keys.ivk(), epk)],
|
||||||
output,
|
output,
|
||||||
@ -911,7 +911,7 @@ pub mod tests {
|
|||||||
fn deshielded_balance_transfer_for_tests(
|
fn deshielded_balance_transfer_for_tests(
|
||||||
sender_keys: &TestPrivateKeys,
|
sender_keys: &TestPrivateKeys,
|
||||||
sender_private_account: &Account,
|
sender_private_account: &Account,
|
||||||
recipient_address: &Address,
|
recipient_account_id: &AccountId,
|
||||||
balance_to_move: u128,
|
balance_to_move: u128,
|
||||||
new_nonce: Nonce,
|
new_nonce: Nonce,
|
||||||
state: &V02State,
|
state: &V02State,
|
||||||
@ -921,9 +921,9 @@ pub mod tests {
|
|||||||
let sender_pre =
|
let sender_pre =
|
||||||
AccountWithMetadata::new(sender_private_account.clone(), true, &sender_keys.npk());
|
AccountWithMetadata::new(sender_private_account.clone(), true, &sender_keys.npk());
|
||||||
let recipient_pre = AccountWithMetadata::new(
|
let recipient_pre = AccountWithMetadata::new(
|
||||||
state.get_account_by_address(recipient_address),
|
state.get_account_by_id(recipient_account_id),
|
||||||
false,
|
false,
|
||||||
*recipient_address,
|
*recipient_account_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
let esk = [3; 32];
|
let esk = [3; 32];
|
||||||
@ -945,7 +945,7 @@ pub mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let message = Message::try_from_circuit_output(
|
let message = Message::try_from_circuit_output(
|
||||||
vec![*recipient_address],
|
vec![*recipient_account_id],
|
||||||
vec![],
|
vec![],
|
||||||
vec![(sender_keys.npk(), sender_keys.ivk(), epk)],
|
vec![(sender_keys.npk(), sender_keys.ivk(), epk)],
|
||||||
output,
|
output,
|
||||||
@ -962,7 +962,8 @@ pub mod tests {
|
|||||||
let sender_keys = test_public_account_keys_1();
|
let sender_keys = test_public_account_keys_1();
|
||||||
let recipient_keys = test_private_account_keys_1();
|
let recipient_keys = test_private_account_keys_1();
|
||||||
|
|
||||||
let mut state = V02State::new_with_genesis_accounts(&[(sender_keys.address(), 200)], &[]);
|
let mut state =
|
||||||
|
V02State::new_with_genesis_accounts(&[(sender_keys.account_id(), 200)], &[]);
|
||||||
|
|
||||||
let balance_to_move = 37;
|
let balance_to_move = 37;
|
||||||
|
|
||||||
@ -974,7 +975,7 @@ pub mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let expected_sender_post = {
|
let expected_sender_post = {
|
||||||
let mut this = state.get_account_by_address(&sender_keys.address());
|
let mut this = state.get_account_by_id(&sender_keys.account_id());
|
||||||
this.balance -= balance_to_move;
|
this.balance -= balance_to_move;
|
||||||
this.nonce += 1;
|
this.nonce += 1;
|
||||||
this
|
this
|
||||||
@ -987,12 +988,12 @@ pub mod tests {
|
|||||||
.transition_from_privacy_preserving_transaction(&tx)
|
.transition_from_privacy_preserving_transaction(&tx)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let sender_post = state.get_account_by_address(&sender_keys.address());
|
let sender_post = state.get_account_by_id(&sender_keys.account_id());
|
||||||
assert_eq!(sender_post, expected_sender_post);
|
assert_eq!(sender_post, expected_sender_post);
|
||||||
assert!(state.private_state.0.contains(&expected_new_commitment));
|
assert!(state.private_state.0.contains(&expected_new_commitment));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
state.get_account_by_address(&sender_keys.address()).balance,
|
state.get_account_by_id(&sender_keys.account_id()).balance,
|
||||||
200 - balance_to_move
|
200 - balance_to_move
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1075,7 +1076,7 @@ pub mod tests {
|
|||||||
let recipient_keys = test_public_account_keys_1();
|
let recipient_keys = test_public_account_keys_1();
|
||||||
let recipient_initial_balance = 400;
|
let recipient_initial_balance = 400;
|
||||||
let mut state = V02State::new_with_genesis_accounts(
|
let mut state = V02State::new_with_genesis_accounts(
|
||||||
&[(recipient_keys.address(), recipient_initial_balance)],
|
&[(recipient_keys.account_id(), recipient_initial_balance)],
|
||||||
&[],
|
&[],
|
||||||
)
|
)
|
||||||
.with_private_account(&sender_keys, &sender_private_account);
|
.with_private_account(&sender_keys, &sender_private_account);
|
||||||
@ -1083,7 +1084,7 @@ pub mod tests {
|
|||||||
let balance_to_move = 37;
|
let balance_to_move = 37;
|
||||||
|
|
||||||
let expected_recipient_post = {
|
let expected_recipient_post = {
|
||||||
let mut this = state.get_account_by_address(&recipient_keys.address());
|
let mut this = state.get_account_by_id(&recipient_keys.account_id());
|
||||||
this.balance += balance_to_move;
|
this.balance += balance_to_move;
|
||||||
this
|
this
|
||||||
};
|
};
|
||||||
@ -1091,7 +1092,7 @@ pub mod tests {
|
|||||||
let tx = deshielded_balance_transfer_for_tests(
|
let tx = deshielded_balance_transfer_for_tests(
|
||||||
&sender_keys,
|
&sender_keys,
|
||||||
&sender_private_account,
|
&sender_private_account,
|
||||||
&recipient_keys.address(),
|
&recipient_keys.account_id(),
|
||||||
balance_to_move,
|
balance_to_move,
|
||||||
0xcafecafe,
|
0xcafecafe,
|
||||||
&state,
|
&state,
|
||||||
@ -1119,14 +1120,14 @@ pub mod tests {
|
|||||||
.transition_from_privacy_preserving_transaction(&tx)
|
.transition_from_privacy_preserving_transaction(&tx)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let recipient_post = state.get_account_by_address(&recipient_keys.address());
|
let recipient_post = state.get_account_by_id(&recipient_keys.account_id());
|
||||||
assert_eq!(recipient_post, expected_recipient_post);
|
assert_eq!(recipient_post, expected_recipient_post);
|
||||||
assert!(state.private_state.0.contains(&sender_pre_commitment));
|
assert!(state.private_state.0.contains(&sender_pre_commitment));
|
||||||
assert!(state.private_state.0.contains(&expected_new_commitment));
|
assert!(state.private_state.0.contains(&expected_new_commitment));
|
||||||
assert!(state.private_state.1.contains(&expected_new_nullifier));
|
assert!(state.private_state.1.contains(&expected_new_nullifier));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
state
|
state
|
||||||
.get_account_by_address(&recipient_keys.address())
|
.get_account_by_id(&recipient_keys.account_id())
|
||||||
.balance,
|
.balance,
|
||||||
recipient_initial_balance + balance_to_move
|
recipient_initial_balance + balance_to_move
|
||||||
);
|
);
|
||||||
@ -2046,18 +2047,18 @@ pub mod tests {
|
|||||||
fn test_claiming_mechanism() {
|
fn test_claiming_mechanism() {
|
||||||
let program = Program::authenticated_transfer_program();
|
let program = Program::authenticated_transfer_program();
|
||||||
let key = PrivateKey::try_new([1; 32]).unwrap();
|
let key = PrivateKey::try_new([1; 32]).unwrap();
|
||||||
let address = Address::from(&PublicKey::new_from_private_key(&key));
|
let account_id = AccountId::from(&PublicKey::new_from_private_key(&key));
|
||||||
let initial_balance = 100;
|
let initial_balance = 100;
|
||||||
let initial_data = [(address, initial_balance)];
|
let initial_data = [(account_id, initial_balance)];
|
||||||
let mut state =
|
let mut state =
|
||||||
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
||||||
let from = address;
|
let from = account_id;
|
||||||
let from_key = key;
|
let from_key = key;
|
||||||
let to = Address::new([2; 32]);
|
let to = AccountId::new([2; 32]);
|
||||||
let amount: u128 = 37;
|
let amount: u128 = 37;
|
||||||
|
|
||||||
// Check the recipient is an uninitialized account
|
// Check the recipient is an uninitialized account
|
||||||
assert_eq!(state.get_account_by_address(&to), Account::default());
|
assert_eq!(state.get_account_by_id(&to), Account::default());
|
||||||
|
|
||||||
let expected_recipient_post = Account {
|
let expected_recipient_post = Account {
|
||||||
program_owner: program.id(),
|
program_owner: program.id(),
|
||||||
@ -2073,7 +2074,7 @@ pub mod tests {
|
|||||||
|
|
||||||
state.transition_from_public_transaction(&tx).unwrap();
|
state.transition_from_public_transaction(&tx).unwrap();
|
||||||
|
|
||||||
let recipient_post = state.get_account_by_address(&to);
|
let recipient_post = state.get_account_by_id(&to);
|
||||||
|
|
||||||
assert_eq!(recipient_post, expected_recipient_post);
|
assert_eq!(recipient_post, expected_recipient_post);
|
||||||
}
|
}
|
||||||
@ -2082,14 +2083,14 @@ pub mod tests {
|
|||||||
fn test_chained_call() {
|
fn test_chained_call() {
|
||||||
let program = Program::chain_caller();
|
let program = Program::chain_caller();
|
||||||
let key = PrivateKey::try_new([1; 32]).unwrap();
|
let key = PrivateKey::try_new([1; 32]).unwrap();
|
||||||
let address = Address::from(&PublicKey::new_from_private_key(&key));
|
let account_id = AccountId::from(&PublicKey::new_from_private_key(&key));
|
||||||
let initial_balance = 100;
|
let initial_balance = 100;
|
||||||
let initial_data = [(address, initial_balance)];
|
let initial_data = [(account_id, initial_balance)];
|
||||||
let mut state =
|
let mut state =
|
||||||
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
V02State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
||||||
let from = address;
|
let from = account_id;
|
||||||
let from_key = key;
|
let from_key = key;
|
||||||
let to = Address::new([2; 32]);
|
let to = AccountId::new([2; 32]);
|
||||||
let amount: u128 = 37;
|
let amount: u128 = 37;
|
||||||
let instruction: (u128, ProgramId) =
|
let instruction: (u128, ProgramId) =
|
||||||
(amount, Program::authenticated_transfer_program().id());
|
(amount, Program::authenticated_transfer_program().id());
|
||||||
@ -2112,8 +2113,8 @@ pub mod tests {
|
|||||||
|
|
||||||
state.transition_from_public_transaction(&tx).unwrap();
|
state.transition_from_public_transaction(&tx).unwrap();
|
||||||
|
|
||||||
let from_post = state.get_account_by_address(&from);
|
let from_post = state.get_account_by_id(&from);
|
||||||
let to_post = state.get_account_by_address(&to);
|
let to_post = state.get_account_by_id(&to);
|
||||||
assert_eq!(from_post.balance, initial_balance - amount);
|
assert_eq!(from_post.balance, initial_balance - amount);
|
||||||
assert_eq!(to_post, expected_to_post);
|
assert_eq!(to_post, expected_to_post);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,13 +4,13 @@ use std::path::PathBuf;
|
|||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
///Helperstruct for account serialization
|
///Helperstruct for account serialization
|
||||||
pub struct AccountInitialData {
|
pub struct AccountInitialData {
|
||||||
///Hex encoded `AccountAddress`
|
/// Hex encoded account id
|
||||||
pub addr: String,
|
pub account_id: String,
|
||||||
pub balance: u128,
|
pub balance: u128,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
///Helperstruct to initialize commitments
|
/// Helperstruct to initialize commitments
|
||||||
pub struct CommitmentsInitialData {
|
pub struct CommitmentsInitialData {
|
||||||
pub npk: nssa_core::NullifierPublicKey,
|
pub npk: nssa_core::NullifierPublicKey,
|
||||||
pub account: nssa_core::account::Account,
|
pub account: nssa_core::account::Account,
|
||||||
|
|||||||
@ -75,10 +75,10 @@ impl SequencerCore {
|
|||||||
initial_commitments.push(comm);
|
initial_commitments.push(comm);
|
||||||
}
|
}
|
||||||
|
|
||||||
let init_accs: Vec<(nssa::Address, u128)> = config
|
let init_accs: Vec<(nssa::AccountId, u128)> = config
|
||||||
.initial_accounts
|
.initial_accounts
|
||||||
.iter()
|
.iter()
|
||||||
.map(|acc_data| (acc_data.addr.parse().unwrap(), acc_data.balance))
|
.map(|acc_data| (acc_data.account_id.parse().unwrap(), acc_data.balance))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut state = nssa::V02State::new_with_genesis_accounts(&init_accs, &initial_commitments);
|
let mut state = nssa::V02State::new_with_genesis_accounts(&init_accs, &initial_commitments);
|
||||||
@ -276,23 +276,23 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn setup_sequencer_config() -> SequencerConfig {
|
fn setup_sequencer_config() -> SequencerConfig {
|
||||||
let acc1_addr: Vec<u8> = vec![
|
let acc1_account_id: 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<u8> = vec![
|
let acc2_account_id: 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: acc1_addr.to_base58(),
|
account_id: acc1_account_id.to_base58(),
|
||||||
balance: 10000,
|
balance: 10000,
|
||||||
};
|
};
|
||||||
|
|
||||||
let initial_acc2 = AccountInitialData {
|
let initial_acc2 = AccountInitialData {
|
||||||
addr: acc2_addr.to_base58(),
|
account_id: acc2_account_id.to_base58(),
|
||||||
balance: 20000,
|
balance: 20000,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -338,15 +338,15 @@ 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 = config.initial_accounts[0]
|
let acc1_account_id = config.initial_accounts[0]
|
||||||
.addr
|
.account_id
|
||||||
.clone()
|
.clone()
|
||||||
.from_base58()
|
.from_base58()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.try_into()
|
.try_into()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let acc2_addr = config.initial_accounts[1]
|
let acc2_account_id = config.initial_accounts[1]
|
||||||
.addr
|
.account_id
|
||||||
.clone()
|
.clone()
|
||||||
.from_base58()
|
.from_base58()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -355,11 +355,11 @@ mod tests {
|
|||||||
|
|
||||||
let balance_acc_1 = sequencer
|
let balance_acc_1 = sequencer
|
||||||
.state
|
.state
|
||||||
.get_account_by_address(&nssa::Address::new(acc1_addr))
|
.get_account_by_id(&nssa::AccountId::new(acc1_account_id))
|
||||||
.balance;
|
.balance;
|
||||||
let balance_acc_2 = sequencer
|
let balance_acc_2 = sequencer
|
||||||
.state
|
.state
|
||||||
.get_account_by_address(&nssa::Address::new(acc2_addr))
|
.get_account_by_id(&nssa::AccountId::new(acc2_account_id))
|
||||||
.balance;
|
.balance;
|
||||||
|
|
||||||
assert_eq!(10000, balance_acc_1);
|
assert_eq!(10000, balance_acc_1);
|
||||||
@ -368,23 +368,23 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_start_different_intial_accounts_balances() {
|
fn test_start_different_intial_accounts_balances() {
|
||||||
let acc1_addr: Vec<u8> = vec![
|
let acc1_account_id: 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<u8> = vec![
|
let acc2_account_id: 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: acc1_addr.to_base58(),
|
account_id: acc1_account_id.to_base58(),
|
||||||
balance: 10000,
|
balance: 10000,
|
||||||
};
|
};
|
||||||
|
|
||||||
let initial_acc2 = AccountInitialData {
|
let initial_acc2 = AccountInitialData {
|
||||||
addr: acc2_addr.to_base58(),
|
account_id: acc2_account_id.to_base58(),
|
||||||
balance: 20000,
|
balance: 20000,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -393,15 +393,15 @@ mod tests {
|
|||||||
let config = setup_sequencer_config_variable_initial_accounts(initial_accounts);
|
let config = setup_sequencer_config_variable_initial_accounts(initial_accounts);
|
||||||
let (sequencer, _mempool_handle) = SequencerCore::start_from_config(config.clone());
|
let (sequencer, _mempool_handle) = SequencerCore::start_from_config(config.clone());
|
||||||
|
|
||||||
let acc1_addr = config.initial_accounts[0]
|
let acc1_account_id = config.initial_accounts[0]
|
||||||
.addr
|
.account_id
|
||||||
.clone()
|
.clone()
|
||||||
.from_base58()
|
.from_base58()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.try_into()
|
.try_into()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let acc2_addr = config.initial_accounts[1]
|
let acc2_account_id = config.initial_accounts[1]
|
||||||
.addr
|
.account_id
|
||||||
.clone()
|
.clone()
|
||||||
.from_base58()
|
.from_base58()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -412,14 +412,14 @@ mod tests {
|
|||||||
10000,
|
10000,
|
||||||
sequencer
|
sequencer
|
||||||
.state
|
.state
|
||||||
.get_account_by_address(&nssa::Address::new(acc1_addr))
|
.get_account_by_id(&nssa::AccountId::new(acc1_account_id))
|
||||||
.balance
|
.balance
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
20000,
|
20000,
|
||||||
sequencer
|
sequencer
|
||||||
.state
|
.state
|
||||||
.get_account_by_address(&nssa::Address::new(acc2_addr))
|
.get_account_by_id(&nssa::AccountId::new(acc2_account_id))
|
||||||
.balance
|
.balance
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -437,14 +437,14 @@ mod tests {
|
|||||||
let (sequencer, _mempool_handle) = common_setup().await;
|
let (sequencer, _mempool_handle) = common_setup().await;
|
||||||
|
|
||||||
let acc1 = sequencer.sequencer_config.initial_accounts[0]
|
let acc1 = sequencer.sequencer_config.initial_accounts[0]
|
||||||
.addr
|
.account_id
|
||||||
.clone()
|
.clone()
|
||||||
.from_base58()
|
.from_base58()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.try_into()
|
.try_into()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let acc2 = sequencer.sequencer_config.initial_accounts[1]
|
let acc2 = sequencer.sequencer_config.initial_accounts[1]
|
||||||
.addr
|
.account_id
|
||||||
.clone()
|
.clone()
|
||||||
.from_base58()
|
.from_base58()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -466,14 +466,14 @@ mod tests {
|
|||||||
let (mut sequencer, _mempool_handle) = common_setup().await;
|
let (mut sequencer, _mempool_handle) = common_setup().await;
|
||||||
|
|
||||||
let acc1 = sequencer.sequencer_config.initial_accounts[0]
|
let acc1 = sequencer.sequencer_config.initial_accounts[0]
|
||||||
.addr
|
.account_id
|
||||||
.clone()
|
.clone()
|
||||||
.from_base58()
|
.from_base58()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.try_into()
|
.try_into()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let acc2 = sequencer.sequencer_config.initial_accounts[1]
|
let acc2 = sequencer.sequencer_config.initial_accounts[1]
|
||||||
.addr
|
.account_id
|
||||||
.clone()
|
.clone()
|
||||||
.from_base58()
|
.from_base58()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -503,14 +503,14 @@ mod tests {
|
|||||||
let (mut sequencer, _mempool_handle) = common_setup().await;
|
let (mut sequencer, _mempool_handle) = common_setup().await;
|
||||||
|
|
||||||
let acc1 = sequencer.sequencer_config.initial_accounts[0]
|
let acc1 = sequencer.sequencer_config.initial_accounts[0]
|
||||||
.addr
|
.account_id
|
||||||
.clone()
|
.clone()
|
||||||
.from_base58()
|
.from_base58()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.try_into()
|
.try_into()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let acc2 = sequencer.sequencer_config.initial_accounts[1]
|
let acc2 = sequencer.sequencer_config.initial_accounts[1]
|
||||||
.addr
|
.account_id
|
||||||
.clone()
|
.clone()
|
||||||
.from_base58()
|
.from_base58()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -542,14 +542,14 @@ mod tests {
|
|||||||
let (mut sequencer, _mempool_handle) = common_setup().await;
|
let (mut sequencer, _mempool_handle) = common_setup().await;
|
||||||
|
|
||||||
let acc1 = sequencer.sequencer_config.initial_accounts[0]
|
let acc1 = sequencer.sequencer_config.initial_accounts[0]
|
||||||
.addr
|
.account_id
|
||||||
.clone()
|
.clone()
|
||||||
.from_base58()
|
.from_base58()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.try_into()
|
.try_into()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let acc2 = sequencer.sequencer_config.initial_accounts[1]
|
let acc2 = sequencer.sequencer_config.initial_accounts[1]
|
||||||
.addr
|
.account_id
|
||||||
.clone()
|
.clone()
|
||||||
.from_base58()
|
.from_base58()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -568,11 +568,11 @@ mod tests {
|
|||||||
|
|
||||||
let bal_from = sequencer
|
let bal_from = sequencer
|
||||||
.state
|
.state
|
||||||
.get_account_by_address(&nssa::Address::new(acc1))
|
.get_account_by_id(&nssa::AccountId::new(acc1))
|
||||||
.balance;
|
.balance;
|
||||||
let bal_to = sequencer
|
let bal_to = sequencer
|
||||||
.state
|
.state
|
||||||
.get_account_by_address(&nssa::Address::new(acc2))
|
.get_account_by_id(&nssa::AccountId::new(acc2))
|
||||||
.balance;
|
.balance;
|
||||||
|
|
||||||
assert_eq!(bal_from, 9900);
|
assert_eq!(bal_from, 9900);
|
||||||
@ -624,14 +624,14 @@ mod tests {
|
|||||||
let (mut sequencer, mempool_handle) = common_setup().await;
|
let (mut sequencer, mempool_handle) = common_setup().await;
|
||||||
|
|
||||||
let acc1 = sequencer.sequencer_config.initial_accounts[0]
|
let acc1 = sequencer.sequencer_config.initial_accounts[0]
|
||||||
.addr
|
.account_id
|
||||||
.clone()
|
.clone()
|
||||||
.from_base58()
|
.from_base58()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.try_into()
|
.try_into()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let acc2 = sequencer.sequencer_config.initial_accounts[1]
|
let acc2 = sequencer.sequencer_config.initial_accounts[1]
|
||||||
.addr
|
.account_id
|
||||||
.clone()
|
.clone()
|
||||||
.from_base58()
|
.from_base58()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -668,14 +668,14 @@ mod tests {
|
|||||||
let (mut sequencer, mempool_handle) = common_setup().await;
|
let (mut sequencer, mempool_handle) = common_setup().await;
|
||||||
|
|
||||||
let acc1 = sequencer.sequencer_config.initial_accounts[0]
|
let acc1 = sequencer.sequencer_config.initial_accounts[0]
|
||||||
.addr
|
.account_id
|
||||||
.clone()
|
.clone()
|
||||||
.from_base58()
|
.from_base58()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.try_into()
|
.try_into()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let acc2 = sequencer.sequencer_config.initial_accounts[1]
|
let acc2 = sequencer.sequencer_config.initial_accounts[1]
|
||||||
.addr
|
.account_id
|
||||||
.clone()
|
.clone()
|
||||||
.from_base58()
|
.from_base58()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -714,8 +714,10 @@ mod tests {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_restart_from_storage() {
|
async fn test_restart_from_storage() {
|
||||||
let config = setup_sequencer_config();
|
let config = setup_sequencer_config();
|
||||||
let acc1_addr: nssa::Address = config.initial_accounts[0].addr.parse().unwrap();
|
let acc1_account_id: nssa::AccountId =
|
||||||
let acc2_addr: nssa::Address = config.initial_accounts[1].addr.parse().unwrap();
|
config.initial_accounts[0].account_id.parse().unwrap();
|
||||||
|
let acc2_account_id: nssa::AccountId =
|
||||||
|
config.initial_accounts[1].account_id.parse().unwrap();
|
||||||
let balance_to_move = 13;
|
let balance_to_move = 13;
|
||||||
|
|
||||||
// In the following code block a transaction will be processed that moves `balance_to_move`
|
// In the following code block a transaction will be processed that moves `balance_to_move`
|
||||||
@ -726,9 +728,9 @@ mod tests {
|
|||||||
let signing_key = PrivateKey::try_new([1; 32]).unwrap();
|
let signing_key = PrivateKey::try_new([1; 32]).unwrap();
|
||||||
|
|
||||||
let tx = common::test_utils::create_transaction_native_token_transfer(
|
let tx = common::test_utils::create_transaction_native_token_transfer(
|
||||||
*acc1_addr.value(),
|
*acc1_account_id.value(),
|
||||||
0,
|
0,
|
||||||
*acc2_addr.value(),
|
*acc2_account_id.value(),
|
||||||
balance_to_move,
|
balance_to_move,
|
||||||
signing_key,
|
signing_key,
|
||||||
);
|
);
|
||||||
@ -747,8 +749,8 @@ mod tests {
|
|||||||
// Instantiating a new sequencer from the same config. This should load the existing block
|
// Instantiating a new sequencer from the same config. This should load the existing block
|
||||||
// with the above transaction and update the state to reflect that.
|
// with the above transaction and update the state to reflect that.
|
||||||
let (sequencer, _mempool_handle) = SequencerCore::start_from_config(config.clone());
|
let (sequencer, _mempool_handle) = SequencerCore::start_from_config(config.clone());
|
||||||
let balance_acc_1 = sequencer.state.get_account_by_address(&acc1_addr).balance;
|
let balance_acc_1 = sequencer.state.get_account_by_id(&acc1_account_id).balance;
|
||||||
let balance_acc_2 = sequencer.state.get_account_by_address(&acc2_addr).balance;
|
let balance_acc_2 = sequencer.state.get_account_by_id(&acc2_account_id).balance;
|
||||||
|
|
||||||
// Balances should be consistent with the stored block
|
// Balances should be consistent with the stored block
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|||||||
@ -1,74 +0,0 @@
|
|||||||
use std::path::Path;
|
|
||||||
|
|
||||||
use block_store::SequecerBlockStore;
|
|
||||||
use common::block::HashableBlockData;
|
|
||||||
use nssa::{self, Address};
|
|
||||||
use rand::{RngCore, rngs::OsRng};
|
|
||||||
|
|
||||||
use crate::config::AccountInitialData;
|
|
||||||
|
|
||||||
pub mod block_store;
|
|
||||||
|
|
||||||
pub struct SequecerChainStore {
|
|
||||||
pub state: nssa::V02State,
|
|
||||||
pub block_store: SequecerBlockStore,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SequecerChainStore {
|
|
||||||
pub fn new_with_genesis(
|
|
||||||
home_dir: &Path,
|
|
||||||
genesis_id: u64,
|
|
||||||
is_genesis_random: bool,
|
|
||||||
initial_accounts: &[AccountInitialData],
|
|
||||||
initial_commitments: &[nssa_core::Commitment],
|
|
||||||
signing_key: nssa::PrivateKey,
|
|
||||||
) -> Self {
|
|
||||||
let init_accs: Vec<(Address, u128)> = initial_accounts
|
|
||||||
.iter()
|
|
||||||
.map(|acc_data| (acc_data.addr.parse().unwrap(), acc_data.balance))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
#[cfg(not(feature = "testnet"))]
|
|
||||||
let state = nssa::V02State::new_with_genesis_accounts(&init_accs, initial_commitments);
|
|
||||||
|
|
||||||
#[cfg(feature = "testnet")]
|
|
||||||
let state = {
|
|
||||||
use common::PINATA_BASE58;
|
|
||||||
|
|
||||||
let mut this =
|
|
||||||
nssa::V02State::new_with_genesis_accounts(&init_accs, initial_commitments);
|
|
||||||
this.add_pinata_program(PINATA_BASE58.parse().unwrap());
|
|
||||||
this
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut data = [0; 32];
|
|
||||||
let mut prev_block_hash = [0; 32];
|
|
||||||
|
|
||||||
if is_genesis_random {
|
|
||||||
OsRng.fill_bytes(&mut data);
|
|
||||||
OsRng.fill_bytes(&mut prev_block_hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
let curr_time = chrono::Utc::now().timestamp_millis() as u64;
|
|
||||||
|
|
||||||
let hashable_data = HashableBlockData {
|
|
||||||
block_id: genesis_id,
|
|
||||||
transactions: vec![],
|
|
||||||
prev_block_hash,
|
|
||||||
timestamp: curr_time,
|
|
||||||
};
|
|
||||||
|
|
||||||
let genesis_block = hashable_data.into_block(&signing_key);
|
|
||||||
|
|
||||||
//Sequencer should panic if unable to open db,
|
|
||||||
//as fixing this issue may require actions non-native to program scope
|
|
||||||
let block_store = SequecerBlockStore::open_db_with_genesis(
|
|
||||||
&home_dir.join("rocksdb"),
|
|
||||||
Some(genesis_block),
|
|
||||||
signing_key,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
Self { state, block_store }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -166,23 +166,23 @@ impl JsonHandler {
|
|||||||
respond(initial_accounts)
|
respond(initial_accounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the balance of the account at the given address.
|
/// Returns the balance of the account at the given account_id.
|
||||||
/// The address must be a valid hex string of the correct length.
|
/// The account_id 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 = get_account_req
|
let account_id_bytes = get_account_req
|
||||||
.address
|
.account_id
|
||||||
.from_base58()
|
.from_base58()
|
||||||
.map_err(|_| RpcError::invalid_params("invalid base58".to_string()))?;
|
.map_err(|_| RpcError::invalid_params("invalid base58".to_string()))?;
|
||||||
let address = nssa::Address::new(
|
let account_id = nssa::AccountId::new(
|
||||||
address_bytes
|
account_id_bytes
|
||||||
.try_into()
|
.try_into()
|
||||||
.map_err(|_| RpcError::invalid_params("invalid length".to_string()))?,
|
.map_err(|_| RpcError::invalid_params("invalid length".to_string()))?,
|
||||||
);
|
);
|
||||||
|
|
||||||
let balance = {
|
let balance = {
|
||||||
let state = self.sequencer_state.lock().await;
|
let state = self.sequencer_state.lock().await;
|
||||||
let account = state.state().get_account_by_address(&address);
|
let account = state.state().get_account_by_id(&account_id);
|
||||||
account.balance
|
account.balance
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -191,25 +191,25 @@ impl JsonHandler {
|
|||||||
respond(response)
|
respond(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the nonces of the accounts at the given addresses.
|
/// Returns the nonces of the accounts at the given account_ids.
|
||||||
/// Each address must be a valid hex string of the correct length.
|
/// Each account_id must be a valid hex string of the correct length.
|
||||||
async fn process_get_accounts_nonces(&self, request: Request) -> Result<Value, RpcErr> {
|
async fn process_get_accounts_nonces(&self, request: Request) -> Result<Value, RpcErr> {
|
||||||
let get_account_nonces_req = GetAccountsNoncesRequest::parse(Some(request.params))?;
|
let get_account_nonces_req = GetAccountsNoncesRequest::parse(Some(request.params))?;
|
||||||
let mut addresses = vec![];
|
let mut account_ids = vec![];
|
||||||
for address_raw in get_account_nonces_req.addresses {
|
for account_id_raw in get_account_nonces_req.account_ids {
|
||||||
let address = address_raw
|
let account_id = account_id_raw
|
||||||
.parse::<nssa::Address>()
|
.parse::<nssa::AccountId>()
|
||||||
.map_err(|e| RpcError::invalid_params(e.to_string()))?;
|
.map_err(|e| RpcError::invalid_params(e.to_string()))?;
|
||||||
|
|
||||||
addresses.push(address);
|
account_ids.push(account_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
let nonces = {
|
let nonces = {
|
||||||
let state = self.sequencer_state.lock().await;
|
let state = self.sequencer_state.lock().await;
|
||||||
|
|
||||||
addresses
|
account_ids
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|addr| state.state().get_account_by_address(&addr).nonce)
|
.map(|account_id| state.state().get_account_by_id(&account_id).nonce)
|
||||||
.collect()
|
.collect()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -218,20 +218,20 @@ impl JsonHandler {
|
|||||||
respond(response)
|
respond(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns account struct for given address.
|
/// Returns account struct for given account_id.
|
||||||
/// Address must be a valid hex string of the correct length.
|
/// AccountId must be a valid hex string of the correct length.
|
||||||
async fn process_get_account(&self, request: Request) -> Result<Value, RpcErr> {
|
async fn process_get_account(&self, request: Request) -> Result<Value, RpcErr> {
|
||||||
let get_account_nonces_req = GetAccountRequest::parse(Some(request.params))?;
|
let get_account_nonces_req = GetAccountRequest::parse(Some(request.params))?;
|
||||||
|
|
||||||
let address = get_account_nonces_req
|
let account_id = get_account_nonces_req
|
||||||
.address
|
.account_id
|
||||||
.parse::<nssa::Address>()
|
.parse::<nssa::AccountId>()
|
||||||
.map_err(|e| RpcError::invalid_params(e.to_string()))?;
|
.map_err(|e| RpcError::invalid_params(e.to_string()))?;
|
||||||
|
|
||||||
let account = {
|
let account = {
|
||||||
let state = self.sequencer_state.lock().await;
|
let state = self.sequencer_state.lock().await;
|
||||||
|
|
||||||
state.state().get_account_by_address(&address)
|
state.state().get_account_by_id(&account_id)
|
||||||
};
|
};
|
||||||
|
|
||||||
let response = GetAccountResponse { account };
|
let response = GetAccountResponse { account };
|
||||||
@ -334,23 +334,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<u8> = vec![
|
let acc1_id: 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<u8> = vec![
|
let acc2_id: 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: acc1_addr.to_base58(),
|
account_id: acc1_id.to_base58(),
|
||||||
balance: 10000,
|
balance: 10000,
|
||||||
};
|
};
|
||||||
|
|
||||||
let initial_acc2 = AccountInitialData {
|
let initial_acc2 = AccountInitialData {
|
||||||
addr: acc2_addr.to_base58(),
|
account_id: acc2_id.to_base58(),
|
||||||
balance: 20000,
|
balance: 20000,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -437,7 +437,7 @@ mod tests {
|
|||||||
let request = serde_json::json!({
|
let request = serde_json::json!({
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"method": "get_account_balance",
|
"method": "get_account_balance",
|
||||||
"params": { "address": "11".repeat(16) },
|
"params": { "account_id": "11".repeat(16) },
|
||||||
"id": 1
|
"id": 1
|
||||||
});
|
});
|
||||||
let expected_response = serde_json::json!({
|
let expected_response = serde_json::json!({
|
||||||
@ -459,7 +459,7 @@ mod tests {
|
|||||||
let request = serde_json::json!({
|
let request = serde_json::json!({
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"method": "get_account_balance",
|
"method": "get_account_balance",
|
||||||
"params": { "address": "not_a_valid_base58" },
|
"params": { "account_id": "not_a_valid_base58" },
|
||||||
"id": 1
|
"id": 1
|
||||||
});
|
});
|
||||||
let expected_response = serde_json::json!({
|
let expected_response = serde_json::json!({
|
||||||
@ -482,7 +482,7 @@ mod tests {
|
|||||||
let request = serde_json::json!({
|
let request = serde_json::json!({
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"method": "get_account_balance",
|
"method": "get_account_balance",
|
||||||
"params": { "address": "cafecafe" },
|
"params": { "account_id": "cafecafe" },
|
||||||
"id": 1
|
"id": 1
|
||||||
});
|
});
|
||||||
let expected_response = serde_json::json!({
|
let expected_response = serde_json::json!({
|
||||||
@ -503,12 +503,12 @@ mod tests {
|
|||||||
async fn test_get_account_balance_for_existing_account() {
|
async fn test_get_account_balance_for_existing_account() {
|
||||||
let (json_handler, initial_accounts, _) = components_for_tests().await;
|
let (json_handler, initial_accounts, _) = components_for_tests().await;
|
||||||
|
|
||||||
let acc1_addr = initial_accounts[0].addr.clone();
|
let acc1_id = initial_accounts[0].account_id.clone();
|
||||||
|
|
||||||
let request = serde_json::json!({
|
let request = serde_json::json!({
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"method": "get_account_balance",
|
"method": "get_account_balance",
|
||||||
"params": { "address": acc1_addr },
|
"params": { "account_id": acc1_id },
|
||||||
"id": 1
|
"id": 1
|
||||||
});
|
});
|
||||||
let expected_response = serde_json::json!({
|
let expected_response = serde_json::json!({
|
||||||
@ -530,7 +530,7 @@ mod tests {
|
|||||||
let request = serde_json::json!({
|
let request = serde_json::json!({
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"method": "get_accounts_nonces",
|
"method": "get_accounts_nonces",
|
||||||
"params": { "addresses": ["11".repeat(16)] },
|
"params": { "account_ids": ["11".repeat(16)] },
|
||||||
"id": 1
|
"id": 1
|
||||||
});
|
});
|
||||||
let expected_response = serde_json::json!({
|
let expected_response = serde_json::json!({
|
||||||
@ -550,13 +550,13 @@ mod tests {
|
|||||||
async fn test_get_accounts_nonces_for_existent_account() {
|
async fn test_get_accounts_nonces_for_existent_account() {
|
||||||
let (json_handler, initial_accounts, _) = components_for_tests().await;
|
let (json_handler, initial_accounts, _) = components_for_tests().await;
|
||||||
|
|
||||||
let acc_1_addr = initial_accounts[0].addr.clone();
|
let acc1_id = initial_accounts[0].account_id.clone();
|
||||||
let acc_2_addr = initial_accounts[1].addr.clone();
|
let acc2_id = initial_accounts[1].account_id.clone();
|
||||||
|
|
||||||
let request = serde_json::json!({
|
let request = serde_json::json!({
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"method": "get_accounts_nonces",
|
"method": "get_accounts_nonces",
|
||||||
"params": { "addresses": [acc_1_addr, acc_2_addr] },
|
"params": { "account_ids": [acc1_id, acc2_id] },
|
||||||
"id": 1
|
"id": 1
|
||||||
});
|
});
|
||||||
let expected_response = serde_json::json!({
|
let expected_response = serde_json::json!({
|
||||||
@ -578,7 +578,7 @@ mod tests {
|
|||||||
let request = serde_json::json!({
|
let request = serde_json::json!({
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"method": "get_account",
|
"method": "get_account",
|
||||||
"params": { "address": "11".repeat(16) },
|
"params": { "account_id": "11".repeat(16) },
|
||||||
"id": 1
|
"id": 1
|
||||||
});
|
});
|
||||||
let expected_response = serde_json::json!({
|
let expected_response = serde_json::json!({
|
||||||
|
|||||||
@ -9,11 +9,11 @@
|
|||||||
"port": 3040,
|
"port": 3040,
|
||||||
"initial_accounts": [
|
"initial_accounts": [
|
||||||
{
|
{
|
||||||
"addr": "BLgCRDXYdQPMMWVHYRFGQZbgeHx9frkipa8GtpG2Syqy",
|
"account_id": "BLgCRDXYdQPMMWVHYRFGQZbgeHx9frkipa8GtpG2Syqy",
|
||||||
"balance": 10000
|
"balance": 10000
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"addr": "Gj1mJy5W7J5pfmLRujmQaLfLMWidNxQ6uwnhb666ZwHw",
|
"account_id": "Gj1mJy5W7J5pfmLRujmQaLfLMWidNxQ6uwnhb666ZwHw",
|
||||||
"balance": 20000
|
"balance": 20000
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@ -19,7 +19,7 @@ impl WalletChainStore {
|
|||||||
for init_acc_data in config.initial_accounts.clone() {
|
for init_acc_data in config.initial_accounts.clone() {
|
||||||
match init_acc_data {
|
match init_acc_data {
|
||||||
InitialAccountData::Public(data) => {
|
InitialAccountData::Public(data) => {
|
||||||
public_init_acc_map.insert(data.address.parse()?, data.pub_sign_key);
|
public_init_acc_map.insert(data.account_id.parse()?, data.pub_sign_key);
|
||||||
}
|
}
|
||||||
InitialAccountData::Private(data) => {
|
InitialAccountData::Private(data) => {
|
||||||
let mut account = data.account;
|
let mut account = data.account;
|
||||||
@ -27,7 +27,8 @@ impl WalletChainStore {
|
|||||||
// the config. Therefore we overwrite it here on startup. Fix this when program
|
// the config. Therefore we overwrite it here on startup. Fix this when program
|
||||||
// id can be fetched from the node and queried from the wallet.
|
// id can be fetched from the node and queried from the wallet.
|
||||||
account.program_owner = Program::authenticated_transfer_program().id();
|
account.program_owner = Program::authenticated_transfer_program().id();
|
||||||
private_init_acc_map.insert(data.address.parse()?, (data.key_chain, account));
|
private_init_acc_map
|
||||||
|
.insert(data.account_id.parse()?, (data.key_chain, account));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,13 +41,16 @@ impl WalletChainStore {
|
|||||||
|
|
||||||
pub fn insert_private_account_data(
|
pub fn insert_private_account_data(
|
||||||
&mut self,
|
&mut self,
|
||||||
addr: nssa::Address,
|
account_id: nssa::AccountId,
|
||||||
account: nssa_core::account::Account,
|
account: nssa_core::account::Account,
|
||||||
) {
|
) {
|
||||||
println!("inserting at addres {}, this account {:?}", addr, account);
|
println!(
|
||||||
|
"inserting at addres {}, this account {:?}",
|
||||||
|
account_id, account
|
||||||
|
);
|
||||||
self.user_data
|
self.user_data
|
||||||
.user_private_accounts
|
.user_private_accounts
|
||||||
.entry(addr)
|
.entry(account_id)
|
||||||
.and_modify(|(_, acc)| *acc = account);
|
.and_modify(|(_, acc)| *acc = account);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,12 +59,12 @@ impl WalletChainStore {
|
|||||||
PersistentAccountData::Public(acc_data) => {
|
PersistentAccountData::Public(acc_data) => {
|
||||||
self.user_data
|
self.user_data
|
||||||
.pub_account_signing_keys
|
.pub_account_signing_keys
|
||||||
.insert(acc_data.address, acc_data.pub_sign_key);
|
.insert(acc_data.account_id, acc_data.pub_sign_key);
|
||||||
}
|
}
|
||||||
PersistentAccountData::Private(acc_data) => {
|
PersistentAccountData::Private(acc_data) => {
|
||||||
self.user_data
|
self.user_data
|
||||||
.user_private_accounts
|
.user_private_accounts
|
||||||
.insert(acc_data.address, (acc_data.key_chain, acc_data.account));
|
.insert(acc_data.account_id, (acc_data.key_chain, acc_data.account));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,7 +80,7 @@ mod tests {
|
|||||||
let initial_acc1 = serde_json::from_str(
|
let initial_acc1 = serde_json::from_str(
|
||||||
r#"{
|
r#"{
|
||||||
"Public": {
|
"Public": {
|
||||||
"address": "BLgCRDXYdQPMMWVHYRFGQZbgeHx9frkipa8GtpG2Syqy",
|
"account_id": "BLgCRDXYdQPMMWVHYRFGQZbgeHx9frkipa8GtpG2Syqy",
|
||||||
"pub_sign_key": [
|
"pub_sign_key": [
|
||||||
16,
|
16,
|
||||||
162,
|
162,
|
||||||
@ -119,7 +123,7 @@ mod tests {
|
|||||||
let initial_acc2 = serde_json::from_str(
|
let initial_acc2 = serde_json::from_str(
|
||||||
r#"{
|
r#"{
|
||||||
"Public": {
|
"Public": {
|
||||||
"address": "Gj1mJy5W7J5pfmLRujmQaLfLMWidNxQ6uwnhb666ZwHw",
|
"account_id": "Gj1mJy5W7J5pfmLRujmQaLfLMWidNxQ6uwnhb666ZwHw",
|
||||||
"pub_sign_key": [
|
"pub_sign_key": [
|
||||||
113,
|
113,
|
||||||
121,
|
121,
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use base58::ToBase58;
|
use base58::ToBase58;
|
||||||
use clap::Subcommand;
|
use clap::Subcommand;
|
||||||
use nssa::{Account, Address, program::Program};
|
use nssa::{Account, AccountId, program::Program};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
SubcommandReturnValue, WalletCore,
|
SubcommandReturnValue, WalletCore,
|
||||||
cli::WalletSubcommand,
|
cli::WalletSubcommand,
|
||||||
helperfunctions::{AddressPrivacyKind, HumanReadableAccount, parse_addr_with_privacy_prefix},
|
helperfunctions::{AccountPrivacyKind, HumanReadableAccount, parse_addr_with_privacy_prefix},
|
||||||
parse_block_range,
|
parse_block_range,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ struct TokenDefinition {
|
|||||||
struct TokenHolding {
|
struct TokenHolding {
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
account_type: u8,
|
account_type: u8,
|
||||||
definition_id: Address,
|
definition_id: AccountId,
|
||||||
balance: u128,
|
balance: u128,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ impl TokenHolding {
|
|||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let account_type = data[0];
|
let account_type = data[0];
|
||||||
let definition_id = Address::new(data[1..33].try_into().unwrap());
|
let definition_id = AccountId::new(data[1..33].try_into().unwrap());
|
||||||
let balance = u128::from_le_bytes(data[33..].try_into().unwrap());
|
let balance = u128::from_le_bytes(data[33..].try_into().unwrap());
|
||||||
Some(Self {
|
Some(Self {
|
||||||
definition_id,
|
definition_id,
|
||||||
@ -76,9 +76,9 @@ pub enum AccountSubcommand {
|
|||||||
raw: bool,
|
raw: bool,
|
||||||
///Valid 32 byte base58 string with privacy prefix
|
///Valid 32 byte base58 string with privacy prefix
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
addr: String,
|
account_id: String,
|
||||||
},
|
},
|
||||||
///Produce new public or private account
|
///Produce new public or private account
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
New(NewSubcommand),
|
New(NewSubcommand),
|
||||||
///Sync private accounts
|
///Sync private accounts
|
||||||
@ -101,28 +101,28 @@ impl WalletSubcommand for NewSubcommand {
|
|||||||
) -> Result<SubcommandReturnValue> {
|
) -> Result<SubcommandReturnValue> {
|
||||||
match self {
|
match self {
|
||||||
NewSubcommand::Public {} => {
|
NewSubcommand::Public {} => {
|
||||||
let addr = wallet_core.create_new_account_public();
|
let account_id = wallet_core.create_new_account_public();
|
||||||
|
|
||||||
println!("Generated new account with addr Public/{addr}");
|
println!("Generated new account with account_id Public/{account_id}");
|
||||||
|
|
||||||
let path = wallet_core.store_persistent_data().await?;
|
let path = wallet_core.store_persistent_data().await?;
|
||||||
|
|
||||||
println!("Stored persistent accounts at {path:#?}");
|
println!("Stored persistent accounts at {path:#?}");
|
||||||
|
|
||||||
Ok(SubcommandReturnValue::RegisterAccount { addr })
|
Ok(SubcommandReturnValue::RegisterAccount { account_id })
|
||||||
}
|
}
|
||||||
NewSubcommand::Private {} => {
|
NewSubcommand::Private {} => {
|
||||||
let addr = wallet_core.create_new_account_private();
|
let account_id = wallet_core.create_new_account_private();
|
||||||
|
|
||||||
let (key, _) = wallet_core
|
let (key, _) = wallet_core
|
||||||
.storage
|
.storage
|
||||||
.user_data
|
.user_data
|
||||||
.get_private_account(&addr)
|
.get_private_account(&account_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"Generated new account with addr Private/{}",
|
"Generated new account with account_id Private/{}",
|
||||||
addr.to_bytes().to_base58()
|
account_id.to_bytes().to_base58()
|
||||||
);
|
);
|
||||||
println!("With npk {}", hex::encode(key.nullifer_public_key.0));
|
println!("With npk {}", hex::encode(key.nullifer_public_key.0));
|
||||||
println!(
|
println!(
|
||||||
@ -134,7 +134,7 @@ impl WalletSubcommand for NewSubcommand {
|
|||||||
|
|
||||||
println!("Stored persistent accounts at {path:#?}");
|
println!("Stored persistent accounts at {path:#?}");
|
||||||
|
|
||||||
Ok(SubcommandReturnValue::RegisterAccount { addr })
|
Ok(SubcommandReturnValue::RegisterAccount { account_id })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,15 +193,17 @@ impl WalletSubcommand for AccountSubcommand {
|
|||||||
wallet_core: &mut WalletCore,
|
wallet_core: &mut WalletCore,
|
||||||
) -> Result<SubcommandReturnValue> {
|
) -> Result<SubcommandReturnValue> {
|
||||||
match self {
|
match self {
|
||||||
AccountSubcommand::Get { raw, addr } => {
|
AccountSubcommand::Get { raw, account_id } => {
|
||||||
let (addr, addr_kind) = parse_addr_with_privacy_prefix(&addr)?;
|
let (account_id, addr_kind) = parse_addr_with_privacy_prefix(&account_id)?;
|
||||||
|
|
||||||
let addr = addr.parse()?;
|
let account_id = account_id.parse()?;
|
||||||
|
|
||||||
let account = match addr_kind {
|
let account = match addr_kind {
|
||||||
AddressPrivacyKind::Public => wallet_core.get_account_public(addr).await?,
|
AccountPrivacyKind::Public => {
|
||||||
AddressPrivacyKind::Private => wallet_core
|
wallet_core.get_account_public(account_id).await?
|
||||||
.get_account_private(&addr)
|
}
|
||||||
|
AccountPrivacyKind::Private => wallet_core
|
||||||
|
.get_account_private(&account_id)
|
||||||
.ok_or(anyhow::anyhow!("Private account not found in storage"))?,
|
.ok_or(anyhow::anyhow!("Private account not found in storage"))?,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -243,7 +245,9 @@ impl WalletSubcommand for AccountSubcommand {
|
|||||||
|
|
||||||
serde_json::to_string(&acc_view)?
|
serde_json::to_string(&acc_view)?
|
||||||
} else {
|
} else {
|
||||||
anyhow::bail!("Invalid data for account {addr:#?} with token program");
|
anyhow::bail!(
|
||||||
|
"Invalid data for account {account_id:#?} with token program"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|||||||
@ -115,7 +115,7 @@ impl WalletSubcommand for ConfigSubcommand {
|
|||||||
println!("Value of variable RUST_LOG to override, affects logging");
|
println!("Value of variable RUST_LOG to override, affects logging");
|
||||||
}
|
}
|
||||||
"sequencer_addr" => {
|
"sequencer_addr" => {
|
||||||
println!("HTTP V4 address of sequencer");
|
println!("HTTP V4 account_id of sequencer");
|
||||||
}
|
}
|
||||||
"seq_poll_timeout_millis" => {
|
"seq_poll_timeout_millis" => {
|
||||||
println!(
|
println!(
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::Subcommand;
|
use clap::Subcommand;
|
||||||
use common::transaction::NSSATransaction;
|
use common::transaction::NSSATransaction;
|
||||||
use nssa::Address;
|
use nssa::AccountId;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
SubcommandReturnValue, WalletCore,
|
SubcommandReturnValue, WalletCore,
|
||||||
cli::WalletSubcommand,
|
cli::WalletSubcommand,
|
||||||
helperfunctions::{AddressPrivacyKind, parse_addr_with_privacy_prefix},
|
helperfunctions::{AccountPrivacyKind, parse_addr_with_privacy_prefix},
|
||||||
};
|
};
|
||||||
|
|
||||||
///Represents generic CLI subcommand for a wallet working with native token transfer program
|
///Represents generic CLI subcommand for a wallet working with native token transfer program
|
||||||
@ -14,9 +14,9 @@ use crate::{
|
|||||||
pub enum AuthTransferSubcommand {
|
pub enum AuthTransferSubcommand {
|
||||||
///Initialize account under authenticated transfer program
|
///Initialize account under authenticated transfer program
|
||||||
Init {
|
Init {
|
||||||
///addr - valid 32 byte base58 string with privacy prefix
|
///account_id - valid 32 byte base58 string with privacy prefix
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
addr: String,
|
account_id: String,
|
||||||
},
|
},
|
||||||
///Send native tokens from one account to another with variable privacy
|
///Send native tokens from one account to another with variable privacy
|
||||||
///
|
///
|
||||||
@ -48,15 +48,15 @@ impl WalletSubcommand for AuthTransferSubcommand {
|
|||||||
wallet_core: &mut WalletCore,
|
wallet_core: &mut WalletCore,
|
||||||
) -> Result<SubcommandReturnValue> {
|
) -> Result<SubcommandReturnValue> {
|
||||||
match self {
|
match self {
|
||||||
AuthTransferSubcommand::Init { addr } => {
|
AuthTransferSubcommand::Init { account_id } => {
|
||||||
let (addr, addr_privacy) = parse_addr_with_privacy_prefix(&addr)?;
|
let (account_id, addr_privacy) = parse_addr_with_privacy_prefix(&account_id)?;
|
||||||
|
|
||||||
match addr_privacy {
|
match addr_privacy {
|
||||||
AddressPrivacyKind::Public => {
|
AccountPrivacyKind::Public => {
|
||||||
let addr = addr.parse()?;
|
let account_id = account_id.parse()?;
|
||||||
|
|
||||||
let res = wallet_core
|
let res = wallet_core
|
||||||
.register_account_under_authenticated_transfers_programs(addr)
|
.register_account_under_authenticated_transfers_programs(account_id)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
println!("Results of tx send is {res:#?}");
|
println!("Results of tx send is {res:#?}");
|
||||||
@ -70,11 +70,13 @@ impl WalletSubcommand for AuthTransferSubcommand {
|
|||||||
|
|
||||||
println!("Stored persistent accounts at {path:#?}");
|
println!("Stored persistent accounts at {path:#?}");
|
||||||
}
|
}
|
||||||
AddressPrivacyKind::Private => {
|
AccountPrivacyKind::Private => {
|
||||||
let addr = addr.parse()?;
|
let account_id = account_id.parse()?;
|
||||||
|
|
||||||
let (res, [secret]) = wallet_core
|
let (res, [secret]) = wallet_core
|
||||||
.register_account_under_authenticated_transfers_programs_private(addr)
|
.register_account_under_authenticated_transfers_programs_private(
|
||||||
|
account_id,
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
println!("Results of tx send is {res:#?}");
|
println!("Results of tx send is {res:#?}");
|
||||||
@ -85,7 +87,7 @@ impl WalletSubcommand for AuthTransferSubcommand {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
||||||
let acc_decode_data = vec![(secret, addr)];
|
let acc_decode_data = vec![(secret, account_id)];
|
||||||
|
|
||||||
wallet_core.decode_insert_privacy_preserving_transaction_results(
|
wallet_core.decode_insert_privacy_preserving_transaction_results(
|
||||||
tx,
|
tx,
|
||||||
@ -111,12 +113,12 @@ impl WalletSubcommand for AuthTransferSubcommand {
|
|||||||
let underlying_subcommand = match (to, to_npk, to_ipk) {
|
let underlying_subcommand = match (to, to_npk, to_ipk) {
|
||||||
(None, None, None) => {
|
(None, None, None) => {
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"Provide either account address of receiver or their public keys"
|
"Provide either account account_id of receiver or their public keys"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
(Some(_), Some(_), Some(_)) => {
|
(Some(_), Some(_), Some(_)) => {
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"Provide only one variant: either account address of receiver or their public keys"
|
"Provide only one variant: either account account_id of receiver or their public keys"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
(_, Some(_), None) | (_, None, Some(_)) => {
|
(_, Some(_), None) | (_, None, Some(_)) => {
|
||||||
@ -127,10 +129,10 @@ impl WalletSubcommand for AuthTransferSubcommand {
|
|||||||
let (to, to_privacy) = parse_addr_with_privacy_prefix(&to)?;
|
let (to, to_privacy) = parse_addr_with_privacy_prefix(&to)?;
|
||||||
|
|
||||||
match (from_privacy, to_privacy) {
|
match (from_privacy, to_privacy) {
|
||||||
(AddressPrivacyKind::Public, AddressPrivacyKind::Public) => {
|
(AccountPrivacyKind::Public, AccountPrivacyKind::Public) => {
|
||||||
NativeTokenTransferProgramSubcommand::Public { from, to, amount }
|
NativeTokenTransferProgramSubcommand::Public { from, to, amount }
|
||||||
}
|
}
|
||||||
(AddressPrivacyKind::Private, AddressPrivacyKind::Private) => {
|
(AccountPrivacyKind::Private, AccountPrivacyKind::Private) => {
|
||||||
NativeTokenTransferProgramSubcommand::Private(
|
NativeTokenTransferProgramSubcommand::Private(
|
||||||
NativeTokenTransferProgramSubcommandPrivate::PrivateOwned {
|
NativeTokenTransferProgramSubcommandPrivate::PrivateOwned {
|
||||||
from,
|
from,
|
||||||
@ -139,14 +141,14 @@ impl WalletSubcommand for AuthTransferSubcommand {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
(AddressPrivacyKind::Private, AddressPrivacyKind::Public) => {
|
(AccountPrivacyKind::Private, AccountPrivacyKind::Public) => {
|
||||||
NativeTokenTransferProgramSubcommand::Deshielded {
|
NativeTokenTransferProgramSubcommand::Deshielded {
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
amount,
|
amount,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(AddressPrivacyKind::Public, AddressPrivacyKind::Private) => {
|
(AccountPrivacyKind::Public, AccountPrivacyKind::Private) => {
|
||||||
NativeTokenTransferProgramSubcommand::Shielded(
|
NativeTokenTransferProgramSubcommand::Shielded(
|
||||||
NativeTokenTransferProgramSubcommandShielded::ShieldedOwned {
|
NativeTokenTransferProgramSubcommandShielded::ShieldedOwned {
|
||||||
from,
|
from,
|
||||||
@ -161,7 +163,7 @@ impl WalletSubcommand for AuthTransferSubcommand {
|
|||||||
let (from, from_privacy) = parse_addr_with_privacy_prefix(&from)?;
|
let (from, from_privacy) = parse_addr_with_privacy_prefix(&from)?;
|
||||||
|
|
||||||
match from_privacy {
|
match from_privacy {
|
||||||
AddressPrivacyKind::Private => {
|
AccountPrivacyKind::Private => {
|
||||||
NativeTokenTransferProgramSubcommand::Private(
|
NativeTokenTransferProgramSubcommand::Private(
|
||||||
NativeTokenTransferProgramSubcommandPrivate::PrivateForeign {
|
NativeTokenTransferProgramSubcommandPrivate::PrivateForeign {
|
||||||
from,
|
from,
|
||||||
@ -171,7 +173,7 @@ impl WalletSubcommand for AuthTransferSubcommand {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
AddressPrivacyKind::Public => {
|
AccountPrivacyKind::Public => {
|
||||||
NativeTokenTransferProgramSubcommand::Shielded(
|
NativeTokenTransferProgramSubcommand::Shielded(
|
||||||
NativeTokenTransferProgramSubcommandShielded::ShieldedForeign {
|
NativeTokenTransferProgramSubcommandShielded::ShieldedForeign {
|
||||||
from,
|
from,
|
||||||
@ -309,8 +311,8 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommandPrivate {
|
|||||||
) -> Result<SubcommandReturnValue> {
|
) -> Result<SubcommandReturnValue> {
|
||||||
match self {
|
match self {
|
||||||
NativeTokenTransferProgramSubcommandPrivate::PrivateOwned { from, to, amount } => {
|
NativeTokenTransferProgramSubcommandPrivate::PrivateOwned { from, to, amount } => {
|
||||||
let from: Address = from.parse().unwrap();
|
let from: AccountId = from.parse().unwrap();
|
||||||
let to: Address = to.parse().unwrap();
|
let to: AccountId = 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?;
|
||||||
|
|
||||||
@ -356,7 +358,7 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommandPrivate {
|
|||||||
to_ipk,
|
to_ipk,
|
||||||
amount,
|
amount,
|
||||||
} => {
|
} => {
|
||||||
let from: Address = from.parse().unwrap();
|
let from: AccountId = from.parse().unwrap();
|
||||||
let to_npk_res = hex::decode(to_npk)?;
|
let to_npk_res = hex::decode(to_npk)?;
|
||||||
let mut to_npk = [0; 32];
|
let mut to_npk = [0; 32];
|
||||||
to_npk.copy_from_slice(&to_npk_res);
|
to_npk.copy_from_slice(&to_npk_res);
|
||||||
@ -405,8 +407,8 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommandShielded {
|
|||||||
) -> Result<SubcommandReturnValue> {
|
) -> Result<SubcommandReturnValue> {
|
||||||
match self {
|
match self {
|
||||||
NativeTokenTransferProgramSubcommandShielded::ShieldedOwned { from, to, amount } => {
|
NativeTokenTransferProgramSubcommandShielded::ShieldedOwned { from, to, amount } => {
|
||||||
let from: Address = from.parse().unwrap();
|
let from: AccountId = from.parse().unwrap();
|
||||||
let to: Address = to.parse().unwrap();
|
let to: AccountId = 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?;
|
||||||
|
|
||||||
@ -450,7 +452,7 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommandShielded {
|
|||||||
to_ipk,
|
to_ipk,
|
||||||
amount,
|
amount,
|
||||||
} => {
|
} => {
|
||||||
let from: Address = from.parse().unwrap();
|
let from: AccountId = from.parse().unwrap();
|
||||||
|
|
||||||
let to_npk_res = hex::decode(to_npk)?;
|
let to_npk_res = hex::decode(to_npk)?;
|
||||||
let mut to_npk = [0; 32];
|
let mut to_npk = [0; 32];
|
||||||
@ -494,8 +496,8 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommand {
|
|||||||
shielded_subcommand.handle_subcommand(wallet_core).await
|
shielded_subcommand.handle_subcommand(wallet_core).await
|
||||||
}
|
}
|
||||||
NativeTokenTransferProgramSubcommand::Deshielded { from, to, amount } => {
|
NativeTokenTransferProgramSubcommand::Deshielded { from, to, amount } => {
|
||||||
let from: Address = from.parse().unwrap();
|
let from: AccountId = from.parse().unwrap();
|
||||||
let to: Address = to.parse().unwrap();
|
let to: AccountId = to.parse().unwrap();
|
||||||
|
|
||||||
let (res, [secret]) = wallet_core
|
let (res, [secret]) = wallet_core
|
||||||
.send_deshielded_native_token_transfer(from, to, amount)
|
.send_deshielded_native_token_transfer(from, to, amount)
|
||||||
@ -524,8 +526,8 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommand {
|
|||||||
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
|
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
|
||||||
}
|
}
|
||||||
NativeTokenTransferProgramSubcommand::Public { from, to, amount } => {
|
NativeTokenTransferProgramSubcommand::Public { from, to, amount } => {
|
||||||
let from: Address = from.parse().unwrap();
|
let from: AccountId = from.parse().unwrap();
|
||||||
let to: Address = to.parse().unwrap();
|
let to: AccountId = to.parse().unwrap();
|
||||||
|
|
||||||
let res = wallet_core
|
let res = wallet_core
|
||||||
.send_public_native_token_transfer(from, to, amount)
|
.send_public_native_token_transfer(from, to, amount)
|
||||||
|
|||||||
@ -6,7 +6,7 @@ use log::info;
|
|||||||
use crate::{
|
use crate::{
|
||||||
SubcommandReturnValue, WalletCore,
|
SubcommandReturnValue, WalletCore,
|
||||||
cli::WalletSubcommand,
|
cli::WalletSubcommand,
|
||||||
helperfunctions::{AddressPrivacyKind, parse_addr_with_privacy_prefix},
|
helperfunctions::{AccountPrivacyKind, parse_addr_with_privacy_prefix},
|
||||||
};
|
};
|
||||||
|
|
||||||
///Represents generic CLI subcommand for a wallet working with pinata program
|
///Represents generic CLI subcommand for a wallet working with pinata program
|
||||||
@ -14,9 +14,9 @@ use crate::{
|
|||||||
pub enum PinataProgramAgnosticSubcommand {
|
pub enum PinataProgramAgnosticSubcommand {
|
||||||
///Claim pinata
|
///Claim pinata
|
||||||
Claim {
|
Claim {
|
||||||
///to_addr - valid 32 byte base58 string with privacy prefix
|
///to_account_id - valid 32 byte base58 string with privacy prefix
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
to_addr: String,
|
to_account_id: String,
|
||||||
///solution - solution to pinata challenge
|
///solution - solution to pinata challenge
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
solution: u128,
|
solution: u128,
|
||||||
@ -29,21 +29,25 @@ impl WalletSubcommand for PinataProgramAgnosticSubcommand {
|
|||||||
wallet_core: &mut WalletCore,
|
wallet_core: &mut WalletCore,
|
||||||
) -> Result<SubcommandReturnValue> {
|
) -> Result<SubcommandReturnValue> {
|
||||||
let underlying_subcommand = match self {
|
let underlying_subcommand = match self {
|
||||||
PinataProgramAgnosticSubcommand::Claim { to_addr, solution } => {
|
PinataProgramAgnosticSubcommand::Claim {
|
||||||
let (to_addr, to_addr_privacy) = parse_addr_with_privacy_prefix(&to_addr)?;
|
to_account_id,
|
||||||
|
solution,
|
||||||
|
} => {
|
||||||
|
let (to_account_id, to_addr_privacy) =
|
||||||
|
parse_addr_with_privacy_prefix(&to_account_id)?;
|
||||||
|
|
||||||
match to_addr_privacy {
|
match to_addr_privacy {
|
||||||
AddressPrivacyKind::Public => {
|
AccountPrivacyKind::Public => {
|
||||||
PinataProgramSubcommand::Public(PinataProgramSubcommandPublic::Claim {
|
PinataProgramSubcommand::Public(PinataProgramSubcommandPublic::Claim {
|
||||||
pinata_addr: PINATA_BASE58.to_string(),
|
pinata_account_id: PINATA_BASE58.to_string(),
|
||||||
winner_addr: to_addr,
|
winner_account_id: to_account_id,
|
||||||
solution,
|
solution,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
AddressPrivacyKind::Private => PinataProgramSubcommand::Private(
|
AccountPrivacyKind::Private => PinataProgramSubcommand::Private(
|
||||||
PinataProgramSubcommandPrivate::ClaimPrivateOwned {
|
PinataProgramSubcommandPrivate::ClaimPrivateOwned {
|
||||||
pinata_addr: PINATA_BASE58.to_string(),
|
pinata_account_id: PINATA_BASE58.to_string(),
|
||||||
winner_addr: to_addr,
|
winner_account_id: to_account_id,
|
||||||
solution,
|
solution,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -72,12 +76,12 @@ 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
|
||||||
Claim {
|
Claim {
|
||||||
///pinata_addr - valid 32 byte hex string
|
///pinata_account_id - valid 32 byte hex string
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pinata_addr: String,
|
pinata_account_id: String,
|
||||||
///winner_addr - valid 32 byte hex string
|
///winner_account_id - valid 32 byte hex string
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
winner_addr: String,
|
winner_account_id: String,
|
||||||
///solution - solution to pinata challenge
|
///solution - solution to pinata challenge
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
solution: u128,
|
solution: u128,
|
||||||
@ -90,12 +94,12 @@ 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
|
||||||
ClaimPrivateOwned {
|
ClaimPrivateOwned {
|
||||||
///pinata_addr - valid 32 byte hex string
|
///pinata_account_id - valid 32 byte hex string
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pinata_addr: String,
|
pinata_account_id: String,
|
||||||
///winner_addr - valid 32 byte hex string
|
///winner_account_id - valid 32 byte hex string
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
winner_addr: String,
|
winner_account_id: String,
|
||||||
///solution - solution to pinata challenge
|
///solution - solution to pinata challenge
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
solution: u128,
|
solution: u128,
|
||||||
@ -109,14 +113,14 @@ impl WalletSubcommand for PinataProgramSubcommandPublic {
|
|||||||
) -> Result<SubcommandReturnValue> {
|
) -> Result<SubcommandReturnValue> {
|
||||||
match self {
|
match self {
|
||||||
PinataProgramSubcommandPublic::Claim {
|
PinataProgramSubcommandPublic::Claim {
|
||||||
pinata_addr,
|
pinata_account_id,
|
||||||
winner_addr,
|
winner_account_id,
|
||||||
solution,
|
solution,
|
||||||
} => {
|
} => {
|
||||||
let res = wallet_core
|
let res = wallet_core
|
||||||
.claim_pinata(
|
.claim_pinata(
|
||||||
pinata_addr.parse().unwrap(),
|
pinata_account_id.parse().unwrap(),
|
||||||
winner_addr.parse().unwrap(),
|
winner_account_id.parse().unwrap(),
|
||||||
solution,
|
solution,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@ -135,22 +139,22 @@ impl WalletSubcommand for PinataProgramSubcommandPrivate {
|
|||||||
) -> Result<SubcommandReturnValue> {
|
) -> Result<SubcommandReturnValue> {
|
||||||
match self {
|
match self {
|
||||||
PinataProgramSubcommandPrivate::ClaimPrivateOwned {
|
PinataProgramSubcommandPrivate::ClaimPrivateOwned {
|
||||||
pinata_addr,
|
pinata_account_id,
|
||||||
winner_addr,
|
winner_account_id,
|
||||||
solution,
|
solution,
|
||||||
} => {
|
} => {
|
||||||
let pinata_addr = pinata_addr.parse().unwrap();
|
let pinata_account_id = pinata_account_id.parse().unwrap();
|
||||||
let winner_addr = winner_addr.parse().unwrap();
|
let winner_account_id = winner_account_id.parse().unwrap();
|
||||||
|
|
||||||
let winner_initialization = wallet_core
|
let winner_initialization = wallet_core
|
||||||
.check_private_account_initialized(&winner_addr)
|
.check_private_account_initialized(&winner_account_id)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let (res, [secret_winner]) = if let Some(winner_proof) = winner_initialization {
|
let (res, [secret_winner]) = if let Some(winner_proof) = winner_initialization {
|
||||||
wallet_core
|
wallet_core
|
||||||
.claim_pinata_private_owned_account_already_initialized(
|
.claim_pinata_private_owned_account_already_initialized(
|
||||||
pinata_addr,
|
pinata_account_id,
|
||||||
winner_addr,
|
winner_account_id,
|
||||||
solution,
|
solution,
|
||||||
winner_proof,
|
winner_proof,
|
||||||
)
|
)
|
||||||
@ -158,8 +162,8 @@ impl WalletSubcommand for PinataProgramSubcommandPrivate {
|
|||||||
} else {
|
} else {
|
||||||
wallet_core
|
wallet_core
|
||||||
.claim_pinata_private_owned_account_not_initialized(
|
.claim_pinata_private_owned_account_not_initialized(
|
||||||
pinata_addr,
|
pinata_account_id,
|
||||||
winner_addr,
|
winner_account_id,
|
||||||
solution,
|
solution,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
@ -173,7 +177,7 @@ impl WalletSubcommand for PinataProgramSubcommandPrivate {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
||||||
let acc_decode_data = vec![(secret_winner, winner_addr)];
|
let acc_decode_data = vec![(secret_winner, winner_account_id)];
|
||||||
|
|
||||||
wallet_core.decode_insert_privacy_preserving_transaction_results(
|
wallet_core.decode_insert_privacy_preserving_transaction_results(
|
||||||
tx,
|
tx,
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::Subcommand;
|
use clap::Subcommand;
|
||||||
use common::transaction::NSSATransaction;
|
use common::transaction::NSSATransaction;
|
||||||
use nssa::Address;
|
use nssa::AccountId;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
SubcommandReturnValue, WalletCore,
|
SubcommandReturnValue, WalletCore,
|
||||||
cli::WalletSubcommand,
|
cli::WalletSubcommand,
|
||||||
helperfunctions::{AddressPrivacyKind, parse_addr_with_privacy_prefix},
|
helperfunctions::{AccountPrivacyKind, parse_addr_with_privacy_prefix},
|
||||||
};
|
};
|
||||||
|
|
||||||
///Represents generic CLI subcommand for a wallet working with token program
|
///Represents generic CLI subcommand for a wallet working with token program
|
||||||
@ -16,12 +16,12 @@ pub enum TokenProgramAgnosticSubcommand {
|
|||||||
///
|
///
|
||||||
///Currently the only supported privacy options is for public definition
|
///Currently the only supported privacy options is for public definition
|
||||||
New {
|
New {
|
||||||
///definition_addr - valid 32 byte base58 string with privacy prefix
|
///definition_account_id - valid 32 byte base58 string with privacy prefix
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
definition_addr: String,
|
definition_account_id: String,
|
||||||
///supply_addr - valid 32 byte base58 string with privacy prefix
|
///supply_account_id - valid 32 byte base58 string with privacy prefix
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
supply_addr: String,
|
supply_account_id: String,
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
name: String,
|
name: String,
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
@ -58,42 +58,42 @@ impl WalletSubcommand for TokenProgramAgnosticSubcommand {
|
|||||||
) -> Result<SubcommandReturnValue> {
|
) -> Result<SubcommandReturnValue> {
|
||||||
match self {
|
match self {
|
||||||
TokenProgramAgnosticSubcommand::New {
|
TokenProgramAgnosticSubcommand::New {
|
||||||
definition_addr,
|
definition_account_id,
|
||||||
supply_addr,
|
supply_account_id,
|
||||||
name,
|
name,
|
||||||
total_supply,
|
total_supply,
|
||||||
} => {
|
} => {
|
||||||
let (definition_addr, definition_addr_privacy) =
|
let (definition_account_id, definition_addr_privacy) =
|
||||||
parse_addr_with_privacy_prefix(&definition_addr)?;
|
parse_addr_with_privacy_prefix(&definition_account_id)?;
|
||||||
let (supply_addr, supply_addr_privacy) =
|
let (supply_account_id, supply_addr_privacy) =
|
||||||
parse_addr_with_privacy_prefix(&supply_addr)?;
|
parse_addr_with_privacy_prefix(&supply_account_id)?;
|
||||||
|
|
||||||
let underlying_subcommand = match (definition_addr_privacy, supply_addr_privacy) {
|
let underlying_subcommand = match (definition_addr_privacy, supply_addr_privacy) {
|
||||||
(AddressPrivacyKind::Public, AddressPrivacyKind::Public) => {
|
(AccountPrivacyKind::Public, AccountPrivacyKind::Public) => {
|
||||||
TokenProgramSubcommand::Public(
|
TokenProgramSubcommand::Public(
|
||||||
TokenProgramSubcommandPublic::CreateNewToken {
|
TokenProgramSubcommandPublic::CreateNewToken {
|
||||||
definition_addr,
|
definition_account_id,
|
||||||
supply_addr,
|
supply_account_id,
|
||||||
name,
|
name,
|
||||||
total_supply,
|
total_supply,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
(AddressPrivacyKind::Public, AddressPrivacyKind::Private) => {
|
(AccountPrivacyKind::Public, AccountPrivacyKind::Private) => {
|
||||||
TokenProgramSubcommand::Private(
|
TokenProgramSubcommand::Private(
|
||||||
TokenProgramSubcommandPrivate::CreateNewTokenPrivateOwned {
|
TokenProgramSubcommandPrivate::CreateNewTokenPrivateOwned {
|
||||||
definition_addr,
|
definition_account_id,
|
||||||
supply_addr,
|
supply_account_id,
|
||||||
name,
|
name,
|
||||||
total_supply,
|
total_supply,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
(AddressPrivacyKind::Private, AddressPrivacyKind::Private) => {
|
(AccountPrivacyKind::Private, AccountPrivacyKind::Private) => {
|
||||||
//ToDo: maybe implement this one. It is not immediately clear why definition should be private.
|
//ToDo: maybe implement this one. It is not immediately clear why definition should be private.
|
||||||
anyhow::bail!("Unavailable privacy pairing")
|
anyhow::bail!("Unavailable privacy pairing")
|
||||||
}
|
}
|
||||||
(AddressPrivacyKind::Private, AddressPrivacyKind::Public) => {
|
(AccountPrivacyKind::Private, AccountPrivacyKind::Public) => {
|
||||||
//ToDo: Probably valid. If definition is not public, but supply is it is very suspicious.
|
//ToDo: Probably valid. If definition is not public, but supply is it is very suspicious.
|
||||||
anyhow::bail!("Unavailable privacy pairing")
|
anyhow::bail!("Unavailable privacy pairing")
|
||||||
}
|
}
|
||||||
@ -111,12 +111,12 @@ impl WalletSubcommand for TokenProgramAgnosticSubcommand {
|
|||||||
let underlying_subcommand = match (to, to_npk, to_ipk) {
|
let underlying_subcommand = match (to, to_npk, to_ipk) {
|
||||||
(None, None, None) => {
|
(None, None, None) => {
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"Provide either account address of receiver or their public keys"
|
"Provide either account account_id of receiver or their public keys"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
(Some(_), Some(_), Some(_)) => {
|
(Some(_), Some(_), Some(_)) => {
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"Provide only one variant: either account address of receiver or their public keys"
|
"Provide only one variant: either account account_id of receiver or their public keys"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
(_, Some(_), None) | (_, None, Some(_)) => {
|
(_, Some(_), None) | (_, None, Some(_)) => {
|
||||||
@ -127,38 +127,38 @@ impl WalletSubcommand for TokenProgramAgnosticSubcommand {
|
|||||||
let (to, to_privacy) = parse_addr_with_privacy_prefix(&to)?;
|
let (to, to_privacy) = parse_addr_with_privacy_prefix(&to)?;
|
||||||
|
|
||||||
match (from_privacy, to_privacy) {
|
match (from_privacy, to_privacy) {
|
||||||
(AddressPrivacyKind::Public, AddressPrivacyKind::Public) => {
|
(AccountPrivacyKind::Public, AccountPrivacyKind::Public) => {
|
||||||
TokenProgramSubcommand::Public(
|
TokenProgramSubcommand::Public(
|
||||||
TokenProgramSubcommandPublic::TransferToken {
|
TokenProgramSubcommandPublic::TransferToken {
|
||||||
sender_addr: from,
|
sender_account_id: from,
|
||||||
recipient_addr: to,
|
recipient_account_id: to,
|
||||||
balance_to_move: amount,
|
balance_to_move: amount,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
(AddressPrivacyKind::Private, AddressPrivacyKind::Private) => {
|
(AccountPrivacyKind::Private, AccountPrivacyKind::Private) => {
|
||||||
TokenProgramSubcommand::Private(
|
TokenProgramSubcommand::Private(
|
||||||
TokenProgramSubcommandPrivate::TransferTokenPrivateOwned {
|
TokenProgramSubcommandPrivate::TransferTokenPrivateOwned {
|
||||||
sender_addr: from,
|
sender_account_id: from,
|
||||||
recipient_addr: to,
|
recipient_account_id: to,
|
||||||
balance_to_move: amount,
|
balance_to_move: amount,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
(AddressPrivacyKind::Private, AddressPrivacyKind::Public) => {
|
(AccountPrivacyKind::Private, AccountPrivacyKind::Public) => {
|
||||||
TokenProgramSubcommand::Deshielded(
|
TokenProgramSubcommand::Deshielded(
|
||||||
TokenProgramSubcommandDeshielded::TransferTokenDeshielded {
|
TokenProgramSubcommandDeshielded::TransferTokenDeshielded {
|
||||||
sender_addr: from,
|
sender_account_id: from,
|
||||||
recipient_addr: to,
|
recipient_account_id: to,
|
||||||
balance_to_move: amount,
|
balance_to_move: amount,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
(AddressPrivacyKind::Public, AddressPrivacyKind::Private) => {
|
(AccountPrivacyKind::Public, AccountPrivacyKind::Private) => {
|
||||||
TokenProgramSubcommand::Shielded(
|
TokenProgramSubcommand::Shielded(
|
||||||
TokenProgramSubcommandShielded::TransferTokenShieldedOwned {
|
TokenProgramSubcommandShielded::TransferTokenShieldedOwned {
|
||||||
sender_addr: from,
|
sender_account_id: from,
|
||||||
recipient_addr: to,
|
recipient_account_id: to,
|
||||||
balance_to_move: amount,
|
balance_to_move: amount,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -169,17 +169,17 @@ impl WalletSubcommand for TokenProgramAgnosticSubcommand {
|
|||||||
let (from, from_privacy) = parse_addr_with_privacy_prefix(&from)?;
|
let (from, from_privacy) = parse_addr_with_privacy_prefix(&from)?;
|
||||||
|
|
||||||
match from_privacy {
|
match from_privacy {
|
||||||
AddressPrivacyKind::Private => TokenProgramSubcommand::Private(
|
AccountPrivacyKind::Private => TokenProgramSubcommand::Private(
|
||||||
TokenProgramSubcommandPrivate::TransferTokenPrivateForeign {
|
TokenProgramSubcommandPrivate::TransferTokenPrivateForeign {
|
||||||
sender_addr: from,
|
sender_account_id: from,
|
||||||
recipient_npk: to_npk,
|
recipient_npk: to_npk,
|
||||||
recipient_ipk: to_ipk,
|
recipient_ipk: to_ipk,
|
||||||
balance_to_move: amount,
|
balance_to_move: amount,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
AddressPrivacyKind::Public => TokenProgramSubcommand::Shielded(
|
AccountPrivacyKind::Public => TokenProgramSubcommand::Shielded(
|
||||||
TokenProgramSubcommandShielded::TransferTokenShieldedForeign {
|
TokenProgramSubcommandShielded::TransferTokenShieldedForeign {
|
||||||
sender_addr: from,
|
sender_account_id: from,
|
||||||
recipient_npk: to_npk,
|
recipient_npk: to_npk,
|
||||||
recipient_ipk: to_ipk,
|
recipient_ipk: to_ipk,
|
||||||
balance_to_move: amount,
|
balance_to_move: amount,
|
||||||
@ -218,9 +218,9 @@ pub enum TokenProgramSubcommandPublic {
|
|||||||
//Create a new token using the token program
|
//Create a new token using the token program
|
||||||
CreateNewToken {
|
CreateNewToken {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
definition_addr: String,
|
definition_account_id: String,
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
supply_addr: String,
|
supply_account_id: String,
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
name: String,
|
name: String,
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
@ -229,9 +229,9 @@ pub enum TokenProgramSubcommandPublic {
|
|||||||
//Transfer tokens using the token program
|
//Transfer tokens using the token program
|
||||||
TransferToken {
|
TransferToken {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
sender_addr: String,
|
sender_account_id: String,
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
recipient_addr: String,
|
recipient_account_id: String,
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
balance_to_move: u128,
|
balance_to_move: u128,
|
||||||
},
|
},
|
||||||
@ -243,9 +243,9 @@ pub enum TokenProgramSubcommandPrivate {
|
|||||||
//Create a new token using the token program
|
//Create a new token using the token program
|
||||||
CreateNewTokenPrivateOwned {
|
CreateNewTokenPrivateOwned {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
definition_addr: String,
|
definition_account_id: String,
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
supply_addr: String,
|
supply_account_id: String,
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
name: String,
|
name: String,
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
@ -254,16 +254,16 @@ pub enum TokenProgramSubcommandPrivate {
|
|||||||
//Transfer tokens using the token program
|
//Transfer tokens using the token program
|
||||||
TransferTokenPrivateOwned {
|
TransferTokenPrivateOwned {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
sender_addr: String,
|
sender_account_id: String,
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
recipient_addr: String,
|
recipient_account_id: String,
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
balance_to_move: u128,
|
balance_to_move: u128,
|
||||||
},
|
},
|
||||||
//Transfer tokens using the token program
|
//Transfer tokens using the token program
|
||||||
TransferTokenPrivateForeign {
|
TransferTokenPrivateForeign {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
sender_addr: String,
|
sender_account_id: String,
|
||||||
///recipient_npk - valid 32 byte hex string
|
///recipient_npk - valid 32 byte hex string
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
recipient_npk: String,
|
recipient_npk: String,
|
||||||
@ -281,9 +281,9 @@ pub enum TokenProgramSubcommandDeshielded {
|
|||||||
//Transfer tokens using the token program
|
//Transfer tokens using the token program
|
||||||
TransferTokenDeshielded {
|
TransferTokenDeshielded {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
sender_addr: String,
|
sender_account_id: String,
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
recipient_addr: String,
|
recipient_account_id: String,
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
balance_to_move: u128,
|
balance_to_move: u128,
|
||||||
},
|
},
|
||||||
@ -295,16 +295,16 @@ pub enum TokenProgramSubcommandShielded {
|
|||||||
//Transfer tokens using the token program
|
//Transfer tokens using the token program
|
||||||
TransferTokenShieldedOwned {
|
TransferTokenShieldedOwned {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
sender_addr: String,
|
sender_account_id: String,
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
recipient_addr: String,
|
recipient_account_id: String,
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
balance_to_move: u128,
|
balance_to_move: u128,
|
||||||
},
|
},
|
||||||
//Transfer tokens using the token program
|
//Transfer tokens using the token program
|
||||||
TransferTokenShieldedForeign {
|
TransferTokenShieldedForeign {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
sender_addr: String,
|
sender_account_id: String,
|
||||||
///recipient_npk - valid 32 byte hex string
|
///recipient_npk - valid 32 byte hex string
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
recipient_npk: String,
|
recipient_npk: String,
|
||||||
@ -323,8 +323,8 @@ impl WalletSubcommand for TokenProgramSubcommandPublic {
|
|||||||
) -> Result<SubcommandReturnValue> {
|
) -> Result<SubcommandReturnValue> {
|
||||||
match self {
|
match self {
|
||||||
TokenProgramSubcommandPublic::CreateNewToken {
|
TokenProgramSubcommandPublic::CreateNewToken {
|
||||||
definition_addr,
|
definition_account_id,
|
||||||
supply_addr,
|
supply_account_id,
|
||||||
name,
|
name,
|
||||||
total_supply,
|
total_supply,
|
||||||
} => {
|
} => {
|
||||||
@ -337,8 +337,8 @@ impl WalletSubcommand for TokenProgramSubcommandPublic {
|
|||||||
name_bytes[..name.len()].copy_from_slice(name);
|
name_bytes[..name.len()].copy_from_slice(name);
|
||||||
wallet_core
|
wallet_core
|
||||||
.send_new_token_definition(
|
.send_new_token_definition(
|
||||||
definition_addr.parse().unwrap(),
|
definition_account_id.parse().unwrap(),
|
||||||
supply_addr.parse().unwrap(),
|
supply_account_id.parse().unwrap(),
|
||||||
name_bytes,
|
name_bytes,
|
||||||
total_supply,
|
total_supply,
|
||||||
)
|
)
|
||||||
@ -346,14 +346,14 @@ impl WalletSubcommand for TokenProgramSubcommandPublic {
|
|||||||
Ok(SubcommandReturnValue::Empty)
|
Ok(SubcommandReturnValue::Empty)
|
||||||
}
|
}
|
||||||
TokenProgramSubcommandPublic::TransferToken {
|
TokenProgramSubcommandPublic::TransferToken {
|
||||||
sender_addr,
|
sender_account_id,
|
||||||
recipient_addr,
|
recipient_account_id,
|
||||||
balance_to_move,
|
balance_to_move,
|
||||||
} => {
|
} => {
|
||||||
wallet_core
|
wallet_core
|
||||||
.send_transfer_token_transaction(
|
.send_transfer_token_transaction(
|
||||||
sender_addr.parse().unwrap(),
|
sender_account_id.parse().unwrap(),
|
||||||
recipient_addr.parse().unwrap(),
|
recipient_account_id.parse().unwrap(),
|
||||||
balance_to_move,
|
balance_to_move,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@ -370,8 +370,8 @@ impl WalletSubcommand for TokenProgramSubcommandPrivate {
|
|||||||
) -> Result<SubcommandReturnValue> {
|
) -> Result<SubcommandReturnValue> {
|
||||||
match self {
|
match self {
|
||||||
TokenProgramSubcommandPrivate::CreateNewTokenPrivateOwned {
|
TokenProgramSubcommandPrivate::CreateNewTokenPrivateOwned {
|
||||||
definition_addr,
|
definition_account_id,
|
||||||
supply_addr,
|
supply_account_id,
|
||||||
name,
|
name,
|
||||||
total_supply,
|
total_supply,
|
||||||
} => {
|
} => {
|
||||||
@ -383,13 +383,13 @@ impl WalletSubcommand for TokenProgramSubcommandPrivate {
|
|||||||
let mut name_bytes = [0; 6];
|
let mut name_bytes = [0; 6];
|
||||||
name_bytes[..name.len()].copy_from_slice(name);
|
name_bytes[..name.len()].copy_from_slice(name);
|
||||||
|
|
||||||
let definition_addr: Address = definition_addr.parse().unwrap();
|
let definition_account_id: AccountId = definition_account_id.parse().unwrap();
|
||||||
let supply_addr: Address = supply_addr.parse().unwrap();
|
let supply_account_id: AccountId = supply_account_id.parse().unwrap();
|
||||||
|
|
||||||
let (res, [secret_supply]) = wallet_core
|
let (res, [secret_supply]) = wallet_core
|
||||||
.send_new_token_definition_private_owned(
|
.send_new_token_definition_private_owned(
|
||||||
definition_addr,
|
definition_account_id,
|
||||||
supply_addr,
|
supply_account_id,
|
||||||
name_bytes,
|
name_bytes,
|
||||||
total_supply,
|
total_supply,
|
||||||
)
|
)
|
||||||
@ -403,7 +403,7 @@ impl WalletSubcommand for TokenProgramSubcommandPrivate {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
||||||
let acc_decode_data = vec![(secret_supply, supply_addr)];
|
let acc_decode_data = vec![(secret_supply, supply_account_id)];
|
||||||
|
|
||||||
wallet_core.decode_insert_privacy_preserving_transaction_results(
|
wallet_core.decode_insert_privacy_preserving_transaction_results(
|
||||||
tx,
|
tx,
|
||||||
@ -418,23 +418,23 @@ impl WalletSubcommand for TokenProgramSubcommandPrivate {
|
|||||||
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
|
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
|
||||||
}
|
}
|
||||||
TokenProgramSubcommandPrivate::TransferTokenPrivateOwned {
|
TokenProgramSubcommandPrivate::TransferTokenPrivateOwned {
|
||||||
sender_addr,
|
sender_account_id,
|
||||||
recipient_addr,
|
recipient_account_id,
|
||||||
balance_to_move,
|
balance_to_move,
|
||||||
} => {
|
} => {
|
||||||
let sender_addr: Address = sender_addr.parse().unwrap();
|
let sender_account_id: AccountId = sender_account_id.parse().unwrap();
|
||||||
let recipient_addr: Address = recipient_addr.parse().unwrap();
|
let recipient_account_id: AccountId = recipient_account_id.parse().unwrap();
|
||||||
|
|
||||||
let recipient_initialization = wallet_core
|
let recipient_initialization = wallet_core
|
||||||
.check_private_account_initialized(&recipient_addr)
|
.check_private_account_initialized(&recipient_account_id)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let (res, [secret_sender, secret_recipient]) =
|
let (res, [secret_sender, secret_recipient]) =
|
||||||
if let Some(recipient_proof) = recipient_initialization {
|
if let Some(recipient_proof) = recipient_initialization {
|
||||||
wallet_core
|
wallet_core
|
||||||
.send_transfer_token_transaction_private_owned_account_already_initialized(
|
.send_transfer_token_transaction_private_owned_account_already_initialized(
|
||||||
sender_addr,
|
sender_account_id,
|
||||||
recipient_addr,
|
recipient_account_id,
|
||||||
balance_to_move,
|
balance_to_move,
|
||||||
recipient_proof,
|
recipient_proof,
|
||||||
)
|
)
|
||||||
@ -442,8 +442,8 @@ impl WalletSubcommand for TokenProgramSubcommandPrivate {
|
|||||||
} else {
|
} else {
|
||||||
wallet_core
|
wallet_core
|
||||||
.send_transfer_token_transaction_private_owned_account_not_initialized(
|
.send_transfer_token_transaction_private_owned_account_not_initialized(
|
||||||
sender_addr,
|
sender_account_id,
|
||||||
recipient_addr,
|
recipient_account_id,
|
||||||
balance_to_move,
|
balance_to_move,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
@ -458,8 +458,8 @@ impl WalletSubcommand for TokenProgramSubcommandPrivate {
|
|||||||
|
|
||||||
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
||||||
let acc_decode_data = vec![
|
let acc_decode_data = vec![
|
||||||
(secret_sender, sender_addr),
|
(secret_sender, sender_account_id),
|
||||||
(secret_recipient, recipient_addr),
|
(secret_recipient, recipient_account_id),
|
||||||
];
|
];
|
||||||
|
|
||||||
wallet_core.decode_insert_privacy_preserving_transaction_results(
|
wallet_core.decode_insert_privacy_preserving_transaction_results(
|
||||||
@ -475,12 +475,12 @@ impl WalletSubcommand for TokenProgramSubcommandPrivate {
|
|||||||
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
|
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
|
||||||
}
|
}
|
||||||
TokenProgramSubcommandPrivate::TransferTokenPrivateForeign {
|
TokenProgramSubcommandPrivate::TransferTokenPrivateForeign {
|
||||||
sender_addr,
|
sender_account_id,
|
||||||
recipient_npk,
|
recipient_npk,
|
||||||
recipient_ipk,
|
recipient_ipk,
|
||||||
balance_to_move,
|
balance_to_move,
|
||||||
} => {
|
} => {
|
||||||
let sender_addr: Address = sender_addr.parse().unwrap();
|
let sender_account_id: AccountId = sender_account_id.parse().unwrap();
|
||||||
let recipient_npk_res = hex::decode(recipient_npk)?;
|
let recipient_npk_res = hex::decode(recipient_npk)?;
|
||||||
let mut recipient_npk = [0; 32];
|
let mut recipient_npk = [0; 32];
|
||||||
recipient_npk.copy_from_slice(&recipient_npk_res);
|
recipient_npk.copy_from_slice(&recipient_npk_res);
|
||||||
@ -495,7 +495,7 @@ impl WalletSubcommand for TokenProgramSubcommandPrivate {
|
|||||||
|
|
||||||
let (res, [secret_sender, _]) = wallet_core
|
let (res, [secret_sender, _]) = wallet_core
|
||||||
.send_transfer_token_transaction_private_foreign_account(
|
.send_transfer_token_transaction_private_foreign_account(
|
||||||
sender_addr,
|
sender_account_id,
|
||||||
recipient_npk,
|
recipient_npk,
|
||||||
recipient_ipk,
|
recipient_ipk,
|
||||||
balance_to_move,
|
balance_to_move,
|
||||||
@ -510,7 +510,7 @@ impl WalletSubcommand for TokenProgramSubcommandPrivate {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
||||||
let acc_decode_data = vec![(secret_sender, sender_addr)];
|
let acc_decode_data = vec![(secret_sender, sender_account_id)];
|
||||||
|
|
||||||
wallet_core.decode_insert_privacy_preserving_transaction_results(
|
wallet_core.decode_insert_privacy_preserving_transaction_results(
|
||||||
tx,
|
tx,
|
||||||
@ -535,17 +535,17 @@ impl WalletSubcommand for TokenProgramSubcommandDeshielded {
|
|||||||
) -> Result<SubcommandReturnValue> {
|
) -> Result<SubcommandReturnValue> {
|
||||||
match self {
|
match self {
|
||||||
TokenProgramSubcommandDeshielded::TransferTokenDeshielded {
|
TokenProgramSubcommandDeshielded::TransferTokenDeshielded {
|
||||||
sender_addr,
|
sender_account_id,
|
||||||
recipient_addr,
|
recipient_account_id,
|
||||||
balance_to_move,
|
balance_to_move,
|
||||||
} => {
|
} => {
|
||||||
let sender_addr: Address = sender_addr.parse().unwrap();
|
let sender_account_id: AccountId = sender_account_id.parse().unwrap();
|
||||||
let recipient_addr: Address = recipient_addr.parse().unwrap();
|
let recipient_account_id: AccountId = recipient_account_id.parse().unwrap();
|
||||||
|
|
||||||
let (res, [secret_sender]) = wallet_core
|
let (res, [secret_sender]) = wallet_core
|
||||||
.send_transfer_token_transaction_deshielded(
|
.send_transfer_token_transaction_deshielded(
|
||||||
sender_addr,
|
sender_account_id,
|
||||||
recipient_addr,
|
recipient_account_id,
|
||||||
balance_to_move,
|
balance_to_move,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@ -558,7 +558,7 @@ impl WalletSubcommand for TokenProgramSubcommandDeshielded {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
||||||
let acc_decode_data = vec![(secret_sender, sender_addr)];
|
let acc_decode_data = vec![(secret_sender, sender_account_id)];
|
||||||
|
|
||||||
wallet_core.decode_insert_privacy_preserving_transaction_results(
|
wallet_core.decode_insert_privacy_preserving_transaction_results(
|
||||||
tx,
|
tx,
|
||||||
@ -583,12 +583,12 @@ impl WalletSubcommand for TokenProgramSubcommandShielded {
|
|||||||
) -> Result<SubcommandReturnValue> {
|
) -> Result<SubcommandReturnValue> {
|
||||||
match self {
|
match self {
|
||||||
TokenProgramSubcommandShielded::TransferTokenShieldedForeign {
|
TokenProgramSubcommandShielded::TransferTokenShieldedForeign {
|
||||||
sender_addr,
|
sender_account_id,
|
||||||
recipient_npk,
|
recipient_npk,
|
||||||
recipient_ipk,
|
recipient_ipk,
|
||||||
balance_to_move,
|
balance_to_move,
|
||||||
} => {
|
} => {
|
||||||
let sender_addr: Address = sender_addr.parse().unwrap();
|
let sender_account_id: AccountId = sender_account_id.parse().unwrap();
|
||||||
let recipient_npk_res = hex::decode(recipient_npk)?;
|
let recipient_npk_res = hex::decode(recipient_npk)?;
|
||||||
let mut recipient_npk = [0; 32];
|
let mut recipient_npk = [0; 32];
|
||||||
recipient_npk.copy_from_slice(&recipient_npk_res);
|
recipient_npk.copy_from_slice(&recipient_npk_res);
|
||||||
@ -603,7 +603,7 @@ impl WalletSubcommand for TokenProgramSubcommandShielded {
|
|||||||
|
|
||||||
let res = wallet_core
|
let res = wallet_core
|
||||||
.send_transfer_token_transaction_shielded_foreign_account(
|
.send_transfer_token_transaction_shielded_foreign_account(
|
||||||
sender_addr,
|
sender_account_id,
|
||||||
recipient_npk,
|
recipient_npk,
|
||||||
recipient_ipk,
|
recipient_ipk,
|
||||||
balance_to_move,
|
balance_to_move,
|
||||||
@ -628,23 +628,23 @@ impl WalletSubcommand for TokenProgramSubcommandShielded {
|
|||||||
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
|
Ok(SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash })
|
||||||
}
|
}
|
||||||
TokenProgramSubcommandShielded::TransferTokenShieldedOwned {
|
TokenProgramSubcommandShielded::TransferTokenShieldedOwned {
|
||||||
sender_addr,
|
sender_account_id,
|
||||||
recipient_addr,
|
recipient_account_id,
|
||||||
balance_to_move,
|
balance_to_move,
|
||||||
} => {
|
} => {
|
||||||
let sender_addr: Address = sender_addr.parse().unwrap();
|
let sender_account_id: AccountId = sender_account_id.parse().unwrap();
|
||||||
let recipient_addr: Address = recipient_addr.parse().unwrap();
|
let recipient_account_id: AccountId = recipient_account_id.parse().unwrap();
|
||||||
|
|
||||||
let recipient_initialization = wallet_core
|
let recipient_initialization = wallet_core
|
||||||
.check_private_account_initialized(&recipient_addr)
|
.check_private_account_initialized(&recipient_account_id)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let (res, [secret_recipient]) =
|
let (res, [secret_recipient]) =
|
||||||
if let Some(recipient_proof) = recipient_initialization {
|
if let Some(recipient_proof) = recipient_initialization {
|
||||||
wallet_core
|
wallet_core
|
||||||
.send_transfer_token_transaction_shielded_owned_account_already_initialized(
|
.send_transfer_token_transaction_shielded_owned_account_already_initialized(
|
||||||
sender_addr,
|
sender_account_id,
|
||||||
recipient_addr,
|
recipient_account_id,
|
||||||
balance_to_move,
|
balance_to_move,
|
||||||
recipient_proof,
|
recipient_proof,
|
||||||
)
|
)
|
||||||
@ -652,8 +652,8 @@ impl WalletSubcommand for TokenProgramSubcommandShielded {
|
|||||||
} else {
|
} else {
|
||||||
wallet_core
|
wallet_core
|
||||||
.send_transfer_token_transaction_shielded_owned_account_not_initialized(
|
.send_transfer_token_transaction_shielded_owned_account_not_initialized(
|
||||||
sender_addr,
|
sender_account_id,
|
||||||
recipient_addr,
|
recipient_account_id,
|
||||||
balance_to_move,
|
balance_to_move,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
@ -667,7 +667,7 @@ impl WalletSubcommand for TokenProgramSubcommandShielded {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
if let NSSATransaction::PrivacyPreserving(tx) = transfer_tx {
|
||||||
let acc_decode_data = vec![(secret_recipient, recipient_addr)];
|
let acc_decode_data = vec![(secret_recipient, recipient_account_id)];
|
||||||
|
|
||||||
wallet_core.decode_insert_privacy_preserving_transaction_results(
|
wallet_core.decode_insert_privacy_preserving_transaction_results(
|
||||||
tx,
|
tx,
|
||||||
|
|||||||
@ -3,26 +3,26 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct InitialAccountDataPublic {
|
pub struct InitialAccountDataPublic {
|
||||||
pub address: String,
|
pub account_id: String,
|
||||||
pub pub_sign_key: nssa::PrivateKey,
|
pub pub_sign_key: nssa::PrivateKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct PersistentAccountDataPublic {
|
pub struct PersistentAccountDataPublic {
|
||||||
pub address: nssa::Address,
|
pub account_id: nssa::AccountId,
|
||||||
pub pub_sign_key: nssa::PrivateKey,
|
pub pub_sign_key: nssa::PrivateKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct InitialAccountDataPrivate {
|
pub struct InitialAccountDataPrivate {
|
||||||
pub address: String,
|
pub account_id: String,
|
||||||
pub account: nssa_core::account::Account,
|
pub account: nssa_core::account::Account,
|
||||||
pub key_chain: KeyChain,
|
pub key_chain: KeyChain,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct PersistentAccountDataPrivate {
|
pub struct PersistentAccountDataPrivate {
|
||||||
pub address: nssa::Address,
|
pub account_id: nssa::AccountId,
|
||||||
pub account: nssa_core::account::Account,
|
pub account: nssa_core::account::Account,
|
||||||
pub key_chain: KeyChain,
|
pub key_chain: KeyChain,
|
||||||
}
|
}
|
||||||
@ -52,19 +52,19 @@ pub struct PersistentStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl InitialAccountData {
|
impl InitialAccountData {
|
||||||
pub fn address(&self) -> nssa::Address {
|
pub fn account_id(&self) -> nssa::AccountId {
|
||||||
match &self {
|
match &self {
|
||||||
Self::Public(acc) => acc.address.parse().unwrap(),
|
Self::Public(acc) => acc.account_id.parse().unwrap(),
|
||||||
Self::Private(acc) => acc.address.parse().unwrap(),
|
Self::Private(acc) => acc.account_id.parse().unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PersistentAccountData {
|
impl PersistentAccountData {
|
||||||
pub fn address(&self) -> nssa::Address {
|
pub fn account_id(&self) -> nssa::AccountId {
|
||||||
match &self {
|
match &self {
|
||||||
Self::Public(acc) => acc.address,
|
Self::Public(acc) => acc.account_id,
|
||||||
Self::Private(acc) => acc.address,
|
Self::Private(acc) => acc.account_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,7 +143,7 @@ impl Default for WalletConfig {
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"Public": {
|
"Public": {
|
||||||
"address": "BLgCRDXYdQPMMWVHYRFGQZbgeHx9frkipa8GtpG2Syqy",
|
"account_id": "BLgCRDXYdQPMMWVHYRFGQZbgeHx9frkipa8GtpG2Syqy",
|
||||||
"pub_sign_key": [
|
"pub_sign_key": [
|
||||||
16,
|
16,
|
||||||
162,
|
162,
|
||||||
@ -182,7 +182,7 @@ impl Default for WalletConfig {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Public": {
|
"Public": {
|
||||||
"address": "Gj1mJy5W7J5pfmLRujmQaLfLMWidNxQ6uwnhb666ZwHw",
|
"account_id": "Gj1mJy5W7J5pfmLRujmQaLfLMWidNxQ6uwnhb666ZwHw",
|
||||||
"pub_sign_key": [
|
"pub_sign_key": [
|
||||||
113,
|
113,
|
||||||
121,
|
121,
|
||||||
@ -221,7 +221,7 @@ impl Default for WalletConfig {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Private": {
|
"Private": {
|
||||||
"address": "3oCG8gqdKLMegw4rRfyaMQvuPHpcASt7xwttsmnZLSkw",
|
"account_id": "3oCG8gqdKLMegw4rRfyaMQvuPHpcASt7xwttsmnZLSkw",
|
||||||
"account": {
|
"account": {
|
||||||
"program_owner": [
|
"program_owner": [
|
||||||
0,
|
0,
|
||||||
@ -450,7 +450,7 @@ impl Default for WalletConfig {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Private": {
|
"Private": {
|
||||||
"address": "AKTcXgJ1xoynta1Ec7y6Jso1z1JQtHqd7aPQ1h9er6xX",
|
"account_id": "AKTcXgJ1xoynta1Ec7y6Jso1z1JQtHqd7aPQ1h9er6xX",
|
||||||
"account": {
|
"account": {
|
||||||
"program_owner": [
|
"program_owner": [
|
||||||
0,
|
0,
|
||||||
|
|||||||
@ -120,20 +120,20 @@ pub fn produce_data_for_storage(
|
|||||||
) -> PersistentStorage {
|
) -> PersistentStorage {
|
||||||
let mut vec_for_storage = vec![];
|
let mut vec_for_storage = vec![];
|
||||||
|
|
||||||
for (addr, key) in &user_data.pub_account_signing_keys {
|
for (account_id, key) in &user_data.pub_account_signing_keys {
|
||||||
vec_for_storage.push(
|
vec_for_storage.push(
|
||||||
PersistentAccountDataPublic {
|
PersistentAccountDataPublic {
|
||||||
address: *addr,
|
account_id: *account_id,
|
||||||
pub_sign_key: key.clone(),
|
pub_sign_key: key.clone(),
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (addr, (key, acc)) in &user_data.user_private_accounts {
|
for (account_id, (key, acc)) in &user_data.user_private_accounts {
|
||||||
vec_for_storage.push(
|
vec_for_storage.push(
|
||||||
PersistentAccountDataPrivate {
|
PersistentAccountDataPrivate {
|
||||||
address: *addr,
|
account_id: *account_id,
|
||||||
account: acc.clone(),
|
account: acc.clone(),
|
||||||
key_chain: key.clone(),
|
key_chain: key.clone(),
|
||||||
}
|
}
|
||||||
@ -154,23 +154,23 @@ pub(crate) fn produce_random_nonces(size: usize) -> Vec<Nonce> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum AddressPrivacyKind {
|
pub enum AccountPrivacyKind {
|
||||||
Public,
|
Public,
|
||||||
Private,
|
Private,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn parse_addr_with_privacy_prefix(
|
pub(crate) fn parse_addr_with_privacy_prefix(
|
||||||
addr_base58: &str,
|
account_base58: &str,
|
||||||
) -> Result<(String, AddressPrivacyKind)> {
|
) -> Result<(String, AccountPrivacyKind)> {
|
||||||
if addr_base58.starts_with("Public/") {
|
if account_base58.starts_with("Public/") {
|
||||||
Ok((
|
Ok((
|
||||||
addr_base58.strip_prefix("Public/").unwrap().to_string(),
|
account_base58.strip_prefix("Public/").unwrap().to_string(),
|
||||||
AddressPrivacyKind::Public,
|
AccountPrivacyKind::Public,
|
||||||
))
|
))
|
||||||
} else if addr_base58.starts_with("Private/") {
|
} else if account_base58.starts_with("Private/") {
|
||||||
Ok((
|
Ok((
|
||||||
addr_base58.strip_prefix("Private/").unwrap().to_string(),
|
account_base58.strip_prefix("Private/").unwrap().to_string(),
|
||||||
AddressPrivacyKind::Private,
|
AccountPrivacyKind::Private,
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
anyhow::bail!("Unsupported privacy kind, available variants is Public/ and Private/");
|
anyhow::bail!("Unsupported privacy kind, available variants is Public/ and Private/");
|
||||||
@ -223,12 +223,12 @@ mod tests {
|
|||||||
let addr_base58 = "Public/BLgCRDXYdQPMMWVHYRFGQZbgeHx9frkipa8GtpG2Syqy";
|
let addr_base58 = "Public/BLgCRDXYdQPMMWVHYRFGQZbgeHx9frkipa8GtpG2Syqy";
|
||||||
let (_, addr_kind) = parse_addr_with_privacy_prefix(addr_base58).unwrap();
|
let (_, addr_kind) = parse_addr_with_privacy_prefix(addr_base58).unwrap();
|
||||||
|
|
||||||
assert_eq!(addr_kind, AddressPrivacyKind::Public);
|
assert_eq!(addr_kind, AccountPrivacyKind::Public);
|
||||||
|
|
||||||
let addr_base58 = "Private/BLgCRDXYdQPMMWVHYRFGQZbgeHx9frkipa8GtpG2Syqy";
|
let addr_base58 = "Private/BLgCRDXYdQPMMWVHYRFGQZbgeHx9frkipa8GtpG2Syqy";
|
||||||
let (_, addr_kind) = parse_addr_with_privacy_prefix(addr_base58).unwrap();
|
let (_, addr_kind) = parse_addr_with_privacy_prefix(addr_base58).unwrap();
|
||||||
|
|
||||||
assert_eq!(addr_kind, AddressPrivacyKind::Private);
|
assert_eq!(addr_kind, AccountPrivacyKind::Private);
|
||||||
|
|
||||||
let addr_base58 = "asdsada/BLgCRDXYdQPMMWVHYRFGQZbgeHx9frkipa8GtpG2Syqy";
|
let addr_base58 = "asdsada/BLgCRDXYdQPMMWVHYRFGQZbgeHx9frkipa8GtpG2Syqy";
|
||||||
assert!(parse_addr_with_privacy_prefix(addr_base58).is_err());
|
assert!(parse_addr_with_privacy_prefix(addr_base58).is_err());
|
||||||
|
|||||||
@ -12,7 +12,7 @@ use chain_storage::WalletChainStore;
|
|||||||
use config::WalletConfig;
|
use config::WalletConfig;
|
||||||
use log::info;
|
use log::info;
|
||||||
use nssa::{
|
use nssa::{
|
||||||
Account, Address, privacy_preserving_transaction::message::EncryptedAccountData,
|
Account, AccountId, privacy_preserving_transaction::message::EncryptedAccountData,
|
||||||
program::Program,
|
program::Program,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -107,20 +107,20 @@ impl WalletCore {
|
|||||||
Ok(config_path)
|
Ok(config_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_new_account_public(&mut self) -> Address {
|
pub fn create_new_account_public(&mut self) -> AccountId {
|
||||||
self.storage
|
self.storage
|
||||||
.user_data
|
.user_data
|
||||||
.generate_new_public_transaction_private_key()
|
.generate_new_public_transaction_private_key()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_new_account_private(&mut self) -> Address {
|
pub fn create_new_account_private(&mut self) -> AccountId {
|
||||||
self.storage
|
self.storage
|
||||||
.user_data
|
.user_data
|
||||||
.generate_new_privacy_preserving_transaction_key_chain()
|
.generate_new_privacy_preserving_transaction_key_chain()
|
||||||
}
|
}
|
||||||
|
|
||||||
///Get account balance
|
///Get account balance
|
||||||
pub async fn get_account_balance(&self, acc: Address) -> Result<u128> {
|
pub async fn get_account_balance(&self, acc: AccountId) -> Result<u128> {
|
||||||
Ok(self
|
Ok(self
|
||||||
.sequencer_client
|
.sequencer_client
|
||||||
.get_account_balance(acc.to_string())
|
.get_account_balance(acc.to_string())
|
||||||
@ -129,7 +129,7 @@ impl WalletCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
///Get accounts nonces
|
///Get accounts nonces
|
||||||
pub async fn get_accounts_nonces(&self, accs: Vec<Address>) -> Result<Vec<u128>> {
|
pub async fn get_accounts_nonces(&self, accs: Vec<AccountId>) -> Result<Vec<u128>> {
|
||||||
Ok(self
|
Ok(self
|
||||||
.sequencer_client
|
.sequencer_client
|
||||||
.get_accounts_nonces(accs.into_iter().map(|acc| acc.to_string()).collect())
|
.get_accounts_nonces(accs.into_iter().map(|acc| acc.to_string()).collect())
|
||||||
@ -138,21 +138,28 @@ impl WalletCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
///Get account
|
///Get account
|
||||||
pub async fn get_account_public(&self, addr: Address) -> Result<Account> {
|
pub async fn get_account_public(&self, account_id: AccountId) -> Result<Account> {
|
||||||
let response = self.sequencer_client.get_account(addr.to_string()).await?;
|
let response = self
|
||||||
|
.sequencer_client
|
||||||
|
.get_account(account_id.to_string())
|
||||||
|
.await?;
|
||||||
Ok(response.account)
|
Ok(response.account)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_account_private(&self, addr: &Address) -> Option<Account> {
|
pub fn get_account_private(&self, account_id: &AccountId) -> Option<Account> {
|
||||||
self.storage
|
self.storage
|
||||||
.user_data
|
.user_data
|
||||||
.user_private_accounts
|
.user_private_accounts
|
||||||
.get(addr)
|
.get(account_id)
|
||||||
.map(|value| value.1.clone())
|
.map(|value| value.1.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_private_account_commitment(&self, addr: &Address) -> Option<Commitment> {
|
pub fn get_private_account_commitment(&self, account_id: &AccountId) -> Option<Commitment> {
|
||||||
let (keys, account) = self.storage.user_data.user_private_accounts.get(addr)?;
|
let (keys, account) = self
|
||||||
|
.storage
|
||||||
|
.user_data
|
||||||
|
.user_private_accounts
|
||||||
|
.get(account_id)?;
|
||||||
Some(Commitment::new(&keys.nullifer_public_key, account))
|
Some(Commitment::new(&keys.nullifer_public_key, account))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,9 +174,9 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub async fn check_private_account_initialized(
|
pub async fn check_private_account_initialized(
|
||||||
&self,
|
&self,
|
||||||
addr: &Address,
|
account_id: &AccountId,
|
||||||
) -> Result<Option<MembershipProof>> {
|
) -> Result<Option<MembershipProof>> {
|
||||||
if let Some(acc_comm) = self.get_private_account_commitment(addr) {
|
if let Some(acc_comm) = self.get_private_account_commitment(account_id) {
|
||||||
self.sequencer_client
|
self.sequencer_client
|
||||||
.get_proof_for_commitment(acc_comm)
|
.get_proof_for_commitment(acc_comm)
|
||||||
.await
|
.await
|
||||||
@ -182,9 +189,9 @@ impl WalletCore {
|
|||||||
pub fn decode_insert_privacy_preserving_transaction_results(
|
pub fn decode_insert_privacy_preserving_transaction_results(
|
||||||
&mut self,
|
&mut self,
|
||||||
tx: nssa::privacy_preserving_transaction::PrivacyPreservingTransaction,
|
tx: nssa::privacy_preserving_transaction::PrivacyPreservingTransaction,
|
||||||
acc_decode_data: &[(nssa_core::SharedSecretKey, Address)],
|
acc_decode_data: &[(nssa_core::SharedSecretKey, AccountId)],
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
for (output_index, (secret, acc_address)) in acc_decode_data.iter().enumerate() {
|
for (output_index, (secret, acc_account_id)) in acc_decode_data.iter().enumerate() {
|
||||||
let acc_ead = tx.message.encrypted_private_post_states[output_index].clone();
|
let acc_ead = tx.message.encrypted_private_post_states[output_index].clone();
|
||||||
let acc_comm = tx.message.new_commitments[output_index].clone();
|
let acc_comm = tx.message.new_commitments[output_index].clone();
|
||||||
|
|
||||||
@ -199,7 +206,7 @@ impl WalletCore {
|
|||||||
println!("Received new acc {res_acc:#?}");
|
println!("Received new acc {res_acc:#?}");
|
||||||
|
|
||||||
self.storage
|
self.storage
|
||||||
.insert_private_account_data(*acc_address, res_acc);
|
.insert_private_account_data(*acc_account_id, res_acc);
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Transaction data is {:?}", tx.message);
|
println!("Transaction data is {:?}", tx.message);
|
||||||
@ -239,7 +246,7 @@ pub enum Command {
|
|||||||
///
|
///
|
||||||
/// All account adresses must be valid 32 byte base58 strings.
|
/// All account adresses must be valid 32 byte base58 strings.
|
||||||
///
|
///
|
||||||
/// All account addresses must be provided as {privacy_prefix}/{addr},
|
/// All account account_ids must be provided as {privacy_prefix}/{account_id},
|
||||||
/// where valid options for `privacy_prefix` is `Public` and `Private`
|
/// where valid options for `privacy_prefix` is `Public` and `Private`
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[clap(version, about)]
|
#[clap(version, about)]
|
||||||
@ -255,7 +262,7 @@ pub struct Args {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum SubcommandReturnValue {
|
pub enum SubcommandReturnValue {
|
||||||
PrivacyPreservingTransfer { tx_hash: String },
|
PrivacyPreservingTransfer { tx_hash: String },
|
||||||
RegisterAccount { addr: nssa::Address },
|
RegisterAccount { account_id: nssa::AccountId },
|
||||||
Account(nssa::Account),
|
Account(nssa::Account),
|
||||||
Empty,
|
Empty,
|
||||||
SyncedToBlock(u64),
|
SyncedToBlock(u64),
|
||||||
@ -343,7 +350,7 @@ pub async fn parse_block_range(
|
|||||||
if let NSSATransaction::PrivacyPreserving(tx) = nssa_tx {
|
if let NSSATransaction::PrivacyPreserving(tx) = nssa_tx {
|
||||||
let mut affected_accounts = vec![];
|
let mut affected_accounts = vec![];
|
||||||
|
|
||||||
for (acc_addr, (key_chain, _)) in
|
for (acc_account_id, (key_chain, _)) in
|
||||||
&wallet_core.storage.user_data.user_private_accounts
|
&wallet_core.storage.user_data.user_private_accounts
|
||||||
{
|
{
|
||||||
let view_tag = EncryptedAccountData::compute_view_tag(
|
let view_tag = EncryptedAccountData::compute_view_tag(
|
||||||
@ -372,19 +379,19 @@ pub async fn parse_block_range(
|
|||||||
|
|
||||||
if let Some(res_acc) = res_acc {
|
if let Some(res_acc) = res_acc {
|
||||||
println!(
|
println!(
|
||||||
"Received new account for addr {acc_addr:#?} with account object {res_acc:#?}"
|
"Received new account for account_id {acc_account_id:#?} with account object {res_acc:#?}"
|
||||||
);
|
);
|
||||||
|
|
||||||
affected_accounts.push((*acc_addr, res_acc));
|
affected_accounts.push((*acc_account_id, res_acc));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (affected_addr, new_acc) in affected_accounts {
|
for (affected_account_id, new_acc) in affected_accounts {
|
||||||
wallet_core
|
wallet_core
|
||||||
.storage
|
.storage
|
||||||
.insert_private_account_data(affected_addr, new_acc);
|
.insert_private_account_data(affected_account_id, new_acc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
use common::{error::ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
use common::{error::ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
||||||
use key_protocol::key_management::ephemeral_key_holder::EphemeralKeyHolder;
|
use key_protocol::key_management::ephemeral_key_holder::EphemeralKeyHolder;
|
||||||
use nssa::{Address, privacy_preserving_transaction::circuit};
|
use nssa::{AccountId, privacy_preserving_transaction::circuit};
|
||||||
use nssa_core::{MembershipProof, SharedSecretKey, account::AccountWithMetadata};
|
use nssa_core::{MembershipProof, SharedSecretKey, account::AccountWithMetadata};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -10,14 +10,14 @@ use crate::{
|
|||||||
impl WalletCore {
|
impl WalletCore {
|
||||||
pub async fn claim_pinata(
|
pub async fn claim_pinata(
|
||||||
&self,
|
&self,
|
||||||
pinata_addr: Address,
|
pinata_account_id: AccountId,
|
||||||
winner_addr: Address,
|
winner_account_id: AccountId,
|
||||||
solution: u128,
|
solution: u128,
|
||||||
) -> Result<SendTxResponse, ExecutionFailureKind> {
|
) -> Result<SendTxResponse, ExecutionFailureKind> {
|
||||||
let addresses = vec![pinata_addr, winner_addr];
|
let account_ids = vec![pinata_account_id, winner_account_id];
|
||||||
let program_id = nssa::program::Program::pinata().id();
|
let program_id = nssa::program::Program::pinata().id();
|
||||||
let message =
|
let message =
|
||||||
nssa::public_transaction::Message::try_new(program_id, addresses, vec![], solution)
|
nssa::public_transaction::Message::try_new(program_id, account_ids, vec![], solution)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let witness_set = nssa::public_transaction::WitnessSet::for_message(&message, &[]);
|
let witness_set = nssa::public_transaction::WitnessSet::for_message(&message, &[]);
|
||||||
@ -28,8 +28,8 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub async fn claim_pinata_private_owned_account_already_initialized(
|
pub async fn claim_pinata_private_owned_account_already_initialized(
|
||||||
&self,
|
&self,
|
||||||
pinata_addr: Address,
|
pinata_account_id: AccountId,
|
||||||
winner_addr: Address,
|
winner_account_id: AccountId,
|
||||||
solution: u128,
|
solution: u128,
|
||||||
winner_proof: MembershipProof,
|
winner_proof: MembershipProof,
|
||||||
) -> Result<(SendTxResponse, [SharedSecretKey; 1]), ExecutionFailureKind> {
|
) -> Result<(SendTxResponse, [SharedSecretKey; 1]), ExecutionFailureKind> {
|
||||||
@ -40,14 +40,14 @@ impl WalletCore {
|
|||||||
auth_acc: winner_pre,
|
auth_acc: winner_pre,
|
||||||
proof: _,
|
proof: _,
|
||||||
} = self
|
} = self
|
||||||
.private_acc_preparation(winner_addr, true, false)
|
.private_acc_preparation(winner_account_id, true, false)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let pinata_acc = self.get_account_public(pinata_addr).await.unwrap();
|
let pinata_acc = self.get_account_public(pinata_account_id).await.unwrap();
|
||||||
|
|
||||||
let program = nssa::program::Program::pinata();
|
let program = nssa::program::Program::pinata();
|
||||||
|
|
||||||
let pinata_pre = AccountWithMetadata::new(pinata_acc.clone(), false, pinata_addr);
|
let pinata_pre = AccountWithMetadata::new(pinata_acc.clone(), false, pinata_account_id);
|
||||||
|
|
||||||
let eph_holder_winner = EphemeralKeyHolder::new(&winner_npk);
|
let eph_holder_winner = EphemeralKeyHolder::new(&winner_npk);
|
||||||
let shared_secret_winner = eph_holder_winner.calculate_shared_secret_sender(&winner_ipk);
|
let shared_secret_winner = eph_holder_winner.calculate_shared_secret_sender(&winner_ipk);
|
||||||
@ -65,7 +65,7 @@ impl WalletCore {
|
|||||||
|
|
||||||
let message =
|
let message =
|
||||||
nssa::privacy_preserving_transaction::message::Message::try_from_circuit_output(
|
nssa::privacy_preserving_transaction::message::Message::try_from_circuit_output(
|
||||||
vec![pinata_addr],
|
vec![pinata_account_id],
|
||||||
vec![],
|
vec![],
|
||||||
vec![(
|
vec![(
|
||||||
winner_npk.clone(),
|
winner_npk.clone(),
|
||||||
@ -95,8 +95,8 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub async fn claim_pinata_private_owned_account_not_initialized(
|
pub async fn claim_pinata_private_owned_account_not_initialized(
|
||||||
&self,
|
&self,
|
||||||
pinata_addr: Address,
|
pinata_account_id: AccountId,
|
||||||
winner_addr: Address,
|
winner_account_id: AccountId,
|
||||||
solution: u128,
|
solution: u128,
|
||||||
) -> Result<(SendTxResponse, [SharedSecretKey; 1]), ExecutionFailureKind> {
|
) -> Result<(SendTxResponse, [SharedSecretKey; 1]), ExecutionFailureKind> {
|
||||||
let AccountPreparedData {
|
let AccountPreparedData {
|
||||||
@ -106,14 +106,14 @@ impl WalletCore {
|
|||||||
auth_acc: winner_pre,
|
auth_acc: winner_pre,
|
||||||
proof: _,
|
proof: _,
|
||||||
} = self
|
} = self
|
||||||
.private_acc_preparation(winner_addr, false, false)
|
.private_acc_preparation(winner_account_id, false, false)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let pinata_acc = self.get_account_public(pinata_addr).await.unwrap();
|
let pinata_acc = self.get_account_public(pinata_account_id).await.unwrap();
|
||||||
|
|
||||||
let program = nssa::program::Program::pinata();
|
let program = nssa::program::Program::pinata();
|
||||||
|
|
||||||
let pinata_pre = AccountWithMetadata::new(pinata_acc.clone(), false, pinata_addr);
|
let pinata_pre = AccountWithMetadata::new(pinata_acc.clone(), false, pinata_account_id);
|
||||||
|
|
||||||
let eph_holder_winner = EphemeralKeyHolder::new(&winner_npk);
|
let eph_holder_winner = EphemeralKeyHolder::new(&winner_npk);
|
||||||
let shared_secret_winner = eph_holder_winner.calculate_shared_secret_sender(&winner_ipk);
|
let shared_secret_winner = eph_holder_winner.calculate_shared_secret_sender(&winner_ipk);
|
||||||
@ -131,7 +131,7 @@ impl WalletCore {
|
|||||||
|
|
||||||
let message =
|
let message =
|
||||||
nssa::privacy_preserving_transaction::message::Message::try_from_circuit_output(
|
nssa::privacy_preserving_transaction::message::Message::try_from_circuit_output(
|
||||||
vec![pinata_addr],
|
vec![pinata_account_id],
|
||||||
vec![],
|
vec![],
|
||||||
vec![(
|
vec![(
|
||||||
winner_npk.clone(),
|
winner_npk.clone(),
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use common::{error::ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
use common::{error::ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
||||||
use nssa::{Account, Address, program::Program};
|
use nssa::{Account, AccountId, program::Program};
|
||||||
use nssa_core::{
|
use nssa_core::{
|
||||||
MembershipProof, NullifierPublicKey, SharedSecretKey, encryption::IncomingViewingPublicKey,
|
MembershipProof, NullifierPublicKey, SharedSecretKey, encryption::IncomingViewingPublicKey,
|
||||||
program::InstructionData,
|
program::InstructionData,
|
||||||
@ -47,20 +47,24 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub async fn send_new_token_definition(
|
pub async fn send_new_token_definition(
|
||||||
&self,
|
&self,
|
||||||
definition_address: Address,
|
definition_account_id: AccountId,
|
||||||
supply_address: Address,
|
supply_account_id: AccountId,
|
||||||
name: [u8; 6],
|
name: [u8; 6],
|
||||||
total_supply: u128,
|
total_supply: u128,
|
||||||
) -> Result<SendTxResponse, ExecutionFailureKind> {
|
) -> Result<SendTxResponse, ExecutionFailureKind> {
|
||||||
let addresses = vec![definition_address, supply_address];
|
let account_ids = vec![definition_account_id, supply_account_id];
|
||||||
let program_id = nssa::program::Program::token().id();
|
let program_id = nssa::program::Program::token().id();
|
||||||
// Instruction must be: [0x00 || total_supply (little-endian 16 bytes) || name (6 bytes)]
|
// Instruction must be: [0x00 || total_supply (little-endian 16 bytes) || name (6 bytes)]
|
||||||
let mut instruction = [0; 23];
|
let mut instruction = [0; 23];
|
||||||
instruction[1..17].copy_from_slice(&total_supply.to_le_bytes());
|
instruction[1..17].copy_from_slice(&total_supply.to_le_bytes());
|
||||||
instruction[17..].copy_from_slice(&name);
|
instruction[17..].copy_from_slice(&name);
|
||||||
let message =
|
let message = nssa::public_transaction::Message::try_new(
|
||||||
nssa::public_transaction::Message::try_new(program_id, addresses, vec![], instruction)
|
program_id,
|
||||||
.unwrap();
|
account_ids,
|
||||||
|
vec![],
|
||||||
|
instruction,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let witness_set = nssa::public_transaction::WitnessSet::for_message(&message, &[]);
|
let witness_set = nssa::public_transaction::WitnessSet::for_message(&message, &[]);
|
||||||
|
|
||||||
@ -71,8 +75,8 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub async fn send_new_token_definition_private_owned(
|
pub async fn send_new_token_definition_private_owned(
|
||||||
&self,
|
&self,
|
||||||
definition_addr: Address,
|
definition_account_id: AccountId,
|
||||||
supply_addr: Address,
|
supply_account_id: AccountId,
|
||||||
name: [u8; 6],
|
name: [u8; 6],
|
||||||
total_supply: u128,
|
total_supply: u128,
|
||||||
) -> Result<(SendTxResponse, [SharedSecretKey; 1]), ExecutionFailureKind> {
|
) -> Result<(SendTxResponse, [SharedSecretKey; 1]), ExecutionFailureKind> {
|
||||||
@ -82,8 +86,8 @@ impl WalletCore {
|
|||||||
// Kind of non-obvious naming
|
// Kind of non-obvious naming
|
||||||
// Basically this funtion is called because authentication mask is [0, 2]
|
// Basically this funtion is called because authentication mask is [0, 2]
|
||||||
self.shielded_two_accs_receiver_uninit(
|
self.shielded_two_accs_receiver_uninit(
|
||||||
definition_addr,
|
definition_account_id,
|
||||||
supply_addr,
|
supply_account_id,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
tx_pre_check,
|
tx_pre_check,
|
||||||
program,
|
program,
|
||||||
@ -93,27 +97,31 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub async fn send_transfer_token_transaction(
|
pub async fn send_transfer_token_transaction(
|
||||||
&self,
|
&self,
|
||||||
sender_address: Address,
|
sender_account_id: AccountId,
|
||||||
recipient_address: Address,
|
recipient_account_id: AccountId,
|
||||||
amount: u128,
|
amount: u128,
|
||||||
) -> Result<SendTxResponse, ExecutionFailureKind> {
|
) -> Result<SendTxResponse, ExecutionFailureKind> {
|
||||||
let addresses = vec![sender_address, recipient_address];
|
let account_ids = vec![sender_account_id, recipient_account_id];
|
||||||
let program_id = nssa::program::Program::token().id();
|
let program_id = nssa::program::Program::token().id();
|
||||||
// Instruction must be: [0x01 || amount (little-endian 16 bytes) || 0x00 || 0x00 || 0x00 || 0x00 || 0x00 || 0x00].
|
// Instruction must be: [0x01 || amount (little-endian 16 bytes) || 0x00 || 0x00 || 0x00 || 0x00 || 0x00 || 0x00].
|
||||||
let mut instruction = [0; 23];
|
let mut instruction = [0; 23];
|
||||||
instruction[0] = 0x01;
|
instruction[0] = 0x01;
|
||||||
instruction[1..17].copy_from_slice(&amount.to_le_bytes());
|
instruction[1..17].copy_from_slice(&amount.to_le_bytes());
|
||||||
let Ok(nonces) = self.get_accounts_nonces(vec![sender_address]).await else {
|
let Ok(nonces) = self.get_accounts_nonces(vec![sender_account_id]).await else {
|
||||||
return Err(ExecutionFailureKind::SequencerError);
|
return Err(ExecutionFailureKind::SequencerError);
|
||||||
};
|
};
|
||||||
let message =
|
let message = nssa::public_transaction::Message::try_new(
|
||||||
nssa::public_transaction::Message::try_new(program_id, addresses, nonces, instruction)
|
program_id,
|
||||||
.unwrap();
|
account_ids,
|
||||||
|
nonces,
|
||||||
|
instruction,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let Some(signing_key) = self
|
let Some(signing_key) = self
|
||||||
.storage
|
.storage
|
||||||
.user_data
|
.user_data
|
||||||
.get_pub_account_signing_key(&sender_address)
|
.get_pub_account_signing_key(&sender_account_id)
|
||||||
else {
|
else {
|
||||||
return Err(ExecutionFailureKind::KeyNotFoundError);
|
return Err(ExecutionFailureKind::KeyNotFoundError);
|
||||||
};
|
};
|
||||||
@ -127,8 +135,8 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub async fn send_transfer_token_transaction_private_owned_account_already_initialized(
|
pub async fn send_transfer_token_transaction_private_owned_account_already_initialized(
|
||||||
&self,
|
&self,
|
||||||
sender_address: Address,
|
sender_account_id: AccountId,
|
||||||
recipient_address: Address,
|
recipient_account_id: AccountId,
|
||||||
amount: u128,
|
amount: u128,
|
||||||
recipient_proof: MembershipProof,
|
recipient_proof: MembershipProof,
|
||||||
) -> Result<(SendTxResponse, [SharedSecretKey; 2]), ExecutionFailureKind> {
|
) -> Result<(SendTxResponse, [SharedSecretKey; 2]), ExecutionFailureKind> {
|
||||||
@ -136,8 +144,8 @@ impl WalletCore {
|
|||||||
WalletCore::token_program_preparation_transfer(amount);
|
WalletCore::token_program_preparation_transfer(amount);
|
||||||
|
|
||||||
self.private_tx_two_accs_all_init(
|
self.private_tx_two_accs_all_init(
|
||||||
sender_address,
|
sender_account_id,
|
||||||
recipient_address,
|
recipient_account_id,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
tx_pre_check,
|
tx_pre_check,
|
||||||
program,
|
program,
|
||||||
@ -148,16 +156,16 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub async fn send_transfer_token_transaction_private_owned_account_not_initialized(
|
pub async fn send_transfer_token_transaction_private_owned_account_not_initialized(
|
||||||
&self,
|
&self,
|
||||||
sender_address: Address,
|
sender_account_id: AccountId,
|
||||||
recipient_address: Address,
|
recipient_account_id: AccountId,
|
||||||
amount: u128,
|
amount: u128,
|
||||||
) -> Result<(SendTxResponse, [SharedSecretKey; 2]), ExecutionFailureKind> {
|
) -> Result<(SendTxResponse, [SharedSecretKey; 2]), ExecutionFailureKind> {
|
||||||
let (instruction_data, program, tx_pre_check) =
|
let (instruction_data, program, tx_pre_check) =
|
||||||
WalletCore::token_program_preparation_transfer(amount);
|
WalletCore::token_program_preparation_transfer(amount);
|
||||||
|
|
||||||
self.private_tx_two_accs_receiver_uninit(
|
self.private_tx_two_accs_receiver_uninit(
|
||||||
sender_address,
|
sender_account_id,
|
||||||
recipient_address,
|
recipient_account_id,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
tx_pre_check,
|
tx_pre_check,
|
||||||
program,
|
program,
|
||||||
@ -167,7 +175,7 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub async fn send_transfer_token_transaction_private_foreign_account(
|
pub async fn send_transfer_token_transaction_private_foreign_account(
|
||||||
&self,
|
&self,
|
||||||
sender_address: Address,
|
sender_account_id: AccountId,
|
||||||
recipient_npk: NullifierPublicKey,
|
recipient_npk: NullifierPublicKey,
|
||||||
recipient_ipk: IncomingViewingPublicKey,
|
recipient_ipk: IncomingViewingPublicKey,
|
||||||
amount: u128,
|
amount: u128,
|
||||||
@ -176,7 +184,7 @@ impl WalletCore {
|
|||||||
WalletCore::token_program_preparation_transfer(amount);
|
WalletCore::token_program_preparation_transfer(amount);
|
||||||
|
|
||||||
self.private_tx_two_accs_receiver_outer(
|
self.private_tx_two_accs_receiver_outer(
|
||||||
sender_address,
|
sender_account_id,
|
||||||
recipient_npk,
|
recipient_npk,
|
||||||
recipient_ipk,
|
recipient_ipk,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
@ -188,16 +196,16 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub async fn send_transfer_token_transaction_deshielded(
|
pub async fn send_transfer_token_transaction_deshielded(
|
||||||
&self,
|
&self,
|
||||||
sender_address: Address,
|
sender_account_id: AccountId,
|
||||||
recipient_address: Address,
|
recipient_account_id: AccountId,
|
||||||
amount: u128,
|
amount: u128,
|
||||||
) -> Result<(SendTxResponse, [SharedSecretKey; 1]), ExecutionFailureKind> {
|
) -> Result<(SendTxResponse, [SharedSecretKey; 1]), ExecutionFailureKind> {
|
||||||
let (instruction_data, program, tx_pre_check) =
|
let (instruction_data, program, tx_pre_check) =
|
||||||
WalletCore::token_program_preparation_transfer(amount);
|
WalletCore::token_program_preparation_transfer(amount);
|
||||||
|
|
||||||
self.deshielded_tx_two_accs(
|
self.deshielded_tx_two_accs(
|
||||||
sender_address,
|
sender_account_id,
|
||||||
recipient_address,
|
recipient_account_id,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
tx_pre_check,
|
tx_pre_check,
|
||||||
program,
|
program,
|
||||||
@ -207,8 +215,8 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub async fn send_transfer_token_transaction_shielded_owned_account_already_initialized(
|
pub async fn send_transfer_token_transaction_shielded_owned_account_already_initialized(
|
||||||
&self,
|
&self,
|
||||||
sender_address: Address,
|
sender_account_id: AccountId,
|
||||||
recipient_address: Address,
|
recipient_account_id: AccountId,
|
||||||
amount: u128,
|
amount: u128,
|
||||||
recipient_proof: MembershipProof,
|
recipient_proof: MembershipProof,
|
||||||
) -> Result<(SendTxResponse, [SharedSecretKey; 1]), ExecutionFailureKind> {
|
) -> Result<(SendTxResponse, [SharedSecretKey; 1]), ExecutionFailureKind> {
|
||||||
@ -216,8 +224,8 @@ impl WalletCore {
|
|||||||
WalletCore::token_program_preparation_transfer(amount);
|
WalletCore::token_program_preparation_transfer(amount);
|
||||||
|
|
||||||
self.shielded_two_accs_all_init(
|
self.shielded_two_accs_all_init(
|
||||||
sender_address,
|
sender_account_id,
|
||||||
recipient_address,
|
recipient_account_id,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
tx_pre_check,
|
tx_pre_check,
|
||||||
program,
|
program,
|
||||||
@ -228,16 +236,16 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub async fn send_transfer_token_transaction_shielded_owned_account_not_initialized(
|
pub async fn send_transfer_token_transaction_shielded_owned_account_not_initialized(
|
||||||
&self,
|
&self,
|
||||||
sender_address: Address,
|
sender_account_id: AccountId,
|
||||||
recipient_address: Address,
|
recipient_account_id: AccountId,
|
||||||
amount: u128,
|
amount: u128,
|
||||||
) -> Result<(SendTxResponse, [SharedSecretKey; 1]), ExecutionFailureKind> {
|
) -> Result<(SendTxResponse, [SharedSecretKey; 1]), ExecutionFailureKind> {
|
||||||
let (instruction_data, program, tx_pre_check) =
|
let (instruction_data, program, tx_pre_check) =
|
||||||
WalletCore::token_program_preparation_transfer(amount);
|
WalletCore::token_program_preparation_transfer(amount);
|
||||||
|
|
||||||
self.shielded_two_accs_receiver_uninit(
|
self.shielded_two_accs_receiver_uninit(
|
||||||
sender_address,
|
sender_account_id,
|
||||||
recipient_address,
|
recipient_account_id,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
tx_pre_check,
|
tx_pre_check,
|
||||||
program,
|
program,
|
||||||
@ -247,7 +255,7 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub async fn send_transfer_token_transaction_shielded_foreign_account(
|
pub async fn send_transfer_token_transaction_shielded_foreign_account(
|
||||||
&self,
|
&self,
|
||||||
sender_address: Address,
|
sender_account_id: AccountId,
|
||||||
recipient_npk: NullifierPublicKey,
|
recipient_npk: NullifierPublicKey,
|
||||||
recipient_ipk: IncomingViewingPublicKey,
|
recipient_ipk: IncomingViewingPublicKey,
|
||||||
amount: u128,
|
amount: u128,
|
||||||
@ -256,7 +264,7 @@ impl WalletCore {
|
|||||||
WalletCore::token_program_preparation_transfer(amount);
|
WalletCore::token_program_preparation_transfer(amount);
|
||||||
|
|
||||||
self.shielded_two_accs_receiver_outer(
|
self.shielded_two_accs_receiver_outer(
|
||||||
sender_address,
|
sender_account_id,
|
||||||
recipient_npk,
|
recipient_npk,
|
||||||
recipient_ipk,
|
recipient_ipk,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
use common::{error::ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
use common::{error::ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
||||||
use nssa::Address;
|
use nssa::AccountId;
|
||||||
|
|
||||||
use crate::WalletCore;
|
use crate::WalletCore;
|
||||||
|
|
||||||
impl WalletCore {
|
impl WalletCore {
|
||||||
pub async fn send_deshielded_native_token_transfer(
|
pub async fn send_deshielded_native_token_transfer(
|
||||||
&self,
|
&self,
|
||||||
from: Address,
|
from: AccountId,
|
||||||
to: Address,
|
to: AccountId,
|
||||||
balance_to_move: u128,
|
balance_to_move: u128,
|
||||||
) -> Result<(SendTxResponse, [nssa_core::SharedSecretKey; 1]), ExecutionFailureKind> {
|
) -> Result<(SendTxResponse, [nssa_core::SharedSecretKey; 1]), ExecutionFailureKind> {
|
||||||
let (instruction_data, program, tx_pre_check) =
|
let (instruction_data, program, tx_pre_check) =
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use common::{error::ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
use common::{error::ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
||||||
use nssa::Address;
|
use nssa::AccountId;
|
||||||
use nssa_core::{
|
use nssa_core::{
|
||||||
MembershipProof, NullifierPublicKey, SharedSecretKey, encryption::IncomingViewingPublicKey,
|
MembershipProof, NullifierPublicKey, SharedSecretKey, encryption::IncomingViewingPublicKey,
|
||||||
};
|
};
|
||||||
@ -9,7 +9,7 @@ use crate::WalletCore;
|
|||||||
impl WalletCore {
|
impl WalletCore {
|
||||||
pub async fn send_private_native_token_transfer_outer_account(
|
pub async fn send_private_native_token_transfer_outer_account(
|
||||||
&self,
|
&self,
|
||||||
from: Address,
|
from: AccountId,
|
||||||
to_npk: NullifierPublicKey,
|
to_npk: NullifierPublicKey,
|
||||||
to_ipk: IncomingViewingPublicKey,
|
to_ipk: IncomingViewingPublicKey,
|
||||||
balance_to_move: u128,
|
balance_to_move: u128,
|
||||||
@ -30,8 +30,8 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub async fn send_private_native_token_transfer_owned_account_not_initialized(
|
pub async fn send_private_native_token_transfer_owned_account_not_initialized(
|
||||||
&self,
|
&self,
|
||||||
from: Address,
|
from: AccountId,
|
||||||
to: Address,
|
to: AccountId,
|
||||||
balance_to_move: u128,
|
balance_to_move: u128,
|
||||||
) -> Result<(SendTxResponse, [SharedSecretKey; 2]), ExecutionFailureKind> {
|
) -> Result<(SendTxResponse, [SharedSecretKey; 2]), ExecutionFailureKind> {
|
||||||
let (instruction_data, program, tx_pre_check) =
|
let (instruction_data, program, tx_pre_check) =
|
||||||
@ -43,8 +43,8 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub async fn send_private_native_token_transfer_owned_account_already_initialized(
|
pub async fn send_private_native_token_transfer_owned_account_already_initialized(
|
||||||
&self,
|
&self,
|
||||||
from: Address,
|
from: AccountId,
|
||||||
to: Address,
|
to: AccountId,
|
||||||
balance_to_move: u128,
|
balance_to_move: u128,
|
||||||
to_proof: MembershipProof,
|
to_proof: MembershipProof,
|
||||||
) -> Result<(SendTxResponse, [SharedSecretKey; 2]), ExecutionFailureKind> {
|
) -> Result<(SendTxResponse, [SharedSecretKey; 2]), ExecutionFailureKind> {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
use common::{error::ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
use common::{error::ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
||||||
use nssa::{
|
use nssa::{
|
||||||
Address, PublicTransaction,
|
AccountId, PublicTransaction,
|
||||||
program::Program,
|
program::Program,
|
||||||
public_transaction::{Message, WitnessSet},
|
public_transaction::{Message, WitnessSet},
|
||||||
};
|
};
|
||||||
@ -10,8 +10,8 @@ use crate::WalletCore;
|
|||||||
impl WalletCore {
|
impl WalletCore {
|
||||||
pub async fn send_public_native_token_transfer(
|
pub async fn send_public_native_token_transfer(
|
||||||
&self,
|
&self,
|
||||||
from: Address,
|
from: AccountId,
|
||||||
to: Address,
|
to: AccountId,
|
||||||
balance_to_move: u128,
|
balance_to_move: u128,
|
||||||
) -> Result<SendTxResponse, ExecutionFailureKind> {
|
) -> Result<SendTxResponse, ExecutionFailureKind> {
|
||||||
let Ok(balance) = self.get_account_balance(from).await else {
|
let Ok(balance) = self.get_account_balance(from).await else {
|
||||||
@ -23,9 +23,10 @@ impl WalletCore {
|
|||||||
return Err(ExecutionFailureKind::SequencerError);
|
return Err(ExecutionFailureKind::SequencerError);
|
||||||
};
|
};
|
||||||
|
|
||||||
let addresses = vec![from, to];
|
let account_ids = vec![from, to];
|
||||||
let program_id = Program::authenticated_transfer_program().id();
|
let program_id = Program::authenticated_transfer_program().id();
|
||||||
let message = Message::try_new(program_id, addresses, nonces, balance_to_move).unwrap();
|
let message =
|
||||||
|
Message::try_new(program_id, account_ids, nonces, balance_to_move).unwrap();
|
||||||
|
|
||||||
let signing_key = self.storage.user_data.get_pub_account_signing_key(&from);
|
let signing_key = self.storage.user_data.get_pub_account_signing_key(&from);
|
||||||
|
|
||||||
@ -45,16 +46,16 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub async fn register_account_under_authenticated_transfers_programs(
|
pub async fn register_account_under_authenticated_transfers_programs(
|
||||||
&self,
|
&self,
|
||||||
from: Address,
|
from: AccountId,
|
||||||
) -> Result<SendTxResponse, ExecutionFailureKind> {
|
) -> Result<SendTxResponse, ExecutionFailureKind> {
|
||||||
let Ok(nonces) = self.get_accounts_nonces(vec![from]).await else {
|
let Ok(nonces) = self.get_accounts_nonces(vec![from]).await else {
|
||||||
return Err(ExecutionFailureKind::SequencerError);
|
return Err(ExecutionFailureKind::SequencerError);
|
||||||
};
|
};
|
||||||
|
|
||||||
let instruction: u128 = 0;
|
let instruction: u128 = 0;
|
||||||
let addresses = vec![from];
|
let account_ids = vec![from];
|
||||||
let program_id = Program::authenticated_transfer_program().id();
|
let program_id = Program::authenticated_transfer_program().id();
|
||||||
let message = Message::try_new(program_id, addresses, nonces, instruction).unwrap();
|
let message = Message::try_new(program_id, account_ids, nonces, instruction).unwrap();
|
||||||
|
|
||||||
let signing_key = self.storage.user_data.get_pub_account_signing_key(&from);
|
let signing_key = self.storage.user_data.get_pub_account_signing_key(&from);
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use common::{error::ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
use common::{error::ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
||||||
use nssa::Address;
|
use nssa::AccountId;
|
||||||
use nssa_core::{
|
use nssa_core::{
|
||||||
MembershipProof, NullifierPublicKey, SharedSecretKey, encryption::IncomingViewingPublicKey,
|
MembershipProof, NullifierPublicKey, SharedSecretKey, encryption::IncomingViewingPublicKey,
|
||||||
};
|
};
|
||||||
@ -9,8 +9,8 @@ use crate::WalletCore;
|
|||||||
impl WalletCore {
|
impl WalletCore {
|
||||||
pub async fn send_shielded_native_token_transfer_already_initialized(
|
pub async fn send_shielded_native_token_transfer_already_initialized(
|
||||||
&self,
|
&self,
|
||||||
from: Address,
|
from: AccountId,
|
||||||
to: Address,
|
to: AccountId,
|
||||||
balance_to_move: u128,
|
balance_to_move: u128,
|
||||||
to_proof: MembershipProof,
|
to_proof: MembershipProof,
|
||||||
) -> Result<(SendTxResponse, [SharedSecretKey; 1]), ExecutionFailureKind> {
|
) -> Result<(SendTxResponse, [SharedSecretKey; 1]), ExecutionFailureKind> {
|
||||||
@ -23,8 +23,8 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub async fn send_shielded_native_token_transfer_not_initialized(
|
pub async fn send_shielded_native_token_transfer_not_initialized(
|
||||||
&self,
|
&self,
|
||||||
from: Address,
|
from: AccountId,
|
||||||
to: Address,
|
to: AccountId,
|
||||||
balance_to_move: u128,
|
balance_to_move: u128,
|
||||||
) -> Result<(SendTxResponse, [SharedSecretKey; 1]), ExecutionFailureKind> {
|
) -> Result<(SendTxResponse, [SharedSecretKey; 1]), ExecutionFailureKind> {
|
||||||
let (instruction_data, program, tx_pre_check) =
|
let (instruction_data, program, tx_pre_check) =
|
||||||
@ -36,7 +36,7 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub async fn send_shielded_native_token_transfer_outer_account(
|
pub async fn send_shielded_native_token_transfer_outer_account(
|
||||||
&self,
|
&self,
|
||||||
from: Address,
|
from: AccountId,
|
||||||
to_npk: NullifierPublicKey,
|
to_npk: NullifierPublicKey,
|
||||||
to_ipk: IncomingViewingPublicKey,
|
to_ipk: IncomingViewingPublicKey,
|
||||||
balance_to_move: u128,
|
balance_to_move: u128,
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use common::{error::ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
use common::{error::ExecutionFailureKind, sequencer_client::json::SendTxResponse};
|
||||||
use key_protocol::key_management::ephemeral_key_holder::EphemeralKeyHolder;
|
use key_protocol::key_management::ephemeral_key_holder::EphemeralKeyHolder;
|
||||||
use nssa::{
|
use nssa::{
|
||||||
Account, Address, PrivacyPreservingTransaction,
|
Account, AccountId, PrivacyPreservingTransaction,
|
||||||
privacy_preserving_transaction::{circuit, message::Message, witness_set::WitnessSet},
|
privacy_preserving_transaction::{circuit, message::Message, witness_set::WitnessSet},
|
||||||
program::Program,
|
program::Program,
|
||||||
};
|
};
|
||||||
@ -23,12 +23,15 @@ pub(crate) struct AccountPreparedData {
|
|||||||
impl WalletCore {
|
impl WalletCore {
|
||||||
pub(crate) async fn private_acc_preparation(
|
pub(crate) async fn private_acc_preparation(
|
||||||
&self,
|
&self,
|
||||||
addr: Address,
|
account_id: AccountId,
|
||||||
is_authorized: bool,
|
is_authorized: bool,
|
||||||
needs_proof: bool,
|
needs_proof: bool,
|
||||||
) -> Result<AccountPreparedData, ExecutionFailureKind> {
|
) -> Result<AccountPreparedData, ExecutionFailureKind> {
|
||||||
let Some((from_keys, from_acc)) =
|
let Some((from_keys, from_acc)) = self
|
||||||
self.storage.user_data.get_private_account(&addr).cloned()
|
.storage
|
||||||
|
.user_data
|
||||||
|
.get_private_account(&account_id)
|
||||||
|
.cloned()
|
||||||
else {
|
else {
|
||||||
return Err(ExecutionFailureKind::KeyNotFoundError);
|
return Err(ExecutionFailureKind::KeyNotFoundError);
|
||||||
};
|
};
|
||||||
@ -66,8 +69,8 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub(crate) async fn private_tx_two_accs_all_init(
|
pub(crate) async fn private_tx_two_accs_all_init(
|
||||||
&self,
|
&self,
|
||||||
from: Address,
|
from: AccountId,
|
||||||
to: Address,
|
to: AccountId,
|
||||||
instruction_data: InstructionData,
|
instruction_data: InstructionData,
|
||||||
tx_pre_check: impl FnOnce(&Account, &Account) -> Result<(), ExecutionFailureKind>,
|
tx_pre_check: impl FnOnce(&Account, &Account) -> Result<(), ExecutionFailureKind>,
|
||||||
program: Program,
|
program: Program,
|
||||||
@ -144,8 +147,8 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub(crate) async fn private_tx_two_accs_receiver_uninit(
|
pub(crate) async fn private_tx_two_accs_receiver_uninit(
|
||||||
&self,
|
&self,
|
||||||
from: Address,
|
from: AccountId,
|
||||||
to: Address,
|
to: AccountId,
|
||||||
instruction_data: InstructionData,
|
instruction_data: InstructionData,
|
||||||
tx_pre_check: impl FnOnce(&Account, &Account) -> Result<(), ExecutionFailureKind>,
|
tx_pre_check: impl FnOnce(&Account, &Account) -> Result<(), ExecutionFailureKind>,
|
||||||
program: Program,
|
program: Program,
|
||||||
@ -218,7 +221,7 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub(crate) async fn private_tx_two_accs_receiver_outer(
|
pub(crate) async fn private_tx_two_accs_receiver_outer(
|
||||||
&self,
|
&self,
|
||||||
from: Address,
|
from: AccountId,
|
||||||
to_npk: NullifierPublicKey,
|
to_npk: NullifierPublicKey,
|
||||||
to_ipk: IncomingViewingPublicKey,
|
to_ipk: IncomingViewingPublicKey,
|
||||||
instruction_data: InstructionData,
|
instruction_data: InstructionData,
|
||||||
@ -289,8 +292,8 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub(crate) async fn deshielded_tx_two_accs(
|
pub(crate) async fn deshielded_tx_two_accs(
|
||||||
&self,
|
&self,
|
||||||
from: Address,
|
from: AccountId,
|
||||||
to: Address,
|
to: AccountId,
|
||||||
instruction_data: InstructionData,
|
instruction_data: InstructionData,
|
||||||
tx_pre_check: impl FnOnce(&Account, &Account) -> Result<(), ExecutionFailureKind>,
|
tx_pre_check: impl FnOnce(&Account, &Account) -> Result<(), ExecutionFailureKind>,
|
||||||
program: Program,
|
program: Program,
|
||||||
@ -349,8 +352,8 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub(crate) async fn shielded_two_accs_all_init(
|
pub(crate) async fn shielded_two_accs_all_init(
|
||||||
&self,
|
&self,
|
||||||
from: Address,
|
from: AccountId,
|
||||||
to: Address,
|
to: AccountId,
|
||||||
instruction_data: InstructionData,
|
instruction_data: InstructionData,
|
||||||
tx_pre_check: impl FnOnce(&Account, &Account) -> Result<(), ExecutionFailureKind>,
|
tx_pre_check: impl FnOnce(&Account, &Account) -> Result<(), ExecutionFailureKind>,
|
||||||
program: Program,
|
program: Program,
|
||||||
@ -416,8 +419,8 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub(crate) async fn shielded_two_accs_receiver_uninit(
|
pub(crate) async fn shielded_two_accs_receiver_uninit(
|
||||||
&self,
|
&self,
|
||||||
from: Address,
|
from: AccountId,
|
||||||
to: Address,
|
to: AccountId,
|
||||||
instruction_data: InstructionData,
|
instruction_data: InstructionData,
|
||||||
tx_pre_check: impl FnOnce(&Account, &Account) -> Result<(), ExecutionFailureKind>,
|
tx_pre_check: impl FnOnce(&Account, &Account) -> Result<(), ExecutionFailureKind>,
|
||||||
program: Program,
|
program: Program,
|
||||||
@ -482,7 +485,7 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub(crate) async fn shielded_two_accs_receiver_outer(
|
pub(crate) async fn shielded_two_accs_receiver_outer(
|
||||||
&self,
|
&self,
|
||||||
from: Address,
|
from: AccountId,
|
||||||
to_npk: NullifierPublicKey,
|
to_npk: NullifierPublicKey,
|
||||||
to_ipk: IncomingViewingPublicKey,
|
to_ipk: IncomingViewingPublicKey,
|
||||||
instruction_data: InstructionData,
|
instruction_data: InstructionData,
|
||||||
@ -540,7 +543,7 @@ impl WalletCore {
|
|||||||
|
|
||||||
pub async fn register_account_under_authenticated_transfers_programs_private(
|
pub async fn register_account_under_authenticated_transfers_programs_private(
|
||||||
&self,
|
&self,
|
||||||
from: Address,
|
from: AccountId,
|
||||||
) -> Result<(SendTxResponse, [SharedSecretKey; 1]), ExecutionFailureKind> {
|
) -> Result<(SendTxResponse, [SharedSecretKey; 1]), ExecutionFailureKind> {
|
||||||
let AccountPreparedData {
|
let AccountPreparedData {
|
||||||
nsk: _,
|
nsk: _,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user