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

Add neo cross chain documentation. #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions neo/How_to_become_neo_relayer_cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# neo-relayer

[English](./How_to_become_neo_relayer_en.md) | 中文

## 架构

一方面,neo-relayer实现了对Neo网络的监听,会持续扫描每个Neo区块并将切换了下一轮共识地址的关键区块头同步到中继链上,同时能识别并转发跨链交易,向中继链提交区块的状态根和交易的梅克尔证明。
另一方面,neo-relayer也实现了对中继链的监听,会持续扫描每个中继链区块并将切换了共识地址的关键区块头同步到Neo链上,中继链收到其他链的跨链信息会构造到Neo链的返回交易,neo-relayer会将这些交易所在的中继链区块头同步到Neo链上因为其中包含了状态根,同时转发这些交易的梅克尔证明及跨链信息。
只要存在一个neo-relayer在工作,那么整个Neo跨链生态就可以持续运作。

## 准备

1. 申请中继链钱包
申请一个中继链的钱包,如果有本体的钱包可以直接使用,二者钱包是通用的。

2. 注册Relayer
然后向中继链注册自己的地址为Relayer。

## 启动Relayer

1. 下载neo-relayer的可执行文件,解压至特定位置
2. 更改配置信息,例如:

```json
{
"RelayJsonRpcUrl": "http://138.91.6.125:40336", // 中继链rpc地址
"RelayChainID": 0, // 中继链编码
"WalletFile": "./wallet.dat", // 中继链钱包
"NeoWalletFile": "TBD", // 待定,后续版本可能采用钱包文件以替代钱包wif
"NeoWalletWIF": "L3Hab7wL43SbWLnkfnVCp6dT99xzfB4qLZxeR9dFgcWWPirwKyXp", // Neo钱包wif
"NeoJsonRpcUrl": "http://47.89.240.111:11332", // Neo链rpc地址
"NeoChainID": 4, // Neo链编码
"NeoCCMC": "b0d4f20da68a6007d4fb7eac374b5566a5b0e229", // Neo链的跨链管理合约
"ScanInterval": 2, // 扫描中继链的时间间隔,单位为秒
"GasPrice": 0,
"GasLimit": 200000
}
```

3. 输入./main --loglevel 0 --cliconfig “path” 执行Relayer可执行文件以运行neo-relayer
45 changes: 45 additions & 0 deletions neo/How_to_become_neo_relayer_en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# neo-relayer

English | [中文](./How_to_become_neo_relayer_CN.md)

## Structure

On one hand, neo-relayer monitors Neo network continuously, scans each Neo block and synchronizes those key block headers which contains different "NextConsensus" field to the relay chain. At the same time, neo-relayer can recognize cross-chain transactions, and provides the "StateRoot" of the block containing those transactions together with the "MerkleProof" of those transactions to the relay chain.
On the other hand, neo-relayer also monitors the relay chain, scans each relay chain block and synchronizes those key block headers which has changed next consensus addresses to Neo chain. Moreover, the relay chain creates cross-chain transactions to Neo chain when it receives cross-chain transactions from other chains. Then neo-relayer relays the "StateRoot" of the block containing those transactions together with the "MerkleProof" of those transactions to Neo chain.
The entire Neo cross-chain ecosystem can continue to function normally even with just one active neo-relayer.

## Setup

1. Create a relay chain wallet
Create a wallet to be used on the relay chain. If you have an existing Ontology wallet it can be used on the relay chain. The two wallets are mutually interchangeable.

2. Register the neo-relayer
Register your address as the **relayer** on the relay chain.

## Start Up

1. Download the executable file of the relayer and extract it to a specific directory.

2. Modify the configuration settings. Here is a sample configuration:

```json
{
"RelayJsonRpcUrl": "http://138.91.6.125:40336", // the rpc address of the relay chain
"RelayChainID": 0, // the relay chain id
"WalletFile": "./wallet.dat", // the wallet used on the relay chain
"NeoWalletFile": "TBD", // to be determined, future versions may replace WIF with wallet file of Neo network
"NeoWalletWIF": "L3Hab7wL43SbWLnkfnVCp6dT99xzfB4qLZxeR9dFgcWWPirwKyXp", // private key in WIF format
"NeoJsonRpcUrl": "http://47.89.240.111:11332", // the rpc address of the Neo chain
"NeoChainID": 4, // Neo chain id
"NeoCCMC": "b0d4f20da68a6007d4fb7eac374b5566a5b0e229", // cross chain management contract of Neo chain
"ScanInterval": 2, // the time interval to scan the relay chain, in seconds
"GasPrice": 0,
"GasLimit": 200000
}
```

3. Use the following command with the configuration file path to enable the relayer:

```bash
./main --loglevel 0 --cliconfig "path"
```
44 changes: 44 additions & 0 deletions neo/How_to_cross_NEP5_asset_cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 如何将NEP5资产跨到其他链上

[English](How_to_cross_NEP5_asset_en.md) | 中文

## 收集资产在链上对应的合约地址

以某个NEP5资产为例,这种资产在链上的合约地址为:

-Neo链: 4da43995ee75be3931fd3abae06a3e6447d2febf (小端序)

-Ethereum链: 0x86B7Be11D77043E5aDe3858f2F694E4f89d4a941

## 执行跨链操作

### 集成跨链功能的NEP5资产

如果该资产集成了跨链的Lock和Unlock接口,则可以直接调用该资产的Lock接口进行跨链资产转移:

```C#
public static bool Lock(byte[] fromAddress, BigInteger toChainId, byte[] toAddress, BigInteger amount)
```

**参数设置:**

- fromAddress: 5392ebf880d9a7119b17b2f1adaebc5f71c28e75 (Neo链地址APPmjituYcgfNxjuQDy9vP73R2PmhFsYJR的script hash,小端序)
- toChainId: 2 (Ethereum链的编码)
- toAddress: 0x0B24aBDd39185055311aaa27082F9dEb294A7255 (Ethereum链地址)
- amount: 10000 (跨链数量)

### 未集成跨链功能的NEP5资产

如果该资产未集成跨链的Lock和Unlock接口,则需要调用该资产对应的代理合约的Lock接口:

```C#
public static bool Lock(byte[] fromAssetHash, byte[] fromAddress, BigInteger toChainId, byte[] toAddress, BigInteger amount)
```

**参数设置:**

- fromAssetHash: 4da43995ee75be3931fd3abae06a3e6447d2febf (NEP5资产的script hash,小端序)
- fromAddress: 5392ebf880d9a7119b17b2f1adaebc5f71c28e75 (Neo链地址APPmjituYcgfNxjuQDy9vP73R2PmhFsYJR的script hash,小端序)
- toChainId: 2 (Ethereum链的编码)
- toAddress: 0x0B24aBDd39185055311aaa27082F9dEb294A7255 (Ethereum链地址)
- amount: 10000 (跨链数量)
44 changes: 44 additions & 0 deletions neo/How_to_cross_NEP5_asset_en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# How to Transfer NEP5 Assets to Other Chains

English | [中文](./How_to_cross_NEP5_asset_cn.md)

## Collect the corresponding contract addresses for the asset on different chains

For example, an NEP5 asset has the following contract addresses:

-Neo chain: 4da43995ee75be3931fd3abae06a3e6447d2febf (little endian)

-Ethereum chain: 0x86B7Be11D77043E5aDe3858f2F694E4f89d4a941

## Start cross chain operation

### NEP5 assets with cross chain features

If the asset has embedded the "Lock" and "Unlock" API methods, cross chain transactions can be carried out by invoking the "Lock" method directly:

```C#
public static bool Lock(byte[] fromAddress, BigInteger toChainId, byte[] toAddress, BigInteger amount)
```

**Parameters setup:**

- fromAddress: 5392ebf880d9a7119b17b2f1adaebc5f71c28e75 (script hash of a Neo chain address APPmjituYcgfNxjuQDy9vP73R2PmhFsYJR in little endian)
- toChainId: 2 (Ethereum chain id)
- toAddress: 0x0B24aBDd39185055311aaa27082F9dEb294A7255 (an address on Ethereum chain)
- amount: 10000 (cross chain amount)

### NEP5 assets without cross chain features

If the asset doesn't have the "Lock" and "Unlock" API methods natively, then the "Lock" method of its corresponding proxy contract is invoked to create cross chain transactions:

```C#
public static bool Lock(byte[] fromAssetHash, byte[] fromAddress, BigInteger toChainId, byte[] toAddress, BigInteger amount)
```

**Parameters setup:**

- fromAssetHash: 4da43995ee75be3931fd3abae06a3e6447d2febf (script hash of the NEP5 asset in little endian)
- fromAddress: 5392ebf880d9a7119b17b2f1adaebc5f71c28e75 (script hash of a Neo chain address APPmjituYcgfNxjuQDy9vP73R2PmhFsYJR in little endian)
- toChainId: 2 (Ethereum chain id)
- toAddress: 0x0B24aBDd39185055311aaa27082F9dEb294A7255 (an address on Ethereum chain)
- amount: 10000 (cross chain amount)
Loading