Skip to content

Commit

Permalink
Merge pull request #183 from gnosis/develop
Browse files Browse the repository at this point in the history
Set version v3.8.0
  • Loading branch information
Uxio0 authored Jan 8, 2020
2 parents 7a34b24 + d25d7d9 commit 37ddfeb
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ install:
before_script:
- psql -c 'create database travisci;' -U postgres
script:
- coverage run --source=$SOURCE_FOLDER -m py.test -W ignore::DeprecationWarning -rxXs
- coverage run --source=$SOURCE_FOLDER -m py.test -rxXs
deploy:
- provider: script
script: bash scripts/deploy_docker.sh staging
Expand Down
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-r requirements.txt
pytest==5.3.1
pytest==5.3.2
pytest-django==3.7.0
pytest-sugar==0.9.2
coverage==4.5.3
17 changes: 8 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
Django==2.2.8
cachetools==3.1.1
celery==4.3.0
cachetools==4.0.0
celery==4.4.0
django-authtools==1.7.0
django-celery-beat==1.5.0
django-environ==0.4.5
django-filter==2.2.0
django-model-utils==3.2.0
django-redis==4.10.0
django-model-utils==4.0.0
django-redis==4.11.0
djangorestframework-camel-case==1.1.2
djangorestframework==3.10.3
djangorestframework==3.11.0
docutils==0.14
drf-yasg[validation]==1.17.0
eth-abi==1.3.0
ethereum==2.3.2
factory-boy==2.12.0
faker==1.0.7
faker==3.0.0
gevent==1.4.0
gnosis-py==1.8.1
gnosis-py==2.0.1
gunicorn==20.0.4
hexbytes==0.2.0
lxml==4.4.1
Expand All @@ -25,4 +24,4 @@ packaging>=19.0
psycopg2-binary==2.8.4
redis==3.3.11
requests==2.22.0
web3==4.9.2
web3==5.4.0
4 changes: 2 additions & 2 deletions safe_relay_service/gas_station/gas_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ def __init__(self,
self.w3 = Web3(HTTPProvider(http_provider_uri))
try:
if self.w3.net.version != 1:
self.w3.middleware_stack.inject(geth_poa_middleware, layer=0)
self.w3.middleware_onion.inject(geth_poa_middleware, layer=0)
# For tests using dummy connections (like IPC)
except (ConnectionError, FileNotFoundError):
self.w3.middleware_stack.inject(geth_poa_middleware, layer=0)
self.w3.middleware_onion.inject(geth_poa_middleware, layer=0)

def _get_block_cache_key(self, block_number):
return 'block:%d' % block_number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Command(BaseCommand):
help = 'Deploys master copy using first unlocked account on the node if `ganache -d` is found and contract ' \
'is not deployed. If not you need to set a private key using `--deployer-key`'
GANACHE_FIRST_ACCOUNT_KEY = '0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d'
DEFAULT_ACCOUNT = Account.privateKeyToAccount(GANACHE_FIRST_ACCOUNT_KEY)
DEFAULT_ACCOUNT = Account.from_key(GANACHE_FIRST_ACCOUNT_KEY)

def add_arguments(self, parser):
# Positional arguments
Expand All @@ -20,7 +20,7 @@ def add_arguments(self, parser):
def handle(self, *args, **options):
ethereum_client = EthereumClientProvider()
deployer_key = options['deployer_key']
deployer_account = Account.privateKeyToAccount(deployer_key) if deployer_key else self.DEFAULT_ACCOUNT
deployer_account = Account.from_key(deployer_key) if deployer_key else self.DEFAULT_ACCOUNT

master_copies_with_deploy_fn = {
settings.SAFE_CONTRACT_ADDRESS: Safe.deploy_master_contract,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def send_eth(w3, account, to, value, nonce=None):
'pending'),
}

signed_tx = w3.eth.account.signTransaction(tx, private_key=account.privateKey)
signed_tx = w3.eth.account.signTransaction(tx, private_key=account.key)
return w3.eth.sendRawTransaction(signed_tx.rawTransaction)


