Classify Transaction.

This commit is contained in:
Gav Wood 2014-11-05 13:45:19 +00:00
parent b01be526db
commit 07ee2e4847
3 changed files with 16 additions and 43 deletions

View File

@ -339,16 +339,11 @@ BOOST_AUTO_TEST_CASE(eth_keypairs)
BOOST_REQUIRE(p.pub() == Public(fromHex("97466f2b32bc3bb76d4741ae51cd1d8578b48d3f1e68da206d47321aec267ce78549b514e4453d74ef11b0cd5e4e4c364effddac8b51bcfc8de80682f952896f"))); BOOST_REQUIRE(p.pub() == Public(fromHex("97466f2b32bc3bb76d4741ae51cd1d8578b48d3f1e68da206d47321aec267ce78549b514e4453d74ef11b0cd5e4e4c364effddac8b51bcfc8de80682f952896f")));
BOOST_REQUIRE(p.address() == Address(fromHex("8a40bfaa73256b60764c1bf40675a99083efb075"))); BOOST_REQUIRE(p.address() == Address(fromHex("8a40bfaa73256b60764c1bf40675a99083efb075")));
{ {
eth::Transaction t; eth::Transaction t(1000, 0, 0, h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b")), bytes(), 0, p.secret());
t.nonce = 0;
t.type = eth::Transaction::MessageCall;
t.receiveAddress = h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b"));
t.value = 1000;
auto rlp = t.rlp(false); auto rlp = t.rlp(false);
cnote << RLP(rlp); cnote << RLP(rlp);
cnote << toHex(rlp); cnote << toHex(rlp);
cnote << t.sha3(false); cnote << t.sha3(false);
t.sign(p.secret());
rlp = t.rlp(true); rlp = t.rlp(true);
cnote << RLP(rlp); cnote << RLP(rlp);
cnote << toHex(rlp); cnote << toHex(rlp);
@ -368,16 +363,11 @@ int cryptoTest()
assert(p.pub() == Public(fromHex("97466f2b32bc3bb76d4741ae51cd1d8578b48d3f1e68da206d47321aec267ce78549b514e4453d74ef11b0cd5e4e4c364effddac8b51bcfc8de80682f952896f"))); assert(p.pub() == Public(fromHex("97466f2b32bc3bb76d4741ae51cd1d8578b48d3f1e68da206d47321aec267ce78549b514e4453d74ef11b0cd5e4e4c364effddac8b51bcfc8de80682f952896f")));
assert(p.address() == Address(fromHex("8a40bfaa73256b60764c1bf40675a99083efb075"))); assert(p.address() == Address(fromHex("8a40bfaa73256b60764c1bf40675a99083efb075")));
{ {
eth::Transaction t; eth::Transaction t(1000, 0, 0, h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b")), bytes(), 0, p.secret());
t.nonce = 0;
t.type = eth::Transaction::MessageCall;
t.receiveAddress = h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b"));
t.value = 1000;
auto rlp = t.rlp(false); auto rlp = t.rlp(false);
cnote << RLP(rlp); cnote << RLP(rlp);
cnote << toHex(rlp); cnote << toHex(rlp);
cnote << t.sha3(false); cnote << t.sha3(false);
t.sign(p.secret());
rlp = t.rlp(true); rlp = t.rlp(true);
cnote << RLP(rlp); cnote << RLP(rlp);
cnote << toHex(rlp); cnote << toHex(rlp);

View File

@ -65,12 +65,7 @@ int stateTest()
// Inject a transaction to transfer funds from miner to me. // Inject a transaction to transfer funds from miner to me.
bytes tx; bytes tx;
{ {
Transaction t; Transaction t(1000, 0, 0, me.address(), bytes(), s.transactionsFrom(myMiner.address()), myMiner.secret());
t.nonce = s.transactionsFrom(myMiner.address());
t.value = 1000; // 1e3 wei.
t.type = eth::Transaction::MessageCall;
t.receiveAddress = me.address();
t.sign(myMiner.secret());
assert(t.sender() == myMiner.address()); assert(t.sender() == myMiner.address());
tx = t.rlp(); tx = t.rlp();
} }

38
vm.cpp
View File

@ -36,11 +36,7 @@ FakeExtVM::FakeExtVM(eth::BlockInfo const& _previousBlock, eth::BlockInfo const&
h160 FakeExtVM::create(u256 _endowment, u256* _gas, bytesConstRef _init, OnOpFunc const&) h160 FakeExtVM::create(u256 _endowment, u256* _gas, bytesConstRef _init, OnOpFunc const&)
{ {
Transaction t; Transaction t(_endowment, gasPrice, *_gas, _init.toBytes());
t.value = _endowment;
t.gasPrice = gasPrice;
t.gas = *_gas;
t.data = _init.toBytes();
m_s.noteSending(myAddress); m_s.noteSending(myAddress);
m_ms.internal.resize(m_ms.internal.size() + 1); m_ms.internal.resize(m_ms.internal.size() + 1);
@ -55,7 +51,6 @@ h160 FakeExtVM::create(u256 _endowment, u256* _gas, bytesConstRef _init, OnOpFun
get<3>(addresses[ret]) = m_s.code(ret); get<3>(addresses[ret]) = m_s.code(ret);
} }
t.type = eth::Transaction::ContractCreation;
callcreates.push_back(t); callcreates.push_back(t);
return ret; return ret;
} }
@ -64,13 +59,7 @@ bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data,
{ {
u256 contractgas = 0xffff; u256 contractgas = 0xffff;
Transaction t; Transaction t(_value, gasPrice, *_gas, _receiveAddress, _data.toVector());
t.value = _value;
t.gasPrice = gasPrice;
t.gas = *_gas;
t.data = _data.toVector();
t.type = eth::Transaction::MessageCall;
t.receiveAddress = _receiveAddress;
callcreates.push_back(t); callcreates.push_back(t);
string codeOf_CodeAddress = _codeAddressOverride ? toHex(get<3>(addresses[_codeAddressOverride])) : toHex(get<3>(addresses[_receiveAddress]) ); string codeOf_CodeAddress = _codeAddressOverride ? toHex(get<3>(addresses[_codeAddressOverride])) : toHex(get<3>(addresses[_receiveAddress]) );
@ -386,10 +375,10 @@ mArray FakeExtVM::exportCallCreates()
for (Transaction const& tx: callcreates) for (Transaction const& tx: callcreates)
{ {
mObject o; mObject o;
o["destination"] = tx.type == Transaction::ContractCreation ? "" : toString(tx.receiveAddress); o["destination"] = tx.type() == Transaction::ContractCreation ? "" : toString(tx.receiveAddress());
push(o, "gasLimit", tx.gas); push(o, "gasLimit", tx.gas());
push(o, "value", tx.value); push(o, "value", tx.value());
o["data"] = "0x" + toHex(tx.data); o["data"] = "0x" + toHex(tx.data());
ret.push_back(o); ret.push_back(o);
} }
return ret; return ret;
@ -404,19 +393,18 @@ void FakeExtVM::importCallCreates(mArray& _callcreates)
BOOST_REQUIRE(tx.count("value") > 0); BOOST_REQUIRE(tx.count("value") > 0);
BOOST_REQUIRE(tx.count("destination") > 0); BOOST_REQUIRE(tx.count("destination") > 0);
BOOST_REQUIRE(tx.count("gasLimit") > 0); BOOST_REQUIRE(tx.count("gasLimit") > 0);
Transaction t; bytes data;
t.type = tx["destination"].get_str().empty() ? Transaction::ContractCreation : Transaction::MessageCall;
t.receiveAddress = Address(tx["destination"].get_str());
t.value = toInt(tx["value"]);
t.gas = toInt(tx["gasLimit"]);
if (tx["data"].type() == str_type) if (tx["data"].type() == str_type)
if (tx["data"].get_str().find_first_of("0x") == 0) if (tx["data"].get_str().find_first_of("0x") == 0)
t.data = fromHex(tx["data"].get_str().substr(2)); data = fromHex(tx["data"].get_str().substr(2));
else else
t.data = fromHex(tx["data"].get_str()); data = fromHex(tx["data"].get_str());
else else
for (auto const& j: tx["data"].get_array()) for (auto const& j: tx["data"].get_array())
t.data.push_back(toByte(j)); data.push_back(toByte(j));
Transaction t = tx["destination"].get_str().empty() ?
Transaction(toInt(tx["value"]), 0, toInt(tx["gasLimit"]), data) :
Transaction(toInt(tx["value"]), 0, toInt(tx["gasLimit"]), Address(tx["destination"].get_str()), data);
callcreates.push_back(t); callcreates.push_back(t);
} }
} }