diff --git a/src/cutecoin/core/transfer.py b/src/cutecoin/core/transfer.py index 23587de0aff0f0bb865b13b4ce959ee42378e05e..edbb505310976dbc1ac1ecfba75b542ee06e405b 100644 --- a/src/cutecoin/core/transfer.py +++ b/src/cutecoin/core/transfer.py @@ -28,12 +28,13 @@ class Transfer(object): self.metadata = metadata @classmethod - def initiate(cls, txdoc, block, time, amount, issuer, receiver): - return cls(txdoc, Transfer.TO_SEND, {'block': block, + def initiate(cls, block, time, amount, issuer, receiver, comment): + return cls(None, Transfer.TO_SEND, {'block': block, 'time': time, 'amount': amount, 'issuer': issuer, - 'receiver': receiver}) + 'receiver': receiver, + 'comment': comment}) @classmethod def create_validated(cls, txdoc, metadata): @@ -56,8 +57,9 @@ class Transfer(object): 'state': self.state, 'metadata': self.metadata} - def send(self, community): + def send(self, txdoc, community): try: + self.txdoc = txdoc community.broadcast(bma.tx.Process, post_args={'transaction': self.txdoc.signed_raw()}) self.state = Transfer.AWAITING diff --git a/src/cutecoin/core/wallet.py b/src/cutecoin/core/wallet.py index 4d7b490b81c7ed4c2cee289667c121c7bbd72e4b..04ba3b38addc6e788631033cdcbcfa3c7bb21548 100644 --- a/src/cutecoin/core/wallet.py +++ b/src/cutecoin/core/wallet.py @@ -238,6 +238,7 @@ class Wallet(object): def send_money(self, salt, password, community, recipient, amount, message): + time = community.get_block().time block_number = community.current_blockid()['number'] key = None @@ -248,31 +249,25 @@ class Wallet(object): key = SigningKey("{0}{1}".format(salt, self.walletid), password) logging.debug("Sender pubkey:{0}".format(key.pubkey)) - 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 + transfer = Transfer.initiate(block_number, time, amount, + key.pubkey, recipient, message) + self.caches[community.currency]._transfers.append(transfer) + + 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.send(tx, community) def sources(self, community): data = community.request(bma.tx.Sources, diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py index bf916d8d194c36a3000c132bd33b65a5e53de7f7..db999f385f7a1886d662ca340825befc8f5375fa 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/currency_tab.py @@ -254,6 +254,7 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): dialog.combo_community.setCurrentText(self.community.name()) dialog.spinbox_amount.setValue(transfer.metadata['amount']) dialog.radio_pubkey.setChecked(True) + dialog.edit_message.setText(transfer.metadata['comment']) result = dialog.exec_() if result == QDialog.Accepted: transfer.drop()