def interpret(self, decoded_event, txid, block_number, eon_number, verbose=False): wallet_address = hex_address(decoded_event.get(u'recipient')) try: wallet = Wallet.objects.get(token__address__iexact=hex_address( decoded_event.get(u'token')), address__iexact=wallet_address) except Wallet.DoesNotExist: logger.warning( "UNKNOWN WALLET PERFORMING DEPOSIT {}".format(wallet_address)) BlacklistEntry.objects.get_or_create(address=wallet_address) return with wallet.lock(auto_renewal=True): deposit = Deposit.objects.create( wallet=wallet, amount=decoded_event.get(u'amount'), eon_number=eon_number, block=block_number, txid=remove_0x_prefix(txid)) # send deposit added notification to sender send_notification(stream_prefix="wallet", stream_id="{}/{}".format(wallet.token.address, wallet.address), event_name=CONFIRMED_DEPOSIT, data=DepositSerializer(deposit, read_only=True).data)
def interpret(self, decoded_event, txid, block_number, eon_number, verbose=False): token_address = decoded_event.get(u'token') wallet_address = decoded_event.get(u'requestor') amount = decoded_event.get(u'amount') try: wallet = Wallet.objects.get( token__address__iexact=hex_address(token_address), address__iexact=hex_address(wallet_address)) except Wallet.DoesNotExist: return # get all unconfirmed unslashed withdrawal requests for this wallet # sorted in ascending order by the date they were added unslashed_unconfirmed_requests = WithdrawalRequest.objects \ .filter(wallet=wallet, slashed=False, withdrawal__isnull=True) \ .order_by('id') withdrawal_requests = [] accumulator = 0 # add withdrawal requests until confirmation amount is reached # from older to newer requests for withdrawal_request in unslashed_unconfirmed_requests: if accumulator < amount: withdrawal_requests.append(withdrawal_request) accumulator += withdrawal_request.amount else: break # if accumulator is not equal to confirmed amount there is something very wrong going on if accumulator != amount: logger.error( 'CONFIRMED WITHDRAWALS BY {} FOR TOKEN {} DID NOT SUM UP TO EXPECTED AMOUNT {}' .format(hex_address(wallet_address), hex_address(token_address), amount)) # create a withdrawal object for every confirmed withdrawal request for withdrawal_request in withdrawal_requests: confirmation = Withdrawal( wallet=wallet, amount=withdrawal_request.amount, eon_number=eon_number, request=withdrawal_request, block=block_number, txid=remove_0x_prefix(txid)) # send withdrawal confirmed notification to wallet send_notification( stream_prefix="wallet", stream_id="{}/{}".format(wallet.token.address, wallet.address), event_name=CONFIRMED_WITHDRAWAL, data=WithdrawalSerializer( confirmation, read_only=True).data ) if verbose: print(withdrawal_request) print(confirmation) confirmation.save()
def interpret(self, decoded_event, txid, block_number, eon_number, verbose=False): try: wallet = Wallet.objects.get( token__address__iexact=hex_address( decoded_event.get(u'token')), address__iexact=hex_address(decoded_event.get(u'requestor'))) except Wallet.DoesNotExist: # TODO this is a problem logger.error("UNKNOWN WALLET REQUESTING WITHDRAWAL {}".format( hex_address(decoded_event.get(u'requestor')))) return with wallet.lock(auto_renewal=True): withdrawal_request = WithdrawalRequest.objects.create( wallet=wallet, amount=decoded_event.get(u'amount'), eon_number=eon_number, block=block_number, txid=remove_0x_prefix(txid)) # send withdrawal requested notification to wallet send_notification( stream_prefix="wallet", stream_id="{}/{}".format(wallet.token.address, wallet.address), event_name=REQUESTED_WITHDRAWAL, data=WithdrawalRequestSerializer( withdrawal_request, read_only=True).data ) logger.warning(withdrawal_request) if verbose: print(withdrawal_request)
def interpret(self, decoded_event, txid, block_number, eon_number, verbose=False): sender_address = hex_address(decoded_event.get(u'sender')) recipient_address = hex_address(decoded_event.get(u'recipient')) token_address = hex_address(decoded_event.get(u'token')) # delivery or state challenge try: token = Token.objects.get(address__iexact=token_address) try: wallet = Wallet.objects.get( address__iexact=sender_address, token=token) except Wallet.DoesNotExist: send_address_not_found_log("SENDER", sender_address) return try: recipient = Wallet.objects.get( address__iexact=recipient_address, token=token) except Wallet.DoesNotExist: send_address_not_found_log("RECIPIENT", sender_address) return # swap challenge except Token.DoesNotExist: try: token_pair = TokenPair.objects.get( conduit__iexact=token_address) except TokenPair.DoesNotExist: send_address_not_found_log( "TOKEN PAIR WITH CONDUIT", token_address) return try: wallet = Wallet.objects.get( address__iexact=sender_address, token=token_pair.token_from) except Wallet.DoesNotExist: send_address_not_found_log("SENDER", sender_address) return try: recipient = Wallet.objects.get( address__iexact=recipient_address, token=token_pair.token_to) except Wallet.DoesNotExist: send_address_not_found_log("RECIPIENT", sender_address) return Challenge.objects.create( wallet=wallet, recipient=recipient, amount=0, eon_number=eon_number, block=block_number, txid=remove_0x_prefix(txid))
def save(self, *args, **kwargs): if not self.pk: result = crypto.hash_array([ crypto.address(self.token_from.address), crypto.address(self.token_to.address) ]) self.conduit = crypto.hex_address(crypto.hex_value(result)) super(TokenPair, self).save(*args, **kwargs)