20 #include <boost/assign/list_of.hpp>
21 #include "json/json_spirit_utils.h"
22 #include "json/json_spirit_value.h"
25 using namespace boost;
29 Value
getinfo(
const Array& params,
bool fHelp)
31 if (fHelp || params.size() != 0)
34 "Returns an object containing various state info.\n"
37 " \"version\": xxxxx, (numeric) the server version\n"
38 " \"protocolversion\": xxxxx, (numeric) the protocol version\n"
39 " \"walletversion\": xxxxx, (numeric) the wallet version\n"
40 " \"balance\": xxxxxxx, (numeric) the total bitcoin balance of the wallet\n"
41 " \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n"
42 " \"timeoffset\": xxxxx, (numeric) the time offset\n"
43 " \"connections\": xxxxx, (numeric) the number of connections\n"
44 " \"proxy\": \"host:port\", (string, optional) the proxy used by the server\n"
45 " \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
46 " \"testnet\": true|false, (boolean) if the server is using testnet or not\n"
47 " \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since GMT epoch) of the oldest pre-generated key in the key pool\n"
48 " \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated\n"
49 " \"unlocked_until\": ttt, (numeric) the timestamp in seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is unlocked for transfers, or 0 if the wallet is locked\n"
50 " \"paytxfee\": x.xxxx, (numeric) the transaction fee set in btc/kb\n"
51 " \"relayfee\": x.xxxx, (numeric) minimum relay fee for non-free transactions in btc/kb\n"
52 " \"errors\": \"...\" (string) any error messages\n"
73 obj.push_back(Pair(
"connections", (
int)
vNodes.size()));
74 obj.push_back(Pair(
"proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string())));
76 obj.push_back(Pair(
"testnet",
TestNet()));
87 obj.push_back(Pair(
"errors",
GetWarnings(
"statusbar")));
92 class DescribeAddressVisitor :
public boost::static_visitor<Object>
95 Object operator()(
const CNoDestination &dest)
const {
return Object(); }
97 Object operator()(
const CKeyID &keyID)
const {
101 obj.push_back(Pair(
"isscript",
false));
102 obj.push_back(Pair(
"pubkey",
HexStr(vchPubKey)));
103 obj.push_back(Pair(
"iscompressed", vchPubKey.
IsCompressed()));
107 Object operator()(
const CScriptID &scriptID)
const {
109 obj.push_back(Pair(
"isscript",
true));
112 std::vector<CTxDestination> addresses;
117 obj.push_back(Pair(
"hex",
HexStr(subscript.begin(), subscript.end())));
121 obj.push_back(Pair("addresses", a));
123 obj.push_back(Pair("sigsrequired", nRequired));
131 if (fHelp || params.size() != 1)
133 "validateaddress \"bitcoinaddress\"\n"
134 "\nReturn information about the given bitcoin address.\n"
136 "1. \"bitcoinaddress\" (string, required) The bitcoin address to validate\n"
139 " \"isvalid\" : true|false, (boolean) If the address is valid or not. If not, this is the only property returned.\n"
140 " \"address\" : \"bitcoinaddress\", (string) The bitcoin address validated\n"
141 " \"ismine\" : true|false, (boolean) If the address is yours or not\n"
142 " \"isscript\" : true|false, (boolean) If the key is a script\n"
143 " \"pubkey\" : \"publickeyhex\", (string) The hex value of the raw public key\n"
144 " \"iscompressed\" : true|false, (boolean) If the address is compressed\n"
145 " \"account\" : \"account\" (string) The account associated with the address, \"\" is the default account\n"
148 +
HelpExampleCli(
"validateaddress",
"\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
149 +
HelpExampleRpc(
"validateaddress",
"\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
153 bool isValid = address.
IsValid();
156 ret.push_back(Pair(
"isvalid", isValid));
160 string currentAddress = address.
ToString();
161 ret.push_back(Pair(
"address", currentAddress));
164 ret.push_back(Pair(
"ismine", fMine));
166 Object detail = boost::apply_visitor(DescribeAddressVisitor(), dest);
167 ret.insert(ret.end(), detail.begin(), detail.end());
181 int nRequired = params[0].get_int();
182 const Array& keys = params[1].get_array();
186 throw runtime_error(
"a multisignature address must require at least one key to redeem");
187 if ((
int)keys.size() < nRequired)
190 "(got %u keys, but need at least %d to redeem)", keys.size(), nRequired));
191 std::vector<CPubKey> pubkeys;
192 pubkeys.resize(keys.size());
193 for (
unsigned int i = 0; i < keys.size(); i++)
195 const std::string& ks = keys[i].get_str();
204 strprintf(
"%s does not refer to a key",ks));
208 strprintf(
"no full public key for address %s",ks));
210 throw runtime_error(
" Invalid public key: "+ks);
211 pubkeys[i] = vchPubKey;
221 throw runtime_error(
" Invalid public key: "+ks);
222 pubkeys[i] = vchPubKey;
226 throw runtime_error(
" Invalid public key: "+ks);
241 if (fHelp || params.size() < 2 || params.size() > 2)
243 string msg =
"createmultisig nrequired [\"key\",...]\n"
244 "\nCreates a multi-signature address with n signature of m keys required.\n"
245 "It returns a json object with the address and redeemScript.\n"
248 "1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.\n"
249 "2. \"keys\" (string, required) A json array of keys which are bitcoin addresses or hex-encoded public keys\n"
251 " \"key\" (string) bitcoin address or hex-encoded public key\n"
257 " \"address\":\"multisigaddress\", (string) The value of the new multisig address.\n"
258 " \"redeemScript\":\"script\" (string) The string value of the hex-encoded redemption script.\n"
262 "\nCreate a multisig address from 2 addresses\n"
263 +
HelpExampleCli(
"createmultisig",
"2 \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") +
264 "\nAs a json rpc call\n"
265 +
HelpExampleRpc(
"createmultisig",
"2, \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"")
267 throw runtime_error(msg);
276 result.push_back(Pair(
"address", address.
ToString()));
277 result.push_back(Pair(
"redeemScript",
HexStr(inner.begin(), inner.end())));
284 if (fHelp || params.size() != 3)
286 "verifymessage \"bitcoinaddress\" \"signature\" \"message\"\n"
287 "\nVerify a signed message\n"
289 "1. \"bitcoinaddress\" (string, required) The bitcoin address to use for the signature.\n"
290 "2. \"signature\" (string, required) The signature provided by the signer in base 64 encoding (see signmessage).\n"
291 "3. \"message\" (string, required) The message that was signed.\n"
293 "true|false (boolean) If the signature is verified or not.\n"
295 "\nUnlock the wallet for 30 seconds\n"
297 "\nCreate the signature\n"
298 +
HelpExampleCli(
"signmessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"my message\"") +
299 "\nVerify the signature\n"
300 +
HelpExampleCli(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"signature\" \"my message\"") +
302 +
HelpExampleRpc(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\", \"signature\", \"my message\"")
305 string strAddress = params[0].get_str();
306 string strSign = params[1].get_str();
307 string strMessage = params[2].get_str();
317 bool fInvalid =
false;
318 vector<unsigned char> vchSig =
DecodeBase64(strSign.c_str(), &fInvalid);
331 return (pubkey.
GetID() == keyID);
CScript _createmultisig_redeemScript(const Array ¶ms)
int64_t nWalletUnlockTime
std::map< CTxDestination, CAddressBookData > mapAddressBook
Value getinfo(const Array ¶ms, bool fHelp)
std::string HelpExampleRpc(string methodname, string args)
static const int CLIENT_VERSION
string GetWarnings(string strFor)
Format a string that describes several potential problems detected by the core.
const char * GetTxnOutputType(txnouttype t)
unsigned int GetKeyPoolSize()
bool IsHex(const string &str)
Object JSONRPCError(int code, const string &message)
base58-encoded Bitcoin addresses.
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE
CTxDestination Get() const
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
const string strMessageMagic
CChain chainActive
The currently-connected chain of blocks.
bool GetKeyID(CKeyID &keyID) const
int64_t GetBalance() const
int Height() const
Return the maximal height in the chain.
Value ValueFromAmount(int64_t amount)
int64_t GetOldestKeyPoolTime()
bool RecoverCompact(const uint256 &hash, const std::vector< unsigned char > &vchSig)
An encapsulated public key.
std::string ToString() const
Value createmultisig(const Array ¶ms, bool fHelp)
bool IsCompressed() const
bool ExtractDestinations(const CScript &scriptPubKey, txnouttype &typeRet, vector< CTxDestination > &addressRet, int &nRequiredRet)
Serialized script, used inside transaction inputs and outputs.
static const int PROTOCOL_VERSION
double GetDifficulty(const CBlockIndex *blockindex)
void SetMultisig(int nRequired, const std::vector< CPubKey > &keys)
bool IsMine(const CKeyStore &keystore, const CTxDestination &dest)
A reference to a CKey: the Hash160 of its serialized public key.
bool IsFullyValid() const
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const
std::pair< CService, int > proxyType
static int64_t nMinRelayTxFee
Fees smaller than this (in satoshi) are considered zero fee (for relaying and mining) ...
Value verifymessage(const Array ¶ms, bool fHelp)
A reference to a CScript: the Hash160 of its serialization (see script.h)
bool GetProxy(enum Network net, proxyType &proxyInfoOut)
std::string HelpExampleCli(string methodname, string args)
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
vector< unsigned char > DecodeBase64(const char *p, bool *pfInvalid)
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
vector< unsigned char > ParseHex(const char *psz)
Value validateaddress(const Array ¶ms, bool fHelp)