aboutsummaryrefslogtreecommitdiff
path: root/src/rpcrawtransaction.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpcrawtransaction.cpp')
-rw-r--r--src/rpcrawtransaction.cpp311
1 files changed, 273 insertions, 38 deletions
diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp
index 49987ecc4..86025918e 100644
--- a/src/rpcrawtransaction.cpp
+++ b/src/rpcrawtransaction.cpp
@@ -3,14 +3,23 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-#include <boost/assign/list_of.hpp>
-
#include "base58.h"
-#include "bitcoinrpc.h"
-#include "db.h"
+#include "rpcserver.h"
#include "init.h"
#include "net.h"
+#include "uint256.h"
+#include "core.h"
+#include "main.h"
+#include "keystore.h"
+#ifdef ENABLE_WALLET
#include "wallet.h"
+#endif
+
+#include <stdint.h>
+
+#include <boost/assign/list_of.hpp>
+#include "json/json_spirit_utils.h"
+#include "json/json_spirit_value.h"
using namespace std;
using namespace boost;
@@ -74,7 +83,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
out.push_back(Pair("value", ValueFromAmount(txout.nValue)));
out.push_back(Pair("n", (boost::int64_t)i));
Object o;
- ScriptPubKeyToJSON(txout.scriptPubKey, o, false);
+ ScriptPubKeyToJSON(txout.scriptPubKey, o, true);
out.push_back(Pair("scriptPubKey", o));
vout.push_back(out);
}
@@ -103,11 +112,64 @@ Value getrawtransaction(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
- "getrawtransaction <txid> [verbose=0]\n"
- "If verbose=0, returns a string that is\n"
- "serialized, hex-encoded data for <txid>.\n"
- "If verbose is non-zero, returns an Object\n"
- "with information about <txid>.");
+ "getrawtransaction \"txid\" ( verbose )\n"
+ "\nReturn the raw transaction data.\n"
+ "\nIf verbose=0, returns a string that is serialized, hex-encoded data for 'txid'.\n"
+ "If verbose is non-zero, returns an Object with information about 'txid'.\n"
+
+ "\nArguments:\n"
+ "1. \"txid\" (string, required) The transaction id\n"
+ "2. verbose (numeric, optional, default=0) If 0, return a string, other return a json object\n"
+
+ "\nResult (if verbose is not set or set to 0):\n"
+ "\"data\" (string) The serialized, hex-encoded data for 'txid'\n"
+
+ "\nResult (if verbose > 0):\n"
+ "{\n"
+ " \"hex\" : \"data\", (string) The serialized, hex-encoded data for 'txid'\n"
+ " \"txid\" : \"id\", (string) The transaction id (same as provided)\n"
+ " \"version\" : n, (numeric) The version\n"
+ " \"locktime\" : ttt, (numeric) The lock time\n"
+ " \"vin\" : [ (array of json objects)\n"
+ " {\n"
+ " \"txid\": \"id\", (string) The transaction id\n"
+ " \"vout\": n, (numeric) \n"
+ " \"scriptSig\": { (json object) The script\n"
+ " \"asm\": \"asm\", (string) asm\n"
+ " \"hex\": \"hex\" (string) hex\n"
+ " },\n"
+ " \"sequence\": n (numeric) The script sequence number\n"
+ " }\n"
+ " ,...\n"
+ " ],\n"
+ " \"vout\" : [ (array of json objects)\n"
+ " {\n"
+ " \"value\" : x.xxx, (numeric) The value in btc\n"
+ " \"n\" : n, (numeric) index\n"
+ " \"scriptPubKey\" : { (json object)\n"
+ " \"asm\" : \"asm\", (string) the asm\n"
+ " \"hex\" : \"hex\", (string) the hex\n"
+ " \"reqSigs\" : n, (numeric) The required sigs\n"
+ " \"type\" : \"pubkeyhash\", (string) The type, eg 'pubkeyhash'\n"
+ " \"addresses\" : [ (json array of string)\n"
+ " \"bitcoinaddress\" (string) bitcoin address\n"
+ " ,...\n"
+ " ]\n"
+ " }\n"
+ " }\n"
+ " ,...\n"
+ " ],\n"
+ " \"blockhash\" : \"hash\", (string) the block hash\n"
+ " \"confirmations\" : n, (numeric) The confirmations\n"
+ " \"time\" : ttt, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT)\n"
+ " \"blocktime\" : ttt (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
+ "}\n"
+
+ "\nExamples:\n"
+ + HelpExampleCli("getrawtransaction", "\"mytxid\"")
+ + HelpExampleCli("getrawtransaction", "\"mytxid\" 1")
+ + HelpExampleRpc("getrawtransaction", "\"mytxid\", 1")
+ );
uint256 hash = ParseHashV(params[0], "parameter 1");
@@ -133,16 +195,44 @@ Value getrawtransaction(const Array& params, bool fHelp)
return result;
}
+#ifdef ENABLE_WALLET
Value listunspent(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 3)
throw runtime_error(
- "listunspent [minconf=1] [maxconf=9999999] [\"address\",...]\n"
- "Returns array of unspent transaction outputs\n"
+ "listunspent ( minconf maxconf [\"address\",...] )\n"
+ "\nReturns array of unspent transaction outputs\n"
"with between minconf and maxconf (inclusive) confirmations.\n"
- "Optionally filtered to only include txouts paid to specified addresses.\n"
+ "Optionally filter to only include txouts paid to specified addresses.\n"
"Results are an array of Objects, each of which has:\n"
- "{txid, vout, scriptPubKey, amount, confirmations}");
+ "{txid, vout, scriptPubKey, amount, confirmations}\n"
+ "\nArguments:\n"
+ "1. minconf (numeric, optional, default=1) The minimum confirmationsi to filter\n"
+ "2. maxconf (numeric, optional, default=9999999) The maximum confirmations to filter\n"
+ "3. \"addresses\" (string) A json array of bitcoin addresses to filter\n"
+ " [\n"
+ " \"address\" (string) bitcoin address\n"
+ " ,...\n"
+ " ]\n"
+ "\nResult\n"
+ "[ (array of json object)\n"
+ " {\n"
+ " \"txid\" : \"txid\", (string) the transaction id \n"
+ " \"vout\" : n, (numeric) the vout value\n"
+ " \"address\" : \"address\", (string) the bitcoin address\n"
+ " \"account\" : \"account\", (string) The associated account, or \"\" for the default account\n"
+ " \"scriptPubKey\" : \"key\", (string) the script key\n"
+ " \"amount\" : x.xxx, (numeric) the transaction amount in btc\n"
+ " \"confirmations\" : n (numeric) The number of confirmations\n"
+ " }\n"
+ " ,...\n"
+ "]\n"
+
+ "\nExamples\n"
+ + HelpExampleCli("listunspent", "")
+ + HelpExampleCli("listunspent", "6 9999999 \"[\\\"1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\",\\\"1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\"]\"")
+ + HelpExampleRpc("listunspent", "6, 9999999 \"[\\\"1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\",\\\"1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\"]\"")
+ );
RPCTypeCheck(params, list_of(int_type)(int_type)(array_type));
@@ -188,7 +278,7 @@ Value listunspent(const Array& params, bool fHelp)
continue;
}
- int64 nValue = out.tx->vout[out.i].nValue;
+ int64_t nValue = out.tx->vout[out.i].nValue;
const CScript& pk = out.tx->vout[out.i].scriptPubKey;
Object entry;
entry.push_back(Pair("txid", out.tx->GetHash().GetHex()));
@@ -219,18 +309,40 @@ Value listunspent(const Array& params, bool fHelp)
return results;
}
+#endif
Value createrawtransaction(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 2)
throw runtime_error(
- "createrawtransaction [{\"txid\":txid,\"vout\":n},...] {address:amount,...}\n"
- "Create a transaction spending given inputs\n"
- "(array of objects containing transaction id and output number),\n"
- "sending to given address(es).\n"
+ "createrawtransaction [{\"txid\":\"id\",\"vout\":n},...] {\"address\":amount,...}\n"
+ "\nCreate a transaction spending the given inputs and sending to the given addresses.\n"
"Returns hex-encoded raw transaction.\n"
"Note that the transaction's inputs are not signed, and\n"
- "it is not stored in the wallet or transmitted to the network.");
+ "it is not stored in the wallet or transmitted to the network.\n"
+
+ "\nArguments:\n"
+ "1. \"transactions\" (string, required) A json array of json objects\n"
+ " [\n"
+ " {\n"
+ " \"txid\":\"id\", (string, required) The transaction id\n"
+ " \"vout\":n (numeric, required) The output number\n"
+ " }\n"
+ " ,...\n"
+ " ]\n"
+ "2. \"addresses\" (string, required) a json object with addresses as keys and amounts as values\n"
+ " {\n"
+ " \"address\": x.xxx (numeric, required) The key is the bitcoin address, the value is the btc amount\n"
+ " ,...\n"
+ " }\n"
+
+ "\nResult:\n"
+ "\"transaction\" (string) hex string of the transaction\n"
+
+ "\nExamples\n"
+ + HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"{\\\"address\\\":0.01}\"")
+ + HelpExampleRpc("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"address\\\":0.01}\"")
+ );
RPCTypeCheck(params, list_of(array_type)(obj_type));
@@ -269,7 +381,7 @@ Value createrawtransaction(const Array& params, bool fHelp)
CScript scriptPubKey;
scriptPubKey.SetDestination(address.Get());
- int64 nAmount = AmountFromValue(s.value_);
+ int64_t nAmount = AmountFromValue(s.value_);
CTxOut out(nAmount, scriptPubKey);
rawTx.vout.push_back(out);
@@ -284,8 +396,57 @@ Value decoderawtransaction(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
- "decoderawtransaction <hex string>\n"
- "Return a JSON object representing the serialized, hex-encoded transaction.");
+ "decoderawtransaction \"hexstring\"\n"
+ "\nReturn a JSON object representing the serialized, hex-encoded transaction.\n"
+
+ "\nArguments:\n"
+ "1. \"txid\" (string, required) The transaction hex string\n"
+
+ "\nResult:\n"
+ "{\n"
+ " \"hex\" : \"data\", (string) The serialized, hex-encoded data for 'txid'\n"
+ " \"txid\" : \"id\", (string) The transaction id (same as provided)\n"
+ " \"version\" : n, (numeric) The version\n"
+ " \"locktime\" : ttt, (numeric) The lock time\n"
+ " \"vin\" : [ (array of json objects)\n"
+ " {\n"
+ " \"txid\": \"id\", (string) The transaction id\n"
+ " \"vout\": n, (numeric) The output number\n"
+ " \"scriptSig\": { (json object) The script\n"
+ " \"asm\": \"asm\", (string) asm\n"
+ " \"hex\": \"hex\" (string) hex\n"
+ " },\n"
+ " \"sequence\": n (numeric) The script sequence number\n"
+ " }\n"
+ " ,...\n"
+ " ],\n"
+ " \"vout\" : [ (array of json objects)\n"
+ " {\n"
+ " \"value\" : x.xxx, (numeric) The value in btc\n"
+ " \"n\" : n, (numeric) index\n"
+ " \"scriptPubKey\" : { (json object)\n"
+ " \"asm\" : \"asm\", (string) the asm\n"
+ " \"hex\" : \"hex\", (string) the hex\n"
+ " \"reqSigs\" : n, (numeric) The required sigs\n"
+ " \"type\" : \"pubkeyhash\", (string) The type, eg 'pubkeyhash'\n"
+ " \"addresses\" : [ (json array of string)\n"
+ " \"12tvKAXCxZjSmdNbao16dKXC8tRWfcF5oc\" (string) bitcoin address\n"
+ " ,...\n"
+ " ]\n"
+ " }\n"
+ " }\n"
+ " ,...\n"
+ " ],\n"
+ " \"blockhash\" : \"hash\", (string) the block hash\n"
+ " \"confirmations\" : n, (numeric) The confirmations\n"
+ " \"time\" : ttt, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT)\n"
+ " \"blocktime\" : ttt (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
+ "}\n"
+
+ "\nExamples:\n"
+ + HelpExampleCli("decoderawtransaction", "\"hexstring\"")
+ + HelpExampleRpc("decoderawtransaction", "\"hexstring\"")
+ );
vector<unsigned char> txData(ParseHexV(params[0], "argument"));
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
@@ -307,8 +468,26 @@ Value decodescript(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
- "decodescript <hex string>\n"
- "Decode a hex-encoded script.");
+ "decodescript \"hex\"\n"
+ "\nDecode a hex-encoded script.\n"
+ "\nArguments:\n"
+ "1. \"hex\" (string) the hex encoded script\n"
+ "\nResult:\n"
+ "{\n"
+ " \"asm\":\"asm\", (string) Script public key\n"
+ " \"hex\":\"hex\", (string) hex encoded public key\n"
+ " \"type\":\"type\", (string) The output type\n"
+ " \"reqSigs\": n, (numeric) The required signatures\n"
+ " \"addresses\": [ (json array of string)\n"
+ " \"address\" (string) bitcoin address\n"
+ " ,...\n"
+ " ],\n"
+ " \"p2sh\",\"address\" (string) script address\n"
+ "}\n"
+ "\nExamples:\n"
+ + HelpExampleCli("decodescript", "\"hexstring\"")
+ + HelpExampleRpc("decodescript", "\"hexstring\"")
+ );
RPCTypeCheck(params, list_of(str_type));
@@ -330,18 +509,51 @@ Value signrawtransaction(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 4)
throw runtime_error(
- "signrawtransaction <hex string> [{\"txid\":txid,\"vout\":n,\"scriptPubKey\":hex,\"redeemScript\":hex},...] [<privatekey1>,...] [sighashtype=\"ALL\"]\n"
- "Sign inputs for raw transaction (serialized, hex-encoded).\n"
- "Second optional argument (may be null) is an array of previous transaction outputs that\n"
+ "signrawtransaction \"hexstring\" ( [{\"txid\":\"id\",\"vout\":n,\"scriptPubKey\":\"hex\",\"redeemScript\":\"hex\"},...] [\"privatekey1\",...] sighashtype )\n"
+ "\nSign inputs for raw transaction (serialized, hex-encoded).\n"
+ "The second optional argument (may be null) is an array of previous transaction outputs that\n"
"this transaction depends on but may not yet be in the block chain.\n"
- "Third optional argument (may be null) is an array of base58-encoded private\n"
+ "The third optional argument (may be null) is an array of base58-encoded private\n"
"keys that, if given, will be the only keys used to sign the transaction.\n"
- "Fourth optional argument is a string that is one of six values; ALL, NONE, SINGLE or\n"
- "ALL|ANYONECANPAY, NONE|ANYONECANPAY, SINGLE|ANYONECANPAY.\n"
- "Returns json object with keys:\n"
- " hex : raw transaction with signature(s) (hex-encoded string)\n"
- " complete : 1 if transaction has a complete set of signature (0 if not)"
- + HelpRequiringPassphrase());
+#ifdef ENABLE_WALLET
+ + HelpRequiringPassphrase() + "\n"
+#endif
+
+ "\nArguments:\n"
+ "1. \"hexstring\" (string, required) The transaction hex string\n"
+ "2. \"prevtxs\" (string, optional) An json array of previous dependent transaction outputs\n"
+ " [ (json array of json objects)\n"
+ " {\n"
+ " \"txid\":\"id\", (string, required) The transaction id\n"
+ " \"vout\":n, (numeric, required) The output number\n"
+ " \"scriptPubKey\": \"hex\", (string, required) script key\n"
+ " \"redeemScript\": \"hex\" (string, required) redeem script\n"
+ " }\n"
+ " ,...\n"
+ " ]\n"
+ "3. \"privatekeys\" (string, optional) A json array of base58-encoded private keys for signing\n"
+ " [ (json array of strings)\n"
+ " \"privatekey\" (string) private key in base58-encoding\n"
+ " ,...\n"
+ " ]\n"
+ "4. \"sighashtype\" (string, optional, default=ALL) The signature has type. Must be one of\n"
+ " \"ALL\"\n"
+ " \"NONE\"\n"
+ " \"SINGLE\"\n"
+ " \"ALL|ANYONECANPAY\"\n"
+ " \"NONE|ANYONECANPAY\"\n"
+ " \"SINGLE|ANYONECANPAY\"\n"
+
+ "\nResult:\n"
+ "{\n"
+ " \"hex\": \"value\", (string) The raw transaction with signature(s) (hex-encoded string)\n"
+ " \"complete\": n (numeric) if transaction has a complete set of signature (0 if not)\n"
+ "}\n"
+
+ "\nExamples:\n"
+ + HelpExampleCli("signrawtransaction", "\"myhex\"")
+ + HelpExampleRpc("signrawtransaction", "\"myhex\"")
+ );
RPCTypeCheck(params, list_of(str_type)(array_type)(array_type)(str_type), true);
@@ -402,8 +614,10 @@ Value signrawtransaction(const Array& params, bool fHelp)
tempKeystore.AddKey(key);
}
}
+#ifdef ENABLE_WALLET
else
EnsureWalletIsUnlocked();
+#endif
// Add previous txouts given in the RPC call:
if (params.size() > 1 && params[1].type() != null_type)
@@ -459,7 +673,11 @@ Value signrawtransaction(const Array& params, bool fHelp)
}
}
+#ifdef ENABLE_WALLET
const CKeyStore& keystore = ((fGivenKeys || !pwalletMain) ? tempKeystore : *pwalletMain);
+#else
+ const CKeyStore& keystore = tempKeystore;
+#endif
int nHashType = SIGHASH_ALL;
if (params.size() > 3 && params[3].type() != null_type)
@@ -521,8 +739,25 @@ Value sendrawtransaction(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
- "sendrawtransaction <hex string> [allowhighfees=false]\n"
- "Submits raw transaction (serialized, hex-encoded) to local node and network.");
+ "sendrawtransaction \"hexstring\" ( allowhighfees )\n"
+ "\nSubmits raw transaction (serialized, hex-encoded) to local node and network.\n"
+ "\nAlso see createrawtransaction and signrawtransaction calls.\n"
+ "\nArguments:\n"
+ "1. \"hexstring\" (string, required) The hex string of the raw transaction)\n"
+ "2. allowhighfees (boolean, optional, default=false) Allow high fees\n"
+ "\nResult:\n"
+ "\"hex\" (string) The transaction hash in hex\n"
+ "\nExamples:\n"
+ "\nCreate a transaction\n"
+ + HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" \"{\\\"myaddress\\\":0.01}\"") +
+ "Sign the transaction, and get back the hex\n"
+ + HelpExampleCli("signrawtransaction", "\"myhex\"") +
+ "\nSend the transaction (signed hex)\n"
+ + HelpExampleCli("sendrawtransaction", "\"signedhex\"") +
+ "\nAs a json rpc call\n"
+ + HelpExampleRpc("sendrawtransaction", "\"signedhex\"")
+ );
+
// parse hex string from parameter
vector<unsigned char> txData(ParseHexV(params[0], "parameter"));
@@ -550,7 +785,7 @@ Value sendrawtransaction(const Array& params, bool fHelp)
if (!fHave) {
// push to local node
CValidationState state;
- if (!mempool.accept(state, tx, false, NULL, !fOverrideFees))
+ if (!AcceptToMemoryPool(mempool, state, tx, false, NULL, !fOverrideFees))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX rejected"); // TODO: report validation state
}
}