Skip to content

Commit

Permalink
add evm support in dapp analytics validation
Browse files Browse the repository at this point in the history
  • Loading branch information
rrozek committed Aug 14, 2024
1 parent 3180ea8 commit fbc0ba0
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-and-push-ecr-dev-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
- name: Build Docker image
run: docker build -t db-api .
- name: Run tests with temp db
run: docker-compose -f docker-compose-test.yaml run db-api npm test
run: docker compose -f docker-compose-test.yaml run db-api npm test
- name: Remove docker and volumes
run: docker-compose -f docker-compose-test.yaml down -v
run: docker compose -f docker-compose-test.yaml down -v
build-push:
name: Build image and push to ECR(tokenguard-dev)
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-and-push-ecr-prod-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
- name: Build Docker image
run: docker build -t db-api .
- name: Run tests with temp db
run: docker-compose -f docker-compose-test.yaml run db-api npm test
run: docker compose -f docker-compose-test.yaml run db-api npm test
- name: Remove docker and volumes
run: docker-compose -f docker-compose-test.yaml down -v
run: docker compose -f docker-compose-test.yaml down -v

build-push:
name: Build and push to ECR(tokenguard-prod)
Expand Down
48 changes: 48 additions & 0 deletions k8s/db-api/environment/dev/values-new.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# values for db-api dev environment.
ecrRegistry: 123622898391.dkr.ecr.eu-west-1.amazonaws.com
eksEnvironment: tokenguard-dev

imagePullSecrets: ~

ingressExternal:
enabled: false

ingressInternal:
enabled: true
name: db-api-new-ingress-internal
rules:
- host: db-api-new.dev.tokenguard.io
http:
paths:
- backend:
service:
name: db-api-new
port:
number: 8082
path: /
pathType: Prefix

dbapi:
deployment:
name: db-api-new
image:
repository: "tokenguard-dev-db-api"
pullPolicy: Always
tag: "3180ea8b2301e29469454514aa1dd60c5e7c99f2"
replicaCount: 1
env:
NODE_ENV: "development"
resources:
requests:
memory: "256Mi"
cpu: "200m"
limits:
memory: "2Gi"
cpu: "2000m"
configmap:
name: db-api-new
service:
name: db-api-new

secrets:
name: db-api-new-secrets
2 changes: 1 addition & 1 deletion k8s/db-api/environment/dev/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dbapi:
image:
repository: "tokenguard-dev-db-api"
pullPolicy: Always
tag: "3a4626d1b83624acbfae925fc9ae71da0df890e2"
tag: "3180ea8b2301e29469454514aa1dd60c5e7c99f2"
replicaCount: 1
env:
NODE_ENV: "development"
Expand Down
2 changes: 1 addition & 1 deletion k8s/db-api/environment/prod/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dbapi:
image:
repository: "tokenguard-prod-db-api"
pullPolicy: Always
tag: "f367530ced7474509a6f1d86032c3bab4de06e0c"
tag: "3193831990458e3d550506dfeba77318bc57df64"
replicaCount: 1
env:
NODE_ENV: "production"
Expand Down
4 changes: 2 additions & 2 deletions k8s/db-api/template/templates/db-api-secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ kind: Secret
metadata:
name: {{ .Values.secrets.name }}
stringData:
data-postgres-host: "ref+awsssm://{{ .Values.eksEnvironment }}/infrastructure/rds/postgres/address"
data-postgres-port: "ref+awsssm://{{ .Values.eksEnvironment }}/infrastructure/rds/postgres/port"
data-postgres-host: "ref+awsssm://{{ .Values.eksEnvironment }}/infrastructure/rds/postgres-prod/address"
data-postgres-port: "ref+awsssm://{{ .Values.eksEnvironment }}/infrastructure/rds/postgres-prod/port"
data-postgres-username: "ref+awsssm://{{ .Values.eksEnvironment }}/application/db-api/db/data/username"
data-postgres-password: "ref+awsssm://{{ .Values.eksEnvironment }}/application/db-api/db/data/password"
data-postgres-dbnames: "ref+awsssm://{{ .Values.eksEnvironment }}/application/db-api/db/data/dbnames"
Expand Down
94 changes: 92 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"cors": "^2.8.5",
"dotenv": "16.3.1",
"errorhandler": "1.5.1",
"ethers": "^6.13.1",
"express": "4.18.2",
"helmet": "^7.1.0",
"http-status": "^1.7.3",
Expand Down
74 changes: 63 additions & 11 deletions src/validation/dapp-analytics-validations.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Joi from "joi";
import { Abi as SubsquidAbi } from "@subsquid/ink-abi";
import { decodeAddress } from "@polkadot/keyring";
import { Abi as SubsquidInkAbi } from "@subsquid/ink-abi";
import { Interface as SubsquidEvmAbi, isAddress as isEvmAddress } from "ethers";
import { decodeAddress as decodeSubstrateAddress } from "@polkadot/keyring";

