├── 5_minutes ├── en.md ├── images │ └── asch-wide-logo.png └── zh-cn.md ├── README.md ├── asch-cli ├── de.md ├── en.md └── zh-cn.md ├── asch-js ├── en.md └── zh-cn.md ├── asch-pay └── zh-cn.md ├── asch-web └── zh-cn.md ├── assets ├── common-dapp-problems │ ├── asch_public_dist_chains_dir.png │ ├── dapp_install_location.png │ └── min_folder_structure.png ├── dapp │ ├── cctime_file.png │ ├── custom_api_example.png │ ├── dapp_variables_article_max_id.png │ ├── debug_ndb_chains_dir.png │ ├── debug_ndb_contract_breakpoint.png │ ├── debug_ndb_contract_breakpoint_hit.png │ ├── debug_ndb_debugger_statement.png │ ├── debug_ndb_debugger_statement_hit.png │ ├── debug_ndb_start.png │ ├── debug_ndb_start_app.png │ ├── debug_ndb_start_app_detail.png │ ├── debug_ndb_switch_context.png │ ├── debug_terminal_start_ndb.png │ ├── hello_world │ │ └── asch_starter_contract_installed.png │ ├── ndb_debug_kill_processes.png │ └── ndb_debug_right_side.png ├── forging-secret.png ├── inbuilt-modules.png ├── js_api │ ├── asch_js_key_two_accounts.png │ ├── asch_js_mainchain_sidechain_endpoints.png │ ├── asch_js_refuel_after.png │ ├── asch_js_refuel_before.png │ ├── asch_js_withdraw_after.png │ └── asch_js_withdraw_before.png ├── process-structure.png ├── sdk_api │ ├── filled_custom_articles_table.png │ ├── filled_custom_comments_table.png │ ├── filled_custom_dapp_table.png │ └── filled_custom_dapp_table_trs.png ├── sidechain-deploy.png └── win_install │ ├── control_panel_system_variables_en.PNG │ ├── env_variables_new_en.PNG │ ├── env_variables_new_python_en.PNG │ ├── env_variables_select_path_en.PNG │ ├── environment_variables_menu_en.PNG │ ├── gcc.png │ ├── gcc_gplusplus_en.PNG │ ├── gcc_verify.png │ ├── git_install_cmd_en.PNG │ ├── git_install_git_bash_en.PNG │ ├── git_openssl_en.PNG │ ├── git_option_en.PNG │ ├── install.png │ ├── install_en.PNG │ ├── mingw_apply_changes_en.PNG │ ├── mingw_env_variable_en.PNG │ ├── mingw_setup_en.PNG │ ├── mingw_sourceforge_en.PNG │ ├── node.png │ ├── node_en.PNG │ ├── openssl_download_en.PNG │ ├── openssl_installation_en.PNG │ ├── python.png │ ├── python_location_en.PNG │ ├── python_not_found_en.PNG │ ├── python_success_en.PNG │ ├── run.png │ ├── run_en.PNG │ ├── sqlite3.png │ ├── sqlite3_env_variable_en.PNG │ ├── sqlite3_extract_zip_en.PNG │ ├── sqlite3_new_dir_content_en.PNG │ ├── sqlite3_success_en.PNG │ ├── sqlite3_verify.png │ ├── vc_custom_en.PNG │ ├── vc_set_msvs_version_2015_en.PNG │ ├── vc_win8_win10_en.PNG │ ├── win10.net.png │ └── win10_dot_net_en.PNG ├── contract ├── contract-in-action │ ├── 1. 智能合约概述.md │ ├── 2.1 Hello, World.md │ ├── 2.2 语法规范(上)——ECMAScript篇.md │ ├── 2.3 语法规范(下)——TypeScript篇.md │ ├── 2.4 实战:CCTime.md │ ├── 3 测试智能合约.md │ ├── 4.1 部署合约.md │ ├── 4.2 调用合约.md │ ├── 4.3 查询合约状态.md │ ├── 5.1 附录一:燃料计费表和智能合约内置函数.md │ ├── 5.2 附录二:调试智能合约.md │ ├── README.md │ └── img │ │ └── 1.2.1.jpg ├── hello-contract │ └── zh-cn.md ├── install │ └── zh-cn.md └── introduction │ └── zh-cn.md ├── create_account ├── en.md └── images │ ├── address.png │ ├── emptybalance.png │ ├── login.png │ ├── logout.png │ ├── nextstep.png │ └── pay.png ├── delegate-forging ├── en.md └── zh-cn.md ├── exchange ├── XAS_integration_in_exchange_CN.md ├── XAS_integration_in_exchange_en.md └── XCT_integration_in_exchange_CN.md ├── http-api ├── de.md ├── en-1.3.6.md ├── en.md ├── zh-cn-1.3.6.md └── zh-cn.md ├── install ├── de.md ├── dev_windows_install.md ├── dev_windows_install_en.md ├── en.md └── zh-cn.md ├── manual └── zh-cn.pdf ├── pics ├── WX20180816-173409.png ├── WX20180816-173442.png ├── WX20180816-174419@2x.png └── WX20180816-185028@2x.png ├── side-chain ├── api │ ├── en.md │ └── zh-cn.md ├── common_dapp_dev_problems_en.md ├── dapp_dev_tutorials.md ├── hello_world │ ├── de.md │ ├── en.md │ └── zh-cn.md ├── how_to_debug_dapps_en.md ├── introduction │ ├── de.md │ ├── en.md │ └── zh-cn.md ├── mini_dao │ └── en.md └── sdk │ ├── en.md │ └── zh-cn.md ├── tokens ├── en.md └── images │ ├── issuedassets.png │ ├── issuing.png │ └── newpublisher.png ├── v1.5-release.md └── whitepaper ├── asch ├── de.md ├── en.md └── zh-cn.md ├── assets ├── chart.png ├── chart2.png ├── math.png ├── score.png └── wechat.png └── cctime ├── en.md └── zh-cn.md /5_minutes/en.md: -------------------------------------------------------------------------------- 1 | ASCH is a blockchain application development platform based on multi-chain architecture. Follow the steps to develop DApps on the ASCH Platform: 2 | 3 |
4 | 5 |

6 | logo 7 |

