default:
url = "/dapp/list-utxos"
}
- return post(url, params).then(resp => resp.data[0])
+ return post(url, params).then(resp => resp.data)
}
export function updateUtxo(params)
--- /dev/null
+export function matchesUTXO(array, amount){
+ let result = array[0]
+ const length = array.length
+ if( length > 0 ){
+ for(let i = 0; i < length; i++){
+ const resp = array[i]
+ if( resp.amount === amount ){
+ result = resp
+ break
+ }else if( resp.amount < amount ){
+ if(i > 0){
+ result = array[i-1]
+ }
+ break
+ }else if( i === length-1 ){
+ result = array[length-1]
+ }
+ }
+ }
+ return result
+}
\ No newline at end of file
spendUTXOAction, spendWalletAction, controlProgramAction, controlAddressAction,
updateBalances, updateUtxo, listDappUTXO, contractArguments
} from '../../bytom'
-import GetContractArgs from "../../constants";
+import GetContractArgs from '../../constants'
+import { matchesUTXO } from '../../filter'
export function FixedLimitProfit(account, amountBill, saver) {
return new Promise((resolve, reject) => {
"order":"desc"
}
}).then(resp => {
- if(!resp) {
+ if(resp.length === 0) {
throw 'cannot load UTXO info.'
}
- const capitalAmount = resp.amount
- const capitalAsset = resp.asset
- const utxo = resp.hash
+ const result = matchesUTXO(resp, amountBill)
+ const capitalAmount = result.amount
+ const capitalAsset = result.asset
+ const utxo = result.hash
if(amountBill > capitalAmount) {
throw 'input amount must be smaller or equal to ' + capitalAmount + '.'
controlAddressAction, listDappUTXO, updateUtxo, updateBalances,
contractArguments
} from '../../bytom'
-import GetContractArgs from "../../constants";
+import GetContractArgs from '../../constants'
export function FixedLimitDeposit(account, amount, address) {
return new Promise((resolve, reject) => {
"order":"desc"
}
}).then(resp => {
- if(!resp) {
+ if(resp.length === 0) {
throw 'cannot load UTXO info.'
}
- const billAmount = resp.amount
- const billAsset = resp.asset
- const utxo = resp.hash
+ const result = resp[0]
+ const billAmount = result.amount
+ const billAsset = result.asset
+ const utxo = result.hash
if(amount > billAmount){
throw 'input amount must be smaller or equal to ' + billAmount +'.'