// Validator for Substrate addresses
const substrateAddressValidator = Joi.extend((joi) => ({
type: "substrateAddress",
base: joi.string(),
Expand All @@ -10,36 +12,86 @@ const substrateAddressValidator = Joi.extend((joi) => ({
},
validate(value, helpers) {
try {
decodeAddress(value);
decodeSubstrateAddress(value);
return { value };
} catch (error) {
return { errors: helpers.error("substrateAddress.base") };
}
},
}));

const subsquidAbiValidator = Joi.extend((joi) => ({
type: "subsquidAbi",
// Validator for EVM addresses
const evmAddressValidator = Joi.extend((joi) => ({
type: "evmAddress",
base: joi.string(),
messages: {
"evmAddress.base": "{{#label}} must be a valid EVM address",
},
validate(value, helpers) {
try {
if (isEvmAddress(value)) {
return { value };
} else {
return { errors: helpers.error("evmAddress.base") };
}
} catch (error) {
return { errors: helpers.error("evmAddress.base") };
}
},
}));

// Validator for Subsquid Ink ABI (object)
const subsquidInkAbiValidator = Joi.extend((joi) => ({
type: "subsquidInkAbi",
base: joi.object(),
messages: {
"subsquidAbi.validate":
"{{#label}} does not conform to Subsquid ABI format",
"subsquidInkAbi.validate":
"{{#label}} does not conform to Subsquid Ink ABI format",
},
validate(value, helpers) {
try {
new SubsquidInkAbi(value);
return { value };
} catch (error) {
return { errors: helpers.error("subsquidInkAbi.validate") };
}
},
}));

// Validator for EVM ABI (array)
const subsquidEvmAbiValidator = Joi.extend((joi) => ({
type: "subsquidEvmAbi",
base: joi.array(),
messages: {
"subsquidEvmAbi.validate":
"{{#label}} does not conform to Subsquid EVM ABI format",
},
validate(value, helpers) {
try {
new SubsquidAbi(value);
new SubsquidEvmAbi(value); // This line checks the validity of the ABI
return { value };
} catch (error) {
return { errors: helpers.error("subsquidAbi.validate") };
return { errors: helpers.error("subsquidEvmAbi.validate") };
}
},
}));

// Combined ABI Validator
const abiSchema = Joi.array().items(
Joi.object({
name: Joi.string(),
address: substrateAddressValidator.substrateAddress().required(),
abi: subsquidAbiValidator.subsquidAbi().required(),
address: Joi.alternatives()
.try(
substrateAddressValidator.substrateAddress(),
evmAddressValidator.evmAddress()
)
.required(),
abi: Joi.alternatives()
.try(
subsquidInkAbiValidator.subsquidInkAbi(),
subsquidEvmAbiValidator.subsquidEvmAbi()
)
.required(),
})
);

Expand Down

0 comments on commit fbc0ba0

Please sign in to comment.