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

Send back a transaction now save the comment too

parent bc3e23a4
No related branches found
No related tags found
No related merge requests found
...@@ -28,12 +28,13 @@ class Transfer(object): ...@@ -28,12 +28,13 @@ class Transfer(object):
self.metadata = metadata self.metadata = metadata
@classmethod @classmethod
def initiate(cls, txdoc, block, time, amount, issuer, receiver): def initiate(cls, block, time, amount, issuer, receiver, comment):
return cls(txdoc, Transfer.TO_SEND, {'block': block, return cls(None, Transfer.TO_SEND, {'block': block,
'time': time, 'time': time,
'amount': amount, 'amount': amount,
'issuer': issuer, 'issuer': issuer,
'receiver': receiver}) 'receiver': receiver,
'comment': comment})
@classmethod @classmethod
def create_validated(cls, txdoc, metadata): def create_validated(cls, txdoc, metadata):
...@@ -56,8 +57,9 @@ class Transfer(object): ...@@ -56,8 +57,9 @@ class Transfer(object):
'state': self.state, 'state': self.state,
'metadata': self.metadata} 'metadata': self.metadata}
def send(self, community): def send(self, txdoc, community):
try: try:
self.txdoc = txdoc
community.broadcast(bma.tx.Process, community.broadcast(bma.tx.Process,
post_args={'transaction': self.txdoc.signed_raw()}) post_args={'transaction': self.txdoc.signed_raw()})
self.state = Transfer.AWAITING self.state = Transfer.AWAITING
......
...@@ -238,6 +238,7 @@ class Wallet(object): ...@@ -238,6 +238,7 @@ class Wallet(object):
def send_money(self, salt, password, community, def send_money(self, salt, password, community,
recipient, amount, message): recipient, amount, message):
time = community.get_block().time time = community.get_block().time
block_number = community.current_blockid()['number'] block_number = community.current_blockid()['number']
key = None key = None
...@@ -248,31 +249,25 @@ class Wallet(object): ...@@ -248,31 +249,25 @@ class Wallet(object):
key = SigningKey("{0}{1}".format(salt, self.walletid), password) key = SigningKey("{0}{1}".format(salt, self.walletid), password)
logging.debug("Sender pubkey:{0}".format(key.pubkey)) logging.debug("Sender pubkey:{0}".format(key.pubkey))
try: transfer = Transfer.initiate(block_number, time, amount,
result = self.tx_inputs(int(amount), community) key.pubkey, recipient, message)
inputs = result[0] self.caches[community.currency]._transfers.append(transfer)
self.caches[community.currency].available_sources = result[1]
logging.debug("Inputs : {0}".format(inputs)) result = self.tx_inputs(int(amount), community)
inputs = result[0]
outputs = self.tx_outputs(recipient, amount, inputs) self.caches[community.currency].available_sources = result[1]
logging.debug("Outputs : {0}".format(outputs)) logging.debug("Inputs : {0}".format(inputs))
tx = Transaction(PROTOCOL_VERSION, community.currency,
[self.pubkey], inputs, outputs = self.tx_outputs(recipient, amount, inputs)
outputs, message, None) logging.debug("Outputs : {0}".format(outputs))
logging.debug("TX : {0}".format(tx.raw())) tx = Transaction(PROTOCOL_VERSION, community.currency,
[self.pubkey], inputs,
tx.sign([key]) outputs, message, None)
logging.debug("Transaction : {0}".format(tx.signed_raw())) logging.debug("TX : {0}".format(tx.raw()))
transfer = Transfer.initiate(tx, block_number, time, amount, tx.sign([key])
key.pubkey, recipient) logging.debug("Transaction : {0}".format(tx.signed_raw()))
transfer.send(community) transfer.send(tx, 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): def sources(self, community):
data = community.request(bma.tx.Sources, data = community.request(bma.tx.Sources,
......
...@@ -254,6 +254,7 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): ...@@ -254,6 +254,7 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
dialog.combo_community.setCurrentText(self.community.name()) dialog.combo_community.setCurrentText(self.community.name())
dialog.spinbox_amount.setValue(transfer.metadata['amount']) dialog.spinbox_amount.setValue(transfer.metadata['amount'])
dialog.radio_pubkey.setChecked(True) dialog.radio_pubkey.setChecked(True)
dialog.edit_message.setText(transfer.metadata['comment'])
result = dialog.exec_() result = dialog.exec_()
if result == QDialog.Accepted: if result == QDialog.Accepted:
transfer.drop() transfer.drop()
......
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