Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a6bc432

Browse files
ntn-x2wischli
authored andcommittedAug 30, 2022
chore: fix serde bounds (#390)
* reduce bounds for serialization and deserialization * update dependencies
1 parent 2dacea0 commit a6bc432

File tree

17 files changed

+48
-56
lines changed

17 files changed

+48
-56
lines changed
 

‎Cargo.lock

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎nodes/parachain/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ hex-literal = "0.3.4"
3232
jsonrpsee = {version = "0.14.0", features = ["server"]}
3333
log = "0.4.17"
3434
parking_lot = "0.12.1"
35-
serde = {version = "1.0.137", features = ["derive"]}
36-
serde_json = "1.0.79"
35+
serde = {version = "1.0.140", features = ["derive"]}
36+
serde_json = "1.0.82"
3737

3838
# Substrate dependencies
3939
frame-rpc-system = {package = "substrate-frame-rpc-system", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26"}

‎nodes/standalone/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ runtime-common = {path = "../../runtimes/common"}
2323
clap = {version = "3.2.10", features = ["derive"]}
2424
futures = "0.3.21"
2525
log = "0.4.17"
26-
serde = {version = "1.0.137", features = ["derive"]}
27-
serde_json = "1.0.79"
26+
serde = {version = "1.0.140", features = ["derive"]}
27+
serde_json = "1.0.82"
2828

2929
# Substrate dependencies
3030
frame-system = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26"}

‎pallets/attestation/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ctype = {features = ["mock"], path = "../ctype"}
1717
kilt-support = {features = ["mock"], path = "../../support"}
1818

1919
pallet-balances = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/substrate"}
20-
serde = "1.0.137"
20+
serde = "1.0.140"
2121
sp-core = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/substrate"}
2222
sp-io = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/substrate"}
2323
sp-keystore = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/substrate"}
@@ -26,7 +26,7 @@ sp-keystore = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech
2626
codec = {package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"]}
2727
log = "0.4.17"
2828
scale-info = {version = "2.1.1", default-features = false, features = ["derive"]}
29-
serde = {version = "1.0.137", optional = true}
29+
serde = {version = "1.0.140", optional = true}
3030

3131
# Internal dependencies
3232
ctype = {default-features = false, path = "../ctype"}

‎pallets/ctype/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ substrate-wasm-builder = {git = "https://github.com/paritytech/substrate", branc
1515
[dev-dependencies]
1616
kilt-support = {features = ["mock"], path = "../../support"}
1717
pallet-balances = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/substrate"}
18-
serde = "1.0.137"
18+
serde = "1.0.140"
1919
sp-core = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/substrate"}
2020
sp-keystore = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/substrate"}
2121

2222
[dependencies]
2323
codec = {package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"]}
2424
log = "0.4.17"
2525
scale-info = {version = "2.1.1", default-features = false, features = ["derive"]}
26-
serde = {version = "1.0.137", optional = true}
26+
serde = {version = "1.0.140", optional = true}
2727

2828
# Internal dependencies
2929
kilt-support = {default-features = false, path = "../../support"}

‎pallets/delegation/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ kilt-support = {features = ["mock"], path = "../../support"}
1919

2020
# External dependencies
2121
env_logger = "0.9.0"
22-
serde = "1.0.137"
22+
serde = "1.0.140"
2323

2424
# Substrate dependencies
2525
pallet-balances = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/substrate"}
@@ -37,7 +37,7 @@ bitflags = {default-features = false, version = "1.3.2"}
3737
codec = {package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"]}
3838
log = "0.4.17"
3939
scale-info = {version = "2.1.1", default-features = false, features = ["derive"]}
40-
serde = {version = "1.0.137", optional = true}
40+
serde = {version = "1.0.140", optional = true}
4141

4242
# Substrate dependencies
4343
frame-benchmarking = {branch = "polkadot-v0.9.26", default-features = false, git = "https://github.com/paritytech/substrate", optional = true}

‎pallets/did/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ substrate-wasm-builder = {git = "https://github.com/paritytech/substrate", branc
1414

1515
[dev-dependencies]
1616
env_logger = "0.9.0"
17-
serde = "1.0.137"
17+
serde = "1.0.140"
1818

1919
ctype = {features = ["mock"], path = "../ctype"}
2020

‎pallets/pallet-inflation/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ version = "1.7.1"
1010
targets = ["x86_64-unknown-linux-gnu"]
1111

1212
[dev-dependencies]
13-
serde = "1.0.137"
13+
serde = "1.0.140"
1414

1515
pallet-balances = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/substrate"}
1616
sp-core = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/substrate"}
@@ -19,7 +19,7 @@ sp-io = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/subst
1919
[dependencies]
2020
codec = {package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"]}
2121
scale-info = {version = "2.1.1", default-features = false, features = ["derive"]}
22-
serde = {version = "1.0.137", optional = true}
22+
serde = {version = "1.0.140", optional = true}
2323

2424
# benchmarking
2525
frame-benchmarking = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false, optional = true}

‎pallets/parachain-staking/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ sp-io = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.
1616
log = "0.4.17"
1717
parity-scale-codec = {version = "3.1.5", default-features = false, features = ["derive"]}
1818
scale-info = {version = "2.1.1", default-features = false, features = ["derive"]}
19-
serde = {version = "1.0.137", optional = true}
19+
serde = {version = "1.0.140", optional = true}
2020

2121
frame-support = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false}
2222
frame-system = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false}

‎rpc/did/runtime-api/src/did_details.rs

+7-15
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,20 @@ use kilt_support::deposit::Deposit;
2828

2929
#[derive(Encode, Decode, TypeInfo, Clone, Debug, PartialEq)]
3030
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
31-
#[cfg_attr(
32-
feature = "std",
33-
serde(bound(
34-
serialize = "
35-
Balance: std::fmt::Display,
36-
AccountId: Serialize,
37-
Key: Serialize,
38-
BlockNumber: Serialize",
39-
deserialize = "
40-
Balance: std::str::FromStr,
41-
AccountId: Deserialize<'de>,
42-
Key: Deserialize<'de>,
43-
BlockNumber: Deserialize<'de>"
44-
))
45-
)]
4631
pub struct DidDetails<Key: Ord, BlockNumber: MaxEncodedLen, AccountId, Balance> {
4732
pub authentication_key: Key,
4833
pub key_agreement_keys: BTreeSet<Key>,
4934
pub delegation_key: Option<Key>,
5035
pub attestation_key: Option<Key>,
5136
pub public_keys: BTreeMap<Key, DidPublicKeyDetails<BlockNumber>>,
5237
pub last_tx_counter: u64,
38+
#[cfg_attr(
39+
feature = "std",
40+
serde(bound(
41+
serialize = "Deposit<AccountId, Balance>: Serialize",
42+
deserialize = "Deposit<AccountId, Balance>: Deserialize<'de>"
43+
))
44+
)]
5345
pub deposit: Deposit<AccountId, Balance>,
5446
}
5547

‎rpc/did/runtime-api/src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ pub struct DidLinkedInfo<
7272
pub accounts: Vec<AccountId>,
7373
pub w3n: Option<Web3Name>,
7474
pub service_endpoints: Vec<ServiceEndpoint<Id, Type, Url>>,
75+
#[cfg_attr(
76+
feature = "std",
77+
serde(bound(
78+
serialize = "DidDetails<Key, BlockNumber, AccountId, Balance>: Serialize",
79+
deserialize = "DidDetails<Key, BlockNumber, AccountId, Balance>: Deserialize<'de>"
80+
))
81+
)]
7582
pub details: DidDetails<Key, BlockNumber, AccountId, Balance>,
7683
}
7784

