Skip to content

Commit

Permalink
Remove all future/py2 compatibility code remaining.
Browse files Browse the repository at this point in the history
This is in line with #525 and corrects erroneous
addition of more compatibility code.
  • Loading branch information
AdamISZ committed Jun 5, 2020
1 parent 647e318 commit 3b55ca2
Show file tree
Hide file tree
Showing 23 changed files with 37 additions and 73 deletions.
2 changes: 1 addition & 1 deletion jmbase/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
author_email='',
license='GPL',
packages=['jmbase'],
install_requires=['future', 'twisted==19.7.0', 'service-identity',
install_requires=['twisted==19.7.0', 'service-identity',
'chromalog==1.0.5'],
python_requires='>=3.3',
zip_safe=False)
9 changes: 3 additions & 6 deletions jmbitcoin/jmbitcoin/secp256k1_ecies.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/usr/bin/python
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import * # noqa: F401
from future.utils import native

import coincurve as secp256k1
import base64
import hmac
Expand All @@ -19,15 +16,15 @@ class ECIESDecryptionError(Exception):
# AES primitives. See BIP-SNICKER for specification.
def aes_encrypt(key, data, iv):
encrypter = pyaes.Encrypter(
pyaes.AESModeOfOperationCBC(key, iv=native(iv)))
pyaes.AESModeOfOperationCBC(key, iv=iv))
enc_data = encrypter.feed(data)
enc_data += encrypter.feed()

return enc_data

def aes_decrypt(key, data, iv):
decrypter = pyaes.Decrypter(
pyaes.AESModeOfOperationCBC(key, iv=native(iv)))
pyaes.AESModeOfOperationCBC(key, iv=iv))
try:
dec_data = decrypter.feed(data)
dec_data += decrypter.feed()
Expand Down
5 changes: 2 additions & 3 deletions jmbitcoin/jmbitcoin/secp256k1_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/python
from future.utils import native_bytes, bytes_to_native_str
import binascii
import hashlib
import sys
Expand Down Expand Up @@ -60,7 +59,7 @@ def privkey_to_pubkey(priv):
and return compressed/uncompressed public key as appropriate.'''
compressed, priv = read_privkey(priv)
#secp256k1 checks for validity of key value.
newpriv = secp256k1.PrivateKey(secret=native_bytes(priv))
newpriv = secp256k1.PrivateKey(secret=priv)
return newpriv.public_key.format(compressed)

# b58check wrapper functions around bitcointx.base58 functions:
Expand Down Expand Up @@ -137,7 +136,7 @@ def multiply(s, pub, return_serialized=True):
'''
newpub = secp256k1.PublicKey(pub)
#see note to "tweak_mul" function in podle.py
res = newpub.multiply(native_bytes(s))
res = newpub.multiply(s)
if not return_serialized:
return res
return res.format()
Expand Down
4 changes: 0 additions & 4 deletions jmbitcoin/jmbitcoin/snicker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import * # noqa: F401

# Implementation of proposal as per
# https://gist.github.com/AdamISZ/2c13fb5819bd469ca318156e2cf25d79
# (BIP SNICKER)
Expand Down
3 changes: 1 addition & 2 deletions jmbitcoin/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
author_email='',
license='GPL',
packages=['jmbitcoin'],
install_requires=['future', 'coincurve', 'urldecode',
'python-bitcointx>=1.0.5', 'pyaes'],
install_requires=['coincurve', 'python-bitcointx>=1.0.5', 'pyaes', 'urldecode'],
zip_safe=False)
3 changes: 0 additions & 3 deletions jmbitcoin/test/test_ecdh.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#! /usr/bin/env python
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import * # noqa: F401
'''Tests coincurve binding to libsecp256k1 ecdh module code'''

import hashlib
Expand Down
3 changes: 0 additions & 3 deletions jmbitcoin/test/test_ecies.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#! /usr/bin/env python
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import * # noqa: F401
'''Tests ECIES implementation as defined in BIP-SNICKER
(and will be updated if that is).'''

Expand Down
3 changes: 1 addition & 2 deletions jmclient/jmclient/client_protocol.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#! /usr/bin/env python
from future.utils import iteritems
from twisted.internet import protocol, reactor, task
from twisted.internet.error import (ConnectionLost, ConnectionAborted,
ConnectionClosed, ConnectionDone)
Expand Down Expand Up @@ -303,7 +302,7 @@ def on_JM_TX_RECEIVED(self, nick, txhex, offer):
return {"accepted": True}

