ethereum / sourcify

Decentralized Solidity contract source code verification service
https://sourcify.dev
MIT License
780 stars 395 forks source link

Implement script to import contracts with `creator-tx-hash.txt` and re-verify them after #1589

Closed marcocastignoli closed 2 months ago

marcocastignoli commented 2 months ago

See #1573

PR

This PR:

Process

  1. Create a dedicated sourcify_sync like table (sourcify_transaction_hash with additional transaction_hash field)
CREATE TABLE sourcify_transaction_hash (
    id BIGSERIAL NOT NULL,
    chain_id numeric NOT NULL,
    address bytea NOT NULL,
    match_type varchar NOT NULL,
    transaction_hash bytea NOT NULL,
    synced bool NOT NULL DEFAULT false,
    created_at timestamptz NOT NULL DEFAULT now(),
    CONSTRAINT sourcify_transaction_hash_pkey PRIMARY KEY (id),
    CONSTRAINT sourcify_transaction_hash_pseudo_pkey UNIQUE (chain_id, address)
);
  1. Run the new import-creator-tx-hash script, pushing all the contracts that have a creator-tx-hash.txt from the legacy Argo repo to sourcify_transaction_hash
npm run sourcify:database import-creator-tx-hash /tmp/sourcify/repository/contracts
  1. Create a new table from the comparison between contract_deployments.transaction_hash with sourcify_transaction_hash.transaction_hash finding all the contracts that don't have transaction_hash in contract_deployments but they have it in sourcify_transaction_hash
CREATE TABLE sourcify_sync_sourcify_transaction_hash AS
SELECT sth.*
FROM sourcify_transaction_hash sth
LEFT JOIN contract_deployments cd 
ON sth.chain_id = cd.chain_id 
   AND sth.address = cd.address 
   AND sth.transaction_hash = cd.transaction_hash
WHERE cd.transaction_hash IS NULL;
  1. Execute sync on the new sourcify_sync_sourcify_transaction_hash table
npm run sourcify:database sync https://staging.sourcify.dev/server /tmp/sourcify/repository/contracts --  -c 1 -st sourcify_sync_sourcify_transaction_hash