I am working with these two tables:
core=> \d contractcode;
Table "public.contractcode"
Column | Type | Collation | Nullable | Default
--------------+---------+-----------+----------+---------
hash | text | C | not null |
ledgerentry | text | C | not null |
lastmodified | integer | | not null |
Indexes:
"contractcode_pkey" PRIMARY KEY, btree (hash)
core=> \d contractdata;
Table "public.contractdata"
Column | Type | Collation | Nullable | Default
--------------+---------+-----------+----------+---------
contractid | text | C | not null |
key | text | C | not null |
type | integer | | not null |
ledgerentry | text | C | not null |
lastmodified | integer | | not null |
Indexes:
"contractdata_pkey" PRIMARY KEY, btree (contractid, key, type)
When I deploy a contract, an entry is added to both tables.
I can use contactdata.ledgerentry to get the address which is fine.
The problem am facing is how to get the adjacent code for the contact (ie from contractcode)
On the database I have something like this:
core=> select hash from contractcode ;
hash
----------------------------------------------
JsyywvEb0yYC+GPWoA25bkrPRGNXBm1wWnEImDUGyuQ=
When I decode contactdata.legderentry, I will get a hash like 26ccb2c2f11bd32602f863d6a00db96e4acf446357066d705a7108983506cae4
I am unable to find the connection which I am assuming it exists.
Give a contract address is there a way to get the contract code using sql queries?