This commit is contained in:
commit
fad58b6ed4
@ -1,4 +1,4 @@
|
|||||||
(function (EXPORTS) { //btcOperator v1.1.3b
|
(function (EXPORTS) { //btcOperator v1.1.4
|
||||||
/* BTC Crypto and API Operator */
|
/* BTC Crypto and API Operator */
|
||||||
const btcOperator = EXPORTS;
|
const btcOperator = EXPORTS;
|
||||||
|
|
||||||
@ -44,6 +44,7 @@
|
|||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
util.get_fee_rate = get_fee_rate;
|
||||||
|
|
||||||
const broadcastTx = btcOperator.broadcastTx = rawTxHex => new Promise((resolve, reject) => {
|
const broadcastTx = btcOperator.broadcastTx = rawTxHex => new Promise((resolve, reject) => {
|
||||||
let url = 'https://coinb.in/api/?uid=1&key=12345678901234567890123456789012&setmodule=bitcoin&request=sendrawtransaction';
|
let url = 'https://coinb.in/api/?uid=1&key=12345678901234567890123456789012&setmodule=bitcoin&request=sendrawtransaction';
|
||||||
@ -282,6 +283,14 @@
|
|||||||
BECH32_MULTISIG_OUTPUT_SIZE = 34,
|
BECH32_MULTISIG_OUTPUT_SIZE = 34,
|
||||||
SEGWIT_OUTPUT_SIZE = 23;
|
SEGWIT_OUTPUT_SIZE = 23;
|
||||||
|
|
||||||
|
btcOperator.CONSTANTS = {
|
||||||
|
DUST_AMT, MIN_FEE_UPDATE, SATOSHI_IN_BTC,
|
||||||
|
BASE_TX_SIZE, BASE_INPUT_SIZE, LEGACY_INPUT_SIZE, BECH32_INPUT_SIZE,
|
||||||
|
BECH32_MULTISIG_INPUT_SIZE, SEGWIT_INPUT_SIZE, MULTISIG_INPUT_SIZE_ES,
|
||||||
|
BASE_OUTPUT_SIZE, LEGACY_OUTPUT_SIZE, BECH32_OUTPUT_SIZE,
|
||||||
|
BECH32_MULTISIG_OUTPUT_SIZE, SEGWIT_OUTPUT_SIZE
|
||||||
|
};
|
||||||
|
|
||||||
function _redeemScript(addr, key) {
|
function _redeemScript(addr, key) {
|
||||||
let decode = coinjs.addressDecode(addr);
|
let decode = coinjs.addressDecode(addr);
|
||||||
switch (decode.type) {
|
switch (decode.type) {
|
||||||
@ -317,6 +326,7 @@
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
util.sizePerInput = _sizePerInput;
|
||||||
|
|
||||||
function _sizePerOutput(addr) {
|
function _sizePerOutput(addr) {
|
||||||
switch (coinjs.addressDecode(addr).type) {
|
switch (coinjs.addressDecode(addr).type) {
|
||||||
@ -332,6 +342,7 @@
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
util.sizePerOutput = _sizePerOutput;
|
||||||
|
|
||||||
function validateTxParameters(parameters) {
|
function validateTxParameters(parameters) {
|
||||||
let invalids = [];
|
let invalids = [];
|
||||||
@ -442,6 +453,20 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getUTXOs = btcOperator.getUTXOs = addr => new Promise((resolve, reject) => {
|
||||||
|
fetch_api(`unspent?active=${addr}`).then(result => {
|
||||||
|
let utxos = result.unspent_outputs;
|
||||||
|
resolve(utxos.map(u => ({
|
||||||
|
txid: u.tx_hash_big_endian,
|
||||||
|
vout: u.tx_output_n,
|
||||||
|
n: u.tx_output_n,
|
||||||
|
value: u.value,
|
||||||
|
value_hex: u.value_hex,
|
||||||
|
script: u.script
|
||||||
|
})))
|
||||||
|
}).catch(error => reject(error))
|
||||||
|
})
|
||||||
|
|
||||||
function addUTXOs(tx, senders, redeemScripts, required_amount, fee_rate, rec_args = {}) {
|
function addUTXOs(tx, senders, redeemScripts, required_amount, fee_rate, rec_args = {}) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
required_amount = parseFloat(required_amount.toFixed(8));
|
required_amount = parseFloat(required_amount.toFixed(8));
|
||||||
@ -462,8 +487,7 @@
|
|||||||
rs = redeemScripts[rec_args.n];
|
rs = redeemScripts[rec_args.n];
|
||||||
let addr_type = coinjs.addressDecode(addr).type;
|
let addr_type = coinjs.addressDecode(addr).type;
|
||||||
let size_per_input = _sizePerInput(addr, rs);
|
let size_per_input = _sizePerInput(addr, rs);
|
||||||
fetch_api(`unspent?active=${addr}`).then(result => {
|
getUTXOs(addr).then(utxos => {
|
||||||
let utxos = result.unspent_outputs;
|
|
||||||
//console.debug("add-utxo", addr, rs, required_amount, utxos);
|
//console.debug("add-utxo", addr, rs, required_amount, utxos);
|
||||||
for (let i = 0; i < utxos.length && required_amount > 0; i++) {
|
for (let i = 0; i < utxos.length && required_amount > 0; i++) {
|
||||||
if (!utxos[i].confirmations) //ignore unconfirmed utxo
|
if (!utxos[i].confirmations) //ignore unconfirmed utxo
|
||||||
@ -480,7 +504,7 @@
|
|||||||
script = Crypto.util.bytesToHex(s.buffer);
|
script = Crypto.util.bytesToHex(s.buffer);
|
||||||
} else //redeemScript for multisig (segwit)
|
} else //redeemScript for multisig (segwit)
|
||||||
script = rs;
|
script = rs;
|
||||||
tx.addinput(utxos[i].tx_hash_big_endian, utxos[i].tx_output_n, script, 0xfffffffd /*sequence*/); //0xfffffffd for Replace-by-fee
|
tx.addinput(utxos[i].txid, utxos[i].vout, script, 0xfffffffd /*sequence*/); //0xfffffffd for Replace-by-fee
|
||||||
//update track values
|
//update track values
|
||||||
rec_args.input_size += size_per_input;
|
rec_args.input_size += size_per_input;
|
||||||
rec_args.input_amount += util.Sat_to_BTC(utxos[i].value);
|
rec_args.input_amount += util.Sat_to_BTC(utxos[i].value);
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
(function (EXPORTS) { //floCloudAPI v2.4.5
|
(function (EXPORTS) { //floCloudAPI v2.4.5a
|
||||||
/* FLO Cloud operations to send/request application data*/
|
/* FLO Cloud operations to send/request application data*/
|
||||||
'use strict';
|
'use strict';
|
||||||
const floCloudAPI = EXPORTS;
|
const floCloudAPI = EXPORTS;
|
||||||
@ -551,7 +551,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
//request any data from supernode cloud
|
//request any data from supernode cloud
|
||||||
const requestApplicationData = floCloudAPI.requestApplicationData = function (type, options = {}) {
|
const _requestApplicationData = function (type, options = {}) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var request = {
|
var request = {
|
||||||
receiverID: options.receiverID || DEFAULT.adminID,
|
receiverID: options.receiverID || DEFAULT.adminID,
|
||||||
@ -582,6 +582,17 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
floCloudAPI.requestApplicationData = function (type, options = {}) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let single_request_mode = !(options.callback instanceof Function);
|
||||||
|
_requestApplicationData(type, options).then(data => {
|
||||||
|
if (single_request_mode)
|
||||||
|
resolve(objectifier(data))
|
||||||
|
else resolve(data);
|
||||||
|
}).catch(error => reject(error))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/*(NEEDS UPDATE)
|
/*(NEEDS UPDATE)
|
||||||
//delete data from supernode cloud (received only)
|
//delete data from supernode cloud (received only)
|
||||||
floCloudAPI.deleteApplicationData = function(vectorClocks, options = {}) {
|
floCloudAPI.deleteApplicationData = function(vectorClocks, options = {}) {
|
||||||
@ -615,7 +626,7 @@
|
|||||||
//request the data from cloud for resigning
|
//request the data from cloud for resigning
|
||||||
let req_options = Object.assign({}, options);
|
let req_options = Object.assign({}, options);
|
||||||
req_options.atVectorClock = vectorClock;
|
req_options.atVectorClock = vectorClock;
|
||||||
requestApplicationData(undefined, req_options).then(result => {
|
_requestApplicationData(undefined, req_options).then(result => {
|
||||||
if (!result.length)
|
if (!result.length)
|
||||||
return reject("Data not found");
|
return reject("Data not found");
|
||||||
let data = result[0];
|
let data = result[0];
|
||||||
@ -709,11 +720,11 @@
|
|||||||
storeGeneral(fk, d);
|
storeGeneral(fk, d);
|
||||||
options.callback(d, e)
|
options.callback(d, e)
|
||||||
}
|
}
|
||||||
requestApplicationData(type, new_options)
|
_requestApplicationData(type, new_options)
|
||||||
.then(result => resolve(result))
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error))
|
.catch(error => reject(error))
|
||||||
} else {
|
} else {
|
||||||
requestApplicationData(type, options).then(dataSet => {
|
_requestApplicationData(type, options).then(dataSet => {
|
||||||
storeGeneral(fk, objectifier(dataSet))
|
storeGeneral(fk, objectifier(dataSet))
|
||||||
resolve(dataSet)
|
resolve(dataSet)
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
@ -738,7 +749,7 @@
|
|||||||
}
|
}
|
||||||
delete options.callback;
|
delete options.callback;
|
||||||
}
|
}
|
||||||
requestApplicationData(objectName, options).then(dataSet => {
|
_requestApplicationData(objectName, options).then(dataSet => {
|
||||||
updateObject(objectName, objectifier(dataSet));
|
updateObject(objectName, objectifier(dataSet));
|
||||||
delete options.comment;
|
delete options.comment;
|
||||||
options.lowerVectorClock = lastVC[objectName] + 1;
|
options.lowerVectorClock = lastVC[objectName] + 1;
|
||||||
@ -746,11 +757,11 @@
|
|||||||
if (callback) {
|
if (callback) {
|
||||||
let new_options = Object.create(options);
|
let new_options = Object.create(options);
|
||||||
new_options.callback = callback;
|
new_options.callback = callback;
|
||||||
requestApplicationData(objectName, new_options)
|
_requestApplicationData(objectName, new_options)
|
||||||
.then(result => resolve(result))
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error))
|
.catch(error => reject(error))
|
||||||
} else {
|
} else {
|
||||||
requestApplicationData(objectName, options).then(dataSet => {
|
_requestApplicationData(objectName, options).then(dataSet => {
|
||||||
updateObject(objectName, objectifier(dataSet))
|
updateObject(objectName, objectifier(dataSet))
|
||||||
resolve(appObjects[objectName])
|
resolve(appObjects[objectName])
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
@ -825,7 +836,7 @@
|
|||||||
floCloudAPI.downloadFile = function (vectorClock, options = {}) {
|
floCloudAPI.downloadFile = function (vectorClock, options = {}) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
options.atVectorClock = vectorClock;
|
options.atVectorClock = vectorClock;
|
||||||
requestApplicationData(options.type, options).then(result => {
|
_requestApplicationData(options.type, options).then(result => {
|
||||||
if (!result.length)
|
if (!result.length)
|
||||||
return reject("File not found");
|
return reject("File not found");
|
||||||
result = result[0];
|
result = result[0];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user