Add pegtxid and pegindex data to federation_txos table

This commit is contained in:
natsee 2024-01-21 12:46:07 +01:00
parent 4b10e32e73
commit de2842b62a
No known key found for this signature in database
GPG Key ID: 233CF3150A89BED8
2 changed files with 8 additions and 6 deletions

View File

@ -839,6 +839,8 @@ class DatabaseMigration {
unspent tinyint(1) NOT NULL, unspent tinyint(1) NOT NULL,
lastblockupdate int(11) unsigned NOT NULL, lastblockupdate int(11) unsigned NOT NULL,
lasttimeupdate int(11) unsigned NOT NULL, lasttimeupdate int(11) unsigned NOT NULL,
pegtxid varchar(65) NOT NULL,
pegindex int(11) NOT NULL,
PRIMARY KEY (txid, txindex), PRIMARY KEY (txid, txindex),
FOREIGN KEY (bitcoinaddress) REFERENCES federation_addresses (bitcoinaddress) FOREIGN KEY (bitcoinaddress) REFERENCES federation_addresses (bitcoinaddress)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;`; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`;

View File

@ -96,8 +96,8 @@ class ElementsParser {
logger.debug(`Saved new Federation address ${bitcoinaddress} to federation addresses.`); logger.debug(`Saved new Federation address ${bitcoinaddress} to federation addresses.`);
// Add the UTXO to the federation txos table // Add the UTXO to the federation txos table
const query_utxos = `INSERT IGNORE INTO federation_txos (txid, txindex, bitcoinaddress, amount, blocknumber, blocktime, unspent, lastblockupdate, lasttimeupdate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`; const query_utxos = `INSERT IGNORE INTO federation_txos (txid, txindex, bitcoinaddress, amount, blocknumber, blocktime, unspent, lastblockupdate, lasttimeupdate, pegtxid, pegindex) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
const params_utxos: (string | number)[] = [bitcointxid, bitcoinindex, bitcoinaddress, amount, bitcoinblock, bitcoinBlockTime, 1, bitcoinblock - 1, 0]; const params_utxos: (string | number)[] = [bitcointxid, bitcoinindex, bitcoinaddress, amount, bitcoinblock, bitcoinBlockTime, 1, bitcoinblock - 1, 0, txid, txindex];
await DB.query(query_utxos, params_utxos); await DB.query(query_utxos, params_utxos);
const [minBlockUpdate] = await DB.query(`SELECT MIN(lastblockupdate) AS lastblockupdate FROM federation_txos WHERE unspent = 1`) const [minBlockUpdate] = await DB.query(`SELECT MIN(lastblockupdate) AS lastblockupdate FROM federation_txos WHERE unspent = 1`)
await this.$saveLastBlockAuditToDatabase(minBlockUpdate[0]['lastblockupdate']); await this.$saveLastBlockAuditToDatabase(minBlockUpdate[0]['lastblockupdate']);
@ -228,8 +228,8 @@ class ElementsParser {
// Check that the UTXO was not already added in the DB by previous scans // Check that the UTXO was not already added in the DB by previous scans
const [rows_check] = await DB.query(`SELECT txid FROM federation_txos WHERE txid = ? AND txindex = ?`, [tx.txid, output.n]) as any[]; const [rows_check] = await DB.query(`SELECT txid FROM federation_txos WHERE txid = ? AND txindex = ?`, [tx.txid, output.n]) as any[];
if (rows_check.length === 0) { if (rows_check.length === 0) {
const query_utxos = `INSERT INTO federation_txos (txid, txindex, bitcoinaddress, amount, blocknumber, blocktime, unspent, lastblockupdate, lasttimeupdate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`; const query_utxos = `INSERT INTO federation_txos (txid, txindex, bitcoinaddress, amount, blocknumber, blocktime, unspent, lastblockupdate, lasttimeupdate, pegtxid, pegindex) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
const params_utxos: (string | number)[] = [tx.txid, output.n, output.scriptPubKey.address, output.value * 100000000, block.height, block.time, 1, block.height, 0]; const params_utxos: (string | number)[] = [tx.txid, output.n, output.scriptPubKey.address, output.value * 100000000, block.height, block.time, 1, block.height, 0, '', 0];
await DB.query(query_utxos, params_utxos); await DB.query(query_utxos, params_utxos);
// Add the UTXO to the utxo array // Add the UTXO to the utxo array
spentAsTip.push({ spentAsTip.push({
@ -348,7 +348,7 @@ class ElementsParser {
// Get all of the UTXOs held by the federation, most recent first // Get all of the UTXOs held by the federation, most recent first
public async $getFederationUtxos(): Promise<any> { public async $getFederationUtxos(): Promise<any> {
const query = `SELECT txid, txindex, bitcoinaddress, amount, blocknumber, blocktime FROM federation_txos WHERE unspent = 1 ORDER BY blocktime DESC;`; const query = `SELECT txid, txindex, bitcoinaddress, amount, blocknumber, blocktime, pegtxid, pegindex FROM federation_txos WHERE unspent = 1 ORDER BY blocktime DESC;`;
const [rows] = await DB.query(query); const [rows] = await DB.query(query);
return rows; return rows;
} }
@ -369,7 +369,7 @@ class ElementsParser {
// Get all of the UTXOs held by the federation one month ago, most recent first // Get all of the UTXOs held by the federation one month ago, most recent first
public async $getFederationUtxosOneMonthAgo(): Promise<any> { public async $getFederationUtxosOneMonthAgo(): Promise<any> {
const query = ` const query = `
SELECT txid, txindex, amount, blocknumber, blocktime FROM federation_txos SELECT txid, txindex, bitcoinaddress, amount, blocknumber, blocktime, pegtxid, pegindex FROM federation_txos
WHERE WHERE
(blocktime < UNIX_TIMESTAMP(TIMESTAMPADD(DAY, -30, CURRENT_TIMESTAMP()))) (blocktime < UNIX_TIMESTAMP(TIMESTAMPADD(DAY, -30, CURRENT_TIMESTAMP())))
AND AND