-
Notifications
You must be signed in to change notification settings - Fork 28
fix : added validation in add image form. #1184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
minato32
wants to merge
7
commits into
cowprotocol:main
Choose a base branch
from
minato32:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6336ce2
fix : added validation for address and image url n addImageForm.yml
minato32 43325fa
Create validate-token-address.yml to check if address exist on chain
minato32 8cecc3e
Update validate-token-address.yml to add label and comment on issue
minato32 696f6c2
Add issue check and valid rpcs
minato32 008744c
Add version hash
minato32 6b67e84
add version 5 hash
minato32 0ae39be
Add actions version
minato32 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| name: Validate Token Address | ||
|
|
||
| on: | ||
| issues: | ||
| types: [opened, edited] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| issues: write | ||
|
|
||
| jobs: | ||
| validate-address: | ||
| if: ${{ contains(join(github.event.issue.labels.*.name, ','), 'addImage') }} | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repo | ||
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 | ||
| with: | ||
| node-version: 20 | ||
|
|
||
| - name: Install ethers.js | ||
| run: npm install ethers | ||
|
|
||
| - name: Extract address and network | ||
| id: extract | ||
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea | ||
| with: | ||
| script: | | ||
| const body = context.payload.issue.body; | ||
|
|
||
| // Extract Network | ||
| const networkMatch = body.match(/Network\s*\n\s*(.*)/); | ||
| const network = networkMatch ? networkMatch[1].trim() : null; | ||
|
|
||
| // Extract Address | ||
| const addressMatch = body.match(/Address\s*\n\s*(0x[a-fA-F0-9]{40})/); | ||
| const address = addressMatch ? addressMatch[1].trim() : null; | ||
|
|
||
| core.setOutput('network', network || ''); | ||
| core.setOutput('address', address || ''); | ||
|
|
||
| - name: Validate on-chain address | ||
| id: validate | ||
| timeout-minutes: 2 | ||
| env: | ||
| NETWORK: ${{ steps.extract.outputs.network }} | ||
| ADDRESS: ${{ steps.extract.outputs.address }} | ||
| run: | | ||
| node -e " | ||
| (() => { | ||
| const {ethers} = import('ethers') | ||
| const network = process.env.NETWORK; | ||
| const address = process.env.ADDRESS; | ||
|
|
||
| if (!address) { | ||
| console.log("No address provided."); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| if (!ethers.isAddress(address)) { | ||
| console.log("Address is not valid"); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const rpcMap = { | ||
| MAINNET: "https://rpc.mevblocker.io", | ||
| GNOSIS_CHAIN: "https://gnosis.oat.farm", | ||
| ARBITRUM_ONE: "https://arbitrum-one.public.blastapi.io", | ||
| BASE: "https://base.drpc.org", | ||
| POLYGON: "https://polygon-bor-rpc.publicnode.com", | ||
| AVALANCHE: "https://api.avax.network/ext/bc/C/rpc", | ||
| BNB: "https://public-bsc-mainnet.fastnode.io", | ||
| LENS: "https://lens.drpc.org", | ||
| }; | ||
|
|
||
| const rpcUrl = rpcMap[network]; | ||
| if (!rpcUrl) { | ||
| console.log("No RPC for network, skipping check."); | ||
| process.exit(0); | ||
| } | ||
|
|
||
| const provider = new ethers.JsonRpcProvider(rpcUrl); | ||
|
|
||
| provider | ||
| .getCode(address) | ||
| .then((code) => { | ||
| if (code === "0x") { | ||
| console.log("Address not found on chain."); | ||
| process.exit(1); | ||
| } else { | ||
| console.log("Address exists on chain."); | ||
| } | ||
| }) | ||
| .catch((err) => { | ||
| if ( | ||
| err && | ||
| (err.code === "INVALID_ARGUMENT" || /invalid address/i.test(String(err))) | ||
| ) { | ||
| console.log("Address not found on chain."); | ||
| process.exit(1); | ||
| } | ||
| console.error("Error checking address:", err); | ||
| process.exit(1); | ||
| }); | ||
| })() | ||
| " | ||
|
|
||
| - name: Add comment and label if invalid | ||
| if: failure() | ||
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea | ||
| with: | ||
| script: | | ||
| const issue_number = context.issue.number; | ||
| const address = '${{ steps.extract.outputs.address }}'; | ||
| const network = '${{ steps.extract.outputs.network }}'; | ||
|
|
||
| // Add comment | ||
| await github.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number, | ||
| body: `⚠️ The address \`${address || 'N/A'}\` does not exist or is invalid on network \`${network || 'N/A'}\`. Please verify.` | ||
| }); | ||
|
|
||
| // Add label | ||
| await github.issues.addLabels({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number, | ||
| labels: ['invalid-address'] | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.