Skip to content

Commit

Permalink
refactor(test_faucet): include create_utxo to avoid unintentionally b…
Browse files Browse the repository at this point in the history
…reaking faucet utxos
  • Loading branch information
sdbondi committed Jan 28, 2022
1 parent d7d76fb commit d1befc2
Showing 1 changed file with 56 additions and 8 deletions.
64 changes: 56 additions & 8 deletions applications/test_faucet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,30 @@
#![deny(unreachable_patterns)]
#![deny(unknown_lints)]

use std::{fs::File, io::Write};
use std::{
fs::File,
io::{stdout, Write},
};

use serde::Serialize;
use tari_common_types::types::{Commitment, PrivateKey};
use tari_core::transactions::{
tari_amount::{MicroTari, T},
test_helpers,
transaction::{KernelFeatures, OutputFeatures, TransactionKernel, TransactionOutput},
CryptoFactories,
use tari_core::{
covenants::Covenant,
transactions::{
tari_amount::{MicroTari, T},
test_helpers,
test_helpers::generate_keys,
transaction::{KernelFeatures, OutputFeatures, TransactionKernel, TransactionOutput},
CryptoFactories,
},
};
use tari_crypto::{
commitment::HomomorphicCommitmentFactory,
range_proof::RangeProofService,
script,
script::TariScript,
tari_utilities::hex::Hex,
};
use tari_crypto::{script, tari_utilities::hex::Hex};
use tokio::{sync::mpsc, task};

const NUM_KEYS: usize = 4000;
Expand Down Expand Up @@ -63,8 +76,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
task::spawn(async move {
let result = task::spawn_blocking(move || {
let script = script!(Nop);
let (utxo, key, _) = test_helpers::create_utxo(value, &fc, feature, &script, &Default::default());
let (utxo, key, _) = create_utxo(value, &fc, feature, script, Default::default());
print!(".");
let _ = stdout().flush();
(utxo, key, value)
})
.await
Expand Down Expand Up @@ -137,3 +151,37 @@ impl Iterator for UTXOFeatures {
Some(f)
}
}

/// Create a new UTXO for the specified value and return the output and spending key
fn create_utxo(
value: MicroTari,
factories: &CryptoFactories,
features: OutputFeatures,
script: TariScript,
covenant: Covenant,
) -> (TransactionOutput, PrivateKey, PrivateKey) {
let keys = generate_keys();
let offset_keys = generate_keys();
let commitment = factories.commitment.commit_value(&keys.k, value.into());
let proof = factories.range_proof.construct_proof(&keys.k, value.into()).unwrap();
let metadata_sig = TransactionOutput::create_final_metadata_signature(
&value,
&keys.k,
&script,
&features,
&offset_keys.k,
&covenant,
)
.unwrap();

let utxo = TransactionOutput::new_current_version(
features,
commitment,
proof.into(),
script,
offset_keys.pk,
metadata_sig,
covenant,
);
(utxo, keys.k, offset_keys.k)
}

0 comments on commit d1befc2

Please sign in to comment.