|
| 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