Skip to content

Commit

Permalink
Merge branch 'development' into confidential-cli-mint-proof
Browse files Browse the repository at this point in the history
* development:
  feat(wallet)!: monitor accounts for received funds (tari-project#425)
  feat(claim_burn)!: adds encrypted value to UnclaimedConfidentialOutput substate (tari-project#427)
  • Loading branch information
sdbondi committed Mar 13, 2023
2 parents 7c97cda + 4a11f98 commit dcbe74b
Show file tree
Hide file tree
Showing 84 changed files with 1,774 additions and 641 deletions.
4 changes: 3 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions applications/tari_dan_app_grpc/proto/transaction.proto
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ message Instruction {
bytes claim_burn_commitment_address = 10;
bytes claim_burn_range_proof = 11;
CommitmentSignature claim_burn_proof_of_knowledge = 12;
bytes claim_burn_public_key = 13;
}

message Arg {
Expand Down
14 changes: 11 additions & 3 deletions applications/tari_dan_app_grpc/src/conversions/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,19 @@ impl TryFrom<proto::transaction::Instruction> for tari_engine_types::instruction
},
4 => Instruction::ClaimBurn {
claim: Box::new(ConfidentialClaim {
commitment_address: request.claim_burn_commitment_address.try_into()?,
public_key: PublicKey::from_bytes(&request.claim_burn_public_key)
.map_err(|e| anyhow!("claim_burn_public_key: {}", e))?,
output_address: request
.claim_burn_commitment_address
.as_slice()
.try_into()
.map_err(|e| anyhow!("claim_burn_commitment_address: {}", e))?,
range_proof: request.claim_burn_range_proof,
proof_of_knowledge: request
.claim_burn_proof_of_knowledge
.ok_or_else(|| anyhow!("claim_burn_proof_of_knowledge not provided"))?
.try_into()?,
.try_into()
.map_err(|e| anyhow!("claim_burn_proof_of_knowledge: {}", e))?,
}),
},
_ => return Err(anyhow!("invalid instruction_type")),
Expand Down Expand Up @@ -173,9 +180,10 @@ impl From<tari_engine_types::instruction::Instruction> for proto::transaction::I
},
Instruction::ClaimBurn { claim } => {
result.instruction_type = 4;
result.claim_burn_commitment_address = claim.commitment_address.to_vec();
result.claim_burn_commitment_address = claim.output_address.to_vec();
result.claim_burn_range_proof = claim.range_proof.to_vec();
result.claim_burn_proof_of_knowledge = Some(claim.proof_of_knowledge.into());
result.claim_burn_public_key = claim.public_key.to_vec();
},
}
result
Expand Down
26 changes: 18 additions & 8 deletions applications/tari_dan_app_utilities/src/base_layer_scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use tari_common_types::types::{Commitment, FixedHash, FixedHashSizeError};
use tari_core::transactions::transaction_components::{
CodeTemplateRegistration,
SideChainFeature,
TransactionOutput,
ValidatorNodeRegistration,
};
use tari_crypto::tari_utilities::ByteArray;
Expand All @@ -52,9 +53,12 @@ use tari_dan_storage_sqlite::{
global::SqliteGlobalDbAdapter,
sqlite_shard_store_factory::SqliteShardStore,
};
use tari_engine_types::substate::{Substate, SubstateAddress, SubstateValue};
use tari_engine_types::{
confidential::UnclaimedConfidentialOutput,
substate::{Substate, SubstateAddress, SubstateValue},
};
use tari_shutdown::ShutdownSignal;
use tari_template_lib::models::{LayerOneCommitmentAddress, TemplateAddress};
use tari_template_lib::models::{EncryptedValue, TemplateAddress, UnclaimedConfidentialOutputAddress};
use tokio::{task, task::JoinHandle, time};

use crate::{
Expand Down Expand Up @@ -287,7 +291,7 @@ impl BaseLayerScanner {
let output_hash = output.hash();
if output.is_burned() {
info!(target: LOG_TARGET, "Found burned output: {}", output_hash);
self.register_burnt_utxo(output.commitment)?;
self.register_burnt_utxo(&output)?;
} else {
let sidechain_feature = output.features.sidechain_feature.ok_or_else(|| {
BaseLayerScannerError::InvalidSideChainUtxoResponse(
Expand Down Expand Up @@ -338,18 +342,24 @@ impl BaseLayerScanner {
Ok(())
}

fn register_burnt_utxo(&mut self, commitment: Commitment) -> Result<(), BaseLayerScannerError> {
let address = SubstateAddress::LayerOneCommitment(
LayerOneCommitmentAddress::try_from_commitment(commitment.as_bytes()).map_err(|e|
fn register_burnt_utxo(&mut self, output: &TransactionOutput) -> Result<(), BaseLayerScannerError> {
let address = SubstateAddress::UnclaimedConfidentialOutput(
UnclaimedConfidentialOutputAddress::try_from_commitment(output.commitment.as_bytes()).map_err(|e|
// Technically impossible, but anyway
BaseLayerScannerError::InvalidSideChainUtxoResponse(format!("Invalid commitment: {}", e)))?,
);
let substate = Substate::new(0, SubstateValue::LayerOneCommitment(commitment.as_bytes().to_vec()));
let substate = Substate::new(
0,
SubstateValue::UnclaimedConfidentialOutput(UnclaimedConfidentialOutput {
commitment: output.commitment.clone(),
encrypted_value: EncryptedValue(output.encrypted_value.0),
}),
);
let shard_id = ShardId::from_address(&address, 0);
self.shard_store
.with_write_tx(|tx| tx.save_burnt_utxo(&substate, address, shard_id))
.map_err(|source| BaseLayerScannerError::CouldNotRegisterBurntUtxo {
commitment: Box::new(commitment),
commitment: Box::new(output.commitment.clone()),
source,
})?;
Ok(())
Expand Down
40 changes: 24 additions & 16 deletions applications/tari_dan_wallet_cli/src/command/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@ use std::{io, io::Read};
use anyhow::anyhow;
use clap::{Args, Subcommand};
use serde_json as json;
use tari_template_lib::prelude::ComponentAddress;
use tari_wallet_daemon_client::{
types::{AccountsCreateRequest, AccountsGetBalancesRequest, AccountsInvokeRequest, ClaimBurnRequest},
types::{
AccountByNameResponse,
AccountsCreateRequest,
AccountsGetBalancesRequest,
AccountsInvokeRequest,
ClaimBurnRequest,
},
WalletDaemonClient,
};

use crate::{
command::transaction::{print_execution_results, CliArg},
command::transaction::{print_execution_results, summarize_finalize_result, CliArg},
table::Table,
table_row,
};
Expand Down Expand Up @@ -79,10 +84,11 @@ pub struct GetByNameArgs {

#[derive(Debug, Args, Clone)]
pub struct ClaimBurnArgs {
#[clap(long, short = 'a')]
account_address: ComponentAddress,
#[clap(long, short = 'n', alias = "name")]
account_name: String,
/// Optional proof JSON from the L1 console wallet. If not provided, you will be prompted to enter it.
#[clap(long, short = 'j', alias = "json")]
proof_json: Option<String>,
proof_json: Option<serde_json::Value>,
#[clap(long, short = 'f')]
fee: Option<u64>,
}
Expand Down Expand Up @@ -180,12 +186,14 @@ async fn handle_get_balances(args: GetBalancesArgs, client: &mut WalletDaemonCli

pub async fn handle_claim_burn(args: ClaimBurnArgs, client: &mut WalletDaemonClient) -> Result<(), anyhow::Error> {
let ClaimBurnArgs {
account_address,
account_name,
proof_json,
fee,
} = args;

let proof_json = if let Some(proof_json) = proof_json {
let AccountByNameResponse { account_address } = client.accounts_get_by_name(account_name).await?;

let claim_proof = if let Some(proof_json) = proof_json {
proof_json
} else {
println!(
Expand All @@ -195,29 +203,29 @@ pub async fn handle_claim_burn(args: ClaimBurnArgs, client: &mut WalletDaemonCli

let mut proof_json = String::new();
io::stdin().read_to_string(&mut proof_json)?;
println!("{}", proof_json);
proof_json.trim().to_string()
json::from_str::<json::Value>(proof_json.trim()).map_err(|e| anyhow!("Failed to parse proof JSON: {}", e))?
};

let claim = json::from_str::<json::Value>(&proof_json).map_err(|e| anyhow!("Failed to parse proof JSON: {}", e))?;
println!("JSON OK");
println!("✅ Claim burn submitted");

let req = ClaimBurnRequest {
account: account_address,
claim,
account: account_address.as_component_address().unwrap(),
claim_proof,
fee: fee.unwrap_or(1),
};

client
let resp = client
.claim_burn(req)
.await
.map_err(|e| anyhow!("Failed to claim burn with error = {}", e.to_string()))?;

summarize_finalize_result(&resp.result);
Ok(())
}

async fn handle_list(client: &mut WalletDaemonClient) -> Result<(), anyhow::Error> {
println!("Submitted account list transaction...");
let resp = client.list_accounts(100).await?;
let resp = client.list_accounts(0, 100).await?;

if resp.accounts.is_empty() {
println!("No accounts found");
Expand Down
11 changes: 9 additions & 2 deletions applications/tari_dan_wallet_cli/src/command/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use tari_template_lib::{
arg,
args,
args::Arg,
constants::CONFIDENTIAL_TARI_RESOURCE_ADDRESS,
models::{Amount, NonFungibleAddress, NonFungibleId},
prelude::{ComponentAddress, ResourceAddress},
};
Expand Down Expand Up @@ -139,6 +140,9 @@ pub struct ConfidentialTransferArgs {
amount: u32,
destination_account: ComponentAddress,
destination_stealth_public_key: FromBase64<Vec<u8>>,
/// The address of the resource to send. If not provided, use the default Tari confidential resource
#[clap(long, short = 'r')]
resource_address: Option<ResourceAddress>,
#[clap(flatten)]
common: CommonSubmitArgs,
}
Expand Down Expand Up @@ -356,6 +360,7 @@ pub async fn handle_confidential_transfer(
) -> Result<TransactionSubmitResponse, anyhow::Error> {
let ConfidentialTransferArgs {
source_account_name,
resource_address,
amount,
destination_account,
destination_stealth_public_key,
Expand All @@ -369,9 +374,11 @@ pub async fn handle_confidential_transfer(
.ok_or_else(|| anyhow!("Invalid component address for source address"))?;
let destination_stealth_public_key = RistrettoPublicKey::from_bytes(&destination_stealth_public_key.into_inner())?;

let resource_address = resource_address.unwrap_or(CONFIDENTIAL_TARI_RESOURCE_ADDRESS);
let proof_generate_req = ProofsGenerateRequest {
amount: Amount::from(amount),
source_account_name,
resource_address,
destination_account,
destination_stealth_public_key,
};
Expand Down Expand Up @@ -463,7 +470,7 @@ fn summarize(result: &TransactionWaitResultResponse, time_taken: Duration) {
}
}

fn summarize_finalize_result(finalize: &FinalizeResult) {
pub fn summarize_finalize_result(finalize: &FinalizeResult) {
println!("========= Substates =========");
match finalize.result {
TransactionResult::Accept(ref diff) => {
Expand All @@ -483,7 +490,7 @@ fn summarize_finalize_result(finalize: &FinalizeResult) {
SubstateValue::NonFungible(_) => {
println!(" ▶ NFT: {}", address);
},
SubstateValue::LayerOneCommitment(_) => {
SubstateValue::UnclaimedConfidentialOutput(_) => {
println!(" ▶ Layer 1 commitment: {}", address);
},
SubstateValue::NonFungibleIndex(index) => {
Expand Down
1 change: 1 addition & 0 deletions applications/tari_dan_wallet_daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tari_wallet_daemon_client = { path = "../../clients/wallet_daemon_client" }
tari_template_builtin = { path = "../../dan_layer/template_builtin" }
# TODO: Ideally we should not have to include the WASM template lib, we should perhaps extract the address types into a separate crate (e.g. template_types)
tari_template_lib = { path = "../../dan_layer/template_lib" }
tari_bor = { path = "../../dan_layer/tari_bor" }

anyhow = "1.0.69"
base64 = "0.20.0-alpha.1"
Expand Down
Loading

0 comments on commit dcbe74b

Please sign in to comment.