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

asch合约文档 #38

Open
xingwy opened this issue Jul 28, 2018 · 0 comments
Open

asch合约文档 #38

xingwy opened this issue Jul 28, 2018 · 0 comments

Comments

@xingwy
Copy link
Contributor

xingwy commented Jul 28, 2018

ASCH 合约文档

合约使用说明

请求过程说明

通过asch-js里面封装好的transaction.createTransactionEx(params)方法获得到transaction,然后将这个transaction POST 发送到peer/transactions路由。

params是一个对象,先介绍下它的所含属性。

  • type: 合约编号

  • fee: 手续费

  • args: 合约所需参数

  • message:备注

  • secret: 发送者密码

  • secondSecret:二级密码

对于不同的合约,合约编号,手续费及合约所需要的参数是不同的。

下面列举一个转账合约的例子

let message = '备注' ,amount = 50*100000000,
    recipient = 'A3w7Rx5bCerJFbfG5BKdQ77bPqfWeyrmgJ',  //(只是给出地址格式,并非有效地址)
    mySecret = 'cat craft often annual face marriage lyrics clutch room helmet crowd biology',
    secondSecret = 'abcd12345'
let args = [amount,recipient],  //第一个参数是转账金额,第二个参数是目标地址
     
//构造params对象
let params = {
        type:1,      //转账的合约编号是1  
        fee:0.1*100000000,    //转账的手续费是0.1XAS
        args:args  //合约所需要参数
        message,    //做一些备注(非必需)
        secret:mySecret,   //我的密码(发送这笔交易的人的secret)
        secondSecret:mySecondSecret}  //二级密码(没设置可以填null,但有些交易必需使用)

//到这里位置所需要的params对象就构造好了,下面将这个对象交给asch-js里的createTransactionEx()接口
let aschjs = require('asch-js')
//这个方法返回的transaction就是需要提交到服务器的交易数据
let transaction = aschjs.transaction.createTransactionEx(params) 

//附带篇 (提交交易)
let axios = require('axios')
axios({
        method: 'post',
        url: 'http://serverhost:port/peer/transactions',    //port默认是4096
        json:true,
        data:{
            transaction:transaction
        },
        headers:{
            'Content-Type':'application/json',
            'version':'',
            'magic':'594fe0f3'
        }
    }).then(function(response){
        console.log(response.data)
    }).catch(function(error){
        console.log(error)
    })

//上述步骤成功后应该返回的是成功交易的交易ID
{success: true,transactionId:"609074700dcea17b56e5a98bbfeee5f6416935b6b444c0750e5cb319d818a502"}

以上就是调用一次合约的全部过程,其实对于不同的合约,所需要变换的变量有type,fee,args这三个属性。

下面枚举所有合约所需要的这三个属性(主要是这三个属性)

XAS的精度是小数点后八位,所以使用XAS币的时候需要乘上100000000,为了简洁,下面使用XAS的时候替换如下:

const xAS = 100000000


合约

1. 基础

1.1 转账

  • type:1

  • fee: 0.1*xAS

  • args: [amount,recipient]

    名称 类型 说明
    amount number 转账金额
    recipient string 接收地址

    代码示例

    //args参数示例
    let amount =  100*xAX   //转账金额
    let recipent = 'A3w7Rx5bCerJFbfG5BKdQ77bPqfWeyrmgJ'    //接收地址
    let args = [amount,recipent]

1.2 设置昵称

  • type:2

  • *fee: 1/10/40/80/100/200 xAX

  • args: [name]

    这里对手续费要左下说明,对于名字越长,手续费越便宜(有上限)

    len-fee关系表

    len fee
    2 200*xAS
    3 100*xAS
    4 80*xAS
    5 40*xAS
    6-10 10*xAS
    >10 1*xAS
    名称 类型 说明
    name string 昵称

    代码示例

    //args参数示例
    let name = 'user1'
    let args = [name]

1.3 设置二级密码

  • type:3

  • fee: 0.1*xAX

  • args: [secondSecret]

    名称 类型 说明
    secondSecret string 二级密码(加密后)
    //这个SecondSecret是加密后的字符串
    let password = 'asch123456'
    let hash = sha256Bytes(new Buffer(password))
    let keypair = nacl.sign.keyPair.fromSeed(hash);
    let secondSecret = new Buffer(keypair.publicKey).toString("hex")
    
    //得到将password加密后的secondSecret作为参数
    let args = [secondSecret]  

1.4 锁仓

  • type:4

  • fee: 0.1*xAX

  • args: [height,amount]

    名称 类型 说明
    height number 锁定的高度
    amount number 锁定的金额

    代码示例

    //args参数示例
    let height = 64200,amount = 20000*xAX
    let args = [height,amount]

