OSDN Git Service

update the Styles.
[bytom/Bytom-Dapp-Demo.git] / src / components / layout / profit / action.js
1 import { spendUTXOAction, spendWalletAction, controlProgramAction, controlAddressAction, listUTXO } from '../../bytom'
2 import { profitProgram, assetDeposited, assetBill } from "../../constants";
3
4 export function FixedLimitProfit(amountBill, saver) {
5
6   listUTXO({
7     "filter": {
8       "script": profitProgram,
9       "asset": assetDeposited
10     }
11   }).then(resp => {
12     const capitalAmount = resp.amount
13     const capitalAsset = resp.asset
14     const utxo = resp.hash
15
16     const gas = 40000000
17     const btm = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
18
19     const input = []
20     const output = []
21
22     const totalAmountBill = 10000000000
23     const totalAmountCapital = 20000000000
24
25     const sAmountBill = amountBill/100000000
26     const sTotalAmountBill = totalAmountBill/100000000
27     const gain = totalAmountCapital*sAmountBill/sTotalAmountBill
28
29     const banker = "00140014f19df269f9334bdcb496da6b63b275d49447"
30
31     input.push(spendUTXOAction(utxo, amountBill, saver))
32     input.push(spendWalletAction(amountBill, assetBill))
33     input.push(spendWalletAction(gas, btm))
34
35     if(amountBill < capitalAmount){
36       output.push(controlProgramAction(amountBill, assetBill, banker ))
37       output.push(controlAddressAction(gain, capitalAsset, saver))
38       output.push(controlProgramAction((capitalAmount - gain), capitalAsset, profitProgram))
39     }else{
40       output.push(controlProgramAction(amountBill, assetBill, banker ))
41       output.push(controlAddressAction(capitalAmount, capitalAsset, saver))
42     }
43
44     window.bytom.advancedTransfer(input, output)
45
46   })
47
48 }