**版本：V6.2.0**
# 部分模块使用流程

## hashlock 哈希锁定合约
Hashlock正常流程，完整过程：

1. 需要准备两个账户A和B，其中A是returnAddr,用于在锁定时间结束后，可以返回余额，B是toAddr，在锁定时间内，能够进行操作转移金额
我这里A：14KEKbYtKKQm4wMthSK9J4La4nAiidGozt    B:1KoVEeACNMyr42uEnfKR7SJTi5wE8nGWqx

2. hashlock要求在lock动作时，合约里存在余额，这些余额在lock后会被frozen
./cli bty send_exec -a 1000 -e hashlock
由A签名并发送

3. lock操作
./cli hashlock lock -a 1000 -d 360 -r 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt -t 1KoVEeACNMyr42uEnfKR7SJTi5wE8nGWqx -s mysecret
由A签名并发送

4. send操作
./cli hashlock send -s mysecret
由B签名并发送

5. 取回，从hashlock合约取钱
./cli bty withdraw -a 1000 -e hashlock
由B签名并发送

注意：
A. 暂时未支持查询命令，如果需要监视操作过程，可以查询合约余额。在lock执行后，合约余额Frozen在A账户，在send完成后，合约余额在B账户
B. 因为send/withdraw都是由B地址签名完成的，因此这个B地址还需要有点钱作为手续费
C. 当前hash命令和一些其他的执行器类似，操作只是创建了交易，还需要签名并发送
D. lock过程指定了lock周期，只有在此时间内，才能成功进行send，超出这个周期只能进行unlock操作

附：
unlock操作，在lock动作后，超过设定时间，可以进行unlock操作，unlock后，余额在A账户，解除冻结状态，可以由A取回
./cli hashlock unlock -s mysecret
## multisig 多重签名合约
"1LmbKkDke6FB4mATfF1WQD2QLQQbk1JUFa" xs1
"1JDVvcppsUpfbaXqdoKyGTYV7eeakZgCHN" xs2
"1GV8NGi8fgbG5kqpL6v64fQNkszkxyvwZ7" xs3
"197MWT1nNxHnmz4Wd6SWCPbL3naUy5WLiz" xs4
"1PpeeGeWfT8hCUroKEYUur12SQsbTyMdQz" xs5
"1LFqpeEiGuWSVUMztxifLGTT7gsmJatGJi" xs6
  
地址4向unfreeze合约打入100JTT  
创建对地址3的合约解冻   
cli send unfreeze create fix_amount -a 0.01 -e token -s JTT -b 1GV8NGi8fgbG5kqpL6v64fQNkszkxyvwZ7  -p 60 -t 2 -k "197MWT1nNxHnmz4Wd6SWCPbL3naUy5WLiz"  

查询该合约状态  
cli unfreeze show --id mavl-unfreeze-f9cf7a1f2482ad1137bdc5af49bd1c2bbe6407308710cdbb21e6162e0cba0657  
该id值无查询接口  需增加
```
{
    "unfreezeID": "mavl-unfreeze-f9cf7a1f2482ad1137bdc5af49bd1c2bbe6407308710cdbb21e6162e0cba0657",
    "startTime": "1547625329",
    "assetExec": "token",
    "assetSymbol": "JTT",
    "totalCount": "200000000",
    "initiator": "197MWT1nNxHnmz4Wd6SWCPbL3naUy5WLiz",
    "beneficiary": "1GV8NGi8fgbG5kqpL6v64fQNkszkxyvwZ7",
    "remaining": "200000000",
    "means": "FixAmount",
    "fixAmount": {
        "period": "60",
        "amount": "1000000"
    }
}
```
查询可取回的份额  
cli unfreeze show_withdraw --id mavl-unfreeze-f9cf7a1f2482ad1137bdc5af49bd1c2bbe6407308710cdbb21e6162e0cba0657  
```
{
    "unfreezeID": "mavl-unfreeze-f9cf7a1f2482ad1137bdc5af49bd1c2bbe6407308710cdbb21e6162e0cba0657",
    "availableAmount": "14000000"
}
```
受益人取回冻结  
cli send unfreeze withdraw --id mavl-unfreeze-f9cf7a1f2482ad1137bdc5af49bd1c2bbe6407308710cdbb21e6162e0cba0657 -k "1GV8NGi8fgbG5kqpL6v64fQNkszkxyvwZ7"  
查询余额  
cli token token_balance -a "1GV8NGi8fgbG5kqpL6v64fQNkszkxyvwZ7" -s JTT -e unfreeze  
```
[
    {
        "Token": "JTT",
        "balance": "0.3200",
        "frozen": "0.0000",
        "addr": "1GV8NGi8fgbG5kqpL6v64fQNkszkxyvwZ7"
    }
]
```
终止合约   
cli send unfreeze  terminate --id mavl-unfreeze-f9cf7a1f2482ad1137bdc5af49bd1c2bbe6407308710cdbb21e6162e0cba0657 -k "197MWT1nNxHnmz4Wd6SWCPbL3naUy5WLiz"  

