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

Fixed issue #66

parent 3ce838ba
No related branches found
No related tags found
No related merge requests found
...@@ -23,23 +23,30 @@ class Transfer(object): ...@@ -23,23 +23,30 @@ class Transfer(object):
''' '''
Constructor Constructor
''' '''
assert('receiver' in metadata)
assert('block' in metadata)
assert('time' in metadata)
assert('issuer' in metadata)
assert('amount' in metadata)
assert('comment' in metadata)
self.txdoc = txdoc self.txdoc = txdoc
self.state = state self.state = state
self.metadata = metadata self._metadata = metadata
@classmethod @classmethod
def initiate(cls, block, time, amount, issuer, receiver, comment): def initiate(cls, metadata):
return cls(None, Transfer.TO_SEND, {'block': block, return cls(None, Transfer.TO_SEND, metadata)
'time': time,
'amount': amount,
'issuer': issuer,
'receiver': receiver,
'comment': comment})
@classmethod @classmethod
def create_validated(cls, txdoc, metadata): def create_validated(cls, txdoc, metadata):
logging.debug("VALIDATED : {0}".format(metadata))
return cls(txdoc, Transfer.VALIDATED, metadata) return cls(txdoc, Transfer.VALIDATED, metadata)
@property
def metadata(self):
return self._metadata
@classmethod @classmethod
def load(cls, data): def load(cls, data):
if data['state'] is Transfer.TO_SEND: if data['state'] is Transfer.TO_SEND:
...@@ -55,7 +62,7 @@ class Transfer(object): ...@@ -55,7 +62,7 @@ class Transfer(object):
txraw = None txraw = None
return {'txdoc': txraw, return {'txdoc': txraw,
'state': self.state, 'state': self.state,
'metadata': self.metadata} 'metadata': self._metadata}
def send(self, txdoc, community): def send(self, txdoc, community):
try: try:
...@@ -68,20 +75,22 @@ class Transfer(object): ...@@ -68,20 +75,22 @@ class Transfer(object):
self.state = Transfer.REFUSED self.state = Transfer.REFUSED
raise raise
finally: finally:
self.metadata['block'] = community.current_blockid()['number'] self._metadata['block'] = community.current_blockid()['number']
self.metadata['time'] = community.get_block().mediantime self._metadata['time'] = community.get_block().mediantime
def check_registered(self, tx, metadata):
logging.debug("{0} > {1} ?".format(metadata['block'], def check_registered(self, tx, block, time):
self.metadata['block'] + 15)) logging.debug("REGISTERED : BEFORE : {0}".format(self._metadata))
if tx.signed_raw() == self.txdoc.signed_raw(): if tx.signed_raw() == self.txdoc.signed_raw():
self.state = Transfer.VALIDATED self.state = Transfer.VALIDATED
self.metadata = metadata self._metadata['block'] = block
self._metadata['time'] = time
logging.debug("REGISTERED : AFTER : {0}".format(self._metadata))
def check_refused(self, block): def check_refused(self, block):
if block > self.metadata['block'] + 15: logging.debug("REFUSED : BEFORE : {0}".format(self._metadata))
if block > self._metadata['block'] + 15:
self.state = Transfer.REFUSED self.state = Transfer.REFUSED
logging.debug("REFUSED : AFTER : {0}".format(self._metadata))
def drop(self): def drop(self):
self.state = Transfer.DROPPED self.state = Transfer.DROPPED
......
...@@ -65,9 +65,6 @@ class Cache(): ...@@ -65,9 +65,6 @@ class Cache():
# Lets look if transactions took too long to be validated # Lets look if transactions took too long to be validated
awaiting = [t for t in self._transfers awaiting = [t for t in self._transfers
if t.state == Transfer.AWAITING] if t.state == Transfer.AWAITING]
for transfer in awaiting:
transfer.check_refused(current_block)
with_tx = community.request(bma.blockchain.TX) with_tx = community.request(bma.blockchain.TX)
# We parse only blocks with transactions # We parse only blocks with transactions
...@@ -88,13 +85,15 @@ class Cache(): ...@@ -88,13 +85,15 @@ class Cache():
except: except:
logging.debug("Error in {0}".format(block_number)) logging.debug("Error in {0}".format(block_number))
raise raise
metadata = {'block': block_number,
'time': block_doc.mediantime}
for tx in block_doc.transactions: for tx in block_doc.transactions:
metadata['issuer'] = tx.issuers[0] metadata = {'block': block_number,
'time': block_doc.mediantime,
'comment': tx.comment,
'issuer': tx.issuers[0]}
receivers = [o.pubkey for o in tx.outputs receivers = [o.pubkey for o in tx.outputs
if o.pubkey != metadata['issuer']] if o.pubkey != metadata['issuer']]
metadata['receiver'] = receivers[0] metadata['receiver'] = receivers[0]
logging.debug("RECEIVER = {0}".format(metadata['receiver']))
in_issuers = len([i for i in tx.issuers in_issuers = len([i for i in tx.issuers
if i == self.wallet.pubkey]) > 0 if i == self.wallet.pubkey]) > 0
...@@ -109,14 +108,14 @@ class Cache(): ...@@ -109,14 +108,14 @@ class Cache():
awaiting = [t for t in self._transfers awaiting = [t for t in self._transfers
if t.state == Transfer.AWAITING] if t.state == Transfer.AWAITING]
awaiting_docs = [t.txdoc.signed_raw() for t in awaiting] awaiting_docs = [t.txdoc.signed_raw() for t in awaiting]
logging.debug(tx.signed_raw())
logging.debug(awaiting_docs)
if tx.signed_raw() not in awaiting_docs: if tx.signed_raw() not in awaiting_docs:
transfer = Transfer.create_validated(tx, metadata) transfer = Transfer.create_validated(tx,
metadata.copy())
self._transfers.append(transfer) self._transfers.append(transfer)
else: else:
for transfer in awaiting: for transfer in awaiting:
transfer.check_registered(tx, metadata) transfer.check_registered(tx, block_number,
block_doc.mediantime)
else: else:
outputs = [o for o in tx.outputs outputs = [o for o in tx.outputs
if o.pubkey == self.wallet.pubkey] if o.pubkey == self.wallet.pubkey]
...@@ -125,10 +124,13 @@ class Cache(): ...@@ -125,10 +124,13 @@ class Cache():
for o in outputs: for o in outputs:
amount += o.amount amount += o.amount
metadata['amount'] = amount metadata['amount'] = amount
self._transfers.append(Received(tx, metadata)) self._transfers.append(Received(tx,
metadata.copy()))
if current_block > self.latest_block: if current_block > self.latest_block:
self.available_sources = self.wallet.sources(community) self.available_sources = self.wallet.sources(community)
for transfer in awaiting:
transfer.check_refused(current_block)
except NoPeerAvailable: except NoPeerAvailable:
return return
...@@ -253,8 +255,15 @@ class Wallet(object): ...@@ -253,8 +255,15 @@ 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))
transfer = Transfer.initiate(block_number, time, amount, metadata = {'block': block_number,
key.pubkey, recipient, message) 'time': time,
'amount': amount,
'issuer': key.pubkey,
'receiver': recipient,
'comment': message
}
transfer = Transfer.initiate(metadata)
self.caches[community.currency]._transfers.append(transfer) self.caches[community.currency]._transfers.append(transfer)
result = self.tx_inputs(int(amount), community) result = self.tx_inputs(int(amount), community)
......
...@@ -176,7 +176,7 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): ...@@ -176,7 +176,7 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
join_date = self.community.get_block(join_block).mediantime join_date = self.community.get_block(join_block).mediantime
parameters = self.community.get_parameters() parameters = self.community.get_parameters()
expiration_date = join_date + parameters['sigValidity'] expiration_date = join_date + parameters['sigValidity']
current_time = QDateTime().currentDateTime() current_time = QDateTime().currentDateTime().toTime_t()
sig_validity = self.community.get_parameters()['sigValidity'] sig_validity = self.community.get_parameters()['sigValidity']
warning_expiration_time = int(sig_validity / 3) warning_expiration_time = int(sig_validity / 3)
will_expire_soon = (current_time > expiration_date*1000 - warning_expiration_time*1000) will_expire_soon = (current_time > expiration_date*1000 - warning_expiration_time*1000)
......
...@@ -43,11 +43,7 @@ class PersonNotFoundError(Error): ...@@ -43,11 +43,7 @@ class PersonNotFoundError(Error):
Constructor Constructor
''' '''
super() .__init__( super() .__init__(
"Person looked by " + "Person looked by {0} in {1} not found ".format(value, community))
value +
" in " +
community +
" not found ")
class MembershipNotFoundError(Error): class MembershipNotFoundError(Error):
......
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