6 #include <boost/assign/list_of.hpp>
17 using namespace boost;
57 vector<CTxDestination> addresses;
61 out.push_back(
Pair(
"hex",
HexStr(scriptPubKey.begin(), scriptPubKey.end())));
69 out.push_back(
Pair(
"reqSigs", nRequired));
75 out.push_back(
Pair(
"addresses", a));
84 BOOST_FOREACH(
const CTxIn& txin, tx.
vin)
96 in.push_back(
Pair(
"scriptSig", o));
101 entry.push_back(
Pair(
"vin", vin));
103 for (
unsigned int i = 0; i < tx.
vout.size(); i++)
111 out.push_back(
Pair(
"scriptPubKey", o));
114 entry.push_back(
Pair(
"vout", vout));
118 entry.push_back(
Pair(
"blockhash", hashBlock.
GetHex()));
119 map<uint256, CBlockIndex*>::iterator mi =
mapBlockIndex.find(hashBlock);
130 entry.push_back(
Pair(
"confirmations", 0));
137 if (fHelp || params.size() < 1 || params.size() > 2)
139 "getrawtransaction <txid> [verbose=0]\n"
140 "If verbose=0, returns a string that is\n"
141 "serialized, hex-encoded data for <txid>.\n"
142 "If verbose is non-zero, returns an Object\n"
143 "with information about <txid>.");
147 bool fVerbose =
false;
148 if (params.size() > 1)
149 fVerbose = (params[1].get_int() != 0);
164 result.push_back(
Pair(
"hex", strHex));
171 if (fHelp || params.size() > 3)
173 "listunspent [minconf=1] [maxconf=9999999] [\"address\",...]\n"
174 "Returns array of unspent transaction outputs\n"
175 "with between minconf and maxconf (inclusive) confirmations.\n"
176 "Optionally filtered to only include txouts paid to specified addresses.\n"
177 "Results are an array of Objects, each of which has:\n"
178 "{txid, vout, scriptPubKey, amount, confirmations}");
183 if (params.size() > 0)
184 nMinDepth = params[0].get_int();
186 int nMaxDepth = 9999999;
187 if (params.size() > 1)
188 nMaxDepth = params[1].get_int();
190 set<CBitcoinAddress> setAddress;
191 if (params.size() > 2)
193 Array inputs = params[2].get_array();
194 BOOST_FOREACH(
Value& input, inputs)
197 if (!address.IsValid())
199 if (setAddress.count(address))
201 setAddress.insert(address);
206 vector<COutput> vecOutputs;
209 BOOST_FOREACH(
const COutput& out, vecOutputs)
214 if (setAddress.size())
220 if (!setAddress.count(address))
228 entry.push_back(
Pair(
"vout", out.
i));
236 entry.push_back(
Pair(
"scriptPubKey",
HexStr(pk.begin(), pk.end())));
242 const CScriptID&
hash = boost::get<const CScriptID&>(address);
245 entry.push_back(
Pair(
"redeemScript",
HexStr(redeemScript.begin(), redeemScript.end())));
249 entry.push_back(
Pair(
"confirmations",out.
nDepth));
250 results.push_back(entry);
258 if (fHelp || params.size() != 2)
260 "createrawtransaction [{\"txid\":txid,\"vout\":n},...] {address:amount,...}\n"
261 "Create a transaction spending given inputs\n"
262 "(array of objects containing transaction id and output number),\n"
263 "sending to given address(es).\n"
264 "Returns hex-encoded raw transaction.\n"
265 "Note that the transaction's inputs are not signed, and\n"
266 "it is not stored in the wallet or transmitted to the network.");
270 Array inputs = params[0].get_array();
271 Object sendTo = params[1].get_obj();
275 BOOST_FOREACH(
const Value& input, inputs)
284 int nOutput = vout_v.
get_int();
289 rawTx.
vin.push_back(in);
292 set<CBitcoinAddress> setAddress;
293 BOOST_FOREACH(
const Pair& s, sendTo)
299 if (setAddress.count(address))
301 setAddress.insert(address);
307 CTxOut out(nAmount, scriptPubKey);
308 rawTx.
vout.push_back(out);
318 if (fHelp || params.size() != 1)
320 "decoderawtransaction <hex string>\n"
321 "Return a JSON object representing the serialized, hex-encoded transaction.");
323 vector<unsigned char> txData(
ParseHexV(params[0],
"argument"));
329 catch (std::exception &e) {
341 if (fHelp || params.size() < 1 || params.size() > 4)
343 "signrawtransaction <hex string> [{\"txid\":txid,\"vout\":n,\"scriptPubKey\":hex,\"redeemScript\":hex},...] [<privatekey1>,...] [sighashtype=\"ALL\"]\n"
344 "Sign inputs for raw transaction (serialized, hex-encoded).\n"
345 "Second optional argument (may be null) is an array of previous transaction outputs that\n"
346 "this transaction depends on but may not yet be in the block chain.\n"
347 "Third optional argument (may be null) is an array of base58-encoded private\n"
348 "keys that, if given, will be the only keys used to sign the transaction.\n"
349 "Fourth optional argument is a string that is one of six values; ALL, NONE, SINGLE or\n"
350 "ALL|ANYONECANPAY, NONE|ANYONECANPAY, SINGLE|ANYONECANPAY.\n"
351 "Returns json object with keys:\n"
352 " hex : raw transaction with signature(s) (hex-encoded string)\n"
353 " complete : 1 if transaction has a complete set of signature (0 if not)"
358 vector<unsigned char> txData(
ParseHexV(params[0],
"argument 1"));
360 vector<CTransaction> txVariants;
361 while (!ssData.
empty())
366 txVariants.push_back(tx);
368 catch (std::exception &e) {
373 if (txVariants.empty())
379 bool fComplete =
true;
390 BOOST_FOREACH(
const CTxIn& txin, mergedTx.
vin) {
399 bool fGivenKeys =
false;
401 if (params.size() > 2 && params[2].type() !=
null_type)
404 Array keys = params[2].get_array();
405 BOOST_FOREACH(
Value k, keys)
419 if (params.size() > 1 && params[1].type() !=
null_type)
421 Array prevTxs = params[1].get_array();
422 BOOST_FOREACH(
Value& p, prevTxs)
433 int nOut =
find_value(prevOut,
"vout").get_int();
437 vector<unsigned char> pkData(
ParseHexO(prevOut,
"scriptPubKey"));
438 CScript scriptPubKey(pkData.begin(), pkData.end());
442 if (coins.IsAvailable(nOut) && coins.vout[nOut].scriptPubKey != scriptPubKey) {
443 string err(
"Previous output scriptPubKey mismatch:\n");
444 err = err + coins.vout[nOut].scriptPubKey.ToString() +
"\nvs:\n"+
445 scriptPubKey.ToString();
450 if ((
unsigned int)nOut >= coins.vout.size())
451 coins.vout.resize(nOut+1);
452 coins.vout[nOut].scriptPubKey = scriptPubKey;
453 coins.vout[nOut].nValue = 0;
458 if (fGivenKeys && scriptPubKey.IsPayToScriptHash())
462 if (!(v == Value::null))
464 vector<unsigned char> rsData(
ParseHexV(v,
"redeemScript"));
465 CScript redeemScript(rsData.begin(), rsData.end());
475 if (params.size() > 3 && params[3].type() !=
null_type)
477 static map<string, int> mapSigHashValues =
478 boost::assign::map_list_of
486 string strHashType = params[3].get_str();
487 if (mapSigHashValues.count(strHashType))
488 nHashType = mapSigHashValues[strHashType];
496 for (
unsigned int i = 0; i < mergedTx.
vin.size(); i++)
509 if (!fHashSingle || (i < mergedTx.
vout.size()))
525 result.push_back(
Pair(
"complete", fComplete));
532 if (fHelp || params.size() < 1 || params.size() > 1)
534 "sendrawtransaction <hex string>\n"
535 "Submits raw transaction (serialized, hex-encoded) to local node and network.");
538 vector<unsigned char> txData(
ParseHexV(params[0],
"parameter"));
546 catch (std::exception &e) {
555 fHave = view.
GetCoins(hashTx, existingCoins);
564 if (existingCoins.
nHeight < 1000000000)
const Object & get_obj() const
Value listunspent(const Array ¶ms, bool fHelp)
void SetHex(const char *psz)
Value createrawtransaction(const Array ¶ms, bool fHelp)
uint256 ParseHashO(const Object &o, string strKey)
const_iterator begin() const
CScript CombineSignatures(CScript scriptPubKey, const CTransaction &txTo, unsigned int nIn, const CScript &scriptSig1, const CScript &scriptSig2)
void SetBackend(CCoinsView &viewIn)
std::vector< CTxOut > vout
bool AcceptToMemoryPool(CValidationState &state, bool fCheckInputs=true, bool fLimitFree=true, bool *pfMissingInputs=NULL)
bool IsPayToScriptHash() const
int64 AmountFromValue(const Value &value)
Value sendrawtransaction(const Array ¶ms, bool fHelp)
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CTransaction &txTo, unsigned int nIn, unsigned int flags, int nHashType)
bool SignSignature(const CKeyStore &keystore, const CScript &fromPubKey, CTransaction &txTo, unsigned int nIn, int nHashType)
vector< unsigned char > ParseHexO(const Object &o, string strKey)
const char * GetTxnOutputType(txnouttype t)
bool IsHex(const string &str)
Double ended buffer combining vector and stream-like interfaces.
pruned version of CTransaction: only retains metadata and unspent transaction outputs ...
Object JSONRPCError(int code, const string &message)
CTxDestination Get() const
Config::Object_type Object
bool GetCoins(const uint256 &txid, CCoins &coins)
std::string ToString() const
bool IsAvailable(unsigned int nPos) const
bool SetString(const char *pszSecret)
void SetDestination(const CTxDestination &address)
virtual bool AddCScript(const CScript &redeemScript)
Value decoderawtransaction(const Array ¶ms, bool fHelp)
void RPCTypeCheck(const Array ¶ms, const list< Value_type > &typesExpected, bool fAllowNull)
void EnsureWalletIsUnlocked()
Abstract view on the open txout dataset.
An input of a transaction.
A base58-encoded secret key.
std::vector< CTxOut > vout
const Object_type::value_type::Value_type & find_value(const Object_type &obj, const String_type &name)
void TxToJSON(const CTransaction &tx, const uint256 hashBlock, Object &entry)
bool IsInMainChain() const
vector< unsigned char > ParseHexV(const Value &v, string strName)
void RelayTransaction(const CTransaction &tx, const uint256 &hash)
const String_type & get_str() const
An output of a transaction.
void SyncWithWallets(const uint256 &hash, const CTransaction &tx, const CBlock *pblock, bool fUpdate)
Push an updated transaction to all registered wallets.
void AvailableCoins(std::vector< COutput > &vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl=NULL) const
An outpoint - a combination of a transaction hash and an index n into its vout.
CCoinsViewCache * pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
virtual bool AddKey(const CKey &key)
uint256 ParseHashV(const Value &v, string strName)
std::string GetHex() const
Capture information about block/transaction validation.
void ScriptPubKeyToJSON(const CScript &scriptPubKey, Object &out)
Value ValueFromAmount(int64 amount)
bool ExtractDestinations(const CScript &scriptPubKey, txnouttype &typeRet, vector< CTxDestination > &addressRet, int &nRequiredRet)
The block chain is a tree shaped structure starting with the genesis block at the root...
Serialized script, used inside transaction inputs and outputs.
A virtual base class for key stores.
Value signrawtransaction(const Array ¶ms, bool fHelp)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock, bool fAllowSlow)
Retrieve a transaction (from memory pool, or from disk, if possible)
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const
std::map< CTxDestination, std::string > mapAddressBook
Value getrawtransaction(const Array ¶ms, bool fHelp)
A reference to a CScript: the Hash160 of its serialization (see script.h)
bool SetCoins(const uint256 &txid, const CCoins &coins)
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
An encapsulated private key.
The basic transaction that is broadcasted on the network and contained in blocks. ...
CCoinsView that adds a memory cache for transactions to another CCoinsView.
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
std::string HelpRequiringPassphrase()
CCoinsView that brings transactions from a memorypool into view.
map< uint256, CBlockIndex * > mapBlockIndex
vector< unsigned char > ParseHex(const char *psz)
Basic key store, that keeps keys in an address->secret map.
const_iterator end() const