1.5 解锁仓库

  • type:5

  • fee: 0*xAX

  • args: []

    说明:解锁仓库合约没有参数,所以args里不需要传数据

1.6 设置理事会

  • type:6
  • fee: 5*xAX
  • args: []

1.7 注册代理人

  • type:7

  • fee: 100*xAX

  • args: []

    说明:无需传入参数

1.8 设置代理人

  • type:8

  • fee: 0.1*xAX

  • args: [agent]

    名称 类型 说明
    agent string 代理人的昵称
    let agent = 'user1'
    let args = [agent]

1.9 取消代理人

  • type:9
  • fee: 0*xAX
  • args: []

1.10 注册委托人

  • type:10
  • fee: 100*xAX
  • args: []

1.11 给委托人投票

  • type:11

  • fee: 0.1*xAX

  • args: [delegates]

    名称 类型 说明
    delegates string 一些受托人的名字

    代码示例

    //delegate1,delegate2,delegate3分别为三个受托人的姓名
    let delegates = 'delegate1,delegate2,delegate3'   
    let args = [delegates]

代码举例

1.12 取消给委托人投票

  • type:12

  • fee: 0.1*xAX

  • args: [delegates]

    名称 类型 说明
    delegates string 一些受托人的名字

    代码示例

    let delegates = 'delegate1,delegate2'   //delegate1,delegate2,delegate3分别为三个受托人的姓名 
    let args = [delegates]

2 资产

2.1 注册发行商

  • type:100

  • fee: 100*xAX

  • args: [name,desc]

    名称 类型 说明
    name string 发行商名字
    desc string 一些文字描述

    代码示例

    //args参数示例
    let name = 'TEST'
    let desc = 'my first issuer'
    let args = [name,desc]

2.2 注册资产

  • type:101

  • fee: 500*xAX

  • args: [symbol,desc,maximum,precsion]

    名称 类型 说明
    symbol string 资产名称
    desc string 一些文字描述
    maximum string 最大发行量
    precsion number 精度

    代码示例

    //args参数示例
    let symbol = 'TXC'   //资产名由三个大写字母组成
    let desc = 'my first asset'
    let maximum = '100000000000'
    let precsion = 1     //取值范围是1-16之间的整数
    //组成args
    let args = [symbol,desc,maximum,precsion]

2.3 发行资产

  • type:102

  • fee: 0.1*xAX

  • args: [name,amount]

    名称 类型 说明
    name string 要发行的资产名
    amount string 发行数量

    代码示例

    //args参数示例
    let name = 'TEST.TXC'    //资产名=发行商名称.代币名
    let amount = '1000000000'
    let args = [name,amount]

2.4 内部转账

  • type:103

  • fee: 0.1*xAX

  • args: [currency,amount,recipient]

    名称 类型 说明
    currency string 内部资产名
    amount string 转账金额
    recipient string 接收地址

    代码示例

    //args参数示例
    let currency = 'TEST.TXC'
    let amount = '10000000'
    let recipient = 'A3w7Rx5bCerJFbfG5BKdQ77bPqfWeyrmgJ'
    //args组成
    let args = [currency,amount,recipient]

3 DApp管理相关合约

3.1 注册dapp

  • type:200

  • fee: 100*xAX

  • args: [name,desc,link,icon,delegates,unlockNumber]

    名称 类型 说明
    name string dapp名
    desc string 描述
    link string 链接
    icon string 图标
    delegates string 委托人
    unlockNumber number 最少需求数

    代码示例

    //args内参数说明
    let name = 'dappTest'        //dapp名称
    let desc = '一些文本描述'
    let link = 'http://yourdomain/dapp.zip'     //dapp的安装文件链接
    let icon = 'htpps//yourdomain/logo.png'     //dapp的图标链接
    //委托人数组delegate是一个数组,里面的数据是委托人的公钥
    let delegates = [
        "0352486d87c928918638c8a13c7e4765f2c9fa075318bd680b8d95e1cf1d616f",
        "cbb3671d343628fe03fba2f0139b783a7b86445f79ee55c99bf5bbe380e4fb46",
        "2f23a9659e32032910b8e078c0c980c6cb7c3a052a235a59079bfd6d608ecc95",
        "351c081c470f41620f4709b6b3ca3721dc920d4e528b27b8fa4d88635e53e128",
        "cbd808111a08081f7dc93aafd9fe26a70216e3f42d927660ab8d15b7bdf8998c"
    ]
    //最少需要的委托人个数(需要委托人共同决定)
    let unlockNumber = 3
    //构建args
    let args = [name,desc,link,icon,delegates,unlockNumber]

