Skip to content

Commit

Permalink
Type Info. Reflect paritytech/substrate#13272
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshOrndorff committed May 1, 2023
1 parent 2ddf7c8 commit d287a37
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
3 changes: 2 additions & 1 deletion tuxedo-core/src/dynamic_typing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@
//! around by, for example, hashing the Debug strong, but that is ugly
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_std::vec::Vec;

/// A piece of encoded data with a type id associated
/// Strongly typed data can be extracted
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct DynamicallyTypedData {
pub data: Vec<u8>,
pub type_id: [u8; 4],
Expand Down
9 changes: 5 additions & 4 deletions tuxedo-core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use crate::dynamic_typing::DynamicallyTypedData;
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_core::H256;
Expand All @@ -10,7 +11,7 @@ use sp_std::vec::Vec;

/// A reference to a output that is expected to exist in the state.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct OutputRef {
/// A hash of the transaction that created this output
pub tx_hash: H256,
Expand All @@ -33,7 +34,7 @@ pub struct OutputRef {
/// In the future, there may be additional notions of peeks (inputs that are not consumed)
/// and evictions (inputs that are forcefully consumed.)
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Eq, Clone)]
#[derive(Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct Transaction<V, C> {
pub inputs: Vec<Input>,
//Todo peeks: Vec<Input>,
Expand Down Expand Up @@ -101,7 +102,7 @@ impl<V, C> Extrinsic for Transaction<V, C> {

/// A reference the a utxo that will be consumed along with proof that it may be consumed
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct Input {
/// a reference to the output being consumed
pub output_ref: OutputRef,
Expand Down Expand Up @@ -133,7 +134,7 @@ pub type DispatchResult<VerifierError> = Result<(), UtxoError<VerifierError>>;
/// In a cryptocurrency, the data represents a single coin. In Tuxedo, the type of
/// the contained data is generic.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct Output<V> {
pub payload: DynamicallyTypedData,
pub verifier: V,
Expand Down
7 changes: 4 additions & 3 deletions tuxedo-core/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//!
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_core::sr25519::{Public, Signature};
Expand All @@ -25,7 +26,7 @@ pub trait Verifier: Debug + Encode + Decode + Clone {

/// A typical verifier that checks an sr25519 signature
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct SigCheck {
pub owner_pubkey: H256,
}
Expand All @@ -43,7 +44,7 @@ impl Verifier for SigCheck {

/// A simple verifier that allows anyone to consume an output at any time
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct UpForGrabs;

impl Verifier for UpForGrabs {
Expand All @@ -57,7 +58,7 @@ impl Verifier for UpForGrabs {
/// `threshold` of the signatories. If the threshold is greater than the number of signatories
/// the input can never be consumed.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct ThresholdMultiSignature {
/// The minimum number of valid signatures needed to consume this input
pub threshold: u8,
Expand Down
7 changes: 4 additions & 3 deletions tuxedo-template-runtime/src/amoeba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//! mother amoeba and creates, in its place two new daughter amoebas.
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_runtime::transaction_validity::TransactionPriority;
Expand Down Expand Up @@ -75,7 +76,7 @@ pub enum ConstraintCheckerError {
/// 2. There are exactly two daughter amoebas
/// 3. Each Daughter amoeba has a generation one higher than its mother.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct AmoebaMitosis;

impl SimpleConstraintChecker for AmoebaMitosis {
Expand Down Expand Up @@ -133,7 +134,7 @@ impl SimpleConstraintChecker for AmoebaMitosis {
/// Any amoeba can be killed by providing it as the sole input to this constraint checker. No
/// new outputs are ever created.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct AmoebaDeath;

impl SimpleConstraintChecker for AmoebaDeath {
Expand Down Expand Up @@ -172,7 +173,7 @@ impl SimpleConstraintChecker for AmoebaDeath {
/// A new amoeba can be created by providing it as the sole output to this constraint checker. No
/// inputs are ever consumed.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct AmoebaCreation;

impl SimpleConstraintChecker for AmoebaCreation {
Expand Down
5 changes: 3 additions & 2 deletions tuxedo-template-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_consensus_grandpa::AuthorityId as GrandpaId;

Expand Down Expand Up @@ -184,7 +185,7 @@ const BLOCK_TIME: u64 = 3000;
/// A verifier checks that an individual input can be consumed. For example that it is signed properly
/// To begin playing, we will have two kinds. A simple signature check, and an anyone-can-consume check.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[tuxedo_verifier]
pub enum OuterVerifier {
SigCheck(SigCheck),
Expand All @@ -200,7 +201,7 @@ pub enum OuterVerifier {
/// For any given Tuxedo runtime there is a finite set of such constraint checkers.
/// For example, this may check that input token values exceed output token values.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[tuxedo_constraint_checker]
pub enum OuterConstraintChecker {
/// Checks monetary transactions in a basic fungible cryptocurrency
Expand Down
7 changes: 4 additions & 3 deletions tuxedo-template-runtime/src/poe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//! https://cannerlaw.com/blog/the-difference-of-recorded-and-registered-land/
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_core::H256;
Expand Down Expand Up @@ -65,7 +66,7 @@ pub enum ConstraintCheckerError {
/// It also allows the creation of zero claims, although such a transaction is useless and is simply a
/// waste of caller fees.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct PoeClaim;

impl SimpleConstraintChecker for PoeClaim {
Expand Down Expand Up @@ -108,7 +109,7 @@ impl SimpleConstraintChecker for PoeClaim {
///
/// Like the creation constraint checker, this allows batch revocation.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct PoeRevoke;

impl SimpleConstraintChecker for PoeRevoke {
Expand Down Expand Up @@ -147,7 +148,7 @@ impl SimpleConstraintChecker for PoeRevoke {
/// Another, weaker example, is when trying o implement something like sudo. Where we want a signature,
/// but we want to authorized signer to come from the a different part of state.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct PoeDispute;

impl SimpleConstraintChecker for PoeDispute {
Expand Down
3 changes: 2 additions & 1 deletion tuxedo-template-runtime/src/runtime_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//! it to the well-known key as a side effect.
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_runtime::transaction_validity::TransactionPriority;
Expand Down Expand Up @@ -63,7 +64,7 @@ pub enum ConstraintCheckerError {
/// writes the full wasm code to the well-known `:code` storage key. This is
/// necessary to satisfy Substrate's assumptions that this will happen.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct RuntimeUpgrade {
full_wasm: Vec<u8>,
}
Expand Down

0 comments on commit d287a37

Please sign in to comment.