8 | 9 |
10 |
11 | 12 | ### What is ASCH? 13 | 14 | 1.ASCH [White Paper](http://asch-public.oss-cn-beijing.aliyuncs.com/asch.io/Asch-Whitepaper-en.pdf) 15 | 16 | 2.ASCH [official website](https://www.asch.io) 17 | 18 | 3.ASCH [blockchain explorer](https://explorer.asch.io) 19 | 20 | 4.ASCH source code [repository](https://github.com/AschPlatform/asch) 21 | 22 | 5.ASCH related [documentation](https://github.com/aschplatform/asch-docs) 23 | 24 |
25 | 26 | ### Get started with Sidechain development (tutorial) 27 | 28 | 1. Install local ASCH blockchain node 29 | 2. Create new DApp 30 | 3. Register your DApp on your local ASCH blockchain 31 | 4. Start developing the business logic 32 | 33 | All steps are described in detail in the following tutorials: 34 | 35 | #### Part 1 36 | 37 | sidechain1 38 | 39 | 40 | #### Part 2 41 | 42 | sidechain2 43 | 44 | 45 | 46 |
47 |
48 | 49 | 50 | ### Hello World (tutorial) 51 | 52 | 1. Build ASCH [Hello World](https://github.com/AschPlatform/asch-docs/blob/master/dapp/hello_world/en.md) DApp 53 | 54 | 3. Build ASCH [Mini DAO](https://github.com/AschPlatform/asch-docs/blob/master/dapp/mini_dao/en.md) DApp 55 | 56 | 57 | ### ASCH Sample DApps 58 | 59 | - CCTime: [Sidechain-Backend](https://github.com/AschPlatform/cctime) and [Sidechain-Frontend](https://github.com/AschPlatform/cctime-frontend) 60 | - Hello-World: [Frontend and Backend](https://github.com/AschPlatform/asch-dapp-helloworld) 61 | 62 | 63 | ### Documentation 64 | - [Dapp Javascript SDK](https://github.com/AschPlatform/asch-docs/blob/master/sdk_api/en.md) 65 | - [Dapp Http API](https://github.com/AschPlatform/asch-docs/blob/master/dapp/api/en.md) 66 | - [ASCH Http API](https://github.com/AschPlatform/asch-docs/blob/master/http_api/en.md) 67 | 68 | ### Tools 69 | - asch-js [repository](https://github.com/aschplatform/asch-js), [documentation](https://github.com/AschPlatform/asch-docs/blob/master/js_api/en.md) 70 | - asch-cli [repository](https://github.com/aschplatform/asch-cli), [documentation](https://github.com/AschPlatform/asch-docs/blob/master/cli_usage/en.md) 71 | - asch-redeploy [repository](https://github.com/aschplatform/asch-redeploy), [documentation](https://github.com/AschPlatform/asch-redeploy/blob/master/README.md) 72 | 73 |
74 |
75 | 76 | 77 | ### Create an Account 78 | 79 | ASCH provides a series of development tools for the blockchain application development, including SDK, a command-line tool as well as a series of REST API interfaces. Developers can choose the right development tools according to their preferences and environment. 80 | 81 | The following are ways to use different tools to create an account, for example: 82 | 83 | #### 1. Call API 84 | 85 | ```bash 86 | Request: 87 | curl -k -X GET 'https://wallet.asch.io/api/accounts/new' 88 | 89 | # return value 90 | Response JSON: 91 | { 92 | success: true, 93 | secret: "during crush zoo wealth horror left night upset spike iron divert lawn", 94 | publicKey: "261fa56f389c324fddbe8777dbc0ef3341ee7b75d1ffdc82192265633b90d503", 95 | privateKey: "67c9523b7622704c4bcfe960cb32d7fa04d3eb94e30e7964d3c6a24a3647a0a3261fa56f389c324fddbe8777dbc0ef3341ee7b75d1ffdc82192265633b90d503", 96 | address: "ANfXDQUZroMnrQ6vRGR7UXXtbPn3fhEVRJ" 97 | } 98 | ``` 99 | 100 | #### 2. Use npm `asch-js` package 101 | 102 | Create new file `account.js`: 103 | 104 | ```bash 105 | touch account.js 106 | ``` 107 | 108 | Create a `package.json` file with the following command: 109 | 110 | ```bash 111 | npm init --yes 112 | ``` 113 | 114 | Install all needed dependencies: 115 | 116 | ```bash 117 | npm install --save asch-js bitcore-mnemonic 118 | ``` 119 | 120 | Paste the following code into the `account.js` file: 121 | 122 | ```js 123 | const AschJS = require('asch-js') 124 | const Mnemonic = require('bitcore-mnemonic') 125 | 126 | module.exports = { 127 | createNewAccount: function () { 128 | let secret = new Mnemonic(Mnemonic.Words.ENGLISH).toString() 129 | let keypair = AschJS.crypto.getKeys(secret) 130 | let address = AschJS.crypto.getAddress(keypair.publicKey) 131 | return { 132 | address: address, 133 | secret: secret 134 | } 135 | } 136 | } 137 | ``` 138 | 139 | Then execute the new code: 140 | 141 | ```bash 142 | node -p 'require("./account").createNewAccount()' 143 | 144 | # return value: 145 | { 146 | address: 'AMD4DNn5fKsnETVUJxBB3RB8nWNxC7goDf', 147 | secret: 'lecture shed style cake dentist print cool noble cloud safe ozone estate' 148 | } 149 | ``` 150 | 151 | 152 | #### 3. Use npm `asch-cli` package 153 | 154 | ```bash 155 | ./asch-cli crypto --generate 156 | # ? Enter number of accounts to generate // 1 157 | 158 | # return value 159 | [ 160 | { 161 | address: 'AP4CiQ7pFaazNfkv8JSqHmM1UmZ4kiqkvY', 162 | secret: 'glance stand fix dumb lottery exist filter peace donate shed intact cannon', 163 | publicKey: 'cd3559626060bd232444c3deb2b4a7a3807e7b8cf5a0558a7a0cb0a98a9ea3da' 164 | } 165 | ] 166 | ``` 167 | 168 | -------------------------------------------------------------------------------- /5_minutes/images/asch-wide-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/5_minutes/images/asch-wide-logo.png -------------------------------------------------------------------------------- /5_minutes/zh-cn.md: -------------------------------------------------------------------------------- 1 | 阿希是一个多链架构的区块链应用开发平台,想要基于阿希开发区块链应用,一般要经历如下步骤: 2 | 3 | ### 一、了解阿希 4 | 5 | 阿希白皮书:http://asch-public.oss-cn-beijing.aliyuncs.com/asch.io/Asch-whitepaper-zh.pdf 6 | 7 | 阿希官网:https://www.asch.io 8 | 9 | 阿希区块链浏览器:https://explorer.asch.io 10 | 11 | 阿希源码: https://github.com/AschPlatform/asch 12 | 13 | 阿希相关文档:https://github.com/AschPlatform/asch/tree/master/docs 14 | 15 | ### 二、开发区块链应用 16 | 17 | 1.搭建本地开发节点 18 | 19 | 2.启动localnet并安装asch-cli 20 | 21 | 3.本地创建一个 Dapp 模板 22 | 23 | 4.注册应用到主链 24 | 25 | 5.部署应用代码及子网络 26 | 27 | 6.实现业务逻辑 28 | 29 | 详细可参考: 30 | 31 | https://github.com/AschPlatform/asch/blob/master/docs/dapp_docs/1_hello.md 32 | 33 | 34 | 35 | ### 三、使用阿希开发工具 36 | 37 | 阿希为区块链应用开发提供了一系列的开发工具,包括SDK、命令行工具以及一系列的REST API接口。 开发者可以根据自己的喜好和环境选择合适的开发工具。以下是以生成账户为例,使用不同工具完成的方法: 38 | 39 | #### 1. 调用API 40 | ``` 41 | 请求: 42 | curl -k -X GET 'http://45.32.248.33:4096/api/accounts/new' 43 | 44 | 返回JSON: 45 | { 46 | success: true, 47 | secret: "during crush zoo wealth horror left night upset spike iron divert lawn", // 密码 48 | publicKey: "261fa56f389c324fddbe8777dbc0ef3341ee7b75d1ffdc82192265633b90d503", // 公钥 49 | privateKey: "67c9523b7622704c4bcfe960cb32d7fa04d3eb94e30e7964d3c6a24a3647a0a3261fa56f389c324fddbe8777dbc0ef3341ee7b75d1ffdc82192265633b90d503", // 私钥 50 | address: "ANfXDQUZroMnrQ6vRGR7UXXtbPn3fhEVRJ" // 地址 51 | } 52 | ``` 53 | #### 2. 使用asch-js 54 | 55 | ``` 56 | const AschJS = require('asch-js') 57 | const Mnemonic = require('bitcore-mnemonic') 58 | 59 | module.exports = { 60 | createNewAccount: function () { 61 | let secret = new Mnemonic(Mnemonic.Words.ENGLISH).toString() 62 | let keypair = AschJS.crypto.getKeys(secret) 63 | let address = AschJS.crypto.getAddress(keypair.publicKey) 64 | return { 65 | address: address, 66 | secret: secret 67 | } 68 | } 69 | } 70 | ``` 71 | #### 3. 使用asch-cli,需要手工填写主密码 72 | ``` 73 | root@asch:~# asch-cli -H 45.32.248.33 -P 4096 openaccount "fault still attack alley expand music basket purse later educate follow ride" 74 | { 75 | "address": "16723473400748954103", 76 | "unconfirmedBalance": 20000000000, 77 | "balance": 20000000000, 78 | "publicKey": "bd1e78c5a10fbf1eca36b28bbb8ea85f320967659cbf1f7ff1603d0a368867b9", 79 | "unconfirmedSignature": false, 80 | "secondSignature": false, 81 | "secondPublicKey": "", 82 | "multisignatures": [], 83 | "u_multisignatures": [] 84 | } 85 | ``` 86 | 87 | 详细可参考: 88 | 89 | API:https://github.com/AschPlatform/asch/blob/master/docs/asch_http_interface.md 90 | 91 | Asch-cli: https://github.com/AschPlatform/asch/blob/master/docs/asch_cli_usage.md 92 | 93 | Asch-js: https://github.com/AschPlatform/asch-js 94 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # asch_docs 2 | 3 | ## 文档索引 4 | 5 | - [v1.5更新说明](./v1.5-release.md) 6 | - [ASCH白皮书](./whitepaper/asch/zh-cn.md) 7 | - [全节点安装](./install/zh-cn.md) 8 | - [受托人锻造区块及收益机制](./delegate-forging/zh-cn.md) 9 | - [asch-web 使用指南](./asch-web/zh-cn.md) 10 | - [asch-pay 使用指南](./asch-pay/zh-cn.md) 11 | - [HTTP API 接口文档](./http-api/zh-cn.md) 12 | - [交易平台对接文档](./exchange) 13 | - **智能合约** 14 | + [准备智能合约开发环境](./contract/install/zh-cn.md) 15 | + [5分钟开发ASCH智能合约](./contract/hello-contract/zh-cn.md) 16 | + [智能合约开发概述](./contract/introduction/zh-cn.md) 17 | + [智能合约开发实战](./contract/contract-in-action/README.md) 18 | + [智能合约Gas计费与函数库](./contract/contract-in-action/5.1%20附录一:燃料计费表和智能合约内置函数.md) 19 | -------------------------------------------------------------------------------- /asch-pay/zh-cn.md: -------------------------------------------------------------------------------- 1 | # AschPay Browser Extension 2 | 3 | [Download From Chrome WebStore](https://chrome.google.com/webstore/detail/aschpay/eibepfonpdkkelekmahbbhcfkeijlpop) 4 | 5 | AschPay is a Browser Extension for Asch NetWork. 6 | It can be used to debug smart contract, or play DApps with browser. 7 | 8 | ## Build 9 | 10 | - Install [Node.js](https://nodejs.org/) version 8.9.3 or later. 11 | - Install local dependencies with `npm install`. 12 | - Build with development `npm run dev`. 13 | - Build for Publishing `npm run build`. 14 | 15 | Uncompressed builds will found in `./build` 16 | 17 | ## DApp Developers 18 | 19 | When AschPay is installed, AschPay will inject a [AschWeb](https://github.com/AschPlatform/asch-web) object into current document, you can find it in `window.aschPay.aschWeb` or `window.aschWeb`. 20 | Note that you can use like this to check AschPay environment 21 | 22 | ``` 23 | window.addEventListener('load', function() { 24 | 25 | // Checking if the aschWeb has been injected 26 | if (typeof aschPay !== 'undefined') { 27 | aschWeb = aschPay.aschWeb || aschWeb 28 | if (aschWeb.isAschPay && aschWeb.ready) { 29 | // Now start you app & access aschWeb 30 | } 31 | } else { 32 | console.log('No aschWeb? You should install AschPay!') 33 | } 34 | }) 35 | ``` 36 | 37 | 38 | 39 | ## Asch智能合约和前端交互 40 | 41 | 42 | ### 安装谷歌AschPay钱包 43 | 44 | ```javascript 45 | // chrome网上应用店 46 | https://chrome.google.com/webstore/detail/asch-pay/gjdneabihbmcpobmfhcnljaojmgoihfk 47 | 48 | // github 49 | https://github.com/AschPlatform/asch-web 50 | 51 | ``` 52 | 53 | ### 全局声明 54 | 55 | ```javascript 56 | const aschWeb = window.aschWeb 57 | const contract = await aschWeb.createContractFromName('crowdFundging_v1') 58 | ``` 59 | 60 | ### 调用合约方法 61 | 62 | ```javascript 63 | let result = await contract.call('getXXT', ['233'], 1000000, false) 64 | console.log('testContract result:' + JSON.stringify(result)) 65 | 66 | ``` 67 | 68 | ### 转账到合约 69 | 70 | ```javascript 71 | contract.pay('XAS', '12345', contract.name, 1000000, false). 72 | then(res => { 73 | if (res.success) { 74 | alert('调用成功') 75 | //document.getElementById('result').innerHTML = JSON.stringify(res) 76 | } else { 77 | // alert(res.error) 78 | console.error(res) 79 | } 80 | }).catch(err => { 81 | alert(res.error) 82 | console.error(err) 83 | }) 84 | 85 | ``` 86 | 87 | 88 | 89 | ## License 90 | 91 | AschPay is [MIT](./LICENSE) licensed# asch-pay 92 | -------------------------------------------------------------------------------- /asch-web/zh-cn.md: -------------------------------------------------------------------------------- 1 | 2 | ## 什么是asch-web? 3 | 4 | __[asch-web - Developer Document](https://github.com/AschPlatform/asch-docs/blob/master/http_api/zh-cn.md)__ 5 | asch-web是一个通过HTTP请求与ASCH节点进行通信的js库。asch-web提供常用的交易写操作API和常用的工具函数,诸如XAS转账,合约执行,账户创建,助记词,公钥和地址转和交易离线签名等等,asch-web受到Ethereum的[web3.js](https://github.com/ethereum/web3.js/)库的设计思想,提供统一的,无缝的开发体验。我们用核心思想对其进行了扩展,集成了ASCH常用的API,asch-web用typescript语言进行编写,可以build生成浏览器环境和node环境的js库,也可以直接在typescript项目中直接引用使用,对于DAapps与asch节点的交互提供了极大的方便。 6 | 7 | ## 兼容性 8 | - 支持Node.js v8及更高版本构建的版本 9 | - 支持Chrome浏览器环境 10 | 11 | 您可以从`dist /`文件夹中专门访问这两个版本。 12 | asch-web还兼容前端框架,如Angular,React和Vue。 13 | 您也可以在Chrome扩展程序中集成asch-web。 14 | 15 | ## Build 16 | 17 | 首先使用git克隆asch-web项目, 安装依赖并且运行示例: 18 | 19 | ``` 20 | git clone https://github.com/AschPlatform/asch-web 21 | cd asch-web 22 | npm install 23 | npm run build 24 | 25 | ``` 26 | dist目录下生成了两个文件夹tsc和webpack, 可供不同环境的项目使用,其中tsc可以拷贝到typescript项目中直接使用,webpack生成的文件可以拷贝到node项目或者web项目直接使用。 27 | 28 | 29 | ## 安装 30 | 31 | 1. npm安装 32 | 33 | ``` 34 | npm install asch-web 35 | 36 | ``` 37 | 38 | 2. 本地安装 39 | 40 | ``` 41 | npm install path/to/asch-web #本地路径 42 | 43 | ``` 44 | 45 | 3. 通过github安装 46 | 47 | ``` 48 | npm install git://github.com/AschPlatform/asch-web.git #master分支 49 | npm install git://github.com/AschPlatform/asch-web.git#kim #kim分支 50 | 51 | ``` 52 | 53 | ## 54 | 55 | ## 实例 56 | 57 | 实例源码在`examples`目录下,这个目录分有三个子目录:typescript, browser和server,分别对应typescript, 浏览器和node三种不同运行环境的实例。 58 | 59 | 60 | ### typescript项目实例 61 | 62 | ``` 63 | cd example/typescript 64 | npm install 65 | npm run build #生成js文件 66 | npm run start #运行js文件 67 | 68 | ``` 69 | 70 | ``` 71 | import { AschWeb } from 'asch-web' 72 | const host = 'http://testnet.asch.cn'// 'http://mainnet.asch.cn/' 73 | const net = AschWeb.Network.Test// Network.Main 74 | 75 | let secret = 'quantum jelly guilt chase march lazy able repeat enrich fold sweet sketch' 76 | let secondSecret = '' //'11111111a' 77 | let address = 'ACFi5K42pVVYxq5rFkFQBa6c6uFLmGFUP2' 78 | let to = 'AHcGmYnCyr6jufT5AGbpmRUv55ebwMLCym' 79 | 80 | let unsignedTrx = 81 | { 82 | type: 1, 83 | fee: 10000000, 84 | args: [1000000, 'AHcGmYnCyr6jufT5AGbpmRUv55ebwMLCym'], 85 | timestamp: 84190767, 86 | message: '', 87 | senderPublicKey: '', 88 | senderId: 'ACFi5K42pVVYxq5rFkFQBa6c6uFLmGFUP2', 89 | } 90 | 91 | 92 | //utils用法 93 | let keys = AschWeb.Utils.getKeys(secret) 94 | console.log('keys:' + JSON.stringify(keys)) 95 | 96 | let addr: string = AschWeb.Utils.getAddress(keys.publicKey) 97 | console.log('get address by publicKey:' + addr) 98 | 99 | 100 | let signedTrx = AschWeb.Utils.fullSign(unsignedTrx, secret, secondSecret) 101 | console.log('full sign transaction:' + JSON.stringify(signedTrx)) 102 | 103 | const provider = new AschWeb.HTTPProvider(host, net) 104 | const aschWeb = new AschWeb(provider, secret, secondSecret) 105 | 106 | aschWeb.api 107 | .transferXAS(1000000, to, 'test') 108 | .then(res => { 109 | console.log('transfer XAS response:' + JSON.stringify(res)) 110 | }) 111 | .catch(err => { 112 | console.error(err) 113 | }) 114 | 115 | const host2 = 'http://mainnet.asch.cn/' 116 | const net2 = AschWeb.Network.Main 117 | const provider2 = new AschWeb.HTTPProvider(host2, net2) 118 | //切换provider 119 | aschWeb.setProvider(provider2) 120 | 121 | aschWeb.api 122 | .get('api/v2/blocks', {}) 123 | .then(res => { 124 | console.log('get blocks response:' + JSON.stringify(res)) 125 | }) 126 | .catch(err => { 127 | console.error(err) 128 | }) 129 | 130 | 131 | 132 | ``` 133 | 134 | 135 | ### 构建交易-->签名交易-->广播交易 136 | 137 | 1. [TransactionBuilder 生成未签名的交易](https://github.com/AschPlatform/asch-web/blob/contract-gen/src/builders/README.md) 138 | ``` 139 | let trans = TransactionBuilder.transferXAS(1000,to,'test') 140 | console.log('unsigned transcation:'+JSON.stringify(trans)) 141 | ``` 142 | 143 | ``` 144 | unsigned transcation: 145 | { 146 | "type": 1, 147 | "fee": 10000000, 148 | "args": [1000, "AHcGmYnCyr6jufT5AGbpmRUv55ebwMLCym"], 149 | "timestamp": 86665886, 150 | "message": "test", 151 | "senderPublicKey": "", 152 | "senderId": "" 153 | } 154 | ``` 155 | 156 | 2. fullSign 对交易签名,并生成交易ID 157 | ``` 158 | let signedTrans = AschWeb.Utils.fullSign(trans, secret, secondSecret) 159 | console.log('signed transcation:'+JSON.stringify(signedTrans)) 160 | ``` 161 | 162 | ``` 163 | signed transcation: 164 | { 165 | "type": 1, 166 | "fee": 10000000, 167 | "args": [1000, "AHcGmYnCyr6jufT5AGbpmRUv55ebwMLCym"], 168 | "timestamp": 86665886, 169 | "message": "test", 170 | "senderPublicKey": "0136d2cc3970fb029ac763cfdae6cc44416a7470d04301897f718ecf0cb0d640", 171 | "senderId": "ACFi5K42pVVYxq5rFkFQBa6c6uFLmGFUP2", 172 | "signatures": ["89812e11e74243aec19cff9979e58e2f6ae31b70c75b52ad65dfebb816f4bce626d3d310396796526316f90daba409dc4cd7865944df50d570295bc1469d9a05"], 173 | "id": "ce6f75041fb0041c6523700af174d12da3a8e39d5e730f81aa3727ca24db2982" 174 | } 175 | ``` 176 | 177 | 3. broadcastTransaction广播交易 178 | 179 | ``` 180 | let result = aschWeb.api.broadcastTransaction(signedTrans) 181 | .then(res => { 182 | console.log('result:' + JSON.stringify(res)) 183 | }) 184 | .catch(err => { 185 | console.error(err) 186 | }) 187 | ``` 188 | 189 | ``` 190 | result: 191 | { 192 | "success": true, 193 | "transactionId": "15cab894a1c86b68c33e0c47e292fdb474cdca73d6337fd2c7f138c48d6e20e3" 194 | } 195 | ``` -------------------------------------------------------------------------------- /assets/common-dapp-problems/asch_public_dist_chains_dir.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/common-dapp-problems/asch_public_dist_chains_dir.png -------------------------------------------------------------------------------- /assets/common-dapp-problems/dapp_install_location.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/common-dapp-problems/dapp_install_location.png -------------------------------------------------------------------------------- /assets/common-dapp-problems/min_folder_structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/common-dapp-problems/min_folder_structure.png -------------------------------------------------------------------------------- /assets/dapp/cctime_file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/dapp/cctime_file.png -------------------------------------------------------------------------------- /assets/dapp/custom_api_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/dapp/custom_api_example.png -------------------------------------------------------------------------------- /assets/dapp/dapp_variables_article_max_id.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/dapp/dapp_variables_article_max_id.png -------------------------------------------------------------------------------- /assets/dapp/debug_ndb_chains_dir.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/dapp/debug_ndb_chains_dir.png -------------------------------------------------------------------------------- /assets/dapp/debug_ndb_contract_breakpoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/dapp/debug_ndb_contract_breakpoint.png -------------------------------------------------------------------------------- /assets/dapp/debug_ndb_contract_breakpoint_hit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/dapp/debug_ndb_contract_breakpoint_hit.png -------------------------------------------------------------------------------- /assets/dapp/debug_ndb_debugger_statement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/dapp/debug_ndb_debugger_statement.png -------------------------------------------------------------------------------- /assets/dapp/debug_ndb_debugger_statement_hit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/dapp/debug_ndb_debugger_statement_hit.png -------------------------------------------------------------------------------- /assets/dapp/debug_ndb_start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/dapp/debug_ndb_start.png -------------------------------------------------------------------------------- /assets/dapp/debug_ndb_start_app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/dapp/debug_ndb_start_app.png -------------------------------------------------------------------------------- /assets/dapp/debug_ndb_start_app_detail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/dapp/debug_ndb_start_app_detail.png -------------------------------------------------------------------------------- /assets/dapp/debug_ndb_switch_context.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/dapp/debug_ndb_switch_context.png -------------------------------------------------------------------------------- /assets/dapp/debug_terminal_start_ndb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/dapp/debug_terminal_start_ndb.png -------------------------------------------------------------------------------- /assets/dapp/hello_world/asch_starter_contract_installed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/dapp/hello_world/asch_starter_contract_installed.png -------------------------------------------------------------------------------- /assets/dapp/ndb_debug_kill_processes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/dapp/ndb_debug_kill_processes.png -------------------------------------------------------------------------------- /assets/dapp/ndb_debug_right_side.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/dapp/ndb_debug_right_side.png -------------------------------------------------------------------------------- /assets/forging-secret.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/forging-secret.png -------------------------------------------------------------------------------- /assets/inbuilt-modules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/inbuilt-modules.png -------------------------------------------------------------------------------- /assets/js_api/asch_js_key_two_accounts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/js_api/asch_js_key_two_accounts.png -------------------------------------------------------------------------------- /assets/js_api/asch_js_mainchain_sidechain_endpoints.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/js_api/asch_js_mainchain_sidechain_endpoints.png -------------------------------------------------------------------------------- /assets/js_api/asch_js_refuel_after.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/js_api/asch_js_refuel_after.png -------------------------------------------------------------------------------- /assets/js_api/asch_js_refuel_before.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/js_api/asch_js_refuel_before.png -------------------------------------------------------------------------------- /assets/js_api/asch_js_withdraw_after.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/js_api/asch_js_withdraw_after.png -------------------------------------------------------------------------------- /assets/js_api/asch_js_withdraw_before.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/js_api/asch_js_withdraw_before.png -------------------------------------------------------------------------------- /assets/process-structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/process-structure.png -------------------------------------------------------------------------------- /assets/sdk_api/filled_custom_articles_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/sdk_api/filled_custom_articles_table.png -------------------------------------------------------------------------------- /assets/sdk_api/filled_custom_comments_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/sdk_api/filled_custom_comments_table.png -------------------------------------------------------------------------------- /assets/sdk_api/filled_custom_dapp_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/sdk_api/filled_custom_dapp_table.png -------------------------------------------------------------------------------- /assets/sdk_api/filled_custom_dapp_table_trs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/sdk_api/filled_custom_dapp_table_trs.png -------------------------------------------------------------------------------- /assets/sidechain-deploy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/sidechain-deploy.png -------------------------------------------------------------------------------- /assets/win_install/control_panel_system_variables_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/control_panel_system_variables_en.PNG -------------------------------------------------------------------------------- /assets/win_install/env_variables_new_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/env_variables_new_en.PNG -------------------------------------------------------------------------------- /assets/win_install/env_variables_new_python_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/env_variables_new_python_en.PNG -------------------------------------------------------------------------------- /assets/win_install/env_variables_select_path_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/env_variables_select_path_en.PNG -------------------------------------------------------------------------------- /assets/win_install/environment_variables_menu_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/environment_variables_menu_en.PNG -------------------------------------------------------------------------------- /assets/win_install/gcc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/gcc.png -------------------------------------------------------------------------------- /assets/win_install/gcc_gplusplus_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/gcc_gplusplus_en.PNG -------------------------------------------------------------------------------- /assets/win_install/gcc_verify.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/gcc_verify.png -------------------------------------------------------------------------------- /assets/win_install/git_install_cmd_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/git_install_cmd_en.PNG -------------------------------------------------------------------------------- /assets/win_install/git_install_git_bash_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/git_install_git_bash_en.PNG -------------------------------------------------------------------------------- /assets/win_install/git_openssl_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/git_openssl_en.PNG -------------------------------------------------------------------------------- /assets/win_install/git_option_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/git_option_en.PNG -------------------------------------------------------------------------------- /assets/win_install/install.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/install.png -------------------------------------------------------------------------------- /assets/win_install/install_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/install_en.PNG -------------------------------------------------------------------------------- /assets/win_install/mingw_apply_changes_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/mingw_apply_changes_en.PNG -------------------------------------------------------------------------------- /assets/win_install/mingw_env_variable_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/mingw_env_variable_en.PNG -------------------------------------------------------------------------------- /assets/win_install/mingw_setup_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/mingw_setup_en.PNG -------------------------------------------------------------------------------- /assets/win_install/mingw_sourceforge_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/mingw_sourceforge_en.PNG -------------------------------------------------------------------------------- /assets/win_install/node.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/node.png -------------------------------------------------------------------------------- /assets/win_install/node_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/node_en.PNG -------------------------------------------------------------------------------- /assets/win_install/openssl_download_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/openssl_download_en.PNG -------------------------------------------------------------------------------- /assets/win_install/openssl_installation_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/openssl_installation_en.PNG -------------------------------------------------------------------------------- /assets/win_install/python.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/python.png -------------------------------------------------------------------------------- /assets/win_install/python_location_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/python_location_en.PNG -------------------------------------------------------------------------------- /assets/win_install/python_not_found_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/python_not_found_en.PNG -------------------------------------------------------------------------------- /assets/win_install/python_success_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/python_success_en.PNG -------------------------------------------------------------------------------- /assets/win_install/run.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/run.png -------------------------------------------------------------------------------- /assets/win_install/run_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/run_en.PNG -------------------------------------------------------------------------------- /assets/win_install/sqlite3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/sqlite3.png -------------------------------------------------------------------------------- /assets/win_install/sqlite3_env_variable_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/sqlite3_env_variable_en.PNG -------------------------------------------------------------------------------- /assets/win_install/sqlite3_extract_zip_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/sqlite3_extract_zip_en.PNG -------------------------------------------------------------------------------- /assets/win_install/sqlite3_new_dir_content_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/sqlite3_new_dir_content_en.PNG -------------------------------------------------------------------------------- /assets/win_install/sqlite3_success_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/sqlite3_success_en.PNG -------------------------------------------------------------------------------- /assets/win_install/sqlite3_verify.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/sqlite3_verify.png -------------------------------------------------------------------------------- /assets/win_install/vc_custom_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/vc_custom_en.PNG -------------------------------------------------------------------------------- /assets/win_install/vc_set_msvs_version_2015_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/vc_set_msvs_version_2015_en.PNG -------------------------------------------------------------------------------- /assets/win_install/vc_win8_win10_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/vc_win8_win10_en.PNG -------------------------------------------------------------------------------- /assets/win_install/win10.net.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/win10.net.png -------------------------------------------------------------------------------- /assets/win_install/win10_dot_net_en.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/assets/win_install/win10_dot_net_en.PNG -------------------------------------------------------------------------------- /contract/contract-in-action/1. 智能合约概述.md: -------------------------------------------------------------------------------- 1 | ASCH 智能合约平台致力于成为简单、灵活、安全、高效的智能合约平台。 2 | 3 | ### 1.1 设计目标 4 | 5 | 1. 简单。智能合约容易学习、容易编写、容易验证。 6 | 2. 灵活。 7 | 1. 设计灵活,易于扩展。 8 | 2. 编写灵活,可满足绝大部分场景。 9 | 3. 安全。 10 | 1. 智能合约是运行安全的,恶意合约不会对区块链造成破坏性的影响。 11 | 2. 智能合约语言必须是图灵完备的。 12 | 3. 智能合约运行必须在有限有的时间内停止。 13 | 4. 高效。ASCH 智能合约能达到上千 TPS。 14 | 15 | ### 1.2 技术选型 16 | 17 | #### 1.2.1 智能合约平台对比 18 | 19 | 在设计智能合约之前,首先得选定一门智能合约语言。现在市面上的智能合约平台情况如图所示: 20 | 21 | ![](./img/1.2.1.jpg) 22 | 23 | 其中最出名的莫过于以太坊的 Solidity,但 Solidity 是一门全新的语音,学习门槛高,以致以太坊后来又开发了新的智能合约语言 Vyper(Python 语言子集),就是为了解决开发门槛高的问题。 24 | 25 | #### 1.2.2 基于 Typescript 子集的智能合约语言 26 | 27 | 阿希技术团队经过各种可行性调研后,最终采用了 Node.js 的 VM(ECMAScript 运行环境) + TypeScript 子集(智能合约语言,最终编译成 js)的方案。好处如下: 28 | 29 | 1. JavaScript 有庞大的开发者群体,TypeScript 是 JavaScript 的超集,且越来越受欢迎。阿希链本身也是基于 Node.js 开发的,开发者只需要学习 TypeScript 即可上手开发智能合约。 30 | 2. Node.js 的 VM 提供了一个安全的沙盒环境运行 JavaScript。 31 | 3. Node.js v10.13.0+ 之后内置了大整数(BigInt)的支持。 32 | 33 | TypeScript 子集的意思是:精简了 TypeScript 部分特性和 ECMAScript 部分语法。如: 34 | 35 | 1. 不能使用 any(TypeScript) 36 | 2. 不能使用可选类型(TypeScript) 37 | 3. 不能使用 Date.now() 和 Math.random()(ECMAScript) 38 | 4. 不能使用 delete、with、try、throw 等等(ECMAScript) 39 | 5. 具体见后面的章节 40 | 41 | #### 1.2.3 为什么是 Typescript 而不是 JavaScript? 42 | 43 | TypeScript 是 JavaScript 的超集,主要添加了静态类型检查。使用 TypeScript 有以下几个优点: 44 | 45 | 1. 更严谨的合约设计。智能合约开发者使用强类型的 TypeScript 更能设计出严谨的 DApp。 46 | 2. 更友好地代码提示。配合 VS Code + TypeScript 插件,大大提高智能代码编写效率。 47 | 3. 更少的 bug。在编写智能合约期间就能检测代码有效性,配合定制化的 tslint,大大减少编写智能合约过程中的 bug。 48 | 4. 最重要的是:在编译 TypeScript 的时候可以拿到参数的类型和属性,保证合约调用时的安全,如:声明为 private 的方法只能在智能合约内部使用,无法通过外部调用。 49 | 50 | #### 1.2.4 与以太坊智能合约对比 51 | 52 | | | 以太坊智能合约平台 | ASCH智能合约平台 | 53 | | -------- | ------------------- | ---------------------- | 54 | | 语言 | Solidity | TypeScript 子集 | 55 | | 运行环境 | 以太坊虚拟机(EVM) | Node.js 沙盒环境(VM) | 56 | | 开发难度 | 难 | 易 | 57 | | 燃料价格 | 高 | 低 | 58 | | tps | 低 | 高 | 59 | 60 | ### 1.3 技术实现 61 | 62 | **隔离的合约执行进程和存储** 63 | 64 | 基于安全性的考虑,智能合约代码执行运行在与 ASCH 链相隔离的独立进程中,虽然带来了引擎实现的复杂度,但好处是智能合约的恶意代码不会修改 ASCH 链的数据,修改合约状态只能通过指定的交易才可以实现,恶意代码也难以通过接口直接篡改合约状态,同时每个合约也运行在独立的沙盒中,合约代码之间相互隔离,一个合约无法修改其他合约的状态。 65 | 66 | **使用 TypeScript 语言作为合约语言** 67 | 68 | TypeScript 是一种由微软开发的自由和开源的编程语言,它是 JavaScript 的一个超集,由实现了静态类型和基于类的面向对象编程。由 Anders Hejlsberg 设计(他同时还是 Delphi 和 .NET 的设计师),TypeScript 借鉴了许多 C#、Java 等现代语言的优点,相对 JavaScript 来说具有更为安全、更完善的工具支持、代码更易维护的特点。ASCH 智能合约平台使用 Typescript 语言作为智能合约编写语言可以实现对合约代码的有效性检查、减少智能合约编写过程中的 bug,提升开发智能合约的效率。 69 | 70 | **自动的状态管理** 71 | 72 | 合约状态管理是智能合约引擎中一个重要的部分,部分平台的做法是提供底层的持久化接口给开发人员自己手动管理状态,但让开发人员需要关注持久化的细节,这样就增加了不必要的复杂性。在 ASCH 智能合约中状态的持久化是透明的、自动完成的,开发人员只需要对状态变量进行赋值即可,不需要考虑持久化的细节。这样让开发人员把注意力集中在合约的逻辑本身上,降低合约的开发难度,提高合约代码的可理解和可维护性。 -------------------------------------------------------------------------------- /contract/contract-in-action/2.1 Hello, World.md: -------------------------------------------------------------------------------- 1 | 下面我们看一个简单的智能合约示例,我们称之为:无聊的复读机。只是为了演示 ASCH 智能合约的写法,并没有实际用处。 2 | 3 | ```js 4 | export class RepeaterContract extends AschContract { 5 | holding: Mapping 6 | 7 | constructor() { 8 | super() 9 | 10 | this.holding = new Mapping() 11 | } 12 | 13 | @payable({ isDefault: true }) 14 | pay(amount: bigint, currency: string): void { 15 | assert(amount > 0, 'amount must great than 0') 16 | assert(currency === 'XAS', 'support XAS only') 17 | 18 | this.increaseHolding(this.context!.senderAddress, amount) 19 | } 20 | 21 | repeater(amount: bigint): string { 22 | const senderAddress = this.context!.senderAddress 23 | assert(amount > 0, 'amount must great than 0') 24 | const remainingHolding = this.getHolding(senderAddress) 25 | assert(remainingHolding >= amount, `holding ${remainingHolding} XAS less than ${amount}`) 26 | 27 | this.increaseHolding(senderAddress, -amount) 28 | 29 | return 'Hello, World!'.repeat(amount) 30 | } 31 | 32 | private increaseHolding(address: string, amount: bigint): void { 33 | const holdingValue = this.holding[address] || BigInt(0) 34 | this.holding[address] = holdingValue + BigInt(amount) 35 | } 36 | 37 | @constant 38 | getHolding(address: string): bigint { 39 | return this.holding[address] || BigInt(0) 40 | } 41 | } 42 | ``` 43 | 44 | 可以看出,一个 ASCH 智能合约就是一个用 TypeScript 写的一个类!简单介绍一下这个复读机智能合约(RepeaterContract)的功能。 45 | 46 | 1. pay 方法添加了 @payable 修饰器并且有 isDefault: true 参数,即表示向合约地址转账时会自动调用 pay 方法。 47 | 2. repeater 是智能合约的一个公开的方法,调用时传参数 amount 表示想消耗多少 XAS,返回 amount 个 Hello, World!。 48 | 3. increaseHolding 是智能合约的一个私有的方法,只能在合约内调用 49 | 4. getHolding 方法被 @constant 修饰,表示这个方法是个只读方法 50 | 51 | 我们还可以看出,这个合约用到了 BigInt、assert、Mapping 等内置类型。下一小节将会讲解 ASCH 智能合约里的基本数据类型。 -------------------------------------------------------------------------------- /contract/contract-in-action/2.2 语法规范(上)——ECMAScript篇.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 概述里提到过,ASCH 智能合约的实现最终采用了 Node.js 的 VM(ECMAScript 运行环境) + TypeScript 子集(智能合约语言,最终编译成 js)的方案。下面讲解一下哪些语言特性是合约内可以使用的,哪些是不可以使用的。 4 | 5 | 首先,我们得明确 ECMAScript 是语言标准,而 Node.js 是 JavaScript(ECMAScript 的主要实现)的运行时环境,并且提供了额外的底层功能,如:文件操作、网络 IO 等等。Node.js 的 VM 是 ECMAScript/JavaScript 的运行环境(基于 V8),并不能使用 Node.js 中独有的 API,即 ASCH 智能合约中也只能使用 ECMAScript 的部分特性。 6 | 7 | #### 2.2.1 智能合约内可以使用的 8 | 9 | **运算符** 10 | 11 | 1. 一元运算符:+、-、!、~、typeof、void 12 | 2. 自增减运算符:++、-- 13 | 3. 二元运算符:==、!=、===、!==、<、<=、>、>=、<<、>>、>>>、+、-、*、/、%、|、^、&、in、instanceof 14 | 4. 赋值运算符:=、+=、-=、*=、/=、%=、<<=、>>=、>>>=、|=、^=、&= 15 | 5. 逻辑运算符:&&、|| 16 | 6. 三元运算符:?: 17 | 7. new 操作符 18 | 19 | **全局变量** 20 | 21 | 1. Object 22 | 23 | 1. 静态方法:assign、entries、keys、values、is 24 | 2. Array 25 | 26 | 1. 静态方法:from、isArray、of 27 | 2. 实例方法:concat、copyWithin、every、fill、filter、find、findIndex、forEach、includes、indexOf、join、lastIndexOf、map、pop、push、reduce、reduceRight、reverse、shift、unshift、slice、some、sort、splice、toString 28 | 3. String 29 | 30 | 1. 静态方法:fromCharCode 31 | 2. 实例方法:charAt、charCodeAt、startsWith、endsWith、includes、indexOf、lastIndexOf、padStart、padEnd、repeat、slice、substr、substring、split、toLowerCase、toUpperCase、trim、trimLeft、trimRight、toString 32 | 4. Number 33 | 34 | 1. 静态方法:isNaN、parseFloat、parseInt 35 | 2. 实例方法:toExponential、toFixed、toPrecision、toString 36 | 5. Math 37 | 38 | 1. 静态方法:abs、acos、acosh、asin、asinh、atan、atan2、atanh、cbrt、ceil、clz32、cos、cosh、exp、expm1、floor、fround、hypot、imul、log、log10、log1p、log2、max、min、pow、round、sign、sin、sinh、sqrt、tan、tanh、trunc 39 | 6. BigInt 40 | 41 | 1. 构造函数。如:BigInt(100000000000000) 42 | 2. 实例方法:toString 43 | 7. **assert**。ASCH 智能合约添加的,断言函数 44 | 8. **Mapping**。ASCH 智能合约添加的,需要使用 new 实例化,key-value 型对象 45 | 1. 静态方法:fromItems、isMapping、keysOf、sizeOf 46 | 9. **Vector**。ASCH 智能合约添加的,容器类,需要使用 new 实例化,类似数组 47 | 1. 静态方法:isVector 48 | 2. 实例方法:push、pop、size 49 | 10. **Crypto**。ASCH 智能合约添加的,常用哈希函数 50 | 1. Crypto.sha256.hash 51 | 2. Crypto.ripemd160.hash 52 | 3. Crypto.ed25519.sign 53 | 4. Crypto.ed25519.verify 54 | 11. **ByteBuffer**。ASCH 智能合约添加的,二进制操作 55 | 1. 静态方法:wrap、isByteBuffer 56 | 2. 实例方法:readInt8、readUint8、readInt16、readUint16、readInt32、readUint32、readInt64、readUint64、readFloat32、readFloat64、readString、readCString、readIString、writeInt8、writeUint8、writeInt16、writeUint16、writeInt32、writeUint32、writeInt64、writeUint64、writeFloat32、writeFloat64、writeString、writeCString、writeIString、toString、toArrayBuffer、flip 57 | 12. **Util**。ASCH 智能合约添加的,工具函数集 58 | 1. Util.Address.generateNormalAddress 59 | 13. **修饰器** 60 | 1. @payable。转账接口,如果有 `isDefault: true` 参数,即表示向该合约地址转账时会自动调用这个方法。其他添加 @payable 修饰器的函数,给合约转账时需要指明函数名,格式 {contract_name}/{pay_mothod_name}。 61 | 2. @constant。只读接口,可以通过 HTTP 接口调用,该函数有以下使用限制: 62 | 1. 不能修改合约的状态,即 this 上的属性 63 | 2. 不能使用 this.transfer,即不能转账 64 | 3. 不能使用 this.context,因为没有区块信息 65 | 66 | #### 2.2.2 智能合约内不能使用的 67 | 68 | **关键字** 69 | 70 | 1. delete 71 | 2. debugger 72 | 3. with 73 | 4. throw 74 | 5. try-catch 75 | 6. AsyncFunction + await 76 | 7. GeneratorFunction + yield 77 | 8. import 78 | 79 | **全局变量** 80 | 81 | 1. Date 82 | 2. Function 83 | 3. Boolean 84 | 4. Symbol 85 | 5. Error + EvalError + RangeError + ReferenceError + SyntaxError + TypeError + URIError 86 | 6. RegExp 87 | 7. Int8Array + Uint8Array + Uint8ClampedArray + Int16Array + Uint16Array + Int32Array + Uint32Array + Float32Array + Float64Array 88 | 8. Map + WeakMap 89 | 9. Set + WeakSet 90 | 10. JSON 91 | 11. Promise 92 | 12. Reflect 93 | 13. Proxy 94 | 14. Intl 95 | 15. WebAssembly 96 | 97 | **全局方法** 98 | 99 | 1. eval + uneval 100 | 2. isFinite 101 | 3. isNaN 102 | 4. parseFloat + parseInt 103 | 5. encodeURI + decodeURI 104 | 6. encodeURIComponent + decodeURIComponent 105 | 7. escape + unescape 106 | 8. setTimeout + clearTimeout 107 | 9. setInterval + clearInterval 108 | 10. setImmediate + clearImmediate 109 | 110 | #### 2.2.3 Node.js 版本要求 111 | 112 | 因为 ASCH 智能合约支持了 BigInt 类型,所以 Node.js 版本应当是 **v10.13.0+**。 113 | -------------------------------------------------------------------------------- /contract/contract-in-action/2.3 语法规范(下)——TypeScript篇.md: -------------------------------------------------------------------------------- 1 | #### 2.3.1 TypeScript 基本规范 2 | 3 | 智能合约语法使用的是 `Typescript` 语言的子集: 4 | 5 | - 所有变量都有具体的类型,不使用`null`、`any`、`never`、`object`、`unknown` 等类型 6 | - 不支持`Symbol` 7 | - 不支持交叉类型(如`string & number`)和联合类型(如`string | null`) 8 | - 不支持生成器和异步语法(不使用`Promise`、`async/await`) 9 | - 不使用强制类型转换(不使用`name`及`name as string`) 10 | - 只能使用引擎内置的类型、对象、函数 11 | - 变量、函数等必须有明确的类型或可推断出明确的类型,不可以是`any` 12 | 13 | ##### 2.3.1.1 常用类型说明 14 | 15 | - 简单类型:指`number`、`string`、`boolean`、`bigint`之一 16 | - 状态容器:指`Mapping`或`Vecotr` 17 | 18 | ##### 2.3.1.2 一个合约文件可包含的内容 19 | 20 | - 常量声明 21 | - 数据接口类型声明 22 | - 自定义状态类型声明 23 | - 合约类定义 24 | 25 | #### 2.3.2 常量声明 26 | 27 | 一个合约文件中可以有多个常量声明,使用`const`关键字声明,需要注意的是:**常量只能使用四种简单类型**(`string`、`number`、`bigint`、`boolean`),其他类型包括`object`,`any`等都不支持,例: 28 | 29 | ```typescript 30 | const DEFAULT_NAME = 'name' 31 | const DEFAULT_INTEVEL = 3 * 1000 32 | ``` 33 | 34 | #### 2.3.3 数据接口类型声明 35 | 36 | 一个合约文件中可以有多个数据接口类型声明,数据接口类型**用于公开方法的参数及返回值**,使用`interface`关键字声明,限制如下: 37 | 38 | - 成员只能使用简单类型、`Array`、数据接口类型,成员可以是可选的(使用`?`语法声明) 39 | - 不支持联合类型(如`string & number`和`string | number`) 40 | - 如果成员是`Array`,必须指定泛型参数。泛型类型可以是简单类型、`Array`、数据接口类型,泛型类型参数如果本身不是泛型推荐使用简写形式(如:`names: string[]`) 41 | - 数据接口类型的嵌套深度不能超过 3 42 | - 数据接口类型不可以使用泛型定义(不支持`inteface Data {...}`) 43 | - 不支持只读成员(不支持`readonly`) 44 | - 不支持索引访问器 45 | 46 | 示例: 47 | 48 | ```typescript 49 | interface AddressInfo { 50 | province: string 51 | city: string 52 | street: string 53 | } 54 | 55 | interface PersonInfo { 56 | name: string 57 | age?: number 58 | sex: boolean 59 | address: Address 60 | } 61 | 62 | interface PeopleResultInfo { 63 | count: number 64 | pepole: PersonInfo[] 65 | } 66 | ``` 67 | 68 | #### 2.3.4 自定义状态类型声明 69 | 70 | 一个合约文件中可以有多个状态类型声明,**状态类型用于合约状态**,类似于传统的`POJO`使用`class`关键字声明,限制如下: 71 | 72 | - 成员只能属性定义或构造函数,属性可以使用简单类型、状态容器、状态类型 73 | - 状态容器指`Mapping`(类似于`Map`)或`Vecotr`(类似于`Array`),状态容器中的数据会自动持久化 74 | - 成员可以是可选的(使用`?`语法定义),可以初始化默认值。除可选成员外的所有成员属性必须通过默认值或构造器初始化 75 | - 只支持实例成员(不支持`static`)且可见性为公开(`public`可省略),不支持`private`, `protected` 76 | - 如果成员是状态容器,必须指定泛型参数。泛型类型可以是简单类型、状态容器和状态类型 77 | - 状态类型的嵌套深度不能超过 3 78 | - 状态类不可以使用泛型定义(不支持`class StateData {...}`) 79 | - 不能是抽象类(不支持`abstract`) 80 | - 不支持实现接口(不支持`implements`语法)和继承(不支持`extends`语法) 81 | - 不支持索引访问器 82 | - 不支持只读成员(不支持`readonly`) 83 | - 不支持`getter`和`setter` 84 | - 所有非可选成员必须初始化,可以在声明时初始化或在构造函数中初始化 85 | - 可以声明一个公开的构造函数,**状态类构造函数不能产生异常** 由于状态数据需要从数据库中加载,需要通过无参构造函数初始化(所有的参数都为`undefined`,随后再初始化各个成员属性)。引擎在调用构造函数时不能产生异常,否则会导致合约加载失败 86 | 87 | 示例: 88 | 89 | ```typescript 90 | class PayState { 91 | payTimes: number 92 | amount: bigint 93 | 94 | constructor() { 95 | this.payTimes = 0 96 | this.amount = BigInt(0) 97 | } 98 | } 99 | 100 | class PayStateDefault { 101 | payTimes = 0 102 | amount = BigInt(0) 103 | } 104 | 105 | class PayStateOptional { 106 | payTimes = 0 107 | amount?: bigint 108 | } 109 | ``` 110 | 111 | #### 2.3.5 合约类定义 112 | 113 | 一个合约文件中必须**有且仅有一个**合约类定义,使用`class`关键字定义,合约类必须是`AschContract`的子类。合约类只允许合约状态和方法两类成员,基本要求如下: 114 | 115 | - 使用`export`关键字修饰 116 | - 必须从`AschContract`直接继承,不支持多重继承 117 | - 不能是泛型类(不能有泛型参数) 118 | - 不能是抽象类(不支持`abstract`) 119 | - 不支持实现接口(不支持`implements`语法) 120 | - 不支持索引访问器 121 | - 不支持`getter`和`setter` 122 | - 只支持实例成员,不支持静态成员(不支持`static`) 123 | 124 | 下面来逐个介绍合约中两类成员的具体规范。 125 | 126 | ##### 2.3.5.1. 合约状态 127 | 128 | 合约状态是可以自动进行持久化的合约成员属性。开发者只需要给合约的成员属性赋值,引擎会自动把这些状态持久化到区块链中,对于合约状态来说: 129 | 130 | - 类型必须是简单类型、状态类型、状态容器之一, 131 | - 如果成员是状态容器,必须指定泛型参数。泛型类型可以是简单类型、状态容器和状态类型 132 | - 状态类型的嵌套深度不能超过 3 133 | - 所有合约状态成员必须初始化,可以在声明时初始化或在构造函数中初始化 134 | - **状态不可以是可选的**(不可以是`undefined`) 135 | - 可见性为公开的状态可以通过HTTP接口查询其状态值(见本文后续介绍),非公开状态不可直接查询(可通过查询方法实现查询) 136 | 137 | ##### 2.3.5.2 合约方法 138 | 139 | 合约类中的方法都必须是成员方法(不支持`static`),不支持异步语法(`Promise`、`async/await`)和生成器语法(`generator`)。可分为以下几类 140 | 141 | - 构造器 142 | - 可调用方法(可见性为公开的普通方法) 143 | - 资产接收方法(使用`payable`注解) 144 | - 查询方法(使用`constant`注解) 145 | - 内部方法(可见性为非公开的普通方法`private`或`protected`) 146 | 147 | ##### 2.3.5.3 构造器 148 | 149 | 一个合约只能有一个构造器,是合约类的初始化方法,名称必须为`constructor`,仅在合约注册时执行一次,具体要求如下: 150 | 151 | - 可见性必须是公开 152 | - 签名必须是`constructor() {...}`,没有参数也没有返回值 153 | - 可以访问`this.context` 154 | - **调用构造器不应产生异常,否则合约无法注册成功** 155 | - **不可以访问`this.transfer`**,否则会产生异常导致合约无法注册(因为合约注册时,合约账户没有任何资产) 156 | 157 | ##### 2.3.5.4 可调用方法 158 | 159 | 一个合约可以有多个可调用方法,是合约类中可见性为公开的,且没有注解修饰的成员方法,具体要求如下: 160 | 161 | - 可见性必须是公开,否则外部不可访问 162 | - 每个参数必须声明明确的类型,参数类型必须是简单类型、`Array`、数据接口类型之一 163 | - 如果成员是`Array`,必须指定泛型参数。泛型类型可以是简单类型、`Array`、数据接口类型,泛型类型参数如果本身不是泛型推荐使用简写形式(如:`names: string[]`) 164 | - **不支持可选参数、不支持参数默认值,也不支持展开参数(`...args: string[]`)** 165 | - 返回值类型同参数类型要求相同,**必须明确声明返回值类型,否则返回值无法从外部获取** 166 | - 可以访问`this.context`和`this.transfer`(如合约账户余额不足,则会失败) 167 | 168 | ##### 2.3.5.5 资产接收方法 169 | 170 | 一个合约可以多个资产接收方法,资产接收方法是使用`payable`注解的公开方法,用于接收调用转入智能合约的资产,要求如下: 171 | 172 | - 可见性必须是公开 173 | - 必须有两个参数分别为金额与资产名称,一般采用 amount 和 currency 命名 174 | - amount 类型为`bigint` 175 | - currency 类型必须为`string` 176 | - 可以不声明返回类型,如果声明了返回类型必须`void` 177 | - 可以访问`this.context`和`this.transfer`(如合约账户余额不足,则会失败) 178 | - `payable`有一个可选参数,类型为`{ isDefault?: boolean }`,用于表示是否是默认的资产接受方法(使用`@payable({ isDefault: true })`注解)。**一个合约中最多只能有一个默认资产接受方法** 179 | 180 | ##### 2.3.5.6 查询方法 181 | 182 | 一个合约可以有多个查询方法,资产接收方法是使用`constant`注解的公开方法,用于实现状态查询等只读状态的计算逻辑,具体要求: 183 | 184 | - 可见性必须是公开 185 | - 必须有返回类型,且必须是简单类型、`Array`、数据接口类型之一 186 | - **不可访问`this.context`和`this.transfer`,否则会失败** 187 | - **只能只读访问状态成员,不能修改状态。否则会失败** 188 | 189 | ##### 2.3.5.7 内部方法 190 | 191 | 一个合约可以有多个内部方法,可见性为保护(`protected`)或私有(`private`,**推荐**),具体要求: 192 | 193 | - 可见性必须是保护或私有 194 | - 不可使用`constant`、`payable`注解 195 | 196 | #### 2.3.6 智能合约其他语法约定 197 | 198 | 智能合约语言是Typescript语言的子集,除上节描述的结构约定外,其他主要限制如下: 199 | 200 | - 不可以使用引入第三方库 201 | - 不支持`Symbol` 202 | - 不使用`null`、`any`、`never`、`object`、`unknown` 等类型,`undefined`可以使用 203 | - 不使用交叉类型(如`string & number`)和联合类型(如`string | null`) 204 | - 不支持生成器和异步语法(不使用`Promise`、`async/await`) 205 | - 不使用强制类型转换(不使用`name`及`name as string`) 206 | - 一个合约文件只能有一个合约类,这个类必须从`AschContract`继承而来 207 | - 不可以定义全局函数、静态函数 208 | - 智能合约中只能使用合约引擎提供的内置类型、方法和对象,未提供的原Node.js内置的对象、函数或类型是不可用的(如`Function`、`Date`都是不可用的) 209 | - 私有或保护方法的参数和返回值的定义比较灵活,但请谨慎使用。尽可能避免不确定性 210 | - 合约中不允许使用`try...catch`语法,也不允许使用`throw`语句。任何时候抛出异常(如使用`assert`语句)即导致中止合约 211 | - 可调用方法和查询方法参数和返回值的额外要求 212 | - 由于合约调用时所有参数会被序列化为`JSON`传递,故只支持可序化的类型(可参考数据接口类的定义)基于效率考虑,全部参数或返回值序列化后的`JSON`字符串长度应控制在`32K`以内(`length <= 32,767`) 213 | - 查询方法必须声明返回类型,对于可调用方法,如果未声明返回值类型,返回值将被丢弃(不作为调用结果返回) 214 | - 状态类型和数据接口类嵌套深度不超过**3** 215 | 由于状态容器类型的值可以是状态容器类型或合约状态类型,而状态类型中也可以有状态类型或状态容器(数据接口类似)。基于代码可读性以及状态管理的性能考虑。嵌套的深度不应超过3,如`Mapping`深度称为 1,`Vector>`深度为2;简单自定义类型本身深度为1,包含一个深度为1的容器类型或自定义状态类型深度为2;以此类推 216 | - 注意,**与以太坊的solidity不同**的是,在solidity中,给存储状态赋值会导致自动的复制。而在ASCH智能合约中,状态容器或自定义状态中使用的是对象的引用。这样的好处是性能更好、编程更灵活、更符合主流语言的习惯,但也会带来一个问题:当两个状态容器中保存相同的对象引用时,可能会导致误操作。合约引擎会自动检查这种情况的存在,当尝试把一个已经属于合约状态一部分的对象赋值给合约状态时,会抛出异常。 -------------------------------------------------------------------------------- /contract/contract-in-action/3 测试智能合约.md: -------------------------------------------------------------------------------- 1 | 这一小节将会讲解如何编写智能合约测试。我们知道,ASCH 智能合约其实就是一个 Class,那么就很容易编写测试了。创建 \_\_tests\_\_/CCTime.test.ts 文件,添加如下示例代码: 2 | 3 | ```typescript 4 | import '../mock' 5 | import CCTimeContract from '../contract/CCTime' 6 | 7 | describe('CCTimeContract', () => { 8 | it('new CCTimeContract()', () => { 9 | const ccTimeContract = new CCTimeContract() 10 | 11 | expect(ccTimeContract.genesisAddress).toBe('GENESIS_ADDRESS') 12 | }) 13 | }) 14 | ``` 15 | 16 | 运行 `npm test` 进行测试。 17 | 18 | 其中,引入 mock.js 注入 ASCH 智能合约运行时所需的全局变量。 -------------------------------------------------------------------------------- /contract/contract-in-action/4.1 部署合约.md: -------------------------------------------------------------------------------- 1 | #### 4.1.1 发布合约 2 | 3 | 发布合约有两种方式: 4 | 5 | 1. 命令行方式 6 | 2. 阿希 web 客户端方式 7 | 8 | 下面分别介绍如何使用。 9 | 10 | **命令行部署智能合约** 11 | 12 | 运行以下命令: 13 | 14 | ```bash 15 | curl -X PUT {serverAddress}/api/transactions \ 16 | -H 'Content-Type: application/json' \ 17 | -d '{ 18 | "secret":"stone elephant caught wrong spend traffic success fetch inside blush virtual element", 19 | "fee": 0, 20 | "type": 600, 21 | "args": ["50000","CCTimeContract","v1.0","测试代码","export default class CCTimeContract extends AschContract { ... }",false] 22 | }' 23 | ``` 24 | 25 | 1. type: 600 26 | 2. args: [gasLimit, name, version, description, code, consumeOwnerEnergy] 27 | 1. gasLimit:最大消耗的 gas,要求 10000000 >= gasLimit >= 100 28 | 2. name:智能合约名称,全网唯一,4 ~ 32 个字符组成,字母开头,可包含字母、数字或下划线组成 29 | 3. version:合约引擎版本,目前请填 v1.0 30 | 4. description:智能合约的描述,长度不超过 255 的字符串 31 | 5. code:智能合约代码,长度不超过 32K 32 | 6. consumeOwnerEnergy:是否优先消耗合约所有者的能量 33 | 34 | **阿希 web 客户端部署智能合约** 35 | 36 | 进入阿希 web 客户端,操作流程如下: 37 | 38 | 1. 点击左侧菜单的 "智能合约",进入 "合约列表" 页 39 | 2. 点击 "我发布的" 切换至已发布的智能合约列表,点击右上角的 "提交新合约" 40 | 3. 填写合约完整信息 41 | 1. 合约名字。合约名称长度范围 4~32,以字母开头,支持字母,数字,减号,下划线 42 | 2. 合约代码。合约代码长度不能超过 20 KB 43 | 3. 合约描述。合约描述长度不超过 255 44 | 4. Gas_Limit。提供的燃料费/能量 45 | 1. 建议值:前端计算用户写入的合约代码量,按每字符 2 能量,额外加收 1000 能量注册费,再增加 500 能量 46 | 2. gas_limit 必须 <= 1000000 能量,每个合约执行的时间 <=500ms 47 | 5. 开发者代付能量 (手续费) 48 | 1. 开发者可以设定用户调用合约时,是否优先由开发者代付调用合约能量(手续费) 49 | 2. 开发者账户能量不足的时候,才由调用合约的用户自己承担手续费 50 | 51 | #### 4.1.2 查看合约 52 | 53 | 左侧导航栏 -> 智能合约 -> 合约列表/我发布的合约 -> 点击合约名称 54 | 55 | #### 4.1.3 搜索合约 56 | 57 | 左侧导航栏 -> 右上角搜索合约(模糊搜索) -------------------------------------------------------------------------------- /contract/contract-in-action/4.2 调用合约.md: -------------------------------------------------------------------------------- 1 | #### 4.2.1 转账到合约 2 | 3 | 使用以下方法往合约地址转账: 4 | 5 | ```bash 6 | curl -X PUT {serverAddress}/api/transactions \ 7 | -H 'Content-Type: application/json' \ 8 | -d '{ 9 | "secret":"stone elephant caught wrong spend traffic success fetch inside blush virtual element", 10 | "fee": 0, 11 | "type": 602, 12 | "args": [5000,true,"CCTimeContract",1000000000,"XCT"] 13 | }' 14 | ``` 15 | 16 | 1. type: 602 17 | 2. args: [gasLimit, enablePayGasInXAS, receiverPath, amount, currency] 18 | 1. gasLimit:最大消耗的 gas,要求 10000000 >= gasLimit >= 100 19 | 2. enablePayGasInXAS:当调用者能量不足时,是否使用 XAS 支付 gas 20 | 3. receiverPath:接收转账的路径(由合约地址或名称、'/'、接收方法名称组成,如接收方法是默认接收方法则 '/' 和接收方法可以省略) 21 | 4. amount:转账金额 22 | 5. currency:转账资产名称 23 | 24 | #### 4.2.2 调用合约方法 25 | 26 | 使用以下方法调用合约方法: 27 | 28 | ```bash 29 | curl -X PUT {serverAddress}/api/transactions \ 30 | -H 'Content-Type: application/json' \ 31 | -d '{ 32 | "secret":"stone elephant caught wrong spend traffic success fetch inside blush virtual element", 33 | "fee": 0, 34 | "type": 601, 35 | "args": [6000,true,"CCTimeContract","createOrUpdateAccount",["usernamexxx","bioxxx"]] 36 | }' 37 | ``` 38 | 39 | 1. type:601 40 | 2. args: [gasLimit, enablePayGasInXAS, contractName, method, methodArgs] 41 | 1. gasLimit:最大消耗的 gas,要求 10000000 >= gasLimit >= 100 42 | 2. enablePayGasInXAS:当调用者能量不足时,是否使用 XAS 支付 gas 43 | 3. contractName:智能合约名称 44 | 4. method:合约方法名称 45 | 5. methodArgs:合约方法所需要的参数列表 -------------------------------------------------------------------------------- /contract/contract-in-action/4.3 查询合约状态.md: -------------------------------------------------------------------------------- 1 | #### 4.3.1 简单状态查询 2 | 3 | 智能合约中 public 状态的属性可以通过 HTTP GET 方式进行查询,查询方式为: 4 | 5 | ```bash 6 | curl {serverAddress}/api/v2/contracts/{contractName}/states/{statePath} 7 | ``` 8 | 9 | 注意,本接口仅能查询基本类型的数据,复杂类型请通过状态查询函数来查询。 10 | 11 | - serverAddress:服务地址 12 | - contractName:合约名称 13 | - statePath:由 '.' 分隔的状态路径。如: `holding.0`将会查询`contract.holding[0]` 14 | - 返回值:如果路径指向的是简单状态值,则返回值本身;如果是 Mapping 或 Vector,返回其包含的元素条数;如果是自定义类型,返回成员数量 15 | 16 | 例如,查询某地址参与众筹的信息可以访问如下地址: 17 | 18 | ```bash 19 | curl {serverAddress}/api/v2/contracts/CrowdFunding/fundingOf.{Address} 20 | ``` 21 | 22 | #### 4.3.2 状态查询函数查询 23 | 24 | 智能合约中通过 `@constant` 注解修饰的方法为状态查询函数,状态查函数的返回值应是基本类型、简单自定义类型、基本类型及简单自定义类型构成的数组。且序列化为 `JSON` 后的字符串长度小于32K。状态查询函数通过 HTTP POST 方式查询,查询方式为: 25 | 26 | ```bash 27 | curl -X POST \ 28 | {serverAddress}/api/v2/contracts/{contractName}/constant/{methodName} 29 | -H 'Content-Type: application/json' \ 30 | -d '["arg1", 2, true]' 31 | ``` 32 | 33 | - serverAddress:服务地址 34 | - contractName:合约名称 35 | - methodName:查询函数名称 36 | - body:查询函数参数数组转换为的 `JSON` 字符串,如:`'["arg1", 2, true]'`表示三个参数 `"arg1"`、`2`和`true` 37 | - 返回值:如调用成功,返回查询函数的结果 -------------------------------------------------------------------------------- /contract/contract-in-action/5.2 附录二:调试智能合约.md: -------------------------------------------------------------------------------- 1 | 我们推荐使用 VS Code 开发 ASCH 智能合约,原因有三: 2 | 3 | 1. 配合 TSLint 插件,TypeScript 开发体验极佳 4 | 2. 众多的插件 5 | 3. 断点调试方便 6 | 7 | 下面列举三种调试方法。 8 | 9 | **方法一** 10 | 11 | 1. 编写 test.ts,引入 mock.ts 和 SimpleContract.ts 12 | 13 | 2. 设置 .vscode/launch.json 14 | 15 | ``` 16 | { 17 | "version": "0.2.0", 18 | "configurations": [ 19 | { 20 | "type": "node", 21 | "request": "launch", 22 | "name": "Test Contract", 23 | "args": [ 24 | "-r", 25 | "${workspaceFolder}/node_modules/ts-node/register", 26 | "${workspaceFolder}/test.ts" 27 | ] 28 | } 29 | ] 30 | } 31 | ``` 32 | 33 | 3. 在 SimpleContract.ts 添加断点 34 | 35 | 4. 启动调试 36 | 37 | **方法二** 38 | 39 | 1. 引入 ts-jest 40 | 41 | 1. `npm i ts-jest --save` 42 | 43 | 2. 配置 jest 的 transform 为 ts-jest 44 | 45 | 1. ```json 46 | "jest": { 47 | "transform": { 48 | "^.+\\.ts$": "ts-jest" 49 | }, 50 | "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.ts$", 51 | "moduleFileExtensions": [ 52 | "ts", 53 | "tsx", 54 | "js", 55 | "jsx", 56 | "json", 57 | "node" 58 | ] 59 | } 60 | ``` 61 | 62 | 3. 在 \_\_tests\_\_ 目录下编写 xxx.test.ts 测试文件 63 | 64 | **方法三** 65 | 66 | 基于方法二。 67 | 68 | 1. VS Code 安装 [Jest Runner](https://marketplace.visualstudio.com/items?itemName=firsttris.vscode-jest-runner) 插件 69 | 2. 在 \_\_tests\_\_/xxx.test.ts 某个 it 测试里添加断点,右键选择「Debug Jest」调试单个 it -------------------------------------------------------------------------------- /contract/contract-in-action/README.md: -------------------------------------------------------------------------------- 1 | 1. [智能合约概述](./1.%20智能合约概述.md) 2 | 1. 设计目标 3 | 2. 技术选型 4 | 1. 智能合约平台对比 5 | 2. 基于 Typescript 子集的智能合约语言 6 | 3. 为什么是 Typescript 而不是 JavaScript? 7 | 4. 与以太坊智能合约对比 8 | 3. 技术实现 9 | 2. 编写智能合约 10 | 1. [Hello, World](./2.1%20Hello,%20World.md) 11 | 2. [语法规范(上)——ECMAScript篇](./2.2%20语法规范(上)——ECMAScript篇.md) 12 | 1. 智能合约内可以使用的 13 | 2. 智能合约内不能使用的 14 | 3. Node.js 版本要求 15 | 3. [语法规范(下)——TypeScript篇](./2.3%20语法规范(下)——TypeScript篇.md) 16 | 1. TypeScript 基本规范 17 | 2. 常量声明 18 | 3. 数据接口类型声明 19 | 4. 自定义状态类型声明 20 | 5. 合约类定义 21 | 6. 智能合约其他语法约定 22 | 4. [实战:CCTime](./2.4%20实战:CCTime.md) 23 | 1. 功能设计与激励机制 24 | 2. 本地环境搭建 25 | 3. 搭建基本框架 26 | 4. 实现充值与提现 27 | 5. 实现账号功能 28 | 6. 实现文章功能 29 | 7. 实现留言功能 30 | 8. 验证合约代码与估算 gas 31 | 9. 总结 32 | 3. [测试智能合约](./3%20测试智能合约.md) 33 | 4. 部署智能合约 34 | 1. [部署合约](./4.1%20部署合约.md) 35 | 1. 发布合约 36 | 2. 查看合约 37 | 3. 搜索合约 38 | 2. [调用合约](./4.2%20调用合约.md) 39 | 1. 转账到合约 40 | 2. 调用合约方法 41 | 3. [查询合约状态](./4.3%20查询合约状态.md) 42 | 5. 附录 43 | 1. [附录一:燃料计费表和智能合约内置函数](./5.1%20附录一:燃料计费表和智能合约内置函数.md) 44 | 2. [附录二:调试智能合约](./5.2%20附录二:调试智能合约.md) -------------------------------------------------------------------------------- /contract/contract-in-action/img/1.2.1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/contract/contract-in-action/img/1.2.1.jpg -------------------------------------------------------------------------------- /contract/hello-contract/zh-cn.md: -------------------------------------------------------------------------------- 1 | 2 | # 5分钟开发ASCH智能合约 3 | 4 | 阿希智能合约平台是基于ASCH链的轻量级DApp解决方案,使用Typescript作为智能合约语言,以Node.js为运行环境的全新智能合约平台。平台以安全、高效、易用、低成本为目标,帮助传统开发人员快速掌握区块链DApp开发。 5 | 6 | ## 1. 开发环境搭建 7 | 8 | 阿希智能合约平台要求的Node.js版本不低于v10.14,推荐安装最新LTS版本(MacOS和Ubuntu环境推荐使用v10.15.1,Windows环境请使用v10.14.1) 9 | 10 | ### 1.1. 智能合约开发工具安装 11 | 12 | 智能合约平台开发使用[vscode](https://code.visualstudio.com/)作为开发环境,请提前安装好 Node.js 和vscode。 13 | 14 | `create-asch-contract`是一个交互式一键生成智能合约vscode项目模板的工具,请在准备好的智能合约开发目录中运行下述命令安装。(注:部分网络服务商在安装npm包时可能会有较大延时甚至失败的可能,请耐心重试) 15 | 16 | ```sh 17 | npm i create-asch-contract -g 18 | create-asch-contract init my-asch-contract 19 | cd [my-asch-contract] && npm test 20 | ``` 21 | 22 | ### 1.2. 本地全节点安装 23 | 24 | 开发者可以安装本地合约运行环境[请参见节点安装](../../install/zh-cn.md),对智能合约进行本地测试。由于目前testnet属于测试阶段,请通过源码方式安装本地测试节点,并手动安装npm包。 25 | 26 | ```sh 27 | git clone https://github.com/AschPlatform/asch 28 | 29 | cd asch 30 | git checkout develop 31 | git pull 32 | 33 | npm install 34 | 35 | #手动创建相关目录 36 | mkdir chains 37 | mkdir -p data/contracts 38 | mkdir -p public/dist 39 | ``` 40 | 41 | 详细开发环境搭建请见[智能合约开发环境安装](../install/zh-cn.md) 42 | 43 | ## 2. 编写智能合约 44 | 45 | 如前所述,智能合约使用的是Typescript作为合约开发语言。它是Javascript基础上增加了静态类型的超级,与主流语言特性接近。大部分开发人员可以很快掌握[语法参见智能合约开发入门](../introduction/zh-cn.md)。我们下面看一个最简单的智能合约: 46 | 47 | ```typescript 48 | const CURRENCY = 'XAS' 49 | 50 | class Payment { 51 | address: string 52 | amount: bigint 53 | 54 | constructor(address: string, amount: bigint) { 55 | this.address = address 56 | this.amount = amount 57 | } 58 | } 59 | 60 | export class HelloContract extends AschContract { 61 | private total: bigint 62 | private payments: Vector 63 | 64 | constructor() { 65 | super() 66 | this.total = BigInt(0) 67 | this.payments = new Vector() 68 | } 69 | 70 | @payable({ isDefault: true }) 71 | onPay(amount: bigint, currency: string) { 72 | assert(amount > 0, `Amount should greater than 0`) 73 | assert(currency === CURRENCY, `Please pay ${CURRENCY}`) 74 | 75 | this.total += amount 76 | const payment = new Payment(this.context.senderAddress, amount) 77 | this.payments.push(payment) 78 | } 79 | 80 | @constant 81 | getPayTimes(): number { 82 | return this.payments.size() 83 | } 84 | 85 | @constant 86 | getTotal(): bigint { 87 | return this.total 88 | } 89 | } 90 | ``` 91 | 92 | 上述合约非常简单,先定义了一个合约状态的类型`Payment`,用于保存合约的状态。 93 | 然后实现了一个合约类`HelloContract`,包括: 94 | 95 | - `total`和`payments`两个状态,分别存储总余额和转账历史 96 | - `onPay`方法,通过`@payable`注解进行修饰,表示当合约默认接收转账的处理方法。该方法只是简单记录下转账的地址和金额,同时更新合约账户总余额 97 | - `@constant`注解修饰的两个方法,用于查询合约内部状态。 98 | 99 | ## 3. 对合约进行调试与测试 100 | 101 | ### 3.1. 合约代码模拟调试 102 | 103 | #### 3.1.1. 通过jest-runner插件进行调试 104 | 105 | 1. 安装 [Jest Runner](https://marketplace.visualstudio.com/items?itemName=firsttris.vscode-jest-runner) 106 | 2. 在 __tests__/SimpleContract.test.ts 某个 it 测试里添加断点,右键选择「Debug Jest」 107 | 108 | #### 3.1.2. 设置vscode的调试配置 109 | 110 | 1. 自己编写 test.ts,引入 mock.ts 和 SimpleContract.ts 111 | 2. 设置 .vscode/launch.json 如下: 112 | 113 | ```json 114 | { 115 | "version": "0.2.0", 116 | "configurations": [ 117 | { 118 | "type": "node", 119 | "request": "launch", 120 | "name": "Test Contract", 121 | "args": [ 122 | "-r", 123 | "${workspaceFolder}/node_modules/ts-node/register", 124 | "${workspaceFolder}/test.ts" 125 | ] 126 | } 127 | ] 128 | } 129 | ``` 130 | 131 | 3. 在 SimpleContract.ts 添加断点 132 | 4. 启动调试 133 | 134 | ### 3.2. 合约测试 135 | 136 | ### 3.2.1. 合约模拟单元测试 137 | 138 | 请参考模板项目中的示例测试代码编写单元测试用例,通过测试工具进行单元测试。 139 | 140 | ### 3.2.2. 在本地节点上进行测试 141 | 142 | 由于模拟测试是在普通的Node.js环境中,通过moke的方法对合约逻辑进行测试。不是在合约的VM中运行,不能代表实际的合约运行情况,故需要将合约部署到本地节点上进行测试(部署方法见第4节)。 143 | 144 | 可以通过[智能合约查询接口](../../http-api/zh-cn.md#212-智能合约)、[智能合约交易接口](../../http-api/zh-cn.md#37-智能合约)或[asch-web](../../asch-web/zh-cn.md)提供的方法实现合约注册、向合约转账、调用合约方法以及访问合约中的状态,测试合约在区块链上的运行效果。 145 | 146 | ## 4. 在区块链上部署智能合约 147 | 148 | 目前可以通过下面几种方法部署智能合约: 149 | 150 | - 使用ASCH平台的Web客户端界面操作注册合约 151 | 152 | 使用ASCH自带的客户端环境,或使用测试网的网页客户端,找到`智能合约->我发布的合约`,单击`提交新合约`。填写智能合约名称、智能合约代码、合约描述、gasLimit以及是否优先消耗合约创建者的能量等参数,单击`提交合约`进行提交。 153 | 154 | 如果提交失败系统会提示错误信息,提交成功后,稍后会在`我发布的合约`中看到刚提交的合约。 155 | 156 | - 使用HTTP接口注册合约 157 | 158 | 通过[智能合约交易接口](../../http-api/zh-cn.md#371-注册智能合约)提交交易的方式来注册合约 159 | 160 | ## 5. 访问智能合约 161 | 162 | 可以通过接口 163 | 164 | ### 5.1. 状态查询 165 | 166 | - 简单合约状态查询 167 | 168 | 简单类型的公开合约状态可直接通过HTTP接口进行查询。请参见[查询智能合约公开状态](../../http-api/zh-cn.md#2125-查询智能合约公开状态) 169 | 170 | - 通过查询方法查询 171 | 172 | 查询方法指用`@constant`注解修饰的方法,对合约的状态只可以只读访问。但可以实现一些查询的逻辑。查询方法可以通过HTTP接口进行访问。请参见[调用查询方法](../../http-api/zh-cn.md#2127-调用查询方法) 173 | 174 | ### 5.2. 调用合约方法 175 | 176 | 合约类中的除`constructor`外的所有没有注解修饰的公开方法都是外部可调用方法,通过ASCH链类型为`601`的交易实现调用。请参见[调用智能合约](../../http-api/zh-cn.md#372-调用智能合约) 177 | 178 | ### 5.1. 向合约转账 179 | 180 | 合约类中使用`@payable`修饰的方法为接收资产转账的方法,资产接收方法通过ASCH链类型为`602`的交易实现调用。请参见[向合约转账](../../http-api/zh-cn.md#373-向智能合约转账) 181 | 182 | ## 6. 进一步阅读 183 | 184 | 诚然,实际的智能合约开发内容比本文档中描述的复杂。智能合约开发过程中也有一些注意事项与语法约定。更多文档请参考: 185 | 186 | - [ASCH智能合约开发概述](../introduction/zh-cn.md) 187 | - [ASCH智能合约开发实战](../contract-in-action/README.md) 188 | - [Gas与内置函数](../contract-in-action/5.1%20附录一:燃料计费表和智能合约内置函数.md) 189 | - [asch-web使用指南](../../asch-web/zh-cn.md) -------------------------------------------------------------------------------- /contract/install/zh-cn.md: -------------------------------------------------------------------------------- 1 | # 智能合约开发环境安装 2 | 3 | ASCH智能合约支持在MacOS、Ubuntu、和Windows三种平台下进行开发。基本安装步骤如下: 4 | 5 | - 安装基础依赖环境 6 | - 安装VSCode及相关插件 7 | - 安装ASCH智能合约开发工具 8 | - 安装本地节点(可选) 9 | 10 | 由于ASCH智能合约开发环境基于Node.js及VSCode为搭建,除了基础依赖环境与系统平台相关外其余部分在不同平台上类似。故基础依赖环境分系统介绍,其余部分统一介绍。 11 | 12 | ## 1. 安装基础依赖环境 13 | 14 | 基础依赖环境主要包括:包管理工具(MacOS和Ubuntu)、Node版本管理工具(nvm)、Node.js 及 npm、node-gyp 以及C++编译所依赖的工具,下面分平台进行介绍。 15 | 16 | ### 1.1. Windows环境 17 | 18 | 支持Windows 8.1以上版本的Windows操作系统。以下操作在 Win10 x64 简体中文专业版 (版本 1809 17763.194)上验证通过 19 | 20 | - **安装 nvm-windows** 21 | 22 | 目前最新版为v1.1.7[下载地址](https://github.com/coreybutler/nvm-windows/releases/download/1.1.7/nvm-setup.zip) 23 | 24 | [安装参考](https://blog.csdn.net/sinat_38334334/article/details/80013648) 25 | **注意使用管理员权限安装,否则安装node后可能无法在命令行中直接运行** 26 | 27 | - **安装 node v10.14.1** 28 | 29 | 以管理员权限在命令行中运行下面的命令 30 | 31 | ```sh 32 | #安装 33 | nvm install 10.14.1 34 | 35 | #使用10.14.1版本 36 | nvm use 10.14.1 37 | 38 | #验证安装是否成功 39 | node -v 40 | 41 | #应该输出 42 | v10.14.1 43 | 44 | ``` 45 | 46 | **在Windows环境中如使用10.15.x版,可能会导致ASCH合约开发工具安装失败** 47 | 48 | - **安装 node-gyp 及 C++编译工具** 49 | 50 | 以管理员权限运行下面的命令 51 | 52 | ```sh 53 | #安装 node-gyp 54 | npm i -g node-gyp 55 | 56 | #如果安装过程非常慢,请尝试 57 | npm i -g node-gyp --registry=https://registry.npm.taobao.org 58 | 59 | #安装 C++编译工具 60 | npm install --global --production windows-build-tools --vs2015 61 | ``` 62 | 63 | **注意,C++编译工具安装比较费时,视网络情况不同约需要2-4小时** 64 | 65 | - **配置 node-gyp 编译参数** 66 | 67 | ```sh 68 | #使用 vs2015版的Visual Studio项目文件格式 69 | npm config set msvs_version 2015 70 | ``` 71 | 72 | ### 1.2. MacOS环境 73 | 74 | 以下操作在MacOS 10.14.4上验证通过 75 | 76 | - **安装 Homebrew** 77 | 78 | Homebrew 是 macOS 平台的软件包管理器,相当于 Linux 常用的 apt-get。首先请确保已经安装XCode,如未安装,直接在AppStore中安装即可。 79 | 80 | ```sh 81 | # 安装 82 | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 83 | 84 | #验证 85 | brew -v 86 | 87 | #安装成功则显示版本信息,例如: 88 | Homebrew 1.9.1 89 | Homebrew/homebrew-core (git revision 46a29; last commit 2019-04-12) 90 | Homebrew/homebrew-cask (git revision 5ed4f; last commit 2019-04-12) 91 | 92 | ``` 93 | 94 | - **安装 nvm 和 Node.js v10.15.1** 95 | 96 | ```sh 97 | #安装nvm 98 | brew insall nvm 99 | 100 | #安装Node.js v10.15.1 101 | nvm install v10.15.1 102 | 103 | #切换默认版本 104 | nvm use 10.15.1 105 | 106 | #验证 107 | node -v 108 | 109 | #成功则输出 110 | v10.15.1 111 | 112 | ``` 113 | 114 | - **安装 node-gyp 及 C++编译工具** 115 | 116 | ```sh 117 | #安装相关编译工具 118 | brew install libtool autoconf automake 119 | 120 | #安装 node-gyp 121 | npm i -g node-gyp 122 | 123 | #如果安装过程非常慢,请尝试 124 | npm i -g node-gyp --registry=https://registry.npm.taobao.org 125 | ``` 126 | 127 | ### 1.3. Ubuntu环境 128 | 129 | 支持Ubuntu14.04以上版本,以下安装在Ubuntu 16.04上验证通过 130 | 131 | - **安装系统工具库** 132 | 133 | ```sh 134 | 135 | #安装系统依赖包 136 | sudo apt-get install curl ntp wget git libssl-dev openssl make gcc g++ autoconf automake python build-essential -y 137 | 138 | #Ubuntu 14.04请运行 139 | sudo apt-get install libtool -y 140 | 141 | # Ubuntu 16.04请运行 142 | sudo apt-get install libtool libtool-bin -y 143 | ``` 144 | 145 | - **安装nvm 和 Node.js v10.15.1** 146 | 147 | ```sh 148 | #安装 nvm 149 | curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash 150 | 151 | #安装Node.js v10.15.1 152 | nvm install v10.15.1 153 | 154 | #验证 155 | node --v 156 | 157 | #应该输出 158 | v10.15.1 159 | 160 | ``` 161 | 162 | - **安装 node-gyp** 163 | 164 | ```sh 165 | #安装 node-gyp 166 | npm i -g node-gyp 167 | 168 | #如果安装过程非常慢,请尝试 169 | npm i -g node-gyp --registry=https://registry.npm.taobao.org 170 | ``` 171 | 172 | ## 2. 安装VSCode及相关插件 173 | 174 | 请访问 [VSCode官网](https://code.visualstudio.com/),安装最新版VSCode。 175 | 176 | 推荐安装 `tslint`、`typescript`、`jest`等常用插件 177 | 178 | ## 3. 安装ASCH智能合约开发工具 179 | 180 | **在Windows环境中请使用管理员权限的命令行工具** 181 | 182 | ```sh 183 | #安装合约开发模板生成工具, 184 | npm i create-asch-contract -g 185 | 186 | #如果安装过程非常慢,请尝试 187 | npm i create-asch-contract -g --registry=https://registry.npm.taobao.org 188 | ``` 189 | 190 | ## 4. 安装本地节点(可选) 191 | 192 | 请参考[节点安装](../../install/zh-cn.md)中的相关内容 -------------------------------------------------------------------------------- /create_account/en.md: -------------------------------------------------------------------------------- 1 | # Create a new account by using the front-end 2 | 3 | 4 | ### Preparation 5 | Make sure to have the ASCH blockchain installed ([Install ASCH blockchain](https://medium.com/aschplatform/develop-blockchain-apps-with-sidechain-technology-part-1-c5aa91c4602f)). 6 | 7 | Also, make sure to have the ASCH GUI downloaded ([Download ASCH GUI](https://github.com/AschPlatform/asch-docs/blob/master/install/en.md#56-configure-frontend)). 8 | 9 | 10 | ### New Account 11 | Now start the ASCH blockchain by executing (`cd asch && node app.js`) in your terminal. Now point your browser to `http://localhost:4096/#/login` and press the "New account" button. 12 | 13 | ![Step 1/2 Create Master Secret](./images/nextstep.png) 14 | 15 | In this example, the secret is `sentence weasel match weather apple onion release keen lens deal fruit matrix` (write it safely down somewhere). Now press the __CREATE MASTER SECRET__ button to confirm the secret. 16 | 17 | 18 | Login with your new secret: 19 | ![Login](./images/login.png) 20 | 21 | You will find your new account with an empty balance and your address `AHMCKebuL2nRYDgszf9J2KjVZzAw95WUyB`: 22 | 23 | ![Empty balance](./images/emptybalance.png) 24 | 25 | 26 |

