diff options
author | Luke Dashjr <luke-jr+git@utopios.org> | 2012-02-22 17:44:46 -0500 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2012-05-08 21:04:57 +0000 |
commit | 7e63dc361512ccaeba5dd31e90549e2fe4d0c1a3 (patch) | |
tree | a8a5c566a924feffd17f341cfb3e298498ee93d4 /src | |
parent | 74335bd32a7bef564d536ba9cf1be64714ceb8fa (diff) |
Support for decomposing scripts as "obj"
Diffstat (limited to 'src')
-rw-r--r-- | src/bitcoinrpc.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 34c43a9e3e..a189b2b2b0 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -155,6 +155,66 @@ void WalletTxToJSON(const CWalletTx& wtx, Object& entry) entry.push_back(Pair(item.first, item.second)); } +void +ScriptSigToJSON(const CTxIn& txin, Object& out) +{ + out.push_back(Pair("asm", txin.scriptSig.ToString())); + out.push_back(Pair("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()))); + + CTransaction txprev; + uint256 hashTxprevBlock; + if (!GetTransaction(txin.prevout.hash, txprev, hashTxprevBlock)) + return; + + txnouttype type; + vector<CBitcoinAddress> addresses; + int nRequired; + + if (!ExtractAddresses(txprev.vout[txin.prevout.n].scriptPubKey, type, + addresses, nRequired)) + { + out.push_back(Pair("type", GetTxnOutputType(TX_NONSTANDARD))); + return; + } + + out.push_back(Pair("type", GetTxnOutputType(type))); + if (type == TX_MULTISIG) + { + // TODO: Need to handle this specially since not all input addresses are required... + return; + } + + Array a; + BOOST_FOREACH(const CBitcoinAddress& addr, addresses) + a.push_back(addr.ToString()); + out.push_back(Pair("addresses", a)); +} + +void +ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out) +{ + txnouttype type; + vector<CBitcoinAddress> addresses; + int nRequired; + + out.push_back(Pair("asm", scriptPubKey.ToString())); + out.push_back(Pair("hex", HexStr(scriptPubKey.begin(), scriptPubKey.end()))); + + if (!ExtractAddresses(scriptPubKey, type, addresses, nRequired)) + { + out.push_back(Pair("type", GetTxnOutputType(TX_NONSTANDARD))); + return; + } + + out.push_back(Pair("reqSigs", nRequired)); + out.push_back(Pair("type", GetTxnOutputType(type))); + + Array a; + BOOST_FOREACH(const CBitcoinAddress& addr, addresses) + a.push_back(addr.ToString()); + out.push_back(Pair("addresses", a)); +} + void TxToJSON(const CTransaction &tx, Object& entry, const Object& decompositions) { entry.push_back(Pair("version", tx.nVersion)); @@ -184,6 +244,13 @@ void TxToJSON(const CTransaction &tx, Object& entry, const Object& decomposition case DM_ASM: in.push_back(Pair("scriptSig", txin.scriptSig.ToString())); break; + case DM_OBJ: + { + Object o; + ScriptSigToJSON(txin, o); + in.push_back(Pair("scriptSig", o)); + break; + } default: throw JSONRPCError(-18, "Invalid script decomposition"); } @@ -206,6 +273,13 @@ void TxToJSON(const CTransaction &tx, Object& entry, const Object& decomposition case DM_ASM: out.push_back(Pair("scriptPubKey", txout.scriptPubKey.ToString())); break; + case DM_OBJ: + { + Object o; + ScriptPubKeyToJSON(txout.scriptPubKey, o); + out.push_back(Pair("scriptPubKey", o)); + break; + } default: throw JSONRPCError(-18, "Invalid script decomposition"); } |