终止合约后，已解冻的部分也被收回，需求是否需要修改  

创建合约时，设置解冻周期为0，交易成功，执行失败，返回输入数据非法，应增加cli端限制。  
设置总量为0时，返回encoding/hex: invalid byte: U+0074 't'  增加cli端限制
创建合约时，total值小于每次解冻值，交易成功并执行成功，应限制total大于每次解冻值  
## para 跨链合约

## retrieve 钱包找回合约
```
Retrieve正常流程，完整过程：

1. 需要准备两个账户A和B，B是A的备份
我这里A：14KEKbYtKKQm4wMthSK9J4La4nAiidGozt    B:1KoVEeACNMyr42uEnfKR7SJTi5wE8nGWqx

2. 为了使最后retrieve能够看到效果，需要由A账户先打点钱进retrieve合约
./cli bty send_exec -a 100 -e retrieve
由A签名并发送

3. backup操作
./cli retrieve backup -b 1KoVEeACNMyr42uEnfKR7SJTi5wE8nGWqx -t 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt -d 61
由A签名并发送

4. prepare操作
./cli retrieve prepare -b 1KoVEeACNMyr42uEnfKR7SJTi5wE8nGWqx -t 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt
由B签名并发送

5. perform操作
./cli retrieve perform -b 1KoVEeACNMyr42uEnfKR7SJTi5wE8nGWqx -t 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt
由B签名并发送

6. 取回，从retrieve合约取钱
./cli bty withdraw -a 100 -e retrieve
由B签名并发送

注意：
A. retrieve合约只能够负责合约里余额的转移，要想达到外部账户的效果，必须要往合约里打钱，并最后取回，否则即便retrieve操作成功，也看不到效果
B. 因为prepare/perform/withdraw都是由备份地址签名完成的，因此这个备份地址还需要有点钱作为手续费
C. 当前retrieve命令和一些其他的执行器类似，操作只是创建了交易，还需要签名并发送
D. retrieve操作需要注意，不同的操作需要不同的地址签名A/B
E. 备份过程指定了prepare以后多久能够进行perform操作，最少是60s，所以为了保证perform能够成功，需要在prepare以后等待一下再perform
F. 测试过程中可以用查询命令查看状态
./cli retrieve query -b 1KoVEeACNMyr42uEnfKR7SJTi5wE8nGWqx -t 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt
```


## token token合约
发行bty token，分为预创建及完成创建两个阶段
向token合约地址转币：(一步完成)
cli send bty send_exec -e token -a 数量 -k 签名地址 
```
返回交易哈希
```

预创建：（一步完成）
cli send token precreate -f 手续费 -i 介绍 -n token名称 -a 拥有者地址 -p 发币费 -s 标志，需大写 -t 发行数量 -k 创建者地址
预创建后会冻结token合约中设置的发币费，可查询预创建列表:
cli token get_precreated
```
---The 30th precreated token is below--------------------
{
    "name": "mouse",
    "symbol": "MOU",
    "introduction": "bigmouse",
    "total": 10002,
    "owner": "152xusBV1onddSYcyTmGcGr1Yva7GAc37w",
    "creator": "165HDiXVdTaP1XgM54QbFJaciwAqDSBuip"
}
```

完成创建需要token-finisher管理权限签名：
cli send token finish -f 手续费 -a 拥有者地址 -s 标志 -k 管理权限地址签名
可查询已完成创建的token：
cli token get_finish_created
```
---The 308th Finish Created token is below--------------------
{
    "name": "mouse",
    "symbol": "MOU",
    "introduction": "bigmouse",
    "total": 10002,
    "owner": "152xusBV1onddSYcyTmGcGr1Yva7GAc37w",
    "creator": "165HDiXVdTaP1XgM54QbFJaciwAqDSBuip",
    "status": 1
}
```

其余命令列表：
```
Available Commands:
  finish             Create a finish created token transaction
  get_finish_created Get finish created tokens
  get_precreated     Get precreated tokens
  precreate          Create a precreated token transaction
  revoke             Create a token revoke transaction
  token_assets       Get token assets
  token_balance      Get token balance of one or more addresses
  transfer           Create a token transfer transaction
  withdraw           Create a token withdraw transaction
```

### revoke 撤销预创建
cli send token revoke -a 拥有者地址 -f 手续费 -s 标志 -k 创建者签名

