Skip to content

Commit 990df5e

Browse files
committed
Make all AccountId a String, fix #27
1 parent 27e2178 commit 990df5e

18 files changed

+99
-99
lines changed

steps/29/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Our goal over the next few steps will be to continually make our runtime more ge
66

77
The flexibility of generic runtime means that we can write code which works for multiple different configurations and types.
88

9-
For example, up until now, we have been using `&'static str` to represent the accounts of users. This is obviously not the right thing to do, but is easy to implement for a basic blockchain tutorial like this.
9+
For example, up until now, we have been using `String` to represent the accounts of users. This is obviously not the right thing to do, but is easy to implement for a basic blockchain tutorial like this.
1010

1111
What would you need to change in order to use more traditional cryptographic public keys?
1212

@@ -83,7 +83,7 @@ But now that `Pallet` is generic, we need to concretely define those types when
8383
That syntax looks like:
8484

8585
```rust
86-
let mut balances = super::Pallet::<&'static str, u128>::new();
86+
let mut balances = super::Pallet::<String, u128>::new();
8787
```
8888

8989
You will notice that now the types are defined wherever the generic `struct Pallet` is being instantiated. This means that you can extract the types out of your Pallets, and move them into the Runtime.

steps/57/src/proof_of_existence.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ mod test {
5858
}
5959

6060
impl crate::system::Config for TestConfig {
61-
type AccountId = &'static str;
61+
type AccountId = String;
6262
type BlockNumber = u32;
6363
type Nonce = u32;
6464
}

steps/58/src/proof_of_existence.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ mod test {
6161
}
6262

6363
impl crate::system::Config for TestConfig {
64-
type AccountId = &'static str;
64+
type AccountId = String;
6565
type BlockNumber = u32;
6666
type Nonce = u32;
6767
}
@@ -70,13 +70,13 @@ mod test {
7070
fn basic_proof_of_existence() {
7171
let mut poe = super::Pallet::<TestConfig>::new();
7272
assert_eq!(poe.get_claim(&"Hello, world!"), None);
73-
assert_eq!(poe.create_claim("alice", "Hello, world!"), Ok(()));
74-
assert_eq!(poe.get_claim(&"Hello, world!"), Some(&"alice"));
73+
assert_eq!(poe.create_claim("alice".to_string(), "Hello, world!"), Ok(()));
74+
assert_eq!(poe.get_claim(&"Hello, world!"), Some(&"alice".to_string()));
7575
assert_eq!(
76-
poe.create_claim("bob", "Hello, world!"),
76+
poe.create_claim("bob".to_string(), "Hello, world!"),
7777
Err("this content is already claimed")
7878
);
79-
assert_eq!(poe.revoke_claim("alice", "Hello, world!"), Ok(()));
80-
assert_eq!(poe.create_claim("bob", "Hello, world!"), Ok(()));
79+
assert_eq!(poe.revoke_claim("alice".to_string(), "Hello, world!"), Ok(()));
80+
assert_eq!(poe.create_claim("bob".to_string(), "Hello, world!"), Ok(()));
8181
}
8282
}

steps/59/src/proof_of_existence.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ mod test {
8787
}
8888

8989
impl crate::system::Config for TestConfig {
90-
type AccountId = &'static str;
90+
type AccountId = String;
9191
type BlockNumber = u32;
9292
type Nonce = u32;
9393
}
@@ -96,13 +96,13 @@ mod test {
9696
fn basic_proof_of_existence() {
9797
let mut poe = super::Pallet::<TestConfig>::new();
9898
assert_eq!(poe.get_claim(&"Hello, world!"), None);
99-
assert_eq!(poe.create_claim("alice", "Hello, world!"), Ok(()));
100-
assert_eq!(poe.get_claim(&"Hello, world!"), Some(&"alice"));
99+
assert_eq!(poe.create_claim("alice".to_string(), "Hello, world!"), Ok(()));
100+
assert_eq!(poe.get_claim(&"Hello, world!"), Some(&"alice".to_string()));
101101
assert_eq!(
102-
poe.create_claim("bob", "Hello, world!"),
102+
poe.create_claim("bob".to_string(), "Hello, world!"),
103103
Err("this content is already claimed")
104104
);
105-
assert_eq!(poe.revoke_claim("alice", "Hello, world!"), Ok(()));
106-
assert_eq!(poe.create_claim("bob", "Hello, world!"), Ok(()));
105+
assert_eq!(poe.revoke_claim("alice".to_string(), "Hello, world!"), Ok(()));
106+
assert_eq!(poe.create_claim("bob".to_string(), "Hello, world!"), Ok(()));
107107
}
108108
}

steps/60/src/proof_of_existence.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ mod test {
9292
}
9393

