-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Re-arrange Chains traits for better composability (#3912)
Co-authored-by: dandanlen <3168260+dandanlen@users.noreply.github.com>
- Loading branch information
1 parent
d9fe415
commit ae957c6
Showing
78 changed files
with
1,659 additions
and
1,549 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 13 additions & 8 deletions
21
engine/src/state_chain_observer/sc_observer/crypto_compat.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,42 @@ | ||
use cf_chains::{dot::PolkadotPublicKey, ChainCrypto}; | ||
use cf_chains::{ | ||
btc::BitcoinCrypto, | ||
dot::{PolkadotCrypto, PolkadotPublicKey}, | ||
evm::EvmCrypto, | ||
ChainCrypto, | ||
}; | ||
use multisig::{ | ||
bitcoin::BtcSigning, eth::EthSigning, polkadot::PolkadotSigning, ChainSigning, CryptoScheme, | ||
}; | ||
use state_chain_runtime::{BitcoinInstance, EthereumInstance, PolkadotInstance}; | ||
|
||
/// Compatibility layer for converting between public keys generated using the [CryptoScheme] types | ||
/// and the on-chain representation as defined by [ChainCrypto]. | ||
pub trait CryptoCompat<S: ChainSigning<Chain = C>, C: ChainCrypto> { | ||
pub trait CryptoCompat<S: ChainSigning<ChainCrypto = C>, C: ChainCrypto> { | ||
fn pubkey_to_aggkey( | ||
pubkey: <<S as ChainSigning>::CryptoScheme as CryptoScheme>::PublicKey, | ||
) -> C::AggKey; | ||
} | ||
|
||
impl CryptoCompat<EthSigning, cf_chains::Ethereum> for EthereumInstance { | ||
impl CryptoCompat<EthSigning, EvmCrypto> for EthereumInstance { | ||
fn pubkey_to_aggkey( | ||
pubkey: <<EthSigning as ChainSigning>::CryptoScheme as CryptoScheme>::PublicKey, | ||
) -> <cf_chains::Ethereum as ChainCrypto>::AggKey { | ||
) -> <EvmCrypto as ChainCrypto>::AggKey { | ||
pubkey | ||
} | ||
} | ||
|
||
impl CryptoCompat<BtcSigning, cf_chains::Bitcoin> for BitcoinInstance { | ||
impl CryptoCompat<BtcSigning, BitcoinCrypto> for BitcoinInstance { | ||
fn pubkey_to_aggkey( | ||
pubkey: <<BtcSigning as ChainSigning>::CryptoScheme as CryptoScheme>::PublicKey, | ||
) -> <cf_chains::Bitcoin as ChainCrypto>::AggKey { | ||
) -> <BitcoinCrypto as ChainCrypto>::AggKey { | ||
cf_chains::btc::AggKey { previous: None, current: pubkey.serialize() } | ||
} | ||
} | ||
|
||
impl CryptoCompat<PolkadotSigning, cf_chains::Polkadot> for PolkadotInstance { | ||
impl CryptoCompat<PolkadotSigning, PolkadotCrypto> for PolkadotInstance { | ||
fn pubkey_to_aggkey( | ||
pubkey: <<PolkadotSigning as ChainSigning>::CryptoScheme as CryptoScheme>::PublicKey, | ||
) -> <cf_chains::Polkadot as ChainCrypto>::AggKey { | ||
) -> <PolkadotCrypto as ChainCrypto>::AggKey { | ||
PolkadotPublicKey::from_aliased(pubkey.to_bytes()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.