3.2 置换委托人

  • type:201
  • fee: 1*xAX
  • args: [chain,from,to]

3.3 增加委托人

  • type:202
  • fee: 1*xAX
  • args: [chain,key]

3.4 删减委托人

  • type:203
  • fee: 1*xAX
  • args: [chain,key]

3.5 存款

  • type:204

  • fee: 0.1*xAX

  • args: [chainName,currency,amount]

    名称 类型 说明
    chainName string 应用名(dapp)
    currency string 资产币名
    amount string 金额数量

    代码示例

    //args参数示例
    let chainName = 'dappTest'
    let currency = 'XAS'   //也可以是TEST.TXC内部资产币
    let amount = '1000000000'
    //args构造
    let args = [chainName,currency,amount]

3.6 提现

  • type:205

  • fee: 0.1*xAX

  • args: [chainName,recipient,currency,amount,oid,seq]

    名称 类型 说明
    chainName string 应用名
    recipient string 接收地址
    currency string 资产名
    amount string 提现金额
    oid string
    seq string

4 提案相关合约

4.1 发起提案

  • type:301

  • fee: 10*xAX

  • args: [title,desc,topic,content,endHeight]

    名称 类型 说明
    title string 提案标题
    desc string 描述
    topic string 提案类型
    content string 内容
    endHeight string 提案结束日期

    代码示例

    //args参数示例
    let title = 'title fo propose'     //  len: 10-100
    let desc = 'some describes of this propose'
    let topic = '提案的类型(下面详细介绍)'
    let content = '提案类型所需要的参数(下面详细介绍)'
    let endHeight = 50000     //结束高度
    //构造args
    let args = [title,desc,topic,content,endHeight]

    对不同提案类型给出不同的参数

    1. 新增网关
    //提案类型
    let topic = 'gateway_register'
    //下面构造content,对于新增网关提案,需要提供提案的名称,描述,最少成员,更新间隔,资产信息等
    let name = 'aschCoin'   //3-16位大小写字母数字
    let desc = 'aschyu: test the gateway register'
    let minimumMembers = 3      //网关最少成员数,这个数值的范围应当在3-33之间的整数,
    let updateInterval = 8640   //更新频率,这个值应当是大于8640的
    
    let symbol = 'TEC'   //比如发行的币叫TEC
    let currencyDesc = 'some describes of currency'    //资产描述
    let precsion = 1      //资产精度
    let currency = {symbol:symbol,
                    currencyDesccurrencyDesc,
                    precsion:precsion}
    //下面构造这个content
    let content = {name:name,
                   desc:desc,
                   minimumMembers:minimumMembers,
                   updateInterval:updateInterval,
                   currency:currency}
    1. 网关初始化
    //提案类型
    let topic = 'gateway_init'
    //下面构造content
    let gateway = 'bitcoin'     //网关的名字
    let members = [             //初始网关的成员
        'A5eTVn2Mz5p2j6SjGKdgvmUc2vMsSvKzuy',
        'A3SmW61ZwxmNc26BbfKLbHkaNbmUQzexuj',
        'A4ncaYtKRrD8YS2Mi82HbwGEE9DxqsbEr9'
    ]
    //下面构造这个content
    let content = {gateway:gateway,
                   members:members
                  }
    1. 更新网关成员
    //提案类型
    let topic = 'gateway_update_member'
    //下面构造content
    let gateway = 'bitcoin'     //网关的名字
    let form = 'A3SmW61ZwxmNc26BbfKLbHkaNbmUQzexuj'   //要撤销的成员地址
    let to = 'A7w7Rx5bCerJFbfG5BKdQ77bPqfWeyrmgJ'     //要添加的成员地址
    //下面构造这个content
    let content = {gateway:gateway,
                   from:from,
                   to:to
                  }
    1. 网关撤销
    //提案类型
    let topic = 'gateway_revoke'     //这个参数较少,只需要网关的名字即可
    //下面构造content
    let gateway = 'bitcoin'     //网关的名字
    //下面构造这个content
    let content = {gateway:gateway}

4.2 投票

  • type:302

  • fee: 0.1*xAX

  • args: [pid]

    名称 类型 说明
    pid string 提案的编号

    代码示例

    //args参数示例
    let pid = 'transactionId'        //发起提案的交易id
    //构造args
    let args = [pid]

4.3 激活提案

  • type:303

  • fee: 0*xAX

  • args: [pid]

    名称 类型 说明
    pid string 提案的编号

    代码示例

    //args参数示例
    let pid = 'transactionId'        //发起提案的交易id
    //构造args
    let args = [pid]

