Skip to content

Commit

Permalink
Use marker trait pattern to simplify component delegation (#76)
Browse files Browse the repository at this point in the history
* Use auto trait delegation using marker traits for LegacyCosmosSdkBootstrapComponents

* Use marker traits for auto component delegation

* Use new marker trait syntax in delegate_components! macro

* Use auto component delegation for relay components

* Use auto component delegation for relay components

* Use auto component delegation for builder context

* Slightly reorganize build modules

* Use auto component delegation for birelay components

* Use auto component delegation for tx components

* Use auto component delegation for chain components

* Use struct-like syntax and put components mapping inside curly brace

* Use delegate_all! macro to auto delegate components

* Use new syntax for all calls to delegate_components!

* Fix Cargo.toml patch

* Use back cgp main branch

* Update cgp version
  • Loading branch information
soareschen authored Dec 20, 2023
1 parent bb03882 commit 291b0ab
Show file tree
Hide file tree
Showing 61 changed files with 1,031 additions and 1,445 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 28 additions & 19 deletions crates/cosmos-integration-tests/src/contexts/bootstrap.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use cgp_core::prelude::*;
use cgp_core::{ErrorRaiserComponent, ErrorTypeComponent};
use cgp_core::{delegate_all, ErrorRaiserComponent, ErrorTypeComponent};
use cgp_error_eyre::HandleErrorsWithEyre;
use cosmos_test_components::bootstrap::components::closures::cosmos_sdk_legacy::CanUseLegacyCosmosSdkChainBootstrapper;
use cosmos_test_components::bootstrap::components::cosmos_sdk_legacy::LegacyCosmosSdkBootstrapComponents;
use cosmos_test_components::bootstrap::components::cosmos_sdk_legacy::{
CanUseLegacyCosmosSdkChainBootstrapper, IsLegacyCosmosSdkBootstrapComponent,
};
use cosmos_test_components::bootstrap::impls::fields::denom::DenomForStaking;
use cosmos_test_components::bootstrap::impls::fields::denom::DenomForTransfer;
use cosmos_test_components::bootstrap::impls::fields::denom::GenesisDenomGetter;
Expand Down Expand Up @@ -53,27 +55,34 @@ impl CanUseLegacyCosmosSdkChainBootstrapper for CosmosStdBootstrapContext {}
pub struct CosmosStdBootstrapComponents;

impl HasComponents for CosmosStdBootstrapContext {
type Components = LegacyCosmosSdkBootstrapComponents<CosmosStdBootstrapComponents>;
type Components = CosmosStdBootstrapComponents;
}

delegate_components!(
CosmosStdBootstrapComponents;
[
ErrorTypeComponent,
ErrorRaiserComponent,
]:
HandleErrorsWithEyre,
RuntimeTypeComponent:
ProvideTokioRuntimeType,
ChainConfigTypeComponent: ProvideCosmosChainConfigType,
GenesisConfigTypeComponent: ProvideCosmosGenesisConfigType,
WalletConfigGeneratorComponent: GenerateStandardWalletConfig,
[
WalletConfigTypeComponent,
WalletConfigFieldsComponent,
]: ProvideCosmosWalletConfigType,
delegate_all!(
IsLegacyCosmosSdkBootstrapComponent,
LegacyCosmosSdkBootstrapComponents,
CosmosStdBootstrapComponents,
);

delegate_components! {
CosmosStdBootstrapComponents {
[
ErrorTypeComponent,
ErrorRaiserComponent,
]:
HandleErrorsWithEyre,
RuntimeTypeComponent:
ProvideTokioRuntimeType,
ChainConfigTypeComponent: ProvideCosmosChainConfigType,
GenesisConfigTypeComponent: ProvideCosmosGenesisConfigType,
WalletConfigGeneratorComponent: GenerateStandardWalletConfig,
[
WalletConfigTypeComponent,
WalletConfigFieldsComponent,
]: ProvideCosmosWalletConfigType,
}
}

impl ProvideChainType<CosmosStdBootstrapContext> for CosmosStdBootstrapComponents {
type Chain = CosmosTestChain;
}
Expand Down
41 changes: 21 additions & 20 deletions crates/cosmos-integration-tests/src/contexts/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,24 @@ impl HasComponents for CosmosTestChain {
type Components = CosmosTestChainComponents;
}

delegate_components!(
CosmosTestChainComponents;
[
ChainIdTypeProviderComponent,
]:
ProvideCosmosChainTypes,
[
WalletTypeComponent,
WalletSignerComponent,
]:
ProvideCosmosTestWallet,
ChainIdFromStringBuilderComponent:
BuildCosmosChainIdFromString,
AmountTypeComponent:
ProvideU128AmountWithDenom,
DenomTypeComponent:
ProvideIbcDenom,
AddressTypeComponent:
ProvideStringAddress,
);
delegate_components! {
CosmosTestChainComponents {
[
ChainIdTypeProviderComponent,
]:
ProvideCosmosChainTypes,
[
WalletTypeComponent,
WalletSignerComponent,
]:
ProvideCosmosTestWallet,
ChainIdFromStringBuilderComponent:
BuildCosmosChainIdFromString,
AmountTypeComponent:
ProvideU128AmountWithDenom,
DenomTypeComponent:
ProvideIbcDenom,
AddressTypeComponent:
ProvideStringAddress,
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 291b0ab

Please sign in to comment.