2020-09-22 14:53:52 +02:00
|
|
|
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
|
|
|
|
// This file is part of OpenEthereum.
|
2018-06-04 10:19:50 +02:00
|
|
|
|
2020-09-22 14:53:52 +02:00
|
|
|
// OpenEthereum is free software: you can redistribute it and/or modify
|
2018-06-04 10:19:50 +02:00
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
2020-09-22 14:53:52 +02:00
|
|
|
// OpenEthereum is distributed in the hope that it will be useful,
|
2018-06-04 10:19:50 +02:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
2020-09-22 14:53:52 +02:00
|
|
|
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
2018-06-04 10:19:50 +02:00
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
use super::{Bytes, H160};
|
2016-06-21 14:42:27 +02:00
|
|
|
use serde_json;
|
2020-08-05 06:08:03 +02:00
|
|
|
use std::io::Read;
|
2016-08-02 14:57:57 +02:00
|
|
|
|
2016-09-28 15:47:52 +02:00
|
|
|
pub type Encseed = Bytes;
|
2016-06-21 14:42:27 +02:00
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Deserialize)]
|
|
|
|
pub struct PresaleWallet {
|
2020-08-05 06:08:03 +02:00
|
|
|
pub encseed: Encseed,
|
|
|
|
#[serde(rename = "ethaddr")]
|
|
|
|
pub address: H160,
|
2016-06-21 14:42:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl PresaleWallet {
|
2020-08-05 06:08:03 +02:00
|
|
|
pub fn load<R>(reader: R) -> Result<Self, serde_json::Error>
|
|
|
|
where
|
|
|
|
R: Read,
|
|
|
|
{
|
|
|
|
serde_json::from_reader(reader)
|
|
|
|
}
|
2016-06-21 14:42:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2020-08-05 06:08:03 +02:00
|
|
|
use json::{PresaleWallet, H160};
|
|
|
|
use serde_json;
|
|
|
|
use std::str::FromStr;
|
2016-06-21 14:42:27 +02:00
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
#[test]
|
|
|
|
fn presale_wallet() {
|
|
|
|
let json = r#"
|
2016-06-21 14:42:27 +02:00
|
|
|
{
|
|
|
|
"encseed": "137103c28caeebbcea5d7f95edb97a289ded151b72159137cb7b2671f394f54cff8c121589dcb373e267225547b3c71cbdb54f6e48ec85cd549f96cf0dedb3bc0a9ac6c79b9c426c5878ca2c9d06ff42a23cb648312fc32ba83649de0928e066",
|
|
|
|
"ethaddr": "ede84640d1a1d3e06902048e67aa7db8d52c2ce1",
|
|
|
|
"email": "123@gmail.com",
|
|
|
|
"btcaddr": "1JvqEc6WLhg6GnyrLBe2ztPAU28KRfuseH"
|
|
|
|
} "#;
|
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
let expected = PresaleWallet {
|
2016-09-28 15:47:52 +02:00
|
|
|
encseed: "137103c28caeebbcea5d7f95edb97a289ded151b72159137cb7b2671f394f54cff8c121589dcb373e267225547b3c71cbdb54f6e48ec85cd549f96cf0dedb3bc0a9ac6c79b9c426c5878ca2c9d06ff42a23cb648312fc32ba83649de0928e066".into(),
|
2016-08-02 14:57:57 +02:00
|
|
|
address: H160::from_str("ede84640d1a1d3e06902048e67aa7db8d52c2ce1").unwrap(),
|
|
|
|
};
|
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
let wallet: PresaleWallet = serde_json::from_str(json).unwrap();
|
|
|
|
assert_eq!(expected, wallet);
|
|
|
|
}
|
2016-08-02 14:57:57 +02:00
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
#[test]
|
|
|
|
fn long_presale_wallet() {
|
|
|
|
let json = r#"
|
2016-08-02 14:57:57 +02:00
|
|
|
{
|
|
|
|
"encseed":
|
|
|
|
"137103c28caeebbcea5d7f95edb97a289ded151b72159137cb7b2671f394f54cff8c121589dcb373e267225547b3c71cbdb54f6e48ec85cd549f96cf0dedb3bc0a9ac6c79b9c426c5878ca2c9d06ff42a23cb648312fc32ba83649de0928e066137103c28caeebbcea5d7f95edb97a289ded151b72159137cb7b2671f394f54cff8c121589dcb373e267225547b3c71cbdb54f6e48ec85cd549f96cf0dedb3bc0a9ac6c79b9c426c5878ca2c9d06ff42a23cb648312fc32ba83649de0928e066137103c28caeebbcea5d7f95edb97a289ded151b72159137cb7b2671f394f54cff8c121589dcb373e267225547b3c71cbdb54f6e48ec85cd549f96cf0dedb3bc0a9ac6c79b9c426c5878ca2c9d06ff42a23cb648312fc32ba83649de0928e066137103c28caeebbcea5d7f95edb97a289ded151b72159137cb7b2671f394f54cff8c121589dcb373e267225547b3c71cbdb54f6e48ec85cd549f96cf0dedb3bc0a9ac6c79b9c426c5878ca2c9d06ff42a23cb648312fc32ba83649de0928e066137103c28caeebbcea5d7f95edb97a289ded151b72159137cb7b2671f394f54cff8c121589dcb373e267225547b3c71cbdb54f6e48ec85cd549f96cf0dedb3bc0a9ac6c79b9c426c5878ca2c9d06ff42a23cb648312fc32ba83649de0928e066137103c28caeebbcea5d7f95edb97a289ded151b72159137cb7b2671f394f54cff8c121589dcb373e267225547b3c71cbdb54f6e48ec85cd549f96cf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0d",
|
|
|
|
"ethaddr": "ede84640d1a1d3e06902048e67aa7db8d52c2ce1",
|
|
|
|
"email": "123@gmail.com",
|
|
|
|
"btcaddr": "1JvqEc6WLhg6GnyrLBe2ztPAU28KRfuseH"
|
|
|
|
} "#;
|
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
let expected = PresaleWallet {
|
2016-09-28 15:47:52 +02:00
|
|
|
encseed: "137103c28caeebbcea5d7f95edb97a289ded151b72159137cb7b2671f394f54cff8c121589dcb373e267225547b3c71cbdb54f6e48ec85cd549f96cf0dedb3bc0a9ac6c79b9c426c5878ca2c9d06ff42a23cb648312fc32ba83649de0928e066137103c28caeebbcea5d7f95edb97a289ded151b72159137cb7b2671f394f54cff8c121589dcb373e267225547b3c71cbdb54f6e48ec85cd549f96cf0dedb3bc0a9ac6c79b9c426c5878ca2c9d06ff42a23cb648312fc32ba83649de0928e066137103c28caeebbcea5d7f95edb97a289ded151b72159137cb7b2671f394f54cff8c121589dcb373e267225547b3c71cbdb54f6e48ec85cd549f96cf0dedb3bc0a9ac6c79b9c426c5878ca2c9d06ff42a23cb648312fc32ba83649de0928e066137103c28caeebbcea5d7f95edb97a289ded151b72159137cb7b2671f394f54cff8c121589dcb373e267225547b3c71cbdb54f6e48ec85cd549f96cf0dedb3bc0a9ac6c79b9c426c5878ca2c9d06ff42a23cb648312fc32ba83649de0928e066137103c28caeebbcea5d7f95edb97a289ded151b72159137cb7b2671f394f54cff8c121589dcb373e267225547b3c71cbdb54f6e48ec85cd549f96cf0dedb3bc0a9ac6c79b9c426c5878ca2c9d06ff42a23cb648312fc32ba83649de0928e066137103c28caeebbcea5d7f95edb97a289ded151b72159137cb7b2671f394f54cff8c121589dcb373e267225547b3c71cbdb54f6e48ec85cd549f96cf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0dcf0d".into(),
|
2016-06-21 14:42:27 +02:00
|
|
|
address: H160::from_str("ede84640d1a1d3e06902048e67aa7db8d52c2ce1").unwrap(),
|
|
|
|
};
|
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
let wallet: PresaleWallet = serde_json::from_str(json).unwrap();
|
|
|
|
assert_eq!(expected, wallet);
|
|
|
|
}
|
2016-06-21 14:42:27 +02:00
|
|
|
}
|