Create Key Image Table
-
Install PostgreSQL if you have not already done so.
-
Set the password for the
postgres
user via the following commands.sudo su postgres
psql
\password postgres
-
There is a file called
create_keyimages_table.sql
in thescripts/monero
directory with the following contents.CREATE TABLE xmr_keyimages ( image VARCHAR(64) NOT NULL, id SERIAL PRIMARY KEY, ring_amount BIGINT, ring_indices INTEGER[], distinct_ring_indices INTEGER[], block_height INTEGER, UNIQUE(image) )
Note: Some old transaction rings in Monero have repeated ring members. The
distinct_ring_indices
only stores the distinct ring member indices. -
Run the following command in the
scripts/monero
directory to create thexmr_keyimages
table.psql -U postgres -h 127.0.0.1 -W -f create_keyimages_table.sql
NOTE: Alternatively, you can create the
xmr_keyimages
table by running the script calledkeyimage_table_creation.sh
in thescripts/monero
directory. You can run the commandsource keyimage_table_creation.sh
and enter the Postgres user password when prompted. -
You can check that the table was successfully created by running the
\dt
command in thepsql
shell.- Run the following commands to enter the
psql
shell.sudo su postgres psql
- Run the
\dt
command in the shell. The output should look like the following.postgres=# \dt List of relations Schema | Name | Type | Owner --------+---------------+-------+---------- public | xmr_keyimages | table | postgres (1 row)
- The
xmr_keyimages
table will be initially empty.postgres=# SELECT * FROM xmr_keyimages; image | id | ring_amount | ring_indices | distinct_ring_indices | block_height -------+----+-------------+--------------+-----------------------+-------------- (0 rows)
- Run the following commands to enter the
-
Run the Monero CLI client in offline mode using the following command. In this mode, the client will not download new blocks.
./monerod --offline
-
Run the
populate_keyimage_table.py
script that is located in thescripts/monero
directory.python3 populate_keyimage_table.py
This script will query the Monero client and populate the
xmr_keyimages
table with non-coinbase transactions from block height 0 to block height 2,530,000. The latter block was mined on January 4, 2022. This script can take more than a day to finish running.WARNING: Before running this script, don't forget to change the
postgres
user password in the script to the password you have set. It needs to be changed in the argument topsycopg2.connect()
. -
Once the
populate_keyimage_table.py
script finishes running, you can stop themonerod
client by pressing Ctrl-D in the CLI window.