|
|
@ -1358,6 +1358,26 @@ class MySqlDbWrapper { |
|
|
|
return (result.length == 0) ? null : result[0].txnID |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Get the mysql IDs of a collection of transactions |
|
|
|
* @param {string[]} txids - txids of the transactions |
|
|
|
* @returns {object[]} returns an array of {txnTxid: txnId} |
|
|
|
*/ |
|
|
|
async getTransactionsIds(txids) { |
|
|
|
if (txids.length == 0) |
|
|
|
return [] |
|
|
|
|
|
|
|
const sqlQuery = 'SELECT `txnID`, `txnTxid` FROM `transactions` WHERE `txnTxid` IN (?)' |
|
|
|
const params = [txids] |
|
|
|
const query = mysql.format(sqlQuery, params) |
|
|
|
const results = await this._query(query) |
|
|
|
|
|
|
|
const ret = {} |
|
|
|
for (let r of results) |
|
|
|
ret[r.txnTxid] = r.txnID |
|
|
|
return ret |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Get the mysql IDs of a set of transactions |
|
|
|
* @param {string[]} txid - array of transactions txids |
|
|
@ -1396,6 +1416,29 @@ class MySqlDbWrapper { |
|
|
|
return this._query(query) |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Insert a collection of transactions in db |
|
|
|
* @param {object[]} txs - array of {txid, version, locktime} |
|
|
|
*/ |
|
|
|
async addTransactions(txs) { |
|
|
|
if (txs.length == 0) |
|
|
|
return |
|
|
|
|
|
|
|
const sqlQuery = 'INSERT INTO `transactions` \ |
|
|
|
(txnTxid, txnCreated, txnVersion, txnLocktime) VALUES ? \ |
|
|
|
ON DUPLICATE KEY UPDATE txnVersion = VALUES(txnVersion)' |
|
|
|
|
|
|
|
const params = [txs.map(tx => [ |
|
|
|
tx.txid, |
|
|
|
tx.created, |
|
|
|
tx.version, |
|
|
|
tx.locktime |
|
|
|
])] |
|
|
|
|
|
|
|
const query = mysql.format(sqlQuery, params) |
|
|
|
return this._query(query) |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Get a transaction for a given txid |
|
|
|
* @param {string} txid - txid of the transaction |
|
|
@ -1773,6 +1816,21 @@ class MySqlDbWrapper { |
|
|
|
return (result.length == 1) ? result[0] : null |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Get a collection of blocks identified by the blocks hashes |
|
|
|
* @param {string[]} hashes - blocks hashes |
|
|
|
* @returns {object[]} returns the blocks |
|
|
|
*/ |
|
|
|
async getBlocksByHashes(hashes) { |
|
|
|
if (hashes.length == 0) |
|
|
|
return [] |
|
|
|
|
|
|
|
const sqlQuery = 'SELECT * FROM `blocks` WHERE `blockHash` IN (?)' |
|
|
|
const params = [hashes] |
|
|
|
const query = mysql.format(sqlQuery, params) |
|
|
|
return await this._query(query) |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Get details about all blocks at a given block height |
|
|
|
* @param {integer} height - block height |
|
|
|