floBlockchainAPI v2.0.1b
Additional filter options to readData function - receivedOnly: filters only received data - txid: (boolean) resolve txid or not - sender: flo-id(s) of sender - receiver: flo-id(s) of receiver
This commit is contained in:
parent
05f110661e
commit
962f68c230
@ -7292,7 +7292,7 @@ Bitcoin.Util = {
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script id="floBlockchainAPI" version="2.0.1a">
|
||||
<script id="floBlockchainAPI" version="2.0.1b">
|
||||
/* FLO Blockchain Operator to send/receive data from blockchain using API calls*/
|
||||
const floBlockchainAPI = {
|
||||
|
||||
@ -7691,13 +7691,18 @@ Bitcoin.Util = {
|
||||
limit : maximum number of filtered data (default = 1000, negative = no limit)
|
||||
ignoreOld : ignore old txs (default = 0)
|
||||
sentOnly : filters only sent data
|
||||
pattern : filters data that starts with a pattern
|
||||
contains : filters data that contains a string
|
||||
receivedOnly: filters only received data
|
||||
pattern : filters data that with JSON pattern
|
||||
filter : custom filter funtion for floData (eg . filter: d => {return d[0] == '$'})
|
||||
txid : (boolean) resolve txid or not
|
||||
sender : flo-id(s) of sender
|
||||
receiver : flo-id(s) of receiver
|
||||
*/
|
||||
readData: function(addr, options = {}) {
|
||||
options.limit = options.limit || 0
|
||||
options.ignoreOld = options.ignoreOld || 0
|
||||
if (typeof options.sender === "string") options.sender = [options.sender];
|
||||
if (typeof options.receiver === "string") options.receiver = [options.receiver];
|
||||
return new Promise((resolve, reject) => {
|
||||
this.promisedAPI(`api/addrs/${addr}/txs?from=0&to=1`).then(response => {
|
||||
var newItems = response.totalItems - options.ignoreOld;
|
||||
@ -7708,8 +7713,6 @@ Bitcoin.Util = {
|
||||
var filteredData = [];
|
||||
for (i = 0; i < (response.totalItems - options.ignoreOld) &&
|
||||
filteredData.length < options.limit; i++) {
|
||||
if (options.sentOnly && response.items[i].vin[0].addr !== addr)
|
||||
continue;
|
||||
if (options.pattern) {
|
||||
try {
|
||||
let jsonContent = JSON.parse(response.items[i].floData)
|
||||
@ -7719,9 +7722,45 @@ Bitcoin.Util = {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (options.sentOnly) {
|
||||
let flag = false;
|
||||
for (let vin of response.items[i].vin)
|
||||
if (vin.addr === addr) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
if (!flag) continue;
|
||||
}
|
||||
if (Array.isArray(options.sender)) {
|
||||
let flag = false;
|
||||
for (let vin of response.items[i].vin)
|
||||
if (options.sender.includes(vin.addr)) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
if (!flag) continue;
|
||||
}
|
||||
if (options.receivedOnly) {
|
||||
let flag = false;
|
||||
for (let vout of response.items[i].vout)
|
||||
if (vout.scriptPubKey.addresses[0] === addr) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
if (!flag) continue;
|
||||
}
|
||||
if (Array.isArray(options.receiver)) {
|
||||
let flag = false;
|
||||
for (let vout of response.items[i].vout)
|
||||
if (options.receiver.includes(vout.scriptPubKey.addresses[0])) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
if (!flag) continue;
|
||||
}
|
||||
if (options.filter && !options.filter(response.items[i].floData))
|
||||
continue;
|
||||
filteredData.push(response.items[i].floData);
|
||||
filteredData.push(options.txid ? [response.items[i].txid, response.items[i].floData] : response.items[i].floData);
|
||||
}
|
||||
resolve({
|
||||
totalTxs: response.totalItems,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user