Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Software Project 2019/2020] Extending the support for cryptocurrencies in our blockchain-based decentralized exchange #44

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ anydex/test/temp/**
cover/**
build/**
dist/**
/bcl_config.ini
178 changes: 92 additions & 86 deletions anydex/config.py
Original file line number Diff line number Diff line change
@@ -1,86 +1,92 @@
import copy

default = {
'address': '0.0.0.0',
'port': 8090,
'keys': [
{
'alias': "main key",
'generation': u"curve25519",
'file': u"ec.pem"
}
],
'logger': {
'level': "INFO"
},
'walker_interval': 0.5,
'overlays': [
{
'class': 'DiscoveryCommunity',
'key': "main key",
'walkers': [
{
'strategy': "RandomWalk",
'peers': 20,
'init': {
'timeout': 3.0
}
},
{
'strategy': "RandomChurn",
'peers': -1,
'init': {
'sample_size': 8,
'ping_interval': 10.0,
'inactive_time': 27.5,
'drop_time': 57.5
}
},
{
'strategy': "PeriodicSimilarity",
'peers': -1,
'init': {}
}
],
'initialize': {},
'on_start': [
('resolve_dns_bootstrap_addresses', )
]
},
{
'class': 'TrustChainCommunity',
'key': "main key",
'walkers': [{
'strategy': "EdgeWalk",
'peers': 20,
'init': {
'edge_length': 4,
'neighborhood_size': 6,
'edge_timeout': 3.0
}
}],
'initialize': {},
'on_start': []
},
{
'class': 'DHTDiscoveryCommunity',
'key': "main key",
'walkers': [{
'strategy': "RandomWalk",
'peers': 20,
'init': {
'timeout': 3.0
}
}],
'initialize': {},
'on_start': []
}
]
}


def get_anydex_configuration():
return copy.deepcopy(default)


__all__ = ['get_anydex_configuration']
import copy

default = {
'address': '0.0.0.0',
'port': 8090,
'keys': [
{
'alias': "main key",
'generation': u"curve25519",
'file': u"ec.pem"
}
],
'logger': {
'level': "INFO"
},
'walker_interval': 0.5,
'overlays': [
{
'class': 'DiscoveryCommunity',
'key': "main key",
'walkers': [
{
'strategy': "RandomWalk",
'peers': 20,
'init': {
'timeout': 3.0
}
},
{
'strategy': "RandomChurn",
'peers': -1,
'init': {
'sample_size': 8,
'ping_interval': 10.0,
'inactive_time': 27.5,
'drop_time': 57.5
}
},
{
'strategy': "PeriodicSimilarity",
'peers': -1,
'init': {}
}
],
'initialize': {},
'on_start': [
('resolve_dns_bootstrap_addresses',)
]
},
{
'class': 'TrustChainCommunity',
'key': "main key",
'walkers': [{
'strategy': "EdgeWalk",
'peers': 20,
'init': {
'edge_length': 4,
'neighborhood_size': 6,
'edge_timeout': 3.0
}
}],
'initialize': {},
'on_start': []
},
{
'class': 'DHTDiscoveryCommunity',
'key': "main key",
'walkers': [{
'strategy': "RandomWalk",
'peers': 20,
'init': {
'timeout': 3.0
}
}],
'initialize': {},
'on_start': []
}
],
'node_config': {
# host: protocol://username:password@domain:port
'host': '',
'timeout': 10.0,
'retry': 3
}
}


def get_anydex_configuration():
return copy.deepcopy(default)


__all__ = ['get_anydex_configuration']
20 changes: 10 additions & 10 deletions anydex/core/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ipv8.messaging.payload_headers import GlobalTimeDistributionPayload
from ipv8.peer import Peer
from ipv8.requestcache import NumberCache, RandomNumberCache, RequestCache
from ipv8.util import fail, succeed
from ipv8.util import succeed

from anydex.core import DeclineMatchReason, DeclinedTradeReason, MAX_ORDER_TIMEOUT
from anydex.core.block import MarketBlock
Expand Down Expand Up @@ -43,7 +43,7 @@
MemoryTransactionRepository
from anydex.core.wallet_address import WalletAddress
from anydex.util.asyncio import call_later
from anydex.wallet.tc_wallet import TrustchainWallet
from anydex.wallet.trustchain.tc_wallet import TrustchainWallet


# Message definitions
Expand Down Expand Up @@ -583,16 +583,16 @@ def get_ipv8_address(self):
"""
return self.my_estimated_lan if self.use_local_address else self.my_estimated_wan

def get_order_addresses(self, order):
async def get_order_addresses(self, order):
"""
Return a tuple of incoming and outgoing payment address of an order.
"""
if order.is_ask():
return (WalletAddress(self.wallets[order.assets.second.asset_id].get_address()),
WalletAddress(self.wallets[order.assets.first.asset_id].get_address()))
return (WalletAddress(await self.wallets[order.assets.second.asset_id].get_address()),
WalletAddress(await self.wallets[order.assets.first.asset_id].get_address()))
else:
return (WalletAddress(self.wallets[order.assets.first.asset_id].get_address()),
WalletAddress(self.wallets[order.assets.second.asset_id].get_address()))
return (WalletAddress(await self.wallets[order.assets.first.asset_id].get_address()),
WalletAddress(await self.wallets[order.assets.second.asset_id].get_address()))

def match_order_ids(self, order_ids):
"""
Expand Down Expand Up @@ -1615,7 +1615,7 @@ async def received_accept_trade(self, peer, payload):
if not order:
return

incoming_address, outgoing_address = self.get_order_addresses(order)
incoming_address, outgoing_address = await self.get_order_addresses(order)

# Create a tx_init block to capture that we are going to initiate a transaction
transaction = await self.create_new_tx_init_block(peer, accepted_trade)
Expand Down Expand Up @@ -1696,7 +1696,7 @@ async def received_wallet_info(self, _, payload):

if not transaction.sent_wallet_info:
order = self.order_manager.order_repository.find_by_id(transaction.order_id)
incoming_address, outgoing_address = self.get_order_addresses(order)
incoming_address, outgoing_address = await self.get_order_addresses(order)
self.send_wallet_info(transaction, incoming_address, outgoing_address)
else:
self.logger.info("Wallet info exchanged for transaction %s - starting payments",
Expand Down Expand Up @@ -1733,7 +1733,7 @@ async def send_payment(self, transaction):
return

payment = Payment(TraderId(self.mid), transaction.transaction_id, transfer_amount,
wallet.get_address(), str(transaction.partner_incoming_address), PaymentId(txid),
wallet.get_address().result(), str(transaction.partner_incoming_address), PaymentId(txid),
Timestamp.now())

# Add it to the transaction
Expand Down
13 changes: 7 additions & 6 deletions anydex/restapi/wallets_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class WalletsEndpoint(BaseMarketEndpoint):
"""
This class represents the root endpoint of the wallets resource.
"""
TRANSFER_NETWORKS = ['BTC', 'TBTC', 'LTC', 'XLT', 'DASH', 'TDASH',
'ETH', 'TETH', 'IOTA', 'TIOTA', 'XMR', 'TXMR', 'XLM', 'TXLM']

def setup_routes(self):
self.app.add_routes([web.get('', self.get_wallets),
Expand Down Expand Up @@ -56,10 +58,11 @@ async def get_wallets(self, request):

async def add_wallet(wallet_id, wallet):
balance = await wallet.get_balance()
address = await wallet.get_address()
wallets[wallet_id] = {
'created': wallet.created,
'unlocked': wallet.unlocked,
'address': wallet.get_address(),
'address': address,
'name': wallet.get_name(),
'precision': wallet.precision(),
'min_unit': wallet.min_unit(),
Expand Down Expand Up @@ -172,8 +175,7 @@ async def transfer_funds(self, request):
.. sourcecode:: none

curl -X POST http://localhost:8085/wallets/BTC/transfer
--data "amount=0.3&destination=mpC1DDgSP4PKc5HxJzQ5w9q6CGLBEQuLsN"

--data "amount=0.3&destination=mpC1DDgSP4PKc5HxJzQ5w9q6CGLBEQuLsN"
**Example response**:

.. sourcecode:: javascript
Expand All @@ -185,9 +187,8 @@ async def transfer_funds(self, request):
parameters = await request.post()

identifier = request.match_info['wallet_id']
if identifier != "BTC" and identifier != "TBTC":
return Response({"error": "currently, currency transfers using the API "
"is only supported for Bitcoin"}, status=HTTP_BAD_REQUEST)
if identifier not in self.TRANSFER_NETWORKS:
return Response({"error": "unsupported currency"}, status=HTTP_BAD_REQUEST)

wallet = self.get_market_community().wallets[identifier]

Expand Down
4 changes: 2 additions & 2 deletions anydex/test/core/test_community.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from anydex.core.timestamp import Timestamp
from anydex.core.transaction import Transaction, TransactionId
from anydex.test.util import MockObject, timeout
from anydex.wallet.dummy_wallet import DummyWallet1, DummyWallet2
from anydex.wallet.tc_wallet import TrustchainWallet
from anydex.wallet.dummy.dummy_wallet import DummyWallet1, DummyWallet2
from anydex.wallet.trustchain.tc_wallet import TrustchainWallet


class TestMarketCommunityBase(TestBase):
Expand Down
2 changes: 1 addition & 1 deletion anydex/test/restapi/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from anydex.core.community import MarketCommunity
from anydex.restapi.rest_manager import RESTManager
from anydex.test.util import get_random_port
from anydex.wallet.dummy_wallet import DummyWallet1, DummyWallet2
from anydex.wallet.dummy.dummy_wallet import DummyWallet1, DummyWallet2


def urlencode(data):
Expand Down
4 changes: 2 additions & 2 deletions anydex/test/restapi/test_wallets_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

from anydex.test.restapi.base import TestRestApiBase
from anydex.test.util import timeout
from anydex.wallet.bitcoinlib.bitcoinlib_wallets import BitcoinWallet, BitcoinTestnetWallet


class TestWalletsEndpoint(TestRestApiBase):

def setUp(self):
super(TestWalletsEndpoint, self).setUp()

from anydex.wallet.btc_wallet import BitcoinWallet, BitcoinTestnetWallet
wallet_path = self.temporary_directory()
btc_wallet = BitcoinWallet(wallet_path)
btc_testnet_wallet = BitcoinTestnetWallet(wallet_path)
Expand Down Expand Up @@ -48,7 +48,7 @@ async def test_create_wallet_btc(self):
"""
Test creating a BTC wallet
"""
self.nodes[0].overlay.wallets['BTC'].create_wallet = lambda: succeed(None)
self.nodes[0].overlay.wallets['BTC'].create_bitcoinlib_wallet = lambda: succeed(None)
self.should_check_equality = False
await self.do_request('wallets/BTC', expected_code=200, request_type='PUT')

Expand Down
3 changes: 3 additions & 0 deletions anydex/test/wallet/bitcoinlib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Contains tests for all child classes of the Bitcoinlib wallet.
"""
Loading