Expand All @@ -33,7 +33,7 @@ def send_token(w3, account, to, amount_to_send, token_address, nonce=None):
nonce = nonce if nonce is not None else w3.eth.getTransactionCount(account.address, 'pending')
tx = erc20_contract.functions.transfer(to, amount_to_send).buildTransaction({'from': account.address,
'nonce': nonce})
signed_tx = w3.eth.account.signTransaction(tx, private_key=account.privateKey)
signed_tx = w3.eth.account.signTransaction(tx, private_key=account.key)
return w3.eth.sendRawTransaction(signed_tx.rawTransaction)


Expand Down Expand Up @@ -76,7 +76,7 @@ def handle(self, *args, **options):
multiple_txs = options['multiple_txs']

self.w3 = Web3(HTTPProvider(options['node_url']))
self.main_account = Account.privateKeyToAccount(options['private_key'])
self.main_account = Account.from_key(options['private_key'])
self.main_account_nonce = self.w3.eth.getTransactionCount(self.main_account.address, 'pending')
main_account_balance = self.w3.eth.getBalance(self.main_account.address)
self.stdout.write(self.style.SUCCESS('Using %s as main account with balance=%d' % (self.main_account.address,
Expand All @@ -92,7 +92,7 @@ def handle(self, *args, **options):
accounts = [Account.create() for _ in range(3)]
for account in accounts:
self.stdout.write(self.style.SUCCESS('Created account=%s with key=%s' % (account.address,
account.privateKey.hex())))
account.key.hex())))
accounts.append(self.main_account)
accounts.sort(key=lambda acc: acc.address.lower())
owners = [account.address for account in accounts]
Expand Down
4 changes: 2 additions & 2 deletions safe_relay_service/relay/services/funding_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, ethereum_client: EthereumClient, gas_station: GasStation, red
self.ethereum_client = ethereum_client
self.gas_station = gas_station
self.redis = redis
self.funder_account = Account.privateKeyToAccount(funder_private_key)
self.funder_account = Account.from_key(funder_private_key)
self.max_eth_to_send = max_eth_to_send