def tx_match(self, txd):
for k,v in iteritems(self.finalized_offers):
for k,v in items(self.finalized_offers):
# Tx considered defined by its output set
if v["txd"].vout == txd.vout:
offerinfo = v
Expand Down
3 changes: 1 addition & 2 deletions jmclient/jmclient/electruminterface.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from future.utils import iteritems
import jmbitcoin as btc
import json
import queue as Queue
Expand Down Expand Up @@ -332,7 +331,7 @@ def sync_unspent(self, wallet):
for m in range(wallet.max_mixdepth):
for fc in [0, 1]:
branch_list = []
for k, v in iteritems(self.temp_addr_history[m][fc]):
for k, v in self.temp_addr_history[m][fc].items():
if k == "finished":
continue
if v["used"]:
Expand Down
5 changes: 2 additions & 3 deletions jmclient/jmclient/maker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#! /usr/bin/env python
from future.utils import iteritems
import base64
import pprint
import random
Expand Down Expand Up @@ -470,7 +469,7 @@ def on_tx_received(self, nick, txser):
[x[1] for x in utxo.values()])

total_sender_input = 0
for i, u in iteritems(utxo):
for i, u in utxo.items():
if utxo_data[i] is None:
return (False, "Proposed transaction contains invalid utxos")
total_sender_input += utxo_data[i]["value"]
Expand Down Expand Up @@ -505,7 +504,7 @@ def on_tx_received(self, nick, txser):

# Manual verification of the transaction signatures.
# TODO handle native segwit properly
for i, u in iteritems(utxo):
for i, u in utxo.items():
if not btc.verify_tx_input(tx, i,
tx.vin[i].scriptSig,
btc.CScript(utxo_data[i]["script"]),
Expand Down
3 changes: 0 additions & 3 deletions jmclient/jmclient/snicker_receiver.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#! /usr/bin/env python
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import * # noqa: F401

import sys
import binascii
Expand Down
6 changes: 2 additions & 4 deletions jmclient/jmclient/storage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from future.utils import native

import os
import shutil
import atexit
Expand Down Expand Up @@ -253,15 +251,15 @@ def _decrypt_file(self, password, data):

def _encrypt(self, data, iv):
encrypter = pyaes.Encrypter(
pyaes.AESModeOfOperationCBC(self._hash.hash, iv=native(iv)))
pyaes.AESModeOfOperationCBC(self._hash.hash, iv=iv))
enc_data = encrypter.feed(self.MAGIC_DETECT_ENC + data)
enc_data += encrypter.feed()

return enc_data

def _decrypt(self, data, iv):
decrypter = pyaes.Decrypter(
pyaes.AESModeOfOperationCBC(self._hash.hash, iv=native(iv)))
pyaes.AESModeOfOperationCBC(self._hash.hash, iv=iv))
try:
dec_data = decrypter.feed(data)
dec_data += decrypter.feed()
Expand Down
16 changes: 7 additions & 9 deletions jmclient/jmclient/taker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#! /usr/bin/env python
from future.utils import iteritems

import base64
import pprint
Expand Down Expand Up @@ -354,7 +353,7 @@ def receive_utxos(self, ioauth_data):
rejected_counterparties = []