5 网关相关合约

5.1 开启网关

  • type:400

  • fee: 0.1*xAX

  • args: [gateway]

    名称 类型 说明
    gateway string 网关的名字

    代码示例

    //args参数示例
    let gateway = 'bitcoin'     //网关名字
    let args = [gateway]

5.2 注册成员

  • type:401

  • fee: 100*xAX

  • args: [pid]

    名称 类型 说明
    gateway string 网关名字
    publicKey string 成员公钥
    desc string 描述

    代码示例

    //args参数示例
    let gateway = 'bitcoin'
    let publicKey = 'c03e43c7e8aefe3b5a83e02a7b4dc8cce84bb787202650338e85d1b7758065d6'
    let desc = 'aschyu: some describes of resgiter member'
    //构造args
    let args = [gateway,publicKey,desc]

5.3 存款

  • type:402

  • fee: 0.01*xAX

  • args: [gateway,address,currency,amount,oid]

    名称 类型 说明
    gateway string 网关名字
    address string 存款地址
    currency string 货币
    amount string 数额
    oid string

    代码示例

    //args参数示例
    let gateway = 'bitcoin'
    let address = 'A7w7Rx5bCerJFbfG5BKdQ77bPqfWeyrmgJ'
    let currency = 'BTC'
    let amount = '100000000000'
    let oid = ''
    //构造args
    let args = [gateway,address,currency,amount,oid]

5.4 提现

  • type:403

  • fee: 0*xAX

  • args: [pid]

    名称 类型 说明
    address string 提现地址
    gateway string 网关名字
    currency string 货币
    amount string 数量
    fee string 手续费

    代码示例

    //args参数说明
    let gateway = 'bitcoin'
    let address = 'A7w7Rx5bCerJFbfG5BKdQ77bPqfWeyrmgJ'
    let currency = 'BTC'
    let amount = '100000000000'    //转账的金额
    let fee = '200000000'          //网关收取的手续费
    //构造args
    let args = [address,gateway,currency,amount,fee]

5.5 提交提现交易

  • type:404

  • fee: 0.01*xAX

  • args: [wid,ot,ots]

    名称 类型 说明
    wid string 提现id
    ot string 交易数据
    ots string

    代码示例

5.6 提交交易签名

  • type:405

  • fee: 0.01*xAX

  • args: [wid,signature]

    名称 类型 说明
    wid string 提现id
    signature string 签名

    代码示例

5.7 提交交易协议

  • type:406

  • fee: 0.01*xAX

  • args: [wid,oid]

    名称 类型 说明
    wid string 提现id
    oid string

6 理事会合约

6.1 投票

  • type:500

  • fee: 0*xAX

  • args: [targetId]

    名称 类型 说明
    targetId string 目标ID

    代码示例

    //args参数示例
    let targetId = 'f80dcf3d520cc14e963ddf4aedd6ae42db92795fc80ac3738c2be5b3aa5c9238'  //交易id
    let args = [targetId]

6.2 激活

  • type:501

  • fee: 0*xAX

  • args: [targetId]

    名称 类型 说明
    targetId string 目标ID

    代码示例

    //args参数示例
    let targetId = 'f80dcf3d520cc14e963ddf4aedd6ae42db92795fc80ac3738c2be5b3aa5c9238'  //交易id
    let args = [targetId]

6.3 增加成员

  • type:502

  • fee: 1*xAX

  • args: [address,weight,m]

    名称 类型 说明
    address string 成员地址
    weight string 权重
    m number

    代码示例

    //args参数示例
    let address = 'AMySpLqC4bEgQ8VoYK1iWNEEuhRtjS59Bt'  
    let weight = ''
    let m = 1
    let args = [address,weight,m]

6.4 移除成员

  • type:503

  • fee: 1*xAX

  • args: [address,m]

    名称 类型 说明
    address string 成员地址
    m number

    代码示例

    //args参数示例
    let address = 'AMySpLqC4bEgQ8VoYK1iWNEEuhRtjS59Bt'  
    let m = 1
    let args = [address,m]

6.5 置换成员

  • type:504

  • fee: 1*xAX

  • args: [form,to,weight,m]

    名称 类型 说明
    form string 将被替换成员
    to string 新来成员
    weight string 权重
    m number
    //args参数示例
    let form = 'AMySpLqC4bEgQ8VoYK1iWNEEuhRtjS59Bt' 
    let to = 'A3gmKrzbTALHpJv2SDZ2SaoyA44Ei9miJC'
    let weight = ''
    let m = 1
    let args = [form,to,weight,m]
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

No branches or pull requests

1 participant