Skip to content

Commit 6724405

Browse files
Seulgi Kimsgkim126
authored andcommitted
Add PodWorld
1 parent 007be39 commit 6724405

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

core/src/spec/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ mod genesis;
1818
mod pod_account;
1919
mod pod_shard_metadata;
2020
mod pod_state;
21+
mod pod_world;
2122
mod seal;
2223
mod spec;
2324

core/src/spec/pod_world.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2018 Kodebox, Inc.
2+
// This file is part of CodeChain.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as
6+
// published by the Free Software Foundation, either version 3 of the
7+
// License, or (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
use std::fmt;
18+
19+
use cjson;
20+
use ckey::Address;
21+
use cstate::World;
22+
use rlp::{Encodable, RlpStream};
23+
24+
#[derive(Clone, Debug, Eq, PartialEq)]
25+
pub struct PodWorld {
26+
pub nonce: u64,
27+
pub owners: Vec<Address>,
28+
}
29+
30+
impl<'a> Into<World> for &'a PodWorld {
31+
fn into(self) -> World {
32+
World::new_with_nonce(self.owners.clone(), self.nonce)
33+
}
34+
}
35+
36+
impl Encodable for PodWorld {
37+
fn rlp_append(&self, s: &mut RlpStream) {
38+
let w: World = self.into();
39+
w.rlp_append(s);
40+
}
41+
}
42+
43+
impl From<cjson::spec::World> for PodWorld {
44+
fn from(s: cjson::spec::World) -> Self {
45+
Self {
46+
nonce: s.nonce.map(Into::into).unwrap_or(0),
47+
owners: s.owners.unwrap_or_else(Vec::new),
48+
}
49+
}
50+
}
51+
52+
impl fmt::Display for PodWorld {
53+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
54+
write!(f, "(#nonce={}; owners={:#?})", self.nonce, self.owners)
55+
}
56+
}

0 commit comments

Comments
 (0)