9494
impl crate::system::Config for TestConfig {
95-
type AccountId = &'static str;
95+
type AccountId = String;
9696
type BlockNumber = u32;
9797
type Nonce = u32;
9898
}
@@ -101,13 +101,13 @@ mod test {
101101
fn basic_proof_of_existence() {
102102
let mut poe = super::Pallet::<TestConfig>::new();
103103
assert_eq!(poe.get_claim(&"Hello, world!"), None);
104-
assert_eq!(poe.create_claim("alice", "Hello, world!"), Ok(()));
105-
assert_eq!(poe.get_claim(&"Hello, world!"), Some(&"alice"));
104+
assert_eq!(poe.create_claim("alice".to_string(), "Hello, world!"), Ok(()));
105+
assert_eq!(poe.get_claim(&"Hello, world!"), Some(&"alice".to_string()));
106106
assert_eq!(
107-
poe.create_claim("bob", "Hello, world!"),
107+
poe.create_claim("bob".to_string(), "Hello, world!"),
108108
Err("this content is already claimed")
109109
);
110-
assert_eq!(poe.revoke_claim("alice", "Hello, world!"), Ok(()));
111-
assert_eq!(poe.create_claim("bob", "Hello, world!"), Ok(()));
110+
assert_eq!(poe.revoke_claim("alice".to_string(), "Hello, world!"), Ok(()));
111+
assert_eq!(poe.create_claim("bob".to_string(), "Hello, world!"), Ok(()));
112112
}
113113
}

steps/61/src/proof_of_existence.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ mod test {
9292
}
9393

9494
impl crate::system::Config for TestConfig {
95-
type AccountId = &'static str;
95+
type AccountId = String;
9696
type BlockNumber = u32;
9797
type Nonce = u32;
9898
}
@@ -101,13 +101,13 @@ mod test {
101101
fn basic_proof_of_existence() {
102102
let mut poe = super::Pallet::<TestConfig>::new();
103103
assert_eq!(poe.get_claim(&"Hello, world!"), None);
104-
assert_eq!(poe.create_claim("alice", "Hello, world!"), Ok(()));
105-
assert_eq!(poe.get_claim(&"Hello, world!"), Some(&"alice"));
104+
assert_eq!(poe.create_claim("alice".to_string(), "Hello, world!"), Ok(()));
105+
assert_eq!(poe.get_claim(&"Hello, world!"), Some(&"alice".to_string()));
106106
assert_eq!(
107-
poe.create_claim("bob", "Hello, world!"),
107+
poe.create_claim("bob".to_string(), "Hello, world!"),
108108
Err("this content is already claimed")
109109
);
110-
assert_eq!(poe.revoke_claim("alice", "Hello, world!"), Ok(()));
111-
assert_eq!(poe.create_claim("bob", "Hello, world!"), Ok(()));
110+
assert_eq!(poe.revoke_claim("alice".to_string(), "Hello, world!"), Ok(()));
111+
assert_eq!(poe.create_claim("bob".to_string(), "Hello, world!"), Ok(()));
112112
}
113113
}

steps/62/src/proof_of_existence.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ mod test {
9292
}
9393

9494
impl crate::system::Config for TestConfig {
95-
type AccountId = &'static str;
95+
type AccountId = String;
9696
type BlockNumber = u32;
9797
type Nonce = u32;
9898
}
@@ -101,13 +101,13 @@ mod test {
101101
fn basic_proof_of_existence() {
102102
let mut poe = super::Pallet::<TestConfig>::new();
103103
assert_eq!(poe.get_claim(&"Hello, world!"), None);
104-
assert_eq!(poe.create_claim("alice", "Hello, world!"), Ok(()));
105-
assert_eq!(poe.get_claim(&"Hello, world!"), Some(&"alice"));
104+
assert_eq!(poe.create_claim("alice".to_string(), "Hello, world!"), Ok(()));
105+
assert_eq!(poe.get_claim(&"Hello, world!"), Some(&"alice".to_string()));
106106
assert_eq!(
107-
poe.create_claim("bob", "Hello, world!"),
107+
poe.create_claim("bob".to_string(), "Hello, world!"),
108108
Err("this content is already claimed")
109109
);
110-
assert_eq!(poe.revoke_claim("alice", "Hello, world!"), Ok(()));
111-
assert_eq!(poe.create_claim("bob", "Hello, world!"), Ok(()));
110+
assert_eq!(poe.revoke_claim("alice".to_string(), "Hello, world!"), Ok(()));
111+
assert_eq!(poe.create_claim("bob".to_string(), "Hello, world!"), Ok(()));
112112
}
113113
}

steps/63/src/proof_of_existence.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ mod test {
9292
}
9393

