Debian Codegraph @

monero/utils/python-rpc/framework/wallet.py

raw symbols SCIP
1 # Copyright (c) 2018-2022, The Monero Project
2
3 #
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without modification, are
7 # permitted provided that the following conditions are met:
8 #
9 # 1. Redistributions of source code must retain the above copyright notice, this list of
10 # conditions and the following disclaimer.
11 #
12 # 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 # of conditions and the following disclaimer in the documentation and/or other
14 # materials provided with the distribution.
15 #
16 # 3. Neither the name of the copyright holder nor the names of its contributors may be
17 # used to endorse or promote products derived from this software without specific
18 # prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23 # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28 # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 """Daemon class to make rpc calls and store state."""
31
32 from .rpc import JSONRPC
33
34 class Wallet(object):
35
36 def __init__(self, protocol='http', host='127.0.0.1', port=0, idx=0):
37 self.host = host
38 self.port = port
39 self.rpc = JSONRPC('{protocol}://{host}:{port}'.format(protocol=protocol, host=host, port=port if port else 18090+idx))
40
41 def transfer(self, destinations, account_index = 0, subaddr_indices = [], priority = 0, ring_size = 0, unlock_time = 0, payment_id = '', get_tx_key = True, do_not_relay = False, get_tx_hex = False, get_tx_metadata = False, subtract_fee_from_outputs = []):
42 transfer = {
43 'method': 'transfer',
44 'params': {
45 'destinations': destinations,
46 'account_index': account_index,
47 'subaddr_indices': subaddr_indices,
48 'subtract_fee_from_outputs': subtract_fee_from_outputs,
49 'priority': priority,
50 'ring_size' : ring_size,
51 'unlock_time' : unlock_time,
52 'payment_id' : payment_id,
53 'get_tx_key' : get_tx_key,
54 'do_not_relay' : do_not_relay,
55 'get_tx_hex' : get_tx_hex,
56 'get_tx_metadata' : get_tx_metadata,
57 },
58 'jsonrpc': '2.0',
59 'id': '0'
60 }
61 return self.rpc.send_json_rpc_request(transfer)
62
63 def transfer_split(self, destinations, account_index = 0, subaddr_indices = [], priority = 0, ring_size = 0, unlock_time = 0, payment_id = '', get_tx_key = True, do_not_relay = False, get_tx_hex = False, get_tx_metadata = False):
64 transfer = {
65 "method": "transfer_split",
66 "params": {
67 'destinations': destinations,
68 'account_index': account_index,
69 'subaddr_indices': subaddr_indices,
70 'priority': priority,
71 'ring_size' : ring_size,
72 'unlock_time' : unlock_time,
73 'payment_id' : payment_id,
74 'get_tx_key' : get_tx_key,
75 'do_not_relay' : do_not_relay,
76 'get_tx_hex' : get_tx_hex,
77 'get_tx_metadata' : get_tx_metadata,
78 },
79 "jsonrpc": "2.0",
80 "id": "0"
81 }
82 return self.rpc.send_json_rpc_request(transfer)
83
84 def get_transfer_by_txid(self, txid, account_index = 0):
85 get_transfer_by_txid = {
86 'method': 'get_transfer_by_txid',
87 'params': {
88 'txid': txid,
89 'account_index': account_index,
90 },
91 'jsonrpc': '2.0',
92 'id': '0'
93 }
94 return self.rpc.send_json_rpc_request(get_transfer_by_txid)
95
96 def get_payments(self, payment_id):
97 get_payments = {
98 'method': 'get_payments',
99 'params': {
100 'payment_id': payment_id,
101 },
102 'jsonrpc': '2.0',
103 'id': '0'
104 }
105 return self.rpc.send_json_rpc_request(get_payments)
106
107 def get_bulk_payments(self, payment_ids = [], min_block_height = 0):
108 get_bulk_payments = {
109 'method': 'get_bulk_payments',
110 'params': {
111 'payment_ids': payment_ids,
112 'min_block_height': min_block_height,
113 },
114 'jsonrpc': '2.0',
115 'id': '0'
116 }
117 return self.rpc.send_json_rpc_request(get_bulk_payments)
118
119 def describe_transfer(self, unsigned_txset = '', multisig_txset = ''):
120 describe_transfer = {
121 'method': 'describe_transfer',
122 'params': {
123 'unsigned_txset': unsigned_txset,
124 'multisig_txset': multisig_txset,
125 },
126 'jsonrpc': '2.0',
127 'id': '0'
128 }
129 return self.rpc.send_json_rpc_request(describe_transfer)
130
131 def create_wallet(self, filename='', password = '', language = 'English'):
132 create_wallet = {
133 'method': 'create_wallet',
134 'params': {
135 'filename': filename,
136 'password': password,
137 'language': language
138 },
139 'jsonrpc': '2.0',
140 'id': '0'
141 }
142 return self.rpc.send_json_rpc_request(create_wallet)
143
144 def get_balance(self, account_index = 0, address_indices = [], all_accounts = False, strict = False):
145 get_balance = {
146 'method': 'get_balance',
147 'params': {
148 'account_index': account_index,
149 'address_indices': address_indices,
150 'all_accounts': all_accounts,
151 'strict': strict,
152 },
153 'jsonrpc': '2.0',
154 'id': '0'
155 }
156 return self.rpc.send_json_rpc_request(get_balance)
157 getbalance = get_balance
158
159 def sweep_dust(self, get_tx_keys = True, do_not_relay = False, get_tx_hex = False, get_tx_metadata = False):
160 sweep_dust = {
161 'method': 'sweep_dust',
162 'params': {
163 'get_tx_keys': get_tx_keys,
164 'do_not_relay': do_not_relay,
165 'get_tx_hex': get_tx_hex,
166 'get_tx_metadata': get_tx_metadata,
167 },
168 'jsonrpc': '2.0',
169 'id': '0'
170 }
171 return self.rpc.send_json_rpc_request(sweep_dust)
172 sweep_unmixable = sweep_dust
173
174 def sweep_all(self, address = '', account_index = 0, subaddr_indices = [], priority = 0, ring_size = 0, outputs = 1, unlock_time = 0, payment_id = '', get_tx_keys = False, below_amount = 0, do_not_relay = False, get_tx_hex = False, get_tx_metadata = False):
175 sweep_all = {
176 'method': 'sweep_all',
177 'params' : {
178 'address' : address,
179 'account_index' : account_index,
180 'subaddr_indices' : subaddr_indices,
181 'priority' : priority,
182 'ring_size' : ring_size,
183 'outputs' : outputs,
184 'unlock_time' : unlock_time,
185 'payment_id' : payment_id,
186 'get_tx_keys' : get_tx_keys,
187 'below_amount' : below_amount,
188 'do_not_relay' : do_not_relay,
189 'get_tx_hex' : get_tx_hex,
190 'get_tx_metadata' : get_tx_metadata,
191 },
192 'jsonrpc': '2.0',
193 'id': '0'
194 }
195 return self.rpc.send_json_rpc_request(sweep_all)
196
197 def sweep_single(self, address = '', priority = 0, ring_size = 0, outputs = 1, unlock_time = 0, payment_id = '', get_tx_keys = False, key_image = "", do_not_relay = False, get_tx_hex = False, get_tx_metadata = False):
198 sweep_single = {
199 'method': 'sweep_single',
200 'params' : {
201 'address' : address,
202 'priority' : priority,
203 'ring_size' : ring_size,
204 'outputs' : outputs,
205 'unlock_time' : unlock_time,
206 'payment_id' : payment_id,
207 'get_tx_keys' : get_tx_keys,
208 'key_image' : key_image,
209 'do_not_relay' : do_not_relay,
210 'get_tx_hex' : get_tx_hex,
211 'get_tx_metadata' : get_tx_metadata,
212 },
213 'jsonrpc': '2.0',
214 'id': '0'
215 }
216 return self.rpc.send_json_rpc_request(sweep_single)
217
218 def get_address(self, account_index = 0, subaddresses = []):
219 get_address = {
220 'method': 'get_address',
221 'params' : {
222 'account_index' : account_index,
223 'address_index': subaddresses
224 },
225 'jsonrpc': '2.0',
226 'id': '0'
227 }
228 return self.rpc.send_json_rpc_request(get_address)
229 getaddress = get_address
230
231 def create_account(self, label = ""):
232 create_account = {
233 'method': 'create_account',
234 'params' : {
235 'label': label
236 },
237 'jsonrpc': '2.0',
238 'id': '0'
239 }
240 return self.rpc.send_json_rpc_request(create_account)
241
242 def create_address(self, account_index = 0, label = "", count = 1):
243 create_address = {
244 'method': 'create_address',
245 'params' : {
246 'account_index': account_index,
247 'label': label,
248 'count': count
249 },
250 'jsonrpc': '2.0',
251 'id': '0'
252 }
253 return self.rpc.send_json_rpc_request(create_address)
254
255 def label_address(self, subaddress_index, label):
256 label_address = {
257 'method': 'label_address',
258 'params' : {
259 'index': { 'major': subaddress_index[0], 'minor': subaddress_index[1]},
260 'label': label
261 },
262 'jsonrpc': '2.0',
263 'id': '0'
264 }
265 return self.rpc.send_json_rpc_request(label_address)
266
267 def label_account(self, account_index, label):
268 label_account = {
269 'method': 'label_account',
270 'params' : {
271 'account_index': account_index,
272 'label': label
273 },
274 'jsonrpc': '2.0',
275 'id': '0'
276 }
277 return self.rpc.send_json_rpc_request(label_account)
278
279 def get_address_index(self, address):
280 get_address_index = {
281 'method': 'get_address_index',
282 'params' : {
283 'address': address
284 },
285 'jsonrpc': '2.0',
286 'id': '0'
287 }
288 return self.rpc.send_json_rpc_request(get_address_index)
289
290 def query_key(self, key_type):
291 query_key = {
292 'method': 'query_key',
293 'params' : {
294 'key_type': key_type
295 },
296 'jsonrpc': '2.0',
297 'id': '0'
298 }
299 return self.rpc.send_json_rpc_request(query_key)
300
301 def restore_deterministic_wallet(self, seed = '', seed_offset = '', filename = '', restore_height = 0, password = '', language = '', autosave_current = True, enable_multisig_experimental = False):
302 restore_deterministic_wallet = {
303 'method': 'restore_deterministic_wallet',
304 'params' : {
305 'restore_height': restore_height,
306 'filename': filename,
307 'seed': seed,
308 'seed_offset': seed_offset,
309 'password': password,
310 'language': language,
311 'autosave_current': autosave_current,
312 'enable_multisig_experimental': enable_multisig_experimental
313 },
314 'jsonrpc': '2.0',
315 'id': '0'
316 }
317 return self.rpc.send_json_rpc_request(restore_deterministic_wallet)
318
319 def generate_from_keys(self, restore_height = 0, filename = "", password = "", address = "", spendkey = "", viewkey = "", autosave_current = True):
320 generate_from_keys = {
321 'method': 'generate_from_keys',
322 'params' : {
323 'restore_height': restore_height,
324 'filename': filename,
325 'address': address,
326 'spendkey': spendkey,
327 'viewkey': viewkey,
328 'password': password,
329 'autosave_current': autosave_current,
330 },
331 'jsonrpc': '2.0',
332 'id': '0'
333 }
334 return self.rpc.send_json_rpc_request(generate_from_keys)
335
336 def open_wallet(self, filename, password='', autosave_current = True):
337 open_wallet = {
338 'method': 'open_wallet',
339 'params' : {
340 'filename': filename,
341 'password': password,
342 'autosave_current': autosave_current,
343 },
344 'jsonrpc': '2.0',
345 'id': '0'
346 }
347 return self.rpc.send_json_rpc_request(open_wallet)
348
349 def close_wallet(self, autosave_current = True):
350 close_wallet = {
351 'method': 'close_wallet',
352 'params' : {
353 'autosave_current': autosave_current
354 },
355 'jsonrpc': '2.0',
356 'id': '0'
357 }
358 return self.rpc.send_json_rpc_request(close_wallet)
359
360 def change_wallet_password(self, old_password, new_password):
361 change_wallet_password = {
362 'method': 'change_wallet_password',
363 'params' : {
364 'old_password': old_password,
365 'new_password': new_password,
366 },
367 'jsonrpc': '2.0',
368 'id': '0'
369 }
370 return self.rpc.send_json_rpc_request(change_wallet_password)
371
372 def store(self):
373 store = {
374 'method': 'store',
375 'jsonrpc': '2.0',
376 'id': '0'
377 }
378 return self.rpc.send_json_rpc_request(store)
379
380 def stop_wallet(self):
381 stop_wallet = {
382 'method': 'stop_wallet',
383 'jsonrpc': '2.0',
384 'id': '0'
385 }
386 return self.rpc.send_json_rpc_request(stop_wallet)
387
388 def refresh(self):
389 refresh = {
390 'method': 'refresh',
391 'params' : {
392 },
393 'jsonrpc': '2.0',
394 'id': '0'
395 }
396 return self.rpc.send_json_rpc_request(refresh)
397
398 def incoming_transfers(self, transfer_type='all', account_index = 0, subaddr_indices = []):
399 incoming_transfers = {
400 'method': 'incoming_transfers',
401 'params' : {
402 'transfer_type': transfer_type,
403 'account_index': account_index,
404 'subaddr_indices': subaddr_indices,
405 },
406 'jsonrpc': '2.0',
407 'id': '0'
408 }
409 return self.rpc.send_json_rpc_request(incoming_transfers)
410
411 def get_transfers(self, in_ = True, out = True, pending = True, failed = True, pool = True, min_height = None, max_height = None, account_index = 0, subaddr_indices = [], all_accounts = False):
412 get_transfers = {
413 'method': 'get_transfers',
414 'params' : {
415 'in': in_,
416 'out': out,
417 'pending': pending,
418 'failed': failed,
419 'pool': pool,
420 'min_height': min_height,
421 'max_height': max_height,
422 'filter_by_height': min_height or max_height,
423 'account_index': account_index,
424 'subaddr_indices': subaddr_indices,
425 'all_accounts': all_accounts,
426 },
427 'jsonrpc': '2.0',
428 'id': '0'
429 }
430 return self.rpc.send_json_rpc_request(get_transfers)
431
432 def make_integrated_address(self, standard_address = '', payment_id = ''):
433 make_integrated_address = {
434 'method': 'make_integrated_address',
435 'params' : {
436 'standard_address': standard_address,
437 'payment_id': payment_id,
438 },
439 'jsonrpc': '2.0',
440 'id': '0'
441 }
442 return self.rpc.send_json_rpc_request(make_integrated_address)
443
444 def split_integrated_address(self, integrated_address):
445 split_integrated_address = {
446 'method': 'split_integrated_address',
447 'params' : {
448 'integrated_address': integrated_address,
449 },
450 'jsonrpc': '2.0',
451 'id': '0'
452 }
453 return self.rpc.send_json_rpc_request(split_integrated_address)
454
455 def auto_refresh(self, enable, period = 0):
456 auto_refresh = {
457 'method': 'auto_refresh',
458 'params' : {
459 'enable': enable,
460 'period': period
461 },
462 'jsonrpc': '2.0',
463 'id': '0'
464 }
465 return self.rpc.send_json_rpc_request(auto_refresh)
466
467 def set_daemon(self, address, trusted = False, ssl_support = "autodetect", ssl_private_key_path = "", ssl_certificate_path = "", ssl_allowed_certificates = [], ssl_allowed_fingerprints = [], ssl_allow_any_cert = False):
468 set_daemon = {
469 'method': 'set_daemon',
470 'params' : {
471 'address': address,
472 'trusted': trusted,
473 'ssl_support': ssl_support,
474 'ssl_private_key_path': ssl_private_key_path,
475 'ssl_certificate_path': ssl_certificate_path,
476 'ssl_allowed_certificates': ssl_allowed_certificates,
477 'ssl_allowed_fingerprints': ssl_allowed_fingerprints,
478 'ssl_allow_any_cert': ssl_allow_any_cert,
479 },
480 'jsonrpc': '2.0',
481 'id': '0'
482 }
483 return self.rpc.send_json_rpc_request(set_daemon)
484
485 def is_multisig(self):
486 is_multisig = {
487 'method': 'is_multisig',
488 'params' : {
489 },
490 'jsonrpc': '2.0',
491 'id': '0'
492 }
493 return self.rpc.send_json_rpc_request(is_multisig)
494
495 def prepare_multisig(self, enable_multisig_experimental = False):
496 prepare_multisig = {
497 'method': 'prepare_multisig',
498 'params' : {
499 'enable_multisig_experimental': enable_multisig_experimental,
500 },
501 'jsonrpc': '2.0',
502 'id': '0'
503 }
504 return self.rpc.send_json_rpc_request(prepare_multisig)
505
506 def make_multisig(self, multisig_info, threshold, password = ''):
507 make_multisig = {
508 'method': 'make_multisig',
509 'params' : {
510 'multisig_info': multisig_info,
511 'threshold': threshold,
512 'password': password,
513 },
514 'jsonrpc': '2.0',
515 'id': '0'
516 }
517 return self.rpc.send_json_rpc_request(make_multisig)
518
519 def finalize_multisig(self):
520 finalize_multisig = {
521 'method': 'finalize_multisig',
522 'params' : {
523 },
524 'jsonrpc': '2.0',
525 'id': '0'
526 }
527 return self.rpc.send_json_rpc_request(finalize_multisig)
528
529 def exchange_multisig_keys(self, multisig_info, password = '', force_update_use_with_caution = False):
530 exchange_multisig_keys = {
531 'method': 'exchange_multisig_keys',
532 'params' : {
533 'multisig_info': multisig_info,
534 'password': password,
535 'force_update_use_with_caution': force_update_use_with_caution,
536 },
537 'jsonrpc': '2.0',
538 'id': '0'
539 }
540 return self.rpc.send_json_rpc_request(exchange_multisig_keys)
541
542 def export_multisig_info(self):
543 export_multisig_info = {
544 'method': 'export_multisig_info',
545 'params' : {
546 },
547 'jsonrpc': '2.0',
548 'id': '0'
549 }
550 return self.rpc.send_json_rpc_request(export_multisig_info)
551
552 def import_multisig_info(self, info = []):
553 import_multisig_info = {
554 'method': 'import_multisig_info',
555 'params' : {
556 'info': info
557 },
558 'jsonrpc': '2.0',
559 'id': '0'
560 }
561 return self.rpc.send_json_rpc_request(import_multisig_info)
562
563 def sign_multisig(self, tx_data_hex):
564 sign_multisig = {
565 'method': 'sign_multisig',
566 'params' : {
567 'tx_data_hex': tx_data_hex
568 },
569 'jsonrpc': '2.0',
570 'id': '0'
571 }
572 return self.rpc.send_json_rpc_request(sign_multisig)
573
574 def submit_multisig(self, tx_data_hex):
575 submit_multisig = {
576 'method': 'submit_multisig',
577 'params' : {
578 'tx_data_hex': tx_data_hex
579 },
580 'jsonrpc': '2.0',
581 'id': '0'
582 }
583 return self.rpc.send_json_rpc_request(submit_multisig)
584
585 def sign_transfer(self, unsigned_txset, export_raw = False, get_tx_keys = False):
586 sign_transfer = {
587 'method': 'sign_transfer',
588 'params' : {
589 'unsigned_txset': unsigned_txset,
590 'export_raw': export_raw,
591 'get_tx_keys': get_tx_keys,
592 },
593 'jsonrpc': '2.0',
594 'id': '0'
595 }
596 return self.rpc.send_json_rpc_request(sign_transfer)
597
598 def submit_transfer(self, tx_data_hex):
599 submit_transfer = {
600 'method': 'submit_transfer',
601 'params' : {
602 'tx_data_hex': tx_data_hex,
603 },
604 'jsonrpc': '2.0',
605 'id': '0'
606 }
607 return self.rpc.send_json_rpc_request(submit_transfer)
608
609 def get_tx_key(self, txid):
610 get_tx_key = {
611 'method': 'get_tx_key',
612 'params' : {
613 'txid': txid,
614 },
615 'jsonrpc': '2.0',
616 'id': '0'
617 }
618 return self.rpc.send_json_rpc_request(get_tx_key)
619
620 def check_tx_key(self, txid = '', tx_key = '', address = ''):
621 check_tx_key = {
622 'method': 'check_tx_key',
623 'params' : {
624 'txid': txid,
625 'tx_key': tx_key,
626 'address': address,
627 },
628 'jsonrpc': '2.0',
629 'id': '0'
630 }
631 return self.rpc.send_json_rpc_request(check_tx_key)
632
633 def get_tx_proof(self, txid = '', address = '', message = ''):
634 get_tx_proof = {
635 'method': 'get_tx_proof',
636 'params' : {
637 'txid': txid,
638 'address': address,
639 'message': message,
640 },
641 'jsonrpc': '2.0',
642 'id': '0'
643 }
644 return self.rpc.send_json_rpc_request(get_tx_proof)
645
646 def check_tx_proof(self, txid = '', address = '', message = '', signature = ''):
647 check_tx_proof = {
648 'method': 'check_tx_proof',
649 'params' : {
650 'txid': txid,
651 'address': address,
652 'message': message,
653 'signature': signature,
654 },
655 'jsonrpc': '2.0',
656 'id': '0'
657 }
658 return self.rpc.send_json_rpc_request(check_tx_proof)
659
660 def get_spend_proof(self, txid = '', message = ''):
661 get_spend_proof = {
662 'method': 'get_spend_proof',
663 'params' : {
664 'txid': txid,
665 'message': message,
666 },
667 'jsonrpc': '2.0',
668 'id': '0'
669 }
670 return self.rpc.send_json_rpc_request(get_spend_proof)
671
672 def check_spend_proof(self, txid = '', message = '', signature = ''):
673 check_spend_proof = {
674 'method': 'check_spend_proof',
675 'params' : {
676 'txid': txid,
677 'message': message,
678 'signature': signature,
679 },
680 'jsonrpc': '2.0',
681 'id': '0'
682 }
683 return self.rpc.send_json_rpc_request(check_spend_proof)
684
685 def get_reserve_proof(self, all_ = True, account_index = 0, amount = 0, message = ''):
686 get_reserve_proof = {
687 'method': 'get_reserve_proof',
688 'params' : {
689 'all': all_,
690 'account_index': account_index,
691 'amount': amount,
692 'message': message,
693 },
694 'jsonrpc': '2.0',
695 'id': '0'
696 }
697 return self.rpc.send_json_rpc_request(get_reserve_proof)
698
699 def check_reserve_proof(self, address = '', message = '', signature = ''):
700 check_reserve_proof = {
701 'method': 'check_reserve_proof',
702 'params' : {
703 'address': address,
704 'message': message,
705 'signature': signature,
706 },
707 'jsonrpc': '2.0',
708 'id': '0'
709 }
710 return self.rpc.send_json_rpc_request(check_reserve_proof)
711
712 def sign(self, data, account_index = 0, address_index = 0, signature_type = ""):
713 sign = {
714 'method': 'sign',
715 'params' : {
716 'data': data,
717 'account_index': account_index,
718 'address_index': address_index,
719 'signature_type': signature_type,
720 },
721 'jsonrpc': '2.0',
722 'id': '0'
723 }
724 return self.rpc.send_json_rpc_request(sign)
725
726 def verify(self, data, address, signature):
727 verify = {
728 'method': 'verify',
729 'params' : {
730 'data': data,
731 'address': address,
732 'signature': signature,
733 },
734 'jsonrpc': '2.0',
735 'id': '0'
736 }
737 return self.rpc.send_json_rpc_request(verify)
738
739 def get_height(self):
740 get_height = {
741 'method': 'get_height',
742 'jsonrpc': '2.0',
743 'id': '0'
744 }
745 return self.rpc.send_json_rpc_request(get_height)
746 getheight = get_height
747
748 def relay_tx(self, hex_):
749 relay_tx = {
750 'method': 'relay_tx',
751 'params': {
752 'hex': hex_,
753 },
754 'jsonrpc': '2.0',
755 'id': '0'
756 }
757 return self.rpc.send_json_rpc_request(relay_tx)
758
759 def get_languages(self):
760 get_languages = {
761 'method': 'get_languages',
762 'params': {
763 },
764 'jsonrpc': '2.0',
765 'id': '0'
766 }
767 return self.rpc.send_json_rpc_request(get_languages)
768
769 def export_outputs(self, all = False, start = 0, count = 0xffffffff):
770 export_outputs = {
771 'method': 'export_outputs',
772 'params': {
773 'all': all,
774 'start': start,
775 'count': count,
776 },
777 'jsonrpc': '2.0',
778 'id': '0'
779 }
780 return self.rpc.send_json_rpc_request(export_outputs)
781
782 def import_outputs(self, outputs_data_hex):
783 import_outputs = {
784 'method': 'import_outputs',
785 'params': {
786 'outputs_data_hex': outputs_data_hex
787 },
788 'jsonrpc': '2.0',
789 'id': '0'
790 }
791 return self.rpc.send_json_rpc_request(import_outputs)
792
793 def export_key_images(self, all_ = False):
794 export_key_images = {
795 'method': 'export_key_images',
796 'params': {
797 'all': all_
798 },
799 'jsonrpc': '2.0',
800 'id': '0'
801 }
802 return self.rpc.send_json_rpc_request(export_key_images)
803
804 def import_key_images(self, signed_key_images, offset = 0):
805 import_key_images = {
806 'method': 'import_key_images',
807 'params': {
808 'offset': offset,
809 'signed_key_images': signed_key_images,
810 },
811 'jsonrpc': '2.0',
812 'id': '0'
813 }
814 return self.rpc.send_json_rpc_request(import_key_images)
815
816 def set_log_level(self, level):
817 set_log_level = {
818 'method': 'set_log_level',
819 'params': {
820 'level': level,
821 },
822 'jsonrpc': '2.0',
823 'id': '0'
824 }
825 return self.rpc.send_json_rpc_request(set_log_level)
826
827 def set_log_categories(self, categories):
828 set_log_categories = {
829 'method': 'set_log_categories',
830 'params': {
831 'categories': categories,
832 },
833 'jsonrpc': '2.0',
834 'id': '0'
835 }
836 return self.rpc.send_json_rpc_request(set_log_categories)
837
838 def validate_address(self, address, any_net_type = False, allow_openalias = False):
839 validate_address = {
840 'method': 'validate_address',
841 'params': {
842 'address': address,
843 'any_net_type': any_net_type,
844 'allow_openalias': allow_openalias,
845 },
846 'jsonrpc': '2.0',
847 'id': '0'
848 }
849 return self.rpc.send_json_rpc_request(validate_address)
850
851 def get_accounts(self, tag, strict_balances = False):
852 get_accounts = {
853 'method': 'get_accounts',
854 'params': {
855 'tag': tag,
856 'strict_balances': strict_balances,
857 },
858 'jsonrpc': '2.0',
859 'id': '0'
860 }
861 return self.rpc.send_json_rpc_request(get_accounts)
862
863 def get_account_tags(self):
864 get_account_tags = {
865 'method': 'get_account_tags',
866 'params': {
867 },
868 'jsonrpc': '2.0',
869 'id': '0'
870 }
871 return self.rpc.send_json_rpc_request(get_account_tags)
872
873 def tag_accounts(self, tag, accounts = []):
874 tag_accounts = {
875 'method': 'tag_accounts',
876 'params': {
877 'tag': tag,
878 'accounts': accounts,
879 },
880 'jsonrpc': '2.0',
881 'id': '0'
882 }
883 return self.rpc.send_json_rpc_request(tag_accounts)
884
885 def untag_accounts(self, accounts = []):
886 untag_accounts = {
887 'method': 'untag_accounts',
888 'params': {
889 'accounts': accounts,
890 },
891 'jsonrpc': '2.0',
892 'id': '0'
893 }
894 return self.rpc.send_json_rpc_request(untag_accounts)
895
896 def set_account_tag_description(self, tag, description):
897 set_account_tag_description = {
898 'method': 'set_account_tag_description',
899 'params': {
900 'tag': tag,
901 'description': description,
902 },
903 'jsonrpc': '2.0',
904 'id': '0'
905 }
906 return self.rpc.send_json_rpc_request(set_account_tag_description)
907
908 def rescan_blockchain(self, hard = False):
909 rescan_blockchain = {
910 'method': 'rescan_blockchain',
911 'jsonrpc': '2.0',
912 'params': {
913 'hard': hard,
914 },
915 'id': '0'
916 }
917 return self.rpc.send_json_rpc_request(rescan_blockchain)
918
919 def rescan_spent(self):
920 rescan_spent = {
921 'method': 'rescan_spent',
922 'jsonrpc': '2.0',
923 'params': {
924 },
925 'id': '0'
926 }
927 return self.rpc.send_json_rpc_request(rescan_spent)
928
929 def set_tx_notes(self, txids = [], notes = []):
930 set_tx_notes = {
931 'method': 'set_tx_notes',
932 'jsonrpc': '2.0',
933 'params': {
934 'txids': txids,
935 'notes': notes,
936 },
937 'id': '0'
938 }
939 return self.rpc.send_json_rpc_request(set_tx_notes)
940
941 def get_tx_notes(self, txids = []):
942 get_tx_notes = {
943 'method': 'get_tx_notes',
944 'jsonrpc': '2.0',
945 'params': {
946 'txids': txids,
947 },
948 'id': '0'
949 }
950 return self.rpc.send_json_rpc_request(get_tx_notes)
951
952 def set_attribute(self, key, value):
953 set_attribute = {
954 'method': 'set_attribute',
955 'jsonrpc': '2.0',
956 'params': {
957 'key': key,
958 'value': value,
959 },
960 'id': '0'
961 }
962 return self.rpc.send_json_rpc_request(set_attribute)
963
964 def get_attribute(self, key):
965 get_attribute = {
966 'method': 'get_attribute',
967 'jsonrpc': '2.0',
968 'params': {
969 'key': key,
970 },
971 'id': '0'
972 }
973 return self.rpc.send_json_rpc_request(get_attribute)
974
975 def make_uri(self, address = '', payment_id = '', amount = 0, tx_description = '', recipient_name = ''):
976 make_uri = {
977 'method': 'make_uri',
978 'jsonrpc': '2.0',
979 'params': {
980 'address': address,
981 'payment_id': payment_id,
982 'amount': amount,
983 'tx_description': tx_description,
984 'recipient_name': recipient_name,
985 },
986 'id': '0'
987 }
988 return self.rpc.send_json_rpc_request(make_uri)
989
990 def parse_uri(self, uri):
991 parse_uri = {
992 'method': 'parse_uri',
993 'jsonrpc': '2.0',
994 'params': {
995 'uri': uri,
996 },
997 'id': '0'
998 }
999 return self.rpc.send_json_rpc_request(parse_uri)
1000
1001 def add_address_book(self, address = '', payment_id = '', description = ''):
1002 add_address_book = {
1003 'method': 'add_address_book',
1004 'jsonrpc': '2.0',
1005 'params': {
1006 'address': address,
1007 'payment_id': payment_id,
1008 'description': description,
1009 },
1010 'id': '0'
1011 }
1012 return self.rpc.send_json_rpc_request(add_address_book)
1013
1014 def edit_address_book(self, index, address = None, payment_id = None, description = None):
1015 edit_address_book = {
1016 'method': 'edit_address_book',
1017 'jsonrpc': '2.0',
1018 'params': {
1019 'index': index,
1020 'set_address': address != None,
1021 'address': address or '',
1022 'set_payment_id': payment_id != None,
1023 'payment_id': payment_id or '',
1024 'set_description': description != None,
1025 'description': description or '',
1026 },
1027 'id': '0'
1028 }
1029 return self.rpc.send_json_rpc_request(edit_address_book)
1030
1031 def get_address_book(self, entries = []):
1032 get_address_book = {
1033 'method': 'get_address_book',
1034 'jsonrpc': '2.0',
1035 'params': {
1036 'entries': entries,
1037 },
1038 'id': '0'
1039 }
1040 return self.rpc.send_json_rpc_request(get_address_book)
1041
1042 def delete_address_book(self, index):
1043 delete_address_book = {
1044 'method': 'delete_address_book',
1045 'jsonrpc': '2.0',
1046 'params': {
1047 'index': index,
1048 },
1049 'id': '0'
1050 }
1051 return self.rpc.send_json_rpc_request(delete_address_book)
1052
1053 def start_mining(self, threads_count, do_background_mining = False, ignore_battery = False):
1054 start_mining = {
1055 'method': 'start_mining',
1056 'jsonrpc': '2.0',
1057 'params': {
1058 'threads_count': threads_count,
1059 'do_background_mining': do_background_mining,
1060 'ignore_battery': ignore_battery,
1061 },
1062 'id': '0'
1063 }
1064 return self.rpc.send_json_rpc_request(start_mining)
1065
1066 def stop_mining(self):
1067 stop_mining = {
1068 'method': 'stop_mining',
1069 'jsonrpc': '2.0',
1070 'params': {
1071 },
1072 'id': '0'
1073 }
1074 return self.rpc.send_json_rpc_request(stop_mining)
1075
1076 def estimate_tx_size_and_weight(self, n_inputs, n_outputs, ring_size = 0, rct = True):
1077 estimate_tx_size_and_weight = {
1078 'method': 'estimate_tx_size_and_weight',
1079 'jsonrpc': '2.0',
1080 'params': {
1081 'n_inputs': n_inputs,
1082 'n_outputs': n_outputs,
1083 'ring_size': ring_size,
1084 'rct': rct,
1085 },
1086 'id': '0'
1087 }
1088 return self.rpc.send_json_rpc_request(estimate_tx_size_and_weight)
1089
1090 def get_default_fee_priority(self):
1091 get_default_fee_priority = {
1092 'method': 'get_default_fee_priority',
1093 'jsonrpc': '2.0',
1094 'params': {
1095 },
1096 'id': '0'
1097 }
1098 return self.rpc.send_json_rpc_request(get_default_fee_priority)
1099
1100 def get_version(self):
1101 get_version = {
1102 'method': 'get_version',
1103 'jsonrpc': '2.0',
1104 'id': '0'
1105 }
1106 return self.rpc.send_json_rpc_request(get_version)
1107
1108 def scan_tx(self, txids):
1109 scan_tx = {
1110 'method': 'scan_tx',
1111 'jsonrpc': '2.0',
1112 'params' : {
1113 'txids': txids,
1114 },
1115 'id': '0'
1116 }
1117 return self.rpc.send_json_rpc_request(scan_tx)
1118
1119 def freeze(self, key_image):
1120 freeze = {
1121 'method': 'freeze',
1122 'jsonrpc': '2.0',
1123 'params' : {
1124 'key_image': key_image,
1125 },
1126 'id': '0'
1127 }
1128 return self.rpc.send_json_rpc_request(freeze)
1129
1130 def thaw(self, key_image):
1131 thaw = {
1132 'method': 'thaw',
1133 'jsonrpc': '2.0',
1134 'params' : {
1135 'key_image': key_image,
1136 },
1137 'id': '0'
1138 }
1139 return self.rpc.send_json_rpc_request(thaw)
1140
1141 def frozen(self, key_image):
1142 frozen = {
1143 'method': 'frozen',
1144 'jsonrpc': '2.0',
1145 'params' : {
1146 'key_image': key_image,
1147 },
1148 'id': '0'
1149 }
1150 return self.rpc.send_json_rpc_request(frozen)
1151
1152 class BackgroundSyncOptions(object):
1153 def __init__(self):
1154 self.off = 'off'
1155 self.reuse_password = 'reuse-wallet-password'
1156 self.custom_password = 'custom-background-password'
1157 background_sync_options = BackgroundSyncOptions()
1158
1159 def setup_background_sync(self, background_sync_type = background_sync_options.off, wallet_password = '', background_cache_password = ''):
1160 setup_background_sync = {
1161 'method': 'setup_background_sync',
1162 'jsonrpc': '2.0',
1163 'params' : {
1164 'background_sync_type': background_sync_type,
1165 'wallet_password': wallet_password,
1166 'background_cache_password': background_cache_password,
1167 },
1168 'id': '0'
1169 }
1170 return self.rpc.send_json_rpc_request(setup_background_sync)
1171
1172 def start_background_sync(self):
1173 start_background_sync = {
1174 'method': 'start_background_sync',
1175 'jsonrpc': '2.0',
1176 'params' : {},
1177 'id': '0'
1178 }
1179 return self.rpc.send_json_rpc_request(start_background_sync)
1180
1181 def stop_background_sync(self, wallet_password = '', seed = '', seed_offset = ''):
1182 stop_background_sync = {
1183 'method': 'stop_background_sync',
1184 'jsonrpc': '2.0',
1185 'params' : {
1186 'wallet_password': wallet_password,
1187 'seed': seed,
1188 'seed_offset': seed_offset,
1189 },
1190 'id': '0'
1191 }
1192 return self.rpc.send_json_rpc_request(stop_background_sync)