34 #include <boost/assign/list_of.hpp> 43 vector<CTxDestination> addresses;
55 out.push_back(
Pair(
"reqSigs", nRequired));
61 out.push_back(
Pair(
"addresses", a));
72 BOOST_FOREACH(
const CTxIn& txin, tx.
vin) {
103 for (
unsigned int i = 0; i < tx.
vout.size(); i++) {
108 out.push_back(
Pair(
"n", (int64_t)i));
111 out.push_back(
Pair(
"scriptPubKey", o));
126 if (!hashBlock.
IsNull()) {
146 if (fHelp || params.
size() < 1 || params.
size() > 2)
148 "getrawtransaction \"txid\" ( verbose )\n" 149 "\nNOTE: By default this function only works sometimes. This is when the tx is in the mempool\n" 150 "or there is an unspent output in the utxo for this transaction. To make it always work,\n" 151 "you need to maintain a transaction index, using the -txindex command line option.\n" 152 "\nReturn the raw transaction data.\n" 153 "\nIf verbose=0, returns a string that is serialized, hex-encoded data for 'txid'.\n" 154 "If verbose is non-zero, returns an Object with information about 'txid'.\n" 157 "1. \"txid\" (string, required) The transaction id\n" 158 "2. verbose (numeric, optional, default=0) If 0, return a string, other return a json object\n" 160 "\nResult (if verbose is not set or set to 0):\n" 161 "\"data\" (string) The serialized, hex-encoded data for 'txid'\n" 163 "\nResult (if verbose > 0):\n" 165 " \"hex\" : \"data\", (string) The serialized, hex-encoded data for 'txid'\n" 166 " \"txid\" : \"id\", (string) The transaction id (same as provided)\n" 167 " \"size\" : n, (numeric) The transaction size\n" 168 " \"version\" : n, (numeric) The version\n" 169 " \"locktime\" : ttt, (numeric) The lock time\n" 170 " \"vin\" : [ (array of json objects)\n" 172 " \"txid\": \"id\", (string) The transaction id\n" 173 " \"vout\": n, (numeric) \n" 174 " \"scriptSig\": { (json object) The script\n" 175 " \"asm\": \"asm\", (string) asm\n" 176 " \"hex\": \"hex\" (string) hex\n" 178 " \"sequence\": n (numeric) The script sequence number\n" 182 " \"vout\" : [ (array of json objects)\n" 184 " \"value\" : x.xxx, (numeric) The value in " +
CURRENCY_UNIT +
"\n" 185 " \"n\" : n, (numeric) index\n" 186 " \"scriptPubKey\" : { (json object)\n" 187 " \"asm\" : \"asm\", (string) the asm\n" 188 " \"hex\" : \"hex\", (string) the hex\n" 189 " \"reqSigs\" : n, (numeric) The required sigs\n" 190 " \"type\" : \"pubkeyhash\", (string) The type, eg 'pubkeyhash'\n" 191 " \"addresses\" : [ (json array of string)\n" 192 " \"dashaddress\" (string) dash address\n" 199 " \"blockhash\" : \"hash\", (string) the block hash\n" 200 " \"confirmations\" : n, (numeric) The confirmations\n" 201 " \"time\" : ttt, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT)\n" 202 " \"blocktime\" : ttt (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n" 215 bool fVerbose =
false;
216 if (params.
size() > 1)
217 fVerbose = (params[1].get_int() != 0);
237 if (fHelp || (params.
size() != 1 && params.
size() != 2))
239 "gettxoutproof [\"txid\",...] ( blockhash )\n" 240 "\nReturns a hex-encoded proof that \"txid\" was included in a block.\n" 241 "\nNOTE: By default this function only works sometimes. This is when there is an\n" 242 "unspent output in the utxo for this transaction. To make it always work,\n" 243 "you need to maintain a transaction index, using the -txindex command line option or\n" 244 "specify the block in which the transaction is included in manually (by blockhash).\n" 245 "\nReturn the raw transaction data.\n" 247 "1. \"txids\" (string) A json array of txids to filter\n" 249 " \"txid\" (string) A transaction hash\n" 252 "2. \"block hash\" (string, optional) If specified, looks for txid in the block with this hash\n" 254 "\"data\" (string) A string that is a serialized, hex-encoded data for the proof.\n" 258 +
HelpExampleCli(
"gettxoutproof",
"'[\"mytxid\",...]' \"blockhash\"")
259 +
HelpExampleRpc(
"gettxoutproof",
"[\"mytxid\",...], \"blockhash\"")
262 set<uint256> setTxids;
265 for (
unsigned int idx = 0; idx < txids.
size(); idx++) {
270 if (setTxids.count(hash))
272 setTxids.insert(hash);
281 if (params.
size() > 1)
283 hashBlock =
uint256S(params[1].get_str());
293 if (pblockindex == NULL)
307 unsigned int ntxFound = 0;
309 if (setTxids.count(tx.
GetHash()))
311 if (ntxFound != setTxids.size())
323 if (fHelp || params.
size() != 1)
325 "verifytxoutproof \"proof\"\n" 326 "\nVerifies that a proof points to a transaction in a block, returning the transaction it commits to\n" 327 "and throwing an RPC error if the block is not in our best chain\n" 329 "1. \"proof\" (string, required) The hex-encoded proof generated by gettxoutproof\n" 331 "[\"txid\"] (array, strings) The txid(s) which the proof commits to, or empty array if the proof is invalid\n" 344 vector<uint256> vMatch;
345 if (merkleBlock.txn.ExtractMatches(vMatch) != merkleBlock.header.hashMerkleRoot)
353 BOOST_FOREACH(
const uint256& hash, vMatch)
360 if (fHelp || params.
size() < 2 || params.
size() > 3)
362 "createrawtransaction [{\"txid\":\"id\",\"vout\":n},...] {\"address\":amount,\"data\":\"hex\",...} ( locktime )\n" 363 "\nCreate a transaction spending the given inputs and creating new outputs.\n" 364 "Outputs can be addresses or data.\n" 365 "Returns hex-encoded raw transaction.\n" 366 "Note that the transaction's inputs are not signed, and\n" 367 "it is not stored in the wallet or transmitted to the network.\n" 370 "1. \"transactions\" (string, required) A json array of json objects\n" 373 " \"txid\":\"id\", (string, required) The transaction id\n" 374 " \"vout\":n (numeric, required) The output number\n" 378 "2. \"outputs\" (string, required) a json object with outputs\n" 380 " \"address\": x.xxx (numeric or string, required) The key is the dash address, the numeric value (can be string) is the " +
CURRENCY_UNIT +
" amount\n" 381 " \"data\": \"hex\", (string, required) The key is \"data\", the value is hex encoded data\n" 384 "3. locktime (numeric, optional, default=0) Raw locktime. Non-0 value also locktime-activates inputs\n" 386 "\"transaction\" (string) hex string of the transaction\n" 389 +
HelpExampleCli(
"createrawtransaction",
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"{\\\"address\\\":0.01}\"")
390 +
HelpExampleCli(
"createrawtransaction",
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"{\\\"data\\\":\\\"00010203\\\"}\"")
391 +
HelpExampleRpc(
"createrawtransaction",
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"address\\\":0.01}\"")
392 +
HelpExampleRpc(
"createrawtransaction",
"\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"data\\\":\\\"00010203\\\"}\"")
397 if (params[0].isNull() || params[1].isNull())
405 if (params.
size() > 2 && !params[2].
isNull()) {
406 int64_t nLockTime = params[2].
get_int64();
407 if (nLockTime < 0 || nLockTime > std::numeric_limits<uint32_t>::max())
412 for (
unsigned int idx = 0; idx < inputs.
size(); idx++) {
413 const UniValue& input = inputs[idx];
421 int nOutput = vout_v.
get_int();
425 uint32_t nSequence = (rawTx.
nLockTime ? std::numeric_limits<uint32_t>::max() - 1 : std::numeric_limits<uint32_t>::max());
428 rawTx.
vin.push_back(in);
431 set<CBitcoinAddress> setAddress;
432 vector<string> addrList = sendTo.
getKeys();
433 BOOST_FOREACH(
const string& name_, addrList) {
435 if (name_ ==
"data") {
436 std::vector<unsigned char>
data =
ParseHexV(sendTo[name_].getValStr(),
"Data");
445 if (setAddress.count(address))
447 setAddress.insert(address);
462 if (fHelp || params.
size() != 1)
464 "decoderawtransaction \"hexstring\"\n" 465 "\nReturn a JSON object representing the serialized, hex-encoded transaction.\n" 468 "1. \"hex\" (string, required) The transaction hex string\n" 472 " \"txid\" : \"id\", (string) The transaction id\n" 473 " \"size\" : n, (numeric) The transaction size\n" 474 " \"version\" : n, (numeric) The version\n" 475 " \"locktime\" : ttt, (numeric) The lock time\n" 476 " \"vin\" : [ (array of json objects)\n" 478 " \"txid\": \"id\", (string) The transaction id\n" 479 " \"vout\": n, (numeric) The output number\n" 480 " \"scriptSig\": { (json object) The script\n" 481 " \"asm\": \"asm\", (string) asm\n" 482 " \"hex\": \"hex\" (string) hex\n" 484 " \"sequence\": n (numeric) The script sequence number\n" 488 " \"vout\" : [ (array of json objects)\n" 490 " \"value\" : x.xxx, (numeric) The value in " +
CURRENCY_UNIT +
"\n" 491 " \"n\" : n, (numeric) index\n" 492 " \"scriptPubKey\" : { (json object)\n" 493 " \"asm\" : \"asm\", (string) the asm\n" 494 " \"hex\" : \"hex\", (string) the hex\n" 495 " \"reqSigs\" : n, (numeric) The required sigs\n" 496 " \"type\" : \"pubkeyhash\", (string) The type, eg 'pubkeyhash'\n" 497 " \"addresses\" : [ (json array of string)\n" 498 " \"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg\" (string) Dash address\n" 528 if (fHelp || params.
size() != 1)
530 "decodescript \"hex\"\n" 531 "\nDecode a hex-encoded script.\n" 533 "1. \"hex\" (string) the hex encoded script\n" 536 " \"asm\":\"asm\", (string) Script public key\n" 537 " \"hex\":\"hex\", (string) hex encoded public key\n" 538 " \"type\":\"type\", (string) The output type\n" 539 " \"reqSigs\": n, (numeric) The required signatures\n" 540 " \"addresses\": [ (json array of string)\n" 541 " \"address\" (string) dash address\n" 544 " \"p2sh\",\"address\" (string) address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH).\n" 555 if (params[0].get_str().size() > 0){
556 vector<unsigned char> scriptData(
ParseHexV(params[0],
"argument"));
557 script =
CScript(scriptData.begin(), scriptData.end());
590 if (fHelp || params.
size() < 1 || params.
size() > 4)
592 "signrawtransaction \"hexstring\" ( [{\"txid\":\"id\",\"vout\":n,\"scriptPubKey\":\"hex\",\"redeemScript\":\"hex\"},...] [\"privatekey1\",...] sighashtype )\n" 593 "\nSign inputs for raw transaction (serialized, hex-encoded).\n" 594 "The second optional argument (may be null) is an array of previous transaction outputs that\n" 595 "this transaction depends on but may not yet be in the block chain.\n" 596 "The third optional argument (may be null) is an array of base58-encoded private\n" 597 "keys that, if given, will be the only keys used to sign the transaction.\n" 603 "1. \"hexstring\" (string, required) The transaction hex string\n" 604 "2. \"prevtxs\" (string, optional) An json array of previous dependent transaction outputs\n" 605 " [ (json array of json objects, or 'null' if none provided)\n" 607 " \"txid\":\"id\", (string, required) The transaction id\n" 608 " \"vout\":n, (numeric, required) The output number\n" 609 " \"scriptPubKey\": \"hex\", (string, required) script key\n" 610 " \"redeemScript\": \"hex\" (string, required for P2SH) redeem script\n" 614 "3. \"privatekeys\" (string, optional) A json array of base58-encoded private keys for signing\n" 615 " [ (json array of strings, or 'null' if none provided)\n" 616 " \"privatekey\" (string) private key in base58-encoding\n" 619 "4. \"sighashtype\" (string, optional, default=ALL) The signature hash type. Must be one of\n" 623 " \"ALL|ANYONECANPAY\"\n" 624 " \"NONE|ANYONECANPAY\"\n" 625 " \"SINGLE|ANYONECANPAY\"\n" 629 " \"hex\" : \"value\", (string) The hex-encoded raw transaction with signature(s)\n" 630 " \"complete\" : true|false, (boolean) If the transaction has a complete set of signatures\n" 631 " \"errors\" : [ (json array of objects) Script verification errors (if there are any)\n" 633 " \"txid\" : \"hash\", (string) The hash of the referenced, previous transaction\n" 634 " \"vout\" : n, (numeric) The index of the output to spent and used as input\n" 635 " \"scriptSig\" : \"hex\", (string) The hex-encoded signature script\n" 636 " \"sequence\" : n, (numeric) Script sequence number\n" 637 " \"error\" : \"text\" (string) Verification or signing error related to the input\n" 655 vector<unsigned char> txData(
ParseHexV(params[0],
"argument 1"));
657 vector<CMutableTransaction> txVariants;
658 while (!ssData.
empty()) {
662 txVariants.push_back(tx);
664 catch (
const std::exception&) {
669 if (txVariants.empty())
685 BOOST_FOREACH(
const CTxIn& txin, mergedTx.
vin) {
694 bool fGivenKeys =
false;
696 if (params.
size() > 2 && !params[2].
isNull()) {
699 for (
unsigned int idx = 0; idx < keys.
size(); idx++) {
717 if (params.
size() > 1 && !params[1].
isNull()) {
719 for (
unsigned int idx = 0; idx < prevTxs.
size(); idx++) {
734 vector<unsigned char> pkData(
ParseHexO(prevOut,
"scriptPubKey"));
735 CScript scriptPubKey(pkData.begin(), pkData.end());
739 if (coins->
IsAvailable(nOut) && coins->
vout[nOut].scriptPubKey != scriptPubKey) {
740 string err(
"Previous output scriptPubKey mismatch:\n");
745 if ((
unsigned int)nOut >= coins->
vout.size())
746 coins->
vout.resize(nOut+1);
747 coins->
vout[nOut].scriptPubKey = scriptPubKey;
748 coins->
vout[nOut].nValue = 0;
753 if (fGivenKeys && scriptPubKey.IsPayToScriptHash()) {
757 vector<unsigned char> rsData(
ParseHexV(v,
"redeemScript"));
758 CScript redeemScript(rsData.begin(), rsData.end());
768 const CKeyStore& keystore = tempKeystore;
772 if (params.
size() > 3 && !params[3].
isNull()) {
773 static map<string, int> mapSigHashValues =
774 boost::assign::map_list_of
782 string strHashType = params[3].
get_str();
783 if (mapSigHashValues.count(strHashType))
784 nHashType = mapSigHashValues[strHashType];
795 for (
unsigned int i = 0; i < mergedTx.
vin.size(); i++) {
806 if (!fHashSingle || (i < mergedTx.
vout.size()))
818 bool fComplete = vErrors.
empty();
822 result.push_back(
Pair(
"complete", fComplete));
823 if (!vErrors.
empty()) {
832 if (fHelp || params.
size() < 1 || params.
size() > 3)
834 "sendrawtransaction \"hexstring\" ( allowhighfees instantsend )\n" 835 "\nSubmits raw transaction (serialized, hex-encoded) to local node and network.\n" 836 "\nAlso see createrawtransaction and signrawtransaction calls.\n" 838 "1. \"hexstring\" (string, required) The hex string of the raw transaction)\n" 839 "2. allowhighfees (boolean, optional, default=false) Allow high fees\n" 840 "3. instantsend (boolean, optional, default=false) Use InstantSend to send this transaction\n" 842 "\"hex\" (string) The transaction hash in hex\n" 844 "\nCreate a transaction\n" 845 +
HelpExampleCli(
"createrawtransaction",
"\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" \"{\\\"myaddress\\\":0.01}\"") +
846 "Sign the transaction, and get back the hex\n" 848 "\nSend the transaction (signed hex)\n" 850 "\nAs a json rpc call\n" 863 bool fOverrideFees =
false;
864 if (params.
size() > 1)
865 fOverrideFees = params[1].get_bool();
867 bool fInstantSend =
false;
868 if (params.
size() > 2)
869 fInstantSend = params[2].get_bool();
874 bool fHaveChain = existingCoins && existingCoins->
nHeight < 1000000000;
875 if (!fHaveMempool && !fHaveChain) {
886 if (fMissingInputs) {
892 }
else if (fHaveChain) {
bool SetString(const char *pszSecret)
void EnsureWalletIsUnlocked()
UniValue gettxoutproof(const UniValue ¶ms, bool fHelp)
vector< unsigned char > ParseHexV(const UniValue &v, string strName)
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
enum ScriptError_t ScriptError
std::string GetRejectReason() const
CCriticalSection cs_wallet
const std::string CURRENCY_UNIT
uint256 ParseHashO(const UniValue &o, string strKey)
bool IsAvailable(unsigned int nPos) const
check whether a particular output is still available
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
const_iterator end() const
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
UniValue getrawtransaction(const UniValue ¶ms, bool fHelp)
bool ExtractDestinations(const CScript &scriptPubKey, txnouttype &typeRet, vector< CTxDestination > &addressRet, int &nRequiredRet)
bool AcceptToMemoryPool(CTxMemPool &pool, CValidationState &state, const CTransaction &tx, bool fLimitFree, bool *pfMissingInputs, bool fOverrideMempoolLimit, bool fRejectAbsurdFee, bool fDryRun)
bool IsHex(const string &str)
void TxToJSON(const CTransaction &tx, const uint256 hashBlock, UniValue &entry)
static CScript CombineSignatures(const CScript &scriptPubKey, const BaseSignatureChecker &checker, const txnouttype txType, const vector< valtype > &vSolutions, vector< valtype > &sigs1, vector< valtype > &sigs2)
static void TxInErrorToJSON(const CTxIn &txin, UniValue &vErrorsRet, const std::string &strMessage)
bool push_back(const UniValue &val)
UniValue ValueFromAmount(const CAmount &amount)
Ran out of memory during operation.
const UniValue & find_value(const UniValue &obj, const std::string &name)
std::vector< CTransaction > vtx
std::string ToString() const
int64_t get_int64() const
const char * ScriptErrorString(const ScriptError serror)
bool Contains(const CBlockIndex *pindex) const
bool exists(uint256 hash) const
CCoinsViewCache * pcoinsTip
std::vector< CTxOut > vout
unspent transaction outputs; spent outputs are .IsNull(); spent outputs at the end of the array are d...
const UniValue & get_obj() const
std::string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode=false)
unsigned int GetSerializeSize(char a, int, int=0)
std::vector< std::string > getKeys() const
const_iterator begin() const
uint256 uint256S(const char *str)
UniValue signrawtransaction(const UniValue ¶ms, bool fHelp)
UniValue createrawtransaction(const UniValue ¶ms, bool fHelp)
virtual bool AddCScript(const CScript &redeemScript)
Support for BIP 0013 : see https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki.
UniValue decoderawtransaction(const UniValue ¶ms, bool fHelp)
const char * GetTxnOutputType(txnouttype t)
void SetBackend(CCoinsView &viewIn)
std::string ToString() const
CCoinsModifier ModifyCoins(const uint256 &txid)
Unexpected type was passed as parameter.
CScript GetScriptForDestination(const CTxDestination &dest)
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
std::string HelpRequiringPassphrase()
bool GetSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value)
static std::pair< std::string, UniValue > Pair(const char *cKey, const char *cVal)
CAmount AmountFromValue(const UniValue &value)
unsigned int GetRejectCode() const
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *serror)
uint256 ParseHashV(const UniValue &v, string strName)
void RPCTypeCheckObj(const UniValue &o, const map< string, UniValue::VType > &typesExpected, bool fAllowNull)
std::vector< CTxOut > vout
UniValue sendrawtransaction(const UniValue ¶ms, bool fHelp)
std::string EncodeHexTx(const CTransaction &tx)
const std::vector< CTxIn > vin
CTxDestination Get() const
void RPCTypeCheck(const UniValue ¶ms, const list< UniValue::VType > &typesExpected, bool fAllowNull)
static const unsigned int STANDARD_SCRIPT_VERIFY_FLAGS
void ScriptPubKeyToJSON(const CScript &scriptPubKey, UniValue &out, bool fIncludeHex)
const CChainParams & Params()
static const int PROTOCOL_VERSION
const uint256 & GetHash() const
bool ProcessTxLockRequest(const CTxLockRequest &txLockRequest, CConnman &connman)
std::string GetHex() const
std::unique_ptr< CConnman > g_connman
const std::vector< CTxOut > vout
UniValue verifytxoutproof(const UniValue ¶ms, bool fHelp)
int64_t GetBlockTime() const
vector< unsigned char > ParseHexO(const UniValue &o, string strKey)
virtual bool AddKey(const CKey &key)
bool GetTransaction(const uint256 &hash, CTransaction &txOut, const Consensus::Params &consensusParams, uint256 &hashBlock, bool fAllowSlow)
bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos, const Consensus::Params &consensusParams)
int nHeight
height of the entry in the chain. The genesis block has height 0
bool SignSignature(const CKeyStore &keystore, const CScript &fromPubKey, CMutableTransaction &txTo, unsigned int nIn, int nHashType)
UniValue decodescript(const UniValue ¶ms, bool fHelp)
UniValue JSONRPCError(int code, const string &message)
const UniValue & get_array() const
std::string get_str() const
int nHeight
at which height this transaction was included in the active block chain
bool DecodeHexTx(CTransaction &tx, const std::string &strHexTx)
const CCoins * AccessCoins(const uint256 &txid) const