9494
impl crate::system::Config for TestConfig {
95-
type AccountId = &'static str;
95+
type AccountId = String;
9696
type BlockNumber = u32;
9797
type Nonce = u32;
9898
}
@@ -101,13 +101,13 @@ mod test {
101101
fn basic_proof_of_existence() {
102102
let mut poe = super::Pallet::<TestConfig>::new();
103103
assert_eq!(poe.get_claim(&"Hello, world!"), None);
104-
assert_eq!(poe.create_claim("alice", "Hello, world!"), Ok(()));
105-
assert_eq!(poe.get_claim(&"Hello, world!"), Some(&"alice"));
104+
assert_eq!(poe.create_claim("alice".to_string(), "Hello, world!"), Ok(()));
105+
assert_eq!(poe.get_claim(&"Hello, world!"), Some(&"alice".to_string()));
106106
assert_eq!(
107-
poe.create_claim("bob", "Hello, world!"),
107+
poe.create_claim("bob".to_string(), "Hello, world!"),
108108
Err("this content is already claimed")
109109
);
110-
assert_eq!(poe.revoke_claim("alice", "Hello, world!"), Ok(()));
111-
assert_eq!(poe.create_claim("bob", "Hello, world!"), Ok(()));
110+
assert_eq!(poe.revoke_claim("alice".to_string(), "Hello, world!"), Ok(()));
111+
assert_eq!(poe.create_claim("bob".to_string(), "Hello, world!"), Ok(()));
112112
}
113113
}

steps/64/src/proof_of_existence.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ mod test {
9292
}
9393

9494
impl crate::system::Config for TestConfig {
95-
type AccountId = &'static str;
95+
type AccountId = String;
9696
type BlockNumber = u32;
9797
type Nonce = u32;
9898
}
@@ -101,13 +101,13 @@ mod test {
101101
fn basic_proof_of_existence() {
102102
let mut poe = super::Pallet::<TestConfig>::new();
103103
assert_eq!(poe.get_claim(&"Hello, world!"), None);
104-
assert_eq!(poe.create_claim("alice", "Hello, world!"), Ok(()));
105-
assert_eq!(poe.get_claim(&"Hello, world!"), Some(&"alice"));
104+
assert_eq!(poe.create_claim("alice".to_string(), "Hello, world!"), Ok(()));
105+
assert_eq!(poe.get_claim(&"Hello, world!"), Some(&"alice".to_string()));
106106
assert_eq!(
107-
poe.create_claim("bob", "Hello, world!"),
107+
poe.create_claim("bob".to_string(), "Hello, world!"),
108108
Err("this content is already claimed")
109109
);
110-
assert_eq!(poe.revoke_claim("alice", "Hello, world!"), Ok(()));
111-
assert_eq!(poe.create_claim("bob", "Hello, world!"), Ok(()));
110+
assert_eq!(poe.revoke_claim("alice".to_string(), "Hello, world!"), Ok(()));
111+
assert_eq!(poe.create_claim("bob".to_string(), "Hello, world!"), Ok(()));
112112
}
113113
}

steps/65/src/proof_of_existence.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ mod test {
9292
}
9393

9494
impl crate::system::Config for TestConfig {
95-
type AccountId = &'static str;
95+
type AccountId = String;
9696
type BlockNumber = u32;
9797
type Nonce = u32;
9898
}
@@ -101,13 +101,13 @@ mod test {
101101
fn basic_proof_of_existence() {
102102
let mut poe = super::Pallet::<TestConfig>::new();
103103
assert_eq!(poe.get_claim(&"Hello, world!"), None);
104-
assert_eq!(poe.create_claim("alice", "Hello, world!"), Ok(()));
105-
assert_eq!(poe.get_claim(&"Hello, world!"), Some(&"alice"));
104+
assert_eq!(poe.create_claim("alice".to_string(), "Hello, world!"), Ok(()));
105+
assert_eq!(poe.get_claim(&"Hello, world!"), Some(&"alice".to_string()));
106106
assert_eq!(
107-
poe.create_claim("bob", "Hello, world!"),
107+
poe.create_claim("bob".to_string(), "Hello, world!"),
108108
Err("this content is already claimed")
109109
);
110-
assert_eq!(poe.revoke_claim("alice", "Hello, world!"), Ok(()));
111-
assert_eq!(poe.create_claim("bob", "Hello, world!"), Ok(()));
110+
assert_eq!(poe.revoke_claim("alice".to_string(), "Hello, world!"), Ok(()));
111+
assert_eq!(poe.create_claim("bob".to_string(), "Hello, world!"), Ok(()));
112112
}
113113
}

0 commit comments

Comments
 (0)