### token_assets 查询指定地址在指定合约中的所有token余额
cli token token_assets -a 地址 -e 执行器
```
[
    {
        "Token": "MOU",
        "balance": "10002.0000",
        "frozen": "0.0000",
        "addr": "152xusBV1onddSYcyTmGcGr1Yva7GAc37w"
    }
]
```

### token_balance 查询指定地址在指定合约中，某指定token的余额
cli token token_balance -a 地址 -e 执行器 -s 标志
```
[
    {
        "Token": "MOU",
        "balance": "10002.0000",
        "frozen": "0.0000",
        "addr": "152xusBV1onddSYcyTmGcGr1Yva7GAc37w"
    }
]
```


### transfere token转账
cli send token transfer -t 接收地址 -a 数量 -s 标志 -k 签名私钥
```
返回交易哈希
```

### withdraw 收回token
cli send token withdraw -a 数量 -s 标志 -e 执行器 -k 签名私钥
```
返回交易哈希
```
## trade trade合约
```
Available Commands:
  buy                     Create a buying token transaction
  buy_order               Show one's buying orders
  revoke                  Create a revoke token transaction
  sell                    Create a selling token transaction
  sell_order              Show one's token selling orders
  status_buy_order        Show one's buying orders of tokens
  status_order            Show one's orders with status
  status_sell_order       Show selling orders of the status
  status_token_buy_order  Show token buying orders of a status
  status_token_sell_order Show token selling orders of a status
```


要执行在trade中的交易，首先需要由token合约向trade合约转币：
获取trade合约地址：
cli exec addr -e trade
```
1BXvgjmBw1aBgmGn1hjfGyRkmN3krWpFP4
```
向合约地址转币：
cli send token transfer -t 1BXvgjmBw1aBgmGn1hjfGyRkmN3krWpFP4 -a 数量 -k 签名地址  -s MOU

查询trade合约指定token余额
cli token token_balance -a 地址 -s MOU -e trade
```
[
    {
        "Token": "MOU",
        "balance": "100.0000",
        "frozen": "0.0000",
        "addr": "165HDiXVdTaP1XgM54QbFJaciwAqDSBuip"
    }
]
```

### sell 挂卖
cli send trade sell -f 手续费 -m 最小手数 -p 价格 -s MOU -t 最大数量 -k "152xusBV1onddSYcyTmGcGr1Yva7GAc37w"
默认每手为0.01个token

### sell_order 根据地址查询挂卖单
cli trade  sell_order -s 152xusBV1onddSYcyTmGcGr1Yva7GAc37w -t MOU
```
{
    "sellOrders": [
        {
            "tokenSymbol": "MOU",
            "owner": "152xusBV1onddSYcyTmGcGr1Yva7GAc37w",
            "amountPerBoardlot": "0.0100",
            "minBoardlot": 1,
            "pricePerBoardlot": "1.0000",
            "totalBoardlot": 2000,
            "tradedBoardlot": 0,
            "buyID": "",
            "status": 1,
            "sellID": "mavl-trade-sell-64cb10c29bedbd5ad1b3e9317999c637aac695cfbcab64ff292922ef9e5881ab",
            "txHash": "0x64cb10c29bedbd5ad1b3e9317999c637aac695cfbcab64ff292922ef9e5881ab",
            "height": 895679,
            "key": "mavl-trade-sell-64cb10c29bedbd5ad1b3e9317999c637aac695cfbcab64ff292922ef9e5881ab",
            "blockTime": 1536740067,
            "isSellOrder": true
        }
    ]
}
```
默认为0.01个每手，共20个token，故为2000手

购买trade中的挂卖时，需要先向trade合约转入bty
cli send bty transfer -t 1BXvgjmBw1aBgmGn1hjfGyRkmN3krWpFP4 -a 数量  -k 签名地址
```
返回交易哈希
```

### buy 购买token
cli send trade buy -c 购买手数 -s sellID -k 签名地址

购买后查询卖单
```
{
    "sellOrders": [
        {
            "tokenSymbol": "MOU",
            "owner": "152xusBV1onddSYcyTmGcGr1Yva7GAc37w",
            "amountPerBoardlot": "0.0100",
            "minBoardlot": 1,
            "pricePerBoardlot": "1.0000",
            "totalBoardlot": 2000,
            "tradedBoardlot": 10,
            "buyID": "",
            "status": 1,
            "sellID": "mavl-trade-sell-64cb10c29bedbd5ad1b3e9317999c637aac695cfbcab64ff292922ef9e5881ab",
            "txHash": "0x64cb10c29bedbd5ad1b3e9317999c637aac695cfbcab64ff292922ef9e5881ab",
            "height": 895679,
            "key": "mavl-trade-sell-64cb10c29bedbd5ad1b3e9317999c637aac695cfbcab64ff292922ef9e5881ab",
            "blockTime": 1536740067,
            "isSellOrder": true
        }
    ]
}
```


