mirror of
https://git.wownero.com/lza_menace/wownero-python.git
synced 2024-08-15 03:25:25 +00:00
Allow creating txs without relaying to the network
This commit is contained in:
parent
1be5d0b063
commit
34fa48fcf8
4 changed files with 38 additions and 11 deletions
|
@ -36,16 +36,21 @@ class Account(object):
|
|||
def get_transactions_out(self):
|
||||
return self._backend.get_transactions_out(account=self.index)
|
||||
|
||||
def transfer(self, address, amount, priority=prio.NORMAL, ringsize=5, payment_id=None, unlock_time=0):
|
||||
def transfer(self, address, amount,
|
||||
priority=prio.NORMAL, ringsize=5, payment_id=None, unlock_time=0,
|
||||
relay=True):
|
||||
return self._backend.transfer(
|
||||
[(address, amount)],
|
||||
priority,
|
||||
ringsize,
|
||||
payment_id,
|
||||
unlock_time,
|
||||
account=self.index)
|
||||
account=self.index,
|
||||
relay=relay)
|
||||
|
||||
def transfer_multiple(self, destinations, priority=prio.NORMAL, ringsize=5, payment_id=None, unlock_time=0):
|
||||
def transfer_multiple(self, destinations,
|
||||
priority=prio.NORMAL, ringsize=5, payment_id=None, unlock_time=0,
|
||||
relay=True):
|
||||
"""
|
||||
destinations = [(address, amount), ...]
|
||||
"""
|
||||
|
@ -55,4 +60,5 @@ class Account(object):
|
|||
ringsize,
|
||||
payment_id,
|
||||
unlock_time,
|
||||
account=self.index)
|
||||
account=self.index,
|
||||
relay=relay)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import binascii
|
||||
from datetime import datetime
|
||||
import operator
|
||||
import json
|
||||
|
@ -115,7 +116,9 @@ class JSONRPCWallet(object):
|
|||
'blob': tx.get('blob', None),
|
||||
}
|
||||
|
||||
def transfer(self, destinations, priority, ringsize, payment_id=None, unlock_time=0, account=0):
|
||||
def transfer(self, destinations, priority, ringsize,
|
||||
payment_id=None, unlock_time=0, account=0,
|
||||
relay=True):
|
||||
data = {
|
||||
'account_index': account,
|
||||
'destinations': list(map(
|
||||
|
@ -127,6 +130,7 @@ class JSONRPCWallet(object):
|
|||
'get_tx_keys': True,
|
||||
'get_tx_hex': True,
|
||||
'new_algorithm': True,
|
||||
'do_not_relay': not relay,
|
||||
}
|
||||
if payment_id is not None:
|
||||
data['payment_id'] = str(PaymentID(payment_id))
|
||||
|
|
|
@ -52,16 +52,21 @@ class Wallet(object):
|
|||
def get_transactions_out(self):
|
||||
return self.accounts[0].get_transactions_out()
|
||||
|
||||
def transfer(self, address, amount, priority=prio.NORMAL, ringsize=5, payment_id=None, unlock_time=0):
|
||||
def transfer(self, address, amount,
|
||||
priority=prio.NORMAL, ringsize=5, payment_id=None, unlock_time=0,
|
||||
relay=True):
|
||||
return self.accounts[0].transfer(
|
||||
address,
|
||||
amount,
|
||||
priority=priority,
|
||||
ringsize=ringsize,
|
||||
payment_id=None,
|
||||
unlock_time=unlock_time)
|
||||
unlock_time=unlock_time,
|
||||
relay=relay)
|
||||
|
||||
def transfer_multiple(self, destinations, priority=prio.NORMAL, ringsize=5, payment_id=None, unlock_time=0):
|
||||
def transfer_multiple(self, destinations,
|
||||
priority=prio.NORMAL, ringsize=5, payment_id=None, unlock_time=0,
|
||||
relay=True):
|
||||
"""
|
||||
destinations = [(address, amount), ...]
|
||||
"""
|
||||
|
@ -70,4 +75,5 @@ class Wallet(object):
|
|||
priority=priority,
|
||||
ringsize=ringsize,
|
||||
payment_id=None,
|
||||
unlock_time=unlock_time)
|
||||
unlock_time=unlock_time,
|
||||
relay=relay)
|
||||
|
|
|
@ -2,6 +2,7 @@ import argparse
|
|||
from decimal import Decimal
|
||||
import operator
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
|
||||
|
@ -34,6 +35,9 @@ argsparser.add_argument('-r', dest='ring_size', type=int, default=5, help="Ring
|
|||
argsparser.add_argument('-i', dest='payment_id', nargs='?', type=PaymentID,
|
||||
const=PaymentID(random.randint(0, 2**256)),
|
||||
help="Payment ID")
|
||||
argsparser.add_argument('--save', dest='outdir', nargs='?', default=None, const='.',
|
||||
help="Save to file, optionally follow by destination directory (default is .)\n"
|
||||
"Transaction will be not relayed to the network.")
|
||||
argsparser.add_argument('destinations', metavar='address:amount', nargs='+', type=destpair,
|
||||
help="Destination address and amount (one or more pairs)")
|
||||
args = argsparser.parse_args()
|
||||
|
@ -48,9 +52,16 @@ logging.basicConfig(level=level, format="%(asctime)-15s %(message)s")
|
|||
|
||||
w = Wallet(JSONRPCWallet(**args.daemon_url))
|
||||
txfrs = w.accounts[args.account].transfer_multiple(
|
||||
args.destinations, priority=prio, mixin=args.ring_size, payment_id=args.payment_id)
|
||||
args.destinations, priority=prio, ringsize=args.ring_size, payment_id=args.payment_id,
|
||||
relay=args.outdir is None)
|
||||
for tx in txfrs:
|
||||
print(u"Transaction {hash}:\nXMR: {amount:21.12f} @ {fee:13.12f} fee\n"
|
||||
u"Payment ID: {payment_id}\nTx key: {key}\nSize: {size} B".format(
|
||||
hash=tx.hash, amount=tx.amount, fee=tx.fee,
|
||||
payment_id=tx.payment_id, key=tx.key, size=len(tx.blob) >> 1))
|
||||
payment_id=tx.payment_id, key=tx.key, size=len(tx.blob)))
|
||||
if args.outdir:
|
||||
outname = os.path.join(args.outdir, tx.hash + '.tx')
|
||||
outfile = open(outname, 'wb')
|
||||
outfile.write(tx.blob)
|
||||
outfile.close()
|
||||
print(u"Transaction saved to {}".format(outname))
|
||||
|
|
Loading…
Reference in a new issue