diff --git a/README.md b/README.md index 7b46fd3..5a5d122 100755 --- a/README.md +++ b/README.md @@ -52,6 +52,10 @@ git clone https://github.com/AschPlatform/asch && cd asch && chmod u+x aschd npm install ``` +## Documentation + +[asch-docs](https://github.com/AschPlatform/asch-docs) + ## Web Wallet ``` @@ -130,7 +134,6 @@ node app.js --help ## Releated projects -- [asch-docs](https://github.com/AschPlatform/asch/tree/master/docs) - [asch-cli](https://github.com/AschPlatform/asch-cli) - [asch-js](https://github.com/AschPlatform/asch-js) - [asch-sandbox](https://github.com/AschPlatform/asch-sandbox-dist) diff --git a/docs/README.md b/docs/README.md deleted file mode 100644 index cb1c176..0000000 --- a/docs/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# asch_docs -Asch documents - -## 文档索引 - -- [白皮书](./asch_whitepaper.md) -- [节点安装](./asch_install.md) -- [受托人锻造及收益机制](./asch_delegate_forging.md) -- [命令行客户端](./asch_cli_usage.md) -- [Http接口](./asch_http_interface.md) -- [Dapp开发](./asch_dapps_introduction.md) - -## Documents index - -- [Whitepaper](./asch_whitepaper_en.md) -- [Install](./asch_install_en.md) -- [Delegate & forging](./asch_delegate_forging_en.md) -- [Command line interface](./asch_cli_usage_en.md) -- [Http interface](./asch_http_interface_en.md) -- Dapp / Sidechain - - [Dapp Javascript SDK](./asch_sdk_api_en.md) - - [Dapp Http API](./asch_dapp_default_api_en.md) - - [Dapp development tutorial](./asch_dapps_introduction_en.md) - -## Inhaltsverzeichnis - -- [Whitepaper](./asch_whitepaper_de.md) -- [Installation](./asch_install_de.md) -- [Delegation & Schmiede](./asch_delegate_forging_de.md) -- [Command Line Interface](./asch_cli_usage_de.md) -- [Http Interface](./asch_http_interface_de.md) -- [Dapp Entwicklung](./asch_dapps_introduction_de.md) \ No newline at end of file diff --git a/docs/asch_cli_usage.md b/docs/asch_cli_usage.md deleted file mode 100644 index 39c1c86..0000000 --- a/docs/asch_cli_usage.md +++ /dev/null @@ -1,1344 +0,0 @@ -Table of Contents -================= - - * [ASCH-CLI说明](#asch-cli说明) - * [0 asch-cli简介](#0-asch-cli简介) - * [1 asch-cli的安装](#1-asch-cli的安装) - * [2 asch-cli使用说明](#2-asch-cli使用说明) - * [3 asch-cli支持的选项](#3-asch-cli支持的选项) - * [3.1 打印帮助文档](#31-打印帮助文档) - * [3.2 打印asch-cli版本号](#32-打印asch-cli版本号) - * [3.3 指定要连接的asch服务器主机名或者ip](#33-指定要连接的asch服务器主机名或者ip) - * [3.4 指定要连接的asch服务器的端口](#34-指定要连接的asch服务器的端口) - * [3.5 指定主链](#35-指定主链) - * [4 asch-cli支持的命令](#4-asch-cli支持的命令) - * [4.1 区块链blockchain](#41-区块链blockchain) - * [4.1.1 查看区块链高度](#411-查看区块链高度) - * [4.1.2 查看区块链状态](#412-查看区块链状态) - * [4.1.3 查看节点信息](#413-查看节点信息) - * [4.1.4 全网节点状态](#414-全网节点状态) - * [4.1.5 全网受托人状态](#415-全网受托人状态) - * [4.1.6 查看全网节点的ip归属](#416-查看全网节点的ip归属) - * [4.1.7 创建创世块文件](#417-创建创世块文件) - * [4.2 账户account](#42-账户account) - * [4.2.1 根据密码查看账户信息](#421--根据密码查看账户信息) - * [4.2.2 根据公钥查看账户信息](#422-根据公钥查看账户信息) - * [4.2.3 根据地址查看账户余额](#423-根据地址查看账户余额) - * [4.2.4 根据地址查看账户信息](#424-根据地址查看账户信息) - * [4.2.5 查看账户地址投了哪些受托人](#425-查看账户地址投了哪些受托人) - * [4.2.6 加密相关](#426-加密相关) - * [4.2.7 账户锁仓](#427-账户锁仓) - * [4.3 受托人delegate](#43-受托人delegate) - * [4.3.1 查看全部受托人个数](#431-查看全部受托人个数) - * [4.3.2 查看受托人详情并排序](#432-查看受托人详情并排序) - * [4.3.3 根据受托人公钥查看都是谁为他投了票](#433-根据受托人公钥查看都是谁为他投了票) - * [4.3.4 根据公钥查看受托人详情](#434-根据公钥查看受托人详情) - * [4.3.5 根据名字查看受托人详情](#435-根据名字查看受托人详情) - * [4.3.5 注册受托人](#435-注册受托人) - * [4.3.6 给受托人投票](#436-给受托人投票) - * [4.3.7 给受托人取消投票](#437-给受托人取消投票) - * [4.4 区块block](#44-区块block) - * [4.4.1 查看(分析)全网区块信息](#441-查看分析全网区块信息) - * [4.4.2 根据区块id查看区块详情](#442-根据区块id查看区块详情) - * [4.4.3 根据区块高度查看区块详情](#443-根据区块高度查看区块详情) - * [4.4.4 根据区块id查看区块详情-包含交易信息](#444-根据区块id查看区块详情-包含交易信息) - * [4.4.5 根据区块高度查看区块详情-包含交易信息](#445-根据区块高度查看区块详情-包含交易信息) - * [4.4.6 验证区块文件字节](#446-验证区块文件字节) - * [4.4.7 验证区块文件payloadhash](#447-验证区块文件payloadhash) - * [4.4.8 验证区块文件区块id](#448-验证区块文件区块id) - * [4.4.8 验证区块签名是否通过](#448-验证区块签名是否通过) - * [4.5 交易transaction](#45-交易transaction) - * [4.5.1 根据公钥查看未确认的交易](#451-根据公钥查看未确认的交易) - * [4.5.2 查看(分析)全网交易信息](#452-查看分析全网交易信息) - * [4.5.3 根据交易id查看交易详情](#453-根据交易id查看交易详情) - * [4.5.4 转账](#454-转账) - * [4.5.5 设置二级密码](#455-设置二级密码) - * [4.5.6 验证交易文件bytes](#456-验证交易文件bytes) - * [4.5.7 验证交易文件id](#457-验证交易文件id) - * [4.4.8 验证交易签名是否通过](#448-验证交易签名是否通过) - * [4.6 侧链dapp](#46-侧链dapp) - * [4.6.1 注册dapp](#461-注册dapp) - * [4.6.2 dapp充值](#462-dapp充值) - * [4.6.3 智能合约的增删](#463--智能合约的增删) - * [4.6.4 dapp交易](#464-dapp交易) - * [4.6.5 dapp创建安装相关](#465--dapp创建安装相关) - -Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc) - - -# ASCH-CLI说明 - - -## 0 asch-cli简介 -以下内容引用自 [Asch白皮书](/asch_whitepaper.md) - ->asch-cli是Asch系统提供了一个命令行工具,只需要根据提示输入一些配置项,就可以快速的建立一个侧链,并可在侧链上开发任意类型的应用。其次,系统还提供了一系列的 api 帮助用户构建复杂的智能合约应用,这些 api 涵盖共识、强随机数、数据库、密码学等方面。 - - -## 1 asch-cli的安装 -sudo apt-get install npm #安装js软件包管理器npm - -npm install -g asch-cli #国内服务器可以考虑加上 “--registry=http://registry.npm.taobao.org” 参数加快安装速度 - -## 2 asch-cli使用说明 -asch-cli [选项] [命令] - -## 3 asch-cli支持的选项 -### 3.1 打印帮助文档 -参数值: -h, --help - -返回值: asch-cli命令或者子命令的帮助文档 - -使用方法:asch-cli -h(查看asch-cli帮助文档);asch-cli 子命令 -h(查看子命令的帮助文档) - -示例: - -``` -root@asch:~# asch-cli -h #查看asch-cli帮助信息 - Usage: asch-cli [options] [command] - Commands: - - getheight get block height - getblockstatus get block status - openaccount [secret] open your account and get the infomation by secret - openaccountbypublickey [publickey] open your account and get the infomation by publickey - getbalance [address] get balance by address - getaccount [address] get account by address - getvoteddelegates [options] [address] get delegates voted by address - getdelegatescount get delegates count - getdelegates [options] get delegates - getvoters [publicKey] get voters of a delegate by public key - getdelegatebypublickey [publicKey] get delegate by public key - getdelegatebyusername [username] get delegate by username - getblocks [options] get blocks - getblockbyid [id] get block by id - getblockbyheight [height] get block by height - getpeers [options] get peers - getunconfirmedtransactions [options] get unconfirmed transactions - gettransactions [options] get transactions - gettransaction [id] get transactions - sendmoney [options] send money to some address - registerdelegate [options] register delegate - upvote [options] vote for delegates - downvote [options] cancel vote for delegates - setsecondsecret [options] set second secret - registerdapp [options] register a dapp - contract [options] contract operations - crypto [options] crypto operations - dapps [options] manage your dapps - creategenesis [options] create genesis block - peerstat analyze block height of all peers - delegatestat analyze delegates status - ipstat analyze peer ip info - - Options: - - -h, --help output usage information - -V, --version output the version number - -H, --host Specify the hostname or ip of the node, default: 127.0.0.1 - -P, --port Specify the port of the node, default: 4096 - -M, --main Specify the mainnet, default: false - -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getvoteddelegates -h #查看子命令帮助 - Usage: getvoteddelegates [options] [address] - get delegates voted by address - Options: - - -h, --help output usage information - -o, --offset - -l, --limit -``` - -### 3.2 打印asch-cli版本号 -参数值: -V, --version - -返回值: asch-cli命令的版本号 - -使用方法:asch-cli -V - -示例: - -``` -root@asch:~# asch-cli -V -1.0.0 -``` - -### 3.3 指定要连接的asch服务器主机名或者ip -参数值: -H, --host 默认:127.0.0.1 - -返回值: 无 - -使用方法:asch-cli -H 45.32.248.33 [子命令] - -示例: - -``` -root@asch:~# asch-cli -H 45.32.248.33 getheight #查看45.32.248.33服务器最新的区块高度 -101236 -``` - -### 3.4 指定要连接的asch服务器的端口 -参数值: -P, --port 默认:4096 - -返回值: 无 - -使用方法:asch-cli -P 4096 [子命令] - -示例: - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getheight -102313 -``` - -### 3.5 指定主链 -参数值: -M, --main 默认:测试链 - -返回值: 无 - -使用方法:asch-cli -H 45.32.248.33 -P 8192 -M [子命令] - -示例: - -``` -root@asch:~# asch-cli -M -H *.*.*.105 -P 8192 getheight #查看asch主链区块高度 -9388 -``` - - -## 4 asch-cli支持的命令 -### 4.1 区块链blockchain -#### 4.1.1 查看区块链高度 -命令值: getheight - -返回值: 区块链高度 - -使用方法:asch-cli getheight - -示例: - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getheight -105387 -``` - -#### 4.1.2 查看区块链状态 -命令值: getblockstatus - -返回值: json字符串,包含区块链高度、交易费、里程碑、受托人每块奖励、当前总量 - -使用方法:asch-cli getblockstatus - -示例: - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getblockstatus -{ - "success": true, - "height": 105392, - "fee": 10000000, - "milestone": 0, - "reward": 350000000, - "supply": 10036887200000000 -} -``` - -#### 4.1.3 查看节点信息 -命令值: getpeers [options] - -返回值: 列表,包含节点ip、端口、os、asch版本等信息 - -使用方法:asch-cli getpeers -o 偏移量数字 -l限制个数数字 -t 状态值 -s 排序 -v 版本 -p 端口 --os os版本 #详情请参考asch-cli getpeers -h帮助信息 - -示例: - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getpeers -o 1 -l 2 -[ - { - "ip": "45.32.62.184", - "port": 4096, - "state": 2, - "os": "linux3.13.0-87-generic", - "version": "1.0.0" - }, - { - "ip": "45.32.22.78", - "port": 4096, - "state": 2, - "os": "linux3.13.0-87-generic", - "version": "1.0.0" - } -] -``` - - -#### 4.1.4 获取本机连接的所有节点信息 -命令值: peerstat - -返回值: 节点信息,包含节点ip、端口、版本、区块高度等信息 - -备注:展示节点只是和本机有连接的节点,并不是全网所有的节点 - -使用方法:asch-cli peerstat - -示例: - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 peerstat -45.32.248.33:4096 1.0.0 106036 -45.32.62.184:4096 1.0.0 106036 -45.32.19.241:4096 1.0.0 106036 -``` - -#### 4.1.5 全网受托人状态 -命令值: delegatestat - -返回值: 受托人信息,包含全网受托人的名字、地址、投票、生产率、区块生成个数、区块高度、id、上一次生成区块的时间等信息 - -使用方法:asch-cli - -示例: - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 delegatestat -name address rate approval productivity produced height id time -nayimoliuguang 3331976396377269399 93 88.36% 98.39% 1037 105618 12962348710289833740 2016/08/17 21:07:20(1 hour ago) -jack 3705405381126069457 86 88.36% 99.41% 506 105628 5876778147855073736 2016/08/17 21:09:00(1 hour ago) -node_3 12796761013870716784 81 88.36% 80.51% 814 105784 4575518649204137595 2016/08/17 21:38:10(40 mins ago) -wgl_003 9961157415582672274 2 98.65% 99.24% 1047 105852 11175724889329116017 2016/08/17 21:49:40(28 mins ago) -xihulongjing 12676662200687508271 59 88.36% 76.92% 150 105853 15273855606472618453 2016/08/17 21:49:50(28 mins ago) -liangpeili 4514546945474752928 50 88.37% 99.68% 627 105855 3771943180359756069 2016/08/17 21:50:10(28 mins ago) -asch_tea1 8812460086240160222 4 98.58% 98.79% 1059 105857 14968719538781965695 2016/08/17 21:50:30(27 mins ago) -intmaster 7321911740133937168 97 88.36% 100% 1032 105871 6757656887343300317 2016/08/17 21:52:50(25 mins ago) -mode_6 9248745407080572308 8 88.48% 100% 1060 105873 3777454410915098884 2016/08/17 21:53:10(25 mins ago) -``` - -#### 4.1.6 查看全网节点的ip归属 -命令值: ipstat - -返回值: 节点ip归属地 - -使用方法:asch-cli ipstat - -示例: - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 ipstat -美国 US -美国 US -美国 US -日本 JP -中国 CN -中国 CN -中国 CN -中国 CN -中国 CN -中国 CN -``` - -#### 4.1.7 创建创世块文件 -命令值: creategenesis [options] - -返回值: 在当前目录生成genesisBlock.json创世块文件、genGenesisBlock.log创世块日志 - -使用方法:asch-cli creategenesis - -示例: - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 creategenesis -root@asch:~# more genesisBlock.json -{ - "version": 0, - "totalAmount": 10000000000000000, - "totalFee": 0, - "reward": 0, - "payloadHash": "baebdb59d0c19a07c2440e22c0512b4efe9794565b352375195c9e7e8a3817b0", - "timestamp": 0, - "numberOfTransactions": 103, -... -} -``` - -### 4.2 账户account -#### 4.2.1 根据密码查看账户信息 -命令值: openaccount [secret] - -返回值: json字符串,含地址、余额、公钥、二级公钥等信息 - -使用方法:asch-cli openaccount "密码" - -示例: - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 openaccount "fault still attack alley expand music basket purse later educate follow ride" -{ - "address": "16723473400748954103", - "unconfirmedBalance": 20000000000, - "balance": 20000000000, - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9", - "unconfirmedSignature": false, - "secondSignature": false, - "secondPublicKey": "", - "multisignatures": [], - "u_multisignatures": [] -} -``` - -#### 4.2.2 根据公钥查看账户信息 -命令值: openaccountbypublickey [publickey] - -返回值: json字符串,含地址、余额、二级公钥等信息 - -使用方法:asch-cli openaccountbypublickey "公钥" - -示例: - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 openaccountbypublickey "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9" -{ - "address": "16723473400748954103", - "unconfirmedBalance": 20000000000, - "balance": 20000000000, - "unconfirmedSignature": false, - "secondSignature": false, - "secondPublicKey": "", - "multisignatures": [], - "u_multisignatures": [] -} -``` - -#### 4.2.3 根据地址查看账户余额 -命令值: getbalance [address] - -返回值: 整型数字,除以100000000后为大家平时所说的余额 - -使用方法:asch-cli getbalance 账户地址 - -示例: - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getbalance 16723473400748954103 -20000000000 -``` - -#### 4.2.4 根据地址查看账户信息 -命令值: getaccount [address] - -返回值: json字符串,含地址、余额、公钥、二级公钥等信息 - -使用方法:asch-cli getaccount 账户地址 - -示例: - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getaccount 16723473400748954103 -{ - "address": "16723473400748954103", - "unconfirmedBalance": 20000000000, - "balance": 20000000000, - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9", - "unconfirmedSignature": false, - "secondSignature": false, - "secondPublicKey": "", - "multisignatures": [], - "u_multisignatures": [] -} -``` - -#### 4.2.5 查看账户地址投了哪些受托人 -命令值: getvoteddelegates [options] [address] - -返回值: 列表 - -使用方法:asch-cli getvoteddelegates 账户地址 -o 偏移量数字 -l 限制打印的受托人个数数字 - -示例: - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getvoteddelegates 15745540293890213312 -o 1 -l 2 -{ success: true, - delegates: - [ { username: 'wgl_002', - address: '14636456069025293113', - publicKey: 'ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7', - vote: 8902736443247261, - producedblocks: 1041, - missedblocks: 6, - rate: 1, - approval: '88.70', - productivity: '99.42' }, - { username: 'wgl_003', - address: '9961157415582672274', - publicKey: 'c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2', - vote: 8902736443247261, - producedblocks: 1043, - missedblocks: 8, - rate: 2, - approval: '88.70', - productivity: '99.23' }] -``` - -#### 4.2.6 加密相关 -命令值: crypto [操作选项] - -返回值: 列表 - -使用方法:asch-cli -p(根据密码生成公钥);asch-cli -g(生成新账户) - -示例: - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 crypto -g -? Enter number of accounts to generate 1 -[ { address: '16723473400748954103', - secret: 'fault still attack alley expand music basket purse later educate follow ride', - publicKey: 'bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9' } ] -Done -``` - -#### 4.2.7 账户锁仓 -命令值: lock [操作选项] -返回值: 锁仓交易id -使用方法:asch-cli -e "一级密码" -s "二级密码" -h 锁仓高度 -备注:锁仓后且区块高度未达到锁仓高度,则该账户不能执行如下操作: -|交易类型type|备注| -|----|----| -|0|主链XAS转账| -|6|Dapp充值| -|7|Dapp提现| -|8|存储小文件| -|9|发行商注册| -|10|资产注册| -|13|资发行产| -|14|主链uia转账| - -示例: -``` -// 锁仓到高度4340 -password="found knife gather faith wrestle private various fame cover response security predict" -asch-cli lock -e "$password" -h 4340 -a533d303f90e3ca9e685c2bd7088b93ae2ff721eafbea61027b7e353bfc2babf -``` - -### 4.3 受托人delegate -#### 4.3.1 查看全部受托人个数 -命令值: getdelegatescount - -返回值: 整型数字 - -使用方法:asch-cli getdelegatescount - -示例: - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getdelegatescount -232 -``` - -#### 4.3.2 查看受托人详情并排序 -命令值: getdelegates [options] - -返回值: 列表 - -使用方法:asch-cli getdelegates -o 偏移量数字 -l 限制打印的受托人个数数字 -s rate:asc #rate:asc代表根据投票数正向排序,其它排序规则请参考asch-cli getdelegates -h帮助信息 - -示例: - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getdelegates -o 1 -l 1 -s rate:asc -[ - { - "username": "wgl_003", - "address": "9961157415582672274", - "publicKey": "c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2", - "vote": 9901544836887660, - "producedblocks": 1044, - "missedblocks": 8, - "fees": 12150495022, - "rewards": 161000000000, - "rate": 2, - "approval": 98.65, - "productivity": 99.24, - "forged": "173150495022" - } -] -``` - -#### 4.3.3 根据受托人公钥查看都是谁为他投了票 -命令值: getvoters [publicKey] - -返回值: 列表 - -使用方法:asch-cli getvoters "受托人公钥" - -示例: - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getvoters "ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7" -[ - { - "address": "2918354313445278349", - "publicKey": "4fde4c49f1297d5d3a24b1494204543c4281aff17917ff7ff8ff32da3b4b222f", - "balance": 1215522376203, - "weight": 0.012110398031994424 - }, - { - "address": "1523444724068322527", - "publicKey": "8a6a61c28dc47541aadf1eecec2175c8f768f2331eea3472b1593bf1aa4e1fb4", - "balance": 2109297623765, - "weight": 0.02101519008767971 - }] -``` - -#### 4.3.4 根据公钥查看受托人详情 -命令值: getdelegatebypublickey [publicKey] - -返回值: json字符串,包含受托人名字、地址、投票数、生成的block数、锻造收益等 - -使用方法:asch-cli getdelegatebypublickey "受托人公钥" - -示例: - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getdelegatebypublickey "ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7" -{ - "username": "wgl_002", - "address": "14636456069025293113", - "publicKey": "ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7", - "vote": 9901546586887660, - "producedblocks": 1042, - "missedblocks": 6, - "fees": 12383762523, - "rewards": 161700000000, - "rate": 1, - "approval": 98.65, - "productivity": 99.43, - "forged": "174083762523" -} -``` -#### 4.3.5 根据名字查看受托人详情 -命令值: getdelegatebyusername [username] - -返回值: json字符串,受托人详情 - -使用方法:asch-cli getdelegatebyusername "受托人名字" - -示例: - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getdelegatebyusername "wgl_002" -{ - "username": "wgl_002", - "address": "14636456069025293113", - "publicKey": "ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7", - "vote": 9901546586887660, - "producedblocks": 1042, - "missedblocks": 6, - "fees": 12383762523, - "rewards": 161700000000, - "rate": 1, - "approval": 98.65, - "productivity": 99.43, - "forged": "174083762523" -} -``` - -#### 4.3.5 注册受托人 -命令值: registerdelegate [options] - -返回值: 结果状态值,true或者报错信息 - -使用方法:asch-cli registerdelegate -e "密码" -s "二级密码" -u "受托人名字" - -示例: - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 registerdelegate -e "fault still attack alley expand music basket purse later educate follow ride" -u "delegate_register" -true -``` - -#### 4.3.6 给受托人投票 -命令值: upvote [options] - -返回值: 结果状态值,true或者报错信息 - -使用方法:asch-cli upvote -e "密码" -s "二级密码" -p "受托人公钥" - -示例: - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 upvote -e "fault still attack alley expand music basket purse later educate follow ride" -p "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9" -true -``` - -#### 4.3.7 给受托人取消投票 -命令值: downvote [options] - -返回值: 结果状态值,true或者报错信息 - -使用方法:asch-cli downvote -e "密码" -s "二级密码" -p "受托人公钥" - -示例: - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 downvote -e "fault still attack alley expand music basket purse later educate follow ride" -p "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9" -true -``` - -### 4.4 区块block -#### 4.4.1 查看(分析)全网区块信息 -命令值: getblocks [options] - -返回值: json字符串,包含查询状态、符合查询要求的区块信息 - -使用方法:asch-cli getblocks -o 偏移量数字 -l 限制的个数数字 -r 奖励 -f 费用 -a 总量 -g 生成区块的公钥 -s 排序规则 - -示例: - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getblocks -o 1 -l 1 -r 350000000 -{ - "success": true, - "blocks": [ - { - "id": "5533619110613125681", - "version": 0, - "timestamp": 3914630, - "height": 60481, - "previousBlock": "11174102253820291084", - "numberOfTransactions": 0, - "totalAmount": 0, - "totalFee": 0, - "reward": 350000000, - "payloadLength": 0, - "payloadHash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "generatorPublicKey": "68b28341605a24f6684df81882df1b13f421ec1cbba7d9aaa68f6c079705b258", - "generatorId": "10651956562526682705", - "blockSignature": "77115fdaab3215039bcf2bf8b3a461b3b7cafca7adae07e271a1a953ca6531a9e93f985bbec8544d596a568595661f1da742e20797b827d5b20aa75e8d80cc0b", - "confirmations": "45349", - "totalForged": 350000000 - } - ], - "count": 45350 -} -``` -#### 4.4.2 根据区块id查看区块详情 -命令值: getblockbyid [id] - -返回值: json字符串,包含区块id、区块高度、前一个blockid、交易数、总额、费用、奖励、哈希值、区块生成者公钥、id、区块签名、确认数等信息 - -使用方法:asch-cli getblockbyid 区块id - -示例: - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getblockbyid 1425942128040906871 #查看创世块 -{ - "id": "1425942128040906871", - "version": 0, - "timestamp": 0, - "height": 1, - "previousBlock": "", - "numberOfTransactions": 103, - "totalAmount": 10000000000000000, - "totalFee": 0, - "reward": 0, - "payloadLength": 19417, - "payloadHash": "dd5cd3186d32145b01f8fd0bd23e3b3d72414b59b162d2e664e759db8fe60d46", - "generatorPublicKey": "2af8566f8555bafb25df5a50e2e22b91a8577ceabc05d47dbd921572d28330e8", - "generatorId": "1170992220085500484", - "blockSignature": "a8ed06bfbfd1b630b1628e97a5c7c9383337c4ce32825969fad830890e0af981312be635b775ff46eea4f739da043f668a70efd5a940429e39fe5063852f4a01", - "confirmations": "105901", - "totalForged": 0 -} -``` - -#### 4.4.3 根据区块高度查看区块详情 -命令值: getblockbyheight [height] - -返回值: json字符串,包含区块id、区块高度、前一个blockid、交易数、总额、费用、奖励、哈希值、区块生成者公钥、id、区块签名、确认数等信息 - -使用方法:asch-cli getblockbyheight 区块高度 - -示例: - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getblockbyheight 1 -{ - "id": "1425942128040906871", - "version": 0, - "timestamp": 0, - "height": 1, - "previousBlock": "", - "numberOfTransactions": 103, - "totalAmount": 10000000000000000, - "totalFee": 0, - "reward": 0, - "payloadLength": 19417, - "payloadHash": "dd5cd3186d32145b01f8fd0bd23e3b3d72414b59b162d2e664e759db8fe60d46", - "generatorPublicKey": "2af8566f8555bafb25df5a50e2e22b91a8577ceabc05d47dbd921572d28330e8", - "generatorId": "1170992220085500484", - "blockSignature": "a8ed06bfbfd1b630b1628e97a5c7c9383337c4ce32825969fad830890e0af981312be635b775ff46eea4f739da043f668a70efd5a940429e39fe5063852f4a01", - "confirmations": "105922", - "totalForged": 0 -} -``` - -#### 4.4.4 根据区块id查看区块详情-包含交易信息 -命令值: getfullblockbyid [blockid] - -返回值: json字符串,包含区块id、区块高度、前一个blockid、交易数、总额、费用、奖励、哈希值、区块生成者公钥、id、区块签名、确认数、交易详情数组 等信息 - -使用方法:asch-cli getfullblockbyid 区块id -备注:比getblockbyid返回的结果多交易信息(交易信息数组) - -示例: - -``` -asch-cli getfullblockbyid 61e5c7c17a365e079d536dcf7d23acca30b927434ca474df8ce28547e3abbdc4 -{ - "id": "61e5c7c17a365e079d536dcf7d23acca30b927434ca474df8ce28547e3abbdc4", - "version": 0, - "timestamp": 40458800, - "height": 4330, - "previousBlock": "ddc0bb392da3b1d22ac4e2c50d1a30a7adabe35e221fc0aeb80e3c6aaa509f68", - "numberOfTransactions": 1, - "totalAmount": 0, - "totalFee": 10000000, - "reward": 350000000, - "payloadLength": 121, - "payloadHash": "a533d303f90e3ca9e685c2bd7088b93ae2ff721eafbea61027b7e353bfc2babf", - "generatorPublicKey": "0ae2e3bcd8c959bccc34445a9473eab1bece60300f3aa00d89612923470dee75", - "generatorId": "4354832300657989346", - "blockSignature": "6b09f19c21574c065015c026eaba049c25827b7008db071f7ac59e4f50538bbd70301dcf2cd9d3bada77e7a4279740fddb55ec72cce7de886517d74bdc1a0d0b", - "totalForged": 360000000, - "transactions": [ // 该区块包含的交易详情数组 - { - "id": "a533d303f90e3ca9e685c2bd7088b93ae2ff721eafbea61027b7e353bfc2babf", - "height": 4330, - "blockId": "61e5c7c17a365e079d536dcf7d23acca30b927434ca474df8ce28547e3abbdc4", - "type": 100, // 交易类型为100代表锁仓 - "timestamp": 40458794, - "senderPublicKey": "2856bdb3ed4c9b34fd2bba277ffd063a00f703113224c88c076c0c58310dbec4", - "requesterPublicKey": "", - "senderId": "ANH2RUADqXs6HPbPEZXv4qM8DZfoj4Ry3M", - "recipientId": "", - "amount": 0, - "fee": 10000000, - "signature": "efd9a349eb2bc0a022461401c312001a5cd9f4f4f2c1e554e5bda465e19d1f0da7b229b68fbcdda81d85e34c3cd331e968f27cc398908e7acd527d27ae7e230a", - "signSignature": "", - "signatures": null, - "args": [ - "4340" // 锁仓高度 - ], - "message": "", - "asset": {} - } - ] -} -``` - -#### 4.4.5 根据区块高度查看区块详情-包含交易信息 -命令值: getfullblockbyheight [blockheight] -返回值: json字符串,包含区块id、区块高度、前一个blockid、交易数、总额、费用、奖励、哈希值、区块生成者公钥、id、区块签名、确认数、交易详情数组 等信息 -使用方法:asch-cli getfullblockbyheight 区块高度 -备注:比getblockbyheight返回的结果多交易信息(交易信息数组) - -示例: - -``` -asch-cli getfullblockbyheight 4330 -{ - "id": "61e5c7c17a365e079d536dcf7d23acca30b927434ca474df8ce28547e3abbdc4", - "version": 0, - "timestamp": 40458800, - "height": 4330, - "previousBlock": "ddc0bb392da3b1d22ac4e2c50d1a30a7adabe35e221fc0aeb80e3c6aaa509f68", - "numberOfTransactions": 1, - "totalAmount": 0, - "totalFee": 10000000, - "reward": 350000000, - "payloadLength": 121, - "payloadHash": "a533d303f90e3ca9e685c2bd7088b93ae2ff721eafbea61027b7e353bfc2babf", - "generatorPublicKey": "0ae2e3bcd8c959bccc34445a9473eab1bece60300f3aa00d89612923470dee75", - "generatorId": "4354832300657989346", - "blockSignature": "6b09f19c21574c065015c026eaba049c25827b7008db071f7ac59e4f50538bbd70301dcf2cd9d3bada77e7a4279740fddb55ec72cce7de886517d74bdc1a0d0b", - "totalForged": 360000000, - "transactions": [ // 该区块包含的交易详情数组 - { - "id": "a533d303f90e3ca9e685c2bd7088b93ae2ff721eafbea61027b7e353bfc2babf", - "height": 4330, - "blockId": "61e5c7c17a365e079d536dcf7d23acca30b927434ca474df8ce28547e3abbdc4", - "type": 100, // 交易类型为100代表锁仓 - "timestamp": 40458794, - "senderPublicKey": "2856bdb3ed4c9b34fd2bba277ffd063a00f703113224c88c076c0c58310dbec4", - "requesterPublicKey": "", - "senderId": "ANH2RUADqXs6HPbPEZXv4qM8DZfoj4Ry3M", - "recipientId": "", - "amount": 0, - "fee": 10000000, - "signature": "efd9a349eb2bc0a022461401c312001a5cd9f4f4f2c1e554e5bda465e19d1f0da7b229b68fbcdda81d85e34c3cd331e968f27cc398908e7acd527d27ae7e230a", - "signSignature": "", - "signatures": null, - "args": [ - "4340" // 锁仓高度 - ], - "message": "", - "asset": {} - } - ] -} -``` - -#### 4.4.6 验证区块文件字节 -命令值: getblockbytes [-f block_file] -返回值: 区块文件字节,hex格式数据 -使用方法:asch-cli getblockbytes -f 区块文件 -备注: 下面这几个命令主要是验证区块文件,通过修改fullblock数据来和区块链上的数据进行对比是否一致 - -示例: - -``` -asch-cli getfullblockbyheight 4330 > blockfile -cat blockfile -{ - "id": "61e5c7c17a365e079d536dcf7d23acca30b927434ca474df8ce28547e3abbdc4", - "version": 0, - "timestamp": 40458800, - "height": 4330, - "previousBlock": "ddc0bb392da3b1d22ac4e2c50d1a30a7adabe35e221fc0aeb80e3c6aaa509f68", - "numberOfTransactions": 1, - "totalAmount": 0, - "totalFee": 10000000, - "reward": 350000000, - "payloadLength": 121, - "payloadHash": "a533d303f90e3ca9e685c2bd7088b93ae2ff721eafbea61027b7e353bfc2babf", - "generatorPublicKey": "0ae2e3bcd8c959bccc34445a9473eab1bece60300f3aa00d89612923470dee75", - "generatorId": "4354832300657989346", - "blockSignature": "6b09f19c21574c065015c026eaba049c25827b7008db071f7ac59e4f50538bbd70301dcf2cd9d3bada77e7a4279740fddb55ec72cce7de886517d74bdc1a0d0b", - "totalForged": 360000000, - "transactions": [ - { - "id": "a533d303f90e3ca9e685c2bd7088b93ae2ff721eafbea61027b7e353bfc2babf", - "height": 4330, - "blockId": "61e5c7c17a365e079d536dcf7d23acca30b927434ca474df8ce28547e3abbdc4", - "type": 100, - "timestamp": 40458794, - "senderPublicKey": "2856bdb3ed4c9b34fd2bba277ffd063a00f703113224c88c076c0c58310dbec4", - "requesterPublicKey": "", - "senderId": "ANH2RUADqXs6HPbPEZXv4qM8DZfoj4Ry3M", - "recipientId": "", - "amount": 0, - "fee": 10000000, - "signature": "efd9a349eb2bc0a022461401c312001a5cd9f4f4f2c1e554e5bda465e19d1f0da7b229b68fbcdda81d85e34c3cd331e968f27cc398908e7acd527d27ae7e230a", - "signSignature": "", - "signatures": null, - "args": [ - "4340" - ], - "message": "", - "asset": {} - } - ] -} - -asch-cli getblockbytes -f blockfile -00000000305a69026464633062623339326461336231643232616334653263353064316133306137616461626533356532323166633061656238306533633661616135303966363801000000000000000000000080969800000000008093dc140000000079000000a533d303f90e3ca9e685c2bd7088b93ae2ff721eafbea61027b7e353bfc2babf0ae2e3bcd8c959bccc34445a9473eab1bece60300f3aa00d89612923470dee75 -``` - -#### 4.4.7 验证区块文件payloadhash -命令值: getblockpayloadhash [-f blockfile] - -返回值: 该区块的paylaod hash - -使用方法:asch-cli getblockpayloadhash -f 区块文件 - -示例: - -``` -asch-cli getfullblockbyheight 4330 > blockfile - -asch-cli getblockpayloadhash -f blockfile -a533d303f90e3ca9e685c2bd7088b93ae2ff721eafbea61027b7e353bfc2babf -``` - -#### 4.4.8 验证区块文件区块id -命令值: getblockid [-f blockfile] -返回值: 该区块文件的blockid -使用方法:asch-cli getblockid -f 区块文件 - -示例: -``` -asch-cli getfullblockbyheight 4330 > blockfile - -asch-cli getblockid -f blockfile -61e5c7c17a365e079d536dcf7d23acca30b927434ca474df8ce28547e3abbdc4 -``` - -#### 4.4.8 验证区块签名是否通过 -命令值: verifybytes [options] -返回值: true or false -使用方法:asch-cli verifybytes -b 区块hex字节数据 -s 区块签名 -p 区块生成者公钥 - -示例: -``` -asch-cli getfullblockbyheight 4330 -{ - "id": "61e5c7c17a365e079d536dcf7d23acca30b927434ca474df8ce28547e3abbdc4", - "version": 0, - "timestamp": 40458800, - "height": 4330, - "previousBlock": "ddc0bb392da3b1d22ac4e2c50d1a30a7adabe35e221fc0aeb80e3c6aaa509f68", - "numberOfTransactions": 1, - "totalAmount": 0, - "totalFee": 10000000, - "reward": 350000000, - "payloadLength": 121, - "payloadHash": "a533d303f90e3ca9e685c2bd7088b93ae2ff721eafbea61027b7e353bfc2babf", - "generatorPublicKey": "0ae2e3bcd8c959bccc34445a9473eab1bece60300f3aa00d89612923470dee75", // 区块生成者公钥 - "generatorId": "4354832300657989346", - "blockSignature": "6b09f19c21574c065015c026eaba049c25827b7008db071f7ac59e4f50538bbd70301dcf2cd9d3bada77e7a4279740fddb55ec72cce7de886517d74bdc1a0d0b", // 区块签名 - "totalForged": 360000000, - "transactions": [ - { - "id": "a533d303f90e3ca9e685c2bd7088b93ae2ff721eafbea61027b7e353bfc2babf", - "height": 4330, - "blockId": "61e5c7c17a365e079d536dcf7d23acca30b927434ca474df8ce28547e3abbdc4", - "type": 100, - "timestamp": 40458794, - "senderPublicKey": "2856bdb3ed4c9b34fd2bba277ffd063a00f703113224c88c076c0c58310dbec4", - "requesterPublicKey": "", - "senderId": "ANH2RUADqXs6HPbPEZXv4qM8DZfoj4Ry3M", - "recipientId": "", - "amount": 0, - "fee": 10000000, - "signature": "efd9a349eb2bc0a022461401c312001a5cd9f4f4f2c1e554e5bda465e19d1f0da7b229b68fbcdda81d85e34c3cd331e968f27cc398908e7acd527d27ae7e230a", - "signSignature": "", - "signatures": null, - "args": [ - "4340" - ], - "message": "", - "asset": {} - } - ] -} - -asch-cli getblockbytes -f blockfile // 生成区块hex数据 -00000000305a69026464633062623339326461336231643232616334653263353064316133306137616461626533356532323166633061656238306533633661616135303966363801000000000000000000000080969800000000008093dc140000000079000000a533d303f90e3ca9e685c2bd7088b93ae2ff721eafbea61027b7e353bfc2babf0ae2e3bcd8c959bccc34445a9473eab1bece60300f3aa00d89612923470dee75 - -asch-cli verifybytes -b 00000000305a69026464633062623339326461336231643232616334653263353064316133306137616461626533356532323166633061656238306533633661616135303966363801000000000000000000000080969800000000008093dc140000000079000000a533d303f90e3ca9e685c2bd7088b93ae2ff721eafbea61027b7e353bfc2babf0ae2e3bcd8c959bccc34445a9473eab1bece60300f3aa00d89612923470dee75 -s 6b09f19c21574c065015c026eaba049c25827b7008db071f7ac59e4f50538bbd70301dcf2cd9d3bada77e7a4279740fddb55ec72cce7de886517d74bdc1a0d0b -p 0ae2e3bcd8c959bccc34445a9473eab1bece60300f3aa00d89612923470dee75 -// 对hex进行签名验证 -true // 结果为true - -// 将上面的hex数据略做改动则验证不会被通过 -asch-cli verifybytes -b 10000000305a69026464633062623339326461336231643232616334653263353064316133306137616461626533356532323166633061656238306533633661616135303966363801000000000000000000000080969800000000008093dc140000000079000000a533d303f90e3ca9e685c2bd7088b93ae2ff721eafbea61027b7e353bfc2babf0ae2e3bcd8c959bccc34445a9473eab1bece60300f3aa00d89612923470dee75 -s 6b09f19c21574c065015c026eaba049c25827b7008db071f7ac59e4f50538bbd70301dcf2cd9d3bada77e7a4279740fddb55ec72cce7de886517d74bdc1a0d0b -p 0ae2e3bcd8c959bccc34445a9473eab1bece60300f3aa00d89612923470dee75 -false // 将hex首位改成1则验证不通过 -``` - -### 4.5 交易transaction -#### 4.5.1 根据公钥查看未确认的交易 -命令值: getunconfirmedtransactions [options] - -返回值: 列表,包含所有未确认的交易详情 - -使用方法:asch-cli getunconfirmedtransactions -k "发送者公钥" -a 接收者地址 - -示例: - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getunconfirmedtransactions -k "d39d6f26869067473d685da742339d1a9117257fe14b3cc7261e3f2ed5a339e3" -[ - { - "type": 0, - "timestamp": 4385190, - "senderPublicKey": "d39d6f26869067473d685da742339d1a9117257fe14b3cc7261e3f2ed5a339e3", - "signature": "98d65df3109802c707eeed706e90a907f337bddab58cb4c1fbe6ec2179aa1c85ec2903cc0cf44bf0092926829aa5a0a6ec99458f65b6ebd11f0988772e58740e", - "recipientId": "16723473400748954103", - "senderId": "15745540293890213312", - "amount": 10000000000, - "fee": 10000000, - "signatures": [], - "id": "17192581936339156329", - "height": 0, - "asset": {} - } -] -``` - -#### 4.5.2 查看(分析)全网交易信息 -命令值: gettransactions [options] - -返回值: 列表,包含所有符合查询条件的交易详情 - -使用方法:asch-cli gettransactions -b 区块id -o 偏移量数字 -l 限制个数数字 #其他参数请参考sch-cli gettransactions -h查看帮助信息 - -示例: - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 gettransactions -o 1 -l 2 #查看全网前2个交易 -[ - { - "id": "10169086766604015960", - "height": "1", - "blockId": "1425942128040906871", - "type": 2, - "timestamp": 0, - "senderPublicKey": "991e0dda00d2c33ce68dd99471de8ebea7b58711f22a2e55236b8864c6d24c84", - "senderId": "3331250159865474723", - "recipientId": "", - "amount": 0, - "fee": 0, - "signature": "60bf38e7a3515aeaa2cac491f7737c94087f448a862099408b90c2cf96d3fe4f709e22e6471dd4e37aca111d8573beeb7b6cff4ef451633d9aaf74ab97ce8d02", - "signSignature": "", - "signatures": null, - "confirmations": "105988", - "asset": {} - }, - { - "id": "10375311635154792515", - "height": "1", - "blockId": "1425942128040906871", - "type": 2, - "timestamp": 0, - "senderPublicKey": "1674ae566c633cde3e01db8f04a02ea087081a270de2dd53e0e0b97c029106fb", - "senderId": "9948352853509008057", - "recipientId": "", - "amount": 0, - "fee": 0, - "signature": "f09c1693cc26c4028c642cb1711cf71c2dee090a50904d1590c74d865b2f5f3ba720ed792704f5379ec9c4a20b018c5e95f325ea179236777a28cddffe8c580d", - "signSignature": "", - "signatures": null, - "confirmations": "105988", - "asset": {} - } -] -``` - -#### 4.5.3 根据交易id查看交易详情 -命令值: gettransaction [id] - -返回值: json字符串,包含交易id、区块高度、区块id、时间戳、发送者公钥、接收者地址、金额、费用、签名、确认数、资产等信息 - -使用方法:asch-cli gettransaction 交易id - -示例: - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 gettransaction 17192581936339156329 -{ - "id": "17192581936339156329", - "height": "105951", - "blockId": "15051364118100195665", - "type": 0, - "timestamp": 4385190, - "senderPublicKey": "d39d6f26869067473d685da742339d1a9117257fe14b3cc7261e3f2ed5a339e3", - "senderId": "15745540293890213312", - "recipientId": "16723473400748954103", - "amount": 10000000000, - "fee": 10000000, - "signature": "98d65df3109802c707eeed706e90a907f337bddab58cb4c1fbe6ec2179aa1c85ec2903cc0cf44bf0092926829aa5a0a6ec99458f65b6ebd11f0988772e58740e", - "signSignature": "", - "signatures": null, - "confirmations": "17", - "asset": {} -} -``` - -#### 4.5.4 转账 -命令值: sendmoney [选项] - -返回值: 结果状态值,true或者报错信息 - -使用方法:asch-cli -e "发送者密码" -t 接收者地址 -a 转账金额 [-s "二级密码"] - -示例: - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 sendmoney -e "motion group blossom coral upper warrior pattern fragile sister misery palm admin" -t 16723473400748954103 -a 100 -true -``` - - -#### 4.5.5 设置二级密码 -命令值: setsecondsecret [options] - -返回值: 结果状态值,true或者报错信息 - -使用方法:asch-cli setsecondsecret -e "密码" -s "二级密码" - -示例: - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 setsecondsecret -e "fault still attack alley expand music basket purse later educate follow ride" -s "ce shi er ji mi ma" -true -``` - -#### 4.5.6 验证交易文件bytes -命令值: gettransactionbytes [-f transaction_file] -返回值: 交易bytes,hex格式数据 -使用方法:asch-cli gettransactionbytes -f 交易数据文件 - -示例: -``` -asch-cli gettransaction a533d303f90e3ca9e685c2bd7088b93ae2ff721eafbea61027b7e353bfc2babf > transactionfile -cat transactionfile -{ - "id": "a533d303f90e3ca9e685c2bd7088b93ae2ff721eafbea61027b7e353bfc2babf", - "height": "4330", - "blockId": "61e5c7c17a365e079d536dcf7d23acca30b927434ca474df8ce28547e3abbdc4", - "type": 100, - "timestamp": 40458794, - "senderPublicKey": "2856bdb3ed4c9b34fd2bba277ffd063a00f703113224c88c076c0c58310dbec4", - "senderId": "ANH2RUADqXs6HPbPEZXv4qM8DZfoj4Ry3M", - "recipientId": "", - "amount": 0, - "fee": 10000000, - "signature": "efd9a349eb2bc0a022461401c312001a5cd9f4f4f2c1e554e5bda465e19d1f0da7b229b68fbcdda81d85e34c3cd331e968f27cc398908e7acd527d27ae7e230a", - "signSignature": "", - "signatures": null, - "confirmations": "413", - "args": [ - "4340" - ], - "message": "", - "asset": {} -} - -asch-cli gettransactionbytes -f transactionfile -642a5a69022856bdb3ed4c9b34fd2bba277ffd063a00f703113224c88c076c0c58310dbec40000000000000000000000000000000034333430 -``` - -#### 4.5.7 验证交易文件id -命令值: gettransactionid [-f transaction_file] -返回值: 交易id - -使用方法:asch-cli gettransactionid -f 交易数据文件 - -示例: -``` -asch-cli gettransaction a533d303f90e3ca9e685c2bd7088b93ae2ff721eafbea61027b7e353bfc2babf > transactionfile - -asch-cli gettransactionid -f transactionfile -a533d303f90e3ca9e685c2bd7088b93ae2ff721eafbea61027b7e353bfc2babf -``` - -#### 4.4.8 验证交易签名是否通过 -命令值: verifybytes [options] -返回值: true or false -使用方法:asch-cli verifybytes -b 交易hex字节数据 -s 交易签名 -p 发送者公钥 - -示例: -``` -asch-cli gettransaction a533d303f90e3ca9e685c2bd7088b93ae2ff721eafbea61027b7e353bfc2babf > transactionfile -cat transactionfile -{ - "id": "a533d303f90e3ca9e685c2bd7088b93ae2ff721eafbea61027b7e353bfc2babf", - "height": "4330", - "blockId": "61e5c7c17a365e079d536dcf7d23acca30b927434ca474df8ce28547e3abbdc4", - "type": 100, - "timestamp": 40458794, - "senderPublicKey": "2856bdb3ed4c9b34fd2bba277ffd063a00f703113224c88c076c0c58310dbec4", // 发送者公钥 - "senderId": "ANH2RUADqXs6HPbPEZXv4qM8DZfoj4Ry3M", - "recipientId": "", - "amount": 0, - "fee": 10000000, - "signature": "efd9a349eb2bc0a022461401c312001a5cd9f4f4f2c1e554e5bda465e19d1f0da7b229b68fbcdda81d85e34c3cd331e968f27cc398908e7acd527d27ae7e230a", // 交易签名 - "signSignature": "", - "signatures": null, - "confirmations": "413", - "args": [ - "4340" - ], - "message": "", - "asset": {} -} - -asch-cli gettransactionbytes -f transactionfile // hex格式交易数据 -642a5a69022856bdb3ed4c9b34fd2bba277ffd063a00f703113224c88c076c0c58310dbec40000000000000000000000000000000034333430 - -asch-cli verifybytes -b 642a5a69022856bdb3ed4c9b34fd2bba277ffd063a00f703113224c88c076c0c58310dbec40000000000000000000000000000000034333430 -s efd9a349eb2bc0a022461401c312001a5cd9f4f4f2c1e554e5bda465e19d1f0da7b229b68fbcdda81d85e34c3cd331e968f27cc398908e7acd527d27ae7e230a -p 2856bdb3ed4c9b34fd2bba277ffd063a00f703113224c88c076c0c58310dbec4 -// 对hex交易数据进行签名验证 -true // 结果为true - -// 对hex交易数据略作修改则签名验证不会通过 -asch-cli verifybytes -b 142a5a69022856bdb3ed4c9b34fd2bba277ffd063a00f703113224c88c076c0c58310dbec40000000000000000000000000000000034333430 -s efd9a349eb2bc0a022461401c312001a5cd9f4f4f2c1e554e5bda465e19d1f0da7b229b68fbcdda81d85e34c3cd331e968f27cc398908e7acd527d27ae7e230a -p 2856bdb3ed4c9b34fd2bba277ffd063a00f703113224c88c076c0c58310dbec4 -false // 将hex数据首位修改为1 - -``` - -### 4.6 侧链dapp -#### 4.6.1 注册dapp -命令值: registerdapp [options] - -返回值: 生成的dapp id - -使用方法:asch-cli registerdapp -e "密码" -s "二级密码" -f dapp元信息文件 - -示例: -``` -root@asch:~$ asch-cli registerdapp -f dapp.json -e "found knife gather faith wrestle private various fame cover response security predict" -d352263c517195a8b612260971c7af869edca305bb64b471686323817e57b2c1 -``` - -#### 4.6.2 dapp充值 -命令值: deposit [options] - -返回值: 充值交易id - -使用方法: asch-cli deposit -e "密码" -s "二级密码" -d dappid -c 待充值资产名称 -a 充值数量 - -示例: -``` -dappid=d352263c517195a8b612260971c7af869edca305bb64b471686323817e57b2c1 -password="elite brush pave enable history risk ankle shrimp debate witness ski trend" - -asch-cli -H 45.32.22.78 -P 4096 deposit -e "$password" -d $dappid -c "CCTime.XCT" -a "100000000" // 给dapp充值 1 CCTime.XCT -e5684046c87bef58e32ac64ea01a97e8323e6fe695e2dc186ca7ee6a55a9dbf5 -``` - -#### 4.6.3 智能合约的增删 -命令值: contract [options] - -返回值: - -使用方法:asch-cli contract -a(创建合约);asch-cli contract -d(删除合约) - -示例: -``` - -``` - -#### 4.6.4 dapp交易 -命令值: dapptransaction [options] - -返回值: dapp交易id - -使用方法: asch-cli dapptransaction -e "密码" -d dappid -t 智能合约编号 -a 数据字符串参数 -f 手续费(暂时是固定的10000000) - -示例: -``` -dappid=d352263c517195a8b612260971c7af869edca305bb64b471686323817e57b2c1 -password="elite brush pave enable history risk ankle shrimp debate witness ski trend" - -asch-cli -H 45.32.22.78 -P 4096 dapptransaction -e "$password" -d $dappid -t 2 -a '["CCTime.XCT","100000000"]' -f 10000000 // 从dapp里面提现 1 CCTime.XCT -24a0b6b08f38882bac2791255e71437c5de4c37b619f5086a0bf32484cd8cf5b - -asch-cli -H 45.32.22.78 -P 4096 dapptransaction -e "$password" -d $dappid -t 3 -a '["CCTime.XCT","100000000","ADimyhJa99XFzVrbnTYsCqPB4TKQNdjCWw"]' -f 10000000 // 给ADimyhJa99XFzVrbnTYsCqPB4TKQNdjCWw在dapp内部转账1 CCTime.XCT -4a33e538f54b418bc89ac4484f954e51a749a94004aaf15939b4148991fac21c - -asch-cli -H 45.32.22.78 -P 4096 dapptransaction -e "$password" -d $dappid -t 4 -a '["zhenxi"]' -f 10000000 // 给该账户设置昵称“zhenxi” -1234b6b08f38882bac2791255e71437c5de4c37b619f5086a0bf32484cd8cf5b -``` - -#### 4.6.5 dapp创建安装相关 -命令值: dapps [options] -返回值: -使用方法:asch-cli dapps -a -示例 -``` - -``` - diff --git a/docs/asch_cli_usage_de.md b/docs/asch_cli_usage_de.md deleted file mode 100644 index 9a6cf8d..0000000 --- a/docs/asch_cli_usage_de.md +++ /dev/null @@ -1,906 +0,0 @@ -# Asch-CLI Dokumentation ---- -Inhaltsverzeichnis -================= - -- [Asch-CLI Dokumentation](#asch-cli-dokumentation) - - [0 Asch-CLI Übersicht](#0-asch-cli-%C3%9Cbersicht) - - [1 Asch-CLI Installation](#1-asch-cli-installation) - - [2 Asch-CLI Zusammenfassung](#2-asch-cli-zusammenfassung) - - [3 Asch-CLI Parameter](#3-asch-cli-parameter) - - [3.1 Zeige die Hilfsinformationen](#31-zeige-die-hilfsinformationen) - - [3.2 Zeige die Version der Asch-CLI](#32-zeige-die-version-der-asch-cli) - - [3.3 Spezifiziere eine IP-Adresse oder einen Hostnamen für den Asch-Zielserver](#33-spezifiziere-eine-ip-adresse-oder-einen-hostnamen-f%C3%BCr-den-asch-zielserver) - - [3.4 Spezifiziere eine Portnummer auf dem Asch-Zielserver](#34-spezifiziere-eine-portnummer-auf-dem-asch-zielserver) - - [3.5 Verwende die Haupt-Blockchain](#35-verwende-die-haupt-blockchain) - - [4 Asch-CLI unterstützte Parameter](#4-asch-cli-unterst%C3%BCtzte-parameter) - - [4.1 Zeige die Höhe der Blockchain](#41-zeige-die-h%C3%B6he-der-blockchain) - - [4.2 Zeige den Status der Blockchain](#42-zeige-den-status-der-blockchain) - - [4.3 Zeige Kontoinformationen mittels Passwort](#43-zeige-kontoinformationen-mittels-passwort) - - [4.4 Zeige Kontoinformationen anhand eines öffentlichen Schlüssels](#44-zeige-kontoinformationen-anhand-eines-%C3%B6ffentlichen-schl%C3%BCssels) - - [4.5 Zeige ein Kontosaldo anhand einer Kontoadresse](#45-zeige-ein-kontosaldo-anhand-einer-kontoadresse) - - [4.6 Zeige Kontoinformationen anhand einer Kontoadresse](#46-zeige-kontoinformationen-anhand-einer-kontoadresse) - - [4.7 Zeige alle Stimmabgaben für Delegate anhand einer öffentlichen Adresse](#47-zeige-alle-stimmabgaben-f%C3%BCr-delegate-anhand-einer-%C3%B6ffentlichen-adresse) - - [4.8 Zeige die Anzahl aller Delegate](#48-zeige-die-anzahl-aller-delegate) - - [4.9 Zeige Informationen zu Delegaten und sortiere nach bestimmten Feldern](#49-zeige-informationen-zu-delegaten-und-sortiere-nach-bestimmten-feldern) - - [4.10 Zeige die Knoten die für ein Delegat gestimmt haben, anhand des öffentlichen Schlüssels des Delegats](#410-zeige-die-knoten-die-f%C3%BCr-ein-delegat-gestimmt-haben-anhand-des-%C3%B6ffentlichen-schl%C3%BCssels-des-delegats) - - [4.11 Zeige die Informationen zu einem Delegat anhand seines öffentlichen Schlüssels an](#411-zeige-die-informationen-zu-einem-delegat-anhand-seines-%C3%B6ffentlichen-schl%C3%BCssels-an) - - [4.12 Zeige die Informationen zu einem Delegat anhand seines Namens](#412-zeige-die-informationen-zu-einem-delegat-anhand-seines-namens) - - [4.13 Zeige die Information zu einem oder mehreren Blöcken im Netzwerk an](#413-zeige-die-information-zu-einem-oder-mehreren-bl%C3%B6cken-im-netzwerk-an) - - [4.14 Überprüfe Blockinformationen mit einer BlockID](#414-%C3%9Cberpr%C3%BCfe-blockinformationen-mit-einer-blockid) - - [4.15 Zeige Informationen zu einem Block anhand der Blockhöhe](#415-zeige-informationen-zu-einem-block-anhand-der-blockh%C3%B6he) - - [4.16 Zeige den Netzwerkstatus / den Status der Peers an](#416-zeige-den-netzwerkstatus-den-status-der-peers-an) - - [4.17 Zeige unbestätigte Transaktionen anhand einer öffentlichen Adresse](#417-zeige-unbest%C3%A4tigte-transaktionen-anhand-einer-%C3%B6ffentlichen-adresse) - - [4.18 Zeige / analysiere Transaktionsinformationen für das gesamte Netzwerk](#418-zeige-analysiere-transaktionsinformationen-f%C3%BCr-das-gesamte-netzwerk) - - [4.19 Zeige Transaktionsdetails anhand einer Transaktions-ID](#419-zeige-transaktionsdetails-anhand-einer-transaktions-id) - - [4.20 Geld überweisen](#420-geld-%C3%BCberweisen) - - [4.21 Ein Delegat registrieren](#421-ein-delegat-registrieren) - - [4.22 Für ein Delegat abstimmen](#422-f%C3%BCr-ein-delegat-abstimmen) - - [4.23 Die Stimmabgabe für ein Delegat zurückziehen](#423-die-stimmabgabe-f%C3%BCr-ein-delegat-zur%C3%BCckziehen) - - [4.24 Ein zweites Passwort setzen](#424-ein-zweites-passwort-setzen) - - [4.25 Eine Dapp registrieren (dezentrale Applikation)](#425-eine-dapp-registrieren-dezentrale-applikation) - - [4.26 Verträge](#426-vertr%C3%A4ge) - - [4.27 Verschlüsselung](#427-verschl%C3%BCsselung) - - [4.28 Dapp Befehle](#428-dapp-befehle) - - [4.29 Erstelle den ersten Block der Blockchain (Genesisblock)](#429-erstelle-den-ersten-block-der-blockchain-genesisblock) - - [4.30 Überprüfe den Status aller Knoten / Peers im Netzwerk](#430-%C3%9Cberpr%C3%BCfe-den-status-aller-knoten-peers-im-netzwerk) - - [4.31 Überprüfe den Status aller Delegate](#431-%C3%9Cberpr%C3%BCfe-den-status-aller-delegate) - - [4.32 Zeige das Land aus dem ursprünglich die IP-Adresse des Knotens registriert wurde](#432-zeige-das-land-aus-dem-urspr%C3%BCnglich-die-ip-adresse-des-knotens-registriert-wurde) - -Inhaltsverzeichnis mittels [markdown-toc](https://github.com/AlanWalk/markdown-toc) erstellt ---- - -## 0 Asch-CLI Übersicht -Aus dem [Asch Whitepaper](/asch_whitepaper_de.md) -> Asch-CLI ist eine Asch Kommandozeile (CLI steht für command-line interface). Mit Hilfe der Asch-CLI können Entwickler ohne große Mühe eine Sidechain erstellen und auf dieser entwickeln. Das System bietet eine Vielzahl an APIs welche das Erstellen von intelligenten Verträgen (Smart Contracts) ermöglicht. Diese APIs umfassen die Möglichkeit für Konsens, Zufallszahlen, Datenbank-Zugriff, Kryptographie und vieles mehr. - -## 1 Asch-CLI Installation -- Installiere den node Paket-Manager **npm** `sudo apt-get install npm` - -- Installiere die Asch-CLI `npm install -g asch-cli` Hinweis: Wenn dein Standort China ist, versuche den folgenden Parameter um die Installation zu beschleunigen. `--registry=http://registry.npm.taobao.org` - - -## 2 Asch-CLI Zusammenfassung -`asch-cli [option] [command]` - -## 3 Asch-CLI Parameter -### 3.1 Zeige die Hilfsinformationen -**Parameter:** -h, --help -**Rückgabe:** Eine Übersicht über alle Parameter und Subparameter -**Verwendung:** - - ```asch-cli -h``` #zeige Asch-CLI Hilfsinformationen - - ```asch-cli [commands] -h``` #zeige Hilfsinformationen zu einem bestimmten Parameter - -**Beispiel:** -``` -root@asch:~# asch-cli -h #zeige die Hilfe an - Usage: asch-cli [options] [command] - Commands: - - getheight get block height - getblockstatus get block status - openaccount [secret] open your account and get the infomation by secret - openaccountbypublickey [publickey] open your account and get the infomation by publickey - getbalance [address] get balance by address - getaccount [address] get account by address - getvoteddelegates [options] [address] get delegates voted by address - getdelegatescount get delegates count - getdelegates [options] get delegates - getvoters [publicKey] get voters of a delegate by public key - getdelegatebypublickey [publicKey] get delegate by public key - getdelegatebyusername [username] get delegate by username - getblocks [options] get blocks - getblockbyid [id] get block by id - getblockbyheight [height] get block by height - getpeers [options] get peers - getunconfirmedtransactions [options] get unconfirmed transactions - gettransactions [options] get transactions - gettransaction [id] get transactions - sendmoney [options] send money to some address - registerdelegate [options] register delegate - upvote [options] vote for delegates - downvote [options] cancel vote for delegates - setsecondsecret [options] set second secret - registerdapp [options] register a dapp - contract [options] contract operations - crypto [options] crypto operations - dapps [options] manage your dapps - creategenesis [options] create genesis block - peerstat analyze block height of all peers - delegatestat analyze delegates status - ipstat analyze peer ip info - - Options: - - -h, --help output usage information - -V, --version output the version number - -H, --host Specify the hostname or ip of the node, default: 127.0.0.1 - -P, --port Specify the port of the node, default: 4096 - -M, --main Specify the mainnet, default: false - -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getvoteddelegates -h #print Asch-CLI command help information - Usage: getvoteddelegates [options] [address] - get delegates voted by address - Options: - - -h, --help output usage information - -o, --offset - -l, --limit -``` - -### 3.2 Zeige die Version der Asch-CLI -**Parameter:** -V, --version -**Rückgabe:** Die verwendete Version -**Verwendung:** `asch-cli -V` - -**Beispiel:** - -``` -root@asch:~# asch-cli -V -1.0.0 -``` - -### 3.3 Spezifiziere eine IP-Adresse oder einen Hostnamen für den Asch-Zielserver -**Parameter:** -H, --host <host> [command] *(Default: 127.0.0.1)* - -**Rückgabe:** keine - -**Verwendung:** `asch-cli -H 45.32.248.33 [command]` - -**Beispiel:** -``` -root@asch:~# asch-cli -H 45.32.248.33 getheight #zeige die Blockhöhe des Asch-Servers auf 45.32.248.33 -101236 -``` - -### 3.4 Spezifiziere eine Portnummer auf dem Asch-Zielserver -**Parameter:** -P, --port <port> [command] *(Default: 4096)* - -**Rückgabe:** keine - -**Verwendung:** ```asch-cli -P 4096``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getheight -102313 -``` - -### 3.5 Verwende die Haupt-Blockchain -**Parameter:** -M, --main *(Default: testchain)* - -**Rückgabe:** keine - -**Verwendung:** ```asch-cli -M``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -M -H *.*.*.105 -P 8192 getheight #zeige die Blockhöhe der Asch-Hauptblockchain -``` - -## 4 Asch-CLI unterstützte Parameter -### 4.1 Zeige die Höhe der Blockchain -**Befehl:** getheight - -**Rückgabe:** Die Höhe der Blockchain (die Anzahl der Blöcke seit dem Ursprungsblock) - -**Verwendung:** ```asch-cli getheight``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getheight -105387 -``` - -### 4.2 Zeige den Status der Blockchain -**Befehl:** getblockstatus - -**Rückgabe:** Ein JSON formattierter String der folgende Informationen beinhaltet: Blockchain-Höhe, die Transaktionsgebühr, den Milestone, die Belohnung für jedes Delegat und das gesamte Volumen - -**Verwendung:** ```asch-cli getblockstatus``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getblockstatus -{ - "success": true, - "height": 105392, - "fee": 10000000, - "milestone": 0, - "reward": 350000000, - "supply": 10036887200000000 -} -``` - -### 4.3 Zeige Kontoinformationen mittels Passwort -**Befehl:** openaccount [secret] - -**Rückgabe:** Ein JSON-String mit folgenden Konto-Informationen: Adresse, Saldo, öffentlicher Schlüssel, zweiter öffentlicher Schlüssel etc. - -**Verwendung:** ```asch-cli openaccount "password"``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 openaccount "fault still attack alley expand music basket purse later educate follow ride" -{ - "address": "16723473400748954103", - "unconfirmedBalance": 20000000000, - "balance": 20000000000, - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9", - "unconfirmedSignature": false, - "secondSignature": false, - "secondPublicKey": "", - "multisignatures": [], - "u_multisignatures": [] -} -``` - -### 4.4 Zeige Kontoinformationen anhand eines öffentlichen Schlüssels -**Befehl:** openaccountbypublickey [publickey] - -**Rückgabe:** Ein JSON-String mit folgenden Informationen: Adresse, Saldo, öffentlicher Schlüssel, zweiter öffentlicher Schlüssel etc. - -**Verwendung:** ```asch-cli openaccountbypublickey "public key"``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 openaccountbypublickey "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9" -{ - "address": "16723473400748954103", - "unconfirmedBalance": 20000000000, - "balance": 20000000000, - "unconfirmedSignature": false, - "secondSignature": false, - "secondPublicKey": "", - "multisignatures": [], - "u_multisignatures": [] -} -``` - -### 4.5 Zeige ein Kontosaldo anhand einer Kontoadresse -**Befehl:** getbalance [address] - -**Rückgabe:** Eine Ganzzahl welche durch das Dividieren von 100000000 zustande kommt. - -**Verwendung:** ```asch-cli getbalance [account address]``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getbalance 16723473400748954103 -20000000000 -``` - -### 4.6 Zeige Kontoinformationen anhand einer Kontoadresse -**Befehl:** getaccount [address] - -**Rückgabe:** Ein JSON-String mit folgenden Informationen: Addresse, Saldo, öffentlicher Schlüssel, zweiter öffentlicher Schlüssel etc. - -**Verwendung:** ```asch-cli getaccount [account address]``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getaccount 16723473400748954103 -{ - "address": "16723473400748954103", - "unconfirmedBalance": 20000000000, - "balance": 20000000000, - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9", - "unconfirmedSignature": false, - "secondSignature": false, - "secondPublicKey": "", - "multisignatures": [], - "u_multisignatures": [] -} -``` - -### 4.7 Zeige alle Stimmabgaben für Delegate anhand einer öffentlichen Adresse -**Befehl:** getvoteddelegates [options] [address] - -**Rückgabe:** Eine Liste von allen Stimmabgaben die eine Adresse abgegeben hat - -**Verwendung:** ```asch-cli getvoteddelegates [account address] -o offset -l [an integer that indicates the maximum delegates that can be printed]``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getvoteddelegates 15745540293890213312 -o 1 -l 2 -{ success: true, - delegates: - [ { username: 'wgl_002', - address: '14636456069025293113', - publicKey: 'ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7', - vote: 8902736443247261, - producedblocks: 1041, - missedblocks: 6, - rate: 1, - approval: '88.70', - productivity: '99.42' }, - { username: 'wgl_003', - address: '9961157415582672274', - publicKey: 'c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2', - vote: 8902736443247261, - producedblocks: 1043, - missedblocks: 8, - rate: 2, - approval: '88.70', - productivity: '99.23' }] -``` - -### 4.8 Zeige die Anzahl aller Delegate -**Befehl:** getdelegatescount - -**Rückgabe:** Eine Ganzzahl mit der Anzahl aller Delegate im System - -**Verwendung:** ```asch-cli getdelegatescount``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getdelegatescount -232 -``` - -### 4.9 Zeige Informationen zu Delegaten und sortiere nach bestimmten Feldern -**Befehl:** getdelegates [options] - -**Rückgabe:** Eine Liste mit Informationen zu Delegaten - -**Verwendung:** ```asch-cli getdelegates -o [offset number] -l [an integer that indicates the maximum delegates that can be printed] -s rate:asc``` - -**HINWEIS:** ```rate:asc``` bedeutet, dass man aufsteigend (asc=aufsteigend, desc=absteigend) nach Stimmabgaben sortieren kann. Um alle Sortieroptionen zu sehen tippe `asch-cli getdelegates -h` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getdelegates -o 1 -l 1 -s rate:asc -[ - { - "username": "wgl_003", - "address": "9961157415582672274", - "publicKey": "c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2", - "vote": 9901544836887660, - "producedblocks": 1044, - "missedblocks": 8, - "fees": 12150495022, - "rewards": 161000000000, - "rate": 2, - "approval": 98.65, - "productivity": 99.24, - "forged": "173150495022" - } -] -``` - -### 4.10 Zeige die Knoten die für ein Delegat gestimmt haben, anhand des öffentlichen Schlüssels des Delegats -**Befehl:** getvoters [publicKey] - -**Rückgabe:** Eine Liste mit allen Wählern - -**Verwendung:** ```asch-cli getvoters "delegate's public key"``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getvoters "ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7" -[ - { - "address": "2918354313445278349", - "publicKey": "4fde4c49f1297d5d3a24b1494204543c4281aff17917ff7ff8ff32da3b4b222f", - "balance": 1215522376203, - "weight": 0.012110398031994424 - }, - { - "address": "1523444724068322527", - "publicKey": "8a6a61c28dc47541aadf1eecec2175c8f768f2331eea3472b1593bf1aa4e1fb4", - "balance": 2109297623765, - "weight": 0.02101519008767971 - }] -``` - -### 4.11 Zeige die Informationen zu einem Delegat anhand seines öffentlichen Schlüssels an -**Befehl:** getdelegatebypublickey [publicKey] - -**Rückgabe:** Ein JSON-String mit folgenden Informationen zu einem Delegat: Name, Adresse, Wahlstimmen, produzierter Blöcke, forging reward etc. - -**Verwendung:** asch-cli getdelegatebypublickey "delegate's public key" - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getdelegatebypublickey "ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7" -{ - "username": "wgl_002", - "address": "14636456069025293113", - "publicKey": "ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7", - "vote": 9901546586887660, - "producedblocks": 1042, - "missedblocks": 6, - "fees": 12383762523, - "rewards": 161700000000, - "rate": 1, - "approval": 98.65, - "productivity": 99.43, - "forged": "174083762523" -} -``` -### 4.12 Zeige die Informationen zu einem Delegat anhand seines Namens -**Befehl:** getdelegatebyusername [username] - -**Rückgabe:** Ein JSON-String mit allen Details zu einem Delegat - -**Verwendung:** ```asch-cli getdelegatebyusername "delegate's name"``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getdelegatebyusername "wgl_002" -{ - "username": "wgl_002", - "address": "14636456069025293113", - "publicKey": "ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7", - "vote": 9901546586887660, - "producedblocks": 1042, - "missedblocks": 6, - "fees": 12383762523, - "rewards": 161700000000, - "rate": 1, - "approval": 98.65, - "productivity": 99.43, - "forged": "174083762523" -} -``` - -### 4.13 Zeige die Information zu einem oder mehreren Blöcken im Netzwerk an -**Befehl:** getblocks [options] - -**Rückgabe:** Ein JSON-String mit den gewünschten Blöcken - -**Verwendung:** ```asch-cli getblocks -o [offset number] -l [an integer that indicates the maximum return data] -r [reward amount] -f [fee] -a [total amount] -g [public key that generates blocks] -s [sort rule]``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getblocks -o 1 -l 1 -r 350000000 -{ - "success": true, - "blocks": [ - { - "id": "5533619110613125681", - "version": 0, - "timestamp": 3914630, - "height": 60481, - "previousBlock": "11174102253820291084", - "numberOfTransactions": 0, - "totalAmount": 0, - "totalFee": 0, - "reward": 350000000, - "payloadLength": 0, - "payloadHash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "generatorPublicKey": "68b28341605a24f6684df81882df1b13f421ec1cbba7d9aaa68f6c079705b258", - "generatorId": "10651956562526682705", - "blockSignature": "77115fdaab3215039bcf2bf8b3a461b3b7cafca7adae07e271a1a953ca6531a9e93f985bbec8544d596a568595661f1da742e20797b827d5b20aa75e8d80cc0b", - "confirmations": "45349", - "totalForged": 350000000 - } - ], - "count": 45350 -} -``` -### 4.14 Überprüfe Blockinformationen mit einer BlockID -**Befehl:** getblockbyid [id] - -**Rückgabe:** Ein JSON-String mit folgenden Feldern: BlockID, Blockhöhe, BlockID des vorhergehenden Blocks, Anzahl der Transaktionen, Gesamtbetrag, Transaktionsgebühr, Belohnungen, Hash, der öffentliche Schlüssel des Blockgenerators und dessen ID, Blocksignatur, Anzahl der Bestätigungen etc. - -**Verwendung:** ```asch-cli getblockbyid [block ID]``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getblockbyid 1425942128040906871 #zeige den Genesisblock an (erster Block in der Blockchain) -{ - "id": "1425942128040906871", - "version": 0, - "timestamp": 0, - "height": 1, - "previousBlock": "", - "numberOfTransactions": 103, - "totalAmount": 10000000000000000, - "totalFee": 0, - "reward": 0, - "payloadLength": 19417, - "payloadHash": "dd5cd3186d32145b01f8fd0bd23e3b3d72414b59b162d2e664e759db8fe60d46", - "generatorPublicKey": "2af8566f8555bafb25df5a50e2e22b91a8577ceabc05d47dbd921572d28330e8", - "generatorId": "1170992220085500484", - "blockSignature": "a8ed06bfbfd1b630b1628e97a5c7c9383337c4ce32825969fad830890e0af981312be635b775ff46eea4f739da043f668a70efd5a940429e39fe5063852f4a01", - "confirmations": "105901", - "totalForged": 0 -} -``` - -### 4.15 Zeige Informationen zu einem Block anhand der Blockhöhe -**Befehl:** getblockbyheight [height] - -**Rückgabe:** Ein JSON-String mit folgenden Feldern: BlockID, Blockhöhe, BlockID des vorhergehenden Blocks, Anzahl der Transaktionen, Gesamtbetrag, Transaktionsgebühren, Belohnungen, der öffentliche Schlüssel des Blockgenerators und dessen ID, Blocksignatur, Anzahl der Bestätigungen etc. - -**Verwendung:** ```asch-cli getblockbyheight [block height]``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getblockbyheight 1 -{ - "id": "1425942128040906871", - "version": 0, - "timestamp": 0, - "height": 1, - "previousBlock": "", - "numberOfTransactions": 103, - "totalAmount": 10000000000000000, - "totalFee": 0, - "reward": 0, - "payloadLength": 19417, - "payloadHash": "dd5cd3186d32145b01f8fd0bd23e3b3d72414b59b162d2e664e759db8fe60d46", - "generatorPublicKey": "2af8566f8555bafb25df5a50e2e22b91a8577ceabc05d47dbd921572d28330e8", - "generatorId": "1170992220085500484", - "blockSignature": "a8ed06bfbfd1b630b1628e97a5c7c9383337c4ce32825969fad830890e0af981312be635b775ff46eea4f739da043f668a70efd5a940429e39fe5063852f4a01", - "confirmations": "105922", - "totalForged": 0 -} -``` - -### 4.16 Zeige den Netzwerkstatus / den Status der Peers an -**Befehl:** getpeers [options] - -**Rückgabe:** Ein JSON-String mit folgenden Feldern: IP-Adresse des Peer-Computers, das verwendete Betriebssystem, die Asch-Version etc. - -**Verwendung:** ```asch-cli getpeers -o [offset] -l [an integer that indicates the maximum return data] -t [status value] -s [sort type] -v [version] -p [port number] --os [OS version]``` - -**HINWEIS:** Für weitere Informationen, tippe `asch-cli getpeers -h` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getpeers -o 1 -l 2 -[ - { - "ip": "45.32.62.184", - "port": 4096, - "state": 2, - "os": "linux3.13.0-87-generic", - "version": "1.0.0" - }, - { - "ip": "45.32.22.78", - "port": 4096, - "state": 2, - "os": "linux3.13.0-87-generic", - "version": "1.0.0" - } -] -``` - -### 4.17 Zeige unbestätigte Transaktionen anhand einer öffentlichen Adresse -**Befehl:** getunconfirmedtransactions [options] - -**Rückgabe:** Eine Liste mit sämtlichen Details zu allen noch unbestätigten Transaktionen - -**Verwendung:** ```asch-cli getunconfirmedtransactions -p "sender's public key" -a [recipient's address]``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getunconfirmedtransactions -k "d39d6f26869067473d685da742339d1a9117257fe14b3cc7261e3f2ed5a339e3" -[ - { - "type": 0, - "timestamp": 4385190, - "senderPublicKey": "d39d6f26869067473d685da742339d1a9117257fe14b3cc7261e3f2ed5a339e3", - "signature": "98d65df3109802c707eeed706e90a907f337bddab58cb4c1fbe6ec2179aa1c85ec2903cc0cf44bf0092926829aa5a0a6ec99458f65b6ebd11f0988772e58740e", - "recipientId": "16723473400748954103", - "senderId": "15745540293890213312", - "amount": 10000000000, - "fee": 10000000, - "signatures": [], - "id": "17192581936339156329", - "height": 0, - "asset": {} - } -] -``` - -### 4.18 Zeige / analysiere Transaktionsinformationen für das gesamte Netzwerk -**Befehl:** gettransactions [options] - -**Rückgabe:** Eine Liste mit allen Transaktionsdetails - -**Verwendung:** ```asch-cli gettransactions -b [block ID] -o [offset] -l [an integer that indicates the maximum return data]``` - -**HINWEIS:** Versuche `asch-cli gettransactions -h` um Informationen zu anderen Parameteroptionen anzuzeigen. - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 gettransactions -o 1 -l 2 #zeige die Information zu den ersten zwei Transaktionen in der Blockchain an -[ - { - "id": "10169086766604015960", - "height": "1", - "blockId": "1425942128040906871", - "type": 2, - "timestamp": 0, - "senderPublicKey": "991e0dda00d2c33ce68dd99471de8ebea7b58711f22a2e55236b8864c6d24c84", - "senderId": "3331250159865474723", - "recipientId": "", - "amount": 0, - "fee": 0, - "signature": "60bf38e7a3515aeaa2cac491f7737c94087f448a862099408b90c2cf96d3fe4f709e22e6471dd4e37aca111d8573beeb7b6cff4ef451633d9aaf74ab97ce8d02", - "signSignature": "", - "signatures": null, - "confirmations": "105988", - "asset": {} - }, - { - "id": "10375311635154792515", - "height": "1", - "blockId": "1425942128040906871", - "type": 2, - "timestamp": 0, - "senderPublicKey": "1674ae566c633cde3e01db8f04a02ea087081a270de2dd53e0e0b97c029106fb", - "senderId": "9948352853509008057", - "recipientId": "", - "amount": 0, - "fee": 0, - "signature": "f09c1693cc26c4028c642cb1711cf71c2dee090a50904d1590c74d865b2f5f3ba720ed792704f5379ec9c4a20b018c5e95f325ea179236777a28cddffe8c580d", - "signSignature": "", - "signatures": null, - "confirmations": "105988", - "asset": {} - } -] -``` - -### 4.19 Zeige Transaktionsdetails anhand einer Transaktions-ID -**Befehl:** gettransaction [id] - -**Rückgabe:** Ein JSON-String mit folgenden Feldern: Transaktions-ID, Blockhöhe, BlockID, Zeitstempel, Öffentliche Adresse des Versenders, Empfangsadresse, Gesamtbetrag, Signatur, Anzahl der Bestätigungen, Assets etc. - -**Verwendung:** ```asch-cli gettransaction [transactionID]``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 gettransaction 17192581936339156329 -{ - "id": "17192581936339156329", - "height": "105951", - "blockId": "15051364118100195665", - "type": 0, - "timestamp": 4385190, - "senderPublicKey": "d39d6f26869067473d685da742339d1a9117257fe14b3cc7261e3f2ed5a339e3", - "senderId": "15745540293890213312", - "recipientId": "16723473400748954103", - "amount": 10000000000, - "fee": 10000000, - "signature": "98d65df3109802c707eeed706e90a907f337bddab58cb4c1fbe6ec2179aa1c85ec2903cc0cf44bf0092926829aa5a0a6ec99458f65b6ebd11f0988772e58740e", - "signSignature": "", - "signatures": null, - "confirmations": "17", - "asset": {} -} -``` - -### 4.20 Geld überweisen -**Befehl:** sendmoney [option] - -**Rückgabe:** Bei erfolgreicher Ausführung wird "True" zurückgegeben, ansonsten kommt eine Fehlermeldung. - -**Verwendung:** ```asch-cli sendmoney -e "[sender's password]" -t [recipient's address] -a [transfer amount] -s "[second password]"``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 sendmoney -e "motion group blossom coral upper warrior pattern fragile sister misery palm admin" -t 16723473400748954103 -a 100 -true -``` - -### 4.21 Ein Delegat registrieren -**Befehl:** registerdelegate [options] - -**Rückgabe:** Bei erfolgreicher Ausführung wird "True" zurückgegeben, ansonsten kommt eine Fehlermeldung - -**Verwendung:** ```asch-cli registerdelegate -e "[password]" -s "[second password]" -u "[delegate's name]"``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 registerdelegate -e "fault still attack alley expand music basket purse later educate follow ride" -u "delegate_register" -true -``` - -### 4.22 Für ein Delegat abstimmen -**Befehl:** upvote [options] - -**Rückgabe:** Für ein Delegat abstimmen. Bei erfolgreicher Ausführung wird "True" zurückgegeben, ansonsten kommt eine Fehlermeldung - -**Verwendung:** ```asch-cli upvote -e "[password]" -s "[second password]" -p "delegate's public key"``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 upvote -e "fault still attack alley expand music basket purse later educate follow ride" -p "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9" -true -``` - -### 4.23 Die Stimmabgabe für ein Delegat zurückziehen -**Befehl:** downvote [options] - -**Rückgabe:** Die Stimmabgabe für ein Delegat zurückziehen. Bei einer erfolgrechen Ausführung wird "True" zurückgegeben, ansonsten kommt eine Fehlermeldung - -**Verwendung:** ```asch-cli downvote -e "[password]" -s "[second password]" -p "delegate's public key"``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 downvote -e "fault still attack alley expand music basket purse later educate follow ride" -p "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9" -true -``` - -### 4.24 Ein zweites Passwort setzen -**Befehl:** setsecondsecret [options] - -**Rückgabe:** Wenn erfolgreich ein zweites Passwort gesetz wurde kommt eine Bestätigung. Ansonsten kommt eine Fehlermeldung - -**Verwendung:** ```asch-cli setsecondsecret -e "[password]" -s "[second password]"``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 setsecondsecret -e "fault still attack alley expand music basket purse later educate follow ride" -s "ce shi er ji mi ma" -true -``` - -### 4.25 Eine Dapp registrieren (dezentrale Applikation) -**Befehl:** registerdapp [options] - -**Rückgabe:** keine - -**Verwendung:** ```asch-cli registerdapp -e "[password]" -s "[second password]" -f [Dapp meta file]``` - -**Beispiel:** - - - -### 4.26 Verträge -**Befehl:** contract [options] - -**Rückgabe:** keine - -**Verwendung:** - - ```asch-cli contract -a``` # einen Vertrag erstellen - - ```asch-cli contract -d``` # einen Vertrag löschen - -**Beispiel:** - - -### 4.27 Verschlüsselung -**Befehl:** crypto [option] - -**Rückgabe:** Eine Liste - -**Verwendung:** -- ```asch-cli -p``` # Erzeuge einen öffentlichen Schlüssel anhand eines Passworts -- ```asch-cli -g``` # Erstelle ein oder mehrere Konten - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 crypto -g -? Enter number of accounts to generate 1 -[ { address: '16723473400748954103', - secret: 'fault still attack alley expand music basket purse later educate follow ride', - publicKey: 'bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9' } ] -Done -``` - -### 4.28 Dapp Befehle -**Befehl:** dapps [options] - -**Rückgabe:** keine - -**Verwendung:** ```asch-cli dapps -a``` - -**Beispiel:** - -### 4.29 Erstelle den ersten Block der Blockchain (Genesisblock) -**Befehl:** creategenesis [options] - -**Rückgabe:** Dieser Befehl erzeugt eine Genesisblock-Datei (genesisBlock.json) und die zugehörige Logdatei (genGenesisBlock.log) im aktuellen Verzeichnis - -**Verwendung:** ```asch-cli creategenesis``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 creategenesis -root@asch:~# more genesisBlock.json -{ - "version": 0, - "totalAmount": 10000000000000000, - "totalFee": 0, - "reward": 0, - "payloadHash": "baebdb59d0c19a07c2440e22c0512b4efe9794565b352375195c9e7e8a3817b0", - "timestamp": 0, - "numberOfTransactions": 103, -... -} -``` - -### 4.30 Überprüfe den Status aller Knoten / Peers im Netzwerk -**Befehl:** peerstat - -**Rückgabe:** Informationen zu den einzelnen Peers wie: Die IP-Adresse, Port, Asch-Version, die Block-Höhe etc. - -**Verwendung:** ```asch-cli peerstat``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 peerstat -45.32.248.33:4096 1.0.0 106036 -45.32.62.184:4096 1.0.0 106036 -45.32.19.241:4096 1.0.0 106036 -``` - -### 4.31 Überprüfe den Status aller Delegate -**Befehl:** delegatestat - -**Rückgabe:** Eine Tabelle mit folgenden Informationen über alle Delegate: Name, Adresse, Zustimmung, Produktivität, Anzahl der generierten Blöcke, Blockhöhe, BlockID, Datum des zuletzt generierten Blocks, etc. - -**Verwendung:** ```asch-cli delegatestat``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 delegatestat -name address rate approval productivity produced height id time -nayimoliuguang 3331976396377269399 93 88.36% 98.39% 1037 105618 12962348710289833740 2016/08/17 21:07:20(1 hour ago) -jack 3705405381126069457 86 88.36% 99.41% 506 105628 5876778147855073736 2016/08/17 21:09:00(1 hour ago) -node_3 12796761013870716784 81 88.36% 80.51% 814 105784 4575518649204137595 2016/08/17 21:38:10(40 mins ago) -wgl_003 9961157415582672274 2 98.65% 99.24% 1047 105852 11175724889329116017 2016/08/17 21:49:40(28 mins ago) -xihulongjing 12676662200687508271 59 88.36% 76.92% 150 105853 15273855606472618453 2016/08/17 21:49:50(28 mins ago) -liangpeili 4514546945474752928 50 88.37% 99.68% 627 105855 3771943180359756069 2016/08/17 21:50:10(28 mins ago) -asch_tea1 8812460086240160222 4 98.58% 98.79% 1059 105857 14968719538781965695 2016/08/17 21:50:30(27 mins ago) -intmaster 7321911740133937168 97 88.36% 100% 1032 105871 6757656887343300317 2016/08/17 21:52:50(25 mins ago) -mode_6 9248745407080572308 8 88.48% 100% 1060 105873 3777454410915098884 2016/08/17 21:53:10(25 mins ago) -``` - -### 4.32 Zeige das Land aus dem ursprünglich die IP-Adresse des Knotens registriert wurde -**Befehl:** ipstat - -**Rückgabe:** Das ursprüngliche Land aus dem die IP-Adresse stammte - -**Verwendung:** ```asch-cli ipstat``` - -**Beispiel:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 ipstat -美国 US -美国 US -美国 US -日本 JP -中国 CN -中国 CN -中国 CN -中国 CN -中国 CN -中国 CN -``` diff --git a/docs/asch_cli_usage_en.md b/docs/asch_cli_usage_en.md deleted file mode 100644 index d48a6ff..0000000 --- a/docs/asch_cli_usage_en.md +++ /dev/null @@ -1,907 +0,0 @@ -# Asch-CLI User Guide ---- -Index -================= - - [Asch-CLI Instruction](#asch-cli-instruction) - - [0 Asch-CLI Overview](#0-asch-cli-overview) - - [1 Asch-CLI Installation](#1-asch-cli-installation) - - [2 Asch-CLI Synopsis](#2-asch-cli-synopsis) - - [3 Asch-CLI Option Description](#3-asch-cli-option-description) - - [3.1 Print help information](#31-print-help-information) - - [3.2 Print Asch-CLI version information](#32-print-asch-cli-version-information) - - [3.3 Appoint the host name or IP address of target Asch Server](#33-appoint-the-host-name-or-ip-address-of-target-asch-server) - - [3.4 Appoint the port number of target Asch server](#34-appoint-the-port-number-of-target-asch-server) - - [3.5 Appoint the main chain](#35-appoint-the-main-chain) - - [4 Asch-CLI supported commands](#4-asch-cli-supported-commands) - - [4.1 Check the blockchain height](#41-check-the-blockchain-height) - - [4.2 Check the blockchain status](#42-check-the-blockchain-status) - - [4.3 Check account information by password](#43-check-account-information-by-password) - - [4.4 Check account information by public key](#44-check-account-information-by-public-key) - - [4.5 Check account balance by account address](##45-check-account-balance-by-account-address) - - [4.6 Check account information by account address](#46-check-account-information-by-account-address) - - [4.7 Check delegates voted by the account address](#47-check-delegates-voted-by-the-account-address) - - [4.8 Check the whole number of delegates](#48-check-the-whole-number-of-delegates) - - [4.9 Check delegates information and sort out](#49-check-delegates-information-and-sort-out) - - [4.10 Check the voters of the delegate by his public key](#410-check-the-voters-of-the-delegate-by-his-public-key) - - [4.11 Check detail information of delegate by public key](#411-check-detail-information-of-delegate-by-public-key) - - [4.12 Check the detail information of delegate by the name](#412-check-the-detail-information-of-delegate-by-the-name) - - [4.13 Check/analyse block information in whole network](#413-checkanalyze-block-information-in-whole-network) - - [4.14 Check block information by block ID](#414-check-block-information-by-block-id) - - [4.15 Check block information by block height](#415-check-block-information-by-block-height) - - [4.16 Check the peer/node status](#416-check-the-peernode-status) - - [4.17 Check unconfirmed transaction by public key](#417-check-unconfirmed-transaction-by-public-key) - - [4.18 Check/analyse transaction information in the whole network](#418-checkanalyse-transaction-information-in-the-whole-network) - - [4.19 Check transaction detail inforamtion by transaction ID](#419-check-transaction-detail-inforamtion-by-transaction-id) - - [4.20 Transfer money](#420-transfer-money) - - [4.21 Register delegate](#421-register-delegate) - - [4.22 Vote for delegate](#422-vote-for-delegate) - - [4.23 Cancel the vote for delegate](#423-cancel-the-vote-for-delegate) - - [4.24 Set second password (secret)](#424-set-second-password-secret) - - [4.25 Register Dapp (decentralized application)](#425-register-dapp-decentralized-application) - - [4.26 Contract related command](#426-contract-related-command) - - [4.27 Encrypt related command](#427-encrypt-related-command) - - [4.28 Dapp related command](#428-dapp-related-command) - - [4.29 Create genesis block file](#429-create-genesis-block-file) - - [4.30 Check the status of all nodes/peers of the whole network](#430-check-the-status-of-all-nodespeers-of-the-whole-network) - - [4.31 Check delegates' status in the whole network](#431-check-delegates-status-in-the-whole-network) - - [4.32 Check the original place of all nodes/peers' IP address in the whole network](#432-check-the-original-place-of-all-nodespeers-ip-address-in-the-whole-network) - -Index created with [markdown-toc](https://github.com/AlanWalk/markdown-toc) ---- - -## 0 Asch-CLI Overview -From [Asch Whitepaper](/asch_whitepaper_en.md) -> Asch-CLI is a command line interface provided by Asch system. Within the Asch-CLI, developers can rapidly establish a sidechain by making some simple configurations according to instructions and then create any kind of applications on this sidechain. The system also provides a series of APIs to help developers to create complicate smart contract applications. The functions of these APIs include consensus, strong random numbers, database, and cryptology and so on. - -## 1 Asch-CLI Installation -- Install nodejs package manager **npm** -`sudo apt-get install npm` - -- Install Asch-CLI -`npm install -g asch-cli` -NOTICE: if you install it in China, try parameter `--registry=http://registry.npm.taobao.org` to accelerate the installation. - -## 2 Asch-CLI Synopsis -`asch-cli [option] [command]` - -## 3 Asch-CLI Option Description -### 3.1 Print help information -**Parameter:** -h, --help -**Return:** Help document of Asch-CLI commands or sub-commands -**Usage:** - - asch-cli -h #print help information of asch-cli itself - - asch-cli [commands] -h #print help information of Asch-CLI command - -**Examples:** -``` -root@asch:~# asch-cli -h #print asch-cli help information - Usage: asch-cli [options] [command] - Commands: - - getheight get block height - getblockstatus get block status - openaccount [secret] open your account and get the infomation by secret - openaccountbypublickey [publickey] open your account and get the infomation by publickey - getbalance [address] get balance by address - getaccount [address] get account by address - getvoteddelegates [options] [address] get delegates voted by address - getdelegatescount get delegates count - getdelegates [options] get delegates - getvoters [publicKey] get voters of a delegate by public key - getdelegatebypublickey [publicKey] get delegate by public key - getdelegatebyusername [username] get delegate by username - getblocks [options] get blocks - getblockbyid [id] get block by id - getblockbyheight [height] get block by height - getpeers [options] get peers - getunconfirmedtransactions [options] get unconfirmed transactions - gettransactions [options] get transactions - gettransaction [id] get transactions - sendmoney [options] send money to some address - registerdelegate [options] register delegate - upvote [options] vote for delegates - downvote [options] cancel vote for delegates - setsecondsecret [options] set second secret - registerdapp [options] register a dapp - contract [options] contract operations - crypto [options] crypto operations - dapps [options] manage your dapps - creategenesis [options] create genesis block - peerstat analyze block height of all peers - delegatestat analyze delegates status - ipstat analyze peer ip info - - Options: - - -h, --help output usage information - -V, --version output the version number - -H, --host Specify the hostname or ip of the node, default: 127.0.0.1 - -P, --port Specify the port of the node, default: 4096 - -M, --main Specify the mainnet, default: false - -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getvoteddelegates -h #print Asch-CLI command help information - Usage: getvoteddelegates [options] [address] - get delegates voted by address - Options: - - -h, --help output usage information - -o, --offset - -l, --limit -``` - -### 3.2 Print Asch-CLI version information -**Parameter:** -V, --version -**Return:** Output the version information -**Usage:** `asch-cli -V` - -**Example:** - -``` -root@asch:~# asch-cli -V -1.0.0 -``` - -### 3.3 Appoint the host name or IP address of target Asch Server -**Parameter:** -H, --host <host> [command] *(Default: 127.0.0.1)* - -**Return:** none - -**Usage:** `asch-cli -H 45.32.248.33 [command]` - -**Example:** -``` -root@asch:~# asch-cli -H 45.32.248.33 getheight #check block height of Asch server whose IP is 45.32.248.33 -101236 -``` - -### 3.4 Appoint the port number of target Asch server -**Parameter:** -P, --port <port> [command] *(Default: 4096)* - -**Return:** none - -**Usage:** asch-cli -P 4096 - -**Example:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getheight -102313 -``` - -### 3.5 Appoint the main chain -**Parameter:** -M, --main *(Default: test chain)* - -**Return:** none - -**Usage:** asch-cli -M - -**Example:** - -``` -root@asch:~# asch-cli -M -H *.*.*.105 -P 8192 getheight #check the block height of Asch main chain -9388 -``` - -## 4 Asch-CLI supported commands -### 4.1 Check the blockchain height -**Command:** getheight - -**Return:** blockchain height - -**Usage:** asch-cli getheight - -**Example:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getheight -105387 -``` - -### 4.2 Check the blockchain status -**Command:** getblockstatus - -**Return:** a JSON format string including blockchain height, transaction fee, milestone, the reward of each delegate's block and the whole current volume - -**Usage:** asch-cli getblockstatus - -**Example:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getblockstatus -{ - "success": true, - "height": 105392, - "fee": 10000000, - "milestone": 0, - "reward": 350000000, - "supply": 10036887200000000 -} -``` - -### 4.3 Check account information by password -**Command:** openaccount [secret] - -**Return:** A JSON string containing account information such as address, balance, public key, and second public key and so on. - -**Usage:**asch-cli openaccount "password" - -**Example:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 openaccount "fault still attack alley expand music basket purse later educate follow ride" -{ - "address": "16723473400748954103", - "unconfirmedBalance": 20000000000, - "balance": 20000000000, - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9", - "unconfirmedSignature": false, - "secondSignature": false, - "secondPublicKey": "", - "multisignatures": [], - "u_multisignatures": [] -} -``` - -### 4.4 Check account information by public key -**Command:** openaccountbypublickey [publickey] - -**Return:** A JSON string containing account information such as address, balance, public key, and second public key and so on. - -**Usage:** asch-cli openaccountbypublickey "public key" - -**Example:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 openaccountbypublickey "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9" -{ - "address": "16723473400748954103", - "unconfirmedBalance": 20000000000, - "balance": 20000000000, - "unconfirmedSignature": false, - "secondSignature": false, - "secondPublicKey": "", - "multisignatures": [], - "u_multisignatures": [] -} -``` - -### 4.5 Check account balance by account address -**Command:** getbalance [address] - -**Return:** A integer number that will be the account balance when divided by 100000000 - -**Usage:** asch-cli getbalance [account address] - -**Example:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getbalance 16723473400748954103 -20000000000 -``` - -### 4.6 Check account information by account address -**Command:** getaccount [address] - -**Return:** A JSON string containing account information such as address, balance, public key, and second public key and so on. - -**Usage:** asch-cli getaccount [account address] - -**Example:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getaccount 16723473400748954103 -{ - "address": "16723473400748954103", - "unconfirmedBalance": 20000000000, - "balance": 20000000000, - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9", - "unconfirmedSignature": false, - "secondSignature": false, - "secondPublicKey": "", - "multisignatures": [], - "u_multisignatures": [] -} -``` - -### 4.7 Check delegates voted by the account address -**Command:** getvoteddelegates [options] [address] - -**Return:** A list containing the delegates voted by this account - -**Usage:**asch-cli getvoteddelegates [account address] -o offset -l [a number indicates maximum delegates that can be printed] - -**Example:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getvoteddelegates 15745540293890213312 -o 1 -l 2 -{ success: true, - delegates: - [ { username: 'wgl_002', - address: '14636456069025293113', - publicKey: 'ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7', - vote: 8902736443247261, - producedblocks: 1041, - missedblocks: 6, - rate: 1, - approval: '88.70', - productivity: '99.42' }, - { username: 'wgl_003', - address: '9961157415582672274', - publicKey: 'c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2', - vote: 8902736443247261, - producedblocks: 1043, - missedblocks: 8, - rate: 2, - approval: '88.70', - productivity: '99.23' }] -``` - -### 4.8 Check the whole number of delegates -**Command:** getdelegatescount - -**Return:** An integer number indicates the count of all delegates - -**Usage:** asch-cli getdelegatescount - -**Example:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getdelegatescount -232 -``` - -### 4.9 Check delegates information and sort out -**Command:**getdelegates [options] - -**Return:** A list containing all delegates' information - -**Usage:** asch-cli getdelegates -o [offset number] -l [a number indicates maximum delegates that can be printed] -s rate:asc - -**NOTICE:** rate:asc means ascending sort according to votes. Check other sort types with `asch-cli getdelegates -h` - -**Example:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 getdelegates -o 1 -l 1 -s rate:asc -[ - { - "username": "wgl_003", - "address": "9961157415582672274", - "publicKey": "c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2", - "vote": 9901544836887660, - "producedblocks": 1044, - "missedblocks": 8, - "fees": 12150495022, - "rewards": 161000000000, - "rate": 2, - "approval": 98.65, - "productivity": 99.24, - "forged": "173150495022" - } -] -``` - -### 4.10 Check the voters of the delegate by his public key -**Command:** getvoters [publicKey] - -**Return:** A list containing all the voters - -**Usage:**asch-cli getvoters "delegate's public key" - -**Example:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getvoters "ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7" -[ - { - "address": "2918354313445278349", - "publicKey": "4fde4c49f1297d5d3a24b1494204543c4281aff17917ff7ff8ff32da3b4b222f", - "balance": 1215522376203, - "weight": 0.012110398031994424 - }, - { - "address": "1523444724068322527", - "publicKey": "8a6a61c28dc47541aadf1eecec2175c8f768f2331eea3472b1593bf1aa4e1fb4", - "balance": 2109297623765, - "weight": 0.02101519008767971 - }] -``` - -### 4.11 Check detail information of delegate by public key -**Command:** getdelegatebypublickey [publicKey] - -**Return:** A JSON string containing delegate's detail information such as name, address, votes, produced blocks, and forging reward and so on. - -**Usage:** asch-cli getdelegatebypublickey "delegate's public key" - -**Example:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getdelegatebypublickey "ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7" -{ - "username": "wgl_002", - "address": "14636456069025293113", - "publicKey": "ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7", - "vote": 9901546586887660, - "producedblocks": 1042, - "missedblocks": 6, - "fees": 12383762523, - "rewards": 161700000000, - "rate": 1, - "approval": 98.65, - "productivity": 99.43, - "forged": "174083762523" -} -``` -### 4.12 Check the detail information of delegate by the name -**Command:** getdelegatebyusername [username] - -**Return:** A JSON string containing delegate's detail - -**Usage:** asch-cli getdelegatebyusername "delegate's name" - -**Example:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getdelegatebyusername "wgl_002" -{ - "username": "wgl_002", - "address": "14636456069025293113", - "publicKey": "ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7", - "vote": 9901546586887660, - "producedblocks": 1042, - "missedblocks": 6, - "fees": 12383762523, - "rewards": 161700000000, - "rate": 1, - "approval": 98.65, - "productivity": 99.43, - "forged": "174083762523" -} -``` - -### 4.13 Check/analyse block information in whole network -**Command:** getblocks [options] - -**Return:** A JSON string containing query result status and queried block information - -**Usage:** asch-cli getblocks -o [offset number] -l [an integer that indicate maximum return data] -r [reward amount] -f [fee] -a [total amount] -g [public key that generates blocks] -s [sort rule] - -**Example:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getblocks -o 1 -l 1 -r 350000000 -{ - "success": true, - "blocks": [ - { - "id": "5533619110613125681", - "version": 0, - "timestamp": 3914630, - "height": 60481, - "previousBlock": "11174102253820291084", - "numberOfTransactions": 0, - "totalAmount": 0, - "totalFee": 0, - "reward": 350000000, - "payloadLength": 0, - "payloadHash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "generatorPublicKey": "68b28341605a24f6684df81882df1b13f421ec1cbba7d9aaa68f6c079705b258", - "generatorId": "10651956562526682705", - "blockSignature": "77115fdaab3215039bcf2bf8b3a461b3b7cafca7adae07e271a1a953ca6531a9e93f985bbec8544d596a568595661f1da742e20797b827d5b20aa75e8d80cc0b", - "confirmations": "45349", - "totalForged": 350000000 - } - ], - "count": 45350 -} -``` -### 4.14 Check block information by block ID -**Command:** getblockbyid [id] - -**Return:** A JSON string containing block ID, block height, previous block ID, total transaction number, total amount, transaction fee, reward, hash, block generator public key and ID, block signature, quantity of confirmation and so on. -**Usage:**asch-cli getblockbyid [block ID] - -**Example:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getblockbyid 1425942128040906871 #check the genesis block -{ - "id": "1425942128040906871", - "version": 0, - "timestamp": 0, - "height": 1, - "previousBlock": "", - "numberOfTransactions": 103, - "totalAmount": 10000000000000000, - "totalFee": 0, - "reward": 0, - "payloadLength": 19417, - "payloadHash": "dd5cd3186d32145b01f8fd0bd23e3b3d72414b59b162d2e664e759db8fe60d46", - "generatorPublicKey": "2af8566f8555bafb25df5a50e2e22b91a8577ceabc05d47dbd921572d28330e8", - "generatorId": "1170992220085500484", - "blockSignature": "a8ed06bfbfd1b630b1628e97a5c7c9383337c4ce32825969fad830890e0af981312be635b775ff46eea4f739da043f668a70efd5a940429e39fe5063852f4a01", - "confirmations": "105901", - "totalForged": 0 -} -``` - -### 4.15 Check block information by block height -**Command:** getblockbyheight [height] - -**Return:** A JSON string containing block ID, block height, previous block ID, total transaction number, total amount, transaction fee, reward, hash, block generator public key and ID, block signature, quantity of confirmation and so on. - -**Usage:**asch-cli getblockbyheight [block height] - -**Example:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getblockbyheight 1 -{ - "id": "1425942128040906871", - "version": 0, - "timestamp": 0, - "height": 1, - "previousBlock": "", - "numberOfTransactions": 103, - "totalAmount": 10000000000000000, - "totalFee": 0, - "reward": 0, - "payloadLength": 19417, - "payloadHash": "dd5cd3186d32145b01f8fd0bd23e3b3d72414b59b162d2e664e759db8fe60d46", - "generatorPublicKey": "2af8566f8555bafb25df5a50e2e22b91a8577ceabc05d47dbd921572d28330e8", - "generatorId": "1170992220085500484", - "blockSignature": "a8ed06bfbfd1b630b1628e97a5c7c9383337c4ce32825969fad830890e0af981312be635b775ff46eea4f739da043f668a70efd5a940429e39fe5063852f4a01", - "confirmations": "105922", - "totalForged": 0 -} -``` - -### 4.16 Check the peer/node status -**Command:** getpeers [options] - -**Return:** A list containing peer ip, port, operation system, and Asch version, and so on. - -**Usage:**asch-cli getpeers -o [offset] -l [an integer that indicate maximum return data] -t [status value] -s [sort type] -v [version] -p [port number] --os [OS version] - -**NOTICE:** For further information, try `asch-cli getpeers -h` - -**Example:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getpeers -o 1 -l 2 -[ - { - "ip": "45.32.62.184", - "port": 4096, - "state": 2, - "os": "linux3.13.0-87-generic", - "version": "1.0.0" - }, - { - "ip": "45.32.22.78", - "port": 4096, - "state": 2, - "os": "linux3.13.0-87-generic", - "version": "1.0.0" - } -] -``` - -### 4.17 Check unconfirmed transaction by public key -**Command:** getunconfirmedtransactions [options] - -**Return:** A list containing details of all transactions that are not confirmed yet - -**Usage:** asch-cli getunconfirmedtransactions -p "sender's public key" -a [recipient's address] - -**Example:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 getunconfirmedtransactions -k "d39d6f26869067473d685da742339d1a9117257fe14b3cc7261e3f2ed5a339e3" -[ - { - "type": 0, - "timestamp": 4385190, - "senderPublicKey": "d39d6f26869067473d685da742339d1a9117257fe14b3cc7261e3f2ed5a339e3", - "signature": "98d65df3109802c707eeed706e90a907f337bddab58cb4c1fbe6ec2179aa1c85ec2903cc0cf44bf0092926829aa5a0a6ec99458f65b6ebd11f0988772e58740e", - "recipientId": "16723473400748954103", - "senderId": "15745540293890213312", - "amount": 10000000000, - "fee": 10000000, - "signatures": [], - "id": "17192581936339156329", - "height": 0, - "asset": {} - } -] -``` - -### 4.18 Check/analyse transaction information in the whole network -**Command:** gettransactions [options] - -**Return:** A list containing all selected transaction's detail information - -**Usage:** asch-cli gettransactions -b [block ID] -o [offset] -l [an integer that indicate maximum return data] - -**NOTICE:** try `asch-cli gettransactions -h` to get the information for other parameters. - -**Example:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 gettransactions -o 1 -l 2 #check the first two transactions' information in the whole network -[ - { - "id": "10169086766604015960", - "height": "1", - "blockId": "1425942128040906871", - "type": 2, - "timestamp": 0, - "senderPublicKey": "991e0dda00d2c33ce68dd99471de8ebea7b58711f22a2e55236b8864c6d24c84", - "senderId": "3331250159865474723", - "recipientId": "", - "amount": 0, - "fee": 0, - "signature": "60bf38e7a3515aeaa2cac491f7737c94087f448a862099408b90c2cf96d3fe4f709e22e6471dd4e37aca111d8573beeb7b6cff4ef451633d9aaf74ab97ce8d02", - "signSignature": "", - "signatures": null, - "confirmations": "105988", - "asset": {} - }, - { - "id": "10375311635154792515", - "height": "1", - "blockId": "1425942128040906871", - "type": 2, - "timestamp": 0, - "senderPublicKey": "1674ae566c633cde3e01db8f04a02ea087081a270de2dd53e0e0b97c029106fb", - "senderId": "9948352853509008057", - "recipientId": "", - "amount": 0, - "fee": 0, - "signature": "f09c1693cc26c4028c642cb1711cf71c2dee090a50904d1590c74d865b2f5f3ba720ed792704f5379ec9c4a20b018c5e95f325ea179236777a28cddffe8c580d", - "signSignature": "", - "signatures": null, - "confirmations": "105988", - "asset": {} - } -] -``` - -### 4.19 Check transaction detail inforamtion by transaction ID -**Command:** gettransaction [id] - -**Return:** A JSON string containing transaction ID, block height, block ID, time stamp, sender's public key, recipient's address, total amount, fee, signature, confirmation quantity, assets, and etc. - -**Usage:**asch-cli gettransaction [transactionID] - -**Example:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 gettransaction 17192581936339156329 -{ - "id": "17192581936339156329", - "height": "105951", - "blockId": "15051364118100195665", - "type": 0, - "timestamp": 4385190, - "senderPublicKey": "d39d6f26869067473d685da742339d1a9117257fe14b3cc7261e3f2ed5a339e3", - "senderId": "15745540293890213312", - "recipientId": "16723473400748954103", - "amount": 10000000000, - "fee": 10000000, - "signature": "98d65df3109802c707eeed706e90a907f337bddab58cb4c1fbe6ec2179aa1c85ec2903cc0cf44bf0092926829aa5a0a6ec99458f65b6ebd11f0988772e58740e", - "signSignature": "", - "signatures": null, - "confirmations": "17", - "asset": {} -} -``` - -### 4.20 Transfer money -**Command:** sendmoney [option] - -**Return:** transaction result. true=success, otherwise error message - -**Usage:** asch-cli sendmoney -e "[sender's password]" -t [recipient's address] -a [transfer amount] [-s "second password"] - -**Example:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 sendmoney -e "motion group blossom coral upper warrior pattern fragile sister misery palm admin" -t 16723473400748954103 -a 100 -true -``` - -### 4.21 Register delegate -**Command:** registerdelegate [options] - -**Return:** Registering result,ture=success, otherwise error message - -**Usage:** asch-cli registerdelegate -e "[password]" -s "[second password]" -u "[delegate's name]" - -**Example:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 registerdelegate -e "fault still attack alley expand music basket purse later educate follow ride" -u "delegate_register" -true -``` - -### 4.22 Vote for delegate -**Command:** upvote [options] - -**Return:** Voting result, ture=success, otherwise error message - -**Usage:** asch-cli upvote -e "[password]" -s "[second password]" -p "delegate's public key" - -**Example:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 upvote -e "fault still attack alley expand music basket purse later educate follow ride" -p "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9" -true -``` - -### 4.23 Cancel the vote for delegate -**Command:**downvote [options] - -**Return:** Cancelling vote result, ture=success, otherwise error message - -**Usage:** asch-cli downvote -e "[password]" -s "[second password]" -p "delegate's public key" - -**Example:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 downvote -e "fault still attack alley expand music basket purse later educate follow ride" -p "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9" -true -``` - -### 4.24 Set second password (secret) -**Command:** setsecondsecret [options] - -**Return:** Setting up result, ture=success, otherwise error message - -**Usage:** asch-cli setsecondsecret -e "[password]" -s "[second password]" - -**Example:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 setsecondsecret -e "fault still attack alley expand music basket purse later educate follow ride" -s "ce shi er ji mi ma" -true -``` - -### 4.25 Register Dapp (decentralized application) -**Command:** registerdapp [options] - -**Return:** - -**Usage:** asch-cli registerdapp -e "[password]" -s "[second password]" -f [Dapp meta file] - -**Example:** - - - -### 4.26 Contract related command -**Command:** contract [options] - -**Return:** - -**Usage:** - - asch-cli contract -a # create a contract - - asch-cli contract -d # delete a contract - -**Example:** - - -###4.27 Encrypt related command -**Command:** crypto [option] - -**Return:** A list - -**Usage:** -- asch-cli -p # generate public key according to password -- asch-cli -g # create one or more new account - -**Example:** - -``` -root@asch:~# asch-cli -H 45.32.248.33 -P 4096 crypto -g -? Enter number of accounts to generate 1 -[ { address: '16723473400748954103', - secret: 'fault still attack alley expand music basket purse later educate follow ride', - publicKey: 'bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9' } ] -Done -``` - -### 4.28 Dapp related command -**Command:** dapps [options] - -**Return:** - -**Usage:** asch-cli dapps -a - -**Example:** - -###4.29 Create genesis block file -**Command:** creategenesis [options] - -**Return:** to create a genesis block file (genesisBlock.json) and log file (genGenesisBlock.log) in the current folder - -**Usage:** asch-cli creategenesis - -**Example:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 creategenesis -root@asch:~# more genesisBlock.json -{ - "version": 0, - "totalAmount": 10000000000000000, - "totalFee": 0, - "reward": 0, - "payloadHash": "baebdb59d0c19a07c2440e22c0512b4efe9794565b352375195c9e7e8a3817b0", - "timestamp": 0, - "numberOfTransactions": 103, -... -} -``` - -### 4.30 Check the status of all nodes/peers of the whole network -**Command:** peerstat - -**Return:** The peer's information, containing peer IP address, port, version and block height and etc. - -**Usage:**asch-cli peerstat - -**Example:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 peerstat -45.32.248.33:4096 1.0.0 106036 -45.32.62.184:4096 1.0.0 106036 -45.32.19.241:4096 1.0.0 106036 -``` - -### 4.31 Check delegates' status in the whole network -**Command:** delegatestat - -**Return:** Delegates' information, containing delegates' name, address, approval votes, productivity, the amount of generated blocks, block height, ID, and the time of last block generated and so on. - -**Usage:** asch-cli delegatestat - -**Example:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 delegatestat -name address rate approval productivity produced height id time -nayimoliuguang 3331976396377269399 93 88.36% 98.39% 1037 105618 12962348710289833740 2016/08/17 21:07:20(1 hour ago) -jack 3705405381126069457 86 88.36% 99.41% 506 105628 5876778147855073736 2016/08/17 21:09:00(1 hour ago) -node_3 12796761013870716784 81 88.36% 80.51% 814 105784 4575518649204137595 2016/08/17 21:38:10(40 mins ago) -wgl_003 9961157415582672274 2 98.65% 99.24% 1047 105852 11175724889329116017 2016/08/17 21:49:40(28 mins ago) -xihulongjing 12676662200687508271 59 88.36% 76.92% 150 105853 15273855606472618453 2016/08/17 21:49:50(28 mins ago) -liangpeili 4514546945474752928 50 88.37% 99.68% 627 105855 3771943180359756069 2016/08/17 21:50:10(28 mins ago) -asch_tea1 8812460086240160222 4 98.58% 98.79% 1059 105857 14968719538781965695 2016/08/17 21:50:30(27 mins ago) -intmaster 7321911740133937168 97 88.36% 100% 1032 105871 6757656887343300317 2016/08/17 21:52:50(25 mins ago) -mode_6 9248745407080572308 8 88.48% 100% 1060 105873 3777454410915098884 2016/08/17 21:53:10(25 mins ago) -``` - -### 4.32 Check the original place of all nodes/peers' IP address in the whole network -**Command:** ipstat - -**Return:** the original place of each peer's IP address - -**Usage:** asch-cli ipstat - -**Example:** - -``` -root@asch:~# asch-cli -H 101.200.162.236 -P 4096 ipstat -美国 US -美国 US -美国 US -日本 JP -中国 CN -中国 CN -中国 CN -中国 CN -中国 CN -中国 CN -``` diff --git a/docs/asch_dapp_default_api.md b/docs/asch_dapp_default_api.md deleted file mode 100644 index 16ae7d3..0000000 --- a/docs/asch_dapp_default_api.md +++ /dev/null @@ -1,681 +0,0 @@ -Table of Contents -================= - - * [Asch dapp默认接口文档](#asch-dapp默认接口文档) - * [1 区块blocks](#1-区块blocks) - * [1.1 获取dapp区块高度](#11-获取dapp区块高度) - * [1.2 获取dapp区块数据](#12-获取dapp区块数据) - * [2 账户accounts](#2-账户accounts) - * [2.1 根据地址获取dapp内账户信息](#21-根据地址获取dapp内账户信息) - * [3 事务transactions](#3-事务transactions) - * [3.1 签名交易](#31-签名交易) - * [3.1.1 客户端签名交易(signed)-更安全](#311-客户端签名交易signed-更安全) - * [3.1.1.1 dapp充值](#3111-dapp充值) - * [3.1.1.2 dapp提现,type=2](#3112-dapp提现type2) - * [3.1.1.2 dapp内部转账,type=3](#3112-dapp内部转账type3) - * [3.1.1.2 dapp设置昵称,type=4](#3112-dapp设置昵称type4) - * [3.1.2 服务器端签名交易(unsigned)](#312-服务器端签名交易unsigned) - * [3.1.2.1 dapp充值](#3121-dapp充值) - * [3.1.2.2 dapp提现,type=2](#3122-dapp提现type2) - * [3.1.2.2 dapp内部转账,type=3](#3122-dapp内部转账type3) - * [3.1.2.2 dapp设置昵称,type=4](#3122-dapp设置昵称type4) - * [3.2 获取未确认的交易](#32-获取未确认的交易) - * [3.3 获取已确认的交易](#33-获取已确认的交易) - * [3.4 根据交易id获取交易详情](#34-根据交易id获取交易详情) - * [3.5 根据查询条件获取交易](#35-根据查询条件获取交易) - * [4 智能合约contracts](#4-智能合约contracts) - * [4.1 获取dapp内的所有智能合约](#41-获取dapp内的所有智能合约) - -Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc) - - -# Asch dapp默认接口文档 - -下面这些是每个dapp都有的通用(默认)api,由asch-sandbox提供支持。 - - -## **1 区块blocks** -### **1.1 获取dapp区块高度** -接口地址:/api/dapps/dappID/blocks/height -请求方式:GET -支持格式:urlencode - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|height|integer |dapp区块高度 | - -请求示例: -```bash -curl -k -H "Content-Type: application/json" -X GET http://localhost:4096/api/dapps/bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024/blocks/height && echo -``` - -JSON返回示例: -```js -{ - height: 10, - success: true -} -``` - - -### **1.2 获取dapp区块数据** -接口地址:/api/dapps/dappID/blocks -请求方式:GET -支持格式:urlencode -接口说明:不加参数则获取全网区块详情 -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|limit |integer |N |限制结果集个数,最小值:0,最大值:100 | -|orderBy|string |N |根据表中字段排序,如height:desc | -|offset|integer |N |偏移量,最小值0 | -|generatorPublicKey|string |N |区块生成者公钥 | -|totalAmount|integer |N |交易总额,最小值:0,最大值:10000000000000000 | -|totalFee|integer |N |手续费总额,最小值:0,最大值:10000000000000000 | -|previousBlock|string |N |上一个区块 | -|height|integer |N |区块高度 | - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|count|integer |符合条件的总结果数目 | -|blocks|Array |每个元素是一个block对象,对象里面包含block的id、height、产块受托人公钥等信息| - -请求示例: -```bash -curl -k -H "Content-Type: application/json" -X GET http://localhost:4096/api/dapps/bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024/blocks?limit=1 && echo -``` - -JSON返回示例: -```js -{ - blocks: [{ - id: "451dd17f273ea5fbd240238178c1343b11031a1d309ee8b29e8b1a5838473ec6", - timestamp: 0, - height: 1, - payloadLength: 103, - payloadHash: "995f4749e1924af55f1cdefd202efd0b37b2aa70553982378c037bc6015d5634", - prevBlockId: "", - pointId: "", - pointHeight: 0, - delegate: "8065a105c785a08757727fded3a06f8f312e73ad40f1f3502e0232ea42e67efd", - signature: "b1d0171494ce6c0621902c6005f7a85e15f3509a68ac6106b166abf711ced73efaeaf1eae0cdf594143854e27b417b253485cf98b3cc9f7aa967a929b717020b", - count: 1 - }], - count: 133, - success: true -} -``` - -## **2 账户accounts** -### **2.1 根据地址获取dapp内账户信息** -接口地址:/api/dapps/dappID/accounts/:address -请求方式:GET -支持格式:urlencode -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|address |string | Y |asch地址 | - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|account|字典 |账户详情,包含dapp内该账户拥有的所有资产及余额,是否受托人,额外信息 | - - -请求示例: -```bash -curl -k -H "Content-Type: application/json" -X GET http://192.168.2.115:4096/api/dapps/bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024/accounts/ANH2RUADqXs6HPbPEZXv4qM8DZfoj4Ry3M && echo -``` - -JSON返回示例: -```js -{ - account: { - balances: [{ - currency: "XAS", // dapp该账户拥有xas(通过自行充值或者他人dapp内转账获得) - balance: "10000000000" // 100XAS - }], - extra: null, - isDelegate: false // 是否受托人:否 - }, - success: true -} -``` - - -## **3 事务transactions** -### **3.1 签名交易** -http接口又分为signed和unsigned,他们的区别是交易在本地还是服务端签名,后者需要将密码通过http传输给服务器进行签名。 - -#### **3.1.1 客户端签名交易(signed)-更安全** -/peer相关的api,在请求时都需要设置一个header - - - key为magic,testnet value:594fe0f3, mainnet value:5f5b3cf5 - - key为version,value为'' - -asch系统的所有写操作都是通过发起一个交易来完成的。 -交易数据通过一个叫做asch-js的库来创建,然后再通过一个POST接口发布出去。 -POST接口规格如下: - -|事项 |说明 | -|--- |--- | -|接口地址|/peer/transactions | -|payload|asch-js创建出来的交易数据 | -|请求方式|post/put等 | -|支持格式|json | - -##### **3.1.1.1 dapp充值** -接口地址:/peer/transactions -请求方式:POST -支持格式:json -备注:充值时在主链发生type=6的交易(intransfer),dapp内部会自动调用编号为1的智能合约进行dapp内部充值 -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|transaction|json|Y|aschJS.transfer.createInTransfer生成的交易数据| - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transactionId|string |交易id | - -请求示例: -```bash -var aschJS = require('asch-js'); -var dappid = "bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024"; -var currency = "XAS"; -var amount = 10*100000000 ; -var secret = "found knife gather faith wrestle private various fame cover response security predict"; -var secondSecret = ""; -var transaction = aschJS.transfer.createInTransfer(dappid, currency, amount, secret, secondSecret || undefined); - -console.log(JSON.stringify(transaction)); -{"type":6,"amount":1000000000,"fee":10000000,"recipientId":null,"senderPublicKey":"2856bdb3ed4c9b34fd2bba277ffd063a00f703113224c88c076c0c58310dbec4","timestamp":39721503,"asset":{"inTransfer":{"dappId":"bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024","currency":"XAS"}},"signature":"8cefc8fa933e4d5e8699828dc8cd5d1b4737ffa82175c744fd681bad0b1a6b68526e0783e85d7979f894fc38850bd2ed0a983ce3cb3f5d16b68fd37dfb9dfb0a","id":"4b580f8f61f4586920a4c0d37b6fad21daf3453fe9ccc5426c2cae7a263c160c"} // type=6表示dapp充值,这里的type指主链的交易类型,非dapp合约编号 - -// 将上面生成的“充值”交易数据通过post提交给asch server -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":6,"amount":1000000000,"fee":10000000,"recipientId":null,"senderPublicKey":"2856bdb3ed4c9b34fd2bba277ffd063a00f703113224c88c076c0c58310dbec4","timestamp":39721503,"asset":{"inTransfer":{"dappId":"bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024","currency":"XAS"}},"signature":"8cefc8fa933e4d5e8699828dc8cd5d1b4737ffa82175c744fd681bad0b1a6b68526e0783e85d7979f894fc38850bd2ed0a983ce3cb3f5d16b68fd37dfb9dfb0a","id":"4b580f8f61f4586920a4c0d37b6fad21daf3453fe9ccc5426c2cae7a263c160c"}}' http://localhost:4096/peer/transactions && echo - -``` - -JSON返回示例: -```js -{ - "success": true, - "transactionId": "4b580f8f61f4586920a4c0d37b6fad21daf3453fe9ccc5426c2cae7a263c160c" -} -``` - -##### **3.1.1.2 dapp提现,type=2** -接口地址:/api/dapps/dappID/transactions/signed -请求方式:PUT -支持格式:json -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|dappID|string|Y|dapp的id | -|transaction|json|Y|aschJS.dapp.createInnerTransaction生成的交易数据| - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transactionId|string |提币交易id | - -请求示例: -```bash -var aschJS = require('asch-js'); -var fee = String(0.1 * 100000000); -var type = 2; -var options = {fee: fee, type: type, args: '["CCTime.XCT", "100000000"]'}; -var secret = "elite brush pave enable history risk ankle shrimp debate witness ski trend"; -var transaction = aschJS.dapp.createInnerTransaction(options, secret); - -console.log(JSON.stringify(transaction)); -{"fee":"10000000","timestamp":40384202,"senderPublicKey":"aa4e4ac1336a1e9db1ee5ce537a59d3fcb0f068cb4b25aac9f48e0e8bc6259c9","type":2,"args":"[\"CCTime.XCT\", \"100000000\"]","signature":"05dba744705fd1dbc1854b415392364cdbae11778671be8eb5fdbce57855a87b3dde5bf2d0219059411253fb304497758422c8d1546ec45eb5521b4a6577d507"} - -// 将上面生成的“提现”交易数据通过post提交给asch server -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X PUT -d '{"transaction":{"fee":"10000000","timestamp":40384202,"senderPublicKey":"aa4e4ac1336a1e9db1ee5ce537a59d3fcb0f068cb4b25aac9f48e0e8bc6259c9","type":2,"args":"[\"CCTime.XCT\", \"100000000\"]","signature":"05dba744705fd1dbc1854b415392364cdbae11778671be8eb5fdbce57855a87b3dde5bf2d0219059411253fb304497758422c8d1546ec45eb5521b4a6577d507"}}' http://45.32.22.78:4096/api/dapps/d352263c517195a8b612260971c7af869edca305bb64b471686323817e57b2c1/transactions/signed && echo - -``` - -JSON返回示例: -```js -{ - "success": true, - "transactionId": "8bcae742206bf236214b9972efaca0bbe29f3703b4055a14cc8b095546880dc4" -} -``` - -##### **3.1.1.2 dapp内部转账,type=3** -接口地址:/api/dapps/dappID/transactions/signed -请求方式:PUT -支持格式:json -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|dappID|string|Y|dapp的id | -|transaction|json|Y|aschJS.dapp.createInnerTransaction生成的交易数据| - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transactionId|string |内部转账交易id | - -请求示例: -```bash -var aschJS = require('asch-js'); -var fee = String(0.1 * 100000000); -var type = 3; -var options = {fee: fee, type: type, args: '["CCTime.XCT", "100000000", "A6H9rawJ7qvE2rKwQfdtBHdeYVehB8gFzC"]'}; -var secret = "elite brush pave enable history risk ankle shrimp debate witness ski trend"; -var transaction = aschJS.dapp.createInnerTransaction(options, secret); - -console.log(JSON.stringify(transaction)); -{"fee":"10000000","timestamp":40387708,"senderPublicKey":"aa4e4ac1336a1e9db1ee5ce537a59d3fcb0f068cb4b25aac9f48e0e8bc6259c9","type":3,"args":"[\"CCTime.XCT\", \"100000000\", \"A6H9rawJ7qvE2rKwQfdtBHdeYVehB8gFzC\"]","signature":"e2364534b8c4b0735a85c68ba17fddf5321fc48af04d483ad05531d4993058eaa35ff44d913a03b6d7278890ff7f42435f8313e08ce70c523dfc256b4de9e303"} - -// 将上面生成的“提现”交易数据通过post提交给asch server -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X PUT -d '{"transaction":{"fee":"10000000","timestamp":40387708,"senderPublicKey":"aa4e4ac1336a1e9db1ee5ce537a59d3fcb0f068cb4b25aac9f48e0e8bc6259c9","type":3,"args":"[\"CCTime.XCT\", \"100000000\", \"A6H9rawJ7qvE2rKwQfdtBHdeYVehB8gFzC\"]","signature":"e2364534b8c4b0735a85c68ba17fddf5321fc48af04d483ad05531d4993058eaa35ff44d913a03b6d7278890ff7f42435f8313e08ce70c523dfc256b4de9e303"}}' http://45.32.22.78:4096/api/dapps/d352263c517195a8b612260971c7af869edca305bb64b471686323817e57b2c1/transactions/signed && echo - -``` - -JSON返回示例: -```js -{ - "success": true, - "transactionId": "e2687a471ac2ddbbdd919266e58b0b652c55f74402b27be850d767fa44162c79" -} -``` - -##### **3.1.1.2 dapp设置昵称,type=4** -接口地址:/api/dapps/dappID/transactions/signed -请求方式:PUT -支持格式:json -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|dappID|string|Y|dapp的id | -|transaction|json|Y|aschJS.dapp.createInnerTransaction生成的交易数据| - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transactionId|string |设置昵称的交易id | - -请求示例: -```bash -var aschJS = require('asch-js'); -var fee = String(0.1 * 100000000); -var type = 4; -var options = {fee: fee, type: type, args: '["Nickname"]'}; // Nickname即昵称 -var secret = "elite brush pave enable history risk ankle shrimp debate witness ski trend"; -var transaction = aschJS.dapp.createInnerTransaction(options, secret); - -console.log(JSON.stringify(transaction)); -{"fee":"10000000","timestamp":40388287,"senderPublicKey":"aa4e4ac1336a1e9db1ee5ce537a59d3fcb0f068cb4b25aac9f48e0e8bc6259c9","type":4,"args":"[\"Nickname\"]","signature":"be08cdb2f4d1a0f2f2e5b02e33e67fdf43e403703ce35cb42a2dc7338c7a352adca56dc61e3be0fedc1727c1adc0101f1a9e1a3e67ac0623602bf872deb80802"} - -// 将上面生成的“提现”交易数据通过post提交给asch server -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X PUT -d '{"transaction":{"fee":"10000000","timestamp":40388287,"senderPublicKey":"aa4e4ac1336a1e9db1ee5ce537a59d3fcb0f068cb4b25aac9f48e0e8bc6259c9","type":4,"args":"[\"Nickname\"]","signature":"be08cdb2f4d1a0f2f2e5b02e33e67fdf43e403703ce35cb42a2dc7338c7a352adca56dc61e3be0fedc1727c1adc0101f1a9e1a3e67ac0623602bf872deb80802"}}' http://45.32.22.78:4096/api/dapps/d352263c517195a8b612260971c7af869edca305bb64b471686323817e57b2c1/transactions/signed && echo - -``` - -JSON返回示例: -```js -{ - "success": true, - "transactionId": "7teae742206bf236214b9972efaca0bbe29f3703b4055a14cc8b095546880dc4" -} -``` - -#### **3.1.2 服务器端签名交易(unsigned)** -##### **3.1.2.1 dapp充值** -##### **3.1.2.2 dapp提现,type=2** -接口地址:/api/dapps/dappId/transactions/unsigned -请求方式:PUT -支持格式:json -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|secret|string|Y|asch密码 | -|fee|string|Y|交易手续费,目前固定为10000000 | -|type|integer|Y|智能合约编号 | -|args|json字符串数组|Y|对应合约编号需要传入的参数 | - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transactionId|string |提现交易id | - -请求示例: -```bash -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X PUT -d '{"secret":"elite brush pave enable history risk ankle shrimp debate witness ski trend","fee":"10000000","type":2,"args":"[\"CCTime.XCT\",\"100000000\"]"}' 'http://45.32.22.78:4096/api/dapps/d352263c517195a8b612260971c7af869edca305bb64b471686323817e57b2c1/transactions/unsigned' && echo - -``` - -JSON返回示例: -```js -{ - "success": true, - "transactionId": "f59d365cbc8ea29f5d3798af795dc66dbdda00e2f1ae6677d5c7239180f3e98a" -} -``` - -##### **3.1.2.2 dapp内部转账,type=3** -接口地址:/api/dapps/dappId/transactions/unsigned -请求方式:PUT -支持格式:json -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|secret|string|Y|asch密码 | -|fee|string|Y|交易手续费,目前固定为10000000 | -|type|integer|Y|智能合约编号 | -|args|json字符串数组|Y|对应合约编号需要传入的参数 | - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transactionId|string |内部转账交易id | - -请求示例: -```bash -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X PUT -d '{"secret":"elite brush pave enable history risk ankle shrimp debate witness ski trend","fee":"10000000","type":3,"args":"[\"CCTime.XCT\",\"1000000000\",\"ADimyhJa99XFzVrbnTYsCqPB4TKQNdjCWw\"]"}' 'http://45.32.22.78:4096/api/dapps/d352263c517195a8b612260971c7af869edca305bb64b471686323817e57b2c1/transactions/unsigned' && echo - -``` - -JSON返回示例: -```js -{ - "success": true, - "transactionId": "96d886b7d724e6a00cc8c52c24b674ec8a9fc7fd8145a326bf69983fdc74a006" -} -``` - -##### **3.1.2.2 dapp设置昵称,type=4** -接口地址:/api/dapps/dappId/transactions/unsigned -请求方式:PUT -支持格式:json -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|secret|string|Y|asch密码 | -|fee|string|Y|交易手续费,目前固定为10000000 | -|type|integer|Y|智能合约编号 | -|args|json字符串数组|Y|对应合约编号需要传入的参数,这里是昵称 | - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transactionId|string |设置昵称交易id | - -请求示例: -```bash -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X PUT -d '{"secret":"minor borrow display rebel depart core buzz right distance avocado immense push","fee":"10000000","type":4,"args":"[\"zhenxi\"]"}' 'http://45.32.22.78:4096/api/dapps/d352263c517195a8b612260971c7af869edca305bb64b471686323817e57b2c1/transactions/unsigned' && echo -``` - -JSON返回示例: -```js -{ - "success": true, - "transactionId": "7b5d9d13cf718ee28efde6bae85fbefbcd0eca3d6c0c6fff1421a1102d730669" -} -``` - -### **3.2 获取未确认的交易** -接口地址:/api/dapps/dappID/transactions/unconfirmed -请求方式:GET -支持格式:urlencode - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transactions|array |未确认交易列表 | - - -请求示例: -```bash -curl -k -X GET http://localhost:4096/api/dapps/bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024/transactions/unconfirmed && echo -``` - -JSON返回示例: -```js -{ - "transactions": [], - "success": true -} -``` - -### **3.3 获取已确认的交易** -接口地址:/api/dapps/dappID/transactions -请求方式:GET -支持格式:urlencode -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|senderId |string |N |发送者地址 | -|type |interger |N |合约编号 | -|limit |interger |N |限制返回的条数,默认值是100 | -|offset |interger |N |偏移量 | - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transactions|array |交易列表 | -|count|integer |符合查询条件的总交易条数 | - -请求示例: -```bash -curl -k -X GET http://localhost:4096/api/dapps/bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024/transactions?senderId=AJTGR8EGsprrF7r63D2XLDftGAKUu1Ucjn && echo -``` - -JSON返回示例: -```js -{ - "transactions": [{ - "id": "b12b144b3dbb76b70cd62f97e3d3b0606d97c0f402bba1fb973dd2d3ab604a16", - "timestamp": 0, - "senderId": "AJTGR8EGsprrF7r63D2XLDftGAKUu1Ucjn", - "senderPublicKey": "27823f51a3dddd475943fb8142380d2f8722b0f6c651f6ac37930b63666c7803", - "fee": "0", - "signature": "22739bb762ff0135a0c4199507e3c45a8615c467bfeb4efa5110802033959698588e39b76d037445e02959ee67b483ac4d24f12304181f4955871cdcd28e3001", - "type": 3, - "args": "[\"CNY\",\"100000000000000\",\"A8QCwz5Vs77UGX9YqBg9kJ6AZmsXQBC8vj\"]", - "height": 1 - }], - "count": 1, - "success": true -} -``` - -### **3.4 根据交易id获取交易详情** -接口地址:/api/dapps/dappID/transactions/:id -请求方式:GET -支持格式:urlencode -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|id |string |Y |交易id | - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transaction|dict |该交易id对应的交易详情 | - - -请求示例: -```bash -curl -k -X GET http://localhost:4096/api/dapps/bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024/transactions/7088c67edd43326276453b833727677df6f312271b824564a6a934371265f0dc && echo -``` - -JSON返回示例: -```js -{ - "transaction": { - "id": "7088c67edd43326276453b833727677df6f312271b824564a6a934371265f0dc", - "timestamp": 39709980, - "senderId": "ADYGpYHmgkbukqByZ2JzwFXZM6wYfMXCaR", - "senderPublicKey": "55ad778a8ff0ce4c25cb7a45735c9e55cf1daca110cfddee30e789cb07c8c9f3", - "fee": "0", - "signature": "bd51295c3373da2a92c77b6a96a0edbda75cdcde5fd7824ff326c366ed0ec5778e1d02e7d9c280a219d6c815d9bfdbc2d03bb960a0f5d8d35458e4bda87d6104", - "type": 1, - "args": "[\"XAS\",\"10000000000\",\"2f1db0014483ffef85289e086af321e374944668dd7fb4f156c70609276ed903\",\"ANH2RUADqXs6HPbPEZXv4qM8DZfoj4Ry3M\"]", - "height": 637 - }, - "success": true -} -``` - -### **3.5 根据查询条件获取dapp转帐记录** -接口地址:/api/dapps/dappID/transfers -请求方式:GET -支持格式:urlencode -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|ownerId |string |N |发送者地址,ownerId和currency必须有一个或者两个都存在 | -|currency |string |N |代币名称,ownerId和currency必须有一个或者两个都存在 | -|limit |interger |N |限制返回的条数,默认值是10 | -|offset |interger |N |偏移量,默认0 | - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transfers|array |符合查询条件的交易列表 | -|count|integer |符合查询条件的条数 | - -请求示例: -```bash -curl -k -X GET http://localhost:4096/api/dapps/bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024/transfers?ownerid=ADYGpYHmgkbukqByZ2JzwFXZM6wYfMXCaR && echo -``` - -JSON返回示例: -```js -{ - "count": 1, - "transfers": [{ - "tid": "b12b144b3dbb76b70cd62f97e3d3b0606d97c0f402bba1fb973dd2d3ab604a16", - "senderId": "AJTGR8EGsprrF7r63D2XLDftGAKUu1Ucjn", - "recipientId": "A8QCwz5Vs77UGX9YqBg9kJ6AZmsXQBC8vj", - "currency": "CNY", - "amount": "100000000000000", - "t_timestamp": 0, - "t_type": 3, - "t_height": 1 - }], - "success": true -} -``` - -## **4 智能合约contracts** -### **4.1 获取dapp内的所有智能合约** -接口地址:/api/dapps/dappID/contracts -请求方式:GET -支持格式:urlencode - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|contracts|array |每个元素都是一个字典,由合约编号、合约名字组成,其中core开头的合约为每个dapp通用的内置合约 | - - -请求示例: -```bash -// 下面是 -curl -k -H "Content-Type: application/json" -X GET http://192.168.2.115:4096/api/dapps/bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024/contracts && echo -``` - -JSON返回示例: -```js -{ - contracts: [{ - type: "1", - name: "core.deposit" // 系统内置合约,充值(从主链往dapp内进行资产充值),普通用户不能直接调用(受托人可以调用但不能通过其它节点的校验),当主链有type=9(intransfer)的交易类型发生时会自动调用该智能合约进行dapp充值 - }, - { - type: "2", - name: "core.withdrawal" // 系统内置合约,提现(将资产从dapp内转出到主链上) - }, - { - type: "3", - name: "core.transfer" // 系统内置合约,dapp内部转账,包括XAS和UIA - }, - { - type: "4", - name: "core.setNickname" // 系统内置合约,dapp内给地址设置昵称 - }, - { - type: "1000", - name: "cctime.postArticle" // dapp自定义合约,发布文章 - }, - { - type: "1001", - name: "cctime.postComment" // dapp自定义合约,发布评论 - }, - { - type: "1002", - name: "cctime.voteArticle" // dapp自定义合约,给文章进行投票 - }, - { - type: "1003", - name: "cctime.likeComment" // dapp自定义合约,对评论进行打赏 - }, - { - type: "1004", - name: "cctime.report" // dapp自定义合约,举报文章 - }], - success: true -} -``` - - - diff --git a/docs/asch_dapp_default_api_en.md b/docs/asch_dapp_default_api_en.md deleted file mode 100644 index 14c6121..0000000 --- a/docs/asch_dapp_default_api_en.md +++ /dev/null @@ -1,1146 +0,0 @@ -Table of Contents -================= - - - - -- [Asch Dapp Default API](#asch-dapp-default-api) - - [**1 Blocks**](#1-blocks) - - [**1.1 Get the Dapp Block Height**](#11-get-the-dapp-block-height) - - [**1.2 Get Dapp Block Data**](#12-get-dapp-block-data) - - [**2 Accounts**](#2-accounts) - - [**2.1 Get Information to a Single Account**](#21-get-information-to-a-single-account) - - [**3 Transactions**](#3-transactions) - - [**3.1 Signature**](#31-signature) - - [**3.1.1 Client signed transaction - more secure**](#311-client-signed-transaction---more-secure) - - [**3.1.1.1 Dapp Recharge**](#3111-dapp-recharge) - - [**3.1.1.2 Dapp Withdraw Money, Type=2**](#3112-dapp-withdraw-money-type2) - - [**3.1.1.2 Dapp Internal Transfer,Type=3**](#3112-dapp-internal-transfertype3) - - [**3.1.1.2 Dapp set a Nickname, Type=4**](#3112-dapp-set-a-nickname-type4) - - [**3.1.2 Server Side Signed Transaction (unsigned)**](#312-server-side-signed-transaction-unsigned) - - [**3.1.2.1 Dapp recharge**](#3121-dapp-recharge) - - [**3.1.2.2 Dapp Withdraw money, Type=2**](#3122-dapp-withdraw-money-type2) - - [**3.1.2.2 Dapp Internal Transfer, Type=3**](#3122-dapp-internal-transfer-type3) - - [**3.1.2.2 set a dapp nickname, type=4**](#3122-set-a-dapp-nickname-type4) - - [**3.2 Get unconfirmed transactions**](#32-get-unconfirmed-transactions) - - [**3.3 Get already confirmed transactions**](#33-get-already-confirmed-transactions) - - [**3.4 Get transaction details for one transaction by id**](#34-get-transaction-details-for-one-transaction-by-id) - - [**3.5 Obtain dapp transfer records**](#35-obtain-dapp-transfer-records) - - [**4 Smart Contract**](#4-smart-contract) - - [**4.1 Get all smart contracts for one Dapp**](#41-get-all-smart-contracts-for-one-dapp) - - [**4.2 Access Custom Dapp Interface**](#42-access-custom-dapp-interface) - - - - -# Asch Dapp Default API - -This documents describes the default API that every Dapp inherits from the asch-sandbox. - -## **1 Blocks** -### **1.1 Get the Dapp Block Height** -__API Endpoint:__ /api/dapps/dappID/blocks/height -__HTTP Header:__ GET -__Supported Format:__ urlencode - -Return Parameter: - -|Name |Type |Description | -|------ |----- |---- | -|success|boolean|Was the operation successful | -|height |integer|Dapp Block Height | - -Javscript Request: -```js -const axios = require('axios') - -let dappId = 'bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024' -let url = `http://localhost:4096/api/dapps/${dappId}/blocks/height` - -axios.get(url) - .then((response) => { - console.log(JSON.stringify(response.data)) - }) - .catch((error) => { - console.log(error.message) - }) -``` - -Bash Request: -```bash -curl -k -H "Content-Type: application/json" -X GET http://localhost:4096/api/dapps/bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024/blocks/height && echo -``` - -JSON Response -```json -{ - "height": 10, - "success": true -} -``` - - -### **1.2 Get Dapp Block Data** -__API Endpoint:__ /api/dapps/dappID/blocks -__HTTP Header:__ GET -__Supported Format:__ urlencode -__Endpoint Description:__ Get all blocks from the Dapp - -Request Parameters: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|limit |integer |No |Limit the number of results, Minimum: 0, Maximum: 100 | -|orderBy|string |No |Sort by a field of the table, e.g. height:desc (sorts after height descending) | -|offset|integer |No |Offset, Minimum: 0 | -|generatorPublicKey|string |No |The public key of the generator (delegate) of this block. | -|totalAmount|integer |No |Total amount of transactions, Minimum: 0, Maximum: 10000000000000000 | -|totalFee|integer |No |Total fee, Minimum: 0,Maximum: 10000000000000000 | -|previousBlock|string |No |Previous Block | -|height|integer |No |Block height | - -Return Parameter: - -|Name |Type |Description | -|------ |----- |---- | -|success|boolean |Was the request successful? | -|count|integer |The total number of blocks that met the query condition| -|blocks|Array |Each element of the returned array carries the data of one block, like id, height and other information| - - -Javascript Request: -```js -const axios = require('axios') - -let parameters = { - params: { - limit: 1 - } -} - -let dappId = 'bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024' -let url = `http://localhost:4096/api/dapps/${dappId}/blocks` - -axios.get(url, parameters) - .then((response) => { - console.log(JSON.stringify(response.data)) - }) - .catch((error) => { - console.log(error.message) - }) -``` - -Bash Request: -```bash -curl -k -H "Content-Type: application/json" -X GET http://localhost:4096/api/dapps/bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024/blocks?limit=1 && echo -``` - -JSON Response: -```json -{ - "blocks": [{ - "id": "451dd17f273ea5fbd240238178c1343b11031a1d309ee8b29e8b1a5838473ec6", - "timestamp": 0, - "height": 1, - "payloadLength": 103, - "payloadHash": "995f4749e1924af55f1cdefd202efd0b37b2aa70553982378c037bc6015d5634", - "prevBlockId": "", - "pointId": "", - "pointHeight": 0, - "delegate": "8065a105c785a08757727fded3a06f8f312e73ad40f1f3502e0232ea42e67efd", - "signature": "b1d0171494ce6c0621902c6005f7a85e15f3509a68ac6106b166abf711ced73efaeaf1eae0cdf594143854e27b417b253485cf98b3cc9f7aa967a929b717020b", - "count": 1 - }], - "count": 133, - "success": true -} -``` - -## **2 Accounts** -### **2.1 Get Information to a Single Account** -__API Endpoint:__ /api/dapps/dappID/accounts/:address -__HTTP Header:__ GET -__Supported Format:__ urlencode - -Request Parameter: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|address |string|Yes |Asch Address| - -Return Parameter: - -|Name |Type |Description | -|------ |----- |---- | -|success|boolean |Was the request successful? | -|account|json |All information regarding one account such as: Asset balances, is the address a delegate? and other information| - - -Javascript Request: -```js -const axios = require('axios') - -let address = 'ANH2RUADqXs6HPbPEZXv4qM8DZfoj4Ry3M' - -let dappId = 'bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024' -let url = `http://localhost:4096/api/dapps/${dappId}/accounts/${address}` - -axios.get(url) - .then((response) => { - console.log(JSON.stringify(response.data)) - }) - .catch((error) => { - console.log(error.message) - }) -``` - -Bash Request: -```bash -curl -k -H "Content-Type: application/json" -X GET http://localhost:4096/api/dapps/bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024/accounts/ANH2RUADqXs6HPbPEZXv4qM8DZfoj4Ry3M && echo -``` - -JSON Response: -```js -{ - "success": true, - "account": { - "balances": [{ - "currency": "XAS", // this account has a XAS balance (either through a recharge or an internal dapp transfer) - "balance": "10000000000" // 100 XAS - }], - "extra": null, - "isDelegate": false // is not a delegate - } -} -``` - - -## **3 Transactions** -### **3.1 Signature** -The HTTP Endpoint is divided into ___signed___ und ___unsigned___. Either will the transaction be signed locally and then send to the server (signed) or the secret must be send to the server and there the transaction will be signed (unsigned). - -#### **3.1.1 Client signed transaction - more secure** -Peer related API, you need to set the a header at a request. - - - key is magic: - - testnet: 594fe0f3 - - mainnet: 5f5b3cf5 - - key version is '' (empty) - -All write operations in Asch start with a transaction. -The transaction data is created through a library called [asch-js](https://github.com/AschPlatform/asch-js) and then published via a POST interface. -The HTTP-POST API specification are as follows: - -|Matter |Description | -|--- |--- | -|API Endpoint|/peer/transactions | -|payload|transaction data that were created with `asch-js`| -|HTTP Method|post/put etc.| -|Supported format|json | - -##### **3.1.1.1 Dapp Recharge** -__API Endpoint:__ /peer/transactions -__HTTP Header:__ POST -__Supported Format:__ json -Note: When the recharge occurs in the main chain (mainchain-transaction-type 6, intransfer) then the Dapp will automatically call the dapp smart contract number 1 for a dapp internal recharge. - -Info: -A Dapp Recharge is necessary if you want to spend XAS or an other currency in the Dapp. If you have 2000 XAS on your mainchain account that doesn't mean that you can spend 2000 XAS in the Dapp. You have to first "recharge" the Dapp with money. You send some XAS to the Dapp and the balance will be credited on your Dapp account. - -Request Parameter: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|transaction|json|Yes|A transaction generated with a function call to `aschJS.transfer.createInTransfer` | - - -Return Parameter: - -|Name |Type |Description | -|------ |----- |---- | -|success|boolean |Was the request successful? | -|transactionId|string |Transaction id| - -Javascript Request: -```js -// this account must have enough XAS on the mainchain -const aschJS = require('asch-js') -const axios = require('axios') - -let dappid = "bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024" -let secret = 'found knife gather faith wrestle private various fame cover response security predict' - -let currency = 'XAS' -let amount = 500 * 1e8 -let transaction = aschJS.transfer.createInTransfer(dappid, currency, amount, secret, secondSecret || undefined) - -let data = { - transaction: transaction -} - -let headers = { - headers: { - magic: '594fe0f3', - version: '' - } -} - -let url = 'http://localhost:4096/peer/transactions' - -axios.post(url, data, headers) - .then((response) => { - console.log(JSON.stringify(response.data)) - }) - .catch((error) => { - console.log(error.message) - }) - - -``` - -Bash Request -```bash -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":6,"amount":1000000000,"fee":10000000,"recipientId":null,"senderPublicKey":"2856bdb3ed4c9b34fd2bba277ffd063a00f703113224c88c076c0c58310dbec4","timestamp":39721503,"asset":{"inTransfer":{"dappId":"bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024","currency":"XAS"}},"signature":"8cefc8fa933e4d5e8699828dc8cd5d1b4737ffa82175c744fd681bad0b1a6b68526e0783e85d7979f894fc38850bd2ed0a983ce3cb3f5d16b68fd37dfb9dfb0a","id":"4b580f8f61f4586920a4c0d37b6fad21daf3453fe9ccc5426c2cae7a263c160c"}}' http://localhost:4096/peer/transactions && echo -``` - -JSON Response: -```js -{ - "success": true, - "transactionId": "4b580f8f61f4586920a4c0d37b6fad21daf3453fe9ccc5426c2cae7a263c160c" -} -``` - -##### **3.1.1.2 Dapp Withdraw Money, Type=2** -__API Endpoint:__ /api/dapps/dappID/transactions/signed -__HTTP Header:__ PUT -__Supported Format:__ json - -Info: -This operation is the opposite to [**3.1.1.1 Dapp Recharge**](#3111-dapp-recharge). This operation withdraws money from the Dapp to the mainchain. - - -Request Parameter: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|dappID|string|Yes|Dapp Id| -|transaction|json|Yes|Transaction data generated by a function call to `aschJS.dapp.createInnerTransaction`| - - -Return Parameter: - -|Name |Type |Description | -|------ |----- |---- | -|success|boolean |Was the request successful? | -|transactionId|string |Transaction Id| - - -Example: -```js -// you need at least 1 CCTime.XCT on your sidechain account -const aschJS = require('asch-js') -const axios = require('axios') - -let fee = String(0.1 * 100000000) -let type = 2 // withdraw money to mainchain -let options = { - fee: fee, - type: type, - args: JSON.stringify(['CCTime.XCT', '100000000']) -} -let secret = "elite brush pave enable history risk ankle shrimp debate witness ski trend" -let transaction = aschJS.dapp.createInnerTransaction(options, secret) - -let dappId = 'b12906bcb8de449e8d41fada9227f1cde206daca17f9bc366666c206ad4d7e20' - -let url = `http://localhost:4096/api/dapps/${dappId}/transactions/signed` -let data = { - transaction: transaction -} -let headers = { - magic: '594fe0f3', - version: '' -} - -axios.put(url, data, headers) - .then((response) => { - console.log(JSON.stringify(response.data)) - }) - .catch((error) => { - console.log(error.message) - }) -``` - -Bash Request: -```bash -# The Money withdraw transaction (type=2) is send to the server -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X PUT -d '{"transaction":{"fee":"10000000","timestamp":40384202,"senderPublicKey":"aa4e4ac1336a1e9db1ee5ce537a59d3fcb0f068cb4b25aac9f48e0e8bc6259c9","type":2,"args":"[\"CCTime.XCT\", \"100000000\"]","signature":"05dba744705fd1dbc1854b415392364cdbae11778671be8eb5fdbce57855a87b3dde5bf2d0219059411253fb304497758422c8d1546ec45eb5521b4a6577d507"}}' http://localhost:4096/api/dapps/d352263c517195a8b612260971c7af869edca305bb64b471686323817e57b2c1/transactions/signed && echo -``` - -JSON Response: -```js -{ - "success": true, - "transactionId": "8bcae742206bf236214b9972efaca0bbe29f3703b4055a14cc8b095546880dc4" -} -``` - -##### **3.1.1.2 Dapp Internal Transfer,Type=3** -__API Endpoint:__ /api/dapps/dappID/transactions/signed -__HTTP Header:__ PUT -__Supported Format:__ JSON - -Info: -This operation transfers money (XAS or other currencies) only between Dapp accounts. - -Request Parameter: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|dappID|string|Yes|Dapp Id| -|transaction|json|Yes|Transaction data generated by a function call to `aschJS.dapp.createInnerTransaction`| - - -Return Parameter: - -|Name |Type |Description | -|------ |----- |---- | -|success|boolean |Was the request successful?| -|transactionId|string |Internal Transfer Transaction Id| - -Example: -```js -// you need at least 1 CCTime.XCT on your sidechain account -const aschJS = require('asch-js') -const axios = require('axios') - -let fee = String(0.1 * 1e8) -let type = 3 // internal transfer -let options = { - fee: fee, - type: type, - args: JSON.stringify(['CCTime.XCT', '100000000', 'A6H9rawJ7qvE2rKwQfdtBHdeYVehB8gFzC']) -} -let secret = 'elite brush pave enable history risk ankle shrimp debate witness ski trend' -let transaction = aschJS.dapp.createInnerTransaction(options, secret) - -let dappId = 'd352263c517195a8b612260971c7af869edca305bb64b471686323817e57b2c1' -let url = `http://localhost:4096/api/dapps/${dappId}/transactions/signed` -let data = { - transaction: transaction -} -let headers = { - magic: '594fe0f3', - version: '' -} - -axios.put(url, data, headers) - .then((response) => { - console.log(JSON.stringify(response.data)) - }) - .catch((error) => { - console.log(error.message) - }) -``` - -Bash Response: -```bash -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X PUT -d '{"transaction":{"fee":"10000000","timestamp":40387708,"senderPublicKey":"aa4e4ac1336a1e9db1ee5ce537a59d3fcb0f068cb4b25aac9f48e0e8bc6259c9","type":3,"args":"[\"CCTime.XCT\", \"100000000\", \"A6H9rawJ7qvE2rKwQfdtBHdeYVehB8gFzC\"]","signature":"e2364534b8c4b0735a85c68ba17fddf5321fc48af04d483ad05531d4993058eaa35ff44d913a03b6d7278890ff7f42435f8313e08ce70c523dfc256b4de9e303"}}' http://localhost:4096/api/dapps/d352263c517195a8b612260971c7af869edca305bb64b471686323817e57b2c1/transactions/signed && echo -``` - -JSON Response: -```json -{ - "success": true, - "transactionId": "e2687a471ac2ddbbdd919266e58b0b652c55f74402b27be850d767fa44162c79" -} -``` - -##### **3.1.1.2 Dapp set a Nickname, Type=4** -__API Endpoint:__ /api/dapps/dappID/transactions/signed -__HTTP Header:__ PUT -__Supported Format:__ json - -Request Parameter: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|dappID|string|Yes|Dapp Id| -|transaction|json|Yes|Transaction data generated by a function call to `aschJS.dapp.createInnerTransaction`| - - -Return Parameter: - -|Name |Type |Description | -|------ |----- |---- | -|success|boolean |Was the request successful? | -|transactionId|string |The TransactionId for the set nickname operation| - -Javascript Example: -```js -const aschJS = require('asch-js') -const axios = require('axios') - -let fee = String(0.1 * 1e8) -let type = 4 // set nickname -let options = { - fee: fee, - type: type, - args: JSON.stringify(['Nickname']) -} - -let secret = 'elite brush pave enable history risk ankle shrimp debate witness ski trend' -let transaction = aschJS.dapp.createInnerTransaction(options, secret) - -let dappId = 'd352263c517195a8b612260971c7af869edca305bb64b471686323817e57b2c1' -let url = `http://localhost:4096/api/dapps/${dappId}/transactions/signed` -let data = { - transaction: transaction -} -let headers = { - magic: '594fe0f3', - version: '' -} - -axios.put(url, data, headers) - .then((response) => { - console.log(JSON.stringify(response.data)) - }) - .catch((error) => { - console.log(error.message) - }) -``` -Bash Request: -```bash -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X PUT -d '{"transaction":{"fee":"10000000","timestamp":40388287,"senderPublicKey":"aa4e4ac1336a1e9db1ee5ce537a59d3fcb0f068cb4b25aac9f48e0e8bc6259c9","type":4,"args":"[\"Nickname\"]","signature":"be08cdb2f4d1a0f2f2e5b02e33e67fdf43e403703ce35cb42a2dc7338c7a352adca56dc61e3be0fedc1727c1adc0101f1a9e1a3e67ac0623602bf872deb80802"}}' http://localhost:4096/api/dapps/d352263c517195a8b612260971c7af869edca305bb64b471686323817e57b2c1/transactions/signed && echo -``` - -JSON Response: -```json -{ - "success": true, - "transactionId": "7teae742206bf236214b9972efaca0bbe29f3703b4055a14cc8b095546880dc4" -} -``` - -#### **3.1.2 Server Side Signed Transaction (unsigned)** -##### **3.1.2.1 Dapp recharge** -##### **3.1.2.2 Dapp Withdraw money, Type=2** -__API Endpoint:__ /api/dapps/dappId/transactions/unsigned -__HTTP Header:__ PUT -__Supported Format:__ JSON - -Info: -This operation is the opposite to the `Dapp recharge`. This operation withdraws money from the Dapp to the mainchain. - -Request Parameter: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|secret|string|Yes|Asch secret| -|fee|string|Yes|Transaction fee, currently fixed at 10000000 | -|type|integer|Yes|Smart contract type | -|args|string Array|Yes|The string Array must contain the contract type| - - -Return Parameter: - -|Name |Type |Description | -|------ |----- |---- | -|success|boolean |Was the request successful? | -|transactionId|string |Withdrawal transaction Id | - -Example: -```js -const axios = require('axios') - -let headers = { - magic: '594fe0f3', - version: '' -} - -let dappId = 'd352263c517195a8b612260971c7af869edca305bb64b471686323817e57b2c1' -let url = `http://localhost:4096/api/dapps/${dappId}/transactions/unsigned` - -let data = { - secret: 'elite brush pave enable history risk ankle shrimp debate witness ski trend', - fee: '10000000', - type: 2, // withdraw money to mainchain - args: JSON.stringify(['CCTime.XCT', '100000000']) -} - -axios.put(url, data, headers) - .then((result) => { - console.log(JSON.stringify(result.data)) - }) - .catch((error) => { - console.log(error.message) - }) -``` - -```bash -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X PUT -d '{"secret":"elite brush pave enable history risk ankle shrimp debate witness ski trend","fee":"10000000","type":2,"args":"[\"CCTime.XCT\",\"100000000\"]"}' 'http://localhost:4096/api/dapps/d352263c517195a8b612260971c7af869edca305bb64b471686323817e57b2c1/transactions/unsigned' && echo - -``` -JSON Response: -```json -{ - "success": true, - "transactionId": "f59d365cbc8ea29f5d3798af795dc66dbdda00e2f1ae6677d5c7239180f3e98a" -} -``` - -##### **3.1.2.2 Dapp Internal Transfer, Type=3** -__API Endpoint:__ /api/dapps/dappId/transactions/unsigned -__HTTP Header:__ PUT -__Supported Format:__ JSON - -Info: See [**3.1.1.2 Dapp Internal Transfer,Type=3**](#3112-dapp-internal-transfertype3) - -Request Parameter: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|secret|string|Yes|Asch secret | -|fee|string|Yes| | -|type|integer|Yes|The number of the smart contract | -|args|string array|Yes|The corresponding contract number needs to be passed in | - - -Return Parameter: - -|Name |Type |Description | -|------ |----- |---- | -|success|boolean |Was the request successful? | -|transactionId|string |Internal transfer transacation Id| - -Javascript Request: -```js -const axios = require('axios') - -let headers = { - magic: '594fe0f3', - version: '' -} - -let data = { - secret: 'elite brush pave enable history risk ankle shrimp debate witness ski trend', - fee: '10000000', - type: 3, // internal transfer - args: JSON.stringify(['CCTime.XCT', '1000000000', 'ADimyhJa99XFzVrbnTYsCqPB4TKQNdjCWw']) -} - -let dappId = 'd352263c517195a8b612260971c7af869edca305bb64b471686323817e57b2c1' -let url = `http://localhost:4096/api/dapps/${dappId}/transactions/unsigned` - -axios.put(url, data, headers) - .then((result) => { - console.log(JSON.stringify(result.data)) - }) - .catch((error) => { - console.log(error.message) - }) -``` - -Bash Request: -```bash -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X PUT -d '{"secret":"elite brush pave enable history risk ankle shrimp debate witness ski trend","fee":"10000000","type":3,"args":"[\"CCTime.XCT\",\"1000000000\",\"ADimyhJa99XFzVrbnTYsCqPB4TKQNdjCWw\"]"}' 'http://localhost:4096/api/dapps/d352263c517195a8b612260971c7af869edca305bb64b471686323817e57b2c1/transactions/unsigned' && echo -``` - -JSON Response: -```json -{ - "success": true, - "transactionId": "96d886b7d724e6a00cc8c52c24b674ec8a9fc7fd8145a326bf69983fdc74a006" -} -``` - -##### **3.1.2.2 set a dapp nickname, type=4** -__API Endpoint:__ /api/dapps/dappId/transactions/unsigned -__HTTP Header:__ PUT -__Supported Format:__ JSON - -Request Parameter: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|secret|string|Yes|asch password | -|fee|string|Yes|Transaction fee, currently 10000000| -|type|integer|Yes|Smart contract number | -|args|string array|Yes|Pass the nickname as a string in an array, see further below for example | - - -Return Parameter: - -|Name |Type |Description | -|------ |----- |---- | -|success|boolean |Was the request successful?| -|transactionId|string |Set nickname transaction id| - -Javascript Request: -```js -const axios = require('axios') - -let headers = { - magic: '594fe0f3', - version: '' -} - -let data = { - secret: 'minor borrow display rebel depart core buzz right distance avocado immense push', - fee: '10000000', - type: 4, // set nickname - args: JSON.stringify(['zhenxi']) -} - -let dappId = 'd352263c517195a8b612260971c7af869edca305bb64b471686323817e57b2c1' -let url = `http://localhost:4096/api/dapps/${dappId}/transactions/unsigned` - -axios.put(url, data, headers) - .then((response) => { - console.log(JSON.stringify(response.data)) - }) - .catch((error) => { - console.log(error.message) - }) -``` - -Bash Request: -```bash -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X PUT -d '{"secret":"minor borrow display rebel depart core buzz right distance avocado immense push","fee":"10000000","type":4,"args":"[\"zhenxi\"]"}' 'http://localhost:4096/api/dapps/d352263c517195a8b612260971c7af869edca305bb64b471686323817e57b2c1/transactions/unsigned' && echo -``` - -JSON Response: -```json -{ - "success": true, - "transactionId": "7b5d9d13cf718ee28efde6bae85fbefbcd0eca3d6c0c6fff1421a1102d730669" -} -``` - -### **3.2 Get unconfirmed transactions** -__API Endpoint:__ /api/dapps/dappID/transactions/unconfirmed -__HTTP Header:__ GET -__Supported Format:__ urlencode - -Return Parameter: - -|Name |Type |Description | -|------ |----- |---- | -|success|boolean |Was the request successful? | -|transactions|array |A list of unconfirmed transactions| - - -Javascript Example: -```js -const axios = require('axios') - -let dappId = 'bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024' -let url = `http://localhost:4096/api/dapps/${dappId}/transactions/unconfirmed` - -axios.get(url) - .then((response) => { - console.log(JSON.stringify(response.data)) - }) - .catch((error) => { - console.log(error.message) - }) -``` - -Bash Example: -```bash -curl -k -X GET http://localhost:4096/api/dapps/bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024/transactions/unconfirmed && echo -``` - -JSON Response: -```json -{ - "transactions": [], - "success": true -} -``` - -### **3.3 Get already confirmed transactions** -__API Endpoint:__ /api/dapps/dappID/transactions -__HTTP Header:__ GET -__Supported Format:__ urlencode - -Request Parameter: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|senderId |string |No|Address of sender | -|type |interger |No|contract number | -|limit |interger |No|Limit the result set, default is 100| -|offset |interger |No|Offset | - - -Return Parameter: - -|Name |Type |Description | -|------ |----- |---- | -|success|boolean |Was the request successful?| -|transactions|array |List of confirmed transactions| -|count|integer |The total number of transactions that met the query conditions| - - -Javascript Request: -```js -const axios = require('axios') - -const parameters = { - params: { - senderId: 'AJTGR8EGsprrF7r63D2XLDftGAKUu1Ucjn' - } -} - -let dappId = 'bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024' -let url = `http://localhost:4096/api/dapps/${dappId}/transactions` - -axios.get(url, parameters) - .then((response) => { - console.log(JSON.stringify(response.data)) - }) - .catch((error) => { - console.log(error.message) - }) -``` - -Bash Request: -```bash -curl -k -X GET http://localhost:4096/api/dapps/bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024/transactions?senderId=AJTGR8EGsprrF7r63D2XLDftGAKUu1Ucjn && echo -``` - -JSON Response: -```json -{ - "count": 1, - "success": true, - "transactions": [{ - "id": "b12b144b3dbb76b70cd62f97e3d3b0606d97c0f402bba1fb973dd2d3ab604a16", - "timestamp": 0, - "senderId": "AJTGR8EGsprrF7r63D2XLDftGAKUu1Ucjn", - "senderPublicKey": "27823f51a3dddd475943fb8142380d2f8722b0f6c651f6ac37930b63666c7803", - "fee": "0", - "signature": "22739bb762ff0135a0c4199507e3c45a8615c467bfeb4efa5110802033959698588e39b76d037445e02959ee67b483ac4d24f12304181f4955871cdcd28e3001", - "type": 3, - "args": "[\"CNY\",\"100000000000000\",\"A8QCwz5Vs77UGX9YqBg9kJ6AZmsXQBC8vj\"]", - "height": 1 - }] -} -``` - -### **3.4 Get transaction details for one transaction by id** -__API Endpoint:__ /api/dapps/dappID/transactions/:id -__HTTP Header:__ GET -__Supported Format:__ urlencode - -Request Parameter: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|id |string |Yes|Transaction Id| - -Return Parameter: - -|Name |Type |Description| -|------ |----- |---- | -|success|boolean |Was the request successful?| -|transaction|object |The requested transaction| - - -Javascript Request: - -```js -const axios = require('axios') - -let transactionId = '7088c67edd43326276453b833727677df6f312271b824564a6a934371265f0dc' - -let dappId = 'bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024' -let url = `http://localhost:4096/api/dapps/${dappId}/transactions/${transactionId}` - -axios.get(url) - .then((response) => { - console.log(JSON.stringify(response.data)) - }) - .catch((error) => { - console.log(error.message) - }) -``` - -Bash Request: - -```bash -curl -k -X GET http://localhost:4096/api/dapps/bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024/transactions/7088c67edd43326276453b833727677df6f312271b824564a6a934371265f0dc && echo -``` - -JSON Response: -```json -{ - "success": true, - "transaction": { - "id": "7088c67edd43326276453b833727677df6f312271b824564a6a934371265f0dc", - "timestamp": 39709980, - "senderId": "ADYGpYHmgkbukqByZ2JzwFXZM6wYfMXCaR", - "senderPublicKey": "55ad778a8ff0ce4c25cb7a45735c9e55cf1daca110cfddee30e789cb07c8c9f3", - "fee": "0", - "signature": "bd51295c3373da2a92c77b6a96a0edbda75cdcde5fd7824ff326c366ed0ec5778e1d02e7d9c280a219d6c815d9bfdbc2d03bb960a0f5d8d35458e4bda87d6104", - "type": 1, - "args": "[\"XAS\",\"10000000000\",\"2f1db0014483ffef85289e086af321e374944668dd7fb4f156c70609276ed903\",\"ANH2RUADqXs6HPbPEZXv4qM8DZfoj4Ry3M\"]", - "height": 637 - } -} -``` - -### **3.5 Obtain dapp transfer records** -__API Endpoint:__ /api/dapps/dappID/transfers -__HTTP Header:__ GET -__Supported Format:__ urlencode - -Info: -Get the records of sended or received transfers. - -Request Parameter: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|ownerId |string |No|At least one of the following have to exists: Sender-Address, OwnerId, Currency| -|currency |string |No|At least one of the following have to exist: Token name, OwnerId, Currency| -|limit |interger |No|Limits the return list, default is 10| -|offset |interger |No|Offset, default 0| - -Return Parameter: - -|Name |Type |Description| -|------ |----- |---- | -|success|boolean|Was the request successful?| -|transfers|array|Get the transfers that met the query| -|count|integer|The total number of transfers that met the query conditions| - -Javascript Request: -```js -const axios = require('axios') - -let dappId = 'bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024' -let url = `http://localhost:4096/api/dapps/${dappId}/transfers` - -let parameters = { - ownerid: 'ADYGpYHmgkbukqByZ2JzwFXZM6wYfMXCaR' -} - -axios.get(url, parameters) - .then((response) => { - console.log(JSON.stringify(response.data)) - }) - .catch((error) => { - console.log(error.message) - }) -``` - -Bash Request: -```bash -curl -k -X GET http://localhost:4096/api/dapps/bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024/transfers?ownerid=ADYGpYHmgkbukqByZ2JzwFXZM6wYfMXCaR && echo -``` - -JSON Response: -```json -{ - "success": true, - "count": 1, - "transfers": [{ - "tid": "b12b144b3dbb76b70cd62f97e3d3b0606d97c0f402bba1fb973dd2d3ab604a16", - "senderId": "AJTGR8EGsprrF7r63D2XLDftGAKUu1Ucjn", - "recipientId": "A8QCwz5Vs77UGX9YqBg9kJ6AZmsXQBC8vj", - "currency": "CNY", - "amount": "100000000000000", - "t_timestamp": 0, - "t_type": 3, - "t_height": 1 - }] -} -``` - -## **4 Smart Contract** -### **4.1 Get all smart contracts for one Dapp** -__API Endpoint:__ /api/dapps/dappID/contracts -__HTTP Header:__ GET -__Supported Format:__ urlencode - -Return Parameter: - -|Name |Type |Description | -|------ |----- |---- | -|success|boolean |Was the request successful?| -|contracts|array |Each element is a object with the following properties: type (number), contract name (string)| - - -Javascript Request: -```js -const axios = require('axios') - -let dappId = 'bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024' -let url = `http://localhost:4096/api/dapps/${dappId}/contracts` - -axios.get(url) - .then((response) => { - console.log(JSON.stringify(response.data)) - }) - .catch((error) => { - console.log(error.message) - }) -``` - -Bash Request: -```bash -curl -k -H "Content-Type: application/json" -X GET http://localhost:4096/api/dapps/bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024/contracts && echo -``` - -JSON Response: -```js -{ - success: true, - contracts: [{ - type: "1", - name: "core.deposit" // built-in contract, recharge (from the main chain to dapp within the asset reload), ordinary users can not be called directly (the trustee can call this contract but the operation can not be verified by other nodes), when the main chain transaction-type=9 (intransfer) the smart contract will automatically call app recharge - }, - { - type: "2", - name: "core.withdrawal" // built-in contract, this operation transfers the asset from the dapp-sidechain to the mainchain - }, - { - type: "3", - name: "core.transfer" // built-in contract, dapp internal transfers including XAS and UIA - }, - { - type: "4", - name: "core.setNickname" // built-in contract, set nickname for dapp address - }, - { - type: "1000", - name: "cctime.postArticle" // custom contract, publish article - }, - { - type: "1001", - name: "cctime.postComment" // custom contract, post a comment - }, - { - type: "1002", - name: "cctime.voteArticle" // custom contract, vote for an article - }, - { - type: "1003", - name: "cctime.likeComment" // custom contract, reward for comments - }, - { - type: "1004", - name: "cctime.report" // custom contract, report articles - }] -} -``` - - -### **4.2 Access Custom Dapp Interface** - -To borrow an example from [aschplatform/cctime](https://github.com/AschPlatform/cctime/blob/master/interface/index.js). It is possible to register custom API endpoints for your Dapp. This makes especially sense if you create a new entity like `articles` (which becomes a table in the sidechain SQL database). Through the new custom api endpoint your frontend can access articles. - -![alt](./assets/dapp/custom_api_example.png) - -```js -// filename interface/index.js - -app.route.get('/articles/:id', async (req) => { - let id = req.params.id - let key = 'article_' + id - if (app.custom.cache.has(key)) { - return app.custom.cache.get(key) - } - let article = await app.model.Article.findOne({ - condition: { id: id } - }) - if (!article) { - throw new Error('Article not found') - } - if (article.reports >= 3) { - throw new Error('Article not allowed') - } - let account = await app.model.Account.findOne({ - condition: { address: article.authorId } - }) - if (account) { - article.nickname = account.str1 - } - let result = { article: article } - app.custom.cache.set(key, result) - return result -}) - -// ommitted other functions -``` - - - -This API Endpoint exposes articles by id. - -__API Endpoint:__ /api/dapps/dappID/articles/:id -__HTTP Header:__ GET - -Request Parameter: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|id |integer |Yes|The id of the desired article| - - -Return Paramter: - -|Name |Type |Description | -|------ |----- |---- | -|id|number |Auto incremented intenger article identifier | -|tid|string |TransactionId, id of transaction in which the article was published | -|authorId|string|Asch Address of publisher| -|timestamp|number|Timestamp of article publication| -|title|string|Title of article| -|url|string|Url that points to other ressource on the internet | -|text|string|Text of article| -|tags|string|tags under which the article should be categorized| -|votes|number|How many times other users voted for the article| -|comments|number|How many comments do this article have?| -|reports|number|How often was this article reported?| - - - -Javascript Request: -```js -const axios = require('axios') - -let articleId = 33 - -let dappId = 'bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024' -let url = `http://localhost:4096/api/dapps/${dappId}/articles/${articleId}` - -axios.get(url) - .then((response) => { - console.log(JSON.stringify(response)) - }) - .catch((error) => { - console.log(error.message) - }) -``` - -JSON Response: -```json -{ - "id": "33", - "tid" "e4a95e133b76af2c1c6bf55ecb8ba8d6d007fc5d1bb353edac688577f0ca19a0", - "authorId": "AHMCKebuL2nRYDgszf9J2KjVZzAw95WUyB", - "timestamp": "62515470", - "title": "How to develop Dapps", - "url": null, - "text": "This is a very long text...", - "tags": "sidechain,dapps,aschplatform", - "votes": 58, - "comments": 4, - "reports": 0 -} -``` diff --git a/docs/asch_dapps_introduction.md b/docs/asch_dapps_introduction.md deleted file mode 100644 index 48adc2d..0000000 --- a/docs/asch_dapps_introduction.md +++ /dev/null @@ -1,62 +0,0 @@ -# Asch Dapp开发介绍 - -我们在白皮书里提到过,asch使用的是不同于以太坊和比特币的侧链架构,dapp是运行在侧链上的,每条侧链对应一个dapp。(Asch主链类比IOS生态系统,每个节点都是一部iphone,所有的dapp组成了appstore,每个节点可以自由选择安装哪些dapp) - -## 侧链的独立性 - -侧链架构的好处是代码和数据独立,不增加主链的负担,避免数据过度膨胀,实际上是一种天然的分片机制。 -侧链有独立的区块链(具有和一般区块链相同的特征属性),有独立的受托人或者说见证人,同时也有独立的节点网络,就是说一个侧链产生的区块只会在所有安装了该侧链的节点之间进行广播。 - -独立性既是优点,也是缺点。开发者完成了dapp的开发工作之后,还要考虑运维,也就是说要寻找足够的节点来运行它(Asch侧链默认用的DPOS共识算法,对运行节点的受托人会给予一定的token奖励,类比BTC的挖矿,所以找人去运行dapp是很容易的事情),否则难以维持足够的安全性。 -从这一点来看,与以太坊相比,是缺陷,以太坊上一旦发布一个dapp,所有的节点都可以为它工作,并为它提供安全保障。 - -## 侧链的灵活性 - -但是侧链架构依然有存在的必要性,因为并非所有的应用都需要那么高的安全性。Asch给用户提供了一种可以选择的灵活性。 -比方说,假设asch有1000个节点,那么其中有的dapp比较重要,需要500个节点来运行它,有的dapp不那么重要,可能只需要100个节点,这完全是由用户和开发者决定的。 -在以太坊上,则只能选择一种,即全部节点都来运行它。据说以太坊也打算实现一种分片的机制,实际上这在asch系统中是一个早就解决了的问题。 -另外,对于比较重要的、安全性要求较高的应用,我们依然可以选择在主链上开发(就是像以太坊那样dapp运行在所有的Asch主链的节点上),但是不可能对所有开发者开放这种权力,还是为了避免主链的膨胀和不可控(DAO事件)。 - -侧链的灵活性还表现在,所有的区块链参数是可以定制的,简单的比如区块间隔、区块奖励、交易费的去向等,高级用户还可以修改共识算法(默认是DPOS共识算法)。 -不过最重要的还是业务逻辑,侧链上可以轻易的开发出与你的业务相关的交易类型或者智能合约。 -这一点是与侧链的发明者blockstreams不同,blockstreams的侧链,只是一个不同的货币系统而已,开发新型交易和智能合约很不容易。 - -如下图所示 -黑色的圆圈代表一个节点,64个节点组成了主链的网络。红色方框之内的是1号侧链,其侧链网络是由12个节点组成。蓝色方框之内的是2号侧链,其网络是由36个节点组成。 - -![sidechain deploy architecture](./assets/sidechain-deploy.png) - -## 主链与侧链的互利关系 - -Asch的主链与侧链之间是互惠互利的关系,asch为侧链提供基础设施,比如数据库写入的api,网络通讯api,加密api等等,侧链则可以为asch主链补充更多的节点,以壮大整个系统。 -侧链的开发者不需要提供所有的机器,可以利用已经存在主链节点,只需要节点主人安装该应用即可。 -另外,主链的代币XAS可以转入侧链中,由于XAS可以在交易所交易,就相当于为侧链的资产提供了一种价值的媒介。 -开发者在侧链发行一种资产后,可以直接与XAS兑换,不需要考虑交易平台的问题。 - -## 解决生产力问题 - -我们在[ASCH_DAPP_SDK](./asch_sdk_api.md)中为侧链提供了一套模板,或者说脚手架,也可以叫做开发框架,侧链的大部分底层功能都是写好的,dapp开发者只需要关心具体的业务逻辑,在这一点上,与以太坊的dapp开发难度相当。 -Asch的侧链框架使用的语言是nodejs,我们内置了不少常用的库让开发者直接使用,当然开发者也可以自行安装所需要的,有一个庞大的javascript社区作为后盾。 - -下面是asch内置的模块 - -![inbuilt modules](./assets/inbuilt-modules.png) - -## 解决安全问题 - -这里的安全问题与上面提到的因为节点不足导致的问题不一样,这里说的安全问题是指侧链代码对安装者造成侵犯的问题。 -我们希望每一个asch节点都能安装一个侧链,而且asch节点的主人无需信任侧链的开发者。这就需要提供一种安全防范的措施,比如,防止侧链代码肆意读取文件系统、进行网络操作。 -在asch系统中,侧链代码会以子进程的方式启动,子进程首先加载一个使用沙箱机制隔离的javascript虚拟机,这个js虚拟机就是没有```require```以及任何多余模块的裸体虚拟机。 -然后我们为这个虚拟机植入一个定制的```require```和一些常用且安全的模块, 最后再加载侧链的代码。 -我们还通过进程间通讯的方式提供一系列的api。 -这样,侧链的框架就拥有了足够多的api,同时侧链的安装者也没有任何风险。 - -![process structure](./assets/process-structure.png) - -## 实例教程 - -接下来我们会提供一个由浅入深的教程,帮助开发者快速入门。 - -- [Dapp开发教程一 Asch Dapp Hello World](./dapp_docs/1_hello.md) - 这个文档会教你如何创建并发布一个基础的侧链应用,并介绍侧链框架的源码结构 -- [Dapp案例一 CCTime的后端源码](https://github.com/AschPlatform/cctime) 这是基于[ASCH_DAPP_SDK](./asch_sdk_api.md)开发的第一个Dapp,开发者可以当做示例代码阅读,[前端代码链接](https://github.com/AschPlatform/cctime-frontend) \ No newline at end of file diff --git a/docs/asch_dapps_introduction_de.md b/docs/asch_dapps_introduction_de.md deleted file mode 100644 index 5edb63d..0000000 --- a/docs/asch_dapps_introduction_de.md +++ /dev/null @@ -1,85 +0,0 @@ -# Einführung in die Asch Dapp Entwicklung -Wie bereits im Whitepaper erwähnt, verwendet Asche eine Sidechain-Architektur, welche sich von Währungen wie Ethereum oder Bitcoin dadurch entscheidet, dass die dezentralen Applikationen (Dapp) auf Sidechains laufen. Eine Sidechain für jede Dapp. - -## Die Unabhängigkeit einer Sidechain - -Die Vorteile eines Sidechain-Frameworks ist, dass der Programmcode und die Daten unabhängig von der Hauptchain sind. So bleiben die Daten an einem Ort und nicht über die ganze Blockchain verteilt sind. Dies könnte man als natürlichen Partitionsmechanismus bezeichnen. -Eine Sidechain hat ihre eigene Blockchain, ihre eigenen Delegate und ihre eigenen Knoten. Dies bedeutet, dass ein auf der Sidechain erzeugter Block zu allen Knoten der Sidechain gesendet werden kann. - -Jede Münze hat zwei Seiten, so auch die Unabhängigkeit der Sidechain. Wenn eine Dapp fertig entwickelt ist, dann muss auch die Wartung als Kriterium herangezogen werden. Um die Sicherheit der Dapp zu gewährleisten müssen genug Knoten zur Ausführen der Dapp zur Verfügung stehen. - -Von dieser Perspektive ist der Sidechain-Mechanismus nicht so gut wie bei Ethereum. Ist eine Dapp erst einmal auf Ethereum deployed, so können alle Knoten für diese arbeiten als auch die Sicherheit garantieren. - - -## Die Flexibilität der Sidechain - -Der Sidechain-Mechanismus hat seine Stärken, denn nicht jede Applikation benötigt das größte Maß an Sicherheit. Asch, welches auf dem Sidechain-Mechanismus basiert, kann seinen Nutzern eine größere Flexibilität bieten. - -Dies soll anhand eines Beispiels gzeigt werden: Angenommen es gibt 1000 Knoten im System. Eine kritische Dapp benötigt 500 dieser Knoten. Eine andere, nicht so kritische Dapp benötigt nur 100 Knoten. Dies liegt ganz im Ermessen der Benutzer und Entwickler. - -Im Vergleich dazu bietet Ethereum nur eine Möglichkeit: Eine Applikation läuft auf allen Knoten. Es wird jedoch gesagt, dass in Zukunft Ethereum auch eine Möglichkeit zur Partitionierung von Dapps bekommt. Eine Funktion welche Asch bereits besitzt. - -Für Anwendungen welche ein Höchstmaß an Sicherheit benötigen, bietet Asch die Möglichkeit, dass diese Dapps auf der Mainchain ausgeführt werden. Dieses Privileg kann jedoch nicht allen Entwicklern zugänglich gemacht werden. Dies liegt einerseits daran, dass dann eine Applikation beliebig groß wachsen kann, andererseits wäre die Unsicherheit zu groß (siehe [DAO Problem](https://en.wikipedia.org/wiki/The_DAO_(organization)#Risks)). - -Die Flexibilität einer Sidechain lässt sich auch daran zeigen, dass alle Parameter ihrer Blockchain konfigurierbar sind. Es können z.B.: Block-Interval, Block-Belohnung, Transaktionsgebühr oder sogar der Konsensus-Algorithmus geändert werden. - - -Das Wichtigste ist die Business-Logik, welche sich leicht auf der Sidechain entwickeln lässt, egal ob es sich um eine Business-Transaktion handelt oder um einen smart contract. - -Beachte, dass Asch sich von [Blockstream](https://en.wikipedia.org/wiki/Blockstream) unterscheidet. Blockstream hat die Sidechaintechnologie entwickelt, ist aber auch zugleich der Betreiber ihrer eigenen Sidechain auf der es aber schwierig ist ein neues Transaktionssystem und neue intelligente Verträge zu entwickeln. - -Schauen wir uns den folgendne Absatz an: - -Jeder Kreis repräsentiert einen Knoten im System. Alle 64 Knoten bilden das Netzwerk der Mainchain. Im roten Rahmen ist die Sidechain Nr.1, welche aus 12 Knoten besteht. Sidechain Nr.2 wird durch den blauen Rahmen repräsentiert und besteht aus 36 Knoten. - -![sidechain deploy architecture](./assets/sidechain-deploy.png) - -## Die Wechselwirkung zwischen Mainchain und Sidechain - -Es existiert eine wechselseitige Beziehung zwischen der Asch Mainchain und den Sidechains. Asch bietet jeder Sidechain den Zugriff auf verschiedene APIs: Datenbank, Netzwerkkommunikation als auch Verschlüsselung. Ein positiver Nebeneffekt der Sidechain ist, dass diese zusätzliche Knoten zum Netzwerk hinzufügt werden und somit das ganze Asch System verstärken. - -Zwangsläufig muss ein Entwickler nicht alle Knoten die er für eine Sidechain benötigt zur Verfügung stellen. Es besteht auch die Möglichkeit, dass Besitzer von bestehenden Knoten die neue entwickelte Applikation auf ihrem Knoten ausführen. - -XAS, die Währung der Asch Mainchain, kann zu jeder Sidechain transferiert werden. XAS wird auf Crypto-Marktplätzen gehandelt. Die Währung einer Sidechain muss nicht zwangsläufig auf einem Crypto-Marktplatz gehandelt werden, sie kann einfach gegen XAS getauscht werden. So hat man als neue Sidechain nicht mit dem "wie bekomme ich meine Währung auf den Marktplatz?" Problem zu kämpfen. Die neue Währung kann direkt in XAS gewechselt werden. - -## Produktivität - -Wir bieten eine Fülle von Vorlagen (oder besser gesagt ein Gerüst zum Entwickeln) für die Entwicklung von Sidechains. Die größten Entwicklungsaufgaben an den Sidechains wurden bereits bewältig. Als Entwickler reicht es, dass man sich nur auf die Business-Logik konzentriert. Zu diesem Zeitpunkt ist das Entwickeln auf Asch gleich schwer wie auf Ethereum. - -Zum Entwickeln von Sidechain wird die Sprache Node.js verwendet. Darauf basierend stellen wir weitere Bibliotheken für Entwickler zur Verfügung. Entwickler können alle Module hinzufügen die sie brauchen, da die Javascript-Community genug Hilfestellung bietet. - - -Die folgenden Module sind von vorhinein in Asch integriert: - -![inbuilt modules](./assets/inbuilt-modules.png) - -## Sicherheitslösung - -Anders als die oben angesprochenen Probleme, geht es im folgenden nicht um den Mangel an Knoten, sondern um das Problem des Ausführens von schädlichem Programm-Code welcher Benutzer von Asch-Dapps angreift. - -Das Ziel ist es, dass jeder Asch-Knoten unterschiedliche Sidechain-Dapps installieren kann, ohne dass er dem Code bedingungslos vertrauen muss. Deshalb bedarf es eines Sicherheitsmechanismuses, welcher den Knoten vor dem Auslesen des Dateisystems oder dem Manipulieren des Netzwerktverkehrs bewahrt. - -Um dieses Problem zu lösen, wird im Asch-System jeder Sidechain-Programm-Code als ein Kindprozess geladen. Dieser Kindprozess ladet eine virtuelle Javascript-Sandbox welche komplett vom restlichen System isoliert ist. Diese Javascript-Sandbox besitzt keine `require` Funktionalität und bekommt keine unnötigen Module mitgeliefert. - -Danach wird eine individuell angepasste `require` Funktion geladen inklusive häufig benutzter und sicherer Javascript-Module. Als letzter Schritt wird der Sidechain-Code geladen. Weiters bieten wir eine API für IPC (inter-process communication) an. Alle diese Schritte gewährleisten, dass der Sidechain-Code genügend APIs zur Verfügung hat, aber auch, dass der Knoten welcher den Sidechain-Code installiert kein Sicherheitsrisiko eingehen muss. - -![process structure](./assets/process-structure.png) - -## Tutorials - -Hier folgen einige Tutorials welche einen schnellen Start für Entwickler ermöglichen sollen. - -- [Dapp Entwicklungs Tutorial 1: Asch Dapp Hello World](./dapp_docs/1_hello_en.md) - Dieses Tutorial zeigt wie man eine einfache Sidechain-Applikation erstellt und veröffentlicht. Desweiteren wird die Code-Struktur des Sidechain-Frameworks beleuchtet. - -- [Dapp Entwicklungs Tutorial 2: Asch Dapp Asset](./dapp_docs/2_asset_en.md) - Dieses Tutorial zeigt wie man ein Asset auf der Sidechain erstellt. Weiters wird die Kommunikation zwischen Front- und Backend analysiert. - -- [Dapp Entwicklungs Tutorial 3: Asch Dapp Mini DAO](./dapp_docs/3_mini_dao_en.md) - Dieses Tutorial zeigt wie man eine Typtransaktion oder einen intelligenten Vertrag erstellt. Dies wird anhand eines kleinen DAO-Projekts (DAO=Dezentrale Autonome Organisation) mit Projekt Management und Voting Funktion erläutert. - -- [Dapp Entwicklungs Tutorial 4: Asch Dapp Dice Game](./dapp_docs/4_dice_game_en.md) - Dieses Tutorial zeigt wie man kompliziertere Transaktionen und intelligente Verträge erstellt, als auch wie man solch einen Vertrag auf Basis von historischen Daten ausführt. Desweiteren wird die Realisierung eine Würfelspiels demonstriert. - -- [Dapp Entwicklungs Tutorial 5: Eine Dapp veröffentlichen](./dapp_docs/5_dapp_publish_en.md) - Dieses Tutorial zeigt wie man eine Applikation online registriert (Testchain, Hauptchain) und wie man diese installiert / deinstalliert. diff --git a/docs/asch_dapps_introduction_en.md b/docs/asch_dapps_introduction_en.md deleted file mode 100644 index fccc058..0000000 --- a/docs/asch_dapps_introduction_en.md +++ /dev/null @@ -1,84 +0,0 @@ -# Introducing Asch Dapp Development -As we mentioned in whitepaper, not like Etherum or Bitcoin, Asch is using a sidechain framework as a platform for decentralised applications (DApp). Usually, each DApp runs on its own sidechain. - -## The Independency of Sidechain - -The advantage of sidechain framework is that both the code and data are independent from main blockchain, hence data over-dilation can be avoided. In fact this is a nature partition mechanism. -A sidechain has its own blockchain, delegates and nodes network, which means a block generated from a sidechain will be able to broadcast among the nodes belong to this sidechain. - -Every coin has two sides, so does independency of sidechain. After finishing the developement of DApp, developers still need to consider the operating and maintenance. In detail, it is necessary for developers to guarntee enough nodes to maintain acceptable security. - -From this perspective, the sidechain mechanism is not as good as Ethereum. Once a DApp is deployed on Ethereum, all the nodes in Ethereum can work for it, as well as promise the security. - - -## The Flexibility of Sidechain - -Sidechain mechanism, however, has its own value of existence since not every application needs such a high level security. Based on sidechain mechanism, Asch can provide a more flexible choice to users. - -For example, let's say Asch system has 1000 nodes. And under this circumstance some DApps are important so that they need 500 nodes to run. But some others may not be such crucial and only 100 nodes can meet their requirements. The point is that all of these choices are totally up to users and developers. - -Comparily, only one option is available in Ethereum, which is all nodes are occupied to run this application. It is said that Ethereum is also about to provide a partition mechanism, which is a solution that Asch system has already had. - -And obviously for those crucial applications that require high level security, Asch system still allows to develop on main blockchain. But this priority cannot be granted to all the developers because of unlimited dilations of main blockchain and potential risk of uncertainty (such as [DAO issue](https://en.wikipedia.org/wiki/The_DAO_(organization)#Risks)) - -The flexibility of sidechain is also reflected in that all paramaters of its blockchain can be customized. You can configure some common ones like block interval, block reward, or transaction fee's destination, or if you are an advanced user, you can even revise the consensus algorithm. - -But the most important thing is business logic, which can be easily developed on sidechain platform, no matter whether it is the business related transactions or smart contracts. Note that Asch is different with blockstreams, the inventor of sidechain, because the blockstreams' sidechain is just another cryptocurrency system on which it is difficult to develop new generation transaction system and smart contracts. - -Let's see the following graph - -Each black circus presents a node, and all 64 nodes constitute the network of main blockchain. In the red frame is sidechain No.1, whose sidechain network is composed by 12 nodes. Sidechain No.2 is represented by the blue frame, which contains 36 nodes. - -![sidechain deploy architecture](./assets/sidechain-deploy.png) - -## The Reciprocity of Main Chain and Sidechain - -There is a reciprocity relationship between the Asch main chain and the sidechains. Asch provides the essential foundation to sidechain as all kinds of API such as database writing , network communication or encrytion. Meanwhile, sidechain brings more nodes to supply hence strengthen the whole Asch system. - -It is unnecessary for sidechain developers to provides all required machines. Oppositely, they can utilized existed nodes as long as the owners of those nodes allow to install the applications on them. - -In addition, XAS, the currency of Asch main chain, can be transferred to sidechain. Because of the characteristic of XAS that is able to trade in exchanges, it can be a reliable media of value that is suitable for the assets existed in sidechain. Developers do not need to concern the trading platform problems when they issue an asset in sidechain because they can exchange it with XAS directly. - - -## Solution of Productivity - -We provide a set of templates, (or we can say scaffold or development framework) for sidechain in the SDK. Most of the fundamental functionalities of sidechain have been already completed, and all DApp developers needs to concern is just real business logic. At this point, DApp development on Asch platform has the same difficulty as on the Ethereum framework. - -The development language used in Asch sidechain framework is nodejs, upon which we built many common libraries that can be directly used by developers. Also developers can install anything they need since there is a large Javascript community providing enough supports. - -The following is modules built in Asch platform. - -![inbuilt modules](./assets/inbuilt-modules.png) - -## Solution of Security - -Different with those nodes deficiency issues we mentioned above, the security problems here we discuss are those sidechain codes intrude on DApp users of Asch platform. - -We hope each Asch node has its own sidechain installed, and the owner of this node does not have to trust the sidechain developer. It means that a security mechanism is required to provide some protection measures such as preventing sidechain from reading file system or manipulating network. - -To sovle this problem, sidechain code within Asch system is launched as a child-process, which firstly loads a Javascript virtual machine isolated by sandbox mechanism that is a purely clean virtual machine without `require` function and any unnecessary modules. - -Then we inplant a customized `require` and some common and secure modules, and then load the sidechain code. We also provide a set of API via IPC (inter-process communication). All of these measures ensure that the sidechain framework has enough API to use, as well as application users of sidechain will not need to suffer any risk. - - -![process structure](./assets/process-structure.png) - -## Tutorials - -Here are some tutorials from the begining which will be helpful to the developers to rapidly develop applications. - -- [Dapp Development Tutorial 1: Asch Dapp Hello World](./dapp_docs/1_hello_en.md) - This tutorial shows how to create and publish a basic sidechain application, as well as introduces the source code structure of sidechain framework. - -- [Dapp Development Tutorial 2: Asch Dapp Asset](./dapp_docs/2_asset_en.md) - This tutorial shows how to designate a built-in asset to sidechain and then analyse communication interface between the front end and back end. - - -- [Dapp Development Tutorial 3: Asch Dapp Mini DAO](./dapp_docs/3_mini_dao_en.md) - This tutorial shows how to create a new type transaction or smart contract, and demostrates a mini decentralized autonomous organization (dao) project with project management and voting function. - -- [Dapp Development Tutorial 4: Asch Dapp Dice Game](./dapp_docs/4_dice_game_en.md) - This tutorial shows how to crate more complicate transaction or smart contract, how to establish the connection among contracts, and how to carry out the contract based on historic data. The tutorial also demostrates a dice game. - -- [Dapp Development Tutorial 5: Publish Dapp online](./dapp_docs/5_dapp_publish_en.md) - This tutorial shows how to register the application to online system (testnet, mainnet and how to install/uninstall it. diff --git a/docs/asch_delegate_forging.md b/docs/asch_delegate_forging.md deleted file mode 100644 index cd4edb8..0000000 --- a/docs/asch_delegate_forging.md +++ /dev/null @@ -1,46 +0,0 @@ -# Asch 受托人与锻造 - -Asch系统中每个账户都可以注册成为受托人(需要支付100XAS)。
-成为受托人以后可以接受任意持币人的投票,当得票率排名进入前101时,可以获得记账权(即生产区块的权利,相当于比特币中的矿工),并获取一定的奖励。 -生产区块的过程叫做锻造(forging)。
-锻造不像比特币挖矿那样需要很强的算力,普通电脑即可进行,验证记账权的算法综合了时间片验证、受托人随机排名、受托人签名以及pbft算法等,具体可以参考[asch的共识协议](http://blog.asch.so/2016/08/11/asch-consensus-and-fault-tolerance/) -排名前101的受托人按照时间顺序轮流产生区块,区块间隔为10秒。当轮班受托人出现异常无法生产区块时,则延期到下一个10秒,由下一个受托人继续生产。
-每101个区块为一个周期,每个周期的受托人锻造顺序随机变换,每个周期的最后一个区块产出的时候,会进行该周期的收益结算,同时刷新新的排名。
-因为宕机、网络错误等原因无法生产区块的受托人无法获得该周期的收益,并且会降低生产率。生产率是衡量一个受托人稳定性的指标,生产率过低会影响得票率。
-正常生产区块的受托人则平分收益,收益包括区块奖励和交易费,排名和得票率的高低并不影响收益的多少,进入前101名的受托人收益率是相同的。
- -## 区块奖励 - -区块奖励会随着时间递减,具体时间则以未来的某一区块高度为准。
-Asch系统的区块奖励从464500块开始,初始奖励3.5币,每300万块递减一次,大约为1年。
-从15464500块以后,奖励不再递减,每年有略小于1.5%的通胀率。
-下面是各个阶段的区块奖励 - -|奖励|起始高度|结束高度| -|-----|------|-------| -|3.5|464500|3464500| -|3|3464500|6464500| -|2.5|6464500|9464500| -|2|9464500|12464500| -|1|12464500|15464500| -|0.5|15464500|---| - -## 交易费 - -除了区块奖励,受托人可以获得系统的交易费,或者手续费,手续费有以下种类。 - -|类型|费用XAS| -|----|---| -|普通转账|0.1| -|投票|0.1| -|二级密码|5| -|注册受托人|100| -|注册dapp|100| -|dapp充值|0.1| -|dapp提现|0.1| -|多重签名|(n+1)*0.5| -|小文件存储|(size / 200 + 1) * 0.1| -|资产发行商注册|100| -|资产注册|500| -|资产发行|0.1| -|资产转账|0.1| diff --git a/docs/asch_delegate_forging_en.md b/docs/asch_delegate_forging_en.md deleted file mode 100644 index 15c9eba..0000000 --- a/docs/asch_delegate_forging_en.md +++ /dev/null @@ -1,64 +0,0 @@ -title: Delegators and forging of Asch ---- - -Each account in Asch system can be registered as a delegator (100XAS is payable). - -A delegator can accept any votes from coin holders. When the rate of vote reaches into top 101, -the delegators can obtain the right to account(that is, the right of block production, which is -equivalent to miners in Bitcoin. ) and get certain reward. The process of block production is -called forging. - -Forging does not need strong computing power like Bitcoin mining. Even the ordinary computer -can be carried out to verify the algorithm of accounting right, which combines time slice -verification, delegators random ranking, delegators signatures and pbft algorithm. More -details refer to Asch consensus agreement. The delegators of top 101 are in turn to produce -blocks in chronological order with a block interval of 10 seconds.When delegators in turn can -not produce blocks because of exceptions, it will be postponed to next 10 seconds and produce -by the next delegator. - -Each 101 blocks as a cycle, forging order of the delegators will be random changed in each cycle. -When the last block is produced, the benefit will be settled in this cycle and the ranking will -also be refreshed. -If delegators can not produce blocks because of the downtime, network errors and other reasons, -they can not only get the benefits of the cycle, but also reduce productivity. Productivity is -an indicator of the stability of a delegator, and lower productivity will affect the vote. - -The delegators of the normal block production divide the benefit equally, including block rewards -and transaction fees. The rankings and the votes do not affect the amount of the benefit. The benefit -rate of the top 101 delegators is the same. - -# 1 Block rewards - -Block rewards will decrease over time, and the specific time will be based on the height of a future block. -The block rewards of Asch system start from the beginning of 464500 block. The initial reward is 3.5 coins. -Every 3 million block decreases once and it lasts about 1 year. -After 15464500 block, the reward is no longer decreasing and each year has slightly less than 1.5% inflation rate. - -The following are the various stages of the block reward - -|reward|initial height|end height| -|-----|------|-------| -|3.5|464500|3464500| -|3|3464500|6464500| -|2.5|6464500|9464500| -|2|9464500|12464500| -|1|12464500|15464500| -|0.5|15464500|---| - -# 2 transaction fee - -In addition to the block rewards, the delegators can obtain the system transaction fee, or the handling fee. -The handling fee has the following kinds. - - -|type|fee| -|----|---| -|transaction|0.1| -|vote|0.1| -|the second password|5| -|registed delegator|100| -|registed dapp|100| -|dapp deposit|0.1| -|dapp withdraw|0.1| -|multiple signatures|(n+1)*0.5| -|small file storage (not yet online)|(size / 200 + 1) * 0.1| diff --git a/docs/asch_dev_windows_install.md b/docs/asch_dev_windows_install.md deleted file mode 100644 index f135a51..0000000 --- a/docs/asch_dev_windows_install.md +++ /dev/null @@ -1,141 +0,0 @@ -# Asch 本地开发环境搭建(Windows) - -## 1 系统要求 - -- Windows操作系统(7/8/10) - -## 2 安装nodejs -[安装nodejs](https://nodejs.org/en/download/) 配置环境变量,版本V6.3以上(以下的没有验证过),如下所示: - -![nodejs环境](assets/win_install/node.png) - -## 3 安装Python -[安装Python](https://www.python.org/downloads/release/python-2713/) 并配置环境变量,版本2.5到3.0之间(最好2.7,3.0以及以上版本不支持),如下所示: - -![python](assets/win_install/python.png) - -## 4 安装.NET Framework 4.5.1 -[下载](https://www.microsoft.com/en-us/download/details.aspx?id=42779) 并安装.NET Framework 4.5.1,如果系统已经安装了可以忽略此步骤(至少4.5版本),win7系统可以直接打开控制**面板》程序》程序和功能** 查看 -是否已经安装,win10系统默认已经安装好了,查看方式如下图所示: - -![python](assets/win_install/win10.net.png) - -## 5 安装 VC++ Build Tools Technical Preview -[下载](http://go.microsoft.com/fwlink/?LinkId=691126)并安装VC++ Build Tools Technical Preview,全部选择默认安装就行了,安装时间可能有点久(10分钟左右) - -[参考](https://stackoverflow.com/questions/21069699/node-packages-not-building-on-windows-8-1-missing-microsoft-cpp-default-props) - -## 6 安装git -[下载](https://git-scm.com/)并安装git,应为asch使用gulp构建工具,其中包含一部分linux命令(如 cp、mv等),所以后面执行命令的时候需要用到git bash - -## 7 安装sqlite3 -[下载](https://pan.baidu.com/s/1WvQYSCCr-n7N5HMCRGqwLA)已经打包好的sqlie3压缩文件,解压放到任意位置,然后添加环境变量,如下所示: - -![sqlite3](assets/win_install/sqlite3.png) - -打开命令行验证如下: - -![sqlite3](assets/win_install/sqlite3_verify.png) - -## 8 安装gcc, g++ -这里有如下两种方式: -* [下载mingw-get-setup](https://sourceforge.net/projects/mingw/files/Installer/),然后再线安装所有依赖包,但是可能会比较慢 -* 下载我已经下载好的依赖包,解压缩后放到任意盘,然后配置环境变量,如下所示: - -![sqlite3](assets/win_install/gcc.png) - -安装完成后分别执行一下命令查看是否成功: -``` -gcc -v -g++ -v -``` - -如下所示: - -![sqlite3](assets/win_install/gcc_verify.png) - -## 9 安装OpenSSL -[下载](http://slproweb.com/products/Win32OpenSSL.html)并安装OpenSSL,全部默认安装即可. - -## 10 npm配置 -首先执行以下命令配置淘宝镜像,这样使用npm下载的时候会更快一些 -``` -npm config set registry https://registry.npm.taobao.org - -##验证 -npm info npm -``` - -执行以下命令配置**msvs** -``` -npm config set msvs_version 2015 --global -``` - -最后安装asch需要的一些依赖,执行以下命令: -``` -npm i -g gulp -npm i -g yarn -``` - -### 11 运行代码 -> 运行前查看之前的 VC++ Build Tools Technical Preview 是否已经安装完成 - -注:运行代码之前需要说明一下,在asch3.0版本之前,用的椭圆曲线加密依赖为ed25519,而3.0以后使用的是sodium, -3.0之前的代码直接安装完依赖就可以运行,但是目前的3.0之后的源码需要改变几行代码,但是asch的所有功能都能正常运行,方便Windows用户本地开发调试使用。 - -修改以下两个文件的内容: -* src\utils\ed.js -* package.json - -package.js: -```json -##原依赖 -"sodium": "^2.0.3", - -## 换成ed25519 -"ed25519": "^0.0.4", -``` - -ed.js: -``` -## 将文件所有内容换成如下代码 -const ed = require('ed25519'); -module.exports = { - MakeKeypair: ed.MakeKeypair, - - Sign: ed.Sign, - - Verify: ed.Verify -}; -``` - -修改完文件以后安装依赖: -``` -npm install -``` - -因为Windows控制台本身的原因,安装过程中如果出现停顿可以按几下回车,如果出现以下步骤则说明前面一些安装成功了: - -![install](assets/win_install/install.png) - -最后执行 **node app.js** 即可正常运行,如下图所示: - -![run](assets/win_install/run.png) - -## 12 编译前端项目 -前端项目具体编译打包操作可以参考 [前端项目的操作说明](../public/README.md),不过这里需要注意一点, -所有的命令都要在 **git bash** 中进行,原因已经在之前安装git的时候说明了,依次执行以下命令即可: -``` -cd public -yarn install -gulp build-test -``` - -## 13 软件下载 -考虑到部分软件可能因为网络原因无法下载,在这里提供一个所有依赖的软件的 [下载地址](https://pan.baidu.com/s/1WLSH9M0Hwp16CPYOgZ_6GQ) - - - - - - diff --git a/docs/asch_http_interface.md b/docs/asch_http_interface.md deleted file mode 100644 index 9ba1652..0000000 --- a/docs/asch_http_interface.md +++ /dev/null @@ -1,3560 +0,0 @@ -Table of Contents -================= - - * [ASCH HTTP API文档](#asch-http-api文档) - * [1 API使用说明](#1-api使用说明) - * [1.1 请求过程说明](#11-请求过程说明) - * [2 接口](#2-接口) - * [2.1 账户accounts](#21-账户accounts) - * [2.1.1 登录](#211-登录) - * [2.1.1.1 本地加密后再登陆(推荐使用)](#2111-本地加密后再登陆推荐使用) - * [2.1.1.2 本地不加密直接登陆](#2112-本地不加密直接登陆) - * [2.1.2 根据地址获取账户信息](#212-根据地址获取账户信息) - * [2.1.3 获取账户余额](#213-获取账户余额) - * [2.1.4 根据地址获取账户公钥](#214-根据地址获取账户公钥) - * [2.1.5 生成公钥](#215-生成公钥) - * [2.1.6 根据地址获取其投票列表](#216-根据地址获取其投票列表) - * [2.1.7 获取受托人手续费设置](#217-获取受托人手续费设置) - * [2.1.8 给受托人投票](#218-给受托人投票) - * [2.1.9 生成新账户](#219-生成新账户) - * [2.1.10 获取账户排行榜前100名](#2110-获取账户排行榜前100名) - * [2.1.11 获取当前链上账户总个数](#2111-获取当前链上账户总个数) - * [2.2 交易transactions](#22-交易transactions) - * [2.2.1 获取交易信息](#221-获取交易信息) - * [2.2.2 根据交易id查看交易详情](#222-根据交易id查看交易详情) - * [2.2.3 根据未确认交易id查看详情](#223-根据未确认交易id查看详情) - * [2.2.4 获取[全网所有]未确认的交易详情](#224-获取全网所有未确认的交易详情) - * [2.2.5 创建交易并广播](#225-创建交易并广播) - * [2.3 区块blocks](#23-区块blocks) - * [2.3.1 获取指定区块的详情](#231-获取指定区块的详情) - * [2.3.2 获取区块数据](#232-获取区块数据) - * [2.3.3 获取区块链高度](#233-获取区块链高度) - * [2.3.4 获取普通转账手续费](#234-获取普通转账手续费) - * [2.3.5 获取里程碑](#235-获取里程碑) - * [2.3.6 查看单个区块奖励](#236-查看单个区块奖励) - * [2.3.7 获取XAS当前供应值](#237-获取xas当前供应值) - * [2.3.8 区块链状态](#238-区块链状态) - * [2.3.9 获取指定区块的交易信息](#239-获取指定区块的交易信息) - * [2.4 受托人delegates](#24-受托人delegates) - * [2.4.1 获取受托人总个数](#241-获取受托人总个数) - * [2.4.2 根据受托人公钥查看哪些人为其投了票](#242-根据受托人公钥查看哪些人为其投了票) - * [2.4.3 根据公钥或者用户名获取受托人详情](#243-根据公钥或者用户名获取受托人详情) - * [2.4.4 获取受托人列表](#244-获取受托人列表) - * [2.4.5 获取受托人设置的转账费](#245-获取受托人设置的转账费) - * [2.4.6 根据公钥查看其锻造情况](#246-根据公钥查看其锻造情况) - * [2.4.7 注册受托人](#247-注册受托人) - * [2.4.8 受托人开启锻造](#248-受托人开启锻造) - * [2.4.9 受托人关闭锻造](#249-受托人关闭锻造) - * [2.4.10 受托人锻造状态查看](#2410-受托人锻造状态查看) - * [2.5 节点peers](#25-节点peers) - * [2.5.1 获取全网节点信息](#251-获取全网节点信息) - * [2.5.2 获取本节点版本号等信息](#252-获取本节点版本号等信息) - * [2.5.3 获取指定ip节点信息](#253-获取指定ip节点信息) - * [2.6 同步和加载](#26-同步和加载) - * [2.6.1 查看本地区块链加载状态](#261-查看本地区块链加载状态) - * [2.6.2 查看区块同步信息](#262-查看区块同步信息) - * [2.7 二级密码signatures](#27-二级密码signatures) - * [2.7.1 设置二级密码](#271-设置二级密码) - * [2.7.2 获取二级密码设置手续费](#272-获取二级密码设置手续费) - * [2.8 多重签名multisignatures](#28-多重签名multisignatures) - * [2.8.1 设置普通账户为多重签名账户](#281-设置普通账户为多重签名账户) - * [2.8.2 根据公钥获取挂起的多重签名交易详情](#282-根据公钥获取挂起的多重签名交易详情) - * [2.8.3 非交易发起人对交易进行多重签名](#283-非交易发起人对交易进行多重签名) - * [2.8.4 获取多重签名账户信息](#284-获取多重签名账户信息) - * [2.9 点对点传输tansport[安全的api]](#29-点对点传输tansport安全的api) - * [2.9.1 说明](#291-说明) - * [2.9.2 普通交易](#292-普通交易) - * [2.9.2.1 设置二级密码](#2921-设置二级密码) - * [2.9.2.2 转账](#2922-转账) - * [2.9.2.3 注册受托人](#2923-注册受托人) - * [2.9.2.4 投票 & 取消投票](#2924-投票--取消投票) - * [2.9.2.5 账户锁仓](#2925-账户锁仓) - * [2.9.3 UIA相关交易](#293-uia相关交易) - * [2.9.3.1 注册资产发行商](#2931-注册资产发行商) - * [2.9.3.2 注册资产](#2932-注册资产) - * [2.9.3.3 资产设置acl模式](#2933-资产设置acl模式) - * [2.9.3.4 更新访问控制列表(acl)](#2934-更新访问控制列表acl) - * [2.9.3.5 资产发行](#2935-资产发行) - * [2.9.3.6 资产转账](#2936-资产转账) - * [2.9.3.7 资产注销](#2937-资产注销) - * [2.9.4 其它内部通讯安全接口](#294-其它内部通讯安全接口) - * [2.10 用户自定义资产uia](#210-用户自定义资产uia) - * [2.10.1 获取全网所有发行商](#2101-获取全网所有发行商) - * [2.10.2 查询指定发行商的信息](#2102-查询指定发行商的信息) - * [2.10.3 查看指定发行商的资产](#2103-查看指定发行商的资产) - * [2.10.4 获取全网所有资产信息](#2104-获取全网所有资产信息) - * [2.10.5 获取指定资产信息](#2105-获取指定资产信息) - * [2.10.6 获取指定资产的访问控制列表(acl)](#2106-获取指定资产的访问控制列表acl) - * [2.10.7 获取指定账户所有uia的余额](#2107-获取指定账户所有uia的余额) - * [2.10.8 获取指定账户所有资产相关操作记录](#2108-获取指定账户所有资产相关操作记录) - * [2.10.9 获取指定账户指定资产的余额](#2109-获取指定账户指定资产的余额) - * [2.10.10 获取指定账户指定资产转账记录](#21010-获取指定账户指定资产转账记录) - * [2.10.11 获取指定资产转账记录](#21011-获取指定资产转账记录) - * [2.10.12 资产创建相关](#21012-资产创建相关) - * [2.10.12.1 注册资产发行商](#210121-注册资产发行商) - * [2.10.12.2 注册资产](#210122-注册资产) - * [2.10.12.3 更新资产访问控制列表(acl)](#210123-更新资产访问控制列表acl) - * [2.10.12.4 资产发行](#210124-资产发行) - * [2.10.12.5 资产转账](#210125-资产转账) - * [2.10.12.6 更新黑白名单](#210126-更新黑白名单) - * [2.11 存储storages](#211-存储storages) - * [2.11.1 上传数据](#2111-上传数据) - * [2.11.1.1 上传数据(直接上传)](#21111-上传数据直接上传) - * [2.11.1.2 上传数据(签名后再上传)](#21112-上传数据签名后再上传) - * [2.11.2 根据交易id查询存储的数据-1](#2112-根据交易id查询存储的数据-1) - * [2.11.3 根据交易id查询存储的数据-2](#2113-根据交易id查询存储的数据-2) - * [附录1:asch-js安装](#附录1asch-js安装) - -Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc) - - -# ASCH HTTP API文档 - - - -## **1 API使用说明** -### **1.1 请求过程说明** -1.1 构造请求数据,用户数据按照Asch提供的接口规则,通过程序生成签名,生成请求数据集合; -1.2 发送请求数据,把构造完成的数据集合通过POST/GET等提交的方式传递给Asch; -1.3 Asch对请求数据进行处理,服务器在接收到请求后,会首先进行安全校验,验证通过后便会处理该次发送过来的请求; -1.4 返回响应结果数据,Asch把响应结果以JSON的格式反馈给用户,每个响应都包含success字段,表示请求是否成功,成功为true, 失败为false。 如果失败,则还会包含一个error字段,表示错误原因; -1.5 对获取的返回结果数据进行处理; - ---- - -## **2 接口** -### **2.1 账户accounts** - -#### **2.1.1 登录** -##### **2.1.1.1 本地加密后再登陆(推荐使用)** -接口地址:/api/accounts/open2/ -请求方式:post -支持格式:json -接口备注:根据用户密码在本地客户端用js代码生成公钥 - -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|publicKey |string |Y |asch账户公钥 | - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否登陆成功 | -|account|json |账户信息 | -请求示例: - -```js -var secret = 'Asch账户密码' //在浏览器内存中保留 -var AschJS = require('asch-js'); //asch-js具体安装方法见附录 -var publicKey = AschJS.crypto.getKeys(secret).publicKey; //根据密码生成公钥 -// var address = AschJS.crypto.getAddress(publicKey); //根据公钥生成地址 - -// 将上面生成的数据通过post提交到asch server -curl -X POST -H "Content-Type: application/json" -k -d '{"publicKey":"bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9"}' http://45.32.248.33:4096/api/accounts/open2/ -``` - -JSON返回示例: -```js -{ - "success": true, - "account": { - "address": "16723473400748954103", //asch地址 - "unconfirmedBalance": 19480000000, //未确认和已确认的余额之和,该值大于等于balance - "balance": 19480000000, //余额 - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9", //公钥 - "unconfirmedSignature": false, - "secondSignature": true, //二级签名 - "secondPublicKey": "edf30942beb74de5ed6368c792af8665e9636f32a5f1c9377bcdc3b252d3f277", //二级密码公钥 - "multisignatures": [], - "u_multisignatures": [], - "lockHeight: ": 0 // 锁仓高度 - }, - "latestBlock": { - "height": 114480, //当前节点最新区块高度 - "timestamp": 4471890 - }, - "version": { - "version": "1.0.0", //当前节点版本号 - "build": "12:11:11 16/08/2016", //构建日期 - "net": "testnet" //区块链类型,是主链还是测试链 - } -} -``` - -##### **2.1.1.2 本地不加密直接登陆** -接口地址:/api/accounts/open/ -请求方式:post -支持格式:json -接口备注:将密码传入到server端,根据生成的地址去查询账户信息。不推荐在公网坏境使用! -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|secret |string |Y |asch账户密码 | - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否登陆成功 | -|account|json |账户信息 | - -请求示例: -```bash -curl -X POST -H "Content-Type: application/json" -k -d '{"secret":"fault still attack alley expand music basket purse later educate follow ride"}' http://45.32.248.33:4096/api/accounts/open/ -``` - -JSON返回示例: -```js -{ - "success": true, - "account": { - "address": "16723473400748954103", - "unconfirmedBalance": 19480000000, - "balance": 19480000000, - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9", - "unconfirmedSignature": false, - "secondSignature": true, - "secondPublicKey": "edf30942beb74de5ed6368c792af8665e9636f32a5f1c9377bcdc3b252d3f277", - "multisignatures": [ ], - "u_multisignatures": [ ] - } -} -``` -#### **2.1.2 根据地址获取账户信息** -接口地址:/api/accounts -请求方式:get -支持格式:urlencoded -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|address |string |Y |用户地址,最小长度:1 | - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|account|json |账户信息 | -|latestBlock|json |该节点最新的区块信息 | -|version|json |版本相关信息 | - -请求示例: -```bash -curl -k -X GET http://45.32.248.33:4096/api/accounts?address=16723473400748954103 -``` - -JSON返回示例: -```js -{ - "success": true, - "account": { - "address": "16723473400748954103", //asch地址 - "unconfirmedBalance": 19480000000, //未确认和已确认的余额之和,该值大于等于balance - "balance": 19480000000, //余额 - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9", //公钥 - "unconfirmedSignature": false, - "secondSignature": true, //二级签名 - "secondPublicKey": "edf30942beb74de5ed6368c792af8665e9636f32a5f1c9377bcdc3b252d3f277", //二级密码公钥 - "multisignatures": [], - "u_multisignatures": [], - "lockHeight: ": 0 // 锁仓高度 - }, - "latestBlock": { - "height": 114480, //当前节点最新区块高度 - "timestamp": 4471890 - }, - "version": { - "version": "1.0.0", //当前节点版本号 - "build": "12:11:11 16/08/2016", //构建日期 - "net": "testnet" //区块链类型,是主链还是测试链 - } -} -``` -#### **2.1.3 获取账户余额** -接口地址:/api/accounts/getBalance -请求方式:get -支持格式:urlencoded -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|address |string |Y |用户地址,最小长度:1 | - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|balance|integer |余额 | -|unconfirmedBalance|integer|未确认和已确认的余额之和,该值大于等于balance| - - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/accounts/getBalance?address=14636456069025293113' -``` - -JSON返回示例: -```js -{ - "success": true, - "balance": 5281328514990, - "unconfirmedBalance": 5281328514990 -} -``` - -#### **2.1.4 根据地址获取账户公钥** -接口地址:/api/accounts/getPublickey -请求方式:get -支持格式:urlencoded -请求参数说明:只有给别人转过账,db中才会存取公钥,否则是查不到的。btc也是这样 - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|address |string |Y |用户地址,最小长度:1 | - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|publicKey|string |公钥 | - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/accounts/getPublickey?address=14636456069025293113' -``` - -JSON返回示例: -```js -{ - "success": true, - "publicKey": "ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7" -} -``` - -#### **2.1.5 生成公钥** -接口地址:/api/accounts/generatePublickey -请求方式:post -支持格式:json -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|secret |string |Y |asch账户密码 | - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|publicKey|string |公钥 | - -请求示例: -```bash -curl -k -H "Content-Type: application/json" -X POST -d '{"secret":"fault still attack alley expand music basket purse later educate follow ride"}' 'http://45.32.248.33:4096/api/accounts/generatePublickey' -``` - -JSON返回示例: -```js -{ - "success": true, - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9" -} -``` - -#### **2.1.6 根据地址获取其投票列表** -接口地址:/api/accounts/delegates -请求方式:get -支持格式:urlencoded -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|address |string |Y |投票人地址 | - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|delegates|Array |已投票的受托人详情数组 | - - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/accounts/delegates?address=14636456069025293113' -``` - -JSON返回示例: -```js -{ - "success": true, - "delegates": [{ - "username": "wgl_002", - "address": "14636456069025293113", - "publicKey": "ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7", - "vote": 9901985415600500, - "producedblocks": 1373, - "missedblocks": 6, - "rate": 1, - "approval": "98.54", - "productivity": "99.56" - }, - { - "username": "wgl_003", - "address": "9961157415582672274", - "publicKey": "c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2", - "vote": 9891995435600500, - "producedblocks": 1371, - "missedblocks": 8, - "rate": 2, - "approval": "98.44", - "productivity": "99.41" - }, - { - "username": "wgl_001", - "address": "1869971419039689816", - "publicKey": "c547df2dde6cbb4508aabcb5970d8f9132e5a1d1c422632da6bc20bf1df165b8", - "vote": 32401577128413, - "producedblocks": 969, - "missedblocks": 8, - "rate": 102, - "approval": "0.32", - "productivity": 0 - }] -} -``` - -#### **2.1.7 获取受托人手续费设置** -接口地址:/api/accounts/delegates/fee -请求方式:get -支持格式:无 -请求参数说明:无 - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|fee|integer |手续费 | - - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/accounts/delegates/fee -``` - -JSON返回示例: -```js -{ - "success": true, - "fee": 100000000 // 0.1 XAS -} -``` - - -#### **2.1.8 给受托人投票** -接口地址:/api/accounts/delegates -请求方式:put -支持格式:json -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|secret |string |Y |asch账户密码 | -|publicKey|string |N|公钥 | -|secondSecret|string|N|asch账户二级密码,最小长度:1,最大长度:100| -|delegates|Array|受托人公钥数组,每个公钥前需要加上+或者-号,代表增加/取消对其的投票| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transaction|json |投票交易详情 | - - -请求示例: -```bash -curl -k -H "Content-Type: application/json" -X PUT -d '{"secret":"call scissors pupil water friend timber spend brand vote obey corn size","publicKey":"3ec1c9ec08c0512641deba37c0e95a0fe5fc3bdf58424009f594d7d6a4e28a2a","delegates":["+fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575"]}' 'http://45.32.248.33:4096/api/accounts/delegates' -``` - -JSON返回示例: -```js - { - "success": true, - "transaction": { - "type": 3, //投票的交易类型为3 - "amount": 0, - "senderPublicKey": "3ec1c9ec08c0512641deba37c0e95a0fe5fc3bdf58424009f594d7d6a4e28a2a", - "requesterPublicKey": null, - "timestamp": 5056064, - "asset": { - "vote": { - "votes": ["+fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575"] - } - }, - "recipientId": null, - "signature": "0bff58c7311fc59b3c8b3ffc236bbfece9850c334fb0c292ab087f78cf9a6c0f4d3e541c501887a2c2ec46294c777e8f7bf7dea9cb7c9a175fdec641bb684f08", - "id": "5630629337798595849", - "fee": 10000000, - "senderId": "15238461869262180695" - } -} -``` - - -#### **2.1.9 生成新账户** -接口地址:/api/accounts/new -请求方式:get -支持格式:无 -请求参数:无 - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|secret|string |密码 | -|publicKey|string |公钥 | -|privateKey|string |私钥 | -|address|string |地址 | - - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/accounts/new' -``` - -JSON返回示例: -```js -{ - success: true, - secret: "during crush zoo wealth horror left night upset spike iron divert lawn", // 密码 - publicKey: "261fa56f389c324fddbe8777dbc0ef3341ee7b75d1ffdc82192265633b90d503", // 公钥 - privateKey: "67c9523b7622704c4bcfe960cb32d7fa04d3eb94e30e7964d3c6a24a3647a0a3261fa56f389c324fddbe8777dbc0ef3341ee7b75d1ffdc82192265633b90d503", // 私钥 - address: "ANfXDQUZroMnrQ6vRGR7UXXtbPn3fhEVRJ" // 地址 -} -``` - - -#### **2.1.10 获取账户排行榜前100名** -接口地址:/api/accounts/top -请求方式:get -支持格式:无 -请求参数说明:如果不加请求参数则返回持币量前100名账户信息 - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|limit |integer |N |限制结果集个数,最小值:0,最大值:100 | -|offset|integer |N |偏移量,最小值0 | - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|accounts|json |账户信息元组,每个元素包含地址、余额、公钥 | - - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/accounts/top?limit=5&offset=0' //返回前5名账户信息 -``` - -JSON返回示例: -```js -{ - "success": true, - "accounts": [{ - "address": "355198157736313687", - "balance": 4400099900000000, //44000999 XAS - "publicKey": "0b8e120db026d58cbf9d3f392f88eefe3a82a0a3023298b9466d7ed64ff05881" - }, - { - "address": "3196144307608101364", - "balance": 3750000020000000, - "publicKey": "988eb82a603dd033f94a4f3b6f9f9ef4a7d3d066607c433e5255d50ea7270720" - }, - { - "address": "9248745407080572308", - "balance": 988703397029757, - "publicKey": "02cedc56da08099532e312c5e563e2859bc5b93cc594eb3e5d350f368d681988" - }, - { - "address": "15745540293890213312", - "balance": 498186229718623, - "publicKey": "d39d6f26869067473d685da742339d1a9117257fe14b3cc7261e3f2ed5a339e3" - }, - { - "address": "8812460086240160222", - "balance": 100704426831866, - "publicKey": "0af92cc32f54d50dd83c4f7de14e71223a57843a40e993bc0813454aa9270053" - } -} -``` - - -#### **2.1.11 获取当前链上账户总个数** -接口地址:/api/accounts/count -请求方式:get -支持格式:无 -请求参数:无 - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|count|integer |当前链上账户总个数 | - - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/accounts/count' -``` - -JSON返回示例: -```js -{ - success: true, - count: 105 -} -``` - - -### **2.2 交易transactions** -#### **2.2.1 获取交易信息** -接口地址:/api/transactions -请求方式:get -支持格式:urlencoded -接口备注:如果请求不加参数则会获取全网所有交易 -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|and|integer|N|取值范围0和1,默认值0。select查询时下面这些条件都是or的关系,and=1时select是and的关系 | -|blockId |string |N |区块id | -|limit |integer |N |限制结果集个数,最小值:0,最大值:100 | -|type|integer |N |交易类型,0:普通转账,1:设置二级密码,2:注册受托人,3:投票,4:多重签名,5:DAPP,6:IN_TRANSFER,7:OUT_TRANSFER | -|orderBy|string |N |根据表中字段排序,senderPublicKey:desc | -|offset|integer |N |偏移量,最小值0 | -|senderPublicKey|string|N|发送者公钥| -|ownerPublicKey|string|N|| - ownerAddress|string|N|| -|senderId|string|N|发送者地址| -|recipientId|string|N|接收者地址,最小长度:1| -|amount|integer|N|金额| -|fee|integer|N|手续费| -|uia|integer|N|是否uia,0:不是,1:是| -|currency|string|N|资产名| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transactions|列表 |多个交易详情json构成的列表 | -|count|int|获取到的交易总个数| - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/transactions?recipientId=16723473400748954103&orderBy=t_timestamp:desc&limit=3' -``` - -JSON返回示例: -```js -{ - "success": true, - "transactions": [{ - "id": "17192581936339156329", - "height": "105951", - "blockId": "15051364118100195665", - "type": 0, - "timestamp": 4385190, - "senderPublicKey": "d39d6f26869067473d685da742339d1a9117257fe14b3cc7261e3f2ed5a339e3", - "senderId": "15745540293890213312", - "recipientId": "16723473400748954103", - "amount": 10000000000, - "fee": 10000000, - "signature": "98d65df3109802c707eeed706e90a907f337bddab58cb4c1fbe6ec2179aa1c85ec2903cc0cf44bf0092926829aa5a0a6ec99458f65b6ebd11f0988772e58740e", - "signSignature": "", - "signatures": null, - "confirmations": "31802", - "asset": { - - } - }, - { - "id": "7000452951235123088", - "height": "105473", - "blockId": "11877628176330539727", - "type": 0, - "timestamp": 4380147, - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "senderId": "16358246403719868041", - "recipientId": "16723473400748954103", - "amount": 10000000000, - "fee": 10000000, - "signature": "dc84044d4f6b4779eecc3a986b6507e458cc5964f601ebeb4d3b68a96129813f4940e14de950526dd685ca1328b6e477e6c57e95aeac45859a2ea62a587d0204", - "signSignature": "", - "signatures": null, - "confirmations": "32280", - "asset": { - - } - }, - { - "id": "14093929199102906687", - "height": "105460", - "blockId": "2237504897174225512", - "type": 0, - "timestamp": 4380024, - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "senderId": "16358246403719868041", - "recipientId": "16723473400748954103", - "amount": 10000000000, - "fee": 10000000, - "signature": "73ceddc3cbe5103fbdd9eee12f7e4d9a125a3bcf2e7cd04282b7329719735aeb36936762f17d842fb14813fa8f857b8144040e5117dffcfc7e2ae88e36440a0f", - "signSignature": "", - "signatures": null, - "confirmations": "32293", - "asset": { - - } - }], - "count": 3 -} -``` -#### **2.2.2 根据交易id查看交易详情** -接口地址:/api/transactions/get -请求方式:get -支持格式:urlencoded -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|Id |string |Y |交易id | - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transactions|json |交易详情 | - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/transactions/get?id=14093929199102906687' -``` - -JSON返回示例: -```js -{ - "success": true, - "transaction": { - "id": "14093929199102906687", // 交易id - "height": "105460",// 该交易所在区块高度 - "blockId": "2237504897174225512",// 所在区块id - "type": 0,// 交易类型,0:普通XAS转账 - "timestamp": 4380024,// 距离阿希创世块的timestamp - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", // 发送者公钥 - "senderId": "16358246403719868041",// 发送者地址 - "recipientId": "16723473400748954103",// 接收者地址 - "amount": 10000000000,// 交易额,100XAS - "fee": 10000000, // 手续费0.1XAS - "signature": "73ceddc3cbe5103fbdd9eee12f7e4d9a125a3bcf2e7cd04282b7329719735aeb36936762f17d842fb14813fa8f857b8144040e5117dffcfc7e2ae88e36440a0f", - "signSignature": "", - "signatures": null, - "confirmations": "34268",// 确认数 - "asset": { - } - } -} -``` - -#### **2.2.3 根据未确认交易id查看详情** -接口地址:/api/transactions/unconfirmed/get -请求方式:get -支持格式:urlencoded -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|id|string |Y |未确认交易id | - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transaction|json |未确认交易详情 | - - -请求示例: -```bash -curl -k -X GET http://45.32.248.33:4096/api/transactions/unconfirmed/get?id=7557072430673853692 // 正常情况,该未确认交易存在时间极短0~10秒 -``` - -JSON返回示例: -```js -{ - "success": true, - "transaction": { - "type": 0, - "amount": 10000, - "senderPublicKey": "3ec1c9ec08c0512641deba37c0e95a0fe5fc3bdf58424009f594d7d6a4e28a2a", - "requesterPublicKey": null, - "timestamp": 5082322, - "asset": { - - }, - "recipientId": "16723473400748954103", - "signature": "3a97f8d63509ef964bda3d816366b8e9e2d9b5d4604a660e7cbeefe210cb910f5de9a51bece06c32d010f55502c62f0f59b8224e1c141731ddfee27206a88d02", - "id": "7557072430673853692", - "fee": 10000000, - "senderId": "15238461869262180695" - } -} -``` - - -#### **2.2.4 获取[全网所有]未确认的交易详情** -接口地址:/api/transactions/unconfirmed -请求方式:get -支持格式:urlencoded -接口说明:如果不加参数,则会获取全网所有未确认交易 -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|senderPublicKey |string |N |发送者公钥 | -|address |string |N |地址 | - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transactions|Array |未确认交易列表 | - - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/transactions/unconfirmed' -``` - -JSON返回示例: -```js -{ - "success": true, - "transactions": [] //全网目前不存在未确认的交易 -} -``` - -#### **2.2.5 创建交易并广播** -接口地址:/api/transactions -请求方式:PUT -支持格式:json - -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|secret |string |Y |asch账户密码 | -|amount|integer|Y|金额,最小值:1,最大值:10000000000000000| -|recipientId|string|Y|接收者地址,最小长度:1| -|publicKey|string|N|发送者公钥| -|secondSecret|string|N|发送者二级密码,最小长度1,最大长度:100| -|multisigAccountPublicKey|string|N|多重签名账户公钥| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transactionId|string |交易id | - - -请求示例: -```bash -curl -k -H "Content-Type: application/json" -X PUT -d '{"secret":"unaware label emerge fancy concert long fiction report affair appear decide twenty","amount":1000000,"recipientId":"16723473400748954103"}' 'http://45.32.248.33:4096/api/transactions' -``` - -JSON返回示例: -```js -{ - "success": true, - "transactionId": "16670272591943275531" -} -``` - -### **2.3 区块blocks** -#### **2.3.1 获取指定区块的详情** -接口地址:/api/blocks/get -请求方式:get -支持格式:urlencoded -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|id |string |参数3选1 |区块id | -|height|string|参数3选1|区块高度| -|hash|string|参数3选1|区块hash| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|block|json |区块详情 | - - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/get?id=6076474715648888747' -``` - -JSON返回示例: -```js -{ - "success": true, - "block": { - "id": "6076474715648888747", - "version": 0, - "timestamp": 4734070, - "height": 140538, - "previousBlock": "16033230167082515105", //上一个区块id - "numberOfTransactions": 0, //交易数 - "totalAmount": 0, //交易额 - "totalFee": 0, - "reward": 350000000, //奖励 - "payloadLength": 0, - "payloadHash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "generatorPublicKey": "1d352950c8141e1b35daba4a974a604519d7a2ef3a1ec0a503ce2653646aa052", - "generatorId": "6656029629904254066", - "blockSignature": "a53de66922cdc2f431acd0a474beec7cf7c420a8460b7b7caf84999be7caebb59fb7fbb7166c2c7013dbb431585ea7294722166cb08bf9663abf50b6bd81cd05", - "confirmations": "2", - "totalForged": 350000000 - } -} -``` - -#### **2.3.2 获取区块数据** -接口地址:/api/blocks -请求方式:get -支持格式:urlencoded -接口说明:不加参数则获取全网区块详情 -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|limit |integer |N |限制结果集个数,最小值:0,最大值:100 | -|orderBy|string |N |根据表中字段排序,如height:desc | -|offset|integer |N |偏移量,最小值0 | -|generatorPublicKey|string |N |区块生成者公钥 | -|totalAmount|integer |N |交易总额,最小值:0,最大值:10000000000000000 | -|totalFee|integer |N |手续费总额,最小值:0,最大值:10000000000000000 | -|reward|integer |N |奖励金额,最小值:0 | -|previousBlock|string |N |上一个区块 | -|height|integer |N |区块高度 | - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|blocks|Array |由区块详情json串构成的数组 | -|count|integer|区块链高度| - - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks?limit=2&offset=0&orderBy=height:desc' -``` - -JSON返回示例: -```js -{ - "success": true, - "blocks": [{ - "id": "12634047624004615059", - "version": 0, - "timestamp": 4708080, - "height": 137986, - "previousBlock": "3498191422350401106", - "numberOfTransactions": 0, // 交易数 - "totalAmount": 0, // 金额 - "totalFee": 0, // 手续费 - "reward": 350000000, // 奖励 - "payloadLength": 0, - "payloadHash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "generatorPublicKey": "44db7bec89ef289d0def257285675ca14f2a947dfd2b70e6b1cff4392ce42ada", - "generatorId": "4925169939071346193", - "blockSignature": "83a2124e3e8201c1a6099b2ac8ab1c117ad34867978add3a90d41a64df9d2ad8fabc9ec14d27a77cd34c08a6479ef684f247c11b1cbbcb0e9767dffc85838600", - "confirmations": "1", - "totalForged": 350000000 - }, - { - "id": "3498191422350401106", - "version": 0, - "timestamp": 4708070, - "height": 137985, - "previousBlock": "14078155423801039323", - "numberOfTransactions": 0, - "totalAmount": 0, - "totalFee": 0, - "reward": 350000000, - "payloadLength": 0, - "payloadHash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "generatorPublicKey": "500b1ec025cd64d36008341ed8d2508473ecf559be213ca5f9580620a21a592c", - "generatorId": "16006295608945777169", - "blockSignature": "a0b5ed6c94b1f33c4d0f017f21a08357061493392b19e34eeedf274b77c751e3f86c92443280de09ea1754d62fe7ef00e02acbdc3bc0c1063cef344bacaa4f07", - "confirmations": "2", - "totalForged": 350000000 - }], - "count": 137986 -} -``` - -#### **2.3.3 获取区块链高度** -接口地址:/api/blocks/getHeight -请求方式:get -支持格式:无 -请求参数说明:无 - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|height|integer |区块链高度 | - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/getheight' -``` - -JSON返回示例: -```js -{"success":true,"height":140569} -``` - -#### **2.3.4 获取普通转账手续费** -接口地址:/api/blocks/getFee -请求方式:get -支持格式:无 -请求参数说明:无 - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|fee|integer |交易手续费 | - - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/getfee' -``` - -JSON返回示例: -```js -{"success":true,"fee":10000000} //手续费为0.1 XAS -``` - -#### **2.3.5 获取里程碑** -接口地址:/api/blocks/getMilestone -请求方式:get -支持格式:无 -请求参数说明:无 -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|milestone|integer | | - - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/getMilestone' -``` - -JSON返回示例: -```js -{"success":true,"milestone":0} -``` - -#### **2.3.6 查看单个区块奖励** -接口地址:/api/blocks/getReward -请求方式:get -支持格式:无 -请求参数说明:无 - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|reward|integer |区块奖励,包含受托人奖励和手续费 | - - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/getReward' -``` - -JSON返回示例: -```js -{"success":true,"reward":350000000} //每个生成一个block奖励3.5 XAS -``` - -#### **2.3.7 获取XAS当前供应值** -接口地址:/api/blocks/getSupply -请求方式:get -支持格式:无 -请求参数说明:无 - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|supply|integer |全网XAS个数 | - - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/getSupply' -``` - -JSON返回示例: -```js -{"success":true,"supply":10049222600000000} //当前testnet共有100492226XAS -``` - -#### **2.3.8 区块链状态** -接口地址:/api/blocks/getStatus -请求方式:get -支持格式:无 -请求参数说明:无 - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|height|integer |区块链高度 | -|fee|integer |交易手续费 | -|milestone|integer | | -|reward|integer |区块奖励 | -|supply|integer |全网XAS个数 | - - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/getStatus' -``` - -JSON返回示例: -```js -{ - "success": true, - "height": 140649, - "fee": 10000000, - "milestone": 0, - "reward": 350000000, - "supply": 10049227150000000 -} -``` - - -#### **2.3.9 获取指定区块的交易信息** -接口地址:/api/blocks/full -请求方式:get -支持格式:无 -请求参数说明:无 - - -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |---- |---- | -|id |string |参数2选1 |区块id | -|height|string|参数2选1|区块高度| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|block|json |区块详情,包含交易信息transactions | - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/full?height=2392' -``` - -JSON返回示例: -```js -{ - success: true, - block: { - id: "99773e6fc4feddc2d876427701ce2b52aabfefc8b54a5a8560ed237acb1c9565", - version: 0, - timestamp: 39605950, - height: 2392, - previousBlock: "436ca0351028854792ca63862e01b5285b017dd40bc8748a97c1de034e97817f", - numberOfTransactions: 1, - totalAmount: 100000000, - totalFee: 10000000, - reward: 350000000, - payloadLength: 117, - payloadHash: "07af33c345f733e5224877b290888db2faab26e779e784881fadb086148335f1", - generatorPublicKey: "1b36e7183125e3de33a4d778c5a705d4e6180e426b15f4737b18d1e09c150a42", - generatorId: "8280768395963849562", - blockSignature: "59b292c97e68f8a0fc311c0894e79e1fe23613b2387f42e389e0b5f4aba61847fb13feb8153578b3eb37d6249c13347001cce9c4d06ae521b6c8cefedb829804", - totalForged: 360000000, - transactions: [{ // 该区块包含的交易信息数组 - id: "07af33c345f733e5224877b290888db2faab26e779e784881fadb086148335f1", - height: 2392, - blockId: "99773e6fc4feddc2d876427701ce2b52aabfefc8b54a5a8560ed237acb1c9565", - type: 0, - timestamp: 39605935, - senderPublicKey: "8065a105c785a08757727fded3a06f8f312e73ad40f1f3502e0232ea42e67efd", - requesterPublicKey: "", - senderId: "14762548536863074694", - recipientId: "1", - amount: 100000000, - fee: 10000000, - signature: "72b72b3db7eb86436a32bff72f19f89fffc51e10f73ca19536968e70d34c38efd24e96ce43e5d4981a23b07849c9baa20263aeadd9dbbbad233c3efa2fa97100", - signSignature: "", - signatures: null, - args: null, - message: "", - asset: { - - } - }] - } -} -``` - - -### **2.4 受托人delegates** - -#### **2.4.1 获取受托人总个数** -接口地址:/api/delegates/count -请求方式:get -支持格式:无 -请求参数说明:无 - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|count|integer |受托人总个数 | - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/delegates/count' -``` - -JSON返回示例: -```js -{ - "success": true, - "count": 234 -} -``` - -#### **2.4.2 根据受托人公钥查看哪些人为其投了票** -接口地址:/api/delegates/voters -请求方式:get -支持格式:urlencoded -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|publicKey |string |Y |受托人公钥 | - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|accounts|Array |账户json串组成的数组 | - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/delegates/voters?publicKey=ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7' -``` - -JSON返回示例: -```js -{ - "success": true, - "accounts": [{ - "address": "2918354313445278349", - "publicKey": "4fde4c49f1297d5d3a24b1494204543c4281aff17917ff7ff8ff32da3b4b222f", - "balance": 1338227722727, - "weight": 0.013316660647014596 - }, - { - "address": "1523444724068322527", - "publicKey": "8a6a61c28dc47541aadf1eecec2175c8f768f2331eea3472b1593bf1aa4e1fb4", - "balance": 2109297623765, - "weight": 0.020989552213127274 - }, - { - "address": "14483826354741911727", - "publicKey": "5dacb7983095466b9b037690150c3edec0f073815326e33a4744b6d1d50953e2", - "balance": 5135815841470, - "weight": 0.051106336795243436 - } - }] -} -``` - -#### **2.4.3 根据公钥或者用户名获取受托人详情** -接口地址: /api/delegates/get -请求方式:get -支持格式:urlencoded -接口备注:通过公钥或者用户名获取受托人信息 -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|publickey |string |二选一 |受托人公钥 | -|username |string |二选一 |受托人用户名 | - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|delegate|json |委托人详情 | - - -请求示例: -```bash -curl -k -X GET http://45.32.248.33:4096/api/delegates/get?publicKey=bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9 -curl -k -X GET http://45.32.248.33:4096/api/delegates/get?username=delegate_register -``` - -JSON返回示例: -```js -{ - "success": true, - "delegate": { - "username": "delegate_register", - "address": "16723473400748954103", - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9", - "vote": 0, - "producedblocks": 0, - "missedblocks": 0, - "fees": 0, - "rewards": 0, - "rate": 191, - "approval": 0, - "productivity": 0, - "forged": "0" - } -} -``` - -#### **2.4.4 获取受托人列表** -接口地址:/api/delegates -请求方式:get -支持格式:urlencoded -接口说明:如果不加参数则会返回全网受托人列表 -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|address |string |N |受托人地址 | -|limit|int |N |限制返回结果数据集的个数 | -|offset|integer |N |偏移量,最小值:0 | -|orderBy|string |N |排序字段:排序规则,如:desc | - - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|delegates|Array |受托人详情列表 | - - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/delegates?orderby=approval:desc&limit=2' //按照得票率降序排序,取出前2名 -``` - -JSON返回示例: -```js -{ - "success": true, - "delegates": [{ - "username": "wgl_002", //受托人名字 - "address": "14636456069025293113", //受托人地址 - "publicKey": "ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7", //受托人公钥 - "vote": 9901984015600500, //得票数 - "producedblocks": 1371, //生成的区块数 - "missedblocks": 6, //丢失的区块数 - "fees": 12588514990, - "rewards": 276850000000, //已经得到的奖励 - "rate": 1, - "approval": 98.54, //得票率 - "productivity": 99.56, //生产率 - "forged": "289438514990" //锻造产生的所有奖励 - }, - { - "username": "wgl_003", - "address": "9961157415582672274", - "publicKey": "c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2", - "vote": 9891994035600500, - "producedblocks": 1370, - "missedblocks": 8, - "fees": 12355148480, - "rewards": 275100000000, - "rate": 2, - "approval": 98.44, - "productivity": 99.42, - "forged": "287455148480" - }], - "totalCount": 233 -} -``` - - -#### **2.4.5 获取受托人设置的转账费** -接口地址:/api/delegates/fee -请求方式:get -支持格式:urlencoded -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|publicKey |string |Y |受托人公钥 | - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|fee|integer |转账费 | - - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/delegates/fee?publicKey=ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7' -``` - -JSON返回示例: -```js -{"success":true,"fee":10000000000} //0.1 XAS -``` - -#### **2.4.6 根据公钥查看其锻造情况** -接口地址:/api/delegates/forging/getForgedByAccount -请求方式:get -支持格式:urlencoded -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|generatorPublicKey |string |Y |区块生成者公钥 | - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|fees|integer |收取的手续费 | -|rewards|integer|已获得奖励| -|forged|integer|锻造获得的总奖励| - - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/delegates/forging/getForgedByAccount?generatorPublicKey=ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7' -``` - -JSON返回示例: -```js -{ - "success": true, - "fees": 12589307065, - "rewards": 285600000000, - "forged": 298189307065 -} -``` - -#### **2.4.7 注册受托人** -接口地址:/api/delegates -请求方式:put -支持格式:urlencoded -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|secret |string |Y |asch账户密码 | -|publicKey|string |N |公钥| -|secondSecret|string|N|asch账户二级密码,最小长度:1,最大长度:100| -|username|string|N|受托人名字| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transaction|json |注册受托人交易详情 | - - -请求示例: -```bash -curl -k -H "Content-Type: application/json" -X PUT -d '{"secret":"unaware label emerge fancy concert long fiction report affair appear decide twenty","username":"delegate_0821"}' 'http://45.32.248.33:4096/api/delegates' -``` - -JSON返回示例: -```js -{ - "success": true, - "transaction": { - "type": 2, //注册受托人的交易类型为2 - "amount": 0, - "senderPublicKey": "3b64f1833e6328043e1f2fee31e638bdaa6dfff5c7eb9c8577a5cefcf11261f2", - "requesterPublicKey": null, - "timestamp": 4737615, - "asset": { - "delegate": { - "username": "delegate_0821", - "publicKey": "3b64f1833e6328043e1f2fee31e638bdaa6dfff5c7eb9c8577a5cefcf11261f2" - } - }, - "recipientId": null, - "signature": "7f8417e8db5f58ddff887c86c789c26b32fd3f01083ef1e3c8d4e18ed16622bf766492d78518c6c7a07aada1c98b1efc36d40c8e09394989dbde229d8e3f8103", - "id": "16351320834453011577", - "fee": 10000000000, - "senderId": "250438937633388106" - } -} -``` - -#### **2.4.8 受托人开启锻造** -接口地址:/api/delegates/forging/enable -请求方式:post -支持格式:urlencoded // url必须是受托人所在服务器 -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|secret |string |Y |asch账户密码 | -|publicKey|string |N |公钥| - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|address|string |受托人地址 | - - -请求示例: -```bash -curl -k -H "Content-Type: application/json" -X POST -d '{"secret":"motion group blossom coral upper warrior pattern fragile sister misery palm detect"}' 'http://localhost:4096/api/delegates/forging/enable' -``` - -JSON返回示例: -```js -{"success":true,"address":"16358246403719868041"} -``` - -#### **2.4.9 受托人关闭锻造** -接口地址:/api/delegates/forging/disable -请求方式:post -支持格式:urlencoded // url必须是受托人所在服务器 -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|secret |string |Y |asch账户密码 | -|publicKey|string |N |公钥| - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|address|string |受托人地址 | - - -请求示例: -```bash -curl -k -H "Content-Type: application/json" -X POST -d '{"secret":"motion group blossom coral upper warrior pattern fragile sister misery palm detect"}' 'http://localhost:4096/api/delegates/forging/disable' -``` - -JSON返回示例: -```js -{"success":true,"address":"16358246403719868041"} -``` - -#### **2.4.10 受托人锻造状态查看** -接口地址:/api/delegates/forging/status -请求方式:get -支持格式:urlencoded -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|publicKey|string |Y |公钥| - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|enabled|string |锻造是否开启 | - - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/delegates/forging/status?publicKey=fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575' -``` - -JSON返回示例: -```js -{"success":true,"enabled":false} -``` - -### **2.5 节点peers** - -#### **2.5.1 获取本机连接的所有节点信息** -接口地址:/api/peers -请求方式:get -支持格式:urlencoded -备注:展示节点只是和本机有连接的节点,并不是全网所有的节点 -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|state |integer |N |节点状态,0: ,1:,2:,3: | -|os|string|N|内核版本| -|version|string|N|asch版本号| -|limit |integer |N |限制结果集个数,最小值:0,最大值:100 | -|orderBy|string|N|| -|offset|integer |N |偏移量,最小值0 | -|port|integer|N|端口,1~65535| - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|peers|Array |节点信息json构成的数组 | -|totalCount|integer|当前正在运行的节点个数| - - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/peers?limit=1' -``` - -JSON返回示例: -```js -{ - "success": true, - "peers": [{ - "ip": "45.32.19.241", - "port": 4096, - "state": 2, - "os": "linux3.13.0-87-generic", - "version": "1.0.0" - }], - "totalCount": ["54"] -} -``` - -#### **2.5.2 获取本节点版本号等信息** -接口地址:/api/peers/version -请求方式:get -支持格式:无 -请求参数说明:无参数 - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|version|string |版本号 | -|build |timestamp |构建时间 | -|net |string |主链或者测试链 | - - -请求示例: -```bash -curl -k -X GET http://45.32.248.33:4096/api/peers/version -``` - -JSON返回示例: -```js -{ - "success": true, - "version": "1.0.0", - "build": "12:11:11 16/08/2016", - "net": "testnet" -} -``` - -#### **2.5.3 获取指定ip节点信息** -接口地址:/api/peers/get -请求方式:get -支持格式:urlencoded -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|ip |string |Y |待查询节点ip | -|port|integer|Y|待查询节点端口,1~65535| - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|peer|json | | - - -请求示例: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/peers/get?ip=45.32.248.33&port=4096' -``` - -JSON返回示例: -```js -{ - "success": true, - "peer": { - } -} -``` - - -### **2.6 同步和加载** -#### **2.6.1 查看本地区块链加载状态** -接口地址:/api/loader/status -请求方式:get -支持格式:无 -请求参数说明:无参数 - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|loaded |boole | | -|blocksCount|integer|| - -请求示例: -```bash -curl -k http://45.32.248.33:4096/api/loader/status -X GET -``` - -JSON返回示例: -```js -{ - "success": true, - "loaded": true, - "blocksCount": 0 -} -``` - -#### **2.6.2 查看区块同步信息** -接口地址:/api/loader/status/sync -请求方式:get -支持格式:无 -请求参数说明:无参数 - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|height |int |区块高度 | - -请求示例: -```bash -curl -k http://45.32.248.33:4096/api/loader/status/sync -X GET -``` - -JSON返回示例: -```js -{ - "success": true, - "syncing": false, // 是否在同步中,如果是则为true,目前没有数据可以同步所以为false - "blocks": 0, - "height": 111987 -} -``` - -### **2.7 二级密码signatures** -#### **2.7.1 设置二级密码** -接口地址:/api/signatures -请求方式:put -支持格式:json -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|secret |string |Y |asch账户密码 | -|publicKey|string |N|公钥 | -|secondSecret|string|Y|asch账户二级密码,最小长度:1,最大长度:100| -|multisigAccountPublicKey|string|N|多重签名账户公钥| - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transaction|json |设置二级密码产生的交易详情 | - - -请求示例: -```bash -curl -k -H "Content-Type: application/json" -X PUT -d '{"secret":"unaware label emerge fancy concert long fiction report affair appear decide twenty","secondSecret":"fault still attack alley expand music basket purse later educate follow ride"}' 'http://45.32.248.33:4096/api/signatures' -``` - -JSON返回示例: -```js -{ - "success": true, - "transaction": { - "type": 1, //设置二级密码密码的交易类型为1 - "amount": 0, - "senderPublicKey": "3b64f1833e6328043e1f2fee31e638bdaa6dfff5c7eb9c8577a5cefcf11261f2", - "requesterPublicKey": null, - "timestamp": 4872315, - "asset": { - "signature": { - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9" - } - }, - "recipientId": null, - "signature": "e76d9b25ec0fdaa88b19d59c5a222b7efdc04f738ee05896f55f4e6959229d9b1600ca25aa92fbea176668f3be7c12c506f2091e2b38c52ef0ece7a5d35e240a", - "id": "1614688380530105232", - "fee": 500000000, //设置二级密码密码的手续费为5 XAS - "senderId": "250438937633388106" - } -} -``` - -#### **2.7.2 获取二级密码设置手续费** -接口地址:/api/signatures/fee -请求方式:get -支持格式:无 -请求参数说明:无 - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|fee|integer |费用 | - - -请求示例: -```bash -curl -k http://45.32.248.33:4096/api/signatures/fee -X GET -``` - -JSON返回示例: -```js -{ - "success": true, - "fee": 500000000 //5 XAS -} -``` - - -### **2.8 多重签名multisignatures** -#### **2.8.1 设置普通账户为多重签名账户** -接口地址:/api/multisignatures -请求方式:put -支持格式:json -接口说明:返回结果只是生成交易id,还需要其他人签名后该账户才能成功设置成多重签名账户。注册多重签名账户后任意一笔转账都需要多人签名,签名最少个数为min的值(含交易发起人自身) -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|secret |string |Y |asch账户密码 | -|publicKey|string |N|公钥 | -|secondSecret|string|N|asch账户二级密码,最小长度:1,最大长度:100| -|min|integer|Y|多重签名交易账户的任意一笔转账都需要多人签名的最少个数,如果是注册多重签名账户操作,这该值不生效(此时需要所有人都签名)。最小值:2,最大值:16,该值需要小于keysgroup.length+1| -|lifetime|integer|Y|多重签名交易的最大挂起时间,最小值:1,最大值:24,暂时不生效| -|keysgroup|array|Y|其它签名人的公钥数组,每个公钥前需要加上+或者-号,代表增加/删除多重签名账户,数组最小长度:1,数组最大长度:10| - - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transactionId|string |多重签名交易的id | - - -请求示例: -```bash -curl -k -H "Content-Type: application/json" -X PUT -d '{"secret":"vanish deliver message evil canyon night extend unusual tell prosper issue antenna","min":2,"lifetime":1,"keysgroup":["+eb48b9ab7c9a34a9b7cdf860265d65b31af774355cabf1b3a387d14a1925dc97","+d5d7aa157f866c47a2a1e09e2746286ed089fd90976b54fbfa930e87d11609cb"]}' 'http://45.32.248.33:4096/api/multisignatures' //公钥为2cef5711e61bb5361c544077aa08aebc4d962a1d656571901c48d716382ad4fd -``` - -JSON返回示例: -```js -{ - "success": true, - "transactionId": "17620378998277022323" //返回结果只是生成交易id,还需要其他人签名后该账户才能成功设置成多重签名账户 -} -``` - -#### **2.8.2 根据公钥获取挂起的多重签名交易详情** -接口地址:/api/multisignatures/pending -请求方式:get -支持格式:urlencoded -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|publicKey|string |Y|公钥 | - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transactions|Array |交易json组成的数组 | - - -请求示例: -```bash -curl -k -X GET http://45.32.248.33:4096/api/multisignatures/pending?publicKey=2cef5711e61bb5361c544077aa08aebc4d962a1d656571901c48d716382ad4fd -``` - -JSON返回示例: -```js -{ - "success": true, - "transactions": [{ //上一步中设置账户为多重签名交易的详情,transactionId: 17620378998277022323 - "min": 2, - "lifetime": 1, - "signed": true, - "transaction": { - "type": 4, //4代表注册多重签名账户 - "amount": 0, - "senderPublicKey": "2cef5711e61bb5361c544077aa08aebc4d962a1d656571901c48d716382ad4fd", - "requesterPublicKey": null, - "timestamp": 4879978, - "asset": { - "multisignature": { - "min": 2, - "keysgroup": ["+eb48b9ab7c9a34a9b7cdf860265d65b31af774355cabf1b3a387d14a1925dc97", - "+d5d7aa157f866c47a2a1e09e2746286ed089fd90976b54fbfa930e87d11609cb"], - "lifetime": 1 - } - }, - "recipientId": null, - "signature": "a42feaccd9f2a4940fc0be1a1580e786b360f189db3154328f307988e75484293eae391f2f9eee489913cc6d15984eb1f5f5a0aa1bf78ea745d5c725f161af08", - "id": "17620378998277022323", - "fee": 1500000000, - "senderId": "3855903394839129841" - } - }] -} - -``` - -#### **2.8.3 非交易发起人对交易进行多重签名** -接口地址:/api/multisignatures/sign -请求方式:post -支持格式:json -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|secret |string |Y |asch账户密码 | -|secondSecret|string|N|asch账户二级密码,最小长度:1,最大长度:100| -|publicKey|string |N|公钥 | -|transactionId|string|Y|交易id| - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|transactionId|string |多重签名交易id | - - -请求示例: -```bash -curl -k -H "Content-Type: application/json" -X POST -d '{"secret":"lemon carpet desk accuse clerk future oyster essay seminar force live dog","transactionId":"17620378998277022323"}' 'http://45.32.248.33:4096/api/multisignatures/sign' //公钥为eb48b9ab7c9a34a9b7cdf860265d65b31af774355cabf1b3a387d14a1925dc97的用户进行签名 -``` - -JSON返回示例: -```js -{ - "success": true, - "transactionId": "17620378998277022323" -} -// 此时再次获取pending -curl -k -X GET http://45.32.248.33:4096/api/multisignatures/pending?publicKey=2cef5711e61bb5361c544077aa08aebc4d962a1d656571901c48d716382ad4fd -{ - "success": true, - "transactions": [{ - "min": 2, - "lifetime": 1, - "signed": true, - "transaction": { - "type": 4, - "amount": 0, - "senderPublicKey": "2cef5711e61bb5361c544077aa08aebc4d962a1d656571901c48d716382ad4fd", - "requesterPublicKey": null, - "timestamp": 4879978, - "asset": { - "multisignature": { - "min": 2, - "keysgroup": ["+eb48b9ab7c9a34a9b7cdf860265d65b31af774355cabf1b3a387d14a1925dc97", - "+d5d7aa157f866c47a2a1e09e2746286ed089fd90976b54fbfa930e87d11609cb"], - "lifetime": 1 - } - }, - "recipientId": null, - "signature": "a42feaccd9f2a4940fc0be1a1580e786b360f189db3154328f307988e75484293eae391f2f9eee489913cc6d15984eb1f5f5a0aa1bf78ea745d5c725f161af08", - "id": "17620378998277022323", - "fee": 1500000000, - "senderId": "3855903394839129841", - "signatures": ["b38a161264db2a23e353d3fbc4983562f6343d5ee693144543ca54e2bc67c0f73d1c761b7bfa38b2bb101ac2ab0797b674b1a9964ccd400aaa310746c3494d03"] //新生成的多重签名 - } - }] -} - -// 公钥为d5d7aa157f866c47a2a1e09e2746286ed089fd90976b54fbfa930e87d11609cb的账户对该注册交易进行签名 -curl -k -H "Content-Type: application/json" -X POST -d '{"secret":"chalk among elbow piece badge try van round quality position simple teach","transactionId":"17620378998277022323"}' 'http://45.32.248.33:4096/api/multisignatures/sign' -{"success":true,"transactionId":"17620378998277022323"} -// 此时再次获取pending,结果为空 -curl -k -X GET http://45.32.248.33:4096/api/multisignatures/pending?publicKey=2cef5711e61bb5361c544077aa08aebc4d962a1d656571901c48d716382ad4fd -{"success":true,"transactions":[]} -// 查看该注册交易详情(该交易已广播并写入blockchain),此时该账户已成功注册成为多重签名账户 -curl -k -X GET http://45.32.248.33:4096/api/transactions/get?id=17620378998277022323 -{ - "success": true, - "transaction": { - "id": "17620378998277022323", //注册账户为多重签名用户的交易id - "height": "157013", - "blockId": "4680888982781013372", - "type": 4, - "timestamp": 4879978, - "senderPublicKey": "2cef5711e61bb5361c544077aa08aebc4d962a1d656571901c48d716382ad4fd", - "senderId": "3855903394839129841", - "recipientId": "", - "amount": 0, - "fee": 1500000000, - "signature": "a42feaccd9f2a4940fc0be1a1580e786b360f189db3154328f307988e75484293eae391f2f9eee489913cc6d15984eb1f5f5a0aa1bf78ea745d5c725f161af08", - "signSignature": "", - "signatures": null, - "confirmations": "26", - "asset": { - - } - } -} - -``` - -#### **2.8.4 获取多重签名账户信息** -接口地址:/api/multisignatures/accounts -请求方式:get -支持格式:urlencoded -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|publicKey |string |Y |多重签名参与者之一的公钥 | - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据 | -|accounts|Array |多重签名账户详情 | - - -请求示例: -```bash -curl -k -X GET http://45.32.248.33:4096/api/multisignatures/accounts?publicKey=eb48b9ab7c9a34a9b7cdf860265d65b31af774355cabf1b3a387d14a1925dc97 -``` - -JSON返回示例: -```js -{ - "success": true, - "accounts": [{ - "address": "3855903394839129841", //多重签名账户地址 - "balance": 18500000000, //多重签名账户余额 - "multisignatures": ["eb48b9ab7c9a34a9b7cdf860265d65b31af774355cabf1b3a387d14a1925dc97", - "d5d7aa157f866c47a2a1e09e2746286ed089fd90976b54fbfa930e87d11609cb"], //多重签名账户公钥 - "multimin": 2, //最少签名个数 - "multilifetime": 1, - "multisigaccounts": [{ //签名者账户详情 - "address": "13542769708474548631", - "publicKey": "eb48b9ab7c9a34a9b7cdf860265d65b31af774355cabf1b3a387d14a1925dc97", - "balance": 0 - }, - { - "address": "4100816257782486230", - "publicKey": "d5d7aa157f866c47a2a1e09e2746286ed089fd90976b54fbfa930e87d11609cb", - "balance": 0 - }] - }] -} -``` - -### **2.9 点对点传输tansport[安全的api]** -#### **2.9.1 说明** -/peer相关的api,在请求时都需要设置一个header - - - key为magic,testnet value:594fe0f3, mainnet value:5f5b3cf5 - - key为version,value为'' - -#### **2.9.2 普通交易** -asch系统的所有写操作都是通过发起一个交易来完成的。 -交易数据通过一个叫做asch-js的库来创建,然后再通过一个POST接口发布出去 - -POST接口规格如下: -payload为asch-js创建出来的交易数据 -接口地址:/peer/transactions -请求方式:post -支持格式:json - -##### **2.9.2.1 设置二级密码** -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|transaction|json|Y|asch-js.signature.createSignature生成的交易数据| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | - - -请求示例: -```js -var asch = require('asch-js'); -var password = 'measure bottom stock hospital calm hurdle come banner high edge foster cram'; -var secondPassword = 'erjimimashezhi001'; -var transaction = asch.signature.createSignature(password,secondPassword); -console.log(JSON.stringify(transaction)) -{"type":1,"amount":0,"fee":500000000,"recipientId":null,"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","timestamp":5328943,"asset":{"signature":{"publicKey":"27116db89cb5a8c02fb559712e0eabdc298480d3c79a089b803e35bc5ef7bb7b"}},"signature":"71ef98b1600f22f3b18cfcf17599db3c40727c230db817f610e86454b62df4fb830211737ff0c03c6a61ecfd4a9fcb68a30b2874060bb33b87766acf800e820a","id":"15605591820551652547"} - -// 将上面生成的设置二级密码的交易数据通过post提交给asch server -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":1,"amount":0,"fee":500000000,"recipientId":null,"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","timestamp":5328943,"asset":{"signature":{"publicKey":"27116db89cb5a8c02fb559712e0eabdc298480d3c79a089b803e35bc5ef7bb7b"}},"signature":"71ef98b1600f22f3b18cfcf17599db3c40727c230db817f610e86454b62df4fb830211737ff0c03c6a61ecfd4a9fcb68a30b2874060bb33b87766acf800e820a","id":"15605591820551652547"}}' http://45.32.248.33:4096/peer/transactions -``` - -JSON返回示例: -```js -{ - "success":true //二级密码设置成功 -} -``` - -##### **2.9.2.2 转账** -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|transaction|json|Y|asch-js.transaction.createTransaction生成的交易数据| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | - - -请求示例: -```js -var asch = require('asch-js'); -var targetAddress = "16358246403719868041"; -var amount = 100*100000000; //100 XAS -var password = 'measure bottom stock hospital calm hurdle come banner high edge foster cram'; -var secondPassword = 'erjimimashezhi001'; -var message = ''; // 转账备注 - -// 其中password是在用户登录的时候记录下来的,secondPassword需要每次让用户输入 -// 可以通过user.secondPublicKey来判断用户是否有二级密码,如果没有,则不必输入,以下几个交易类型类似 -var transaction = asch.transaction.createTransaction(targetAddress, amount, message, password, secondPassword || undefined); -JSON.stringify(transaction) -'{"type":0,"amount":10000000000,"fee":10000000,"recipientId":"16358246403719868041","message":"","timestamp":37002975,"asset":{},"senderPublicKey":"8065a105c785a08757727fded3a06f8f312e73ad40f1f3502e0232ea42e67efd","signature":"bd0ed22abf09a13c1778ebfb96fc8584dd209961cb603fd0d818d88df647a926795b5e3c51e23f6ed38648169f4e4c912dd854725c22cce9bbdc15ec51c23008","id":"de72b89312c7d128db28611ed36eab2ff0136912c4a67f97342417c942b055cf"}' - -// 将上面生成的转账操作的交易数据通过post提交给asch server -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":0,"amount":10000000000,"fee":10000000,"recipientId":"16358246403719868041","message":"","timestamp":37002975,"asset":{},"senderPublicKey":"8065a105c785a08757727fded3a06f8f312e73ad40f1f3502e0232ea42e67efd","signature":"bd0ed22abf09a13c1778ebfb96fc8584dd209961cb603fd0d818d88df647a926795b5e3c51e23f6ed38648169f4e4c912dd854725c22cce9bbdc15ec51c23008","id":"de72b89312c7d128db28611ed36eab2ff0136912c4a67f97342417c942b055cf"}}' http://45.32.248.33:4096/peer/transactions -``` - -JSON返回示例: -```js -{ - "success":true, //转账成功 - "transactionId":"a95c3a5bda15f3fd38295950268c234e922aae97cf803dd8c38c73a6ccf7c561" -} -``` - -##### **2.9.2.3 注册受托人** -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|transaction|json|Y|asch-js.delegate.createDelegate生成的交易数据| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | - - -请求示例: -```js -var asch = require('asch-js'); -var password = 'measure bottom stock hospital calm hurdle come banner high edge foster cram'; -var secondPassword = 'erjimimashezhi001'; -var userName = 'zhenxi_test'; - -var transaction = asch.delegate.createDelegate(userName, password, secondPassword || undefined); -JSON.stringify(transaction) -'{"type":2,"amount":0,"fee":10000000000,"recipientId":null,"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","timestamp":5334485,"asset":{"delegate":{"username":"zhenxi_test","publicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f"}},"signature":"a12ce415d2d21ab46e4c1b918b8717b1d351dd99abd6f2f94d9a1a7e1f32b697f843a05b1851cb857ea45a2476dce592f5ddd612c00cd44488b8b610c57d7f0a","signSignature":"35adc9f1f37d14458e8588f9b4332eedf1151c02480159f64a287a4b0cbb59bfe82040dfec96a4d9560bae99b8eaa1799a7023395db5ddc640d95447992d6e00","id":"12310465407307249905"}' - -// 将上面生成的注册受托人的交易数据通过post提交给asch server -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":2,"amount":0,"fee":10000000000,"recipientId":null,"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","timestamp":5334485,"asset":{"delegate":{"username":"zhenxi_test","publicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f"}},"signature":"a12ce415d2d21ab46e4c1b918b8717b1d351dd99abd6f2f94d9a1a7e1f32b697f843a05b1851cb857ea45a2476dce592f5ddd612c00cd44488b8b610c57d7f0a","signSignature":"35adc9f1f37d14458e8588f9b4332eedf1151c02480159f64a287a4b0cbb59bfe82040dfec96a4d9560bae99b8eaa1799a7023395db5ddc640d95447992d6e00","id":"12310465407307249905"}}' http://45.32.248.33:4096/peer/transactions -``` - -JSON返回示例: -```js -{ - "success":true //注册受托人成功 -} -``` - -##### **2.9.2.4 投票 & 取消投票** - -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|transaction|json|Y|asch-js.vote.createVote生成的交易数据| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | - - -请求示例: -```js -var asch = require('asch-js'); -var password = 'measure bottom stock hospital calm hurdle come banner high edge foster cram'; -var secondPassword = 'erjimimashezhi001'; -// 投票内容是一个列表,列表中的每一个元素是一个符号加上所选择的受托人的公钥,符号为+表示投票,符号为-表示取消投票 -var voteContent = [ - '-ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7', - '+c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2' -]; - -var transaction = asch.vote.createVote(voteContent, password, secondPassword || undefined); -JSON.stringify(transaction) -{"type":3,"amount":0,"fee":10000000,"recipientId":null,"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","timestamp":5334923,"asset":{"vote":{"votes":["-ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7","+c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2"]}},"signature":"6036c2066a231c452a1c83aafd3bb9db3842ee05d5f17813f8264a4294cdec761faa89edf4a95f9b2e2451285807ab18aa9f989ad9a3165b95643179b8e4580f","signSignature":"a216ca739112e6f65986604b9467ccc8058138a7077faf134d6c4d673306cd1c514cc95bd54a036f7c602a56c4b4f2e4e59f6aa7c376cb1429e89054042e050b","id":"17558357483072606427"} - -// 将上面生成的投票的交易数据通过post提交给asch server -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":3,"amount":0,"fee":10000000,"recipientId":null,"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","timestamp":5334923,"asset":{"vote":{"votes":["-ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7","+c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2"]}},"signature":"6036c2066a231c452a1c83aafd3bb9db3842ee05d5f17813f8264a4294cdec761faa89edf4a95f9b2e2451285807ab18aa9f989ad9a3165b95643179b8e4580f","signSignature":"a216ca739112e6f65986604b9467ccc8058138a7077faf134d6c4d673306cd1c514cc95bd54a036f7c602a56c4b4f2e4e59f6aa7c376cb1429e89054042e050b","id":"17558357483072606427"}}' http://45.32.248.33:4096/peer/transactions -``` - -JSON返回示例: -```js -{ - "success":true //投票&取消投票 成功 -} -``` - -##### **2.9.2.5 账户锁仓** -备注:锁仓后且区块高度未达到锁仓高度,则该账户不能执行如下操作: - -|交易类型type|备注| -|----|----| -|0|主链XAS转账| -|6|Dapp充值| -|7|Dapp提现| -|8|存储小文件| -|9|发行商注册| -|10|资产注册| -|13|资发行产| -|14|主链uia转账| - -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|transaction|json|Y|asch-js.transaction.createLock生成的交易数据| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | -|transactionId|string|交易id| - - -请求示例: -```js -var asch = require('asch-js'); -var height = 3500; // 锁仓高度 -var password = 'found knife gather faith wrestle private various fame cover response security predict'; -var secondPassword = ''; - - -// 其中password是在用户登录的时候记录下来的,secondPassword需要每次让用户输入 -// 可以通过user.secondPublicKey来判断用户是否有二级密码,如果没有,则不必输入,以下几个交易类型类似 -var transaction = asch.transaction.createLock(height, password, secondPassword || undefined); -JSON.stringify(transaction) -'{"type":100,"amount":0,"fee":10000000,"recipientId":null,"args":["3500"],"timestamp":39615653,"asset":{},"senderPublicKey":"2856bdb3ed4c9b34fd2bba277ffd063a00f703113224c88c076c0c58310dbec4","signature":"46770ea4ba48ebb0abbaae95b7931dd9f6cc0d178ff22ec50b9e97f3f31126b8d0c9c47f7d2e4479124530f7d36d9e1aac72da598330cda3b7404cd48fb10e0c","id":"b71187f59e2a7f6dd68f18b4ddd0bb87f20394473f0388952f0ceedf49596811"}' - -// 将上面生成的转账操作的交易数据通过post提交给asch server -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":100,"amount":0,"fee":10000000,"recipientId":null,"args":["3500"],"timestamp":39615653,"asset":{},"senderPublicKey":"2856bdb3ed4c9b34fd2bba277ffd063a00f703113224c88c076c0c58310dbec4","signature":"46770ea4ba48ebb0abbaae95b7931dd9f6cc0d178ff22ec50b9e97f3f31126b8d0c9c47f7d2e4479124530f7d36d9e1aac72da598330cda3b7404cd48fb10e0c","id":"b71187f59e2a7f6dd68f18b4ddd0bb87f20394473f0388952f0ceedf49596811"}}' http://localhost:4096/peer/transactions && echo -``` - -JSON返回示例: -```js -{ - "success":true, // 锁仓成功 - "transactionId":"b71187f59e2a7f6dd68f18b4ddd0bb87f20394473f0388952f0ceedf49596811" -} -``` - -#### **2.9.3 UIA相关交易** -asch系统的所有写操作都是通过发起一个交易来完成的。 -交易数据通过一个叫做asch-js的库来构建,然后再通过一个POST接口发布出去。 - -POST接口规格如下: -payload为asch-js创建出来的交易数据 -接口地址:/peer/transactions -请求方式:post -支持格式:json -公用变量: -``` -var AschJS = require('asch-js'); -// 一级密码 -var secret = 'motion group blossom coral upper warrior pattern fragile sister misery palm detect' -// 二级密码 -var secondSecret = 'erjimima001' -``` - -##### **2.9.3.1 注册资产发行商** -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|transaction|json|Y|AschJS.uia.createIssuer根据发行商名字、描述、一级密码、二级密码生成的交易数据| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | - - -请求示例: -```js -// 发行商名称,唯一标识 -var name = 'IssuerName' -// 发行商描述 -var desc = 'IssuerDesc' -// 构造交易数据 -var trs = AschJS.uia.createIssuer(name, desc, secret, secondSecret) -console.log(JSON.stringify(trs)) -{"type":9,"amount":0,"fee":10000000,"recipientId":null,"senderPublicKey":"fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575","timestamp":19395607,"asset":{"uiaIssuer":{"name":"IssuerName","desc":"IssuerDesc"}},"signature":"c6ed2a4bafe2b8aa31f4aaceacc2a96cb028abbabb2ed062937498c58e24ca5467a340ddd63b67f809a680ff91b83e685c64991eb695494ddb2fdc57e5761607","signSignature":"8eceacbd47c2b8ed335145ced19d7a3a51f99bdd6631d16ed214180c6f80e29bd6d572f45e7c7d685584e55cb5c303cf340406553ece28c9c0a2fa7a777aac0b"} - -// 将生成的交易数据通过post发送给server,注册资产发行商IssuerName -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":9,"amount":0,"fee":10000000,"recipientId":null,"senderPublicKey":"fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575","timestamp":19395607,"asset":{"uiaIssuer":{"name":"IssuerName","desc":"IssuerDesc"}},"signature":"c6ed2a4bafe2b8aa31f4aaceacc2a96cb028abbabb2ed062937498c58e24ca5467a340ddd63b67f809a680ff91b83e685c64991eb695494ddb2fdc57e5761607","signSignature":"8eceacbd47c2b8ed335145ced19d7a3a51f99bdd6631d16ed214180c6f80e29bd6d572f45e7c7d685584e55cb5c303cf340406553ece28c9c0a2fa7a777aac0b"}}' 'http://localhost:4096/peer/transactions' && echo -``` - -JSON返回示例: -```js -{"success":true} -``` - -##### **2.9.3.2 注册资产** -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|transaction|json|Y|AschJS.uia.createAsset根据资产名字、描述、上限、精度、策略、一级密码、二级密码生成的交易数据| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | - - -请求示例: -```js -// 资产名称,发行商名.资产名,唯一标识 -var name = 'IssuerName.CNY'; -var desc = '资产描述'; -// 上限 -var maximum = '1000000'; -// 精度,小数点的位数,这里上限是1000000,精度为3,代表资产IssuerName.CNY的最大发行量为1000.000 -var precision = 3; -// 策略 -var strategy = ''; -// 是否允许注销,默认不允许。0:不允许,1:允许 -var allowWriteoff = 0; -// 是否允许白名单,默认不允许。0:不允许,1:允许 -var allowWhitelist = 0; -// 是否允许黑名单,默认不允许。0:不允许,1:允许 -var allowBlacklist = 0; -// 构造交易数据 -var trs = AschJS.uia.createAsset(name, desc, maximum , precision, strategy, allowWriteoff, allowWhitelist, allowBlacklist, secret, secondSecret) -console.log(JSON.stringify(trs)) -// 返回的结果如下 -{"type":10,"amount":0,"fee":50000000000,"recipientId":null,"senderPublicKey":"fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575","timestamp":48697173,"message":null,"asset":{"uiaAsset":{"name":"IssuerName.CNY","desc":"资产描述","maximum":"1000000","precision":3,"strategy":"","allowBlacklist":0,"allowWhitelist":0,"allowWriteoff":0}},"signature":"17e12a741375bd0420b9e88a5be5b8563c12d90961914477116eb95ca5df119ca73c8edbcefef071a69bf5bf8a2b9829ed0e0d6fc3efedaaa16b528aa6239f04","signSignature":"a325267c0fc9cfcbed848494b7577dfe85f2ca751dcb02336ff84153cf46e79e99dc87a377f56ce2e500331f04df952415e38b7e3e8cbdb90192c99a0787120b","id":"8ef0982580b58094cb87f1f81c0cf3fa5588ec86681895b44b946ebbf05951d4"} - -// 将生成的交易数据通过post发送给server,注册资产IssuerName.CNY -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{{"type":10,"amount":0,"fee":50000000000,"recipientId":null,"senderPublicKey":"fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575","timestamp":48697173,"message":null,"asset":{"uiaAsset":{"name":"IssuerName.CNY","desc":"资产描述","maximum":"1000000","precision":3,"strategy":"","allowBlacklist":0,"allowWhitelist":0,"allowWriteoff":0}},"signature":"17e12a741375bd0420b9e88a5be5b8563c12d90961914477116eb95ca5df119ca73c8edbcefef071a69bf5bf8a2b9829ed0e0d6fc3efedaaa16b528aa6239f04","signSignature":"a325267c0fc9cfcbed848494b7577dfe85f2ca751dcb02336ff84153cf46e79e99dc87a377f56ce2e500331f04df952415e38b7e3e8cbdb90192c99a0787120b","id":"8ef0982580b58094cb87f1f81c0cf3fa5588ec86681895b44b946ebbf05951d4"}}' 'http://localhost:4096/peer/transactions' && echo -``` - -JSON返回示例: -```js -{"success":true} -``` - -##### **2.9.3.3 资产设置acl模式** -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|transaction|json|Y|AschJS.uia.createFlags根据资产名、流通状态、黑白名单模式、一级密码、二级密码生成的交易数据| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | - - -请求示例: -```js -var currency = 'IssuerName.CNY' -// 资产是否注销,1:流通,2:注销 -var flagType = 1 -// 访问控制列表的类型,0:黑名单, 1:白名单,资产创建后默认为黑名单模式 -var flag = 1 -var trs = AschJS.uia.createFlags(currency, flagType, flag, secret, secondSecret) -console.log(JSON.stringify(trs)) -{"type":11,"amount":0,"fee":10000000,"recipientId":null,"senderPublicKey":"fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575","timestamp":19400996,"asset":{"uiaFlags":{"currency":"IssuerName.CNY","flagType":1,"flag":1}},"signature":"b96fb3d1456e1f26357109cc24d82834eb9a4687f29e69c374bbb1d534568336e148cac52f213aa4d2a69185092f8e1143b49ec4b8048cd9b3af4e20f6ba0b08","signSignature":"b37c77ebebe90341346be2aefe1e12bd7403e5d8f4d6e8f04630190b3e09494a28820da0ffd5f9ff011033aa6d70fc9bb4c159a4493be3b18fd7ff470103570d"} - -// 将生成的交易数据通过post发送给server,将acl改为白名单模式 -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":11,"amount":0,"fee":10000000,"recipientId":null,"senderPublicKey":"fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575","timestamp":19400996,"asset":{"uiaFlags":{"currency":"IssuerName.CNY","flagType":1,"flag":1}},"signature":"b96fb3d1456e1f26357109cc24d82834eb9a4687f29e69c374bbb1d534568336e148cac52f213aa4d2a69185092f8e1143b49ec4b8048cd9b3af4e20f6ba0b08","signSignature":"b37c77ebebe90341346be2aefe1e12bd7403e5d8f4d6e8f04630190b3e09494a28820da0ffd5f9ff011033aa6d70fc9bb4c159a4493be3b18fd7ff470103570d"}}' 'http://localhost:4096/peer/transactions' && echo -``` - -JSON返回示例: -```js -{"success":true} -``` - -##### **2.9.3.4 更新访问控制列表(acl)** -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|transaction|json|Y|AschJS.uia.createAcl根据资产名字、列表操作方法、黑名单还是白名单、地址列表、一级密码、二级密码生成的交易数据| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | - - -请求示例: -```js -var currency = 'IssuerName.CNY' -// '+'表示增加列表, ‘-’表示删除列表 -var operator = '+' -var list = ['15745540293890213312'] -// 访问控制列表的类型,0:黑名单, 1:白名单 -var flag =1 -var trs = AschJS.uia.createAcl(currency, operator, flag, list, secret, secondSecret) -console.log(JSON.stringify(trs)) -{"type":12,"amount":0,"fee":20000000,"recipientId":null,"senderPublicKey":"fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575","timestamp":19403125,"asset":{"uiaAcl":{"currency":"IssuerName.CNY","operator":"+","flag":1,"list":["15745540293890213312"]}},"signature":"ad4060e04c1a12256de114e34499f8add24326753f1f8362991ee14aefc4c0fe90ff394d2db97e83770855a5688d463de00656fdd2d04604605cf3c04fdaca0e","signSignature":"63129c58b1b9fcce88cbe829f3104a10ab06037253e9b65feb50ce0d2bb988533b93e8edcad016a85675f9027758fc318cf899ca7ef161a95a8d8a055ae83a02"} - -// 将生成的交易数据通过post发送给server,把地址列表['15745540293890213312']增加到该白名单中,只修改名单列表,不修改acl模式,手续费0.2XAS -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":12,"amount":0,"fee":20000000,"recipientId":null,"senderPublicKey":"fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575","timestamp":19403125,"asset":{"uiaAcl":{"currency":"IssuerName.CNY","operator":"+","flag":1,"list":["15745540293890213312"]}},"signature":"ad4060e04c1a12256de114e34499f8add24326753f1f8362991ee14aefc4c0fe90ff394d2db97e83770855a5688d463de00656fdd2d04604605cf3c04fdaca0e","signSignature":"63129c58b1b9fcce88cbe829f3104a10ab06037253e9b65feb50ce0d2bb988533b93e8edcad016a85675f9027758fc318cf899ca7ef161a95a8d8a055ae83a02"}}' 'http://localhost:4096/peer/transactions' && echo -``` - -JSON返回示例: -```js -{"success":true} -// 查询更新后的列表(acl/1代表白名单) -curl -X GET -H "Content-Type: application/json" 'http://localhost:4096/api/uia/assets/IssuerName.CNY/acl/1?limit=10&offset=0' && echo -{ - "success": true, - "list": [{ - "address": "15745540293890213312" - }], - "count": 1 -} -``` - - -##### **2.9.3.5 资产发行** -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|transaction|json|Y|AschJS.uia.createIssuer根据发行商名字、描述、一级密码、二级密码生成的交易数据| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | - - -请求示例: -```js -var currency = 'IssuerName.CNY' -// 本次发行量=真实数量(100)*10**精度(3),所有发行量之和需 <= 上限*精度 -var amount = '100000' -var trs = AschJS.uia.createIssue(currency, amount, secret, secondSecret) -console.log(JSON.stringify(trs)) -{"type":13,"amount":0,"fee":10000000,"recipientId":null,"senderPublicKey":"fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575","timestamp":19475744,"asset":{"uiaIssue":{"currency":"IssuerName.CNY","amount":"100000"}},"signature":"32b01a18eca2b0dc7e2ce77ba4e758eaae2532f60844760a762cc20918e7439ac6ca585b921db6ede833ed0bf1c62e30cec545a928abafe0b679183a6ad02202","signSignature":"4fc290d7d7d788e9112a56233df0fe796cba39be3efa0cebf00cbc7e5bc5fd1369fad49e5698d967845b5c02e427926049cab25845d4d385e4a395791906f909"} - -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":13,"amount":0,"fee":10000000,"recipientId":null,"senderPublicKey":"fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575","timestamp":19475744,"asset":{"uiaIssue":{"currency":"IssuerName.CNY","amount":"100000"}},"signature":"32b01a18eca2b0dc7e2ce77ba4e758eaae2532f60844760a762cc20918e7439ac6ca585b921db6ede833ed0bf1c62e30cec545a928abafe0b679183a6ad02202","signSignature":"4fc290d7d7d788e9112a56233df0fe796cba39be3efa0cebf00cbc7e5bc5fd1369fad49e5698d967845b5c02e427926049cab25845d4d385e4a395791906f909"}}' 'http://localhost:4096/peer/transactions' && echo -``` - -JSON返回示例: -```js -{"success":true} -``` - -##### **2.9.3.6 资产转账** -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|transaction|json|Y|AschJS.uia.createTransfer根据资产名字、数量、接收者地址、一级密码、二级密码生成的交易数据| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | - - -请求示例: -```js -var currency = 'IssuerName.CNY' -// 本次转账数(10000)=真实数量(10)*10**精度(3),需 <= 当前资产发行总量 -var amount = '10000' -// 接收地址,需满足前文定义好的acl规则 -var recipientId = 'AKKHPvQb2A119LNicCQWLZQDFxhGVEY57a' -var trs = AschJS.uia.createTransfer(currency, amount, recipientId, secret, secondSecret) -console.log(JSON.stringify(trs)) -{"type":14,"amount":0,"fee":10000000,"recipientId":"AKKHPvQb2A119LNicCQWLZQDFxhGVEY57a","senderPublicKey":"fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575","timestamp":19481489,"asset":{"uiaTransfer":{"currency":"IssuerName.CNY","amount":"10000"}},"signature":"77789071a2ad6d407b9d1e0d654a9deb6d85340a3d2a13d786030e26ac773b4e9b5f052589958d2b8553ae5fc9449496946b5c225e0baa723e7ddecbd89f060a","signSignature":"f0d4a000aae3dd3fa48a92f792d4318e41e3b56cdbaf98649261ae34490652b87645326a432d5deb69f771c133ee4b67d2d22789197be34249e6f7f0c30c1705"} - -// 给AKKHPvQb2A119LNicCQWLZQDFxhGVEY57a发送10.000 IssuerName.CNY资产 -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":14,"amount":0,"fee":10000000,"recipientId":"AKKHPvQb2A119LNicCQWLZQDFxhGVEY57a","senderPublicKey":"fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575","timestamp":19481489,"asset":{"uiaTransfer":{"currency":"IssuerName.CNY","amount":"10000"}},"signature":"77789071a2ad6d407b9d1e0d654a9deb6d85340a3d2a13d786030e26ac773b4e9b5f052589958d2b8553ae5fc9449496946b5c225e0baa723e7ddecbd89f060a","signSignature":"f0d4a000aae3dd3fa48a92f792d4318e41e3b56cdbaf98649261ae34490652b87645326a432d5deb69f771c133ee4b67d2d22789197be34249e6f7f0c30c1705"}}' 'http://localhost:4096/peer/transactions' && echo -``` - -JSON返回示例: -```js -{"success":true} -``` - -##### **2.9.3.7 资产注销** -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|transaction|json|Y|AschJS.uia.createFlags根据资产名字、注销状态、黑白名单模式、一级密码、二级密码生成的交易数据| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | - - -请求示例: -```js -var currency = 'IssuerName.CNY' -// flagType为资产是否注销,1:流通,2:注销 -var flagType = 2 -// flag为黑、白名单模式 -var flag =1 -var trs = AschJS.uia.createFlags(currency, flagType, flag, secret, secondSecret) -console.log(JSON.stringify(trs)) -{"type":11,"amount":0,"fee":10000000,"recipientId":null,"senderPublicKey":"fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575","timestamp":19488690,"asset":{"uiaFlags":{"currency":"IssuerName.CNY","flagType":2,"flag":1}},"signature":"cbd656552417604704703e1236ec2bbed8eba6a2ccfcb54cc0b2d629c0a9d1335a264fc9f6dee1705f4a86c36a5ce2ba8e039d913a189b7c273c8ac0d9e3780c","signSignature":"3c7b91d03efeed2dc86e1f2301da60789751c1be8850460d8c66c0ae8f55ea27d26f0bc79541d74b4777d9b85c518c1c73c0284dbf3e826db0a686560e57a80b"} - -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":11,"amount":0,"fee":10000000,"recipientId":null,"senderPublicKey":"fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575","timestamp":19488690,"asset":{"uiaFlags":{"currency":"IssuerName.CNY","flagType":2,"flag":1}},"signature":"cbd656552417604704703e1236ec2bbed8eba6a2ccfcb54cc0b2d629c0a9d1335a264fc9f6dee1705f4a86c36a5ce2ba8e039d913a189b7c273c8ac0d9e3780c","signSignature":"3c7b91d03efeed2dc86e1f2301da60789751c1be8850460d8c66c0ae8f55ea27d26f0bc79541d74b4777d9b85c518c1c73c0284dbf3e826db0a686560e57a80b"}}' 'http://localhost:4096/peer/transactions' && echo -``` - -JSON返回示例: -```js -{"success":true} -``` - - -#### **2.9.4 其它内部通讯安全接口** -get /peer/list //查找dapp peer -get /peer/blocks/common //查找common block -... - - - -### **2.10 用户自定义资产uia** -#### **2.10.1 获取全网所有发行商** -接口地址:/api/uia/issuers -请求方式:get -支持格式:urlencoded - -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|limit|integer|N|限制结果集个数,最小值:0,最大值:100| -|offset|integer|N|偏移量,最小值0| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | -|issuers|list|元素为字典,每个字典代表一个发行商,包含发行商名字、描述、id(Asch地址)| -|count|integer|发行商总个数| - -请求示例: -```js -curl -X GET -H "Content-Type: application/json" 'http://testnet.asch.so:4096/api/uia/issuers?offset=0&limit=1' && echo -``` - -JSON返回示例: -```js -{ - "success": true, - "issuers": [{ - "name": "zhenxi", - "desc": "注册资产发行商-测试", - "issuerId": "AKKHPvQb2A119LNicCQWLZQDFxhGVEY57a" - }, - { - "name": "speedtest", - "desc": "speedtest", - "issuerId": "AEVWQWAq3TEJkCPSDxXMP2uCRrL2xbQnsy" - }], - "count": 6 -} -``` - -#### **2.10.2 查询指定发行商的信息** -接口地址:/api/uia/issuers/:name -请求方式:get -支持格式:urlencoded - -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|name|string|Y|可以为发行商名称或Asch账户地址| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | -|issuers|dict|包含发行商名字、描述、id(Asch地址)| - -请求示例: -```js -curl -X GET -H "Content-Type: application/json" 'http://testnet.asch.so:4096/api/uia/issuers/zhenxi' && echo -``` - -JSON返回示例: -```js -{ - "success": true, - "issuer": { - "name": "zhenxi", - "desc": "注册资产发行商-测试", - "issuerId": "AKKHPvQb2A119LNicCQWLZQDFxhGVEY57a" - } -} -``` - -#### **2.10.3 查看指定发行商的资产** -接口地址:/api/uia/issuers/:name/assets -请求方式:get -支持格式:urlencoded - -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|name|string|Y|可以为发行商名称或Asch账户地址| -|limit|integer|N|限制结果集个数,最小值:0,最大值:100| -|offset|integer|N|偏移量,最小值0| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | -|assets|list|每个元素是一个字典,每个字典是一个资产详情,包含资产名字、描述、上限(最大发行量=真实发行量*10**精度)、精度、策略、当前发行量、发行高度、发行商id,acl模式(0:黑名单,1:白名单)、是否注销| -|count|interger|该发行商注册的资产总个数(包含已注销的)| - - - -请求示例: -```js -curl -X GET -H "Content-Type: application/json" 'http://testnet.asch.so:4096/api/uia/issuers/zhenxi/assets?offset=0&limit=2' && echo -``` - -JSON返回示例: -```js -{ - "success": true, - "assets": [{ - "name": "zhenxi.UIA", - "desc": "注册资产-测试", - "maximum": "10000000", - "precision": 3, - "strategy": "", - "quantity": "1000000", - "height": 301, - "issuerId": "AKKHPvQb2A119LNicCQWLZQDFxhGVEY57a", - "acl": 0, - "writeoff": 1 - }], - "count": 1 -} -``` - -#### **2.10.4 获取全网所有资产信息** -接口地址:/api/uia/assets -请求方式:get -支持格式:urlencoded - -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|limit|integer|N|限制结果集个数,最小值:0,最大值:100| -|offset|integer|N|偏移量,最小值0| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | -|assets|list|每个元素是一个字典,每个字典是一个资产详情,包含资产名字、描述、上限、精度、策略、当前发行量、发行高度、发行商id,acl、是否注销| -|count|integer|所有资产的个数| - - - -请求示例: -```js -curl -X GET -H "Content-Type: application/json" 'http://testnet.asch.so:4096/api/uia/assets?offset=0&limit=2' && echo -``` - -JSON返回示例: -```js -{ - "success": true, - "assets": [{ - "name": "zhenxi.UIA", - "desc": "注册资产-测试", - "maximum": "10000000", - "precision": 3, - "strategy": "", - "quantity": "1000000", - "height": 301, - "issuerId": "AKKHPvQb2A119LNicCQWLZQDFxhGVEY57a", - "acl": 0, - "writeoff": 1 - }, - { - "name": "speedtest.SPEED", - "desc": "测速", - "maximum": "10000", - "precision": 1, - "strategy": "", - "quantity": "10000", - "height": 380, - "issuerId": "AEVWQWAq3TEJkCPSDxXMP2uCRrL2xbQnsy", - "acl": 0, - "writeoff": 0 - }], - "count": 13 -} -``` - -#### **2.10.5 获取指定资产信息** -接口地址:/api/uia/assets/:name -请求方式:get -支持格式:urlencoded - -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|name|string|Y|资产名| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | -|assets|dict|包含资产名字、描述、上限、精度、策略、当前发行量、发行高度、发行商id,acl、是否注销| - -请求示例: -```js -curl -X GET -H "Content-Type: application/json" 'http://testnet.asch.so:4096/api/uia/assets/zhenxi.UIA' && echo -``` - -JSON返回示例: -```js -{ - "success": true, - "asset": { - "name": "zhenxi.UIA", - "desc": "注册资产-测试", - "maximum": "10000000", - "precision": 3, - "strategy": "", - "quantity": "1000000", - "height": 301, - "issuerId": "AKKHPvQb2A119LNicCQWLZQDFxhGVEY57a", - "acl": 0, - "writeoff": 1 - } -} -``` - -#### **2.10.6 获取指定资产的访问控制列表(acl)** -接口地址:/api/uia/assets/:name/acl/flag -请求方式:get -支持格式:urlencoded - -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|name|string|Y|资产名| -|flag|boole|Y|取值0和1,0表示黑名单,1表示白名单| -|limit|integer|N|限制结果集个数,最小值:0,最大值:100| -|offset|integer|N|偏移量,最小值0| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | -|list|list|符合规则的账户列表| -|count|integer|符合规则账户总数| - - -请求示例: -```js -// 获取资产zhenxi.UIA白名单中的地址列表 -curl -X GET -H "Content-Type: application/json" 'http://localhost:4096/api/uia/assets/zhenxi.UIA/acl/1' && echo -``` - -JSON返回示例: -```js -{ - "success": true, - "list": [{ - "address": "15745540293890213312" - }, - { - "address": "AKKHPvQb2A119LNicCQWLZQDFxhGVEY57a" - }], - "count": 2 -} -``` - -#### **2.10.7 获取指定账户所有uia的余额** -接口地址:/api/uia/balances/:address -请求方式:get -支持格式:urlencoded - -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|address|string|Y|账户地址| -|limit|integer|N|限制结果集个数,最小值:0,最大值:100| -|offset|integer|N|偏移量,最小值0| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | -|balances|list|拥有的资产详情列表,每个元素是一个资产,包含资产名、余额、上限、精度、当前发行量、是否注销(0:未注销,1:已注销)| -|count|integer|当前该地址拥有的资产个数| - -请求示例: -```js -curl -X GET -H "Content-Type: application/json" 'http://localhost:4096/api/uia/balances/AKKHPvQb2A119LNicCQWLZQDFxhGVEY57a' && echo -``` - -JSON返回示例: -```js -{ - "success": true, - "balances": [{ - "currency": "zhenxi.UIA", - "balance": "900000", - "maximum": "10000000", - "precision": 3, - "quantity": "1000000", - "writeoff": 1 - }, - { - "currency": "speedtest.SPEED", - "balance": "400", - "maximum": "10000", - "precision": 1, - "quantity": "10000", - "writeoff": 0 - }], - "count": 2 -} -``` - -#### **2.10.8 获取指定账户所有资产相关操作记录** -接口地址:/api/uia/transactions/my/:address -请求方式:get -支持格式:urlencoded -备注:包含发行商创建以及资产创建、发行、转账等 - -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|address|string|Y|账户地址| -|limit|integer|N|限制结果集个数,最小值:0,最大值:100| -|offset|integer|N|偏移量,最小值0| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | -|transactions|list|交易列表,每个元素是一个字典代表一次交易,包含交易id、区块高度、区块id、交易类型、时间戳、发送者公钥、发送者id、接收者id(系统为空,如资产注册)、交易数量(资产交易都为0)、手续费0.1XAS、签名、多重签名、确认数、资产信息(包含发行商id、发行商名字、描述)、交易id。| -|count|integer|资产交易总个数| - -请求示例: -```js -curl -X GET -H "Content-Type: application/json" 'http://localhost:4096/api/uia/my/transactions/16358246403719868041?offset=0&limit=2' && echo -``` - -JSON返回示例: -```js -{ - "success": true, - "transactions": [{ - "id": "12372526051670720162", // 交易id - "height": "286", // 交易所在区块高度 - "blockId": "14863181420651287815", // 交易所在区块id - "type": 9, // 交易类型,9代表注册发行商 - "timestamp": 17597873, // 交易时间,距离创世块的offset - "senderPublicKey": "d39d6f26869067473d685da742339d1a9117257fe14b3cc7261e3f2ed5a339e3", // 交易发起者公钥 - "senderId": "AKKHPvQb2A119LNicCQWLZQDFxhGVEY57a", // 交易发起者id - "recipientId": "", // 接收者id,如果是系统则为空 - "amount": 0, // 交易数量,如果是资产或者XAS则为非0,否则为0 - "fee": 10000000, // 交易费 - "signature": "6a1e66387f610de5a89489105697082037b82bff4fb6f95f9786304176efe59f7d41e8fe9c5501e1b0b34a47e957a38e10e940fdb180f8ebcaf0ac062a63c601", // 交易签名 - "signSignature": "", // 二级签名,有二级密码时才有 - "signatures": null, // 多重签名,使用多重签名账户时才有 - "confirmations": "155998", // 交易确认数 - "asset": { - "uiaIssuer": { - "transactionId": "12372526051670720162", // 交易id - "name": "zhenxi", // 发行商名字 - "desc": "注册资产发行商-测试" // 发行商描述 - } - }, - "t_id": "12372526051670720162" // 交易id - }, - { - "id": "17308768226103450697", - "height": "371", - "blockId": "244913990990213995", - "type": 9, - "timestamp": 17598730, - "senderPublicKey": "7bd645f9626820d390311fb28dc30875e8bd26cce2d04ba2809df82e84088020", - "senderId": "AEVWQWAq3TEJkCPSDxXMP2uCRrL2xbQnsy", - "recipientId": "", - "amount": 0, - "fee": 10000000, - "signature": "6ea76ff6f58f1bc99d6b40ece45e371948db58a68f6fa41e13b34ff86bbf1f0bea53d6afe982562392861727f879205efc7d1342f6e963028985e243a94e5507", - "signSignature": "", - "signatures": null, - "confirmations": "155913", - "asset": { - "uiaIssuer": { - "transactionId": "17308768226103450697", - "name": "speedtest", - "desc": "speedtest" - } - }, - "t_id": "17308768226103450697" - }], - "count": 58 -} -``` - - -说明: - 注意这里asset内容与type相关,9 <= type <= 14, 根据不同的type从asset中取出不同的值,详情如下: - -``` -type=9 -"asset": { - "uiaIssuer": { - "transactionId": "260434858608363290", - "name": "issuername", - "desc": "issuer1_desc" - } - }, -展示: 注册了发行商"issuername" -``` - -``` -type=10 -"asset": { - "uiaAsset": { - "transactionId": "11613326283813789432", - "name": "issuername.BTC", - "desc": "asset1_desc", - "maximum": "10000000000000", - "precision": "6", - "strategy": "" - } - }, -展示: 注册了资产"issuername.BTC" -``` - -``` -type=11 -"asset": { - "uiaFlags": { - "transactionId": "14649028077581400942", - "currency": "issuername.BTC", - "flagType": "1", - "flag": "1" - } - }, -展示: -如果$flagType==1 : 资产issuername.BTC访问控制设置为(flag==0?黑名单:白名单) -如果$flagType==2 : 资产issuername.BTC被注销 -``` - -``` -type=12 -"asset": { - "uiaAcl": { - "transactionId": "16597707943986371131", - "currency": "issuername.BTC", - "operator": "+", - "flag": "1", - "list": [ - "196751217687897827", - "11053997261735317227" - ] - } - }, -展示:资产issuername.BTC更新了访问控制列表 -``` - -``` -type=13 -"asset": { - "uiaIssue": { - "transactionId": "10646196155790595088", - "currency": "issuername.BTC", - "amount": "10000000000" - } - }, -展示: 资产issuername.BTC新发行10000000000(实际数量*精度) -``` - -``` -type=14 -"asset": { - "uiaTransfer": { - "transactionId": "9105235822289198060", - "currency": "issuername.BTC", - "amount": "10" - } - }, -展示:转账10个issuername.BTC资产,交易id是9105235822289198060 -``` - - - - - -#### **2.10.9 获取指定账户指定资产的余额** -接口地址:/api/uia/balances/:address/:currency -请求方式:get -支持格式:urlencoded - -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|address|string|Y|Asch地址| -|currency|string|Y|资产名字| -|limit|integer|N|限制结果集个数,最小值:0,最大值:100| -|offset|integer|N|偏移量,最小值0| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | -|balances|dict|包含资产名、余额、最大发行量、精度、当前发行量、是否注销| - -请求示例: -```js -curl -X GET -H "Content-Type: application/json" 'http://localhost:4096/api/uia/balances/16358246403719868041/IssuerName.CNY' && echo -``` - -JSON返回示例: -```js -{ - "success": true, - "balance": { - "currency": "IssuerName.CNY", - "balance": "80000", - "maximum": "1000000", - "precision": 3, - "quantity": "100000", - "writeoff": 1 - } -} -``` - -#### **2.10.10 获取指定账户指定资产转账记录** -接口地址:/api/uia/transactions/my/:address/:currency -请求方式:get -支持格式:urlencoded -备注:只返回资产转账记录 - -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|address|string|Y|Asch地址| -|currency|string|Y|资产名字| -|limit|integer|N|限制结果集个数,最小值:0,最大值:100| -|offset|integer|N|偏移量,最小值0| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | -|transactions|list|交易列表,每个元素是一个字典代表一次交易,包含交易id、区块高度、区块id、交易类型、时间戳、发送者公钥、发送者id、接收者id(系统为空,如资产注册)、交易数量(资产交易都为0)、手续费0.1XAS、签名、多重签名、确认数、资产信息(包含发行商id、发行商名字、描述)、交易id。| -|count|integer|资产交易总个数| - -请求示例: -```js -curl -X GET -H "Content-Type: application/json" 'http://localhost:4096/api/uia/transactions/my/16358246403719868041/IssuerName.CNY' && echo -``` - -JSON返回示例: -```js -{ - "success": true, - "transactions": [{ - "id": "d6102fc30931e4dc449811cbbab705fd64bc79b09de703e8172f7bdd90835abc", - "height": "173109", - "blockId": "baa23acd566780e338436b48e4eb79a87d3bdd67caeb3812a663da8f77ae87d9", - "type": 14, - "timestamp": 19481489, - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "senderId": "16358246403719868041", - "recipientId": "AKKHPvQb2A119LNicCQWLZQDFxhGVEY57a", - "amount": 0, - "fee": 10000000, - "signature": "77789071a2ad6d407b9d1e0d654a9deb6d85340a3d2a13d786030e26ac773b4e9b5f052589958d2b8553ae5fc9449496946b5c225e0baa723e7ddecbd89f060a", - "signSignature": "f0d4a000aae3dd3fa48a92f792d4318e41e3b56cdbaf98649261ae34490652b87645326a432d5deb69f771c133ee4b67d2d22789197be34249e6f7f0c30c1705", - "signatures": null, - "confirmations": "90853", - "asset": { - "uiaTransfer": { - "transactionId": "d6102fc30931e4dc449811cbbab705fd64bc79b09de703e8172f7bdd90835abc", - "currency": "IssuerName.CNY", - "amount": "10000", - "amountShow": "10" - } - }, - "t_id": "d6102fc30931e4dc449811cbbab705fd64bc79b09de703e8172f7bdd90835abc" - }], - "count": 15 -} -``` - -#### **2.10.11 获取指定资产转账记录** -接口地址:/api/uia/transactions/:currency -请求方式:get -支持格式:urlencoded -备注:只返回指定资产转账记录 - -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|currency|string|Y|资产名字| -|limit|integer|N|限制结果集个数,最小值:0,最大值:100| -|offset|integer|N|偏移量,最小值0| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功 | -|transactions|list|交易列表,每个元素是一个字典代表一次交易,包含交易id、区块高度、区块id、交易类型、时间戳、发送者公钥、发送者id、接收者id(系统为空,如资产注册)、交易数量(资产交易都为0)、手续费0.1XAS、签名、多重签名、确认数、资产信息(包含发行商id、发行商名字、描述)、交易id。| -|count|integer|该资产交易总数| - -请求示例: -```js -// 查询引力波资产absorb.YLB的所有转账记录 -curl -X GET -H "Content-Type: application/json" 'http://127.0.0.1:4096/api/uia/transactions/absorb.YLB' && echo -``` - -JSON返回示例: -```js -{ - success: true, - transactions: [{ - id: "a1ff79e3f37fd73b41abd293c22171ac7760160ad457e55f028e7a8b527651d3", - height: "43", - blockId: "b16b87e79b47edffdc2fd93bd1de70cbe3541684d5dbf8dc1d292903275e03dc", - type: 14, - timestamp: 39167334, - senderPublicKey: "2856bdb3ed4c9b34fd2bba277ffd063a00f703113224c88c076c0c58310dbec4", - senderId: "ANH2RUADqXs6HPbPEZXv4qM8DZfoj4Ry3M", - recipientId: "AMzDw5BmZ39we18y7Ty9VW79eL9k7maZPH", - amount: 0, - fee: 10000000, - signature: "a4e6b0e2c265e0d601fdfc9e82d971e7908457383835b801c725cdaac01bd619a435344241c64247599255f43a43b6576e1da3a357eac5bbd7058e013a8aa60e", - signSignature: "", - signatures: null, - confirmations: "809", - args: null, - message: "", - asset: { - uiaTransfer: { - transactionId: "a1ff79e3f37fd73b41abd293c22171ac7760160ad457e55f028e7a8b527651d3", - currency: "absorb.YLB", - amount: "200000000", - amountShow: "2", - precision: 8 - } - } - }, - { - id: "7cf50223e12b6eb51096353a066befcf2ef862bdd4d4eddcba28a79aa0249af9", - height: "809", - blockId: "278b096893bc028bb79692faec02de8c2f367804485b71f14e46027f3dd3000c", - type: 14, - timestamp: 39182041, - senderPublicKey: "b33b5fc45640cfc414981985bf92eef962c08c53e1a34f90dab039e985bb5fab", - senderId: "AMzDw5BmZ39we18y7Ty9VW79eL9k7maZPH", - recipientId: "1", - amount: 0, - fee: 10000000, - signature: "560bd31a4efe103ef9bd92f52cae5cf5a3b2aeb90fc83298498ff4126705e0433f751169bc32a3a7cfe894c7d8586d7182ebc790f2311daf9f02b881dc2aca0e", - signSignature: "", - signatures: null, - confirmations: "43", - args: null, - message: "", - asset: { - uiaTransfer: { - transactionId: "7cf50223e12b6eb51096353a066befcf2ef862bdd4d4eddcba28a79aa0249af9", - currency: "absorb.YLB", - amount: "100000000", - amountShow: "1", - precision: 8 - } - } - }], - count: 2 -} -``` - -#### **2.10.12 资产创建相关** -下面没有内容的章节请参考《2.9.3》章节。 -##### **2.10.12.1 注册资产发行商** -##### **2.10.12.2 注册资产** -##### **2.10.12.3 更新资产访问控制列表(acl)** -##### **2.10.12.4 资产发行** -##### **2.10.12.5 资产转账** -接口地址:/api/uia/transfers -请求方式:PUT -支持格式:json -接口备注: -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|secret |string |Y |发送者密码,最大长度100 | -|currency |string |Y |资产名,最大长度22 | -|amount |string |Y |转账金额,最大长度50 | -|recipientId |string |Y |接收地址,最小长度1 | -|publicKey|string|N|发送者公钥,格式必须符合公钥格式| -|secondSecret|string|N|发送者二级密码,最小长度1,最大长度:100| -|multisigAccountPublicKey|string|N|多签账户公钥,格式必须符合公钥格式| -|message|string|N|转账备注,最大长度256| - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据。| -|transactionId|string |交易id | - - -请求示例: -```bash -// 转0.01 absorb.YLB给16723473400748954103 -curl -k -H "Content-Type: application/json" -X PUT -d '{"secret":"found knife gather faith wrestle private various fame cover response security predict","amount":"1000000","recipientId":"16723473400748954103","currency":"absorb.YLB"}' 'http://localhost:4096/api/uia/transfers' && echo -``` - -JSON返回示例: -```js -{ - "success": true, - "transactionId": "3cb6d97534a3b90cf7fc883927f0a9a7c7f4878a9df526c2906ca97e250fcaba" -} -``` - -##### **2.10.12.6 更新黑白名单** - - - -### **2.11 存储storages** -源码在src/core/transactions.js文件中,适合存储短文。 -#### **2.11.1 上传数据** -##### **2.11.1.1 上传数据(直接上传)** -接口地址:/api/storages -请求方式:PUT -支持格式:json -接口备注: -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|secret |string |Y |asch账户密码 | -|secondSecret|string|N|发送者二级密码,最小长度1,最大长度:100| -|content|string|Y|上传数据内容| -|encode|string|N|上传数据的格式,可选项为:raw/base64/hex,默认为raw| -|wait|number|N|等待确认数,范围为0-6,默认为0。wait为0表示不等待,速度最快,但无法保证数据在掉电情况下不丢失,大于2时,可以100%确保数据已经同步到大部分机器上了,但需要时间较长10-20秒之间,折中的方案是1,wait为1时虽然不能100%保证同步到其他机器,但失败的几率非常小,只是理论上存在,实际上还没遇到过| - - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据。| -|transactionId|string |交易id | - - -请求示例: -```bash -// 将字符串"helloworld"用base64进行编码 -console.log(new Buffer('helloworld').toString('base64')); -aGVsbG93b3JsZA== -// Asch用base64方式存储刚才得到的编码值"aGVsbG93b3JsZA==" -curl -k -H "Content-Type: application/json" -X PUT -d '{"secret":"motion group blossom coral upper warrior pattern fragile sister misery palm detect","secondSecret":"erjimima001","content":"aGVsbG93b3JsZA==","encode":"base64","wait":1}' http://localhost:4096/api/storages && echo -``` - -JSON返回示例: -```js -{ - "success": true, - "transactionId": "2ae89f859f20e6e9be7aeef5f7ff7b8c6a457ff712100a1b694436bddd9800c0" -} -``` - -##### **2.11.1.2 上传数据(本地签名后再上传)** - -POST接口规格如下: -payload为asch-js创建出来的交易数据 -接口地址:/peer/transactions -请求方式:post -支持格式:json - -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|secret |string |Y |asch账户密码 | -|secondSecret|string|N|发送者二级密码,最小长度1,最大长度:100| -|content|string|Y|上传数据内容,必须是hex格式| - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据。| -|transactionId|string |交易id | - - -请求示例: -``` -var AschJS = require('asch-js'); -// 一级密码 -var secret = 'motion group blossom coral upper warrior pattern fragile sister misery palm detect' -// 二级密码 -var secondSecret = 'erjimima001' -// 将字符串"helloworld"用hex进行编码 -var content = new Buffer('helloworld').toString('hex') -68656c6c6f776f726c64 - -// Asch用hex方式存储刚才得到的编码值"68656c6c6f776f726c64" -var trs = AschJS.storage.createStorage(content, secret, secondSecret) -console.log(JSON.stringify(trs)) -{"type":8,"amount":0,"fee":10000000,"recipientId":null,"senderPublicKey":"fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575","timestamp":20587956,"asset":{"storage":{"content":"68656c6c6f776f726c64"}},"__assetBytes__":{"type":"Buffer","data":[]},"signature":"9663a7f54fd1c18c2447ada61326c34e1cb3ff417089b48e28c25196ebd4a648532782da2a2344de01100c896e568287c2445716f7ac096ff5972bcdf45d850a","signSignature":"60dcfc71cd93d09509c3384b5fa0311de2f31050628efb784e782d9dd39f9a76e76fc09dd03d73165853a194bb59a9d224c960d693c000490d83e58df5fbdd00"} - -// 将生成的交易信息广播出去 -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":8,"amount":0,"fee":10000000,"recipientId":null,"senderPublicKey":"fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575","timestamp":20587956,"asset":{"storage":{"content":"68656c6c6f776f726c64"}},"__assetBytes__":{"type":"Buffer","data":[]},"signature":"9663a7f54fd1c18c2447ada61326c34e1cb3ff417089b48e28c25196ebd4a648532782da2a2344de01100c896e568287c2445716f7ac096ff5972bcdf45d850a","signSignature":"60dcfc71cd93d09509c3384b5fa0311de2f31050628efb784e782d9dd39f9a76e76fc09dd03d73165853a194bb59a9d224c960d693c000490d83e58df5fbdd00"}}' 'http://localhost:4096/peer/transactions' && echo -``` - -JSON返回示例: -```js -{ - "success": true, - "transactionId": "0e009c7b5b732bc8d78a7ff98462f74d57706a8b3a32ac31d5ab67fede5d4c8d" -} -``` - -#### **2.11.2 根据交易id查询存储的数据-1** -接口地址:/api/storages/get -请求方式:GET -支持格式:urlencode -请求参数说明: - -|名称 |类型 |必填 |说明 | -|------ |----- |--- |---- | -|id |string |Y |交易id | - -返回参数说明: - -|名称 |类型 |说明 | -|------ |----- |---- | -|success|boole |是否成功获得response数据。| -|id|string |交易id | - - -请求示例: -```bash -curl -k -H "Content-Type: application/json" -X GET http://localhost:4096/api/storages/get/?id=2ae89f859f20e6e9be7aeef5f7ff7b8c6a457ff712100a1b694436bddd9800c0 && echo -``` - -JSON返回示例: -```js -{ - "success": true, - "id": "2ae89f859f20e6e9be7aeef5f7ff7b8c6a457ff712100a1b694436bddd9800c0", // 交易id - "height": "180182", // 交易所在区块高度 - "blockId": "b59e579a002297557003856fd4cc2b10ac72d3384a5d2a8aece5f906019d79ab", // 交易所在区块id - "type": 8, // 交易类型,8代表存储信息 - "timestamp": 19552678, // 交易时间,举例创世块的offset - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", // 上传者公钥 - "senderId": "16358246403719868041", // 上传者id - "recipientId": "", - "amount": 0, - "fee": 10000000, // 交易费。0.1XAS - "signature": "8a8a256ab16c9cc966f2b975cf5ce39f13f4f13ae4a60f8c6bdfbe94e2e4ee4cb79c3be80630a5c15289d7e959e50dba5f711e9956781b150185ca9d8519f50b", // 交易签名 - "signSignature": "46431039f7e15f3147ca6991e6b46a856741b8566aeb54af97dd73d8d3e03b69eb74693c87d4ce1ef4aa2fb69d56c710681494a013fcf747de24d7ea4e79740f", // 二级签名,有二级密码时才有 - "signatures": null, // 多重签名,使用多重签名账户时才有 - "confirmations": "68", // 交易确认数 - "asset": { - "storage": { - "content": "68656c6c6f776f726c64" // 数据内容,16进制字符串 - } - } -} -// 将得到的16进制(hex)格式的字符串"68656c6c6f776f726c64"转为文本字符串正好是"helloworld" -console.log(new Buffer('68656c6c6f776f726c64','hex').toString()); -helloworld -``` - -#### **2.11.3 根据交易id查询存储的数据-2** -接口地址:/api/storages/:id -请求方式:GET -支持格式:urlencode -请求参数说明:交易id -备注:与/api/storages/get功能相同 - -请求示例: -```bash -curl -k -H "Content-Type: application/json" -X GET http://localhost:4096/api/storages/2ae89f859f20e6e9be7aeef5f7ff7b8c6a457ff712100a1b694436bddd9800c0 && echo -``` - -JSON返回示例: -```js - -``` - - - -## **附录1:asch-js安装** -asch系统的所有写操作都是通过发起一个交易来完成的。 -交易数据通过一个叫做asch-js的库来创建,然后再通过一个POST接口发布出去 -**库安装** -npm install asch-js - - diff --git a/docs/asch_http_interface_de.md b/docs/asch_http_interface_de.md deleted file mode 100644 index d90bfaa..0000000 --- a/docs/asch_http_interface_de.md +++ /dev/null @@ -1,1976 +0,0 @@ -Inhaltsverzeichnis -================= - -- [Asch-HTTP Interface Spezifikation](#asch-http-interface-spezifikation) - - [1 Verwendung der API](#1-verwendung-der-api) - - [1.1 Übersicht über Netzwerkrequests](#11-übersicht-über-netzwerkrequests) - - [2 Interface](#2-interface) - - [2.1 Konten](#21-konten) - - [2.1.1 Login](#211-login) - - [2.1.1.1 Einloggen nachdem lokal verschlüsselt wurde (wird ausdrücklich empfohlen)](#2111-einloggen-nachdem-lokal-verschlüsselt-wurde-wird-ausdrücklich-empfohlen) - - [2.1.1.2 Einloggen ohne vorheriges lokales Verschlüssel (wird ausdrücklich nicht empfohlen)](#2112-einloggen-ohne-vorheriges-lokales-verschlüssel-wird-ausdrücklich-nicht-empfohlen) - - [2.1.2 Zeige Kontoinformationen](#212-zeige-kontoinformationen) - - [2.1.3 Zeige Saldo eines Kontos](#213-zeige-saldo-eines-kontos) - - [2.1.4 Zeigen öffentlichen Schlüssel eines Kontos](#214-zeigen-öffentlichen-schlüssel-eines-kontos) - - [2.1.5 Erzeuge öffentlichen Schlüssel](#215-erzeuge-öffentlichen-schlüssel) - - [2.1.6 Zeige eine Liste von Stimmabgaben von einer Adresse](#216-zeige-eine-liste-von-stimmabgaben-von-einer-adresse) - - [2.1.7 Zeige die Gebühren eines bestimmten Delegats](#217-zeige-die-gebühren-eines-bestimmten-delegats) - - [2.1.8 Abstimmung](#218-abstimmung) - - [2.2 Transaktionen](#22-transaktionen) - - [2.2.1 Zeige die Transaktionsdetails](#221-zeige-die-transaktionsdetails) - - [2.2.2 Zeige Details zu einer Transaktion](#222-zeige-details-zu-einer-transaktion) - - [2.2.3 Zeige Transaktionsdetails anhand von der ID einer unbestätigten Transaktion](#223-zeige-transaktionsdetails-anhand-von-der-id-einer-unbestätigten-transaktion) - - [2.2.4 Zeige unbestätigte Transaktionen [im ganzen Netzwerk]](#224-zeige-unbestätigte-transaktionen-im-ganzen-netzwerk) - - [2.2.5 Erstelle eine Transaktion](#225-erstelle-eine-transaktion) - - [2.3 Blocks](#23-blocks) - - [2.3.1 Zeige Blockinformationen anhand von ID, Blockhöhe oder Hash](#231-zeige-blockinformationen-anhand-von-id-blockhöhe-oder-hash) - - [2.3. Zeige den letzten Block an](#23-zeige-den-letzten-block-an) - - [2.3.3 Zeige die Blockhöhe](#233-zeige-die-blockhöhe) - - [2.3.4 Zeige die Transaktionsgebühr](#234-zeige-die-transaktionsgebühr) - - [2.3.5 Zeige den Milestone](#235-zeige-den-milestone) - - [2.3.6 Zeige die Belohnung für einen Block](#236-zeige-die-belohnung-für-einen-block) - - [2.3.7 Zeige die maximalen Anzahl an XAS im Umlauf](#237-zeige-die-maximalen-anzahl-an-xas-im-umlauf) - - [2.3.8 Zeige den momentanen Status der Blockchain](#238-zeige-den-momentanen-status-der-blockchain) - - [2.4 Delegate](#24-delegate) - - [2.4.1 Zeige die Anzahl aller Delegate](#241-zeige-die-anzahl-aller-delegate) - - [2.4.2 Zeige die Konten die für ein Delegat abgestimmt haben anhand des öffentlichen Schlüssels des Delegats](#242-zeige-die-konten-die-für-ein-delegat-abgestimmt-haben-anhand-des-öffentlichen-schlüssels-des-delegats) - - [2.4.3 Zeige die Details zu einem Delegat mittels öffentlichem Schlüssel oder Namen](#243-zeige-die-details-zu-einem-delegat-mittels-öffentlichem-schlüssel-oder-namen) - - [2.4.4 Zeige eine Liste aller Delegate](#244-zeige-eine-liste-aller-delegate) - - [2.4.5 Zeige die Transaktionsgebühr eines Delegats](#245-zeige-die-transaktionsgebühr-eines-delegats) - - [2.4.6 Zeige die Schmiede-Informationen (Forging) anhand eines öffentlichen Schlüssels](#246-zeige-die-schmiede-informationen-forging-anhand-eines-öffentlichen-schlüssels) - - [2.4.7 Registriere eine Delegat](#247-registriere-eine-delegat) - - [2.5 Andere Knoten](#25-andere-knoten) - - [2.5.1 Zeige die Information zu allen Knoten in einem Netzwerk](#251-zeige-die-information-zu-allen-knoten-in-einem-netzwerk) - - [2.5.2 Zeige die Asch-Versionsnummer eines Knotens](#252-zeige-die-asch-versionsnummer-eines-knotens) - - [2.5.3 Zeige die Information zu einem Knoten mittels seiner IP-Adresse](#253-zeige-die-information-zu-einem-knoten-mittels-seiner-ip-adresse) - - [2.6 Die Synchronisierung und der Lademechanismus](#26-die-synchronisierung-und-der-lademechanismus) - - [2.6.1 Zeige den lokalen Blockchain Ladestatus](#261-zeige-den-lokalen-blockchain-ladestatus) - - [2.6.2 Zeige den Status der Block-Synchronisierung](#262-zeige-den-status-der-block-synchronisierung) - - [2.7 Zweites Passwort](#27-zweites-passwort) - - [2.7.1 Setze ein zweites Passwort](#271-setze-ein-zweites-passwort) - - [2.7.2 Zeige die Gebühr für das Setzen eines zweiten Passworts](#272-zeige-die-gebühr-für-das-setzen-eines-zweiten-passworts) - - [2.8 Multi-Signatur](#28-multi-signatur) - - [2.8.1 Ein normales Konto in ein Multi-Signatur-Konto verwandeln](#281-ein-normales-konto-in-ein-multi-signatur-konto-verwandeln) - - [2.8.2 Zeige Informationen zu ausstehenden Multi-Signatur-Transaktionen](#282-zeige-informationen-zu-ausstehenden-multi-signatur-transaktionen) - - [2.8.3 Unterschriebe eine Multi-Signatur-Transaktion (als nicht Initiator)](#283-unterschriebe-eine-multi-signatur-transaktion-als-nicht-initiator) - - [2.8.4 Zeige Details zu einem Multi-Signatur Konto](#284-zeige-details-zu-einem-multi-signatur-konto) - - [2.9 Peer2Peer Transport[sichere API]](#29-peer2peer-transportsichere-api) - - [2.9.1 Übersicht](#291-übersicht) - - [2.9.2 Transaktion](#292-transaktion) - - [2.9.2.1 Setze ein zweites Bezahl-Passwort](#2921-setze-ein-zweites-bezahl-passwort) - - [2.9.2.2 Geld überweisen](#2922-geld-überweisen) - - [2.9.2.3 Ein Delegat registrieren](#2923-ein-delegat-registrieren) - - [2.9.2.4 Wahl abgeben und Stimmabgabe zurückziehen](#2924-wahl-abgeben-und-stimmabgabe-zurückziehen) - - [Appendix 1:Installiere das 'asch-js' Modul](#appendix-1installiere-das-asch-js-modul) - - -Inhaltsverzeichnis erstellt mittels [markdown-toc](https://github.com/AlanWalk/markdown-toc) - - -# Asch-HTTP Interface Spezifikation - ---- -## 1 Verwendung der API -### 1.1 Übersicht über Netzwerkrequests -- **Erstelle die Daten zum verschicken:** Laut der Asch-Interface Dokumentation müssen die Daten als JSON-Objekt versedet werden. (Um eine sichere Peer-to-Peer Verbindung herzustellen kann es hilfreich sein eine Signatur mittels asch-js zu erstellen. Siehe mehr in Abschnitt [2.9 Peer-to-Peer Transport](#29-Peer2Peer-Transport%5Bsichere-API%5D). -- **Sende Daten:** Sende das erstellte Objekt zur Asch-Plattform mittels HTTP POST/GET -- **Das Asch System überprüft die gesendeten Daten:** Nachdem der Asch-Server die Daten empfangen hat, wird er diese validieren und dann weiter verarbeiten. -- **Daten werden zurückgesandt:** Das Asch-System retouniert die Daten als JSON-Objekt. Weiterführende API-Informationen findest du weiter unten. -- **Der Client verarbeitet die empfangen Daten** - -## 2 Interface -### 2.1 Konten - -#### 2.1.1 Login -##### 2.1.1.1 Einloggen nachdem lokal verschlüsselt wurde (wird ausdrücklich empfohlen) -API Endpunkt: /api/accounts/open2/ -HTTP Verb: POST -Unterstützes Datenformat: JSON -Hinweis: Der öffentliche Schlüssel muss lokal mit Hilfe des Passwortes generiert werden (siehe Beispiel) - -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|publicKey |string |Ja|Öffentlicher Schlüssel| - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Ob der Login erfolreich war | -|account|json |Kontoinformationen| -|latestBlock|json |Informationen zum letzten Block| -|version|json |Asch-Versionsnummer| -Beispiel: - -```js -var AschJS = require('asch-js'); //Mehr Informationen zu asch-js findest du im Appendix ganz unten -var publicKey = AschJS.crypto.getKeys(secret).publicKey; //zeige die Adresse anhand des Geheimnisses -// var address = AschJS.crypto.getAddress(publicKey); //zeige die Adresse anhand des öffentlichen Schlüssels - -// Schicke die gerade gesammelten Daten an den Asch-Server mit Hilfe der HTTP POST Methode -curl -X POST -H "Content-Datentyp: application/json" -k -d '{"publicKey":"bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9"}' http://45.32.248.33:4096/api/accounts/open2/ -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "account": { - "address": "16723473400748954103", - "unconfirmedBalance": 19480000000, - "balance": 19480000000, - "unconfirmedSignature": false, - "secondSignature": true, - "secondPublicKey": "edf30942beb74de5ed6368c792af8665e9636f32a5f1c9377bcdc3b252d3f277", - "multisignatures": [], - "u_multisignatures": [] - }, - "latestBlock": { - "height": 111923, - "timestamp": 4446270 - }, - "version": { - "version": "1.0.0", - "build": "12:11:11 16/08/2016", - "net": "testnet" - } -``` - -##### 2.1.1.2 Einloggen ohne vorheriges lokales Verschlüsseln (wird ausdrücklich nicht empfohlen) -API Endpunkt: /api/accounts/open/ -HTTP Verb: POST -Unterstützes Datenformat: JSON -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|secret |string |Ja|Passwort des Asch-Kontos| - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Ob der Login erfolgreich war| -|account|json |Kontoinformationen | - -Beispiel: -```bash -curl -X POST -H "Content-Datentyp: application/json" -k -d '{"secret":"fault still attack alley expand music basket purse later educate follow ride"}' http://45.32.248.33:4096/api/accounts/open/ -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "account": { - "address": "16723473400748954103", - "unconfirmedBalance": 19480000000, - "balance": 19480000000, - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9", - "unconfirmedSignature": false, - "secondSignature": true, - "secondPublicKey": "edf30942beb74de5ed6368c792af8665e9636f32a5f1c9377bcdc3b252d3f277", - "multisignatures": [ ], - "u_multisignatures": [ ] - } -} -``` -#### 2.1.2 Zeige Kontoinformationen -API Endpunkt: /api/accounts -HTTP Verb: GET -Unterstütztes Format: urlencoded -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|address |string |Ja|Client Adresse, Minimum:1| - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert| -|account|json |Kontoinformationen| -|latestBlock|json |Informationen zum letzten Block| -|version|json |Asch-Versionsnummer| - -Beispiel: -```bash -curl -k -X GET http://45.32.248.33:4096/api/accounts?address=16723473400748954103 -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "account": { - "address": "16723473400748954103", //Asch Adresse - "unconfirmedBalance": 19480000000, //Die Summe des unbestätigten und des bereits bestätigten Saldos. Dieses sollte größer als das Saldo weiter unten sein. - "balance": 19480000000, //Saldo - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9", //Öffentlicher Schlüssel - "unconfirmedSignature": false, - "secondSignature": true, //zweite Signatur - "secondPublicKey": "edf30942beb74de5ed6368c792af8665e9636f32a5f1c9377bcdc3b252d3f277", //zweiter öffentlicher Schlüssel - "multisignatures": [], - "u_multisignatures": [] - }, - "latestBlock": { - "height": 114480, //Blockhöhe - "timestamp": 4471890 - }, - "version": { - "version": "1.0.0", - "build": "12:11:11 16/08/2016", //Datum des Builds - "net": "testnet" //Blockchain-Typ: Mainnet oder Testnet - } -} -``` -#### 2.1.3 Zeige Saldo eines Kontos -API Endpunkt: /api/accounts/getBalance -HTTP Verb: GET -Unterstütztes Format: urlencoded -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|address |string |Ja|Kontoadresse, Minimum:1 | - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert | -|balance|integer |Saldo | -|unconfirmedBalance|integer|Die Summe des unbestätigten und des bereits bestätigten Saldos. Dieses sollte größer als das Saldo sein.| - - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/accounts/getBalance?address=14636456069025293113' -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "balance": 5281328514990, - "unconfirmedBalance": 5281328514990 -} -``` - -#### 2.1.4 Zeige öffentlichen Schlüssel eines Kontos -API Endpunkt: /api/accounts/getPublickey -HTTP Verb: GET -Unterstütztes Format: urlencoded -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|address |string |Ja|Adresse, Minimum:1 | - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|publicKey|string |Öffentlicher Schlüssel| - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/accounts/getPublickey?address=14636456069025293113' -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "publicKey": "ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7" -} -``` - -#### 2.1.5 Erzeuge öffentlichen Schlüssel -API Endpunkt: /api/accounts/generatePublickey -HTTP Verb: POST -Unterstützes Datenformat: JSON -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|secret |string |Ja|Passwort des Asch-Kontos| - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|publicKey|string |Öffentlicher Schlüssel| - -Beispiel: -```bash -curl -k -H "Content-Datentyp: application/json" -X POST -d '{"secret":"fault still attack alley expand music basket purse later educate follow ride"}' 'http://45.32.248.33:4096/api/accounts/generatePublickey' -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9" -} -``` - -#### 2.1.6 Zeige eine Liste von Stimmabgaben von einer Adresse -API Endpunkt: /api/accounts/delegates -HTTP Verb: GET -Unterstütztes Format: urlencoded -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|address |string |Ja|Die Adresse welche die Stimme abgegeben hat| - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|delegates|Array |Eine Liste mit Kontos für welche diese Adresse bereits gestimmt hat| - - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/accounts/delegates?address=14636456069025293113' -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "delegates": [{ - "username": "wgl_002", - "address": "14636456069025293113", - "publicKey": "ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7", - "vote": 9901985415600500, - "producedblocks": 1373, - "missedblocks": 6, - "rate": 1, - "approval": "98.54", - "productivity": "99.56" - }, - { - "username": "wgl_003", - "address": "9961157415582672274", - "publicKey": "c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2", - "vote": 9891995435600500, - "producedblocks": 1371, - "missedblocks": 8, - "rate": 2, - "approval": "98.44", - "productivity": "99.41" - }, - { - "username": "wgl_001", - "address": "1869971419039689816", - "publicKey": "c547df2dde6cbb4508aabcb5970d8f9132e5a1d1c422632da6bc20bf1df165b8", - "vote": 32401577128413, - "producedblocks": 969, - "missedblocks": 8, - "rate": 102, - "approval": "0.32", - "productivity": 0 - }] -} -``` - -#### 2.1.7 Zeige die Gebühren eines bestimmten Delegats -API Endpunkt: /api/accounts/delegates/fee -HTTP Verb: GET -Unterstütztes Format: keine -Beschreibung der Parameter: keine - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|fee|integer |Gebühren-Einstellungen | - - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/accounts/delegates/fee -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "fee": 100000000 -} -``` - - -#### 2.1.8 Abstimmung -API Endpunkt: /api/accounts/delegates -HTTP Verb: PUT -Unterstützes Datenformat: JSON -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|secret |string |Ja|Passwort des Asch-Kontos| -|publicKey|string |Nein|Öffentlicher Schlüssel| -|secondSecret|string|Nein|Zweites Asch-Konto Passwort. Länge zwischen 1 und 100| -|delegates|Array||Eine Liste mit öffentlichen Schlüssel von Delegaten. Setze ein Plus (+) oder ein Minus (-) vor den öffentlichen Schlüssel um zu signalisieren, dass es sich um eine Stimmabgabe bzw. um die Rückziehung einer Stimme handelt. - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|transaction|json |Informationen zur Stimmabgabe | - - -Beispiel: -```bash -curl -k -H "Content-Datentyp: application/json" -X PUT -d '{"secret":"call scissors pupil water friend timber spend brand vote obey corn size","publicKey":"3ec1c9ec08c0512641deba37c0e95a0fe5fc3bdf58424009f594d7d6a4e28a2a","delegates":["+fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575"]}' 'http://45.32.248.33:4096/api/accounts/delegates' -``` - -Mögliche JSON Antwort: -```js - { - "success": true, - "transaction": { - "type": 3, //Der Datentyp der Stimmabgabe ist '3' - "amount": 0, - "senderPublicKey": "3ec1c9ec08c0512641deba37c0e95a0fe5fc3bdf58424009f594d7d6a4e28a2a", - "requesterPublicKey": null, - "timestamp": 5056064, - "asset": { - "vote": { - "votes": ["+fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575"] - } - }, - "recipientId": null, - "signature": "0bff58c7311fc59b3c8b3ffc236bbfece9850c334fb0c292ab087f78cf9a6c0f4d3e541c501887a2c2ec46294c777e8f7bf7dea9cb7c9a175fdec641bb684f08", - "id": "5630629337798595849", - "fee": 10000000, - "senderId": "15238461869262180695" - } -} -``` - -### 2.2 Transaktionen -#### 2.2.1 Zeige die Transaktionsdetails -API Endpunkt: /api/transactions -HTTP Verb: GET -Unterstütztes Format: urlencoded -Hinweis: Falls kein Parameter angegeben wird, dann werden alle Transaktionen retourniert - -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|blockId |string |Nein|BlockID| -|limit |integer |Nein|Rückgabe der Datensätze limitieren,Minimum:0, Maximum:100 | -|type|integer |Nein|Die Transaktions-Datentypen: 0:Normaler Transfer,1:Setzen eines zweiten Passworts,2:Delegat registrieren,3:Stimmabgabe,4:Multi-Signatur,5:DAPP,6:IN_TRANSFER,7:OUT_TRANSFER| -|orderBy|string |Nein|Sortiere nach einem Feld in der Tabelle,senderPublicKey:desc (asc=aufsteigend, desc=absteigend)| -|offset|integer |Nein|Paging-Abstand, Minimum 0| -|senderPublicKey|string|Nein|Öffentlicher Schlüssel des Senders| -|ownerPublicKey|string|Nein|| -|ownerAddress|string|Nein|| -|senderId|string|Nein|Adresse des Senders| -|recipientId|string|Nein|Adresse des Empfängers, Minimum:1| -|amount|integer|Nein|Betrag| -|fee|integer|Nein|Gebühr| - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|transactions|Array |Eine Liste mit Transaktionsdetails| -|count|int|Anzahl der aufgelisteten Transaktionen| - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/transactions?recipientId=16723473400748954103&orderBy=t_timestamp:desc&limit=3' -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "transactions": [{ - "id": "17192581936339156329", - "height": "105951", - "blockId": "15051364118100195665", - "type": 0, - "timestamp": 4385190, - "senderPublicKey": "d39d6f26869067473d685da742339d1a9117257fe14b3cc7261e3f2ed5a339e3", - "senderId": "15745540293890213312", - "recipientId": "16723473400748954103", - "amount": 10000000000, - "fee": 10000000, - "signature": "98d65df3109802c707eeed706e90a907f337bddab58cb4c1fbe6ec2179aa1c85ec2903cc0cf44bf0092926829aa5a0a6ec99458f65b6ebd11f0988772e58740e", - "signSignature": "", - "signatures": null, - "confirmations": "31802", - "asset": { - - } - }, - { - "id": "7000452951235123088", - "height": "105473", - "blockId": "11877628176330539727", - "type": 0, - "timestamp": 4380147, - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "senderId": "16358246403719868041", - "recipientId": "16723473400748954103", - "amount": 10000000000, - "fee": 10000000, - "signature": "dc84044d4f6b4779eecc3a986b6507e458cc5964f601ebeb4d3b68a96129813f4940e14de950526dd685ca1328b6e477e6c57e95aeac45859a2ea62a587d0204", - "signSignature": "", - "signatures": null, - "confirmations": "32280", - "asset": { - - } - }, - { - "id": "14093929199102906687", - "height": "105460", - "blockId": "2237504897174225512", - "type": 0, - "timestamp": 4380024, - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "senderId": "16358246403719868041", - "recipientId": "16723473400748954103", - "amount": 10000000000, - "fee": 10000000, - "signature": "73ceddc3cbe5103fbdd9eee12f7e4d9a125a3bcf2e7cd04282b7329719735aeb36936762f17d842fb14813fa8f857b8144040e5117dffcfc7e2ae88e36440a0f", - "signSignature": "", - "signatures": null, - "confirmations": "32293", - "asset": { - - } - }], - "count": 3 -} -``` -#### 2.2.2 Zeige Details zu einer Transaktion -API Endpunkt: /api/transactions/GET -HTTP Verb: GET -Unterstütztes Format: urlencoded -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|Id |string |Ja|TransaktionsId| - - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|transactions|json |Transaktionsdetails| - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/transactions/get?id=14093929199102906687' -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "transaction": { - "id": "14093929199102906687", - "height": "105460", - "blockId": "2237504897174225512", - "type": 0, - "timestamp": 4380024, - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "senderId": "16358246403719868041", - "recipientId": "16723473400748954103", - "amount": 10000000000, - "fee": 10000000, - "signature": "73ceddc3cbe5103fbdd9eee12f7e4d9a125a3bcf2e7cd04282b7329719735aeb36936762f17d842fb14813fa8f857b8144040e5117dffcfc7e2ae88e36440a0f", - "signSignature": "", - "signatures": null, - "confirmations": "34268", - "asset": { - } - } -} -``` - -#### 2.2.3 Zeige Transaktionsdetails anhand von der ID einer unbestätigten Transaktion -API Endpunkt: /api/transactions/unconfirmed/GET -HTTP Verb: GET -Unterstütztes Format: urlencoded -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|id|string |Ja|Id einer unbestätigten Transaktion| - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|transaction|json |Die Informationen zu der unbestätigten Transaktion| - - -Beispiel: -```bash -curl -k -X GET http://45.32.248.33:4096/api/transactions/unconfirmed/get?id=7557072430673853692 //Normalerweise existiert eine unbestätigte Transaktion nur für wenige Sekunden (0-10 Sekunden). -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "transaction": { - "type": 0, - "amount": 10000, - "senderPublicKey": "3ec1c9ec08c0512641deba37c0e95a0fe5fc3bdf58424009f594d7d6a4e28a2a", - "requesterPublicKey": null, - "timestamp": 5082322, - "asset": { - - }, - "recipientId": "16723473400748954103", - "signature": "3a97f8d63509ef964bda3d816366b8e9e2d9b5d4604a660e7cbeefe210cb910f5de9a51bece06c32d010f55502c62f0f59b8224e1c141731ddfee27206a88d02", - "id": "7557072430673853692", - "fee": 10000000, - "senderId": "15238461869262180695" - } -} -``` - - -#### 2.2.4 Zeige unbestätigte Transaktionen (im ganzen Netzwerk) -API Endpunkt: /api/transactions/unconfirmed -HTTP Verb: GET -Unterstütztes Format: urlencoded -Hinweis: Falls kein Parameter angegeben wurde, werden alle unbestätigten Transaktionen retourniert -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|senderPublicKey |string |Nein|Der öffentliche Schlüssel des Senders| -|address |string |Nein|Adresse| - - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert| -|transactions|Array |Eine Liste mit allen unbestätigten Transaktionen| - - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/transactions/unconfirmed' -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "transactions": [] //Zur Zeit existieren keine unbestätigten Transaktionen im Netzwerk -} -``` - -#### 2.2.5 Erstelle eine Transaktion -API Endpunkt: /api/transactions -HTTP Verb: PUT -Unterstützes Datenformat: JSON -Hinweis: Der Empfänger muss (vor der Transaktion) bereits sich einmal in die Web-Wallet eingeloggt haben. -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|secret |string |Ja|Passwort des Asch-Kontos| -|amount|integer|Ja|Betrag,muss zwischen 1 und 10000000000000000 (10^16^) sein| -|recipientId|string|Ja|Addresse des Empfängers, Minimum:1| -|publicKey|string|Nein|Öffentlicher Schlüssel des Senders| -|secondSecret|string|Nein|Zweites Passwort des Sender (dieses muss dem [BIP39 Standard](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) entsprechen), die Länge muss zwischen 1 und 100 sein| -|multisigAccountPublicKey|string|Nein|Der öffentliche Schlüssel eines Multi-Signatur-Kontos| - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|transactionId|string |Transaktions-ID| - - -Beispiel: -```bash -curl -k -H "Content-Datentyp: application/json" -X PUT -d '{"secret":"unaware label emerge fancy concert long fiction report affair appear decide twenty","amount":1000000,"recipientId":"16723473400748954103"}' 'http://45.32.248.33:4096/api/transactions' -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "transactionId": "16670272591943275531" -} -``` - -### 2.3 Blocks -#### 2.3.1 Zeige Blockinformationen anhand von ID, Blockhöhe oder Hash -API Endpunkt: /api/blocks/ -HTTP Verb: GET -Unterstütztes Format: urlencoded -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung| -|------ |----- |--- |---- | -|id |string |only choose one of these three parameters |BlockID| -|height|string|ditto|Blockhöhe| -|hash|string|ditto|Der Hash des blocks| - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|block|json |Die Blockdetails| - - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/get?id=6076474715648888747' -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "block": { - "id": "6076474715648888747", - "version": 0, - "timestamp": 4734070, - "height": 140538, - "previousBlock": "16033230167082515105", //vorherige block ID - "numberOfTransactions": 0, //Anzahl der Transaktionen - "totalAmount": 0, //Summe der Transaktionen - "totalFee": 0, - "reward": 350000000, //Belohnung - "payloadLength": 0, - "payloadHash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "generatorPublicKey": "1d352950c8141e1b35daba4a974a604519d7a2ef3a1ec0a503ce2653646aa052", - "generatorId": "6656029629904254066", - "blockSignature": "a53de66922cdc2f431acd0a474beec7cf7c420a8460b7b7caf84999be7caebb59fb7fbb7166c2c7013dbb431585ea7294722166cb08bf9663abf50b6bd81cd05", - "confirmations": "2", - "totalForged": 350000000 - } -} -``` - -#### 2.3. Zeige den letzten Block an -API Endpunkt: /api/blocks -HTTP Verb: GET -Unterstütztes Format: urlencoded -Hinweis: Falls kein Parameter spezifiziert wird, dann werden die Details zu allen Blöcken im Netzwerk zurückgegeben. -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|limit |integer |Nein|Maximal zu retounierende Anzahl an Datensätzen, muss zwischen 0 und 100 sein| -|orderBy|string |Nein|Sortiere anhand eines Feldes in der Tabelle z.B.: height:desc (asc=aufsteigend, desc=absteigend) | -|offset|integer |Nein|Paging-Abstand, minimum 0 | -|generatorPublicKey|string |Nein|Öffentlicher Schlüssels des Blockgenerators| -|totalAmount|integer |Nein|Anzahl aller Transaktionen, muss zwischen 0 und 10000000000000000 (10^16^) sein | -|totalFee|integer |Nein|Summe der Transaktionsgebühr, muss zwischen 0 und 10000000000000000 (10^16^) sein| -|reward|integer |Nein|Belohnung, Minimum: 0 | -|previousBlock|string |Nein|Vorhergehender Block | -|height|integer |Nein|Blockhöhe| - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|blocks|Array |Eine Liste von Blockdetails| -|count|integer|Blockhöhe| - - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks?limit=2&offset=0&orderBy=height:desc' -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "blocks": [{ - "id": "12634047624004615059", - "version": 0, - "timestamp": 4708080, - "height": 137986, - "previousBlock": "3498191422350401106", - "numberOfTransactions": 0, // die Anzahl der Transaktionen - "totalAmount": 0, // Summe der Transaktionen - "totalFee": 0, // Transaktionsgebühr - "reward": 350000000, // Belohnung - "payloadLength": 0, - "payloadHash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "generatorPublicKey": "44db7bec89ef289d0def257285675ca14f2a947dfd2b70e6b1cff4392ce42ada", - "generatorId": "4925169939071346193", - "blockSignature": "83a2124e3e8201c1a6099b2ac8ab1c117ad34867978add3a90d41a64df9d2ad8fabc9ec14d27a77cd34c08a6479ef684f247c11b1cbbcb0e9767dffc85838600", - "confirmations": "1", - "totalForged": 350000000 - }, - { - "id": "3498191422350401106", - "version": 0, - "timestamp": 4708070, - "height": 137985, - "previousBlock": "14078155423801039323", - "numberOfTransactions": 0, - "totalAmount": 0, - "totalFee": 0, - "reward": 350000000, - "payloadLength": 0, - "payloadHash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "generatorPublicKey": "500b1ec025cd64d36008341ed8d2508473ecf559be213ca5f9580620a21a592c", - "generatorId": "16006295608945777169", - "blockSignature": "a0b5ed6c94b1f33c4d0f017f21a08357061493392b19e34eeedf274b77c751e3f86c92443280de09ea1754d62fe7ef00e02acbdc3bc0c1063cef344bacaa4f07", - "confirmations": "2", - "totalForged": 350000000 - }], - "count": 137986 -} -``` - -#### 2.3.3 Zeige die Blockhöhe -API Endpunkt: /api/blocks/getHeight -HTTP Verb: GET -Unterstütztes Format: keine -Beschreibung der Parameter: keine -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|height|integer |Blockhöhe| - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/getheight' -``` - -Mögliche JSON Antwort: -```js -{"success":true,"height":140569} -``` - -#### 2.3.4 Zeige die Transaktionsgebühr -API Endpunkt: /api/blocks/getFee -HTTP Verb: GET -Unterstütztes Format: keine -Beschreibung der Parameter: keine -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|fee|integer |Transaktionsgebühr| - - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/getfee' -``` - -Mögliche JSON Antwort: -```js -{"success":true,"fee":10000000} //die Transaktionsgebühr ist 0.1 XAS -``` - -#### 2.3.5 Zeige den Milestone -API Endpunkt: /api/blocks/getMilestone -HTTP Verb: GET -Unterstütztes Format: keine -Beschreibung der Parameter: keine -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|milestone|integer | | - - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/getMilestone' -``` - -Mögliche JSON Antwort: -```js -{"success":true,"milestone":0} -``` - -#### 2.3.6 Zeige die Belohnung für einen Block -API Endpunkt: /api/blocks/getReward -HTTP Verb: GET -Unterstütztes Format: keine -Beschreibung der Parameter: keine -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|reward|integer |Die Belohnung für den Block| - - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/getReward' -``` - -Mögliche JSON Antwort: -```js -{"success":true,"reward":350000000} //jeder von dir erzeugte Block wird mit 3.5 XAS belohnt -``` - -#### 2.3.7 Zeige die maximalen Anzahl an XAS im Umlauf -API Endpunkt: /api/blocks/getSupply -HTTP Verb: GET -Unterstütztes Format: keine -Beschreibung der Parameter: keine -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|supply|integer |XAS Summe im ganzen Netzwerk| - - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/getSupply' -``` - -Mögliche JSON Antwort: -```js -{"success":true,"supply":10049222600000000} //Zur Zeit existieren 100492226 XAS im Testnet -``` - -#### 2.3.8 Zeige den momentanen Status der Blockchain -API Endpunkt: /api/blocks/getStatus -HTTP Verb: GET -Unterstütztes Format: keine -Beschreibung der Parameter: keine -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert| -|height|integer |Höhe der Blockchain| -|fee|integer |Transaktionsgebühr| -|milestone|integer | | -|reward|integer |Belohnung des Blocks| -|supply|integer |XAS Summe im ganzen Netzwerk| - - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/getStatus' -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "height": 140649, - "fee": 10000000, - "milestone": 0, - "reward": 350000000, - "supply": 10049227150000000 -} -``` - - - -### 2.4 Delegate - -#### 2.4.1 Zeige die Anzahl aller Delegate -API Endpunkt: /api/delegates/count -HTTP Verb: GET -Unterstütztes Format: keine -Beschreibung der Parameter: keine - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|count|integer |Die Summe aller Delegate| - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/delegates/count' -``` - -Mögliche JSON Antwort: -```js -{"success":true,"count":234} -``` - -#### 2.4.2 Zeige die Konten die für ein Delegat abgestimmt haben anhand des öffentlichen Schlüssels des Delegats -API Endpunkt: /api/delegates/voters -HTTP Verb: GET -Unterstütztes Format: urlencoded -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|publicKey |string |Ja|Der öffentliche Schülssel des Delegats| - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|accounts|Array |Eine Kontenliste| - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/delegates/voters?publicKey=ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7' -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "accounts": [{ - "address": "2918354313445278349", - "publicKey": "4fde4c49f1297d5d3a24b1494204543c4281aff17917ff7ff8ff32da3b4b222f", - "balance": 1338227722727, - "weight": 0.013316660647014596 - }, - { - "address": "1523444724068322527", - "publicKey": "8a6a61c28dc47541aadf1eecec2175c8f768f2331eea3472b1593bf1aa4e1fb4", - "balance": 2109297623765, - "weight": 0.020989552213127274 - }, - { - "address": "14483826354741911727", - "publicKey": "5dacb7983095466b9b037690150c3edec0f073815326e33a4744b6d1d50953e2", - "balance": 5135815841470, - "weight": 0.051106336795243436 - } - }] -} -``` - -#### 2.4.3 Zeige die Details zu einem Delegat mittels öffentlichem Schlüssel oder Namen -API Endpunkt: /api/delegates/get/ -HTTP Verb: GET -Unterstütztes Format: urlencoded -Hinweis: Greife auf die Details des Delegats über seinen öffentlichen Schlüssel oder seinen Benutzernamen zu. -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|publickey |string |choose only one parameter of these two |Der öffentliche Schlüssel des Delegats| -|username |string |ditto |Der Benutzername des Delegats| - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|delegate|json |the detail information of this delegate | - - -Beispiel: -```bash -curl -k -X GET http://45.32.248.33:4096/api/delegates/get?publicKey=bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9 -curl -k -X GET http://45.32.248.33:4096/api/delegates/get?username=delegate_register -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "delegate": { - "username": "delegate_register", - "address": "16723473400748954103", - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9", - "vote": 0, - "producedblocks": 0, - "missedblocks": 0, - "fees": 0, - "rewards": 0, - "rate": 191, - "approval": 0, - "productivity": 0, - "forged": "0" - } -} -``` - -#### 2.4.4 Zeige eine Liste aller Delegate -API Endpunkt: /api/delegates -HTTP Verb: GET -Unterstütztes Format: urlencoded -Hinweis: if there is no parameter, all delegates in the whole network will be returned. -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|address |string |Nein|delegate's address | -|limit|int |Nein|maximum return records | -|offset|integer |Nein|offset, minimum: 0 | -|orderBy|string |Nein|[field used to sort]:[sort Datentyp] e.g., address:desc | - - - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|delegates|Array |a list containing delegates' detail information | - - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/delegates?orderby=approval:desc&limit=2' //the first two delegates order by approval vote, descendingly -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "delegates": [{ - "username": "wgl_002", //delegate's user name - "address": "14636456069025293113", //delegate's address - "publicKey": "ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7", //delegate's public key - "vote": 9901984015600500, //the number of vote - "producedblocks": 1371, //the number of generated blocks - "missedblocks": 6, //the number of missed blocks - "fees": 12588514990, - "rewards": 276850000000, //the gained reward - "rate": 1, - "approval": 98.54, //the rate of approval votes - "productivity": 99.56, //the productivity - "forged": "289438514990" //All reward from forge - }, - { - "username": "wgl_003", - "address": "9961157415582672274", - "publicKey": "c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2", - "vote": 9891994035600500, - "producedblocks": 1370, - "missedblocks": 8, - "fees": 12355148480, - "rewards": 275100000000, - "rate": 2, - "approval": 98.44, - "productivity": 99.42, - "forged": "287455148480" - }], - "totalCount": 233 -} -``` - - - - - - -#### 2.4.5 Zeige die Transaktionsgebühr eines Delegats -API Endpunkt: /api/delegates/fee -HTTP Verb: GET -Unterstütztes Format: urlencoded -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|publicKey |string |Ja|Der öffentliche Schlüssel des Delegats|| - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|fee|integer |Transaktionsgebühr| - - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/delegates/fee?publicKey=ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7' -``` - -Mögliche JSON Antwort: -```js -{"success":true,"fee":10000000000} //0.1 XAS -``` - -#### 2.4.6 Zeige die Schmiede-Informationen (Forging) anhand eines öffentlichen Schlüssels -API Endpunkt: /api/delegates/forging/getForgedByAccount -HTTP Verb: GET -Unterstütztes Format: urlencoded -Beschreibung der Parameter: - -|Name|Datentyp|Obligatorisch|Beschreibung | -|------ |----- |--- |---- | -|generatorPublicKey |string |Ja|Der öffentliche Schlüssel des Block-Generators| - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert| -|fees|integer |Die Summe der Transaktionsgebühren| -|rewards|integer|Errungene Belohnungen| -|forged|integer|Summe der Belohnungen von der Schmiede-Aktivität (Forging)| - - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/delegates/forging/getForgedByAccount?generatorPublicKey=ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7' -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "fees": 12589307065, - "rewards": 285600000000, - "forged": 298189307065 -} -``` - -#### 2.4.7 Registriere eine Delegat -API Endpunkt: /api/delegates -HTTP Verb: PUT -Unterstütztes Format: urlencoded -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|secret |string |Ja|Passwort des Asch-Kontos| -|publicKey|string |Nein|Öffentlicher Schlüssel| -|secondSecret|string|Nein|Zweites Asch-Konto Passwort, Minimale Länge: 1 Maximale Länge: 100| -|username|string|Nein|Der Benutzername des Delegats| - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|transaction|json |Die Details zum Registrierungsprozess| - - -Beispiel: -```bash -curl -k -H "Content-Datentyp: application/json" -X PUT -d '{"secret":"unaware label emerge fancy concert long fiction report affair appear decide twenty","username":"delegate_0821"}' 'http://45.32.248.33:4096/api/delegates' -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "transaction": { - "type": 2, //der Transaktions-Typ einer Delegat-Registrierung ist 2 - "amount": 0, - "senderPublicKey": "3b64f1833e6328043e1f2fee31e638bdaa6dfff5c7eb9c8577a5cefcf11261f2", - "requesterPublicKey": null, - "timestamp": 4737615, - "asset": { - "delegate": { - "username": "delegate_0821", - "publicKey": "3b64f1833e6328043e1f2fee31e638bdaa6dfff5c7eb9c8577a5cefcf11261f2" - } - }, - "recipientId": null, - "signature": "7f8417e8db5f58ddff887c86c789c26b32fd3f01083ef1e3c8d4e18ed16622bf766492d78518c6c7a07aada1c98b1efc36d40c8e09394989dbde229d8e3f8103", - "id": "16351320834453011577", - "fee": 10000000000, - "senderId": "250438937633388106" - } -} -``` - -### 2.5 Andere Knoten - -#### 2.5.1 Zeige die Information zu allen Knoten in einem Netzwerk -API Endpunkt: /api/peers -HTTP Verb: GET -Unterstütztes Format: urlencoded -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|state |integer |Nein|Stati der Peers: 0:,1:,2:,3: | -|os|string|Nein|Linux Kernel Version| -|version|string|Nein|Asch-System Version| -|limit |integer |Nein|Anzahl der maximal zu retournierenden Datensätze, Minimum: 0, Maximum: 100| -|orderBy|string|Nein|| -|offset|integer |Nein|Abstand, Minimum: 0| -|port|integer|Nein|Port-Nummer,1~65535| - - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|peers|Array |Eine Liste von Knoteninformationen| -|totalCount|integer|Die Anzahl an gerade laufenden Knoten| - - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/peers?limit=1' -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "peers": [{ - "ip": "45.32.19.241", - "port": 4096, - "state": 2, - "os": "linux3.13.0-87-generic", - "version": "1.0.0" - }], - "totalCount": ["54"] -} -``` - -#### 2.5.2 Zeige die Asch-Versionsnummer eines Knotens -API Endpunkt: /api/peers/version -HTTP Verb: GET -Unterstütztes Format: keine -Beschreibung der Parameter: keine - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|version|string |Versionsnummer| -|build |timestamp |Zeitpunkt des Builds| -|net |string |Läuft der Knoten auf dem Mainnet oder auf dem Testnet| - - -Beispiel: -```bash -curl -k -X GET http://45.32.248.33:4096/api/peers/version -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "version": "1.0.0", - "build": "12:11:11 16/08/2016", - "net": "testnet" -} -``` - -#### 2.5.3 Zeige die Information zu einem Knoten mittels seiner IP-Adresse -API Endpunkt: /api/peers/GET -HTTP Verb: GET -Unterstütztes Format: urlencoded -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|ip |string |Ja|peer's IP | -|port|integer|Ja|peer's port,1~65535| - - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|peer|json |Die Information zu dem Knoten | - - -Beispiel: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/peers/get?ip=45.32.248.33&port=4096' -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "peer": { - } -} -``` - -### 2.6 Die Synchronisierung und der Lademechanismus -#### 2.6.1 Zeige den lokalen Blockchain Ladestatus -API Endpunkt: /api/loader/status -HTTP Verb: GET -Unterstütztes Format: keine -Beschreibung der Parameter: keine - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool|Die Daten wurden erfolgreich retouniert| -|loaded |bool| | -|blocksCount|integer|Anzahl der Blocks| - -Beispiel: -```bash -curl -k http://45.32.248.33:4096/api/loader/status -X GET -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "loaded": true, - "blocksCount": 0 -} -``` - -#### 2.6.2 Zeige den Status der Block-Synchronisierung -API Endpunkt: /api/loader/status/sync -HTTP Verb: GET -Unterstütztes Format: keine -Beschreibung der Parameter: keine - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool|Die Daten wurden erfolgreich retouniert| -|height |int|Blockhöhe| - - -Beispiel: -```bash -curl -k http://45.32.248.33:4096/api/loader/status/sync -X GET -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "syncing": false, // zeigt ob gerade sychronisiert wird. Wenn Ja, dann ist der Wert "true". Wenn keine Daten synchronisiert werden, dann ist der Wert "false". - "blocks": 0, - "height": 111987 -} -``` - -### 2.7 Zweites Passwort -#### 2.7.1 Setze ein zweites Passwort -API Endpunkt: /api/signatures -HTTP Verb: PUT -Unterstützes Datenformat: JSON -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|secret |string |Ja|Asch account's password | -|publicKey|string |Nein|Öffentlicher Schlüssel| -|secondSecret|string|Ja|Das zweite Passwort eines Asch-Kontos. Minimale Länge:1,Maximale Länge:100| -|multisigAccountPublicKey|string|Nein|Der öffentliche Schlüssel eines Multi-Signatur-Kontos| - - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert| -|transaction|json|the detail information of setting transaction| - - -Beispiel: -```bash -curl -k -H "Content-Datentyp: application/json" -X PUT -d '{"secret":"unaware label emerge fancy concert long fiction report affair appear decide twenty","secondSecret":"fault still attack alley expand music basket purse later educate follow ride"}' 'http://45.32.248.33:4096/api/signatures' -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "transaction": { - "type": 1, //Der Transaktions-Typ für das Setzen eines zweiten Passworts ist 1 - "amount": 0, - "senderPublicKey": "3b64f1833e6328043e1f2fee31e638bdaa6dfff5c7eb9c8577a5cefcf11261f2", - "requesterPublicKey": null, - "timestamp": 4872315, - "asset": { - "signature": { - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9" - } - }, - "recipientId": null, - "signature": "e76d9b25ec0fdaa88b19d59c5a222b7efdc04f738ee05896f55f4e6959229d9b1600ca25aa92fbea176668f3be7c12c506f2091e2b38c52ef0ece7a5d35e240a", - "id": "1614688380530105232", - "fee": 500000000, //Die Gebühr für das Setzen eines zweiten Passworts sind 5 XAS - "senderId": "250438937633388106" - } -} -``` - -#### 2.7.2 Zeige die Gebühr für das Setzen eines zweiten Passworts -API Endpunkt: /api/signatures/fee -HTTP Verb: GET -Unterstütztes Format: keine -Beschreibung der Parameter: keine - - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|fee|integer |Transaktionsgebühr| - - -Beispiel: -```bash -curl -k http://45.32.248.33:4096/api/signatures/fee -X GET -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "fee": 500000000 //5 XAS -} -``` - -### 2.8 Multi-Signatur -#### 2.8.1 Ein normales Konto in ein Multi-Signatur-Konto verwandeln -API Endpunkt: /api/multisignatures -HTTP Verb: PUT -Unterstützes Datenformat: JSON -Hinweis: Die Return-Wert ist ausschließlich die Transaktions-Id. Um erfolgreich ein Multi-Signatur-Konto zu eröffnen bedarf es weiterer Signaturen. Jede Transaktion nach dem Erstellen eines Multi-Signatur-Kontos benötigt mehrere Signaturen. Die kleinste Anzahl an Signaturen welche mit übertragen werden müssen wird festgehalten im Parameter "min" (schließt den Sender mit ein). -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|secret |string |Ja|Das Passwort des Asch-Kontos| -|publicKey|string |Nein|Öffentlicher Schlüssel| -|secondSecret|string|Nein|Das zweite Passwort des Asch-Kontos. Minimale Länge: 1, Maximale Länge: 100| -|min|integer|Ja|Die minimale Anzahl an Signaturen welche für eine Transaktion eines Multi-Signatur-Kontos verwendet werden muss. (Bei der Registrierung eines Multi-Signatur-Kontos hat dieser Parameter keine Bedeutung da jedes teilnehmende Konto die Transaktion unterzeichnen muss.) Minumum: 2, Maximum: 16. Diese Zahl darf nicht größer sein als "keysgroup.length + 1". | -|lifetime|integer|Ja|Die maximale Lebensdauer einer Multi-Signatur-Transaktion. Minimum:1, Maximum:24. HINWEIS: Dieser Parameter kann zur Zeit nicht verwendet werden.| -|keysgroup|array|Ja|Eine Liste mit allen öffentlichen Schlüssel der anderen Unterzeichner. Die Symbole Plus/Minus (+/-) vor einem öffentlichen Schlüssel bedeuten, dass ein Multi-Signatur-Konto hinzugefügt wird (+), oder ein Multi-Signatur-Konto entfernt wird (-). Minimale Anzahl an Konten:1, Maximum Anzahl an Konten Konten:10.| - - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|transactionId|string |die Multi-Signatur-TransaktionsId| - - -Beispiel: -```bash -curl -k -H "Content-Datentyp: application/json" -X PUT -d '{"secret":"vanish deliver message evil canyon night extend unusual tell prosper issue antenna","min":2,"lifetime":1,"keysgroup":["+eb48b9ab7c9a34a9b7cdf860265d65b31af774355cabf1b3a387d14a1925dc97","+d5d7aa157f866c47a2a1e09e2746286ed089fd90976b54fbfa930e87d11609cb"]}' 'http://45.32.248.33:4096/api/multisignatures' //der öffentliche Schlüssel ist 2cef5711e61bb5361c544077aa08aebc4d962a1d656571901c48d716382ad4fd -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "transactionId": "17620378998277022323" //Ausschließlich die TransaktionsId wird retouniert. Um erfolgreich ein Multi-Signatur-Konto zu eröffnen benötigt es mehrere Konto-Signaturen. -} -``` - -#### 2.8.2 Zeige Informationen zu ausstehenden Multi-Signatur-Transaktionen -API Endpunkt: /api/multisignatures/pending -HTTP Verb: GET -Unterstütztes Format: urlencoded -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|publicKey|string |Ja|Öffentlicher Schlüssel| - - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|transactions|Array |Eine Liste der ausstehenden transaktionen| - - -Beispiel: -```bash -curl -k -X GET http://45.32.248.33:4096/api/multisignatures/pending?publicKey=2cef5711e61bb5361c544077aa08aebc4d962a1d656571901c48d716382ad4fd -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "transactions": [{ //die Informationen zu der Multi-Signatur-Transaktion (siehe 2.8.1, TransaktionsId: 17620378998277022323) - "min": 2, - "lifetime": 1, - "signed": true, - "transaction": { - "type": 4, //4 bedeutet, dass ein Multi-Signatur-Konto registriert wird - "amount": 0, - "senderPublicKey": "2cef5711e61bb5361c544077aa08aebc4d962a1d656571901c48d716382ad4fd", - "requesterPublicKey": null, - "timestamp": 4879978, - "asset": { - "multisignature": { - "min": 2, - "keysgroup": ["+eb48b9ab7c9a34a9b7cdf860265d65b31af774355cabf1b3a387d14a1925dc97", - "+d5d7aa157f866c47a2a1e09e2746286ed089fd90976b54fbfa930e87d11609cb"], - "lifetime": 1 - } - }, - "recipientId": null, - "signature": "a42feaccd9f2a4940fc0be1a1580e786b360f189db3154328f307988e75484293eae391f2f9eee489913cc6d15984eb1f5f5a0aa1bf78ea745d5c725f161af08", - "id": "17620378998277022323", - "fee": 1500000000, - "senderId": "3855903394839129841" - } - }] -} - -``` - -#### 2.8.3 Unterschriebe eine Multi-Signatur-Transaktion (als nicht Initiator) -API Endpunkt: /api/multisignatures/sign -HTTP Verb: POST -Unterstützes Datenformat: JSON -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|secret |string |Ja|Password des Asch-Kontos| -|secondSecret|string|Nein|Zweites Passwort des Asch-Kontos. Minimale Länge: 1, Maximale Länge: 100| -|publicKey|string |Nein|Öffentlicher Schlüssel| -|transactionId|string|Ja|TransaktionsId| - - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert -|transactionId|string |Multi-Signatur-Transaktions-Id| - - -Beispiel: -```bash -curl -k -H "Content-Datentyp: application/json" -X POST -d '{"secret":"lemon carpet desk accuse clerk future oyster essay seminar force live dog","transactionId":"17620378998277022323"}' 'http://45.32.248.33:4096/api/multisignatures/sign' //dies wurde unterzeichnet von einem Benutzer dessen öffentlicher Schlüssel wie folgt ist: eb48b9ab7c9a34a9b7cdf860265d65b31af774355cabf1b3a387d14a1925dc97 -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "transactionId": "17620378998277022323" -} -// erhalte die ausstehende Transaktion -curl -k -X GET http://45.32.248.33:4096/api/multisignatures/pending?publicKey=2cef5711e61bb5361c544077aa08aebc4d962a1d656571901c48d716382ad4fd -{ - "success": true, - "transactions": [{ - "min": 2, - "lifetime": 1, - "signed": true, - "transaction": { - "type": 4, - "amount": 0, - "senderPublicKey": "2cef5711e61bb5361c544077aa08aebc4d962a1d656571901c48d716382ad4fd", - "requesterPublicKey": null, - "timestamp": 4879978, - "asset": { - "multisignature": { - "min": 2, - "keysgroup": ["+eb48b9ab7c9a34a9b7cdf860265d65b31af774355cabf1b3a387d14a1925dc97", - "+d5d7aa157f866c47a2a1e09e2746286ed089fd90976b54fbfa930e87d11609cb"], - "lifetime": 1 - } - }, - "recipientId": null, - "signature": "a42feaccd9f2a4940fc0be1a1580e786b360f189db3154328f307988e75484293eae391f2f9eee489913cc6d15984eb1f5f5a0aa1bf78ea745d5c725f161af08", - "id": "17620378998277022323", - "fee": 1500000000, - "senderId": "3855903394839129841", - "signatures": ["b38a161264db2a23e353d3fbc4983562f6343d5ee693144543ca54e2bc67c0f73d1c761b7bfa38b2bb101ac2ab0797b674b1a9964ccd400aaa310746c3494d03"] //die neue Multi-Signatur - } - }] -} - -// Der öffentlichen Schlüssel eines Benutzers ist "d5d7aa157f866c47a2a1e09e2746286ed089fd90976b54fbfa930e87d11609cb". Unterzeichne folgenden Registrierungs-Vertrag -curl -k -H "Content-Datentyp: application/json" -X POST -d '{"secret":"chalk among elbow piece badge try van round quality position simple teach","transactionId":"17620378998277022323"}' 'http://45.32.248.33:4096/api/multisignatures/sign' -{"success":true,"transactionId":"17620378998277022323"} -// Versuch ausstehende Transaktionen herunterzuladen. Diesmal gibt es keine. -curl -k -X GET http://45.32.248.33:4096/api/multisignatures/pending?publicKey=2cef5711e61bb5361c544077aa08aebc4d962a1d656571901c48d716382ad4fd -{"success":true,"transactions":[]} -// Beachte die Details dieser Transaktion. Zu diesem Zeitpunkt wurde die Transaktion an das ganze Netzwerk gesendet und wird auf die Blockchain geschrieben. Dieses Konto wurde erfolgreich als ein Multi-Signatur Konto registriert. - -curl -k -X GET http://45.32.248.33:4096/api/transactions/get?id=17620378998277022323 -{ - "success": true, - "transaction": { - "id": "17620378998277022323", //the registering transaction ID - "height": "157013", - "blockId": "4680888982781013372", - "type": 4, - "timestamp": 4879978, - "senderPublicKey": "2cef5711e61bb5361c544077aa08aebc4d962a1d656571901c48d716382ad4fd", - "senderId": "3855903394839129841", - "recipientId": "", - "amount": 0, - "fee": 1500000000, - "signature": "a42feaccd9f2a4940fc0be1a1580e786b360f189db3154328f307988e75484293eae391f2f9eee489913cc6d15984eb1f5f5a0aa1bf78ea745d5c725f161af08", - "signSignature": "", - "signatures": null, - "confirmations": "26", - "asset": { - - } - } -} - -``` - -#### 2.8.4 Zeige Details zu einem Multi-Signatur Konto -API Endpunkt: /api/multisignatures/accounts -HTTP Verb: GET -Unterstütztes Format: urlencoded -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|publicKey |string |Ja|Der öffentliche Schlüssel eines der Teilnehmer| - - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |Die Daten wurden erfolgreich retouniert| -|accounts|Array |Die Details des Multi-Signatur Kontos| - - -Beispiel: -```bash -curl -k -X GET http://45.32.248.33:4096/api/multisignatures/accounts?publicKey=eb48b9ab7c9a34a9b7cdf860265d65b31af774355cabf1b3a387d14a1925dc97 -``` - -Mögliche JSON Antwort: -```js -{ - "success": true, - "accounts": [{ - "address": "3855903394839129841", //die Adresse dieses Multi-Signatur-Kontos - "balance": 18500000000, //das Saldo des Multi-Signatur Kontos - "multisignatures": ["eb48b9ab7c9a34a9b7cdf860265d65b31af774355cabf1b3a387d14a1925dc97", - "d5d7aa157f866c47a2a1e09e2746286ed089fd90976b54fbfa930e87d11609cb"], //der öffentliche Schlüssel des Multi-Signatur Kontos - "multimin": 2, //Minimum an obligatorischen Signaturen - "multilifetime": 1, - "multisigaccounts": [{ //Die Kontodetails des Unterzeichners - "address": "13542769708474548631", - "publicKey": "eb48b9ab7c9a34a9b7cdf860265d65b31af774355cabf1b3a387d14a1925dc97", - "balance": 0 - }, - { - "address": "4100816257782486230", - "publicKey": "d5d7aa157f866c47a2a1e09e2746286ed089fd90976b54fbfa930e87d11609cb", - "balance": 0 - }] - }] -} -``` - -### 2.9 Peer2Peer Transport[sichere API] -#### 2.9.1 Übersicht -Um Informationen zu einer Knoten-API abzufragen müssen folgender Header gesetzt werden: - - - key=magic, and value=594fe0f3 - - key=version, and value='' - -#### 2.9.2 Transaktion -Alle Schreiboperationen im Asch-System werden mit dem Erstellen einer Transaktion beendet. Die Daten für die Transaktion werden mit Hilfe des Moduls "asch-js" erstellt und dann mit einem HTTP POST an den Server geschickt. Der API-Endpunkt sieht folgendermaßen aus: - -Nutzlast: Transaktionsinformationen erstellt durch asch-js -API Endpunkt: /peer/transactions -HTTP Verb: POST -Unterstützes Datenformat: JSON - -##### 2.9.2.1 Setze ein zweites Bezahl-Passwort -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|transaction|JSON|Ja|Transaktionsdaten erstellt mittels [asch-js.signature.createSignature]| - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |ob die Stimmabgabe erfolgreich war | - - -Beispiel: -```js -var asch = require('asch-js'); -var transaction = asch.signature.createSignature('measure bottom stock hospital calm hurdle come banner high edge foster cram','erjimimashezhi001') -console.log(json.stringify(transaction)) -{"type":1,"amount":0,"fee":500000000,"recipientId":null,"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","timestamp":5328943,"asset":{"signature":{"publicKey":"27116db89cb5a8c02fb559712e0eabdc298480d3c79a089b803e35bc5ef7bb7b"}},"signature":"71ef98b1600f22f3b18cfcf17599db3c40727c230db817f610e86454b62df4fb830211737ff0c03c6a61ecfd4a9fcb68a30b2874060bb33b87766acf800e820a","id":"15605591820551652547"} - -// schicke die oben erstellten Daten mittels HTTP POST an den Asch-Server um ein zweites Passwort zu hinterlegen -curl -H "Content-Datentyp: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":1,"amount":0,"fee":500000000,"recipientId":null,"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","timestamp":5328943,"asset":{"signature":{"publicKey":"27116db89cb5a8c02fb559712e0eabdc298480d3c79a089b803e35bc5ef7bb7b"}},"signature":"71ef98b1600f22f3b18cfcf17599db3c40727c230db817f610e86454b62df4fb830211737ff0c03c6a61ecfd4a9fcb68a30b2874060bb33b87766acf800e820a","id":"15605591820551652547"}}' http://45.32.248.33:4096/peer/transactions -``` - -Mögliche JSON Antwort: -```js -{ - "success":true //Aktion war erfolgreich -} -``` - -##### 2.9.2.2 Geld überweisen -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|transaction|JSON|Ja|Transaktionsdaten erstellt mittels [asch-js.transaction.createTransaction]| - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |ob die Stimmabgabe erfolgreich war | - - -Beispiel: -```js -var asch = require('asch-js'); -var targetAddress = "16358246403719868041"; -var amount = 100*100000000; //100 XAS -var password = 'measure bottom stock hospital calm hurdle come banner high edge foster cram'; -var secondPassword = 'erjimimashezhi001'; - -// Hier ist die Eingabe eines Passworts zu sehen. In diesem Beispiel muss das zweite Passwort auch eingegeben werden. -// Ob ein zweites Passwort notwendig ist hängt davon ab, ob der Benutzer ein zweites Passwort festgelegt hat. Über die Funktion "user.secondPublicKey" kann verifiziert werden ob ein Benutzer ein zweites Passwort hinterlegt hat. - -var transaction = asch.transaction.createTransaction(targetAddress, amount, password, secondPassword || undefined); -json.stringify(transaction) -'{"type":0,"amount":10000000000,"fee":10000000,"recipientId":"16358246403719868041","timestamp":5333378,"asset":{},"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","signature":"2d47810b7d9964c5c4d330a53d1382769e5092b3a53639853f702cf4a382aafcff8ef8663c0f6856a23f41c249944f0c3cfac0744847268853a62af5dd8fc90a","signSignature":"dfa9b807fff362d581170b41c56a2b8bd723c48d1f100f2856d794408723e8973016d75aeff4705e6837dcdb745aafb41aa10a9f1ff8a77d128ba3d712e90907","id":"16348623380114619131"}' - -// schicke diese Daten mittels HTTP POST an den Asch-Server -curl -H "Content-Datentyp: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":0,"amount":10000000000,"fee":10000000,"recipientId":"16358246403719868041","timestamp":5333378,"asset":{},"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","signature":"2d47810b7d9964c5c4d330a53d1382769e5092b3a53639853f702cf4a382aafcff8ef8663c0f6856a23f41c249944f0c3cfac0744847268853a62af5dd8fc90a","signSignature":"dfa9b807fff362d581170b41c56a2b8bd723c48d1f100f2856d794408723e8973016d75aeff4705e6837dcdb745aafb41aa10a9f1ff8a77d128ba3d712e90907","id":"16348623380114619131"}}' http://45.32.248.33:4096/peer/transactions -``` - -Mögliche JSON Antwort: -```js -{ - "success":true //Erfolgte Überweisung -} -``` - -##### 2.9.2.3 Ein Delegat registrieren -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|transaction|JSON|Ja|Transaktionsdaten erstellt mittels [asch-js.delegate.createDelegate]| - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |ob die Transaktion erfolgreich war oder nicht | - - -Beispiel: -```js -var asch = require('asch-js'); -var password = 'measure bottom stock hospital calm hurdle come banner high edge foster cram'; -var secondPassword = 'erjimimashezhi001'; -var userName = 'zhenxi_test'; - -var transaction = asch.delegate.createDelegate(password, userName, secondPassword || undefined); -json.stringify(transaction) -'{"type":2,"amount":0,"fee":10000000000,"recipientId":null,"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","timestamp":5334485,"asset":{"delegate":{"username":"zhenxi_test","publicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f"}},"signature":"a12ce415d2d21ab46e4c1b918b8717b1d351dd99abd6f2f94d9a1a7e1f32b697f843a05b1851cb857ea45a2476dce592f5ddd612c00cd44488b8b610c57d7f0a","signSignature":"35adc9f1f37d14458e8588f9b4332eedf1151c02480159f64a287a4b0cbb59bfe82040dfec96a4d9560bae99b8eaa1799a7023395db5ddc640d95447992d6e00","id":"12310465407307249905"}' - -// schicke oben erstellte Daten an den Asch Server mittels HTTP Post um ein Delegat zu registrieren -curl -H "Content-Datentyp: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":2,"amount":0,"fee":10000000000,"recipientId":null,"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","timestamp":5334485,"asset":{"delegate":{"username":"zhenxi_test","publicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f"}},"signature":"a12ce415d2d21ab46e4c1b918b8717b1d351dd99abd6f2f94d9a1a7e1f32b697f843a05b1851cb857ea45a2476dce592f5ddd612c00cd44488b8b610c57d7f0a","signSignature":"35adc9f1f37d14458e8588f9b4332eedf1151c02480159f64a287a4b0cbb59bfe82040dfec96a4d9560bae99b8eaa1799a7023395db5ddc640d95447992d6e00","id":"12310465407307249905"}}' http://45.32.248.33:4096/peer/transactions -``` - -Mögliche JSON Antwort: -```js -{ - "success":true //Registration war erfolgreich -} -``` - -##### 2.9.2.4 Wahl abgeben und Stimmabgabe zurückziehen - -Beschreibung der Parameter: - -|Name |Datentyp |Obligatorisch |Beschreibung | -|------ |----- |--- |---- | -|transaction|JSON|Ja|Transaktionsdaten erstellt mittels [asch-js.vote.createVote]| - -Beschreibung der Antwort-Parameter: - -|Name |Datentyp |Beschreibung | -|------ |----- |---- | -|success|bool |ob die Stimmabgabe erfolgreich war | - - -Beispiel: -```js -var asch = require('asch-js'); -var password = 'measure bottom stock hospital calm hurdle come banner high edge foster cram'; -var secondPassword = 'erjimimashezhi001'; -// Jedes Element der Liste zur Stimmabgabe setzt sich aus einem Symbol (+ oder -) und des öffentlichen Schlüssels des Delegats. Plus (+) bedeutet eine Stimmabgabe, ein Minus (-) steht für eine Annullierung der Stimme. -var voteContent = [ - '-ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7', - '+c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2' -]; - -var transaction = asch.vote.createVote(password, voteContent, secondPassword || undefined); -json.stringify(transaction) -{"type":3,"amount":0,"fee":10000000,"recipientId":null,"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","timestamp":5334923,"asset":{"vote":{"votes":["-ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7","+c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2"]}},"signature":"6036c2066a231c452a1c83aafd3bb9db3842ee05d5f17813f8264a4294cdec761faa89edf4a95f9b2e2451285807ab18aa9f989ad9a3165b95643179b8e4580f","signSignature":"a216ca739112e6f65986604b9467ccc8058138a7077faf134d6c4d673306cd1c514cc95bd54a036f7c602a56c4b4f2e4e59f6aa7c376cb1429e89054042e050b","id":"17558357483072606427"} - -// sende die oben bekommenen Daten den Asch-Server mittels HTTP POST -curl -H "Content-Datentyp: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":3,"amount":0,"fee":10000000,"recipientId":null,"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","timestamp":5334923,"asset":{"vote":{"votes":["-ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7","+c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2"]}},"signature":"6036c2066a231c452a1c83aafd3bb9db3842ee05d5f17813f8264a4294cdec761faa89edf4a95f9b2e2451285807ab18aa9f989ad9a3165b95643179b8e4580f","signSignature":"a216ca739112e6f65986604b9467ccc8058138a7077faf134d6c4d673306cd1c514cc95bd54a036f7c602a56c4b4f2e4e59f6aa7c376cb1429e89054042e050b","id":"17558357483072606427"}}' http://45.32.248.33:4096/peer/transactions -``` - -Mögliche JSON Antwort: -```js -{ - "success":true //war Stimmabgabe oder Rückziehung erfolgreich -} -``` - - -## Appendix 1:Installiere das 'asch-js' Modul -Alle Operationen in Asch werden mit einer Transaktion beendet. Die Transaktionsdaten werden mittels des Moduls "asch-js" erstellt und dann mittels HTTP POST an den API Endpunkt geschickt. - -**Installiere das Modul** -`npm install asch-js` diff --git a/docs/asch_http_interface_en.md b/docs/asch_http_interface_en.md deleted file mode 100644 index 683d16c..0000000 --- a/docs/asch_http_interface_en.md +++ /dev/null @@ -1,1979 +0,0 @@ -Table of Contents -================= - - * [Asch-HTTP Interface Specification](#asch-http-interface-specification) - * [1 API Usage Guide](#1-api-usage-guide) - * [1.1 Request Process Overview](#11-request-process-overview) - * [2 Interface](#2-interface) - * [2.1 Accounts](#21-accounts) - * [2.1.1 Login](#211-login) - * [2.1.1.1 Login after locally encrypt (recommended)](#2111-login-after-locally-encrypt-recommended) - * [2.1.1.2 Login without locally encrypt (not recommend)](#2112-login-without-locally-encrypt-not-recommend) - * [2.1.2 Get Account Information](#212-get-account-information) - * [2.1.3 Get Balance of Account](#213-get-balance-of-account) - * [2.1.4 Get Account's Public Key](#214-get-accounts-public-key) - * [2.1.5 Generate Public Key](#215-generate-public-key) - * [2.1.6 Get Voting List by Address](#216-get-voting-list-by-address) - * [2.1.7 Get the Fee of Given Delegate](#217-get-the-fee-of-given-delegate) - * [2.1.8 Voting](#218-voting) - * [2.2 Transactions](#22-transactions) - * [2.2.1 Get the Transaction Detail Information](#221-get-the-transaction-detail-information) - * [2.2.2 Get the Transaction Detail Information by Transaction ID](#222-get-the-transaction-detail-information-by-transaction-id) - * [2.2.3 Get Transaction Detail by Unconfirmed Transaction ID](#223-get-transaction-detail-by-unconfirmed-transaction-id) - * [**2.2.4 Get Unconfirmed Transaction Detail Inforamtion [within all network]](#224-get-unconfirmed-transaction-detail-inforamtion-within-all-network) - * [2.2.5 Create Transaction](#225-create-transaction) - * [2.3 Blocks](#23-blocks) - * [2.3.1 Get the Block Detail Information of the Given ID](#231-get-the-block-detail-information-of-the-given-id) - * [2.3.2 Get the Latest Block](#232-get-the-latest-block) - * [2.3.3 Get the Block Height](#233-get-the-block-height) - * [2.3.4 Get the Transaction Fee](#234-get-the-transaction-fee) - * [2.3.5 Get the Milestone](#235-get-the-milestone) - * [2.3.6 Get the Reward Information of a Block](#236-get-the-reward-information-of-a-block) - * [2.3.7 Get the Current Maximum Supply of the Blockchain](#237-get-the-current-maximum-supply-of-the-blockchain) - * [2.3.8 Get Current Status of Blockchain](#238-get-current-status-of-blockchain) - * [2.4 Delegates](#24-delegates) - * [2.4.1 Get the Total Number of Delegates](#241-get-the-total-number-of-delegates) - * [2.4.2 Check the Voters of Delegates by Public Key](#242-check-the-voters-of-delegates-by-public-key) - * [2.4.3 Get the Delegate's Detail by Public Key or Name](#243-get-the-delegates-detail-by-public-key-or-name) - * [2.4.4 Get the List of Delegates](#244-get-the-list-of-delegates) - * [2.4.5 Get the Transaction Fee Set by Delegate](#245-get-the-transaction-fee-set-by-delegate) - * [2.4.6 Get Forge Information by Public Key](#246-get-forge-information-by-public-key) - * [2.4.7 Register Delegate](#247-register-delegate) - * [2.5 Peers](#25-peers) - * [2.5.1 Get all Peers' Information in the Whole Network](#251-get-all-peers-information-in-the-whole-network) - * [2.5.2 Get the Version of Peer](#252-get-the-version-of-peer) - * [2.5.3 Get the Peer Information of a Given IP Address](#253-get-the-peer-information-of-a-given-ip-address) - * [2.6 Sync and Loader](#26-sync-and-loader) - * [2.6.1 Get the local blockchain loadig status](#261-get-the-local-blockchain-loadig-status) - * [2.6.2 Get the block syncing status](#262-get-the-block-syncing-status) - * [2.7 Second Password](#27-second-password) - * [2.7.1 Set the Second Password](#271-set-the-second-password) - * [2.7.2 Get the Transaction Fee of Setting Second Password](#272-get-the-transaction-fee-of-setting-second-password) - * [2.8 Multiple Signatures](#28-multiple-signatures) - * [2.8.1 Set Normal Account to Multi-signatures Account](#281-set-normal-account-to-multi-signatures-account) - * [2.8.2 Get the Detail Information of Pending Multi-signature Transaction](#282-get-the-detail-information-of-pending-multi-signature-transaction) - * [2.8.3 Sign the Multi-signature Transaction (by non-initiator)](#283-sign-the-multi-signature-transaction-by-non-initiator) - * [2.8.4 Get Detail Information of the Multi-signature Account](#284-get-detail-information-of-the-multi-signature-account) - * [2.9 Peer to Peer Transportation[secure API]](#29-peer-to-peer-transportationsecure-api) - * [2.9.1 Overview](#291-overview) - * [2.9.2 Transaction](#292-transaction) - * [2.9.2.1 Set the Second Payment Password](#2921-set-the-second-payment-password) - * [2.9.2.2 Transfer Money](#2922-transfer-money) - * [2.9.2.3 Register Delegates](#2923-register-delegates) - * [2.9.2.4 Vote and Cancel the vote](#2924-vote-and-cancel-the-vote) - * [Appendix 1: Install 'asch-js' library](#appendix-1-install-asch-js-library) - -Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc) - -# Asch-HTTP Interface Specification - ---- -## 1 API Usage Guide -### 1.1 Request Process Overview -- **Generate request data:** according the interface specification provided by Asch system, generate the request data as a JSON object. (In one case, if you write about secure peer to peer transportation, you may need a JS library called asch-js to create signature. see [2.9 Peer to Peer transportation](# 29-peer-to-peer-transportation) for detail). -- **Send request data:** transfer the generated data object to Asch platform through POST/GET method upon HTTP -- **Asch system handles the data object:** after receiving the data object, Asch server will validate the data firstly, then deal with it. -- **Return the response data:** Asch system send the response data to client as a JSON object. See interface part for detail, like response data format and error code. -- **Client handles the response data** - -## 2 Interface -### 2.1 Accounts - -#### 2.1.1 Login -##### 2.1.1.1 Login after locally encrypt (recommended) -Interface Address: /api/accounts/open2/ -Request Type: post -Supported Format: json -Comment: Public key needs to be generated locally according to user's password (see Request Example) - -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|publicKey |string |Y |Asch account public key | - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |Whether login is successful | -|account|json |Account Information | -Request Example: - -```js -var AschJS = require('asch-js'); //For further information about asch-js, please see Appendix -var publicKey = AschJS.crypto.getKeys(secret).publicKey; //Generate public key according to password -// var address = AschJS.crypto.getAddress(publicKey); //Generate address according to public key - -// Submit the above data to Asch server through post method -curl -X POST -H "Content-Type: application/json" -k -d '{"publicKey":"bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9"}' http://45.32.248.33:4096/api/accounts/open2/ -``` - -JSON Response Example: -```js -{ - "success": true, - "account": { - "address": "16723473400748954103", - "unconfirmedBalance": 19480000000, - "balance": 19480000000, - "unconfirmedSignature": false, - "secondSignature": true, - "secondPublicKey": "edf30942beb74de5ed6368c792af8665e9636f32a5f1c9377bcdc3b252d3f277", - "multisignatures": [], - "u_multisignatures": [] - }, - "latestBlock": { - "height": 111923, - "timestamp": 4446270 - }, - "version": { - "version": "1.0.0", - "build": "12:11:11 16/08/2016", - "net": "testnet" - } -``` - -##### 2.1.1.2 Login without locally encrypt (not recommend) -Interface Address: /api/accounts/open/ -Request Method:post -Supported Format: json -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|secret |string |Y |asch account password | - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |Whether login is successful | -|account|json |Account information | - -Request Example: -```bash -curl -X POST -H "Content-Type: application/json" -k -d '{"secret":"fault still attack alley expand music basket purse later educate follow ride"}' http://45.32.248.33:4096/api/accounts/open/ -``` - -JSON Response Example: -```js -{ - "success": true, - "account": { - "address": "16723473400748954103", - "unconfirmedBalance": 19480000000, - "balance": 19480000000, - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9", - "unconfirmedSignature": false, - "secondSignature": true, - "secondPublicKey": "edf30942beb74de5ed6368c792af8665e9636f32a5f1c9377bcdc3b252d3f277", - "multisignatures": [ ], - "u_multisignatures": [ ] - } -} -``` -#### 2.1.2 Get Account Information -Interface Address: /api/accounts -Request Method:get -Supported Format: urlencoded -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|address |string |Y |Client's address, minimum length:1 | - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |whether response data can be returned | -|account|json |account information | -|latestBlock|json |latest block information | -|version|json |version information | - -Request Example: -```bash -curl -k -X GET http://45.32.248.33:4096/api/accounts?address=16723473400748954103 -``` - -JSON Response Example: -```js -{ - "success": true, - "account": { - "address": "16723473400748954103", //Asch address - "unconfirmedBalance": 19480000000, //the sum of unconfirmed and confirmed balance, that should be larger than or equal to balance below. - "balance": 19480000000, //balance - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9", //Public key - "unconfirmedSignature": false, - "secondSignature": true, //second signature - "secondPublicKey": "edf30942beb74de5ed6368c792af8665e9636f32a5f1c9377bcdc3b252d3f277", //second public key - "multisignatures": [], - "u_multisignatures": [] - }, - "latestBlock": { - "height": 114480, //block height - "timestamp": 4471890 - }, - "version": { - "version": "1.0.0", - "build": "12:11:11 16/08/2016", //build date - "net": "testnet" //blockchain type: main chain or test one - } -} -``` -#### 2.1.3 Get Balance of Account -Interface Address: /api/accounts/getBalance -Request Method: get -Supported Format: urlencoded -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|address |string |Y |Client's address, minimum length:1 | - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|balance|integer |balance | -|unconfirmedBalance|integer|the sum of unconfirmed and confirmed balance, that should be larger than or equal to balance| - - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/accounts/getBalance?address=14636456069025293113' -``` - -JSON Response Example: -```js -{ - "success": true, - "balance": 5281328514990, - "unconfirmedBalance": 5281328514990 -} -``` - -#### 2.1.4 Get Account's Public Key -Interface Address: /api/accounts/getPublickey -Request Method:get -Supported Format: urlencoded -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|address |string |Y |Client's address, minimum length:1 | - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|publicKey|string |public key | - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/accounts/getPublickey?address=14636456069025293113' -``` - -JSON Response Example: -```js -{ - "success": true, - "publicKey": "ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7" -} -``` - -#### 2.1.5 Generate Public Key -Interface Address: /api/accounts/generatePublickey -Request Method: post -Supported Format: json -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|secret |string |Y |Asch account password | - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|publicKey|string |public key | - -Request Example: -```bash -curl -k -H "Content-Type: application/json" -X POST -d '{"secret":"fault still attack alley expand music basket purse later educate follow ride"}' 'http://45.32.248.33:4096/api/accounts/generatePublickey' -``` - -JSON Response Example: -```js -{ - "success": true, - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9" -} -``` - -#### 2.1.6 Get Voting List by Address -Interface Address: /api/accounts/delegates -Request Method: get -Supported Format: urlencoded -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|address |string |Y |Voter's address | - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|delegates|Array |A list that contains detail information of those delegates who have already voted | - - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/accounts/delegates?address=14636456069025293113' -``` - -JSON Response Example: -```js -{ - "success": true, - "delegates": [{ - "username": "wgl_002", - "address": "14636456069025293113", - "publicKey": "ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7", - "vote": 9901985415600500, - "producedblocks": 1373, - "missedblocks": 6, - "rate": 1, - "approval": "98.54", - "productivity": "99.56" - }, - { - "username": "wgl_003", - "address": "9961157415582672274", - "publicKey": "c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2", - "vote": 9891995435600500, - "producedblocks": 1371, - "missedblocks": 8, - "rate": 2, - "approval": "98.44", - "productivity": "99.41" - }, - { - "username": "wgl_001", - "address": "1869971419039689816", - "publicKey": "c547df2dde6cbb4508aabcb5970d8f9132e5a1d1c422632da6bc20bf1df165b8", - "vote": 32401577128413, - "producedblocks": 969, - "missedblocks": 8, - "rate": 102, - "approval": "0.32", - "productivity": 0 - }] -} -``` - -#### 2.1.7 Get the Fee of Given Delegate -Interface Address: /api/accounts/delegates/fee -Request Method:get -Supported Format: none -Request Parameter Description: none - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|fee|integer |fee setting | - - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/accounts/delegates/fee -``` - -JSON Response Example: -```js -{ - "success": true, - "fee": 100000000 -} -``` - - -#### 2.1.8 Voting -Interface Address: /api/accounts/delegates -Request Method:put -Supported Format: json -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|secret |string |Y |Asch account password | -|publicKey|string |N|public key | -|secondSecret|string|N|Asch account's second password,minimum length:1,maximum length:100| -|delegates|Array|a list that contains delegates' public key. put +/- in front of each public key, which means vote/abolish this delegate. | - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|transaction|json |voting detail inforamtion | - - -Request Example: -```bash -curl -k -H "Content-Type: application/json" -X PUT -d '{"secret":"call scissors pupil water friend timber spend brand vote obey corn size","publicKey":"3ec1c9ec08c0512641deba37c0e95a0fe5fc3bdf58424009f594d7d6a4e28a2a","delegates":["+fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575"]}' 'http://45.32.248.33:4096/api/accounts/delegates' -``` - -JSON Response Example: -```js - { - "success": true, - "transaction": { - "type": 3, //the type of vote is '3' - "amount": 0, - "senderPublicKey": "3ec1c9ec08c0512641deba37c0e95a0fe5fc3bdf58424009f594d7d6a4e28a2a", - "requesterPublicKey": null, - "timestamp": 5056064, - "asset": { - "vote": { - "votes": ["+fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575"] - } - }, - "recipientId": null, - "signature": "0bff58c7311fc59b3c8b3ffc236bbfece9850c334fb0c292ab087f78cf9a6c0f4d3e541c501887a2c2ec46294c777e8f7bf7dea9cb7c9a175fdec641bb684f08", - "id": "5630629337798595849", - "fee": 10000000, - "senderId": "15238461869262180695" - } -} -``` - -### 2.2 Transactions -#### 2.2.1 Get the Transaction Detail Information -Interface Address: /api/transactions -Request Method: get -Supported Format: urlencoded -Comment: if there is no parameter in request data, all network transactions will be returned. -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|blockId |string |N |block id | -|limit |integer |N |the limitation of returned records,minimum:0,maximum:100 | -|type|integer |N |The transaction type,0:normal transfer,1:setting second password,2:registering delegate,3:voting,4:multiple signature,5:DAPP,6:IN_TRANSFER,7:OUT_TRANSFER | -|orderBy|string |N |sort with a field in the table,senderPublicKey:desc | -|offset|integer |N |offset, minimum 0 | -|senderPublicKey|string|N|sender's public key| -|ownerPublicKey|string|N|| -|ownerAddress|string|N|| -|senderId|string|N|sender's address| -|recipientId|string|N|recipient's address, minimum:1| -|amount|integer|N|amount| -|fee|integer|N|charge fee| - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|transactions|Array |A JSON object list containing multiple transactions' detail | -|count|int|the total number of retrieved transactions| - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/transactions?recipientId=16723473400748954103&orderBy=t_timestamp:desc&limit=3' -``` - -JSON Response Example: -```js -{ - "success": true, - "transactions": [{ - "id": "17192581936339156329", - "height": "105951", - "blockId": "15051364118100195665", - "type": 0, - "timestamp": 4385190, - "senderPublicKey": "d39d6f26869067473d685da742339d1a9117257fe14b3cc7261e3f2ed5a339e3", - "senderId": "15745540293890213312", - "recipientId": "16723473400748954103", - "amount": 10000000000, - "fee": 10000000, - "signature": "98d65df3109802c707eeed706e90a907f337bddab58cb4c1fbe6ec2179aa1c85ec2903cc0cf44bf0092926829aa5a0a6ec99458f65b6ebd11f0988772e58740e", - "signSignature": "", - "signatures": null, - "confirmations": "31802", - "asset": { - - } - }, - { - "id": "7000452951235123088", - "height": "105473", - "blockId": "11877628176330539727", - "type": 0, - "timestamp": 4380147, - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "senderId": "16358246403719868041", - "recipientId": "16723473400748954103", - "amount": 10000000000, - "fee": 10000000, - "signature": "dc84044d4f6b4779eecc3a986b6507e458cc5964f601ebeb4d3b68a96129813f4940e14de950526dd685ca1328b6e477e6c57e95aeac45859a2ea62a587d0204", - "signSignature": "", - "signatures": null, - "confirmations": "32280", - "asset": { - - } - }, - { - "id": "14093929199102906687", - "height": "105460", - "blockId": "2237504897174225512", - "type": 0, - "timestamp": 4380024, - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "senderId": "16358246403719868041", - "recipientId": "16723473400748954103", - "amount": 10000000000, - "fee": 10000000, - "signature": "73ceddc3cbe5103fbdd9eee12f7e4d9a125a3bcf2e7cd04282b7329719735aeb36936762f17d842fb14813fa8f857b8144040e5117dffcfc7e2ae88e36440a0f", - "signSignature": "", - "signatures": null, - "confirmations": "32293", - "asset": { - - } - }], - "count": 3 -} -``` -#### 2.2.2 Get the Transaction Detail Information by Transaction ID -Interface Address: /api/transactions/get -Request Method:get -Supported Format: urlencoded -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|Id |string |Y |transaction id | - - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|transactions|json |transaction detail information | - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/transactions/get?id=14093929199102906687' -``` - -JSON Response Example: -```js -{ - "success": true, - "transaction": { - "id": "14093929199102906687", - "height": "105460", - "blockId": "2237504897174225512", - "type": 0, - "timestamp": 4380024, - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "senderId": "16358246403719868041", - "recipientId": "16723473400748954103", - "amount": 10000000000, - "fee": 10000000, - "signature": "73ceddc3cbe5103fbdd9eee12f7e4d9a125a3bcf2e7cd04282b7329719735aeb36936762f17d842fb14813fa8f857b8144040e5117dffcfc7e2ae88e36440a0f", - "signSignature": "", - "signatures": null, - "confirmations": "34268", - "asset": { - } - } -} -``` - -#### 2.2.3 Get Transaction Detail by Unconfirmed Transaction ID -Interface Address: /api/transactions/unconfirmed/get -Request Method:get -Supported Format: urlencoded -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|id|string |Y |unconfirmed transaction id | - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|transaction|json |unconfirmed transaction detail inforamtion | - - -Request Example: -```bash -curl -k -X GET http://45.32.248.33:4096/api/transactions/unconfirmed/get?id=7557072430673853692 //Regularly, this unconfirmed transaction exist during an extremely short time, almost 0~10 second. -``` - -JSON Response Example: -```js -{ - "success": true, - "transaction": { - "type": 0, - "amount": 10000, - "senderPublicKey": "3ec1c9ec08c0512641deba37c0e95a0fe5fc3bdf58424009f594d7d6a4e28a2a", - "requesterPublicKey": null, - "timestamp": 5082322, - "asset": { - - }, - "recipientId": "16723473400748954103", - "signature": "3a97f8d63509ef964bda3d816366b8e9e2d9b5d4604a660e7cbeefe210cb910f5de9a51bece06c32d010f55502c62f0f59b8224e1c141731ddfee27206a88d02", - "id": "7557072430673853692", - "fee": 10000000, - "senderId": "15238461869262180695" - } -} -``` - - -#### **2.2.4 Get Unconfirmed Transaction Detail Inforamtion [within all network] -Interface Address: /api/transactions/unconfirmed -Request Method:get -Supported Format: urlencoded -Comment: If there is no parameter, all unconfirmed transactions in the whole network will be returned. -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|senderPublicKey |string |N |sender's public key | -|address |string |N |address | - - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|transactions|Array |a list containing all unconfirmed transactions | - - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/transactions/unconfirmed' -``` - -JSON Response Example: -```js -{ - "success": true, - "transactions": [] //Currently there is no unconfirmed transaction in the whole network -} -``` - -#### 2.2.5 Create Transaction -Interface Address: /api/transactions -Request Method:PUT -Supported Format: json -Comment: Recipiant acount must have already login in wallet on the web. -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|secret |string |Y |Asch account password | -|amount|integer|Y|amount,between 1 and 10000000000000000| -|recipientId|string|Y|recipient's address, minimum:1| -|publicKey|string|N|sender's public key| -|secondSecret|string|N|sender's second password (must fit the BIP39 standard), the length should be between 1 and 100| -|multisigAccountPublicKey|string|N|the public key of multiple signature account| - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|transactionId|string |transaction id | - - -Request Example: -```bash -curl -k -H "Content-Type: application/json" -X PUT -d '{"secret":"unaware label emerge fancy concert long fiction report affair appear decide twenty","amount":1000000,"recipientId":"16723473400748954103"}' 'http://45.32.248.33:4096/api/transactions' -``` - -JSON Response Example: -```js -{ - "success": true, - "transactionId": "16670272591943275531" -} -``` - -### 2.3 Blocks -#### 2.3.1 Get the Block Detail Information of the Given ID -Interface Address: /api/blocks/ -Request Method:get -Supported Format: urlencoded -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|id |string |only choose one of these three parameters |block ID | -|height|string|ditto|block height| -|hash|string|ditto|block hash value| - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|block|json |the block detail information | - - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/get?id=6076474715648888747' -``` - -JSON Response Example: -```js -{ - "success": true, - "block": { - "id": "6076474715648888747", - "version": 0, - "timestamp": 4734070, - "height": 140538, - "previousBlock": "16033230167082515105", //previous block ID - "numberOfTransactions": 0, //The number of transactions - "totalAmount": 0, //the total transactions' amount - "totalFee": 0, - "reward": 350000000, //reward - "payloadLength": 0, - "payloadHash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "generatorPublicKey": "1d352950c8141e1b35daba4a974a604519d7a2ef3a1ec0a503ce2653646aa052", - "generatorId": "6656029629904254066", - "blockSignature": "a53de66922cdc2f431acd0a474beec7cf7c420a8460b7b7caf84999be7caebb59fb7fbb7166c2c7013dbb431585ea7294722166cb08bf9663abf50b6bd81cd05", - "confirmations": "2", - "totalForged": 350000000 - } -} -``` - -#### 2.3.2 Get the Latest Block -Interface Address: /api/blocks -Request Method: get -Supported Format: urlencoded -Comment: if there is no parameter, the detail of all the blocks in the whole network will be returned -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|limit |integer |N |maximum number of returned records, between 0 and 100 | -|orderBy|string |N |sort by a field in the table, for example, height:desc | -|offset|integer |N |offset, minimum 0 | -|generatorPublicKey|string |N |public key of the block generator | -|totalAmount|integer |N |total amount of transactions, from 0 to 10000000000000000 | -|totalFee|integer |N |total fee of transaction, from 0 to 10000000000000000 | -|reward|integer |N |the amount of reward, minimum: 0 | -|previousBlock|string |N |previous block | -|height|integer |N |block height | - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|blocks|Array |a list of JSON objects containing block detail| -|count|integer|block height| - - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks?limit=2&offset=0&orderBy=height:desc' -``` - -JSON Response Example: -```js -{ - "success": true, - "blocks": [{ - "id": "12634047624004615059", - "version": 0, - "timestamp": 4708080, - "height": 137986, - "previousBlock": "3498191422350401106", - "numberOfTransactions": 0, // the number of transactions - "totalAmount": 0, // total amount of transactions - "totalFee": 0, // transaction fee - "reward": 350000000, // reward - "payloadLength": 0, - "payloadHash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "generatorPublicKey": "44db7bec89ef289d0def257285675ca14f2a947dfd2b70e6b1cff4392ce42ada", - "generatorId": "4925169939071346193", - "blockSignature": "83a2124e3e8201c1a6099b2ac8ab1c117ad34867978add3a90d41a64df9d2ad8fabc9ec14d27a77cd34c08a6479ef684f247c11b1cbbcb0e9767dffc85838600", - "confirmations": "1", - "totalForged": 350000000 - }, - { - "id": "3498191422350401106", - "version": 0, - "timestamp": 4708070, - "height": 137985, - "previousBlock": "14078155423801039323", - "numberOfTransactions": 0, - "totalAmount": 0, - "totalFee": 0, - "reward": 350000000, - "payloadLength": 0, - "payloadHash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "generatorPublicKey": "500b1ec025cd64d36008341ed8d2508473ecf559be213ca5f9580620a21a592c", - "generatorId": "16006295608945777169", - "blockSignature": "a0b5ed6c94b1f33c4d0f017f21a08357061493392b19e34eeedf274b77c751e3f86c92443280de09ea1754d62fe7ef00e02acbdc3bc0c1063cef344bacaa4f07", - "confirmations": "2", - "totalForged": 350000000 - }], - "count": 137986 -} -``` - -#### 2.3.3 Get the Block Height -Interface Address: /api/blocks/getHeight -Request Method:get -Supported Format: none -Request Parameter Description: none - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|height|integer |block height | - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/getheight' -``` - -JSON Response Example: -```js -{"success":true,"height":140569} -``` - -#### 2.3.4 Get the Transaction Fee -Interface Address: /api/blocks/getFee -Request Method:get -Supported Format: none -Request Parameter Description: none - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|fee|integer |transaction fee | - - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/getfee' -``` - -JSON Response Example: -```js -{"success":true,"fee":10000000} //transaction fee is -0.1 XAS -``` - -#### 2.3.5 Get the Milestone -Interface Address: /api/blocks/getMilestone -Request Method: get -Supported Format: none -Request Parameter Description: none -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|milestone|integer | | - - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/getMilestone' -``` - -JSON Response Example: -```js -{"success":true,"milestone":0} -``` - -#### 2.3.6 Get the Reward Information of a Block -Interface Address: /api/blocks/getReward -Request Method:get -Supported Format: none -Request Parameter Description: none - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|reward|integer |the reward of the block | - - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/getReward' -``` - -JSON Response Example: -```js -{"success":true,"reward":350000000} //every single block you created will be rewarded by 3.5 XAS -``` - -#### 2.3.7 Get the Current Maximum Supply of the Blockchain -Interface Address: /api/blocks/getSupply -Request Method:get -Supported Format: none -Request Parameter Description: none - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|supply|integer |the total amount of XAS in the whole network | - - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/getSupply' -``` - -JSON Response Example: -```js -{"success":true,"supply":10049222600000000} //There are totally 100492226 XAS in current testnet -``` - -#### 2.3.8 Get Current Status of Blockchain -Interface Address: /api/blocks/getStatus -Request Method:get -Supported Format: none -Request Parameter Description: none - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|height|integer |blockchain height | -|fee|integer |transaction fee | -|milestone|integer | | -|reward|integer |block reward | -|supply|integer |total amount of XAS in the whole network | - - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/blocks/getStatus' -``` - -JSON Response Example: -```js -{ - "success": true, - "height": 140649, - "fee": 10000000, - "milestone": 0, - "reward": 350000000, - "supply": 10049227150000000 -} -``` - - - -### 2.4 Delegates - -#### 2.4.1 Get the Total Number of Delegates -Interface Address: /api/delegates/count -Request Method: get -Supported Format: none -Request Parameter Description: none - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|count|integer |total number of delegates | - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/delegates/count' -``` - -JSON Response Example: -```js -{"success":true,"count":234} -``` - -#### 2.4.2 Check the Voters of Delegates by Public Key -Interface Address: /api/delegates/voters -Request Method:get -Supported Format: urlencoded -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|publicKey |string |Y |public key of the delegate | - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|accounts|Array |a JSON object list of account | - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/delegates/voters?publicKey=ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7' -``` - -JSON Response Example: -```js -{ - "success": true, - "accounts": [{ - "address": "2918354313445278349", - "publicKey": "4fde4c49f1297d5d3a24b1494204543c4281aff17917ff7ff8ff32da3b4b222f", - "balance": 1338227722727, - "weight": 0.013316660647014596 - }, - { - "address": "1523444724068322527", - "publicKey": "8a6a61c28dc47541aadf1eecec2175c8f768f2331eea3472b1593bf1aa4e1fb4", - "balance": 2109297623765, - "weight": 0.020989552213127274 - }, - { - "address": "14483826354741911727", - "publicKey": "5dacb7983095466b9b037690150c3edec0f073815326e33a4744b6d1d50953e2", - "balance": 5135815841470, - "weight": 0.051106336795243436 - } - }] -} -``` - -#### 2.4.3 Get the Delegate's Detail by Public Key or Name -Interface Address: /api/delegates/get/ -Request Method:get -Supported Format: urlencoded -Comment:Get the delegate's detail by his/her public key or user name -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|publickey |string |choose only one parameter of these two |delegate's public key | -|username |string |ditto |delegate's user name | - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|delegate|json |the detail information of this delegate | - - -Request Example: -```bash -curl -k -X GET http://45.32.248.33:4096/api/delegates/get?publicKey=bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9 -curl -k -X GET http://45.32.248.33:4096/api/delegates/get?username=delegate_register -``` - -JSON Response Example: -```js -{ - "success": true, - "delegate": { - "username": "delegate_register", - "address": "16723473400748954103", - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9", - "vote": 0, - "producedblocks": 0, - "missedblocks": 0, - "fees": 0, - "rewards": 0, - "rate": 191, - "approval": 0, - "productivity": 0, - "forged": "0" - } -} -``` - -#### 2.4.4 Get the List of Delegates -Interface Address: /api/delegates -Request Method:get -Supported Format: urlencoded -Comment: if there is no parameter, all delegates in the whole network will be returned. -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|address |string |N |delegate's address | -|limit|int |N |maximum return records | -|offset|integer |N |offset, minimum: 0 | -|orderBy|string |N |[field used to sort]:[sort type] e.g., address:desc | - - - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|delegates|Array |a list containing delegates' detail information | - - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/delegates?orderby=approval:desc&limit=2' //the first two delegates order by approval vote, descendingly -``` - -JSON Response Example: -```js -{ - "success": true, - "delegates": [{ - "username": "wgl_002", //delegate's user name - "address": "14636456069025293113", //delegate's address - "publicKey": "ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7", //delegate's public key - "vote": 9901984015600500, //the number of vote - "producedblocks": 1371, //the number of generated blocks - "missedblocks": 6, //the number of missed blocks - "fees": 12588514990, - "rewards": 276850000000, //the gained reward - "rate": 1, - "approval": 98.54, //the rate of approval votes - "productivity": 99.56, //the productivity - "forged": "289438514990" //All reward from forge - }, - { - "username": "wgl_003", - "address": "9961157415582672274", - "publicKey": "c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2", - "vote": 9891994035600500, - "producedblocks": 1370, - "missedblocks": 8, - "fees": 12355148480, - "rewards": 275100000000, - "rate": 2, - "approval": 98.44, - "productivity": 99.42, - "forged": "287455148480" - }], - "totalCount": 233 -} -``` - - - - - - -#### 2.4.5 Get the Transaction Fee Set by Delegate -Interface Address: /api/delegates/fee -Request Method:get -Supported Format: urlencoded -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|publicKey |string |Y |delegate's public key | - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|fee|integer |transaction fee | - - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/delegates/fee?publicKey=ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7' -``` - -JSON Response Example: -```js -{"success":true,"fee":10000000000} //0.1 XAS -``` - -#### 2.4.6 Get Forge Information by Public Key -Interface Address: /api/delegates/forging/getForgedByAccount -Request Method:get -Supported Format: urlencoded -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|generatorPublicKey |string |Y |block generator's public key | - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|fees|integer |total amount of charged fee | -|rewards|integer|gained rewards| -|forged|integer|total rewards comming from forge| - - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/delegates/forging/getForgedByAccount?generatorPublicKey=ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7' -``` - -JSON Response Example: -```js -{ - "success": true, - "fees": 12589307065, - "rewards": 285600000000, - "forged": 298189307065 -} -``` - -#### 2.4.7 Register Delegate -Interface Address: /api/delegates -Request Method:put -Supported Format: urlencoded -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|secret |string |Y |Asch account password | -|publicKey|string |N |public key| -|secondSecret|string|N|Asch account's second password, minimum length:1 maximum length: 100 | -|username|string|N|the delegate's user name| - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|transaction|json |the detail of the registering process | - - -Request Example: -```bash -curl -k -H "Content-Type: application/json" -X PUT -d '{"secret":"unaware label emerge fancy concert long fiction report affair appear decide twenty","username":"delegate_0821"}' 'http://45.32.248.33:4096/api/delegates' -``` - -JSON Response Example: -```js -{ - "success": true, - "transaction": { - "type": 2, //the transaction type of registering delegate is 2 - "amount": 0, - "senderPublicKey": "3b64f1833e6328043e1f2fee31e638bdaa6dfff5c7eb9c8577a5cefcf11261f2", - "requesterPublicKey": null, - "timestamp": 4737615, - "asset": { - "delegate": { - "username": "delegate_0821", - "publicKey": "3b64f1833e6328043e1f2fee31e638bdaa6dfff5c7eb9c8577a5cefcf11261f2" - } - }, - "recipientId": null, - "signature": "7f8417e8db5f58ddff887c86c789c26b32fd3f01083ef1e3c8d4e18ed16622bf766492d78518c6c7a07aada1c98b1efc36d40c8e09394989dbde229d8e3f8103", - "id": "16351320834453011577", - "fee": 10000000000, - "senderId": "250438937633388106" - } -} -``` - -### 2.5 Peers - -#### 2.5.1 Get all Peers' Information in the Whole Network -Interface Address: /api/peers -Request Method:get -Supported Format: urlencoded -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|state |integer |N |peer's status: 0:,1:,2:,3: | -|os|string|N|Linux kernel version| -|version|string|N|Asch system version| -|limit |integer |N |maximum return records, minimum:0, maximum: 100| -|orderBy|string|N|| -|offset|integer |N |offset, minimum 0 | -|port|integer|N|port number,1~65535| - - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|peers|Array |a JSON array of peers' information | -|totalCount|integer|the number of currently running peers| - - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/peers?limit=1' -``` - -JSON Response Example: -```js -{ - "success": true, - "peers": [{ - "ip": "45.32.19.241", - "port": 4096, - "state": 2, - "os": "linux3.13.0-87-generic", - "version": "1.0.0" - }], - "totalCount": ["54"] -} -``` - -#### 2.5.2 Get the Version of Peer -Interface Address: /api/peers/version -Request Method:get -Supported Format: none -Request Parameter Description: none - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|version|string |version number | -|build |timestamp |built time | -|net |string |if the peer is mainnet or testnet | - - -Request Example: -```bash -curl -k -X GET http://45.32.248.33:4096/api/peers/version -``` - -JSON Response Example: -```js -{ - "success": true, - "version": "1.0.0", - "build": "12:11:11 16/08/2016", - "net": "testnet" -} -``` - -#### 2.5.3 Get the Peer Information of a Given IP Address -Interface Address: /api/peers/get -Request Method:get -Supported Format: urlencoded -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|ip |string |Y |peer's IP | -|port|integer|Y|peer's port,1~65535| - - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|peer|json | peer's information | - - -Request Example: -```bash -curl -k -X GET 'http://45.32.248.33:4096/api/peers/get?ip=45.32.248.33&port=4096' -``` - -JSON Response Example: -```js -{ - "success": true, - "peer": { - } -} -``` - -### 2.6 Sync and Loader -#### 2.6.1 Get the local blockchain loadig status -Interface Address: /api/loader/status -Request Method: get -Supported Format: none -Request Parameter Description: none - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|loaded |bool | | -|blocksCount|integer|| - -Request Example: -```bash -curl -k http://45.32.248.33:4096/api/loader/status -X GET -``` - -JSON Response Example: -```js -{ - "success": true, - "loaded": true, - "blocksCount": 0 -} -``` - -#### 2.6.2 Get the block syncing status -Interface Address: /api/loader/status/sync -Request Method: get -Supported Format: none -Request Parameter Description: none - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|height |int |block height | - -Request Example: -```bash -curl -k http://45.32.248.33:4096/api/loader/status/sync -X GET -``` - -JSON Response Example: -```js -{ - "success": true, - "syncing": false, // show whether in synchronising. if yes, it will be "true". if there is no data to synchronise, it will be "false" - "blocks": 0, - "height": 111987 -} -``` - -### 2.7 Second Password -#### 2.7.1 Set the Second Password -Interface Address: /api/signatures -Request Method: put -Supported Format: json -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|secret |string |Y |Asch account's password | -|publicKey|string |N|public key | -|secondSecret|string|Y|Asch account's second password,minimum length:1,maximum length:100| -|multisigAccountPublicKey|string|N|the public key of multi signatures account| - - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|transaction|json |the detail information of setting transaction | - - -Request Example: -```bash -curl -k -H "Content-Type: application/json" -X PUT -d '{"secret":"unaware label emerge fancy concert long fiction report affair appear decide twenty","secondSecret":"fault still attack alley expand music basket purse later educate follow ride"}' 'http://45.32.248.33:4096/api/signatures' -``` - -JSON Response Example: -```js -{ - "success": true, - "transaction": { - "type": 1, //the transaction type of setting second password is 1 - "amount": 0, - "senderPublicKey": "3b64f1833e6328043e1f2fee31e638bdaa6dfff5c7eb9c8577a5cefcf11261f2", - "requesterPublicKey": null, - "timestamp": 4872315, - "asset": { - "signature": { - "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9" - } - }, - "recipientId": null, - "signature": "e76d9b25ec0fdaa88b19d59c5a222b7efdc04f738ee05896f55f4e6959229d9b1600ca25aa92fbea176668f3be7c12c506f2091e2b38c52ef0ece7a5d35e240a", - "id": "1614688380530105232", - "fee": 500000000, //the transaction fee of setting second password is 5 XAS - "senderId": "250438937633388106" - } -} -``` - -#### 2.7.2 Get the Transaction Fee of Setting Second Password -Interface Address: /api/signatures/fee -Request Method:get -Supported Format: none -Request Parameter Description: none - - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|fee|integer |transaction fee | - - -Request Example: -```bash -curl -k http://45.32.248.33:4096/api/signatures/fee -X GET -``` - -JSON Response Example: -```js -{ - "success": true, - "fee": 500000000 //5 XAS -} -``` - -### 2.8 Multiple Signatures -#### 2.8.1 Set Normal Account to Multi-signatures Account -Interface Address: /api/multisignatures -Request Method: put -Supported Format: json -Comment: the return value is transaction ID only. To successfully set to multi-signature account still needs other's signatures. Every transaction after registered as multi-signatures account will be asked for multiple signatures. The minimum necessary signatures is defined by "min" (include sender itself) -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|secret |string |Y |Asch account's password | -|publicKey|string |N|public key | -|secondSecret|string|N|Asch account's second password, minimum length:1 maximum length: 100| -|min|integer|Y|the minimum signatures that is required to each transaction for multi-signatures account. (When the transaction is to register multi-signature account, this parameter will not work since everyone needs to sign.) Minimum:2, maximum:16. This number must not be larger than keysgroup.length+1. | -|lifetime|integer|Y|the maximum pending time of multi-signature transaction. Minimum:1, maximum:24. NOTE: this parameter is not available currently.| -|keysgroup|array|Y|an array containing other signaturers' public key. There are plus/minus (+/-) in front of each public key, means add or delete multi-signature account respectively. Minimum length:1, maximum length:10.| - - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|transactionId|string |the multi-signature transaction ID | - - -Request Example: -```bash -curl -k -H "Content-Type: application/json" -X PUT -d '{"secret":"vanish deliver message evil canyon night extend unusual tell prosper issue antenna","min":2,"lifetime":1,"keysgroup":["+eb48b9ab7c9a34a9b7cdf860265d65b31af774355cabf1b3a387d14a1925dc97","+d5d7aa157f866c47a2a1e09e2746286ed089fd90976b54fbfa930e87d11609cb"]}' 'http://45.32.248.33:4096/api/multisignatures' //公钥为2cef5711e61bb5361c544077aa08aebc4d962a1d656571901c48d716382ad4fd -``` - -JSON Response Example: -```js -{ - "success": true, - "transactionId": "17620378998277022323" //only transaction ID is returned. To successfully set to multi-signature account needs other accounts' signatures. -} -``` - -#### 2.8.2 Get the Detail Information of Pending Multi-signature Transaction -Interface Address: /api/multisignatures/pending -Request Method:get -Supported Format: urlencoded -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|publicKey|string |Y|public key | - - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|transactions|Array |a JSON object list containing those pending transactions | - - -Request Example: -```bash -curl -k -X GET http://45.32.248.33:4096/api/multisignatures/pending?publicKey=2cef5711e61bb5361c544077aa08aebc4d962a1d656571901c48d716382ad4fd -``` - -JSON Response Example: -```js -{ - "success": true, - "transactions": [{ //the detail information of the setting multi-signature account transaction (see 2.8.1, transactionId: 17620378998277022323) - "min": 2, - "lifetime": 1, - "signed": true, - "transaction": { - "type": 4, //4 means registering multi-signature account - "amount": 0, - "senderPublicKey": "2cef5711e61bb5361c544077aa08aebc4d962a1d656571901c48d716382ad4fd", - "requesterPublicKey": null, - "timestamp": 4879978, - "asset": { - "multisignature": { - "min": 2, - "keysgroup": ["+eb48b9ab7c9a34a9b7cdf860265d65b31af774355cabf1b3a387d14a1925dc97", - "+d5d7aa157f866c47a2a1e09e2746286ed089fd90976b54fbfa930e87d11609cb"], - "lifetime": 1 - } - }, - "recipientId": null, - "signature": "a42feaccd9f2a4940fc0be1a1580e786b360f189db3154328f307988e75484293eae391f2f9eee489913cc6d15984eb1f5f5a0aa1bf78ea745d5c725f161af08", - "id": "17620378998277022323", - "fee": 1500000000, - "senderId": "3855903394839129841" - } - }] -} - -``` - -#### 2.8.3 Sign the Multi-signature Transaction (by non-initiator) -Interface Address: /api/multisignatures/sign -Request Method:post -Supported Format: json -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|secret |string |Y |Asch account's password | -|secondSecret|string|N|Asch account second password. Minimum length:1, maximum length:100| -|publicKey|string |N|public key | -|transactionId|string|Y|transaction ID| - - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|transactionId|string |multi-signature transaction ID | - - -Request Example: -```bash -curl -k -H "Content-Type: application/json" -X POST -d '{"secret":"lemon carpet desk accuse clerk future oyster essay seminar force live dog","transactionId":"17620378998277022323"}' 'http://45.32.248.33:4096/api/multisignatures/sign' //signed by a user whose public key is eb48b9ab7c9a34a9b7cdf860265d65b31af774355cabf1b3a387d14a1925dc97 -``` - -JSON Response Example: -```js -{ - "success": true, - "transactionId": "17620378998277022323" -} -// Now get the pending transaction again -curl -k -X GET http://45.32.248.33:4096/api/multisignatures/pending?publicKey=2cef5711e61bb5361c544077aa08aebc4d962a1d656571901c48d716382ad4fd -{ - "success": true, - "transactions": [{ - "min": 2, - "lifetime": 1, - "signed": true, - "transaction": { - "type": 4, - "amount": 0, - "senderPublicKey": "2cef5711e61bb5361c544077aa08aebc4d962a1d656571901c48d716382ad4fd", - "requesterPublicKey": null, - "timestamp": 4879978, - "asset": { - "multisignature": { - "min": 2, - "keysgroup": ["+eb48b9ab7c9a34a9b7cdf860265d65b31af774355cabf1b3a387d14a1925dc97", - "+d5d7aa157f866c47a2a1e09e2746286ed089fd90976b54fbfa930e87d11609cb"], - "lifetime": 1 - } - }, - "recipientId": null, - "signature": "a42feaccd9f2a4940fc0be1a1580e786b360f189db3154328f307988e75484293eae391f2f9eee489913cc6d15984eb1f5f5a0aa1bf78ea745d5c725f161af08", - "id": "17620378998277022323", - "fee": 1500000000, - "senderId": "3855903394839129841", - "signatures": ["b38a161264db2a23e353d3fbc4983562f6343d5ee693144543ca54e2bc67c0f73d1c761b7bfa38b2bb101ac2ab0797b674b1a9964ccd400aaa310746c3494d03"] //new multi-signature generated - } - }] -} - -// a user whose public key is "d5d7aa157f866c47a2a1e09e2746286ed089fd90976b54fbfa930e87d11609cb" sign this registering transaction -curl -k -H "Content-Type: application/json" -X POST -d '{"secret":"chalk among elbow piece badge try van round quality position simple teach","transactionId":"17620378998277022323"}' 'http://45.32.248.33:4096/api/multisignatures/sign' -{"success":true,"transactionId":"17620378998277022323"} -// trying to get pending transaction again, but this time there isn't any of it. -curl -k -X GET http://45.32.248.33:4096/api/multisignatures/pending?publicKey=2cef5711e61bb5361c544077aa08aebc4d962a1d656571901c48d716382ad4fd -{"success":true,"transactions":[]} -// Check the detail of this transaction. (at this time, this transaction has been broadcasted to the whole network and been written to the blockchain) Now the account has already registered as a multi-signature account. -curl -k -X GET http://45.32.248.33:4096/api/transactions/get?id=17620378998277022323 -{ - "success": true, - "transaction": { - "id": "17620378998277022323", //the registering transaction ID - "height": "157013", - "blockId": "4680888982781013372", - "type": 4, - "timestamp": 4879978, - "senderPublicKey": "2cef5711e61bb5361c544077aa08aebc4d962a1d656571901c48d716382ad4fd", - "senderId": "3855903394839129841", - "recipientId": "", - "amount": 0, - "fee": 1500000000, - "signature": "a42feaccd9f2a4940fc0be1a1580e786b360f189db3154328f307988e75484293eae391f2f9eee489913cc6d15984eb1f5f5a0aa1bf78ea745d5c725f161af08", - "signSignature": "", - "signatures": null, - "confirmations": "26", - "asset": { - - } - } -} - -``` - -#### 2.8.4 Get Detail Information of the Multi-signature Account -Interface Address: /api/multisignatures/accounts -Request Method: get -Supported Format: urlencoded -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|publicKey |string |Y |One of the participants‘ public key | - - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |true: response data return successfully | -|accounts|Array |the detail of this multi-signature account | - - -Request Example: -```bash -curl -k -X GET http://45.32.248.33:4096/api/multisignatures/accounts?publicKey=eb48b9ab7c9a34a9b7cdf860265d65b31af774355cabf1b3a387d14a1925dc97 -``` - -JSON Response Example: -```js -{ - "success": true, - "accounts": [{ - "address": "3855903394839129841", //the address of this multi-signature account - "balance": 18500000000, //the balance of this multi-signature account - "multisignatures": ["eb48b9ab7c9a34a9b7cdf860265d65b31af774355cabf1b3a387d14a1925dc97", - "d5d7aa157f866c47a2a1e09e2746286ed089fd90976b54fbfa930e87d11609cb"], //the public key of this multi-signature account - "multimin": 2, //minimum required signature - "multilifetime": 1, - "multisigaccounts": [{ //the detail of signer's account - "address": "13542769708474548631", - "publicKey": "eb48b9ab7c9a34a9b7cdf860265d65b31af774355cabf1b3a387d14a1925dc97", - "balance": 0 - }, - { - "address": "4100816257782486230", - "publicKey": "d5d7aa157f866c47a2a1e09e2746286ed089fd90976b54fbfa930e87d11609cb", - "balance": 0 - }] - }] -} -``` - -### 2.9 Peer to Peer Transportation[secure API] -#### 2.9.1 Overview -To request a peer related API, it is required to set a header like this: - - - key=magic, and value=594fe0f3 - - key=version, and value='' - -#### 2.9.2 Transaction -All the writing operations in Asch system are finished by starting a transaction. -The transaction data is generated through a JS library named "asch-js", and then broadcasted by a POST API. -The POST API specification is as follows: - -payload: transaction data generated by asch-js -API Address: /peer/transactions -Request Method: POST -Supported Format: JSON - -##### 2.9.2.1 Set the Second Payment Password -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|transaction|json|Y|transaction data generated by [asch-js.signature.createSignature]| - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |whether the transaction is successful | - - -Request Example: -```js -var asch = require('asch-js'); -var transaction = asch.signature.createSignature('measure bottom stock hospital calm hurdle come banner high edge foster cram','erjimimashezhi001') -console.log(JSON.stringify(transaction)) -{"type":1,"amount":0,"fee":500000000,"recipientId":null,"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","timestamp":5328943,"asset":{"signature":{"publicKey":"27116db89cb5a8c02fb559712e0eabdc298480d3c79a089b803e35bc5ef7bb7b"}},"signature":"71ef98b1600f22f3b18cfcf17599db3c40727c230db817f610e86454b62df4fb830211737ff0c03c6a61ecfd4a9fcb68a30b2874060bb33b87766acf800e820a","id":"15605591820551652547"} - -// submit above data of setting second password to Asch server by POST method -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":1,"amount":0,"fee":500000000,"recipientId":null,"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","timestamp":5328943,"asset":{"signature":{"publicKey":"27116db89cb5a8c02fb559712e0eabdc298480d3c79a089b803e35bc5ef7bb7b"}},"signature":"71ef98b1600f22f3b18cfcf17599db3c40727c230db817f610e86454b62df4fb830211737ff0c03c6a61ecfd4a9fcb68a30b2874060bb33b87766acf800e820a","id":"15605591820551652547"}}' http://45.32.248.33:4096/peer/transactions -``` - -JSON Response Example: -```js -{ - "success":true //setting is successful -} -``` - -##### 2.9.2.2 Transfer Money -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|transaction|json|Y|transaction data generated by [asch-js.transaction.createTransaction]| - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |whether the transaction is successful | - - -Request Example: -```js -var asch = require('asch-js'); -var targetAddress = "16358246403719868041"; -var amount = 100*100000000; //100 XAS -var password = 'measure bottom stock hospital calm hurdle come banner high edge foster cram'; -var secondPassword = 'erjimimashezhi001'; - -// in above code, password is recorded when user logs in. meanwhile the second password needs to be input every time by user. -// To input or not depends on whether user has second password, which can be identified by "user.secondPublicKey" function. - -var transaction = asch.transaction.createTransaction(targetAddress, amount, password, secondPassword || undefined); -JSON.stringify(transaction) -'{"type":0,"amount":10000000000,"fee":10000000,"recipientId":"16358246403719868041","timestamp":5333378,"asset":{},"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","signature":"2d47810b7d9964c5c4d330a53d1382769e5092b3a53639853f702cf4a382aafcff8ef8663c0f6856a23f41c249944f0c3cfac0744847268853a62af5dd8fc90a","signSignature":"dfa9b807fff362d581170b41c56a2b8bd723c48d1f100f2856d794408723e8973016d75aeff4705e6837dcdb745aafb41aa10a9f1ff8a77d128ba3d712e90907","id":"16348623380114619131"}' - -// submit above data of transfer to Asch server by POST method -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":0,"amount":10000000000,"fee":10000000,"recipientId":"16358246403719868041","timestamp":5333378,"asset":{},"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","signature":"2d47810b7d9964c5c4d330a53d1382769e5092b3a53639853f702cf4a382aafcff8ef8663c0f6856a23f41c249944f0c3cfac0744847268853a62af5dd8fc90a","signSignature":"dfa9b807fff362d581170b41c56a2b8bd723c48d1f100f2856d794408723e8973016d75aeff4705e6837dcdb745aafb41aa10a9f1ff8a77d128ba3d712e90907","id":"16348623380114619131"}}' http://45.32.248.33:4096/peer/transactions -``` - -JSON Response Example: -```js -{ - "success":true //transfer success -} -``` - -##### 2.9.2.3 Register Delegates -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|transaction|json|Y|transaction data generated by [asch-js.delegate.createDelegate]| - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |whether transaction is success | - - -Request Example: -```js -var asch = require('asch-js'); -var password = 'measure bottom stock hospital calm hurdle come banner high edge foster cram'; -var secondPassword = 'erjimimashezhi001'; -var userName = 'zhenxi_test'; - -var transaction = asch.delegate.createDelegate(password, userName, secondPassword || undefined); -JSON.stringify(transaction) -'{"type":2,"amount":0,"fee":10000000000,"recipientId":null,"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","timestamp":5334485,"asset":{"delegate":{"username":"zhenxi_test","publicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f"}},"signature":"a12ce415d2d21ab46e4c1b918b8717b1d351dd99abd6f2f94d9a1a7e1f32b697f843a05b1851cb857ea45a2476dce592f5ddd612c00cd44488b8b610c57d7f0a","signSignature":"35adc9f1f37d14458e8588f9b4332eedf1151c02480159f64a287a4b0cbb59bfe82040dfec96a4d9560bae99b8eaa1799a7023395db5ddc640d95447992d6e00","id":"12310465407307249905"}' - -// submit above data of registering delegate to Asch server by POST method -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":2,"amount":0,"fee":10000000000,"recipientId":null,"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","timestamp":5334485,"asset":{"delegate":{"username":"zhenxi_test","publicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f"}},"signature":"a12ce415d2d21ab46e4c1b918b8717b1d351dd99abd6f2f94d9a1a7e1f32b697f843a05b1851cb857ea45a2476dce592f5ddd612c00cd44488b8b610c57d7f0a","signSignature":"35adc9f1f37d14458e8588f9b4332eedf1151c02480159f64a287a4b0cbb59bfe82040dfec96a4d9560bae99b8eaa1799a7023395db5ddc640d95447992d6e00","id":"12310465407307249905"}}' http://45.32.248.33:4096/peer/transactions -``` - -JSON Response Example: -```js -{ - "success":true //register successfully -} -``` - -##### 2.9.2.4 Vote and Cancel the vote - -Request Parameter Description: - -|Name |Type |Required |Description | -|------ |----- |--- |---- | -|transaction|json|Y|transaction data generated by [asch-js.vote.createVote]| - -Response Parameter Description: - -|Name |Type |Description | -|------ |----- |---- | -|success|bool |whether the transaction is successful | - - -Request Example: -```js -var asch = require('asch-js'); -var password = 'measure bottom stock hospital calm hurdle come banner high edge foster cram'; -var secondPassword = 'erjimimashezhi001'; -// the voting content is a list in which each item consists of a symbol (+ or -) and the delegate's public key. The "+" means vote, and "-" means cancel the vote. -var voteContent = [ - '-ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7', - '+c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2' -]; - -var transaction = asch.vote.createVote(password, voteContent, secondPassword || undefined); -JSON.stringify(transaction) -{"type":3,"amount":0,"fee":10000000,"recipientId":null,"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","timestamp":5334923,"asset":{"vote":{"votes":["-ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7","+c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2"]}},"signature":"6036c2066a231c452a1c83aafd3bb9db3842ee05d5f17813f8264a4294cdec761faa89edf4a95f9b2e2451285807ab18aa9f989ad9a3165b95643179b8e4580f","signSignature":"a216ca739112e6f65986604b9467ccc8058138a7077faf134d6c4d673306cd1c514cc95bd54a036f7c602a56c4b4f2e4e59f6aa7c376cb1429e89054042e050b","id":"17558357483072606427"} - -// submit above data of vote/cancel vote to Asch server by POST method -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":3,"amount":0,"fee":10000000,"recipientId":null,"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","timestamp":5334923,"asset":{"vote":{"votes":["-ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7","+c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2"]}},"signature":"6036c2066a231c452a1c83aafd3bb9db3842ee05d5f17813f8264a4294cdec761faa89edf4a95f9b2e2451285807ab18aa9f989ad9a3165b95643179b8e4580f","signSignature":"a216ca739112e6f65986604b9467ccc8058138a7077faf134d6c4d673306cd1c514cc95bd54a036f7c602a56c4b4f2e4e59f6aa7c376cb1429e89054042e050b","id":"17558357483072606427"}}' http://45.32.248.33:4096/peer/transactions -``` - -JSON Response Example: -```js -{ - "success":true //transaction of vote/cancel the vote is success -} -``` - - -## Appendix 1: Install 'asch-js' library -All the writing operations in Asch system are finished by starting a transaction. -The transaction data is generated through a JS library named "asch-js", and then broadcasted by a POST API. - -**Install the library** -`npm install asch-js` - \ No newline at end of file diff --git a/docs/asch_install.md b/docs/asch_install.md deleted file mode 100644 index 642d45a..0000000 --- a/docs/asch_install.md +++ /dev/null @@ -1,207 +0,0 @@ -# Asch节点安装文档 - -## 1 系统要求 - -- 必须是linux系统 -- 必须有公网ip -- 建议使用ubuntu 16.04 64位操作系统 -- 建议CPU 2C以上 -- 建议内存2G以上 -- 建议带宽2Mb以上 -- 建议硬盘空间10GB以上 - -## 2 安装 - -测试版(testnet)与正式版(mainnet)是同时存在但无法互通的两套系统
-除了安装包、默认配置文件(包括默认端口等)不一样外,安装流程是一样的
-只要端口不冲突,可以同时在一台机器安装,但是不推荐这样做,除非机器配置足够好,比如4核、4G内存、4M带宽... - -### 2.1 下载和解压缩 - -测试版testnet - -``` -wget https://www.asch.io/downloads/asch-linux-latest-testnet.tar.gz -tar zxvf asch-linux-latest-testnet.tar.gz -``` - -正式版mainnet - -``` -wget https://www.asch.io/downloads/asch-linux-latest-mainnet.tar.gz -tar zxvf asch-linux-latest-mainnet.tar.gz -``` - -一般情况下,testnet的版本号大于等于mainnet的版本号 - -### 2.2 初始化 - -这一步会自动帮您做以下几件事情 - -1. 安装sqlite3等依赖软件 -2. 安装和配置ntp服务,保证您的时间与其他节点同步 - -这一步只需要运行一次即可,重复运行也无妨 - -``` -# 进入你的安装目录 -# ubuntu执行下面的命令 -chmod u+x init/*.sh && ./aschd configure -# 其他linux系统 -请自行利用apt-get/yum/zypper等包管理器工具安装sqlite3/ntp2个依赖包 -``` - -## 3 运行 - -``` -# 进入你的安装目录 - -# 启动 -./aschd start - -# 停止 -./aschd stop - -# 查看运行状态 -./aschd status - -# 重启 -./aschd restart - -# 升级 -./aschd upgrade - -# 重新同步区块 -./aschd rebuild - -# 查看版本 -./aschd version - -# 开启区块生产 -./aschd enable "your sercret" - -# 查看log -tail -f logs/debug.log -``` - -## 4 受托人配置 - -### 4.1 受托人密码 - -使用文本编辑工具打开config.json, 找到secret字段,将你的受托人密钥填进去即可,该字段为json字符串数组,一台机器可以配置多个,但不能重复 - -![forging secret](./assets/forging-secret.png) - -**注意** 不管是一台机器还是多台机器,不要配置重复的受托人密钥 - -### 4.2 公网IP - -默认情况下,系统会自动检测公网ip,但在某些云主机中,公网ip无法检测到,这时需要手动在config.json修改或添加如下字段 - -``` -"publicIp": "此处填写你的公网ip", -``` - -配置完之后需要重启程序 - -``` -./aschd restart -``` - -## 5 升级 - -``` -./aschd upgrade -./aschd start -``` - -## 6 错误诊断 - -### 6.1 在线钱包无法访问 - -【情况一】 - -查看是否改了config.json里的port字段, testnet的端口默认为4096,mainnet的端口默认为8192
-官方的种子节点将端口改成了80 -检查防火墙配置,需要打开Asch的端口入站和出站。 - -【情况二】 - -查看服务是否启动,可以使用如下命令 - -``` -./aschd status - -# 如果没有启动则显示 -Asch server is not running - -# 如果出现这种情况,重启即可 -./aschd restart -``` - -### 6.2 无法生产区块 - -【情况一】 - -查看受托人排名是否进入前101 - -【情况二】 - -使用下面的命令搜索错误日志 - -``` -grep Failed logs/debug.log -``` - -如果出现了如下字样 - -``` -Failed to get public ip, block forging MAY not work! -``` - -说明公网ip没有自动获取到,需要你手动配置,具体可以参考[4.2 公网IP]一节 - -【情况三】 - -使用下面的命令搜索错误日志 - -``` -grep error logs/debug.log -``` - -如果出现了如下字样 - -``` -Failed to load delegates: Account xxxxxxxxx not found -``` - -说明你配置的账户密钥还没有注册成为受托人,或者注册成为受托人之前就启动了服务,这时重启服务即可
-**注意** 如果你的节点正在同步区块,不要立即重启,等同步完成了再重启 - -``` -./aschd restart -``` - -正常情况下应该会出现如下log - -``` -grep Forging logs/debug.log - -Forging enabled on account: xxxxxxxxxxxxxx -``` - -### 6.3 无法同步区块(卡块) - -(可以通过对比自己钱包的区块高度与官方节点的最新区块高度来确认这一现象)
- -优先使用restart命令 - -``` -./aschd restart -``` - -如果无法解决,使用rebuild命令 - -``` -./aschd rebuild -``` \ No newline at end of file diff --git a/docs/asch_install_de.md b/docs/asch_install_de.md deleted file mode 100644 index 33a251e..0000000 --- a/docs/asch_install_de.md +++ /dev/null @@ -1,172 +0,0 @@ -# Asch Knoten Installation Anleitung - -## 1. System Anforderung -- Linux-System erforderlich -- Öffentliche IP-Adresse erforderlich -- Ubuntu 16.04 64bit OS empfohlen -- Mehr als 2Gb RAM wird empfohlen -- Mehr als 2Mb Bandbreite wird empfohlen -- Mehr als 10GB Festplattespeicher wird empfohlen - -## 2. Installation - -Es gibt zwei unterschiedliche Systeme: Das Testsystem (testnet) und Hauptsystem (mainnet). Beide existieren nebeneinander, können aber nicht miteinander kommunizieren. - -Die Schritte zur Installation sind für diese beiden System die Gleichen. Bis auf das Installationspaket und die Datei-Konfiguration (inklusive der Port Einstellungen). - -So lange es keinen Konflikt mit den Ports gibt, ist es möglich die beiden Versionen nebeneinander auf dem Computer zu installieren. Dies ist jedoch nicht empfohlen, da alle Ressourcen benötigt werden. Am besten eignet sich ein Server mit einer 4 Kerne CPU, 4GB RAM und mindestens 4MB Netzwerkanbindung. - - -### 2.1 Downloaden und Entpacken - -test version (testnet) - -``` -wget https://www.asch.so/downloads/asch-linux-latest-testnet.tar.gz -tar zxvf asch-linux-latest-testnet.tar.gz -``` - -official version (mainnet) -``` -wget https://www.asch.so/downloads/asch-linux-latest-mainnet.tar.gz -tar zxvf asch-linux-latest-mainnet.tar.gz -``` - -Üblicherweise ist die Versionsnumber der Testchain höher als die der Mainchain. - -### 2.2 Initialisierung -In diesem Schritt werden folgenden Dinge automatisch installiert: -- Installtion von Module wie **sqlite3** -- Installation und Konfiguration des NTP-Service, welcher die Systemzeit mit der der anderen Knoten synchronisiert - -Dieser Schritt muss nicht ausgeführt werden, es passiert aber nichts Schlimmes, wenn er öfters ausgeführt wird. - - # dies soll im Installations-Verzeichnis ausgeführt werden - ./aschd configure - ... - -## 3. Starten -``` -# Folgende Kommandos werden im Installations-Verzeichnis ausgeführt - -# das Service starten -./aschd start - -# das Service stoppen -./aschd stop - -# zeige den aktuellen Status -./aschd status - -# das Service neustarten -./aschd restart - -# ein Asch-Upgrade durchführen -./aschd upgrade - -# die blockchain resynchronisieren -./aschd rebuild - -# die Asch-Version anzeigen lassen -./aschd version - -# mit der Blöcke-Produzieren starten -./aschd enable "your sercret" - -# die Logs anzeigen -tail -f logs/debug.log -``` - -## 4. Delegat Konfiguration -### 4.1 Delegat Passwort - -Öffne mit deinem Lieblingseditor folgende Datei `config.json` und navigiere zum `[secret]` Feld. Fülle dieses Feld mit dem Passwort des Delegats. Dieses Feld ist eine JSON-String-Array welches verwendet werden kann um mehrere Passwörter zu setzen. Sei vorsichtig kein Passwort zu wiederholen. - -![forging secret](./assets/forging-secret.png) - -**HINWEIS:** Konfiguriere NIEMALS das selbe Passwort. Egal ob auf einem Rechner oder auf unterschiedlichen. - - -### 4.2 Öffentliche IP-Adresse -Von Haus aus erkennt das System automatisch die zugewiesene öffentliche IP-Adresse. Aber auf manchen Knoten in der Cloud kann die öffentliche IP-Adresse nicht identifiziert werden. Unter diesen Umständen muss folgendes Feld an die Datei `config.json` angehängt werden. - - -``` -"publicIp": "Hier steht die öffentliche IP-Adresse", -``` -Vergiss nicht das System nach der Konfiguration mit folgendem Befehl neu zu starten. -``` -./aschd restart -``` - -## 5. System Upgrade -``` -./aschd upgrade -./aschd start -``` -## 6. Fehlerbehebung -### 6.1 Ich kann nicht auf meine Online-Wallet zugreifen -#### Lösung 1 -Überprüfe das `[port]` Feld in der `config.json` Datei. Die default Portnummer für das **testnet** ist `4096` und für das **mainnet** `8192`. -Die offiziellen Seed-Nodes haben die Portnummer auf 80 geändert. -Überprüfe die Firewall-Einstellungen und öffne den Asch-Port für eingehenden und ausgehenden Verkehr. - -#### Lösung 2 -Überprüfe ob mit folgendem Kommando ob der Service gestartet ist: -``` -./aschd status - -# falls der Service nicht läuft kommt folgende Meldung: -Asch server is not running - -# danach starte das Service neu -./aschd restart -``` - -### 6.2 Es werden keine Blöcke produziert -#### Lösung 1 -Stelle sicher, dass dein Delegat-Rank unter den TOP 101 ist - -#### Lösung 2 -Überprüfe den Fehler-Log mit folgendem Kommando: -``` -grep Failed logs/debug.log -``` -Falls es eine ähnliche Fehlernachricht gibt wie: -``` -Failed to get public ip, block forging MAY not work! -``` -bedeutet dies, dass das system nicht die öffentliche IP-Adresse hat. Dies muss manuell konfiguriert werden. Siehe **[4.2 Public IP]** - -#### Lösung 3 -Überprüfe den Fehler-Log mit folgendem Kommando: -``` -grep error logs/debug.log -``` -Falls es eine ähnliche Fehlernachricht gibt wie: -``` -Failed to load delegates: Account xxxxxxxxx not found -``` -bedeutet dies, dass die Passphrase für dein Konto noch nicht als Delegat registriert wurde. Es kann auch sein, dass der Service gestartet wurde bevor er als Delegat registriert wurde. In diesem Fall hilft ein einfaches neustarten des Services. - -**HINWEIS:** Falls dein Knoten gerade die Blöcke synchronisiert ist es zu empfehlen das System erst nach der abgeschlossenen Sychronisation zu starten. -``` -./aschd restart -``` -Wenn das System erfolgreich neugestartet wurde, ist folgendes im Log zu lesen: -``` -grep Forging logs/debug.log - -Forging enabled on account: xxxxxxxxxxxxxx -``` -### 6.3 Meine Blöcke werden nicht sychronisiert (Blockhöhe wächst nicht) -*Dieses Problem kann verifiziert werden in dem man seine Blockhöhe mit der des offiziellen Knotens vergleicht - -Als allererstes, versuche das System neu zu starten -``` -./aschd restart -``` -Falls das Problem noch immer auftritt, versuche folgendes:` -``` -./aschd rebuild -``` diff --git a/docs/asch_install_en.md b/docs/asch_install_en.md deleted file mode 100644 index d7c1143..0000000 --- a/docs/asch_install_en.md +++ /dev/null @@ -1,170 +0,0 @@ -# Asch Node Installation Guide - -## 1. System requirements -- Linux system required -- Public IP address required -- Ubuntu 16.04 64bit OS recommended -- Above 2Gb RAM recommended -- Above 2Mb broadwidth recommended -- Above 10GB GB harddisk recommended - -## 2. Installation -There are two seperated system: test version (testnet) and main official version (mainnet). Both of them are co-existed but unable to communicate with each other. - -The installation procedures of these two system are the same except the installation package and configuration file (including default port setting). - -As long as there is no conflict of ports, you can install the test version and official version into the same compouter, but please note, the power of the machine is highly required, such as 4core CPU, 4Gb RAM above or at least 4Mb broadwidth... - -### 2.1 Download and unpack - -test version (testnet) - -``` -wget https://www.asch.io/downloads/asch-linux-latest-testnet.tar.gz -tar zxvf asch-linux-latest-testnet.tar.gz -``` - -official version (mainnet) -``` -wget https://www.asch.io/downloads/asch-linux-latest-mainnet.tar.gz -tar zxvf asch-linux-latest-mainnet.tar.gz -``` - -Usually, the version number of testnet will larger than that of mainnet. - -### 2.2 Initialize -In this step, something will be done for you automatically: -- Install some dependency modules like **sqlite3** -- Install and configure the ntp service by which your time can be synchronized with that of other nodes. - -There is no need to run this step once although there is no harm to execute it more than one time. - - # locate to your installation folder - # for ubuntu - chmod u+x init/*.sh && ./aschd configure - # for other linux - please install sqlite3/ntp using apt-get/yum/zypper or other package manager. - ... - -## 3. Run -``` -# Enter the installation folder - -# start the service -./aschd start - -# stop the service -./aschd stop - -# check the running status -./aschd status - -# restart the service -./aschd restart - -# upgrade the system -./aschd upgrade - -# re-synchronize the blockchain -./aschd rebuild - -# check the system version -./aschd version - -# start producing block -./aschd enable "your sercret" - -# check the log -tail -f logs/debug.log -``` - -## 4. Delegate configuration -### 4.1 Delegate's password - -Use your favorite editor to open `config.json` and locate the `[secret]` field. Fill this field with your delegate's password. This field is an array of JSON format string, which means you can set several passwords in one particular computer, but be careful not to duplicate them. - -![forging secret](./assets/forging-secret.png) - -**NOTICE:** DO NOT configure the same password, no matter in a single machine or in multiple machines. - -### 4.2 Public IP -By default, the system will automatically detect the public IP you assigned. But in some host built on cloud, the public IP may not be able to identified. Under such circumstance, the following field needs to be appended in `config.json`: -``` -"publicIp": "Here is your public IP", -``` -And don't forget restarting your system after configuration by: -``` -./aschd restart -``` - -## 5. Upgrade the system -``` -./aschd upgrade -./aschd start -``` -## 6. Troubleshooting -### 6.1 I cannot access my online wallet -#### Solution 1 -Check the `[port]` field in `config.json`, the default port numbers of **testnet** and **mainnet** are `4096` and `8192`, respectively. -The official seed nodes changed the port to 80. -Check the firewall configuration, and you need to open the Asch port inbound and outbound. - -#### Solution 2 -Check whether service is started by typing commands as follows: -``` -./aschd status - -# if service is not started, then following message will be shown -Asch server is not running - -# then restart the service -./aschd restart -``` - -### 6.2 Unable to generate the block -#### Solution 1 -Make sure the rank of delegate is in top 101 - -#### Solution 2 -Check the error log with following commands: -``` -grep Failed logs/debug.log -``` -If there is an error message like this: -``` -Failed to get public ip, block forging MAY not work! -``` -it means system cannot get the public IP, and it will need you to configure it manually, see **[4.2 Public IP]** - -#### Solution 3 -Check the error log with following commands: -``` -grep error logs/debug.log -``` -If there is an error message like this: -``` -Failed to load delegates: Account xxxxxxxxx not found -``` -It means that the passphrase of your account has not been registed as delegates yet, or you started the service before it registered as a delegate. Simply restarting the servie will solve the problem. - -**NOTICE:** If your node is synchronizing the blocks, restart the system after the synchronization is finished. -``` -./aschd restart -``` -If the system has been restarted successfully, the following log will be found: -``` -grep Forging logs/debug.log - -Forging enabled on account: xxxxxxxxxxxxxx -``` -### 6.3 Unable to synchronize the block (blockchain growth suspend) -*This issue can be confirmed by comparing the block height of your wallet and official node* - -First, try `restart` the system: -``` -./aschd restart -``` -If problem is still unsolved, try `rebuild` -``` -./aschd rebuild -``` diff --git a/docs/asch_js_api.md b/docs/asch_js_api.md deleted file mode 100644 index 8c1df90..0000000 --- a/docs/asch_js_api.md +++ /dev/null @@ -1,994 +0,0 @@ -Table of Contents -================= - - * [Asch-JS API 使用说明](#asch-js-api-使用说明) - * [1 Asch-js说明](#1-asch-js说明) - * [1.1 asch-js安装](#11-asch-js安装) - * [1.2 说明](#12-说明) - * [2 账户](#2-账户) - * [2.1 根据密码获取密钥对](#21-根据密码获取密钥对) - * [2.1 根据公钥获取地址](#21-根据公钥获取地址) - * [2.3 设置二级密码,type=1](#23-设置二级密码type1) - * [2.4 账户锁仓,type=100](#24-账户锁仓type100) - * [3 普通交易transactions](#3-普通交易transactions) - * [3.1 在主链转账XAS,type=0](#31-在主链转账xastype0) - * [3.2 根据交易内容获取交易id](#32-根据交易内容获取交易id) - * [4 资产相关uia](#4-资产相关uia) - * [4.1 资产发行商注册,type=9](#41-资产发行商注册type9) - * [4.2 资产注册,type=10](#42-资产注册type10) - * [4.3 资产设置访问控制列表(acl)模式,type=11](#43-资产设置访问控制列表acl模式type11) - * [4.4 更新访问控制列表(acl),type=12](#44-更新访问控制列表acltype12) - * [4.5 资产发行,type=13](#45-资产发行type13) - * [4.6 资产转账,type=14](#46-资产转账type14) - * [4.7 资产注销,type=11](#47-资产注销type11) - * [5 受托人delegate](#5-受托人delegate) - * [5.1 注册受托人,type=2](#51-注册受托人type2) - * [5.2 给受托人增加/取消投票,type=3](#52-给受托人增加取消投票type3) - * [6 dapp相关](#6-dapp相关) - * [6.1 dapp注册,type=5](#61-dapp注册type5) - * [6.2 dapp充值,type=6](#62-dapp充值type6) - * [6.3 dapp内部合约调用](#63-dapp内部合约调用) - * [6.3.1 dapp提现,合约type=2](#631-dapp提现合约type2) - * [6.3.2 dapp内部转账,合约type=3](#632-dapp内部转账合约type3) - * [6.3.4 dapp内设置昵称,合约type=3](#634-dapp内设置昵称合约type3) - * [6.4 dapp提现](#64-dapp提现) - * [6.4.1 创建提现交易,type=7](#641-创建提现交易type7) - * [6.4.2 受托人对提现交易进行签名](#642-受托人对提现交易进行签名) - * [7 存储storage](#7-存储storage) - * [7.1 创建存储交易,type=8](#71-创建存储交易type8) - * [8 签名验证相关crypto](#8-签名验证相关crypto) - * [8.1 根据交易内容获取字节Buffer对象](#81-根据交易内容获取字节buffer对象) - * [8.2 根据交易内容获取Hash Buffer对象](#82-根据交易内容获取hash-buffer对象) - * [8.3 根据交易内容获取交易id](#83-根据交易内容获取交易id) - * [8.4 对交易Bytes Buffer进行签名](#84-对交易bytes-buffer进行签名) - * [8.5 验证交易签名是否和已存在的签名一致](#85-验证交易签名是否和已存在的签名一致) - * [9 其它](#9-其它) - * [9.1 全局参数变量options](#91-全局参数变量options) - * [9.1.1 设置变量k/v](#911-设置变量kv) - * [9.1.2 根据key获取value](#912-根据key获取value) - * [9.1.3 获取所有的k/v](#913-获取所有的kv) - * [9.2 时间相关slot.time](#92-时间相关slottime) - * [9.2.1 asch主网创世块生成时间](#921-asch主网创世块生成时间) - * [9.2.2 根据unix时间戳获获Asch时间戳](#922-根据unix时间戳获获asch时间戳) - * [9.2.3 根据Asch时间戳获取unix时间戳](#923-根据asch时间戳获取unix时间戳) - -Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc) - - -# Asch-JS API 使用说明 - - -## **1 Asch-js说明** - -### **1.1 asch-js安装** - -``` -npm install asch-js -var AschJS = require('asch-js'); -``` - -### **1.2 说明** -很多函数都需要传入secret、secondSecret这2个参数,分表代表密码和二级密码,下面章节不再赘述。 -自定如下全局变量,用于之后章节代码演示。 - -- `secret` 密码 -- `publicKey` 公钥 -- `secondSecret` 二级密码 - -``` -> var secret = 'minor borrow display rebel depart core buzz right distance avocado immense push' -> var publicKey = 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed'; -> var secondSecret = 'erjimima2017'; -``` - -生成的json交易信息都需要通过http api进行广播。 -- 主链交易通过 `POST /peer/transactions` -- dapp交易通过 `PUT /api/dapps/dappID/transactions/signed` - - -## **2 账户** - -### **2.1 根据密码获取密钥对** - -`crypto.getKeys(secret)` - -- `secret` 密码 - -``` -> AschJS.crypto.getKeys(secret) -{ publicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - privateKey: '7ae536fa343281d9e9ed383e8b5ef62e0fd0d0cbed79786cac241d484e312fdeebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed' } -``` - -### **2.1 根据公钥获取地址** - -`crypto.getAddress(publicKey)` - -- `publicKey` 公钥 - -``` -> AschJS.crypto.getAddress(publicKey); -'AFUH568CbGC2GPcE4gXHiZhxdYQYfziz2J' - -``` - -### **2.3 设置二级密码,type=1** - -`crypto.signature.createSignature(secret, secondSecret)` -`备注` 在主链的交易类型为1 - -- `secret` 密码 -- `secondSecret` 二级密码 - -``` -> AschJS.signature.createSignature(secret, secondSecret) -{ type: 1, - amount: 0, - fee: 500000000, - recipientId: null, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - timestamp: 40566038, - asset: { signature: { publicKey: '632a41caf7d3c8d3754f27a11004acaea6f5571eed28b42451b5560ee91e991c' } }, - signature: 'ee42f4dc17ace4f76f86fba93c7d86b61a69de46ac96e102e9f93668c8cdd9e6281821c63cb3e0c23099968cccdcfd0197aaab42afba4a98fa696c17b133be06', - id: '2237134c11b3cbaa9b7951f4afd47454ca04af2c7c6a030729ec63f75230e9ad' } - -``` - -### **2.4 账户锁仓,type=100** - -`transaction.createLock(height, secret, secondSecret)` -`备注` 在主链的交易类型为100 - -- `height` 锁仓高度 -- `secret` 密码 -- `secondSecret` 二级密码 - -``` -> AschJS.transaction.createLock(8130, secret, secondSecret) -{ type: 100, - amount: 0, - fee: 10000000, - recipientId: null, - args: [ '8130' ], - timestamp: 40566287, - asset: {}, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - signature: '06f6852d0e2e56ca441fa60b407aaa2197290ff096558c746c9c8bcdc971b8c4065ec08edd49c7292eca51849c16c5b8f0d33bb4ce972a932603dcf46a391e0e', - signSignature: '3b645b0f6a2c597c55595669a856489c0c4f3a132c798c615b8e0241f3169a367edea7228ebc8915d5fd7a0571cc08c971d07520b9908c80c9b2c2c76ada5e07', - id: 'c87d93af84939076a65a49c3b483897d262edc340b2d4184a4d2505b58711a91' } -``` - - -## **3 普通交易transactions** - -### **3.1 在主链转账XAS,type=0** - -`transaction.createTransaction(recipientId, amount, message, secret, secondSecret)` -`备注` 在主链的交易类型为0 - -- `recipientId` 接收者地址 -- `amount` 转账数量 -- `message` 转账附言 -- `secret` 密码 -- `secondSecret` 二级密码 - -``` -> var targetAddress = "16358246403719868041"; -undefined -> var amount = 100*100000000; //100 XAS -undefined -> var message = 'beizhu'; -undefined -> AschJS.transaction.createTransaction(targetAddress, amount, message, secret, secondSecret) -{ type: 0, - amount: 10000000000, - fee: 10000000, - recipientId: '16358246403719868041', - message: 'beizhu', - timestamp: 40566970, - asset: {}, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - signature: '9bef374be100fcfec59d245af59e5646ba5dcb79c6f1399ddd676a617542eeb45cc363822b84410e379f0caa501c25b66e59142353c04d23d1cb95cf64cef306', - signSignature: '513e3efdbb65f8e60e85ca98d8d065ec9bd3bfa6f45a1f48cfade9c94d410338ee64bd55938c168b10f0749335c050312785dbf08882ffd0e40a65fde8c2b10b', - id: '871554a8346d84cab2147324706d8ab5494fde928a7463a68d536ed6c0357897' } - -``` - - -### **3.2 根据交易内容获取交易id** - -`crypto.getId(transaction)` - -- `transaction` 签名后的交易内容 - -``` -> var targetAddress = "16358246403719868041"; -> var amount = 100*100000000; //100 XAS -> var message = 'beizhu'; -> transaction = AschJS.transaction.createTransaction(targetAddress, amount, message, secret, secondSecret) -{ type: 0, - amount: 10000000000, - fee: 10000000, - recipientId: '16358246403719868041', - message: 'beizhu', - timestamp: 40566970, - asset: {}, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - signature: '9bef374be100fcfec59d245af59e5646ba5dcb79c6f1399ddd676a617542eeb45cc363822b84410e379f0caa501c25b66e59142353c04d23d1cb95cf64cef306', - signSignature: '513e3efdbb65f8e60e85ca98d8d065ec9bd3bfa6f45a1f48cfade9c94d410338ee64bd55938c168b10f0749335c050312785dbf08882ffd0e40a65fde8c2b10b', - id: '871554a8346d84cab2147324706d8ab5494fde928a7463a68d536ed6c0357897' } - -> AschJS.crypto.getId(transaction) -'871554a8346d84cab2147324706d8ab5494fde928a7463a68d536ed6c0357897' // 返回结果,交易id - -``` - - -## **4 资产相关uia** - -### **4.1 资产发行商注册,type=9** - -`uia.createIssuer(name, desc, secret, secondSecret)` -`备注` 在主链的交易类型为9 - -- `name` 资产发行商名字 -- `desc` 资产发行商描述 - -``` -var name = 'IssuerName' -var desc = 'IssuerDesc' -AschJS.uia.createIssuer(name, desc, secret, secondSecret) -{ - "type": 9, - "amount": 0, - "fee": 10000000, - "recipientId": null, - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "timestamp": 19395607, - "asset": { - "uiaIssuer": { - "name": "IssuerName", - "desc": "IssuerDesc" - } - }, - "signature": "c6ed2a4bafe2b8aa31f4aaceacc2a96cb028abbabb2ed062937498c58e24ca5467a340ddd63b67f809a680ff91b83e685c64991eb695494ddb2fdc57e5761607", - "signSignature": "8eceacbd47c2b8ed335145ced19d7a3a51f99bdd6631d16ed214180c6f80e29bd6d572f45e7c7d685584e55cb5c303cf340406553ece28c9c0a2fa7a777aac0b" -} -``` - - - -### **4.2 资产注册,type=10** - -`uia.createAsset(name, desc, maximum , precision, strategy, secret, secondSecret)` -`备注` 在主链的交易类型为10 - -- `name` 资产名称,格式为:发行商名.资产名,是资产的唯一标识 -- `desc` 资产描述 -- `maximum` 资产可发行的上限值 -- `precision` 精度,小数点的位数,这里上限是1000000,精度为3,代表资产IssuerName.CNY的最大发行量为1000.000 -- `strategy` 发行策略策略,如没隔1年发行10% - -``` -var name = 'IssuerName.CNY' -var desc = '资产描述' -var maximum = '1000000' -var precision = 3 -var strategy = '' - -AschJS.uia.createAsset(name, desc, maximum , precision, strategy, secret, secondSecret) -{ - "type": 10, - "amount": 0, - "fee": 10000000, - "recipientId": null, - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "timestamp": 19397444, - "asset": { - "uiaAsset": { - "name": "IssuerName.CNY", - "desc": "资产描述", - "maximum": "1000000", - "precision": 3, - "strategy": "" - } - }, - "signature": "c755587d331dd2eb62ef91dce1511d83a3e603c7cdc7548a16052519c21ea89c78364e35e5d46da0e2103fa2fb7f037eec55a5deba18826fa13e4252422d750e", - "signSignature": "1b7ed4c21c477b8ff3d2acfdfd7ff85617093f4c21de70938c46b61c9704b037dbcf7f9e5f5dd1a5dc8f22cf473aaa459e6e5b15ced388b8a1da1e307987a509" -} -``` - - - -### **4.3 资产设置访问控制列表(acl)模式,type=11** - -`uia.createFlags(currency, flagType, flag, secret, secondSecret)` -`备注` 在主链的交易类型为11 - -- `currency` 资产名称 -- `flagType` 资产是否注销,1:流通,2:注销 -- `flag` 访问控制列表的类型,0:黑名单, 1:白名单,资产创建后默认为黑名单模式 - -``` -var currency = 'IssuerName.CNY' -var flagType = 1 -var flag = 1 - -AschJS.uia.createFlags(currency, flagType, flag, secret, secondSecret) -{ - "type": 11, - "amount": 0, - "fee": 10000000, - "recipientId": null, - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "timestamp": 19400996, - "asset": { - "uiaFlags": { - "currency": "IssuerName.CNY", - "flagType": 1, - "flag": 1 - } - }, - "signature": "b96fb3d1456e1f26357109cc24d82834eb9a4687f29e69c374bbb1d534568336e148cac52f213aa4d2a69185092f8e1143b49ec4b8048cd9b3af4e20f6ba0b08", - "signSignature": "b37c77ebebe90341346be2aefe1e12bd7403e5d8f4d6e8f04630190b3e09494a28820da0ffd5f9ff011033aa6d70fc9bb4c159a4493be3b18fd7ff470103570d" -} -``` - -### **4.4 更新访问控制列表(acl),type=12** - -`uia.createAcl(currency, operator, flag, list, secret, secondSecret)` -`备注` 在主链的交易类型为12 - -- `currency` 资产名称 -- `operator` 操作符,'+'表示增加列表, ‘-’表示删除列表 -- `flag` 访问控制列表的类型,0:黑名单, 1:白名单,资产创建后默认为黑名单模式 -- `list` 待修改地址列表 - -``` -var currency = 'IssuerName.CNY' -var operator = '+' -var list = ['15745540293890213312'] -var flag =1 - -AschJS.uia.createAcl(currency, operator, flag, list, secret, secondSecret) -{ - "type": 12, - "amount": 0, - "fee": 20000000, - "recipientId": null, - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "timestamp": 19403125, - "asset": { - "uiaAcl": { - "currency": "IssuerName.CNY", - "operator": "+", - "flag": 1, - "list": ["15745540293890213312"] - } - }, - "signature": "ad4060e04c1a12256de114e34499f8add24326753f1f8362991ee14aefc4c0fe90ff394d2db97e83770855a5688d463de00656fdd2d04604605cf3c04fdaca0e", - "signSignature": "63129c58b1b9fcce88cbe829f3104a10ab06037253e9b65feb50ce0d2bb988533b93e8edcad016a85675f9027758fc318cf899ca7ef161a95a8d8a055ae83a02" -} -``` - -### **4.5 资产发行,type=13** - -`uia.createIssue(currency, amount, secret, secondSecret)` -`备注` 在主链的交易类型为13 - -- `currency` 资产名称 -- `amount` 本次发行量=真实数量(100)*10**精度(3),并且所有发行量之和 <= 上限*精度 - -``` -var currency = 'IssuerName.CNY' -var amount = '100000' - -AschJS.uia.createIssue(currency, amount, secret, secondSecret) -{ - "type": 13, - "amount": 0, - "fee": 10000000, - "recipientId": null, - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "timestamp": 19475744, - "asset": { - "uiaIssue": { - "currency": "IssuerName.CNY", - "amount": "100000" - } - }, - "signature": "32b01a18eca2b0dc7e2ce77ba4e758eaae2532f60844760a762cc20918e7439ac6ca585b921db6ede833ed0bf1c62e30cec545a928abafe0b679183a6ad02202", - "signSignature": "4fc290d7d7d788e9112a56233df0fe796cba39be3efa0cebf00cbc7e5bc5fd1369fad49e5698d967845b5c02e427926049cab25845d4d385e4a395791906f909" -} -``` - -### **4.6 资产转账,type=14** - -`uia.createTransfer(currency, amount, recipientId, secret, secondSecret)` -`备注` 在主链的交易类型为14 - -- `currency` 资产名字 -- `amount` 本次转账数(10000)=真实数量(10)*10**精度(3),需 <= 当前资产发行总量 -- `recipientId` 收地址,需满足前文定义好的acl规则 - -``` -var currency = 'IssuerName.CNY' -var amount = '10000' -var recipientId = 'AKKHPvQb2A119LNicCQWLZQDFxhGVEY57a' -AschJS.uia.createTransfer(currency, amount, recipientId, secret, secondSecret) -{ - "type": 14, - "amount": 0, - "fee": 10000000, - "recipientId": "AKKHPvQb2A119LNicCQWLZQDFxhGVEY57a", - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "timestamp": 19481489, - "asset": { - "uiaTransfer": { - "currency": "IssuerName.CNY", - "amount": "10000" - } - }, - "signature": "77789071a2ad6d407b9d1e0d654a9deb6d85340a3d2a13d786030e26ac773b4e9b5f052589958d2b8553ae5fc9449496946b5c225e0baa723e7ddecbd89f060a", - "signSignature": "f0d4a000aae3dd3fa48a92f792d4318e41e3b56cdbaf98649261ae34490652b87645326a432d5deb69f771c133ee4b67d2d22789197be34249e6f7f0c30c1705" -} -``` - -### **4.7 资产注销,type=11** - -`uia.createTransfer(currency, amount, recipientId, secret, secondSecret)` -`备注` 在主链的交易类型为11 - -- `currency` 资产名字 -- `flagType` 资产是否注销,1:流通,2:注销 -- `flag` flag为黑、白名单模式 - -``` -var currency = 'IssuerName.CNY' -var flagType = 2 -var flag =1 - -AschJS.uia.createFlags(currency, flagType, flag, secret, secondSecret) -{ - "type": 11, - "amount": 0, - "fee": 10000000, - "recipientId": null, - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "timestamp": 19488690, - "asset": { - "uiaFlags": { - "currency": "IssuerName.CNY", - "flagType": 2, - "flag": 1 - } - }, - "signature": "cbd656552417604704703e1236ec2bbed8eba6a2ccfcb54cc0b2d629c0a9d1335a264fc9f6dee1705f4a86c36a5ce2ba8e039d913a189b7c273c8ac0d9e3780c", - "signSignature": "3c7b91d03efeed2dc86e1f2301da60789751c1be8850460d8c66c0ae8f55ea27d26f0bc79541d74b4777d9b85c518c1c73c0284dbf3e826db0a686560e57a80b" -} -``` - -## **5 受托人delegate** -### **5.1 注册受托人,type=2** - -`delegate.createDelegate(username, secret, secondSecret)` -`备注` 在主链的交易类型为2 - -- `username` 受托人名字 -- `secret` 密码 -- `secondSecret` 二级密码 - -``` -> var userName='zhenxi' -undefined -> AschJS.delegate.createDelegate(userName, secret, secondSecret || undefined) -{ type: 2, - amount: 0, - fee: 10000000000, - recipientId: null, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - timestamp: 40568017, - asset: - { delegate: - { username: 'zhenxi', - publicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed' } }, - signature: 'e471ade7ded7785f597821f8946d4e98da5ba4331505141c5bea5ff80bbf30b649218ef03254ac703ce93e15207c8b71c69c0d1400cb5790440860ed0e51a30a', - signSignature: 'ec47d565a70e6ad075abaf1ff55c129bde9495e4cc7ab2a9404b698ef257f3b1cfd0ce4f9f1854a1bbfec0f663867823a544f80964e3be05ddf03a50a9b77d07', - id: '774ccf5e7d9d9fefa459b23d96e10ffae4bb891e1e07912ac1370af04192e810' } -``` - -### **5.2 给受托人增加/取消投票,type=3** - -`vote.createVote(keyList, secret, secondSecret)` -`备注` 在主链的交易类型为3 - -- `keyList` 受托人公钥列表 -- `secret` 密码 -- `secondSecret` 二级密码 - -``` -// 投票内容是一个列表,列表中的每一个元素是一个符号加上所选择的受托人的公钥,符号为+表示投票,符号为-表示取消投票 -> var voteContent = [ -... '-ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7', -... '+c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2' -... ]; -undefined - -> transaction=AschJS.vote.createVote(voteContent, secret, secondSecret || undefined); -{ type: 3, - amount: 0, - fee: 10000000, - recipientId: null, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - timestamp: 40568669, - asset: { vote: { votes: [Array] } }, - signature: '66f6f3c4fbb8545df53ea35ff655fc1a28815591885757d0b735e77ed348caf33d8d9cb2895f85cd40bf2d3b4633f45a19ebd1dd130233305a603304a92ce003', - signSignature: 'c026d373e026b524efd82ad1ab046708ee1ff68573f016490d12908f5ad00a97fa7501f46834c94f6dd64afd00aa77f9d29ded087977ac6601778d4aacb5cd0e', - id: '0789524787384e2e4da7773afdd3871193a67303c4da69c4a9070eaa5676d36c' } - -> transaction.asset.vote.votes -[ '-ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7', - '+c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2' ] - -``` - - -## **6 dapp相关** - -### **6.1 dapp注册,type=5** - -`dapp.createDApp(options, secret, secondSecret)` -`备注` 在主链的交易类型为5 - -- `options` dapp的基本属性,如名字、url、icon、预置的受托人公钥、dapp类型、dapp tag等信息 -- `secret` 密码 -- `secondSecret` 二级密码 - -``` -> var options = { name: 'asch-dapp-cctime', -... link: 'https://github.com/AschPlatform/asch-dapp-cctime/archive/master.zip', -... category: 1, -... description: 'Decentralized news channel', -... tags: 'asch,dapp,demo,cctime', -... icon: 'http://o7dyh3w0x.bkt.clouddn.com/hello.png', -... type: 0, -... delegates: -... [ '8b1c24a0b9ba9b9ccf5e35d0c848d582a2a22cca54d42de8ac7b2412e7dc63d4', -... 'aa7dcc3afd151a549e826753b0547c90e61b022adb26938177904a73fc4fee36', -... 'e29c75979ac834b871ce58dc52a6f604f8f565dea2b8925705883b8c001fe8ce', -... '55ad778a8ff0ce4c25cb7a45735c9e55cf1daca110cfddee30e789cb07c8c9f3', -... '982076258caab20f06feddc94b95ace89a2862f36fea73fa007916ab97e5946a' ], -... unlockDelegates: 3 }; -undefined - -> trs=AschJS.dapp.createDApp(options, secret); -{ type: 5, - amount: 0, - fee: 10000000000, - recipientId: null, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - timestamp: 40572296, - asset: - { dapp: - { category: 1, - name: 'asch-dapp-cctime', - description: 'Decentralized news channel', - tags: 'asch,dapp,demo,cctime', - type: 0, - link: 'https://github.com/AschPlatform/asch-dapp-cctime/archive/master.zip', - icon: 'http://o7dyh3w0x.bkt.clouddn.com/hello.png', - delegates: [Array], - unlockDelegates: 3 } }, - signature: '5a8e2dba5e14b4ec62ce1b8543de2796d3cded249ed899c5049dd0adeff00963dd40436e7cfc6f9952e09d5c6ac8f5144d3e568f263586520c68012d3c7ca509', - id: 'ecf9366a128408b843f0e6b2bd7261a4d602c32ae36a8c3cef609e904f180735' } -> trs.asset.dapp.delegates -[ '8b1c24a0b9ba9b9ccf5e35d0c848d582a2a22cca54d42de8ac7b2412e7dc63d4', - 'aa7dcc3afd151a549e826753b0547c90e61b022adb26938177904a73fc4fee36', - 'e29c75979ac834b871ce58dc52a6f604f8f565dea2b8925705883b8c001fe8ce', - '55ad778a8ff0ce4c25cb7a45735c9e55cf1daca110cfddee30e789cb07c8c9f3', - '982076258caab20f06feddc94b95ace89a2862f36fea73fa007916ab97e5946a' ] -``` - -### **6.2 dapp充值,type=6** - -`transfer.createInTransfer(dappid, currency, amount, secret, secondSecret);` -`备注` 在主链的交易类型为6 - -- `dappid` dapp的id -- `currency` 充值的资产名 -- `amount` 充值的数量 - -``` -var dappid = "bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024"; -var currency = "XAS"; -var amount = 10*100000000 ; - -> AschJS.transfer.createInTransfer(dappid, currency, amount, secret, secondSecret || undefined); -{ type: 6, - amount: 1000000000, - fee: 10000000, - recipientId: null, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - timestamp: 40578327, - asset: - { inTransfer: - { dappId: 'bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024', - currency: 'XAS' } }, - signature: '6907c1402c702e0fd504a8734a047c1bb216d437e65d5675325846b92ef8b916fc634ea7e33a7c72c60c058d1496d0385c95e39a8291e27b2dceb2f40b6aed02', - signSignature: '86de438431c639124a13429e8c6a8c13a5cbbbab3a8323ae08b56f65faeff6d816815d7cdecfdb7287077b14e4d14865637efc9d7fd72d085b0aa9d82f27170c', - id: '25be71c296430a409cfeaf1ffaa957d18793f3695db07a846c22a7c467c45994' } -``` - -### **6.3 dapp内部合约调用** - -`dapp.createInnerTransaction(options, secret)` - -- `options` 合约相关的选项,如手续费、合约编号、合约字符串数组参数 -- `secret` 密码 - -自定如下全局变量,用于下面子章节代码演示。 - -``` -> var fee = String(0.1 * 100000000); // 目前dapp内置合约调用的手续费统一为10000000 对应的资产 -``` - -#### **6.3.1 dapp提现,合约type=2** - -`args` '["资产名字","提现数额"]' - -``` -> var type = 2; // 这里的type指的是合约标号,而非主链的交易类型 -> var options = {fee: fee, type: type, args: '["CCTime.XCT", "100000000"]'}; - -> AschJS.dapp.createInnerTransaction(options, secret); -{ fee: '10000000', - timestamp: 40572732, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - type: 2, - args: '["CCTime.XCT", "100000000"]', - signature: 'a0d860a0c13cf40d6be08f42a66bf01264f96fadc8ed2997139c583ba7fcd5e7ceeda9207c635215ddfd60bde8c35914cdfe2b03a4862cdd187b9142d497c301' } -``` - -#### **6.3.2 dapp内部转账,合约type=3** - -`args` '["资产名字","转账数额","接收地址"]' - -``` -> var type = 3; -> var options = {fee: fee, type: type, args: '["CCTime.XCT", "100000000", "A6H9rawJ7qvE2rKwQfdtBHdeYVehB8gFzC"]'}; - -> AschJS.dapp.createInnerTransaction(options, secret); -{ fee: '10000000', - timestamp: 40573272, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - type: 3, - args: '["CCTime.XCT", "100000000", "A6H9rawJ7qvE2rKwQfdtBHdeYVehB8gFzC"]', - signature: '3843bef77ad7c6f2b57083270055720186b8ba286cd44e263028eef9b8650ecf6d243c1861f9b9416e123b594695934430deb0f5146a173ebfcdccb6915acf0c' } - -``` - -#### **6.3.4 dapp内设置昵称,合约type=3** - -`args` '["昵称"]' - -``` -> var type = 4; -> var options = {fee: fee, type: type, args: '["nicheng"]'}; - -> AschJS.dapp.createInnerTransaction(options, secret); -{ fee: '10000000', - timestamp: 40573343, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - type: 4, - args: '["nicheng"]', - signature: '172998ddbb2ef72037be673d658dbc64760da307d451257666c956868b142707cd4aa38668b52d1d0d7cc62c01866daef2bae8d427844194d42ca9fea97ea70b' } -``` - -### **6.4 dapp提现** -#### **6.4.1 创建提现交易,type=7** - -`transfer.createOutTransfer(recipientId, dappId, transactionId, currency, amount, secret, secondSecret)` -`备注` 在主链的交易类型为7,该接口一般由dapp受托人来调用(受托人每隔10秒扫描侧链上由智能合约所创建的提现交易,发现后则在主链创建type=7的提现交易),所以一般情况下开发人员用不到。 - -- `recipientId` 提现接收者id -- `dappId` dapp id -- `transactionId` 提现交易id,该交易id是编号为2的智能合约在侧链dapp上所创建的 -- `currency` 提现资产名(XAS或者UIA) -- `amount` 提现数额 - -``` -let recipientId = 'AFUH568CbGC2GPcE4gXHiZhxdYQYfziz2J'; -let dappId = 'bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024'; -let transactionId = '123b04a6e380500903d8942622d57987661e72b2ae95464066d0af3f02c3c691'; -let currency = 'XAS' -let amount = '10000000' - -> transaction = AschJS.transfer.createOutTransfer(recipientId, dappId, transactionId, currency, amount, secret, secondSecret); -{ type: 7, - amount: 0, - fee: 10000000, - recipientId: 'AFUH568CbGC2GPcE4gXHiZhxdYQYfziz2J', - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - timestamp: 40668981, - asset: - { outTransfer: - { dappId: 'bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024', - transactionId: '123b04a6e380500903d8942622d57987661e72b2ae95464066d0af3f02c3c691', - currency: 'XAS', - amount: '10000000' } }, - signature: '432d25e5c5b81fa3a5937adca2dd4a1e2a38e51f8896838601902e0c123a5ccb664bbc8a55344b9fedb773da98e0988e4e8d1ca99dcbc51a80ea3bc9a6b61806', - signSignature: '8154c1f8305b9b957974e778de1e08dd3f08afcb70f27624d1385dbae9dfa6d0a3aaed6211ed8a40f4015f7e47312f0f205d94518c68e4deec8d76567f56f10f', - id: '237925a60ccc0abfc1494720aab8c11c74ba61e8ab3ca4bd8ded8c3215c201a7' } - -``` - -#### **6.4.2 受托人对提现交易进行签名** - -`transfer.signOutTransfer(transaction, secret)` -`备注` dapp提现交易,需要多个受托人签名后才能生效。受托人签名的最小数量取决于dapp的注册参数:unlockDelegates。受托人每隔10秒扫描侧链上由智能合约所创建的提现交易,发现有交易且签名个数未满足时,会对其进行签名。一般情况下普通开发人员用不到。 - -- `transaction` transfer.createOutTransfer生成的提现交易 -- `secret` 受托人密码 - -``` -// 沿用上一章节《6.4.1 创建提现交易,type=7》的变量 -transaction.signatures = [] // 受托人签名列表 - -// 第1个受托人对提现交易transaction进行签名 -delegate1_secret = 'chalk flame jeans rebuild dutch stone abstract capital lucky pottery raven depend' -> signature1 = AschJS.transfer.signOutTransfer(transaction,delegate1_secret); -'ac0ea4c10b911f2134e5adfb3535ffc070ffa8f2858a5a1bc4e9bef442863e117e6bce552bba0d5b0160c4076dd3c657ebc33cbe077a8ef719798a8bb0fac30c' -transaction.signatures.push(signature1) // 将签名加入到transaction的签名列表中 -// 第2个受托人对提现交易transaction进行签名 -delegate2_secret = 'twist arrange matter twice daughter cave cause never enough scare warfare uncover' -> signature2 = AschJS.transfer.signOutTransfer(transaction,delegate2_secret); -'480e0717e4be02e48a27e2323bf6507c4c72d1033b4e7e674651e9e4feced17836f0b81b91ade99b61620a2766ecc901f090d81cc72d22b86807ae981eb2d10c' -transaction.signatures.push(signature2) // 将签名加入到transaction的签名列表中 -// 依次类推,多个受托人都对该交易进行签名,当满足最小签名个数时,该提现交易才会真正生效 -> transaction -{ type: 7, - amount: 0, - fee: 10000000, - recipientId: 'AFUH568CbGC2GPcE4gXHiZhxdYQYfziz2J', - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - timestamp: 40669013, - asset: - { outTransfer: - { dappId: 'bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024', - transactionId: '123b04a6e380500903d8942622d57987661e72b2ae95464066d0af3f02c3c691', - currency: 'XAS', - amount: '10000000' } }, - signature: '1dfae733408d374cd7be5f4b55183c0c05dc31341f93daaf82c26c80ab11035202502180dd78c5643edcd3bb481a38f352408bc35e44e6c1c53c95612fbca804', - signSignature: '8f4f7aa06c02c0a3d637329e1a3b23489b91797b9f3477afd4314b2f78d1e8e8a369a640d75916bd9477e69363cf440c27124db615dced1701a1a934714afe05', - id: '95a0c4ac9d5397452629b89410413f54ed37caee84a13edf3c9c26d3d0606dab', - signatures: - [ 'ac0ea4c10b911f2134e5adfb3535ffc070ffa8f2858a5a1bc4e9bef442863e117e6bce552bba0d5b0160c4076dd3c657ebc33cbe077a8ef719798a8bb0fac30c', - '480e0717e4be02e48a27e2323bf6507c4c72d1033b4e7e674651e9e4feced17836f0b81b91ade99b61620a2766ecc901f090d81cc72d22b86807ae981eb2d10c' ] // 受托人签名数组 - } -``` - - -## **7 存储storage** - -### **7.1 创建存储交易,type=8** - -`storage.createStorage(content, secret, secondSecret)` -`备注` 在主链的交易类型为8 - -- `content` - - -``` -> var content = new Buffer('helloworld').toString('hex') -> AschJS.storage.createStorage(content, secret, secondSecret) -{ type: 8, - amount: 0, - fee: 10000000, - recipientId: null, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - timestamp: 40578932, - asset: { storage: { content: '68656c6c6f776f726c64' } }, - signature: 'd7f3f29549542d6716bdb13e8e1f97e3965c6fbe34f1ee18dbdcad7ba9cbf83ee7cb2b7fcbaab5ffed5d569771731bb5a40efc4fabd142cb30becdad8bc8bb06', - signSignature: '38315bf369540cc7a793139b1b6195f4c0e1512514d62bf028d454182a4b7a8912c1b1e6f617f6fb4ff8d80bd141a2ebb9dfcaa8fee68cfc81f8872611bba803', - id: '4d0b04a6e380500903d8942622d57987661e72b2ae95464066d0af3f02c3c691' } -``` - -## **8 签名验证相关crypto** - -自定义如下已签名的转账交易内容(在主链给16358246403719868041转账100XAS),用于下面章节演示。 -``` -> var targetAddress = "16358246403719868041"; -> var amount = 100*100000000; //100 XAS -> var message = 'beizhu'; -> transaction = AschJS.transaction.createTransaction(targetAddress, amount, message, secret, secondSecret) -{ type: 0, - amount: 10000000000, - fee: 10000000, - recipientId: '16358246403719868041', - message: 'beizhu', - timestamp: 40566970, - asset: {}, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - signature: '9bef374be100fcfec59d245af59e5646ba5dcb79c6f1399ddd676a617542eeb45cc363822b84410e379f0caa501c25b66e59142353c04d23d1cb95cf64cef306', - signSignature: '513e3efdbb65f8e60e85ca98d8d065ec9bd3bfa6f45a1f48cfade9c94d410338ee64bd55938c168b10f0749335c050312785dbf08882ffd0e40a65fde8c2b10b', - id: '871554a8346d84cab2147324706d8ab5494fde928a7463a68d536ed6c0357897' } -``` - -### **8.1 根据交易内容获取字节Buffer对象** - -`getBytes(transaction, skipSignature, skipSecondSignature)` - -- `transaction` 交易内容,可以是签名后也可是未签名的,默认需传入签名后的交易。必传参数 -- `skipSignature` 是否跳过签名计算,默认不跳过。非必传参数 -- `skipSecondSignature` 是否跳过二级密码签名计算,默认不跳过。非必传参数 - -``` -// 此时transaction.signature和transaction.signSignature都会计算在内 -> AschJS.crypto.getBytes(transaction) - // 返回的字节buffer对象 -``` - -### **8.2 根据交易内容获取Hash Buffer对象** - -`getHash(transaction, skipSignature, skipSecondSignature)` - -- `transaction` 交易内容,可以是签名后也可是未签名的,默认需传入签名后的交易。必传参数 -- `skipSignature` 是否跳过签名计算,默认不跳过。非必传参数 -- `skipSecondSignature` 是否跳过二级密码签名计算,默认不跳过。非必传参数 - -``` -// 此时transaction.signature和transaction.signSignature都会计算在内 -> AschJS.crypto.getHash(transaction) - // 返回的Hash Buffer -``` - -### **8.3 根据交易内容获取交易id** - -`crypto.getId(transaction)` - -- `transaction` 签名后的交易内容 - -``` -> AschJS.crypto.getId(transaction) -'871554a8346d84cab2147324706d8ab5494fde928a7463a68d536ed6c0357897' // 返回结果,交易id - -``` - -### **8.4 对交易Bytes Buffer进行签名** - -`crypto.signBytes(bytes, keys)` - -- `bytes` 交易的Bytes Buffer,未签名交易或者一级密码签名但二级密码未签名的交易 -- `keys` 公钥/私钥 密钥对 - -``` -// 定义未签名交易 -> var trs = { type: 0, -... amount: 10000000000, -... fee: 10000000, -... recipientId: '16358246403719868041', -... message: 'beizhu', -... timestamp: 40566970, -... asset: {}} - -// 根据密码,生成 -> keys = AschJS.crypto.getKeys(secret) -{ publicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - privateKey: '7ae536fa343281d9e9ed383e8b5ef62e0fd0d0cbed79786cac241d484e312fdeebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed' } - -> trs.senderPublicKey = keys.publicKey; -'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed' - -// 获取交易的Bytes Buffer -> buf = AschJS.crypto.getBytes(trs) - -// 通过私钥对交易Bytes Buffer进行签名 -> signature = AschJS.crypto.signBytes(buf,keys) -'9bef374be100fcfec59d245af59e5646ba5dcb79c6f1399ddd676a617542eeb45cc363822b84410e379f0caa501c25b66e59142353c04d23d1cb95cf64cef306' // 返回值与上面自定义的已签名交易中的签名一致 - -``` - -### **8.5 验证交易签名是否和已存在的签名一致** - -`crypto.verifyBytes(bytes, signature, publicKey)` 返回true/false - -- `bytes` 交易的Bytes Buffer,未签名交易或者一级密码签名但二级密码未签名的交易 -- `signature` 待校验的签名 -- `publicKey` 签名者公钥 - -``` -// 沿用上一章节《对交易Bytes Buffer进行签名》的变量 -> AschJS.crypto.verifyBytes(buf,transaction.signature,transaction.senderPublicKey) -true // 本章最上面自定义的transaction签名一致 -``` - -## **9 其它** - -### **9.1 全局参数变量options** - -#### **9.1.1 设置变量k/v** -`options.set(key, values)` - -- `key` 键名 -- `value` 键值 - -``` -> AschJS.options.set('secret','minor borrow display rebel depart core buzz right distance avocado immense push') -undefined - -``` - - -#### **9.1.2 根据key获取value** - -`options.get(key)` - -- `key` 键名 - -``` -> AschJS.options.get('secret') -'minor borrow display rebel depart core buzz right distance avocado immense push' - -``` - - -#### **9.1.3 获取所有的k/v** - -`options.getAll()` - -``` -> AschJS.options.getAll() -{ clientDriftSeconds: 5, // asch-js内置变量 - secret: 'minor borrow display rebel depart core buzz right distance avocado immense push' } - -``` - -### **9.2 时间相关slot.time** - -#### **9.2.1 asch主网创世块生成时间** - -`utils.slots.beginEpochTime()` -`备注` 结果为UTC时间,即Asch纪元的开始时间。 - -``` -> AschJS.utils.slots.beginEpochTime() -2016-06-27T20:00:00.000Z // Asch主网创世块生成时间,但主网正式运行是在8月16号那天(主网正式运行的标志是 生成了block heihgt=2的区块) -``` - - -#### **9.2.2 根据unix时间戳获获Asch时间戳** - -`utils.slots.getTime(time)` -`备注` 获得结果叫做EpochTim(Asch时间戳),传入的time相对于Asch纪元经历的秒数 - -- `time` 如果不传值则取当前时刻的 Unix时间戳*1000 (即单位是毫秒) - -``` -> AschJS.utils.slots.getTime() -40655681 // Asch时间戳 - -> unix_timestamp = 1507713496 -> epochTime = AschJS.utils.slots.getTime(unix_timestamp * 1000) -40655896 // Asch时间戳 - -``` - -#### **9.2.3 根据Asch时间戳获取unix时间戳** - -`utils.slots.getRealTime(epochTime)` -`备注` 返回结果是真实的 unix时间戳* 1000 - -- `epochTime` Asch时间戳,单位是秒 - -``` -> unix_timestamp = 1507713496 // unix时间戳 -> epochTime = AschJS.utils.slots.getTime(unix_timestamp * 1000) -40655896 // 通过unix时间戳获取到asch时间戳 -> real_time = AschJS.utils.slots.getRealTime(epochTime) -1507713496000 // 通过asch时间戳获取unix时间戳 - -> unix_timestamp === real_time/1000 -true // 换算结果一致 -``` - - diff --git a/docs/asch_js_api_en.md b/docs/asch_js_api_en.md deleted file mode 100644 index 2ad7f6d..0000000 --- a/docs/asch_js_api_en.md +++ /dev/null @@ -1,1042 +0,0 @@ -Table of Contents -================= - -- [Asch-JS API](#asch-js-api) - - [**1 Asch-js description**](#1-asch-js-description) - - [**1.1 asch-js installation**](#11-asch-js-installation) - - [**1.2 description**](#12-description) - - [**2 Account**](#2-account) - - [**2.1 Get keypairs from secret**](#21-get-keypairs-from-secret) - - [**2.1 Get address from public key**](#21-get-address-from-public-key) - - [**2.3 Set second secret, type=1**](#23-set-second-secret-type1) - - [**2.4 Lock account,type=100**](#24-lock-accounttype100) - - [**3 Ordinary transactions**](#3-ordinary-transactions) - - [**3.1 Transfer XAS in the main-chain, type=0**](#31-transfer-xas-in-the-main-chain-type0) - - [**3.2 Get TransactionId from Transaction**](#32-get-transactionid-from-transaction) - - [**4 Asset related UIA**](#4-asset-related-uia) - - [**4.1 Asset publisher registration,type=9**](#41-asset-publisher-registrationtype9) - - [**4.2 Asset registration, type=10**](#42-asset-registration-type10) - - [**4.3 Asset set Access control list (acl), type=11**](#43-asset-set-access-control-list-acl-type11) - - [**4.4 Update access control list(acl), type=12**](#44-update-access-control-listacl-type12) - - [**4.5 Asset distribution, type=13**](#45-asset-distribution-type13) - - [**4.6 Asset transfer, type=14**](#46-asset-transfer-type14) - - [**4.7 Asset write-off, type=11**](#47-asset-write-off-type11) - - [**5 Delegate**](#5-delegate) - - [**5.1 Registere delegate, type=2**](#51-registere-delegate-type2) - - [**5.2 Vote or cancel vote for delegate, type=3**](#52-vote-or-cancel-vote-for-delegate-type3) - - [**6 Dapp**](#6-dapp) - - [**6.1 Dapp registration, type=5**](#61-dapp-registration-type5) - - [**6.2 Dapp recharge, type=6**](#62-dapp-recharge-type6) - - [**6.3 Dapp internal contract call**](#63-dapp-internal-contract-call) - - [**6.3.1 Dapp cash, contract type=2**](#631-dapp-cash-contract-type2) - - [**6.3.2 Dapp internal transfer, contract type=3**](#632-dapp-internal-transfer-contract-type3) - - [**6.3.4 Set a dapp nickname, contract type=3**](#634-set-a-dapp-nickname-contract-type3) - - [**6.4 Dapp withdraw**](#64-dapp-withdraw) - - [**6.4.1 Create a cash transaction, type=7**](#641-create-a-cash-transaction-type7) - - [**6.4.2 The delegate signs the cash transaction**](#642-the-delegate-signs-the-cash-transaction) - - [**7 Storage**](#7-storage) - - [**7.1 Create a storage transaction,type=8**](#71-create-a-storage-transactiontype8) - - [**8 Related to signature verification, crypto**](#8-related-to-signature-verification-crypto) - - [**8.1 Get transaction bytes**](#81-get-transaction-bytes) - - [**8.2 Get Transaction Hash**](#82-get-transaction-hash) - - [**8.3 Get transaction id based on transaction content**](#83-get-transaction-id-based-on-transaction-content) - - [**8.4 Sign the transaction bytes**](#84-sign-the-transaction-bytes) - - [**8.5 Verify that the transaction signature is consistent with the existing signature**](#85-verify-that-the-transaction-signature-is-consistent-with-the-existing-signature) - - [**9 Miscellaneous**](#9-miscellaneous) - - [**9.1 Global parameters**](#91-global-parameters) - - [**9.1.1 Set the variable k/v**](#911-set-the-variable-kv) - - [**9.1.2 According to the key for value**](#912-according-to-the-key-for-value) - - [**9.1.3 Get all k/v**](#913-get-all-kv) - - [**9.2 Time related slot.time**](#92-time-related-slottime) - - [**9.2.1 Asch main network creation block generation time**](#921-asch-main-network-creation-block-generation-time) - - [**9.2.2 Get Asch timestamp based on unix timestamp**](#922-get-asch-timestamp-based-on-unix-timestamp) - - [**9.2.3 Get the unix timestamp based on the Asch timestamp**](#923-get-the-unix-timestamp-based-on-the-asch-timestamp) - - -Created by [Markdown-Toc](https://github.com/AlanWalk/Markdown-TOC) - -# Asch-JS API - - -## **1 Asch-js description** - -### **1.1 asch-js installation** - -``` -npm install asch-js -var AschJS = require('asch-js'); -``` - -### **1.2 description** -Many functions need to receive a password or optionally a second password. - -- `secret` password -- `publicKey` public key -- `secondSecret` second password - -```js -var secret = 'minor borrow display rebel depart core buzz right distance avocado immense push' -var publicKey = 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed'; -var secondSecret = 'erjimima2017'; -``` - -The generated transaction data (in json format) needs to be send to a http api -- The main chain transaction passed `POST /peer/transactions` -- Dapp transaction passed `PUT /api/dapps/dappID/transactions/signed` - - -## **2 Account** - -### **2.1 Get keypairs from secret** - -`crypto.getKeys(secret)` - -- `secret` password - -```js -AschJS.crypto.getKeys(secret) -{ - publicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - privateKey: '7ae536fa343281d9e9ed383e8b5ef62e0fd0d0cbed79786cac241d484e312fdeebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed' -} -``` - -### **2.1 Get address from public key** - -`crypto.getAddress(publicKey)` - -- `publicKey` public key - -```js -AschJS.crypto.getAddress(publicKey); -'AFUH568CbGC2GPcE4gXHiZhxdYQYfziz2J' -``` - -### **2.3 Set second secret, type=1** - -`crypto.signature.createSignature(secret, secondSecret)` -`remarks` The transaction-type in the main chain for this operation is 1 - -- `secret` password -- `secondSecret` second password - -```js -AschJS.signature.createSignature(secret, secondSecret) -{ - type: 1, - amount: 0, - fee: 500000000, - recipientId: null, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - timestamp: 40566038, - asset: { - signature: { - publicKey: '632a41caf7d3c8d3754f27a11004acaea6f5571eed28b42451b5560ee91e991c' - } - }, - signature: 'ee42f4dc17ace4f76f86fba93c7d86b61a69de46ac96e102e9f93668c8cdd9e6281821c63cb3e0c23099968cccdcfd0197aaab42afba4a98fa696c17b133be06', - id: '2237134c11b3cbaa9b7951f4afd47454ca04af2c7c6a030729ec63f75230e9ad' -} -``` - -### **2.4 Lock account, type=100** - -`transaction.createLock(height, secret, secondSecret)` -`remarks` The transaction-type in the main chain for this operation is 100 - -- `height` The block height at which the account should be locked -- `secret` password -- `secondSecret` second password - -```js -AschJS.transaction.createLock(8130, secret, secondSecret) -{ - type: 100, - amount: 0, - fee: 10000000, - recipientId: null, - args: [ '8130' ], - timestamp: 40566287, - asset: {}, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - signature: '06f6852d0e2e56ca441fa60b407aaa2197290ff096558c746c9c8bcdc971b8c4065ec08edd49c7292eca51849c16c5b8f0d33bb4ce972a932603dcf46a391e0e', - signSignature: '3b645b0f6a2c597c55595669a856489c0c4f3a132c798c615b8e0241f3169a367edea7228ebc8915d5fd7a0571cc08c971d07520b9908c80c9b2c2c76ada5e07', - id: 'c87d93af84939076a65a49c3b483897d262edc340b2d4184a4d2505b58711a91' -} -``` - -## **3 Ordinary transactions** - -### **3.1 Transfer XAS in the main-chain, type=0** - -`transaction.createTransaction(recipientId, amount, message, secret, secondSecret)` -`remark` The transaction-type in the main chain for this operation is 0 - -- `recipientId` Receiver address -- `amount` Transfer amount -- `message` Transfer postscript -- `secret` Password -- `secondSecret` Second password - -```js -var targetAddress = "16358246403719868041"; -undefined -var amount = 100*100000000; //100 XAS -undefined -var message = 'beizhu'; -undefined -AschJS.transaction.createTransaction(targetAddress, amount, message, secret, secondSecret) -{ - type: 0, - amount: 10000000000, - fee: 10000000, - recipientId: '16358246403719868041', - message: 'beizhu', - timestamp: 40566970, - asset: {}, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - signature: '9bef374be100fcfec59d245af59e5646ba5dcb79c6f1399ddd676a617542eeb45cc363822b84410e379f0caa501c25b66e59142353c04d23d1cb95cf64cef306', - signSignature: '513e3efdbb65f8e60e85ca98d8d065ec9bd3bfa6f45a1f48cfade9c94d410338ee64bd55938c168b10f0749335c050312785dbf08882ffd0e40a65fde8c2b10b', - id: '871554a8346d84cab2147324706d8ab5494fde928a7463a68d536ed6c0357897' -} -``` - -### **3.2 Get TransactionId from Transaction** - -`crypto.getId(transaction)` - -- `transaction` Content of signed transaction - -```js -var targetAddress = "16358246403719868041"; -var amount = 100*100000000; //100 XAS -var message = 'beizhu'; -transaction = AschJS.transaction.createTransaction(targetAddress, amount, message, secret, secondSecret) -{ - type: 0, - amount: 10000000000, - fee: 10000000, - recipientId: '16358246403719868041', - message: 'beizhu', - timestamp: 40566970, - asset: {}, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - signature: '9bef374be100fcfec59d245af59e5646ba5dcb79c6f1399ddd676a617542eeb45cc363822b84410e379f0caa501c25b66e59142353c04d23d1cb95cf64cef306', - signSignature: '513e3efdbb65f8e60e85ca98d8d065ec9bd3bfa6f45a1f48cfade9c94d410338ee64bd55938c168b10f0749335c050312785dbf08882ffd0e40a65fde8c2b10b', - id: '871554a8346d84cab2147324706d8ab5494fde928a7463a68d536ed6c0357897' -} - -AschJS.crypto.getId(transaction) -'871554a8346d84cab2147324706d8ab5494fde928a7463a68d536ed6c0357897' // Return result, transaction id -``` - - -## **4 Asset related UIA** - -### **4.1 Asset publisher registration,type=9** - -`uia.createIssuer(name, desc, secret, secondSecret)` -`remark` The transaction-type in the main chain for this operation is 9 - -- `name` Asset publisher name -- `desc` Assset publisher description - -```js -var name = 'IssuerName' -var desc = 'IssuerDesc' -AschJS.uia.createIssuer(name, desc, secret, secondSecret) -{ - "type": 9, - "amount": 0, - "fee": 10000000, - "recipientId": null, - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "timestamp": 19395607, - "asset": { - "uiaIssuer": { - "name": "IssuerName", - "desc": "IssuerDesc" - } - }, - "signature": "c6ed2a4bafe2b8aa31f4aaceacc2a96cb028abbabb2ed062937498c58e24ca5467a340ddd63b67f809a680ff91b83e685c64991eb695494ddb2fdc57e5761607", - "signSignature": "8eceacbd47c2b8ed335145ced19d7a3a51f99bdd6631d16ed214180c6f80e29bd6d572f45e7c7d685584e55cb5c303cf340406553ece28c9c0a2fa7a777aac0b" -} -``` - - - -### **4.2 Asset registration, type=10** - -`uia.createAsset(name, desc, maximum , precision, strategy, secret, secondSecret)` -`remark` The transaction-type in the main chain for this operation is 10 - -- `name` The name of the asset, has the following format: issuer name, asset name (this is the unique identifier for the asset) -- `desc` Asset description -- `maximum` The maximum quantity of assets that can be issued -- `precision` Precision in decimal places, the upper limit is 1000000, the accuracy of 3, representing the maximum issuance of assets IssuerName.CNY 1000.000 -- `strategy` Issue strategy, if not set then the default is 10% every 10 years - -```js -var name = 'IssuerName.CNY' -var desc = 'Asset description' -var maximum = '1000000' -var precision = 3 -var strategy = '' - -AschJS.uia.createAsset(name, desc, maximum, precision, strategy, secret, secondSecret) -{ - "type": 10, - "amount": 0, - "fee": 10000000, - "recipientId": null, - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "timestamp": 19397444, - "asset": { - "uiaAsset": { - "name": "IssuerName.CNY", - "desc": "Asset description", - "maximum": "1000000", - "precision": 3, - "strategy": "" - } - }, - "signature": "c755587d331dd2eb62ef91dce1511d83a3e603c7cdc7548a16052519c21ea89c78364e35e5d46da0e2103fa2fb7f037eec55a5deba18826fa13e4252422d750e", - "signSignature": "1b7ed4c21c477b8ff3d2acfdfd7ff85617093f4c21de70938c46b61c9704b037dbcf7f9e5f5dd1a5dc8f22cf473aaa459e6e5b15ced388b8a1da1e307987a509" -} -``` - - - -### **4.3 Asset set Access control list (acl), type=11** - -`uia.createFlags(currency, flagType, flag, secret, secondSecret)` -`remark` The transaction-type in the main chain for this operation is 11 - -- `currency` Asset name -- `flagType` Whether the assets write-off, 1: circulation, 2: cancellation -- `flag` Access control list type, 0: blacklist, 1: whitelist, default to blacklist mode after assets are created - -```js -var currency = 'IssuerName.CNY' -var flagType = 1 -var flag = 1 - -AschJS.uia.createFlags(currency, flagType, flag, secret, secondSecret) -{ - "type": 11, - "amount": 0, - "fee": 10000000, - "recipientId": null, - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "timestamp": 19400996, - "asset": { - "uiaFlags": { - "currency": "IssuerName.CNY", - "flagType": 1, - "flag": 1 - } - }, - "signature": "b96fb3d1456e1f26357109cc24d82834eb9a4687f29e69c374bbb1d534568336e148cac52f213aa4d2a69185092f8e1143b49ec4b8048cd9b3af4e20f6ba0b08", - "signSignature": "b37c77ebebe90341346be2aefe1e12bd7403e5d8f4d6e8f04630190b3e09494a28820da0ffd5f9ff011033aa6d70fc9bb4c159a4493be3b18fd7ff470103570d" -} -``` - -### **4.4 Update access control list(acl), type=12** - -`uia.createAcl(currency, operator, flag, list, secret, secondSecret)` -`remark` The transaction-type in the main chain for this operation is 12 - -- `currency` Asset name -- `operator` Operator '+' means adding something to the list, '-' means deleting from the list -- `flag` Access control list types, 0: blacklist, 1: whitelist, default flag is blacklist after assets are created -- `list` A list of address that should be updated - -```js -var currency = 'IssuerName.CNY' -var operator = '+' -var list = ['15745540293890213312'] -var flag = 1 - -AschJS.uia.createAcl(currency, operator, flag, list, secret, secondSecret) -{ - "type": 12, - "amount": 0, - "fee": 20000000, - "recipientId": null, - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "timestamp": 19403125, - "asset": { - "uiaAcl": { - "currency": "IssuerName.CNY", - "operator": "+", - "flag": 1, - "list": ["15745540293890213312"] - } - }, - "signature": "ad4060e04c1a12256de114e34499f8add24326753f1f8362991ee14aefc4c0fe90ff394d2db97e83770855a5688d463de00656fdd2d04604605cf3c04fdaca0e", - "signSignature": "63129c58b1b9fcce88cbe829f3104a10ab06037253e9b65feb50ce0d2bb988533b93e8edcad016a85675f9027758fc318cf899ca7ef161a95a8d8a055ae83a02" -} -``` - -### **4.5 Asset distribution, type=13** - -`uia.createIssue(currency, amount, secret, secondSecret)` -`remark` The transaction-type in the main chain for this operation is 13 - -- `currency` Asset name -- `amount` This Issue = Actual Quantity (100) * 10 ** Accuracy (3), and Sum of All Circulations <= Upper Limit * Accuracy - -```js -var currency = 'IssuerName.CNY' -var amount = '100000' - -AschJS.uia.createIssue(currency, amount, secret, secondSecret) -{ - "type": 13, - "amount": 0, - "fee": 10000000, - "recipientId": null, - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "timestamp": 19475744, - "asset": { - "uiaIssue": { - "currency": "IssuerName.CNY", - "amount": "100000" - } - }, - "signature": "32b01a18eca2b0dc7e2ce77ba4e758eaae2532f60844760a762cc20918e7439ac6ca585b921db6ede833ed0bf1c62e30cec545a928abafe0b679183a6ad02202", - "signSignature": "4fc290d7d7d788e9112a56233df0fe796cba39be3efa0cebf00cbc7e5bc5fd1369fad49e5698d967845b5c02e427926049cab25845d4d385e4a395791906f909" -} -``` - -### **4.6 Asset transfer, type=14** - -`uia.createTransfer(currency, amount, recipientId, secret, secondSecret)` -`remark` The transaction-type in the main chain for this operation is 14 - -- `currency` Asset name -- `amount` The number of transfer (10000) = true number (10) * 10 ** accuracy (3), required <= the current total assets issued -- `recipientId` Receive address, to meet the above definition of the acl rules - -```js -var currency = 'IssuerName.CNY' -var amount = '10000' -var recipientId = 'AKKHPvQb2A119LNicCQWLZQDFxhGVEY57a' -AschJS.uia.createTransfer(currency, amount, recipientId, secret, secondSecret) -{ - "type": 14, - "amount": 0, - "fee": 10000000, - "recipientId": "AKKHPvQb2A119LNicCQWLZQDFxhGVEY57a", - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "timestamp": 19481489, - "asset": { - "uiaTransfer": { - "currency": "IssuerName.CNY", - "amount": "10000" - } - }, - "signature": "77789071a2ad6d407b9d1e0d654a9deb6d85340a3d2a13d786030e26ac773b4e9b5f052589958d2b8553ae5fc9449496946b5c225e0baa723e7ddecbd89f060a", - "signSignature": "f0d4a000aae3dd3fa48a92f792d4318e41e3b56cdbaf98649261ae34490652b87645326a432d5deb69f771c133ee4b67d2d22789197be34249e6f7f0c30c1705" -} -``` - -### **4.7 Asset write-off, type=11** - -`uia.createTransfer(currency, amount, recipientId, secret, secondSecret)` -`remark` The transaction-type in the main chain for this operation is 11 - -- `currency` Asset name -- `flagType` Whether the assets write-off, 1: circulation, 2: cancellation -- `flag` flag is for black and white list mode - -```js -var currency = 'IssuerName.CNY' -var flagType = 2 -var flag =1 - -AschJS.uia.createFlags(currency, flagType, flag, secret, secondSecret) -{ - "type": 11, - "amount": 0, - "fee": 10000000, - "recipientId": null, - "senderPublicKey": "fafcd01f6b813fdeb3c086e60bc7fa9bfc8ef70ae7be47ce0ac5d06e7b1a8575", - "timestamp": 19488690, - "asset": { - "uiaFlags": { - "currency": "IssuerName.CNY", - "flagType": 2, - "flag": 1 - } - }, - "signature": "cbd656552417604704703e1236ec2bbed8eba6a2ccfcb54cc0b2d629c0a9d1335a264fc9f6dee1705f4a86c36a5ce2ba8e039d913a189b7c273c8ac0d9e3780c", - "signSignature": "3c7b91d03efeed2dc86e1f2301da60789751c1be8850460d8c66c0ae8f55ea27d26f0bc79541d74b4777d9b85c518c1c73c0284dbf3e826db0a686560e57a80b" -} -``` - -## **5 Delegate** -### **5.1 Registere delegate, type=2** - -`delegate.createDelegate(username, secret, secondSecret)` -`remark` The transaction-type in the main chain for this operation is 2 - -- `username` Delegate name -- `secret` password -- `secondSecret` second password - -```js -var userName='zhenxi' -undefined -AschJS.delegate.createDelegate(userName, secret, secondSecret || undefined) -{ - type: 2, - amount: 0, - fee: 10000000000, - recipientId: null, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - timestamp: 40568017, - asset: { - delegate: { - username: 'zhenxi', - publicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed' - } - }, - signature: 'e471ade7ded7785f597821f8946d4e98da5ba4331505141c5bea5ff80bbf30b649218ef03254ac703ce93e15207c8b71c69c0d1400cb5790440860ed0e51a30a', - signSignature: 'ec47d565a70e6ad075abaf1ff55c129bde9495e4cc7ab2a9404b698ef257f3b1cfd0ce4f9f1854a1bbfec0f663867823a544f80964e3be05ddf03a50a9b77d07', - id: '774ccf5e7d9d9fefa459b23d96e10ffae4bb891e1e07912ac1370af04192e810' -} -``` - -### **5.2 Vote or cancel vote for delegate, type=3** - -`vote.createVote(keyList, secret, secondSecret)` -`remark` The transaction-type in the main chain for this operation is 3 - -- `keyList` list of delegate's public keys -- `secret` password -- `secondSecret` second password - -```js -// voting works as shown below as a array with a symbol ('+'/'-') and a public key for each delegate. The '+' symbol votes for a person the '-' symbol cancels the vote for this delegate. -var voteContent = [ -... '-ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7', -... '+c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2' -... ]; -undefined - -transaction=AschJS.vote.createVote(voteContent, secret, secondSecret || undefined); -{ - type: 3, - amount: 0, - fee: 10000000, - recipientId: null, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - timestamp: 40568669, - asset: { - vote: { - votes: [Array] - } - }, - signature: '66f6f3c4fbb8545df53ea35ff655fc1a28815591885757d0b735e77ed348caf33d8d9cb2895f85cd40bf2d3b4633f45a19ebd1dd130233305a603304a92ce003', - signSignature: 'c026d373e026b524efd82ad1ab046708ee1ff68573f016490d12908f5ad00a97fa7501f46834c94f6dd64afd00aa77f9d29ded087977ac6601778d4aacb5cd0e', - id: '0789524787384e2e4da7773afdd3871193a67303c4da69c4a9070eaa5676d36c' -} - -transaction.asset.vote.votes [ - '-ae256559d06409435c04bd62628b3e7ea3894c43298556f52b1cfb01fb3e3dc7', - '+c292db6ea14d518bc29e37cb227ff260be21e2e164ca575028835a1f499e4fe2' -] -``` - - -## **6 Dapp** - -### **6.1 Dapp registration, type=5** - -`dapp.createDApp(options, secret, secondSecret)` -`remark` The transaction-type in the main chain for this operation is 5 - -- `options` Basic dapp related attributes, such as name, url, icon, initial delegates public key, dapp type, dapp tag and other information -- `secret` password -- `secondSecret` second password - -```js -var options = { -... name: 'asch-dapp-cctime', -... link: 'https://github.com/AschPlatform/asch-dapp-cctime/archive/master.zip', -... category: 1, -... description: 'Decentralized news channel', -... tags: 'asch,dapp,demo,cctime', -... icon: 'http://o7dyh3w0x.bkt.clouddn.com/hello.png', -... type: 0, -... delegates: -... [ '8b1c24a0b9ba9b9ccf5e35d0c848d582a2a22cca54d42de8ac7b2412e7dc63d4', -... 'aa7dcc3afd151a549e826753b0547c90e61b022adb26938177904a73fc4fee36', -... 'e29c75979ac834b871ce58dc52a6f604f8f565dea2b8925705883b8c001fe8ce', -... '55ad778a8ff0ce4c25cb7a45735c9e55cf1daca110cfddee30e789cb07c8c9f3', -... '982076258caab20f06feddc94b95ace89a2862f36fea73fa007916ab97e5946a' ], -... unlockDelegates: 3 -}; -undefined - -trs = AschJS.dapp.createDApp(options, secret); -{ - type: 5, - amount: 0, - fee: 10000000000, - recipientId: null, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - timestamp: 40572296, - asset: { - dapp: { - category: 1, - name: 'asch-dapp-cctime', - description: 'Decentralized news channel', - tags: 'asch,dapp,demo,cctime', - type: 0, - link: 'https://github.com/AschPlatform/asch-dapp-cctime/archive/master.zip', - icon: 'http://o7dyh3w0x.bkt.clouddn.com/hello.png', - delegates: [Array], - unlockDelegates: 3 - } - }, - signature: '5a8e2dba5e14b4ec62ce1b8543de2796d3cded249ed899c5049dd0adeff00963dd40436e7cfc6f9952e09d5c6ac8f5144d3e568f263586520c68012d3c7ca509', - id: 'ecf9366a128408b843f0e6b2bd7261a4d602c32ae36a8c3cef609e904f180735' -} - -trs.asset.dapp.delegates -[ '8b1c24a0b9ba9b9ccf5e35d0c848d582a2a22cca54d42de8ac7b2412e7dc63d4', - 'aa7dcc3afd151a549e826753b0547c90e61b022adb26938177904a73fc4fee36', - 'e29c75979ac834b871ce58dc52a6f604f8f565dea2b8925705883b8c001fe8ce', - '55ad778a8ff0ce4c25cb7a45735c9e55cf1daca110cfddee30e789cb07c8c9f3', - '982076258caab20f06feddc94b95ace89a2862f36fea73fa007916ab97e5946a' ] -``` - -### **6.2 Dapp recharge, type=6** - -`transfer.createInTransfer(dappid, currency, amount, secret, secondSecret);` -`remark` The transaction-type in the main chain for this operation is 6 - -- `dappid` id of dapp -- `currency` Recharge the name of the asset -- `amount` The amount to recharge - -```js -var dappid = "bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024"; -var currency = "XAS"; -var amount = 10*100000000 ; - -AschJS.transfer.createInTransfer(dappid, currency, amount, secret, secondSecret || undefined); -{ - type: 6, - amount: 1000000000, - fee: 10000000, - recipientId: null, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - timestamp: 40578327, - asset: { - inTransfer: { - dappId: 'bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024', - currency: 'XAS' - } - }, - signature: '6907c1402c702e0fd504a8734a047c1bb216d437e65d5675325846b92ef8b916fc634ea7e33a7c72c60c058d1496d0385c95e39a8291e27b2dceb2f40b6aed02', - signSignature: '86de438431c639124a13429e8c6a8c13a5cbbbab3a8323ae08b56f65faeff6d816815d7cdecfdb7287077b14e4d14865637efc9d7fd72d085b0aa9d82f27170c', - id: '25be71c296430a409cfeaf1ffaa957d18793f3695db07a846c22a7c467c45994' -} -``` - -### **6.3 Dapp internal contract call** - -`dapp.createInnerTransaction(options, secret)` - -- `options` Contract related options such as commission, contract number, contract string array parameters -- `secret` password - -Customize the following global variables for the following code demo - -```js -var fee = String(0.1 * 100000000); // Currently dapp built-in contract calls the unified fee of 10,000,000 corresponding to the assets -``` - -#### **6.3.1 Dapp cash, contract type=2** - -`args` '["Asset name","Withdrawal amount"]' - -```js -var type = 2; // The type here refers to the contract number, not the main transaction-type -var options = {fee: fee, type: type, args: '["CCTime.XCT", "100000000"]'}; - -AschJS.dapp.createInnerTransaction(options, secret); -{ - fee: '10000000', - timestamp: 40572732, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - type: 2, - args: '["CCTime.XCT", "100000000"]', - signature: 'a0d860a0c13cf40d6be08f42a66bf01264f96fadc8ed2997139c583ba7fcd5e7ceeda9207c635215ddfd60bde8c35914cdfe2b03a4862cdd187b9142d497c301' -} -``` - -#### **6.3.2 Dapp internal transfer, contract type=3** - -`args` '["Asset name","Transfer amount","Receiving address"]' - -```js -var type = 3; -var options = {fee: fee, type: type, args: '["CCTime.XCT", "100000000", "A6H9rawJ7qvE2rKwQfdtBHdeYVehB8gFzC"]'}; - -AschJS.dapp.createInnerTransaction(options, secret); -{ - fee: '10000000', - timestamp: 40573272, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - type: 3, - args: '["CCTime.XCT", "100000000", "A6H9rawJ7qvE2rKwQfdtBHdeYVehB8gFzC"]', - signature: '3843bef77ad7c6f2b57083270055720186b8ba286cd44e263028eef9b8650ecf6d243c1861f9b9416e123b594695934430deb0f5146a173ebfcdccb6915acf0c' -} -``` - -#### **6.3.4 Set a dapp nickname, contract type=3** - -`args` '["nickname"]' - -```js -var type = 4; -var options = { fee: fee, type: type, args: '["nicheng"]' }; - -AschJS.dapp.createInnerTransaction(options, secret); -{ - fee: '10000000', - timestamp: 40573343, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - type: 4, - args: '["nicheng"]', - signature: '172998ddbb2ef72037be673d658dbc64760da307d451257666c956868b142707cd4aa38668b52d1d0d7cc62c01866daef2bae8d427844194d42ca9fea97ea70b' -} -``` - -### **6.4 Dapp withdraw** -#### **6.4.1 Create a cash transaction, type=7** - -`transfer.createOutTransfer(recipientId, dappId, transactionId, currency, amount, secret, secondSecret)` -`remark` The transaction-type in the main chain for this operation is 7. This interface is typically called by the dapp delegate (the delegate scans the cash transaction created by the smart contract on the sidechain every 10 seconds, and when found, creates a type = 7 cash transaction in the main chain) - - -- `recipientId` Receiptient Id -- `dappId` dapp id -- `transactionId` Transaction id, which is the smart contract number 2 created on the sidechain -- `currency` Withdraw the asset (XAS or UIA) -- `amount` Withdrawal amount - -```js -let recipientId = 'AFUH568CbGC2GPcE4gXHiZhxdYQYfziz2J'; -let dappId = 'bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024'; -let transactionId = '123b04a6e380500903d8942622d57987661e72b2ae95464066d0af3f02c3c691'; -let currency = 'XAS' -let amount = '10000000' - -var transaction = AschJS.transfer.createOutTransfer(recipientId, dappId, transactionId, currency, amount, secret, secondSecret); -{ - type: 7, - amount: 0, - fee: 10000000, - recipientId: 'AFUH568CbGC2GPcE4gXHiZhxdYQYfziz2J', - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - timestamp: 40668981, - asset: { - outTransfer: { - dappId: 'bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024', - transactionId: '123b04a6e380500903d8942622d57987661e72b2ae95464066d0af3f02c3c691', - currency: 'XAS', - amount: '10000000' - } - }, - signature: '432d25e5c5b81fa3a5937adca2dd4a1e2a38e51f8896838601902e0c123a5ccb664bbc8a55344b9fedb773da98e0988e4e8d1ca99dcbc51a80ea3bc9a6b61806', - signSignature: '8154c1f8305b9b957974e778de1e08dd3f08afcb70f27624d1385dbae9dfa6d0a3aaed6211ed8a40f4015f7e47312f0f205d94518c68e4deec8d76567f56f10f', - id: '237925a60ccc0abfc1494720aab8c11c74ba61e8ab3ca4bd8ded8c3215c201a7' -} -``` - -#### **6.4.2 The delegate signs the cash transaction** - -`transfer.signOutTransfer(transaction, secret)` -`remark` For the Dapp cash transactions more than one trustee must sign the transaction. The minimum number of trustee signatures depends on dapp's registration parameters: unlockDelegates. The trustee scans the cash transaction created by the smart contract on the sidechain every 10 seconds and signs the transaction if there is a transaction and the number of signatures is not met. - -- `transaction` the withdrawal transaction is generated with a call to transfer.createOutTransfer -- `secret` delegate password - -```js -// Follow the previous section Create a cash transaction, type=7" variable -transaction.signatures = [] // delegate signature list - -// The first delegate signs the cash transaction -delegate1_secret = 'chalk flame jeans rebuild dutch stone abstract capital lucky pottery raven depend' -signature1 = AschJS.transfer.signOutTransfer(transaction,delegate1_secret); -'ac0ea4c10b911f2134e5adfb3535ffc070ffa8f2858a5a1bc4e9bef442863e117e6bce552bba0d5b0160c4076dd3c657ebc33cbe077a8ef719798a8bb0fac30c' -transaction.signatures.push(signature1) // Add the signature to the transaction's signature list -// The second delegate signs the cash transaction -delegate2_secret = 'twist arrange matter twice daughter cave cause never enough scare warfare uncover' -signature2 = AschJS.transfer.signOutTransfer(transaction,delegate2_secret); -'480e0717e4be02e48a27e2323bf6507c4c72d1033b4e7e674651e9e4feced17836f0b81b91ade99b61620a2766ecc901f090d81cc72d22b86807ae981eb2d10c' -transaction.signatures.push(signature2) // Add the signature to the transaction's signature list -// By analogy, multiple delegates sign the transaction and the take-over transaction takes effect when the minimum number of signatures is satisfied -transaction -{ - type: 7, - amount: 0, - fee: 10000000, - recipientId: 'AFUH568CbGC2GPcE4gXHiZhxdYQYfziz2J', - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - timestamp: 40669013, - asset: { - outTransfer: { - dappId: 'bebe3c57d76a5bbe3954bd7cb4b9e381e8a1ba3c78e183478b4f98b9d532f024', - transactionId: '123b04a6e380500903d8942622d57987661e72b2ae95464066d0af3f02c3c691', - currency: 'XAS', - amount: '10000000' - } - }, - signature: '1dfae733408d374cd7be5f4b55183c0c05dc31341f93daaf82c26c80ab11035202502180dd78c5643edcd3bb481a38f352408bc35e44e6c1c53c95612fbca804', - signSignature: '8f4f7aa06c02c0a3d637329e1a3b23489b91797b9f3477afd4314b2f78d1e8e8a369a640d75916bd9477e69363cf440c27124db615dced1701a1a934714afe05', - id: '95a0c4ac9d5397452629b89410413f54ed37caee84a13edf3c9c26d3d0606dab', - signatures: - [ 'ac0ea4c10b911f2134e5adfb3535ffc070ffa8f2858a5a1bc4e9bef442863e117e6bce552bba0d5b0160c4076dd3c657ebc33cbe077a8ef719798a8bb0fac30c', - '480e0717e4be02e48a27e2323bf6507c4c72d1033b4e7e674651e9e4feced17836f0b81b91ade99b61620a2766ecc901f090d81cc72d22b86807ae981eb2d10c' ] // 受托人签名数组 -} -``` - - -## **7 Storage** - -### **7.1 Create a storage transaction,type=8** - -`storage.createStorage(content, secret, secondSecret)` -`remark` The transaction-type in the main chain for this operation is 8 - -- `content` - - -```js -var content = new Buffer('helloworld').toString('hex') -AschJS.storage.createStorage(content, secret, secondSecret) -{ - type: 8, - amount: 0, - fee: 10000000, - recipientId: null, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - timestamp: 40578932, - asset: { - storage: { - content: '68656c6c6f776f726c64' - } - }, - signature: 'd7f3f29549542d6716bdb13e8e1f97e3965c6fbe34f1ee18dbdcad7ba9cbf83ee7cb2b7fcbaab5ffed5d569771731bb5a40efc4fabd142cb30becdad8bc8bb06', - signSignature: '38315bf369540cc7a793139b1b6195f4c0e1512514d62bf028d454182a4b7a8912c1b1e6f617f6fb4ff8d80bd141a2ebb9dfcaa8fee68cfc81f8872611bba803', - id: '4d0b04a6e380500903d8942622d57987661e72b2ae95464066d0af3f02c3c691' -} -``` - -## **8 Related to signature verification, crypto** - -Customize the signed transfer transaction (transfer 100 XAS to 16358246403719868041 in the main chain) for the demo purpose. - -```js -var targetAddress = "16358246403719868041"; -var amount = 100*100000000; //100 XAS -var message = 'beizhu'; -transaction = AschJS.transaction.createTransaction(targetAddress, amount, message, secret, secondSecret) -{ - type: 0, - amount: 10000000000, - fee: 10000000, - recipientId: '16358246403719868041', - message: 'beizhu', - timestamp: 40566970, - asset: {}, - senderPublicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - signature: '9bef374be100fcfec59d245af59e5646ba5dcb79c6f1399ddd676a617542eeb45cc363822b84410e379f0caa501c25b66e59142353c04d23d1cb95cf64cef306', - signSignature: '513e3efdbb65f8e60e85ca98d8d065ec9bd3bfa6f45a1f48cfade9c94d410338ee64bd55938c168b10f0749335c050312785dbf08882ffd0e40a65fde8c2b10b', - id: '871554a8346d84cab2147324706d8ab5494fde928a7463a68d536ed6c0357897' -} -``` - -### **8.1 Get transaction bytes** - -`getBytes(transaction, skipSignature, skipSecondSignature)` - -- `transaction` The content of the transaction can be signed or unsigned, and the signed transaction is required by default. -- `skipSignature` Whether to skip the signature calculation, the default is not skipped. Non-mandatory parameters -- `skipSecondSignature` Whether to skip the secondary password signature calculation, the default is not skipped. Non-mandatory parameters - -```js -// Transaction.signature and transaction.signSignature are counted -AschJS.crypto.getBytes(transaction) - // The returned byte buffer -``` - -### **8.2 Get Transaction Hash** - -`getHash(transaction, skipSignature, skipSecondSignature)` - -- `transaction` The content of the transaction can be signed or unsigned, and the signed transaction is required by default. -- `skipSignature` Whether to skip the signature calculation, the default is not skipped. Non-mandatory parameters -- `skipSecondSignature` Whether to skip the secondary password signature calculation, the default is not skipped. Non-mandatory parameters - - -```js -// Transaction.signature and transaction.signSignature are counted -AschJS.crypto.getHash(transaction) - // the hash buffer which was returned -``` - -### **8.3 Get transaction id based on transaction content** - -`crypto.getId(transaction)` - -- `transaction` Signed transaction content - -```js -AschJS.crypto.getId(transaction) -'871554a8346d84cab2147324706d8ab5494fde928a7463a68d536ed6c0357897' // Return result, transaction id -``` - -### **8.4 Sign the transaction bytes** - -`crypto.signBytes(bytes, keys)` - -- `bytes` Transaction Bytes, unsigned transactions or primary password signatures but secondary password unsigned transactions -- `keys` Public key / private key pair - -```js -// Define unsigned transactions -var trs = { -... type: 0, -... amount: 10000000000, -... fee: 10000000, -... recipientId: '16358246403719868041', -... message: 'beizhu', -... timestamp: 40566970, -... asset: {} -} - -// created from the password -keys = AschJS.crypto.getKeys(secret) -{ - publicKey: 'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed', - privateKey: '7ae536fa343281d9e9ed383e8b5ef62e0fd0d0cbed79786cac241d484e312fdeebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed' -} - -trs.senderPublicKey = keys.publicKey; -'ebd4c62ebe2255b7ad5ee43120a9f9191c76e30928c92cd536351e3cc2c626ed' - -// Get the transaction byte buffer -buf = AschJS.crypto.getBytes(trs) - -// 通过私钥对交易Bytes Buffer进行签名 -signature = AschJS.crypto.signBytes(buf,keys) -'9bef374be100fcfec59d245af59e5646ba5dcb79c6f1399ddd676a617542eeb45cc363822b84410e379f0caa501c25b66e59142353c04d23d1cb95cf64cef306' // 返回值与上面自定义的已签名交易中的签名一致 -``` - -### **8.5 Verify that the transaction signature is consistent with the existing signature** - -`crypto.verifyBytes(bytes, signature, publicKey)` 返回true/false - -- `bytes` Transaction Bytes Buffer, unsigned transactions or primary password signatures but secondary password unsigned transactions -- `signature` Signature to be verified -- `publicKey` Signer public key - -```js -// Follow the previous section, "Sign Trading Bytes Buffer" variables -AschJS.crypto.verifyBytes(buf, transaction.signature,transaction.senderPublicKey) -true // The top of this chapter custom transaction signature -``` - -## **9 Miscellaneous** - -### **9.1 Global parameters** - -#### **9.1.1 Set the variable k/v** -`options.set(key, values)` - -- `key` Key name -- `value` Key value - -```js -AschJS.options.set('secret', 'minor borrow display rebel depart core buzz right distance avocado immense push') -undefined -``` - - -#### **9.1.2 According to the key for value** - -`options.get(key)` - -- `key` key - -```js -AschJS.options.get('secret') -'minor borrow display rebel depart core buzz right distance avocado immense push' -``` - - -#### **9.1.3 Get all k/v** - -`options.getAll()` - -```js -AschJS.options.getAll() -{ - clientDriftSeconds: 5, // asch-js built in variables - secret: 'minor borrow display rebel depart core buzz right distance avocado immense push' -} -``` - -### **9.2 Time related slot.time** - -#### **9.2.1 Asch main network creation block generation time** - -`utils.slots.beginEpochTime()` -`remark` The result is UTC time, the beginning of the Asch era. - -```js -AschJS.utils.slots.beginEpochTime() -2016-06-27T20:00:00.000Z // Asch main network creation time, but the main network is officially running on August 16 that day (the main network is running the logo is generated block heihgt = 2 block) -``` - - -#### **9.2.2 Get Asch timestamp based on unix timestamp** - -`utils.slots.getTime(time)` -`remark` The result is called EpochTim (Asch timestamp), the time passed in relation to the number of seconds experienced by the Asch era - -- `time` If you do not pass the current time Unix timestamp * 1000 (ie milliseconds) - -```js -AschJS.utils.slots.getTime() -40655681 // Asch time stamp - -unix_timestamp = 1507713496 -epochTime = AschJS.utils.slots.getTime(unix_timestamp * 1000) -40655896 // Asch time stamp -``` - -#### **9.2.3 Get the unix timestamp based on the Asch timestamp** - -`utils.slots.getRealTime(epochTime)` -`remark` The result is a real unix timestamp * 1000 - -- `epochTime` Asch timestamp in seconds - -```js -unix_timestamp = 1507713496 // unix timestamp -epochTime = AschJS.utils.slots.getTime(unix_timestamp * 1000) -40655896 // Obtained by the unix timestamp asch timestamp -real_time = AschJS.utils.slots.getRealTime(epochTime) -1507713496000 // Get the unix timestamp by asch timestamp - -unix_timestamp === real_time/1000 -true // The conversion result is the same -``` diff --git a/docs/asch_sdk_api.md b/docs/asch_sdk_api.md deleted file mode 100644 index 3488ef4..0000000 --- a/docs/asch_sdk_api.md +++ /dev/null @@ -1,621 +0,0 @@ -Table of Contents -================= - - * [Asch SDK API 使用说明](#asch-sdk-api-使用说明) - * [1. 数据库](#1-数据库) - * [1.1 aync app.sdb.load(model, fields, indices)](#11-aync-appsdbloadmodel-fields-indices) - * [1.2 app.sdb.get(model, cond)](#12-appsdbgetmodel-cond) - * [1.3 app.sdb.keys(model)](#13-appsdbkeysmodel) - * [1.4 app.sdb.entries(model)](#14-appsdbentriesmodel) - * [1.5 ap.sdb.lock(key)](#15-apsdblockkey) - * [1.6 app.sdb.create(model, values)](#16-appsdbcreatemodel-values) - * [1.7 app.sdb.replace(model, values)](#17-appsdbreplacemodel-values) - * [1.8 app.sdb.update(model, modifier, cond)](#18-appsdbupdatemodel-modifier-cond) - * [1.9 app.sdb.increment(model, modifier, cond)](#19-appsdbincrementmodel-modifier-cond) - * [1.10 app.sdb.del(model, cond)](#110-appsdbdelmodel-cond) - * [2. 余额](#2-余额) - * [2.1 app.balances.get(address, currency)](#21-appbalancesgetaddress-currency) - * [2.2 app.balances.increase(address, currency, amount)](#22-appbalancesincreaseaddress-currency-amount) - * [2.3 app.balances.decrease(address, currency, amount)](#23-appbalancesdecreaseaddress-currency-amount) - * [2.4 app.balances.transfer(currency, amount, from, to)](#24-appbalancestransfercurrency-amount-from-to) - * [3 数据模型](#3-数据模型) - * [3.1 app.model[name]](#31-appmodelname) - * [3.2 fields()](#32-fields) - * [3.3 count(cond)](#33-countcond) - * [3.4 exists(cond)](#34-existscond) - * [3.5 findOne(options)](#35-findoneoptions) - * [3.6 findAll(options)](#36-findalloptions) - * [4. 路由](#4-路由) - * [4.1 app.route.get(path, handler)](#41-approutegetpath-handler) - * [4.2 app.route.post(path, handler)](#42-approutepostpath-handler) - * [4.3 app.route.put(path, handler)](#43-approuteputpath-handler) - * [5. 费用池](#5-费用池) - * [5.1 app.feePool.add(currency, amount)](#51-appfeepooladdcurrency-amount) - * [6. 自增ID](#6-自增id) - * [6.1 app.autoID.get(name)](#61-appautoidgetname) - * [6.2 app.autoID.increment(name)](#62-appautoidincrementname) - * [7. 日志](#7-日志) - * [7.1 app.logger.setLevel(level)](#71-apploggersetlevellevel) - * [7.2 app.logger.log()](#72-apploggerlog) - * [7.3 app.logger.trace()](#73-apploggertrace) - * [7.4 app.logger.debug()](#74-apploggerdebug) - * [7.5 app.logger.info()](#75-apploggerinfo) - * [7.6 app.logger.warn()](#76-apploggerwarn) - * [7.7 app.logger.error()](#77-apploggererror) - * [8. 工具类](#8-工具类) - * [8.1 app.validate(type, value)](#81-appvalidatetype-value) - * [8.2 app.registerContract(type, name)](#82-appregistercontracttype-name) - * [8.3 app.getContractName(type)](#83-appgetcontractnametype) - * [8.4 app.registerFee(type, min, currency)](#84-appregisterfeetype-min-currency) - * [8.5 app.getFee(type)](#85-appgetfeetype) - * [8.6 app.setDefaultFee(min, currency)](#86-appsetdefaultfeemin-currency) - * [8.7 app.getRealTime(epochTime)](#87-appgetrealtimeepochtime) - * [8.8 app.registerHook](#88-appregisterhook) - * [8.9 app.custom[]](#89-appcustom) - -Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc) - - -# Asch SDK API 使用说明 - - -## **1. 数据库** - -### 1.1 `aync` app.sdb.load(model, fields, indices) - -- `model` 模型名称 -- `fields` 加载到内存中的字段 -- `indices` 索引数组, 单字段索引时, 元素为字符串; 多字段索引时, 元素为字符串数组 - -> 无返回值, 出现错误时抛异常 -> 将指定模型的数据加载到内存并建立索引, 这样可以提高查询和更新一个状态的效率 -> 当一个数据模型需要频繁更新和查询时, 建议使用这个接口, 比如系统内置的账户余额、自增ID都使用了这个功能 - -示例: - -``` -await app.sdb.load('Balance', app.model.Balance.fields(), [['address', 'currency']]) -await app.sdb.load('Variable', ['key', 'value'], ['key']) -``` - -### 1.2 app.sdb.get(model, cond) - -- `model` 模型名称 -- `cond` 查询条件 - -> 返回一个数据项, 包含的字段为`load`时指定的字段 -> 按指定条件查询内存中的数据, 如果该模型没有被载入内存, 会抛出异常; 查询条件包换未建索引的字段时也会抛出异常 - -示例: - -``` -app.sdb.get('Variable', { key: 'foo' }) -/* output: -{ - key: 'foo', - value: 'bar' -} -*/ - -let balance = app.sdb.get('Balance', { address: 'foo', currency: 'XAS' }) -/* output: -{ - address: 'foo', - currency: 'XAS', - balance: '1000000' -} -*/ -``` - -### 1.3 app.sdb.keys(model) - -- `model` 模型名称 - -> 返回一个数据模型的全部索引字段 - -示例: - -``` -let keys = app.sdb.keys('Variable') -for (let i of keys) { - console.log(i) -} -/* output: -foo -foo1 -foo2 -*/ -``` - - -### 1.4 app.sdb.entries(model) - -- `model` 模型名称 - -> 返回一个数据模型的所有缓存项 - -示例: - -``` -let entries = app.sdb.entries('Variable') -for (let [key, value] of entries) { - console.log(key, value) -} -/* output: -foo bar -foo1 bar1 -foo2 bar2 -*/ -``` - -### 1.5 ap.sdb.lock(key) - -- `key` - -> 无返回值 -> 对一个key进行加锁, 有效期为一个区块间隔, 在同一个区块生命周期内不允许对一个key二次加锁, 否则会抛异常 -> 该功能主要是为了解决对未确认数据的依赖问题。比如, 一个合约中需要对某账户设置昵称, 在这个合约调用被确认之前, 我们需要防止再次调用, 这种情况下可以使用加锁功能 - -示例: - -``` -app.sdb.lock('AC3pinmvz9qX9cj6c7VrGigq7bpPxVJq85@nickname' -``` - -### 1.6 app.sdb.create(model, values) - -- `model` 模型名称 -- `values` 待创建的数据项 - -> 无返回值 -> 创建一个数据项, 如果该模型有缓存, 会实时更新缓存. 在区块确认后, 持久化到磁盘数据库 - -示例: - -``` -app.sdb.create('Article', { - title: 'This is an article title', - content: 'article contents', - author: 'qingfeng', - tag: 'Science' -}) -``` - -### 1.7 app.sdb.replace(model, values) - -- `model` 模型名称 -- `values` 待创建或更新的数据项 - -> 无返回值 -> 创建或更新一个数据项, 如果数据库中无此项则创建, 否则更新. 模型必须包含主键, `values`必须包含主键 - -示例: - -``` -app.sdb.replace('Account', { - address: 'AC3pinmvz9qX9cj6c7VrGigq7bpPxVJq85', - nickname: 'Nakamoto' -}) -``` - -### 1.8 app.sdb.update(model, modifier, cond) - -- `model` 模型名称 -- `modifier` 待更新的数据项 -- `cond` 更新条件 - -> 无返回值 -> 按指定条件更新一个模型的若干个数据项 - -示例: - -``` -app.sdb.update('Account', { nickname: 'Nakamoto' }, { nickname: 'Satoshi' }) -``` - -### 1.9 app.sdb.increment(model, modifier, cond) - -- `model` 模型名称 -- `modifier` 待更新的数据项 -- `cond` 更新条件 - -> 按指定条件增量更新一个模型的若干个数据项, 只能用于更新整数类型 - -示例: - -``` -app.sdb.increment('Article', { votes: -10 }, { id: '10000' }) -app.sdb.increment('Article', { comments: 1 }, { id: '10000' }) -``` - -### 1.10 app.sdb.del(model, cond) - -- `model` 模型名称 -- `cond` 删除条件 - -> 无返回值 -> 按条件删除一个模型中的数据项 -> 删除操作的底层实现目前是标记为deleted, 默认的查询接口都会过滤掉被标记的数据, 但非标准接口或协议仍然可以获取到这些已经被`删除`的数据 - -示例: - -``` -app.sdb.del('Article', { id: '100001' }) -``` - -## 2. 余额 - -### 2.1 app.balances.get(address, currency) - -- `address` 账户地址 -- `currency` 币种 - -> 获取指定账户、指定币种的余额 - -示例: - -``` -app.balances.get('AC3pinmvz9qX9cj6c7VrGigq7bpPxVJq85', 'XAS') -/* output: -{ - address: 'AC3pinmvz9qX9cj6c7VrGigq7bpPxVJq85', - currency: 'XAS', - balance: '10000000' -} -*/ -``` - -### 2.2 app.balances.increase(address, currency, amount) - -- `address` 账户地址 -- `currency` 币种 -- `amount` 增加的数额 - -> 无返回值 -> 增加指定账户、指定币种的余额 - -示例: - -``` -app.balances.increase('AC3pinmvz9qX9cj6c7VrGigq7bpPxVJq85', 'XAS', '100000') -``` - -### 2.3 app.balances.decrease(address, currency, amount) - -- `address` 账户地址 -- `currency` 币种 -- `amount` 减少的数额 - -> 无返回值 -> 减少指定账户、指定币种的余额 - -示例: - -``` -app.balances.decrease('AC3pinmvz9qX9cj6c7VrGigq7bpPxVJq85', 'XAS', '100000') -``` - -### 2.4 app.balances.transfer(currency, amount, from, to) - -- `currency` 币种 -- `amount` 转移的数额 -- `from` 源地址(发款人) -- `to` 目的地址(收款人) - -> 无返回值 -> 两个账户之间转移资产 - -示例: - -``` -app.balances.transfer('XAS', '100000', 'AC3pinmvz9qX9cj6c7VrGigq7bpPxVJq85', 'A4MFPoF3c9vCzZ3GGf9sNQ3rDy2q8aXuVF') -``` - -## 3 数据模型 - -### 3.1 app.model[name] - -- `name` 模型名称 - -> 返回一个模型的实例, 主要用于查询已确认的数据 - -### 3.2 fields() - -> 返回该模型所有字段 - -### 3.3 count(cond) - -- `cond` 查询条件 - -> 返回`Number` -> 表示指定条件的数据项总数 - -示例: - -``` -app.model.Block.count({ height: { $lt: 100 } }) -/* output: -99 -/* -``` - -### 3.4 exists(cond) - -- `cond` 查询条件 - -> 返回`Boolean` -> 表示指定条件的数据项是否存在 - -示例: - -``` -app.model.Transaction.exists({ id: '9a5ec0669c79b9f5a1d5a4dbb2c200bc28c9ea829dbff71f41cbb2ad5a7d9b01' }) -/* output: -false -/* - -app.model.Account.exists({ nickname: 'Nakamoto' }) -/* output: -true -*/ -``` - -### 3.5 findOne(options) - -`options`是一个对象, 包含以下元素 - -- `condition` 查询条件 -- `fields` 返回的字段 - -> 查询一个指定条件的数据项 - -示例: - -``` -app.model.Account.findOne({ nickname: 'Nakamoto' }) -/* output: -{ - address: 'AC3pinmvz9qX9cj6c7VrGigq7bpPxVJq85', - nickname: 'Nakamoto', - ...other values -} -*/ -``` - -### 3.6 findAll(options) - -`options`是一个对象, 包含以下元素 - -- `condition` 查询条件 -- `fields` 返回的字段 -- `sort` 排序字段 -- `limit` 返回的最大数量 -- `offset` 偏移量 - -> 查询指定条件的所有数据项 - -示例: - -``` -app.model.Transfer.findAll({ senderId: 'AC3pinmvz9qX9cj6c7VrGigq7bpPxVJq85'}) -/* output: -[ - { - tid: "50e062f25946d220b924cb5ec6e52e260e44c9417d9f3c8ea041b704e06895f7", - senderId: "AFnwUuET2XddPtqpFb2ns78CQEqc7KZ6vD", - recipientId: "asdasdasd", - currency: "CCTime.XCT", - amount: "100000000", - t_timestamp: 38660145, - t_type: 3, - t_height: 93953 - }, - { - tid: "f15ce92add809b4a132936d514dce7fa7bdc15e850e7c026a001625b48595af3", - senderId: "AFnwUuET2XddPtqpFb2ns78CQEqc7KZ6vD", - recipientId: "asdasd", - currency: "CCTime.XCT", - amount: "100000000", - t_timestamp: 38660096, - t_type: 3, - t_height: 93948 - } -] -*/ -``` - -## 4. 路由 - -- `path` 路径 -- `handler` http请求处理函数, async类型 - -### 4.1 app.route.get(path, handler) - -> 注册一个`get`类型的`http`请求处理函数 - -### 4.2 app.route.post(path, handler) - -> 注册一个`post`类型的`http`请求处理函数 - -### 4.3 app.route.put(path, handler) - -> 注册一个`put`类型的`http`请求处理函数 - -## 5. 费用池 - -### 5.1 app.feePool.add(currency, amount) - -- `currency` 币种 -- `amount` 数额 - -> 无返回值 -> 将资产加入费用池(在每一个`round`结尾平均分给记账人) - -示例: - -``` -app.feelPool.add('XAS', '10000000') -``` - -## 6. 自增ID - -### 6.1 app.autoID.get(name) - -- `name` ID类型名称 - -> 返回`String` -> 获取一个类型的当前最大ID - -### 6.2 app.autoID.increment(name) - -- `name` ID类型名称 - -> 返回`String` -> 对指定类型的ID增加1并以字符串形式返回更新后的数值, 相当于原子的`++1`, 超大数也适用 - -示例: - -``` -const AID = 'article_id' -app.autoID.get(AID) === '0' -app.autoID.increment(AID) === '1' -app.autoID.get(AID) === '1' -``` - -## 7. 日志 - -### 7.1 app.logger.setLevel(level) -### 7.2 app.logger.log() -### 7.3 app.logger.trace() -### 7.4 app.logger.debug() -### 7.5 app.logger.info() -### 7.6 app.logger.warn() -### 7.7 app.logger.error() - -示例: - -``` -app.logger.setLevel('debug') -app.logger.setLevel('info') - -logger.log('hello'); -logger.trace('hello', 'world'); -logger.debug('hello %s', 'world', 123); -logger.info('hello %s %d', 'world', 123, {foo:'bar'}); -logger.warn('hello %s %d %j', 'world', 123, {foo:'bar'}); -logger.error('hello %s %d %j', 'world', 123, {foo:'bar'}, [1, 2, 3, 4], Object); -``` - -## 8. 工具类 - -### 8.1 app.validate(type, value) - -- `type` 待验证的数据类型 -- `value` 待验证的数据值 - -> 验证一个数据是否符合规范, 不符合则抛出异常 - -示例: - -``` -app.validate('amount', '10000') // pase -app.validate('amount', 10000) // throws -app.validate('amount', 'abc') // throws -app.validate('amount', '1e10') // throws -``` - -### 8.2 app.registerContract(type, name) - -- `type` 合约数值类型或编号 -- `name` 合约的字符串名称 - -> 无返回值 -> 为合约注册一个数字类型, 未注册的合约无法被外部调用 - -示例: - -``` -app.registerContract(1001, 'cctime.postArticle') -``` - -### 8.3 app.getContractName(type) - -- `type` 合约的数字类型或编号 - -> 根据合约编号查询名称 - -示例: - -``` -app.getContractName(1001) === 'cctime.postArticle' -``` - -### 8.4 app.registerFee(type, min, currency) - -- `type` 合约的数字类型或编号 -- `min` 最小费用 -- `currency` 币种 - -> 为一个合约注册最小费用, 不固定资产, 可通过`currency`参数指定收哪种资产作为手续费 -> `min`表示最小费用, 实际调用合约的时候, 费用不能小于`min`, 但可以大于, 超过的部分自动放入费用池 - -示例: - -``` -app.registerFee(1001, '100000', 'XAS') -``` -### 8.5 app.getFee(type) - -- `type` 合约的数字类型或编号 - -> 获取指定合约的费用设定 - -示例: - -``` -app.getFee(1001) -/* output: -{ - min: '100000', - currency: 'XAS' -} -*/ -``` - -### 8.6 app.setDefaultFee(min, currency) - -- `min` 最小费用 -- `currency` 币种 - -> 为系统的所有合约设置默认手续费 - -示例: - -``` -app.setDefaultFee('10000', 'XAS') -``` - -### 8.7 app.getRealTime(epochTime) - -- `epochTime` 距离创世区块生成时间的秒数 - -> 返回完整的时间戳, 即区块创世时间加上偏移量, 单位为毫秒 -> Asch系统中底层存储和上层查询的时间戳均为一个偏移量, 并非实际时间戳, 可以调用这个函数转换为真实的时间戳 - -示例: - -``` -app.getRealTime(4353634) -``` - -### 8.8 app.registerHook - -// TBD - -### 8.9 app.custom[] - -> 应用的名字空间, 可用来保存应用本身自定义的一些全局变量, 主要是为了与系统级的全局变量进行隔离 - - - - diff --git a/docs/asch_sdk_api_en.md b/docs/asch_sdk_api_en.md deleted file mode 100644 index c2d7ea2..0000000 --- a/docs/asch_sdk_api_en.md +++ /dev/null @@ -1,1017 +0,0 @@ - -# Table of Contents - - - -- [Table of Contents](#table-of-contents) -- [Asch SDK API](#asch-sdk-api) - - [**1. Database**](#1-database) - - [1.1 `aync` app.sdb.load(model, fields, indices)](#11-aync-appsdbloadmodel-fields-indices) - - [1.2 app.sdb.get(model, cond)](#12-appsdbgetmodel-cond) - - [1.3 app.sdb.keys(model)](#13-appsdbkeysmodel) - - [1.4 app.sdb.entries(model)](#14-appsdbentriesmodel) - - [1.5 ap.sdb.lock(key)](#15-apsdblockkey) - - [1.6 app.sdb.create(model, values)](#16-appsdbcreatemodel-values) - - [1.7 app.sdb.replace(model, values)](#17-appsdbreplacemodel-values) - - [1.8 app.sdb.update(model, modifier, cond)](#18-appsdbupdatemodel-modifier-cond) - - [1.9 app.sdb.increment(model, modifier, cond)](#19-appsdbincrementmodel-modifier-cond) - - [1.10 app.sdb.del(model, cond)](#110-appsdbdelmodel-cond) - - [2. Balance](#2-balance) - - [2.1 app.balances.get(address, currency)](#21-appbalancesgetaddress-currency) - - [2.2 app.balances.increase(address, currency, amount)](#22-appbalancesincreaseaddress-currency-amount) - - [2.3 app.balances.decrease(address, currency, amount)](#23-appbalancesdecreaseaddress-currency-amount) - - [2.4 app.balances.transfer(currency, amount, from, to)](#24-appbalancestransfercurrency-amount-from-to) - - [3 Data model](#3-data-model) - - [3.1 app.model[name]](#31-appmodelname) - - [3.2 fields()](#32-fields) - - [3.3 count(cond)](#33-countcond) - - [3.4 exists(cond)](#34-existscond) - - [3.5 findOne(options)](#35-findoneoptions) - - [3.6 findAll(options)](#36-findalloptions) - - [4. Routing](#4-routing) - - [4.1 app.route.get(path, handler)](#41-approutegetpath-handler) - - [4.2 app.route.post(path, handler)](#42-approutepostpath-handler) - - [4.3 app.route.put(path, handler)](#43-approuteputpath-handler) - - [5. Cost pool](#5-cost-pool) - - [5.1 app.feePool.add(currency, amount)](#51-appfeepooladdcurrency-amount) - - [6. Increment ID](#6-increment-id) - - [6.1 app.autoID.get(name)](#61-appautoidgetname) - - [6.2 app.autoID.increment(name)](#62-appautoidincrementname) - - [7. Logging](#7-logging) - - [7.1 app.logger.setLevel(level)](#71-apploggersetlevellevel) - - [7.2 app.logger.log()](#72-apploggerlog) - - [7.3 app.logger.trace()](#73-apploggertrace) - - [7.4 app.logger.debug()](#74-apploggerdebug) - - [7.5 app.logger.info()](#75-apploggerinfo) - - [7.6 app.logger.warn()](#76-apploggerwarn) - - [7.7 app.logger.error()](#77-apploggererror) - - [8. Tools](#8-tools) - - [8.1 app.validate(type, value)](#81-appvalidatetype-value) - - [8.2 app.registerContract(type, name)](#82-appregistercontracttype-name) - - [8.3 app.getContractName(type)](#83-appgetcontractnametype) - - [8.4 app.registerFee(type, min, currency)](#84-appregisterfeetype-min-currency) - - [8.5 app.getFee(type)](#85-appgetfeetype) - - [8.6 app.setDefaultFee(min, currency)](#86-appsetdefaultfeemin-currency) - - [8.7 app.getRealTime(epochTime)](#87-appgetrealtimeepochtime) - - [8.8 app.registerHook](#88-appregisterhook) - - [8.8.1 beforeCreateBlock](#881-beforecreateblock) - - [8.9 app.custom[]](#89-appcustom) - - [8.10 app.meta](#810-appmeta) - - - -# Asch SDK API - - -## **1. Database** - -### 1.1 `aync` app.sdb.load(model, fields, indices) - -- `model` Datamodel -- `fields` Fields of the data model -- `indices` Array of indexes, it can be a single field index or a multi field index (provide an string array) - -> The operation has no return value, it throws an Exception when an error occurs -> Load the data for the specified model into memory and index the table which can further improve the efficiency of the query -> When a data model needs frequent updates and inquiries, it is recommended to use this interface, such as the system's built-in account balance, the increment ID uses this operation - -Example: - -```js -await app.sdb.load('Balance', app.model.Balance.fields(), [['address', 'currency']]) -await app.sdb.load('Variable', ['key', 'value'], ['key']) -``` - -### 1.2 app.sdb.get(model, cond) - -- `model` Datamodel -- `cond` Query conditions - -> Returns the model that matched the query conditions -> Query the data according to the specified query condition. When the model can't be loaded an exception will be thrown. Query conditions will also throw an error if the key value is not indexed - -Example: - -```js -app.sdb.get('Variable', { key: 'foo' }) -/* output: -{ - key: 'foo', - value: 'bar' -} -*/ - -let balance = app.sdb.get('Balance', { address: 'foo', currency: 'XAS' }) -/* output: -{ - address: 'foo', - currency: 'XAS', - balance: '1000000' -} -*/ -``` - -### 1.3 app.sdb.keys(model) - -- `model` Model - -> This operation returns all indexed fields for a model - -Example: - -```js -let keys = app.sdb.keys('Variable') -for (let i of keys) { - console.log(i) -} -/* output: -foo -foo1 -foo2 -*/ -``` - - -### 1.4 app.sdb.entries(model) - -- `model` Model name - -> Returns all cached fields for a data model - -Example: - -```js -let entries = app.sdb.entries('Variable') -for (let [key, value] of entries) { - console.log(key, value) -} -/* output: -foo bar -foo1 bar1 -foo2 bar2 -*/ -``` - -### 1.5 ap.sdb.lock(key) - -- `key` - -> No return value -> Lock a key. This lock is valid for the timespan of a block interval. A block life cycle does not allow a second lock or an exception will be thrown. -> This features is to prevent a duplicate call in a block life cycle. For example: A contract needs to set a nickname for an account. Before the contract call is confirmed, we need to prevent that the nickname is set again. Therefore we can use the lock function. - -Example: - -```js -let senderId = 'AHMCKebuL2nRYDgszf9J2KjVZzAw95WUyB' -app.sdb.lock(`cctime.postArticle@${senderId}`) -``` - -### 1.6 app.sdb.create(model, values) - -- `model` Model -- `values` Data items that will be created - -> No return value -> This operation creates a data item that updates the cache in real time if the model is cached. After the block is confirmed, the data will be persisted in the database. - -Example: - -```js -app.sdb.create('Article', { - title: 'This is an article title', - content: 'article contents', - author: 'qingfeng', - tag: 'Science' -}) -``` - -### 1.7 app.sdb.replace(model, values) - -- `model` model -- `values` data item that will be created or updated - -> No return value -> Create or update the data model. If the data model already exists, update it. The parameter `values` must must contain the primary key. - -Example: - -```js -app.sdb.replace('Account', { - address: 'AC3pinmvz9qX9cj6c7VrGigq7bpPxVJq85', - nickname: 'Nakamoto' -}) -``` - -### 1.8 app.sdb.update(model, modifier, cond) - -- `model` Model -- `modifier` Data item that should be updated -- `cond` Update condition - -> No return value -> One or many data items of a model are updated according to the update condition. - -Example: - -```js -app.sdb.update('Account', { nickname: 'Nakamoto' }, { nickname: 'Satoshi' }) -``` - -### 1.9 app.sdb.increment(model, modifier, cond) - -- `model` Model -- `modifier` Data item that should be updated -- `cond` Update condition - -> Incremental update of a model by specified number. This can only be used to update integer types. - -Example: - -```js -app.sdb.increment('Article', { votes: -10 }, { id: '10000' }) -app.sdb.increment('Article', { comments: 1 }, { id: '10000' }) -``` - -### 1.10 app.sdb.del(model, cond) - -- `model` Model name -- `cond` Delete condition - -> No return value -> Delete data items in a model according to a query condition -> The implementation of the delete operation is currently marked as obsolete. This query interface will not delete model data. However, a custom implementation can still delete data. - -Example: - -```js -app.sdb.del('Article', { id: '100001' }) -``` - -## 2. Balance - -### 2.1 app.balances.get(address, currency) - -- `address` Account address -- `currency` Currency - -> Returns the balance of the specified account - -Example: - -```js -app.balances.get('AC3pinmvz9qX9cj6c7VrGigq7bpPxVJq85', 'XAS') -/* output: -{ - address: 'AC3pinmvz9qX9cj6c7VrGigq7bpPxVJq85', - currency: 'XAS', - balance: '10000000' -} -*/ -``` - -### 2.2 app.balances.increase(address, currency, amount) - -- `address` Account address -- `currency` Currency -- `amount` Amount to increase - -> No return value -> This operation raises the balance of the address by `amount` (amount to increase). - -Example: - -```js -app.balances.increase('AC3pinmvz9qX9cj6c7VrGigq7bpPxVJq85', 'XAS', '100000') -``` - -### 2.3 app.balances.decrease(address, currency, amount) - -- `address` Account address -- `currency` Currency -- `amount` Amount to subtract - -> No return value -> This operation subtracts the `amount` of the balance. - -Example: - -```js -app.balances.decrease('AC3pinmvz9qX9cj6c7VrGigq7bpPxVJq85', 'XAS', '100000') -``` - -### 2.4 app.balances.transfer(currency, amount, from, to) - -- `currency` Currency -- `amount` Amount to transfer -- `from` Sender -- `to` Recipient - -> No return value -> Transfers assets between two accounts - -Example: - -```js -app.balances.transfer('XAS', '100000', 'AC3pinmvz9qX9cj6c7VrGigq7bpPxVJq85', 'A4MFPoF3c9vCzZ3GGf9sNQ3rDy2q8aXuVF') -``` - -## 3 Data model - -### 3.1 app.model[name] - -- `name` Model name - -> Returns an instance of the model - -### 3.2 fields() - -> Returns all fields of the model - -```js -app.model.Article.fields() -/* output: -[ - 'id', - 'tid', - 'authorId', - 'timestamp', - 'title', - 'url', - 'text', - 'tags', - 'votes', - 'comments', - 'reports' -] -*/ -``` - -### 3.3 count(cond) - -- `cond` Query condition - -> Returns a `Number` -> The total number of data items that match the specified condition. - -Example: - -```js -app.model.Block.count({ height: { $lt: 100 } }) -/* output: -99 -/* -``` - -### 3.4 exists(cond) - -- `cond` Query condition - -> Returns a `Boolean` -> Indicates whether the data item for the specified condition exists. - -Example: - -```js -app.model.Transaction.exists({ id: '9a5ec0669c79b9f5a1d5a4dbb2c200bc28c9ea829dbff71f41cbb2ad5a7d9b01' }) -/* output: -false -/* - -app.model.Account.exists({ nickname: 'Nakamoto' }) -/* output: -true -*/ -``` - -### 3.5 findOne(options) - -`options` Is an object that has the following properties: - -- `condition` Query conditions -- `fields` The field that should be returned - -> Query data items for a specified condition. - -Example: - -```js -app.model.Account.findOne({ nickname: 'Nakamoto' }) -/* output: -{ - address: 'AC3pinmvz9qX9cj6c7VrGigq7bpPxVJq85', - nickname: 'Nakamoto', - ...other values -} -*/ -``` - -### 3.6 findAll(options) - -`options` Is an object that has the following properties: - -- `condition` Query condition -- `fields` Fields to return -- `sort` Fields to sort after -- `limit` The maximum number to return -- `offset` Offset - -> Query all data items for the specified condition - -Example: - -```js -app.model.Transfer.findAll({ senderId: 'AC3pinmvz9qX9cj6c7VrGigq7bpPxVJq85'}) -/* output: -[ - { - tid: "50e062f25946d220b924cb5ec6e52e260e44c9417d9f3c8ea041b704e06895f7", - senderId: "AFnwUuET2XddPtqpFb2ns78CQEqc7KZ6vD", - recipientId: "asdasdasd", - currency: "CCTime.XCT", - amount: "100000000", - t_timestamp: 38660145, - t_type: 3, - t_height: 93953 - }, - { - tid: "f15ce92add809b4a132936d514dce7fa7bdc15e850e7c026a001625b48595af3", - senderId: "AFnwUuET2XddPtqpFb2ns78CQEqc7KZ6vD", - recipientId: "asdasd", - currency: "CCTime.XCT", - amount: "100000000", - t_timestamp: 38660096, - t_type: 3, - t_height: 93948 - } -] -*/ -``` - -## 4. Routing - -- `path` Path -- `handler` Http Request Handler (async) - -### 4.1 app.route.get(path, handler) - -> Register a `get` type `http` request handler - - -Example: -```js -// file-name: interface/index.js -// Access this API endpoint with a GET call to `http://localhost:4096/api/dapps//articles` - -app.route.get('/articles', async (req) => { - - let articles = await app.model.Article.findAll({ - limit: 50, - offset: 0, - sort: { timestamp: -1 } - }) - - return articles -}) - -``` - -### 4.2 app.route.post(path, handler) - -> Register a `post` type `http` request handler - -### 4.3 app.route.put(path, handler) - -> Register a `put` type `http` request handler - -## 5. Cost pool - -### 5.1 app.feePool.add(currency, amount) - -- `currency` Currency -- `amount` Amount - -> No return value -> The specified asset (currency) is added to the fee pool (the amount is evenly distributed to all accountants at the end of each round). - -Example: - -```js -app.feelPool.add('XAS', '10000000') -``` - -## 6. Increment ID - -The creation of a table `articles` (with primary key id) results into the creation of a variable `article_max_id`. This new variable can be incremented. - -Example: -```js -// file-name: model/article.js -module.exports = { - name: 'articles', - fields: [ - { - name: 'id', - type: 'Number', - not_null: true, - primary_key: true - } - ] -} -``` - -![alt](./assets/dapp/dapp_variables_article_max_id.png) - -### 6.1 app.autoID.get(name) - -- `name` Id Type - -> Returns a `String` -> Get the highest Id of a type - -Example: -```js -const aid = 'article_max_id' -app.autoID.get(aid) === '0' // true -``` - -### 6.2 app.autoID.increment(name) - -- `name` Id Type - -> Returns a `String` -> Increment the Id of the specified type by 1 and return the updated value as a string. This is equivalent to the `++i` operation in javascript. - -Example: - -```js -const aid = 'article_max_id' -app.autoID.get(aid) === '0' -app.autoID.increment(aid) === '1' -app.autoID.get(aid) === '1' -``` - -## 7. Logging - -### 7.1 app.logger.setLevel(level) - -Example: -```js -app.logger.setLevel('debug') -app.logger.setLevel('info') -``` - -### 7.2 app.logger.log() - -Example: -```js -app.logger.log('hello') -``` - -### 7.3 app.logger.trace() - -Example: -```js -app.logger.trace('hello', 'world'); -``` - -### 7.4 app.logger.debug() - -Example: -```js -app.logger.debug('hello %s', 'world', 123) -``` - -### 7.5 app.logger.info() - -Example: -```js -app.logger.info('hello %s %d', 'world', 123, {foo:'bar'}) -``` - -### 7.6 app.logger.warn() - -Example: -```js -app.logger.warn('hello %s %d %j', 'world', 123, {foo:'bar'}) -``` - -### 7.7 app.logger.error() - -Example: -```js -app.logger.error('hello %s %d %j', 'world', 123, {foo:'bar'}, [1, 2, 3, 4], Object) -``` - -## 8. Tools - -### 8.1 app.validate(type, value) - -- `type` The datatype that should be verified -- `value` Data value which will be verified - -> Verify that a data is matches the specification. If not, throw an exception. - -Example: - -```js -app.validate('amount', '10000') // pase -app.validate('amount', 10000) // throws -app.validate('amount', 'abc') // throws -app.validate('amount', '1e10') // throws - -app.validate('string', title, { length: { minimum: 5, maximum: 256 }}) -app.validate('string', image, { length: { minimum: 15, maximum: 256 }}) -app.validate('string', image, { url: { schemes: ["http", "https"] }}) -app.validate('string', desc, { length: { minimum: 1000, maximum: 4096 }}) -``` - -### 8.2 app.registerContract(type, name) - -- `type` Contract Type -- `name` The name of contract - -> No return value -> To register a number type for a contract, an unregistered contract can not be called externally - - -Example: - -```js -app.registerContract(1001, 'cctime.postArticle') -``` - - -The string `'cctime.postArticle'` means, that they must be a `cctime` file in the `contract` directory and in the `cctime` file a function named `postArticle`. - -![alt](./assets/dapp/cctime_file.png) - - -### 8.3 app.getContractName(type) - -- `type` The type or the number of the contract - -> Get the contract name for a specified type - -Example: - -```js -app.getContractName(1001) === 'cctime.postArticle' -``` - -### 8.4 app.registerFee(type, min, currency) - -- `type` The type or the the number of the contract -- `min` Minimum cost -- `currency` Currency - -> The minimum fee for a contract registration -> `Min` stands for the minimum cost. The fee to call the contract. The fee can not be less then `min`. The fee can be greater. The execess part will be send to the fee pool. - -Example: - -```js -app.registerFee(1001, '100000', 'XAS') -``` -### 8.5 app.getFee(type) - -- `type` The type or number of the contract - -> Get the specified fee for a contract - -Example: - -```js -app.getFee(1001) -/* output: */ -{ - min: '100000', - currency: 'XAS' -} -``` - -### 8.6 app.setDefaultFee(min, currency) - -- `min` Minimum cost -- `currency` Currency - -> Set default fee for all contracts in the system. - -Example: - -```js -app.setDefaultFee('10000', 'XAS') -``` - -### 8.7 app.getRealTime(epochTime) - -- `epochTime` The number of seconds since the creation of the block. - -> Returns a timestamp which is the time of the block creation plus the offset in milliseconds -> Asch systems timestamp is not a real timestamp. It is timespan. You can call this function to get a real timestamp - -Example: - -```js -app.getRealTime(4353634) -``` - -### 8.8 app.registerHook - -##### 8.8.1 beforeCreateBlock - -> The callback `beforeCreateBlock` can be used to execute code before a new block gets created. This callback is executed before each block. - - -Params Properties: - -|Name |Type | Description | -|------ |----- |---- | -|height|number | Get the upcoming block height.
code: `modules.blockchain.blocks.getLastBlock().height + 1` | -|pointId|string |block-id of the corresponding block in the mainchain
e.g. `802231c4798740e12bf702bd88fbb41b5b93c709e75abedc585b7813f11c76ce` | -|pointHeight |number |block-height of the corresponding block in the mainchain
e.g.`2847` | -|slotTime |timestamp |time in which the sidechain-block and the mainchain-block was created. The timestamp is in epoch-time e.g. `62551620`
See [8.7 app.getRealTime(epochTime)](#87-appgetrealtimeepochtime) for details | -|signTransaction |method |Parameters: object with the following properties
__type:__ Smart contract Number e.g. 1000
__fee:__ The fee of the smart contract
__args:__ a JSON stringified array with parameters for the smart contract | -|addTransactions |method |Parameters: array of signed transactions
Usually the result from multiple calls to `params.signTransaction` | - - -Simple Example: -```js -// file-name. init.js - -module.exports = async function () { - app.logger.info('enter dapp init') - - app.registerHook('beforeCreateBlock', async (params) => { - // action - }) -} -``` - - -Advanced Example: Delete tweet-like message after certain block height -```js -// file-name: model/tweet.js -module.exports = { - name: 'tweets', - fields: [ - { - name: 'id', - type: 'Number', - not_null: true, - primary_key: true - }, - { - name: 'tid', - type: 'String', - length: 64, - not_null: true, - unique: true, - index: true - }, - { - name: 'creator', - type: 'String', - length: 50, - not_null: true, - index: true - }, - { - name: 'timestamp', - type: 'Number', - not_null: true, - index: true - }, - { - name: 'title', - type: 'String', - length: 128, - not_null: true - }, - { - name: 'message', - type: 'String', - length: 256, - not_null: true - }, - { - name: 'endingBlockHeight', - type: 'BigInt', - not_null: true - } - ] -} -``` - -```js -// file-name contract/tweet.js -module.exports = { - tweet: async function (title, message, endingBlockHeight) { - app.validate('string', title, { length: { minimum: 5, maximum: 128 }}) - app.validate('string', message, { length: { minimum: 20, maximum: 256 }}) - app.validate('amount', endingBlockHeight) - - let tweetId = app.autoID.increment('tweet_max_id') - app.sdb.create('Tweet', { - id: tweetId, - tid: this.trs.id, - creator: this.trs.senderId, - timestamp: this.trs.timestamp, - title: title, - message: message, - endingBlockHeight: endingBlockHeight - }) - }, - deleteTweet: async function (tweetId) { - // only delegates can delete tweets - if (app.meta.delegates.indexOf(this.trs.senderPublicKey) === -1) { - return 'Permission denied' - } - await app.sdb.del('Tweet', { id: tweetId }) - } -} -``` - -```js -// file: interface/tweet.js -app.route.get('/tweets', async (req) => { - - let tweets = await app.model.Tweet.findAll({}) - - return tweets -}) -``` - -```js -// file-name init.js - -async function deleteTweets (params) { - app.logger.info(`current sidechain block height: ${params.height}`) - - // load all tweets that should be closed - let tweetsToClose = await app.model.Tweet.findAll({ - condition: { - endingBlockHeight: { - $lt: params.height - 1 - } - } - }) - - if (!tweetsToClose.length) { - return - } - app.logger.info(`closing ${tweetsToClose.length} tweets`) - - let transactions = tweetsToClose.map((tw) => { - return params.signTransaction({ - type: 1001, - fee: '0', - args: JSON.stringify([tw.id]) - }) - }) - - await params.addTransactions(transactions) -} - - -module.exports = async function () { - app.logger.info('enter dapp init') - - // register contract: 'fileName.functionName' - app.registerContract(1000, 'tweet.tweet') - app.registerContract(1001, 'tweet.deleteTweet') - - app.setDefaultFee('0', 'XAS') - - app.registerHook('beforeCreateBlock', deleteTweets) -} -``` - - -### 8.9 app.custom[] - -> The application's namespace can be used to save some of the application's own custom global variables, mainly to isolate system-wide global variables - -This namespace can be used for example for a custom cache implementation - -Example: Create custom cache implementation - -```js -// file-name: lib/interval-cache.js -class IntervalCache { - constructor(interval) { - if (!Number.isInteger(interval)) throw new Error('Invalid interval') - this.interval = interval - this.container = new Map - setInterval(() => { - this.container.clear() - }, interval) - } - has(key) { - return this.container.has(key) - } - set(key, value) { - this.container.set(key, value) - } - get(key) { - return this.container.get(key) - } -} - -module.exports = IntervalCache -``` - -Register own custom cache implementation: -```js -// file-name: init.js -const IntervalCache = require('./lib/interval-cache') - -module.exports = async function () { - app.logger.info('enter dapp init') - - app.registerContract(1000, 'cctime.postArticle') - app.registerContract(1001, 'cctime.postComment') - app.registerContract(1002, 'cctime.voteArticle') - app.registerContract(1003, 'cctime.likeComment') - app.registerContract(1004, 'cctime.report') - - app.setDefaultFee('10000000', 'CCTime.XCT') - - // set cache - app.custom.cache = new IntervalCache(10 * 1000) -} -``` - -Use cache: -```js -// file-name: interface/index.js - -app.route.get('/articles/:id', async (req) => { - let id = req.params.id - let key = 'article_' + id - - // check cache - if (app.custom.cache.has(key)) { - return app.custom.cache.get(key) - } - let article = await app.model.Article.findOne({ - condition: { id: id } - }) - if (!article) throw new Error('Article not found') - if (article.reports >= 3) throw new Error('Article not allowed') - let account = await app.model.Account.findOne({ - condition: { address: article.authorId } - }) - if (account) { - article.nickname = account.str1 - } - let result = { article: article } - - // set cache - app.custom.cache.set(key, result) - return result -}) - -// ommitted further api endpoints... -``` - -### 8.10 app.meta - -> Returns object -> With `app.meta` you can access meta-information about your dapp, like name, which delegates are responsible etc... - -Warning: -This information is not available in `init.js`, because it is not loaded yet. - -`app.meta` has following properties: - -|Name |Type | Description | -|------ |----- |---- | -|name |string |The name of the dapp.
e.g. asch-dapp-cctime| -|description |string |The description of the dapp.
e.g. Decentralized news channel | -|tags |string|A comma seperated list of tags that categorize this Dapp
e.g. asch,dapp,demo,cctime | -|link |url|The link to the .zip archive of the source code.
e.g. https://github.com/AschPlatform/asch-dapp-cctime/archive/master.zip | -|type | | | -|category |number |Identifies an dapp category
e.g. 1 | -|icon |url|An URL to the dapp icon
e.g.http://o7dyh3w0x.bkt.clouddn.com/hello.png| -|delegates |array |An array of the public keys of the delegates | -|unlockDelegates |number | | -|transactionId |string |The mainchain-transaction in which this dapp was registered
e.g. f30b85cff0d57d949ee84950bf59dbfbeebc369c0287cd6ea3f3d7501994a42a | - -Example: Use `app.meta` to allow access to a smart contract only to the dapp delegates - -```js -// file-name: contract/tweet.js - -module.exports = { - deleteTweet: async function (tweetId) { - // only delegates can delete tweets - if (app.meta.delegates.indexOf(this.trs.senderPublicKey) === -1) { - return 'Permission denied' - } - await app.sdb.del('Tweet', { id: tweetId }) - } - - // other functions ommitted -} -``` diff --git a/docs/asch_whitepaper.md b/docs/asch_whitepaper.md deleted file mode 100644 index cd185bf..0000000 --- a/docs/asch_whitepaper.md +++ /dev/null @@ -1,265 +0,0 @@ -title: 白皮书 ---- -# 0 引言 - -比特币的出现使得去中心化的货币系统成为可能,经过几年的发展,人们发现比特币背后的区块链技术潜力巨大,可以被广泛应用在各行各业。为了更好地利用区块链技术,出现了以以太坊为代表的一批应用平台,它们封装了底层协议、建设了基础设施,为开发者提供了更加友好、也更加灵活的接口,使得开发者的关注点能够集中在业务逻辑上,很大程度上提高了开发效率。本文提出的 asch 系统也是一种去中心化应用的开发平台,接下来我们会详细阐述这一系统的特色、原理及应用场景。 - -# 1 概述 - -## 1.1 去中心化应用 - -去中心化应用是一种具有以下特点的应用。 - -1. 必须完全开源,自主运行,不能被中心化的组织、机构或个人操控,可以被改进以响应市场需求,但必须经过用户们的共识。 - -2. 数据必须被安全、公开、冗余的存储在一个分布式网络中,以避免被篡改和单点故障。 - -3. 应用访问者需要消耗令牌,而应用贡献者可以获得令牌的奖励。 - -4. 应用必须使用一种价值证明的密码学算法来生成令牌。 - - 去中心化应用可以通过授权系统的权益人来投资应用的开发,从而有潜力达到自给自 - -足。去中心化应用还有公开透明、安全可靠、去信任等优点。因此,可以想像去中心化应用在支付、数据存储、云计算、电子商务等领域将有非常可观的前景,它所产生的价值甚至有可能会超过 visa、dropbox、亚马逊等跨国公司的市值。 - -## 1.2 侧链是什么 - -区块链是一串使用密码学方法相关联产生的数据块,每一个数据块中包含了若干网络交易的信息,用于验证其信息的有效性(防伪)和生成下一个区块,对于普通用户来说它就像一个公有账本,记载所有的交易记录,对于开发者来说可以理解为一个分布式的数据库。区块链这个数据库的特点是去中心化、开放、自治、不可篡改,区块链与去中心化应用息息相关,非常适合为去中心化应用提供存储功能。 - -侧链是一种特殊的区块链。它使用一种叫做“SPV 楔入”的技术实现与其他区块链之间的资产转移,这使得用户能用已有的资产来使用新的加密货币系统。人们不必再担心比特币难于采纳创新和适应新需求,只要创造一个侧链,然后对接到比特币的区块链中即可,通过继承和复用比特币强大的区块链,还避免了新货币的流动性短缺和市场波动等问题。并且由于侧链是一个独立的、隔离的系统,侧链中出现的严重问题只会影响侧链本身,这极大地降低了创新的风险和成本。 - -## 1.3 Asch 是什么 - -Asch 是一个去中心化的应用平台。它提供了一系列的 sdk 和 api 来帮助开发者构建基于 Javascript 和侧链技术的去中心化应用。Asch 通过提供定制侧链、智能合约、应用托管等一体化的行业解决方案,致力于打造一个易于使用、功能完备、即插即用的系统。利用 Asch 生态系统,开发者可以快速迭代他们的 Javascript 应用,并发布到系统内置的应用商店中,这些应用可以被平台中的分布式节点下载并执行,并服务于普通用户,整个过程都由诚实安全的 Asch 侧链共识网络提供安全保证。 - -Asch 系统本身也是一个完全开放的、去中心化的应用,内置有代币,单位为 XAS,中文名叫阿希币。阿希币可以通过双向楔入的方式与侧链或 dapp 进行交互,作为所有 - -dapp 之间资产转换的桥梁和媒介,这些代币将在系统发布之前以 ico 的方式预售给投资人。系统一旦发布,Asch 最初的核心团队将不再掌控系统的走向,只有系统的权益人和代币的拥有者决定系统将来的发展。 - -## 1.4 Asch 面向哪些用户 - -Asch 平台除提供一些基本服务外,还将提供技术和工具上的支持,主要面向以下群体: - -### 1.4.1 开发者 - -开发者可以根据 Asch 平台的应用开发规则和商业行为准则,并按照相关的规范进行开发和提交 dapp。Dapp 的商业模式或免费,或定价销售,或按增值服务付费。采用何种商业模式完全由开发者决定。 - -### 1.4.2 企业 - -Asch 平台提供的工具可以非常容易地创建一个完整的区块链,更重要的是可以楔入到Asch 平台的主链或者比特币的区块链中,实现与成熟电子货币的对接,这对中小型企业,特别是初创企业是非常有吸引力的。 - -中小企业可以通过区块链技术提供原本封闭在企业内部、互联网内部的信息和数据,甚至与监管机构的相关系统数据相互链接,增强透明度,以此树立良好的形象,赢得投资者、金融机构的信任度,顺利拿到融资或项目合同等。 - -中小企业主动公开和开放资料,已成无法阻挡的趋势。因为现在有很多的公开渠道来获取数据,中小企业已经越来越难隐瞒它们不想让外界知道的信息。我们可以大胆预测,在未来区块链将是帮助中小企业发展的重要武器。 - -### 1.4.3 普通用户 - -普通用户可以通过 Asch 内置的应用商店进行下载、安装和使用去中心化应用,这跟手机平台的应用商店是类似的模式。Asch 系统支持多种类型的去中心化应用,普通用户在消费这些应用的同时,还可以通过贡献内容来获得收益。开发者与普通用户将共同组成一个繁荣的生态系统。 - -# 2 设计理念 - -## 2.1 完备脚本 vs 侧链 - -比特币为人称道的一个设计上的亮点就是它的脚本引擎。基于这套脚本引擎,不但可以实现普通的转账功能,还可以实现多方签名、抵押担保、博彩等智能合约应用。但是出于安全和实现难度的考虑,比特币的脚本系统设计的较为简陋,做了非常多的限制,比如它不支持循环、脚本长度受限、只支持几种标准的的交易类型。 - -以太坊的最大特色就是极大地扩展了这个脚本引擎的功能,加入了读取区块链、计费、跳转等新指令,还解除了栈内存、函数调用深度以及脚本长度限制等。以太坊自称他们的脚本语言达到了图灵完备,利用这样的脚本,开发者可以实现几乎任何可以用数学方式表述的功能。 - -自以太坊以来,扩展脚本成为了一种实现去中心化开发平台的流行方式,但这种方式有一个很大的缺点就是,应用代码本身及应用产生的数据都存在同一个区块链中,造成了区块链的快速膨胀。以太坊试图通过优化和压缩区块和交易本身来延缓这种膨胀,也只是一种治标不治本的方法。此外,基于脚本实现的应用之间是共享同一个账本的,像区块产生时间等参数是无法被定制的,这无疑限制了应用的个性化。 - -侧链机制是通过另一个维度实现扩展性的,每个侧链运行在不同的分布式节点网络中,有独立的受众、投资人和开发团队。这种天然的分片解决方案,不但解决了区块链的膨胀问题,而且每个应用都拥有一套个性化的账本,其共识机制、区块参数、交易类型都是可以被定制的,所以我们认为侧链与完备交易脚本相比,是一种成本更低、更加灵活、也更加易用的解决方案。 - -## 2.2 账户 vs UTXO - -在比特币及其衍生系统中,是没有一个所谓的账户来存储用户的余额的,用户的余额是通过整个系统的交易状态转换来实现的。这里要引入一个术语,UTXO(unspenttransaction outputs),即未花费的交易输出。每个 UTXO 都有一个面值和所有者,一笔交易包括一个或多个输入和一个或多个输出。每个输入包含一个对现有 UTXO 的引用和由与所有者地址相对应的私钥创建的密码学签名,如果一个用户拥有这个私钥,那么他就可以消费这个 UTXO 对应的币值,也就是说一个用户的余额就是他所有拥有的所有私钥对应的 UTXO 的币值总和。UTXO 主要优点是高度的私密性,用户可以为每一笔交易生成一个新的地址,从而使得用户无法被追踪,这对于货币来说是好事,但对于各式各样的dapp 来说,就未必了。账户相对于 UTXO 来说,有以下几个优点: - -1. 节省空间。举例来说,如果某个用户有 5 个 UTXO,需要的存储空间是(20 + 32 +8)* 5 = 300 字节(其中 20 字节为地址,32 字节为交易号,8 字节为交易额),而账户仅需要 20+8+2=30 字节(20 字节位地址,8 字节位余额,2 字节为随机数)。 -2. 利于监督。账户的存在使得电子货币很容易被区分,因为我们只要知道这些币来自哪些账户即可。 -3. 简单、易于编码和理解。 -4. 常量级引用。轻客户端能以常数时间访问一个用户的账户任意数据,而在 UTXO 系统中,每当有交易发生时,数据引用将发生变化。 - -Asch 平台本身并不是一个纯粹的货币系统,要容纳各种各样的应用,综合比较起来,账户对于我们来说是一种更好的选择。 - -## 2.3 关系数据库 vs 非关系数据库 - -目前大多数的区块链系统都选择使用模型较简单的非关系数据库来存储数据,比如berkeley db,leveldb 等,这些数据库一般都提供一些简单的数据结构,比如 btree、hashtable、queue 等,它们一般不支持 SQL 对数据进行操作,虽然这些数据库对于一般的电子货币系统来说足够了,但对于应用平台来说是远远不够的,特别是对于金融、银行、电子商务等领域,目前主流的存储系统都是采用了关系数据库,因为关系数据有以下几个优点: - -1. 事务处理; -2. 数据更新开销非常小; -3. 可以进行 join 等复杂查询。 - -我们选择的 sqlite 是一种性能极佳的轻量级嵌入式关系数据库,容量最高支持 2T,数据文件可在不同字节序机器之间自由共享,特别是对 SQL 的支持,将为 dapp 开发者提供极大的便利。 - -# 3 系统特点 - -## 3.1 易用 - -### 3.1.1 开发语言 - -开发者可以使用 javascript 语言以及海量的 npm 库来构建他们的应用。相对于比特币的 c++语言及栈式脚本、以太坊的新语言 solidity,javascript 流行度更高、受众更广、上手更容易的一门语言。此外,关系数据库的加入也是 Asch 系统的一大特色,使得去中心化的应用开发模式与传统 web 应用的开发模式已经非常相近了。Asch 平台的应用开发门槛可以说是同类产品中最低的。 - -### 3.1.2 工具 - -Asch 系统提供了一个命令行工具,只需要根据提示输入一些配置项,就可以快速的建立一个侧链,并可在侧链上开发任意类型的应用。其次,系统还提供了一系列的 api 帮助用户构建复杂的智能合约应用,这些 api 涵盖共识、强随机数、数据库、密码学等方面。 - -### 3.1.3 部署 - -开发者只需要把自己的 dapp 提交到 github,然后在 web 钱包或轻钱包中注册,就完成了部署的工作,之后 dapp 将被显示在应用商店中被用户下载和使用。 - -## 3.2 灵活 - -开发者可以随意定制其侧链的各项参数,比如区块产生速度、交易类型、交易费等等,甚至可以实现一个新的共识机制,比如开发者可以使用权益证明或工作量证明的共识机制来取代默认的委托人权益证明机制。 - -## 3.3 安全 - -Asch 系统的一大亮点是使用了一个增强 DPOS 的共识算法,在 DPOS 的基础上加入了一个高效的实用拜占庭容错算法,极大地降低了网络分叉的可能性,只要不超过 1/3 节点联合做恶,系统就不会分叉,也就没有双重支付的风险。其次,系统在一些小的细节方面也是尽量从安全角度进行了考量。比如采用 BIP39 标准算法的口令助记符、二级交易密码、多重签名账户等。 - -# 4 技术细节 - -## 4.1 共识机制 - -Asch 系统采用的共识机制是基于 DPOS 的,也是使用了委托人选举的制度,但是在算法的后半部分采用了一个优化后的 PBFT 算法变种,这个算法可以在 t < n / 3 时,以O(n^2)消息复杂度,O(1)的时间复杂度使忠诚的节点达成一致,不会分叉,其中 t 表示拜占庭节点(即可能发生任意行为的节点,比如网络延迟、停机、恶意攻击等等)的个数,n 表示所有节点的个数。 - -### 4.1.1 委托人选举 - -Asch 系统的委托人选举制度与 DPOS 是类似的,核心系统是由 101 个委托人节点组成,委托人是被社区选举的可信账户,得票最高的 101 个委托人负责生产区块。得票排名未进入前 101 名的账户被称为候选人,当他们将来获得足够多的选票并进入前 101 名后,将成为正式的委托人。 - -每个 Asch 用户都有权利投票给最多 101 位委托人,选票的权重是由用户持有的 XAS数量决定。 - -每一个选举周期产生 101 个区块,每一次投票和委托人排名的变化将体现在下一个周 - -期。每个区块产生的间隔时间是 10 秒,新创建的区块会被广播到网络中并添加到区块链中。每当新的区块被添加到区块链中,该区块之前的所有交易的确认次数加一,得到 6 个确认后,可以认为交易是安全的,如果数额较小的交易,可以允许更小的确认次数,相反,数额较大的交易可以通过增加确认数来保证安全性。 - -如果有少数委托人发生故障,比如被攻击或者宕机,就会错失区块,这会被记录在案,这将影响该节点的在线率,进而影响社区的投票。因此委托人的竞选是需要严肃对待的,委托人应当由有一定网站运营经验的人来做,委托人要保障自己节点的稳定性,并以此促进整个系统的安全和稳定。 - -### 4.1.2 拜占庭容错 - -Asch 系统与 DPOS 的不同主要体现在算法的后半部分。 - -DPOS 采用的方法是,首先对当前 round 的委托人列表进行随机的排序(保证每一轮的委托人顺序不同,也无法预测下一轮委托人顺序),然后通过 round-robin 的方式依次让每个委托人创建区块。这个算法的主要缺点是,如果某个委托人节点叛变了,他可能会广播多个不一致的区块,这些区块间可能包括双重支付交易,导致整个网络被分叉了。当然,如果只有一个委托人叛变的话,这个分叉很快就可以通过下一次最长链同步的方法来消除,但是随着叛变节点的增加,消除分叉的时间将越来越长,少量节点的联合叛变将严重影响系统的安全性,即使一个交易达到 6 次确认,也很可能是不安全的。 - -为了解决这个问题,我们引入了 PBFT(Pratical Byzantine Fault Tolerance)算法。PBFT 算法也是使用 round-robin 的方式选择委托人,但是选出委托人后并不立即创建区块,而是首先发起一个提议(propose),这个提议的目的是确定下一次区块的 hash。当超过 2/3 的节点都赞成该提议时,才接受由提议人创建的的下一个区块,下一个区块的 - -hash 必须与当前 round 达成共识的区块 hash 一致。从本质上来说,PBFT 算法的加入解决了委托人权利滥用的问题,使得委托人的记账能力更为可控。 - -## 4.2 侧链与 dapp - -Asch 系统提供了一个命令行工具,可以用来轻松创建一个基础的侧链系统,侧链的开发者也可以深度定制自己的侧链,侧链拥有自己的数据库、共识机制、交易类型以及账户体系。侧链可以托管在独立的委托人节点集群中,这就自然形成了一种分片的机制,延缓了主区块链的膨胀。 - -每一个 dapp 对应一个侧链,侧链的核心逻辑使用 nodejs 开发,界面部分可以使用任意前端技术,比如 qt,html,javascript 等等,前端与后端之间一般通过 json rpc 协议通讯。Dapp 的作者或者所有者可以跟踪自己的 dapp 被使用的情况,加密货币是基于社区的共识,但 dapp 更像是一家私人拥有的公司。Dapp 内的交易是由主节点处理的,主节点是由 dapp 所有者运行的,dapp 所有者必须拥有一个 Asch 帐号,这个帐号类似多重签名的帐号,它的主要任务是在 dapp 主节点创建共识并签名新的区块,如多重签名钱包。一旦一个新的 dapp 区块被创建,并且在主节点内被签名,这个区块需要被计算出SHA256 哈希,然后 dapp 所有者提交这个哈希值给 Asch 区块链,然后存储该哈希值为dapp 区块,一旦 Asch 区块链收到一条包含 dapp 哈希值的交易,由受托人对比这条哈希值与上一个啥希值,并将它保存到 Asch 区块链,在未来,当主节点同步网络,用户将通过 Asch 区块链来验证所有 dapp 区块,想从 Asch 区块链中移走上一个 dapp 区块将是不可能的事情。相同的功能,以比特币区块链来替代 Asch 区块链将同样适用,API 在比特币区块链上工作的方式是一样的,通过比特币区块链来保证 dapp 的安全性。开发者可以使用 XAS 和 BTC 来做为其 dapp 的货币,使用 dapp 时可能需要存入或者取出资金,当 Asch 或者 BTC 被发送到 dapp 的地址时,资金会在其 dapp 的帐户内出现,用户便可在 dapp 内使用该资金,BTC 和 Asch 的存入方式是一样的,都是发送到 dapp 的特定地址,然后资金就会出现在 dapp 帐户内。Dapp 的帐户都是由 dapp 的作者创建的,所有存入的 Asch 或者 BTC 都将被存储在这个地址内,考虑到安全性,只推荐使用了多重签名可信任的签名者的 dapp 帐户。从 dapp 取款是由主节点负责处理的,当有人发送一条取款请求,dapp 主节点就会处理它并且把资金从 dapp 的地址上移出到 Asch 区块链上,或者比特币区块链上。开发者可以在他们自己的 dapp 里面发行令牌,而且使用此令牌做为该 dapp 的流通货币,这些令牌在该 dapp 内可像 XAS 或者 BTC 一样使用,但是它不能直接从一个 dapp 转移到另一个 dapp,他们必须通过 Asch 主链来转移。 - -## 4.3 沙箱和 VM - -沙箱是一种按照安全策略限制程序行为的执行环境。早期主要用于测试可疑软件等,比如黑客们为了试用某种病毒或者不安全产品,往往可以将它们在沙箱环境中运行。经典的沙箱系统的实现途径一般是通过拦截系统调用,监视程序行为,然后依据用户定义的策略来控制和限制程序对计算机资源的使用,比如读写磁盘等。 - -Asch 系统使用了 nodejs 的 vm 模块实现沙箱机制。VM 模块是对 javascript 的 v8引擎的封装,可以用来执行纯粹的 javascript 代码,但无法使用系统层的 api,比如文件系统、网络传输相关的模块,并且由于没有 require 函数,第三方库也没法轻易导入进来,甚至无法进行模块化开发,这就需要 dapp 的开发者使用 browserify 的技术将常用的第三方库打包成一个 js 文件,Asch 的主链系统才能加载并运行。对于一些必须的系统级api,则通过进程间通讯的方法为侧链提供,这样兼顾了安全性与功能的完备性。 - -## 4.4 交易 - -Asch 系统内建了一个交易抽象层,核心系统的几乎所有功能都是建立在交易上的,比如转账、投票、应用商店、充值、提现等。侧链本身也可以实现自己的不同类型的交易。交易之间的区别主要是交易类型和 asset。基础交易的数据结构如下,扩展部分会根据类型的不同分别存在不同的 asset 表中。 - -```sql -Transaction { -required VARCHAR(20) id; -required VARCHAR(20) blockId; -required TINYINT type; -required INT timstamp; -required VARCHAR(21) senderId; -optional VARCHAR(21) recpientId; -required BIGINT amount; -required BIGINT fee; -required BINARY(64) signature; -optional BINARY(64) signSignature; -optional TEXT signatures; -required BINARY(32) senderPublicKey; -} -``` - -以投票交易举例来说, votes 实体通过交易 id 来关联到一个基础交易中。 - -```sql -Asset_Votes { -required VARCHAR(20) transactionId; -optional TEXT votes; -} -``` - -## 4.5 账户系统 - -Asch 的每个账户由一个口令、一对公私钥、一个地址组成。用户还可以额外设置一个二级密码。注意这里与比特币有所不同的是,每个账户仅对应一个地址,而比特币中每个钱包对用多个地址和私钥。 - -口令(passphrase)是符合 BIP39 标准的用于产生确定性钱包的助记符。这种助记符与二进制或十六进制字符相比对人类记忆更友好。口令的生成方式是将一个 32bit 倍数长度的熵转换成若干个单词,Asch 系统选择的熵长度为 128bit,将转换成 12 个单词。口令作为一级密码,由用户保管,不对外公开,一旦丢失用户将失去对应账户的所有权。口令形式如下: - -``` -barely decline dust stamp protect color certain cup arena busy latin shell -``` - -**密钥对**包括公钥和私钥,是以口令的`sha256` 哈希做种子,再通过 `ed25519` 爱德华兹曲线签名算法生成的。形式如下: - -``` -公钥: -9989388b220a13465e49f52df5ba28ba08eb1e7a973320347f9687a107dc2f -9a - -私钥: -91e891f653e3ed0232d8c7de2e72b625d50d48593fc0fb570c0db25c5e4456 -9a9989388b220a13465e49f52df5ba28ba08eb1e7a973320347f9687a107dc -2f9a -``` - -账户地址是取公钥的 `sha256` 哈希的前 8 位,逆序后转换成 bignumber,其形式如下 - -``` -5034187504202890358 -``` - -## 4.6 客户端 - -Asch 系统将提供三种客户端程序。 - -完整版客户端是针对超级用户、委托人和开发者的最佳解决方案,它可用于windows,Mac OS 以及 linux,但它只允许 linux 运行受托人节点。 - -轻钱包的用户可以通过连接到完整版钱包以连接到网络,也可以直接调用 API,但前提是完整版钱包的所有者有开放该 API 权限,完整版钱包会通过点对点网络,从其它完整版钱包节点下载完整的区块链。 - -普通用户将主要使用轻钱包来管理自己的 Asch 帐户,它是一个精简版的 Asch 钱包,轻钱包支持 windows 和 Mac OS,它无需安装,它使用的是内嵌式的浏览器,它无法作为网络节点,因为它不下载区块数据,它只通过 http 连接到其它的节点,这样做能带来几点好处。首先它不下载区块数据,这意味着它会一直保持着较小的体积,不占容量;其次它不向网络广播密钥,所有数据在本地设计上签名,可以做所有类型的交易,如果你想运行一个受托人节点,你可以使用轻钱包注册一个受托人帐号,但你无法使用轻钱包来运行受托人节点来创建区块,为了运行受托人节点,你需要下载完整版钱包,并运行在 linux 上。Dapp 用户可以使用轻钱包来管理已安装的 dapp。Dapp 的 API 和节点的API 也可供开发人员调用,这使得开发人员可以使用 Node.js 快速且简单地创建javascript dapp。 - -移动版客户端允许用户通过移动终端来操作自己的 Asch 帐户,它将提供 ios 与安卓两种版本,并于苹果应用商店和安卓应用商店提供下载。它的后端将基于我们的桌面版的解决方案,与桌面版的区别将在于移动版钱包界面将使用响应式技术,自适应移动终端屏幕,并根据移动设计调整了一些交互方式。该 APP 使用了专为移动终端定制了易用的界面,类似于 bitcoin 和一些常用的银行类 app 的界面,而且它将支持在内部运行所有你喜爱的 dapp。 - -## 4.7 性能 - -一笔交易信息通过优化和压缩后大概占 100 字节,我们算算系统达到 1 万 tps 时候需要消耗的带宽。因为出块间隔为 10 秒,那么每次出块需要包含 10 万个交易,也就是说要包含 10M 字节的交易数据,这 10MB 的数据需要在 10 秒内广播到全网,按最理想情况下,第一跳广播到 10 个节点,第二跳广播至 100 个节点,每一跳要在 5 秒内传输完毕,服务器需要的带宽是 10MB * 10 / 5 = 20MB,考虑到中间的带宽损耗和非理想情况,我们认为至少要 40MB 的带宽才能够满足 1 万 tps 的吞吐量。这个带宽要求显然不低,但是相信 1 万 tps 给委托人带来的收益远大于网络维护的费用。2014 年双十一支付宝的吞吐量峰值达到了 8.59 万每秒。Asch 系统在交易吞吐量方面还是有优化空间的,这也是将来我们的重点要投入的方向。 - -# 5 应用场景 - -## 5.1 令牌系统 - -使用 Asch 工具创建的第一个 hello world 应用,就是一个最基本的令牌系统了。 - -开发者可能不需要编写代码,只要在 genesis.json 文件里修改一些创世参数,就可以发布一个令牌系统了。Asch 系统中的令牌与以太坊的子货币一样,可以表示黄金、股票、抵押物、或任意其他资产,这些令牌可以与转入侧链中的 XAS 通过去中心化的方式进行交易,从而实现流通,也可以在中心化的交易所与其他货币进行交易。 - -## 5.2 仲裁合约 - -假设一个买家想跟一个不认识的人进行交易,一般情况下如果交易顺利进行的话,双方都不希望有第三方介入,但是如果某个环节出了问题,比如买家对商品不满意时,他们就希望有一个中间人来做调解。这个中间人可能会要求买卖双方出示一些证据,然后做出判决,比如把钱退还一部分给买家。这个业务流程如下: - -1. 买卖双方共同选择一个中间人 -2. 买家使用三方的公钥创建一个 2-3 的多重签名账户,然后转账到这个账户,再以该账户为发起人,以卖家的账户为接收人,签署一个交易并发布出去。此时这个交易是不能立即被确认的,只有 3 个人中的 2 个人共同签名,才会生效。 -3. 卖家发货给买家。 -4. 如果买家收到货物后,检查没问题,使用自己的私钥对刚才的交易进行签名。然后卖家再次签名后,交易就顺利完成。 -5. 如果买家对货物不满意,可以向中间人发起申诉并出示证据,卖家也可以出示证据,最终由中间人与买卖其中的一方达成一致,共同签署,完成交易,结束仲裁。 - -## 5.3 去中心化交易所 - -根据是否支持法币,可以分为两种程度的去中心化。如果不支持法币,可以实现完全的去中心化,如果支持法币,则只能实现半去中心化,即法币通过网关出入,但交易信息公开。 - -完全的去中心化交易所又分为两种,一种是点对点的交易,通过 Asch 系统提供的“原子跨链交易 api”来实现。另一种是挂单交易,挂单交易要求卖方从其他区块链转入一定的资产到 Asch 侧链中,这个转入操作通过父链冻结资产的 SPV 证明达成。此外,由于关系数据库的支持,利用联表查询和索引功能,可以很容易的实现一个效率不错的撮合引擎。 - -## 5.4 存在性证明 - -存在性证明可以用于登记文件版权、专利等,其基本原理是将要存储的文件的哈希值存入到 Asch 的侧链中,以此来证明某个特定文件存在,还可以加上时间戳、当事人的数字签名等元数据,来证明他们是在何时持有这些文件的。这些信息无法伪造、无法篡改,不会暴露数据和隐私,在需要的时候随时可以验证且不依赖第三方机构。 - -## 5.5 物联网 - -物联网中存在海量的联网设备,很难有一个中央机构来管理所有的设备和各节点的身份。Asch 的侧链是一个很好的解决方案,首先,它解决了节点间信任问题,设备间彼此相连形成分布式网络,通过共识算法来保证设备间交易的合法,并且可追踪、可审查、可分析。其次,不同种类的设备可以接入不同的侧链,这是我们前面提到的天然分片机制,避免了总账本的爆炸式增长。我们试想下,在一个基于区块链的物联网中,一个自动售货机不但可以监控和报告它自身的存货,还可以通过分析历史交易数据智能地从分销商那里进行招标并自动完成付款。 - -# 6 总结 - -Asch 是一个去中心化的应用平台,其设计初衷是为了降低开发者的门槛,比如使用javascript 作为应用编程语言,支持关系数据库来存储交易数据,使得开发一个 dapp 与传统的 web 应用非常相似,相信这对开发者和中小型企业有很大的吸引力,只有开发者的生产力提高了,整个平台的生态才能够更迅速的繁荣起来。Asch 在设计上也是开放的,并没有局限于某个细分领域,比如金融、文件存储、版权证明等,其提供的 api 都是较底层和抽象的,它们可以被自由组合实现各种不同的应用。在共识机制方面,Asch 继承并增强了 DPOS 算法,大大降低了分叉几率和双重支付风险。另外,Asch 的侧链即应用模式不但延缓了区块链膨胀问题,还使得 dapp 更加的灵活和个性化。Asch 是一个具有前瞻性的、低成本的一站式应用解决方案,相信将成为新一代去中心化应用的孵化器。 \ No newline at end of file diff --git a/docs/asch_whitepaper_de.md b/docs/asch_whitepaper_de.md deleted file mode 100644 index 24600c0..0000000 --- a/docs/asch_whitepaper_de.md +++ /dev/null @@ -1 +0,0 @@ -Bitte besuchen Sie die offizielle Webseite um das englisprachige Whitepaper zu lesen. [Whitepaper (eng)](https://www.asch.so/asch-whitepaper-en.pdf) diff --git a/docs/asch_whitepaper_en.md b/docs/asch_whitepaper_en.md deleted file mode 100644 index f32f381..0000000 --- a/docs/asch_whitepaper_en.md +++ /dev/null @@ -1,164 +0,0 @@ -title: Whitepaper ---- -# Introduction -Since Bitcoin was introduced in 2009 and had been rapidly developing for these several years, people found that Bitcoin has more potential than just be a kind of electronic currency. Especially blockchain, the underlying technology of Bitcoin, has the unlimited capacity even more valuable than Bitcoin itself. The blockchain technology can be applied in the development of different kinds of application, which have the same characteristic that is decentralization. The emerging of these decentralized applications also promotes a new application architecture, which is based on an open-source platform. Based on this concept, we propose the Asch system, a development platform for decentralized applications. -# Overview -## Decentralized Application -Decentralized application has following features: -1. The application must be completely open-sourced. It must be run under the control of itself, which means it should not be tampered by any centralized organization, institution or individual. It can be revised to reflect the market requests, but has to be recognized by all users. -2. The application data should be stored in a distributed network that has to be secure, open, and redundant, in order to avoid data manipulation and single node failure. -3. Application users need tokens to access, and application contributors can get tokens as rewards. -4. The application must apply a value-proved cryptographic algorithm to generate tokens. -The decentralized application can make the stakeholder to invest in the development of it by granting them the privilege in it so that it becomes possible to be self-sufficient. These kinds of application also have the advantages such as publicity, security, and trustless. Therefore, it is not strange that decentralized applications will play a vital role in following fields: payment, data store, cloud computing, e-business, and etc., and it is even possible that the value created by those applications will exceed the market value of giant international company such as VISA, Dropbox, or Amazon. -## About Sidechain -A blockchain is a well-ordered collection of data blocks generated by using cryptographic algorithm. Each block of data contains an amount of network transaction information which is used to validate the authenticity, as well as generate the next block. To a normal user it looks like a public ledger on which every single transaction will be recorded, and to an -application developer it looks like a distributed database, which features decentralization, open, self-autonomy, and harden against tampering. The blockchain presents a very tight relationship with decentralized application which makes it very suitable for store these applications. -As a specific blockchain, the sidechain applies a “SPV (simplified payment verification) Pegged” technology to achieve the goal that the user’s asset can be transferred from one blockchain to another, which means users can use their current assets to utilize the new cryptocurrency system. There will be no need to worry about the disadvantage of Bitcoin that is hard to adapt the innovation and meet the new request. What need to be done is just create a sidechain and link it to the main blockchain of Bitcoin. By inheriting and reusing the powerful blockchain of Bitcoin, other issues such as liquidity shortage and market fluctuation, often occurred when a new currency is introduced, can be averted. Furthermore, since the sidechain is a isolate individual system, any severe failure will only impact the sidechain itself instead of the whole blockchain, thus significantly reduce the risk and cost of innovations. -## About Asch Platform -Asch is a decentralized application platform, providing a series of SDK and API to help developers creating decentralized applications based on JavaScript and sidechain technology. By providing a whole set of industry standard solutions including customized sidechain, -smart contracts, application hosting, and etc., Asch intends to offer an easy-to-use, fully functional and plug & play ecosystem, by which developers can rapidly iterate their JavaScript applications, and easily deploy them into application store built in the system. These application can be smoothly downloaded and executed by every node and user located in everywhere of this ecosystem. The whole process will be secured by the Asch sidechain consensus network. -On the other hand Asch itself is also a fully opened, decentralized application, which has its own cryptocurrency known as Asch coin. Asch coin is capable of interfacing with sidechain or any decentralized application (DAPP) through “two-way peg” mechanism so that it can be the bridge or media for the asset transition among all DAPPs, and to achieve that purpose, the Asch coin will be sold to the investors through ICO (initial coin offering) before the deployment of the system. Once an Asch system is published, it will not under the control of the core development team, but the stakeholders of the system and the owners of Asch coin. -## Who Should Use Asch Platform -Apart from some basic services, Asch platform also provides technology and toolkit support, whose main target audiences are as follow: -### Developers -Developers can create and deploy DAPP in Asch platform by following the criteria of application development and business activities. The business model of these DAPPs may be free or fixed price, or pay with value added service. It is all up to the developers themselves. -### Enterprises -The tools provided by Asch platform can be used to easily create a complete blockchain, and more importantly, this blockchain can be pegged into main chain of Asch platform or even the blockchain of Bitcoin, thereby connected with well-developed electronic currency. It is a very attractive feature that is suitable for small and medium enterprises (SMEs) especially start-up companies. -SMEs can utilize blockchain technology to provide the information and data that were enclosed inside companies or Internet in the past, and to connect with the system data owned by authority so that they can promote the business publicity and improve the companies’ image. Consequently more trustiness can be brought to the investors and financial institutions to make it easy to get the funds or contracts. -It is inevitable for SMEs to public their business information. SMEs found it is difficult to prevent social community to know their secrets. Therefore we can assume that blockchain will play a vital role in SMEs everyday business activities. -### End users -Individual users can download, install and use numbers of decentralized applications through Asch built-in app store, which is similar with application store in current smart phone. Asch system supports different kinds of decentralized application on which end users can make profit by contributing the program or content. It is possible for developers and users to create a vivid ecosystem together. -# Design Rationale -## Turing-Completeness Scripting vs Sidechain -The scripting engine is a highlight in design of Bitcoin on which not only can transfer the currency but can realize the smart contracts such as multi-signature, escrow and arbitration, and gambling. Bitcoin’s scripting system, however, applies a concise design setting a series of limitations due to the consideration of security and difficulty of implementation, for example, it cannot support loop, or must strict the length of its scripts, or only supports limited numbers of standard transactions. -The most attractive characteristic of Ethereum is that it significantly expands the scale of functionality of this scripting engine. In detail, Ethereum adds several instructions such as reading blockchain, charging, jumping, etc., as well as releases the limitation of the invoke depth of stakes and functions, and length of the script. Ethereum claims that its scripting engine is Turing-completeness by which developers can carry out almost any computation that can be represented by mathematic model. -Although with Ethereum, expanding script became a prevail approach of decentralized application platform, it still has one disadvantage that cannot be ignored: the application itself and the data generated by it have to be stored in the same blockchain, which makes the blockchain grows extremely rapidly. Ethereum tried to slow this trend down by optimizing or compressing the program code and data, but still cannot solve the problem completely. Moreover, since those applications based on scripting have to share the same ledger, some parameters, i.e., created-time of blockchain, cannot be changed, which prevents developers from customizing the application. -Sidechain mechanism, in contrast, deals with scalability in another way. Every sidechain is running in a different distributed network node, having separate users, investors and development team. This partition-like solution has resolved the blockchain expansion problem, and has made every application has its own ledger, on which the consensus mechanism, blockchain parameter, and transaction mode can be customized. For this reason, we believe sidechain mechanism is a lower-cost, more flexible and easier to use solution -than a Turing-completeness transaction scripting. -## Account vs UTXO -Within Bitcoin and derived systems, there is no so-called “account” to save the user’s balance. The balance has to be dealt with by the status transition of the whole transaction system’s status. Let’s introduce a new term, UTXO, standing for unspent transaction outputs. Every UTXO has its own nominal price and its owner and each transaction has multiple -inputs and outputs. Each input includes a reference of current UTXO and a cryptographic signature generated by private key related to owner’s address. If a user own this private key, he/she can consume the value of this UTXO, in other words, the balance this user has is the sum of the currency value of all the UTXO related to the user’s private keys. The main advantage of UTXO is high level security, which means the user can generate a new address for each of his/her transaction so that he/she cannot be traced. It is a great thing for a currency involved transaction, but to variety of DAPPs, it is not sure. Compare to UTXO, account has following benefits: -1. Space efficiency. For instance, it will take a user 300 bytes space when he/she has 5 UTXOs: (20+32+8) x 5 = 300 bytes (20 bytes for address, 32 bytes for transaction No., -and 8 bytes for transaction amount). Meanwhile if using account, the storage space will be limited to 30 bytes: 20+8+2=30 bytes (in this case, 20 bytes for address, 8 bytes for balance, and 2 bytes for random number). -2. Easy to monitor. Due to the account, the electronic currencies are easy to recognized, since all we have to know is the account that the currency is coming from. -3. Simple, easy to code and understand. -4. Referring in a fixed time. A lightweight client can access all the data in a user’s account -in a fixed time, while with UTXO system, the access time will change every time once there is a transaction. -Asch platform is not a pure currency system because it has to contain various applications. In general, account mechanism is a better option under this circumstance. -## Relational Database vs Non-relational Database -At present most blockchain system choose to use lightweight non-relational databases, such as Berkeley DB, LevelDB, and so on. Usually these kinds of database support some simple data structures, like B-tree, hashtable, and they are not able to manipulate data through SQL. Generally non-relational database is good enough at the application of electronic currency system, but speaking of application platform, it is not the case, especially when we talk -about finance, bank, e-commerce and so no. Within these fields, the relational database is wildly used because of its following advantages: -1. Transaction processing -2. Very low cost of data updating -3. Capability of complex query (using join, for example) -We decide to adopt SQLite, a high-performance lightweight embedded rational database. SQLite can support up to 2T data volume, and the data file can be shared smoothly among different byte order machines. The most attractive feature is SQL, which is very suitable for DAPP developers. -# System Highlights -## Ease of Use -### Development Language -Developers can use JavaScript and numerous npm libraries to create their application. Unlike C++ and transaction script for Bitcoin and new Solidity for Ethereum, JavaScript is more popular, has more followers, and is easier to master. Furthermore, by introducing relational database, Asch platform make decentralized application development more like coding -traditional web application, hence it become the easiest way among all the current development approaches. -### Toolkits -Asch system provides a command-line tool to rapidly create a sidechain on which any kind of applications can be created and deployed. Also the system provides a series of API, involving consensus mechanism, strong random number, database, and cryptography, to help users creating complex smart contract applications. -### Deployment -To deploy the applications, all the developers need to do is committing their DAPPs onto Github, and registering in web wallet or light wallet. After that DAPPs will be presented in App store to download. -## Flexibility -Developers can freely customize all parameters in their sidechain, such as generating speed of block, transaction type, and transaction fee, etc., even can carry out a new consensus mechanism. -## Security -One well-known highlight of Asch system is an consensus algorithm based on improved DPOS, in detail, the system embedded a high-performance Byzantine fault tolerance algorithm upon original DPOS hence significantly reduce the possibility of network forks. As long as there is no more than 1/3 nodes which are attempting to attack together, the system will not generate a separate chain, or a fork, so that the risk of double payment will be avoided. Secondly, Asch system closely examined every detail with security consideration, such as passphrase hint based on BIP39 algorithm, two level trading password, and multi-signature, etc. -# Technique Specification -## Consensus Mechanism -The consensus mechanism used by Asch system is based on DPOS, a mechanism of delegates vote, but applied an optimized variant algorithm of PBFT, which can make loyal nodes reach an agreement, i.e., not fork, in O(n^2) message complexity and O(1) time complexity when t < n/3. Here “t” refers to the number of Byzantine node (on which any situation can happen, such as network delay, machine shutdown, or malicious attacks) and “n” refers to the number of all nodes. -### Delegates vote -The delegates vote mechanism of Asch is similar with the one of DPOS, which is composed of 101 delegate nodes. A delegate is a trustful account voted by community, and 101 delegates who have the most votes are allowed to running the nodes which maintain the network and generate the blocks. Those accounts who cannot be the top 101 are called “candidates”, who can be delegate once they get enough votes to become the top 101. -Every Asch user has the right to vote up to 101 delegates, and the weights of vote is determined by the amount of XAS owned by this user. -Each voting round will generate 101 blocks, and the ranking change of each voting and delegates will be shown in the next round. The new block will be generated in 10 seconds after the previous one, and then be broadcasted into network and appended in the blockchain. Once new block is added, the confirmation count of all transactions before will be increased 1 time. After gaining 6 confirmations, a transaction can be treated as “safe”. If the amount of transaction is small, less confirmation count is allowed. In other words, larger confirmation count is necessary when it is a large transaction to improve the security. -If some failures occurred in a few delegates, such as under attacks or shutdown, the block will miss, and this issue will be recorded. This problem has an impact on the online rate of this node hence the voting of community. Therefore the election of delegate should be treated solemnly, for example, a delegate needs to have experience on running a website, ability to maintain the nodes stable, so that the security and stability of the whole system will be strengthened. -### Byzantine Fault Tolerance -The major difference between Asch system and DPOS is reflected in the second part of the algorithm. -What the DPOS applied is, first, randomly sorting the delegate list of current round (to make sure the delegate of next round cannot be predicted since the order of delegate of each round will be different), then let delegates create block in turn through a round-robin way. The main issue of this algorithm is that, if a delegate attempt to attack, he may broadcast many different blocks, which may contact double payment trades, to “fork” the whole network. It is no doubt that if only one delegate betrays, the fork will be solved by syncing with the next longest chain. However, it will take a much longer time to eliminate betrayed nodes as their amount is increasing. A few betrayed nodes are enough to have a serious impact on system security, which means even we can gain 6 confirmations, it still may not be sure that the network is safe. -To deal with this problem, we introduced an algorithm known as PBFT (Practical Byzantine Fault Tolerance). Same as DPOS, PBFT also chooses delegates in the way of round-robin. The different part is there will not be a block generated after delegates are voted. In fact, there will be a piece of propose issued to determine the hash code of next block. Only when more than 2/3 of all nodes agree with this propose, next block will be generated. The hash of next block must be the same as that agreed with all delegates of current round. Essentially, the introduction of PBFT solved the issue of abusing the delegates’ right, and improved the control capability of ledgers. -## Sidechain and DAPP -Asch system provides a command tool by which developers can easily create a basic sidechain system. Developers are also able to fully customize their sidechain system, including its own database, consensus mechanism, trading mode and account architecture. Sidechain system can be hosted in the clusters of nodes of individual delegates, so that a partitioned mechanism can be naturally generated hence avoid the rapid expansion of the main blockchain. -Every DAPP is related to a sidechain. A sidechain’s core code is developed by nodejs, but UI can be programmed by any of front-end techniques such as QT, HTML, or JavaScript. The communication between front-end and back-end is usually implemented under JSON RPC protocol. The developer or owner of a DAPP can trace the usage of their application. Compare to cryptocurrency that is based on community consensus, DAPPs are more like a private company. All the transactions within a DAPP are handled by main node, which is run by DAPP’s owner. The owner of DAPP must have an Asch account, like a multi-signature account, whose major objective is to create a consensus of a new block and to sign it in DAPP’s main node, just like multi-signature wallet. Once a new DAPP is created, and signed in main node, the SHA256 hash of this block need to be calculated, and submitted to the main blockchain of Asch system as a DAPP block by the owner of it. When Asch’s main blockchain received information of a trade including DAPP hash, the delegate will compare it with the previous one and then store it into Asch blockchain. Then lately when main node is in sync with network, the user will validate all DAPP blocks through Asch blockchain, which means it is impossible to remove the previous DAPP block from main blockchain. Developers can replace Asch blockchain with Bitcoin blockchain to use the same functionality since the usage of Asch API will be the same. The security of DAPP can also be guaranteed by Bitcoin blockchain. Developers can take advantage of both XAS and BTC as the currency of their DAPP. In the case of money in-and-out when using a DAPP, the Asch coin or BTC will be delivered to a DAPP address, and appropriate amount of money will be shown in that DAPP’s account, ready to use. The deposit mechanisms of both BTC and Asch are the same, which is to deliver to a particular DAPP address, and then the appropriate amount will be shown in -the account. In every DAPP the account is created by the developer, so all deposited BTC or Asch coin will be saved in related address. Considering the security, only those DAPP accounts owned by trustable signers with multi-signature are recommended. A withdrawal from DAPP is main node’s responsibility. When someone requests a withdrawal of money, DAPP main nodes will acquire the request and move the money from DAPP address to Asch blockchain or Bitcoin blockchain. Developers are allowed to issue a token in their own DAPP, and to use it as the currency of this DAPP. These kinds of token can be circulated in DAPP like XAS or BTC, but are not allowed to transfer from one DAPP to another directly but through Asch main blockchain. -## Sandbox and VM -Sandbox is a running environment that restricts program’s activities under the security policy. In early time it was used to test suspicious software, for example hackers usually use sandbox technique to run some virus or unsafe program. The implementation of a classic sandbox is usually to intercept the system calls, to monitor program’s activities, in order to control the usage of computer’s resource such as disk I/O according to user’s policy. -Asch system implemented sandbox mechanism by using VM module of nodejs. The VM module is an encapsulation of JavaScript V8 engine, which is used to run the pure JavaScript code. But it cannot use system APIs like file system or network communication. It also is lack of “require” function therefore the third-party libraries cannot be imported smoothly and even worse, the modular development cannot be conducted. This requires DAPP developers to use a “browserify” technique to bundle all the third-party libraries they used to a JavaScript file, so that Asch system can load it and run. Some necessary system level API will be provided to sidechain through IPC (Inter-Process Communication), which takes into account both security and functional completeness. -## Transaction -Asch system has built a abstract transaction layer, on which almost all the functionalities of system core are established, such as transferring, voting, application store, deposit, and withdrawal. The sidechain itself can also implement its own type of transaction. The main difference between each transaction is their types and assets. The data structure of a basic transaction is as follow, and the extension of transaction will be saved in different asset table according to its type. -```sql -Transaction { -required VARCHAR(20) id; -required VARCHAR(20) blockId; -required TINYINT type; -required INT timstamp; -required VARCHAR(21) senderId; -optional VARCHAR(21) recpientId; -required BIGINT amount; -required BIGINT fee; -required BINARY(64) signature; -optional BINARY(64) signSignature; -optional TEXT signatures; -required BINARY(32) senderPublicKey; -} -``` -Let us take a vote transaction as an example: the vote entity is connected to a basic transaction through transaction Id like follows: -```sql -Asset_Votes { -required VARCHAR(20) transactionId; -optional TEXT votes; -} -``` - -## Account System -Every account in Asch system consists of one passphrase, a pair of public/private key and an address. Users can also set their own secondary password. Note that the difference with Bitcoin here is that each account is related to only one address, instead of multiple addresses and private keys related to one wallet in Bitcoin. -Passphrase is a mnemonics used to produce real wallet in line with BIP39 standard. The mnemonics is much easier to remember for people than other binary or hexadecimal characteristics. The way in which a passphrase is generated is to convert entropy on a multiple of 32bit into several words, particular in Asch system, the length of entropy is 128bit and it will be converted into 12 words. The passphrase, as a top-level password, is maintained by users instead of published in public. Once users lost their passphrase they would lost the ownership of their account. A passphrase is generally like follows: -barely decline dust stamp protect color certain cup arena busy latin shell -A pair of keys includes public key and private key, which uses SHA256 hash of passphrase as seed and is generated through ed25519 Edwards-curve Digital Signature Algorithm (EdDSA). It looks like this: -``` -Public Key: -9989388b220a13465e49f52df5ba28ba08eb1e7a973320347f9687a107dc2f9a - -Private Key: -91e891f653e3ed0232d8c7de2e72b625d50d48593fc0fb570c0db25c5e44569a9989388b220a13465e4 -9f52df5ba28ba08eb1e7a973320347f9687a107dc2f9a -``` -The account address is a big number generated by reversely converting the first 8 bits of SHA256 hash of public key, shown as follows: -``` -5034187504202890358 -``` -## Client -Asch platform provides three types of clients: -The full version client is a perfect solution for those super users, delegates and developers, running on Windows, Mac OSX and Linux, but only Linux system can run delegate nodes on which blocks forging is enabled. -The lite wallet client allows users to connect network through full version wallet or API, but it is necessary to open all the right of this API by the owner of this full version wallet. A full version wallet can download the whole blockchain from other full version wallets through peer-to-peer network. -An ordinary user usually use lite wallet to manage his/her Asch account. The lite wallet can run on Windows and Mac OSX platform without installation. It utilizes the system built-in browser. It needs to be noted that the lite wallet cannot run as a network node since it would not download the blockchain data but only links with other nodes through HTTP protocol, which have several advantages: first, no blockchain data downloaded would keep the volume small; second, no private key broadcasted to network make it possible to make all types of trade since all the data will be signed locally. If you want to run a delegate node, you can use lite wallet to register a delegate account, but cannot run delegate node through it to produce block. In order to run it, downloading and running a full version wallet in Linux would be necessary. The DAPP users can take advantage of lite version wallet to manage installed DAPP. The APIs of both DAPP and node are available for developer to invoke, so that it can make them rapidly and easily creating JavaScript DAPP through Node.js. -The mobile version client allows users to manipulate their own Asch accounts on their mobile devices, both iOS and Android platform. They can download the client from AppStore or Google Play. The backend of the client is based on our solution applied in our desktop version, but mobile client applies responsive UI instead to fit the mobile device screen and changes some interface mode according to the device characteristics. This mobile -application brings mobile user-friendly interface, like Bitcoin or some major bank application, and of course, the mobile client can also support all the DAPP you like running inside of it. -## Performance -All the information of a transaction usually occupies about 100 bytes. Let us calculate how much network bandwidth will it be demanded when system achieve 10,000 TPS. Since the interval of block production is 10 seconds, each block needs to carry 100,000 transactions, which make the volume become 10 megabytes. This 10 MB data needs to be broadcasted to whole network, so even under the best situation, 10 nodes will be achieved in the first step, and then 100 nodes in the next step, and each step is supposed to complete in 5 seconds, which makes the necessary bandwidth be 10MB x 10 /5 = 20 MB. Considering the bandwidth loss and unexpected circumstance, we think that bandwidth needs to be at least 40 MB to satisfy the 10,000 TPS throughput. Although this volume of bandwidth is not easy to gain, it can be sure that it will bring much more benefit to delegates than the cost. In Nov 11, 2014, the peak throughput of Alipay payment system reached 85900 per second. There is still possibility for optimization of trade throughput in Asch system, which is our major investment in the future. -# Scenarios -## Token System -The “hello world” program generated by Asch toolkit would be a basic token system. -Developers may not need to write even a line of code but adjust some initial parameters in genesis.json, to publish a token system. Like sub-currency on top of Ethereum, the token in Asch system can represent gold, stock, mortgage, or any other type of asset. These tokens can be traded with XAS transferred in sidechain in a decentralized way, and with any other currencies in a centralized exchange. -## Mediatory Contract -Let us assume that a buyer wants to trade with a person he/she does not familiar with. Generally if the trade is well-doing, both would not hope the interference from a third-party. But if there is any issue occurred during the procedure, like the buyer does not satisfy with the items, they would like a mediator to help solving the problem. The mediator will ask both sides to present some evidences and then make a decision, for example, ask seller making a refund. This business process can be described as follows: -1. Both the buyer and seller of the transaction choose a mediator together. -2. The buyer creates a 2-3 multi-signature account by using a public key shared with all the -three parties. Then the buyer transfers the money into this account, then signs and -publishes a transaction in which the buyer’s account and seller’s one are treated as promotor and recipient respectively. At this moment this transaction would not be confirmed immediately until two of these three people have signed. -3. The seller dispatches the item to the buyer. -4. If the buyer received the item and satisfy with it, he/she will sign the transaction with -his/her private key. After that when the seller sign the transaction again, it will be -completed successfully. -5. If the buyer does not satisfy with the item, he/she can launch a complaint to the -mediator and show evidences about the item with faults. Then the seller also can show evidences against buyer’s one. Finally the mediator would make an agreement with one of the two sides of trade and sign this trade together to complete it. -## Decentralized Exchange -There are two types of decentralization according to legal currency support. If legal currency is not supported, the full decentralization can be realized; otherwise only half decentralization would be supported. In this case, legal currency can circulate through gateway but transaction information would be made public. -Full decentralized exchange can still be divided into two types: one is peer-to-peer trade through “atomic cross chain exchange API”. The other one is pending order, which require seller transfer an amount of asset to Asch sidechain from other blockchain. This moving should be achieved by the SPV proof of frozen assets of main chain. Beside, with the support of relational database, it is easy to create a well performance matching engine by using union-table query and index. -## Existence Proof -Existence proof is used to register copyright, patent and so on, which is based on the idea that to prove an existed particular file by saving hash code of this file into Asch sidechain. In addition we can add metadata such as timestamps, owners’ digital signatures to prove when they own these files. This kind of information cannot be forged or revised, will not expose the privacy data and ready to verify at any time without any third-party authority. -## IoT (Internet of Things) -There are numerous of online devices existed in IoT, which make it difficult to manage all the devices and identification of every nodes by a single authority. Asch sidechain is an excellent solution for it. Firstly, it can deal with trustiness among different nodes. It means that all devices connect to each other to be a distributed network, and trade between devices can be verified by consensus algorithm, and can be traced, audited, and analyzed. Secondly, different types of devices can be connected to different side chains, and this natural partition mechanism that we mentioned above can prevent main ledger from explosive -increment. Let us imagine that a vending machine in a sidechain based IoT can not only monitor and report its own stock, but also analyze historic trading data to select suppliers to submit the tender, and then automatically complete payment. -# Conclusion -Asch system is a decentralized application platform, which is designed to lower the threshold for developers, such as using JavaScript as develop language, supporting relational database to save transaction data, and making DAPP development be similar with traditional Web application. It is sure that these characteristics are very attractive to developers and SMEs. The ecosystem of the whole platform cannot be improved until developers make a huge progress on productivity. Also, Asch platform is designed to be open for various fields, not limited to some particular parts such as finance, file storage, or copyright proof. It provides underlying and abstract API which can be combined freely to create different types of applications. In consensus mechanism, Asch inherits and enhances DPOS algorithm, by which the possibility of forks and risk of duplicate payments would be significantly reduced. Furthermore, Asch sidechain mode not only can mitigate the pressure of blockchain expansion, but also make DAPP more flexible and personal. Asch system, as a proactive, low-cost and full stack solution, will surely be a next generation incubator of decentralized applications. \ No newline at end of file diff --git a/docs/assets/dapp/cctime_file.png b/docs/assets/dapp/cctime_file.png deleted file mode 100644 index ef35ecd..0000000 Binary files a/docs/assets/dapp/cctime_file.png and /dev/null differ diff --git a/docs/assets/dapp/custom_api_example.png b/docs/assets/dapp/custom_api_example.png deleted file mode 100644 index f2974c6..0000000 Binary files a/docs/assets/dapp/custom_api_example.png and /dev/null differ diff --git a/docs/assets/dapp/dapp_variables_article_max_id.png b/docs/assets/dapp/dapp_variables_article_max_id.png deleted file mode 100644 index ba034e1..0000000 Binary files a/docs/assets/dapp/dapp_variables_article_max_id.png and /dev/null differ diff --git a/docs/assets/forging-secret.png b/docs/assets/forging-secret.png deleted file mode 100644 index 9c4aba0..0000000 Binary files a/docs/assets/forging-secret.png and /dev/null differ diff --git a/docs/assets/inbuilt-modules.png b/docs/assets/inbuilt-modules.png deleted file mode 100644 index 8e84271..0000000 Binary files a/docs/assets/inbuilt-modules.png and /dev/null differ diff --git a/docs/assets/process-structure.png b/docs/assets/process-structure.png deleted file mode 100644 index d414e36..0000000 Binary files a/docs/assets/process-structure.png and /dev/null differ diff --git a/docs/assets/sidechain-deploy.png b/docs/assets/sidechain-deploy.png deleted file mode 100644 index 32ec1ce..0000000 Binary files a/docs/assets/sidechain-deploy.png and /dev/null differ diff --git a/docs/assets/win_install/gcc.png b/docs/assets/win_install/gcc.png deleted file mode 100644 index 2dae362..0000000 Binary files a/docs/assets/win_install/gcc.png and /dev/null differ diff --git a/docs/assets/win_install/gcc_verify.png b/docs/assets/win_install/gcc_verify.png deleted file mode 100644 index 7dc91fc..0000000 Binary files a/docs/assets/win_install/gcc_verify.png and /dev/null differ diff --git a/docs/assets/win_install/install.png b/docs/assets/win_install/install.png deleted file mode 100644 index 3d26ab7..0000000 Binary files a/docs/assets/win_install/install.png and /dev/null differ diff --git a/docs/assets/win_install/node.png b/docs/assets/win_install/node.png deleted file mode 100644 index cfd47c1..0000000 Binary files a/docs/assets/win_install/node.png and /dev/null differ diff --git a/docs/assets/win_install/python.png b/docs/assets/win_install/python.png deleted file mode 100644 index 336dcb6..0000000 Binary files a/docs/assets/win_install/python.png and /dev/null differ diff --git a/docs/assets/win_install/run.png b/docs/assets/win_install/run.png deleted file mode 100644 index 28d49f1..0000000 Binary files a/docs/assets/win_install/run.png and /dev/null differ diff --git a/docs/assets/win_install/sqlite3.png b/docs/assets/win_install/sqlite3.png deleted file mode 100644 index c128bac..0000000 Binary files a/docs/assets/win_install/sqlite3.png and /dev/null differ diff --git a/docs/assets/win_install/sqlite3_verify.png b/docs/assets/win_install/sqlite3_verify.png deleted file mode 100644 index 7cd4303..0000000 Binary files a/docs/assets/win_install/sqlite3_verify.png and /dev/null differ diff --git a/docs/assets/win_install/win10.net.png b/docs/assets/win_install/win10.net.png deleted file mode 100644 index 03fc623..0000000 Binary files a/docs/assets/win_install/win10.net.png and /dev/null differ diff --git a/docs/dapp_docs/1_hello.md b/docs/dapp_docs/1_hello.md deleted file mode 100644 index 646459e..0000000 --- a/docs/dapp_docs/1_hello.md +++ /dev/null @@ -1,316 +0,0 @@ -# Dapp开发教程一 Asch Dapp Hello World - -## 1 基本流程 - -Asch有三种网络类型,分别是localnet,testnet,mainnet,后两种是发布到线上的,可通过公网访问。下面对这三种网络做一个介绍: - -- localnet:运行在本地的、只有一个节点(101个受托人都配置在本地的config.json文件中)的私链,主要是为了方便本地测试和开发。locanet就是私有链。 -- testnet:Asch链公网测试环境,由多个服务器组成,具备完整的p2p广播、分布式存储等,在功能上跟mainnet一致,和mainnet的区别在于magic不同(可以理解为用于区分不同链的id,目前Asch testnet的magic为594fe0f3,mainnet的magic为:5f5b3cf5) -- mainnet:Asch主网正式环境,这上面的XAS Token会在各大交易平台进行交易。 - - - -Dapp的开发同样要涉及到这三种网络,即 - -- 第一步,在localnet开发、本地调试 -- 第二步,在testnet测试 -- 第三步,正式发布到mainnet,其他节点可以安装 - -## 2 启动localnet - -每个开发者都可以在本地启动自己的localnet,需要先下载[asch源码](https://github.com/AschPlatform/asch)。 - -``` -> git clone https://github.com/AschPlatform/asch.git -``` - -下载后就可以参照该项目的[README](https://github.com/AschPlatform/asch/blob/master/README.md)进行后面的安装、运行操作。 - -## 3 安装asch-cli -建议用nvm安装node和npm -``` -# Install nvm -curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash -# This loads nvm -export NVM_DIR="$HOME/.nvm" -[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" -[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion - -# Install node and npm for current user. -nvm install node 8 -# check node version and it should be v8.x.x -node --version -``` - -``` -> npm install -g asch-cli -``` - -注意这一步不要用淘宝的```cnpm```, **有bug** - -## 4 在本地创建一个应用 - -首先要进入你的asch源码目录,并确保localnet启动(访问http://127.0.0.1:4096,如能打开钱包页面说明启动成功) - -``` -> cd -> npm install -> node app.js -``` - -### 4.1 创建你的受托人账户 - -每个dapp都有独立的受托人,这些受托人也是默认的记账人,他们负责区块的生产,跨链资产的中转,与此同时可以获得交易手续费。 -注册dapp的时候,我们只需要收集受托人的公钥就行,为了权力分散,最好每个秘钥分别由一个人保管。 -这里为了演示,我们一次性创建5个账户,一个dapp最多有101个受托人,最少是5个。 - -``` -// 注意这里的密码都是演示用途,且不可用于正式的dapp中 -> asch-cli crypto -g - -# 接下来输入 5 即可生成5个账户 -[ { address: 'AijfU9bAE6Jpt5ve7zG3LoriDamH67eLb', // 地址 - secret: 'easy snap cable harvest plate tone planet yellow spot employ humble what', // 主密码,也叫一级密码,可以生成公钥和地址,实质为私钥的助记词,必须记录下来 - publicKey: 'a437a1d4bedf738e8620920ef29542644e3366c635b16fc9faa6f5db744bcd5c' },// 公钥,用于4.2章节配置受托人公钥 - { address: 'ABGGUL5D2SoBaQTqDMAb3u9RdUjYBcmRxx', - secret: 'adjust edge exist hurry joke carbon spice envelope battle shuffle hawk thought', - publicKey: '522cdc822d3bec74aa5c4e972ed6cba84850f9c4d521e43fe08675e9e4759bb9' }, - { address: 'AMg37s4avDUojJd6d3df7HPA3vqtRRwved', - secret: 'survey spoil submit select warm chapter crazy link actual lonely pig grain', - publicKey: '6ee3ae36166f69e8b9408d277486c9870f40c1b7c16016328737d6445409b99f' }, - { address: 'AL5p8BHzhCU3e5pkjMYbcjUSz771MrQcQr', - secret: 'march struggle gap piece entry route kind pistol chunk spell honey summer', - publicKey: 'ad558e44b347a54981295fcb5ee163c2915ca03536496129103e9d72c5025d69' }, - { address: 'A2WassKticpB7cx15RZfenBekthwmqXRXd', - secret: 'response modify knife brass excess absurd chronic original digital surge note spare', - publicKey: '6b2594ebeee9b072087e5f1e89e5c41ee2d73eb788b63abeedf5c04664f0ce5b' } ] -``` - -## 4.2 生成应用模板 - -应用模板包括注册dapp必须的元信息、创世块以及一个初始的目录结构 - -生成应用模板需要使用`dapps`子命令,如下所示 - -``` -# 生成应用模板的时候,最好建立一个新目录 -> mkdir asch-test-dapp && cd asch-test-dapp -> asch-cli dapps -a -``` - -接下来,我们要回答一系列的问题,以生成应用的注册信息与创世块 - -``` -? Enter DApp name Asch-test-dapp -? Enter DApp description Demo of asch dapp -? Enter DApp tags asch,dapp,demo -? Choose DApp category Common -? Enter DApp link https://github.com/AschPlatform/Asch-test-dapp.zip -? Enter DApp icon url https://yourdomain.com/logo.png -? Enter public keys of dapp delegates - hex array, use ',' for separator //这里是4.1章节生存的5个受托人对应的公钥 -a437a1d4bedf738e8620920ef29542644e3366c635b16fc9faa6f5db744bcd5c,522cdc822d3bec74aa5c4e972ed6cba84850f9c4d521e43fe08675e9e4759bb9,6ee3ae36166f69e8b9408d277486c9870f40c1b7c16016328737d6445409b99f,ad558e44b347a54981295fcb5ee163c2915ca03536496129103e9d72c5025d69,6b2594ebeee9b072087e5f1e89e5c41ee2d73eb788b63abeedf5c04664f0ce5b -? How many delegates are needed to unlock asset of a dapp? 3 -DApp meta information is saved to ./dapp.json ... -? Enter master secret of your genesis account [hidden] -? Do you want publish a inbuilt asset in this dapp? Yes -? Enter asset name, for example: BTC, CNY, USD, MYASSET XCT -? Enter asset total amount 1000000 -? Enter asset precision 8 -``` - -有几个注意事项 - -1. `DApp link`是为了方便普通用户自动安装,必须以`.zip`结尾, 如果您的dapp不打算开源或者没有准备好,可以把这个选项当做占位符,它所在的地址不必真实存在 -2. `DApp icon url`这是在阿希应用中心展示用的应用图标, 必须以`.jpg`或`.png`结尾,如果该图片无法访问,阿希应用中心会展示一个默认的图标 -3. `How many delegates ...`这个选项表示从`dapp`跨链转账资产时需要多少个受托人联合签名,该数字必须大于等于3、小于等于你配置的受托人公钥个数且小于等于101,数字越大越安全,但效率和费用越高 -4. Dapp的创世块中可以创建内置资产,但不是必须的,内置资产无法跨链转账,只能在链内使用。在主链发行的UIA(用户自定义资产)可以充值到任意dapp中,也可从dapp提现到主链,这是dapp内置资产和UIA最大的区别。“一链多币,一币多链”指的就是主链可以发行多个UIA,而每个UIA都可以充值到多个dapp中。 - -## 4.3 注册应用到主链 - -注意这里的`主链`不是指`mainnet`, 每个`net`下都有相应的主链, 主链是相对Dapp(侧链)而言。 - -我们可以使用`registerdapp`注册应用到主链,如下所示 - -``` -// 先生成一个dapp注册账户 -// 注意这里的密码都是演示用途,且不可用于正式的dapp中 -> asch-cli crypto -g -? Enter number of accounts to generate 1 -[ { address: 'A9rhsV5xDny4G45gD2TXmFFpeiTfvAAQ7W', - secret: 'possible melt adapt spoon wing coyote found flower bitter warm tennis easily', - publicKey: '74db8511d0021206abfdc993a97312e3eb7f8595b8bc855d87b0dc764cdfa5a8' } ] -Done - -// 在http://127.0.0.1:4096用localnet的创世账户“someone manual strong movie roof episode eight spatial brown soldier soup motor”登陆(该账户中有初始发行的1亿xas token),然后给A8QCwz5Vs77UGX9YqBg9kJ6AZmsXQBC8vj地址转10000个xas - -> asch-cli registerdapp -f dapp.json -e "possible melt adapt spoon wing coyote found flower bitter warm tennis easily" -# 返回结果如下,这就是应用id。每个应用注册时返回的id不同,请记下你自己的应用id -0599a6100280df0d296653e89177b9011304d971fb98aba3edcc5b937c4183fb -``` - -使用浏览器访问`http://localhost:4096/api/dapps/get?id=0599a6100280df0d296653e89177b9011304d971fb98aba3edcc5b937c4183fb`, 可以查询到该dapp了,下面是返回信息 - -``` -{ - "success": true, - "dapp": { - "name": "asch-dapp-helloworld", - "description": "A hello world demo for asch dapp", - "tags": "asch,dapp,demo", - "link": "https://github.com/AschPlatform/asch-dapp-helloworld/archive/master.zip", - "type": 0, - "category": 1, - "icon": "http://o7dyh3w0x.bkt.clouddn.com/hello.png", - "delegates": [ - "a518e4390512e43d71503a02c9912413db6a9ffac4cbefdcd25b8fa2a1d5ca27", - "c7dee266d5c85bf19da8fab1efc93204fed7b35538a3618d7f6a12d022498cab", - "9cac187d70713b33cc4a9bf3ff4c004bfca94802aed4a32e2f23ed662161ea50", - "01944ce58570592250f509214d29171a84f0f9c15129dbea070251512a08f5cc", - "f31d61066c902bebc80155fed318200ffbcfc97792511ed18d85bd5af666639f" - ], - "unlockDelegates": 3, - "transactionId": "0599a6100280df0d296653e89177b9011304d971fb98aba3edcc5b937c4183fb" - } -} -``` - -## 4.4 部署应用代码及子网络 - -现在我们把4.2章节中创建的模板代码拷贝到asch的安装目录下的dapp子目录,并改名为dapp的id - -``` -> cp -r asch-test-dapp path/to/asch/dapps/0599a6100280df0d296653e89177b9011304d971fb98aba3edcc5b937c4183fb -``` - -然后把4.1章节创建的5个受托人密码写入这个dapp的配置文件中 - -``` -> cat path/to/asch/dapps/0599a6100280df0d296653e89177b9011304d971fb98aba3edcc5b937c4183fb/config.json -{ - "secrets": [ - "easy snap cable harvest plate tone planet yellow spot employ humble what", - "adjust edge exist hurry joke carbon spice envelope battle shuffle hawk thought", - "survey spoil submit select warm chapter crazy link actual lonely pig grain", - "march struggle gap piece entry route kind pistol chunk spell honey summer", - "response modify knife brass excess absurd chronic original digital surge note spare" - ] -} -``` - -这里我们把所有受托人的配置到同一个节点了,在生产环境中不推荐这样做,应该把秘钥尽量分散到多个节点,以防止单点故障。 -至此,dapp手工安装部署完成,开发调试阶段需要这样。等以后正式发布到mainnet后,其他节点只需要在钱包页面点击dapp就可以安装。 - -## 4.5 重启asch节点程序 - -``` -> ./aschd restart -``` - -使用浏览器打开`http://localhost:4096/dapps/0599a6100280df0d296653e89177b9011304d971fb98aba3edcc5b937c4183fb/`,可以访问默认的一个前端页面,该页面可以进行一些简单的接口测试 - -也可以观察dapp的日志来排查一些问题 - -``` -> tail -f path/to/asch/dapps/0599a6100280df0d296653e89177b9011304d971fb98aba3edcc5b937c4183fb/logs/debug.*.log -``` - -## 4.6 跨链充值 - -dapp的前后端通讯协议一般可以分为两大类:读和写。 -读指的是数据查询,比如内置的区块查询、交易查询、转账记录,以及自己定义和实现的一些查询接口。 -写指的是合约调用或事务执行,比如发起转账、设置昵称、提现等,同样,也包括其他的由开发者实现的各种合约或事务。 - -每一个写入操作都需要消耗燃料资产,模板dapp默认的燃料是XAS,开发者可以通过调用相关接口改为适合您的燃料类型,可以设置成任意其他资产,包括dapp内置资产。 -如果你您设置的燃料为外部资产,则需要从主链转入资产到这个dapp,这个过程叫充值,相反的过程叫做提现,这都是通过asch的跨链协议实现的。 - -充值有三种方式: - -1. 使用交互式的web图型界面,在【应用中心】的【已安装应用列表】,选择“充值”即可 -2. 使用`asch-cli deposit`命令,具体可参考[asch-cli文档](../asch_cli_usage.md)的“4.6.2 dapp充值章节” -3. 调用`asch-js`的`createInTransfer`函数,具体可参考[asch-js接口文档](../asch_js_api.md) - -## 4.7 查询接口调用 - -查询接口一般通过http get协议,比如 - -``` -// 获取dapp区块数据 -> curl http://localhost:4096/api/dapps/0599a6100280df0d296653e89177b9011304d971fb98aba3edcc5b937c4183fb/blocks -# 返回结果如下 -{ - "blocks": [ - { - "id": "9fae0c8200b7f4ef8c96f264e621f01a39a0b365ff42b80232aece0f3136b0e5", - "timestamp": 0, - "height": 1, - "payloadLength": 103, - "payloadHash": "c3674e36954811f869865a3b106ada847d47b6bc1ffc0a69c1859756d34cb5ad", - "prevBlockId": "", - "pointId": "", - "pointHeight": 0, - "delegate": "8065a105c785a08757727fded3a06f8f312e73ad40f1f3502e0232ea42e67efd", - "signature": "fd7423c1ce4cb82e79125e39fc13e040cefce158af69b45d035aaf5a4c78db8f66aa3e93bbdfb72bfa0dd604f64f8bebc66dd08fd17715bb77225fc0743f680b", - "count": 1 - } - ], - "count": 1, - "success": true -} -``` - -更多接口(外部获取dapp数据,非内部通讯)可以参考[dapp默认接口文档](../asch_dapp_default_api.md) - -## 4.8 合约或事务调用 - -合约调用也有三种方式 - -1. 在模板应用的默认前端页面,通过交互式web图型界面进行 -2. 使用`asch-cli dapptransaction`命令, 具体可参考[asch-cli使用说明](../asch_cli_usage.md) -3. 使用`asch-js`的`createInnerTransaction`函数, 具体可参考[asch-js接口文档](../asch_js_api.md) - -## 5 目录结构 - -下面我们分析下asch dapp的目录结构 - -``` -dapps/0599a6100280df0d296653e89177b9011304d971fb98aba3edcc5b937c4183fb/ -├── blockchain.db // dapp数据库文件,与主链的数据是分开存放的 -├── config.json // 应用的节点配置文件,目前主要用于配置受托人秘钥 -├── contract // 合约目录 -│   └── domain.js // 域名合约的实现代码 -├── dapp.json // 注册dapp时用到的元文件 -├── genesis.json // 创世区块 -├── init.js // 应用初始化代码,可以在该文件进行一些设置、事件注册等 -├── interface // 查询接口的实现目录 -│   ├── domain.js // 域名查询接口实现 -│   └── helloworld.js -├── logs // 日志目录 -│   └── debug.20170928.log -├── model -│   └── domain.js // 域名业务数据模型定义 -└── public - └── index.html // 默认前端页面 -``` - -## 6 实现你的业务逻辑 - -我曾经在这个[博客里](http://blog.asch.so/2017/06/30/asch-1.3-foresight-2/)写过我们的开发理念 - -在asch dapp中实现一个业务逻辑,大概思路如下 - -### 6.1 定义你的数据模型 - -在这个环节,你需要考虑的是在区块链中保存什么数据或状态,你的账本内容是什么。 -哪些字段需要建立索引,以提高客户端查询速度。 -dapp有自己的db文件(sqlite3),在dapps/dappId/blockchain.db,所有的表结构定义以及数据都存在这里。跟主链的数据是隔离的,主链的db文件在asch根目录下。 - -### 6.2 实现合约逻辑 - -这个环节,你需要考虑的是一个事务或一个调用会修改哪些状态,比如资产余额,账户属性等。 -我们在sdk中提供了丰富的接口可供调用,具体可参考[sdk接口文档](../asch_sdk_api.md) - -### 6.3 实现查询接口 - -在这个环节,你需要考虑的是如何给前端返回数据,比如区块、交易,各种合约业务状态的查询等 -也可以可用这个通道将一些非全局状态保存到本地节点,我们会在后续章节介绍这些高级用法。 -目前dapp有[预置的通用查询接口](../asch_dapp_default_api.md),这些是由asch-sandbox提供的。另外一部分就是用户自定义的查询接口,在dapps/dappID/interface/xx.js中进行定义。 diff --git a/docs/dapp_docs/1_hello_de.md b/docs/dapp_docs/1_hello_de.md deleted file mode 100644 index 9f338f2..0000000 --- a/docs/dapp_docs/1_hello_de.md +++ /dev/null @@ -1,167 +0,0 @@ -# Dapp Entwicklung Tutorial 1: Asch Dapp Hello World - -## 1 Grundlegender Ablauf - -Asch kann in drei grundlegend verschiedenen Netzwerkumgebungen ausgeführt werden. Localnet, Testnet und Mainnet. Die zwei letztgenannten Testnet und Mainnet sind öffentlich für jeden im Internet zugänglich. Hingegen der erstgenannte Typ, Localnet läuft auf der eigenen Maschine. Dies ist eine private Blockchain mit nur einem Knoten. Diese erleichtert das lokale Entwickeln und das Testen von Applikationen. - -Der Entwicklungsprozess einer Dapp nützt alle drei dieser Netzwerktypen: -- Schritt 1: Entwickeln und Testen auf dem lokalen Rechner mittels der Localnet -- Schritt 2: Das Testen der Dapp auf dem Testnet -- Schritt 3: Das Deployen der Dapp auf dem Mainnet - -## 2 Localnet starten - -Das Localnet kann gleich nach dem Download ausgeführt werden. [Asch Source-Code](https://github.com/AschPlatform/asch). - -``` -git clone https://github.com/AschPlatform/asch -``` -Danach müssen die Installationsschritte in der README-Datei befolgt werden. - -## 3 Install asch-cli - -``` -npm install -g asch-cli -``` -HINWEIS: Verwende NICHT ```cnpm``` von TAOBAO da es dort einige **Bugs** gibt. - -## 4 Erstelle eine Applikation lokal - -Wechsle in das Asch Source-Code Verzeichnis und stelle sicher, dass das Localnet läuft. - -``` -cd -node app.js -``` - -Führe dann das Kommande ```dapps``` der ```asch-cli``` aus, um eine Applikation zu erstellen. - - -``` -asch-cli dapps -a -``` -Anschließend folgen einige Fragen welche beantwortet werden müssen damit der Genesisblock erstellt werden kann. - -``` -? Enter secret of your testnet account ******************************************************************************* -# To input a primary password of the genesis account, which can be any of the main passwords of Asch system (the one that contains 12 words) - -? Enter second secret of your testnet account if you have -# By default genesis account does not set second password, so we can just type the Enter key. - -? Enter DApp name Hello Dapp -# The name of DApp, we choose "Hello Dapp" - -? Enter DApp description Hello world demo for asch dapp -# The description of DApp, let's leave it empty. - -? Enter DApp tags hello,asch,dapp -# The tags of DApp. It can be empty to be searched more efficiently. - -? Choose DApp category - 1) Common - 2) Business - 3) Social - 4) Education - 5) Entertainment - 6) News -(Move up and down to reveal more choices) - Answer: -# The type of DApp, you can choose it according to your business type. Just input the number in front of each option. - -? Enter DApp link https://github.com/sqfasd/asch-hello/archive/master.zip -# Input the zip file of DApp source code (must end by zip). The installation process needs this link to download necessary source file. - -? Enter DApp icon url https://www.asch.com/logo.png -# The URL of DApp's icon file. - -? Do you want publish a inbuilt asset in this dapp? No -# Input Yes if you need an asset built in DApp. For the time being, input No. - -? Enter public keys of dapp forgers - hex array, use ',' for separator 8065a105c785a08757727fded3a06f8f312e73ad40f1f3502e0232ea42e67efd -# Input the list of public keys of DApp's initial delegates, seperated by comma. You can dynamically add delegates later so right now you can just input one private key for genesis account. - -Creating DApp genesis block -Fetching Asch Dapps SDK -Saving genesis block -Saving dapp meta information -Registering dapp in localnet -Done (DApp id is 6299140990391157236) - -# Then the program can automatically register this DApp on localnet. In this case, our application ID is 6299140990391157236 -``` - -## 5 Die Verzeichnis Struktur -Unter dem Verzeichnis `dapps` findet sich jetzt ein neues Verzeichnis dessen Name der Name der Dapp ID ist. - -``` -ls -1 dapps/ - -blockchain.json # the database description of DApp -config.json # the configuration file of DApp, which mainly contains the list of seed nodes. Developers can also add other configurations in it. -dapp.json # the meta information of DApp, including name, description, source code package, and etc. This file can also be used when registering the app to other networks. -genesis.json # indicate the genesis blcok. This file is generated by CLI automatically, but also can be written by yourself, by which the assets of genesis account can be distributed with more flexibility. -index.js # this file contains the entry of DApp -init.js # this file contains the initial code of each module. -LICENSE # this file describes the permit license of source code. -modules # main code -modules.full.json # this file indicates all the modules need to be loaded. You can add other necessary modules here. -modules.genesis.json # (the simplified version of modules.full.json, currently not need) -node_modules # -package.json # -public # this folders contains all front-end files -routes.json # this file contains the configuration of http route. If you want to add new interface, you need to revise this file. -``` -Keine Sorge bezüglich der Komplexität der Verzeichnisstruktur. Zur Zeit genügt es wenn wir nur einen Blick drauf werfen. - -Die für die Entwickler wichtige Dateien befinden sich in ```modules/contracts/```. - -Es gibt von Haus aus 4 verschiedene Verträge in diesem Verzeichnis. - -``` -ls -1 dapps//modules/contracts/ - -delegates.js # Delegat-Registrierungs-Vertrag -insidetransfer.js # In-Chain Transfer Vertrag -outsidetransfer.js # XAS Einzahlungs-Vertrag -withdrawaltransfer.js # XAS Auszahlungs-Vertrag -``` -Entwickler müssen nur einen neuen Vertrag erstellen um ihre Business-Logik auszuführen. - -## 6 Das Genesis-Passwort für die Dapp setzen - -Es ist obligatorisch das Primärpasswort des Genesis-Blocks sowie die Dapp ID in die ```config.json``` Datei unter dem Punkt ```dapp``` zu schreiben. - -In der Zukunft wenn die Dapp auf dem Mainnet veröffentlich wird, wird auch ein Rechner zur Konfiguration der Primärpassworts benötigt. HINWEIS: Es genügt ein Rechner. - -``` -"params": { - "6299140990391157236": [ - "someone manual strong movie roof episode eight spatial brown soldier soup motor" - ] -} -``` - -## 7 Auf die Front-End Oberfläche zugreifen - -Wir könnnen uns nun mit der grafischen Benutzeroberfläche für die Dapp-Entwicklung auseinander setzen. - -Diese findet man im Programm in der Liste der installierten Anwendungen. Alternativ dazu kann man auch mit folgender URL darauf zugreifen: ```localhost:4096/dapps/``` - -Für dieses Projekt zeigen wir mehrere Schritte. Einzahlen, In-Chain Transfer und Auszahlen. - -Zur Zeit können Einzahlungen nur über die Konsole getätigt werden (Einzahlungen über die GUI sind für die Zukunft geplant). Alle anderen Operationen können über die GUI geschehen. - -``` -asch-cli dapps -d - -? Enter secret ******************************************************************************* -? Enter amount 100 -? DApp Id 6299140990391157236 -? Enter secondary secret (if defined) -? Host and port localhost:4096 -null { success: true, transactionId: '10589988261732949004' } -10589988261732949004 -``` - -Die Applikation aktualisiert sich alle 30 Sekunden. Nach kurzer Zeit können wir das Saldo der Ein- und Auszahlungen sehen. diff --git a/docs/dapp_docs/1_hello_en.md b/docs/dapp_docs/1_hello_en.md deleted file mode 100644 index 9b3efdd..0000000 --- a/docs/dapp_docs/1_hello_en.md +++ /dev/null @@ -1,400 +0,0 @@ -# Dapp Development Tutorial 1: Asch Dapp Hello World - -## 1 Basic Process - -There are three types of networks in Asch, localnet, testnet, and mainnet. The later two, testnet and mainnet, are usually deployed online, which can be accessed by a public network. Meanwhile the first type, localnet, as its name is running on local machine, which is actually a private chain with only one node. Localnet is designed to help developing and testing locally. - -And the development of Dapp involves all of these types of network simultaneously, which is: -- step 1: developing and testing locally on the localnet -- step 2: testing on the testnet -- step 3: deploying officially on mainnet - -### 1.1 System requirements -- Node v8.x.x - -## 2 Setup asch-cli - -``` -npm install -g asch-cli -``` - -## 3 Setup asch -``` -# clone asch -git clone https://github.com/aschplatform/asch.git asch && cd asch && npm install && cd .. -``` -## 4 Start localnet - -Run your own local asch node. - -``` -# change directory -cd asch - -# start the localnet (default on localhost:4096) -node app.js -``` - - -## 5 Start The Frontend Application (optional) - -To access the localnet via a graphical user interface (GUI) start the frontend application. Be sure to have the localnet up and running. - -This step must be run from another console. The first console is already busy with running the localnet. - -``` -# change directory -cd asch/public -``` - -Install the dependencies for the frontend application -``` -yarn install -``` - -Build the frontend application for the localnet. -``` -gulp build-local -``` - -Now you can access the frontend application on the address ```localhost:4096```. -*NOTE:* You don't need to start a http-server. Asch is already providing one for you. - - -## 6 Prepare Account For Dapp Registration - -First create a new local asch-account. - -``` -# execute (in root folder) -> asch-cli -H 127.0.0.1 -P 4096 crypto --generate -# ? Enter number of accounts to generate: -1 -``` -**Our New Account** -``` - address: AHMCKebuL2nRYDgszf9J2KjVZzAw95WUyB - secret: sentence weasel match weather apple onion release keen lens deal fruit matrix - publicKey: a7cfd49d25ce247568d39b17fca221d9b2ff8402a9f6eb6346d2291a5c81374c -``` - -**Genesis Account** -``` - address: 14762548536863074694 - secret: someone manual strong movie roof episode eight spatial brown soldier soup motor - publicKey: 8065a105c785a08757727fded3a06f8f312e73ad40f1f3502e0232ea42e67efd -``` - - -**Our new Acccount** will be our account for this tutorial. - -We need **100 XAS** to register a dapp. Our new account has **0 XAS**. The **genesis** account has 100000000 XAS on it. Lets send some money to **our** account. - - -``` -# send money to our account -> asch-cli -H 127.0.0.1 -P 4096 sendmoney --secret "someone manual strong movie roof episode eight spatial brown soldier soup motor" --to "AHMCKebuL2nRYDgszf9J2KjVZzAw95WUyB" --amount 100000000000 - -# check your balance -> asch-cli -H 127.0.0.1 -P 4096 openaccount "sentence weasel match weather apple onion release keen lens deal fruit matrix" -``` - - -## 7 Create A Dapp Metadata File - -First we have to create 5 delegate accounts: - -``` -# execute in root (you don't have to point to the localhost, this command is execute only in asch-cli) -> asch-cli crypto --generate -? Enter number of accounts to generate -5 - -[ - { - address: 'AN1yKK47P3MtD5ZgHYoncGQ1gCn4p2vGAC', - secret: 'flame bottom dragon rely endorse garage supply urge turtle team demand put', - publicKey: 'db18d5799944030f76b6ce0879b1ca4b0c2c1cee51f53ce9b43f78259950c2fd' - }, - { - address: 'AGeeCmSVLDNbtMqqpJchQZakchwzpuje1P', - secret: 'thrive veteran child enforce puzzle buzz valley crew genuine basket start top', - publicKey: '590e28d2964b0aa4d7c7b98faee4676d467606c6761f7f41f99c52bb4813b5e4' - }, - { - address: 'A7NWaYUkpa543hdTsfw57AoZAgCBr2NFY6', - secret: 'black tool gift useless bring nothing huge vendor asset mix chimney weird', - publicKey: 'bfe511158d674c3a1e21111223a49770bee93611d998e88a5d2ea3145de2b68b' - }, - { - address: 'ABU1G2pQFMGa7c1GiAPYCQuUhiPHdvCSB2', - secret: 'ribbon crumble loud chief turn maid neglect move day churn share fabric', - publicKey: '7bbf62931cf3c596591a580212631aff51d6bc0577c54769953caadb23f6ab00' - }, - { - address: 'AG1A3ojeLAMZySaZWTkg49jcoVCV7FCKXF', - secret: 'scan prevent agent close human pair aerobic sad forest wave toe dust', - publicKey: '452df9213aedb3b9fed6db3e2ea9f49d3db226e2dac01828bc3dcd73b7a953b4' - } -] -``` - - -After that enter your Asch source code folder and make sure the localnet is running. - -``` -# this must be executed in a new console -> mkdir asch-test-dapp && cd asch-test-dapp -> asch-cli dapps -a - -# enter dapp name? -hello - -# enter dapp description? -[empty] - -# enter dapp tags? -[empty] - -# choose dapp category -1 - -# enter dapp link -https://github.com/AschPlatform/asch-dapp-helloworld/archive/master.zip - -# enter dapp icon url -http://o7dyh3w0x.bkt.clouddn.com/hello.png - -# enter public keys of dapp delegates - hex array, use ',' for separator (at least 5 delegates, max 101): -db18d5799944030f76b6ce0879b1ca4b0c2c1cee51f53ce9b43f78259950c2fd,590e28d2964b0aa4d7c7b98faee4676d467606c6761f7f41f99c52bb4813b5e4,bfe511158d674c3a1e21111223a49770bee93611d998e88a5d2ea3145de2b68b,7bbf62931cf3c596591a580212631aff51d6bc0577c54769953caadb23f6ab00,452df9213aedb3b9fed6db3e2ea9f49d3db226e2dac01828bc3dcd73b7a953b4 - -# how many delegates are needed to unlock asset of a dapp? -3 - -# Enter master secret of your genesis account -[hidden] - -# Do you want publish a inbuilt asset in this dapp? -No -``` - -This step created the `asch-test-dapp/dapp.json` file. -``` -{ - "name": "hello", - "link": "https://github.com/sqfasd/asch-hello-dapp/archive/master.zip", - "category": 1, - "description": "", - "tags": "", - "icon": "http://o7dyh3w0x.bkt.clouddn.com/hello.png", - "delegates": [ - "db18d5799944030f76b6ce0879b1ca4b0c2c1cee51f53ce9b43f78259950c2fd", - "590e28d2964b0aa4d7c7b98faee4676d467606c6761f7f41f99c52bb4813b5e4", - "bfe511158d674c3a1e21111223a49770bee93611d998e88a5d2ea3145de2b68b", - "7bbf62931cf3c596591a580212631aff51d6bc0577c54769953caadb23f6ab00", - "452df9213aedb3b9fed6db3e2ea9f49d3db226e2dac01828bc3dcd73b7a953b4" - ], - "unlockDelegates": 3, - "type": 0 -} -``` - - -## 8 Register The Dapp On The Localnet - -Until now we only have generated file (`asch-test-dapp/dapp.json`). Now we want to register this dapp metadata file on the localnet. We register the dapp with **our** newly generated address. - -``` -# execute (in asch/dapps) -> asch-cli -H 127.0.0.1 -P 4096 registerdapp --metafile dapp.json --secret "sentence weasel match weather apple onion release keen lens deal fruit matrix" -``` - -**Result** -``` -# This returns the new Dapp-ID - -``` - -Now navigate in your browser to `localhost:4096`. Login with **our** new created account. Under dapps you should see the register dapps. - -Use browser access `http://localhost:4096/api/dapps/get?id=`, you can query the dapp, the following is the return information: - -``` -{ - "success": true, - "dapp": { - "name": "asch-dapp-helloworld", - "description": "A hello world demo for asch dapp", - "tags": "asch,dapp,demo", - "link": "https://github.com/AschPlatform/asch-dapp-helloworld/archive/master.zip", - "type": 0, - "category": 1, - "icon": "http://o7dyh3w0x.bkt.clouddn.com/hello.png", - "delegates": [ - "a518e4390512e43d71503a02c9912413db6a9ffac4cbefdcd25b8fa2a1d5ca27", - "c7dee266d5c85bf19da8fab1efc93204fed7b35538a3618d7f6a12d022498cab", - "9cac187d70713b33cc4a9bf3ff4c004bfca94802aed4a32e2f23ed662161ea50", - "01944ce58570592250f509214d29171a84f0f9c15129dbea070251512a08f5cc", - "f31d61066c902bebc80155fed318200ffbcfc97792511ed18d85bd5af666639f" - ], - "unlockDelegates": 3, - "transactionId": "0599a6100280df0d296653e89177b9011304d971fb98aba3edcc5b937c4183fb" - } -} -``` - -## 9 Install the dapp on the localnet - -Finally it is time to install the dapp on the localnet. - -First we copy the files created in previous step to the dapp subdirectory under the asch installation directory and rename it to dapp's id: - -``` -> cp -r asch-test-dapp path/to/asch/dapps/0599a6100280df0d296653e89177b9011304d971fb98aba3edcc5b937c4183fb -``` - -then: -``` -# execute -asch-cli -H 127.0.0.1 -P 4096 dapps --install - -# ? Enter dapp id -# (input your dapp Id) - -# ? Host and port (localhost:4096) -# [Enter] - -# ? What is your dapp master password -# -``` -The dapp masterpassword is located in `asch/config.json`. -``` - "dapp": { - "masterpassword": "ytfACAMegjrK", - "params": { - "": [ - ] - } -``` - -Then write the passwords of the 5 delegates into the dapp configuration file `asch/dapps//config.json`. - -``` -# config.json -{ - "secrets": [ - "flame bottom dragon rely endorse garage supply urge turtle team demand put", - "thrive veteran child enforce puzzle buzz valley crew genuine basket start top", - "black tool gift useless bring nothing huge vendor asset mix chimney weird", - "ribbon crumble loud chief turn maid neglect move day churn share fabric", - "scan prevent agent close human pair aerobic sad forest wave toe dust" - ] -} -``` - -**After the installation restart the node** -``` -# stop the localnet with Ctrl + C - -# restart the localnet -> node app.js -``` - -## 10 Access The Dapp In Your Browser - -Now you can access the dapp like a website `localhost:4096/dapps//` in your browser. - - -## 11 Set Dapp Genesis Password - -Under `asch/config.json` set the genesis password for your dapp. Input your `` and the secret of your - -**before** -``` - "dapp": { - "masterpassword": "ytfACAMegjrK", - "params": {} - } -``` - -**after** -``` - "dapp": { - "masterpassword": "ytfACAMegjrK", - "params": { - "": [ - "sentence weasel match weather apple onion release keen lens deal fruit matrix" - ] - } - } -``` -In the future when the DApp is published in testnet or mainnet, it still needs a machine that configures the primary password. NOTE: Only one machine is required. - - -## 12 The folder structure - -Now we can see that there is a new folder added under `asch/dapps`, named as the DApp ID just created. - -``` -> ls -la dapps/ - -dapps -└─── - blockchain.json # the database description of DApp - config.json # the configuration file of DApp, which mainly contains the list of seed nodes. Developers can also add other configurations in it. - dapp.json # the meta information of DApp, including name, description, source code package, and etc. This file can also be used when registering the app to other networks. - genesis.json # indicate the genesis blcok. This file is generated by CLI automatically, but also can be written by yourself, by which the assets of genesis account can be distributed with more flexibility. - index.js # this file contains the entry of DApp - init.js # this file contains the initial code of each module. - LICENSE # this file describes the permit license of source code. - modules # main code - modules.full.json # this file indicates all the modules need to be loaded. You can add other necessary modules here. - modules.genesis.json # (the simplified version of modules.full.json, currently not need) - node_modules # - package.json # - public # this folders contains all front-end files - routes.json # this file contains the configuration of http route. If you want to add new interface, you need to revise this file. -``` -Don't worry about the complexity of the file structure. For now a first look is enough. - -All the essential files for developers can be found in ```modules/contracts/``` - -There are 4 build-in contract types in this folder: - -``` -> ls -1 dapps//modules/contracts/ - - -dapps -└─── - └───modules - └───contracts - delegates.js # registering delegate contract - insidetransfer.js # in-chain transfer contract - outsidetransfer.js # XAS deposit contract - withdrawaltransfer.js # XAS withdraw contract -``` - -Developers need to create a new contact to run business logic. That's all. - - - -## 13 Dapp Deposit - -In this project, we are able to conduct multiple tasks such as deposit, in-chain transfer, and withdraw. - -Currently deposit can only be executed via command line (this feature will be built into the main wallet in the future). - -``` -> asch-cli dapps --deposit - -? Enter secret ******************************************************************************* -? Enter amount 100 -? DApp Id 6299140990391157236 -? Enter secondary secret (if defined) -? Host and port localhost:4096 -null { success: true, transactionId: '10589988261732949004' } -10589988261732949004 -``` - -In the web wallet (`localhost:4096`) we can see (after approximately 30 seconds) that the balance was updated. diff --git a/docs/dapp_docs/dapp_dev_tutorials.md b/docs/dapp_docs/dapp_dev_tutorials.md deleted file mode 100644 index ed0f771..0000000 --- a/docs/dapp_docs/dapp_dev_tutorials.md +++ /dev/null @@ -1,545 +0,0 @@ -# Asch DAPP核心开发流程解析 - -标签(空格分隔): Asch DAPP - ---- - -## 1.准备工作 - - -`基础知识`:明白什么是区块链?什么是侧链?怎么用linux?怎么用nodejs?bitcoin的基本运行原理?什么是共识?什么是dpos?什么是受托人?什么是主密码?什么是私钥、公钥、地址?什么是创世块?什么是资产?这些弄明白了(最起码得大体了解)再往下看,否则就是事倍功半,真没必要往下看了。 - -`概念理解`:Asch的DAPP是运行在侧链上的,每个DAPP也可以简单理解为一条侧链,具有区块链的基本属性,比如共识机制(默认是dpos,高端玩家可以定制自己的共识算法)、区块信息、转账交易记录、P2P广播通讯、数据库文件等,跟Asch主链有相同的加密算法、地址生成算法,也就是说同一个账户在主链和DAPP中是通用的(通用指的是同一个密码登陆进去后地址相同)。 - -`OS`:Ubuntu 14.04.x 或者 16.04.x(物理机、虚拟机或者Bash on Ubuntu on Windows都可以) - -`IDE`:vscode - -`nodejs`: 8.4.0 - -`npm`:5.3.0 - -如下链接为 `DAPP开发前必读文章` (包含里面的那些链接文章也要读) -https://github.com/AschPlatform/asch/blob/master/docs/asch_dapps_introduction.md -https://github.com/AschPlatform/asch/blob/master/docs/dapp_docs/1_hello.md -https://github.com/AschPlatform/asch/blob/master/docs/asch_sdk_api.md -https://github.com/AschPlatform/asch/blob/master/docs/asch_dapp_default_api.md -https://github.com/AschPlatform/asch/blob/master/docs/asch_cli_usage.md -https://github.com/AschPlatform/asch/blob/master/docs/asch_http_interface.md - -在开发期间遇到的任何的技术问题都可以去https://github.com/AschPlatform/asch/issues 查找或者创建新的issue。 - -`友情提示`:区块链是块大蛋糕,但吃之前先给自己做个评估,看是否有能力吃的下、能吃多少、是否能吃的顺心。 - -## 2.搭建本地localnet - -localnet简单理解就是Asch私有链,这里是为了方便DAPP开发而搭建的。localnet上的DAPP如果开发、测试顺利通过,相当于整个DAPP已完成90%的工作。 - -``` -# Install dependency package -sudo apt-get install curl sqlite3 ntp wget git libssl-dev openssl make gcc g++ autoconf automake python build-essential -y -# libsodium for ubuntu 14.04 -sudo apt-get install libtool -y -# libsodium for ubuntu 16.04 -sudo apt-get install libtool libtool-bin -y - -# Install nvm -curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash -# This loads nvm -export NVM_DIR="$HOME/.nvm" -[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" -[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion - -# Install node and npm for current user. -nvm install v8 -# check node version and it should be v8.x.x -node --version - -# git clone sourece code -git clone https://github.com/AschPlatform/asch && cd asch && chmod u+x aschd - -# Install node packages -npm install -至此,完成localnet服务端部分的构建。 -``` - -``` -# Web Wallet -cd public/ - -npm install bower -g -npm install browserify -g -npm install yarn -g - -yarn install -# angular chose "angular#~1.5.3 which resolved to 1.5.11 and is required by ASCH" - - -npm run build -gulp build-test #This make the front-end files in public dir. -至此,完成localnet前端页面(钱包UI)的构建。 -``` - -``` -// 启动Asch -cd asch && node app.js // 日志打印到屏幕终端,ctrl+c结束进程 -或者 -cd asch && ./aschd start // 守护进程方式启动,日志记录到logs/debug.log中。./aschd stop结束进程 -或者其它的启动方式,比如pm2 start app.js - -``` -然后在浏览器中打开 ```http://localhost:4096```,如果能看到Asch钱包登陆页面说明localnet的搭建和启动成功(localnet的创世账户密码:"someone manual strong movie roof episode eight spatial brown soldier soup motor",里面有一亿XAS)。如果页面报错,则需要检查app.js进程是否存在、日志报错信息等。 - - -## 3.注册并启动第一个DAPP - -### 3.1 发行资产(UIA) -发行自己的资产,请参考这个链接http://docs.asch.mobi/docs/asch_issue_assets.html -这里我们在钱包页面生成一个新账户A,主密码为“almost journey future similar begin type write celery girl month forget breeze”,对应的地址是AAjoobuMcmkQ1gS8vTfBy3dQavBiH7sBCF,该账户将作为下面的cctime.XCT资产发行者、cctime DAPP的注册者以及给其它账户转账的发送者,创世账户给该地址转1000个xas。 - -A账户去注册发行商cctime,然后注册一个资产XCT(上限100亿,精度8,描述为:cctime.org的token时讯币,其它用默认的),最后发行10亿的cctime.XCT。 - -### 3.2 利用模板启动第一个DAPP -Asch作为一个区块链开发平台,为开发者提供了一个安全且高性能的虚拟机(asch-sandbox)以及一系列的内部接口、框架等。其中的一个脚手架就是利用模板来生成自定义的DAPP,通过回答几个问题就可以完成DAPP框架代码的开发工作。 -模板包含了启动一个dapp需要的最少数据 - -#### 3.2.1 生成DAPP元信息(创世块) - -``` -// 生成5个受托人账号 -zhenxi@MiAir:~/Codes/github/AschPlatform/asch$ asch-cli crypto -g -? Enter number of accounts to generate 5 -[ { address: 'A9pDhjc7NuYMWYLxkgAgVmHE2NQ7diMcWX', - secret: 'fit night someone unveil dwarf believe middle evidence puzzle hotel common choose', - publicKey: 'afdf69f0da9ff333218f2cd10cb0a907c2e76788f752b799cb1dab3a9f03bf63' }, - { address: 'A2jvQUNowLgP9hHMN3tSCAUkakuigGRytB', - secret: 'lawsuit ride civil slice kitchen unfold unable lumber prevent suspect finger chunk', - publicKey: '67d52a0265f9e5366660c8b384cee56d3f8b5737b2dd3c617d22df83b5ebef02' }, - { address: 'A7JjHgx7ACCJ6AxypBn4Qt9NrGaY4JuZDF', - secret: 'absurd sweet blast dinner battle zero ladder steak coral fork venture coffee', - publicKey: '39c2322600a0c81ecfa97119ec8e2d5bfb73394914d92b54e961846a987e4e22' }, - { address: 'AMu7kuP9TjywkUQQQgALid96So2VCve5QB', - secret: 'topic ramp throw cloud moment jungle bar series task protect erupt answer', - publicKey: '4740d2c16bf6c5a174eba1e0f859253a64851d30acbc9655b01394af82d3e325' }, - { address: 'A9BzaJDkyzb9RVAFjsePMemSVXMDLiQpjJ', - secret: 'shoot tired know dish rally kiwi snack patrol bunker ocean panel this', - publicKey: 'b433c226645981477642491f77de7b8d63274aa51f932bbe1fe3f445a8aaecc9' } ] -Done -``` - -``` -// 根据模板和自定义参数生成自己的dapp框架,包含创世块、配置文件、数据和合约、接口、日志等目录 -cd dapps -mkdir cctime && cd cctime -zhenxi@MiAir:~/Codes/github/AschPlatform/asch/dapps$ asch-cli dapps -a -Copying template to the current directory ... -? Enter DApp name cctime -? Enter DApp description cctime.org -? Enter DApp tags news -? Choose DApp category News -? Enter DApp link http://github/aschplatform/cctime.zip -? Enter DApp icon url http://a.com/x.png -? Enter public keys of dapp delegates - hex array, use ',' for separator afdf69f0da9ff333218f2cd10cb0a907c2e76788f752b799cb1dab3a9f03bf63,67d52a0265f9e5366660c8b384cee56d3f8b5737b2dd3c617d22 -df83b5ebef02,39c2322600a0c81ecfa97119ec8e2d5bfb73394914d92b54e961846a987e4e22,4740d2c16bf6c5a174eba1e0f859253a64851d30acbc9655b01394af82d3e325,b433c226645981477642491f77de7b8d63274aa51f932bb -e1fe3f445a8aaecc9 -? How many delegates are needed to unlock asset of a dapp? 3 -DApp meta information is saved to ./dapp.json ... -? Enter master secret of your genesis account [hidden] //这里输入的密码为:'almost journey future similar begin type write celery girl month forget breeze' -? Do you want publish a inbuilt asset in this dapp? Yes -? Enter asset name, for example: BTC, CNY, USD, MYASSET XCT -? Enter asset total amount 100000000 -? Enter asset precision 8 -New genesis block is created at: ./genesis.json -// 生成的文件如下 -zhenxi@MiAir:~/Codes/github/AschPlatform/asch/dapps/cctime$ ls -config.json contract dapp.json genesis.json init.js interface model public -``` - -#### 3.2.2 注册DAPP到localnet上 - -``` -zhenxi@MiAir:~/Codes/github/AschPlatform/asch/dapps/cctime$ asch-cli registerdapp -f dapp.json -e "almost journey future similar begin type write celery girl month forget breeze" -// 返回结果为dappId -75d084dc91221b380e7a3c6b3b7467935572b4ebaa1e9a3db91e1239377c1fed -``` - -此时钱包的“应用列表”就可以看到该应用了。 -![](http://asch-public.oss-cn-beijing.aliyuncs.com/pics/dapp%E6%A0%B8%E5%BF%83%E5%BC%80%E5%8F%91%E6%B5%81%E7%A8%8B%E8%A7%A3%E6%9E%90/2.png) - -将cctime目录改名为75d084dc91221b380e7a3c6b3b7467935572b4ebaa1e9a3db91e1239377c1fed,这样就完成了dappp在本地节点的安装(整个过程是手工安装,以后正式上线后,其他节点安装时无须这么麻烦,只需要在页面点击就可以安装)。 - -``` -cd .. -mv cctime 75d084dc91221b380e7a3c6b3b7467935572b4ebaa1e9a3db91e1239377c1fed -``` - -#### 3.2.3 启动DAPP - -重启asch服务,默认会加载dapps目录下的所有的dapp。此时dapp中只有模板预置的信息,虽然此时没有自定义的数据、合约、接口等信息,但dapp已经是一条具备最小功能的侧链了,只需要配置好受托人就可以产块和转账。 -此时钱包的“已安装应用列表”就可以看到该应用了。 -![](http://asch-public.oss-cn-beijing.aliyuncs.com/pics/dapp%E6%A0%B8%E5%BF%83%E5%BC%80%E5%8F%91%E6%B5%81%E7%A8%8B%E8%A7%A3%E6%9E%90/3.png) - -启动后,dapps/75d084dc91221b380e7a3c6b3b7467935572b4ebaa1e9a3db91e1239377c1fed下会多出一个blockchain.db文件。dapp第一次启动时会创建2种表,1:用户自定义表,由model下的数据模型文件决定,2:asch_sandbox预置表,这些都是区块链的系统表。 - -目前我们这个DAPP的blockchain.db包含如下表: - -`accounts` dapp内账户信息,asch_sandbox预置 - -`blocks` dapp区块表,asch_sandbox预置 - -`domains` 域名表,非asch_sandbox预置表,而是根据model下的domain.js定义生成的表,可以删除 - -`transactions` dapp交易表,asch_sandbox预置 - -`variables` dapp变量表,asch_sandbox预置 - -`balances` dapp余额表,asch_sandbox预置 - -`deposits` 主链往dapp上充值记录表,asch_sandbox预置 - -`round_fees` dapp的dpos共识下,每轮的手续费详情表,asch_sandbox预置 - -`transfers` dapp内部转账表,asch_sandbox预置 - -浏览器打开 `http://localhost:4096/dapps/75d084dc91221b380e7a3c6b3b7467935572b4ebaa1e9a3db91e1239377c1fed/` 如果能看到“Asch DApp Example 1 - hello world”页面说明dapp启动成功。 - -此时用'almost journey future similar begin type write celery girl month forget breeze'登陆后看到XCT(这是dapp内置的资产,只能在dapp内使用,不是我们之前在主链发行的用户资产cctime.XCT)余额为100000000,与我们注册dapp时设定的参数一致。 - -![](http://asch-public.oss-cn-beijing.aliyuncs.com/pics/dapp%E6%A0%B8%E5%BF%83%E5%BC%80%E5%8F%91%E6%B5%81%E7%A8%8B%E8%A7%A3%E6%9E%90/1.png) - -#### 3.2.4 配置DAPP的受托人 -编辑dapps/75d084dc91221b380e7a3c6b3b7467935572b4ebaa1e9a3db91e1239377c1fed/config.json文件,将上面5个受托人的密码加入到该文件中 -``` -{ - "secrets": [ - "fit night someone unveil dwarf believe middle evidence puzzle hotel common choose", - "lawsuit ride civil slice kitchen unfold unable lumber prevent suspect finger chunk", - "absurd sweet blast dinner battle zero ladder steak coral fork venture coffee", - "topic ramp throw cloud moment jungle bar series task protect erupt answer", - "hoot tired know dish rally kiwi snack patrol bunker ocean panel this" - ] -} -``` -然后重启asch,此时dapp已经可以产块了。具体可以看dapp的日志输出 dapps/75d084dc91221b380e7a3c6b3b7467935572b4ebaa1e9a3db91e1239377c1fed/logs/debug.20180125.log - -#### 3.2.5 DAPP基本操作 - -##### 3.2.5.1 往DAPP中进行充值 - -用密码“almost journey future similar begin type write celery girl month forget breeze”登陆Asch钱包,往DAPP中充值100 XAS(这个充值动作实质就是跨链操作),消耗0.1XAS手续费。 -![](http://asch-public.oss-cn-beijing.aliyuncs.com/pics/dapp%E6%A0%B8%E5%BF%83%E5%BC%80%E5%8F%91%E6%B5%81%E7%A8%8B%E8%A7%A3%E6%9E%90/4.png) - -10秒后(也有可能是1秒、3秒或者8秒,这里实质是要等一个区块确认后才能看到充值余额,而10秒是一个块的默认出块时间),去 `http://localhost:4096/dapps/75d084dc91221b380e7a3c6b3b7467935572b4ebaa1e9a3db91e1239377c1fed/` 页面验证充值 -![](http://asch-public.oss-cn-beijing.aliyuncs.com/pics/dapp%E6%A0%B8%E5%BF%83%E5%BC%80%E5%8F%91%E6%B5%81%E7%A8%8B%E8%A7%A3%E6%9E%90/5.png) - -此时AAjoobuMcmkQ1gS8vTfBy3dQavBiH7sBCF这个账户在主链的XAS余额减少了100.1(0.1是充值手续费),而在侧链cctime中XAS余额增加了100。 - -同理充值100 cctime.XCT资产。 -![](http://asch-public.oss-cn-beijing.aliyuncs.com/pics/dapp%E6%A0%B8%E5%BF%83%E5%BC%80%E5%8F%91%E6%B5%81%E7%A8%8B%E8%A7%A3%E6%9E%90/6.png) - -##### 3.2.5.2 DAPP内部转账 -生成另一个账户B,主密码“attack exist tuna tunnel enhance coach favorite safe buffalo faculty robot blue”,地址为APoBYfxx266FH5HCrkBdebAZ2wFPjJ3Q4z。 -A调用DAPP的系统内置合约给B用户转账10 cctime.XCT,这里展示的是通过页面调用接口(该页面的Contract invoke可以理解为postman),该合约的详细描述见[DAPP_默认API](https://github.com/AschPlatform/asch/blob/master/docs/asch_dapp_default_api.md#3122-dapp%E5%86%85%E9%83%A8%E8%BD%AC%E8%B4%A6type3) - -转账时的数额是 真实数额*10**资产精度数值(区块链上前端看到的有小数,但后端都是按照整数计算的) -这里选择编号为3的system合约就是dapp内部转账(小于1000的都是system内置合约,目前已经1-4共4个合约,详情见文档:https://github.com/AschPlatform/asch/blob/master/docs/asch_dapp_default_api.md#3-%E4%BA%8B%E5%8A%A1transactions) -![](http://asch-public.oss-cn-beijing.aliyuncs.com/pics/dapp%E6%A0%B8%E5%BF%83%E5%BC%80%E5%8F%91%E6%B5%81%E7%A8%8B%E8%A7%A3%E6%9E%90/7.png) - -![](http://asch-public.oss-cn-beijing.aliyuncs.com/pics/dapp%E6%A0%B8%E5%BF%83%E5%BC%80%E5%8F%91%E6%B5%81%E7%A8%8B%E8%A7%A3%E6%9E%90/8.png) - -![](http://asch-public.oss-cn-beijing.aliyuncs.com/pics/dapp%E6%A0%B8%E5%BF%83%E5%BC%80%E5%8F%91%E6%B5%81%E7%A8%8B%E8%A7%A3%E6%9E%90/9.png) - -此时A账户在DAPP中的XAS余额减少0.1(DAPP默认手续费是XAS,可以自定义为其它资产或者不收手续费),cctime.XCT余额减少10。B账户的cctime.XCT余额增加10. - -账户A的余额: -![](http://asch-public.oss-cn-beijing.aliyuncs.com/pics/dapp%E6%A0%B8%E5%BF%83%E5%BC%80%E5%8F%91%E6%B5%81%E7%A8%8B%E8%A7%A3%E6%9E%90/10.png) - -账户B的余额: -![](http://asch-public.oss-cn-beijing.aliyuncs.com/pics/dapp%E6%A0%B8%E5%BF%83%E5%BC%80%E5%8F%91%E6%B5%81%E7%A8%8B%E8%A7%A3%E6%9E%90/11.png) - -##### 3.2.5.3 DAPP内给地址设置昵称 -![](http://asch-public.oss-cn-beijing.aliyuncs.com/pics/dapp%E6%A0%B8%E5%BF%83%E5%BC%80%E5%8F%91%E6%B5%81%E7%A8%8B%E8%A7%A3%E6%9E%90/14.png) - -OK,上面BB了那么多,其实就干了一件事:没有写一行代码只是利用现有的工具就搭建起来一条具备跨连充值、跨链提现、内部转账功能的侧链,并且还可以创建内置资产。从下面章节开始,才是用户自定义数据、智能合约、外部接口的代码编写。 - -## 4 DAPP核心开发流程 -开发dapp跟把大象放进冰箱的步骤一毛一样,本章节就是围绕下面这三步来做 :) - -![](http://asch-public.oss-cn-beijing.aliyuncs.com/pics/dapp%E6%A0%B8%E5%BF%83%E5%BC%80%E5%8F%91%E6%B5%81%E7%A8%8B%E8%A7%A3%E6%9E%90/12.png) - -下面这些操作都是在dapps/75d084dc91221b380e7a3c6b3b7467935572b4ebaa1e9a3db91e1239377c1fed/目录下进行的。 - -### 4.1 自定义用户数据模型(RDBMS表) - -注意事项: - -- `表结构定义需要放到model目录下` - -- `字段属性都是RDBMS通用的,比如类型有string、nmber等,not_null,defaut值,length长度、主外键约束、唯一约束等` - -- `如果字段是String类型,则必须加上length属性` - -- `DAPP启动时会检查这些表是否存在,如果不存在则会自动创建,保存到blockchain.db文件中` - - -在model目下创建article.js文件,该文件定义了articles表,内容如下 -``` -module.exports = { - name: 'articles', - fields: [ - // 文章id - { - name: 'id', - type: 'String', - length: '20', - not_null: true, - primary_key: true - }, - // 发表文章时的交易id - { - name: 'tid', - type: 'String', - length: 64, - not_null: true, - unique: true - }, - // 文章作者的地址 - { - name: 'authorId', - type: 'String', - length: 50, - not_null: true - }, - // 时间戳,距离cctime创世块经历的秒数 - { - name: 'timestamp', - type: 'Number', - not_null: true - }, - // 文章标题 - { - name: 'title', - type: 'String', - length: 256, - not_null: true - }, - // 如果文章是引用的,其url地址定义 - { - name: 'url', - type: 'String', - length: 256 - }, - // 文章内容 - { - name: 'text', - type: 'String', - length: 4096, - not_null: true, - }, - // 文章标签 - { - name: 'tags', - type: 'String', - length: 20 - }, - // 文章得到的投票数 - { - name: 'votes', - type: 'Number', - not_null: true - }, - // 文章评论 - { - name: 'comments', - type: 'Number', - not_null: true, - default: 0 - }, - // 举报 - { - name: 'reports', - type: 'Number', - not_null: true, - default: 0 - } - ] -} -``` - -### 4.2 自定义用户合约 - -这一步里面主要用到的文档是:https://github.com/AschPlatform/asch/blob/master/docs/asch_sdk_api.md -app.xxx这种接口都来自asch_sandbox。 - -合约就是业务逻辑处理。 - -``` -// 在contrac目录下创建cctime.js -module.exports = { - // 定义发布文章的智能合约函数 - postArticle: async function (title, url, text, tags) { - // 下面这些if判断是用来校验文章信息是否合法,有些是可以用 app.validate(type, value) 接口进行重写的 - if (!url && !text) { - return 'Should provide url or text' - } - if (url && text) { - return 'Both url and text are not supported' - } - if (!tags) { - return 'Should provide tags' - } - if (tags.length > 20) { - return 'Invalid tags size' - } - if (!title) { - return 'Should provide title' - } - if (title.length > 256) { - return 'Invalid title size' - } - if (url && url.length > 256) { - return 'Url too long' - } - if (text && text.length > 4096) { - return 'Text too long' - } - //TODO validate url format - - // 对key进行加锁,防止重复数据。这里的意思是如果用户发表的文章是转载其它url的,则需要检查该url是否已经被发布过了。需要在内存中将这个url的key锁住,防止同一个区块内其他人再次发布这个url然后去检查db中是否已经有这个url了 - if (url) { - app.sdb.lock('postArticle@' + url) - let exists = await app.model.Article.exists({ url: url }) - if (exists) { - return 'Url already exists' - } - } - // 调用app.sdb.create将校验过的文章信息插入到articles表中 - app.sdb.create('Article', { - title: title, - url: url || '', - text: text || '', - tags: tags, - id: app.autoID.increment('article_max_id'), - votes: 0, - tid: this.trs.id, - authorId: this.trs.senderId, - timestamp: this.trs.timestamp, - comments: 0 - }) - } -} -``` - -``` -// 修改init.js -// 注册合约 -module.exports = async function () { - console.log('enter dapp init') - // 注册合约,用户自定义合约编号是从1000开始的,之前的都是system保留合约。 - app.registerContract(1000, 'cctime.postArticle') - - app.events.on('newBlock', (block) => { - console.log('new block received', block.height) - }) -} -``` - -### 4.3 自定义查询接口 - -// interface目录下新增index.js,内容如下 - -``` -// 根据条件查询被举报次数小于的文章,并按照时间倒序排 -async function getArticlesByTime(options) { - // 查询符合条件的记录数 - let count = await app.model.Article.count({ reports: { $lt: 3 } }) - // 查询符合条件的记录详情 - let articles = await app.model.Article.findAll({ - condition: { - reports: { $lt: 3 } - }, - limit: options.limit || 50, - offset: options.offset || 0, - sort: { timestamp: -1 } - }) - return { count: count, articles: articles } -} - -// 定义url路由,根据条件获取文章 -app.route.get('/articles', async (req) => { - // 获取url传进来的参数 - let query = req.query - // 默认按照timestamp来排序 - if (!query.sortBy) { - query.sortBy = 'timestamp' - } - - // 设定本次查询的key - let key = ['articles', query.sortBy, query.limit, query.offset].join('_') - // 如果内存中有本次查询的key,则直接返回其对应的结果 - if (app.custom.cache.has(key)) { - return app.custom.cache.get(key) - } - - let res = null - if (query.sortBy === 'timestamp') { - res = await getArticlesByTime(query) - } else { - throw new Error('Sort field not supported') - } - // 从articles表只能获取到地址,没有昵称,下面一系列的操作是把昵称加入到返回结果中 - let addresses = res.articles.map((a) => a.authorId) - let accounts = await app.model.Account.findAll({ - condition: { - // sql的in查询 - address: { $in: addresses } - }, - fields: ['str1', 'address'] - }) - let accountMap = new Map - for (let account of accounts) { - accountMap.set(account.address, account) - } - for (let article of res.articles) { - let account = accountMap.get(article.authorId) - if (account) { - article.nickname = account.str1 - } - } - // 将key和其值加入到内存中 - app.custom.cache.set(key, res) - return res - }) -``` - -4.4 测试 -重启asch服务。 -此时已经能看到我们刚才定义的“发布文章的”智能合约 -![](http://asch-public.oss-cn-beijing.aliyuncs.com/pics/dapp%E6%A0%B8%E5%BF%83%E5%BC%80%E5%8F%91%E6%B5%81%E7%A8%8B%E8%A7%A3%E6%9E%90/13.png) - -根据编号为1000的智能合约的定义,我们可以传4个参数给后台。 -titile:news_title -url:null -test:This is news text. -tags:tag1 - -![](http://asch-public.oss-cn-beijing.aliyuncs.com/pics/dapp%E6%A0%B8%E5%BF%83%E5%BC%80%E5%8F%91%E6%B5%81%E7%A8%8B%E8%A7%A3%E6%9E%90/15.png) - -成功创建文章,交易id为:746279f5c7831968fb8e507456651f946b4aa5127125de6070143a8f82f00ffb -![](http://asch-public.oss-cn-beijing.aliyuncs.com/pics/dapp%E6%A0%B8%E5%BF%83%E5%BC%80%E5%8F%91%E6%B5%81%E7%A8%8B%E8%A7%A3%E6%9E%90/16.png) - - -根据interface定义的接口去查询数据 - -``` -http://localhost:4096/api/dapps/75d084dc91221b380e7a3c6b3b7467935572b4ebaa1e9a3db91e1239377c1fed/articles -``` - -未完待续 - - - - - - - diff --git a/docs/exchange/XAS_integration_in_exchange_CN.md b/docs/exchange/XAS_integration_in_exchange_CN.md deleted file mode 100644 index da65f42..0000000 --- a/docs/exchange/XAS_integration_in_exchange_CN.md +++ /dev/null @@ -1,268 +0,0 @@ -# XAS与交易平台对接文档 - - ---- - -## 1 Asch基本信息 -代币名称:阿希币 -英文标识:XAS -主网上线时间:2016-08-16 -发行总量:1亿,目前总的供应量为1.11亿XAS(有一个动态变化的通胀率,发行时间越长,通胀率越低) -共识算法:dpos+pbft -交易模式:账户余额模式,非UTXO -官网:www.asch.io -在线钱包:mainnet.asch.io,基本功能可以在这里进行体验 -区块链浏览器:https://explorer.asch.io/ -Asch地址:分为2类 - -- 老地址:纯数字格式的,长度不低于10,比如3432613344807570257 -- 新地址:字母数字混合,base58格式且以大写字母A开头且长度不低于10,比如A7RD9YP37iUnYZ1SFnmAp6ySHUx3msC4r5 - - -Asch不是btc源码的山寨而是用nodejs全新开发的,目前都是纯http api,所以对接的时候请勿用btc模板的交易网站代码去生拉硬套,目前有java和nodejs版本的sdk,交易平台可以直接用,其它开发语言,需要自己封装http api。 -Asch没有钱包的概念,每个密码对应一个账户地址,也就是说一个“钱包”中只包含一个地址(实质为脑钱包),与btc、eth等区别较大。 -Asch的精度是小数点后8位,但后台处理的时候都是按照整数来处理,比如想转0.1XAS,后台实际处理的是0.1 * 100000000。 -Asch http接口文档-中文版:https://github.com/AschPlatform/asch/blob/master/docs/asch_http_interface.md -Asch http接口文档-英文版:https://github.com/AschPlatform/asch/blob/master/docs/asch_http_interface_en.md -该文档包含大部分的Asch接口,比如查询余额、转账、交易详情等,调用api返回结果为json数据。 - - -## 2 建议交易平台在局域网内搭建一个Asch全节点(重钱包) -需要用Linux服务器(建议用ubuntu 16.04),这样交易平台处理充值、提现性能要好很多并且安全,不需要有公网ip但需要能访问公网。 -下面是节点搭建命令 -``` -> sudo apt-get update && sudo apt-get install curl wget sqlite3 ntp -y -> wget http://www.asch.io/downloads/asch-linux-latest-mainnet.tar.gz -> tar zxvf asch-linux-latest-mainnet.tar.gz -> # cd 解压后的目录名字,一般是 “asch-linux-版本号-mainnet” -> chmod u+x init/*.sh && sudo ./aschd configure -> # 下面这个curl命令是加载快照,加速第一次区块链同步的速度 -> curl -sL http://www.asch.io/downloads/rebuild-mainnet3.sh | bash -> tail logs/debug.log # 查看节点同步日志,等待同步到最新的区块即可。最新高度可以在区块链浏览器中看到 https://explorer.asch.io/ -``` - -## 3 用户充值XAS -Asch1.3版本开始支持转账备注,因此交易平台可以有下面两种充值方案。 -- `为每个用户生成一个充值地址` -- `为所有用户生成同一个充值地址,根据转账备注判断具体是哪个用户进行了充值` - -### 3.1 方案1-为每个用户生成一个充值地址 -目前bit-z.com、chaoex.com、coinegg.com、coolcoin .com等早期上线XAS的交易平台都是采用这种方式。 - -#### 3.1.1 为用户生成充值地址 -用户UserA登陆交易平台,进入Asch币充值页面,平台通过调用下面的代码生成充值地址、写入数据库,并在页面上展示给用户。 -通过下面的代码为UserA生成一个Asch充值地址:ALu3f2GaGrWzG4iczamDmGKr4YsbMFCdxB,该充值地址的密码是'latin december swing love square parade era fuel circle over hub spy',这里只是举例,数据非真实。 - -##### 3.1.1.1 调用http接口生成地址 - -``` -> curl -k -X GET 'http://192.168.1.100:8192/api/accounts/new' -// JSON返回示例如下 -{ - success: true, - secret: "during crush zoo wealth horror left night upset spike iron divert lawn", // 密码 - publicKey: "261fa56f389c324fddbe8777dbc0ef3341ee7b75d1ffdc82192265633b90d503", // 公钥 - privateKey: "67c9523b7622704c4bcfe960cb32d7fa04d3eb94e30e7964d3c6a24a3647a0a3261fa56f389c324fddbe8777dbc0ef3341ee7b75d1ffdc82192265633b90d503", // 私钥 - address: "ANfXDQUZroMnrQ6vRGR7UXXtbPn3fhEVRJ" // 地址 -} -``` - -##### 3.1.1.2 用asch-cli命令行工具批量生成地址 -``` -// 如果用其他编程语言,觉得批量生成账户地址有困难还可以用asch-cli命令行工具批量生成钱包地址(含密码、地址、公钥),生成多个地址,加密存到数据库或者其它地方,然后程序直接用. -// 安装asch-cli工具 -> npm install -g asch-cli -// 批量生成钱包地址 -// 需要nodejs版本为8.x,node --version查看node版本 -> asch-cli crypto -g -? Enter number of accounts to generate 1 // 这里输入的的1表示生成一个地址,可以填写10、100或者1000等数字 -[ { address: 'AAW3Bh86U8RdHryp86KN19ScSVLpr2x6J4', - secret: 'actress south egg hen neutral salute section sign truck produce agent daughter', - publicKey: 'fd86a5bb9e06bd3a0555e27402f90b565300b0a7a6fb42ee4269aae0cfca60c6' } ] -Done -``` - -##### 3.1.1.3 nodejs代码生成地址 -``` -// 以下为nodejs编程语言的demo(目前Asch SDK支持nodejs、java这2种语言,其它语言后续会支持,当前需开发者自行编码) - -// 建议用ubuntu 16.04,nodejs 8.x最新版 -// 安装nodejs的版本管理工具nvm -> curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash -// 上面命令执行完成后再开一个os shell窗口执行下面的命令,安装nodejs 8.x -> nvm install node 8 - -// 安装依赖库(asch-js、bitcore-mnemonic),在os shell中运行 -> npm install asch-js bitcore-mnemonic - -// 以下在node中运行 -var Mnemonic = require('bitcore-mnemonic'); -var secret = new Mnemonic(Mnemonic.Words.ENGLISH).toString(); // 生成密码 -console.log(secret); // 打印密码,'latin december swing love square parade era fuel circle over hub spy' -Mnemonic.isValid(secret); // 验证密码是否符合bip39规范 - -var AschJS = require('asch-js'); -var publicKey = AschJS.crypto.getKeys(secret).publicKey; // 根据密码生成公钥 -var address = AschJS.crypto.getAddress(publicKey); // 根据公钥生成地址 -console.log(address); // 打印地址,ALu3f2GaGrWzG4iczamDmGKr4YsbMFCdxB -然后将用户名、地址、加密后的密码存入到数据库或者文件中,从而完成用户和充值地址的绑定,然后将充值地址展示在前端页面上。 -``` - -#### 3.1.2 用户进行充值 -用户UserA在Asch钱包(比如mainnet.asch.io)往充值地址转阿希币,比如转0.8XAS。 - -#### 3.1.3 交易平台确认用户充值 -交易平台检测每个新的区块,可以每隔10秒(也可以是30秒或者一分钟,技术上都没有问题,只是用户体验不一样)检测一次,每次检查时区块高度加1,检查的高度建议持久化存储并增加一个标记位“是否已检查”。 -如果区块里面交易详情的接收地址是平台的充值地址,则该笔充值记录需要显示到前端页面上并入库。 -##### 3.1.3.1 检测最新区块是否包含交易 - -``` -// 通过区块高度获去检查该区块是否有交易并取到区块id,每个新区块都要检查 -// height=3183940表示区块高度 -> curl -k -X GET 'http://mainnet.asch.io/api/blocks/get?height=3183940' -// 返回结果如下,保存到变量res中,下面会用到 -{ - "success": true, - "block": { - "id": "951e14ef5100a9724a133f74e8f5c35e0d872aee654e7ea5323e57cd1c7b004e", // 区块id - "version": 0, - "timestamp": 36252710, - "height": 3183940, - "previousBlock": "5dbf4b80063153e3bb66b46b27f9041955d308c47d57e51b4934952591519589", - "numberOfTransactions": 1, //该区块包含的交易个数 - "totalAmount": 80000000, - "totalFee": 10000000, - "reward": 350000000, - "payloadLength": 143, - "payloadHash": "5a61b58b75a70a42a6d51deba4dba560c78b2d671dfac68d37984eb464421d81", - "generatorPublicKey": "65e318f0022e3a05cc1603610125cf42af6772ac1afed657eec44bb3f8b02e64", - "generatorId": "9537352069871373416", - "blockSignature": "7b26571e3a55798d83e531817a5971ebdca59b4cfbb1edd182aff3b25c31578356b3a8992714b543f004cd7b362d7069f5dd426f411caacf06659747de1e580e", - "confirmations": "17", // 该区块的确认数 - "totalForged": 360000000 - } -} -``` -##### 3.1.3.2 根据区块id查询交易详情 - -``` -// 如果res.block.numberOfTransactions > 0,则说明该区块包含交易。 -// 然后根据res.block.id并利用下面的接口去查询该区块包含的交易详情 -> curl -k -X GET 'http://mainnet.asch.io/api/transactions?blockId=951e14ef5100a9724a133f74e8f5c35e0d872aee654e7ea5323e57cd1c7b004e' -// 返回结果如下,保存为变量trs -{ - "success": true, - "transactions": [{ - "id": "5a61b58b75a70a42a6d51deba4dba560c78b2d671dfac68d37984eb464421d81", // 交易id - "height": "3183940", //区块高度 - "blockId": "951e14ef5100a9724a133f74e8f5c35e0d872aee654e7ea5323e57cd1c7b004e", //区块id - "type": 0, // 交易类型,0:XAS普通转账 - "timestamp": 36252686, // 交易时间戳,Asch时间,可以换算成现实世界的时间 - "senderPublicKey": "40e322be1ec9084f48a17b5fecf88d59d0c70ce7ab06b1c4f6d285acfa3b0525", - "senderId": "AC4i4srjg1TyW24p8M4B8NTcYApUgvTpkd", // 发送地址 - "recipientId": "ALu3f2GaGrWzG4iczamDmGKr4YsbMFCdxB", // 接收地址,如果是平台地址,则需要做处理 - "amount": 80000000, //转账金额,除以100000000后是真实的XAS个数,这里0.8XAS - "fee": 10000000, - "signature": "08a97ba29f7db324b31f782272e17c048f4b99d1761830bd7f541c484c28fcf14b1ee0dbbdd05ab2e80d186473e67d9bfed8e27b8c5e096d29a7f521236d8900", - "signSignature": "", - "signatures": null, - "confirmations": "20", // 区块确认数 - "args": [], - "message": "", // 转账备注 - "asset": { - - } - }], - "count": 1 // 该区块包含的交易个数 -} - -// 如果数组trs.transactions.length>0,则循环遍历trs.transactions得到元素i,如果(i.type == 0 and i.recipientId是平台的地址),那么前端页面就要展示该充值记录并将该记录(充值id、充值地址、数量、确认数、发送时间、充值状态、交易id)写入到本地数据库中。 - -// 充值状态是由确认数决定的,具体是几,由平台自己定,如果入库时确认数未满足平台标准,则充值状态是“未确认”,否则就是“已确认”.(目前Asch网络认为6个确认就是安全的,交易平台可适当增大该值。) - -// 每隔1分钟对本地数据库中所有的“未确认”充值记录进行再次确认,根据数据库中的“交易id”利用下面的接口去检查交易详情 -> curl -k -X GET 'http://mainnet.asch.io/api/transactions/get?id=5a61b58b75a70a42a6d51deba4dba560c78b2d671dfac68d37984eb464421d81' -{ - "success": true, - "transaction": { - "id": "5a61b58b75a70a42a6d51deba4dba560c78b2d671dfac68d37984eb464421d81", - "height": "3183940", - "blockId": "951e14ef5100a9724a133f74e8f5c35e0d872aee654e7ea5323e57cd1c7b004e", - "type": 0, - "timestamp": 36252686, - "senderPublicKey": "40e322be1ec9084f48a17b5fecf88d59d0c70ce7ab06b1c4f6d285acfa3b0525", - "senderId": "AC4i4srjg1TyW24p8M4B8NTcYApUgvTpkd", - "recipientId": "ALu3f2GaGrWzG4iczamDmGKr4YsbMFCdxB", //接收地址 - "amount": 80000000, // 金额 - "fee": 10000000, - "signature": "08a97ba29f7db324b31f782272e17c048f4b99d1761830bd7f541c484c28fcf14b1ee0dbbdd05ab2e80d186473e67d9bfed8e27b8c5e096d29a7f521236d8900", - "signSignature": "", - "signatures": null, - "confirmations": "7837", // 确认数 - "args": [], - "message": "", // 转账备注信息 - "asset": { - - } - } -} -// 当"confirmations"达到平台要求后,更改数据库中的“充值状态”为“已确认”并显示在前端页面,最后用户UserA的XAS余额做相应的增加。 - -``` -至此用户UserA完成了充值流程。 - -#### 3.1.4 交易平台将用户充值的XAS转到一个总账户中 -充值完成后,交易平台再将这些分散的用户xas转账到交易平台自己的总账户中(请一定保存好密码)。 -总账户:可以做为平台的Asch冷钱包或者热钱包供用户提现。 -举例,平台XAS总账户地址:A7RD9YP37iUnYZ1SFnmAp6ySHUx3msC4r5 -Asch提供了下面2种方式进行转账操作。 - -##### 3.1.4.1 通过不安全的api进行转账 -这种方式是把密钥放到请求里面并且明文发送给服务器进行交易的生成和签名,不安全,不建议使用。如果非要使用这种方式,务必在局域网内搭建一台Asch节点服务器,用来提供API服务。 - -- 汇总前通过查询本地数据库将XAS余额大于0的账户找到 - -- 可以利用如下api将充值的XAS转入到平台总账户中,该操作消耗0.1XAS手续费 -``` -> curl -k -H "Content-Type: application/json" -X PUT -d '{"secret":"latin december swing love square parade era fuel circle over hub spy","amount":70000000,"recipientId":"A7RD9YP37iUnYZ1SFnmAp6ySHUx3msC4r5","message":"beizhu"}' 'http://192.168.1.100:8192/api/transactions' && echo // 70000000表示0.7 XAS,因为网络需要收取固定的0.1XAS手续费,所以UserA的充值地址只可以转出0.7 XAS -// 返回结果如下 -{ - "success": true, // 转账状态,成功 - "transactionId": "6d9b9338ea71ca74a41995458959250e16e49f52b31f4887ac28d3cc3586b1a1" // 交易id -} -``` - -##### 3.1.4.2 通过安全的api进行转账 -建议使用这种安全的方法进行转账,此种方法是在本地生成交易信息并签名,然后广播到区块链网络中,这里对Asch Server没有安全性要求。 -``` -var asch = require('asch-js'); -var targetAddress = "A7RD9YP37iUnYZ1SFnmAp6ySHUx3msC4r5"; // 接受地址 -var amount = 0.7*100000000; // 0.7 XAS -var message = 'beizhuxinxi'; // 转账备注 -var password = 'latin december swing love square parade era fuel circle over hub spy'; // 发送者主密码 -var secondPassword=null; // 发送者二级密码,如果没有设置的话就是null -// 生成交易信息并签名 -var transaction = asch.transaction.createTransaction(targetAddress, amount, message, password, secondPassword || undefined); -JSON.stringify({"transaction":transaction}) -'{"transaction":{"type":0,"amount":70000000,"fee":10000000,"recipientId":"A7RD9YP37iUnYZ1SFnmAp6ySHUx3msC4r5","message":"beizhuxinxi","timestamp":43831575,"asset":{},"senderPublicKey":"d1cda821c7f98436f0c7824b96e9fe4dba50d54ed8fd69a92752cd923e416fc2","signature":"005e529e580010398424dbbd65b9c154b37f6cd575010a4f6d9396594311c1ef62487f1040a2cba1dd16a5dba3d12605d211fa08171967886ce9ef301ae82f05","id":"0f28435e9c395dd6b825bda167359bc23d41b5fc632afb59fedfafa298c27cde"}}' - -// 将上面生成的转账操作的交易数据通过post提交给asch server -curl -H "Content-Type: application/json" -H "magic:5f5b3cf5" -H "version:''" -k -X POST -d '{"transaction":{"type":0,"amount":70000000,"fee":10000000,"recipientId":"A7RD9YP37iUnYZ1SFnmAp6ySHUx3msC4r5","message":"beizhuxinxi","timestamp":43831575,"asset":{},"senderPublicKey":"d1cda821c7f98436f0c7824b96e9fe4dba50d54ed8fd69a92752cd923e416fc2","signature":"005e529e580010398424dbbd65b9c154b37f6cd575010a4f6d9396594311c1ef62487f1040a2cba1dd16a5dba3d12605d211fa08171967886ce9ef301ae82f05","id":"0f28435e9c395dd6b825bda167359bc23d41b5fc632afb59fedfafa298c27cde"}}' http://192.168.1.100:8192/peer/transactions -``` - - -### 3.2 方案2-为所有用户生成同一个充值地址 -所有的用户共用一个Asch充值地址,充值时填写备注信息为自己在交易平台的用户名或者id,这样就不需要生成多个Asch充值地址了,但是如果用户填写错备注信息的话处理起来较为麻烦,需要专人客服去处理。 -该种方式,大体流程和方案1一致,这里不再赘述。 - - -## 4 提币XAS -提现操作就是转账,把平台的币转给用户。 -### 4.1 用户绑定提币地址 -用户登陆Asch提现页面,参考其它代币,让用户可以自行绑定提现地址。 -### 4.2 用户进行提币 -输入提币数量,手机短信验证,点击确认。 -### 4.2 平台执行提币操作 -参考“3.1.4”章节,有2种转账方式,请自行决定用哪一种。接口会返回,提币的交易id,记录到数据库中并展示到前端页面,更新提币状态为“成功”。 -### 4.3 用户确认 -用户自行确认提币结果,如有疑问,可以拿着交易id来平台这里进行查询验证。 diff --git a/docs/exchange/XCT_integration_in_exchange_CN.md b/docs/exchange/XCT_integration_in_exchange_CN.md deleted file mode 100644 index d4e0430..0000000 --- a/docs/exchange/XCT_integration_in_exchange_CN.md +++ /dev/null @@ -1,345 +0,0 @@ -# CCTime.XCT与交易平台对接文档 - - - ---- - -写在前面的话,本文档同样适用于在Asch平台发行的其它资产与交易平台的对接,其它资产请将下面的CCTime.XCT 换成你的资产名即可。 - -## 1 CCTime.XCT基本信息 -中文名称:时讯币 -英文标识:CCTime.XCT(前台页面可以展示为XCT,但后端调用接口处理时则必须是CCTime.XCT) -发行总量:最大发行总量100亿(目前已空投10亿,精度为8位) -官网:http://cctime.org -在线钱包:http://asch.cn ,基本功能可以在这里进行体验。 -特别声明:XCT是在Asch发行的资产(UIA),所以可以跟xas共用一个地址,具体是否共用,由交易平台自行决定。 -发行说明:采用空投的方式将XCT分给XAS、BTC、ETH、BTS持有者。 - -备注:由于XCT是在Asch上面发行的资产,所以XCT的在Asch主链上的转账需要支付XAS做为手续费,目前每笔XCT转账都需要固定的0.1XAS手续费。(类比以太坊的ERC20资产转账需要消耗ETH) - -对XCT的操作可以通过Asch API来进行。 -Asch http接口文档-中文版:https://github.com/AschPlatform/asch/blob/master/docs/asch_http_interface.md -Asch http接口文档-英文版:https://github.com/AschPlatform/asch/blob/master/docs/asch_http_interfaceen.md -该文档包含大部分的Asch接口,比如查询余额、转账、交易详情等,调用api返回结果为json数据。 - - -## 2 建议交易平台在局域网内搭建一个Asch全节点 -需要用Linux服务器(建议用ubuntu 16.04),这样交易平台处理充值、提现性能要好很多并且安全,不需要有公网ip但需要能访问公网。 -下面是节点搭建命令 - -``` -> sudo apt-get update && sudo apt-get install curl wget sqlite3 ntp -y -> wget http://www.asch.io/downloads/asch-linux-latest-mainnet.tar.gz -> tar zxvf asch-linux-latest-mainnet.tar.gz -> # cd 解压后的目录名字,一般是 “asch-linux-版本号-mainnet” -> chmod u+x init/*.sh && sudo ./aschd configure -> # 下面这个curl命令是加载快照,加速第一次区块链同步的速度 -> curl -sL http://www.asch.io/downloads/rebuild-mainnet3.sh | bash -> tail logs/debug.log # 查看节点同步日志,等待同步到最新的区块即可。最新高度可以在区块链浏览器中看到 https://explorer.asch.io/ -``` -举例:这里搭建完成后局域网ip是:192.168.1.100 - -备注:交易平台开发对接阶段可以用我们提供的测试服务器http://101.200.84.232:4097 ,测试账户密码'found knife gather faith wrestle private various fame cover response security predict' - -## 3 充值XCT -Asch1.3版本开始支持转账备注,因此交易平台可以有两种充值方案。 - -- `为每个用户生成一个充值地址` -- `为所有用户生成同一个充值地址,根据转账备注判断具体是哪个用户进行了充值` - -### 3.1 方案1-为每个用户生成一个充值地址 -目前bit-z.com、chaoex.com、coinegg.com、coolcoin.com等早期上线XAS的交易平台都是采用这种方式。 - - -#### 3.1.1 为用户生成充值地址 -用户UserA登陆交易平台,进入XCT充值页面,平台通过调用下面的代码生成充值地址,并将地址、密码(需要加密存储)写入数据库或者其它持久化存储中,并在页面上展示给用户。 - -通过下面几种生成地址方法中的任意一种为UserA生成一个Asch充值账户。 -地址:ANH2RUADqXs6HPbPEZXv4qM8DZfoj4Ry3M -密码:'found knife gather faith wrestle private various fame cover response security predict',这里只是举例,数据非真实。 - -##### 3.1.1.1 调用http接口生成地址 - -``` -curl -k -X GET 'http://192.168.1.100:4096/api/accounts/new' - -// JSON返回示例: -{ - success: true, - secret: "during crush zoo wealth horror left night upset spike iron divert lawn", // 主密码 - publicKey: "261fa56f389c324fddbe8777dbc0ef3341ee7b75d1ffdc82192265633b90d503", // 公钥 - privateKey: "67c9523b7622704c4bcfe960cb32d7fa04d3eb94e30e7964d3c6a24a3647a0a3261fa56f389c324fddbe8777dbc0ef3341ee7b75d1ffdc82192265633b90d503", // 私钥 - address: "ANfXDQUZroMnrQ6vRGR7UXXtbPn3fhEVRJ" // 地址 -} -``` - -##### 3.1.1.2 用asch-cli命令行工具批量生成地址 - -``` -// 用asch-cli命令行工具批量生成钱包地址(含密码、地址、公钥),生成多个地址,加密存到数据库或者其它地方,然后程序直接用. -// 安装asch-cli工具 -npm install -g asch-cli -// 批量生成钱包地址 -asch-cli crypto -g -? Enter number of accounts to generate 1 //这里的1表示生成一个地址,可以填写10、100等数字 -[ { address: 'AAW3Bh86U8RdHryp86KN19ScSVLpr2x6J4', - secret: 'actress south egg hen neutral salute section sign truck produce agent daughter', - publicKey: 'fd86a5bb9e06bd3a0555e27402f90b565300b0a7a6fb42ee4269aae0cfca60c6' } ] -Done -``` - -##### 3.1.1.3 nodejs代码生成地址 - -``` -// 以下为nodejs编程语言的demo(目前Asch SDK支持nodejs、java这2种语言,其它语言后续会支持,当前需开发者自行编码) - -// 建议用ubuntu 16.04,nodejs 8.x最新版 -// 安装nodejs的版本管理工具nvm -curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash -// 上面命令执行完成后再开一个os shell窗口执行下面的命令,安装nodejs 8.x -nvm install node 8 - -// 安装依赖库(asch-js、bitcore-mnemonic),在os shell中运行 -npm install asch-js bitcore-mnemonic - -// 以下在node中运行 -var Mnemonic = require('bitcore-mnemonic'); -var secret = new Mnemonic(Mnemonic.Words.ENGLISH).toString(); // 生成密码 -console.log(secret); // 打印密码,'latin december swing love square parade era fuel circle over hub spy' -Mnemonic.isValid(secret); // 验证密码是否符合bip39规范 - -var AschJS = require('asch-js'); -var publicKey = AschJS.crypto.getKeys(secret).publicKey; // 根据密码生成公钥 -var address = AschJS.crypto.getAddress(publicKey); // 根据公钥生成地址 -console.log(address); // 打印地址,ALu3f2GaGrWzG4iczamDmGKr4YsbMFCdxB -然后将用户名、地址、加密后的密码存入到数据库或者文件中,从而完成用户和充值地址的绑定,然后将充值地址展示在前端页面上。 -``` - - - - -#### 3.1.2 用户进行充值 -用户UserA在XCT钱包(比如http://asch.cn)往充值地址转XCT,比如转10 XCT。 - -#### 3.1.3 交易平台确认用户充值 -交易平台检测每个新的区块,可以每隔10秒检测一次,每次检查时区块高度加1,检查的高度建议持久化存储并增加一个标记位“是否已检查”,这样做的优势:能最快地检测到用户的充值信息并保证充值金额的正确(用户在极短时间内充值多次相同的金额也能保证结果准确)。 - -下面演示UserA的充值确认过程。 -``` -// 通过区块高度获去检查该区块是否有交易,每个新区块都要检查 -// height=223994,表示最新的区块高度是223994 -curl -k -X GET 'http://192.168.1.100:4097/api/blocks/full?height=223994' -// 返回结果如下(该json结果保存到变量res中) -{ - success: true, // 接口是否成功被调用 - block: { - id: "322e0f70f1e9de584fcf60fdcd10306691dbcdb7d738db66062c860dc29e3333", // 区块id - version: 0, - timestamp: 41428170, - height: 223994, // 区块高度 - previousBlock: "20594953fed0d67c87639f0c42050d56b3d1ddc06a72990b916dbd6676288310", - numberOfTransactions: 1, - totalAmount: 0, - totalFee: 10000000, // 该区块中所有交易的手续费之和0.1XAS(xas精度是8) - reward: 350000000, - payloadLength: 177, - payloadHash: "a43f6d3fb54b27c90503cb5d619e63f33cf1e2b7df72354ebbe4d6aab7175145", - generatorPublicKey: "238bdc9d75760560d438a86adef6f3126c5cd0f0be43ebbd9a9053f705a30176", - generatorId: "15652667420882928094", - blockSignature: "ab322a2adf7fe1eb02c746bafa365e7bc0408b5fefc2d8ae3954cfbf0d3a6e74b44ac7b178a7d663610bd30296a7c1cf95af6ee2ed3417fbf5642ccd53e6480a", - totalForged: 360000000, - transactions: [{ // 该区块包含的所有交易详情列表,每个元素代表一个交易 - id: "a43f6d3fb54b27c90503cb5d619e63f33cf1e2b7df72354ebbe4d6aab7175145", // 充值交易id - height: 223994, - blockId: "322e0f70f1e9de584fcf60fdcd10306691dbcdb7d738db66062c860dc29e3333", - type: 14, // XCT转账的类型为14 - timestamp: 41428161, // 充值时间戳,Asch纪元,可以转换为unix timestamp - senderPublicKey: "b33b5fc45640cfc414981985bf92eef962c08c53e1a34f90dab039e985bb5fab", - requesterPublicKey: "", - senderId: "AMzDw5BmZ39we18y7Ty9VW79eL9k7maZPH", // 发送者地址 - recipientId: "ANH2RUADqXs6HPbPEZXv4qM8DZfoj4Ry3M", // 接收者地址 - amount: 0, - fee: 10000000, // 本条交易转账手续费0.1XAS(目前每笔转账都是固定的0.1XAS手续费) - signature: "9e77b3868869af334d539d23feb5d4746db5c842466207f9c22f7e4dee91f4722c8738bc8bcc36abb7365d24dadb26727110ab18673b9bb86a32c29e4b96260c", - signSignature: "", - signatures: null, - args: null, - message: "deposit 10 XCT", // 冲值时的备注信息 - asset: { - uiaTransfer: { - transactionId: "a43f6d3fb54b27c90503cb5d619e63f33cf1e2b7df72354ebbe4d6aab7175145", // 充值交易id - currency: "CCTime.XCT", // 资产名字,CCTime.XCT代表XCT - amount: "1000000000" // 转账数额=真实数额10*XCT精度8,这里是10 XCT - } - } - }] - } -} - -// 如果上面的res.block.numberOfTransactions == 0则直接跳过该区块,否则循环遍历的res.block.transactions交易详情数组得到每条交易记录trs. -// 如果(trs.type == 14 and trs.recipientId在'交易平台的充值地址列表'中 and trs.asset.uiaTransfer.currency == 'CCTime.XCT')则代表该交易为XCT的冲值记录。此时前端页面就要展示该充值记录并将该记录(充值id、平台的充值地址、数量、确认数、发送时间、充值状态、交易id)写入到本地数据库中。 - -// 充值状态是由确认数决定的,具体是几,由平台自己定,如果入库时确认数未满足平台标准,则充值状态是“未确认”,否则就是“已确认”。(目前Asch网络认为6个确认就是安全的,交易平台可适当增大该值。) -// 每隔2分钟(交易平台可以自定义该时间,时间越短用户体验越好)对本地数据库中所有的“未确认”充值记录进行再次确认,根据数据库中的“交易id”利用下面的接口去检查交易详情 -curl -k -X GET 'http://192.168.1.100:4097/api/transactions/get?id=a43f6d3fb54b27c90503cb5d619e63f33cf1e2b7df72354ebbe4d6aab7175145' -{ - success: true, - transaction: { - id: "a43f6d3fb54b27c90503cb5d619e63f33cf1e2b7df72354ebbe4d6aab7175145", - height: "223994", - blockId: "322e0f70f1e9de584fcf60fdcd10306691dbcdb7d738db66062c860dc29e3333", - type: 14, - timestamp: 41428161, - senderPublicKey: "b33b5fc45640cfc414981985bf92eef962c08c53e1a34f90dab039e985bb5fab", - senderId: "AMzDw5BmZ39we18y7Ty9VW79eL9k7maZPH", - recipientId: "ANH2RUADqXs6HPbPEZXv4qM8DZfoj4Ry3M", - amount: 0, - fee: 10000000, - signature: "9e77b3868869af334d539d23feb5d4746db5c842466207f9c22f7e4dee91f4722c8738bc8bcc36abb7365d24dadb26727110ab18673b9bb86a32c29e4b96260c", - signSignature: "", - signatures: null, - confirmations: "326", // 区块确认数 - args: null, - message: "deposit 10 XCT", - asset: { - - } - } -} -// 当"confirmations"达到平台要求后,更改数据库中的“充值状态”为“已确认”并显示在前端页面,最后用户UserA在交易平台的XCT余额做相应的增加。 - -``` -至此用户UserA完成了充值流程。 - -#### 3.1.4 交易平台将用户充值的XCT转到一个总账户中 -充值完成后,交易平台再将这些分散的用户XCT转账到交易平台自己的总账户中(请一定保存好密码)。 -总账户:可以做为平台的XCT冷钱包或者热钱包供用户提现。 -举例,平台XCT总账户地址:A7RD9YP37iUnYZ1SFnmAp6ySHUx3msC4r5 - -Asch提供了下面2种方式进行XCT转账操作,请选择其中一种即可。 - -##### 3.1.4.1 通过不安全的api进行XCT转账 -这种方式是把密钥放到请求里面并且明文发送给服务器进行交易的生成和签名,不安全,不建议使用。如果非要使用这种方式,务必在局域网内搭建一台Asch节点服务器,用来提供API服务。 - -- 汇总前需要确定UserA充值地址上有多少个XCT -``` -curl -X GET http://192.168.1.100:4097/api/uia/balances/ANH2RUADqXs6HPbPEZXv4qM8DZfoj4Ry3M/CCTime.XCT -// 返回结果如下 -{ - success: true, - balance: { - currency: "CCTime.XCT", - balance: "990900000000", // 该值=余额*100000000 - maximum: "10000000000000000", - precision: 8, // XCT的精度 - quantity: "20000000000000000", - writeoff: 0, - allowWriteoff: 0, - allowWhitelist: 0, - allowBlacklist: 0, - maximumShow: "100000000", - quantityShow: "200000000", - balanceShow: "9909" // 该账户余额为9909个XCT,平台可以设定当该值大于某个值时才会进行向总钱包汇总 - } -} -``` - -- 确认UserA充值地址上是否有XAS(XCT每次转账都需要消耗0.1XAS) -``` -curl -X GET 'http://192.168.1.100:4097/api/accounts/getBalance?address=ANH2RUADqXs6HPbPEZXv4qM8DZfoj4Ry3M' -// 返回结果 -{ - success: true, - balance: 0, // 0个XAS - unconfirmedBalance: 0 -} -``` - -- 如果UserA充值地址上的XAS余额小于0.1,则需要给该地址转一笔小额的XAS做XCT转账时的手续费 -``` -// 'object betray start purse camp remove lucky cry soccer middle harvest clerk'为有XAS余额的账户 -curl -k -H "Content-Type: application/json" -X PUT -d '{"secret":"object betray start purse camp remove lucky cry soccer middle harvest clerk","amount":100000000,"recipientId":"ANH2RUADqXs6HPbPEZXv4qM8DZfoj4Ry3M"}' 'http://192.168.1.100:4097/api/transactions' && echo // 给用户充值地址转1XAS做为后面XCT转账时的手续费,该操作本身也消耗0.1XAS手续费 -// 返回结果 -{ - "success": true, - "transactionId": "0c8d1c0174ceb563d074a742934920b07fb8a29b5ff1d8450d0885c300dedd53" -} -``` - -- 将UserA充值地址上的全部XCT转入到平台总账户中 -``` -curl -k -H "Content-Type: application/json" -X PUT -d '{"secret":"found knife gather faith wrestle private various fame cover response security predict","amount":"99090000000","recipientId":"A7RD9YP37iUnYZ1SFnmAp6ySHUx3msC4r5","currency":"CCTime.XCT"}' 'http://192.168.1.100:4097/api/uia/transfers' && echo // 99090000000表示9909 XCT -// 返回结果如下 -{ - "success": true, // 转账状态,成功 - "transactionId": "ab0f548a3a3b56d437187d1c26a25a3d3c5411821955301ab44dcd8511f5da64" // 交易id -} - -``` - -##### 3.1.4.2 通过安全的api进行XCT转账(本地签名) -建议使用这种安全的方法进行转账,此种方法是在本地生成交易信息并签名,然后广播到区块链网络中,这里对Asch Server没有安全性要求。 - -- 只有XAS转账和XCT转账和上面章节不一样,其它查询操作一致。 - -- 如果UserA充值地址上的XAS余额小于0.1,则需要给该地址转一笔小额的XAS做XCT转账时的手续费 -``` -// asch-js安装参考《3.1.1.3 nodejs代码生成地址》章节 -var asch = require('asch-js'); -var targetAddress = "ANH2RUADqXs6HPbPEZXv4qM8DZfoj4Ry3M"; -var amount = 1*100000000; //1 XAS -var password = 'object betray start purse camp remove lucky cry soccer middle harvest clerk'; -var message = ''; // 转账备注 -// 生成交易信息并签名 -var transaction = asch.transaction.createTransaction(targetAddress, amount, message, password); -JSON.stringify({transaction:transaction}) -'{"transaction":{"type":0,"amount":100000000,"fee":10000000,"recipientId":"A7RD9YP37iUnYZ1SFnmAp6ySHUx3msC4r5","timestamp":5333378,"asset":{},"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","signature":"2d47810b7d9964c5c4d330a53d1382769e5092b3a53639853f702cf4a382aafcff8ef8663c0f6856a23f41c249944f0c3cfac0744847268853a62af5dd8fc90a","signSignature":"dfa9b807fff362d581170b41c56a2b8bd723c48d1f100f2856d794408723e8973016d75aeff4705e6837dcdb745aafb41aa10a9f1ff8a77d128ba3d712e90907","id":"a95c3a5bda15f3fd38295950268c234e922aae97cf803dd8c38c73a6ccf7c561"}}' - -// 将上面生成的转账操作的交易数据通过post提交给asch server -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":0,"amount":100000000,"fee":10000000,"recipientId":"A7RD9YP37iUnYZ1SFnmAp6ySHUx3msC4r5","timestamp":5333378,"asset":{},"senderPublicKey":"3e6e7c90571b9f7dabc0abc2e499c2fcee8e436af3a9d5c8eadd82ac7aeae85f","signature":"2d47810b7d9964c5c4d330a53d1382769e5092b3a53639853f702cf4a382aafcff8ef8663c0f6856a23f41c249944f0c3cfac0744847268853a62af5dd8fc90a","signSignature":"dfa9b807fff362d581170b41c56a2b8bd723c48d1f100f2856d794408723e8973016d75aeff4705e6837dcdb745aafb41aa10a9f1ff8a77d128ba3d712e90907","id":"a95c3a5bda15f3fd38295950268c234e922aae97cf803dd8c38c73a6ccf7c561"}}' http://192.168.1.100:4096/peer/transactions -// 返回结果 -{ - "success":true, //转账成功 - "transactionId":"a95c3a5bda15f3fd38295950268c234e922aae97cf803dd8c38c73a6ccf7c561" -} -``` - -- 将UserA充值地址上的全部XCT转入到平台总账户中 -``` -var asch = require('asch-js'); -var currency = 'CCTime.XCT'; // 资产名 -// 本次转账数(9909)=真实数量(9909)*10**精度(8) -var amount = String(9909 * 100000000); -var recipientId = 'A7RD9YP37iUnYZ1SFnmAp6ySHUx3msC4r5'; // 接收地址,即总账户地址 -var message = 'memo'; // 转账备注 -var secret = 'found knife gather faith wrestle private various fame cover response security predict'; -var trs = asch.uia.createTransfer(currency, amount, recipientId, message, secret); - -JSON.stringify({transaction:trs}) -'{"transaction":{"type":14,"amount":0,"fee":10000000,"recipientId":"A7RD9YP37iUnYZ1SFnmAp6ySHUx3msC4r5","senderPublicKey":"2856bdb3ed4c9b34fd2bba277ffd063a00f703113224c88c076c0c58310dbec4","timestamp":42795778,"message":"memo","asset":{"uiaTransfer":{"currency":"CCTime.XCT","amount":"990900000000"}},"signature":"a09e2cd425e32656c8a1411ffde48dd53917f65af562dd235e47bca6e151ed8d9742ed1e799a5a2ed26dfce0761ff518ced691953a3f150ecab5bfa740a1590c","id":"5c61ce9c88c7a957d6dd4e2585c7382d0bdd9a4f889976aefae172f5211610fb"}}' - -// 广播该交易 -curl -H "Content-Type: application/json" -H "magic:594fe0f3" -H "version:''" -k -X POST -d '{"transaction":{"type":14,"amount":0,"fee":10000000,"recipientId":"A7RD9YP37iUnYZ1SFnmAp6ySHUx3msC4r5","senderPublicKey":"2856bdb3ed4c9b34fd2bba277ffd063a00f703113224c88c076c0c58310dbec4","timestamp":42795778,"message":"memo","asset":{"uiaTransfer":{"currency":"CCTime.XCT","amount":"990900000000"}},"signature":"a09e2cd425e32656c8a1411ffde48dd53917f65af562dd235e47bca6e151ed8d9742ed1e799a5a2ed26dfce0761ff518ced691953a3f150ecab5bfa740a1590c","id":"5c61ce9c88c7a957d6dd4e2585c7382d0bdd9a4f889976aefae172f5211610fb"}}' 'http://localhost:4096/peer/transactions' && echo -// 返回结果 -{"success":true} -``` - - - -### 3.2 方案2-转账备注方式 -所有的用户共用一个XCT充值地址,充值时填写备注信息为自己在交易平台的用户名或者id,这样就不需要生成多个地址了,但是用户填写错备注的话处理起来较为麻烦。 -该种方式,大体流程和方案1一致,这里不再赘述。 - - -## 4 提币XCT -提现操作就是转账,把平台的币转给用户。 -### 4.1 用户绑定提币地址 -用户登陆Asch提现页面,参考其它代币,让用户可以自行绑定提现地址。 -XCT地址符合base58规则、以大写字母A开头、地址长度至少是24个字母数字的混合体。 -### 4.2 用户进行提币 -输入提币数量,手机短信验证,点击确认。 - -### 4.2 平台执行提币操作 -参考“3.1.4”章节,有2种转账方式,请自行决定用哪一种。接口会返回,提币的交易id,记录到数据库中并展示到前端页面,更新提币状态为“成功”。 -### 4.3 用户确认 -用户自行确认提币结果,如有疑问,可以拿着交易id来平台这里进行查询验证。 diff --git a/docs/whitepaper/assets/chart.png b/docs/whitepaper/assets/chart.png deleted file mode 100644 index 8d66271..0000000 Binary files a/docs/whitepaper/assets/chart.png and /dev/null differ diff --git a/docs/whitepaper/assets/chart2.png b/docs/whitepaper/assets/chart2.png deleted file mode 100644 index 0fcf152..0000000 Binary files a/docs/whitepaper/assets/chart2.png and /dev/null differ diff --git a/docs/whitepaper/assets/math.png b/docs/whitepaper/assets/math.png deleted file mode 100644 index 32bcabb..0000000 Binary files a/docs/whitepaper/assets/math.png and /dev/null differ diff --git a/docs/whitepaper/assets/score.png b/docs/whitepaper/assets/score.png deleted file mode 100644 index 4895540..0000000 Binary files a/docs/whitepaper/assets/score.png and /dev/null differ diff --git a/docs/whitepaper/assets/wechat.png b/docs/whitepaper/assets/wechat.png deleted file mode 100644 index 5a60a1b..0000000 Binary files a/docs/whitepaper/assets/wechat.png and /dev/null differ diff --git a/docs/whitepaper/cctime.md b/docs/whitepaper/cctime.md deleted file mode 100644 index aa3cbb9..0000000 --- a/docs/whitepaper/cctime.md +++ /dev/null @@ -1,248 +0,0 @@ -title: CCTime白皮书 ---- -# 0 项目介绍 - -CCTime(Cryptocurrency Time)是基于阿希(Asch)侧链技术开发的 -分布式社会新闻分享与交流平台。CCTime 在 Hacker News 的基础上进行重 -构,使用区块链技术改变现有中心化的内容市场格局,解决优质内容难以识别、 -传播和变现的问题,通过全新的内容价值评估体系保证优质内容的生产者直接 -获得收益。通过“打赏模式”给予优质新闻发布者、分享者代币激励,构建一 -个有价值且符合大众需求的新闻聚合和内容分享平台。 - -# 1 为什么要做 CCTime - -## 1.1 思想起源 - -CCTime(Cryptocurrency Time)作为阿希应用的示范性案例,其创意来源 -于 Hacker News。CCTime 仅包括账户注册与登录、新闻发布、浏览、评论、 -投票等简单功能,设计的核心思想是不做内容原创,不做版权保护,不做社交, -只做内容分享与评论,使用区块链技术打造轻量级新闻聚合平台。 - -随着开发进度的加深,我们相信这个项目是具有深度发展潜力的,主要有 -以下原因: - -1. CCTime 的出现填补了以新闻分享和评论为主的区块链行业空白; - -2. 币圈有一大批高水平的用户,但目前还没有一个像 Hacker News 这样高质量的社区把这群优质用户聚集起来,CCTime 是一个机会,币圈也需要这样一个产品; - -3. 与传统新闻聚合平台相比,加入代币激励的功能,可以有效解决优质内容难以识别与变现的问题。基于区块链的 CCTime 旨在实现价值回归于价值创造者和传递者手里,让所有的参与者共同分享价值,而不是大部分收益由公司掌控; - -4. YOYOW 、DECENT 、亿书更注重于内容原创与版权保护,CCTime 只是一个内容分享与评论的平台,属于新闻聚合类的平台,它的竞品应该是今日头条和 flipboard; - -5. 与今日头条相比,CCTime 排名算法避免了机器学习算法带来的偏见深化问题,因为机器只会推荐你喜欢的内容; - -6. CCTime 的功能简单易用,可以让用户迅速上手; - -7. 在如今快速阅读膨胀的时代,新闻应用一直是一个强烈的需求,市场空间巨大。 - - -## 1.2 运作模式 - -中心化的内容发布平台权力全部集中在中心机构,会导致中心化机构权力过大。完全去中心化的内容发布平台权力无法监管,可能会导致大量低俗、色情、反动等言论的自由传播。 - -CCTime(Cryptocurrency Time)的理念是传播价值信息。因此,为了减轻、避免,甚至杜绝完全去中心化所带来的负面影响,CCTime 系统采用多种方式结合的监管模式。 - -初期采用受托人作为监管者,受托人通过联合举报的方式来进行过滤,同时监管者的权利也会受到其他人的监督,避免权利的滥用。后期考虑采用“抵押 -发文”的机制,每位发布者在发表信息的时候,通过抵押 XCT(时讯币)发文,系统将根据抵押发文进行排名,供阅读受众“点评”,当达到一定数量的星级时, -发布者便可通过赎回方式领回代币,也可以继续留给系统,作为下一次分享信息的“筹码”,通过 CCTime 系统的数据分析,抵押率会随之降低。 - -# 2 设计理念 - -## 2.1 简单易用 - -仅包括账户注册与登录、新闻发布、浏览、评论、投票等几个功能,不花费精力做社交、版权保护和原创内容,任何人都能够快速轻松使用。 - -## 2.2 监管合规 - -设置监管者角色,对不合规内容(色情、反动、暴力、凶杀等)进行审查。同时监管者也会受到所有人的监督,避免权利的滥用。 - -## 2.3 免费分发 - -代币全部进行免费分发,只 ICO,不进行融资,还原 ICO (Initial CryptoToken Offering)的本质,让更多的人可以免费持有代币。 - -## 2.4 价值共享 - -分布式价值传输,打破传统信息互联网的局限性,通过代币将产生的价值共享给所有的参与者,大家共同享受 CCTime 增值所带来的利润分配,有效的 -促进内容发布者的积极性,促使更高质量的内容产生和传播。 - - - -# 3 技术细节 - -## 3.1 资产创生 - -CCTime 是基于 Asch 应用 sdk 开发的去中心化应用,与 Asch 主链可以互通资产。CCTime 应用内部不会发行代币,代币来自主链的转入。 - -我们会在 Asch 主链注册一个叫做 CCTime 的发行商,然后使用这个发行商注册一个名为 XCT(时讯币)的资产,这个资产的全称为 CCTime.XCT(时讯币)。 - -资产发行后会被一次性转入 CCTime 应用内部,并且被锁定在这个应用的一个联合签名账户内。 - -我们会在一年之内将 95%的代币免费发放给对这个应用感兴趣的用户。 - -为什么不在 CCTime 内部创生资产? - -在主链发行资产的好处是,将来这些转入 Dapp 的资产还可以通过跨链接口转移到主链,然后再转到其他应用,以达到一币多链、一币多用的目的。 - -## 3.2 账户体系 - -Asch 主链与所有 Dapp 的账户是通用的(老版本的数字地址除外)。账户鉴权使用了非对称加密技术,因此不需要中心化的注册过程。用户只需保管一 -个账户对应的主密码,就可以进行各种区块链的写入操作,比如转账、发布新闻、打赏、点赞、评论等。 - -主密码是使用 bip39 协议生成的由若干个(12 的倍数)单词组成的助记符,而公私钥对是以主密码为种子,通过 ed25519 椭圆曲线算法计算得到 - -账户 id 或账户地址则是由公钥通过两次 sha256 哈希以及一次 ripemd160 哈希再经过 base58check 进行编码获得。 - -## 3.3 密码学算法 - -区块 id 与交易 id 使用的是 sha256 hash 算法 - -区块的记账人签名与交易签名使用的是 ed25519 算法的 sodium 实现版 - -## 3.4 合约及抽象事务模型 - -Asch 应用使用了抽象事务模型,这个模型可以表达任意的函数调用。在比特币中,区块的 payload 是交易或转账记录,在 Asch 应用中,区块的 payload 就是函数或合约调用,也叫做事务(transaction)。 - -一个事务可以修改多个状态,比如余额、昵称、新闻、评论等,事务是原子性的,要么全部执行,要么全部撤销,不会出现执行一半的情况。CCTimeime 主要包括以下具体事务: - -1. postArticle 发布文章(新闻) -2. postComment 发布评论 -3. voteArticle 给文章投票 -4. likeComment 打赏评论 -5. report 举报文章或评论 - -## 3.5 新闻排名算法 -CCTime 使用了如下的综合评分算法: -![score](./assets/score.png) -其中, -V 表示一篇文章获得的投票数,投票数以代币 XCT(时讯币)来计量 -T 表示距离发布文章的时间(单位为小时),加上 2 是考虑到一篇文章从创作出来 -至分享到 CCTime 系统需要一定的时间,也避免了由于发布时间过短导致分母 -太小的问题 -G 是一个重力因子,它决定了文章排名下降的速度,CCTime 使用的默认值为1.8 -![chart](./assets/chart.png) -从上图可以看到,有三个同时发表的帖子,得票分别为 199 票、59 票和 29 票,分别以黄色、紫色和蓝色表示。在任一个时间点上,都是黄色曲线在最上方,蓝色曲线在最下方。 -在其他条件不变的情况下,越是新发表的帖子,排名越高。或者说,一个帖子的排名,会随着时间不断下降。 -从上图可以看到,经过 24 小时之后,所有帖子的得分基本上都小于 1,这 -意味着它们都将跌到排行榜的末尾,保证了排名前列的都将是较新的内容。 -![chart2](./assets/chart2.png) -从上图可以看到,三根曲线的其他参数都一样,G 的值分别为 1.5、1.8 和 2.0。G 值越大,曲线越陡峭,排名下降得越快,意味着排行榜的更新速度越快。 -(本节内容引用了阮一峰的博客, 并稍作修改 ) - -## 3.6 激励机制 -每个事务的执行都需要消耗基础手续费,费用由发起人支付,并平均分配给所有记账人。 - -voteArticle 和 likeComment 两个事务除了基础手续费之外,发起人还需要选择支出额外的代币,用来代表投票及打赏的额度,这些额外支出的代币大部分都奖励给文章的发布者 -或评论的发布者,但少部分(10%)会进入费用池分配给记账人。 - -## 3.7 审查机制 -CCTime 是一个去中心化的系统,没有做用户身份认证,用户一般也是匿名登录,我们需要一个审查机制来防止反政府、反社会或其他违反法律的言论的出现。 - -CCTime1.0 的审查暂时由全体受托人来负责,每个受托人都可以举报任意一篇文章或评论,被举报次数超过 3 次的文章或评论将会过滤掉,但不会从底层数据库删除,仅仅是做一次标记。 - -审查机制影响的只是查询接口返回的数据,一个兼容 CCTime 协议的非标准节点仍然可以展示出所有非过滤的数据。 - - -# 4 分发机制 -XCT(时讯币)发行上限 100 亿。主创团队预留 5%代币,10%赠送给合作伙伴,其余 85%将全部空投给以币圈为主的社会各界人士,不进行融资,还原ICO (Initial Crypto-Token Offering)本质 - -## 4.1 分发原则 - -分发的原则是尽量覆盖更多的用户群体,但是以币圈内主,币圈外为次。对于币圈内采用资产证明(Proof of Asset)的方式。对于币圈外的社区,比如知乎,计划采用影响力证明的方式,但具体方案待定,方案将面向全社区征集。 - -## 4.2 币圈多社区分配公式(MCDF) - -![math](./assets/math.png) - -## 4.3 分期空投细则 - -### 4.3.1 首轮空投规则 - -1. 只针对币圈四个社区(阿希币,比特币,以太坊,比特股); - -2. 采用 5.2 节的多社区分配规则; - -3. 8 月 20 号正式开始空投, 9 月 20 号对四大公有链进行快照,并按公式计算出用户应得份额后立即分发代币 ; - -4. 分配总量 10 亿; - -5. 示例说明请参考附录 A。 - -### 4.3.2 第二期以后 - -从第二期开始,持有 XCT(时讯币)可参与空投,除了指定币种外,每个XCT(时讯币)可领取 0.1 个 XCT(时讯币),其他币种以及空投比例,方案待定。 - - -# 5 竞争优势 - -CCTime(Cryptocurrency Time)是基于阿希系统侧链的第一个 Dapp 应用(去中心化的内容分发平台),相比于 Steem、Synereo、Decent、PressOne等其他平台拥有较大的优势,具体地: - -1. 拥有阿希的技术支持和社区支持; -2. 产品模式创新,细分市场无竞争者; -3. 免费分发 - -# 6 风险提示 - -虽然 CCTime(Cryptocurrency Time)分发模式采用空投,但随着每轮空投,受众人数的增加, XCT(时讯币)难免会带来炒作(操作)风险的可能,包括但不局限: - -1. 二级交易市场形成,线下交易活跃,风险大; - -2. XCT(时讯币)一经分发,官方不再持有,持有者即为所有者, 密匙等应当妥善保存,一经丢失,官方不承担责任; - -3. CCTime(Cryptocurrency Time)是基于阿希系统的一款分布式内容分享与交流平台的应用,作为一个平台应用,参与者应当遵守相关的法律法规,禁止一切不良、反动等言论,共同打造良好的环境氛围。 - - -# 7 更多关注 -阿希团队秉承区块链分享、贡献的理念,经过长时间的调研和开发,即将向国内区块链社区分享阿希生态的第一个应用,欢迎大家的使用,同时也欢迎广大的区块链开发者加入阿希社区,共同推进中国区块链应用落地。 - -CCTime(Cryptocurrency Time)即将与大家见面,更多资讯敬请关注: - -CCTime 官网:www.cctime.org - -ASCH 官网:www.asch.so - -官方微博:北京阿希链科技有限公司 - -ASCH 官方微信公众号: - -![wechat](./assets/wechat.png) - -官方 QQ 群: - -CCTime 官方 1 群:644658047 - -CCTime 官方 2 群:65622549 - -#8 附录A:XCT(时讯币)首轮空投示例 - -举例:假如本轮参与阿希币的总量为 4000 万(Xxas),阿希的加权系数为 2 阿希 -币的总量按照 1 亿(Sxas)计算。 -阿希币的比例: -Pxas=Xxas*Kxas/Sxas=4000 万*2/1 亿=0.8 -假如本轮参与比特币的总量为 500 万(Xbtc),比特币的加权系数为 1,比特币 -的总量按照 2000 万(Sbtc)计算。 -比特币的比例: -Pbtc=Xbtc*Kbtc/Sbtc=500 万*1/2000 万=0.25 -假如本轮参与以太坊币的总量为 5000 万(Xeth),以太坊币的加权系数为 1,以 -太坊币的总量按照 1 亿(Seth)计算。 -以太坊的比例: -Peth=Xeth*Keth/Seth=5000 万*1/1 亿=0.5 -假如本轮参与比特股的总量为 10 亿(Xbts),比特股的加权系数为 1,比特股的 -总量按照 25 亿(Sbts)计算。 -比特股的比例: -Pbts=Xbts*Kbts/Sbts=10 亿*1/25 亿=0.4 -阿希币获得的空投总量: -Gxas=DPxas/Pxas+Pbtc+Peth+ Pbts=10 亿*0.8/(0.8+0.25+0.5+0.4)=4.10 亿 -比特币获得的空投总量: -Gbtc=DPbtc/Pxas+Pbtc+Peth+ Pbts =10 亿*0.25/(0.8+0.25+0.5+0.4)=1.28 亿 -以太币获得的空投总量: -Geth=DPeth/Pxas+Pbtc+Peth+ Pbts =10 亿*0.5/(0.8+0.25+0.5+0.4)=2.56 亿 -比特股获得的空投总量: -Gbts=DPxas/Pxas+Pbtc+Peth+ Pbts=10 亿*0.4/(0.8+0.25+0.5+0.4)=2.05 亿 -假如用户 j 持有百分之一(40 万)阿希币(Txasj),可以获得 CCTime 数量: -Uxasj=√40 万 ∗ 4.1 亿/∑√Txasj亿 -假如用户 j 持有百分之一(5 万)比特币(Tbtcj),可以获得 CCTime 数量: -Ubtcj=√5 万 ∗ 1.28 亿/∑√Tbtcj亿 -假如用户 j 持有百分之一(50 万)以太币(Tethj),可以获得 CCTime 数量: -Ubtcj=√50 万 ∗ 2.56 亿/∑√Tethj亿 -假如用户 j 持有百分之一(1000 万)比特股(Tbtsj),可以获得 CCTime 数量: -Ubtcj=√1000 万 ∗ 2.05 亿/∑√Tbtsj亿 \ No newline at end of file diff --git a/docs/whitepaper/cctime_en.md b/docs/whitepaper/cctime_en.md deleted file mode 100644 index 7dac23a..0000000 --- a/docs/whitepaper/cctime_en.md +++ /dev/null @@ -1,312 +0,0 @@ -title: CCTime Whitepaper ---- -# 0 Introduction - -CCTime (Cryptocurrency Time) is a distributed social news sharing and communication platform based on -Asch's side-chain technology. CCTime is reconstructed based on the Hacker News. The block chain technology -is used to change the existing pattern of centralized content-sharing market and to solve the difficulties -of identification, spreading and making profit with high-quality content. Making high-quality content will -always get paid by a new content value assessment system. Publishers and sharers of high-quality news will -be rewarded with tokens according to this "bonus mode", and this will benefit to build a valuable public news -gathering and sharing platform, which will keep with the demands of readers. - -# 1 Why To Make CCtime - -## 1.1 Conceptual Origin - -CCTime (Cryptocurrency Time) is a demonstration example of Asch’s applications. The conceptual origin comes -from the Hacker News. CCTime only have some simple functions including account registration and login, press -release, browsing, making comments, voting and so on. The core conception of this design is not making original -content, copyright protection or social interactions, just the content sharing and making comments, and building -a lightweight news gathering platform based on block chain technology. - -With the development of this project, we believe that it will have great potential, the main reasons including:: - -1. CCTime is the first project mainly aiming at news sharing and making comments based on the block chain technology; - -2. There are large numbers of high-level participants in the crypto market, but there is no high-quality community -such as Hacker News to gather these high-quality users together. CCTime will be the answer, and crypto market will -also need this product; - -3. when compared with the traditional news platform, on the new platform, the difficulties of high quality content -identification can be solved effectively by adding tokens incentive function. Based on the block chain technology, -the CCTime is designed to return the value to the value creators and deliverers, and all the participants can share -this value, the company can not control most of the value anymore; - -4. The YOYOW, DECENT, GitBook pay more attention on making original content and copyright protection, while CCTime -is only a content sharing and comments making platform, which is a kind of news releasing platform. Its competitive -product can be the Jinritoutiao and flipboard; - -5.when compared with the Jinritoutiao, CCTime’s ranking algorithm can avoid the bias-deepen problem brought by the -machine learning algorithm since the machine will only recommend your favorite content; - -6.The functions of the CCTime are simple and easy to use. Users can get started quickly; - -7. Today, fast reading is in expansion, there is more demand for news application, the market is very promising. - - -## 1.2 Business model - -Centralized content distribution platforms have all the power concentrated in the central institutions, this will lead -to over centralization of institutional power. While the completely decentralized content distribution platforms may be -full of vulgar, pornography, reactionary speeches since there is no regulation. - -The conception of CCTime (Cryptocurrency Time) is to spread the value of information. Therefore, in order to reduce, -avoid or even eliminate the negative impact of the completely decentralization, CCTime system uses a regulatory model -combined with variety of ways. - -In the early days, the trustees, as regulators, supervise CCTime platform by joint reporting. And the regulators' -rights will be supervised by users in order to avoid abuse of power. - -Later, each publisher uses the "collateral message" mechanism to publish information. The system will rank the content -according to the mortgage issue via the mortgage XCT. Readers can comment contents. When a certain level is reached, -the publisher can redeem the token, or leave it to the system as a "bargaining chip" for the next information sharing. -Through the data analysis of CCTime system, the mortgage rate will decrease accordingly. - -# 2 Design Concept - -## 2.1 Simplicity - -CCTime Only includes the functions of account registration and login, press release, browse, comment, vote. It doesn't -focus on advertising social, copyright or original content. And everyone can use it quickly and easily. - -## 2.2 Effective Supervision - -CCTime Only includes the functions of account registration and login, press release, browse, comment, vote. It doesn't -focus on advertising social, copyright or original content. And everyone can use it quickly and easily. - -## 2.3 Free distribution - -Instead of ICO, the tokens are free distribution, allowing more people to hold tokens for free. - -## 2.4 Sharing Value - -Distributed value transmission breaks the limitation of traditional information Internet. Everyone enjoys CCTime’s -value-added profit distribution by tokens, effectively promoting content publishers' enthusiasm and improving the -production and dissemination of higher quality content. - - - -# 3 Technical Detail - -## 3.1 Asset production - -CCTime is a decentralized application based on Asch application SDK. The CCTime application will not issue tokens -independently, transferring from main chain. - -We will register a publisher called CCTime in the Asch main chain, and then use the publisher to register an asset -called XCT, which is known as cctime.xct. - -Once the asset is issued, it will be transferred to the CCTime application in a lump sum and locked in a joint -signature account of the application. - -We will release 95 percent of tokens by airdropping within one year to users who are interested in the application. - -Why do not produce assets within CCTime? - -It is good to issue assets in the main chain. In the future, the assets transferred to Dapp can also be transferred to -the main chain through the cross-link port and then transferred to other applications,achieving the goal of multi-chain -and multi-purpose. - -## 3.2 System of account - -The main chain of Asch is in common use with all the accounts of Dapp(except for the old version of the digital address). -Account authentication uses asymmetric encryption techniques, therefore, there is no need for a centralized registration -process. The user only needs to keep the master password corresponding to an account, then you can make various write -operation of block chains . Such as transfer, release news, reward, praise, comment and so on. - -The master password is to use the bip39 protocol generated by several (multiples of 12) word mnemonic symbol, as well as -the public key pair and the private key pair take the master password as seed, calculated by ed25519 elliptic curve -algorithm. - -Account ID or account address then is encoded by the public key, followed by two sha256 hashes and one ripemd160 hash, -repass Base58check. - -## 3.3 Cryptography algorithm - -Block ID and transaction ID use the sha256 hash algorithm. - -The signature of the bookkeeper and the transaction signature of the block are the sodium implementation version of the ed25519 algorithm. - -## 3.4 Contract and abstract transaction model - -The Asch application uses an abstract transaction model, this model can represent any function call. In Bitcoin, -the payload of the block is transaction or transfer record, In Asch applications, the payload of the block is -the function or contract call, also called affair(transaction). - -A transaction can modify multiple states, such as balances, nicknames, news, comments, etc., -transactions are atomic, either perform all or cancel all, there will be no half done. - -CCTime include the following specific matters -1. postArticle (Release news) -2. postComment (Release comment) -3. voteArticle (Vote for the article) -4. likeComment (Reward for the comment) -5. report (Reporting articles or comments) - -## 3.5 News ranking algorithm -CCTime uses the following comprehensive scoring algorithm: -![score](./assets/score.png) -Thereinto, - -V stands for the number of votes obtained by an article, votes are measured in tokens of XCT - -T stands for the time from which an article is published (in hours), Plus 2 is  in consideration -of that it takes time to create an article from authoring it to sharing it with the CCTime system, -it also avoids the problem that the denominator is too small due to too short release time. - -G is a gravity factor ,it determines the rate of decline in the article ranking, the default value for CCTime is 1.8 - -![chart](./assets/chart.png) - -As you can see from the picture above, there are three simultaneous posts, respectively scoring 199, 59 and 29, -which is respectively in yellow, in purple an in blue. At any time point, the yellow curve is at the top, -the blue curve at the bottom. - -Provided that other conditions are the same, the more newly published posts, the higher the ranking. In other words, -the ranking of a post will fall as time goes on. - -What you can see from the picture above is that all posts are basically less than 1 score after 24 hours. That means -they will fall to the bottom of the list, ensuring that the top ones will be new. - -![chart2](./assets/chart2.png) -As can be seen from the figure above, the other parameters of the three curves are the same. G values are 1.5, 1.8 and -2.0 respectively. The higher the G value, the steeper the curve, the faster the ranking drops, Which means that the -ranking is updated faster. -(This section refers to the Yifeng Ruan's blog, and slightly modified) - -## 3.6 Reward Mechanism -The execution of each transaction requires the consumption of basic fees, which are paid by the sponsor and distributed -equally to all accounts. - -In addition to the basic fee, PostArticle and postComment, the sponsor also needs to choose to spend extra tokens to -represent the amount of votes and quotas, which are mostly rewarded to the publisher of the articles or the commenter -publishers, but a small number (10%) will enter into the expense pool to assign to the accountant. - -## 3.7 Review Mechanism -CCTime is a decentralized system, without user authentication. The user generally logins anonymously. we need a review -mechanism to prevent anti-government, anti-social or other violations of the law of the emergence of speech. - -The review of CCTime1.0 is temporarily responsible by all the delegators. Each delegator can report any articles or -comments. If the number of times is reported more than 3 times, the article or comment will be filtered out, but not be -deleted from the underlying database, just make a mark. - -The review mechanism only affects the data returned by the query interface. A non-standard node compatible with the -CCTime protocol can still show all non-filtered data. - - -# 4 Distribution Mechanism -XCT (current coin) issues limit of 10 billion. The main team reserves 5% tokens, and the remaining 95% will be airdrop -to blockchain community, without finance and restore the ICO (Initial Crypto-Token Offering) essence. - -## 4.1 Distribution Principle - -The principle of distribution is to cover as many user groups as possible, but mainly in the coin circle, the outside -coin circle is for the second. - -## 4.2 Formula(MCDF) - -![math](./assets/math.png) - -## 4.3 Staging Airdrop Rules - -### 4.3.1 First Round of Airdrop Rules - -1. Only for the four communities in coin circle (Asch coin, Bitcoin, Ethereum, BitShares); - -2. Use the multi-community allocation rule in section 5.2; - -3.Begin to airdrop officially on August 20. On September 20, snapshot on the four public chains, and calculate the user’s -share according to the formula and distribute the tokens immediately ; - -4. Distribute a total of 1 billion; - -5. Refer to Appendix A for examples. - -### 4.3.2 After the second period - -Starting from the second period, The one who is holding XCT (current coin) can participate in the airdrop, in addition -to the specified coins. Each XCT (current coin) can receive 0.1 XCT (current coin). Program of other coins and airdrop -ratio is to be determined. - -# 5 Competition Advantages - -CCTime (Cryptocurrency Time) is the first Dapp application (decentralized content distribution platform) based on Asch -system side-chain, which has a greater advantage over other platforms such as Steem, Synereo, Decent, PressOne, -specifically: - -1. Own the support of Asch's technology and community; -2. Product model innovation, market segments without competitors; - - -# 6 Risk Tips - -Although distribution model of CCTime (Cryptocurrency Time) uses the airdrop, but with each round of airdrop and the -increasing number of visitors, XCT (time currency) will inevitably bring the risk of speculation (operation), -including but not limited: - -1. Secondary trading market has formed. Offline trading becomes active and highly risky; - -2.XCT ( current coin) once distributed, the authority no longer holds. The holder is the owner. The key should be -properly preserved. Once lost, the authority will not shoulder responsibility; - -3. CCTime (Cryptocurrency Time) is a application of distributed content sharing and communication, which based on the -Asch system. As a platform application, participants should abide by the relevant laws and regulations, prohibit all -bad, reactionary and other remarks, together to create a good atmosphere. - - -# 7 More Attention -Asch team is adhering to the concept of blockchain sharing and contribution. After a long period of research and -development, it is about  to share the first application of Asch ecological to the domestic blockchain community. -Welcome to use it , and also welcome the majority of the blockchain developers to join the Asch community. Together -promote the application of China's blockchain to land in. - -CCTime (Cryptocurrency Time) will meet you soon. More information, please pay attention to: - -CCTime official website: www.cctime.org - -ASCH official website: www.asch.so - -Official weibo: Beijing Asch Chain Technology Co., Ltd. - -ASCH Official Wechat Public Subscribe - -![wechat](./assets/wechat.png) - -Official QQ group: - -CCTime official group1:644658047 - -CCTime official group2:65622549 - -#8 Appendix A: XCT (Current Coin) First Round Airdrop Examples - -For example, if total number of Asch coin to participate in airdrop is 40 million(Xxas) this round and the weighting factor of Asch is 2, the Asch coin is calculated as 100 million(Sxas) totally. -The proportion of Asch coin: -Pxas = Xxas * Kxas / Sxas = 40 million * 2/100 million = 0.8 -If total number of Bitcoin to participate in airdrop is 5 million(Xbtc) this round and the weighting factor of Bitcoin is 1, the Bitcoin is calculated as 20 million(Sbtc) totally. -The proportion of Bitcoin: -Pbtc = Xbtc * Kbtc / Sbtc = 5 million * 1/20 million = 0.25 -If total number of Ethereum to participate in airdrop is 50 million(Xeth) this round and the weighting factor of Ethereum is 1, the Ethereum is calculated as 100 million(Seth) totally. -The proportion of Ethereum: -Peth = Xeth * Keth / Seth = 50 million * 1/100 million = 0.5 -If total number of Bitshare to participate in airdrop is 1 billion(Xbts) this round and the weighting factor of Bitshare is 1, the Bitshare is calculated as 2.5 billion(Sbts) totally. -The proportion of Bitshare: -Pbts = Xbts * Kbts / Sbts = 1 billion * 1 / 2.5 billion = 0.4 -A total airdrop amount of Asch coin earned: -Gxas = DPxas / Pxas + Pbtc + Peth + Pbts = 1 billion * 0.8 / (0.8 + 0.25 + 0.5 + 0.4) = $ 410 million -A total airdrop amount of Bitcoin earned: -Gbtc = DPbtc / Pxas + Pbtc + Peth + Pbts = 1 billion * 0.25 / (0.8 + 0.25 + 0.5 + 0.4) = 128 million -A total airdrop amount of Ethereum earned: -Geth = DPeth / Pxas + Pbtc + Peth + Pbts = 1 billion * 0.5 / (0.8 + 0.25 + 0.5 + 0.4) = 256 million -A total airdrop amount of Bitshare earned: -Gbts = DPxas / Pxas + Pbtc + Peth + Pbts = 1 billion * 0.4 / (0.8 + 0.25 + 0.5 + 0.4) = 205 million - -If the user j holds one percent (400,000)of Asch coin(Txasj), the number of CCTime he can get is: -Uxasj= 100million -If the user j holds one percent (50,000)of Bitcoin(Tbtcj), the number of CCTime he can get is: -Ubtcj= 100million -If the user j holds one percent (500,000)of Ethereum(Tethj), the number of CCTime he can get is: -Uethj= 100million -If the user j holds one percent (10million)of Bitshare(Tbtsj), the number of CCTime he can get is: -Ubtsj= 100million \ No newline at end of file diff --git a/docs/whitepaper/index.md b/docs/whitepaper/index.md deleted file mode 100644 index a9e70e9..0000000 --- a/docs/whitepaper/index.md +++ /dev/null @@ -1,265 +0,0 @@ -title: Asch白皮书 ---- -# 0 引言 - -比特币的出现使得去中心化的货币系统成为可能,经过几年的发展,人们发现比特币背后的区块链技术潜力巨大,可以被广泛应用在各行各业。为了更好地利用区块链技术,出现了以以太坊为代表的一批应用平台,它们封装了底层协议、建设了基础设施,为开发者提供了更加友好、也更加灵活的接口,使得开发者的关注点能够集中在业务逻辑上,很大程度上提高了开发效率。本文提出的 asch 系统也是一种去中心化应用的开发平台,接下来我们会详细阐述这一系统的特色、原理及应用场景。 - -# 1 概述 - -## 1.1 去中心化应用 - -去中心化应用是一种具有以下特点的应用。 - -1. 必须完全开源,自主运行,不能被中心化的组织、机构或个人操控,可以被改进以响应市场需求,但必须经过用户们的共识。 - -2. 数据必须被安全、公开、冗余的存储在一个分布式网络中,以避免被篡改和单点故障。 - -3. 应用访问者需要消耗令牌,而应用贡献者可以获得令牌的奖励。 - -4. 应用必须使用一种价值证明的密码学算法来生成令牌。 - - 去中心化应用可以通过授权系统的权益人来投资应用的开发,从而有潜力达到自给自 - -足。去中心化应用还有公开透明、安全可靠、去信任等优点。因此,可以想像去中心化应用在支付、数据存储、云计算、电子商务等领域将有非常可观的前景,它所产生的价值甚至有可能会超过 visa、dropbox、亚马逊等跨国公司的市值。 - -## 1.2 侧链是什么 - -区块链是一串使用密码学方法相关联产生的数据块,每一个数据块中包含了若干网络交易的信息,用于验证其信息的有效性(防伪)和生成下一个区块,对于普通用户来说它就像一个公有账本,记载所有的交易记录,对于开发者来说可以理解为一个分布式的数据库。区块链这个数据库的特点是去中心化、开放、自治、不可篡改,区块链与去中心化应用息息相关,非常适合为去中心化应用提供存储功能。 - -侧链是一种特殊的区块链。它使用一种叫做“SPV 楔入”的技术实现与其他区块链之间的资产转移,这使得用户能用已有的资产来使用新的加密货币系统。人们不必再担心比特币难于采纳创新和适应新需求,只要创造一个侧链,然后对接到比特币的区块链中即可,通过继承和复用比特币强大的区块链,还避免了新货币的流动性短缺和市场波动等问题。并且由于侧链是一个独立的、隔离的系统,侧链中出现的严重问题只会影响侧链本身,这极大地降低了创新的风险和成本。 - -## 1.3 Asch 是什么 - -Asch 是一个去中心化的应用平台。它提供了一系列的 sdk 和 api 来帮助开发者构建基于 Javascript 和侧链技术的去中心化应用。Asch 通过提供定制侧链、智能合约、应用托管等一体化的行业解决方案,致力于打造一个易于使用、功能完备、即插即用的系统。利用 Asch 生态系统,开发者可以快速迭代他们的 Javascript 应用,并发布到系统内置的应用商店中,这些应用可以被平台中的分布式节点下载并执行,并服务于普通用户,整个过程都由诚实安全的 Asch 侧链共识网络提供安全保证。 - -Asch 系统本身也是一个完全开放的、去中心化的应用,内置有代币,单位为 XAS,中文名叫阿希币。阿希币可以通过双向楔入的方式与侧链或 dapp 进行交互,作为所有 - -dapp 之间资产转换的桥梁和媒介,这些代币将在系统发布之前以 ico 的方式预售给投资人。系统一旦发布,Asch 最初的核心团队将不再掌控系统的走向,只有系统的权益人和代币的拥有者决定系统将来的发展。 - -## 1.4 Asch 面向哪些用户 - -Asch 平台除提供一些基本服务外,还将提供技术和工具上的支持,主要面向以下群体: - -### 1.4.1 开发者 - -开发者可以根据 Asch 平台的应用开发规则和商业行为准则,并按照相关的规范进行开发和提交 dapp。Dapp 的商业模式或免费,或定价销售,或按增值服务付费。采用何种商业模式完全由开发者决定。 - -### 1.4.2 企业 - -Asch 平台提供的工具可以非常容易地创建一个完整的区块链,更重要的是可以楔入到Asch 平台的主链或者比特币的区块链中,实现与成熟电子货币的对接,这对中小型企业,特别是初创企业是非常有吸引力的。 - -中小企业可以通过区块链技术提供原本封闭在企业内部、互联网内部的信息和数据,甚至与监管机构的相关系统数据相互链接,增强透明度,以此树立良好的形象,赢得投资者、金融机构的信任度,顺利拿到融资或项目合同等。 - -中小企业主动公开和开放资料,已成无法阻挡的趋势。因为现在有很多的公开渠道来获取数据,中小企业已经越来越难隐瞒它们不想让外界知道的信息。我们可以大胆预测,在未来区块链将是帮助中小企业发展的重要武器。 - -### 1.4.3 普通用户 - -普通用户可以通过 Asch 内置的应用商店进行下载、安装和使用去中心化应用,这跟手机平台的应用商店是类似的模式。Asch 系统支持多种类型的去中心化应用,普通用户在消费这些应用的同时,还可以通过贡献内容来获得收益。开发者与普通用户将共同组成一个繁荣的生态系统。 - -# 2 设计理念 - -## 2.1 完备脚本 vs 侧链 - -比特币为人称道的一个设计上的亮点就是它的脚本引擎。基于这套脚本引擎,不但可以实现普通的转账功能,还可以实现多方签名、抵押担保、博彩等智能合约应用。但是出于安全和实现难度的考虑,比特币的脚本系统设计的较为简陋,做了非常多的限制,比如它不支持循环、脚本长度受限、只支持几种标准的的交易类型。 - -以太坊的最大特色就是极大地扩展了这个脚本引擎的功能,加入了读取区块链、计费、跳转等新指令,还解除了栈内存、函数调用深度以及脚本长度限制等。以太坊自称他们的脚本语言达到了图灵完备,利用这样的脚本,开发者可以实现几乎任何可以用数学方式表述的功能。 - -自以太坊以来,扩展脚本成为了一种实现去中心化开发平台的流行方式,但这种方式有一个很大的缺点就是,应用代码本身及应用产生的数据都存在同一个区块链中,造成了区块链的快速膨胀。以太坊试图通过优化和压缩区块和交易本身来延缓这种膨胀,也只是一种治标不治本的方法。此外,基于脚本实现的应用之间是共享同一个账本的,像区块产生时间等参数是无法被定制的,这无疑限制了应用的个性化。 - -侧链机制是通过另一个维度实现扩展性的,每个侧链运行在不同的分布式节点网络中,有独立的受众、投资人和开发团队。这种天然的分片解决方案,不但解决了区块链的膨胀问题,而且每个应用都拥有一套个性化的账本,其共识机制、区块参数、交易类型都是可以被定制的,所以我们认为侧链与完备交易脚本相比,是一种成本更低、更加灵活、也更加易用的解决方案。 - -## 2.2 账户 vs UTXO - -在比特币及其衍生系统中,是没有一个所谓的账户来存储用户的余额的,用户的余额是通过整个系统的交易状态转换来实现的。这里要引入一个术语,UTXO(unspenttransaction outputs),即未花费的交易输出。每个 UTXO 都有一个面值和所有者,一笔交易包括一个或多个输入和一个或多个输出。每个输入包含一个对现有 UTXO 的引用和由与所有者地址相对应的私钥创建的密码学签名,如果一个用户拥有这个私钥,那么他就可以消费这个 UTXO 对应的币值,也就是说一个用户的余额就是他所有拥有的所有私钥对应的 UTXO 的币值总和。UTXO 主要优点是高度的私密性,用户可以为每一笔交易生成一个新的地址,从而使得用户无法被追踪,这对于货币来说是好事,但对于各式各样的dapp 来说,就未必了。账户相对于 UTXO 来说,有以下几个优点: - -1. 节省空间。举例来说,如果某个用户有 5 个 UTXO,需要的存储空间是(20 + 32 +8)* 5 = 300 字节(其中 20 字节为地址,32 字节为交易号,8 字节为交易额),而账户仅需要 20+8+2=30 字节(20 字节位地址,8 字节位余额,2 字节为随机数)。 -2. 利于监督。账户的存在使得电子货币很容易被区分,因为我们只要知道这些币来自哪些账户即可。 -3. 简单、易于编码和理解。 -4. 常量级引用。轻客户端能以常数时间访问一个用户的账户任意数据,而在 UTXO 系统中,每当有交易发生时,数据引用将发生变化。 - -Asch 平台本身并不是一个纯粹的货币系统,要容纳各种各样的应用,综合比较起来,账户对于我们来说是一种更好的选择。 - -## 2.3 关系数据库 vs 非关系数据库 - -目前大多数的区块链系统都选择使用模型较简单的非关系数据库来存储数据,比如berkeley db,leveldb 等,这些数据库一般都提供一些简单的数据结构,比如 btree、hashtable、queue 等,它们一般不支持 SQL 对数据进行操作,虽然这些数据库对于一般的电子货币系统来说足够了,但对于应用平台来说是远远不够的,特别是对于金融、银行、电子商务等领域,目前主流的存储系统都是采用了关系数据库,因为关系数据有以下几个优点: - -1. 事务处理; -2. 数据更新开销非常小; -3. 可以进行 join 等复杂查询。 - -我们选择的 sqlite 是一种性能极佳的轻量级嵌入式关系数据库,容量最高支持 2T,数据文件可在不同字节序机器之间自由共享,特别是对 SQL 的支持,将为 dapp 开发者提供极大的便利。 - -# 3 系统特点 - -## 3.1 易用 - -### 3.1.1 开发语言 - -开发者可以使用 javascript 语言以及海量的 npm 库来构建他们的应用。相对于比特币的 c++语言及栈式脚本、以太坊的新语言 solidity,javascript 流行度更高、受众更广、上手更容易的一门语言。此外,关系数据库的加入也是 Asch 系统的一大特色,使得去中心化的应用开发模式与传统 web 应用的开发模式已经非常相近了。Asch 平台的应用开发门槛可以说是同类产品中最低的。 - -### 3.1.2 工具 - -Asch 系统提供了一个命令行工具,只需要根据提示输入一些配置项,就可以快速的建立一个侧链,并可在侧链上开发任意类型的应用。其次,系统还提供了一系列的 api 帮助用户构建复杂的智能合约应用,这些 api 涵盖共识、强随机数、数据库、密码学等方面。 - -### 3.1.3 部署 - -开发者只需要把自己的 dapp 提交到 github,然后在 web 钱包或轻钱包中注册,就完成了部署的工作,之后 dapp 将被显示在应用商店中被用户下载和使用。 - -## 3.2 灵活 - -开发者可以随意定制其侧链的各项参数,比如区块产生速度、交易类型、交易费等等,甚至可以实现一个新的共识机制,比如开发者可以使用权益证明或工作量证明的共识机制来取代默认的委托人权益证明机制。 - -## 3.3 安全 - -Asch 系统的一大亮点是使用了一个增强 DPOS 的共识算法,在 DPOS 的基础上加入了一个高效的实用拜占庭容错算法,极大地降低了网络分叉的可能性,只要不超过 1/3 节点联合做恶,系统就不会分叉,也就没有双重支付的风险。其次,系统在一些小的细节方面也是尽量从安全角度进行了考量。比如采用 BIP39 标准算法的口令助记符、二级交易密码、多重签名账户等。 - -# 4 技术细节 - -## 4.1 共识机制 - -Asch 系统采用的共识机制是基于 DPOS 的,也是使用了委托人选举的制度,但是在算法的后半部分采用了一个优化后的 PBFT 算法变种,这个算法可以在 t < n / 3 时,以O(n^2)消息复杂度,O(1)的时间复杂度使忠诚的节点达成一致,不会分叉,其中 t 表示拜占庭节点(即可能发生任意行为的节点,比如网络延迟、停机、恶意攻击等等)的个数,n 表示所有节点的个数。 - -### 4.1.1 委托人选举 - -Asch 系统的委托人选举制度与 DPOS 是类似的,核心系统是由 101 个委托人节点组成,委托人是被社区选举的可信账户,得票最高的 101 个委托人负责生产区块。得票排名未进入前 101 名的账户被称为候选人,当他们将来获得足够多的选票并进入前 101 名后,将成为正式的委托人。 - -每个 Asch 用户都有权利投票给最多 101 位委托人,选票的权重是由用户持有的 XAS数量决定。 - -每一个选举周期产生 101 个区块,每一次投票和委托人排名的变化将体现在下一个周 - -期。每个区块产生的间隔时间是 10 秒,新创建的区块会被广播到网络中并添加到区块链中。每当新的区块被添加到区块链中,该区块之前的所有交易的确认次数加一,得到 6 个确认后,可以认为交易是安全的,如果数额较小的交易,可以允许更小的确认次数,相反,数额较大的交易可以通过增加确认数来保证安全性。 - -如果有少数委托人发生故障,比如被攻击或者宕机,就会错失区块,这会被记录在案,这将影响该节点的在线率,进而影响社区的投票。因此委托人的竞选是需要严肃对待的,委托人应当由有一定网站运营经验的人来做,委托人要保障自己节点的稳定性,并以此促进整个系统的安全和稳定。 - -### 4.1.2 拜占庭容错 - -Asch 系统与 DPOS 的不同主要体现在算法的后半部分。 - -DPOS 采用的方法是,首先对当前 round 的委托人列表进行随机的排序(保证每一轮的委托人顺序不同,也无法预测下一轮委托人顺序),然后通过 round-robin 的方式依次让每个委托人创建区块。这个算法的主要缺点是,如果某个委托人节点叛变了,他可能会广播多个不一致的区块,这些区块间可能包括双重支付交易,导致整个网络被分叉了。当然,如果只有一个委托人叛变的话,这个分叉很快就可以通过下一次最长链同步的方法来消除,但是随着叛变节点的增加,消除分叉的时间将越来越长,少量节点的联合叛变将严重影响系统的安全性,即使一个交易达到 6 次确认,也很可能是不安全的。 - -为了解决这个问题,我们引入了 PBFT(Pratical Byzantine Fault Tolerance)算法。PBFT 算法也是使用 round-robin 的方式选择委托人,但是选出委托人后并不立即创建区块,而是首先发起一个提议(propose),这个提议的目的是确定下一次区块的 hash。当超过 2/3 的节点都赞成该提议时,才接受由提议人创建的的下一个区块,下一个区块的 - -hash 必须与当前 round 达成共识的区块 hash 一致。从本质上来说,PBFT 算法的加入解决了委托人权利滥用的问题,使得委托人的记账能力更为可控。 - -## 4.2 侧链与 dapp - -Asch 系统提供了一个命令行工具,可以用来轻松创建一个基础的侧链系统,侧链的开发者也可以深度定制自己的侧链,侧链拥有自己的数据库、共识机制、交易类型以及账户体系。侧链可以托管在独立的委托人节点集群中,这就自然形成了一种分片的机制,延缓了主区块链的膨胀。 - -每一个 dapp 对应一个侧链,侧链的核心逻辑使用 nodejs 开发,界面部分可以使用任意前端技术,比如 qt,html,javascript 等等,前端与后端之间一般通过 json rpc 协议通讯。Dapp 的作者或者所有者可以跟踪自己的 dapp 被使用的情况,加密货币是基于社区的共识,但 dapp 更像是一家私人拥有的公司。Dapp 内的交易是由主节点处理的,主节点是由 dapp 所有者运行的,dapp 所有者必须拥有一个 Asch 帐号,这个帐号类似多重签名的帐号,它的主要任务是在 dapp 主节点创建共识并签名新的区块,如多重签名钱包。一旦一个新的 dapp 区块被创建,并且在主节点内被签名,这个区块需要被计算出SHA256 哈希,然后 dapp 所有者提交这个哈希值给 Asch 区块链,然后存储该哈希值为dapp 区块,一旦 Asch 区块链收到一条包含 dapp 哈希值的交易,由受托人对比这条哈希值与上一个啥希值,并将它保存到 Asch 区块链,在未来,当主节点同步网络,用户将通过 Asch 区块链来验证所有 dapp 区块,想从 Asch 区块链中移走上一个 dapp 区块将是不可能的事情。相同的功能,以比特币区块链来替代 Asch 区块链将同样适用,API 在比特币区块链上工作的方式是一样的,通过比特币区块链来保证 dapp 的安全性。开发者可以使用 XAS 和 BTC 来做为其 dapp 的货币,使用 dapp 时可能需要存入或者取出资金,当 Asch 或者 BTC 被发送到 dapp 的地址时,资金会在其 dapp 的帐户内出现,用户便可在 dapp 内使用该资金,BTC 和 Asch 的存入方式是一样的,都是发送到 dapp 的特定地址,然后资金就会出现在 dapp 帐户内。Dapp 的帐户都是由 dapp 的作者创建的,所有存入的 Asch 或者 BTC 都将被存储在这个地址内,考虑到安全性,只推荐使用了多重签名可信任的签名者的 dapp 帐户。从 dapp 取款是由主节点负责处理的,当有人发送一条取款请求,dapp 主节点就会处理它并且把资金从 dapp 的地址上移出到 Asch 区块链上,或者比特币区块链上。开发者可以在他们自己的 dapp 里面发行令牌,而且使用此令牌做为该 dapp 的流通货币,这些令牌在该 dapp 内可像 XAS 或者 BTC 一样使用,但是它不能直接从一个 dapp 转移到另一个 dapp,他们必须通过 Asch 主链来转移。 - -## 4.3 沙箱和 VM - -沙箱是一种按照安全策略限制程序行为的执行环境。早期主要用于测试可疑软件等,比如黑客们为了试用某种病毒或者不安全产品,往往可以将它们在沙箱环境中运行。经典的沙箱系统的实现途径一般是通过拦截系统调用,监视程序行为,然后依据用户定义的策略来控制和限制程序对计算机资源的使用,比如读写磁盘等。 - -Asch 系统使用了 nodejs 的 vm 模块实现沙箱机制。VM 模块是对 javascript 的 v8引擎的封装,可以用来执行纯粹的 javascript 代码,但无法使用系统层的 api,比如文件系统、网络传输相关的模块,并且由于没有 require 函数,第三方库也没法轻易导入进来,甚至无法进行模块化开发,这就需要 dapp 的开发者使用 browserify 的技术将常用的第三方库打包成一个 js 文件,Asch 的主链系统才能加载并运行。对于一些必须的系统级api,则通过进程间通讯的方法为侧链提供,这样兼顾了安全性与功能的完备性。 - -## 4.4 交易 - -Asch 系统内建了一个交易抽象层,核心系统的几乎所有功能都是建立在交易上的,比如转账、投票、应用商店、充值、提现等。侧链本身也可以实现自己的不同类型的交易。交易之间的区别主要是交易类型和 asset。基础交易的数据结构如下,扩展部分会根据类型的不同分别存在不同的 asset 表中。 - -```sql -Transaction { -required VARCHAR(20) id; -required VARCHAR(20) blockId; -required TINYINT type; -required INT timstamp; -required VARCHAR(21) senderId; -optional VARCHAR(21) recpientId; -required BIGINT amount; -required BIGINT fee; -required BINARY(64) signature; -optional BINARY(64) signSignature; -optional TEXT signatures; -required BINARY(32) senderPublicKey; -} -``` - -以投票交易举例来说, votes 实体通过交易 id 来关联到一个基础交易中。 - -```sql -Asset_Votes { -required VARCHAR(20) transactionId; -optional TEXT votes; -} -``` - -## 4.5 账户系统 - -Asch 的每个账户由一个口令、一对公私钥、一个地址组成。用户还可以额外设置一个二级密码。注意这里与比特币有所不同的是,每个账户仅对应一个地址,而比特币中每个钱包对用多个地址和私钥。 - -口令(passphrase)是符合 BIP39 标准的用于产生确定性钱包的助记符。这种助记符与二进制或十六进制字符相比对人类记忆更友好。口令的生成方式是将一个 32bit 倍数长度的熵转换成若干个单词,Asch 系统选择的熵长度为 128bit,将转换成 12 个单词。口令作为一级密码,由用户保管,不对外公开,一旦丢失用户将失去对应账户的所有权。口令形式如下: - -``` -barely decline dust stamp protect color certain cup arena busy latin shell -``` - -**密钥对**包括公钥和私钥,是以口令的`sha256` 哈希做种子,再通过 `ed25519` 爱德华兹曲线签名算法生成的。形式如下: - -``` -公钥: -9989388b220a13465e49f52df5ba28ba08eb1e7a973320347f9687a107dc2f -9a - -私钥: -91e891f653e3ed0232d8c7de2e72b625d50d48593fc0fb570c0db25c5e4456 -9a9989388b220a13465e49f52df5ba28ba08eb1e7a973320347f9687a107dc -2f9a -``` - -账户地址是取公钥的 `sha256` 哈希的前 8 位,逆序后转换成 bignumber,其形式如下 - -``` -5034187504202890358 -``` - -## 4.6 客户端 - -Asch 系统将提供三种客户端程序。 - -完整版客户端是针对超级用户、委托人和开发者的最佳解决方案,它可用于windows,Mac OS 以及 linux,但它只允许 linux 运行受托人节点。 - -轻钱包的用户可以通过连接到完整版钱包以连接到网络,也可以直接调用 API,但前提是完整版钱包的所有者有开放该 API 权限,完整版钱包会通过点对点网络,从其它完整版钱包节点下载完整的区块链。 - -普通用户将主要使用轻钱包来管理自己的 Asch 帐户,它是一个精简版的 Asch 钱包,轻钱包支持 windows 和 Mac OS,它无需安装,它使用的是内嵌式的浏览器,它无法作为网络节点,因为它不下载区块数据,它只通过 http 连接到其它的节点,这样做能带来几点好处。首先它不下载区块数据,这意味着它会一直保持着较小的体积,不占容量;其次它不向网络广播密钥,所有数据在本地设计上签名,可以做所有类型的交易,如果你想运行一个受托人节点,你可以使用轻钱包注册一个受托人帐号,但你无法使用轻钱包来运行受托人节点来创建区块,为了运行受托人节点,你需要下载完整版钱包,并运行在 linux 上。Dapp 用户可以使用轻钱包来管理已安装的 dapp。Dapp 的 API 和节点的API 也可供开发人员调用,这使得开发人员可以使用 Node.js 快速且简单地创建javascript dapp。 - -移动版客户端允许用户通过移动终端来操作自己的 Asch 帐户,它将提供 ios 与安卓两种版本,并于苹果应用商店和安卓应用商店提供下载。它的后端将基于我们的桌面版的解决方案,与桌面版的区别将在于移动版钱包界面将使用响应式技术,自适应移动终端屏幕,并根据移动设计调整了一些交互方式。该 APP 使用了专为移动终端定制了易用的界面,类似于 bitcoin 和一些常用的银行类 app 的界面,而且它将支持在内部运行所有你喜爱的 dapp。 - -## 4.7 性能 - -一笔交易信息通过优化和压缩后大概占 100 字节,我们算算系统达到 1 万 tps 时候需要消耗的带宽。因为出块间隔为 10 秒,那么每次出块需要包含 10 万个交易,也就是说要包含 10M 字节的交易数据,这 10MB 的数据需要在 10 秒内广播到全网,按最理想情况下,第一跳广播到 10 个节点,第二跳广播至 100 个节点,每一跳要在 5 秒内传输完毕,服务器需要的带宽是 10MB * 10 / 5 = 20MB,考虑到中间的带宽损耗和非理想情况,我们认为至少要 40MB 的带宽才能够满足 1 万 tps 的吞吐量。这个带宽要求显然不低,但是相信 1 万 tps 给委托人带来的收益远大于网络维护的费用。2014 年双十一支付宝的吞吐量峰值达到了 8.59 万每秒。Asch 系统在交易吞吐量方面还是有优化空间的,这也是将来我们的重点要投入的方向。 - -# 5 应用场景 - -## 5.1 令牌系统 - -使用 Asch 工具创建的第一个 hello world 应用,就是一个最基本的令牌系统了。 - -开发者可能不需要编写代码,只要在 genesis.json 文件里修改一些创世参数,就可以发布一个令牌系统了。Asch 系统中的令牌与以太坊的子货币一样,可以表示黄金、股票、抵押物、或任意其他资产,这些令牌可以与转入侧链中的 XAS 通过去中心化的方式进行交易,从而实现流通,也可以在中心化的交易所与其他货币进行交易。 - -## 5.2 仲裁合约 - -假设一个买家想跟一个不认识的人进行交易,一般情况下如果交易顺利进行的话,双方都不希望有第三方介入,但是如果某个环节出了问题,比如买家对商品不满意时,他们就希望有一个中间人来做调解。这个中间人可能会要求买卖双方出示一些证据,然后做出判决,比如把钱退还一部分给买家。这个业务流程如下: - -1. 买卖双方共同选择一个中间人 -2. 买家使用三方的公钥创建一个 2-3 的多重签名账户,然后转账到这个账户,再以该账户为发起人,以卖家的账户为接收人,签署一个交易并发布出去。此时这个交易是不能立即被确认的,只有 3 个人中的 2 个人共同签名,才会生效。 -3. 卖家发货给买家。 -4. 如果买家收到货物后,检查没问题,使用自己的私钥对刚才的交易进行签名。然后卖家再次签名后,交易就顺利完成。 -5. 如果买家对货物不满意,可以向中间人发起申诉并出示证据,卖家也可以出示证据,最终由中间人与买卖其中的一方达成一致,共同签署,完成交易,结束仲裁。 - -## 5.3 去中心化交易所 - -根据是否支持法币,可以分为两种程度的去中心化。如果不支持法币,可以实现完全的去中心化,如果支持法币,则只能实现半去中心化,即法币通过网关出入,但交易信息公开。 - -完全的去中心化交易所又分为两种,一种是点对点的交易,通过 Asch 系统提供的“原子跨链交易 api”来实现。另一种是挂单交易,挂单交易要求卖方从其他区块链转入一定的资产到 Asch 侧链中,这个转入操作通过父链冻结资产的 SPV 证明达成。此外,由于关系数据库的支持,利用联表查询和索引功能,可以很容易的实现一个效率不错的撮合引擎。 - -## 5.4 存在性证明 - -存在性证明可以用于登记文件版权、专利等,其基本原理是将要存储的文件的哈希值存入到 Asch 的侧链中,以此来证明某个特定文件存在,还可以加上时间戳、当事人的数字签名等元数据,来证明他们是在何时持有这些文件的。这些信息无法伪造、无法篡改,不会暴露数据和隐私,在需要的时候随时可以验证且不依赖第三方机构。 - -## 5.5 物联网 - -物联网中存在海量的联网设备,很难有一个中央机构来管理所有的设备和各节点的身份。Asch 的侧链是一个很好的解决方案,首先,它解决了节点间信任问题,设备间彼此相连形成分布式网络,通过共识算法来保证设备间交易的合法,并且可追踪、可审查、可分析。其次,不同种类的设备可以接入不同的侧链,这是我们前面提到的天然分片机制,避免了总账本的爆炸式增长。我们试想下,在一个基于区块链的物联网中,一个自动售货机不但可以监控和报告它自身的存货,还可以通过分析历史交易数据智能地从分销商那里进行招标并自动完成付款。 - -# 6 总结 - -Asch 是一个去中心化的应用平台,其设计初衷是为了降低开发者的门槛,比如使用javascript 作为应用编程语言,支持关系数据库来存储交易数据,使得开发一个 dapp 与传统的 web 应用非常相似,相信这对开发者和中小型企业有很大的吸引力,只有开发者的生产力提高了,整个平台的生态才能够更迅速的繁荣起来。Asch 在设计上也是开放的,并没有局限于某个细分领域,比如金融、文件存储、版权证明等,其提供的 api 都是较底层和抽象的,它们可以被自由组合实现各种不同的应用。在共识机制方面,Asch 继承并增强了 DPOS 算法,大大降低了分叉几率和双重支付风险。另外,Asch 的侧链即应用模式不但延缓了区块链膨胀问题,还使得 dapp 更加的灵活和个性化。Asch 是一个具有前瞻性的、低成本的一站式应用解决方案,相信将成为新一代去中心化应用的孵化器。 \ No newline at end of file diff --git a/docs/whitepaper/index_en.md b/docs/whitepaper/index_en.md deleted file mode 100644 index f03127f..0000000 --- a/docs/whitepaper/index_en.md +++ /dev/null @@ -1,164 +0,0 @@ -title: Asch Whitepaper ---- -# Introduction -Since Bitcoin was introduced in 2009 and had been rapidly developing for these several years, people found that Bitcoin has more potential than just be a kind of electronic currency. Especially blockchain, the underlying technology of Bitcoin, has the unlimited capacity even more valuable than Bitcoin itself. The blockchain technology can be applied in the development of different kinds of application, which have the same characteristic that is decentralization. The emerging of these decentralized applications also promotes a new application architecture, which is based on an open-source platform. Based on this concept, we propose the Asch system, a development platform for decentralized applications. -# Overview -## Decentralized Application -Decentralized application has following features: -1. The application must be completely open-sourced. It must be run under the control of itself, which means it should not be tampered by any centralized organization, institution or individual. It can be revised to reflect the market requests, but has to be recognized by all users. -2. The application data should be stored in a distributed network that has to be secure, open, and redundant, in order to avoid data manipulation and single node failure. -3. Application users need tokens to access, and application contributors can get tokens as rewards. -4. The application must apply a value-proved cryptographic algorithm to generate tokens. -The decentralized application can make the stakeholder to invest in the development of it by granting them the privilege in it so that it becomes possible to be self-sufficient. These kinds of application also have the advantages such as publicity, security, and trustless. Therefore, it is not strange that decentralized applications will play a vital role in following fields: payment, data store, cloud computing, e-business, and etc., and it is even possible that the value created by those applications will exceed the market value of giant international company such as VISA, Dropbox, or Amazon. -## About Sidechain -A blockchain is a well-ordered collection of data blocks generated by using cryptographic algorithm. Each block of data contains an amount of network transaction information which is used to validate the authenticity, as well as generate the next block. To a normal user it looks like a public ledger on which every single transaction will be recorded, and to an -application developer it looks like a distributed database, which features decentralization, open, self-autonomy, and harden against tampering. The blockchain presents a very tight relationship with decentralized application which makes it very suitable for store these applications. -As a specific blockchain, the sidechain applies a “SPV (simplified payment verification) Pegged” technology to achieve the goal that the user’s asset can be transferred from one blockchain to another, which means users can use their current assets to utilize the new cryptocurrency system. There will be no need to worry about the disadvantage of Bitcoin that is hard to adapt the innovation and meet the new request. What need to be done is just create a sidechain and link it to the main blockchain of Bitcoin. By inheriting and reusing the powerful blockchain of Bitcoin, other issues such as liquidity shortage and market fluctuation, often occurred when a new currency is introduced, can be averted. Furthermore, since the sidechain is a isolate individual system, any severe failure will only impact the sidechain itself instead of the whole blockchain, thus significantly reduce the risk and cost of innovations. -## About Asch Platform -Asch is a decentralized application platform, providing a series of SDK and API to help developers creating decentralized applications based on JavaScript and sidechain technology. By providing a whole set of industry standard solutions including customized sidechain, -smart contracts, application hosting, and etc., Asch intends to offer an easy-to-use, fully functional and plug & play ecosystem, by which developers can rapidly iterate their JavaScript applications, and easily deploy them into application store built in the system. These application can be smoothly downloaded and executed by every node and user located in everywhere of this ecosystem. The whole process will be secured by the Asch sidechain consensus network. -On the other hand Asch itself is also a fully opened, decentralized application, which has its own cryptocurrency known as Asch coin. Asch coin is capable of interfacing with sidechain or any decentralized application (DAPP) through “two-way peg” mechanism so that it can be the bridge or media for the asset transition among all DAPPs, and to achieve that purpose, the Asch coin will be sold to the investors through ICO (initial coin offering) before the deployment of the system. Once an Asch system is published, it will not under the control of the core development team, but the stakeholders of the system and the owners of Asch coin. -## Who Should Use Asch Platform -Apart from some basic services, Asch platform also provides technology and toolkit support, whose main target audiences are as follow: -### Developers -Developers can create and deploy DAPP in Asch platform by following the criteria of application development and business activities. The business model of these DAPPs may be free or fixed price, or pay with value added service. It is all up to the developers themselves. -### Enterprises -The tools provided by Asch platform can be used to easily create a complete blockchain, and more importantly, this blockchain can be pegged into main chain of Asch platform or even the blockchain of Bitcoin, thereby connected with well-developed electronic currency. It is a very attractive feature that is suitable for small and medium enterprises (SMEs) especially start-up companies. -SMEs can utilize blockchain technology to provide the information and data that were enclosed inside companies or Internet in the past, and to connect with the system data owned by authority so that they can promote the business publicity and improve the companies’ image. Consequently more trustiness can be brought to the investors and financial institutions to make it easy to get the funds or contracts. -It is inevitable for SMEs to public their business information. SMEs found it is difficult to prevent social community to know their secrets. Therefore we can assume that blockchain will play a vital role in SMEs everyday business activities. -### End users -Individual users can download, install and use numbers of decentralized applications through Asch built-in app store, which is similar with application store in current smart phone. Asch system supports different kinds of decentralized application on which end users can make profit by contributing the program or content. It is possible for developers and users to create a vivid ecosystem together. -# Design Rationale -## Turing-Completeness Scripting vs Sidechain -The scripting engine is a highlight in design of Bitcoin on which not only can transfer the currency but can realize the smart contracts such as multi-signature, escrow and arbitration, and gambling. Bitcoin’s scripting system, however, applies a concise design setting a series of limitations due to the consideration of security and difficulty of implementation, for example, it cannot support loop, or must strict the length of its scripts, or only supports limited numbers of standard transactions. -The most attractive characteristic of Ethereum is that it significantly expands the scale of functionality of this scripting engine. In detail, Ethereum adds several instructions such as reading blockchain, charging, jumping, etc., as well as releases the limitation of the invoke depth of stakes and functions, and length of the script. Ethereum claims that its scripting engine is Turing-completeness by which developers can carry out almost any computation that can be represented by mathematic model. -Although with Ethereum, expanding script became a prevail approach of decentralized application platform, it still has one disadvantage that cannot be ignored: the application itself and the data generated by it have to be stored in the same blockchain, which makes the blockchain grows extremely rapidly. Ethereum tried to slow this trend down by optimizing or compressing the program code and data, but still cannot solve the problem completely. Moreover, since those applications based on scripting have to share the same ledger, some parameters, i.e., created-time of blockchain, cannot be changed, which prevents developers from customizing the application. -Sidechain mechanism, in contrast, deals with scalability in another way. Every sidechain is running in a different distributed network node, having separate users, investors and development team. This partition-like solution has resolved the blockchain expansion problem, and has made every application has its own ledger, on which the consensus mechanism, blockchain parameter, and transaction mode can be customized. For this reason, we believe sidechain mechanism is a lower-cost, more flexible and easier to use solution -than a Turing-completeness transaction scripting. -## Account vs UTXO -Within Bitcoin and derived systems, there is no so-called “account” to save the user’s balance. The balance has to be dealt with by the status transition of the whole transaction system’s status. Let’s introduce a new term, UTXO, standing for unspent transaction outputs. Every UTXO has its own nominal price and its owner and each transaction has multiple -inputs and outputs. Each input includes a reference of current UTXO and a cryptographic signature generated by private key related to owner’s address. If a user own this private key, he/she can consume the value of this UTXO, in other words, the balance this user has is the sum of the currency value of all the UTXO related to the user’s private keys. The main advantage of UTXO is high level security, which means the user can generate a new address for each of his/her transaction so that he/she cannot be traced. It is a great thing for a currency involved transaction, but to variety of DAPPs, it is not sure. Compare to UTXO, account has following benefits: -1. Space efficiency. For instance, it will take a user 300 bytes space when he/she has 5 UTXOs: (20+32+8) x 5 = 300 bytes (20 bytes for address, 32 bytes for transaction No., -and 8 bytes for transaction amount). Meanwhile if using account, the storage space will be limited to 30 bytes: 20+8+2=30 bytes (in this case, 20 bytes for address, 8 bytes for balance, and 2 bytes for random number). -2. Easy to monitor. Due to the account, the electronic currencies are easy to recognized, since all we have to know is the account that the currency is coming from. -3. Simple, easy to code and understand. -4. Referring in a fixed time. A lightweight client can access all the data in a user’s account -in a fixed time, while with UTXO system, the access time will change every time once there is a transaction. -Asch platform is not a pure currency system because it has to contain various applications. In general, account mechanism is a better option under this circumstance. -## Relational Database vs Non-relational Database -At present most blockchain system choose to use lightweight non-relational databases, such as Berkeley DB, LevelDB, and so on. Usually these kinds of database support some simple data structures, like B-tree, hashtable, and they are not able to manipulate data through SQL. Generally non-relational database is good enough at the application of electronic currency system, but speaking of application platform, it is not the case, especially when we talk -about finance, bank, e-commerce and so no. Within these fields, the relational database is wildly used because of its following advantages: -1. Transaction processing -2. Very low cost of data updating -3. Capability of complex query (using join, for example) -We decide to adopt SQLite, a high-performance lightweight embedded rational database. SQLite can support up to 2T data volume, and the data file can be shared smoothly among different byte order machines. The most attractive feature is SQL, which is very suitable for DAPP developers. -# System Highlights -## Ease of Use -### Development Language -Developers can use JavaScript and numerous npm libraries to create their application. Unlike C++ and transaction script for Bitcoin and new Solidity for Ethereum, JavaScript is more popular, has more followers, and is easier to master. Furthermore, by introducing relational database, Asch platform make decentralized application development more like coding -traditional web application, hence it become the easiest way among all the current development approaches. -### Toolkits -Asch system provides a command-line tool to rapidly create a sidechain on which any kind of applications can be created and deployed. Also the system provides a series of API, involving consensus mechanism, strong random number, database, and cryptography, to help users creating complex smart contract applications. -### Deployment -To deploy the applications, all the developers need to do is committing their DAPPs onto Github, and registering in web wallet or light wallet. After that DAPPs will be presented in App store to download. -## Flexibility -Developers can freely customize all parameters in their sidechain, such as generating speed of block, transaction type, and transaction fee, etc., even can carry out a new consensus mechanism. -## Security -One well-known highlight of Asch system is an consensus algorithm based on improved DPOS, in detail, the system embedded a high-performance Byzantine fault tolerance algorithm upon original DPOS hence significantly reduce the possibility of network forks. As long as there is no more than 1/3 nodes which are attempting to attack together, the system will not generate a separate chain, or a fork, so that the risk of double payment will be avoided. Secondly, Asch system closely examined every detail with security consideration, such as passphrase hint based on BIP39 algorithm, two level trading password, and multi-signature, etc. -# Technique Specification -## Consensus Mechanism -The consensus mechanism used by Asch system is based on DPOS, a mechanism of delegates vote, but applied an optimized variant algorithm of PBFT, which can make loyal nodes reach an agreement, i.e., not fork, in O(n^2) message complexity and O(1) time complexity when t < n/3. Here “t” refers to the number of Byzantine node (on which any situation can happen, such as network delay, machine shutdown, or malicious attacks) and “n” refers to the number of all nodes. -### Delegates vote -The delegates vote mechanism of Asch is similar with the one of DPOS, which is composed of 101 delegate nodes. A delegate is a trustful account voted by community, and 101 delegates who have the most votes are allowed to running the nodes which maintain the network and generate the blocks. Those accounts who cannot be the top 101 are called “candidates”, who can be delegate once they get enough votes to become the top 101. -Every Asch user has the right to vote up to 101 delegates, and the weights of vote is determined by the amount of XAS owned by this user. -Each voting round will generate 101 blocks, and the ranking change of each voting and delegates will be shown in the next round. The new block will be generated in 10 seconds after the previous one, and then be broadcasted into network and appended in the blockchain. Once new block is added, the confirmation count of all transactions before will be increased 1 time. After gaining 6 confirmations, a transaction can be treated as “safe”. If the amount of transaction is small, less confirmation count is allowed. In other words, larger confirmation count is necessary when it is a large transaction to improve the security. -If some failures occurred in a few delegates, such as under attacks or shutdown, the block will miss, and this issue will be recorded. This problem has an impact on the online rate of this node hence the voting of community. Therefore the election of delegate should be treated solemnly, for example, a delegate needs to have experience on running a website, ability to maintain the nodes stable, so that the security and stability of the whole system will be strengthened. -### Byzantine Fault Tolerance -The major difference between Asch system and DPOS is reflected in the second part of the algorithm. -What the DPOS applied is, first, randomly sorting the delegate list of current round (to make sure the delegate of next round cannot be predicted since the order of delegate of each round will be different), then let delegates create block in turn through a round-robin way. The main issue of this algorithm is that, if a delegate attempt to attack, he may broadcast many different blocks, which may contact double payment trades, to “fork” the whole network. It is no doubt that if only one delegate betrays, the fork will be solved by syncing with the next longest chain. However, it will take a much longer time to eliminate betrayed nodes as their amount is increasing. A few betrayed nodes are enough to have a serious impact on system security, which means even we can gain 6 confirmations, it still may not be sure that the network is safe. -To deal with this problem, we introduced an algorithm known as PBFT (Practical Byzantine Fault Tolerance). Same as DPOS, PBFT also chooses delegates in the way of round-robin. The different part is there will not be a block generated after delegates are voted. In fact, there will be a piece of propose issued to determine the hash code of next block. Only when more than 2/3 of all nodes agree with this propose, next block will be generated. The hash of next block must be the same as that agreed with all delegates of current round. Essentially, the introduction of PBFT solved the issue of abusing the delegates’ right, and improved the control capability of ledgers. -## Sidechain and DAPP -Asch system provides a command tool by which developers can easily create a basic sidechain system. Developers are also able to fully customize their sidechain system, including its own database, consensus mechanism, trading mode and account architecture. Sidechain system can be hosted in the clusters of nodes of individual delegates, so that a partitioned mechanism can be naturally generated hence avoid the rapid expansion of the main blockchain. -Every DAPP is related to a sidechain. A sidechain’s core code is developed by nodejs, but UI can be programmed by any of front-end techniques such as QT, HTML, or JavaScript. The communication between front-end and back-end is usually implemented under JSON RPC protocol. The developer or owner of a DAPP can trace the usage of their application. Compare to cryptocurrency that is based on community consensus, DAPPs are more like a private company. All the transactions within a DAPP are handled by main node, which is run by DAPP’s owner. The owner of DAPP must have an Asch account, like a multi-signature account, whose major objective is to create a consensus of a new block and to sign it in DAPP’s main node, just like multi-signature wallet. Once a new DAPP is created, and signed in main node, the SHA256 hash of this block need to be calculated, and submitted to the main blockchain of Asch system as a DAPP block by the owner of it. When Asch’s main blockchain received information of a trade including DAPP hash, the delegate will compare it with the previous one and then store it into Asch blockchain. Then lately when main node is in sync with network, the user will validate all DAPP blocks through Asch blockchain, which means it is impossible to remove the previous DAPP block from main blockchain. Developers can replace Asch blockchain with Bitcoin blockchain to use the same functionality since the usage of Asch API will be the same. The security of DAPP can also be guaranteed by Bitcoin blockchain. Developers can take advantage of both XAS and BTC as the currency of their DAPP. In the case of money in-and-out when using a DAPP, the Asch coin or BTC will be delivered to a DAPP address, and appropriate amount of money will be shown in that DAPP’s account, ready to use. The deposit mechanisms of both BTC and Asch are the same, which is to deliver to a particular DAPP address, and then the appropriate amount will be shown in -the account. In every DAPP the account is created by the developer, so all deposited BTC or Asch coin will be saved in related address. Considering the security, only those DAPP accounts owned by trustable signers with multi-signature are recommended. A withdrawal from DAPP is main node’s responsibility. When someone requests a withdrawal of money, DAPP main nodes will acquire the request and move the money from DAPP address to Asch blockchain or Bitcoin blockchain. Developers are allowed to issue a token in their own DAPP, and to use it as the currency of this DAPP. These kinds of token can be circulated in DAPP like XAS or BTC, but are not allowed to transfer from one DAPP to another directly but through Asch main blockchain. -## Sandbox and VM -Sandbox is a running environment that restricts program’s activities under the security policy. In early time it was used to test suspicious software, for example hackers usually use sandbox technique to run some virus or unsafe program. The implementation of a classic sandbox is usually to intercept the system calls, to monitor program’s activities, in order to control the usage of computer’s resource such as disk I/O according to user’s policy. -Asch system implemented sandbox mechanism by using VM module of nodejs. The VM module is an encapsulation of JavaScript V8 engine, which is used to run the pure JavaScript code. But it cannot use system APIs like file system or network communication. It also is lack of “require” function therefore the third-party libraries cannot be imported smoothly and even worse, the modular development cannot be conducted. This requires DAPP developers to use a “browserify” technique to bundle all the third-party libraries they used to a JavaScript file, so that Asch system can load it and run. Some necessary system level API will be provided to sidechain through IPC (Inter-Process Communication), which takes into account both security and functional completeness. -## Transaction -Asch system has built a abstract transaction layer, on which almost all the functionalities of system core are established, such as transferring, voting, application store, deposit, and withdrawal. The sidechain itself can also implement its own type of transaction. The main difference between each transaction is their types and assets. The data structure of a basic transaction is as follow, and the extension of transaction will be saved in different asset table according to its type. -```sql -Transaction { -required VARCHAR(20) id; -required VARCHAR(20) blockId; -required TINYINT type; -required INT timstamp; -required VARCHAR(21) senderId; -optional VARCHAR(21) recpientId; -required BIGINT amount; -required BIGINT fee; -required BINARY(64) signature; -optional BINARY(64) signSignature; -optional TEXT signatures; -required BINARY(32) senderPublicKey; -} -``` -Let us take a vote transaction as an example: the vote entity is connected to a basic transaction through transaction Id like follows: -```sql -Asset_Votes { -required VARCHAR(20) transactionId; -optional TEXT votes; -} -``` - -## Account System -Every account in Asch system consists of one passphrase, a pair of public/private key and an address. Users can also set their own secondary password. Note that the difference with Bitcoin here is that each account is related to only one address, instead of multiple addresses and private keys related to one wallet in Bitcoin. -Passphrase is a mnemonics used to produce real wallet in line with BIP39 standard. The mnemonics is much easier to remember for people than other binary or hexadecimal characteristics. The way in which a passphrase is generated is to convert entropy on a multiple of 32bit into several words, particular in Asch system, the length of entropy is 128bit and it will be converted into 12 words. The passphrase, as a top-level password, is maintained by users instead of published in public. Once users lost their passphrase they would lost the ownership of their account. A passphrase is generally like follows: -barely decline dust stamp protect color certain cup arena busy latin shell -A pair of keys includes public key and private key, which uses SHA256 hash of passphrase as seed and is generated through ed25519 Edwards-curve Digital Signature Algorithm (EdDSA). It looks like this: -``` -Public Key: -9989388b220a13465e49f52df5ba28ba08eb1e7a973320347f9687a107dc2f9a - -Private Key: -91e891f653e3ed0232d8c7de2e72b625d50d48593fc0fb570c0db25c5e44569a9989388b220a13465e4 -9f52df5ba28ba08eb1e7a973320347f9687a107dc2f9a -``` -The account address is a big number generated by reversely converting the first 8 bits of SHA256 hash of public key, shown as follows: -``` -5034187504202890358 -``` -## Client -Asch platform provides three types of clients: -The full version client is a perfect solution for those super users, delegates and developers, running on Windows, Mac OSX and Linux, but only Linux system can run delegate nodes on which blocks forging is enabled. -The lite wallet client allows users to connect network through full version wallet or API, but it is necessary to open all the right of this API by the owner of this full version wallet. A full version wallet can download the whole blockchain from other full version wallets through peer-to-peer network. -An ordinary user usually use lite wallet to manage his/her Asch account. The lite wallet can run on Windows and Mac OSX platform without installation. It utilizes the system built-in browser. It needs to be noted that the lite wallet cannot run as a network node since it would not download the blockchain data but only links with other nodes through HTTP protocol, which have several advantages: first, no blockchain data downloaded would keep the volume small; second, no private key broadcasted to network make it possible to make all types of trade since all the data will be signed locally. If you want to run a delegate node, you can use lite wallet to register a delegate account, but cannot run delegate node through it to produce block. In order to run it, downloading and running a full version wallet in Linux would be necessary. The DAPP users can take advantage of lite version wallet to manage installed DAPP. The APIs of both DAPP and node are available for developer to invoke, so that it can make them rapidly and easily creating JavaScript DAPP through Node.js. -The mobile version client allows users to manipulate their own Asch accounts on their mobile devices, both iOS and Android platform. They can download the client from AppStore or Google Play. The backend of the client is based on our solution applied in our desktop version, but mobile client applies responsive UI instead to fit the mobile device screen and changes some interface mode according to the device characteristics. This mobile -application brings mobile user-friendly interface, like Bitcoin or some major bank application, and of course, the mobile client can also support all the DAPP you like running inside of it. -## Performance -All the information of a transaction usually occupies about 100 bytes. Let us calculate how much network bandwidth will it be demanded when system achieve 10,000 TPS. Since the interval of block production is 10 seconds, each block needs to carry 100,000 transactions, which make the volume become 10 megabytes. This 10 MB data needs to be broadcasted to whole network, so even under the best situation, 10 nodes will be achieved in the first step, and then 100 nodes in the next step, and each step is supposed to complete in 5 seconds, which makes the necessary bandwidth be 10MB x 10 /5 = 20 MB. Considering the bandwidth loss and unexpected circumstance, we think that bandwidth needs to be at least 40 MB to satisfy the 10,000 TPS throughput. Although this volume of bandwidth is not easy to gain, it can be sure that it will bring much more benefit to delegates than the cost. In Nov 11, 2014, the peak throughput of Alipay payment system reached 85900 per second. There is still possibility for optimization of trade throughput in Asch system, which is our major investment in the future. -# Scenarios -## Token System -The “hello world” program generated by Asch toolkit would be a basic token system. -Developers may not need to write even a line of code but adjust some initial parameters in genesis.json, to publish a token system. Like sub-currency on top of Ethereum, the token in Asch system can represent gold, stock, mortgage, or any other type of asset. These tokens can be traded with XAS transferred in sidechain in a decentralized way, and with any other currencies in a centralized exchange. -## Mediatory Contract -Let us assume that a buyer wants to trade with a person he/she does not familiar with. Generally if the trade is well-doing, both would not hope the interference from a third-party. But if there is any issue occurred during the procedure, like the buyer does not satisfy with the items, they would like a mediator to help solving the problem. The mediator will ask both sides to present some evidences and then make a decision, for example, ask seller making a refund. This business process can be described as follows: -1. Both the buyer and seller of the transaction choose a mediator together. -2. The buyer creates a 2-3 multi-signature account by using a public key shared with all the -three parties. Then the buyer transfers the money into this account, then signs and -publishes a transaction in which the buyer’s account and seller’s one are treated as promotor and recipient respectively. At this moment this transaction would not be confirmed immediately until two of these three people have signed. -3. The seller dispatches the item to the buyer. -4. If the buyer received the item and satisfy with it, he/she will sign the transaction with -his/her private key. After that when the seller sign the transaction again, it will be -completed successfully. -5. If the buyer does not satisfy with the item, he/she can launch a complaint to the -mediator and show evidences about the item with faults. Then the seller also can show evidences against buyer’s one. Finally the mediator would make an agreement with one of the two sides of trade and sign this trade together to complete it. -## Decentralized Exchange -There are two types of decentralization according to legal currency support. If legal currency is not supported, the full decentralization can be realized; otherwise only half decentralization would be supported. In this case, legal currency can circulate through gateway but transaction information would be made public. -Full decentralized exchange can still be divided into two types: one is peer-to-peer trade through “atomic cross chain exchange API”. The other one is pending order, which require seller transfer an amount of asset to Asch sidechain from other blockchain. This moving should be achieved by the SPV proof of frozen assets of main chain. Beside, with the support of relational database, it is easy to create a well performance matching engine by using union-table query and index. -## Existence Proof -Existence proof is used to register copyright, patent and so on, which is based on the idea that to prove an existed particular file by saving hash code of this file into Asch sidechain. In addition we can add metadata such as timestamps, owners’ digital signatures to prove when they own these files. This kind of information cannot be forged or revised, will not expose the privacy data and ready to verify at any time without any third-party authority. -## IoT (Internet of Things) -There are numerous of online devices existed in IoT, which make it difficult to manage all the devices and identification of every nodes by a single authority. Asch sidechain is an excellent solution for it. Firstly, it can deal with trustiness among different nodes. It means that all devices connect to each other to be a distributed network, and trade between devices can be verified by consensus algorithm, and can be traced, audited, and analyzed. Secondly, different types of devices can be connected to different side chains, and this natural partition mechanism that we mentioned above can prevent main ledger from explosive -increment. Let us imagine that a vending machine in a sidechain based IoT can not only monitor and report its own stock, but also analyze historic trading data to select suppliers to submit the tender, and then automatically complete payment. -# Conclusion -Asch system is a decentralized application platform, which is designed to lower the threshold for developers, such as using JavaScript as develop language, supporting relational database to save transaction data, and making DAPP development be similar with traditional Web application. It is sure that these characteristics are very attractive to developers and SMEs. The ecosystem of the whole platform cannot be improved until developers make a huge progress on productivity. Also, Asch platform is designed to be open for various fields, not limited to some particular parts such as finance, file storage, or copyright proof. It provides underlying and abstract API which can be combined freely to create different types of applications. In consensus mechanism, Asch inherits and enhances DPOS algorithm, by which the possibility of forks and risk of duplicate payments would be significantly reduced. Furthermore, Asch sidechain mode not only can mitigate the pressure of blockchain expansion, but also make DAPP more flexible and personal. Asch system, as a proactive, low-cost and full stack solution, will surely be a next generation incubator of decentralized applications. \ No newline at end of file