Skip to content

Commit

Permalink
add bridge doc (ontio#115)
Browse files Browse the repository at this point in the history
* add keccak256!

* fmt code

* add test

* add doc

* add doc

* Update examples/bridge/src/lib.rs

Co-authored-by: laizy <[email protected]>
  • Loading branch information
lucas7788 and laizy authored Jul 30, 2021
1 parent 1fde475 commit d49858b
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 2 deletions.
95 changes: 95 additions & 0 deletions examples/bridge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# 接口文档

请采用wasm合约的交互方式调用此合约

1. getAllTokenPairName

查询所有支持兑换的TokenPair对的名字

* 参数: 无

* 返回值
* Vec<Vec<u8>>, 二维字节数组, 可以用utf8编码转换成可视化的tokenPairName, 例如 pUSDT-USDT

2. getTokenPair

查询tokenPair信息

* 参数

|参数名|参数类型|
|:---|:---|
|token_pair_name|&[u8], 字节数组|

* 返回值
* TokenPair, 其定义如下,请按照结构体定义进行解析

```
#[derive(Encoder, Decoder, Default)]
struct TokenPair {
erc20: Address,
erc20_decimals: u32,
oep4: Address,
oep4_decimals: u32,
}
```

3. oep4ToErc20

oep4 资产转换成erc20资产

* 参数

|参数名|参数类型|参数描述|
|:---|:---|:---|
|ont_acct|Address|用户的ontology账户地址|
|eth_acct|Address|用户的ethereum账户地址|
|amount|U128|要兑换的oep4资产的数量|
|token_pair_name|&[u8]|要兑换的tokenPair对的名字|


注意: 会校验ont_acct的签名



* 事件

|参数名|参数描述|
|:---|:---|
|oep4ToErc20|方法名|
|ont_acct|用户的ontology账户地址|
|eth_acct|用户的ethereum账户地址|
|amount|要兑换的oep4资产的数量|
|erc20_amt|兑换到的erc20的数量|
|oep4_addr|oep4合约地址|
|erc20_addr|erc20合约地址|



4. erc20ToOep4

erc20资产兑换成oep4资产

* 参数

|参数名|参数类型|参数描述|
|:---|:---|:---|
|ont_acct|Address|用户的ontology账户地址|
|eth_acct|Address|用户的ethereum账户地址|
|amount|U128|要兑换的oep4资产的数量|
|token_pair_name|&[u8]|要兑换的tokenPair对的名字|

注意: 会校验ont_acct的签名


* 事件

|参数名|参数描述|
|:---|:---|
|erc20ToOep4|方法名|
|ont_acct|用户的ontology账户地址|
|eth_acct|用户的ethereum账户地址|
|amount|要兑换的erc20资产的数量|
|oep4_amt|兑换到的oep4_amt的数量|
|oep4_addr|oep4合约地址|
|erc20_addr|erc20合约地址|
2 changes: 1 addition & 1 deletion examples/bridge/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub fn erc20_to_oep4_event(
) {
EventBuilder::new()
.string("erc20ToOep4")
.address(eth_acct)
.address(ont_acct)
.address(eth_acct)
.number(amount)
.number(oep4_amt)
.address(oep4_addr)
Expand Down
2 changes: 1 addition & 1 deletion examples/bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ fn erc20_to_oep4(
transfer_neovm(&pair.oep4, this, ont_acct, oep4_amt);
oep4_amt
};
erc20_to_oep4_event(eth_acct, ont_acct, amount, oep4_amt, &pair.oep4, &pair.erc20);
erc20_to_oep4_event(ont_acct, eth_acct, amount, oep4_amt, &pair.oep4, &pair.erc20);
true
} else {
false
Expand Down

0 comments on commit d49858b

Please sign in to comment.