Browse Source

Add normalized transaction hash

Rebased-from: e7853a91cf646a6a4701158d148f036924575a97
Rebased-by:   Warren Togami <wtogami@gmail.com>

Original code from https://github.com/bitcoin/bitcoin/pull/3656

Warning
=======
This patch was rejected from Bitcoin Core and must be considered experimental.
Theoretically it is compatible with the de facto standard as utilized by
blockchain.info and a few vendors.
0.8
Pieter Wuille 11 years ago committed by Warren Togami
parent
commit
bc7bc9d751
  1. 1
      src/bitcoinrpc.cpp
  2. 1
      src/bitcoinrpc.h
  3. 5
      src/main.h
  4. 22
      src/rpcrawtransaction.cpp
  5. 1
      src/rpcwallet.cpp
  6. 1
      src/script.h

1
src/bitcoinrpc.cpp

@ -260,6 +260,7 @@ static const CRPCCommand vRPCCommands[] =
{ "decoderawtransaction", &decoderawtransaction, false, false, false }, { "decoderawtransaction", &decoderawtransaction, false, false, false },
{ "signrawtransaction", &signrawtransaction, false, false, false }, { "signrawtransaction", &signrawtransaction, false, false, false },
{ "sendrawtransaction", &sendrawtransaction, false, false, false }, { "sendrawtransaction", &sendrawtransaction, false, false, false },
{ "getnormalizedtxid", &getnormalizedtxid, true, true, false },
{ "gettxoutsetinfo", &gettxoutsetinfo, true, false, false }, { "gettxoutsetinfo", &gettxoutsetinfo, true, false, false },
{ "gettxout", &gettxout, true, false, false }, { "gettxout", &gettxout, true, false, false },
{ "lockunspent", &lockunspent, false, false, true }, { "lockunspent", &lockunspent, false, false, true },

1
src/bitcoinrpc.h

@ -194,6 +194,7 @@ extern json_spirit::Value createrawtransaction(const json_spirit::Array& params,
extern json_spirit::Value decoderawtransaction(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value decoderawtransaction(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value signrawtransaction(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value signrawtransaction(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value sendrawtransaction(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value sendrawtransaction(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getnormalizedtxid(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getblockcount(const json_spirit::Array& params, bool fHelp); // in rpcblockchain.cpp extern json_spirit::Value getblockcount(const json_spirit::Array& params, bool fHelp); // in rpcblockchain.cpp
extern json_spirit::Value getbestblockhash(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getbestblockhash(const json_spirit::Array& params, bool fHelp);

5
src/main.h

@ -514,6 +514,11 @@ public:
return SerializeHash(*this); return SerializeHash(*this);
} }
uint256 GetNormalizedHash() const
{
return SignatureHash(CScript(), *this, 0, SIGHASH_ALL);
}
bool IsFinal(int nBlockHeight=0, int64 nBlockTime=0) const bool IsFinal(int nBlockHeight=0, int64 nBlockTime=0) const
{ {
// Time based nLockTime implemented in 0.1.6 // Time based nLockTime implemented in 0.1.6

22
src/rpcrawtransaction.cpp

@ -576,3 +576,25 @@ Value sendrawtransaction(const Array& params, bool fHelp)
return hashTx.GetHex(); return hashTx.GetHex();
} }
Value getnormalizedtxid(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error("blah");
// parse hex string from parameter
vector<unsigned char> txData(ParseHexV(params[0], "parameter"));
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
CTransaction tx;
// deserialize binary data stream
try {
ssData >> tx;
}
catch (std::exception &e) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
}
uint256 hashNormalized = tx.GetNormalizedHash();
return hashNormalized.GetHex();
}

1
src/rpcwallet.cpp

@ -45,6 +45,7 @@ void WalletTxToJSON(const CWalletTx& wtx, Object& entry)
entry.push_back(Pair("blocktime", (boost::int64_t)(mapBlockIndex[wtx.hashBlock]->nTime))); entry.push_back(Pair("blocktime", (boost::int64_t)(mapBlockIndex[wtx.hashBlock]->nTime)));
} }
entry.push_back(Pair("txid", wtx.GetHash().GetHex())); entry.push_back(Pair("txid", wtx.GetHash().GetHex()));
entry.push_back(Pair("normtxid", wtx.GetNormalizedHash().GetHex()));
entry.push_back(Pair("time", (boost::int64_t)wtx.GetTxTime())); entry.push_back(Pair("time", (boost::int64_t)wtx.GetTxTime()));
entry.push_back(Pair("timereceived", (boost::int64_t)wtx.nTimeReceived)); entry.push_back(Pair("timereceived", (boost::int64_t)wtx.nTimeReceived));
BOOST_FOREACH(const PAIRTYPE(string,string)& item, wtx.mapValue) BOOST_FOREACH(const PAIRTYPE(string,string)& item, wtx.mapValue)

1
src/script.h

@ -670,6 +670,7 @@ public:
bool IsCanonicalPubKey(const std::vector<unsigned char> &vchPubKey); bool IsCanonicalPubKey(const std::vector<unsigned char> &vchPubKey);
bool IsCanonicalSignature(const std::vector<unsigned char> &vchSig); bool IsCanonicalSignature(const std::vector<unsigned char> &vchSig);
uint256 SignatureHash(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType);
bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, const CTransaction& txTo, unsigned int nIn, unsigned int flags, int nHashType); bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, const CTransaction& txTo, unsigned int nIn, unsigned int flags, int nHashType);
bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet); bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet);
int ScriptSigArgsExpected(txnouttype t, const std::vector<std::vector<unsigned char> >& vSolutions); int ScriptSigArgsExpected(txnouttype t, const std::vector<std::vector<unsigned char> >& vSolutions);

Loading…
Cancel
Save