@@ -22,26 +22,65 @@ export class SourcifyVerifier extends AbstractVerifier implements Verifier {
22
22
await super . verifyAll ( contractNameAddressPairs ) ;
23
23
}
24
24
25
- async verifyContract ( artifact : Artifact ) : Promise < VerificationStatus > {
25
+ // Note that Sourcify may indicate failed verification in through errors, but also through 200 responses
26
+ // This is why we check both cases
27
+ async verifyContract ( artifact : Artifact ) : Promise < string > {
26
28
await this . checkBoundaries ( ) ;
27
29
28
- const res = await this . sendVerifyRequest ( artifact ) ;
29
- enforceOrThrow ( res . data ?. result ?. length === 1 , `Failed to connect to Sourcify API at url ${ SOURCIFY_API_URL } ` ) ;
30
+ const inputJSON = await getInputJSON ( artifact , this . options , this . logger ) ;
30
31
31
- const [ contract ] = res . data . result ;
32
+ const files : { [ path : string ] : string } = { } ;
33
+ Object . keys ( inputJSON . sources ) . forEach ( ( path ) => {
34
+ files [ path . replace ( / ^ .* [ \\ / ] / , '' ) ] = inputJSON . sources [ path ] . content ;
35
+ } ) ;
36
+ files [ 'metadata.json' ] = JSON . stringify ( JSON . parse ( artifact . metadata ) ) ;
32
37
33
- if ( contract . storageTimestamp ) {
34
- return VerificationStatus . ALREADY_VERIFIED ;
35
- }
38
+ const postQueries = {
39
+ address : artifact . networks [ `${ this . options . networkId } ` ] . address ,
40
+ chain : `${ this . options . chainId } ` ,
41
+ files,
42
+ } ;
43
+
44
+ try {
45
+ this . logger . debug ( 'Sending verify request with POST arguments:' ) ;
46
+ logObject ( this . logger , 'debug' , postQueries , 2 ) ;
47
+ const res = await axios . post ( SOURCIFY_API_URL , postQueries ) ;
48
+
49
+ const [ result ] = res ?. data ?. result ?? [ ] ;
50
+ this . logger . debug ( 'Received response:' ) ;
51
+ logObject ( this . logger , 'debug' , result , 2 ) ;
52
+
53
+ if ( ! result ) {
54
+ // If no result was returned, there is likely an issue with the API connection
55
+ throw new Error ( `Could not connect to Sourcify API at url ${ SOURCIFY_API_URL } ` ) ;
56
+ }
57
+
58
+ if ( result . storageTimestamp ) return VerificationStatus . ALREADY_VERIFIED ;
59
+ if ( result . status === 'partial' ) return VerificationStatus . PARTIAL ;
60
+ if ( result . status === 'perfect' ) return VerificationStatus . SUCCESS ;
61
+ return `${ VerificationStatus . FAILED } : ${ result ?. message } `
62
+ } catch ( error : any ) {
63
+ const errorResponse = error ?. response ?. data ;
64
+ const errorResponseMessage = errorResponse ?. message ?? errorResponse ?. error ;
65
+
66
+ this . logger . debug ( `Error: ${ error ?. message } ` ) ;
67
+ logObject ( this . logger , 'debug' , error ?. response ?. data , 2 )
68
+
69
+ // If an error message is present in the checked response, this likely indicates a failed verification
70
+ if ( errorResponseMessage ) {
71
+ return `${ VerificationStatus . FAILED } : ${ errorResponseMessage } `
72
+ }
36
73
37
- return VerificationStatus . SUCCESS ;
74
+ // If no message was passed in the response, this likely indicates a failed connection
75
+ throw new Error ( `Could not connect to Sourcify API at url ${ SOURCIFY_API_URL } ` ) ;
76
+ }
38
77
}
39
78
40
79
async verifyProxyContract (
41
80
proxyArtifact : Artifact ,
42
81
implementationName : string ,
43
82
implementationAddress : string
44
- ) : Promise < VerificationStatus > {
83
+ ) : Promise < string > {
45
84
await this . checkBoundaries ( ) ;
46
85
47
86
if ( this . options . customProxy ) {
@@ -63,32 +102,6 @@ export class SourcifyVerifier extends AbstractVerifier implements Verifier {
63
102
return status ;
64
103
}
65
104
66
- private async sendVerifyRequest ( artifact : Artifact ) {
67
- const inputJSON = await getInputJSON ( artifact , this . options , this . logger ) ;
68
-
69
- const files : { [ path : string ] : string } = { } ;
70
- Object . keys ( inputJSON . sources ) . forEach ( ( path ) => {
71
- files [ path . replace ( / ^ .* [ \\ / ] / , '' ) ] = inputJSON . sources [ path ] . content ;
72
- } ) ;
73
- files [ 'metadata.json' ] = JSON . stringify ( JSON . parse ( artifact . metadata ) ) ;
74
-
75
- const postQueries = {
76
- address : artifact . networks [ `${ this . options . networkId } ` ] . address ,
77
- chain : `${ this . options . chainId } ` ,
78
- files,
79
- } ;
80
-
81
- try {
82
- this . logger . debug ( 'Sending verify request with POST arguments:' ) ;
83
- logObject ( this . logger , 'debug' , postQueries , 2 ) ;
84
- return await axios . post ( SOURCIFY_API_URL , postQueries ) ;
85
- } catch ( error : any ) {
86
- this . logger . debug ( error . message ) ;
87
- this . logger . debug ( error . response . data . message ) ;
88
- throw new Error ( `Failed to connect to Sourcify API at url ${ SOURCIFY_API_URL } ` ) ;
89
- }
90
- }
91
-
92
105
private async checkBoundaries ( ) {
93
106
enforceOrThrow (
94
107
await this . isSupportedChain ( this . options . chainId ) ,
@@ -103,7 +116,7 @@ export class SourcifyVerifier extends AbstractVerifier implements Verifier {
103
116
104
117
private async getSupportedChains ( ) {
105
118
if ( this . supportedChainIds ) return this . supportedChainIds ;
106
- const chainsUrl = `${ SOURCIFY_API_URL } chains`
119
+ const chainsUrl = `${ SOURCIFY_API_URL } chains` ;
107
120
108
121
try {
109
122
this . logger . debug ( `Fetching supported chains from ${ chainsUrl } ` ) ;
0 commit comments