‎runtimes/common/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ sp-io = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.
1111
codec = {package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"]}
1212
log = "0.4.17"
1313
scale-info = {version = "2.1.1", default-features = false, features = ["derive"]}
14-
serde = {version = "1.0.137", optional = true, features = ["derive"]}
14+
serde = {version = "1.0.140", optional = true, features = ["derive"]}
1515
smallvec = "1.8.0"
1616

1717
attestation = {default-features = false, path = "../../pallets/attestation"}

‎runtimes/peregrine/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ smallvec = "1.8.0"
1515
static_assertions = "1.1.0"
1616

1717
hex-literal = {version = "0.3.4", optional = true}
18-
serde = {version = "1.0.137", optional = true, features = ["derive"]}
18+
serde = {version = "1.0.140", optional = true, features = ["derive"]}
1919

2020
# RPC
2121
did-rpc-runtime-api = {path = "../../rpc/did/runtime-api", default-features = false}

‎runtimes/spiritnet/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ smallvec = "1.8.0"
1515
static_assertions = "1.1.0"
1616

1717
hex-literal = {version = "0.3.4", optional = true}
18-
serde = {version = "1.0.137", optional = true, features = ["derive"]}
18+
serde = {version = "1.0.140", optional = true, features = ["derive"]}
1919

2020
# RPC
2121
did-rpc-runtime-api = {path = "../../rpc/did/runtime-api", default-features = false}

‎runtimes/standalone/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ log = "0.4.17"
1414
scale-info = {version = "2.1.1", default-features = false, features = ["derive"]}
1515

1616
hex-literal = {version = "0.3.4", optional = true}
17-
serde = {version = "1.0.137", optional = true, features = ["derive"]}
17+
serde = {version = "1.0.140", optional = true, features = ["derive"]}
1818

1919
# kilt functionality
2020
attestation = {default-features = false, path = "../../pallets/attestation"}

‎support/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ sp-runtime = {branch = "polkadot-v0.9.26", default-features = false, git = "http
1818
sp-std = {branch = "polkadot-v0.9.26", default-features = false, git = "https://github.com/paritytech/substrate"}
1919

2020
[dev-dependencies]
21-
serde_json = "1.0.79"
21+
serde_json = "1.0.82"
2222

2323
[package.metadata.docs.rs]
2424
targets = ["x86_64-unknown-linux-gnu"]

‎support/src/deposit.rs

+9-16
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,18 @@ use serde::{Deserialize, Serialize};
2424
/// An amount of balance reserved by the specified address.
2525
#[derive(Clone, Debug, Encode, Decode, PartialEq, TypeInfo, MaxEncodedLen)]
2626
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
27-
#[cfg_attr(
28-
feature = "std",
29-
serde(bound(
30-
serialize = "
31-
Balance: std::fmt::Display,
32-
Account: Serialize",
33-
deserialize = "
34-
Balance: std::str::FromStr,
35-
Account: Deserialize<'de>"
36-
))
37-
)]
3827
pub struct Deposit<Account, Balance> {
3928
pub owner: Account,
29+
#[cfg_attr(
30+
feature = "std",
31+
serde(bound(serialize = "Balance: std::fmt::Display", deserialize = "Balance: std::str::FromStr"))
32+
)]
4033
#[cfg_attr(feature = "std", serde(with = "serde_balance"))]
4134
pub amount: Balance,
4235
}
4336

