diff options
author | Gav Wood <i@gavwood.com> | 2014-03-31 09:49:36 +0800 |
---|---|---|
committer | Gav Wood <i@gavwood.com> | 2014-03-31 09:49:36 +0800 |
commit | b3de90e246a53ead7614b09c1a6b0d815e845479 (patch) | |
tree | 15f2237735675a4f9320c4231703267a068620ad /vm.cpp | |
parent | 63e19e178bcb26bfea9f2d5af0957ae9f778efe9 (diff) | |
download | dexon-solidity-b3de90e246a53ead7614b09c1a6b0d815e845479.tar dexon-solidity-b3de90e246a53ead7614b09c1a6b0d815e845479.tar.gz dexon-solidity-b3de90e246a53ead7614b09c1a6b0d815e845479.tar.bz2 dexon-solidity-b3de90e246a53ead7614b09c1a6b0d815e845479.tar.lz dexon-solidity-b3de90e246a53ead7614b09c1a6b0d815e845479.tar.xz dexon-solidity-b3de90e246a53ead7614b09c1a6b0d815e845479.tar.zst dexon-solidity-b3de90e246a53ead7614b09c1a6b0d815e845479.zip |
Separation of code & data compiling.
Diffstat (limited to 'vm.cpp')
-rw-r--r-- | vm.cpp | 51 |
1 files changed, 25 insertions, 26 deletions
@@ -40,7 +40,7 @@ public: FakeExtVM() {} 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) @@ -69,15 +69,14 @@ public: 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; t.value = _endowment; - t.isCreation = true; - t.storage.reserve(_storage.size()); - for (auto i: _storage) - t.storage.push_back(i); t.gasPrice = gasPrice; + t.gas = *_gas; + t.data = _code.toBytes(); + t.init = _init.toBytes(); txs.push_back(t); return right160(t.sha3(false)); } @@ -85,11 +84,10 @@ public: bool call(Address _receiveAddress, u256 _txValue, bytesConstRef _txData, u256* _gas, bytesRef _txOut) { Transaction t; - t.isCreation = false; t.value = _txValue; - t.data = _txData.toVector(); - t.gas = *_gas; t.gasPrice = gasPrice; + t.gas = *_gas; + t.data = _txData.toVector(); t.receiveAddress = _receiveAddress; txs.push_back(t); (void)_txOut; @@ -103,18 +101,25 @@ public: txData = &_txData; 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; - 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<1>(addresses[_a]) = _myNonce; get<2>(addresses[_a]) = 0; - for (unsigned i = 0; i < _storage.size(); ++i) - get<3>(addresses[_a])[i] = _storage[i]; + get<3>(addresses[_a]) = _storage; + 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() @@ -235,9 +240,9 @@ public: } if (o.count("code")) { - u256s d = compileLisp(o["code"].get_str()); - for (unsigned i = 0; i < d.size(); ++i) - get<3>(a)[(u256)i] = d[i]; + bytes e; + bytes d = compileLisp(o["code"].get_str(), false, e); + get<4>(a) = d; } } } @@ -299,14 +304,7 @@ public: } } - void reset(u256 _myBalance, u256 _myNonce, u256s _myData) - { - txs.clear(); - addresses.clear(); - set(myAddress, _myBalance, _myNonce, _myData); - } - - map<Address, tuple<u256, u256, u256, map<u256, u256>>> addresses; + map<Address, tuple<u256, u256, u256, map<u256, u256>, bytes>> addresses; Transactions txs; bytes thisTxData; }; @@ -409,7 +407,8 @@ public: cb.timestamp = 1; cb.coinbaseAddress = toAddress(sha3("coinbase")); 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["pre"] = fev.exportState(); fev.setTransaction(toAddress(sha3("sender")), ether, finney, bytes()); |