From 4ffa45b83fcd116f5feca4945124a1038ad8ff05 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 20 Jan 2015 11:56:06 -0800 Subject: [PATCH] Genesis info. --- libethereum/BlockChain.cpp | 3 +++ libethereum/CanonBlockChain.cpp | 25 +++++++++++----------- libethereum/GenesisInfo.cpp | 37 +++++++++++++++++++++++++++++++++ libethereum/GenesisInfo.h | 32 ++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 12 deletions(-) create mode 100644 libethereum/GenesisInfo.cpp create mode 100644 libethereum/GenesisInfo.h diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index 11ab08ce6..29095076f 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -22,6 +22,7 @@ #include "BlockChain.h" #include +#include #include #include #include @@ -29,11 +30,13 @@ #include #include #include +#include "GenesisInfo.h" #include "State.h" #include "Defaults.h" using namespace std; using namespace dev; using namespace dev::eth; +namespace js = json_spirit; #define ETH_CATCH 1 diff --git a/libethereum/CanonBlockChain.cpp b/libethereum/CanonBlockChain.cpp index fc7107154..0e468970c 100644 --- a/libethereum/CanonBlockChain.cpp +++ b/libethereum/CanonBlockChain.cpp @@ -21,6 +21,7 @@ #include "CanonBlockChain.h" +#include #include #include #include @@ -29,11 +30,13 @@ #include #include #include +#include "GenesisInfo.h" #include "State.h" #include "Defaults.h" using namespace std; using namespace dev; using namespace dev::eth; +namespace js = json_spirit; #define ETH_CATCH 1 @@ -42,18 +45,16 @@ std::map const& dev::eth::genesisState() static std::map s_ret; if (s_ret.empty()) { - // Initialise. - for (auto i: vector({ - "dbdbdb2cbd23b783741e8d7fcf51e459b497e4a6", - "e6716f9544a56c530d868e4bfbacb172315bdead", - "b9c015918bdaba24b4ff057a92a3873d6eb201be", - "1a26338f0d905e295fccb71fa9ea849ffa12aaf4", - "2ef47100e0787b915105fd5e3f4ff6752079d5cb", - "cd2a3d9f938e13cd947ec05abc7fe734df8dd826", - "6c386a4b26f73c802f34673f7248bb118f97424a", - "e4157b34ea9615cfbde6b4fda419828124b70c78" - })) - s_ret[Address(fromHex(i))] = Account(u256(1) << 200, Account::NormalCreation); + js::mValue val; + json_spirit::read_string(c_genesisInfo, val); + for (auto account: val.get_obj()) + if (account.second.get_obj()["code"].get_str().size()) + { + s_ret[Address(fromHex(account.first))] = Account(fromBigEndian(fromHex(account.second.get_obj()["balance"].get_str())), Account::ContractConception); + s_ret[Address(fromHex(account.first))].setCode(fromHex(account.second.get_obj()["code"].get_str())); + } + else + s_ret[Address(fromHex(account.first))] = Account(fromBigEndian(fromHex(account.second.get_obj()["balance"].get_str())), Account::NormalCreation); } return s_ret; } diff --git a/libethereum/GenesisInfo.cpp b/libethereum/GenesisInfo.cpp new file mode 100644 index 000000000..5b5a4ba5d --- /dev/null +++ b/libethereum/GenesisInfo.cpp @@ -0,0 +1,37 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + 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. + + cpp-ethereum is distributed in the hope that it will be useful, + 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 + along with cpp-ethereum. If not, see . +*/ +/** @file GenesisInfo.cpp + * @author Gav Wood + * @date 2014 + */ + +#include "GenesisInfo.h" + +std::string const dev::eth::c_genesisInfo = +R"ETHEREUM( +{ + "51ba59315b3a95761d0863b05ccc7a7f54703d99": { "balance": "0000000000000100000000000000000000000000000000000000000000000000" }, + "e6716f9544a56c530d868e4bfbacb172315bdead": { "balance": "0000000000000100000000000000000000000000000000000000000000000000" }, + "b9c015918bdaba24b4ff057a92a3873d6eb201be": { "balance": "0000000000000100000000000000000000000000000000000000000000000000" }, + "1a26338f0d905e295fccb71fa9ea849ffa12aaf4": { "balance": "0000000000000100000000000000000000000000000000000000000000000000" }, + "2ef47100e0787b915105fd5e3f4ff6752079d5cb": { "balance": "0000000000000100000000000000000000000000000000000000000000000000" }, + "cd2a3d9f938e13cd947ec05abc7fe734df8dd826": { "balance": "0000000000000100000000000000000000000000000000000000000000000000" }, + "6c386a4b26f73c802f34673f7248bb118f97424a": { "balance": "0000000000000100000000000000000000000000000000000000000000000000" }, + "e4157b34ea9615cfbde6b4fda419828124b70c78": { "balance": "0000000000000100000000000000000000000000000000000000000000000000" }, + "000000000000000000000000000000000000002a": { "balance": "0000000000000100000000000000000000000000000000000000000000000000", code: "60035415601c576000600060006000609660020a3360155a03f150005b610100331015602757005b60003560805260805160a060020a02330160a0523460a051540160a051553460805154016080515560006000546003600154041015607557506a027b46536c66c8e300000060005460015401115b608157600060025560a5565b600254608f574260025560a4565b62093a806002544203111560a35760016003555b5b5b" } +} +)ETHEREUM"; diff --git a/libethereum/GenesisInfo.h b/libethereum/GenesisInfo.h new file mode 100644 index 000000000..7775da9e8 --- /dev/null +++ b/libethereum/GenesisInfo.h @@ -0,0 +1,32 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + 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. + + cpp-ethereum is distributed in the hope that it will be useful, + 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 + along with cpp-ethereum. If not, see . +*/ +/** @file GenesisInfo.h + * @author Gav Wood + * @date 2014 + */ + +#pragma once + +#include + +namespace dev { +namespace eth { + +extern std::string const c_genesisInfo; + +} +}