Skip to content

Commit 504a297

Browse files
committed
feat: support contracts verification
1 parent 196cead commit 504a297

File tree

3 files changed

+159
-3
lines changed

3 files changed

+159
-3
lines changed

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ USAGE
6767
- [`scrollsdk setup prep-charts`](#scrollsdk-setup-prep-charts)
6868
- [`scrollsdk setup push-secrets`](#scrollsdk-setup-push-secrets)
6969
- [`scrollsdk setup tls`](#scrollsdk-setup-tls)
70+
- [`scrollsdk setup verify-contracts`](#scrollsdk-setup-verify-contracts)
7071
- [`scrollsdk test contracts`](#scrollsdk-test-contracts)
7172
- [`scrollsdk test dependencies`](#scrollsdk-test-dependencies)
7273
- [`scrollsdk test e2e`](#scrollsdk-test-e2e)
@@ -523,7 +524,7 @@ DESCRIPTION
523524
EXAMPLES
524525
$ scrollsdk setup configs
525526
526-
$ scrollsdk setup configs --image-tag gen-configs-2eba3d2c418b16f4a66d9baadeb1c1bafdca81b1
527+
$ scrollsdk setup configs --image-tag gen-configs-8ff2948aa2b9cbd24a7644b060097765a6faee10
527528
528529
$ scrollsdk setup configs --configs-dir custom-configs
529530
```
@@ -704,6 +705,29 @@ EXAMPLES
704705

705706
_See code: [src/commands/setup/tls.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/setup/tls.ts)_
706707

708+
## `scrollsdk setup verify-contracts`
709+
710+
Verify both L1/L2 contracts scource code on block chain explorer
711+
712+
```
713+
USAGE
714+
$ scrollsdk setup verify-contracts [--image-tag <value>]
715+
716+
FLAGS
717+
--image-tag=<value> Specify the Docker image tag to use
718+
719+
DESCRIPTION
720+
Verify both L1/L2 contracts scource code on block chain explorer
721+
722+
EXAMPLES
723+
$ scrollsdk setup verify-contracts
724+
725+
$ scrollsdk setup verify-contracts --image-tag verify-8ff2948aa2b9cbd24a7644b060097765a6faee10
726+
```
727+
728+
_See code: [src/commands/setup/configs.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/setup/verify-contracts.ts)_
729+
730+
707731
## `scrollsdk test contracts`
708732

709733
Test contracts by checking deployment and initialization

src/commands/setup/configs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default class SetupConfigs extends Command {
1414

1515
static override examples = [
1616
'<%= config.bin %> <%= command.id %>',
17-
'<%= config.bin %> <%= command.id %> --image-tag gen-configs-2eba3d2c418b16f4a66d9baadeb1c1bafdca81b1',
17+
'<%= config.bin %> <%= command.id %> --image-tag gen-configs-8ff2948aa2b9cbd24a7644b060097765a6faee10',
1818
'<%= config.bin %> <%= command.id %> --configs-dir custom-configs',
1919
]
2020

@@ -465,7 +465,7 @@ export default class SetupConfigs extends Command {
465465
}
466466

467467
private async getDockerImageTag(providedTag: string | undefined): Promise<string> {
468-
const defaultTag = 'gen-configs-2eba3d2c418b16f4a66d9baadeb1c1bafdca81b1'
468+
const defaultTag = 'gen-configs-8ff2948aa2b9cbd24a7644b060097765a6faee10'
469469

470470
if (!providedTag) {
471471
return defaultTag
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import {Command, Flags} from '@oclif/core'
2+
import chalk from 'chalk'
3+
import { select } from '@inquirer/prompts'
4+
import Docker from 'dockerode'
5+
6+
export default class ContractsVerification extends Command {
7+
static override description = 'Set up contracts verification'
8+
9+
static override examples = [
10+
'<%= config.bin %> <%= command.id %>',
11+
'<%= config.bin %> <%= command.id %> --image-tag verify-8ff2948aa2b9cbd24a7644b060097765a6faee10',
12+
]
13+
14+
static override flags = {
15+
'image-tag': Flags.string({
16+
description: 'Specify the Docker image tag to use',
17+
required: false,
18+
}),
19+
}
20+
21+
private async fetchDockerTags(): Promise<string[]> {
22+
try {
23+
const response = await fetch(
24+
'https://registry.hub.docker.com/v2/repositories/scrolltech/scroll-stack-contracts/tags?page_size=100',
25+
)
26+
if (!response.ok) {
27+
throw new Error(`HTTP error! status: ${response.status}`)
28+
}
29+
const data = await response.json()
30+
return data.results.map((tag: any) => tag.name).filter((tag: string) => tag.startsWith('verify'))
31+
} catch (error) {
32+
this.error(`Failed to fetch Docker tags: ${error}`)
33+
}
34+
}
35+
36+
private async getDockerImageTag(providedTag: string | undefined): Promise<string> {
37+
const defaultTag = 'verify-8ff2948aa2b9cbd24a7644b060097765a6faee10'
38+
39+
if (!providedTag) {
40+
return defaultTag
41+
}
42+
43+
const tags = await this.fetchDockerTags()
44+
45+
if (providedTag.startsWith('gen-configs-v') && tags.includes(providedTag)) {
46+
return providedTag
47+
} else if (providedTag.startsWith('v') && tags.includes(`verify-${providedTag}`)) {
48+
return `verify-${providedTag}`
49+
} else if (/^\d+\.\d+\.\d+$/.test(providedTag) && tags.includes(`verify-v${providedTag}`)) {
50+
return `verify-v${providedTag}`
51+
}
52+
53+
const selectedTag = await select({
54+
message: 'Select a Docker image tag:',
55+
choices: tags.map((tag) => ({name: tag, value: tag})),
56+
})
57+
58+
return selectedTag
59+
}
60+
61+
private async runDockerCommand(imageTag: string): Promise<void> {
62+
const docker = new Docker()
63+
const image = `scrolltech/scroll-stack-contracts:${imageTag}`
64+
65+
try {
66+
this.log(chalk.cyan('Pulling Docker Image...'))
67+
// Pull the image if it doesn't exist locally
68+
const pullStream = await docker.pull(image)
69+
await new Promise((resolve, reject) => {
70+
docker.modem.followProgress(pullStream, (err, res) => {
71+
if (err) {
72+
reject(err)
73+
} else {
74+
this.log(chalk.green('Image pulled successfully'))
75+
resolve(res)
76+
}
77+
})
78+
})
79+
80+
this.log(chalk.cyan('Creating Docker Container...'))
81+
// Create and run the container
82+
const container = await docker.createContainer({
83+
Image: image,
84+
Cmd: [], // Add any command if needed
85+
HostConfig: {
86+
Binds: [`${process.cwd()}:/contracts/volume`],
87+
},
88+
})
89+
90+
this.log(chalk.cyan('Starting Container'))
91+
await container.start()
92+
93+
// Wait for the container to finish and get the logs
94+
const stream = await container.logs({
95+
follow: true,
96+
stdout: true,
97+
stderr: true,
98+
})
99+
100+
// Print the logs
101+
stream.pipe(process.stdout)
102+
103+
// Wait for the container to finish
104+
await new Promise((resolve) => {
105+
container.wait((err, data) => {
106+
if (err) {
107+
this.error(`Container exited with error: ${err}`)
108+
} else if (data.StatusCode !== 0) {
109+
this.error(`Container exited with status code: ${data.StatusCode}`)
110+
}
111+
resolve(null)
112+
})
113+
})
114+
115+
// Remove the container
116+
await container.remove()
117+
} catch (error) {
118+
this.error(`Failed to run Docker command: ${error}`)
119+
}
120+
}
121+
122+
public async run(): Promise<void> {
123+
this.log(chalk.blue('Running docker command to contracts verification...'))
124+
125+
const {flags} = await this.parse(ContractsVerification)
126+
127+
const imageTag = await this.getDockerImageTag(flags['image-tag'])
128+
this.log(chalk.blue(`Using Docker image tag: ${imageTag}`))
129+
130+
await this.runDockerCommand(imageTag)
131+
}
132+
}

0 commit comments

Comments
 (0)