27 | 28 | ### Send yourself some XAS 29 | 30 | First, logout from your current session. The logout button is in the upper right corner: 31 | 32 | ![Logout](./images/logout.png) 33 | 34 | Use the genesis account to send our new user some XAS. The genesis account is the account where all the money of the ASCH blockchain is initally located. This account has hundred millions of XAS (our standard currency). 35 | 36 | 37 | **Genesis Account** 38 | ``` 39 | address: ABuH9VHV3cFi9UKzcHXGMPGnSC4QqT2cZ5 40 | secret: stone elephant caught wrong spend traffic success fetch inside blush virtual element 41 | publicKey: 116025d5664ce153b02c69349798ab66144edd2a395e822b13587780ac9c9c09 42 | ``` 43 | 44 | Point your browser to `http://localhost:4096/#/login` again. Login with the __secret__ of the genesis account now. Then Click the "Transfer" tab on the left side of your screen. Now send 1000 XAS to `AHMCKebuL2nRYDgszf9J2KjVZzAw95WUyB`. 45 | 46 | ![Pay](./images/pay.png) 47 | 48 | Login with your new account now. You'll see that your balance is now 1000 XAS. 49 | 50 | # Create a new acount with asch-cli 51 | Alternatively you can also use [asch-cli](https://github.com/AschPlatform/asch-cli) to [create a new account](https://github.com/AschPlatform/asch-docs/blob/master/dapp/hello_world/en.md#6-prepare-account-for-dapp-registration). 52 | 53 | -------------------------------------------------------------------------------- /create_account/images/address.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/create_account/images/address.png -------------------------------------------------------------------------------- /create_account/images/emptybalance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/create_account/images/emptybalance.png -------------------------------------------------------------------------------- /create_account/images/login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/create_account/images/login.png -------------------------------------------------------------------------------- /create_account/images/logout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/create_account/images/logout.png -------------------------------------------------------------------------------- /create_account/images/nextstep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/create_account/images/nextstep.png -------------------------------------------------------------------------------- /create_account/images/pay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/create_account/images/pay.png -------------------------------------------------------------------------------- /delegate-forging/en.md: -------------------------------------------------------------------------------- 1 | title: Delegators and forging of Asch 2 | --- 3 | 4 | Each account in Asch system can be registered as a delegator (100XAS is payable). 5 | 6 | A delegator can accept any votes from coin holders. When the rate of vote reaches into top 101, 7 | the delegators can obtain the right to account(that is, the right of block production, which is 8 | equivalent to miners in Bitcoin. ) and get certain reward. The process of block production is 9 | called forging. 10 | 11 | Forging does not need strong computing power like Bitcoin mining. Even the ordinary computer 12 | can be carried out to verify the algorithm of accounting right, which combines time slice 13 | verification, delegators random ranking, delegators signatures and pbft algorithm. More 14 | details refer to Asch consensus agreement. The delegators of top 101 are in turn to produce 15 | blocks in chronological order with a block interval of 10 seconds.When delegators in turn can 16 | not produce blocks because of exceptions, it will be postponed to next 10 seconds and produce 17 | by the next delegator. 18 | 19 | Each 101 blocks as a cycle, forging order of the delegators will be random changed in each cycle. 20 | When the last block is produced, the benefit will be settled in this cycle and the ranking will 21 | also be refreshed. 22 | If delegators can not produce blocks because of the downtime, network errors and other reasons, 23 | they can not only get the benefits of the cycle, but also reduce productivity. Productivity is 24 | an indicator of the stability of a delegator, and lower productivity will affect the vote. 25 | 26 | The delegators of the normal block production divide the benefit equally, including block rewards 27 | and transaction fees. The rankings and the votes do not affect the amount of the benefit. The benefit 28 | rate of the top 101 delegators is the same. 29 | 30 | # 1 Block rewards 31 | 32 | Block rewards will decrease over time, and the specific time will be based on the height of a future block. 33 | The block rewards of Asch system start from the beginning of 464500 block. The initial reward is 3.5 coins. 34 | Every 3 million block decreases once and it lasts about 1 year. 35 | After 12464500 block, the reward is no longer decreasing and each year has slightly less than 1.5% inflation rate. 36 | 37 | The following are the various stages of the block reward 38 | 39 | |reward|initial height|end height| 40 | |-----|------|-------| 41 | |3.5|464500|3464500| 42 | |3|3464500|6464500| 43 | |2|6464500|9464500| 44 | |1|9464500|12464500| 45 | |0.5|12464500|---| 46 | 47 | # 2 transaction fee 48 | 49 | In addition to the block rewards, the delegators can obtain the system transaction fee, or the handling fee. 50 | The handling fee has the following kinds. 51 | 52 | 53 | |type|fee| 54 | |----|---| 55 | |transaction|0.1| 56 | |vote|0.1| 57 | |the second password|5| 58 | |registed delegator|100| 59 | |registed dapp|100| 60 | |dapp deposit|0.1| 61 | |dapp withdraw|0.1| 62 | |multiple signatures|(n+1)*0.5| 63 | |small file storage (not yet online)|(size / 200 + 1) * 0.1| 64 | -------------------------------------------------------------------------------- /delegate-forging/zh-cn.md: -------------------------------------------------------------------------------- 1 | # Asch 受托人与锻造 2 | 3 | Asch系统中每个账户都可以注册成为受托人(需要支付100XAS)。
4 | 成为受托人以后可以接受任意持币人的投票,当得票率排名进入前21时,可以获得记账权(即生产区块的权利,相当于比特币中的矿工),并获取一定的奖励。 5 | 生产区块的过程叫做锻造(forging)。
6 | 锻造不像比特币挖矿那样需要很强的算力,普通电脑即可进行,验证记账权的算法综合了时间片验证、受托人随机排名、受托人签名以及pbft算法等,具体可以参考[asch的共识协议](http://blog.asch.so/2016/08/11/asch-consensus-and-fault-tolerance/) 7 | 排名前21的受托人按照时间顺序轮流产生区块,区块间隔为10秒。当轮班受托人出现异常无法生产区块时,则延期到下一个10秒,由下一个受托人继续生产。
8 | 每21个区块为一个周期,每个周期的受托人锻造顺序随机变换,每个周期的最后一个区块产出的时候,会进行该周期的收益结算,同时刷新新的排名。
9 | 因为宕机、网络错误等原因无法生产区块的受托人无法获得该周期的收益,并且会降低生产率。生产率是衡量一个受托人稳定性的指标,生产率过低会影响得票率。
10 | 正常生产区块的受托人根据预定的规则分配收益,收益包括区块奖励和交易费,进入前21名的受托人的总收益为全部收益的40%,基中的20%归受托人平分,另20%根据其所得票数所占全部投票的比例进行分配。
11 | 12 | ## 区块奖励 13 | 14 | 区块奖励会随着时间递减,具体时间则以未来的某一区块高度为准。
15 | Asch系统的区块奖励从464500块开始,初始奖励3.5币,每300万块递减一次,大约为1年。
16 | 从12464500块以后,奖励不再递减,每年有略小于1.5%的通胀率。
17 | 下面是各个阶段的区块奖励 18 | 19 | |奖励|起始高度|结束高度| 20 | |-----|------|-------| 21 | |3.5|464500|3464500| 22 | |3|3464500|6464500| 23 | |2|6464500|9464500| 24 | |1|9464500|12464500| 25 | |0.5|12464500|---| 26 | 27 | ## 交易费 28 | 29 | 除了区块奖励,提交交易或调用合约时需支付Gas和交易费(或称手续费),当Gas或手续费使用XAS支付时,进入分配池分配。不使用XAS支付(使用带宽或能量支付)时,则无需进行分配。部分交易的手续费标准如下: 30 | 31 | |类型|费用XAS| 32 | |----|---| 33 | |普通转账|0.1| 34 | |投票|0.1| 35 | |二级密码|5| 36 | |注册受托人|100| 37 | |多重签名|(n+1)*0.5| 38 | |资产发行商注册|100| 39 | |资产注册|500| 40 | |资产发行|0.1| 41 | |资产转账|0.1| 42 | -------------------------------------------------------------------------------- /exchange/XAS_integration_in_exchange_CN.md: -------------------------------------------------------------------------------- 1 | # XAS与交易平台对接文档 2 | 3 | ## 1 Asch基本信息 4 | 5 | 代币名称:阿希币
6 | 英文标识:XAS
7 | 主网上线时间:2016-08-16
8 | 发行总量:1亿,目前总的供应量为1.11亿XAS(有一个动态变化的通胀率,发行时间越长,通胀率越低)
9 | 共识算法:DPoS + PBFT
10 | 交易模式:账户余额模式,非UTXO
11 | 官网:https://www.asch.io
12 | 在线钱包:https://mainnet.asch.io,基本功能可以在这里进行体验
13 | 区块链浏览器:https://explorer.asch.io/
14 | 地址格式:字母数字混合,base58格式且以大写字母A开头且长度不低于10,比如A7RD9YP37iUnYZ1SFnmAp6ySHUx3msC4r5
15 | 16 | Asch 不是 BTC 源码的山寨,而是用 Node.js 全新开发的,目前都是纯 HTTP API,所以对接的时候请勿用 BTC 模板的交易网站代码去生拉硬套,目前有 Java 和 Node.js 版本的 SDK,交易平台可以直接用,其它开发语言,需要自己封装 HTTP API。
17 | Asch 没有钱包的概念,每个密码对应一个账户地址,也就是说一个“钱包”中只包含一个地址(实质为脑钱包),与BTC、ETH等区别较大。
18 | Asch 的精度是小数点后8位,但后台处理的时候都是按照整数来处理,比如想转0.1XAS,后台实际处理的是0.1 * 100000000。
19 | Asch http接口文档-中文版:https://github.com/AschPlatform/asch-docs/blob/master/http_api/zh-cn.md
20 | Asch http接口文档-英文版:https://github.com/AschPlatform/asch-docs/blob/master/http_api/en.md
21 | 该文档包含大部分的Asch接口,比如查询余额、转账、交易详情等,调用api返回结果为 JSON 数据。
22 | 23 | ## 2 建议交易平台在局域网内搭建一个Asch全节点 24 | 25 | 节点安装文档: 26 | 27 | 中文:https://github.com/AschPlatform/asch-docs/blob/master/install/zh-cn.md
28 | 英文:https://github.com/AschPlatform/asch-docs/blob/master/install/en.md 29 | 30 | ## 3 用户充值XAS 31 | 32 | Asch1.4 版本开始支持转账备注,因此交易平台可以有下面两种充值方案。 33 | 34 | - `为每个用户生成一个充值地址` 35 | - `为所有用户生成同一个充值地址,根据转账备注判断具体是哪个用户进行了充值` 36 | 37 | ### 3.1 方案1-为每个用户生成一个充值地址 38 | 39 | 目前bit-z.com、chaoex.com、coinegg.com、coolcoin .com等早期上线XAS的交易平台都是采用这种方式。 40 | 41 | #### 3.1.1 为用户生成充值地址 42 | 43 | 用户UserA登陆交易平台,进入Asch币充值页面,平台通过调用下面的代码生成充值地址、写入数据库,并在页面上展示给用户。 44 | 通过下面的代码为UserA生成一个Asch充值地址:ALu3f2GaGrWzG4iczamDmGKr4YsbMFCdxB,该充值地址的密码是'latin december swing love square parade era fuel circle over hub spy',这里只是举例,数据非真实。 45 | 46 | ##### 3.1.1.1 调用 HTTP 接口生成地址 47 | 48 | ```bash 49 | > curl -k -X GET 'http://192.168.1.100:8192/api/accounts/new' 50 | // JSON返回示例如下 51 | { 52 | success: true, 53 | secret: "during crush zoo wealth horror left night upset spike iron divert lawn", // 密码 54 | publicKey: "261fa56f389c324fddbe8777dbc0ef3341ee7b75d1ffdc82192265633b90d503", // 公钥 55 | privateKey: "67c9523b7622704c4bcfe960cb32d7fa04d3eb94e30e7964d3c6a24a3647a0a3261fa56f389c324fddbe8777dbc0ef3341ee7b75d1ffdc82192265633b90d503", // 私钥 56 | address: "ANfXDQUZroMnrQ6vRGR7UXXtbPn3fhEVRJ" // 地址 57 | } 58 | ``` 59 | 60 | ##### 3.1.1.2 用asch-cli命令行工具批量生成地址 61 | 62 | ```bash 63 | // 如果用其他编程语言,觉得批量生成账户地址有困难还可以用asch-cli命令行工具批量生成钱包地址(含密码、地址、公钥),生成多个地址,加密存到数据库或者其它地方,然后程序直接用. 64 | // 安装asch-cli工具 65 | > npm install -g asch-cli 66 | // 批量生成钱包地址 67 | // 需要nodejs版本为8.x,node --version查看node版本 68 | > asch-cli crypto -g 69 | ? Enter number of accounts to generate 1 // 这里输入的的1表示生成一个地址,可以填写10、100或者1000等数字 70 | [ { address: 'AAW3Bh86U8RdHryp86KN19ScSVLpr2x6J4', 71 | secret: 'actress south egg hen neutral salute section sign truck produce agent daughter', 72 | publicKey: 'fd86a5bb9e06bd3a0555e27402f90b565300b0a7a6fb42ee4269aae0cfca60c6' } ] 73 | Done 74 | ``` 75 | 76 | ##### 3.1.1.3 nodejs代码生成地址 77 | 78 | ```bash 79 | // 以下为nodejs编程语言的demo(目前Asch SDK支持nodejs、java这2种语言,其它语言后续会支持,当前需开发者自行编码) 80 | 81 | // 建议用ubuntu 16.04,nodejs 8.x最新版 82 | // 安装nodejs的版本管理工具nvm 83 | > curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash 84 | // 上面命令执行完成后再开一个os shell窗口执行下面的命令,安装nodejs 8.x 85 | > nvm install 8 86 | 87 | // 安装依赖库(asch-js、bitcore-mnemonic),在os shell中运行 88 | > npm install asch-js bitcore-mnemonic 89 | 90 | // 以下在node中运行 91 | var Mnemonic = require('bitcore-mnemonic'); 92 | var secret = new Mnemonic(Mnemonic.Words.ENGLISH).toString(); // 生成密码 93 | console.log(secret); // 打印密码,'latin december swing love square parade era fuel circle over hub spy' 94 | Mnemonic.isValid(secret); // 验证密码是否符合bip39规范 95 | 96 | var AschJS = require('asch-js'); 97 | var publicKey = AschJS.crypto.getKeys(secret).publicKey; // 根据密码生成公钥 98 | var address = AschJS.crypto.getAddress(publicKey); // 根据公钥生成地址 99 | console.log(address); // 打印地址,ALu3f2GaGrWzG4iczamDmGKr4YsbMFCdxB 100 | 然后将用户名、地址、加密后的密码存入到数据库或者文件中,从而完成用户和充值地址的绑定,然后将充值地址展示在前端页面上。 101 | ``` 102 | 103 | #### 3.1.2 用户进行充值 104 | 105 | 用户UserA在Asch钱包(比如mainnet.asch.io)往充值地址转阿希币,比如转0.8XAS。 106 | 107 | #### 3.1.3 交易平台确认用户充值 108 | 109 | 交易平台检测每个新的区块,可以每隔10秒(也可以是30秒或者一分钟,技术上都没有问题,只是用户体验不一样)检测一次,每次检查时区块高度加1,检查的高度建议持久化存储并增加一个标记位“是否已检查”。 110 | 如果区块里面交易详情的接收地址是平台的充值地址,则该笔充值记录需要显示到前端页面上并入库。 111 | 112 | ##### 3.1.3.1 检测最新区块是否包含交易 113 | 114 | ```bash 115 | // 通过区块高度获去检查该区块是否有交易并取到区块id,每个新区块都要检查 116 | // height=3183940表示区块高度 117 | > curl -k -X GET 'http://mainnet.asch.io/api/blocks/get?height=3183940' 118 | // 返回结果如下,保存到变量res中,下面会用到 119 | { 120 | "success": true, 121 | "block": { 122 | "id": "951e14ef5100a9724a133f74e8f5c35e0d872aee654e7ea5323e57cd1c7b004e", // 区块id 123 | "version": 0, 124 | "timestamp": 36252710, 125 | "height": 3183940, 126 | "previousBlock": "5dbf4b80063153e3bb66b46b27f9041955d308c47d57e51b4934952591519589", 127 | "numberOfTransactions": 1, //该区块包含的交易个数 128 | "totalAmount": 80000000, 129 | "totalFee": 10000000, 130 | "reward": 350000000, 131 | "payloadLength": 143, 132 | "payloadHash": "5a61b58b75a70a42a6d51deba4dba560c78b2d671dfac68d37984eb464421d81", 133 | "generatorPublicKey": "65e318f0022e3a05cc1603610125cf42af6772ac1afed657eec44bb3f8b02e64", 134 | "generatorId": "9537352069871373416", 135 | "blockSignature": "7b26571e3a55798d83e531817a5971ebdca59b4cfbb1edd182aff3b25c31578356b3a8992714b543f004cd7b362d7069f5dd426f411caacf06659747de1e580e", 136 | "confirmations": "17", // 该区块的确认数 137 | "totalForged": 360000000 138 | } 139 | } 140 | ``` 141 | 142 | ##### 3.1.3.2 根据区块id查询交易详情 143 | 144 | ```bash 145 | // 如果res.block.numberOfTransactions > 0,则说明该区块包含交易。 146 | // 然后根据res.block.id并利用下面的接口去查询该区块包含的交易详情 147 | > curl -k -X GET 'http://mainnet.asch.io/api/transactions?blockId=951e14ef5100a9724a133f74e8f5c35e0d872aee654e7ea5323e57cd1c7b004e' 148 | // 返回结果如下,保存为变量trs 149 | { 150 | "success": true, 151 | "transactions": [{ 152 | "id": "5a61b58b75a70a42a6d51deba4dba560c78b2d671dfac68d37984eb464421d81", // 交易id 153 | "height": "3183940", //区块高度 154 | "blockId": "951e14ef5100a9724a133f74e8f5c35e0d872aee654e7ea5323e57cd1c7b004e", //区块id 155 | "type": 0, // 交易类型,0:XAS普通转账 156 | "timestamp": 36252686, // 交易时间戳,Asch时间,可以换算成现实世界的时间 157 | "senderPublicKey": "40e322be1ec9084f48a17b5fecf88d59d0c70ce7ab06b1c4f6d285acfa3b0525", 158 | "senderId": "AC4i4srjg1TyW24p8M4B8NTcYApUgvTpkd", // 发送地址 159 | "recipientId": "ALu3f2GaGrWzG4iczamDmGKr4YsbMFCdxB", // 接收地址,如果是平台地址,则需要做处理 160 | "amount": 80000000, //转账金额,除以100000000后是真实的XAS个数,这里0.8XAS 161 | "fee": 10000000, 162 | "signature": "08a97ba29f7db324b31f782272e17c048f4b99d1761830bd7f541c484c28fcf14b1ee0dbbdd05ab2e80d186473e67d9bfed8e27b8c5e096d29a7f521236d8900", 163 | "signSignature": "", 164 | "signatures": null, 165 | "confirmations": "20", // 区块确认数 166 | "args": [], 167 | "message": "", // 转账备注 168 | "asset": { 169 | 170 | } 171 | }], 172 | "count": 1 // 该区块包含的交易个数 173 | } 174 | 175 | // 如果数组trs.transactions.length>0,则循环遍历trs.transactions得到元素i,如果(i.type == 0 and i.recipientId是平台的地址),那么前端页面就要展示该充值记录并将该记录(充值id、充值地址、数量、确认数、发送时间、充值状态、交易id)写入到本地数据库中。 176 | 177 | // 充值状态是由确认数决定的,具体是几,由平台自己定,如果入库时确认数未满足平台标准,则充值状态是“未确认”,否则就是“已确认”.(目前Asch网络认为6个确认就是安全的,交易平台可适当增大该值。) 178 | 179 | // 每隔1分钟对本地数据库中所有的“未确认”充值记录进行再次确认,根据数据库中的“交易id”利用下面的接口去检查交易详情 180 | > curl -k -X GET 'http://mainnet.asch.io/api/transactions/get?id=5a61b58b75a70a42a6d51deba4dba560c78b2d671dfac68d37984eb464421d81' 181 | { 182 | "success": true, 183 | "transaction": { 184 | "id": "5a61b58b75a70a42a6d51deba4dba560c78b2d671dfac68d37984eb464421d81", 185 | "height": "3183940", 186 | "blockId": "951e14ef5100a9724a133f74e8f5c35e0d872aee654e7ea5323e57cd1c7b004e", 187 | "type": 0, 188 | "timestamp": 36252686, 189 | "senderPublicKey": "40e322be1ec9084f48a17b5fecf88d59d0c70ce7ab06b1c4f6d285acfa3b0525", 190 | "senderId": "AC4i4srjg1TyW24p8M4B8NTcYApUgvTpkd", 191 | "recipientId": "ALu3f2GaGrWzG4iczamDmGKr4YsbMFCdxB", //接收地址 192 | "amount": 80000000, // 金额 193 | "fee": 10000000, 194 | "signature": "08a97ba29f7db324b31f782272e17c048f4b99d1761830bd7f541c484c28fcf14b1ee0dbbdd05ab2e80d186473e67d9bfed8e27b8c5e096d29a7f521236d8900", 195 | "signSignature": "", 196 | "signatures": null, 197 | "confirmations": "7837", // 确认数 198 | "args": [], 199 | "message": "", // 转账备注信息 200 | "asset": { 201 | 202 | } 203 | } 204 | } 205 | // 当"confirmations"达到平台要求后,更改数据库中的“充值状态”为“已确认”并显示在前端页面,最后用户UserA的XAS余额做相应的增加。 206 | 207 | ``` 208 | 209 | 至此用户UserA完成了充值流程。 210 | 211 | #### 3.1.4 交易平台将用户充值的XAS转到一个总账户中 212 | 213 | 充值完成后,交易平台再将这些分散的用户xas转账到交易平台自己的总账户中(请一定保存好密码)。
214 | 总账户:可以做为平台的Asch冷钱包或者热钱包供用户提现。
215 | 举例,平台XAS总账户地址:A7RD9YP37iUnYZ1SFnmAp6ySHUx3msC4r5
216 | Asch提供了下面2种方式进行转账操作。 217 | 218 | ##### 3.1.4.1 通过不安全的api进行转账 219 | 220 | 这种方式是把密钥放到请求里面并且明文发送给服务器进行交易的生成和签名,不安全,不建议使用。如果非要使用这种方式,务必在局域网内搭建一台Asch节点服务器,用来提供API服务。 221 | 222 | - 汇总前通过查询本地数据库将XAS余额大于0的账户找到 223 | 224 | - 可以利用如下api将充值的XAS转入到平台总账户中,该操作消耗0.1XAS手续费 225 | 226 | ```bash 227 | > curl -k -H "Content-Type: application/json" -X PUT -d '{"secret":"latin december swing love square parade era fuel circle over hub spy","secondSecret":"二级密码,如果没有则不用传该参数","args":[70000000,"A7RD9YP37iUnYZ1SFnmAp6ySHUx3msC4r5"],"message":"beizhu","type":1,"fee":10000000}' 'http://127.0.0.1:8192/api/transactions' && echo // 70000000表示0.7 XAS,type为1表示XAS普通转账,因为网络需要收取固定的0.1XAS手续费,所以UserA的充值地址只可以转出0.7 XAS(之前充值了0.8XAS) 228 | // 返回结果如下 229 | { 230 | "success": true, // 转账状态,成功 231 | "transactionId": "6d9b9338ea71ca74a41995458959250e16e49f52b31f4887ac28d3cc3586b1a1" // 交易id 232 | } 233 | ``` 234 | 235 | ##### 3.1.4.2 通过安全的api进行转账 236 | 237 | 建议使用这种安全的方法进行转账,此种方法是在本地生成交易信息并签名,然后广播到区块链网络中,这里对Asch Server没有安全性要求。 238 | ``` 239 | var asch = require('asch-js'); 240 | var targetAddress = "A7RD9YP37iUnYZ1SFnmAp6ySHUx3msC4r5"; // 接受地址 241 | var amount = 0.7*100000000; // 0.7 XAS 242 | var message = 'beizhuxinxi'; // 转账备注 243 | var password = 'latin december swing love square parade era fuel circle over hub spy'; // 发送者主密码 244 | var secondPassword=null; // 发送者二级密码,如果没有设置的话就是null 245 | // 生成交易信息并签名 246 | var transaction = asch.transaction.createTransaction(targetAddress, amount, message, password, secondPassword || undefined); 247 | JSON.stringify({"transaction":transaction}) 248 | '{"transaction":{"type":0,"amount":70000000,"fee":10000000,"recipientId":"A7RD9YP37iUnYZ1SFnmAp6ySHUx3msC4r5","message":"beizhuxinxi","timestamp":43831575,"asset":{},"senderPublicKey":"d1cda821c7f98436f0c7824b96e9fe4dba50d54ed8fd69a92752cd923e416fc2","signature":"005e529e580010398424dbbd65b9c154b37f6cd575010a4f6d9396594311c1ef62487f1040a2cba1dd16a5dba3d12605d211fa08171967886ce9ef301ae82f05","id":"0f28435e9c395dd6b825bda167359bc23d41b5fc632afb59fedfafa298c27cde"}}' 249 | 250 | // 将上面生成的转账操作的交易数据通过post提交给asch server 251 | 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 252 | ``` 253 | 254 | ### 3.2 方案2-为所有用户生成同一个充值地址 255 | 256 | 所有的用户共用一个Asch充值地址,充值时填写备注信息为自己在交易平台的用户名或者id,这样就不需要生成多个Asch充值地址了,但是如果用户填写错备注信息的话处理起来较为麻烦,需要专人客服去处理。 257 | 该种方式,大体流程和方案1一致,这里不再赘述。 258 | 259 | ## 4 提币XAS 260 | 261 | 提现操作就是转账,把平台的币转给用户。 262 | 263 | ### 4.1 用户绑定提币地址 264 | 265 | 用户登陆Asch提现页面,参考其它代币,让用户可以自行绑定提现地址。 266 | 267 | ### 4.2 用户进行提币 268 | 269 | 输入提币数量,手机短信验证,点击确认。 270 | 271 | ### 4.2 平台执行提币操作 272 | 273 | 参考“3.1.4”章节,有2种转账方式,请自行决定用哪一种。接口会返回,提币的交易id,记录到数据库中并展示到前端页面,更新提币状态为“成功”。 274 | 275 | ### 4.3 用户确认 276 | 277 | 用户自行确认提币结果,如有疑问,可以拿着交易id来平台这里进行查询验证。 278 | -------------------------------------------------------------------------------- /install/de.md: -------------------------------------------------------------------------------- 1 | # Asch Knoten Installation Anleitung 2 | 3 | ## 1. System Anforderung 4 | - Linux-System erforderlich 5 | - Öffentliche IP-Adresse erforderlich 6 | - Ubuntu 16.04 64bit OS empfohlen 7 | - Mehr als 2Gb RAM wird empfohlen 8 | - Mehr als 2Mb Bandbreite wird empfohlen 9 | - Mehr als 10GB Festplattespeicher wird empfohlen 10 | 11 | ## 2. Installation 12 | 13 | Es gibt zwei unterschiedliche Systeme: Das Testsystem (testnet) und Hauptsystem (mainnet). Beide existieren nebeneinander, können aber nicht miteinander kommunizieren. 14 | 15 | Die Schritte zur Installation sind für diese beiden System die Gleichen. Bis auf das Installationspaket und die Datei-Konfiguration (inklusive der Port Einstellungen). 16 | 17 | 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. 18 | 19 | 20 | ### 2.1 Downloaden und Entpacken 21 | 22 | test version (testnet) 23 | 24 | ``` 25 | wget https://www.asch.so/downloads/asch-linux-latest-testnet.tar.gz 26 | tar zxvf asch-linux-latest-testnet.tar.gz 27 | ``` 28 | 29 | official version (mainnet) 30 | ``` 31 | wget https://www.asch.so/downloads/asch-linux-latest-mainnet.tar.gz 32 | tar zxvf asch-linux-latest-mainnet.tar.gz 33 | ``` 34 | 35 | Üblicherweise ist die Versionsnumber der Testchain höher als die der Mainchain. 36 | 37 | ### 2.2 Initialisierung 38 | In diesem Schritt werden folgenden Dinge automatisch installiert: 39 | - Installtion von Module wie **sqlite3** 40 | - Installation und Konfiguration des NTP-Service, welcher die Systemzeit mit der der anderen Knoten synchronisiert 41 | 42 | Dieser Schritt muss nicht ausgeführt werden, es passiert aber nichts Schlimmes, wenn er öfters ausgeführt wird. 43 | 44 | # dies soll im Installations-Verzeichnis ausgeführt werden 45 | ./aschd configure 46 | ... 47 | 48 | ## 3. Starten 49 | ``` 50 | # Folgende Kommandos werden im Installations-Verzeichnis ausgeführt 51 | 52 | # das Service starten 53 | ./aschd start 54 | 55 | # das Service stoppen 56 | ./aschd stop 57 | 58 | # zeige den aktuellen Status 59 | ./aschd status 60 | 61 | # das Service neustarten 62 | ./aschd restart 63 | 64 | # ein Asch-Upgrade durchführen 65 | ./aschd upgrade 66 | 67 | # die blockchain resynchronisieren 68 | ./aschd rebuild 69 | 70 | # die Asch-Version anzeigen lassen 71 | ./aschd version 72 | 73 | # mit der Blöcke-Produzieren starten 74 | ./aschd enable "your sercret" 75 | 76 | # die Logs anzeigen 77 | tail -f logs/debug.log 78 | ``` 79 | 80 | ## 4. Delegat Konfiguration 81 | ### 4.1 Delegat Passwort 82 | 83 | Ö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. 84 | 85 | ![forging secret](../assets/forging-secret.png) 86 | 87 | **HINWEIS:** Konfiguriere NIEMALS das selbe Passwort. Egal ob auf einem Rechner oder auf unterschiedlichen. 88 | 89 | 90 | ### 4.2 Öffentliche IP-Adresse 91 | 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. 92 | 93 | 94 | ``` 95 | "publicIp": "Hier steht die öffentliche IP-Adresse", 96 | ``` 97 | Vergiss nicht das System nach der Konfiguration mit folgendem Befehl neu zu starten. 98 | ``` 99 | ./aschd restart 100 | ``` 101 | 102 | ## 5. System Upgrade 103 | ``` 104 | ./aschd upgrade 105 | ./aschd start 106 | ``` 107 | ## 6. Fehlerbehebung 108 | ### 6.1 Ich kann nicht auf meine Online-Wallet zugreifen 109 | #### Lösung 1 110 | Ü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`. 111 | Die offiziellen Seed-Nodes haben die Portnummer auf 80 geändert. 112 | Überprüfe die Firewall-Einstellungen und öffne den Asch-Port für eingehenden und ausgehenden Verkehr. 113 | 114 | #### Lösung 2 115 | Überprüfe ob mit folgendem Kommando ob der Service gestartet ist: 116 | ``` 117 | ./aschd status 118 | 119 | # falls der Service nicht läuft kommt folgende Meldung: 120 | Asch server is not running 121 | 122 | # danach starte das Service neu 123 | ./aschd restart 124 | ``` 125 | 126 | ### 6.2 Es werden keine Blöcke produziert 127 | #### Lösung 1 128 | Stelle sicher, dass dein Delegat-Rank unter den TOP 101 ist 129 | 130 | #### Lösung 2 131 | Überprüfe den Fehler-Log mit folgendem Kommando: 132 | ``` 133 | grep Failed logs/debug.log 134 | ``` 135 | Falls es eine ähnliche Fehlernachricht gibt wie: 136 | ``` 137 | Failed to get public ip, block forging MAY not work! 138 | ``` 139 | bedeutet dies, dass das system nicht die öffentliche IP-Adresse hat. Dies muss manuell konfiguriert werden. Siehe **[4.2 Public IP]** 140 | 141 | #### Lösung 3 142 | Überprüfe den Fehler-Log mit folgendem Kommando: 143 | ``` 144 | grep error logs/debug.log 145 | ``` 146 | Falls es eine ähnliche Fehlernachricht gibt wie: 147 | ``` 148 | Failed to load delegates: Account xxxxxxxxx not found 149 | ``` 150 | 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. 151 | 152 | **HINWEIS:** Falls dein Knoten gerade die Blöcke synchronisiert ist es zu empfehlen das System erst nach der abgeschlossenen Sychronisation zu starten. 153 | ``` 154 | ./aschd restart 155 | ``` 156 | Wenn das System erfolgreich neugestartet wurde, ist folgendes im Log zu lesen: 157 | ``` 158 | grep Forging logs/debug.log 159 | 160 | Forging enabled on account: xxxxxxxxxxxxxx 161 | ``` 162 | ### 6.3 Meine Blöcke werden nicht sychronisiert (Blockhöhe wächst nicht) 163 | *Dieses Problem kann verifiziert werden in dem man seine Blockhöhe mit der des offiziellen Knotens vergleicht 164 | 165 | Als allererstes, versuche das System neu zu starten 166 | ``` 167 | ./aschd restart 168 | ``` 169 | Falls das Problem noch immer auftritt, versuche folgendes:` 170 | ``` 171 | ./aschd rebuild 172 | ``` 173 | -------------------------------------------------------------------------------- /install/dev_windows_install.md: -------------------------------------------------------------------------------- 1 | # Asch 本地开发环境搭建(Windows) 2 | 3 | ## 1 系统要求 4 | 5 | - Windows操作系统(7/8/10) 6 | 7 | ## 2 安装nodejs 8 | [安装nodejs](https://nodejs.org/en/download/) 配置环境变量,版本V6.3以上(以下的没有验证过),如下所示: 9 | 10 | ![nodejs环境](../assets/win_install/node.png) 11 | 12 | ## 3 安装Python 13 | [安装Python](https://www.python.org/downloads/release/python-2713/) 并配置环境变量,版本2.5到3.0之间(最好2.7,3.0以及以上版本不支持),如下所示: 14 | 15 | ![python](../assets/win_install/python.png) 16 | 17 | ## 4 安装.NET Framework 4.5.1 18 | [下载](https://www.microsoft.com/en-us/download/details.aspx?id=42779) 并安装.NET Framework 4.5.1,如果系统已经安装了可以忽略此步骤(至少4.5版本),win7系统可以直接打开控制**面板》程序》程序和功能** 查看 19 | 是否已经安装,win10系统默认已经安装好了,查看方式如下图所示: 20 | 21 | ![python](../assets/win_install/win10.net.png) 22 | 23 | ## 5 安装 VC++ Build Tools Technical Preview 24 | [下载](http://go.microsoft.com/fwlink/?LinkId=691126)并安装VC++ Build Tools Technical Preview,全部选择默认安装就行了,安装时间可能有点久(10分钟左右) 25 | 26 | [参考](https://stackoverflow.com/questions/21069699/node-packages-not-building-on-windows-8-1-missing-microsoft-cpp-default-props) 27 | 28 | ## 6 安装git 29 | [下载](https://git-scm.com/)并安装git,应为asch使用gulp构建工具,其中包含一部分linux命令(如 cp、mv等),所以后面执行命令的时候需要用到git bash 30 | 31 | ## 7 安装sqlite3 32 | [下载](https://pan.baidu.com/s/1WvQYSCCr-n7N5HMCRGqwLA)已经打包好的sqlie3压缩文件,解压放到任意位置,然后添加环境变量,如下所示: 33 | 34 | ![sqlite3](../assets/win_install/sqlite3.png) 35 | 36 | 打开命令行验证如下: 37 | 38 | ![sqlite3](../assets/win_install/sqlite3_verify.png) 39 | 40 | ## 8 安装gcc, g++ 41 | 这里有如下两种方式: 42 | * [下载mingw-get-setup](https://sourceforge.net/projects/mingw/files/Installer/),然后再线安装所有依赖包,但是可能会比较慢 43 | * 下载我已经下载好的依赖包,解压缩后放到任意盘,然后配置环境变量,如下所示: 44 | 45 | ![sqlite3](../assets/win_install/gcc.png) 46 | 47 | 安装完成后分别执行一下命令查看是否成功: 48 | ``` 49 | gcc -v 50 | g++ -v 51 | ``` 52 | 53 | 如下所示: 54 | 55 | ![sqlite3](../assets/win_install/gcc_verify.png) 56 | 57 | ## 9 安装OpenSSL 58 | [下载](http://slproweb.com/products/Win32OpenSSL.html)并安装OpenSSL,全部默认安装即可. 59 | 60 | ## 10 npm配置 61 | 首先执行以下命令配置淘宝镜像,这样使用npm下载的时候会更快一些 62 | ``` 63 | npm config set registry https://registry.npm.taobao.org 64 | 65 | ##验证 66 | npm info npm 67 | ``` 68 | 69 | 执行以下命令配置**msvs** 70 | ``` 71 | npm config set msvs_version 2015 --global 72 | ``` 73 | 74 | 最后安装asch需要的一些依赖,执行以下命令: 75 | ``` 76 | npm i -g gulp 77 | npm i -g yarn 78 | ``` 79 | 80 | ### 11 运行代码 81 | > 运行前查看之前的 VC++ Build Tools Technical Preview 是否已经安装完成 82 | 83 | 注:运行代码之前需要说明一下,在asch3.0版本之前,用的椭圆曲线加密依赖为ed25519,而3.0以后使用的是sodium, 84 | 3.0之前的代码直接安装完依赖就可以运行,但是目前的3.0之后的源码需要改变几行代码,但是asch的所有功能都能正常运行,方便Windows用户本地开发调试使用。 85 | 86 | 修改以下两个文件的内容: 87 | * src\utils\ed.js 88 | * package.json 89 | 90 | package.js: 91 | ```json 92 | ##原依赖 93 | "sodium": "^2.0.3", 94 | 95 | ## 换成ed25519 96 | "ed25519": "^0.0.4", 97 | ``` 98 | 99 | ed.js: 100 | ``` 101 | ## 将文件所有内容换成如下代码 102 | const ed = require('ed25519'); 103 | module.exports = { 104 | MakeKeypair: ed.MakeKeypair, 105 | 106 | Sign: ed.Sign, 107 | 108 | Verify: ed.Verify 109 | }; 110 | ``` 111 | 112 | 修改完文件以后安装依赖: 113 | ``` 114 | npm install 115 | ``` 116 | 117 | 因为Windows控制台本身的原因,安装过程中如果出现停顿可以按几下回车,如果出现以下步骤则说明前面一些安装成功了: 118 | 119 | ![install](../assets/win_install/install.png) 120 | 121 | 最后执行 **node app.js** 即可正常运行,如下图所示: 122 | 123 | ![run](../assets/win_install/run.png) 124 | 125 | ## 12 编译前端项目 126 | 前端项目具体编译打包操作可以参考 [前端项目的操作说明](../public/README.md),不过这里需要注意一点, 127 | 所有的命令都要在 **git bash** 中进行,原因已经在之前安装git的时候说明了,依次执行以下命令即可: 128 | ``` 129 | cd public 130 | yarn install 131 | gulp build-test 132 | ``` 133 | 134 | ## 13 软件下载 135 | 考虑到部分软件可能因为网络原因无法下载,在这里提供一个所有依赖的软件的 [下载地址](https://pan.baidu.com/s/1WLSH9M0Hwp16CPYOgZ_6GQ) 136 | 137 | 138 | 139 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /install/dev_windows_install_en.md: -------------------------------------------------------------------------------- 1 | # Setup Local Asch Development Environment (Windows) 2 | 3 | 4 | 5 | - [Setup Local Asch Development Environment (Windows)](#setup-local-asch-development-environment-windows) 6 | - [1 System Requirements](#1-system-requirements) 7 | - [2 Install node.js](#2-install-nodejs) 8 | - [3 Install Python](#3-install-python) 9 | - [Common Problem: Python can't be found](#common-problem-python-cant-be-found) 10 | - [Test Python Installation](#test-python-installation) 11 | - [4 Install .NET Framework 4.5.1](#4-install-net-framework-451) 12 | - [5 Install VC++ Build Tools Technical Preview](#5-install-vc-build-tools-technical-preview) 13 | - [6 Install git](#6-install-git) 14 | - [7 Install sqlite3](#7-install-sqlite3) 15 | - [8 Install MinGW (gcc, g++)](#8-install-mingw-gcc-g) 16 | - [10 Install OpenSSL](#10-install-openssl) 17 | - [Info](#info) 18 | - [11 Clone Asch Blockchain](#11-clone-asch-blockchain) 19 | - [12 Run the code](#12-run-the-code) 20 | - [13 Compile the front-end project](#13-compile-the-front-end-project) 21 | 22 | 23 | 24 | 25 | ## 1 System Requirements 26 | 27 | - Windows (7/8/10) 28 | 29 | __Warning__ 30 | This tutorial is for development purpose only. Don't run the Asch Blockchain on Windows in production. 31 | 32 | ## 2 Install node.js 33 | Install node.js version 6.3 or later. 34 | [Download node.js](https://nodejs.org/en/download/) 35 | 36 | ![node](../assets/win_install/node_en.PNG) 37 | 38 | ## 3 Install Python 39 | Install version 2.5 up to 3.0. Python version v2.7 is preferred. Version v3.0 and above are not supported. 40 | [Download Python 2.7.13](https://www.python.org/downloads/release/python-2713/) 41 | 42 | 43 | ### Common Problem: Python can't be found 44 | 45 | Often can python not be found from the command line after the installation: 46 | ![python](../assets/win_install/python_not_found_en.PNG) 47 | 48 | Open the windows `Control Panel` 49 | ![python](../assets/win_install/control_panel_system_variables_en.PNG) 50 | 51 | Select `Environment Variables`: 52 | ![env-var](../assets/win_install/environment_variables_menu_en.PNG) 53 | 54 | Edit `%PATH%`: 55 | ![env-var](../assets/win_install/env_variables_select_path_en.PNG) 56 | 57 | Add new Environment Variable: 58 | ![env-variable](../assets/win_install/env_variables_new_en.PNG) 59 | 60 | Python is normally installed in `C:\Python27`. 61 | ![python](../assets/win_install/python_location_en.PNG) 62 | 63 | Add `C:\Python27\` to the Environment Variables: 64 | ![python27](../assets/win_install/env_variables_new_python_en.PNG) 65 | 66 | 67 | 68 | ### Test Python Installation 69 | 70 | Be sure to __restart__ your system before testing if it works. 71 | 72 | ![python](../assets/win_install/python_success_en.PNG) 73 | 74 | 75 | ## 4 Install .NET Framework 4.5.1 76 | 77 | If the .NET Version 4.5 or higher is already installed ignore this step. On windows 10 .NET 4.5 is already installed. 78 | [Download .NET 4.5](https://www.microsoft.com/en-us/download/details.aspx?id=42779) 79 | 80 | Check if the `.NET 4.5` is already installed: 81 | * Open: Control Panel 82 | * Click: Programs 83 | * Click: Turn Windows features on or off 84 | 85 | ![python](../assets/win_install/win10_dot_net_en.PNG) 86 | 87 | ## 5 Install VC++ Build Tools Technical Preview 88 | 89 | Install the VC++ Build Tools Technical Preview. Choose the __custom__ installation. 90 | [Download](http://go.microsoft.com/fwlink/?LinkId=691126) 91 | 92 | ![vs](../assets/win_install/vc_custom_en.PNG) 93 | 94 | Select: 95 | * __Windows 8.1 SDK__ 96 | * __Windows 10 SDK__ 97 | 98 | ![vs](../assets/win_install/vc_win8_win10_en.PNG) 99 | 100 | This installation step can take up to 10 minutes. 101 | 102 | Set in `npm` the Visual Studio Version to __2015__ 103 | ```cmd 104 | npm config set msvs_version 2015 105 | ``` 106 | 107 | ![vs](../assets/win_install/vc_set_msvs_version_2015_en.PNG) 108 | 109 | [Reference](https://stackoverflow.com/questions/21069699/node-packages-not-building-on-windows-8-1-missing-microsoft-cpp-default-props) 110 | 111 | 112 | ## 6 Install git 113 | Download and install git. 114 | You need to select `git bash console`. 115 | [Download git](https://git-scm.com/download/win) 116 | 117 | Install Git Bash: 118 | ![git](../assets/win_install/git_install_git_bash_en.PNG) 119 | 120 | Git use Windows Command Prompt: 121 | ![git](../assets/win_install/git_option_en.PNG) 122 | 123 | Select Git OpenSSL Version: 124 | ![git](../assets/win_install/git_openssl_en.PNG) 125 | 126 | Use Windows default console: 127 | ![git](../assets/win_install/git_install_cmd_en.PNG) 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | ## 7 Install sqlite3 136 | [Download](https://sqlite.org/2018/sqlite-tools-win32-x86-3240000.zip) 137 | 138 | Unzip the zip archive 139 | ![sqlite3](../assets/win_install/sqlite3_extract_zip_en.PNG) 140 | 141 | Create new directory `C:\sqlite3` 142 | ![sqlite3](../assets/win_install/sqlite3_new_dir_content_en.PNG) 143 | 144 | Edit `%PATH%`: 145 | ![env-var](../assets/win_install/env_variables_select_path_en.PNG) 146 | 147 | ![sqlite3](../assets/win_install/sqlite3_env_variable_en.PNG) 148 | 149 | Be sure to __restart__ your PC for the following command to work. 150 | Open the command line to verify the sqlite installation: 151 | 152 | ![sqlite3](../assets/win_install/sqlite3_success_en.PNG) 153 | 154 | ## 8 Install MinGW (gcc, g++) 155 | Install MinGW from Sourceforge. This installation step can take up to 10 minutes: 156 | * [download mingw-setup](https://sourceforge.net/projects/mingw/files/Installer/) 157 | 158 | Download from Sourceforge: 159 | ![mingw](../assets/win_install/mingw_sourceforge_en.PNG) 160 | 161 | Setup: 162 | ![mingw](../assets/win_install/mingw_setup_en.PNG) 163 | 164 | Apply Changes: 165 | ![mingw](../assets/win_install/mingw_apply_changes_en.PNG) 166 | 167 | Edit `%PATH%`: 168 | ![env-var](../assets/win_install/env_variables_select_path_en.PNG) 169 | 170 | Àdd the environment variable `C:\MinGW\bin\`: 171 | ![mingw](../assets/win_install/mingw_env_variable_en.PNG) 172 | 173 | 174 | Be sure to __restart__ your system in order for the following commands to work: 175 | ```cmd 176 | gcc -v 177 | g++ -v 178 | ``` 179 | 180 | As follows: 181 | 182 | ![sqlite3](../assets/win_install/gcc_gplusplus_en.PNG) 183 | 184 | 185 | ## 10 Install OpenSSL 186 | 187 | Install OpenSSL. 188 | [Download](http://slproweb.com/products/Win32OpenSSL.html) 189 | 190 | Select correct version: 191 | ![openssl-download](../assets/win_install/openssl_download_en.PNG) 192 | 193 | Choose Installation option: 194 | ![openssl-installation](../assets/win_install/openssl_installation_en.PNG) 195 | 196 | __Restart__ your PC in order for OpenSSL to work correctly. 197 | 198 | ### Info 199 | Unfortunately due to a bug in in the npm package [ed25519](https://github.com/dazoe/ed25519) is it not possbile that we use the newest OpenSSL version (newest: `OpenSSL v1.1.0h`). Therefore we need to go with the older OpenSSL version `OpenSSL v1.0.2o`. 200 | 201 | ## 11 Clone Asch Blockchain 202 | 203 | Clone the Asch Blockchain into an empty directory. 204 | ```cmd 205 | git clone https://github.com/aschplatform/asch 206 | ``` 207 | 208 | ## 12 Run the code 209 | 210 | We need to change a few lines of code in order for the blockchain to work on windows. 211 | 212 | * __Option 1__ 213 | Change the content of `package.json` file 214 | ``` 215 | ## before 216 | "sodium": "^2.0.3" 217 | 218 | ## change sodium version to 2.0.1 219 | "sodium": "2.0.1" 220 | ``` 221 | 222 | 223 | * __Option 2__ 224 | 225 | Modify the contents of the following two files: 226 | 227 | * src\utils\ed.js 228 | * package.json 229 | 230 | `package.js`: 231 | ```js 232 | ## originally relied on 233 | "sodium": "^2.0.3", 234 | 235 | ## Change to ed25519 236 | "ed25519": "^0.0.4", 237 | ``` 238 | 239 | `ed.js`: 240 | ```js 241 | ## Replace all the contents of the file with the following code 242 | const ed = require('ed25519'); 243 | module.exports = { 244 | MakeKeypair: ed.MakeKeypair, 245 | 246 | Sign: ed.Sign, 247 | 248 | Verify: ed.Verify 249 | }; 250 | ``` 251 | 252 | After __Option1__ or __Option2__ install the dependencies: 253 | ```cmd 254 | npm install 255 | ``` 256 | 257 | 258 | 259 | 260 | Because of the Windows console, there could be a pause during installation. Maybe you have to press Enter several times. If the following steps appear, it means that the previous installation steps were successful: 261 | 262 | ![install](../assets/win_install/install_en.PNG) 263 | 264 | Finally, execute **node app.js** to start the blockchain, as shown in the following figure: 265 | 266 | ![run](../assets/win_install/run_en.PNG) 267 | 268 | 269 | [Reference node-gyp problem](https://github.com/nodejs/node-gyp/issues/629#issuecomment-153196245) 270 | 271 | 272 | ## 13 Compile the front-end project 273 | The following commands need to be executed in **git bash** in a __new__ console. The first console is already busy with running the blockchain. 274 | Execute the following commands in order: 275 | 276 | ```bash 277 | # change directory 278 | cd pubilc 279 | ``` 280 | 281 | Install the dependencies for the frontend application 282 | ```bash 283 | npm install yarn --global 284 | npm install browserify --global 285 | npm install gulp --globalg 286 | 287 | yarn install 288 | ``` 289 | 290 | Build the frontend application for the localnet. 291 | ```bash 292 | gulp build-local 293 | ``` -------------------------------------------------------------------------------- /install/en.md: -------------------------------------------------------------------------------- 1 | * [Asch Full Node Installation](#asch-full-node-installation) 2 | * [1. System Requirements and dependencies](#1-system-requirements-and-dependencies) 3 | * [1.1 System Requirements](#11-system-requirements) 4 | * [1.2 Install dependencies](#12-install-dependencies) 5 | * [1.3 Install Node.js](#13-install-nodejs) 6 | * [2. Install Asch Mainnet Full Node](#2-install-asch-mainnet-full-node) 7 | * [2.1 Download installation package](#21-download-installation-package) 8 | * [2.2 Modify config.json](#22-modify-configjson) 9 | * [2.3 Download database snapshot](#23-download-database-snapshot) 10 | * [2.4 Start the node](#24-start-the-node) 11 | * [3. Install Asch Testnet Full Node](#3-install-asch-testnet-full-node) 12 | * [3.1 Download installation package](#31-download-installation-package) 13 | * [3.2 Modify config.json](#32-modify-configjson) 14 | * [3.3 Download database snapshot](#33-download-database-snapshot) 15 | * [3.4 Start the node](#34-start-the-node) 16 | * [4. Install Asch Localnet Full Node](#4-install-asch-localnet-full-node) 17 | * [4.1 Download installation package](#41-download-installation-package) 18 | * [4.2 Modify config.json](#42-modify-configjson) 19 | * [4.3 Start the node](#43-start-the-node) 20 | * [4.4 Genesis account](#44-genesis-account) 21 | * [5. Install from source code](#5-install-from-source-code) 22 | * [5.1 Clone the code](#51-clone-the-code) 23 | * [5.2 Install dependencies](#52-install-dependencies) 24 | * [5.3 Modify app.js](#53-modify-appjs) 25 | * [5.4 Replace config.json](#54-replace-configjson) 26 | * [5.5 Create relevent folders](#55-create-relevent-folders) 27 | * [5.6 Configure frontend](#56-configure-frontend) 28 | * [5.7 Download database snapshot](#57-download-database-snapshot) 29 | * [5.8 Start the node](#58-start-the-node) 30 | * [6. Common errors and solutions](#6-common-errors-and-solutions) 31 | * [6.1 Cannot access wallet webpage](#61-cannot-access-wallet-webpage) 32 | * [6.2 Delegates node can not forge new blocks](#62-delegates-node-can-not-forge-new-blocks) 33 | * [6.3 Cannot sync blocks](#63-cannot-sync-blocks) 34 | * [7. Upgrade](#7-upgrade) 35 | * [8. Frequently used commands](#8-frequently-used-commands) 36 | * [9. Configure delegate](#9-configure-delegate) 37 | 38 | 39 | # Asch Full Node Installation 40 | 41 | ## 1. System Requirements and dependencies 42 | 43 | ### 1.1 System Requirements 44 | 45 | - Must be a linux os, recommend Ubuntu 14.04+ 46 | - Must have a public IP address 47 | - CPU > 2 cores 48 | - Memory > 2G 49 | - Bandwidth > 2Mbps 50 | - Hard disk > 30 GB 51 | 52 | ### 1.2 Install dependencies 53 | 54 | ``` 55 | # Install dependency package 56 | sudo apt-get install curl sqlite3 ntp wget git libssl-dev openssl make gcc g++ autoconf automake python build-essential -y 57 | # libsodium for ubuntu 14.04 58 | sudo apt-get install libtool -y 59 | # libsodium for ubuntu 16.04 60 | sudo apt-get install libtool libtool-bin -y 61 | ``` 62 | 63 | ### 1.3 Install Node.js 64 | 65 | Asch support the latest LTS version of Node.js(current version is v8.11.3). Please make sure that you install the right version. 66 | 67 | ``` 68 | # Install nvm 69 | curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash 70 | 71 | # This loads nvm 72 | export NVM_DIR="$HOME/.nvm" 73 | [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" 74 | [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion 75 | 76 | # Install node and npm for current user. 77 | nvm install v8 78 | 79 | # check node version and it should be v8.x.x 80 | node --version 81 | ``` 82 | 83 | ## 2. Install Asch Mainnet Full Node 84 | 85 | Default port for mainnet is 8192, P2P port is 8193. If you change the default port, please make sure `P2P port = default port + 1` 86 | 87 | ### 2.1 Download installation package 88 | 89 | ``` 90 | wget http://china.aschcdn.com/asch-linux-latest-mainnet.tar.gz 91 | tar zxvf asch-linux-latest-mainnet.tar.gz 92 | cd asch-linux-1.4.2-mainnet // This version varies in different time 93 | ``` 94 | 95 | ### 2.2 Modify config.json 96 | 97 | ``` 98 | vim config.json 99 | 100 | add your IP address to the field publicIp 101 | ``` 102 | 103 | ### 2.3 Download database snapshot 104 | 105 | Download the database snapshot and then unpack it. Replace the original data folder. 106 | 107 | ``` 108 | wget http://china.aschcdn.com/blockchain-mainnet-snapshot.tar.gz 109 | tar zvxf blockchain-mainnet-snapshot.tar.gz 110 | ``` 111 | 112 | ### 2.4 Start the node 113 | execute 114 | `./aschd start` 115 | 116 | Check your height from `logs/debug.2018xxxx.log` or `http://yourip:8192/api/blocks/getHeight` 117 | 118 | 119 | ## 3. Install Asch Testnet Full Node 120 | 121 | Default port for testnet is 4096, P2P port is 4097. If you change the default port, please make sure `P2P port = default port + 1` 122 | 123 | 124 | ### 3.1 Download installation package 125 | 126 | ``` 127 | wget http://china.aschcdn.com/asch-linux-latest-testnet.tar.gz 128 | tar zxvf asch-linux-latest-testnet.tar.gz 129 | cd asch-linux-1.4.2-testnet // This version varies in different time 130 | ``` 131 | 132 | ### 3.2 Modify config.json 133 | 134 | ``` 135 | vim config.json 136 | 137 | add your IP address to the field publicIp 138 | ``` 139 | 140 | ### 3.3 Download database snapshot 141 | 142 | Download the database snapshot and then unpack it. Replace the original data folder. 143 | 144 | ``` 145 | wget http://china.aschcdn.com/blockchain-testnet-snapshot.tar.gz 146 | tar zvxf blockchain-testnet-snapshot.tar.gz 147 | ``` 148 | 149 | ### 3.4 Start the node 150 | 151 | execute `./aschd start` 152 | 153 | Check your height from `logs/debug.2018xxxx.log` or `http://yourip:8192/api/blocks/getHeight` 154 | 155 | ## 4. Install Asch Localnet Full Node 156 | 157 | Default port for localnet is 4096, P2P port is 4097. If you change the default port, please make sure `P2P port = default port + 1` 158 | 159 | ### 4.1 Download installation package 160 | 161 | ``` 162 | wget http://china.aschcdn.com/asch-linux-latest-localnet.tar.gz 163 | tar zxvf asch-linux-latest-localnet.tar.gz 164 | cd asch-linux-1.4.2-localnet // This version varies in different time 165 | ``` 166 | 167 | ### 4.2 Modify config.json 168 | 169 | ``` 170 | vim config.json 171 | 172 | add your IP address to the field publicIp 173 | ``` 174 | 175 | ### 4.3 Start the node 176 | 177 | execute `./aschd start` 178 | 179 | Check your height from `logs/debug.2018xxxx.log` or `http://yourip:8192/api/blocks/getHeight` 180 | 181 | ### 4.4 Genesis account 182 | 183 | There are 100,000,000 XAS in the genesis account, the password is 184 | 185 | `stone elephant caught wrong spend traffic success fetch inside blush virtual element` 186 | 187 | ## 5. Install from source code 188 | 189 | We will install mainnet from source code here. 190 | 191 | ### 5.1 Clone the code 192 | ``` 193 | git clone https://github.com/AschPlatform/asch 194 | ``` 195 | 196 | ### 5.2 Install dependencies 197 | 198 | ``` 199 | npm install 200 | ``` 201 | 202 | ### 5.3 Modify app.js 203 | 204 | ``` 205 | search for testnet and modify it to mainnet。Result: 206 | 207 | appConfig.netVersion = process.env.NET_VERSION || 'mainnet' 208 | ``` 209 | 210 | ### 5.4 Replace config.json 211 | 212 | ``` 213 | cp config-mainnet.json config.json 214 | ``` 215 | 216 | Add you IP address to the publicIp field. 217 | 218 | ### 5.5 Create relevent folders 219 | 220 | ``` 221 | mkdir -p public/dist 222 | mkdir chains 223 | ``` 224 | 225 | ### 5.6 Configure frontend 226 | 227 | ``` 228 | cd public/dist 229 | wget http://china.aschcdn.com/frontend-mainnet-5f5b3cf5.zip 230 | unzip frontend-mainnet-5f5b3cf5.zip 231 | ``` 232 | 233 | ### 5.7 Download database snapshot 234 | 235 | ``` 236 | cd asch 237 | wget http://47.75.26.122/blockchain-mainnet-snapshot.tar.gz 238 | tar zvxf blockchain-mainnet-snapshot.tar.gz 239 | ``` 240 | 241 | ### 5.8 Start the node 242 | 243 | ``` 244 | ./aschd start 245 | ``` 246 | 247 | ## 6. Common errors and solutions 248 | 249 | ### 6.1 Cannot access wallet webpage 250 | 251 | The url of wallet is http://your_ip:your_port, Mainnet default port is 8192, Testnet and Localnet are both 4096. 252 | 253 | Steps: 254 | 255 | 1. Check the port in config.json 256 | 2. Check your firewall 257 | 3. Check the node status executing `./aschd status`. If not started, please run `./aschd start`. 258 | 259 | ### 6.2 Delegates node can not forge new blocks 260 | 261 | Steps: 262 | 263 | 1. Check your ranking (should be in the top 101) 264 | 2. Seach the log by executing `grep Failed logs/debug.log`. If you found errors like `Failed to get public ip, block forging MAY not work!`, please config your publicIp in config.json 265 | 3. Search the log by executing `grep error logs/debug.log`. If you found errors like `Failed to load delegates: Account xxxxxxxxx not found`, please register your account to a delegate first. 266 | 267 | If your node is syncing blocks, please wait the server to finish syncing and then restart. 268 | 269 | ``` 270 | ./aschd restart 271 | ``` 272 | If you found these logs, then your node is worked! 273 | ``` 274 | grep Forging logs/debug.log 275 | Forging enabled on account: xxxxxxxxxxxxxx 276 | ``` 277 | 278 | ### 6.3 Cannot sync blocks 279 | 280 | Check your node's block height with the latest block height(can be found on https://wallet.asch.cn/api/blocks/getHeight). If you found your node's height is not increasing, please check the follow steps: 281 | 282 | 1. Update to the latest version and restart 283 | ``` 284 | ./aschd upgrade 285 | ./aschd start 286 | ``` 287 | 288 | 2. rebuild 289 | ``` 290 | ./aschd rebuild 291 | ``` 292 | 293 | ## 7. Upgrade 294 | 295 | After installing the node, upgrade is easy by executing `./aschd upgrade`. 296 | 297 | Go to the asch folder and run: 298 | ``` 299 | ./aschd upgrade 300 | ./aschd start 301 | ``` 302 | 303 | ## 8. Frequently used commands 304 | 305 | ``` 306 | # start node 307 | ./aschd start 308 | 309 | # stop node 310 | ./aschd stop 311 | 312 | # check node status 313 | ./aschd status 314 | 315 | # restart node 316 | ./aschd restart 317 | 318 | # upgrade node 319 | ./aschd upgrade 320 | 321 | # rebuild the blocks 322 | ./aschd rebuild 323 | 324 | # check node version 325 | ./aschd version 326 | 327 | # enable forging blocks(only used for delegates) 328 | ./aschd enable "your sercret" 329 | 330 | # check node log 331 | tail -f logs/debug.201xxxxx.log 332 | ``` 333 | 334 | ## 9. Configure delegate 335 | 336 | Open config.json and fill in your master secret to the secret field. 337 | 338 | Note: Please don't configure the same delegate on different servers! 339 | 340 | run following commands: 341 | ``` 342 | // restart node 343 | ./aschd restart 344 | 345 | // enable forging 346 | ./aschd enable "your sercret" 347 | ``` 348 | -------------------------------------------------------------------------------- /install/zh-cn.md: -------------------------------------------------------------------------------- 1 | # Asch 节点安装文档 2 | 3 | * [Asch 节点安装文档](#asch-节点安装文档) 4 | * [一、系统环境和依赖](#一系统环境和依赖) 5 | * [1.1 系统要求](#11-系统要求) 6 | * [1.2 系统依赖安装](#12-系统依赖安装) 7 | * [1.3 Node.js 安装](#13-nodejs-安装) 8 | * [二、Asch Mainnet 节点安装](#二asch-mainnet-节点安装) 9 | * [2.1 下载安装包并解压](#21-下载安装包并解压) 10 | * [2.2 修改config.json](#22-修改configjson) 11 | * [2.3 下载数据库快照并解压替换](#23-下载数据库快照并解压替换) 12 | * [2.4 启动节点,监听区块同步情况](#24-启动节点监听区块同步情况) 13 | * [三、Asch Testnet 节点安装](#三asch-testnet-节点安装) 14 | * [3.1 下载安装包并解压](#31-下载安装包并解压) 15 | * [3.2 修改config.json](#32-修改configjson) 16 | * [3.3 下载数据库快照并解压替换](#33-下载数据库快照并解压替换) 17 | * [3.4 启动节点,监听区块同步情况](#34-启动节点监听区块同步情况) 18 | * [四、Asch Localnet 节点安装](#四asch-localnet-节点安装) 19 | * [4.1 下载安装包并解压](#41-下载安装包并解压) 20 | * [4.2 修改config.json](#42-修改configjson) 21 | * [4.3 启动节点,监听区块同步情况](#43-启动节点监听区块同步情况) 22 | * [4.4 创世账户](#44-创世账户) 23 | * [五、源码安装](#五源码安装) 24 | * [5.1 克隆源码到本地](#51-克隆源码到本地) 25 | * [5.2 安装依赖](#52-安装依赖) 26 | * [5.3 修改 app.js](#53-修改-appjs) 27 | * [5.4 覆盖config.json](#54-覆盖configjson) 28 | * [5.5 创建依赖目录](#55-创建依赖目录) 29 | * [5.6 配置网页客户端](#56-配置网页客户端) 30 | * [5.7 下载快照并解压](#57-下载快照并解压) 31 | * [5.8 启动节点](#58-启动节点) 32 | * [六、常见错误处理](#六常见错误处理) 33 | * [6.1 网页客户端无法访问](#61-网页客户端无法访问) 34 | * [6.2 受托人节点无法生产区块](#62-受托人节点无法生产区块) 35 | * [6.3 无法同步区块(卡块)](#63-无法同步区块卡块) 36 | * [七、节点升级](#七节点升级) 37 | * [八、常用命令](#八常用命令) 38 | * [九、受托人配置](#九受托人配置) 39 | 40 | ## 一、系统环境和依赖 41 | 42 | ### 1.1 系统要求 43 | 44 | - 必须是linux系统,使用 Ubuntu 14.04 以上的64位系统,推荐使用 Ubuntu 16.04以上版本系统 45 | - 必须有公网ip 46 | - 建议4核以上CPU,主频不低于2G 47 | - 建议内存8G以上 48 | - 建议公网带宽5Mb以上 49 | - 建议可用空间32GB以上的SSD硬盘 50 | 51 | ### 1.2 系统依赖安装 52 | 53 | ```sh 54 | # Install dependency package 55 | sudo apt-get install curl ntp wget git libssl-dev openssl make gcc g++ autoconf automake python build-essential -y 56 | # libsodium for ubuntu 14.04 57 | sudo apt-get install libtool -y 58 | # libsodium for ubuntu 16.04 59 | sudo apt-get install libtool libtool-bin -y 60 | ``` 61 | 62 | ### 1.3 Node.js 安装 63 | 64 | ASCH v1.5基于Node.js v10.14开发,**最低要求为v10.14**(推荐使用当前最新LTS版本:v10.15.1)。在安装 node.js 时一定要注意版本是否符合要求。建议使用 nvm 管理版本。 65 | 66 | ```sh 67 | # Install nvm 68 | curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash 69 | 70 | # This loads nvm 71 | export NVM_DIR="$HOME/.nvm" 72 | [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" 73 | [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion 74 | 75 | # Install node and npm for current user. 76 | nvm install v10 77 | 78 | # check node version and it should be v10.x.x 79 | node --version 80 | ``` 81 | 82 | ## 二、Asch Mainnet 节点安装 83 | 84 | Mainnet 默认端口为8192, P2P 端口为8193。如果开启了防火墙,请确保放行此两个端口的出入数据(TCP协议) 85 | 86 | ### 2.1 下载安装包并解压 87 | 88 | ```sh 89 | wget http://china.aschcdn.com/asch-linux-latest-mainnet.tar.gz 90 | tar zxvf asch-linux-latest-mainnet.tar.gz 91 | cd asch-linux-1.4.2-mainnet // 不同版本的安装包解压出来的目录名不同,此处为1.4.2 92 | ``` 93 | 94 | ### 2.2 修改config.json 95 | 96 | ```sh 97 | vim config.json 98 | 99 | #修改 publicIp 为自己服务器的公网 IP 100 | ``` 101 | 102 | ### 2.3 下载数据库快照并解压替换 103 | 104 | 主网数据库较大,不建议从头开始同步。可以下载数据库快照,直接解压后替换 asch 目录下的 data 目录。 105 | 106 | ```sh 107 | wget http://china.aschcdn.com/blockchain-mainnet-snapshot.tar.gz 108 | tar zvxf blockchain-mainnet-snapshot.tar.gz 109 | ``` 110 | 111 | ### 2.4 启动节点,监听区块同步情况 112 | 113 | 执行 114 | `./aschd start` 115 | 116 | 此时可以监听日志(位于logs/debug.yyyyMMdd.log)查看日志信息或者通过接口 `http://yourip:8192/api/blocks/getHeight`来查看区块高度是否增长。 117 | 118 | ## 三、Asch Testnet 节点安装 119 | 120 | Testnet 默认端口为4096, P2P 端口为4097。如果修改了端口,请两者一并修改,P2P 端口 = 默认端口 + 1 121 | 122 | ### 3.1 下载安装包并解压 123 | 124 | ```sh 125 | wget http://china.aschcdn.com/asch-linux-latest-testnet.tar.gz 126 | tar zxvf asch-linux-latest-testnet.tar.gz 127 | cd asch-linux-1.5.0-testnet // 不同版本的安装包解压出来的目录名不同,此处为1.5.0 128 | ``` 129 | 130 | ### 3.2 修改config.json 131 | 132 | ```sh 133 | vim config.json 134 | 135 | #修改 publicIp 为自己服务器的公网 IP 136 | ``` 137 | 138 | ### 3.3 下载数据库快照并解压替换 139 | 140 | 主网数据库较大,不建议从头开始同步。可以下载数据库快照,直接解压后替换 asch 目录下的 data 目录。 141 | 142 | ```sh 143 | wget http://china.aschcdn.com/blockchain-testnet-snapshot.tar.gz 144 | tar zvxf blockchain-testnet-snapshot.tar.gz 145 | ``` 146 | 147 | ### 3.4 启动节点,监听区块同步情况 148 | 149 | 执行 150 | `./aschd start` 151 | 152 | 此时可以监听日志(logs/debug.2018xxxx.log)或者通过接口 `http://yourip:4096/api/blocks/getHeight`来查看区块高度是否增长。 153 | 154 | ## 四、Asch Localnet 节点安装 155 | 156 | Localnet 默认端口为4096, P2P 端口为4097。如果修改了端口,请两者一并修改,P2P 端口 = 默认端口 + 1 157 | 158 | ### 4.1 下载安装包并解压 159 | 160 | ```sh 161 | wget http://china.aschcdn.com/asch-linux-latest-localnet.tar.gz 162 | tar zxvf asch-linux-latest-localnet.tar.gz 163 | #不同版本的安装包解压出来的目录名不同,此处为1.4.2 164 | cd asch-linux-1.4.2-localnet 165 | ``` 166 | 167 | ### 4.2 修改config.json 168 | 169 | ```sh 170 | vim config.json 171 | 172 | # 修改 publicIp 为自己服务器的公网 IP 或局域网 IP 173 | ``` 174 | 175 | ### 4.3 启动节点,监听区块同步情况 176 | 177 | 执行 178 | `./aschd start` 179 | 180 | 此时可以监听日志(logs/debug.2018xxxx.log)或者通过接口 `http://yourip:4096/api/blocks/getHeight`来查看区块高度是否增长。 181 | 182 | ### 4.4 创世账户 183 | 184 | 在 localnet 里,创世账户会有1亿个初始 XAS。创世账户主密码为: 185 | 186 | `stone elephant caught wrong spend traffic success fetch inside blush virtual element` 187 | 188 | ## 五、源码安装 189 | 190 | 下面以安装 Mainnet 为例,演示如何通过源码安装 Mainnet 节点,请在安装前确保[系统环境和依赖](#一系统环境和依赖)安装完成 191 | 192 | ### 5.1 克隆源码到本地 193 | 194 | ```sh 195 | git clone https://github.com/AschPlatform/asch 196 | ``` 197 | 198 | ### 5.2 安装依赖 199 | 200 | ```sh 201 | npm install 202 | ``` 203 | 204 | **备注**: 此处依赖较多,可能需要较长时间 205 | 206 | ### 5.3 修改 app.js 207 | 208 | ```javascript 209 | //搜索testnet,修改为 mainnet。修改后的结果如下: 210 | appConfig.netVersion = process.env.NET_VERSION || 'mainnet' 211 | ``` 212 | 213 | ### 5.4 覆盖config.json 214 | 215 | 默认的config.json 是用于 localnet 调试,Mainnet 需要修改。 216 | 217 | ```sh 218 | cp config-mainnet.json config.json 219 | ``` 220 | 221 | 修改 config.json 里的 publicIp 字段为自己服务器的 IP 地址。 222 | 223 | ### 5.5 创建依赖目录 224 | 225 | ```sh 226 | mkdir -p public/dist 227 | mkdir -p data/contracts 228 | mkdir chains 229 | ``` 230 | 231 | ### 5.6 配置网页客户端 232 | 233 | ```sh 234 | # 下载前端源码 235 | git clone https://github.com/AschPlatform/asch-frontend-2.git 236 | # 安装包管理器yarn 237 | npm install -g yarn 238 | # 安装依赖包 239 | yarn install 240 | # 编译 dev: localnet, test: testnet, pro: mainnet 241 | yarn pro 242 | # 把编译后的结果拷至 asch 主目录下的 public/dist目录中 243 | cp -r dist/spa-mat/* ../asch/src/public/dist 244 | # 详细内容请参考前端项目内的文档 245 | ``` 246 | 247 | ### 5.7 下载快照并解压 248 | 249 | ```sh 250 | cd asch 251 | wget http://47.75.26.122/blockchain-mainnet-snapshot.tar.gz 252 | tar zvxf blockchain-mainnet-snapshot.tar.gz 253 | ``` 254 | 255 | ### 5.8 启动节点 256 | 257 | ```sh 258 | ./aschd start 259 | ``` 260 | 261 | ## 六、常见错误处理 262 | 263 | ### 6.1 网页客户端无法访问 264 | 265 | 网页客户端访问地址为:`http://your_ip:your_port`, Mainnet 端口默认为8192, Testnet 以及 Localnet 默认为 4096. 266 | 267 | 排查步骤: 268 | 269 | 1. 查看是否改了config.json里的port字段 270 | 2. 查看防火墙是否放行端口 271 | 3. 查看节点是否启动,执行命令`./aschd status`, 如果没有启动则显示`Asch server is not running`,此时执行`./aschd start`即可 272 | 273 | ### 6.2 受托人节点无法生产区块 274 | 275 | 排查步骤: 276 | 277 | 1. 从网页客户端查看受托人排名是否进入前21 278 | 2. 使用下面的命令搜索错误日志`grep Failed logs/debug.log`,如果出现字样`Failed to get public ip, block forging MAY not work!`说明公网ip没有自动获取到,需要手动配置。 279 | 3. 使用下面的命令搜索错误日志`grep error logs/debug.log`如果出现字样`Failed to load delegates: Account xxxxxxxxx not found`。说明你配置的账户密钥还没有注册成为受托人,或者注册成为受托人之前就启动了服务,这时重启服务即可 280 | 281 | **注意** 如果你的节点正在同步区块,不要立即重启,等同步完成了再重启 282 | 283 | ```sh 284 | ./aschd restart 285 | ``` 286 | 287 | 正常情况下应该会出现如下log 288 | 289 | ```sh 290 | grep Forging logs/debug.log 291 | 292 | #Forging enabled on account: xxxxxxxxxxxxxx 293 | ``` 294 | 295 | ### 6.3 无法同步区块(卡块) 296 | 297 | 对比自己节点区块高度和最新区块高度。[最新区块高度](https://wallet.asch.cn/api/blocks/getHeight)。 如果发现自己节点的高度一直落后且不增长,可以断定为自己的节点没有同步区块。 298 | 299 | 解决方法: 300 | 301 | 1. 升级到最新版本并重启 302 | 303 | ```sh 304 | ./aschd upgrade 305 | ./aschd start 306 | ``` 307 | 308 | 2. 重建 309 | 310 | ```sh 311 | ./aschd rebuild 312 | ``` 313 | 314 | ## 七、节点升级 315 | 316 | 在安装完节点以后,后续节点的升级可以通过简单的`./aschd upgrade`来完成,不必重复安装。 317 | 318 | 进入 asch 目录执行命令: 319 | 320 | ```sh 321 | ./aschd upgrade 322 | ./aschd start 323 | ``` 324 | 325 | ## 八、常用命令 326 | 327 | ```sh 328 | # 启动节点 329 | ./aschd start 330 | 331 | # 停止节点 332 | ./aschd stop 333 | 334 | # 查看节点运行状态 335 | ./aschd status 336 | 337 | # 重启节点 338 | ./aschd restart 339 | 340 | # 升级节点 341 | ./aschd upgrade 342 | 343 | # 重新同步区块 344 | ./aschd rebuild 345 | 346 | # 查看节点版本 347 | ./aschd version 348 | 349 | # 开启区块生产(仅供受托人使用) 350 | ./aschd enable "your sercret" 351 | 352 | # 查看log 353 | tail -f logs/debug.201xxxxx.log 354 | ``` 355 | 356 | ## 九、受托人配置 357 | 358 | 使用文本编辑工具(比如 vim)打开config.json, 找到secret字段,将你的受托人主密码填进去即可,该字段为 json 字符串数组,一台机器可以配置多个,但不能重复。 359 | 360 | **注意** 不管运行了几个节点,请不要重复配置相同的受托人主密码 361 | 362 | 执行以下命令: 363 | 364 | ```sh 365 | # 重启节点 366 | ./aschd restart 367 | 368 | # 打开生产区块开关 369 | ./aschd enable "your sercret" 370 | ``` 371 | -------------------------------------------------------------------------------- /manual/zh-cn.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/manual/zh-cn.pdf -------------------------------------------------------------------------------- /pics/WX20180816-173409.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/pics/WX20180816-173409.png -------------------------------------------------------------------------------- /pics/WX20180816-173442.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/pics/WX20180816-173442.png -------------------------------------------------------------------------------- /pics/WX20180816-174419@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/pics/WX20180816-174419@2x.png -------------------------------------------------------------------------------- /pics/WX20180816-185028@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/pics/WX20180816-185028@2x.png -------------------------------------------------------------------------------- /side-chain/common_dapp_dev_problems_en.md: -------------------------------------------------------------------------------- 1 | # Common DApp Development Problems 2 | 3 | Table of Contents 4 | ================= 5 | 6 | 7 | 8 | - [Common DApp Development Problems](#common-dapp-development-problems) 9 | - [Overview](#overview) 10 | - [**DApp is not starting**](#dapp-is-not-starting) 11 | - [**Incorrect peers in config.json**](#incorrect-peers-in-configjson) 12 | - [**DApp needs right folder structure**](#dapp-needs-right-folder-structure) 13 | - [**Is DApp correctly registered and installed**](#is-dapp-correctly-registered-and-installed) 14 | - [**Directory asch/public/dist/chains must exist**](#directory-aschpublicdistchains-must-exist) 15 | - [**Missing length property in conjunction with string type of new DApp model**](#missing-length-property-in-conjunction-with-string-type-of-new-dapp-model) 16 | - [**DApp is not producing blocks**](#dapp-is-not-producing-blocks) 17 | - [**Not enough DApp delegates in config.json**](#not-enough-dapp-delegates-in-configjson) 18 | - [**Transaction failed**](#transaction-failed) 19 | - [**Depending transaction not verified**](#depending-transaction-not-verified) 20 | - [**Sending transaction to wrong API endpoint**](#sending-transaction-to-wrong-api-endpoint) 21 | - [**Can not register custom DApp contracts**](#can-not-register-custom-dapp-contracts) 22 | - [**Contract number must be above 1000**](#contract-number-must-be-above-1000) 23 | - [**Contract is not pointing to the right file and function**](#contract-is-not-pointing-to-the-right-file-and-function) 24 | - [**Request failed with status code 404**](#request-failed-with-status-code-404) 25 | - [**Check correct Dapp-Name in request URL**](#check-correct-dapp-name-in-request-url) 26 | - [**Can not run npm install in asch directory**](#can-not-run-npm-install-in-asch-directory) 27 | - [**Parent directory has space in its name**](#parent-directory-has-space-in-its-name) 28 | - [**Can not reach ASCH blockchain**](#can-not-reach-asch-blockchain) 29 | - [**Check port and configuration**](#check-port-and-configuration) 30 | 31 | 32 | 33 | 34 |

35 | 36 | ## Overview 37 | In this document we will present common DApp development problems and their respective solution. 38 | 39 | 40 | __Where is my DApp installed__ 41 | Your DApp is installed in your `asch/` directory under `asch/chains/your-dapp-name/` with the dapp-name you registered the DApp with. This is also the place where you can find the DApp log files (`logs/`). 42 | 43 | All registerd DApps: `curl http://localhost:4096/api/v2/transactions?type=200` 44 | All installed DApps: `curl http://localhost:4096/api/chains/installed` 45 | 46 | __Log Files__ 47 | To access the log files of your DApp, go to `asch/chains/your-dapp-name/logs/debug.20180826.log`. To access the log files of your Mainchain, go to `asch/logs/debug.20180826.log`. 48 | 49 | __General Information__ 50 | If we talk about a file, then only the file counts that the ASCH blockchain and your DApp is using (the file your DApp is using in `asch/chains/your-dapp-name`). So be sure to have the right files at the right place. Restart the ASCH node if you changed anything. 51 | 52 | >NOTE: 53 | `config.json` = `asch/chains/your-dapp-name/config.json` 54 | 55 | 56 |

57 | 58 | ## **DApp is not starting** 59 | 60 | ### **Incorrect peers in config.json** 61 | 62 | Don't provide an empty `peers` array in the `config.json` file. Remove the `peers` property or specify at least one peer: 63 | 64 | Remove the `peers` property: 65 | ```diff 66 | - { 67 | - "peers": [], 68 | - "secrets": [ 69 | - "flame bottom dragon rely endorse garage supply urge turtle team demand put", 70 | - "thrive veteran child enforce puzzle buzz valley crew genuine basket start top", 71 | - "black tool gift useless bring nothing huge vendor asset mix chimney weird", 72 | - ] 73 | - } 74 | + { 75 | + "secrets": [ 76 | + "flame bottom dragon rely endorse garage supply urge turtle team demand put", 77 | + "thrive veteran child enforce puzzle buzz valley crew genuine basket start top", 78 | + "black tool gift useless bring nothing huge vendor asset mix chimney weird", 79 | + ] 80 | + } 81 | ``` 82 | 83 | Or specify at least one peer: 84 | ```diff 85 | - { 86 | - "peers": [], 87 | - "secrets": [ 88 | - "flame bottom dragon rely endorse garage supply urge turtle team demand put", 89 | - "thrive veteran child enforce puzzle buzz valley crew genuine basket start top", 90 | - "black tool gift useless bring nothing huge vendor asset mix chimney weird", 91 | - ] 92 | - } 93 | + { 94 | + "peers": [{"ip":"127.0.0.1","port":4096}], 95 | + "secrets": [ 96 | + "flame bottom dragon rely endorse garage supply urge turtle team demand put", 97 | + "thrive veteran child enforce puzzle buzz valley crew genuine basket start top", 98 | + "black tool gift useless bring nothing huge vendor asset mix chimney weird", 99 | + ] 100 | + } 101 | ``` 102 | 103 |

104 | 105 | ### **DApp needs right folder structure** 106 | 107 | The minimum folder configuration is listed below: 108 | 109 | ![img](../assets/common-dapp-problems/min_folder_structure.png) 110 | 111 | 112 | ### **Is DApp correctly registered and installed** 113 | Make sure, that that your Dapp is correctly located under `asch/chains/your-dapp-name`. Double check all installed DApps: `curl http://localhost:4096/api/chains/installed` 114 | 115 | ![img](../assets/common-dapp-problems/dapp_install_location.png) 116 | 117 | 118 | ### **Directory asch/public/dist/chains must exist** 119 | 120 | Make sure that the `asch/public/dist/chains` exists. 121 | 122 | ![img](../assets/common-dapp-problems/asch_public_dist_chains_dir.png) 123 | 124 | ### **Missing length property in conjunction with string type of new DApp model** 125 | 126 | In the DApp directory under the `model/` directory are definitions for all custom table fields. If you declare a column with the type `string` then you __must__ also provide the `length` property for this column! 127 | 128 | Wrong: 129 | ```js 130 | module.exports = { 131 | name: 'articles', 132 | fields: [ 133 | { 134 | name: 'tid', 135 | type: 'String' 136 | } 137 | ] 138 | } 139 | ``` 140 | 141 | Right: 142 | ```js 143 | module.exports = { 144 | name: 'articles', 145 | fields: [ 146 | { 147 | name: 'tid', 148 | type: 'String', 149 | length: 64 150 | } 151 | ] 152 | } 153 | ``` 154 | 155 |

156 | 157 | ## **DApp is not producing blocks** 158 | 159 | ### **Not enough DApp delegates in config.json** 160 | 161 | Be sure to have enough DApp delegates secrets in your `config.json` file (in your productive DApp directory under `asch/chains/your-dapp-name`). Restart the ASCH node afterwards. 162 | 163 | __NOTE__ 164 | Specify the secrets of the DApp delegates which were used during the Dapp registration. 165 | 166 | 167 | ```diff 168 | - { 169 | - "peers": [{"ip":"127.0.0.1","port":4096}], 170 | - "secrets": [ 171 | - ] 172 | - } 173 | + { 174 | + "peers": [{"ip":"127.0.0.1","port":4096}], 175 | + "secrets": [ 176 | + "flame bottom dragon rely endorse garage supply urge turtle team demand put", 177 | + "thrive veteran child enforce puzzle buzz valley crew genuine basket start top", 178 | + "black tool gift useless bring nothing huge vendor asset mix chimney weird", 179 | + "ribbon crumble loud chief turn maid neglect move day churn share fabric", 180 | + "scan prevent agent close human pair aerobic sad forest wave toe dust" 181 | + ] 182 | + } 183 | ``` 184 | 185 | 186 |

187 | 188 | ## **Transaction failed** 189 | 190 | ### **Depending transaction not verified** 191 | Your transaction didn't get processed because it depends upon another transaction that wasn't confirmed yet. 192 | 193 | > __Solution:__ 194 | > Wait for __10 seconds__ for the previous transaction to get confirmed and after that send your transaction again. A block gets forged every 10 seconds. As long as the previous transaction can be found in the unconfirmed transactions (`http://localhost:4096/api/transactions/unconfirmed`) you need to wait. 195 | 196 | 197 | ### **Sending transaction to wrong API endpoint** 198 | 199 | With the multitude of API endpoints it is not always easy to use the correct API endpoint: 200 | 201 | Mainchain: 202 | - Signed (HTTP __POST__): `http://localhost:4096/peer/transaction` 203 | - Unsigned (HTTP PUT): `http://localhost:4096/api/transactions` 204 | 205 | DApp: 206 | - Signed (HTTP PUT): `http://localhost:4096/api/chains/your-dapp-name/transactions/signed` 207 | - Unsigned (HTTP PUT): `http://localhost:4096/api/chains/your-dapp-name/transactions/unsigned` 208 | 209 | 210 | 211 |

212 | 213 | ## **Can not register custom DApp contracts** 214 | 215 | ### **Contract number must be above 1000** 216 | 217 | Contract aliases (numbers) below 1000 are reserved for DApp in-built contracts. Use an aliases above 1000. 218 | 219 | ```diff 220 | # init.js file 221 | 222 | module.exports = async function () { 223 | app.logger.info('enter dapp init') 224 | 225 | - app.registerContract(800, 'cctime.postArticle') 226 | + app.registerContract(1002, 'cctime.postArticle') 227 | 228 | } 229 | ``` 230 | 231 | ### **Contract is not pointing to the right file and function** 232 | 233 | 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`. 234 | 235 | ```js 236 | registerContract(1001, 'cctime.postArticle') 237 | ``` 238 | 239 | ![img](../assets/dapp/cctime_file.png) 240 | 241 | Documentation: [Register Contract](https://github.com/AschPlatform/asch-docs/blob/master/sdk_api/en.md#82-appregistercontracttype-name) 242 | 243 | 244 | 245 |

246 | 247 | ## **Request failed with status code 404** 248 | ### **Check correct Dapp-Name in request URL** 249 | 250 | Double check that you accesing the correct DApp. Check especially __your-dapp-name__ in your request (`http://localhost:4096/api/chains/your-dapp-name/endpoint`). 251 | 252 | See also [**Sending transaction to wrong API endpoint**](#sending-transaction-to-wrong-api-endpoint) 253 | 254 | View all installed DApps: 255 | 256 | ```bash 257 | curl http://localhost:4096/api/chains/installed 258 | 259 | # returns: 260 | { 261 | "success":true, 262 | "chains":[ 263 | { 264 | "tid":"23f3c877d9a4163d14cb90a10a8132d9b5ae2d25cf568d994720acd85a9272b1", 265 | "name":"test-rTGrJniQQEys", 266 | "address":"CNKb1p78kKY9DGT7eNfYQ4Xe2r1B9T91nB", 267 | "desc":"A hello world demo for asch dapp", 268 | "link":"https://test-wnNethfKMmTk.zip", 269 | "icon":"http://o7dyh3w0x.bkt.clouddn.com/hello.png", 270 | "unlockNumber":3, 271 | "_version_":1 272 | } 273 | ] 274 | } 275 | ``` 276 | 277 |

278 | 279 | ## **Can not run npm install in asch directory** 280 | ### **Parent directory has space in its name** 281 | 282 | If one of the parent directories of `asch` has a whitespace in its name, the `npm install` process doesn't work: 283 | 284 | Error: 285 | ``` 286 | configure: error: The build directory contains whitespaces - This can cause tests/installation to fail due to limitations of some libtool versions 287 | Makefile:61: recipe for target 'libsodium' failed 288 | make: *** [libsodium] Error 1 289 | /home/a1300/test/asch 2/node_modules/sodium/install.js:287 290 | throw new Error(cmdLine + ' exited with code ' + code); 291 | ^ 292 | ``` 293 | 294 | > __Solution:__ 295 | > Remove the whitespace in the parent's directory name 296 | 297 |

298 | 299 | ## **Can not reach ASCH blockchain** 300 | 301 | ### **Check port and configuration** 302 | If you are running ASCH on localnet the default port is `4096`. 303 | 304 | - Did you changed port configuration in the `config.json` file? 305 | - Did you run `node app.js --port 1234` command and specified another port then 4096? 306 | - Did you started ASCH with `./aschd start` as a daemon then check your `asch.pid` file and see on which port the ASCH blockchain is listening: `netstat -tulpn | grep -f asch.pid`. 307 | 308 | 309 | 310 |

311 | 312 | --------- 313 | 314 | If your problem is not represeted above, create an github issue [ASCH/issues](https://github.com/AschPlatform/asch/issues) 315 | -------------------------------------------------------------------------------- /side-chain/hello_world/de.md: -------------------------------------------------------------------------------- 1 | # Dapp Entwicklung Tutorial 1: Asch Dapp Hello World 2 | 3 | ## 1 Grundlegender Ablauf 4 | 5 | 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. 6 | 7 | Der Entwicklungsprozess einer Dapp nützt alle drei dieser Netzwerktypen: 8 | - Schritt 1: Entwickeln und Testen auf dem lokalen Rechner mittels der Localnet 9 | - Schritt 2: Das Testen der Dapp auf dem Testnet 10 | - Schritt 3: Das Deployen der Dapp auf dem Mainnet 11 | 12 | ## 2 Localnet starten 13 | 14 | Das Localnet kann gleich nach dem Download ausgeführt werden. [Asch Source-Code](https://github.com/AschPlatform/asch). 15 | 16 | ``` 17 | git clone https://github.com/AschPlatform/asch 18 | ``` 19 | Danach müssen die Installationsschritte in der README-Datei befolgt werden. 20 | 21 | ## 3 Install asch-cli 22 | 23 | ``` 24 | npm install -g asch-cli 25 | ``` 26 | HINWEIS: Verwende NICHT ```cnpm``` von TAOBAO da es dort einige **Bugs** gibt. 27 | 28 | ## 4 Erstelle eine Applikation lokal 29 | 30 | Wechsle in das Asch Source-Code Verzeichnis und stelle sicher, dass das Localnet läuft. 31 | 32 | ``` 33 | cd 34 | node app.js 35 | ``` 36 | 37 | Führe dann das Kommande ```dapps``` der ```asch-cli``` aus, um eine Applikation zu erstellen. 38 | 39 | 40 | ``` 41 | asch-cli dapps -a 42 | ``` 43 | Anschließend folgen einige Fragen welche beantwortet werden müssen damit der Genesisblock erstellt werden kann. 44 | 45 | ``` 46 | ? Enter secret of your testnet account ******************************************************************************* 47 | # 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) 48 | 49 | ? Enter second secret of your testnet account if you have 50 | # By default genesis account does not set second password, so we can just type the Enter key. 51 | 52 | ? Enter DApp name Hello Dapp 53 | # The name of DApp, we choose "Hello Dapp" 54 | 55 | ? Enter DApp description Hello world demo for asch dapp 56 | # The description of DApp, let's leave it empty. 57 | 58 | ? Enter DApp tags hello,asch,dapp 59 | # The tags of DApp. It can be empty to be searched more efficiently. 60 | 61 | ? Choose DApp category 62 | 1) Common 63 | 2) Business 64 | 3) Social 65 | 4) Education 66 | 5) Entertainment 67 | 6) News 68 | (Move up and down to reveal more choices) 69 | Answer: 70 | # The type of DApp, you can choose it according to your business type. Just input the number in front of each option. 71 | 72 | ? Enter DApp link https://github.com/sqfasd/asch-hello/archive/master.zip 73 | # Input the zip file of DApp source code (must end by zip). The installation process needs this link to download necessary source file. 74 | 75 | ? Enter DApp icon url https://www.asch.com/logo.png 76 | # The URL of DApp's icon file. 77 | 78 | ? Do you want publish a inbuilt asset in this dapp? No 79 | # Input Yes if you need an asset built in DApp. For the time being, input No. 80 | 81 | ? Enter public keys of dapp forgers - hex array, use ',' for separator 8065a105c785a08757727fded3a06f8f312e73ad40f1f3502e0232ea42e67efd 82 | # 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. 83 | 84 | Creating DApp genesis block 85 | Fetching Asch Dapps SDK 86 | Saving genesis block 87 | Saving dapp meta information 88 | Registering dapp in localnet 89 | Done (DApp id is 6299140990391157236) 90 | 91 | # Then the program can automatically register this DApp on localnet. In this case, our application ID is 6299140990391157236 92 | ``` 93 | 94 | ## 5 Die Verzeichnis Struktur 95 | Unter dem Verzeichnis `dapps` findet sich jetzt ein neues Verzeichnis dessen Name der Name der Dapp ID ist. 96 | 97 | ``` 98 | ls -1 dapps/ 99 | 100 | blockchain.json # the database description of DApp 101 | config.json # the configuration file of DApp, which mainly contains the list of seed nodes. Developers can also add other configurations in it. 102 | 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. 103 | 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. 104 | index.js # this file contains the entry of DApp 105 | init.js # this file contains the initial code of each module. 106 | LICENSE # this file describes the permit license of source code. 107 | modules # main code 108 | modules.full.json # this file indicates all the modules need to be loaded. You can add other necessary modules here. 109 | modules.genesis.json # (the simplified version of modules.full.json, currently not need) 110 | node_modules # 111 | package.json # 112 | public # this folders contains all front-end files 113 | routes.json # this file contains the configuration of http route. If you want to add new interface, you need to revise this file. 114 | ``` 115 | Keine Sorge bezüglich der Komplexität der Verzeichnisstruktur. Zur Zeit genügt es wenn wir nur einen Blick drauf werfen. 116 | 117 | Die für die Entwickler wichtige Dateien befinden sich in ```modules/contracts/```. 118 | 119 | Es gibt von Haus aus 4 verschiedene Verträge in diesem Verzeichnis. 120 | 121 | ``` 122 | ls -1 dapps//modules/contracts/ 123 | 124 | delegates.js # Delegat-Registrierungs-Vertrag 125 | insidetransfer.js # In-Chain Transfer Vertrag 126 | outsidetransfer.js # XAS Einzahlungs-Vertrag 127 | withdrawaltransfer.js # XAS Auszahlungs-Vertrag 128 | ``` 129 | Entwickler müssen nur einen neuen Vertrag erstellen um ihre Business-Logik auszuführen. 130 | 131 | ## 6 Das Genesis-Passwort für die Dapp setzen 132 | 133 | Es ist obligatorisch das Primärpasswort des Genesis-Blocks sowie die Dapp ID in die ```config.json``` Datei unter dem Punkt ```dapp``` zu schreiben. 134 | 135 | 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. 136 | 137 | ``` 138 | "params": { 139 | "6299140990391157236": [ 140 | "someone manual strong movie roof episode eight spatial brown soldier soup motor" 141 | ] 142 | } 143 | ``` 144 | 145 | ## 7 Auf die Front-End Oberfläche zugreifen 146 | 147 | Wir könnnen uns nun mit der grafischen Benutzeroberfläche für die Dapp-Entwicklung auseinander setzen. 148 | 149 | Diese findet man im Programm in der Liste der installierten Anwendungen. Alternativ dazu kann man auch mit folgender URL darauf zugreifen: ```localhost:4096/dapps/``` 150 | 151 | Für dieses Projekt zeigen wir mehrere Schritte. Einzahlen, In-Chain Transfer und Auszahlen. 152 | 153 | 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. 154 | 155 | ``` 156 | asch-cli dapps -d 157 | 158 | ? Enter secret ******************************************************************************* 159 | ? Enter amount 100 160 | ? DApp Id 6299140990391157236 161 | ? Enter secondary secret (if defined) 162 | ? Host and port localhost:4096 163 | null { success: true, transactionId: '10589988261732949004' } 164 | 10589988261732949004 165 | ``` 166 | 167 | Die Applikation aktualisiert sich alle 30 Sekunden. Nach kurzer Zeit können wir das Saldo der Ein- und Auszahlungen sehen. 168 | -------------------------------------------------------------------------------- /side-chain/hello_world/zh-cn.md: -------------------------------------------------------------------------------- 1 | # DApp 的开发及部署 2 | 3 | ## 一、概述 4 | 5 | 利用阿希提供的侧链技术,企业或者开发者可以根据自己的业务很容易的开发一个 DApp。基于阿希开发的 DApp 拥有自己独立的数据库。数据模型可以灵活设计,手续费也可以指定为自己发行的资产。开发一个 DApp 使用的编程语言为 JavaScript。 6 | 7 | 在正式开发 DApp 之前,开发者需要了解一些阿希的基本情况,详细可以参考[官网](https://www.asch.io)或者[白皮书]()。这里仅强调一下阿希的网络类型: 8 | 9 | Asch 有三种网络类型,分别是 Localnet,Testnet 以及 Mainnet。其中 Localnet 可以用于本地搭建环境进行开发和测试,Testnet 和 Mainnet 由社区进行维护,访问地址分别为 https://testnet.asch.io 和 https://mainnet.asch.io . 10 | 11 | 新的功能更新会首先发布到 Testnet 上进行测试,Testnet 在功能上基本和 Mainnet 一致。它和 Mainnet 的区别在于部署时的 magic 值不同(Testnet 的 magic 为594fe0f3, Mainnet 的 magic 为 5f5b3cf5)。另外一个区别就是 Mainnet 上的资产是有价值的,可以在交易所进行流通。Testnet 上的币没有价值,仅用于测试。如果开发者需要测试币,请联系官方团队索取。 12 | 13 | ## 二、DApp 开发的基本流程 14 | 15 | DApp 的开发流程一般为: 16 | 17 | - 第一步,在 Localnet 开发、本地调试 18 | - 第二步,部署到 Testnet 进行发布前的测试 19 | - 第三步,正式发布到 Mainnet,其他节点也可以选择安装 20 | 21 | ## 三、配置 Localnet 22 | 23 | ### 3.1 安装系统依赖 24 | 25 | 请参考文档[安装系统依赖](https://github.com/AschPlatform/asch-docs/blob/master/install/zh-cn.md#%E4%B8%80%E7%B3%BB%E7%BB%9F%E7%8E%AF%E5%A2%83%E5%92%8C%E4%BE%9D%E8%B5%96) 26 | 27 | ### 3.2 安装 Localnet 28 | 29 | 请参考文档[安装 Localnet](https://github.com/AschPlatform/asch-docs/blob/master/install/zh-cn.md#%E5%9B%9Basch-localnet-%E8%8A%82%E7%82%B9%E5%AE%89%E8%A3%85) 30 | 31 | 此时打开浏览器,输入 http://your-ip:4096,应该可以看到网页客户端界面了。 32 | 33 | 创世账户为`stone elephant caught wrong spend traffic success fetch inside blush virtual element`,登录到客户端后会有1亿 XAS。 34 | 35 | ## 四、安装 asch-cli 36 | 37 | 运行命令 38 | 39 | ```JavaScript 40 | npm install asch-cli 41 | ``` 42 | 43 | (由于最新版 asch-cli 还没有推送,大家可以使用git clone https://github.com/AschPlatform/asch-cli 克隆到本地,然后执行npm install) 44 | 45 | ## 五、生成新账户 46 | 47 | 每个 DApp 都有独立的受托人,这些受托人也是默认的记账人,他们负责区块的生产,跨链资产的中转,与此同时可以获得 DApp 内部交易的手续费。注册 DApp 的时候,我们只需要收集受托人的公钥就行,为了权力分散,最好每个秘钥分别由一个人保管。 48 | 49 | DApp 的受托人是 DApp 里非常重要的角色。这里生成的账户一定要记好。为了演示,这里使用 `asch-cli` 生成5个新账户。一个 DApp 最多有101个受托人,最少是5个。 50 | 51 | ```shell 52 | asch@asch-16:~/asch-cli$ ./bin/asch-cli crypto -g 53 | ? Enter number of accounts to generate 5 54 | [ { address: 'AL7MfrDrUCysvSotoDZ9ir2YESqRUqah4T', 55 | secret: 'code flush merit drop april theory element during avoid device large plunge', 56 | publicKey: '9cb5be153e78bfb110790a2210634da58206aabed769ebc51ad6884239995f1c' }, 57 | { address: 'APh8DfNJgiSuPVi196BgnPNVUM3KWPc7zR', 58 | secret: 'logic field kiss upper lock park wife invest effort exact poverty confirm', 59 | publicKey: 'e446e798b64d74cb4825872cc217d22d35db67d8f97e73d78d9cc9cd2b2d7214' }, 60 | { address: 'A9T6JRytQmaHrN9NAcma1TYnUhMX69iHay', 61 | secret: 'kite vapor nest net gesture present prison climb dad salon title donate', 62 | publicKey: '643d2658656feb41631d2c4800fa7c4f7d117693d789a77c89367d627ddc8fb6' }, 63 | { address: 'AEQfSifHXmQrQA9mtDKbGqA1sREPxHziJo', 64 | secret: 'parrot couple chef neglect cinnamon attitude discover lecture mask fantasy worth board', 65 | publicKey: '7bd25b08d1a3f3e61b805eac6a3bc94c2c51ae437f3eb00152317db01020d998' }, 66 | { address: 'A2fH3HzbC3f9XfhVUfhPLHwkUz5wFTnXCt', 67 | secret: 'upset angle august army problem size glow poem mandate claim toss join', 68 | publicKey: 'a3efd2079543483f6b54573f0bac9b239e20c5e7e09a173e01eefb2179e1ed8b' } ] 69 | Done 70 | ``` 71 | 72 | ## 六、生成应用模板 73 | 74 | 这一步会生成一个应用的模板目录,可以作为 DApp 开发的起点。 75 | 76 | ```shell 77 | asch@asch-16:~$ mkdir asch-dapp-demo 78 | asch@asch-16:~$ cd asch-dapp-demo 79 | asch@asch-16:~/asch-cli$ ./bin/asch-cli chain -c 80 | Copying template to the current directory ... 81 | ? Enter chain name asch-dapp-demo 82 | ? Enter chain description This is a demo DApp , used for showing how to build a DApp 83 | ? Enter chain link https://your-domain/dapp.zip 84 | ? Enter chain icon url https://your-domain/dapp.png 85 | ? Enter public keys of chain delegates - hex array, use "," for separator 9cb5be153e78bfb110790a2210634da58206aabed769ebc51ad6 86 | 884239995f1c,e446e798b64d74cb4825872cc217d22d35db67d8f97e73d78d9cc9cd2b2d7214,643d2658656feb41631d2c4800fa7c4f7d117693d789a77c 87 | 89367d627ddc8fb6,7bd25b08d1a3f3e61b805eac6a3bc94c2c51ae437f3eb00152317db01020d998,a3efd2079543483f6b54573f0bac9b239e20c5e7e09a 88 | 173e01eefb2179e1ed8b 89 | ? How many delegates are needed to unlock asset of a chain? 3 90 | Chain meta information is saved to ./chain.json ... 91 | ``` 92 | 93 | 这一步会生成一个名字为`chain.json`的文件。此时的文件目录结构应该为: 94 | 95 | ```shell 96 | asch@asch-16:~/asch-dapp-demo$ ll 97 | 总用量 36 98 | drwxrwxr-x 6 asch asch 4096 8月 16 16:29 ./ 99 | drwxr-xr-x 25 asch asch 4096 8月 16 16:27 ../ 100 | -rw-rw-r-- 1 asch asch 590 8月 16 16:26 chain.json 101 | -rw-rw-r-- 1 asch asch 23 8月 16 16:24 config.json 102 | drwxrwxr-x 2 asch asch 4096 8月 16 16:24 contract/ 103 | -rw-rw-r-- 1 asch asch 266 8月 16 16:24 init.js 104 | drwxrwxr-x 2 asch asch 4096 8月 16 16:24 interface/ 105 | drwxrwxr-x 2 asch asch 4096 8月 16 16:24 model/ 106 | drwxrwxr-x 2 asch asch 4096 8月 16 16:24 public/ 107 | ``` 108 | 109 | 注意事项: 110 | 111 | 1. `chain link`是为了方便普通用户自动安装,必须以`.zip`结尾, 如果您的 DApp 不打算开源或者没有准备好,可以把这个选项当做占位符,它所在的地址不必真实存在 112 | 2. `chain icon url`这是在阿希应用中心展示用的应用图标, 必须以`.jpg`或`.png`结尾,如果该图片无法访问,阿希应用中心会展示一个默认的图标 113 | 3. `How many delegates ...`这个选项表示从` DApp `跨链转账资产时需要多少个受托人联合签名,该数字必须大于等于3、小于等于你配置的受托人公钥个数且小于等于101,数字越大越安全,但效率会变低和费用越高 114 | 115 | ## 七、生成创世区块 116 | 117 | DApp 的创世块中可以创建内置资产,但不是必须的,内置资产无法跨链转账,只能在链内使用。在主链发行的 UIA(用户自定义资产)可以充值到任意 DApp 中,也可从 DApp 提现到主链,这是 DApp 内置资产和 UIA 最大的区别。“一链多币,一币多链”指的就是主链可以发行多个 UIA,而每个 UIA 都可以充值到多个 DApp 中。 118 | 119 | 不发行资产的情况: 120 | 121 | ```shell 122 | asch@asch-16:~/asch-dapp-demo$ ../asch-cli/bin/asch-cli chain -g 123 | ? Enter master secret of your genesis account [hidden] 124 | ? Do you want publish a inbuilt asset in this chain? No 125 | New genesis block is created at: ./genesis.json 126 | ``` 127 | 128 | 发行资产的情况 129 | 130 | ```shell 131 | asch@asch-16:~/asch-dapp-demo$ ../asch-cli/bin/asch-cli chain -g 132 | ? Enter master secret of your genesis account [hidden] 133 | ? Do you want publish a inbuilt asset in this chain? Yes 134 | ? Enter asset name, for example: BTC, CNY, USD, MYASSET CNY 135 | ? Enter asset total amount 100000000 136 | ? Enter asset precision 8 137 | New genesis block is created at: ./genesis.json 138 | ``` 139 | 140 | 此时在目录里应该生成了一个 `genesis.json` 的文件。 141 | 142 | ## 八、目录结构 143 | 144 | 下面我们分析下 DApp 的目录结构 145 | 146 | ```shell 147 | . 148 | └── asch-dapp-demo 149 | ├── blockchain.db // DApp 数据库文件,与主链的数据是分开存放的 150 | ├── chain.json 151 | ├── config.json // 应用的节点配置文件,目前主要用于配置受托人秘钥 152 | ├── contract // 合约目录 153 | │   └── domain.js // 域名合约的实现代码 154 | ├── genesis.json // 创世区块 155 | ├── init.js // 应用初始化代码,可以在该文件进行一些设置、事件注册等 156 | ├── interface // 查询接口的实现目录 157 | │   ├── domain.js // 域名查询接口实现 158 | │   └── helloworld.js 159 | ├── logs // 日志目录 160 | │   └── debug.20180816.log 161 | ├── model 162 | │   └── domain.js // 域名业务数据模型定义 163 | └── public 164 | └── index.html // 默认前端页面 165 | ``` 166 | 167 | ## 九、DApp 的开发过程 168 | 169 | 阿希创始人单青峰曾经在这个[博客里](http://blog.asch.so/2017/06/30/asch-1.3-foresight-2/)写过开发理念。在 DApp 中实现一个业务逻辑,大概步骤如下: 170 | 171 | ### 9.1 定义你的数据模型 172 | 173 | 在这个环节,你需要考虑的是在区块链中保存什么数据或状态,你的账本内容是什么、哪些字段需要建立索引来以提高客户端查询速度。 174 | DApp 有自己的 db 文件(sqlite3),位置在 chains/chainname/blockchain.db。所有的表结构定义以及数据都存在这里。这里的数据跟主链的数据是隔离的,主链的db文件在 asch 目录下。 175 | 176 | ### 9.2 实现合约逻辑 177 | 178 | 这个环节,你需要考虑的是一个事务或一个调用会修改哪些状态,比如资产余额,账户属性等。我们在 SDK 中提供了丰富的接口可供调用,具体可参考[SDK接口文档](../asch_sdk_api.md) 179 | 180 | ### 9.3 实现查询接口 181 | 182 | 在这个环节,你需要考虑的是如何给前端返回数据,比如区块、交易,各种合约业务状态的查询等。也可以可用这个通道将一些非全局状态保存到本地节点,我们会在后续章节介绍这些高级用法。 183 | 目前 DApp 有[预置的通用查询接口](../asch_ DApp _default_api.md),这些是由 asch-sandbox 提供的。另外一部分就是用户自定义的查询接口,在 chains/chainname/interface/xx.js中进行定义。 184 | 185 | ## 十、注册应用到区块链 186 | 187 | 利用 `asch-cli` 提供的 `registerchain`来完成应用到区块链的注册。 要选择一个有 XAS 的账户,这里我们使用创世账户。 188 | 189 | ```shell 190 | asch@asch-16:~/asch-dapp-demo$ ../asch-cli/bin/asch-cli -H 127.0.0.1 -P 4096 registerchain -e "stone elephant caught wrong spend traffic success fetch inside blush virtual element" -f chain.json 191 | f9ccac2a7d353f708c838cc49b54dfb31ea50e7120d5162efc6882274fca20cb 192 | ``` 193 | 194 | 此时进客户端查看,会显示 195 | 196 | ![](../../pics/WX20180816-185028@2x.png) 197 | 198 | ## 十一、部署应用 199 | 200 | 在正式部署应用之前,我们需要先修改 config.json ,添加之前生成的受托人以及 peers。其中 peers 里的 ip 要改成自己服务器的 IP 地址。 201 | 202 | ```json 203 | { 204 | "secrets": [ 205 | "code flush merit drop april theory element during avoid device large plunge", 206 | "logic field kiss upper lock park wife invest effort exact poverty confirm", 207 | "kite vapor nest net gesture present prison climb dad salon title donate", 208 | "parrot couple chef neglect cinnamon attitude discover lecture mask fantasy worth board", 209 | "upset angle august army problem size glow poem mandate claim toss join" 210 | ], 211 | "peers":[{"ip":"192.168.1.155","port":4097}] 212 | } 213 | ``` 214 | 215 | 然后执行命令: 216 | 217 | ```shell 218 | cp -r asch-dapp-demo asch-linux-1.4.3-localnet/chains/ 219 | ./aschd restart // 进入 asch 目录,重启节点 220 | ``` 221 | 222 | 此时查看主链日志,应该有如下字样 223 | `2018-08-16T17:31:25+0800 chains.js:405 (priv.launch) Launched chain[asch-dapp-demo] successfully` 224 | 225 | ## 十二、查看应用状态 226 | 227 | DApp 的登录界面为:http://192.168.1.155:4096/chains/asch-dapp-demo/, 登录后可以查看账户基本信息以及进行调用合约的操作: 228 | 229 | ![](../../pics/WX20180816-173409.png) 230 | ![](../../pics/WX20180816-173442.png) 231 | 232 | DApp 的日志目录为 asch/chains/chainname/logs/debug.2018xxxx.log 233 | 234 | ![](../../pics/WX20180816-174419@2x.png) 235 | 236 | 查看 DApp 区块高度可以访问接口:http://192.168.1.155:4096/api/chains/asch-dapp-demo/blocks/height 237 | -------------------------------------------------------------------------------- /side-chain/how_to_debug_dapps_en.md: -------------------------------------------------------------------------------- 1 | # How to debug Dapps 2 | 3 | 4 | 5 | 6 | - [How to debug Dapps](#how-to-debug-dapps) 7 | - [**Overview**](#overview) 8 | - [**Differnt Log files and their location**](#differnt-log-files-and-their-location) 9 | - [**Mainchain log file**](#mainchain-log-file) 10 | - [**Sidechain log file**](#sidechain-log-file) 11 | - [**Consult Common-Dev-Problems Document**](#consult-common-dev-problems-document) 12 | - [**Debug your Sidechain code with Chrome `ndb` Debugger**](#debug-your-sidechain-code-with-chrome-ndb-debugger) 13 | - [**Why an extra tool for Sidechain code Debugging?**](#why-an-extra-tool-for-sidechain-code-debugging) 14 | - [**Install `ndb`**](#install-ndb) 15 | - [**Open Chrome `ndb` Debugger**](#open-chrome-ndb-debugger) 16 | - [**Start Blockchain**](#start-blockchain) 17 | - [**Where is my Sidechain code?**](#where-is-my-sidechain-code) 18 | - [**Set debugger statements and Breakpoints**](#set-debugger-statements-and-breakpoints) 19 | - [**Example: Debug Contract Execution**](#example-debug-contract-execution) 20 | - [**Kill Process**](#kill-process) 21 | - [**Restart**](#restart) 22 | - [**Switch between Contexts**](#switch-between-contexts) 23 | 24 | 25 | 26 |

27 | 28 | 29 | 30 | ### **Overview** 31 | 32 | Developing Dapps is not always easy and straightforward. Problems can't always be spotted right away because the Dapp code is run by the [asch-sandbox](https://github.com/aschplatform/asch-sandbox-dist). This document tries to help make the lives of developers easy. 33 | 34 | ### **Different Log files and their location** 35 | 36 | There are different `log` files. One of these can often help to spot the problem. 37 | 38 | #### **Mainchain log file** 39 | The log files for the [ASCH](https://github.com/aschplatform/asch) Mainchain are located under `asch/logs/debug..log`. 40 | 41 | > WARNING 42 | > The log files for the ASCH mainchain are only created if the blockchain is started through `./aschd start`. If you start the blockchain in the terminal with `node app.js` then, the log files are not getting constructed. 43 | 44 | #### **Sidechain log file** 45 | 46 | The log files for every Sidechain are located under `asch/chains//logs/debug..log` 47 | 48 | ### **Consult Common-Dev-Problems Document** 49 | 50 | If your Dapp is not working, this can be due to numerous causes. Be sure to check out the [Common Dapp Dev Problems](../common_dapp_dev_problems_en.md) file. 51 | 52 | ### **Debug your Sidechain code with Chrome `ndb` Debugger** 53 | 54 | #### **Why an extra tool for Sidechain code Debugging?** 55 | 56 | Every Sidechain runs in a separate [asch-sandbox](https://github.com/aschplatform/asch-sandbox-dist) environment. 57 | 58 | If we didn't have the Chrome [ndb](https://github.com/GoogleChromeLabs/ndb) tool at hand, we would need to pass the `'['--inspect=9228', '--debug-brk']` options to the `spawn()` function (from the built-in `child_process` package). Of course with an extra port number for every Sidechain. 59 | 60 | Due to the new Chrome [ndb](https://github.com/GoogleChromeLabs/ndb) tool, we can __automatically__ connect to new child processes! No need for extra `spawn()` parameters! 61 | 62 | #### **Install `ndb`** 63 | 64 | Install the `ndb` npm package: 65 | ```bash 66 | npm install ndb --global 67 | ``` 68 | 69 | The whole installation is approximately 300 MB. 70 | 71 | 72 | #### **Open Chrome `ndb` Debugger** 73 | 74 | Open a terminal and change directories to your `asch/` directory (where your `asch` blockchain is): 75 | ```bash 76 | # change directory 77 | cd asch 78 | ``` 79 | 80 | Fire `ndb` in your `asch/` directory up: 81 | 82 | ![](../assets/dapp/debug_terminal_start_ndb.png) 83 | 84 | 85 | The `ndb` tool looks like the Chrome Debugger. You can also save files to the filesystem. 86 | 87 | ![](../assets/dapp/debug_ndb_start.png) 88 | 89 | #### **Start Blockchain** 90 | 91 | In the panel `Filesystem` on the left, you can find the `asch/app.js` file and with `Right Click` + `Run this script` you can start the ASCH blockchain: 92 | 93 | ![](../assets/dapp/debug_ndb_start_app.png) 94 | 95 | 96 | #### **Where is my Sidechain code?** 97 | 98 | You can have as many Sidechains installed on your local ASCH blockchain as you like. They are located in the `asch/chains/` directory: 99 | 100 | ![](../assets/dapp/debug_ndb_chains_dir.png) 101 | 102 | 103 | #### **Set debugger statements and Breakpoints** 104 | 105 | I want that the execution halts in the `init.js` of my sample `they-clap-dapp` Sidechain. Therefore I place a `debugger;` statement in the `asch/chains/they-clapp-dapp/init.js` file: 106 | 107 | Place `debugger;` statement in `init.js` file: 108 | ![](../assets/dapp/debug_ndb_debugger_statement.png) 109 | 110 | Start the ASCH blockchain again by executing the `app.js` file (like in point [**Start Blockchain**](#start-blockchain)). 111 | ![](../assets/dapp/debug_ndb_start_app_detail.png) 112 | 113 | 114 | The debugger hits the `debugger;` statement a few seconds after the ASCH blockchain started: 115 | 116 | ![](../assets/dapp/debug_ndb_debugger_statement_hit.png) 117 | 118 | 119 | #### **Example: Debug Contract Execution** 120 | 121 | > INFO 122 | > In this example, we are using the [CCTime](https://github.com/aschplatform/cctime) Sidechain code but we gave our Sidechains random names, because Sidechain-names must be unique (in this case we named our Sidechain `they-clap-dapp`). 123 | 124 | Most times we want to debug a Sidechain contract. Therefore, we set a __Breakpoint__ in the `asch/chains/they-clapp-dapp/contract/cctime.js` file: 125 | 126 | ![](../assets/dapp/debug_ndb_contract_breakpoint.png) 127 | 128 | Then, we sign a transaction and send it to the `they-clapp-dapp` Sidechain: 129 | 130 | ```js 131 | const aschJS = require('asch-js') 132 | const axios = require('axios') 133 | 134 | const secret = 'sentence weasel match weather apple onion release keen lens deal fruit matrix'; 135 | 136 | const type = 1000 137 | const fee = String(0.1 * 1e8) 138 | 139 | let title = 'Superb article', 140 | articleUrl = '', 141 | text = 'Very long text...', 142 | tags = 'debugging,javascript,ndb' 143 | 144 | const options = { 145 | fee: fee, 146 | type: type, 147 | args: JSON.stringify([title, articleUrl, text, tags]) 148 | }; 149 | 150 | let trs = aschJS.dapp.createInnerTransaction(options, secret); 151 | 152 | console.log(JSON.stringify(trs, null, 2)) 153 | 154 | let dappName = 'they-clap-dapp' 155 | let url = `http://localhost:4096/api/chains/${dappName}/transactions/signed` 156 | 157 | let headers = { 158 | headers: { 159 | 'Content-Type': 'application/json' 160 | } 161 | } 162 | 163 | axios.put(url, { transaction: trs }, headers) 164 | .then((response) => { 165 | console.log(`${JSON.stringify(response.data)}`) 166 | }) 167 | .catch(erro => { 168 | console.log('error occured') 169 | console.log(JSON.stringify(erro.message)) 170 | }) 171 | ``` 172 | 173 | 174 | #### **Kill Process** 175 | 176 | On the Chrome [ndb](https://github.com/GoogleChromeLabs/ndb) tool, the buttons for stopping the debugging are not so easy to spot. 177 | 178 | On the right side under `Node processes`: 179 | ![](../assets/dapp/ndb_debug_right_side.png) 180 | 181 | Every process must be killed with the __white square__ button: 182 | ![](../assets/dapp/ndb_debug_kill_processes.png) 183 | 184 | 185 | #### **Restart** 186 | 187 | Beside killing the process, you can also __restart__ the debugging with the latest configuration with the keyboard shortcut `Ctrl + R` 188 | 189 | 190 | #### **Switch between Contexts** 191 | 192 | When you have at least one Sidechain running, then, you have different Javascript Execution Environments to switch between. This step is normally not necessary because the `ndb` is smart enough to switch automatically to the Context where the `debugger;` statement or the `Breakpoint` was hit. 193 | 194 | However, if you want to pause the execution in the right JavaScript process you need to __switch__ context: 195 | 196 | ![](../assets/dapp/debug_ndb_switch_context.png) 197 | 198 | -------------------------------------------------------------------------------- /side-chain/introduction/de.md: -------------------------------------------------------------------------------- 1 | # Einführung in die Asch Dapp Entwicklung 2 | 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. 3 | 4 | ## Die Unabhängigkeit einer Sidechain 5 | 6 | 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. 7 | 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. 8 | 9 | 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. 10 | 11 | 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. 12 | 13 | 14 | ## Die Flexibilität der Sidechain 15 | 16 | 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. 17 | 18 | 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. 19 | 20 | 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. 21 | 22 | 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)). 23 | 24 | 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. 25 | 26 | 27 | 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. 28 | 29 | 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. 30 | 31 | Schauen wir uns den folgendne Absatz an: 32 | 33 | 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. 34 | 35 | ![sidechain deploy architecture](../../assets/sidechain-deploy.png) 36 | 37 | ## Die Wechselwirkung zwischen Mainchain und Sidechain 38 | 39 | 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. 40 | 41 | 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. 42 | 43 | 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. 44 | 45 | ## Produktivität 46 | 47 | 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. 48 | 49 | 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. 50 | 51 | 52 | Die folgenden Module sind von vorhinein in Asch integriert: 53 | 54 | ![inbuilt modules](../../assets/inbuilt-modules.png) 55 | 56 | ## Sicherheitslösung 57 | 58 | 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. 59 | 60 | 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. 61 | 62 | 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. 63 | 64 | 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. 65 | 66 | ![process structure](../../assets/process-structure.png) 67 | 68 | ## Tutorials 69 | 70 | Hier folgen einige Tutorials welche einen schnellen Start für Entwickler ermöglichen sollen. 71 | 72 | - [Dapp Entwicklungs Tutorial 1: Asch Dapp Hello World](./dapp_docs/1_hello_en.md) 73 | Dieses Tutorial zeigt wie man eine einfache Sidechain-Applikation erstellt und veröffentlicht. Desweiteren wird die Code-Struktur des Sidechain-Frameworks beleuchtet. 74 | 75 | - [Dapp Entwicklungs Tutorial 2: Asch Dapp Asset](./dapp_docs/2_asset_en.md) 76 | Dieses Tutorial zeigt wie man ein Asset auf der Sidechain erstellt. Weiters wird die Kommunikation zwischen Front- und Backend analysiert. 77 | 78 | - [Dapp Entwicklungs Tutorial 3: Asch Dapp Mini DAO](./dapp_docs/3_mini_dao_en.md) 79 | 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. 80 | 81 | - [Dapp Entwicklungs Tutorial 4: Asch Dapp Dice Game](./dapp_docs/4_dice_game_en.md) 82 | 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. 83 | 84 | - [Dapp Entwicklungs Tutorial 5: Eine Dapp veröffentlichen](./dapp_docs/5_dapp_publish_en.md) 85 | Dieses Tutorial zeigt wie man eine Applikation online registriert (Testchain, Hauptchain) und wie man diese installiert / deinstalliert. 86 | -------------------------------------------------------------------------------- /side-chain/introduction/en.md: -------------------------------------------------------------------------------- 1 | # Introducing Asch Dapp Development 2 | 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. 3 | 4 | ## The Independency of Sidechain 5 | 6 | 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. 7 | 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. 8 | 9 | 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. 10 | 11 | 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. 12 | 13 | 14 | ## The Flexibility of Sidechain 15 | 16 | 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. 17 | 18 | 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. 19 | 20 | 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. 21 | 22 | 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)) 23 | 24 | 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. 25 | 26 | 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. 27 | 28 | Let's see the following graph 29 | 30 | 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. 31 | 32 | ![sidechain deploy architecture](../../assets/sidechain-deploy.png) 33 | 34 | ## The Reciprocity of Main Chain and Sidechain 35 | 36 | 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. 37 | 38 | 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. 39 | 40 | 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. 41 | 42 | 43 | ## Solution of Productivity 44 | 45 | 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. 46 | 47 | 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. 48 | 49 | The following is modules built in Asch platform. 50 | 51 | ![inbuilt modules](../../assets/inbuilt-modules.png) 52 | 53 | ## Solution of Security 54 | 55 | 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. 56 | 57 | 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. 58 | 59 | 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. 60 | 61 | 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. 62 | 63 | 64 | ![process structure](../../assets/process-structure.png) 65 | 66 | ## Tutorials 67 | 68 | Here are some tutorials from the begining which will be helpful to the developers to rapidly develop applications. 69 | 70 | - [Dapp Development Tutorial 1: Asch Dapp Hello World](../hello_world/en.md) 71 | This tutorial shows how to create and publish a basic sidechain application, as well as introduces the source code structure of sidechain framework. 72 | 73 | - [Dapp Development Tutorial 2: Asch Dapp Asset] 74 | This tutorial shows how to designate a built-in asset to sidechain and then analyse communication interface between the front end and back end. 75 | 76 | 77 | - [Dapp Development Tutorial 3: Asch Dapp Mini DAO](../mini-dao/en.md) 78 | 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. 79 | 80 | - [Dapp Development Tutorial 4: Asch Dapp Dice Game] 81 | 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. 82 | 83 | - [Dapp Development Tutorial 5: Publish Dapp online] 84 | This tutorial shows how to register the application to online system (testnet, mainnet and how to install/uninstall it. 85 | -------------------------------------------------------------------------------- /side-chain/introduction/zh-cn.md: -------------------------------------------------------------------------------- 1 | # Asch Dapp开发介绍 2 | 3 | 我们在白皮书里提到过,asch使用的是不同于以太坊和比特币的侧链架构,dapp是运行在侧链上的,每条侧链对应一个dapp。(Asch主链类比IOS生态系统,每个节点都是一部iphone,所有的dapp组成了appstore,每个节点可以自由选择安装哪些dapp) 4 | 5 | ## 侧链的独立性 6 | 7 | 侧链架构的好处是代码和数据独立,不增加主链的负担,避免数据过度膨胀,实际上是一种天然的分片机制。 8 | 侧链有独立的区块链(具有和一般区块链相同的特征属性),有独立的受托人或者说见证人,同时也有独立的节点网络,就是说一个侧链产生的区块只会在所有安装了该侧链的节点之间进行广播。 9 | 10 | 独立性既是优点,也是缺点。开发者完成了dapp的开发工作之后,还要考虑运维,也就是说要寻找足够的节点来运行它(Asch侧链默认用的DPOS共识算法,对运行节点的受托人会给予一定的token奖励,类比BTC的挖矿,所以找人去运行dapp是很容易的事情),否则难以维持足够的安全性。 11 | 从这一点来看,与以太坊相比,是缺陷,以太坊上一旦发布一个dapp,所有的节点都可以为它工作,并为它提供安全保障。 12 | 13 | ## 侧链的灵活性 14 | 15 | 但是侧链架构依然有存在的必要性,因为并非所有的应用都需要那么高的安全性。Asch给用户提供了一种可以选择的灵活性。 16 | 比方说,假设asch有1000个节点,那么其中有的dapp比较重要,需要500个节点来运行它,有的dapp不那么重要,可能只需要100个节点,这完全是由用户和开发者决定的。 17 | 在以太坊上,则只能选择一种,即全部节点都来运行它。据说以太坊也打算实现一种分片的机制,实际上这在asch系统中是一个早就解决了的问题。 18 | 另外,对于比较重要的、安全性要求较高的应用,我们依然可以选择在主链上开发(就是像以太坊那样dapp运行在所有的Asch主链的节点上),但是不可能对所有开发者开放这种权力,还是为了避免主链的膨胀和不可控(DAO事件)。 19 | 20 | 侧链的灵活性还表现在,所有的区块链参数是可以定制的,简单的比如区块间隔、区块奖励、交易费的去向等,高级用户还可以修改共识算法(默认是DPOS共识算法)。 21 | 不过最重要的还是业务逻辑,侧链上可以轻易的开发出与你的业务相关的交易类型或者智能合约。 22 | 这一点是与侧链的发明者blockstreams不同,blockstreams的侧链,只是一个不同的货币系统而已,开发新型交易和智能合约很不容易。 23 | 24 | 如下图所示 25 | 黑色的圆圈代表一个节点,64个节点组成了主链的网络。红色方框之内的是1号侧链,其侧链网络是由12个节点组成。蓝色方框之内的是2号侧链,其网络是由36个节点组成。 26 | 27 | ![sidechain deploy architecture](../../assets/sidechain-deploy.png) 28 | 29 | ## 主链与侧链的互利关系 30 | 31 | Asch的主链与侧链之间是互惠互利的关系,asch为侧链提供基础设施,比如数据库写入的api,网络通讯api,加密api等等,侧链则可以为asch主链补充更多的节点,以壮大整个系统。 32 | 侧链的开发者不需要提供所有的机器,可以利用已经存在主链节点,只需要节点主人安装该应用即可。 33 | 另外,主链的代币XAS可以转入侧链中,由于XAS可以在交易所交易,就相当于为侧链的资产提供了一种价值的媒介。 34 | 开发者在侧链发行一种资产后,可以直接与XAS兑换,不需要考虑交易平台的问题。 35 | 36 | ## 解决生产力问题 37 | 38 | 我们在[ASCH_DAPP_SDK](./asch_sdk_api.md)中为侧链提供了一套模板,或者说脚手架,也可以叫做开发框架,侧链的大部分底层功能都是写好的,dapp开发者只需要关心具体的业务逻辑,在这一点上,与以太坊的dapp开发难度相当。 39 | Asch的侧链框架使用的语言是nodejs,我们内置了不少常用的库让开发者直接使用,当然开发者也可以自行安装所需要的,有一个庞大的javascript社区作为后盾。 40 | 41 | 下面是asch内置的模块 42 | 43 | ![inbuilt modules](../../assets/inbuilt-modules.png) 44 | 45 | ## 解决安全问题 46 | 47 | 这里的安全问题与上面提到的因为节点不足导致的问题不一样,这里说的安全问题是指侧链代码对安装者造成侵犯的问题。 48 | 我们希望每一个asch节点都能安装一个侧链,而且asch节点的主人无需信任侧链的开发者。这就需要提供一种安全防范的措施,比如,防止侧链代码肆意读取文件系统、进行网络操作。 49 | 在asch系统中,侧链代码会以子进程的方式启动,子进程首先加载一个使用沙箱机制隔离的javascript虚拟机,这个js虚拟机就是没有```require```以及任何多余模块的裸体虚拟机。 50 | 然后我们为这个虚拟机植入一个定制的```require```和一些常用且安全的模块, 最后再加载侧链的代码。 51 | 我们还通过进程间通讯的方式提供一系列的api。 52 | 这样,侧链的框架就拥有了足够多的api,同时侧链的安装者也没有任何风险。 53 | 54 | ![process structure](../../assets/process-structure.png) 55 | 56 | ## 实例教程 57 | 58 | 接下来我们会提供一个由浅入深的教程,帮助开发者快速入门。 59 | 60 | - [Dapp开发教程一 Asch Dapp Hello World](./dapp_docs/1_hello.md) 61 | 这个文档会教你如何创建并发布一个基础的侧链应用,并介绍侧链框架的源码结构 62 | - [Dapp案例一 CCTime的后端源码](https://github.com/AschPlatform/cctime) 这是基于[ASCH_DAPP_SDK](./asch_sdk_api.md)开发的第一个Dapp,开发者可以当做示例代码阅读,[前端代码链接](https://github.com/AschPlatform/cctime-frontend) 63 | -------------------------------------------------------------------------------- /side-chain/mini_dao/en.md: -------------------------------------------------------------------------------- 1 | # Dapp Development Tutorial 3: Asch Dapp Mini DAO 2 | This tutorial shows how to create a new type transaction or smart contract, and demonstrates a mini dao project with project management and voting function. The complete source of the Dapp can be downloaded at [Asch Mini DAO](https://github.com/bassjobsen/asch-mini-dao). 3 | 4 | With this Dapp one can add projects (title and description) and gain votes for it. 5 | 6 | ## Setup your environment 7 | 8 | ### Install ASCH 9 | 10 | ``` 11 | # clone asch 12 | git clone https://github.com/aschplatform/asch.git asch && cd asch && npm install && cd .. 13 | ``` 14 | 15 | ### Setup your file structure 16 | Your file and directory structure should look like that shown beneath: 17 | 18 | ``` 19 | ├── config.json 20 | ├── contract 21 | ├── dapp.json 22 | ├── genesis.json 23 | ├── init.js 24 | ├── interface 25 | ├── model 26 | └── public 27 |    └── index.html 28 | ``` 29 | 30 | You can also install the [Basic Asch Dapp](https://github.com/bassjobsen/asch-test-dapp). 31 | 32 | ``` 33 | > git clone https://github.com/bassjobsen/asch-test-dapp.git asch-mini-dao 34 | ``` 35 | 36 | ### Install Asch redeploy 37 | 38 | ``` 39 | npm install --global asch-redeploy 40 | ``` 41 | 42 | More information about Asch redeploy can be found at: [Asch redeploy](https://github.com/AschPlatform/asch-redeploy) 43 | 44 | ## Run the Dapp on the localnet 45 | After setting your environment you can navigate to the Dapp directory and run Asch redeploy. 46 | 47 | ``` 48 | > cd asch-mini-dao 49 | > asch-redeploy 50 | ``` 51 | 52 | The above commands will give you the output like that shown beneath: 53 | 54 | ``` 55 | ... 56 | [2018-07-21 21:50:241][INFO] starting to register Dapp... 57 | [2018-07-21 21:50:268][INFO] dapp: { 58 | "name": "test-BOPTsZpkzdvw", 59 | "link": "https://test-RLLEzdTFyAEG.zip", 60 | "category": 1, 61 | "description": "A hello world demo for asch dapp", 62 | "tags": "asch,dapp,demo", 63 | "icon": "http://o7dyh3w0x.bkt.clouddn.com/hello.png", 64 | "type": 0, 65 | "delegates": [ 66 | "db18d5799944030f76b6ce0879b1ca4b0c2c1cee51f53ce9b43f78259950c2fd", 67 | "590e28d2964b0aa4d7c7b98faee4676d467606c6761f7f41f99c52bb4813b5e4", 68 | "bfe511158d674c3a1e21111223a49770bee93611d998e88a5d2ea3145de2b68b", 69 | "7bbf62931cf3c596591a580212631aff51d6bc0577c54769953caadb23f6ab00", 70 | "452df9213aedb3b9fed6db3e2ea9f49d3db226e2dac01828bc3dcd73b7a953b4" 71 | ], 72 | "unlockDelegates": 3 73 | } 74 | [2018-07-21 21:50:876][INFO] DAPP registered, DappId: a09a3917cc1d05b11ed25566634586f8a5100d3d1094b4e93b77a6a227c8b926 75 | [2018-07-21 21:50:692][INFO] dappId "a09a3917cc1d05b11ed25566634586f8a5100d3d1094b4e93b77a6a227c8b926" successfully added to "../asch/config.json" 76 | ... 77 | ``` 78 | 79 | Now you can visit your Dapp at `http://localhost:4096/api/dapps//`. 80 | 81 | Asch redeploy helps you to watch for changes on your Dapp and re-deploy it automatically. Asch redeploy installs a new Dapp when you change the files of your Dapp every time. Notice that you can stop and restart the tool when you have to change more than one file. 82 | 83 | In stead of running Asch redeploy you can also install the Dapp on the Localnet yourself. Follow the instructions at [Dapp Development Tutorial 1: Asch Dapp Hello World](https://github.com/AschPlatform/asch-docs/blob/master/dapp/hello_world/en.md) to do so. 84 | 85 | ## Create your models 86 | To store our projects and votes in the database we'll have to create the models. Asch use the [SQlite](https://www.sqlite.org/index.html) database and the [JSON-SQL](https://github.com/AschPlatform/json-sql) library for mapping mongo-style query objects to SQL queries. To store your project create a new `models/projects.json` file that contains the following JSON code: 87 | 88 | 89 | ``` 90 | module.exports = { 91 | name: 'projects', 92 | alias: 'p', 93 | fields: [ 94 | { 95 | name: 'id', 96 | type: 'BigInt', 97 | not_null: true, 98 | unique: true, 99 | primary_key: true 100 | }, 101 | { 102 | name: 'transactionId', 103 | type: 'String', 104 | length: 64, 105 | not_null: true, 106 | unique: true 107 | }, 108 | { 109 | name: 'name', 110 | type: 'String', 111 | length: 16, 112 | not_null: true 113 | }, 114 | { 115 | name: 'description', 116 | type: 'Text', 117 | not_null: true 118 | }, 119 | { 120 | name: 'authorId', 121 | type: 'String', 122 | length: 50, 123 | not_null: true 124 | }, 125 | { 126 | name: 'votes', 127 | type: 'Number', 128 | not_null: true 129 | }, 130 | { 131 | name: 'timestamp', 132 | type: 'Number', 133 | not_null: true 134 | } 135 | ] 136 | } 137 | ``` 138 | 139 | ## Create a smart contract 140 | To create a new project you'll have to pay a fee. So we use a smart contract to create a new project. Create a new `contracts/project.js` file that contains the following code to do so: 141 | 142 | ``` 143 | module.exports = { 144 | addProject: async function(name, description) { 145 | app.sdb.create('Project', { 146 | name: name, 147 | description: description, 148 | id: app.autoID.increment('project_max_id'), 149 | transactionId: this.trs.id, 150 | votes: 0, 151 | authorId: this.trs.senderId, 152 | timestamp: this.trs.timestamp 153 | }) 154 | } 155 | } 156 | ``` 157 | 158 | ### Make your contract available 159 | 160 | Write down the following code into the `init.js` file now: 161 | 162 | ``` 163 | app.registerContract(1002, 'project.addProject') 164 | ``` 165 | 166 | In the above `1002` is an unique number used to call the contract. The `project.addProjects` string sets up a call to the `addProjects` function in the `contracts/project.js` file created in the [previous step](#create-a-smart-contract). See also [registerContract](https://github.com/AschPlatform/asch-docs/blob/master/sdk_api/en.md#82-appregistercontracttype-name) 167 | 168 | ### 169 | 170 | Optional you can add [parameter validation](https://github.com/AschPlatform/asch-docs/blob/master/sdk_api/en.md#81-appvalidatetype-value) in the contract files like that shown beneath: 171 | 172 | 173 | ``` 174 | app.validate('string', name, { length: { minimum: 1, maximum: 256 }}) 175 | app.validate('string', description, { length: { minimum: 1, maximum: 1024 }}) 176 | ``` 177 | 178 | ## Create a REST Api endpoint 179 | In this step we create a REST Api endpoint which return the list of projects. Create a new `interface/project.js` file. Write down the following code into this file: 180 | 181 | ``` 182 | app.route.get('/project/all', async function (req) { 183 | return await app.model.Project.findAll() 184 | }); 185 | ``` 186 | 187 | In the above code the `[app.route.get()](https://github.com/AschPlatform/asch-docs/blob/master/sdk_api/en.md#41-approutegetpath-handler)` call sets up a API endpoint. You can access this API endpoint with a GET call to `http://localhost:4096/api/dapps//project/all`. The `app.model.Project.findAll` queries all data items in the `project` table for the specified condition. More information about the Data Model can be found at: [Data Model of the Asch SDK API](https://github.com/AschPlatform/asch-docs/blob/master/sdk_api/en.md#3-data-model). 188 | 189 | ## Howto build the user-interface 190 | The HTML UI can be found in the `public/` directory of your Dapp. In this tutorial we'll use a single file to create the UI. The UI is build with HTML and [jQuery](https://jquery.com/). Create a new HTML file called `public/index.html`: 191 | 192 | ``` 193 | 194 | 195 | 196 | 197 | 198 | 199 | Asch Mini DAO 200 | 202 | 210 | 211 | 212 |

Asch Mini DAO

213 | 214 | 215 | 216 | ``` 217 | 218 | ### The HTML part 219 | 220 | #### Create a HTML form to add a new project 221 | 222 | ``` 223 |

新建项目

224 |
225 |
226 |
227 | 228 |
229 | ``` 230 | 231 | #### Create a HTML table to display the project list 232 | 233 | ``` 234 |

所有项目

235 |
236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 |
ID名称描述创建者票数操作
246 |
247 | 248 | ``` 249 | 250 | ### The javaScript part 251 | 252 | #### Add a new project 253 | 254 | ``` 255 | $('#newProjectBtn').click(function () { 256 | var prjName = $('#projectNameInput').val(); 257 | var prjDesc = $('#projectDescText').val(); 258 | if (!prjName || !prjDesc) { 259 | return alert('您输入的内容不正确!'); 260 | } 261 | var fee = '10000000' 262 | let data = { 263 | secret: UserInfo.secret, 264 | fee: fee, 265 | type: 1002, 266 | args: JSON.stringify([prjName,prjDesc]) 267 | } 268 | invoke(data); 269 | 270 | $('#projectNameInput').val(''); 271 | $('#projectDescText').val(''); 272 | }); 273 | ``` 274 | 275 | ##### The invoke() function 276 | 277 | The `invoke()` creates a `PUT` request to `/api/dapps//transactions/unsigned`. You can read more about the API at . 278 | Notice that the smart contract is hardcoded set by `type: 1002` as defined in `config.json`. (see: [Make your contract available](#make-your-contract-available)) 279 | 280 | #### Get the list of projects: 281 | 282 | ``` 283 | function getProjects() { 284 | $.ajax({ 285 | type: 'GET', 286 | url: BASE_URL + '/project/all', 287 | data: null, 288 | dataType: 'json', 289 | success: function (projects) { 290 | updateProjectView(projects); 291 | return; 292 | } 293 | }) 294 | } 295 | ``` 296 | 297 | The jQuery code above creates a GET request to `/api/dapps//project/all` and returns a list of projects. We create the REST Api endpoint before, see [Create a REST Api endpoint](#create-a-rest-api-endpoint). 298 | 299 | #### Refresh the project list 300 | To refresh the project list every 10 seconds we can use the folloqing code: 301 | 302 | ``` 303 | State.timer = setInterval(function () { 304 | if (UserInfo.publicKey) { 305 | getProjects(); 306 | } 307 | }, 10 * 1000); 308 | ``` 309 | 310 | ##### Update the HTML code 311 | The `getProjects()` function calls the updateProjectView() which updates the HTML table: 312 | 313 | ``` 314 | function updateProjectView(projects) { 315 | // find projects 316 | console.log(projects); 317 | var $table = $('#projectTable'); 318 | $table.find('tr:not(:first)').remove(); 319 | for (var i = 0; i < projects.length; ++i) { 320 | var prj = projects[i]; 321 | var keys = ['id', 'name', 'description', 'authorId', 'votes']; 322 | var values = keys.map(function (k) { 323 | return prj[k]; 324 | }); 325 | values.push(''); 326 | $table.append(constructTr(values)); 327 | invoke(data); 328 | 329 | }); 330 | } 331 | } 332 | ``` 333 | 334 | The complete code also adds a button for voting to the project HTML table. The `constructTr()` function can be found in the source code too. 335 | 336 | ## The Voting system 337 | Now you shoud be able to setup the voting system yourself. Good Luck. 338 | -------------------------------------------------------------------------------- /tokens/en.md: -------------------------------------------------------------------------------- 1 | # Create a new Asset by using the (default) front-end 2 | 3 | The normal process would be: 4 | 5 | - Register publisher 6 | - Wait 10 sec for next block 7 | - Register asset 8 | - Wait 10 sec for next block 9 | - Mint tokens (only available in Chinese language, you can see it on the screen, but not translated yet) 10 | 11 | ## Preparation 12 | Make sure that ASCH is running (`cd asch && node app.js`) and you've created a (new) account. See also [Create a new account by using the (default) front-end](../create-account/en.md). Notice that one account can only register as publisher once. 13 | 14 | ## Create a publisher 15 | Point yout browser to http://localhost:4096/#/login and login with your account. Make sure your account contains enough XAS. Registering a publisher requires 100 XAS and registering an asset requires 500 XAS again. Choose the "Asset" tab from the left side of the screen now. Then navigate to "Registered Publisher" tab and fill in the form like that shown in the frgure below: 16 | 17 | ![new publisher](./images/newpublisher.png) 18 | 19 | Confirm the popup that: "This operation requires a fee of 100 XAS" 20 | 21 | Now wait at least 10 seconds for the next block. 22 | 23 | ## Create an asset 24 | Now navigate to the "Registered Assets" tab an fill in the form like that shown in the figure below, ignore the field under "Accuracy": 25 | 26 | Confirm the popup that: "This operation requires a fee of 500 XAS". After 10 second you will find your asset under the "My Issued Assets": 27 | 28 | ![new asset](./images/issuedassets.png). 29 | 30 | Now you can cancel, change, release and transfer your new assets. Let's try to release some pub.New assets now. 31 | 32 | Enter the number of asset you're issuing in the popup and confirm your operation: 33 | 34 | ![issuing](./images/issuing.png). 35 | 36 | After 10 seconds you'll find your 200000 new `pub.NEW` assets under the "Asset Profile". Now you're able to send (transfer) `pub.NEW` assets to other adresses too. 37 | 38 | # Using asch-redeploy 39 | Notice that you can also use [asch-redeploy](https://github.com/AschPlatform/asch-redeploy) to create a new Asset: 40 | 41 | Change the directory to some random Dapp and execute: 42 | 43 | ``` 44 | > asch-redeploy --publisher pub --asset NEW 45 | ``` 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /tokens/images/issuedassets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/tokens/images/issuedassets.png -------------------------------------------------------------------------------- /tokens/images/issuing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/tokens/images/issuing.png -------------------------------------------------------------------------------- /tokens/images/newpublisher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/tokens/images/newpublisher.png -------------------------------------------------------------------------------- /v1.5-release.md: -------------------------------------------------------------------------------- 1 | # ASCH v1.5 2 | 3 | ## 1. v1.5 更新日志 4 | 5 | ### 1.1. 新功能 6 | 7 | #### 1.1.1. 智能合约平台 8 | 9 | - ASCH平台在v1.5版中实现了一个基于`Typescript`语言的对开发者友好的智能合约平台。详见[智能合约介绍](#3-智能合约) 10 | 11 | #### 1.1.2. 跨链网关 12 | 13 | - 新增网关防作恶机制; 14 | - 新增网关候选人申请页和列表页; 15 | - 新增网关储备金机制(追加/退回); 16 | - 新增网关储备金展示; 17 | 18 | #### 1.1.3. 提案系统 19 | 20 | - 新增"网关清算"提案类型; 21 | - 新增“资源租赁比例调整”提案类型; 22 | - 新增“Gas_Price调整“提案类型; 23 | 24 | #### 1.1.4. 理事会 25 | 26 | - 新增网关资产列表的多资产类型展示; 27 | - 新增了理事会资产转账记录列表展示; 28 | 29 | #### 1.1.5. 资源租赁机制(燃料费机制) 30 | 31 | - 新增抵押XAS换取ASCH网络资源使用权策略; 32 | - 新增Net Point(NET/带宽)作为普通交易手续费; 33 | - 新增Energy Point(EP/能量)作为智能合约平台燃料费; 34 | 35 | #### 1.1.6. 其他 36 | 37 | - 新增个人中心“查看公钥“的功能; 38 | - 新增个人中心“查看主密钥二维码”的功能; 39 | - 新增登录页面“根据浏览器语言调整默认语言“的功能; 40 | 41 | ### 1.2. 调整及优化 42 | 43 | #### 1.2.1. 共识规则优化 44 | 45 | - 超级节点由101优化为21个,网络负载更小。激励效果更佳; 46 | 47 | #### 1.2.2. 区块链底层优化 48 | 49 | - 优化了交易处理逻辑,减少不必要的交易执行; 50 | - 优化了区块产生的流程,系统负载更小; 51 | - block升级到v1,支持状态校验; 52 | - SmartDB实现了自动的一致性检测和自动恢复功能; 53 | - 使用了自主开发的fastp2p替换第三方p2p库,提升网络利用率和稳定性; 54 | 55 | #### 1.2.3. 其他 56 | 57 | - 优化了移动端转账记录中的交易ID不可点击的问题; 58 | - 优化了区块浏览频道列表区块高度不可点击的问题; 59 | - 优化锁仓换取投票权的展示样式; 60 | 61 | ## 2. v1.5 客户端用户手册 62 | 63 | 点击下载[v1.5用户手册](./manual/zh-cn.pdf) 64 | 65 | ## 3. 智能合约 66 | 67 | 智能合约相关文档: 68 | 69 | - [智能合约开发环境安装](./contract/install/zh-cn.md) 70 | - [5分钟开发ASCH智能合约](./contract/hello-contract/zh-cn.md) 71 | - [智能合约开发入门](./contract/introduction/zh-cn.md) 72 | - [智能合约开发实战](./contract/contract-in-action/README.md) 73 | - [Gas计费与内置函数](./contract/contract-in-action/5.1%20附录一:燃料计费表和智能合约内置函数.md) 74 | 75 | ## 4. 常见问题 76 | 77 | - 如何进行投票 78 | 79 | 可通过网页客户端中的`投票`菜单,选中要投票的受托人,然后点击页面上方的`赞`图标进行投票,也可以进入[超级节点投票主页](https://delegates.asch.io/)进行投票,超级节点投票主页需要使用chrome浏览器,并从`chrome商店`中安装`asch-pay`插件。 80 | 81 | - 如何获取免费的能量/带宽/投票权 82 | 83 | 通过Web客户端`个人中心->我的资源`中的`冻结`换取能量的功能,目前冻结1XAS可获得1,000能量。1能量可抵扣1Gas。带宽及票权的操作方式类似。 84 | 85 | - 能量用完怎么办 86 | 87 | 能量用完后,调用合约时可选择使用XAS抵扣,目前1XAS可抵扣10,000Gas。注册合约合约与调用合约稍有不同,当注册合约能量不足时,自动使用XAS抵扣 88 | -------------------------------------------------------------------------------- /whitepaper/asch/de.md: -------------------------------------------------------------------------------- 1 | Bitte besuchen Sie die offizielle Webseite um das englisprachige Whitepaper zu lesen. [Whitepaper (eng)](https://www.asch.so/asch-whitepaper-en.pdf) 2 | -------------------------------------------------------------------------------- /whitepaper/asch/zh-cn.md: -------------------------------------------------------------------------------- 1 | title: Asch白皮书 2 | --- 3 | # 0 引言 4 | 5 | 比特币的出现使得去中心化的货币系统成为可能,经过几年的发展,人们发现比特币背后的区块链技术潜力巨大,可以被广泛应用在各行各业。为了更好地利用区块链技术,出现了以以太坊为代表的一批应用平台,它们封装了底层协议、建设了基础设施,为开发者提供了更加友好、也更加灵活的接口,使得开发者的关注点能够集中在业务逻辑上,很大程度上提高了开发效率。本文提出的 asch 系统也是一种去中心化应用的开发平台,接下来我们会详细阐述这一系统的特色、原理及应用场景。 6 | 7 | # 1 概述 8 | 9 | ## 1.1 去中心化应用 10 | 11 | 去中心化应用是一种具有以下特点的应用。 12 | 13 | 1. 必须完全开源,自主运行,不能被中心化的组织、机构或个人操控,可以被改进以响应市场需求,但必须经过用户们的共识。 14 | 15 | 2. 数据必须被安全、公开、冗余的存储在一个分布式网络中,以避免被篡改和单点故障。 16 | 17 | 3. 应用访问者需要消耗令牌,而应用贡献者可以获得令牌的奖励。 18 | 19 | 4. 应用必须使用一种价值证明的密码学算法来生成令牌。 20 | 21 | 去中心化应用可以通过授权系统的权益人来投资应用的开发,从而有潜力达到自给自 22 | 23 | 足。去中心化应用还有公开透明、安全可靠、去信任等优点。因此,可以想像去中心化应用在支付、数据存储、云计算、电子商务等领域将有非常可观的前景,它所产生的价值甚至有可能会超过 visa、dropbox、亚马逊等跨国公司的市值。 24 | 25 | ## 1.2 侧链是什么 26 | 27 | 区块链是一串使用密码学方法相关联产生的数据块,每一个数据块中包含了若干网络交易的信息,用于验证其信息的有效性(防伪)和生成下一个区块,对于普通用户来说它就像一个公有账本,记载所有的交易记录,对于开发者来说可以理解为一个分布式的数据库。区块链这个数据库的特点是去中心化、开放、自治、不可篡改,区块链与去中心化应用息息相关,非常适合为去中心化应用提供存储功能。 28 | 29 | 侧链是一种特殊的区块链。它使用一种叫做“SPV 楔入”的技术实现与其他区块链之间的资产转移,这使得用户能用已有的资产来使用新的加密货币系统。人们不必再担心比特币难于采纳创新和适应新需求,只要创造一个侧链,然后对接到比特币的区块链中即可,通过继承和复用比特币强大的区块链,还避免了新货币的流动性短缺和市场波动等问题。并且由于侧链是一个独立的、隔离的系统,侧链中出现的严重问题只会影响侧链本身,这极大地降低了创新的风险和成本。 30 | 31 | ## 1.3 Asch 是什么 32 | 33 | Asch 是一个去中心化的应用平台。它提供了一系列的 sdk 和 api 来帮助开发者构建基于 Javascript 和侧链技术的去中心化应用。Asch 通过提供定制侧链、智能合约、应用托管等一体化的行业解决方案,致力于打造一个易于使用、功能完备、即插即用的系统。利用 Asch 生态系统,开发者可以快速迭代他们的 Javascript 应用,并发布到系统内置的应用商店中,这些应用可以被平台中的分布式节点下载并执行,并服务于普通用户,整个过程都由诚实安全的 Asch 侧链共识网络提供安全保证。 34 | 35 | Asch 系统本身也是一个完全开放的、去中心化的应用,内置有代币,单位为 XAS,中文名叫阿希币。阿希币可以通过双向楔入的方式与侧链或 dapp 进行交互,作为所有 36 | 37 | dapp 之间资产转换的桥梁和媒介,这些代币将在系统发布之前以 ico 的方式预售给投资人。系统一旦发布,Asch 最初的核心团队将不再掌控系统的走向,只有系统的权益人和代币的拥有者决定系统将来的发展。 38 | 39 | ## 1.4 Asch 面向哪些用户 40 | 41 | Asch 平台除提供一些基本服务外,还将提供技术和工具上的支持,主要面向以下群体: 42 | 43 | ### 1.4.1 开发者 44 | 45 | 开发者可以根据 Asch 平台的应用开发规则和商业行为准则,并按照相关的规范进行开发和提交 dapp。Dapp 的商业模式或免费,或定价销售,或按增值服务付费。采用何种商业模式完全由开发者决定。 46 | 47 | ### 1.4.2 企业 48 | 49 | Asch 平台提供的工具可以非常容易地创建一个完整的区块链,更重要的是可以楔入到Asch 平台的主链或者比特币的区块链中,实现与成熟电子货币的对接,这对中小型企业,特别是初创企业是非常有吸引力的。 50 | 51 | 中小企业可以通过区块链技术提供原本封闭在企业内部、互联网内部的信息和数据,甚至与监管机构的相关系统数据相互链接,增强透明度,以此树立良好的形象,赢得投资者、金融机构的信任度,顺利拿到融资或项目合同等。 52 | 53 | 中小企业主动公开和开放资料,已成无法阻挡的趋势。因为现在有很多的公开渠道来获取数据,中小企业已经越来越难隐瞒它们不想让外界知道的信息。我们可以大胆预测,在未来区块链将是帮助中小企业发展的重要武器。 54 | 55 | ### 1.4.3 普通用户 56 | 57 | 普通用户可以通过 Asch 内置的应用商店进行下载、安装和使用去中心化应用,这跟手机平台的应用商店是类似的模式。Asch 系统支持多种类型的去中心化应用,普通用户在消费这些应用的同时,还可以通过贡献内容来获得收益。开发者与普通用户将共同组成一个繁荣的生态系统。 58 | 59 | # 2 设计理念 60 | 61 | ## 2.1 完备脚本 vs 侧链 62 | 63 | 比特币为人称道的一个设计上的亮点就是它的脚本引擎。基于这套脚本引擎,不但可以实现普通的转账功能,还可以实现多方签名、抵押担保、博彩等智能合约应用。但是出于安全和实现难度的考虑,比特币的脚本系统设计的较为简陋,做了非常多的限制,比如它不支持循环、脚本长度受限、只支持几种标准的的交易类型。 64 | 65 | 以太坊的最大特色就是极大地扩展了这个脚本引擎的功能,加入了读取区块链、计费、跳转等新指令,还解除了栈内存、函数调用深度以及脚本长度限制等。以太坊自称他们的脚本语言达到了图灵完备,利用这样的脚本,开发者可以实现几乎任何可以用数学方式表述的功能。 66 | 67 | 自以太坊以来,扩展脚本成为了一种实现去中心化开发平台的流行方式,但这种方式有一个很大的缺点就是,应用代码本身及应用产生的数据都存在同一个区块链中,造成了区块链的快速膨胀。以太坊试图通过优化和压缩区块和交易本身来延缓这种膨胀,也只是一种治标不治本的方法。此外,基于脚本实现的应用之间是共享同一个账本的,像区块产生时间等参数是无法被定制的,这无疑限制了应用的个性化。 68 | 69 | 侧链机制是通过另一个维度实现扩展性的,每个侧链运行在不同的分布式节点网络中,有独立的受众、投资人和开发团队。这种天然的分片解决方案,不但解决了区块链的膨胀问题,而且每个应用都拥有一套个性化的账本,其共识机制、区块参数、交易类型都是可以被定制的,所以我们认为侧链与完备交易脚本相比,是一种成本更低、更加灵活、也更加易用的解决方案。 70 | 71 | ## 2.2 账户 vs UTXO 72 | 73 | 在比特币及其衍生系统中,是没有一个所谓的账户来存储用户的余额的,用户的余额是通过整个系统的交易状态转换来实现的。这里要引入一个术语,UTXO(unspenttransaction outputs),即未花费的交易输出。每个 UTXO 都有一个面值和所有者,一笔交易包括一个或多个输入和一个或多个输出。每个输入包含一个对现有 UTXO 的引用和由与所有者地址相对应的私钥创建的密码学签名,如果一个用户拥有这个私钥,那么他就可以消费这个 UTXO 对应的币值,也就是说一个用户的余额就是他所有拥有的所有私钥对应的 UTXO 的币值总和。UTXO 主要优点是高度的私密性,用户可以为每一笔交易生成一个新的地址,从而使得用户无法被追踪,这对于货币来说是好事,但对于各式各样的dapp 来说,就未必了。账户相对于 UTXO 来说,有以下几个优点: 74 | 75 | 1. 节省空间。举例来说,如果某个用户有 5 个 UTXO,需要的存储空间是(20 + 32 +8)* 5 = 300 字节(其中 20 字节为地址,32 字节为交易号,8 字节为交易额),而账户仅需要 20+8+2=30 字节(20 字节位地址,8 字节位余额,2 字节为随机数)。 76 | 2. 利于监督。账户的存在使得电子货币很容易被区分,因为我们只要知道这些币来自哪些账户即可。 77 | 3. 简单、易于编码和理解。 78 | 4. 常量级引用。轻客户端能以常数时间访问一个用户的账户任意数据,而在 UTXO 系统中,每当有交易发生时,数据引用将发生变化。 79 | 80 | Asch 平台本身并不是一个纯粹的货币系统,要容纳各种各样的应用,综合比较起来,账户对于我们来说是一种更好的选择。 81 | 82 | ## 2.3 关系数据库 vs 非关系数据库 83 | 84 | 目前大多数的区块链系统都选择使用模型较简单的非关系数据库来存储数据,比如berkeley db,leveldb 等,这些数据库一般都提供一些简单的数据结构,比如 btree、hashtable、queue 等,它们一般不支持 SQL 对数据进行操作,虽然这些数据库对于一般的电子货币系统来说足够了,但对于应用平台来说是远远不够的,特别是对于金融、银行、电子商务等领域,目前主流的存储系统都是采用了关系数据库,因为关系数据有以下几个优点: 85 | 86 | 1. 事务处理; 87 | 2. 数据更新开销非常小; 88 | 3. 可以进行 join 等复杂查询。 89 | 90 | 我们选择的 sqlite 是一种性能极佳的轻量级嵌入式关系数据库,容量最高支持 2T,数据文件可在不同字节序机器之间自由共享,特别是对 SQL 的支持,将为 dapp 开发者提供极大的便利。 91 | 92 | # 3 系统特点 93 | 94 | ## 3.1 易用 95 | 96 | ### 3.1.1 开发语言 97 | 98 | 开发者可以使用 javascript 语言以及海量的 npm 库来构建他们的应用。相对于比特币的 c++语言及栈式脚本、以太坊的新语言 solidity,javascript 流行度更高、受众更广、上手更容易的一门语言。此外,关系数据库的加入也是 Asch 系统的一大特色,使得去中心化的应用开发模式与传统 web 应用的开发模式已经非常相近了。Asch 平台的应用开发门槛可以说是同类产品中最低的。 99 | 100 | ### 3.1.2 工具 101 | 102 | Asch 系统提供了一个命令行工具,只需要根据提示输入一些配置项,就可以快速的建立一个侧链,并可在侧链上开发任意类型的应用。其次,系统还提供了一系列的 api 帮助用户构建复杂的智能合约应用,这些 api 涵盖共识、强随机数、数据库、密码学等方面。 103 | 104 | ### 3.1.3 部署 105 | 106 | 开发者只需要把自己的 dapp 提交到 github,然后在 web 钱包或轻钱包中注册,就完成了部署的工作,之后 dapp 将被显示在应用商店中被用户下载和使用。 107 | 108 | ## 3.2 灵活 109 | 110 | 开发者可以随意定制其侧链的各项参数,比如区块产生速度、交易类型、交易费等等,甚至可以实现一个新的共识机制,比如开发者可以使用权益证明或工作量证明的共识机制来取代默认的委托人权益证明机制。 111 | 112 | ## 3.3 安全 113 | 114 | Asch 系统的一大亮点是使用了一个增强 DPOS 的共识算法,在 DPOS 的基础上加入了一个高效的实用拜占庭容错算法,极大地降低了网络分叉的可能性,只要不超过 1/3 节点联合做恶,系统就不会分叉,也就没有双重支付的风险。其次,系统在一些小的细节方面也是尽量从安全角度进行了考量。比如采用 BIP39 标准算法的口令助记符、二级交易密码、多重签名账户等。 115 | 116 | # 4 技术细节 117 | 118 | ## 4.1 共识机制 119 | 120 | Asch 系统采用的共识机制是基于 DPOS 的,也是使用了委托人选举的制度,但是在算法的后半部分采用了一个优化后的 PBFT 算法变种,这个算法可以在 t < n / 3 时,以O(n^2)消息复杂度,O(1)的时间复杂度使忠诚的节点达成一致,不会分叉,其中 t 表示拜占庭节点(即可能发生任意行为的节点,比如网络延迟、停机、恶意攻击等等)的个数,n 表示所有节点的个数。 121 | 122 | ### 4.1.1 委托人选举 123 | 124 | Asch 系统的委托人选举制度与 DPOS 是类似的,核心系统是由 N 个委托人节点组成,委托人是被社区选举的可信账户,得票最高的 N 个委托人负责生产区块。得票排名未进入前 N 名的账户被称为候选人,当他们将来获得足够多的选票并进入前 N 名后,将成为正式的委托人。 125 | 126 | 每个 Asch 用户都有权利投票给最多 N 位委托人,选票的权重是由用户持有的 XAS数量决定。 127 | 128 | 每一个选举周期产生 N 个区块,每一次投票和委托人排名的变化将体现在下一个周 129 | 130 | 期。每个区块产生的间隔时间是 10 秒,新创建的区块会被广播到网络中并添加到区块链中。每当新的区块被添加到区块链中,该区块之前的所有交易的确认次数加一,得到 6 个确认后,可以认为交易是安全的,如果数额较小的交易,可以允许更小的确认次数,相反,数额较大的交易可以通过增加确认数来保证安全性。 131 | 132 | 如果有少数委托人发生故障,比如被攻击或者宕机,就会错失区块,这会被记录在案,这将影响该节点的在线率,进而影响社区的投票。因此委托人的竞选是需要严肃对待的,委托人应当由有一定网站运营经验的人来做,委托人要保障自己节点的稳定性,并以此促进整个系统的安全和稳定。 133 | 134 | ### 4.1.2 拜占庭容错 135 | 136 | Asch 系统与 DPOS 的不同主要体现在算法的后半部分。 137 | 138 | DPOS 采用的方法是,首先对当前 round 的委托人列表进行随机的排序(保证每一轮的委托人顺序不同,也无法预测下一轮委托人顺序),然后通过 round-robin 的方式依次让每个委托人创建区块。这个算法的主要缺点是,如果某个委托人节点叛变了,他可能会广播多个不一致的区块,这些区块间可能包括双重支付交易,导致整个网络被分叉了。当然,如果只有一个委托人叛变的话,这个分叉很快就可以通过下一次最长链同步的方法来消除,但是随着叛变节点的增加,消除分叉的时间将越来越长,少量节点的联合叛变将严重影响系统的安全性,即使一个交易达到 6 次确认,也很可能是不安全的。 139 | 140 | 为了解决这个问题,我们引入了 PBFT(Pratical Byzantine Fault Tolerance)算法。PBFT 算法也是使用 round-robin 的方式选择委托人,但是选出委托人后并不立即创建区块,而是首先发起一个提议(propose),这个提议的目的是确定下一次区块的 hash。当超过 2/3 的节点都赞成该提议时,才接受由提议人创建的的下一个区块,下一个区块的 141 | 142 | hash 必须与当前 round 达成共识的区块 hash 一致。从本质上来说,PBFT 算法的加入解决了委托人权利滥用的问题,使得委托人的记账能力更为可控。 143 | 144 | ## 4.2 侧链与 dapp 145 | 146 | Asch 系统提供了一个命令行工具,可以用来轻松创建一个基础的侧链系统,侧链的开发者也可以深度定制自己的侧链,侧链拥有自己的数据库、共识机制、交易类型以及账户体系。侧链可以托管在独立的委托人节点集群中,这就自然形成了一种分片的机制,延缓了主区块链的膨胀。 147 | 148 | 每一个 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 主链来转移。 149 | 150 | ## 4.3 沙箱和 VM 151 | 152 | 沙箱是一种按照安全策略限制程序行为的执行环境。早期主要用于测试可疑软件等,比如黑客们为了试用某种病毒或者不安全产品,往往可以将它们在沙箱环境中运行。经典的沙箱系统的实现途径一般是通过拦截系统调用,监视程序行为,然后依据用户定义的策略来控制和限制程序对计算机资源的使用,比如读写磁盘等。 153 | 154 | Asch 系统使用了 nodejs 的 vm 模块实现沙箱机制。VM 模块是对 javascript 的 v8引擎的封装,可以用来执行纯粹的 javascript 代码,但无法使用系统层的 api,比如文件系统、网络传输相关的模块,并且由于没有 require 函数,第三方库也没法轻易导入进来,甚至无法进行模块化开发,这就需要 dapp 的开发者使用 browserify 的技术将常用的第三方库打包成一个 js 文件,Asch 的主链系统才能加载并运行。对于一些必须的系统级api,则通过进程间通讯的方法为侧链提供,这样兼顾了安全性与功能的完备性。 155 | 156 | ## 4.4 交易 157 | 158 | Asch 系统内建了一个交易抽象层,核心系统的几乎所有功能都是建立在交易上的,比如转账、投票、应用商店、充值、提现等。侧链本身也可以实现自己的不同类型的交易。交易之间的区别主要是交易类型和 asset。基础交易的数据结构如下,扩展部分会根据类型的不同分别存在不同的 asset 表中。 159 | 160 | ```sql 161 | Transaction { 162 | required VARCHAR(20) id; 163 | required VARCHAR(20) blockId; 164 | required TINYINT type; 165 | required INT timstamp; 166 | required VARCHAR(N) senderId; 167 | optional VARCHAR(N) recpientId; 168 | required BIGINT amount; 169 | required BIGINT fee; 170 | required BINARY(64) signature; 171 | optional BINARY(64) signSignature; 172 | optional TEXT signatures; 173 | required BINARY(32) senderPublicKey; 174 | } 175 | ``` 176 | 177 | 以投票交易举例来说, votes 实体通过交易 id 来关联到一个基础交易中。 178 | 179 | ```sql 180 | Asset_Votes { 181 | required VARCHAR(20) transactionId; 182 | optional TEXT votes; 183 | } 184 | ``` 185 | 186 | ## 4.5 账户系统 187 | 188 | Asch 的每个账户由一个口令、一对公私钥、一个地址组成。用户还可以额外设置一个二级密码。注意这里与比特币有所不同的是,每个账户仅对应一个地址,而比特币中每个钱包对用多个地址和私钥。 189 | 190 | 口令(passphrase)是符合 BIP39 标准的用于产生确定性钱包的助记符。这种助记符与二进制或十六进制字符相比对人类记忆更友好。口令的生成方式是将一个 32bit 倍数长度的熵转换成若干个单词,Asch 系统选择的熵长度为 128bit,将转换成 12 个单词。口令作为一级密码,由用户保管,不对外公开,一旦丢失用户将失去对应账户的所有权。口令形式如下: 191 | 192 | ``` 193 | barely decline dust stamp protect color certain cup arena busy latin shell 194 | ``` 195 | 196 | **密钥对**包括公钥和私钥,是以口令的`sha256` 哈希做种子,再通过 `ed25519` 爱德华兹曲线签名算法生成的。形式如下: 197 | 198 | ``` 199 | 公钥: 200 | 9989388b220a13465e49f52df5ba28ba08eb1e7a973320347f9687a107dc2f 201 | 9a 202 | 203 | 私钥: 204 | 91e891f653e3ed0232d8c7de2e72b625d50d48593fc0fb570c0db25c5e4456 205 | 9a9989388b220a13465e49f52df5ba28ba08eb1e7a973320347f9687a107dc 206 | 2f9a 207 | ``` 208 | 209 | 账户地址是取公钥的 `sha256` 哈希的前 8 位,逆序后转换成 bignumber,其形式如下 210 | 211 | ``` 212 | 5034187504202890358 213 | ``` 214 | 215 | ## 4.6 客户端 216 | 217 | Asch 系统将提供三种客户端程序。 218 | 219 | 完整版客户端是针对超级用户、委托人和开发者的最佳解决方案,它可用于windows,Mac OS 以及 linux,但它只允许 linux 运行受托人节点。 220 | 221 | 轻钱包的用户可以通过连接到完整版钱包以连接到网络,也可以直接调用 API,但前提是完整版钱包的所有者有开放该 API 权限,完整版钱包会通过点对点网络,从其它完整版钱包节点下载完整的区块链。 222 | 223 | 普通用户将主要使用轻钱包来管理自己的 Asch 帐户,它是一个精简版的 Asch 钱包,轻钱包支持 windows 和 Mac OS,它无需安装,它使用的是内嵌式的浏览器,它无法作为网络节点,因为它不下载区块数据,它只通过 http 连接到其它的节点,这样做能带来几点好处。首先它不下载区块数据,这意味着它会一直保持着较小的体积,不占容量;其次它不向网络广播密钥,所有数据在本地设计上签名,可以做所有类型的交易,如果你想运行一个受托人节点,你可以使用轻钱包注册一个受托人帐号,但你无法使用轻钱包来运行受托人节点来创建区块,为了运行受托人节点,你需要下载完整版钱包,并运行在 linux 上。Dapp 用户可以使用轻钱包来管理已安装的 dapp。Dapp 的 API 和节点的API 也可供开发人员调用,这使得开发人员可以使用 Node.js 快速且简单地创建javascript dapp。 224 | 225 | 移动版客户端允许用户通过移动终端来操作自己的 Asch 帐户,它将提供 ios 与安卓两种版本,并于苹果应用商店和安卓应用商店提供下载。它的后端将基于我们的桌面版的解决方案,与桌面版的区别将在于移动版钱包界面将使用响应式技术,自适应移动终端屏幕,并根据移动设计调整了一些交互方式。该 APP 使用了专为移动终端定制了易用的界面,类似于 bitcoin 和一些常用的银行类 app 的界面,而且它将支持在内部运行所有你喜爱的 dapp。 226 | 227 | ## 4.7 性能 228 | 229 | 一笔交易信息通过优化和压缩后大概占 100 字节,我们算算系统达到 1 万 tps 时候需要消耗的带宽。因为出块间隔为 10 秒,那么每次出块需要包含 10 万个交易,也就是说要包含 10M 字节的交易数据,这 10MB 的数据需要在 10 秒内广播到全网,按最理想情况下,第一跳广播到 10 个节点,第二跳广播至 100 个节点,每一跳要在 5 秒内传输完毕,服务器需要的带宽是 10MB * 10 / 5 = 20MB,考虑到中间的带宽损耗和非理想情况,我们认为至少要 40MB 的带宽才能够满足 1 万 tps 的吞吐量。这个带宽要求显然不低,但是相信 1 万 tps 给委托人带来的收益远大于网络维护的费用。2014 年双十一支付宝的吞吐量峰值达到了 8.59 万每秒。Asch 系统在交易吞吐量方面还是有优化空间的,这也是将来我们的重点要投入的方向。 230 | 231 | # 5 应用场景 232 | 233 | ## 5.1 令牌系统 234 | 235 | 使用 Asch 工具创建的第一个 hello world 应用,就是一个最基本的令牌系统了。 236 | 237 | 开发者可能不需要编写代码,只要在 genesis.json 文件里修改一些创世参数,就可以发布一个令牌系统了。Asch 系统中的令牌与以太坊的子货币一样,可以表示黄金、股票、抵押物、或任意其他资产,这些令牌可以与转入侧链中的 XAS 通过去中心化的方式进行交易,从而实现流通,也可以在中心化的交易所与其他货币进行交易。 238 | 239 | ## 5.2 仲裁合约 240 | 241 | 假设一个买家想跟一个不认识的人进行交易,一般情况下如果交易顺利进行的话,双方都不希望有第三方介入,但是如果某个环节出了问题,比如买家对商品不满意时,他们就希望有一个中间人来做调解。这个中间人可能会要求买卖双方出示一些证据,然后做出判决,比如把钱退还一部分给买家。这个业务流程如下: 242 | 243 | 1. 买卖双方共同选择一个中间人 244 | 2. 买家使用三方的公钥创建一个 2-3 的多重签名账户,然后转账到这个账户,再以该账户为发起人,以卖家的账户为接收人,签署一个交易并发布出去。此时这个交易是不能立即被确认的,只有 3 个人中的 2 个人共同签名,才会生效。 245 | 3. 卖家发货给买家。 246 | 4. 如果买家收到货物后,检查没问题,使用自己的私钥对刚才的交易进行签名。然后卖家再次签名后,交易就顺利完成。 247 | 5. 如果买家对货物不满意,可以向中间人发起申诉并出示证据,卖家也可以出示证据,最终由中间人与买卖其中的一方达成一致,共同签署,完成交易,结束仲裁。 248 | 249 | ## 5.3 去中心化交易所 250 | 251 | 根据是否支持法币,可以分为两种程度的去中心化。如果不支持法币,可以实现完全的去中心化,如果支持法币,则只能实现半去中心化,即法币通过网关出入,但交易信息公开。 252 | 253 | 完全的去中心化交易所又分为两种,一种是点对点的交易,通过 Asch 系统提供的“原子跨链交易 api”来实现。另一种是挂单交易,挂单交易要求卖方从其他区块链转入一定的资产到 Asch 侧链中,这个转入操作通过父链冻结资产的 SPV 证明达成。此外,由于关系数据库的支持,利用联表查询和索引功能,可以很容易的实现一个效率不错的撮合引擎。 254 | 255 | ## 5.4 存在性证明 256 | 257 | 存在性证明可以用于登记文件版权、专利等,其基本原理是将要存储的文件的哈希值存入到 Asch 的侧链中,以此来证明某个特定文件存在,还可以加上时间戳、当事人的数字签名等元数据,来证明他们是在何时持有这些文件的。这些信息无法伪造、无法篡改,不会暴露数据和隐私,在需要的时候随时可以验证且不依赖第三方机构。 258 | 259 | ## 5.5 物联网 260 | 261 | 物联网中存在海量的联网设备,很难有一个中央机构来管理所有的设备和各节点的身份。Asch 的侧链是一个很好的解决方案,首先,它解决了节点间信任问题,设备间彼此相连形成分布式网络,通过共识算法来保证设备间交易的合法,并且可追踪、可审查、可分析。其次,不同种类的设备可以接入不同的侧链,这是我们前面提到的天然分片机制,避免了总账本的爆炸式增长。我们试想下,在一个基于区块链的物联网中,一个自动售货机不但可以监控和报告它自身的存货,还可以通过分析历史交易数据智能地从分销商那里进行招标并自动完成付款。 262 | 263 | # 6 总结 264 | 265 | Asch 是一个去中心化的应用平台,其设计初衷是为了降低开发者的门槛,比如使用javascript 作为应用编程语言,支持关系数据库来存储交易数据,使得开发一个 dapp 与传统的 web 应用非常相似,相信这对开发者和中小型企业有很大的吸引力,只有开发者的生产力提高了,整个平台的生态才能够更迅速的繁荣起来。Asch 在设计上也是开放的,并没有局限于某个细分领域,比如金融、文件存储、版权证明等,其提供的 api 都是较底层和抽象的,它们可以被自由组合实现各种不同的应用。在共识机制方面,Asch 继承并增强了 DPOS 算法,大大降低了分叉几率和双重支付风险。另外,Asch 的侧链即应用模式不但延缓了区块链膨胀问题,还使得 dapp 更加的灵活和个性化。Asch 是一个具有前瞻性的、低成本的一站式应用解决方案,相信将成为新一代去中心化应用的孵化器。 -------------------------------------------------------------------------------- /whitepaper/assets/chart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/whitepaper/assets/chart.png -------------------------------------------------------------------------------- /whitepaper/assets/chart2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/whitepaper/assets/chart2.png -------------------------------------------------------------------------------- /whitepaper/assets/math.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/whitepaper/assets/math.png -------------------------------------------------------------------------------- /whitepaper/assets/score.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/whitepaper/assets/score.png -------------------------------------------------------------------------------- /whitepaper/assets/wechat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AschPlatform/asch-docs/846d351ba96c1a3846503a529f5df03dd3bc7a02/whitepaper/assets/wechat.png -------------------------------------------------------------------------------- /whitepaper/cctime/zh-cn.md: -------------------------------------------------------------------------------- 1 | title: CCTime白皮书 2 | --- 3 | # 0 项目介绍 4 | 5 | CCTime(Cryptocurrency Time)是基于阿希(Asch)侧链技术开发的 6 | 分布式社会新闻分享与交流平台。CCTime 在 Hacker News 的基础上进行重 7 | 构,使用区块链技术改变现有中心化的内容市场格局,解决优质内容难以识别、 8 | 传播和变现的问题,通过全新的内容价值评估体系保证优质内容的生产者直接 9 | 获得收益。通过“打赏模式”给予优质新闻发布者、分享者代币激励,构建一 10 | 个有价值且符合大众需求的新闻聚合和内容分享平台。 11 | 12 | # 1 为什么要做 CCTime 13 | 14 | ## 1.1 思想起源 15 | 16 | CCTime(Cryptocurrency Time)作为阿希应用的示范性案例,其创意来源 17 | 于 Hacker News。CCTime 仅包括账户注册与登录、新闻发布、浏览、评论、 18 | 投票等简单功能,设计的核心思想是不做内容原创,不做版权保护,不做社交, 19 | 只做内容分享与评论,使用区块链技术打造轻量级新闻聚合平台。 20 | 21 | 随着开发进度的加深,我们相信这个项目是具有深度发展潜力的,主要有 22 | 以下原因: 23 | 24 | 1. CCTime 的出现填补了以新闻分享和评论为主的区块链行业空白; 25 | 26 | 2. 币圈有一大批高水平的用户,但目前还没有一个像 Hacker News 这样高质量的社区把这群优质用户聚集起来,CCTime 是一个机会,币圈也需要这样一个产品; 27 | 28 | 3. 与传统新闻聚合平台相比,加入代币激励的功能,可以有效解决优质内容难以识别与变现的问题。基于区块链的 CCTime 旨在实现价值回归于价值创造者和传递者手里,让所有的参与者共同分享价值,而不是大部分收益由公司掌控; 29 | 30 | 4. YOYOW 、DECENT 、亿书更注重于内容原创与版权保护,CCTime 只是一个内容分享与评论的平台,属于新闻聚合类的平台,它的竞品应该是今日头条和 flipboard; 31 | 32 | 5. 与今日头条相比,CCTime 排名算法避免了机器学习算法带来的偏见深化问题,因为机器只会推荐你喜欢的内容; 33 | 34 | 6. CCTime 的功能简单易用,可以让用户迅速上手; 35 | 36 | 7. 在如今快速阅读膨胀的时代,新闻应用一直是一个强烈的需求,市场空间巨大。 37 | 38 | 39 | ## 1.2 运作模式 40 | 41 | 中心化的内容发布平台权力全部集中在中心机构,会导致中心化机构权力过大。完全去中心化的内容发布平台权力无法监管,可能会导致大量低俗、色情、反动等言论的自由传播。 42 | 43 | CCTime(Cryptocurrency Time)的理念是传播价值信息。因此,为了减轻、避免,甚至杜绝完全去中心化所带来的负面影响,CCTime 系统采用多种方式结合的监管模式。 44 | 45 | 初期采用受托人作为监管者,受托人通过联合举报的方式来进行过滤,同时监管者的权利也会受到其他人的监督,避免权利的滥用。后期考虑采用“抵押 46 | 发文”的机制,每位发布者在发表信息的时候,通过抵押 XCT(时讯币)发文,系统将根据抵押发文进行排名,供阅读受众“点评”,当达到一定数量的星级时, 47 | 发布者便可通过赎回方式领回代币,也可以继续留给系统,作为下一次分享信息的“筹码”,通过 CCTime 系统的数据分析,抵押率会随之降低。 48 | 49 | # 2 设计理念 50 | 51 | ## 2.1 简单易用 52 | 53 | 仅包括账户注册与登录、新闻发布、浏览、评论、投票等几个功能,不花费精力做社交、版权保护和原创内容,任何人都能够快速轻松使用。 54 | 55 | ## 2.2 监管合规 56 | 57 | 设置监管者角色,对不合规内容(色情、反动、暴力、凶杀等)进行审查。同时监管者也会受到所有人的监督,避免权利的滥用。 58 | 59 | ## 2.3 免费分发 60 | 61 | 代币全部进行免费分发,只 ICO,不进行融资,还原 ICO (Initial CryptoToken Offering)的本质,让更多的人可以免费持有代币。 62 | 63 | ## 2.4 价值共享 64 | 65 | 分布式价值传输,打破传统信息互联网的局限性,通过代币将产生的价值共享给所有的参与者,大家共同享受 CCTime 增值所带来的利润分配,有效的 66 | 促进内容发布者的积极性,促使更高质量的内容产生和传播。 67 | 68 | 69 | 70 | # 3 技术细节 71 | 72 | ## 3.1 资产创生 73 | 74 | CCTime 是基于 Asch 应用 sdk 开发的去中心化应用,与 Asch 主链可以互通资产。CCTime 应用内部不会发行代币,代币来自主链的转入。 75 | 76 | 我们会在 Asch 主链注册一个叫做 CCTime 的发行商,然后使用这个发行商注册一个名为 XCT(时讯币)的资产,这个资产的全称为 CCTime.XCT(时讯币)。 77 | 78 | 资产发行后会被一次性转入 CCTime 应用内部,并且被锁定在这个应用的一个联合签名账户内。 79 | 80 | 我们会在一年之内将 95%的代币免费发放给对这个应用感兴趣的用户。 81 | 82 | 为什么不在 CCTime 内部创生资产? 83 | 84 | 在主链发行资产的好处是,将来这些转入 Dapp 的资产还可以通过跨链接口转移到主链,然后再转到其他应用,以达到一币多链、一币多用的目的。 85 | 86 | ## 3.2 账户体系 87 | 88 | Asch 主链与所有 Dapp 的账户是通用的(老版本的数字地址除外)。账户鉴权使用了非对称加密技术,因此不需要中心化的注册过程。用户只需保管一 89 | 个账户对应的主密码,就可以进行各种区块链的写入操作,比如转账、发布新闻、打赏、点赞、评论等。 90 | 91 | 主密码是使用 bip39 协议生成的由若干个(12 的倍数)单词组成的助记符,而公私钥对是以主密码为种子,通过 ed25519 椭圆曲线算法计算得到 92 | 93 | 账户 id 或账户地址则是由公钥通过两次 sha256 哈希以及一次 ripemd160 哈希再经过 base58check 进行编码获得。 94 | 95 | ## 3.3 密码学算法 96 | 97 | 区块 id 与交易 id 使用的是 sha256 hash 算法 98 | 99 | 区块的记账人签名与交易签名使用的是 ed25519 算法的 sodium 实现版 100 | 101 | ## 3.4 合约及抽象事务模型 102 | 103 | Asch 应用使用了抽象事务模型,这个模型可以表达任意的函数调用。在比特币中,区块的 payload 是交易或转账记录,在 Asch 应用中,区块的 payload 就是函数或合约调用,也叫做事务(transaction)。 104 | 105 | 一个事务可以修改多个状态,比如余额、昵称、新闻、评论等,事务是原子性的,要么全部执行,要么全部撤销,不会出现执行一半的情况。CCTimeime 主要包括以下具体事务: 106 | 107 | 1. postArticle 发布文章(新闻) 108 | 2. postComment 发布评论 109 | 3. voteArticle 给文章投票 110 | 4. likeComment 打赏评论 111 | 5. report 举报文章或评论 112 | 113 | ## 3.5 新闻排名算法 114 | CCTime 使用了如下的综合评分算法: 115 | ![score](../assets/score.png) 116 | 其中, 117 | V 表示一篇文章获得的投票数,投票数以代币 XCT(时讯币)来计量 118 | T 表示距离发布文章的时间(单位为小时),加上 2 是考虑到一篇文章从创作出来 119 | 至分享到 CCTime 系统需要一定的时间,也避免了由于发布时间过短导致分母 120 | 太小的问题 121 | G 是一个重力因子,它决定了文章排名下降的速度,CCTime 使用的默认值为1.8 122 | ![chart](../assets/chart.png) 123 | 从上图可以看到,有三个同时发表的帖子,得票分别为 199 票、59 票和 29 票,分别以黄色、紫色和蓝色表示。在任一个时间点上,都是黄色曲线在最上方,蓝色曲线在最下方。 124 | 在其他条件不变的情况下,越是新发表的帖子,排名越高。或者说,一个帖子的排名,会随着时间不断下降。 125 | 从上图可以看到,经过 24 小时之后,所有帖子的得分基本上都小于 1,这 126 | 意味着它们都将跌到排行榜的末尾,保证了排名前列的都将是较新的内容。 127 | ![chart2](../assets/chart2.png) 128 | 从上图可以看到,三根曲线的其他参数都一样,G 的值分别为 1.5、1.8 和 2.0。G 值越大,曲线越陡峭,排名下降得越快,意味着排行榜的更新速度越快。 129 | (本节内容引用了阮一峰的博客, 并稍作修改 ) 130 | 131 | ## 3.6 激励机制 132 | 每个事务的执行都需要消耗基础手续费,费用由发起人支付,并平均分配给所有记账人。 133 | 134 | voteArticle 和 likeComment 两个事务除了基础手续费之外,发起人还需要选择支出额外的代币,用来代表投票及打赏的额度,这些额外支出的代币大部分都奖励给文章的发布者 135 | 或评论的发布者,但少部分(10%)会进入费用池分配给记账人。 136 | 137 | ## 3.7 审查机制 138 | CCTime 是一个去中心化的系统,没有做用户身份认证,用户一般也是匿名登录,我们需要一个审查机制来防止反政府、反社会或其他违反法律的言论的出现。 139 | 140 | CCTime1.0 的审查暂时由全体受托人来负责,每个受托人都可以举报任意一篇文章或评论,被举报次数超过 3 次的文章或评论将会过滤掉,但不会从底层数据库删除,仅仅是做一次标记。 141 | 142 | 审查机制影响的只是查询接口返回的数据,一个兼容 CCTime 协议的非标准节点仍然可以展示出所有非过滤的数据。 143 | 144 | 145 | # 4 分发机制 146 | XCT(时讯币)发行上限 100 亿。主创团队预留 5%代币,10%赠送给合作伙伴,其余 85%将全部空投给以币圈为主的社会各界人士,不进行融资,还原ICO (Initial Crypto-Token Offering)本质 147 | 148 | ## 4.1 分发原则 149 | 150 | 分发的原则是尽量覆盖更多的用户群体,但是以币圈内主,币圈外为次。对于币圈内采用资产证明(Proof of Asset)的方式。对于币圈外的社区,比如知乎,计划采用影响力证明的方式,但具体方案待定,方案将面向全社区征集。 151 | 152 | ## 4.2 币圈多社区分配公式(MCDF) 153 | 154 | ![math](../assets/math.png) 155 | 156 | ## 4.3 分期空投细则 157 | 158 | ### 4.3.1 首轮空投规则 159 | 160 | 1. 只针对币圈四个社区(阿希币,比特币,以太坊,比特股); 161 | 162 | 2. 采用 5.2 节的多社区分配规则; 163 | 164 | 3. 8 月 20 号正式开始空投, 9 月 20 号对四大公有链进行快照,并按公式计算出用户应得份额后立即分发代币 ; 165 | 166 | 4. 分配总量 10 亿; 167 | 168 | 5. 示例说明请参考附录 A。 169 | 170 | ### 4.3.2 第二期以后 171 | 172 | 从第二期开始,持有 XCT(时讯币)可参与空投,除了指定币种外,每个XCT(时讯币)可领取 0.1 个 XCT(时讯币),其他币种以及空投比例,方案待定。 173 | 174 | 175 | # 5 竞争优势 176 | 177 | CCTime(Cryptocurrency Time)是基于阿希系统侧链的第一个 Dapp 应用(去中心化的内容分发平台),相比于 Steem、Synereo、Decent、PressOne等其他平台拥有较大的优势,具体地: 178 | 179 | 1. 拥有阿希的技术支持和社区支持; 180 | 2. 产品模式创新,细分市场无竞争者; 181 | 3. 免费分发 182 | 183 | # 6 风险提示 184 | 185 | 虽然 CCTime(Cryptocurrency Time)分发模式采用空投,但随着每轮空投,受众人数的增加, XCT(时讯币)难免会带来炒作(操作)风险的可能,包括但不局限: 186 | 187 | 1. 二级交易市场形成,线下交易活跃,风险大; 188 | 189 | 2. XCT(时讯币)一经分发,官方不再持有,持有者即为所有者, 密匙等应当妥善保存,一经丢失,官方不承担责任; 190 | 191 | 3. CCTime(Cryptocurrency Time)是基于阿希系统的一款分布式内容分享与交流平台的应用,作为一个平台应用,参与者应当遵守相关的法律法规,禁止一切不良、反动等言论,共同打造良好的环境氛围。 192 | 193 | 194 | # 7 更多关注 195 | 阿希团队秉承区块链分享、贡献的理念,经过长时间的调研和开发,即将向国内区块链社区分享阿希生态的第一个应用,欢迎大家的使用,同时也欢迎广大的区块链开发者加入阿希社区,共同推进中国区块链应用落地。 196 | 197 | CCTime(Cryptocurrency Time)即将与大家见面,更多资讯敬请关注: 198 | 199 | CCTime 官网:www.cctime.org 200 | 201 | ASCH 官网:www.asch.so 202 | 203 | 官方微博:北京阿希链科技有限公司 204 | 205 | ASCH 官方微信公众号: 206 | 207 | ![wechat](../assets/wechat.png) 208 | 209 | 官方 QQ 群: 210 | 211 | CCTime 官方 1 群:644658047 212 | 213 | CCTime 官方 2 群:65622549 214 | 215 | #8 附录A:XCT(时讯币)首轮空投示例 216 | 217 | 举例:假如本轮参与阿希币的总量为 4000 万(Xxas),阿希的加权系数为 2 阿希 218 | 币的总量按照 1 亿(Sxas)计算。 219 | 阿希币的比例: 220 | Pxas=Xxas*Kxas/Sxas=4000 万*2/1 亿=0.8 221 | 假如本轮参与比特币的总量为 500 万(Xbtc),比特币的加权系数为 1,比特币 222 | 的总量按照 2000 万(Sbtc)计算。 223 | 比特币的比例: 224 | Pbtc=Xbtc*Kbtc/Sbtc=500 万*1/2000 万=0.25 225 | 假如本轮参与以太坊币的总量为 5000 万(Xeth),以太坊币的加权系数为 1,以 226 | 太坊币的总量按照 1 亿(Seth)计算。 227 | 以太坊的比例: 228 | Peth=Xeth*Keth/Seth=5000 万*1/1 亿=0.5 229 | 假如本轮参与比特股的总量为 10 亿(Xbts),比特股的加权系数为 1,比特股的 230 | 总量按照 25 亿(Sbts)计算。 231 | 比特股的比例: 232 | Pbts=Xbts*Kbts/Sbts=10 亿*1/25 亿=0.4 233 | 阿希币获得的空投总量: 234 | Gxas=DPxas/Pxas+Pbtc+Peth+ Pbts=10 亿*0.8/(0.8+0.25+0.5+0.4)=4.10 亿 235 | 比特币获得的空投总量: 236 | Gbtc=DPbtc/Pxas+Pbtc+Peth+ Pbts =10 亿*0.25/(0.8+0.25+0.5+0.4)=1.28 亿 237 | 以太币获得的空投总量: 238 | Geth=DPeth/Pxas+Pbtc+Peth+ Pbts =10 亿*0.5/(0.8+0.25+0.5+0.4)=2.56 亿 239 | 比特股获得的空投总量: 240 | Gbts=DPxas/Pxas+Pbtc+Peth+ Pbts=10 亿*0.4/(0.8+0.25+0.5+0.4)=2.05 亿 241 | 假如用户 j 持有百分之一(40 万)阿希币(Txasj),可以获得 CCTime 数量: 242 | Uxasj=√40 万 ∗ 4.1 亿/∑√Txasj亿 243 | 假如用户 j 持有百分之一(5 万)比特币(Tbtcj),可以获得 CCTime 数量: 244 | Ubtcj=√5 万 ∗ 1.28 亿/∑√Tbtcj亿 245 | 假如用户 j 持有百分之一(50 万)以太币(Tethj),可以获得 CCTime 数量: 246 | Ubtcj=√50 万 ∗ 2.56 亿/∑√Tethj亿 247 | 假如用户 j 持有百分之一(1000 万)比特股(Tbtsj),可以获得 CCTime 数量: 248 | Ubtcj=√1000 万 ∗ 2.05 亿/∑√Tbtsj亿 249 | --------------------------------------------------------------------------------