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;
35 Value
getinfo(
const Array& params,
bool fHelp)
37 if (fHelp || params.size() != 0)
40 "Returns an object containing various state info.\n"
43 " \"version\": xxxxx, (numeric) the server version\n"
44 " \"protocolversion\": xxxxx, (numeric) the protocol version\n"
45 " \"walletversion\": xxxxx, (numeric) the wallet version\n"
46 " \"balance\": xxxxxxx, (numeric) the total anoncoin balance of the wallet\n"
47 " \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n"
48 " \"timeoffset\": xxxxx, (numeric) the time offset\n"
49 " \"connections\": xxxxx, (numeric) the number of connections\n"
50 " \"proxy\": \"host:port\", (string, optional) the proxy used by the server\n"
51 " \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
52 " \"testnet\": true|false, (boolean) if the server is using testnet or not\n"
53 " \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since GMT epoch) of the oldest pre-generated key in the key pool\n"
54 " \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated\n"
55 " \"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"
56 " \"paytxfee\": x.xxxx, (numeric) the transaction fee set in btc/kb\n"
57 " \"relayfee\": x.xxxx, (numeric) minimum relay fee for non-free transactions in btc/kb\n"
58 " \"errors\": \"...\" (string) any error messages\n"
69 obj.push_back(Pair(
"version", (
int)CLIENT_VERSION));
70 obj.push_back(Pair(
"protocolversion",(
int)PROTOCOL_VERSION));
79 obj.push_back(Pair(
"connections", (
int)
vNodes.size()));
82 obj.push_back(Pair(
"testnet",
TestNet()));
93 obj.push_back(Pair(
"errors",
GetWarnings(
"statusbar")));
98 class DescribeAddressVisitor :
public boost::static_visitor<Object>
104 DescribeAddressVisitor(
isminetype mineIn) : mine(mineIn) {}
106 Object operator()(
const CNoDestination &dest)
const {
return Object(); }
108 Object operator()(
const CKeyID &keyID)
const {
111 obj.push_back(Pair(
"isscript",
false));
114 obj.push_back(Pair(
"pubkey",
HexStr(vchPubKey)));
115 obj.push_back(Pair(
"iscompressed", vchPubKey.
IsCompressed()));
120 Object operator()(
const CScriptID &scriptID)
const {
122 obj.push_back(Pair(
"isscript",
true));
126 std::vector<CTxDestination> addresses;
131 obj.push_back(Pair(
"hex",
HexStr(subscript.begin(), subscript.end())));
135 obj.push_back(Pair("addresses", a));
137 obj.push_back(Pair("sigsrequired", nRequired));
146 if (fHelp || params.size() != 1)
148 "validateaddress \"anoncoinaddress\"\n"
149 "\nReturn information about the given anoncoin address.\n"
151 "1. \"anoncoinaddress\" (string, required) The anoncoin address to validate\n"
154 " \"isvalid\" : true|false, (boolean) If the address is valid or not. If not, this is the only property returned.\n"
155 " \"address\" : \"anoncoinaddress\", (string) The anoncoin address validated\n"
156 " \"ismine\" : true|false, (boolean) If the address is yours or not\n"
157 " \"isscript\" : true|false, (boolean) If the key is a script\n"
158 " \"pubkey\" : \"publickeyhex\", (string) The hex value of the raw public key\n"
159 " \"iscompressed\" : true|false, (boolean) If the address is compressed\n"
160 " \"account\" : \"account\" (string) The account associated with the address, \"\" is the default account\n"
163 +
HelpExampleCli(
"validateaddress",
"\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
164 +
HelpExampleRpc(
"validateaddress",
"\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
168 bool isValid = address.
IsValid();
171 ret.push_back(Pair(
"isvalid", isValid));
175 string currentAddress = address.
ToString();
176 ret.push_back(Pair(
"address", currentAddress));
182 Object detail = boost::apply_visitor(DescribeAddressVisitor(mine), dest);
183 ret.insert(ret.end(), detail.begin(), detail.end());
197 int nRequired = params[0].get_int();
198 const Array& keys = params[1].get_array();
202 throw runtime_error(
"a multisignature address must require at least one key to redeem");
203 if ((
int)keys.size() < nRequired)
206 "(got %u keys, but need at least %d to redeem)", keys.size(), nRequired));
207 std::vector<CPubKey> pubkeys;
208 pubkeys.resize(keys.size());
209 for (
unsigned int i = 0; i < keys.size(); i++)
211 const std::string& ks = keys[i].get_str();
220 strprintf(
"%s does not refer to a key",ks));
224 strprintf(
"no full public key for address %s",ks));
226 throw runtime_error(
" Invalid public key: "+ks);
227 pubkeys[i] = vchPubKey;
237 throw runtime_error(
" Invalid public key: "+ks);
238 pubkeys[i] = vchPubKey;
242 throw runtime_error(
" Invalid public key: "+ks);
248 if (result.size() > MAX_SCRIPT_ELEMENT_SIZE)
250 strprintf(
"redeemScript exceeds size limit: %d > %d", result.size(), MAX_SCRIPT_ELEMENT_SIZE));
257 if (fHelp || params.size() < 2 || params.size() > 2)
259 string msg =
"createmultisig nrequired [\"key\",...]\n"
260 "\nCreates a multi-signature address with n signature of m keys required.\n"
261 "It returns a json object with the address and redeemScript.\n"
264 "1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.\n"
265 "2. \"keys\" (string, required) A json array of keys which are anoncoin addresses or hex-encoded public keys\n"
267 " \"key\" (string) anoncoin address or hex-encoded public key\n"
273 " \"address\":\"multisigaddress\", (string) The value of the new multisig address.\n"
274 " \"redeemScript\":\"script\" (string) The string value of the hex-encoded redemption script.\n"
278 "\nCreate a multisig address from 2 addresses\n"
279 +
HelpExampleCli(
"createmultisig",
"2 \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") +
280 "\nAs a json rpc call\n"
281 +
HelpExampleRpc(
"createmultisig",
"2, \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"")
283 throw runtime_error(msg);
292 result.push_back(Pair(
"address", address.
ToString()));
293 result.push_back(Pair(
"redeemScript",
HexStr(inner.begin(), inner.end())));
300 if (fHelp || params.size() != 3)
302 "verifymessage \"anoncoinaddress\" \"signature\" \"message\"\n"
303 "\nVerify a signed message\n"
305 "1. \"anoncoinaddress\" (string, required) The anoncoin address to use for the signature.\n"
306 "2. \"signature\" (string, required) The signature provided by the signer in base 64 encoding (see signmessage).\n"
307 "3. \"message\" (string, required) The message that was signed.\n"
309 "true|false (boolean) If the signature is verified or not.\n"
311 "\nUnlock the wallet for 30 seconds\n"
313 "\nCreate the signature\n"
314 +
HelpExampleCli(
"signmessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"my message\"") +
315 "\nVerify the signature\n"
316 +
HelpExampleCli(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"signature\" \"my message\"") +
318 +
HelpExampleRpc(
"verifymessage",
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\", \"signature\", \"my message\"")
321 string strAddress = params[0].get_str();
322 string strSign = params[1].get_str();
323 string strMessage = params[2].get_str();
333 bool fInvalid =
false;
334 vector<unsigned char> vchSig =
DecodeBase64(strSign.c_str(), &fInvalid);
347 return (pubkey.
GetID() == keyID);
CScript _createmultisig_redeemScript(const Array ¶ms)
int64_t nWalletUnlockTime
std::map< CTxDestination, CAddressBookData > mapAddressBook
isminetype IsMine(const CKeyStore &keystore, const CTxDestination &dest)
Value getinfo(const Array ¶ms, bool fHelp)
std::string ToStringIPPort() const
std::string HelpExampleRpc(string methodname, string args)
CTxDestination Get() const
string GetWarnings(string strFor)
bool GetKeyID(CKeyID &keyID) const
const char * GetTxnOutputType(txnouttype t)
unsigned int GetKeyPoolSize()
bool IsHex(const string &str)
Object JSONRPCError(int code, const string &message)
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
const string strMessageMagic
CChain chainActive
The currently-connected chain of blocks.
isminetype
IsMine() return codes.
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)
A combination of a network address (CNetAddr) and a (TCP) port.
An encapsulated public key.
base58-encoded Anoncoin addresses.
std::string ToString() const
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
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.
double GetDifficulty(const CBlockIndex *blockindex)
void SetMultisig(int nRequired, const std::vector< CPubKey > &keys)
A reference to a CKey: the Hash160 of its serialized public key.
bool IsFullyValid() const
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const
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)
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)