### buy_order 查询买单
cli trade buy_order -b "165HDiXVdTaP1XgM54QbFJaciwAqDSBuip" -t MOU
```
{
    "buyOrders": [
        {
            "tokenSymbol": "MOU",
            "owner": "165HDiXVdTaP1XgM54QbFJaciwAqDSBuip",
            "amountPerBoardlot": "0.0100",
            "minBoardlot": 1,
            "pricePerBoardlot": "1.0000",
            "totalBoardlot": 10,
            "tradedBoardlot": 10,
            "buyID": "",
            "status": 6,
            "sellID": "mavl-trade-sell-64cb10c29bedbd5ad1b3e9317999c637aac695cfbcab64ff292922ef9e5881ab",
            "txHash": "0xd8e5f2dd4c5159f1e100b3f7f6d3de89c09f664bc8e00326d8eb66b6dc7bd67f",
            "height": 895679,
            "key": "0xd8e5f2dd4c5159f1e100b3f7f6d3de89c09f664bc8e00326d8eb66b6dc7bd67f",
            "blockTime": 1536741001,
            "isSellOrder": false
        }
    ]
}
```


### status_buy_order 查询指定地址的指定状态的买单
cli trade status_buy_order -b 查询地址 -s 买单状态
```
{
    "buyOrders": [
        {
            "tokenSymbol": "MOU",
            "owner": "165HDiXVdTaP1XgM54QbFJaciwAqDSBuip",
            "amountPerBoardlot": "0.0100",
            "minBoardlot": 1,
            "pricePerBoardlot": "1.0000",
            "totalBoardlot": 10,
            "tradedBoardlot": 10,
            "buyID": "",
            "status": 6,
            "sellID": "mavl-trade-sell-64cb10c29bedbd5ad1b3e9317999c637aac695cfbcab64ff292922ef9e5881ab",
            "txHash": "0xd8e5f2dd4c5159f1e100b3f7f6d3de89c09f664bc8e00326d8eb66b6dc7bd67f",
            "height": 895679,
            "key": "0xd8e5f2dd4c5159f1e100b3f7f6d3de89c09f664bc8e00326d8eb66b6dc7bd67f",
            "blockTime": 1536741001,
            "isSellOrder": false
        }
    ]
}
```

※ -s支持onbuy, boughtout or buyrevoked

### status_order 查询指定地址的指定状态的所有买卖单，可指定配置查询
cli trade status_order -a "152xusBV1onddSYcyTmGcGr1Yva7GAc37w" -s 1
```
{
    "orders": [
        {
            "tokenSymbol": "MOU",
            "owner": "152xusBV1onddSYcyTmGcGr1Yva7GAc37w",
            "amountPerBoardlot": "0.0100",
            "minBoardlot": 1,
            "pricePerBoardlot": "1.0000",
            "totalBoardlot": 2000,
            "tradedBoardlot": 10,
            "buyID": "",
            "status": 1,
            "sellID": "mavl-trade-sell-64cb10c29bedbd5ad1b3e9317999c637aac695cfbcab64ff292922ef9e5881ab",
            "txHash": "0x64cb10c29bedbd5ad1b3e9317999c637aac695cfbcab64ff292922ef9e5881ab",
            "height": 895679,
            "key": "mavl-trade-sell-64cb10c29bedbd5ad1b3e9317999c637aac695cfbcab64ff292922ef9e5881ab",
            "blockTime": 1536740067,
            "isSellOrder": true
        }
    ]
}

```
※ -s后1: on, 2: done, 3: revoke
※ -c可选择输入，为显示的买卖单上限，默认为10；-d可选择输入，显示查询的方向，默认为1，即正向，0代表反向。

### revoke 撤销挂单

cli send trade revoke -s "mavl-trade-sell-64cb10c29bedbd5ad1b3e9317999c637aac695cfbcab64ff292922ef9e5881ab" -k "152xusBV1onddSYcyTmGcGr1Yva7GAc37w"
## unfreeze 冻结解冻合约

## privacy 隐私交易合约

## tx group 构建交易组
即原子交易，将多个交易捆绑，若其中有任意一笔交易失败，则整个交易组所有交易失败。交易手续费由第一笔的交易的地址统一扣除。
首先构建多个交易：
cli bty transfer -t 地址A 
```
返回字符串A1
```
cli bty transfer -t 地址B
```
返回字符串A2
```

将两个交易组成交易组:

cli bty txgroup -t "字符串A1 字符串A2"
```
返回字符串A3
```

签名，需根据index指定签名
cli wallet sign -d 字符串A3 -i 1 -a 签名地址
```
返回字符串A4
```

cli wallet sign -d 字符串A4 -i 2 -a 签名地址
```
返回字符串A5
```

发送：
cli wallet send -d 字符串A5


