Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace NumberOrHex #4163

Merged
merged 25 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.

2 changes: 1 addition & 1 deletion api/bin/chainflip-broker-api/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use cf_utilities::{
rpc::NumberOrHex,
task_scope::{task_scope, Scope},
AnyhowRpcError,
};
Expand All @@ -12,7 +13,6 @@ use clap::Parser;
use futures::FutureExt;
use jsonrpsee::{core::async_trait, proc_macros::rpc, server::ServerBuilder};
use serde::{Deserialize, Serialize};
use sp_rpc::number::NumberOrHex;
use std::path::PathBuf;
use tracing::log;

Expand Down
4 changes: 2 additions & 2 deletions api/bin/chainflip-lp-api/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use cf_utilities::{
rpc::NumberOrHex,
task_scope::{task_scope, Scope},
try_parse_number_or_hex, AnyhowRpcError,
};
Expand All @@ -17,18 +18,17 @@ use futures::FutureExt;
use jsonrpsee::{core::async_trait, proc_macros::rpc, server::ServerBuilder};
use pallet_cf_pools::{IncreaseOrDecrease, OrderId, RangeOrderSize};
use rpc_types::{OpenSwapChannels, OrderIdJson, RangeOrderSizeJson};
use sp_rpc::number::NumberOrHex;
use std::{collections::BTreeMap, ops::Range, path::PathBuf};
use tracing::log;

/// Contains RPC interface types that differ from internal types.
pub mod rpc_types {
use super::*;
use anyhow::anyhow;
use cf_utilities::rpc::NumberOrHex;
use chainflip_api::queries::SwapChannelInfo;
use pallet_cf_pools::AssetsMap;
use serde::{Deserialize, Serialize};
use sp_rpc::number::NumberOrHex;

#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
pub struct OrderIdJson(NumberOrHex);
Expand Down
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"