Skip to content

Commit

Permalink
fix(extriniscs): avoid code duplication
Browse files Browse the repository at this point in the history
This commit reuses Missing and state for all commands instead of declaring them in every file

Signed-off-by: Tarek <[email protected]>
  • Loading branch information
tareknaser committed Jul 12, 2023
1 parent c4c161c commit 5aba9ba
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 52 deletions.
16 changes: 2 additions & 14 deletions crates/extrinsics/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use super::{
events::DisplayEvents,
prompt_confirm_tx,
runtime_api::api,
state,
state_call,
submit_extrinsic,
AccountId32,
Expand All @@ -31,6 +32,7 @@ use super::{
DefaultConfig,
ErrorVariant,
ExtrinsicOpts,
Missing,
PairSigner,
StorageDeposit,
TokenMetadata,
Expand Down Expand Up @@ -89,20 +91,6 @@ pub struct CallCommand {
output_json: bool,
}

/// Type state for `CallCommandBuilder` to tell that some mandatory state has not
/// yet been set yet or to fail upon setting the same state multiple times.
pub struct Missing<S>(PhantomData<fn() -> S>);

mod state {
//! Type states that tell what state of the Upload Command has not
//! yet been set properly for a valid construction.

/// Type state for the name of the contract message to call.
pub struct Message;
/// Type state for extrinsic options.
pub struct ExtrinsicOptions;
}

/// A builder for the call command.
pub struct CallCommandBuilder<Message, ExtrinsicOptions> {
opts: CallCommand,
Expand Down
14 changes: 2 additions & 12 deletions crates/extrinsics/src/instantiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use super::{
events::DisplayEvents,
prompt_confirm_tx,
runtime_api::api,
state,
state_call,
submit_extrinsic,
Balance,
Expand All @@ -31,6 +32,7 @@ use super::{
DefaultConfig,
ErrorVariant,
ExtrinsicOpts,
Missing,
PairSigner,
StorageDeposit,
TokenMetadata,
Expand Down Expand Up @@ -92,18 +94,6 @@ pub struct InstantiateCommand {
output_json: bool,
}

/// Type state for `InstantiateCommandBuilder` to tell that some mandatory state has not
/// yet been set yet or to fail upon setting the same state multiple times.
pub struct Missing<S>(PhantomData<fn() -> S>);

mod state {
//! Type states that tell what state of the Upload Command has not
//! yet been set properly for a valid construction.

/// Type state for extrinsic options.
pub struct ExtrinsicOptions;
}

/// A builder for the instantiate command.
pub struct InstantiateCommandBuilder<ExtrinsicOptions> {
opts: InstantiateCommand,
Expand Down
8 changes: 6 additions & 2 deletions crates/extrinsics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,20 @@ pub struct ExtrinsicOpts {
skip_confirm: bool,
}

/// Type state for `ExtrinsicOptsBuilder` to tell that some mandatory state has not yet
/// Type state for the extrinsics' commands to tell that some mandatory state has not yet
/// been set yet or to fail upon setting the same state multiple times.
pub struct Missing<S>(PhantomData<fn() -> S>);

mod state {
//! Type states that tell what state of the Extrinsics Options has not
//! Type states that tell what state of the commands has not
//! yet been set properly for a valid construction.

/// Type state for the Secret key URI.
pub struct Suri;
/// Type state for extrinsic options.
pub struct ExtrinsicOptions;
/// Type state for the name of the contract message to call.
pub struct Message;
}

/// A builder for extrinsic options.
Expand Down
14 changes: 2 additions & 12 deletions crates/extrinsics/src/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ use super::{
self,
contracts::events::CodeRemoved,
},
state,
submit_extrinsic,
Client,
CodeHash,
ContractMessageTranscoder,
DefaultConfig,
ErrorVariant,
ExtrinsicOpts,
Missing,
PairSigner,
TokenMetadata,
};
Expand All @@ -53,18 +55,6 @@ pub struct RemoveCommand {
output_json: bool,
}

/// Type state for `RemoveCommandBuilder` to tell that some mandatory state has not
/// yet been set yet or to fail upon setting the same state multiple times.
pub struct Missing<S>(PhantomData<fn() -> S>);

mod state {
//! Type states that tell what state of the Upload Command has not
//! yet been set properly for a valid construction.

/// Type state for extrinsic options.
pub struct ExtrinsicOptions;
}

/// A builder for the remove command.
pub struct RemoveCommandBuilder<ExtrinsicOptions> {
opts: RemoveCommand,
Expand Down
14 changes: 2 additions & 12 deletions crates/extrinsics/src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use super::{
self,
runtime_types::pallet_contracts::wasm::Determinism,
},
state,
state_call,
submit_extrinsic,
Balance,
Expand All @@ -30,6 +31,7 @@ use super::{
DefaultConfig,
ErrorVariant,
ExtrinsicOpts,
Missing,
PairSigner,
TokenMetadata,
WasmCode,
Expand All @@ -54,18 +56,6 @@ pub struct UploadCommand {
output_json: bool,
}

/// Type state for `UploadCommandBuilder` to tell that some mandatory state has not yet
/// been set yet or to fail upon setting the same state multiple times.
pub struct Missing<S>(PhantomData<fn() -> S>);

mod state {
//! Type states that tell what state of the Upload Command has not
//! yet been set properly for a valid construction.

/// Type state for extrinsic options.
pub struct ExtrinsicOptions;
}

/// A builder for the upload command.
pub struct UploadCommandBuilder<ExtrinsicOptions> {
opts: UploadCommand,
Expand Down

0 comments on commit 5aba9ba

Please sign in to comment.