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.
106 lines
3.8 KiB
106 lines
3.8 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 MixClient.h
|
|
* @author Yann yann@ethdev.com
|
|
* @author Arkadiy Paronyan arkadiy@ethdev.com
|
|
* @date 2015
|
|
* Ethereum IDE client.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <vector>
|
|
#include <string>
|
|
#include <libethereum/ClientBase.h>
|
|
#include <libethereum/Client.h>
|
|
#include "MachineStates.h"
|
|
|
|
namespace dev
|
|
{
|
|
namespace mix
|
|
{
|
|
|
|
class MixBlockChain: public dev::eth::BlockChain
|
|
{
|
|
public:
|
|
MixBlockChain(std::string const& _path, h256 _stateRoot): BlockChain(createGenesisBlock(_stateRoot), _path, true) {}
|
|
|
|
static bytes createGenesisBlock(h256 _stateRoot);
|
|
};
|
|
|
|
class MixClient: public dev::eth::ClientBase
|
|
{
|
|
public:
|
|
MixClient(std::string const& _dbPath);
|
|
virtual ~MixClient();
|
|
/// Reset state to the empty state with given balance.
|
|
void resetState(std::map<Secret, u256> _accounts);
|
|
void mine();
|
|
ExecutionResult lastExecution() const;
|
|
ExecutionResult execution(unsigned _index) const;
|
|
|
|
void submitTransaction(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice) override;
|
|
Address submitTransaction(Secret _secret, u256 _endowment, bytes const& _init, u256 _gas, u256 _gasPrice) override;
|
|
dev::eth::ExecutionResult call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, eth::BlockNumber _blockNumber = eth::PendingBlock) override;
|
|
dev::eth::ExecutionResult create(Secret _secret, u256 _value, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * eth::szabo, eth::BlockNumber _blockNumber = eth::PendingBlock) override;
|
|
|
|
void setAddress(Address _us) override;
|
|
void setMiningThreads(unsigned _threads) override;
|
|
unsigned miningThreads() const override;
|
|
void startMining() override;
|
|
void stopMining() override;
|
|
bool isMining() override;
|
|
eth::MineProgress miningProgress() const override;
|
|
std::pair<h256, u256> getWork() override { return std::pair<h256, u256>(); }
|
|
bool submitWork(eth::ProofOfWork::Proof const&) override { return false; }
|
|
virtual void flushTransactions() override {}
|
|
|
|
/// @returns the last mined block information
|
|
using Interface::blockInfo; // to remove warning about hiding virtual function
|
|
eth::BlockInfo blockInfo() const;
|
|
std::vector<KeyPair> userAccounts() { return m_userAccounts; }
|
|
|
|
protected:
|
|
virtual dev::eth::BlockChain& bc() { return *m_bc; }
|
|
|
|
/// InterfaceStub methods
|
|
virtual dev::eth::State asOf(eth::BlockNumber _block) const override;
|
|
virtual dev::eth::State asOf(h256 _block) const override;
|
|
virtual dev::eth::BlockChain const& bc() const override { return *m_bc; }
|
|
virtual dev::eth::State preMine() const override { ReadGuard l(x_state); return m_startState; }
|
|
virtual dev::eth::State postMine() const override { ReadGuard l(x_state); return m_state; }
|
|
virtual void prepareForTransaction() override {}
|
|
|
|
private:
|
|
void executeTransaction(dev::eth::Transaction const& _t, eth::State& _state, bool _call);
|
|
void noteChanged(h256Set const& _filters);
|
|
|
|
std::vector<KeyPair> m_userAccounts;
|
|
eth::State m_state;
|
|
eth::State m_startState;
|
|
OverlayDB m_stateDB;
|
|
std::auto_ptr<MixBlockChain> m_bc;
|
|
mutable boost::shared_mutex x_state;
|
|
mutable boost::shared_mutex x_executions;
|
|
ExecutionResults m_executions;
|
|
std::string m_dbPath;
|
|
unsigned m_minigThreads;
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|