import axios from 'axios'
-export function spendUTXOAction(utxo, amount, address){
+export function spendUTXOAction(utxo){
return {
"type": "spend_utxo",
- "output_id": utxo,
- "arguments": [
- {
- "type": "integer",
- "raw_data": {
- "value": amount
- }
- },
- {
- "type": "address",
- "raw_data": {
- "value": address
- }
- },
- {
- "type": "data",
- "raw_data": {
- "value": ""
- }
- }
- ]
+ "output_id": utxo
}
}
+export function contractArguments(amount, address){
+ return [
+ {
+ "type": "integer",
+ "value": amount
+ },
+ {
+ "type": "address",
+ "value": address
+ },
+ {
+ "type": "data",
+ "value": ""
+ }
+ ]
+}
+
export function spendWalletAction(amount, asset){
return {
"amount": amount,
}
}
-export function listUTXO(params)
+export function listAddress(guid)
{
- const url = "/api/api/v1/btm/q/list-utxos"
- return axios({
- method: 'post',
- url,
- data: params
- }).then(response => {
- return response.data.result.data[0];
- })
-}
-
-export function listAddress(params)
-{
- const url = "/api/api/v1/btm//account/list-addresses"
- return axios({
- method: 'post',
- url,
- data: params
- }).then(response => {
- return response.data.result.data[0];
- })
+ return bytomAPI.sdk.accounts.listAddressUseServer(guid)
+ .then(resp => resp[0])
}
export function listDappUTXO(params)
url,
data: params
}).then(response => {
- return response.data.result.data[0];
+ if(response.data.code === 200){
+ return response.data.result.data[0];
+ }
+ else {
+ throw response.data.msg
+ }
})
}
url,
data: params
}).then(response => {
- return response.data.result;
+ if(response.data.code === 200){
+ return response.data.result;
+ }else {
+ throw response.data.msg
+ }
})
}
url,
data: params
}).then(response => {
- return response.data.result;
+ if(response.data.code === 200){
+ return response.data.result;
+ }else{
+ throw response.data.msg
+ }
})
}
url,
data: params
}).then(response => {
- return response.data.result;
+ if(response.data.code === 200){
+ return response.data.result;
+ }else{
+ throw response.data.msg
+ }
})
}
url,
data: params
}).then(response => {
- return response.data.result;
+ if(response.data.code === 200){
+ return response.data.result;
+ }else{
+ throw response.data.msg
+ }
})
}
const updateBalances = (guid = '') => {
return (dispatch) => {
- return listAddress({guid})
+ return listAddress(guid)
.then((resp)=>{
const balances = resp.balances
const billBalance = balances.filter(balance => balance.asset === assetBill)
import {
spendUTXOAction, spendWalletAction, controlProgramAction, controlAddressAction,
- updateBase, updateBalances, updateUtxo, listDappUTXO
+ updateBase, updateBalances, updateUtxo, listDappUTXO, contractArguments
} from '../../bytom'
import {profitProgram, assetDeposited, assetBill, gas, banker, totalAmountBill, totalAmountCapital} from "../../constants";
const sTotalAmountBill = totalAmountBill/100000000
const gain = totalAmountCapital*sAmountBill/sTotalAmountBill
- input.push(spendUTXOAction(utxo, amountBill, saver))
+ const args = contractArguments(amountBill, saver)
+
+ input.push(spendUTXOAction(utxo))
input.push(spendWalletAction(amountBill, assetBill))
if(amountBill < capitalAmount){
output.push(controlAddressAction(capitalAmount, capitalAsset, saver))
}
- window.bytom.advancedTransfer(account, input, output, gas*10000000)
+ window.bytom.advancedTransfer(account, input, output, gas*10000000, args)
.then((resp) => {
if(resp.action === 'reject'){
reject('user reject the request')
"amount": -amountBill
}).then(()=>{
resolve()
+ }).catch(err => {
+ throw err
})
+ }).catch(err => {
+ throw err
})
})
+ .catch(err => {
+ throw err
+ })
}
})
.catch(err => {
import {
spendUTXOAction, spendWalletAction, controlProgramAction,
- controlAddressAction, listDappUTXO, updateBase, updateUtxo ,updateBalances
+ controlAddressAction, listDappUTXO, updateBase, updateUtxo ,updateBalances,
+ contractArguments
} from '../../bytom'
import {
depositProgram, profitProgram, assetDeposited, assetBill, gas
const input = []
const output = []
- input.push(spendUTXOAction(utxo, amount, address))
+ const args = contractArguments(amount, address)
+
+ input.push(spendUTXOAction(utxo))
input.push(spendWalletAction(amount, assetDeposited))
if(amount < billAmount){
output.push(controlAddressAction(billAmount, billAsset, address))
}
- window.bytom.advancedTransfer(account, input, output, gas*10000000)
+ window.bytom.advancedTransfer(account, input, output, gas*10000000, args)
.then((resp) => {
if(resp.action === 'reject'){
reject('user reject the request')
"amount": amount
}).then(()=>{
resolve()
+ }).catch(err => {
+ throw err
})
+ }).catch(err => {
+ throw err
})
})
+ .catch(err => {
+ throw err
+ })
}
})
.catch(err => {