-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1990.js
53 lines (48 loc) · 1.38 KB
/
1990.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const { Pool } = require("pg");
const stakePoolId = process.argv.slice(2)[0];
const query = `
SELECT json
FROM tx_metadata txm
JOIN tx_in txi ON (txm.tx_id = txi.tx_in_id)
JOIN tx_out txo ON (txm.tx_id = txo.tx_id AND txi.tx_out_index = txo.index)
WHERE txo.stake_address_id IN
(
SELECT id
FROM stake_address sa
WHERE (RIGHT(sa.hash_raw::VARCHAR, LENGTH(sa.hash_raw::VARCHAR)-4)) IN
(
SELECT encode(po.hash, 'hex')
FROM pool_owner po
JOIN pool_hash ph ON (po.pool_hash_id = ph.id)
WHERE registered_tx_id =
(
SELECT MAX(registered_tx_id)
FROM pool_owner po
JOIN pool_hash ph ON (po.pool_hash_id = ph.id)
WHERE view = '${stakePoolId}'
)
)
)
AND txm.key = 1990
ORDER BY txm.id DESC;
`;
// Define PostgreSQL connection to your cardano-db-sync instance
const pool = new Pool({
user: "csyncdb",
host: "localhost",
database: "csyncdb",
port: 5432,
});
pool.query(query, (err, res) => {
const result = res.rows;
console.log("Fetching metadata for stake pool " + stakePoolId + "\n");
for (var i = 0; i < result.length; i++) {
var obj = result[i];
console.log("TITLE: " + obj["json"]["title"]);
var body = obj["json"]["content"].join("");
console.log("BODY: " + body);
console.log("LINK: " + obj["json"]["link"]);
console.log("\n\t ~~ \n");
}
pool.end();
});