1- import { EscrowClient } from "@human-protocol/sdk" ;
1+ //This script reads manifest urls from the blockchain and set them in the database in the new column manifest_url
22
3+ import { EscrowClient } from '@human-protocol/sdk' ;
4+ import * as dotenv from 'dotenv' ;
35import { Client } from 'pg' ;
46import { ethers } from 'ethers' ;
57
8+ dotenv . config ( {
9+ path : '.env' ,
10+ } ) ;
11+
612const dbConfig = {
713 user : process . env . POSTGRES_USER ,
814 host : process . env . POSTGRES_HOST ,
915 database : process . env . POSTGRES_DATABASE ,
1016 password : process . env . POSTGRES_PASSWORD ,
1117 port : + process . env . POSTGRES_PORT ! ,
18+ ssl : process . env . POSTGRES_SSL == 'true' ,
1219} ;
1320
14- async function createSigner ( ) {
21+ async function createProvider ( ) {
1522 const provider = new ethers . JsonRpcProvider ( process . env . RPC_URL ) ;
16- const wallet = new ethers . Wallet ( process . env . WEB3_PRIVATE_KEY ! ) ;
17- return wallet . connect ( provider ) ;
23+ return provider ;
1824}
1925
2026async function updateJobsWithManifestUrls ( ) {
@@ -23,12 +29,14 @@ async function updateJobsWithManifestUrls() {
2329 try {
2430 await client . connect ( ) ;
2531
26- const signer = await createSigner ( ) ;
27- const escrowClient = await EscrowClient . build ( signer ) ;
28-
32+ const provider = await createProvider ( ) ;
33+ const escrowClient = await EscrowClient . build ( provider ) ;
34+
2935 console . log ( 'Connected to the database.' ) ;
3036
31- const res = await client . query ( 'SELECT * FROM "hmt"."jobs" WHERE manifest_url IS NULL' ) ;
37+ const res = await client . query (
38+ 'SELECT * FROM "hmt"."jobs" WHERE manifest_url IS NULL' ,
39+ ) ;
3240 const jobsWithoutManifest = res . rows ;
3341
3442 for ( const job of jobsWithoutManifest ) {
@@ -38,7 +46,10 @@ async function updateJobsWithManifestUrls() {
3846 const manifestUrl = await escrowClient . getManifestUrl ( escrowAddress ) ;
3947
4048 if ( manifestUrl ) {
41- await client . query ( 'UPDATE "hmt"."jobs" SET manifest_url = $1 WHERE id = $2' , [ manifestUrl , id ] ) ;
49+ await client . query (
50+ 'UPDATE "hmt"."jobs" SET manifest_url = $1 WHERE id = $2' ,
51+ [ manifestUrl , id ] ,
52+ ) ;
4253 console . log ( `Updated job ${ id } with manifestUrl: ${ manifestUrl } ` ) ;
4354 }
4455 } catch ( error ) {
0 commit comments