Create PostgreSQL Tables
We will be using PostgreSQL tables to store the Monero v9 data. We will need three tables that are named as follows.
xmrv9_keyimages
: Contains transaction rings and key imagesxmrv9_outputs
: Contains the transaction outputsxmr_xmrv9_keyimages
: Contains the rows ofxmr_keyimages
whose key images appear inxmrv9_keyimages
-
There is a file called
create_keyimages_table.sql
in thescripts/hardforks/monero-v9
directory with the following contents.CREATE TABLE xmrv9_keyimages ( image VARCHAR(64) NOT NULL, id SERIAL PRIMARY KEY, ring_amount BIGINT, ring_indices INTEGER[], block_height INTEGER, UNIQUE(image) )
-
Run the following command in the
scripts/hardforks/monero-v9
directory to create thexmrv9_keyimages
table.psql -U postgres -h 127.0.0.1 -W -f create_keyimages_table.sql
-
There is a file called
create_outputs_table.sql
in thescripts/hardforks/monero-v9
directory with the following contents.CREATE TABLE xmrv9_outputs ( image VARCHAR(64) NOT NULL, id SERIAL PRIMARY KEY, ring_amount BIGINT, ring_indices INTEGER[], block_height INTEGER, UNIQUE(image) )
-
Run the following command in the
scripts/hardforks/monero-v9
directory to create thexmrv9_outputs
table.psql -U postgres -h 127.0.0.1 -W -f create_outputs_table.sql
NOTE: Alternatively, you can create the
xmrv9_keyimages
andxmrv9_outputs
tables by running the script calledsql_table_creation.sh
in thescripts/hardforks/monero-v9
directory. You can run the commandsource sql_table_creation.sh
and enter the Postgres user password when prompted. -
Run the
populate_xmrv9_tables.py
script that is located in thescripts/hardforks/monero-v9
directory.python3 populate_xmrv9_tables.py
This script will query the Monero v9 client and populate the
xmrv9_keyimages
andxmrv9_outputs
tables with non-coinbase transactions from block height 1,788,000 to block height 1,788,072. The Monero v9 blockchain diverged from the main Monero chain at block height 1,788,000. -
Once the
populate_xmrv9_tables.py
script finishes running, you can stop the Monero v9 client by pressing Ctrl-D in the CLI window. -
Create the
xmr_xmrv9_keyimages
table using the following steps. It will contain the subset ofxmr_keyimages
that corresponds to key images which have appeared both on the main Monero chain and the Monero v9 chain.- Run the following commands to enter the
psql
shell.sudo su postgres psql
- Run the following query.
CREATE TABLE xmr_xmrv9_keyimages AS (SELECT xmrk.* FROM xmr_keyimages xmrk INNER JOIN xmrv9_keyimages xmrv9k ON xmrk.image=xmrv9k.image);
- Run the following commands to enter the