From f2a90b34a6934ffde51687a8cb808ce64b9418d5 Mon Sep 17 00:00:00 2001 From: muraca Date: Mon, 13 Nov 2023 21:10:22 +0100 Subject: [PATCH] renamed `SigCheck` to `Sr25519Signature` Signed-off-by: muraca --- tuxedo-core/src/verifier.rs | 20 ++++++++++---------- tuxedo-template-runtime/src/genesis.rs | 8 ++++---- tuxedo-template-runtime/src/lib.rs | 4 ++-- wallet/src/main.rs | 6 +++--- wallet/src/money.rs | 6 +++--- wallet/src/output_filter.rs | 22 ++++++++++++---------- wallet/src/sync.rs | 4 ++-- 7 files changed, 36 insertions(+), 34 deletions(-) diff --git a/tuxedo-core/src/verifier.rs b/tuxedo-core/src/verifier.rs index 62d16cf53..140648954 100644 --- a/tuxedo-core/src/verifier.rs +++ b/tuxedo-core/src/verifier.rs @@ -25,19 +25,19 @@ pub trait Verifier: Debug + Encode + Decode + Clone { /// A typical verifier that checks an sr25519 signature #[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] -pub struct SigCheck { +pub struct Sr25519Signature { pub owner_pubkey: H256, } -impl SigCheck { +impl Sr25519Signature { pub fn new>(value: T) -> Self { - SigCheck { + Sr25519Signature { owner_pubkey: value.into(), } } } -impl Verifier for SigCheck { +impl Verifier for Sr25519Signature { fn verify(&self, simplified_tx: &[u8], redeemer: &[u8]) -> bool { let sig = match Signature::try_from(redeemer) { Ok(s) => s, @@ -190,17 +190,17 @@ mod test { } #[test] - fn sig_check_with_good_sig() { + fn sr25519_signature_with_good_sig() { let pair = Pair::from_seed(&[0u8; 32]); let simplified_tx = b"hello world".as_slice(); let sig = pair.sign(simplified_tx); let redeemer: &[u8] = sig.as_ref(); - let sig_check = SigCheck { + let sr25519_signature = Sr25519Signature { owner_pubkey: pair.public().into(), }; - assert!(sig_check.verify(simplified_tx, redeemer)); + assert!(sr25519_signature.verify(simplified_tx, redeemer)); } #[test] @@ -354,15 +354,15 @@ mod test { } #[test] - fn sig_check_with_bad_sig() { + fn sr25519_signature_with_bad_sig() { let simplified_tx = b"hello world".as_slice(); let redeemer = b"bogus_signature".as_slice(); - let sig_check = SigCheck { + let sr25519_signature = Sr25519Signature { owner_pubkey: H256::zero(), }; - assert!(!sig_check.verify(simplified_tx, redeemer)); + assert!(!sr25519_signature.verify(simplified_tx, redeemer)); } #[test] diff --git a/tuxedo-template-runtime/src/genesis.rs b/tuxedo-template-runtime/src/genesis.rs index e41a604f4..923a62406 100644 --- a/tuxedo-template-runtime/src/genesis.rs +++ b/tuxedo-template-runtime/src/genesis.rs @@ -8,7 +8,7 @@ use super::{ use hex_literal::hex; use tuxedo_core::{ inherents::InherentInternal, - verifier::{SigCheck, ThresholdMultiSignature, UpForGrabs}, + verifier::{Sr25519Signature, ThresholdMultiSignature, UpForGrabs}, }; /// Helper type for the ChainSpec. @@ -28,7 +28,7 @@ pub fn development_genesis_config() -> RuntimeGenesisConfig { genesis_transactions.extend([ // Money Transactions - Coin::<0>::mint(100, SigCheck::new(SHAWN_PUB_KEY_BYTES)), + Coin::<0>::mint(100, Sr25519Signature::new(SHAWN_PUB_KEY_BYTES)), Coin::<0>::mint(100, ThresholdMultiSignature::new(1, signatories)), // Kitty Transactions KittyData::mint(Parent::mom(), b"mother", UpForGrabs), @@ -85,7 +85,7 @@ mod tests { let mut genesis_transactions = OuterConstraintCheckerInherentHooks::genesis_transactions(); genesis_transactions.extend([ // Money Transactions - Coin::<0>::mint(100, SigCheck::new(shawn_pub_key_bytes)), + Coin::<0>::mint(100, Sr25519Signature::new(shawn_pub_key_bytes)), Coin::<0>::mint(100, ThresholdMultiSignature::new(1, signatories)), ]); @@ -118,7 +118,7 @@ mod tests { // Grab genesis value from storage and assert it is correct let genesis_utxo = Output { - verifier: OuterVerifier::SigCheck(SigCheck { + verifier: OuterVerifier::Sr25519Signature(Sr25519Signature { owner_pubkey: shawn_pub_key.into(), }), payload: DynamicallyTypedData { diff --git a/tuxedo-template-runtime/src/lib.rs b/tuxedo-template-runtime/src/lib.rs index bea0f00d2..a5e1f3033 100644 --- a/tuxedo-template-runtime/src/lib.rs +++ b/tuxedo-template-runtime/src/lib.rs @@ -36,7 +36,7 @@ use sp_version::RuntimeVersion; use tuxedo_core::{ tuxedo_constraint_checker, tuxedo_verifier, types::Transaction as TuxedoTransaction, - verifier::{SigCheck, ThresholdMultiSignature, UpForGrabs}, + verifier::{Sr25519Signature, ThresholdMultiSignature, UpForGrabs}, }; pub use amoeba; @@ -124,7 +124,7 @@ const BLOCK_TIME: u64 = 3000; #[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] #[tuxedo_verifier] pub enum OuterVerifier { - SigCheck(SigCheck), + Sr25519Signature(Sr25519Signature), UpForGrabs(UpForGrabs), ThresholdMultiSignature(ThresholdMultiSignature), } diff --git a/wallet/src/main.rs b/wallet/src/main.rs index ef356934d..e298c7189 100644 --- a/wallet/src/main.rs +++ b/wallet/src/main.rs @@ -73,7 +73,7 @@ async fn main() -> anyhow::Result<()> { let keystore_filter = |v: &OuterVerifier| -> bool { matches![ v, - OuterVerifier::SigCheck(SigCheck { owner_pubkey }) if crate::keystore::has_key(&keystore, owner_pubkey) + OuterVerifier::Sr25519Signature(Sr25519Signature { owner_pubkey }) if crate::keystore::has_key(&keystore, owner_pubkey) ] }; @@ -243,8 +243,8 @@ fn default_data_path() -> PathBuf { /// Utility to pretty print an outer verifier pub fn pretty_print_verifier(v: &OuterVerifier) { match v { - OuterVerifier::SigCheck(sig_check) => { - println! {"owned by {}", sig_check.owner_pubkey} + OuterVerifier::Sr25519Signature(sr25519_signature) => { + println! {"owned by {}", sr25519_signature.owner_pubkey} } OuterVerifier::UpForGrabs(_) => println!("that can be spent by anyone"), OuterVerifier::ThresholdMultiSignature(multi_sig) => { diff --git a/wallet/src/money.rs b/wallet/src/money.rs index e0264f41a..d4fb2e728 100644 --- a/wallet/src/money.rs +++ b/wallet/src/money.rs @@ -15,7 +15,7 @@ use sp_core::sr25519::Public; use sp_runtime::traits::{BlakeTwo256, Hash}; use tuxedo_core::{ types::{Input, Output, OutputRef}, - verifier::SigCheck, + verifier::Sr25519Signature, }; /// Create and send a transaction that spends coins on the network @@ -40,7 +40,7 @@ pub async fn spend_coins( for amount in &args.output_amount { let output = Output { payload: Coin::<0>::new(*amount).into(), - verifier: OuterVerifier::SigCheck(SigCheck { + verifier: OuterVerifier::Sr25519Signature(Sr25519Signature { owner_pubkey: args.recipient, }), }; @@ -93,7 +93,7 @@ pub async fn spend_coins( // Construct the proof that it can be consumed let redeemer = match utxo.verifier { - OuterVerifier::SigCheck(SigCheck { owner_pubkey }) => { + OuterVerifier::Sr25519Signature(Sr25519Signature { owner_pubkey }) => { let public = Public::from_h256(owner_pubkey); crate::keystore::sign_with(keystore, &public, &stripped_encoded_transaction)? } diff --git a/wallet/src/output_filter.rs b/wallet/src/output_filter.rs index 13759a06f..555fc5a55 100644 --- a/wallet/src/output_filter.rs +++ b/wallet/src/output_filter.rs @@ -16,8 +16,8 @@ pub trait OutputFilter { fn build_filter(verifier: OuterVerifier) -> Self::Filter; } -pub struct SigCheckFilter; -impl OutputFilter for SigCheckFilter { +pub struct Sr25519SignatureFilter; +impl OutputFilter for Sr25519SignatureFilter { // Todo Add filter error type Filter = Result; @@ -48,8 +48,8 @@ mod tests { #[cfg(test)] use tuxedo_core::{dynamic_typing::DynamicallyTypedData, verifier::*}; - pub struct TestSigCheckFilter; - impl OutputFilter for TestSigCheckFilter { + pub struct TestSr25519SignatureFilter; + impl OutputFilter for TestSr25519SignatureFilter { type Filter = Result; fn build_filter(_verifier: OuterVerifier) -> Self::Filter { @@ -62,7 +62,7 @@ mod tests { #[test] fn filter_prints() { - let verifier = OuterVerifier::SigCheck(SigCheck { + let verifier = OuterVerifier::Sr25519Signature(Sr25519Signature { owner_pubkey: H256::zero(), }); let output = Output { @@ -73,13 +73,14 @@ mod tests { }, }; - let my_filter = TestSigCheckFilter::build_filter(verifier).expect("Can build print filter"); + let my_filter = + TestSr25519SignatureFilter::build_filter(verifier).expect("Can build print filter"); let _ = my_filter(&[output], &H256::zero()); } #[test] - fn filter_sig_check_works() { - let verifier = OuterVerifier::SigCheck(SigCheck { + fn filter_sr25519_signature_works() { + let verifier = OuterVerifier::Sr25519Signature(Sr25519Signature { owner_pubkey: H256::zero(), }); @@ -92,7 +93,7 @@ mod tests { }, }, Output { - verifier: OuterVerifier::SigCheck(SigCheck { + verifier: OuterVerifier::Sr25519Signature(Sr25519Signature { owner_pubkey: H256::from_slice(b"asdfasdfasdfasdfasdfasdfasdfasdf"), }), payload: DynamicallyTypedData { @@ -126,7 +127,8 @@ mod tests { }, )]; - let my_filter = SigCheckFilter::build_filter(verifier).expect("Can build sigcheck filter"); + let my_filter = Sr25519SignatureFilter::build_filter(verifier) + .expect("Can build Sr25519Signature filter"); let filtered_output_infos = my_filter(&outputs_to_filter, &H256::zero()) .expect("Can filter the outputs by verifier correctly"); diff --git a/wallet/src/sync.rs b/wallet/src/sync.rs index 0ade4fe6f..bc2d0ef10 100644 --- a/wallet/src/sync.rs +++ b/wallet/src/sync.rs @@ -21,7 +21,7 @@ use sp_core::H256; use sp_runtime::traits::{BlakeTwo256, Hash}; use tuxedo_core::{ types::{Input, OutputRef}, - verifier::SigCheck, + verifier::Sr25519Signature, }; use jsonrpsee::http_client::HttpClient; @@ -274,7 +274,7 @@ async fn apply_transaction bool>( }; match output.verifier { - OuterVerifier::SigCheck(SigCheck { owner_pubkey }) => { + OuterVerifier::Sr25519Signature(Sr25519Signature { owner_pubkey }) => { // Add it to the global unspent_outputs table add_unspent_output(db, &output_ref, &owner_pubkey, &amount)?; }