Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
rpcrawtransaction.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2012 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include <boost/assign/list_of.hpp>
7 
8 #include "base58.h"
9 #include "bitcoinrpc.h"
10 #include "db.h"
11 #include "init.h"
12 #include "main.h"
13 #include "net.h"
14 #include "wallet.h"
15 
16 using namespace std;
17 using namespace boost;
18 using namespace boost::assign;
19 using namespace json_spirit;
20 
21 //
22 // Utilities: convert hex-encoded Values
23 // (throws error if not hex).
24 //
25 uint256 ParseHashV(const Value& v, string strName)
26 {
27  string strHex;
28  if (v.type() == str_type)
29  strHex = v.get_str();
30  if (!IsHex(strHex)) // Note: IsHex("") is false
31  throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be hexadecimal string (not '"+strHex+"')");
32  uint256 result;
33  result.SetHex(strHex);
34  return result;
35 }
36 uint256 ParseHashO(const Object& o, string strKey)
37 {
38  return ParseHashV(find_value(o, strKey), strKey);
39 }
40 vector<unsigned char> ParseHexV(const Value& v, string strName)
41 {
42  string strHex;
43  if (v.type() == str_type)
44  strHex = v.get_str();
45  if (!IsHex(strHex))
46  throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be hexadecimal string (not '"+strHex+"')");
47  return ParseHex(strHex);
48 }
49 vector<unsigned char> ParseHexO(const Object& o, string strKey)
50 {
51  return ParseHexV(find_value(o, strKey), strKey);
52 }
53 
54 void ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out)
55 {
56  txnouttype type;
57  vector<CTxDestination> addresses;
58  int nRequired;
59 
60  out.push_back(Pair("asm", scriptPubKey.ToString()));
61  out.push_back(Pair("hex", HexStr(scriptPubKey.begin(), scriptPubKey.end())));
62 
63  if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired))
64  {
65  out.push_back(Pair("type", GetTxnOutputType(TX_NONSTANDARD)));
66  return;
67  }
68 
69  out.push_back(Pair("reqSigs", nRequired));
70  out.push_back(Pair("type", GetTxnOutputType(type)));
71 
72  Array a;
73  BOOST_FOREACH(const CTxDestination& addr, addresses)
74  a.push_back(CBitcoinAddress(addr).ToString());
75  out.push_back(Pair("addresses", a));
76 }
77 
78 void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
79 {
80  entry.push_back(Pair("txid", tx.GetHash().GetHex()));
81  entry.push_back(Pair("version", tx.nVersion));
82  entry.push_back(Pair("locktime", (boost::int64_t)tx.nLockTime));
83  Array vin;
84  BOOST_FOREACH(const CTxIn& txin, tx.vin)
85  {
86  Object in;
87  if (tx.IsCoinBase())
88  in.push_back(Pair("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())));
89  else
90  {
91  in.push_back(Pair("txid", txin.prevout.hash.GetHex()));
92  in.push_back(Pair("vout", (boost::int64_t)txin.prevout.n));
93  Object o;
94  o.push_back(Pair("asm", txin.scriptSig.ToString()));
95  o.push_back(Pair("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())));
96  in.push_back(Pair("scriptSig", o));
97  }
98  in.push_back(Pair("sequence", (boost::int64_t)txin.nSequence));
99  vin.push_back(in);
100  }
101  entry.push_back(Pair("vin", vin));
102  Array vout;
103  for (unsigned int i = 0; i < tx.vout.size(); i++)
104  {
105  const CTxOut& txout = tx.vout[i];
106  Object out;
107  out.push_back(Pair("value", ValueFromAmount(txout.nValue)));
108  out.push_back(Pair("n", (boost::int64_t)i));
109  Object o;
111  out.push_back(Pair("scriptPubKey", o));
112  vout.push_back(out);
113  }
114  entry.push_back(Pair("vout", vout));
115 
116  if (hashBlock != 0)
117  {
118  entry.push_back(Pair("blockhash", hashBlock.GetHex()));
119  map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashBlock);
120  if (mi != mapBlockIndex.end() && (*mi).second)
121  {
122  CBlockIndex* pindex = (*mi).second;
123  if (pindex->IsInMainChain())
124  {
125  entry.push_back(Pair("confirmations", 1 + nBestHeight - pindex->nHeight));
126  entry.push_back(Pair("time", (boost::int64_t)pindex->nTime));
127  entry.push_back(Pair("blocktime", (boost::int64_t)pindex->nTime));
128  }
129  else
130  entry.push_back(Pair("confirmations", 0));
131  }
132  }
133 }
134 
135 Value getrawtransaction(const Array& params, bool fHelp)
136 {
137  if (fHelp || params.size() < 1 || params.size() > 2)
138  throw runtime_error(
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>.");
144 
145  uint256 hash = ParseHashV(params[0], "parameter 1");
146 
147  bool fVerbose = false;
148  if (params.size() > 1)
149  fVerbose = (params[1].get_int() != 0);
150 
151  CTransaction tx;
152  uint256 hashBlock = 0;
153  if (!GetTransaction(hash, tx, hashBlock, true))
154  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction");
155 
156  CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
157  ssTx << tx;
158  string strHex = HexStr(ssTx.begin(), ssTx.end());
159 
160  if (!fVerbose)
161  return strHex;
162 
163  Object result;
164  result.push_back(Pair("hex", strHex));
165  TxToJSON(tx, hashBlock, result);
166  return result;
167 }
168 
169 Value listunspent(const Array& params, bool fHelp)
170 {
171  if (fHelp || params.size() > 3)
172  throw runtime_error(
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}");
179 
180  RPCTypeCheck(params, list_of(int_type)(int_type)(array_type));
181 
182  int nMinDepth = 1;
183  if (params.size() > 0)
184  nMinDepth = params[0].get_int();
185 
186  int nMaxDepth = 9999999;
187  if (params.size() > 1)
188  nMaxDepth = params[1].get_int();
189 
190  set<CBitcoinAddress> setAddress;
191  if (params.size() > 2)
192  {
193  Array inputs = params[2].get_array();
194  BOOST_FOREACH(Value& input, inputs)
195  {
196  CBitcoinAddress address(input.get_str());
197  if (!address.IsValid())
198  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Feathercoin address: ")+input.get_str());
199  if (setAddress.count(address))
200  throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+input.get_str());
201  setAddress.insert(address);
202  }
203  }
204 
205  Array results;
206  vector<COutput> vecOutputs;
207  assert(pwalletMain != NULL);
208  pwalletMain->AvailableCoins(vecOutputs, false);
209  BOOST_FOREACH(const COutput& out, vecOutputs)
210  {
211  if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth)
212  continue;
213 
214  if (setAddress.size())
215  {
216  CTxDestination address;
217  if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address))
218  continue;
219 
220  if (!setAddress.count(address))
221  continue;
222  }
223 
224  int64 nValue = out.tx->vout[out.i].nValue;
225  const CScript& pk = out.tx->vout[out.i].scriptPubKey;
226  Object entry;
227  entry.push_back(Pair("txid", out.tx->GetHash().GetHex()));
228  entry.push_back(Pair("vout", out.i));
229  CTxDestination address;
230  if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address))
231  {
232  entry.push_back(Pair("address", CBitcoinAddress(address).ToString()));
233  if (pwalletMain->mapAddressBook.count(address))
234  entry.push_back(Pair("account", pwalletMain->mapAddressBook[address]));
235  }
236  entry.push_back(Pair("scriptPubKey", HexStr(pk.begin(), pk.end())));
237  if (pk.IsPayToScriptHash())
238  {
239  CTxDestination address;
240  if (ExtractDestination(pk, address))
241  {
242  const CScriptID& hash = boost::get<const CScriptID&>(address);
243  CScript redeemScript;
244  if (pwalletMain->GetCScript(hash, redeemScript))
245  entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end())));
246  }
247  }
248  entry.push_back(Pair("amount",ValueFromAmount(nValue)));
249  entry.push_back(Pair("confirmations",out.nDepth));
250  results.push_back(entry);
251  }
252 
253  return results;
254 }
255 
256 Value createrawtransaction(const Array& params, bool fHelp)
257 {
258  if (fHelp || params.size() != 2)
259  throw runtime_error(
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.");
267 
268  RPCTypeCheck(params, list_of(array_type)(obj_type));
269 
270  Array inputs = params[0].get_array();
271  Object sendTo = params[1].get_obj();
272 
273  CTransaction rawTx;
274 
275  BOOST_FOREACH(const Value& input, inputs)
276  {
277  const Object& o = input.get_obj();
278 
279  uint256 txid = ParseHashO(o, "txid");
280 
281  const Value& vout_v = find_value(o, "vout");
282  if (vout_v.type() != int_type)
283  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key");
284  int nOutput = vout_v.get_int();
285  if (nOutput < 0)
286  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive");
287 
288  CTxIn in(COutPoint(txid, nOutput));
289  rawTx.vin.push_back(in);
290  }
291 
292  set<CBitcoinAddress> setAddress;
293  BOOST_FOREACH(const Pair& s, sendTo)
294  {
295  CBitcoinAddress address(s.name_);
296  if (!address.IsValid())
297  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Feathercoin address: ")+s.name_);
298 
299  if (setAddress.count(address))
300  throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+s.name_);
301  setAddress.insert(address);
302 
303  CScript scriptPubKey;
304  scriptPubKey.SetDestination(address.Get());
305  int64 nAmount = AmountFromValue(s.value_);
306 
307  CTxOut out(nAmount, scriptPubKey);
308  rawTx.vout.push_back(out);
309  }
310 
311  CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
312  ss << rawTx;
313  return HexStr(ss.begin(), ss.end());
314 }
315 
316 Value decoderawtransaction(const Array& params, bool fHelp)
317 {
318  if (fHelp || params.size() != 1)
319  throw runtime_error(
320  "decoderawtransaction <hex string>\n"
321  "Return a JSON object representing the serialized, hex-encoded transaction.");
322 
323  vector<unsigned char> txData(ParseHexV(params[0], "argument"));
324  CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
325  CTransaction tx;
326  try {
327  ssData >> tx;
328  }
329  catch (std::exception &e) {
330  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
331  }
332 
333  Object result;
334  TxToJSON(tx, 0, result);
335 
336  return result;
337 }
338 
339 Value signrawtransaction(const Array& params, bool fHelp)
340 {
341  if (fHelp || params.size() < 1 || params.size() > 4)
342  throw runtime_error(
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)"
355 
356  RPCTypeCheck(params, list_of(str_type)(array_type)(array_type)(str_type), true);
357 
358  vector<unsigned char> txData(ParseHexV(params[0], "argument 1"));
359  CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
360  vector<CTransaction> txVariants;
361  while (!ssData.empty())
362  {
363  try {
364  CTransaction tx;
365  ssData >> tx;
366  txVariants.push_back(tx);
367  }
368  catch (std::exception &e) {
369  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
370  }
371  }
372 
373  if (txVariants.empty())
374  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Missing transaction");
375 
376  // mergedTx will end up with all the signatures; it
377  // starts as a clone of the rawtx:
378  CTransaction mergedTx(txVariants[0]);
379  bool fComplete = true;
380 
381  // Fetch previous transactions (inputs):
382  CCoinsView viewDummy;
383  CCoinsViewCache view(viewDummy);
384  {
385  LOCK(mempool.cs);
386  CCoinsViewCache &viewChain = *pcoinsTip;
387  CCoinsViewMemPool viewMempool(viewChain, mempool);
388  view.SetBackend(viewMempool); // temporarily switch cache backend to db+mempool view
389 
390  BOOST_FOREACH(const CTxIn& txin, mergedTx.vin) {
391  const uint256& prevHash = txin.prevout.hash;
392  CCoins coins;
393  view.GetCoins(prevHash, coins); // this is certainly allowed to fail
394  }
395 
396  view.SetBackend(viewDummy); // switch back to avoid locking mempool for too long
397  }
398 
399  bool fGivenKeys = false;
400  CBasicKeyStore tempKeystore;
401  if (params.size() > 2 && params[2].type() != null_type)
402  {
403  fGivenKeys = true;
404  Array keys = params[2].get_array();
405  BOOST_FOREACH(Value k, keys)
406  {
407  CBitcoinSecret vchSecret;
408  bool fGood = vchSecret.SetString(k.get_str());
409  if (!fGood)
410  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key");
411  CKey key = vchSecret.GetKey();
412  tempKeystore.AddKey(key);
413  }
414  }
415  else
417 
418  // Add previous txouts given in the RPC call:
419  if (params.size() > 1 && params[1].type() != null_type)
420  {
421  Array prevTxs = params[1].get_array();
422  BOOST_FOREACH(Value& p, prevTxs)
423  {
424  if (p.type() != obj_type)
425  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "expected object with {\"txid'\",\"vout\",\"scriptPubKey\"}");
426 
427  Object prevOut = p.get_obj();
428 
429  RPCTypeCheck(prevOut, map_list_of("txid", str_type)("vout", int_type)("scriptPubKey", str_type));
430 
431  uint256 txid = ParseHashO(prevOut, "txid");
432 
433  int nOut = find_value(prevOut, "vout").get_int();
434  if (nOut < 0)
435  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "vout must be positive");
436 
437  vector<unsigned char> pkData(ParseHexO(prevOut, "scriptPubKey"));
438  CScript scriptPubKey(pkData.begin(), pkData.end());
439 
440  CCoins coins;
441  if (view.GetCoins(txid, coins)) {
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();
447  }
448  // what todo if txid is known, but the actual output isn't?
449  }
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; // we don't know the actual output value
454  view.SetCoins(txid, coins);
455 
456  // if redeemScript given and not using the local wallet (private keys
457  // given), add redeemScript to the tempKeystore so it can be signed:
458  if (fGivenKeys && scriptPubKey.IsPayToScriptHash())
459  {
460  RPCTypeCheck(prevOut, map_list_of("txid", str_type)("vout", int_type)("scriptPubKey", str_type)("redeemScript",str_type));
461  Value v = find_value(prevOut, "redeemScript");
462  if (!(v == Value::null))
463  {
464  vector<unsigned char> rsData(ParseHexV(v, "redeemScript"));
465  CScript redeemScript(rsData.begin(), rsData.end());
466  tempKeystore.AddCScript(redeemScript);
467  }
468  }
469  }
470  }
471 
472  const CKeyStore& keystore = ((fGivenKeys || !pwalletMain) ? tempKeystore : *pwalletMain);
473 
474  int nHashType = SIGHASH_ALL;
475  if (params.size() > 3 && params[3].type() != null_type)
476  {
477  static map<string, int> mapSigHashValues =
478  boost::assign::map_list_of
479  (string("ALL"), int(SIGHASH_ALL))
480  (string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY))
481  (string("NONE"), int(SIGHASH_NONE))
482  (string("NONE|ANYONECANPAY"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY))
483  (string("SINGLE"), int(SIGHASH_SINGLE))
484  (string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY))
485  ;
486  string strHashType = params[3].get_str();
487  if (mapSigHashValues.count(strHashType))
488  nHashType = mapSigHashValues[strHashType];
489  else
490  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid sighash param");
491  }
492 
493  bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE);
494 
495  // Sign what we can:
496  for (unsigned int i = 0; i < mergedTx.vin.size(); i++)
497  {
498  CTxIn& txin = mergedTx.vin[i];
499  CCoins coins;
500  if (!view.GetCoins(txin.prevout.hash, coins) || !coins.IsAvailable(txin.prevout.n))
501  {
502  fComplete = false;
503  continue;
504  }
505  const CScript& prevPubKey = coins.vout[txin.prevout.n].scriptPubKey;
506 
507  txin.scriptSig.clear();
508  // Only sign SIGHASH_SINGLE if there's a corresponding output:
509  if (!fHashSingle || (i < mergedTx.vout.size()))
510  SignSignature(keystore, prevPubKey, mergedTx, i, nHashType);
511 
512  // ... and merge in other signatures:
513  BOOST_FOREACH(const CTransaction& txv, txVariants)
514  {
515  txin.scriptSig = CombineSignatures(prevPubKey, mergedTx, i, txin.scriptSig, txv.vin[i].scriptSig);
516  }
517  if (!VerifyScript(txin.scriptSig, prevPubKey, mergedTx, i, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC, 0))
518  fComplete = false;
519  }
520 
521  Object result;
522  CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
523  ssTx << mergedTx;
524  result.push_back(Pair("hex", HexStr(ssTx.begin(), ssTx.end())));
525  result.push_back(Pair("complete", fComplete));
526 
527  return result;
528 }
529 
530 Value sendrawtransaction(const Array& params, bool fHelp)
531 {
532  if (fHelp || params.size() < 1 || params.size() > 1)
533  throw runtime_error(
534  "sendrawtransaction <hex string>\n"
535  "Submits raw transaction (serialized, hex-encoded) to local node and network.");
536 
537  // parse hex string from parameter
538  vector<unsigned char> txData(ParseHexV(params[0], "parameter"));
539  CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
540  CTransaction tx;
541 
542  // deserialize binary data stream
543  try {
544  ssData >> tx;
545  }
546  catch (std::exception &e) {
547  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
548  }
549  uint256 hashTx = tx.GetHash();
550 
551  bool fHave = false;
552  CCoinsViewCache &view = *pcoinsTip;
553  CCoins existingCoins;
554  {
555  fHave = view.GetCoins(hashTx, existingCoins);
556  if (!fHave) {
557  // push to local node
559  if (!tx.AcceptToMemoryPool(state, true, false))
560  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX rejected"); // TODO: report validation state
561  }
562  }
563  if (fHave) {
564  if (existingCoins.nHeight < 1000000000)
565  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "transaction already in block chain");
566  // Not in block, but already in the memory pool; will drop
567  // through to re-relay it.
568  } else {
569  SyncWithWallets(hashTx, tx, NULL, true);
570  }
571  RelayTransaction(tx, hashTx);
572 
573  return hashTx.GetHex();
574 }
const Object & get_obj() const
Value listunspent(const Array &params, bool fHelp)
void SetHex(const char *psz)
Definition: uint256.h:306
bool IsValid() const
Definition: base58.h:296
int nVersion
Definition: main.h:483
int i
Definition: wallet.h:700
Value createrawtransaction(const Array &params, bool fHelp)
uint256 ParseHashO(const Object &o, string strKey)
const_iterator begin() const
Definition: serialize.h:884
CScript scriptPubKey
Definition: main.h:404
Definition: util.cpp:28
CScript CombineSignatures(CScript scriptPubKey, const CTransaction &txTo, unsigned int nIn, const CScript &scriptSig1, const CScript &scriptSig2)
Definition: script.cpp:1671
void SetBackend(CCoinsView &viewIn)
Definition: main.cpp:196
CKey GetKey()
Definition: base58.h:415
std::vector< CTxOut > vout
Definition: main.h:903
bool AcceptToMemoryPool(CValidationState &state, bool fCheckInputs=true, bool fLimitFree=true, bool *pfMissingInputs=NULL)
Definition: main.cpp:822
bool IsPayToScriptHash() const
Definition: script.cpp:1734
int64 AmountFromValue(const Value &value)
Definition: bitcoinrpc.cpp:94
Value sendrawtransaction(const Array &params, bool fHelp)
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CTransaction &txTo, unsigned int nIn, unsigned int flags, int nHashType)
Definition: script.cpp:1477
bool SignSignature(const CKeyStore &keystore, const CScript &fromPubKey, CTransaction &txTo, unsigned int nIn, int nHashType)
Definition: script.cpp:1519
int nHeight
Definition: main.h:906
vector< unsigned char > ParseHexO(const Object &o, string strKey)
uint256 GetHash() const
Definition: main.h:515
const char * GetTxnOutputType(txnouttype t)
Definition: script.cpp:73
bool IsHex(const string &str)
Definition: util.cpp:490
Double ended buffer combining vector and stream-like interfaces.
Definition: serialize.h:799
pruned version of CTransaction: only retains metadata and unspent transaction outputs ...
Definition: main.h:896
unsigned int n
Definition: main.h:282
Object JSONRPCError(int code, const string &message)
Definition: bitcoinrpc.cpp:46
CTxDestination Get() const
Definition: base58.h:345
Config::Object_type Object
bool GetCoins(const uint256 &txid, CCoins &coins)
Definition: main.cpp:202
std::string ToString() const
Definition: script.h:561
bool IsAvailable(unsigned int nPos) const
Definition: main.h:1080
bool SetString(const char *pszSecret)
Definition: base58.h:440
void SetDestination(const CTxDestination &address)
Definition: script.cpp:1768
virtual bool AddCScript(const CScript &redeemScript)
Definition: keystore.cpp:29
Value_type type() const
Value decoderawtransaction(const Array &params, bool fHelp)
unsigned int nTime
Definition: main.h:1666
void RPCTypeCheck(const Array &params, const list< Value_type > &typesExpected, bool fAllowNull)
Definition: bitcoinrpc.cpp:54
unsigned int nLockTime
Definition: main.h:486
int nDepth
Definition: wallet.h:701
void EnsureWalletIsUnlocked()
Definition: rpcwallet.cpp:29
Abstract view on the open txout dataset.
Definition: main.h:2146
An input of a transaction.
Definition: main.h:323
#define LOCK(cs)
Definition: sync.h:108
A base58-encoded secret key.
Definition: base58.h:398
std::vector< CTxOut > vout
Definition: main.h:485
txnouttype
Definition: script.h:40
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
Definition: main.h:1763
vector< unsigned char > ParseHexV(const Value &v, string strName)
std::vector< CTxIn > vin
Definition: main.h:484
MTState * state
Definition: db_test.cc:1708
CWallet * pwalletMain
Definition: init.cpp:31
void RelayTransaction(const CTransaction &tx, const uint256 &hash)
Definition: net.cpp:1871
Config::Array_type Array
const String_type & get_str() const
An output of a transaction.
Definition: main.h:400
void SyncWithWallets(const uint256 &hash, const CTransaction &tx, const CBlock *pblock, bool fUpdate)
Push an updated transaction to all registered wallets.
Definition: main.cpp:129
void AvailableCoins(std::vector< COutput > &vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl=NULL) const
Definition: wallet.cpp:968
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: main.h:278
CCoinsViewCache * pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
Definition: main.cpp:289
virtual bool AddKey(const CKey &key)
Definition: keystore.cpp:18
uint256 ParseHashV(const Value &v, string strName)
std::string GetHex() const
Definition: uint256.h:298
CCriticalSection cs
Definition: main.h:2101
CTxMemPool mempool
Definition: main.cpp:34
CScript scriptSig
Definition: main.h:327
unsigned int nSequence
Definition: main.h:328
Capture information about block/transaction validation.
Definition: main.h:1907
256-bit unsigned integer
Definition: uint256.h:537
void ScriptPubKeyToJSON(const CScript &scriptPubKey, Object &out)
Value ValueFromAmount(int64 amount)
Definition: bitcoinrpc.cpp:105
bool ExtractDestinations(const CScript &scriptPubKey, txnouttype &typeRet, vector< CTxDestination > &addressRet, int &nRequiredRet)
Definition: script.cpp:1448
int64 nValue
Definition: main.h:403
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: main.h:1626
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:244
A virtual base class for key stores.
Definition: keystore.h:15
Value signrawtransaction(const Array &params, bool fHelp)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Definition: script.cpp:1422
const CWalletTx * tx
Definition: wallet.h:699
bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock, bool fAllowSlow)
Retrieve a transaction (from memory pool, or from disk, if possible)
Definition: main.cpp:968
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const
Definition: keystore.cpp:42
std::map< CTxDestination, std::string > mapAddressBook
Definition: wallet.h:119
Value getrawtransaction(const Array &params, bool fHelp)
bool IsCoinBase() const
Definition: main.h:566
signed long long int64_t
Definition: stdint.h:18
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition: key.h:32
bool SetCoins(const uint256 &txid, const CCoins &coins)
Definition: main.cpp:232
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
Definition: script.h:62
An encapsulated private key.
Definition: key.h:172
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: main.h:477
int nHeight
Definition: main.h:1639
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: main.h:2194
int nBestHeight
Definition: main.cpp:41
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
Definition: util.h:292
std::string HelpRequiringPassphrase()
Definition: rpcwallet.cpp:22
COutPoint prevout
Definition: main.h:326
Config::Pair_type Pair
CCoinsView that brings transactions from a memorypool into view.
Definition: main.h:2229
map< uint256, CBlockIndex * > mapBlockIndex
Definition: main.cpp:37
vector< unsigned char > ParseHex(const char *psz)
Definition: util.cpp:500
uint32_t hash
Definition: cache.cc:34
Basic key store, that keeps keys in an address->secret map.
Definition: keystore.h:43
bool empty() const
Definition: serialize.h:889
const_iterator end() const
Definition: serialize.h:886
uint256 hash
Definition: main.h:281
long long int64
Definition: serialize.h:25