Skip to content

Commit

Permalink
feat(custom-rpc): improve environment RPC (#4154)
Browse files Browse the repository at this point in the history
* feat(custom-rpc): improve environment RPC

* redo

* add serialization test

* update type

* fix clippy

* rename

* chore: use serde(flatten), more explicit conversion

* untagged

* unimplement deserialization

* fixes

* snapshot

* add snapshots

* fix clippy

* serialize to string

* change serialization

* delete file

* safer serialization

* safer number or hex

---------

Co-authored-by: Daniel <daniel@chainflip.io>
  • Loading branch information
acdibble and dandanlen authored Oct 26, 2023
1 parent 0afe022 commit ed0baff
Show file tree
Hide file tree
Showing 14 changed files with 424 additions and 91 deletions.
23 changes: 23 additions & 0 deletions Cargo.lock

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

18 changes: 17 additions & 1 deletion state-chain/chains/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,29 @@ impl ToHumanreadableAddress for PolkadotAccountId {
}

#[cfg(feature = "std")]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
/// A type that serializes the address in a human-readable way. This can only be
/// serialized and not deserialized.
/// `deserialize` is not implemented for ForeignChainAddressHumanreadable
/// because it is not possible to deserialize a human-readable address without
/// further context around the asset and chain.
pub enum ForeignChainAddressHumanreadable {
Eth(<EthereumAddress as ToHumanreadableAddress>::Humanreadable),
Dot(<PolkadotAccountId as ToHumanreadableAddress>::Humanreadable),
Btc(<ScriptPubkey as ToHumanreadableAddress>::Humanreadable),
}

#[cfg(feature = "std")]
impl<'de> Deserialize<'de> for ForeignChainAddressHumanreadable {
fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
unimplemented!("Deserialization of ForeignChainAddressHumanreadable is not implemented")
}
}

impl ToHumanreadableAddress for ForeignChainAddress {
#[cfg(feature = "std")]
type Humanreadable = ForeignChainAddressHumanreadable;
Expand Down
3 changes: 2 additions & 1 deletion state-chain/custom-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ sp-runtime = { git = "https://github.com/chainflip-io/substrate.git", tag = "cha
sc-client-api = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainflip-monthly-2023-08+2" }

[dev-dependencies]
serde_json = "1.0.107"
insta = { version = "1.34.0", features = ["json"] }
serde_json = "1.0"
Loading

0 comments on commit ed0baff

Please sign in to comment.