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 | 
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 | 
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 | 
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 | 
11 |
12 | ## 3 安装Python
13 | [安装Python](https://www.python.org/downloads/release/python-2713/) 并配置环境变量,版本2.5到3.0之间(最好2.7,3.0以及以上版本不支持),如下所示:
14 |
15 | 
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 | 
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 | 
35 |
36 | 打开命令行验证如下:
37 |
38 | 
39 |
40 | ## 8 安装gcc, g++
41 | 这里有如下两种方式:
42 | * [下载mingw-get-setup](https://sourceforge.net/projects/mingw/files/Installer/),然后再线安装所有依赖包,但是可能会比较慢
43 | * 下载我已经下载好的依赖包,解压缩后放到任意盘,然后配置环境变量,如下所示:
44 |
45 | 
46 |
47 | 安装完成后分别执行一下命令查看是否成功:
48 | ```
49 | gcc -v
50 | g++ -v
51 | ```
52 |
53 | 如下所示:
54 |
55 | 
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 | 
120 |
121 | 最后执行 **node app.js** 即可正常运行,如下图所示:
122 |
123 | 
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 | 
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 | 
47 |
48 | Open the windows `Control Panel`
49 | 
50 |
51 | Select `Environment Variables`:
52 | 
53 |
54 | Edit `%PATH%`:
55 | 
56 |
57 | Add new Environment Variable:
58 | 
59 |
60 | Python is normally installed in `C:\Python27`.
61 | 
62 |
63 | Add `C:\Python27\` to the Environment Variables:
64 | 
65 |
66 |
67 |
68 | ### Test Python Installation
69 |
70 | Be sure to __restart__ your system before testing if it works.
71 |
72 | 
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 | 
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 | 
93 |
94 | Select:
95 | * __Windows 8.1 SDK__
96 | * __Windows 10 SDK__
97 |
98 | 
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 | 
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 | 
119 |
120 | Git use Windows Command Prompt:
121 | 
122 |
123 | Select Git OpenSSL Version:
124 | 
125 |
126 | Use Windows default console:
127 | 
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 | 
140 |
141 | Create new directory `C:\sqlite3`
142 | 
143 |
144 | Edit `%PATH%`:
145 | 
146 |
147 | 
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 | 
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 | 
160 |
161 | Setup:
162 | 
163 |
164 | Apply Changes:
165 | 
166 |
167 | Edit `%PATH%`:
168 | 
169 |
170 | Àdd the environment variable `C:\MinGW\bin\`:
171 | 
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 | 
183 |
184 |
185 | ## 10 Install OpenSSL
186 |
187 | Install OpenSSL.
188 | [Download](http://slproweb.com/products/Win32OpenSSL.html)
189 |
190 | Select correct version:
191 | 
192 |
193 | Choose Installation option:
194 | 
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 | 
263 |
264 | Finally, execute **node app.js** to start the blockchain, as shown in the following figure:
265 |
266 | 
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 |
104 |
105 | ### **DApp needs right folder structure**
106 |
107 | The minimum folder configuration is listed below:
108 |
109 | 
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 | 
116 |
117 |
118 | ### **Directory asch/public/dist/chains must exist**
119 |
120 | Make sure that the `asch/public/dist/chains` exists.
121 |
122 | 
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 | 
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 | 
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 | 
230 | 
231 |
232 | DApp 的日志目录为 asch/chains/chainname/logs/debug.2018xxxx.log
233 |
234 | 
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 | 
83 |
84 |
85 | The `ndb` tool looks like the Chrome Debugger. You can also save files to the filesystem.
86 |
87 | 
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 | 
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 | 
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 | 
109 |
110 | Start the ASCH blockchain again by executing the `app.js` file (like in point [**Start Blockchain**](#start-blockchain)).
111 | 
112 |
113 |
114 | The debugger hits the `debugger;` statement a few seconds after the ASCH blockchain started:
115 |
116 | 
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 | 
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 | 
180 |
181 | Every process must be killed with the __white square__ button:
182 | 
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 | 
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 | 
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 | 
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 | 
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 | 
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 | 
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 | 
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 | 
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 | 
44 |
45 | ## 解决安全问题
46 |
47 | 这里的安全问题与上面提到的因为节点不足导致的问题不一样,这里说的安全问题是指侧链代码对安装者造成侵犯的问题。
48 | 我们希望每一个asch节点都能安装一个侧链,而且asch节点的主人无需信任侧链的开发者。这就需要提供一种安全防范的措施,比如,防止侧链代码肆意读取文件系统、进行网络操作。
49 | 在asch系统中,侧链代码会以子进程的方式启动,子进程首先加载一个使用沙箱机制隔离的javascript虚拟机,这个js虚拟机就是没有```require```以及任何多余模块的裸体虚拟机。
50 | 然后我们为这个虚拟机植入一个定制的```require```和一些常用且安全的模块, 最后再加载侧链的代码。
51 | 我们还通过进程间通讯的方式提供一系列的api。
52 | 这样,侧链的框架就拥有了足够多的api,同时侧链的安装者也没有任何风险。
53 |
54 | 
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 |