code refactoring
This commit is contained in:
parent
cd89411365
commit
c857c04b85
@ -86,8 +86,11 @@
|
|||||||
txHex({ txid, url }) {
|
txHex({ txid, url }) {
|
||||||
return fetch_api(`tx/${txid}/hex`, { url: url || this.url, asText: true })
|
return fetch_api(`tx/${txid}/hex`, { url: url || this.url, asText: true })
|
||||||
},
|
},
|
||||||
txs({ addr, before, after, url }) {
|
txs({ addr, url, ...args }) {
|
||||||
return fetch_api(`address/${addr}/txs${before ? `?before=${before}` : ''}${after ? `?after=${after}` : ''}`, { url: url || this.url })
|
let queryParams = Object.entries(args).map(([key, value]) => `${key}=${value}`).join('&')
|
||||||
|
if (queryParams)
|
||||||
|
queryParams = '?' + queryParams
|
||||||
|
return fetch_api(`address/${addr}/txs${queryParams}`, { url: url || this.url })
|
||||||
},
|
},
|
||||||
async block({ id, url }) {
|
async block({ id, url }) {
|
||||||
// if id is hex string then it is block hash
|
// if id is hex string then it is block hash
|
||||||
@ -123,8 +126,11 @@
|
|||||||
txHex({ txid }) {
|
txHex({ txid }) {
|
||||||
return fetch_api(`tx/${txid}/hex`, { url: this.url, asText: true })
|
return fetch_api(`tx/${txid}/hex`, { url: this.url, asText: true })
|
||||||
},
|
},
|
||||||
txs({ addr, before, after }) {
|
txs({ addr, ...args }) {
|
||||||
return fetch_api(`address/${addr}/txs${before ? `?before=${before}` : ''}${after ? `?after=${after}` : ''}`, { url: this.url })
|
let queryParams = Object.entries(args).map(([key, value]) => `${key}=${value}`).join('&')
|
||||||
|
if (queryParams)
|
||||||
|
queryParams = '?' + queryParams
|
||||||
|
return fetch_api(`address/${addr}/txs${queryParams}`, { url: this.url })
|
||||||
},
|
},
|
||||||
async block({ id }) {
|
async block({ id }) {
|
||||||
// if id is hex string then it is block hash
|
// if id is hex string then it is block hash
|
||||||
@ -160,8 +166,11 @@
|
|||||||
txHex({ txid }) {
|
txHex({ txid }) {
|
||||||
return fetch_api(`rawtx/${txid}?format=hex`, { url: this.url, asText: true })
|
return fetch_api(`rawtx/${txid}?format=hex`, { url: this.url, asText: true })
|
||||||
},
|
},
|
||||||
txs({ addr, before, after }) {
|
txs({ addr, ...args }) {
|
||||||
return fetch_api(`rawaddr/${addr}${before ? `?before=${before}` : ''}${after ? `?after=${after}` : ''}`, { url: this.url })
|
let queryParams = Object.entries(args).map(([key, value]) => `${key}=${value}`).join('&')
|
||||||
|
if (queryParams)
|
||||||
|
queryParams = '?' + queryParams
|
||||||
|
return fetch_api(`rawaddr/${addr}${queryParams}`, { url: this.url })
|
||||||
.then(result => result.txs)
|
.then(result => result.txs)
|
||||||
},
|
},
|
||||||
latestBlock() {
|
latestBlock() {
|
||||||
@ -347,10 +356,6 @@
|
|||||||
console.error(error)
|
console.error(error)
|
||||||
APIs[index].coolDownTime = new Date().getTime() + 1000 * 60 * 10; // 10 minutes
|
APIs[index].coolDownTime = new Date().getTime() + 1000 * 60 * 10; // 10 minutes
|
||||||
return multiApi(fnName, { index: index + 1, ...args });
|
return multiApi(fnName, { index: index + 1, ...args });
|
||||||
if (error.code && [301, 429, 404].includes(error.code)) {
|
|
||||||
} else {
|
|
||||||
throw error.message || error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
2
scripts/btcOperator.min.js
vendored
2
scripts/btcOperator.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user