def send_eth_to(self, to: str, value: int, gas: int = 22000, gas_price=None,
Expand All @@ -57,7 +57,7 @@ def send_eth_to(self, to: str, value: int, gas: int = 22000, gas_price=None,

with EthereumNonceLock(self.redis, self.ethereum_client, self.funder_account.address,
timeout=60 * 2) as tx_nonce:
return self.ethereum_client.send_eth_to(self.funder_account.privateKey, to, gas_price, value,
return self.ethereum_client.send_eth_to(self.funder_account.key, to, gas_price, value,
gas=gas,
retry=retry,
block_identifier=block_identifier,
Expand Down
2 changes: 1 addition & 1 deletion safe_relay_service/relay/services/safe_creation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(self, gas_station: GasStation, ethereum_client: EthereumClient, red
self.safe_contract_address = safe_contract_address
self.proxy_factory = ProxyFactory(proxy_factory_address, self.ethereum_client)
self.default_callback_handler = default_callback_handler
self.funder_account = Account.privateKeyToAccount(safe_funder_private_key)
self.funder_account = Account.from_key(safe_funder_private_key)
self.safe_fixed_creation_cost = safe_fixed_creation_cost

def _get_token_eth_value_or_raise(self, address: str) -> float:
Expand Down
10 changes: 5 additions & 5 deletions safe_relay_service/relay/services/transaction_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def __init__(self, gas_station: GasStation, ethereum_client: EthereumClient, red
self.redis = redis
self.safe_valid_contract_addresses = safe_valid_contract_addresses
self.proxy_factory = ProxyFactory(proxy_factory_address, self.ethereum_client)
self.tx_sender_account = Account.privateKeyToAccount(tx_sender_private_key)
self.tx_sender_account = Account.from_key(tx_sender_private_key)

@staticmethod
def _check_refund_receiver(refund_receiver: str) -> bool:
Expand Down Expand Up @@ -387,14 +387,14 @@ def _send_multisig_tx(self,
safe_base_gas_estimation = safe.estimate_tx_base_gas(to, value, data, operation, gas_token,
safe_tx_gas_estimation)
if safe_tx_gas < safe_tx_gas_estimation or base_gas < safe_base_gas_estimation:
raise InvalidGasEstimation("Gas should be at least equal to safe-tx-gas=%d and data-gas=%d. Current is "
"safe-tx-gas=%d and data-gas=%d" %
raise InvalidGasEstimation("Gas should be at least equal to safe-tx-gas=%d and base-gas=%d. Current is "
"safe-tx-gas=%d and base-gas=%d" %
(safe_tx_gas_estimation, safe_base_gas_estimation, safe_tx_gas, base_gas))

# We use fast tx gas price, if not txs could be stuck
tx_gas_price = self._get_configured_gas_price()
tx_sender_private_key = self.tx_sender_account.privateKey
tx_sender_address = Account.privateKeyToAccount(tx_sender_private_key).address
tx_sender_private_key = self.tx_sender_account.key
tx_sender_address = Account.from_key(tx_sender_private_key).address

safe_tx = safe.build_multisig_tx(
to,
Expand Down
10 changes: 5 additions & 5 deletions safe_relay_service/relay/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Meta:
owners = factory.LazyFunction(lambda: [Account.create().address, Account.create().address])
threshold = 2
payment = factory.fuzzy.FuzzyInteger(100, 1000)
tx_hash = factory.Sequence(lambda n: Web3.sha3(n))
tx_hash = factory.Sequence(lambda n: Web3.keccak(n))
gas = factory.fuzzy.FuzzyInteger(100000, 200000)
gas_price = factory.fuzzy.FuzzyInteger(Web3.toWei(1, 'gwei'), Web3.toWei(20, 'gwei'))
payment_token = None
Expand Down Expand Up @@ -74,7 +74,7 @@ class Meta:
setup_data = factory.Sequence(lambda n: HexBytes('%x' % (n + 1000)))
gas_estimated = factory.fuzzy.FuzzyInteger(100000, 200000)
gas_price_estimated = factory.fuzzy.FuzzyInteger(Web3.toWei(1, 'gwei'), Web3.toWei(20, 'gwei'))
tx_hash = factory.Sequence(lambda n: Web3.sha3(text='safe-creation-2-%d' % n))
tx_hash = factory.Sequence(lambda n: Web3.keccak(text='safe-creation-2-%d' % n))
block_number = None


Expand All @@ -93,15 +93,15 @@ class Meta:
gas_limit = factory.fuzzy.FuzzyInteger(100000000, 200000000)
gas_used = factory.fuzzy.FuzzyInteger(100000, 500000)
timestamp = factory.LazyFunction(timezone.now)
block_hash = factory.Sequence(lambda n: Web3.sha3(text='block%d' % n))
block_hash = factory.Sequence(lambda n: Web3.keccak(text='block%d' % n))


class EthereumTxFactory(factory.DjangoModelFactory):
class Meta:
model = EthereumTx

block = factory.SubFactory(EthereumBlockFactory)
tx_hash = factory.Sequence(lambda n: Web3.sha3(text='ethereum_tx_hash%d' % n))
tx_hash = factory.Sequence(lambda n: Web3.keccak(text='ethereum_tx_hash%d' % n))
_from = factory.LazyFunction(lambda: Account.create().address)
gas = factory.fuzzy.FuzzyInteger(1000, 5000)
gas_price = factory.fuzzy.FuzzyInteger(1, 100)
Expand All @@ -127,7 +127,7 @@ class Meta:
gas_token = None
refund_receiver = factory.LazyFunction(lambda: Account.create().address)
nonce = factory.Sequence(lambda n: n)
safe_tx_hash = factory.Sequence(lambda n: Web3.sha3(text='safe_tx_hash%d' % n))
safe_tx_hash = factory.Sequence(lambda n: Web3.keccak(text='safe_tx_hash%d' % n))


class InternalTxFactory(factory.DjangoModelFactory):
Expand Down
2 changes: 1 addition & 1 deletion safe_relay_service/relay/tests/test_transaction_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_create_multisig_tx(self):
NULL_ADDRESS,
NULL_ADDRESS, 0
).buildTransaction({'from': self.ethereum_test_account.address})
tx_hash = self.ethereum_client.send_unsigned_transaction(proxy_create_tx, private_key=self.ethereum_test_account.privateKey)
tx_hash = self.ethereum_client.send_unsigned_transaction(proxy_create_tx, private_key=self.ethereum_test_account.key)
tx_receipt = self.ethereum_client.get_transaction_receipt(tx_hash, timeout=60)
proxy_address = tx_receipt.contractAddress
with self.assertRaises(InvalidMasterCopyAddress):
Expand Down
2 changes: 1 addition & 1 deletion safe_relay_service/relay/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def test_safe_multisig_tx_post_gas_token(self):
).safe_tx_hash

signatures = [w3.eth.account.signHash(multisig_tx_hash, private_key)
for private_key in [owner_account.privateKey]]
for private_key in [owner_account.key]]
signatures_json = [{'v': s['v'], 'r': s['r'], 's': s['s']} for s in signatures]

data = {
Expand Down
10 changes: 4 additions & 6 deletions safe_relay_service/relay/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
from .serializers import (
ERC20Serializer, ERC721Serializer, EthereumTxWithInternalTxsSerializer,
InternalTxWithEthereumTxSerializer, SafeBalanceResponseSerializer,
SafeContractSerializer, SafeCreationEstimateResponseSerializer,
SafeCreationEstimateSerializer, SafeCreationResponseSerializer,
SafeContractSerializer, SafeCreationResponseSerializer,
SafeCreationSerializer, SafeFundingResponseSerializer,
SafeMultisigEstimateTxResponseSerializer, SafeMultisigTxResponseSerializer,
SafeRelayMultisigTxSerializer, SafeResponseSerializer,
Expand All @@ -39,8 +38,7 @@
from .services.funding_service import FundingServiceException
from .services.safe_creation_service import (SafeCreationServiceException,
SafeCreationServiceProvider)
from .services.transaction_service import (SafeMultisigTxExists,
TransactionServiceException,
from .services.transaction_service import (TransactionServiceException,
TransactionServiceProvider)
from .tasks import fund_deployer_task

Expand Down Expand Up @@ -77,9 +75,9 @@ class AboutView(APIView):
renderer_classes = (JSONRenderer,)

def get(self, request, format=None):
safe_funder_public_key = Account.privateKeyToAccount(settings.SAFE_FUNDER_PRIVATE_KEY).address \
safe_funder_public_key = Account.from_key(settings.SAFE_FUNDER_PRIVATE_KEY).address \
if settings.SAFE_FUNDER_PRIVATE_KEY else None
safe_sender_public_key = Account.privateKeyToAccount(settings.SAFE_TX_SENDER_PRIVATE_KEY).address \
safe_sender_public_key = Account.from_key(settings.SAFE_TX_SENDER_PRIVATE_KEY).address \
if settings.SAFE_TX_SENDER_PRIVATE_KEY else None
content = {
'name': 'Safe Relay Service',
Expand Down
4 changes: 2 additions & 2 deletions safe_relay_service/tokens/price_oracles.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def get_price(self, ticker: str) -> float:
:return: price
"""
ethereum_client = EthereumClientProvider()
uniswap = UniswapOracle(ethereum_client.w3, self.uniswap_exchange_address)
uniswap = UniswapOracle(ethereum_client, self.uniswap_exchange_address)
try:
return uniswap.get_price(ticker)
except OracleException as e:
Expand All @@ -132,7 +132,7 @@ def get_price(self, ticker: str) -> float:
:return: price
"""
ethereum_client = EthereumClientProvider()
kyber = KyberOracle(ethereum_client.w3, self.kyber_network_proxy_address)
kyber = KyberOracle(ethereum_client, self.kyber_network_proxy_address)
try:
return kyber.get_price(ticker, self.weth_token_address)
except OracleException as e:
Expand Down
4 changes: 4 additions & 0 deletions safe_relay_service/tokens/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ class TokensView(ListAPIView):
ordering_fields = '__all__'
ordering = ('relevance', 'name')
queryset = Token.objects.all()

@method_decorator(cache_page(60 * 5)) # Cache 5 minutes
def get(self, request, *args, **kwargs):
return super().get(request, *args, **kwargs)
2 changes: 1 addition & 1 deletion safe_relay_service/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '3.7.0'
__version__ = '3.8.0'
__version_info__ = tuple([int(num) if num.isdigit() else num for num in __version__.replace('-', '.', 1).split('.')])

0 comments on commit 37ddfeb

Please sign in to comment.