| 1122 | } |
| 1123 | |
| 1124 | UniValue importmulti(const JSONRPCRequest& mainRequest) |
| 1125 | { |
| 1126 | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(mainRequest); |
| 1127 | CWallet* const pwallet = wallet.get(); |
| 1128 | if (!EnsureWalletIsAvailable(pwallet, mainRequest.fHelp)) { |
| 1129 | return NullUniValue; |
| 1130 | } |
| 1131 | |
| 1132 | // clang-format off |
| 1133 | if (mainRequest.fHelp || mainRequest.params.size() < 1 || mainRequest.params.size() > 2) |
| 1134 | throw std::runtime_error( |
| 1135 | "importmulti \"requests\" ( \"options\" )\n\n" |
| 1136 | "Import addresses/scripts (with private or public keys, redeem script (P2SH)), rescanning all addresses in one-shot-only (rescan can be disabled via options). Requires a new wallet backup.\n\n" |
| 1137 | "Arguments:\n" |
| 1138 | "1. requests (array, required) Data to be imported\n" |
| 1139 | " [ (array of json objects)\n" |
| 1140 | " {\n" |
| 1141 | " \"scriptPubKey\": \"<script>\" | { \"address\":\"<address>\" }, (string / json, required) Type of scriptPubKey (string for script, json for address)\n" |
| 1142 | " \"timestamp\": timestamp | \"now\" , (integer / string, required) Creation time of the key in seconds since epoch (Jan 1 1970 GMT),\n" |
| 1143 | " or the string \"now\" to substitute the current synced blockchain time. The timestamp of the oldest\n" |
| 1144 | " key will determine how far back blockchain rescans need to begin for missing wallet transactions.\n" |
| 1145 | " \"now\" can be specified to bypass scanning, for keys which are known to never have been used, and\n" |
| 1146 | " 0 can be specified to scan the entire blockchain. Blocks up to 2 hours before the earliest key\n" |
| 1147 | " creation time of all keys being imported by the importmulti call will be scanned.\n" |
| 1148 | " \"redeemscript\": \"<script>\" , (string, optional) Allowed only if the scriptPubKey is a P2SH address or a P2SH scriptPubKey\n" |
| 1149 | " \"pubkeys\": [\"<pubKey>\", ... ] , (array, optional) Array of strings giving pubkeys that must occur in the output or redeemscript\n" |
| 1150 | " \"keys\": [\"<key>\", ... ] , (array, optional) Array of strings giving private keys whose corresponding public keys must occur in the output or redeemscript\n" |
| 1151 | " \"internal\": <true> , (boolean, optional, default: false) Stating whether matching outputs should be treated as not incoming payments\n" |
| 1152 | " \"watchonly\": <true> , (boolean, optional, default: false) Stating whether matching outputs should be considered watched even when they're not spendable, only allowed if keys are empty\n" |
| 1153 | " \"label\": <label> , (string, optional, default: '') Label to assign to the address (aka account name, for now), only allowed with internal=false\n" |
| 1154 | " }\n" |
| 1155 | " ,...\n" |
| 1156 | " ]\n" |
| 1157 | "2. options (json, optional)\n" |
| 1158 | " {\n" |
| 1159 | " \"rescan\": <false>, (boolean, optional, default: true) Stating if should rescan the blockchain after all imports\n" |
| 1160 | " }\n" |
| 1161 | "\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n" |
| 1162 | "may report that the imported keys, addresses or scripts exists but related transactions are still missing.\n" |
| 1163 | "\nExamples:\n" + |
| 1164 | HelpExampleCli("importmulti", "'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, \"timestamp\":1455191478 }, " |
| 1165 | "{ \"scriptPubKey\": { \"address\": \"<my 2nd address>\" }, \"label\": \"example 2\", \"timestamp\": 1455191480 }]'") + |
| 1166 | HelpExampleCli("importmulti", "'[{ \"scriptPubKey\": { \"address\": \"<my address>\" }, \"timestamp\":1455191478 }]' '{ \"rescan\": false}'") + |
| 1167 | |
| 1168 | "\nResponse is an array with the same size as the input that has the execution result :\n" |
| 1169 | " [{ \"success\": true } , { \"success\": false, \"error\": { \"code\": -1, \"message\": \"Internal Server Error\"} }, ... ]\n"); |
| 1170 | |
| 1171 | // clang-format on |
| 1172 | |
| 1173 | RPCTypeCheck(mainRequest.params, {UniValue::VARR, UniValue::VOBJ}); |
| 1174 | |
| 1175 | const UniValue& requests = mainRequest.params[0]; |
| 1176 | |
| 1177 | //Default options |
| 1178 | bool fRescan = true; |
| 1179 | |
| 1180 | if (!mainRequest.params[1].isNull()) { |
| 1181 | const UniValue& options = mainRequest.params[1]; |