Jeff Garzik
10 years ago
7 changed files with 73 additions and 33 deletions
@ -0,0 +1,14 @@ |
|||
#ifndef __BITCOIN_CORE_IO_H__ |
|||
#define __BITCOIN_CORE_IO_H__ |
|||
|
|||
#include <string> |
|||
|
|||
class CTransaction; |
|||
|
|||
// core_read.cpp
|
|||
extern bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx); |
|||
|
|||
// core_write.cpp
|
|||
extern std::string EncodeHexTx(const CTransaction& tx); |
|||
|
|||
#endif // __BITCOIN_CORE_IO_H__
|
@ -0,0 +1,25 @@ |
|||
|
|||
#include <vector> |
|||
#include "core_io.h" |
|||
#include "core.h" |
|||
#include "serialize.h" |
|||
|
|||
using namespace std; |
|||
|
|||
bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx) |
|||
{ |
|||
if (!IsHex(strHexTx)) |
|||
return false; |
|||
|
|||
vector<unsigned char> txData(ParseHex(strHexTx)); |
|||
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION); |
|||
try { |
|||
ssData >> tx; |
|||
} |
|||
catch (std::exception &e) { |
|||
return false; |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
@ -0,0 +1,15 @@ |
|||
|
|||
#include "core_io.h" |
|||
#include "core.h" |
|||
#include "serialize.h" |
|||
#include "util.h" |
|||
|
|||
using namespace std; |
|||
|
|||
string EncodeHexTx(const CTransaction& tx) |
|||
{ |
|||
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); |
|||
ssTx << tx; |
|||
return HexStr(ssTx.begin(), ssTx.end()); |
|||
} |
|||
|
Loading…
Reference in new issue