mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Separation of code & data compiling.
This commit is contained in:
parent
63e19e178b
commit
b3de90e246
51
vm.cpp
51
vm.cpp
@ -40,7 +40,7 @@ public:
|
|||||||
FakeExtVM()
|
FakeExtVM()
|
||||||
{}
|
{}
|
||||||
FakeExtVM(BlockInfo const& _previousBlock, BlockInfo const& _currentBlock, uint _currentNumber):
|
FakeExtVM(BlockInfo const& _previousBlock, BlockInfo const& _currentBlock, uint _currentNumber):
|
||||||
ExtVMFace(Address(), Address(), 0, 1, bytesConstRef(), _previousBlock, _currentBlock, _currentNumber)
|
ExtVMFace(Address(), Address(), 0, 1, bytesConstRef(), bytesConstRef(), _previousBlock, _currentBlock, _currentNumber)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
u256 store(u256 _n)
|
u256 store(u256 _n)
|
||||||
@ -69,15 +69,14 @@ public:
|
|||||||
txs.push_back(_t);
|
txs.push_back(_t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
h160 create(u256 _endowment, vector_ref<h256 const> _storage)
|
h160 create(u256 _endowment, u256* _gas, bytesConstRef _code, bytesConstRef _init)
|
||||||
{
|
{
|
||||||
Transaction t;
|
Transaction t;
|
||||||
t.value = _endowment;
|
t.value = _endowment;
|
||||||
t.isCreation = true;
|
|
||||||
t.storage.reserve(_storage.size());
|
|
||||||
for (auto i: _storage)
|
|
||||||
t.storage.push_back(i);
|
|
||||||
t.gasPrice = gasPrice;
|
t.gasPrice = gasPrice;
|
||||||
|
t.gas = *_gas;
|
||||||
|
t.data = _code.toBytes();
|
||||||
|
t.init = _init.toBytes();
|
||||||
txs.push_back(t);
|
txs.push_back(t);
|
||||||
return right160(t.sha3(false));
|
return right160(t.sha3(false));
|
||||||
}
|
}
|
||||||
@ -85,11 +84,10 @@ public:
|
|||||||
bool call(Address _receiveAddress, u256 _txValue, bytesConstRef _txData, u256* _gas, bytesRef _txOut)
|
bool call(Address _receiveAddress, u256 _txValue, bytesConstRef _txData, u256* _gas, bytesRef _txOut)
|
||||||
{
|
{
|
||||||
Transaction t;
|
Transaction t;
|
||||||
t.isCreation = false;
|
|
||||||
t.value = _txValue;
|
t.value = _txValue;
|
||||||
t.data = _txData.toVector();
|
|
||||||
t.gas = *_gas;
|
|
||||||
t.gasPrice = gasPrice;
|
t.gasPrice = gasPrice;
|
||||||
|
t.gas = *_gas;
|
||||||
|
t.data = _txData.toVector();
|
||||||
t.receiveAddress = _receiveAddress;
|
t.receiveAddress = _receiveAddress;
|
||||||
txs.push_back(t);
|
txs.push_back(t);
|
||||||
(void)_txOut;
|
(void)_txOut;
|
||||||
@ -103,18 +101,25 @@ public:
|
|||||||
txData = &_txData;
|
txData = &_txData;
|
||||||
gasPrice = _gasPrice;
|
gasPrice = _gasPrice;
|
||||||
}
|
}
|
||||||
void setContract(Address _myAddress, u256 _myBalance, u256 _myNonce, u256s const& _storage)
|
void setContract(Address _myAddress, u256 _myBalance, u256 _myNonce, bytes const& _code, map<u256, u256> const& _storage)
|
||||||
{
|
{
|
||||||
myAddress = _myAddress;
|
myAddress = _myAddress;
|
||||||
set(myAddress, _myBalance, _myNonce, _storage);
|
set(myAddress, _myBalance, _myNonce, _code, _storage);
|
||||||
}
|
}
|
||||||
void set(Address _a, u256 _myBalance, u256 _myNonce, u256s const& _storage)
|
void set(Address _a, u256 _myBalance, u256 _myNonce, bytes const& _code, map<u256, u256> const& _storage)
|
||||||
{
|
{
|
||||||
get<0>(addresses[_a]) = _myBalance;
|
get<0>(addresses[_a]) = _myBalance;
|
||||||
get<1>(addresses[_a]) = _myNonce;
|
get<1>(addresses[_a]) = _myNonce;
|
||||||
get<2>(addresses[_a]) = 0;
|
get<2>(addresses[_a]) = 0;
|
||||||
for (unsigned i = 0; i < _storage.size(); ++i)
|
get<3>(addresses[_a]) = _storage;
|
||||||
get<3>(addresses[_a])[i] = _storage[i];
|
get<4>(addresses[_a]) = _code;
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset(u256 _myBalance, u256 _myNonce, map<u256, u256> const& _storage)
|
||||||
|
{
|
||||||
|
txs.clear();
|
||||||
|
addresses.clear();
|
||||||
|
set(myAddress, _myBalance, _myNonce, get<4>(addresses[myAddress]), _storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
mObject exportEnv()
|
mObject exportEnv()
|
||||||
@ -235,9 +240,9 @@ public:
|
|||||||
}
|
}
|
||||||
if (o.count("code"))
|
if (o.count("code"))
|
||||||
{
|
{
|
||||||
u256s d = compileLisp(o["code"].get_str());
|
bytes e;
|
||||||
for (unsigned i = 0; i < d.size(); ++i)
|
bytes d = compileLisp(o["code"].get_str(), false, e);
|
||||||
get<3>(a)[(u256)i] = d[i];
|
get<4>(a) = d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -299,14 +304,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset(u256 _myBalance, u256 _myNonce, u256s _myData)
|
map<Address, tuple<u256, u256, u256, map<u256, u256>, bytes>> addresses;
|
||||||
{
|
|
||||||
txs.clear();
|
|
||||||
addresses.clear();
|
|
||||||
set(myAddress, _myBalance, _myNonce, _myData);
|
|
||||||
}
|
|
||||||
|
|
||||||
map<Address, tuple<u256, u256, u256, map<u256, u256>>> addresses;
|
|
||||||
Transactions txs;
|
Transactions txs;
|
||||||
bytes thisTxData;
|
bytes thisTxData;
|
||||||
};
|
};
|
||||||
@ -409,7 +407,8 @@ public:
|
|||||||
cb.timestamp = 1;
|
cb.timestamp = 1;
|
||||||
cb.coinbaseAddress = toAddress(sha3("coinbase"));
|
cb.coinbaseAddress = toAddress(sha3("coinbase"));
|
||||||
FakeExtVM fev(pb, cb, 0);
|
FakeExtVM fev(pb, cb, 0);
|
||||||
fev.setContract(toAddress(sha3("contract")), ether, 0, compileLisp("(suicide (txsender))"));
|
bytes init;
|
||||||
|
fev.setContract(toAddress(sha3("contract")), ether, 0, compileLisp("(suicide (txsender))", false, init), map<u256, u256>());
|
||||||
o["env"] = fev.exportEnv();
|
o["env"] = fev.exportEnv();
|
||||||
o["pre"] = fev.exportState();
|
o["pre"] = fev.exportState();
|
||||||
fev.setTransaction(toAddress(sha3("sender")), ether, finney, bytes());
|
fev.setTransaction(toAddress(sha3("sender")), ether, finney, bytes());
|
||||||
|
Loading…
Reference in New Issue
Block a user