4437
// This code was copied from https://github.com/paritytech/substrate/blob/ded44948e2d5a398abcb4e342b0513cb690961bb/frame/transaction-payment/src/types.rs#L113
45-
// It is needed because u128 cannot be serialized by serde out of the box.
38+
// It is needed because u128 cannot be serialized by serde_json out of the box.
4639
#[cfg(feature = "std")]
4740
mod serde_balance {
4841
use serde::{Deserialize, Deserializer, Serializer};
@@ -66,10 +59,10 @@ mod tests {
6659
fn should_serialize_and_deserialize_properly_with_string() {
6760
let deposit = Deposit {
6861
owner: 0_u8,
69-
amount: 1_000_000_u128,
62+
amount: 0_u128,
7063
};
7164

72-
let json_str = r#"{"owner":0,"amount":"1000000"}"#;
65+
let json_str = r#"{"owner":0,"amount":"0"}"#;
7366

7467
assert_eq!(serde_json::to_string(&deposit).unwrap(), json_str);
7568
assert_eq!(serde_json::from_str::<Deposit<u8, u128>>(json_str).unwrap(), deposit);
@@ -82,10 +75,10 @@ mod tests {
8275
fn should_serialize_and_deserialize_properly_large_value() {
8376
let deposit = Deposit {
8477
owner: 0_u8,
85-
amount: 1_000_000_u128,
78+
amount: u128::MAX,
8679
};
8780

88-
let json_str = r#"{"owner":0,"amount":"1000000"}"#;
81+
let json_str = r#"{"owner":0,"amount":"340282366920938463463374607431768211455"}"#;
8982

9083
assert_eq!(serde_json::to_string(&deposit).unwrap(), json_str);
9184
assert_eq!(serde_json::from_str::<Deposit<u8, u128>>(json_str).unwrap(), deposit);

0 commit comments

Comments
 (0)
Please sign in to comment.