diff options
Diffstat (limited to 'transaction.cpp')
-rw-r--r-- | transaction.cpp | 86 |
1 files changed, 46 insertions, 40 deletions
diff --git a/transaction.cpp b/transaction.cpp index 00de5fb2..6a1aa0d8 100644 --- a/transaction.cpp +++ b/transaction.cpp @@ -29,6 +29,50 @@ using namespace dev::eth; namespace dev { namespace test { +RLPStream createRLPStreamFromTransactionFields(mObject& _tObj) +{ + //Construct Rlp of the given transaction + RLPStream rlpStream; + rlpStream.appendList(_tObj.size()); + + if (_tObj.count("nonce") > 0) + rlpStream << bigint(_tObj["nonce"].get_str()); + + if (_tObj.count("gasPrice") > 0) + rlpStream << bigint(_tObj["gasPrice"].get_str()); + + if (_tObj.count("gasLimit") > 0) + rlpStream << bigint(_tObj["gasLimit"].get_str()); + + if (_tObj.count("to") > 0) + { + if (_tObj["to"].get_str().empty()) + rlpStream << ""; + else + rlpStream << importByteArray(_tObj["to"].get_str()); + } + + if (_tObj.count("value") > 0) + rlpStream << bigint(_tObj["value"].get_str()); + + if (_tObj.count("data") > 0) + rlpStream << importData(_tObj); + + if (_tObj.count("v") > 0) + rlpStream << bigint(_tObj["v"].get_str()); + + if (_tObj.count("r") > 0) + rlpStream << bigint(_tObj["r"].get_str()); + + if (_tObj.count("s") > 0) + rlpStream << bigint(_tObj["s"].get_str()); + + if (_tObj.count("extrafield") > 0) + rlpStream << bigint(_tObj["extrafield"].get_str()); + + return rlpStream; +} + void doTransactionTests(json_spirit::mValue& _v, bool _fillin) { for (auto& i: _v.get_obj()) @@ -57,8 +101,7 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin) BOOST_REQUIRE(o.count("transaction") > 0); mObject tObj = o["transaction"].get_obj(); - bytes txRLP = createTransactionFromFields(tObj); - Transaction txFromFields(txRLP, CheckSignature::Sender); + Transaction txFromFields(createRLPStreamFromTransactionFields(tObj).out(), CheckSignature::Sender); //Check the fields restored from RLP to original fields BOOST_CHECK_MESSAGE(txFromFields.data() == txFromRlp.data(), "Data in given RLP not matching the Transaction data!"); @@ -80,44 +123,7 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin) mObject tObj = o["transaction"].get_obj(); //Construct Rlp of the given transaction - RLPStream rlpStream; - rlpStream.appendList(tObj.size()); - - if (tObj.count("nonce") > 0) - rlpStream << bigint(tObj["nonce"].get_str()); - - if (tObj.count("gasPrice") > 0) - rlpStream << bigint(tObj["gasPrice"].get_str()); - - if (tObj.count("gasLimit") > 0) - rlpStream << bigint(tObj["gasLimit"].get_str()); - - if (tObj.count("to") > 0) - { - if (tObj["to"].get_str().empty()) - rlpStream << ""; - else - rlpStream << Address(tObj["to"].get_str()); - } - - if (tObj.count("value") > 0) - rlpStream << bigint(tObj["value"].get_str()); - - if (tObj.count("data") > 0) - rlpStream << importData(tObj); - - if (tObj.count("v") > 0) - rlpStream << bigint(tObj["v"].get_str()); - - if (tObj.count("r") > 0) - rlpStream << bigint(tObj["r"].get_str()); - - if (tObj.count("s") > 0) - rlpStream << bigint(tObj["s"].get_str()); - - if (tObj.count("extrafield") > 0) - rlpStream << bigint(tObj["extrafield"].get_str()); - + RLPStream rlpStream = createRLPStreamFromTransactionFields(tObj); o["rlp"] = "0x" + toHex(rlpStream.out()); try |