#Need to authorize against the btc pubkey first.
for nick, nickdata in iteritems(ioauth_data):
for nick, nickdata in ioauth_data.items():
utxo_list, auth_pub, cj_addr, change_addr, btc_sig, maker_pk = nickdata
if not self.auth_counterparty(btc_sig, auth_pub, maker_pk):
jlog.debug(
Expand All @@ -374,7 +373,7 @@ def receive_utxos(self, ioauth_data):

self.maker_utxo_data = {}

for nick, nickdata in iteritems(ioauth_data):
for nick, nickdata in ioauth_data.items():
utxo_list, auth_pub, cj_addr, change_addr, _, _ = nickdata
utxo_data = jm_single().bc_interface.query_utxo_set(utxo_list)
self.utxos[nick] = utxo_list
Expand Down Expand Up @@ -452,8 +451,7 @@ def receive_utxos(self, ioauth_data):
#used to track return of signatures for phase 2
self.nonrespondants = list(self.maker_utxo_data.keys())

my_total_in = sum([va['value'] for u, va in iteritems(self.input_utxos)
])
my_total_in = sum([va['value'] for u, va in self.input_utxos.items()])
if self.my_change_addr:
#Estimate fee per choice of next/3/6 blocks targetting.
estimated_fee = estimate_tx_fee(
Expand Down Expand Up @@ -559,7 +557,7 @@ def on_sig(self, nick, sigb64):
utxo_data = jm_single().bc_interface.query_utxo_set([x[
1] for x in utxo.values()])
# insert signatures
for i, u in iteritems(utxo):
for i, u in utxo.items():
if utxo_data[i] is None:
continue
# Check if the sender included the scriptCode in the sig message;
Expand Down Expand Up @@ -698,7 +696,7 @@ def priv_utxo_pairs_from_utxos(utxos, age, amt):
new_utxos, too_old, too_small = filter_by_coin_age_amt(list(utxos.keys()),
age, amt)
new_utxos_dict = {k: v for k, v in utxos.items() if k in new_utxos}
for k, v in iteritems(new_utxos_dict):
for k, v in new_utxos_dict.items():
addr = self.wallet_service.script_to_addr(v["script"])
priv = self.wallet_service.get_key_from_addr(addr)
if priv: #can be null from create-unsigned
Expand Down Expand Up @@ -985,7 +983,7 @@ def receive_utxos(self, ioauth_data):
# use output destination self.my_cj_addr and use amount self.amount
self.outputs.append({'address': self.my_cj_addr,
'value': self.cjamount})
my_total_in = sum([va['value'] for u, va in iteritems(self.input_utxos)])
my_total_in = sum([va['value'] for u, va in self.input_utxos.items()])
# estimate the fee for the version of the transaction which is
# not coinjoined:
est_fee = estimate_tx_fee(len(self.input_utxos), 2,
Expand Down Expand Up @@ -1137,7 +1135,7 @@ def on_tx_received(self, nick, txser):
# Next we'll verify each of the counterparty's inputs,
# while at the same time gathering the total they spent.
total_receiver_input = 0
for i, u in iteritems(retrieve_utxos):
for i, u in retrieve_utxos.items():
if utxo_data[i] is None:
return (False, "Proposed transaction contains invalid utxos")
total_receiver_input += utxo_data[i]["value"]
Expand Down
6 changes: 2 additions & 4 deletions jmclient/jmclient/taker_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from future.utils import iteritems
import logging
import pprint
import os
Expand Down Expand Up @@ -81,8 +80,7 @@ def direct_send(wallet_service, amount, mixdepth, destination, answeryes=False,
log.error(
"There are no available utxos in mixdepth: " + str(mixdepth) + ", quitting.")
return

total_inputs_val = sum([va['value'] for u, va in iteritems(utxos)])
total_inputs_val = sum([va['value'] for u, va in utxos.items()])

if is_burn_destination(destination):
if len(utxos) > 1:
Expand Down Expand Up @@ -116,7 +114,7 @@ def direct_send(wallet_service, amount, mixdepth, destination, answeryes=False,
fee_est = estimate_tx_fee(len(utxos), 2, txtype=txtype)
else:
fee_est = initial_fee_est
total_inputs_val = sum([va['value'] for u, va in iteritems(utxos)])
total_inputs_val = sum([va['value'] for u, va in utxos.items()])
changeval = total_inputs_val - fee_est - amount
outs = [{"value": amount, "address": destination}]
change_addr = wallet_service.get_internal_addr(mixdepth)
Expand Down
7 changes: 3 additions & 4 deletions jmclient/jmclient/wallet_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from future.utils import iteritems
import json
import os
import sys
Expand Down Expand Up @@ -382,7 +381,7 @@ def wallet_showutxos(wallet, showprivkey):
unsp[us]['privkey'] = wallet.get_wif_path(av['path'])

used_commitments, external_commitments = podle.get_podle_commitments()
for u, ec in iteritems(external_commitments):
for u, ec in external_commitments.items():
success, us = utxo_to_utxostr(u)
assert success
tries = podle.get_podle_tries(utxo=u, max_tries=max_tries,
Expand All @@ -403,7 +402,7 @@ def wallet_display(wallet_service, showprivkey, displayall=False,
def get_addr_status(addr_path, utxos, is_new, is_internal):
addr_balance = 0
status = []
for utxo, utxodata in iteritems(utxos):
for utxo, utxodata in utxos.items():
if addr_path != utxodata['path']:
continue
addr_balance += utxodata['value']
Expand Down Expand Up @@ -864,7 +863,7 @@ def print_row(index, time, tx_type, amount, delta, balance, cj_n,
amount = cj_amount
delta_balance = out_value - our_input_value
mixdepth_src = wallet.get_script_mixdepth(list(our_input_scripts)[0])
cj_script = list(set([a for a, v in iteritems(output_script_values)
cj_script = list(set([a for a, v in output_script_values.items()
if v == cj_amount]).intersection(our_output_scripts))[0]
mixdepth_dst = wallet.get_script_mixdepth(cj_script)
else:
Expand Down
7 changes: 3 additions & 4 deletions jmclient/jmclient/yieldgenerator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#! /usr/bin/env python
from future.utils import iteritems

import datetime
import os
Expand Down Expand Up @@ -78,7 +77,7 @@ def __init__(self, wallet_service, offerconfig):

def create_my_orders(self):
mix_balance = self.get_available_mixdepths()
if len([b for m, b in iteritems(mix_balance) if b > 0]) == 0:
if len([b for m, b in mix_balance.items() if b > 0]) == 0:
jlog.error('do not have any coins left')
return []

Expand Down Expand Up @@ -115,7 +114,7 @@ def oid_to_order(self, offer, amount):
mix_balance = self.get_available_mixdepths()

filtered_mix_balance = {m: b
for m, b in iteritems(mix_balance)
for m, b in mix_balance.items()
if b >= total_amount}
if not filtered_mix_balance:
return None, None, None
Expand Down Expand Up @@ -177,7 +176,7 @@ def select_input_mixdepth(self, available, offer, amount):
inputs. available is a mixdepth/balance dict of all the mixdepths
that can be chosen from, i.e. have enough balance. If there is no
suitable input, the function can return None to abort the order."""
available = sorted(iteritems(available), key=lambda entry: entry[0])
available = sorted(available.items(), key=lambda entry: entry[0])
return available[0][0]

def select_output_address(self, input_mixdepth, offer, amount):
Expand Down
2 changes: 1 addition & 1 deletion jmclient/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
author_email='',
license='GPL',
packages=['jmclient'],
install_requires=['future', 'configparser;python_version<"3.2"',
install_requires=['configparser;python_version<"3.2"',
'joinmarketbase==0.6.2', 'mnemonic', 'argon2_cffi',
'bencoder.pyx>=2.0.0', 'pyaes'],
python_requires='>=3.3',
Expand Down
7 changes: 2 additions & 5 deletions jmclient/test/test_snicker.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#! /usr/bin/env python
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import * # noqa: F401
'''Test of unusual transaction types creation and push to
network to check validity.'''
'''Test of SNICKER functionality using Joinmarket
wallets as defined in jmclient.wallet.'''

import binascii
from commontest import make_wallets, dummy_accept_callback, dummy_info_callback
Expand Down
3 changes: 1 addition & 2 deletions jmdaemon/jmdaemon/daemon_protocol.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#! /usr/bin/env python
from future.utils import iteritems

from .message_channel import MessageChannelCollection
from .orderbookwatch import OrderbookWatch
Expand Down Expand Up @@ -239,7 +238,7 @@ def on_JM_FILL(self, amount, commitment, revelation, filled_offers):
#Reset utxo data to null for this new transaction
self.ioauth_data = {}
self.active_orders = json.loads(filled_offers)
for nick, offer_dict in iteritems(self.active_orders):
for nick, offer_dict in self.active_orders.items():
offer_fill_msg = " ".join([str(offer_dict["oid"]), str(amount),
self.kp.hex_pk().decode('ascii'), str(commitment)])
self.mcc.prepare_privmsg(nick, "fill", offer_fill_msg)
Expand Down
1 change: 0 additions & 1 deletion jmdaemon/jmdaemon/irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def wlog(*x):
"""Simplifier to add lists to the debug log
"""
def conv(s):
# note: this only works because of the future package
if isinstance(s, str):
return s
elif isinstance(s, bytes):
Expand Down
Loading

0 comments on commit 3b55ca2

Please sign in to comment.