OSDN Git Service

Bump node-sass from 4.11.0 to 4.13.1
[bytom/Bytom-Dapp-Demo.git] / README.md
1 # Bytom-Dapp-Demo
2
3
4 ## What is this?
5 A simple deposit and profit bytom dapp demo, Bytom-Chrome-Extension needed before it can be used. 
6
7 ## Setup
8 - Install [Node.js](https://nodejs.org) version 8 and the latest available npm@6.
9 - Install dependencies: `npm install`.
10
11 ### Buffer Server
12 Before run all the project, you may need to set up you own [bufferserver](https://github.com/oysheng/bufferserver). Configure the proxy rules under the `webpack.config.js`.
13
14 ### Deploy Contract
15 Currently we are manually deploy the contract using the [equity compiler tool](https://github.com/Bytom/equity), and configure the `control program` constants accordingly.
16
17 ### Contract configuration
18 Network and smart contract control program's constants configurations are stored under the `contracts/configure.json.js` file.
19 You may edit the configure after an new control program is launched.
20
21 ### Dapp logic
22 Under the `./src/components/util/submitContract.js`, you will see the basic and reusable logic, for developing a Dapp. Including the following steps:
23 - list utxo from buffer server
24 - create the custom contract transaction
25 - lock utxo
26 - call `window.bytom.send_advanced_transaction` to create the advanced Transaction
27 - update balance if success.
28
29 ### Input and Output Object
30 #### Input
31 The first Input object must be spend utxo action, utxo will be selected according to the amount matches.
32
33 The second Spend Wallet Action, maybe needed if there is a exchanged. 
34  
35 ```
36 input.push(spendUTXOAction(utxo))
37 input.push(spendWalletAction(amount, GetContractArgs().assetDeposited))
38 ```
39
40 #### Output
41 Since the contract type and logic are different, building the unlock action may be different.
42
43 ```
44 if amountDeposited < billAmount {
45       lock amountDeposited of assetDeposited with FixedLimitProfit(billAsset, totalAmountBill, totalAmountCapital, expireBlockHeight, additionalBlockHeight, banker, bankerKey)
46       lock amountDeposited of billAsset with saver
47       lock billAmount-amountDeposited of billAsset with FixedLimitCollect(assetDeposited, totalAmountBill, totalAmountCapital, dueBlockHeight, expireBlockHeight, additionalBlockHeight, banker, bankerKey)
48     } else {
49       lock amountDeposited of assetDeposited with FixedLimitProfit(billAsset, totalAmountBill, totalAmountCapital, expireBlockHeight, additionalBlockHeight, banker, bankerKey)
50       lock billAmount of billAsset with saver
51     }
52 ```
53 Will need to be converted into
54 ```
55  if(amount < billAmount){
56           output.push(controlProgramAction(amount, GetContractArgs().assetDeposited, GetContractArgs().profitProgram))
57           output.push(controlAddressAction(amount, billAsset, address))
58           output.push(controlProgramAction((BigNumber(billAmount).minus(BigNumber(amount))).toNumber(), billAsset, GetContractArgs().depositProgram))
59         }else{
60           output.push(controlProgramAction(amount, GetContractArgs().assetDeposited, GetContractArgs().profitProgram))
61           output.push(controlAddressAction(billAmount, billAsset, address))
62         }
63 ```
64
65
66 ## Run the Project
67
68 Make sure the contracts are compiled, built the correct input output object and bufferserver is running.
69
70 Start the Webpack dev server.
71
72 `npm start`
73
74 Your server should now be running at http://127.0.0.1:8080
75
76 ## Building the Project
77    
78 `npm run build`
79