8 #if defined(HAVE_CONFIG_H)
26 #include <boost/assign/list_of.hpp>
27 #include "json/json_spirit_utils.h"
28 #include "json/json_spirit_value.h"
31 using namespace boost;
38 vector<CTxDestination> addresses;
41 out.push_back(Pair(
"asm", scriptPubKey.
ToString()));
43 out.push_back(Pair(
"hex",
HexStr(scriptPubKey.begin(), scriptPubKey.end())));
51 out.push_back(Pair(
"reqSigs", nRequired));
57 out.push_back(Pair(
"addresses", a));
63 entry.push_back(Pair(
"version", tx.
nVersion));
64 entry.push_back(Pair(
"locktime", (int64_t)tx.
nLockTime));
66 BOOST_FOREACH(
const CTxIn& txin, tx.
vin)
74 in.push_back(Pair(
"vout", (int64_t)txin.
prevout.
n));
78 in.push_back(Pair(
"scriptSig", o));
80 in.push_back(Pair(
"sequence", (int64_t)txin.
nSequence));
83 entry.push_back(Pair(
"vin", vin));
85 for (
unsigned int i = 0; i < tx.
vout.size(); i++)
90 out.push_back(Pair(
"n", (int64_t)i));
93 out.push_back(Pair(
"scriptPubKey", o));
96 entry.push_back(Pair(
"vout", vout));
100 entry.push_back(Pair(
"blockhash", hashBlock.
GetHex()));
101 map<uint256, CBlockIndex*>::iterator mi =
mapBlockIndex.find(hashBlock);
108 entry.push_back(Pair(
"time", (int64_t)pindex->
nTime));
109 entry.push_back(Pair(
"blocktime", (int64_t)pindex->
nTime));
112 entry.push_back(Pair(
"confirmations", 0));
119 if (fHelp || params.size() < 1 || params.size() > 2)
121 "getrawtransaction \"txid\" ( verbose )\n"
122 "\nReturn the raw transaction data.\n"
123 "\nIf verbose=0, returns a string that is serialized, hex-encoded data for 'txid'.\n"
124 "If verbose is non-zero, returns an Object with information about 'txid'.\n"
127 "1. \"txid\" (string, required) The transaction id\n"
128 "2. verbose (numeric, optional, default=0) If 0, return a string, other return a json object\n"
130 "\nResult (if verbose is not set or set to 0):\n"
131 "\"data\" (string) The serialized, hex-encoded data for 'txid'\n"
133 "\nResult (if verbose > 0):\n"
135 " \"hex\" : \"data\", (string) The serialized, hex-encoded data for 'txid'\n"
136 " \"txid\" : \"id\", (string) The transaction id (same as provided)\n"
137 " \"version\" : n, (numeric) The version\n"
138 " \"locktime\" : ttt, (numeric) The lock time\n"
139 " \"vin\" : [ (array of json objects)\n"
141 " \"txid\": \"id\", (string) The transaction id\n"
142 " \"vout\": n, (numeric) \n"
143 " \"scriptSig\": { (json object) The script\n"
144 " \"asm\": \"asm\", (string) asm\n"
145 " \"hex\": \"hex\" (string) hex\n"
147 " \"sequence\": n (numeric) The script sequence number\n"
151 " \"vout\" : [ (array of json objects)\n"
153 " \"value\" : x.xxx, (numeric) The value in btc\n"
154 " \"n\" : n, (numeric) index\n"
155 " \"scriptPubKey\" : { (json object)\n"
156 " \"asm\" : \"asm\", (string) the asm\n"
157 " \"hex\" : \"hex\", (string) the hex\n"
158 " \"reqSigs\" : n, (numeric) The required sigs\n"
159 " \"type\" : \"pubkeyhash\", (string) The type, eg 'pubkeyhash'\n"
160 " \"addresses\" : [ (json array of string)\n"
161 " \"anoncoinaddress\" (string) anoncoin address\n"
168 " \"blockhash\" : \"hash\", (string) the block hash\n"
169 " \"confirmations\" : n, (numeric) The confirmations\n"
170 " \"time\" : ttt, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT)\n"
171 " \"blocktime\" : ttt (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
182 bool fVerbose =
false;
183 if (params.size() > 1)
184 fVerbose = (params[1].get_int() != 0);
199 result.push_back(Pair(
"hex", strHex));
207 if (fHelp || params.size() > 3)
209 "listunspent ( minconf maxconf [\"address\",...] )\n"
210 "\nReturns array of unspent transaction outputs\n"
211 "with between minconf and maxconf (inclusive) confirmations.\n"
212 "Optionally filter to only include txouts paid to specified addresses.\n"
213 "Results are an array of Objects, each of which has:\n"
214 "{txid, vout, scriptPubKey, amount, confirmations}\n"
216 "1. minconf (numeric, optional, default=1) The minimum confirmationsi to filter\n"
217 "2. maxconf (numeric, optional, default=9999999) The maximum confirmations to filter\n"
218 "3. \"addresses\" (string) A json array of anoncoin addresses to filter\n"
220 " \"address\" (string) anoncoin address\n"
224 "[ (array of json object)\n"
226 " \"txid\" : \"txid\", (string) the transaction id \n"
227 " \"vout\" : n, (numeric) the vout value\n"
228 " \"address\" : \"address\", (string) the anoncoin address\n"
229 " \"account\" : \"account\", (string) The associated account, or \"\" for the default account\n"
230 " \"scriptPubKey\" : \"key\", (string) the script key\n"
231 " \"amount\" : x.xxx, (numeric) the transaction amount in btc\n"
232 " \"confirmations\" : n (numeric) The number of confirmations\n"
239 +
HelpExampleCli(
"listunspent",
"6 9999999 \"[\\\"1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\",\\\"1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\"]\"")
240 +
HelpExampleRpc(
"listunspent",
"6, 9999999 \"[\\\"1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\",\\\"1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\"]\"")
243 RPCTypeCheck(params, list_of(int_type)(int_type)(array_type));
246 if (params.size() > 0)
247 nMinDepth = params[0].get_int();
249 int nMaxDepth = 9999999;
250 if (params.size() > 1)
251 nMaxDepth = params[1].get_int();
253 set<CAnoncoinAddress> setAddress;
254 if (params.size() > 2)
256 Array inputs = params[2].get_array();
257 BOOST_FOREACH(Value& input, inputs)
260 if (!address.IsValid())
262 if (setAddress.count(address))
264 setAddress.insert(address);
269 vector<COutput> vecOutputs;
272 BOOST_FOREACH(
const COutput& out, vecOutputs)
277 if (setAddress.size())
283 if (!setAddress.count(address))
287 int64_t nValue = out.
tx->
vout[out.
i].nValue;
291 entry.push_back(Pair(
"vout", out.
i));
299 entry.push_back(Pair(
"scriptPubKey",
HexStr(pk.begin(), pk.end())));
305 const CScriptID& hash = boost::get<const CScriptID&>(address);
308 entry.push_back(Pair(
"redeemScript",
HexStr(redeemScript.begin(), redeemScript.end())));
312 entry.push_back(Pair(
"confirmations",out.
nDepth));
313 entry.push_back(Pair(
"spendable", out.
fSpendable));
314 results.push_back(entry);
323 if (fHelp || params.size() != 2)
325 "createrawtransaction [{\"txid\":\"id\",\"vout\":n},...] {\"address\":amount,...}\n"
326 "\nCreate a transaction spending the given inputs and sending to the given addresses.\n"
327 "Returns hex-encoded raw transaction.\n"
328 "Note that the transaction's inputs are not signed, and\n"
329 "it is not stored in the wallet or transmitted to the network.\n"
332 "1. \"transactions\" (string, required) A json array of json objects\n"
335 " \"txid\":\"id\", (string, required) The transaction id\n"
336 " \"vout\":n (numeric, required) The output number\n"
340 "2. \"addresses\" (string, required) a json object with addresses as keys and amounts as values\n"
342 " \"address\": x.xxx (numeric, required) The key is the anoncoin address, the value is the anc amount\n"
347 "\"transaction\" (string) hex string of the transaction\n"
350 +
HelpExampleCli(
"createrawtransaction",
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"{\\\"address\\\":0.01}\"")
351 +
HelpExampleRpc(
"createrawtransaction",
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"address\\\":0.01}\"")
356 Array inputs = params[0].get_array();
357 Object sendTo = params[1].get_obj();
361 BOOST_FOREACH(
const Value& input, inputs)
363 const Object& o = input.get_obj();
367 const Value& vout_v = find_value(o,
"vout");
368 if (vout_v.type() != int_type)
370 int nOutput = vout_v.get_int();
375 rawTx.
vin.push_back(in);
378 set<CAnoncoinAddress> setAddress;
379 BOOST_FOREACH(
const Pair& s, sendTo)
385 if (setAddress.count(address))
387 setAddress.insert(address);
393 CTxOut out(nAmount, scriptPubKey);
394 rawTx.
vout.push_back(out);
404 if (fHelp || params.size() != 1)
406 "decoderawtransaction \"hexstring\"\n"
407 "\nReturn a JSON object representing the serialized, hex-encoded transaction.\n"
410 "1. \"hex\" (string, required) The transaction hex string\n"
414 " \"txid\" : \"id\", (string) The transaction id\n"
415 " \"version\" : n, (numeric) The version\n"
416 " \"locktime\" : ttt, (numeric) The lock time\n"
417 " \"vin\" : [ (array of json objects)\n"
419 " \"txid\": \"id\", (string) The transaction id\n"
420 " \"vout\": n, (numeric) The output number\n"
421 " \"scriptSig\": { (json object) The script\n"
422 " \"asm\": \"asm\", (string) asm\n"
423 " \"hex\": \"hex\" (string) hex\n"
425 " \"sequence\": n (numeric) The script sequence number\n"
429 " \"vout\" : [ (array of json objects)\n"
431 " \"value\" : x.xxx, (numeric) The value in btc\n"
432 " \"n\" : n, (numeric) index\n"
433 " \"scriptPubKey\" : { (json object)\n"
434 " \"asm\" : \"asm\", (string) the asm\n"
435 " \"hex\" : \"hex\", (string) the hex\n"
436 " \"reqSigs\" : n, (numeric) The required sigs\n"
437 " \"type\" : \"pubkeyhash\", (string) The type, eg 'pubkeyhash'\n"
438 " \"addresses\" : [ (json array of string)\n"
439 " \"12tvKAXCxZjSmdNbao16dKXC8tRWfcF5oc\" (string) anoncoin address\n"
453 vector<unsigned char> txData(
ParseHexV(params[0],
"argument"));
459 catch (std::exception &e) {
471 if (fHelp || params.size() != 1)
473 "decodescript \"hex\"\n"
474 "\nDecode a hex-encoded script.\n"
476 "1. \"hex\" (string) the hex encoded script\n"
479 " \"asm\":\"asm\", (string) Script public key\n"
480 " \"hex\":\"hex\", (string) hex encoded public key\n"
481 " \"type\":\"type\", (string) The output type\n"
482 " \"reqSigs\": n, (numeric) The required signatures\n"
483 " \"addresses\": [ (json array of string)\n"
484 " \"address\" (string) anoncoin address\n"
487 " \"p2sh\",\"address\" (string) script address\n"
498 if (params[0].get_str().size() > 0){
499 vector<unsigned char> scriptData(
ParseHexV(params[0],
"argument"));
500 script =
CScript(scriptData.begin(), scriptData.end());
512 if (fHelp || params.size() < 1 || params.size() > 4)
514 "signrawtransaction \"hexstring\" ( [{\"txid\":\"id\",\"vout\":n,\"scriptPubKey\":\"hex\",\"redeemScript\":\"hex\"},...] [\"privatekey1\",...] sighashtype )\n"
515 "\nSign inputs for raw transaction (serialized, hex-encoded).\n"
516 "The second optional argument (may be null) is an array of previous transaction outputs that\n"
517 "this transaction depends on but may not yet be in the block chain.\n"
518 "The third optional argument (may be null) is an array of base58-encoded private\n"
519 "keys that, if given, will be the only keys used to sign the transaction.\n"
525 "1. \"hexstring\" (string, required) The transaction hex string\n"
526 "2. \"prevtxs\" (string, optional) An json array of previous dependent transaction outputs\n"
527 " [ (json array of json objects, or 'null' if none provided)\n"
529 " \"txid\":\"id\", (string, required) The transaction id\n"
530 " \"vout\":n, (numeric, required) The output number\n"
531 " \"scriptPubKey\": \"hex\", (string, required) script key\n"
532 " \"redeemScript\": \"hex\" (string, required for P2SH) redeem script\n"
536 "3. \"privatekeys\" (string, optional) A json array of base58-encoded private keys for signing\n"
537 " [ (json array of strings, or 'null' if none provided)\n"
538 " \"privatekey\" (string) private key in base58-encoding\n"
541 "4. \"sighashtype\" (string, optional, default=ALL) The signature hash type. Must be one of\n"
545 " \"ALL|ANYONECANPAY\"\n"
546 " \"NONE|ANYONECANPAY\"\n"
547 " \"SINGLE|ANYONECANPAY\"\n"
551 " \"hex\": \"value\", (string) The raw transaction with signature(s) (hex-encoded string)\n"
552 " \"complete\": n (numeric) if transaction has a complete set of signature (0 if not)\n"
560 RPCTypeCheck(params, list_of(str_type)(array_type)(array_type)(str_type),
true);
562 vector<unsigned char> txData(
ParseHexV(params[0],
"argument 1"));
564 vector<CTransaction> txVariants;
565 while (!ssData.
empty())
570 txVariants.push_back(tx);
572 catch (std::exception &e) {
577 if (txVariants.empty())
583 bool fComplete =
true;
594 BOOST_FOREACH(
const CTxIn& txin, mergedTx.
vin) {
603 bool fGivenKeys =
false;
605 if (params.size() > 2 && params[2].type() != null_type)
608 Array keys = params[2].get_array();
609 BOOST_FOREACH(Value k, keys)
612 bool fGood = vchSecret.
SetString(k.get_str());
625 if (params.size() > 1 && params[1].type() != null_type)
627 Array prevTxs = params[1].get_array();
628 BOOST_FOREACH(Value& p, prevTxs)
630 if (p.type() != obj_type)
633 Object prevOut = p.get_obj();
635 RPCTypeCheck(prevOut, map_list_of(
"txid", str_type)(
"vout", int_type)(
"scriptPubKey", str_type));
639 int nOut = find_value(prevOut,
"vout").get_int();
643 vector<unsigned char> pkData(
ParseHexO(prevOut,
"scriptPubKey"));
644 CScript scriptPubKey(pkData.begin(), pkData.end());
648 if (coins.IsAvailable(nOut) && coins.vout[nOut].scriptPubKey != scriptPubKey) {
649 string err(
"Previous output scriptPubKey mismatch:\n");
650 err = err + coins.vout[nOut].scriptPubKey.ToString() +
"\nvs:\n"+
651 scriptPubKey.ToString();
656 if ((
unsigned int)nOut >= coins.vout.size())
657 coins.vout.resize(nOut+1);
658 coins.vout[nOut].scriptPubKey = scriptPubKey;
659 coins.vout[nOut].nValue = 0;
664 if (fGivenKeys && scriptPubKey.IsPayToScriptHash())
666 RPCTypeCheck(prevOut, map_list_of(
"txid", str_type)(
"vout", int_type)(
"scriptPubKey", str_type)(
"redeemScript",str_type));
667 Value v = find_value(prevOut,
"redeemScript");
668 if (!(v == Value::null))
670 vector<unsigned char> rsData(
ParseHexV(v,
"redeemScript"));
671 CScript redeemScript(rsData.begin(), rsData.end());
681 const CKeyStore& keystore = tempKeystore;
685 if (params.size() > 3 && params[3].type() != null_type)
687 static map<string, int> mapSigHashValues =
688 boost::assign::map_list_of
696 string strHashType = params[3].get_str();
697 if (mapSigHashValues.count(strHashType))
698 nHashType = mapSigHashValues[strHashType];
706 for (
unsigned int i = 0; i < mergedTx.
vin.size(); i++)
719 if (!fHashSingle || (i < mergedTx.
vout.size()))
735 result.push_back(Pair(
"complete", fComplete));
742 if (fHelp || params.size() < 1 || params.size() > 2)
744 "sendrawtransaction \"hexstring\" ( allowhighfees )\n"
745 "\nSubmits raw transaction (serialized, hex-encoded) to local node and network.\n"
746 "\nAlso see createrawtransaction and signrawtransaction calls.\n"
748 "1. \"hexstring\" (string, required) The hex string of the raw transaction)\n"
749 "2. allowhighfees (boolean, optional, default=false) Allow high fees\n"
751 "\"hex\" (string) The transaction hash in hex\n"
753 "\nCreate a transaction\n"
754 +
HelpExampleCli(
"createrawtransaction",
"\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" \"{\\\"myaddress\\\":0.01}\"") +
755 "Sign the transaction, and get back the hex\n"
757 "\nSend the transaction (signed hex)\n"
759 "\nAs a json rpc call\n"
765 vector<unsigned char> txData(
ParseHexV(params[0],
"parameter"));
769 bool fOverrideFees =
false;
770 if (params.size() > 1)
771 fOverrideFees = params[1].get_bool();
777 catch (std::exception &e) {
785 bool fHaveChain = view.
GetCoins(hashTx, existingCoins) && existingCoins.
nHeight < 1000000000;
786 if (!fHaveMempool && !fHaveChain) {
797 }
else if (fHaveChain) {
Value createrawtransaction(const Array ¶ms, bool fHelp)
std::string HelpRequiringPassphrase()
const_iterator begin() const
CScript CombineSignatures(CScript scriptPubKey, const CTransaction &txTo, unsigned int nIn, const CScript &scriptSig1, const CScript &scriptSig2)
void SetBackend(CCoinsView &viewIn)
vector< unsigned char > ParseHexO(const Object &o, string strKey)
uint256 ParseHashO(const Object &o, string strKey)
std::vector< CTxOut > vout
std::map< CTxDestination, CAddressBookData > mapAddressBook
bool IsPayToScriptHash() const
std::string HelpExampleRpc(string methodname, string args)
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)
CTxDestination Get() const
const char * GetTxnOutputType(txnouttype t)
Double ended buffer combining vector and stream-like interfaces.
Object JSONRPCError(int code, const string &message)
pruned version of CTransaction: only retains metadata and unspent transaction outputs ...
void RPCTypeCheck(const Array ¶ms, const list< Value_type > &typesExpected, bool fAllowNull)
CChain chainActive
The currently-connected chain of blocks.
Value decodescript(const Array ¶ms, bool fHelp)
bool GetCoins(const uint256 &txid, CCoins &coins)
std::string ToString() const
bool IsAvailable(unsigned int nPos) const
void SetDestination(const CTxDestination &address)
virtual bool AddCScript(const CScript &redeemScript)
json_spirit::Value listunspent(const json_spirit::Array ¶ms, bool fHelp)
bool AcceptToMemoryPool(CTxMemPool &pool, CValidationState &state, const CTransaction &tx, bool fLimitFree, bool *pfMissingInputs, bool fRejectInsaneFee)
(try to) add transaction to memory pool
void ScriptPubKeyToJSON(const CScript &scriptPubKey, Object &out, bool fIncludeHex)
Value decoderawtransaction(const Array ¶ms, bool fHelp)
int Height() const
Return the maximal height in the chain.
Value ValueFromAmount(int64_t amount)
Abstract view on the open txout dataset.
An input of a transaction.
void EnsureWalletIsUnlocked()
A base58-encoded secret key.
std::vector< CTxOut > vout
void TxToJSON(const CTransaction &tx, const uint256 hashBlock, Object &entry)
base58-encoded Anoncoin addresses.
void RelayTransaction(const CTransaction &tx, const uint256 &hash)
bool SetString(const char *pszSecret)
An output of a transaction.
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)
std::string GetHex() const
std::string GetRejectReason() const
unsigned char GetRejectCode() const
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
Capture information about block/transaction validation.
void SyncWithWallets(const uint256 &hash, const CTransaction &tx, const CBlock *pblock)
Push an updated transaction to all registered wallets.
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.
vector< unsigned char > ParseHexV(const Value &v, string strName)
A virtual base class for key stores.
Value signrawtransaction(const Array ¶ms, bool fHelp)
bool exists(uint256 hash)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
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
int64_t AmountFromValue(const Value &value)
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)
uint256 ParseHashV(const Value &v, string strName)
std::string HelpExampleCli(string methodname, string args)
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)
CCoinsView that brings transactions from a memorypool into view.
map< uint256, CBlockIndex * > mapBlockIndex
Basic key store, that keeps keys in an address->secret map.
const_iterator end() const