Skip to content
Snippets Groups Projects
Commit bc3e23a4 authored by inso's avatar inso
Browse files

Added the ability to send again a transaction without enough sources

parent f7a86436
No related branches found
No related tags found
No related merge requests found
......@@ -28,14 +28,12 @@ class Transfer(object):
self.metadata = metadata
@classmethod
def initiate(cls, txdoc, block, time, amount):
receivers = [o.pubkey for o in txdoc.outputs
if o.pubkey != txdoc.issuers[0]]
def initiate(cls, txdoc, block, time, amount, issuer, receiver):
return cls(txdoc, Transfer.TO_SEND, {'block': block,
'time': time,
'amount': amount,
'issuer': txdoc.issuers[0],
'receiver': receivers[0]})
'issuer': issuer,
'receiver': receiver})
@classmethod
def create_validated(cls, txdoc, metadata):
......@@ -43,11 +41,18 @@ class Transfer(object):
@classmethod
def load(cls, data):
txdoc = Transaction.from_signed_raw(data['txdoc'])
if data['state'] is Transfer.TO_SEND:
txdoc = None
else:
txdoc = Transaction.from_signed_raw(data['txdoc'])
return cls(txdoc, data['state'], data['metadata'])
def jsonify(self):
return {'txdoc': self.txdoc.signed_raw(),
if self.txdoc:
txraw = self.txdoc.signed_raw()
else:
txraw = None
return {'txdoc': txraw,
'state': self.state,
'metadata': self.metadata}
......
......@@ -238,18 +238,8 @@ class Wallet(object):
def send_money(self, salt, password, community,
recipient, amount, message):
result = self.tx_inputs(int(amount), community)
inputs = result[0]
self.caches[community.currency].available_sources = result[1]
logging.debug("Inputs : {0}".format(inputs))
outputs = self.tx_outputs(recipient, amount, inputs)
logging.debug("Outputs : {0}".format(outputs))
tx = Transaction(PROTOCOL_VERSION, community.currency,
[self.pubkey], inputs,
outputs, message, None)
logging.debug("TX : {0}".format(tx.raw()))
time = community.get_block().time
block_number = community.current_blockid()['number']
key = None
logging.debug("Key : {0} : {1}".format(salt, password))
if self.walletid == 0:
......@@ -258,15 +248,31 @@ class Wallet(object):
key = SigningKey("{0}{1}".format(salt, self.walletid), password)
logging.debug("Sender pubkey:{0}".format(key.pubkey))
tx.sign([key])
logging.debug("Transaction : {0}".format(tx.signed_raw()))
block_number = community.current_blockid()['number']
time = community.get_block().time
transfer = Transfer.initiate(tx, block_number, time, amount)
transfer.send(community)
self.caches[community.currency]._transfers.append(transfer)
try:
result = self.tx_inputs(int(amount), community)
inputs = result[0]
self.caches[community.currency].available_sources = result[1]
logging.debug("Inputs : {0}".format(inputs))
outputs = self.tx_outputs(recipient, amount, inputs)
logging.debug("Outputs : {0}".format(outputs))
tx = Transaction(PROTOCOL_VERSION, community.currency,
[self.pubkey], inputs,
outputs, message, None)
logging.debug("TX : {0}".format(tx.raw()))
tx.sign([key])
logging.debug("Transaction : {0}".format(tx.signed_raw()))
transfer = Transfer.initiate(tx, block_number, time, amount,
key.pubkey, recipient)
transfer.send(community)
self.caches[community.currency]._transfers.append(transfer)
except NotEnoughMoneyError:
transfer = Transfer.initiate(None, block_number, time, amount,
key.pubkey, recipient)
self.caches[community.currency]._transfers.append(transfer)
raise
def sources(self, community):
data = community.request(bma.tx.Sources,
......
......@@ -213,7 +213,7 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
pubkey_col)
person = model.sourceModel().data(person_index, Qt.DisplayRole)
transfer = model.sourceModel().transfers[source_index.row()]
if state_data == Transfer.REFUSED:
if state_data == Transfer.REFUSED or state_data == Transfer.TO_SEND:
send_back = QAction("Send again", self)
send_back.triggered.connect(self.send_again)
send_back.setData(transfer)
......
......@@ -72,10 +72,9 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
QMessageBox.Ok)
return
except NotEnoughMoneyError as e:
QMessageBox.critical(self, "Money transfer",
"You don't have enough money available in this block : \n{0}"
.format(e.message))
return
QMessageBox.warning(self, "Money transfer",
"""This transaction could not be sent on this block
Please try again later""")
except NoPeerAvailable as e:
QMessageBox.critical(self, "Money transfer",
"Couldn't connect to network : {0}".format(e),
......
......@@ -87,6 +87,8 @@ class TxFilterProxyModel(QSortFilterProxyModel):
font.setItalic(True)
elif state_data == Transfer.REFUSED:
font.setItalic(True)
elif state_data == Transfer.TO_SEND:
font.setBold(True)
else:
font.setItalic(False)
return font
......@@ -94,6 +96,8 @@ class TxFilterProxyModel(QSortFilterProxyModel):
if role == Qt.ForegroundRole:
if state_data == Transfer.REFUSED:
return QColor(Qt.red)
elif state_data == Transfer.TO_SEND:
return QColor(Qt.blue)
return source_data
......@@ -129,7 +133,9 @@ class HistoryTableModel(QAbstractTableModel):
def data_received(self, transfer):
amount = transfer.metadata['amount']
comment = transfer.txdoc.comment
comment = ""
if transfer.txdoc:
comment = transfer.txdoc.comment
pubkey = transfer.metadata['issuer']
try:
#sender = Person.lookup(pubkey, self.community).name
......@@ -148,8 +154,9 @@ class HistoryTableModel(QAbstractTableModel):
def data_sent(self, transfer):
amount = transfer.metadata['amount']
comment = transfer.txdoc.comment
comment = ""
if transfer.txdoc:
comment = transfer.txdoc.comment
pubkey = transfer.metadata['receiver']
try:
#receiver = Person.lookup(pubkey, self.community).name
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment