Create Key Image Table
-
Install PostgreSQL if you have not already done so.
-
Set the password for the
postgresuser via the following commands.sudo su postgrespsql\password postgres
-
There is a file called
create_keyimages_table.sqlin thescripts/monerodirectory 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_indicesonly stores the distinct ring member indices. -
Run the following command in the
scripts/monerodirectory to create thexmr_keyimagestable.psql -U postgres -h 127.0.0.1 -W -f create_keyimages_table.sqlNOTE: Alternatively, you can create the
xmr_keyimagestable by running the script calledkeyimage_table_creation.shin thescripts/monerodirectory. You can run the commandsource keyimage_table_creation.shand enter the Postgres user password when prompted. -
You can check that the table was successfully created by running the
\dtcommand in thepsqlshell.- Run the following commands to enter the
psqlshell.sudo su postgres psql - Run the
\dtcommand 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_keyimagestable 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.pyscript that is located in thescripts/monerodirectory.python3 populate_keyimage_table.pyThis script will query the Monero client and populate the
xmr_keyimagestable 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
postgresuser 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.pyscript finishes running, you can stop themonerodclient by pressing Ctrl-D in the CLI window.