bridge

module
v0.0.0-...-0d91d44 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2021 License: GPL-3.0

README

Acent bridge

git clone https://github.com/acentswap/bridge.git cd bridge make all


after building, the following files will be generated in `./build/bin` directory:

```text
swapserver	# server provide api service, and trigger swap processing
swaporacle      # oracle take part in dcrm signing (can disagree illegal transaction)
config-example.toml
config-tokenpair-example.toml

Modify config file

copy the example config file config-example.toml in ./build/bin directory, and modify it accordingly.

see more, please refer config file example

Identifier

Identifier should be a short string to identify the bridge (eg. BTC2ETH, BTC2FSN)

MongoDB

MongoDB is used by the server to store swap status and history, you should config according to your modgodb database setting. (the swap oracle don't need it)

APIServer

APIServer is used by the server to provide API service to register swap and to provide history retrieving. (the swap oracle don't need it)

Oracle

Oracle is needed by the swap oracle to post swap register RPC requests to swap server (the swap server don't need Oracle).

BtcExtra

BtcExtra is used to customize fees when build transaction on Bitcoin blockchain

SrcChain

SrcChain is used to config the chain of source endpoint of the cross chain bridge.

SrcGateway

SrcGateway is used to do RPC request to verify transactions on source blockchain, and to broadcast signed transaction.

DestChain

DestChain is used to config the chain of dest endpoint of the cross chain bridge.

DestGateway

DestGateway is used to do RPC request to verify transactions on dest blockchain, and to broadcast signed transaction.

Dcrm

Dcrm is used to config DCRM node info and group info.

Initiators is used to specify the server dcrm user (initiators of dcrm sign)

Dcrm.DefaultNode is used to specify default dcrm node to connect.

Dcrm.OtherNodes is an array used by server to specify other initiators of dcrm node.

for the swap server, SignGroups is needed for dcrm signing.

Notice: If in test enviroment you may run more than one program of swap servers on one machine, Please specify different log file name to clarify the outputs. And please specify different config files for each server, and assgin KeystoreFile, PasswordFile and RPCAddress etc. separatly.

Modify token pair config files

copy the example config file config-tokenpair-example.toml in ./build/bin directory, and modify it accordingly.

see more, please refer token pair config file example

PairID

pair ID of this token pair, must be unique.

SrcToken

SrcToken is used to config the token of source endpoint of the cross chain bridge.

DestToken

DestToken is used to config the token of dest endpoint of the cross chain bridge.

Run swap server

setsid ./build/bin/swapserver --verbosity 6 --config build/bin/config.toml --pairsdir build/bin/tokenpairs --log build/bin/logs/server.log

Run swap oracle

setsid ./build/bin/swaporacle --verbosity 6 --config build/bin/config.toml --pairsdir build/bin/tokenpairs --log build/bin/logs/oracle.log

Others

swapserver and swaporacle has the following subcommands:

help       - to see hep info.
version - to show the version.
license - to show the license

Preparations

Running swapserver and swaporacle to provide cross chain bridge service, we must prepare the following things firstly and config them rightly. Otherwise the program will not run or run rightly. To ensure this, we have add many checkings to the config items.

For the config file, please refer config file example

  1. create Mongodb database (shared by all swap servers of the bridge provider)

    config [MongoDB] section accordingly (eg. DbURL,DbName,UserName,Password)

    For security reason, we suggest:

    1. change the mongodb port ( defaults to 27017)
    2. enable auth
    3. create user with passord to access the database
  2. create DCRM group

    For example, we take creating 2/3 theshold jonitly managed DCRM group as an example.

    we have 3 users in the DCRM group, each user is running a gdcrm node to perform DCRM functions.

    1. user1 - build raw tx and trigger DCRM signing
    2. user2, user3 - verify tx and accept the DCRM signing with AGREE/DISAGREE result

    After created DCRM group,

    We can get the corresponding DCRM addresses on supported blockchains. Then we should config DcrmAddress in [SrcToken] and [DestToken] section according to the blockchain of them.

    We should config the [Dcrm] section accordingly( eg. GroupID, TotalOraclesMode, DefaultNode, etc.)

    And we should config the following [Dcrm] section items sparately for each user in the DCRM group:

    1. KeystoreFile
    2. PasswordFile
    3. RPCAddress

    For example,

    we are configing user1 now, we should config KeystoreFile and PasswordFile use user1's keystore and password file (we will get user1's private key to sign a DCRM requesting).

    And we should config RPCAddress to the RPC address of the running gdcrm node of user1 (we will do RPC calls to this address to complete DCRM signing or accepting, etc.)

  3. create DCRM sub-groups for signing

    In the above step we have created a 2/3 threshold DCRM group.

    In signing we only need 2 members to agree.

    So we prepared the sub-groups (2/2) for signing. (eg. user1 + user2, user1 + user3) please see more detail about DCRM here

    After created, we should config SignGroups in [Dcrm] accordingly.

  4. create mapping asset (eg. mBTC) contract with DCRM account

    mBTC is an smart contract inherit from ERC20 and add two methods: Swapin and Swapout.

    please see more here about mBTC

    After created mBTC, we should config ContractAddress in [DestToken] section.

  5. config [APIServer] section

    The swap server provides RPC service to query swap status and swap history. etc.

    Please see more here about bridge-API

    We should config Port (defaults to 11556), and AllowedOrigins (CORS defaults to empty array. ["*"] for allow any)

  6. config [SrcChain],[SrcGateway]

    We should config APIAddress in [SrcGateway] section, to post RPC request to the running full node to get transaction, broadcat transaction etc.

    Config [SrcChain], ref. to the following example:

    BlockChain = "Bitcoin" # required
    NetID = "TestNet3"  # required
    Confirmations = 0 # suggest >= 6 for Mainnet # required
    InitialHeight = 0
    EnableScan = false
    
  7. config [DestChain], [DestGateway]

    We should config APIAddress in [DestGateway] section, to post RPC request to the running full node to get transaction, broadcat transaction etc.

    Config [DestChain] like [SrcChain].

  8. config Identifier to identify your crosschain bridge

    This should be a short string to identify the bridge (eg. BTC2ETH, BTC2FSN)

    Different DCRM group can have same Identifier.

    It only matter if you want use a DCRM group to provide multiple crosschain bridge service, and config each bridge with a different identifier (Notice: This way is not suggested)

  9. config [BtcExtra]

    When build and sign transaction on Bitcoin blockchain, we can customize the following items:

    MinRelayFee   = 400
    RelayFeePerKb = 2000
    UtxoAggregateMinCount = 20
    UtxoAggregateMinValue = 1000000
    

    If not configed, the default vlaue will be used (in fact, the above values are the defaults)

  10. config [SrcToken]

    Config [SrcToken], ref. to the following example:

    ID = ""
    Name = "Bitcoin Coin"
    Symbol = "BTC"
    Decimals = 8  # required
    Description = "Bitcoin Coin"
    ContractAddress = ""
    DepositAddress = "mq6XaNvFWiSJtfGYiGakkRdXNrqH6V4Jpu" # required
    DcrmAddress = "mfwPnCuht2b4Lvb5XTds4Rvzy3jZ2ZWrBL" # required
    DcrmPubkey = "045c8648793e4867af465691685000ae841dccab0b011283139d2eae454b569d5789f01632e13a75a5aad8480140e895dd671cae3639f935750bea7ae4b5a25122"
    MaximumSwap = 1000.0 # required
    MinimumSwap = 0.00001 # required
    SwapFeeRate = 0.001 # required
    MaximumSwapFee = 0.01
    MinimumSwapFee = 0.00001
    PlusGasPricePercentage = 15
    BigValueThreshold = 5.0
    DisableSwap = false
    

    For ERC20 token, we should config ID = "ERC20" and ContractAddress to the token's contract address.

  11. config [DestToken]

    Config [DestToken] like [SrcToken].

    Don't forget to config ContractAddress in [DestToken] section (see step 4)

  12. config PairID to identify token pair

repeat step 10, 11, 12 to prepare multiple token pairs config,
put them in a directory (will be referenced by --pairsdir command line option)

Directories

Path Synopsis
Package admin provides methods to sign message and to verify signed message
Package admin provides methods to sign message and to verify signed message
Package build provide customized methods to build project.
Package build provide customized methods to build project.
cmd
riskctrl
Command riskctrl do the audit job and send warning emails when finds illegal situations.
Command riskctrl do the audit job and send warning emails when finds illegal situations.
swapadmin
Command swapadmin send admin swap command to the server node.
Command swapadmin send admin swap command to the server node.
swaporacle
Command swaporacle start the oracle node.
Command swaporacle start the oracle node.
swapscan
Command swapscan scan blockchains and post swap registers to the server node.
Command swapscan scan blockchains and post swap registers to the server node.
swapserver
Command swapserver start the server node.
Command swapserver start the server node.
swaptools
Package swaptools provides tools to build and send txs to blockchain.
Package swaptools provides tools to build and send txs to blockchain.
utils
Package utils provides common sub commands and command flags.
Package utils provides common sub commands and command flags.
Package common contains various helper functions.
Package common contains various helper functions.
hexutil
Package hexutil implements hex encoding with 0x prefix.
Package hexutil implements hex encoding with 0x prefix.
math
Package math provides integer math utilities.
Package math provides integer math utilities.
Package dcrm is a client of dcrm server, doing the sign and accept tasks.
Package dcrm is a client of dcrm server, doing the sign and accept tasks.
internal
Package leveldb is a wrapper of goleveldb.
Package leveldb is a wrapper of goleveldb.
Package log is a wrapper of logrus.
Package log is a wrapper of logrus.
Package mongodb is a wrapper of mgo.v2 that defines the collections and CRUD apis on them.
Package mongodb is a wrapper of mgo.v2 that defines the collections and CRUD apis on them.
Package params provides common version info and config items.
Package params provides common version info and config items.
Package riskctrl do the audit job and send warning emails when finds illegal situations.
Package riskctrl do the audit job and send warning emails when finds illegal situations.
rpc
client
Package client provides methods to do http GET / POST request.
Package client provides methods to do http GET / POST request.
restapi
Package restapi provides RESTful RPC service.
Package restapi provides RESTful RPC service.
rpcapi
Package rpcapi provides JSON RPC service.
Package rpcapi provides JSON RPC service.
server
Package server provides JSON/RESTful RPC service.
Package server provides JSON/RESTful RPC service.
Package tokens defines the common interfaces and supported bridges in sub directories.
Package tokens defines the common interfaces and supported bridges in sub directories.
block
Package block implements the bridge interfaces for block blockchain.
Package block implements the bridge interfaces for block blockchain.
bridge
Package bridge init crosschain bridges.
Package bridge init crosschain bridges.
btc
Package btc implements the bridge interfaces for btc blockchain.
Package btc implements the bridge interfaces for btc blockchain.
btc/electrs
Package electrs get or post RPC queries to electrs server.
Package electrs get or post RPC queries to electrs server.
colx
Package colx implements the bridge interfaces for colx blockchain.
Package colx implements the bridge interfaces for colx blockchain.
colx/colxdev
Package colxdev dev tools to output compressed public key.
Package colxdev dev tools to output compressed public key.
etc
Package etc implements the bridge interfaces for etc blockchain.
Package etc implements the bridge interfaces for etc blockchain.
eth
Package eth implements the bridge interfaces for eth-like blockchain.
Package eth implements the bridge interfaces for eth-like blockchain.
fsn
Package fsn implements the bridge interfaces for fsn blockchain.
Package fsn implements the bridge interfaces for fsn blockchain.
ltc
Package ltc implements the bridge interfaces for ltc blockchain.
Package ltc implements the bridge interfaces for ltc blockchain.
okex
Package okex implements the bridge interfaces for okex blockchain.
Package okex implements the bridge interfaces for okex blockchain.
tools
Package tools provides tools for scanning and registering swaps.
Package tools provides tools for scanning and registering swaps.
crypto
Package crypto provides facilities for ecdsa encryption and decryption.
Package crypto provides facilities for ecdsa encryption and decryption.
keystore
Package keystore encrypt private key and save on disk uses JSON encoding.
Package keystore encrypt private key and save on disk uses JSON encoding.
rlp
Package rlp implements the RLP serialization format.
Package rlp implements the RLP serialization format.
Package types defines the eth-like core types (Transaction, etc) and RPC result types.
Package types defines the eth-like core types (Transaction, etc) and RPC result types.
Package worker includes all the tasks and jobs to process bridge swaps.
Package worker includes all the tasks and jobs to process bridge swaps.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL