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

60 isolate connector #92

Merged
merged 32 commits into from
Feb 22, 2022
Merged

60 isolate connector #92

merged 32 commits into from
Feb 22, 2022

Conversation

0xp3gasus
Copy link
Collaborator

@0xp3gasus 0xp3gasus commented Feb 12, 2022

Description

Connector can be isolated from blockchain nodes. It supports multiple tokens at the same time in differents networks. With the Admin package created, it is posible to add, update and remove tokens in differents networks. The rest of the functionality of the connector is the same.

Endpoint paths have been replace from /rpc and /ws to {coin}/{network}/rpc and /{coin}/network}/ws

Fixes #60

Dependencies (if any)

None

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Adding ETH Token in regtest network to connector

    Request

    curl --location --request POST 'http://localhost:80/admin/addCoin' \
    --header 'Origin: http://localhost' \
    --header 'Access-Control-Request-Method: POST' \
    --header 'Access-Control-Request-Headers: access-control-allow-origin,content-type' \
    --header 'Sec-Fetch-Mode: cors' \
    --header 'Sec-Fetch-Site: same-site' \
    --header 'Sec-Fetch-Dest: empty' \
    --header 'Referer: http://localhost' \
    --header 'Accept-Language: es,en-GB;q=0.9,en-US;q=0.8,en;q=0.7' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "coin": "eth",
        "network": "regtest",
        "config": {
            "rpcPort": 8546,
            "wsPort": 8546
        }
    }'
    

    Response

    {
        "success": true,
        "message": "regtest network added for currency eth"
    }
    
  • Getting ETH config

    Request

    curl --location --request POST 'http://localhost:80/admin/getCoin' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "coin": "eth",
        "network": "regtest"
    }'
    

    Response

    {
        "success": true,
        "message": "Config configuration for regtest network for currency eth retrieved successfully",
        "coin": "eth",
        "network": "regtest",
        "config": {
            "protocol": "http",
            "host": "ethereumgo",
            "rpcPort": 8546,
            "wsPort": 8546
        }
    }
    
  • Removing ETH token in regtest network from connector

    Request

    curl --location --request POST 'http://localhost:80/admin/removeCoin' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "coin": "eth",
        "network": "regtest"
    }'
    

    Response

    {
        "success": true,
        "message": "regtest network removed for currency eth"
    }
    
  • Making RPC request to ETH token in regtest network when it is not added to connector

    Request

    curl --location --request POST 'http://localhost:80/eth/regtest/rpc' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "id": 1609070896412,
        "method": "getHeight",
        "params": {},
        "jsonrpc": "2.0"
    }'
    

    Response

    {
        "message": "Currency eth has not been previously added",
        "code": 404
    }
    
  • Making RPC request to ETH token in regtest network when it is added to connector

    Request

    curl --location --request POST 'http://localhost:80/eth/regtest/rpc' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "id": 1609070896412,
        "method": "getHeight",
        "params": {},
        "jsonrpc": "2.0"
    }'
    

    Response

    {
        "id": 1609070896412,
        "jsonrpc": "2.0",
        "result": {
            "latestBlockIndex": "6",
            "latestBlockHash": "0x687fab92aba99fce014e97c68b3acf41c42ee0b9ae30f0a198408fd5938781c0"
        }
    }
    
  • Wesockets subscribe to New Blocks Topic in ETH token in regtest mode

    Endpoint: ws://localhost:80/eth/regtest/ws

    Request

    {
        "id": 1,
        "method": "subscribeToNewBlocks",
        "jsonrpc": "2.0",
        "params": {}
    }
    

    Response

    {
        "id": 1, 
        "jsonrpc": "2.0", 
        "result": {
            "subscribed": true
        }
    }
    

Test Configuration:

  • Operating system (output of sw_vers): macOS 12.0.1

Good practices to consider

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@0xp3gasus 0xp3gasus marked this pull request as ready for review February 20, 2022 17:20
Connector/admin/schemas/removecoin_request.json Outdated Show resolved Hide resolved
Connector/admin/schemas/updatecoin_request.json Outdated Show resolved Hide resolved
Connector/btc/apirpc.py Show resolved Hide resolved

def start(self):

# TODO: Check this is working properly
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO here. Is this checked?


async def stop(self):

# TODO: Check this is working properly
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO here. Is this checked?

Connector/httputils/router.py Outdated Show resolved Hide resolved
reqParsed[rpcutils.ID] if reqParsed is not None else rpcutils.UNKNOWN_RPC_REQUEST_ID,
e.jsonEncode()
)
# from utils import utils
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented line should be deleted

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package utils is going to be mandatory once the script is refactored

Connector/utils/utils.py Show resolved Hide resolved
Connector/wsutils/websocket.py Show resolved Hide resolved
Connector/xmr/config.py Show resolved Hide resolved
@phoenix-web3
Copy link
Collaborator

This PR is huge, @hippocampusSwapper and @bridgedragon should review this PR

@phoenix-web3 phoenix-web3 merged commit 7093516 into swapper-org:staging Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Isolate Connector and prepare it to accept data from the script
2 participants