difftreelog
fix serde rpc
in: master
3 files changed
client/rpc/src/lib.rsdiffbeforeafterboth63 account: CrossAccountId,63 account: CrossAccountId,64 token: TokenId,64 token: TokenId,65 at: Option<BlockHash>,65 at: Option<BlockHash>,66 ) -> Result<u128>;66 ) -> Result<String>;67 #[rpc(name = "nft_allowance")]67 #[rpc(name = "nft_allowance")]68 fn allowance(68 fn allowance(69 &self,69 &self,72 spender: CrossAccountId,72 spender: CrossAccountId,73 token: TokenId,73 token: TokenId,74 at: Option<BlockHash>,74 at: Option<BlockHash>,75 ) -> Result<u128>;75 ) -> Result<String>;767677 #[rpc(name = "nft_adminlist")]77 #[rpc(name = "nft_adminlist")]78 fn adminlist(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<Vec<AccountId>>;78 fn adminlist(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<Vec<AccountId>>;109}109}110110111macro_rules! pass_method {111macro_rules! pass_method {112 ($method_name:ident($($name:ident: $ty:ty),* $(,)?) -> $result:ty) => {112 ($method_name:ident($($name:ident: $ty:ty),* $(,)?) -> $result:ty $(=> $mapper:expr)?) => {113 fn $method_name(113 fn $method_name(114 &self,114 &self,115 $(115 $(124 code: ErrorCode::ServerError(Error::RuntimeError.into()),124 code: ErrorCode::ServerError(Error::RuntimeError.into()),125 message: "Unable to query".into(),125 message: "Unable to query".into(),126 data: Some(format!("{:?}", e).into()),126 data: Some(format!("{:?}", e).into()),127 })127 }) $(128 .map($mapper)129 )?128 }130 }129 };131 };130}132}145 pass_method!(variable_metadata(collection: CollectionId, token: TokenId) -> Vec<u8>);147 pass_method!(variable_metadata(collection: CollectionId, token: TokenId) -> Vec<u8>);146 pass_method!(collection_tokens(collection: CollectionId) -> u32);148 pass_method!(collection_tokens(collection: CollectionId) -> u32);147 pass_method!(account_balance(collection: CollectionId, account: CrossAccountId) -> u32);149 pass_method!(account_balance(collection: CollectionId, account: CrossAccountId) -> u32);148 pass_method!(balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> u128);150 pass_method!(balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> String => |v| v.to_string());149 pass_method!(allowance(collection: CollectionId, sender: CrossAccountId, spender: CrossAccountId, token: TokenId) -> u128);151 pass_method!(allowance(collection: CollectionId, sender: CrossAccountId, spender: CrossAccountId, token: TokenId) -> String => |v| v.to_string());150152151 pass_method!(adminlist(collection: CollectionId) -> Vec<AccountId>);153 pass_method!(adminlist(collection: CollectionId) -> Vec<AccountId>);152 pass_method!(allowlist(collection: CollectionId) -> Vec<AccountId>);154 pass_method!(allowlist(collection: CollectionId) -> Vec<AccountId>);pallets/common/Cargo.tomldiffbeforeafterboth212122pallet-evm = { default-features = false, version = "6.0.0-dev", git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.10" }22pallet-evm = { default-features = false, version = "6.0.0-dev", git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.10" }23serde = { version = "1.0.130", default-features = false }23serde = { version = "1.0.130", default-features = false }24scale-info = { version = "1.0.0", default-features = false, features = [25 "derive",26] }242725[features]28[features]26default = ["std"]29default = ["std"]pallets/common/src/account.rsdiffbeforeafterboth20 fn from_eth(account: H160) -> Self;20 fn from_eth(account: H160) -> Self;21}21}2223#[derive(Encode, Decode, Serialize, Deserialize)]24#[serde(rename_all = "camelCase")]25enum BasicCrossAccountIdRepr<AccountId> {26 Substrate(AccountId),27 Ethereum(H160),28}222923#[derive(Eq, Serialize, Deserialize)]30#[derive(Eq)]24pub struct BasicCrossAccountId<T: Config> {31pub struct BasicCrossAccountId<T: Config> {25 /// If true - then ethereum is canonical encoding32 /// If true - then ethereum is canonical encoding26 from_ethereum: bool,33 from_ethereum: bool,84}91}85impl<T: Config> Encode for BasicCrossAccountId<T> {92impl<T: Config> Encode for BasicCrossAccountId<T> {86 fn encode(&self) -> Vec<u8> {93 fn encode(&self) -> Vec<u8> {87 let as_result = if !self.from_ethereum {88 Ok(self.substrate.clone())94 BasicCrossAccountIdRepr::from(self.clone()).encode()89 } else {90 Err(self.ethereum)91 };92 as_result.encode()93 }95 }94}96}95impl<T: Config> EncodeLike for BasicCrossAccountId<T> {}97impl<T: Config> EncodeLike for BasicCrossAccountId<T> {}98 where100 where99 I: codec::Input,101 I: codec::Input,100 {102 {101 Ok(match <Result<T::AccountId, H160>>::decode(input)? {103 Ok(BasicCrossAccountIdRepr::decode(input)?.into())102 Ok(s) => Self::from_sub(s),103 Err(e) => Self::from_eth(e),104 })105 }104 }106}105}106impl<T> Serialize for BasicCrossAccountId<T>107where108 T: Config,109 T::AccountId: Serialize,110{111 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>112 where113 S: serde::Serializer,114 {115 let repr = BasicCrossAccountIdRepr::from(self.clone());116 (&repr).serialize(serializer)117 }118}119impl<'de, T> Deserialize<'de> for BasicCrossAccountId<T>120where121 T: Config,122 T::AccountId: Deserialize<'de>,123{124 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>125 where126 D: serde::Deserializer<'de>,127 {128 Ok(BasicCrossAccountIdRepr::deserialize(deserializer)?.into())129 }130}107impl<T: Config> CrossAccountId<T::AccountId> for BasicCrossAccountId<T> {131impl<T: Config> CrossAccountId<T::AccountId> for BasicCrossAccountId<T> {108 fn as_sub(&self) -> &T::AccountId {132 fn as_sub(&self) -> &T::AccountId {109 &self.substrate133 &self.substrate126 }150 }127 }151 }128}152}153impl<T: Config> From<BasicCrossAccountIdRepr<T::AccountId>> for BasicCrossAccountId<T> {154 fn from(repr: BasicCrossAccountIdRepr<T::AccountId>) -> Self {155 match repr {156 BasicCrossAccountIdRepr::Substrate(s) => Self::from_sub(s),157 BasicCrossAccountIdRepr::Ethereum(e) => Self::from_eth(e),158 }159 }160}161impl<T: Config> From<BasicCrossAccountId<T>> for BasicCrossAccountIdRepr<T::AccountId> {162 fn from(v: BasicCrossAccountId<T>) -> Self {163 if v.from_ethereum {164 BasicCrossAccountIdRepr::Ethereum(*v.as_eth())165 } else {166 BasicCrossAccountIdRepr::Substrate(v.as_sub().clone())167 }168 }169}129170130pub trait EvmBackwardsAddressMapping<AccountId> {171pub trait EvmBackwardsAddressMapping<AccountId> {131 fn from_account_id(account_id: AccountId) -> H160;172 fn from_account_id(account_id: AccountId) -> H160;