You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
6.2 KiB
99 lines
6.2 KiB
/*
|
|
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 <http://www.gnu.org/licenses/>.
|
|
*/
|
|
/** @file CanonBlockChain.cpp
|
|
* @author Gav Wood <i@gavwood.com>
|
|
* @date 2014
|
|
*/
|
|
|
|
#include "CanonBlockChain.h"
|
|
|
|
#include <test/JsonSpiritHeaders.h>
|
|
#include <boost/filesystem.hpp>
|
|
#include <libdevcore/Common.h>
|
|
#include <libdevcore/RLP.h>
|
|
#include <libdevcrypto/FileSystem.h>
|
|
#include <libethcore/Exceptions.h>
|
|
#include <libethcore/ProofOfWork.h>
|
|
#include <libethcore/BlockInfo.h>
|
|
#include <liblll/Compiler.h>
|
|
#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
|
|
|
|
std::map<Address, Account> const& dev::eth::genesisState()
|
|
{
|
|
static std::map<Address, Account> s_ret;
|
|
|
|
if (s_ret.empty())
|
|
{
|
|
s_ret[Address(1)] = Account(0, Account::ContractConception);
|
|
s_ret[Address(2600)].setCode(fromHex("60e060020a60003504806301984892146100ba5780631c83171b146100cf578063449c2090146100e05780635d574e32146100fe5780635fd4b08a14610112578063618242da146101275780636be16bed1461013c5780636c4489b41461014d5780637d2e3ce914610180578063994d29cc146101935780639e71f357146101a8578063b8202c18146101bc578063c284bc2a146101d0578063e50f599a146101e1578063e5811b35146101f8578063ec7b92001461021657005b6100c5600435610652565b8060005260206000f35b6100da600435610446565b60006000f35b6100eb600435610426565b80600160a060020a031660005260206000f35b61010c600435602435610324565b60006000f35b61011d600435610375565b8060005260206000f35b610132600435610612565b8060005260206000f35b6101476004356105f2565b60006000f35b61015860043561037c565b84600160a060020a031660005283600160a060020a0316602052816040528060605260806000f35b61018d60043560006102d3565b60006000f35b61019e600435610632565b8060005260206000f35b6101b6600435602435610234565b60006000f35b6101ca600435602435610282565b60006000f35b6101db600435610513565b60006000f35b6101f2600435602435604435610495565b60006000f35b61020360043561048e565b80600160a060020a031660005260206000f35b610221600435610409565b80600160a060020a031660005260206000f35b33600160a060020a03166001600084815260200190815260200160002054600160a060020a0316146102655761027e565b8060016000848152602001908152602001600020819055505b5050565b33600160a060020a03166001600084815260200190815260200160002054600160a060020a0316146102b3576102cf565b8060016000848152602001908152602001600020600401819055505b5050565b33600160a060020a03166001600084815260200190815260200160002054600160a060020a03161461030457610320565b8060016000848152602001908152602001600020600201819055505b5050565b33600160a060020a03166001600084815260200190815260200160002054600160a060020a03161461035557610371565b8060016000848152602001908152602001600020600301819055505b5050565b6000919050565b60006000600060006000600160008781526020019081526020016000205494506001600087815260200190815260200160002060010154935060016000878152602001908152602001600020600201549250600160008781526020019081526020016000206003015491506001600087815260200190815260200160002060040154905091939590929450565b600060016000838152602001908152602001600020549050919050565b600060016000838152602001908152602001600020600101549050919050565b6001600082815260200190815260200160002054600160a060020a031660001461046f5761048b565b3360016000838152602001908152602001600020600101819055505b50565b6000919050565b33600160a060020a03166001600085815260200190815260200160002054600160a060020a0316146104c65761050e565b816001600085815260200190815260200160002060010181905550806104eb5761050d565b826000600084600160a060020a03168152602001908152602001600020819055505b5b505050565b33600160a060020a03166001600083815260200190815260200160002054600160a060020a031614610544576105ef565b80600060006001600085815260200190815260200160002060010154600160a060020a031681526020019081526020016000205414610582576105bb565b6000600060006001600085815260200190815260200160002060010154600160a060020a03168152602001908152602001600020819055505b6001600082815260200190815260200160002060008155600101600081556001016000815560010160008155600101600090555b50565b600060016000838152602001908152602001600020600201549050919050565b600060016000838152602001908152602001600020600301549050919050565b600060016000838152602001908152602001600020600401549050919050565b60006000600083600160a060020a0316815260200190815260200160002054905091905056"));
|
|
js::mValue val;
|
|
json_spirit::read_string(c_genesisInfo, val);
|
|
for (auto account: val.get_obj())
|
|
{
|
|
u256 balance;
|
|
if (account.second.get_obj().count("wei"))
|
|
balance = u256(account.second.get_obj()["wei"].get_str());
|
|
else
|
|
balance = u256(account.second.get_obj()["finney"].get_str()) * finney;
|
|
if (account.second.get_obj().count("code"))
|
|
{
|
|
s_ret[Address(fromHex(account.first))] = Account(balance, 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(balance, Account::NormalCreation);
|
|
}
|
|
}
|
|
return s_ret;
|
|
}
|
|
|
|
// TODO: place Registry in here.
|
|
|
|
std::unique_ptr<BlockInfo> CanonBlockChain::s_genesis;
|
|
boost::shared_mutex CanonBlockChain::x_genesis;
|
|
|
|
bytes CanonBlockChain::createGenesisBlock()
|
|
{
|
|
RLPStream block(3);
|
|
|
|
h256 stateRoot;
|
|
{
|
|
MemoryDB db;
|
|
TrieDB<Address, MemoryDB> state(&db);
|
|
state.init();
|
|
dev::eth::commit(genesisState(), db, state);
|
|
stateRoot = state.root();
|
|
}
|
|
|
|
block.appendList(14)
|
|
<< h256() << EmptyListSHA3 << h160() << stateRoot << EmptyTrie << EmptyTrie << LogBloom() << c_genesisDifficulty << 0 << 1000000 << 0 << (unsigned)0 << string() << sha3(bytes(1, 42));
|
|
block.appendRaw(RLPEmptyList);
|
|
block.appendRaw(RLPEmptyList);
|
|
return block.out();
|
|
}
|
|
|
|
CanonBlockChain::CanonBlockChain(std::string _path, bool _killExisting): BlockChain(CanonBlockChain::createGenesisBlock(), _path, _killExisting)
|
|
{
|
|
}
|
|
|