Skip to content

Strongly typed UTXOs #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion tuxedo-core/src/constraint_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use sp_std::{fmt::Debug, vec::Vec};

use crate::{dynamic_typing::DynamicallyTypedData, inherents::InherentInternal, types::Output};
use crate::{dynamic_typing::{DynamicallyTypedData}, inherents::InherentInternal, types::Output};
use parity_scale_codec::{Decode, Encode};
use sp_runtime::transaction_validity::TransactionPriority;

Expand All @@ -19,6 +19,10 @@ pub trait SimpleConstraintChecker: Debug + Encode + Decode + Clone {
/// The error type that this constraint checker may return
type Error: Debug;

/// Storable type(s) introduced by this piece. Any data type that you plan to store in
/// a UTXO should be included here. If there are multiple such types, use an enum.
type UtxoData: Encode + Decode + Debug;

/// The actual check validation logic
fn check(
&self,
Expand All @@ -42,6 +46,10 @@ pub trait ConstraintChecker<V>: Debug + Encode + Decode + Clone {
/// The error type that this constraint checker may return
type Error: Debug;

/// Storable type(s) introduced by this piece. Any data type that you plan to store in
/// a UTXO should be included here. If there are multiple such types, use an enum.
type UtxoData: Encode + Decode + Debug;

/// Optional Associated Inherent processing logic. If this transaction type is not an inherent, use ().
/// If it is an inherent, use Self, and implement the TuxedoInherent trait.
type InherentHooks: InherentInternal<V, Self>;
Expand All @@ -66,6 +74,10 @@ impl<T: SimpleConstraintChecker, V> ConstraintChecker<V> for T {
// Use the same error type used in the simple implementation.
type Error = <T as SimpleConstraintChecker>::Error;

/// Storable type(s) introduced by this piece. Any data type that you plan to store in
/// a UTXO should be included here. If there are multiple such types, use an enum.
type UtxoData = <T as SimpleConstraintChecker>::UtxoData;

type InherentHooks = ();

fn check(
Expand Down Expand Up @@ -116,6 +128,7 @@ pub mod testing {

impl ConstraintChecker<TestVerifier> for TestConstraintChecker {
type Error = ();
type UtxoData = ();
type InherentHooks = ();

fn check(
Expand Down
6 changes: 2 additions & 4 deletions wardrobe/money/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ impl<const ID: u8> Coin<ID> {
}
}

impl<const ID: u8> UtxoData for Coin<ID> {
const TYPE_ID: [u8; 4] = [b'c', b'o', b'i', ID];
}

/// Errors that can occur when checking money transactions.
#[derive(
Serialize,
Expand Down Expand Up @@ -138,6 +134,8 @@ pub enum ConstraintCheckerError {
impl<const ID: u8> SimpleConstraintChecker for MoneyConstraintChecker<ID> {
type Error = ConstraintCheckerError;

type UtxoData = Coin<ID>;

fn check(
&self,
input_data: &[DynamicallyTypedData],
Expand Down