Skip to content

Commit

Permalink
Merge pull request #1 from rarimo/feaure/check-registry-and-nullifier
Browse files Browse the repository at this point in the history
Request validation
  • Loading branch information
freigeistig authored Mar 3, 2024
2 parents 50e5628 + 691ea14 commit e9850d0
Show file tree
Hide file tree
Showing 13 changed files with 1,916 additions and 389 deletions.
36 changes: 36 additions & 0 deletions docs/spec/components/schemas/Errors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
description: 'Standard JSON:API error'
type: object
required:
- errors
properties:
errors:
type: array
description: Non empty array of errors occurred during request processing
items:
type: object
required:
- title
- status
properties:
title:
type: string
description: 'Title is a short, human-readable summary of the problem'
example: Bad Request
detail:
type: string
description: >-
Detail is a human-readable explanation specific to this occurrence
of the problem
example: "Request body was expected"
status:
type: integer
description: Status is the HTTP status code applicable to this problem
example: 400
enum:
- 400
- 401
- 403
- 404
- 409
- 429
- 500
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,28 @@ post:
responses:
'200':
description: Success
'500':
description: Internal Error
content:
application/json:
schema:
$ref: '#/components/schemas/Errors'
type: object
properties:
data:
type: object
$ref: '#/components/schemas/Tx'
'400':
description: Bad Request Error
content:
application/json:
schema:
$ref: '#/components/schemas/Errors'
'429':
description: Too Many Requests Error
content:
application/json:
schema:
$ref: '#/components/schemas/Errors'
'500':
description: Internal Error
content:
application/json:
schema:
Expand Down
10 changes: 1 addition & 9 deletions internal/assets/migrations/001_initial.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
-- +migrate Up
create table proofs(
id uuid default gen_random_uuid(),
voting_session text not null,
document_nullifier text not null,
created_at timestamp default now(),
unique (voting_session, document_nullifier)
);

-- +migrate Down
drop table proofs;
-- +migrate Down
12 changes: 7 additions & 5 deletions internal/config/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ type ethereum struct {
}

type NetworkConfig struct {
RPC string `fig:"rpc,required"`
VerifierAddress common.Address `fig:"verifier_address,required"`
Address string `fig:"vault_address,required"`
MountPath string `fig:"vault_mount_path,required"`
RPC string `fig:"rpc,required"`
Proposer common.Address `fig:"proposer,required"`
VotingRegistry common.Address `fig:"voting_registry,required"`
Address string `fig:"vault_address,required"`
MountPath string `fig:"vault_mount_path,required"`

ChainID *big.Int `fig:"chain_id"`
Token string `dig:"VAULT_TOKEN,clear"`
Expand Down Expand Up @@ -74,7 +75,8 @@ func (e *ethereum) NetworkConfig() *NetworkConfig {
if err := dig.Out(&result).
Where(map[string]interface{}{
"rpc": result.RPC,
"verifier_address": result.VerifierAddress,
"proposer": result.Proposer,
"voting_registry": result.VotingRegistry,
"vault_address": result.Address,
"vault_mount_path": result.MountPath,
}).Now(); err != nil {
Expand Down
443 changes: 237 additions & 206 deletions internal/contracts/Verifier.go → internal/contracts/VoteVerifier.go

Large diffs are not rendered by default.

1,492 changes: 1,492 additions & 0 deletions internal/contracts/VotingRegistry.go

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions internal/data/main.go

This file was deleted.

30 changes: 0 additions & 30 deletions internal/data/pg/main.go

This file was deleted.

87 changes: 0 additions & 87 deletions internal/data/pg/proofs.go

This file was deleted.

22 changes: 0 additions & 22 deletions internal/data/proofs.go

This file was deleted.

28 changes: 20 additions & 8 deletions internal/service/api/handlers/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package handlers

import (
"context"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/rarimo/proof-verification-relayer/internal/config"
"github.com/rarimo/proof-verification-relayer/internal/data"
"net/http"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/rarimo/proof-verification-relayer/internal/config"
"github.com/rarimo/proof-verification-relayer/internal/contracts"
"gitlab.com/distributed_lab/logan/v3"
)

Expand All @@ -16,7 +17,8 @@ const (
logCtxKey ctxKey = iota
networkConfigCtxKey
ethClientCtxKey
masterQKey
voteVerifierRegisterMethodCtxKey
votingRegistryCtxKey
)

func CtxLog(entry *logan.Entry) func(context.Context) context.Context {
Expand Down Expand Up @@ -49,12 +51,22 @@ func EthClient(r *http.Request) *ethclient.Client {
return r.Context().Value(ethClientCtxKey).(*ethclient.Client)
}

func CtxMasterQ(entry data.MasterQ) func(context.Context) context.Context {
func CtxVoteVerifierRegisterMethod(method *abi.Method) func(context.Context) context.Context {
return func(ctx context.Context) context.Context {
return context.WithValue(ctx, voteVerifierRegisterMethodCtxKey, method)
}
}

func VoteVerifierRegisterMethod(r *http.Request) *abi.Method {
return r.Context().Value(voteVerifierRegisterMethodCtxKey).(*abi.Method)
}

func CtxVotingRegistry(registry *contracts.VotingRegistry) func(context.Context) context.Context {
return func(ctx context.Context) context.Context {
return context.WithValue(ctx, masterQKey, entry)
return context.WithValue(ctx, votingRegistryCtxKey, registry)
}
}

func MasterQ(r *http.Request) data.MasterQ {
return r.Context().Value(masterQKey).(data.MasterQ).New()
func VotingRegistry(r *http.Request) *contracts.VotingRegistry {
return r.Context().Value(votingRegistryCtxKey).(*contracts.VotingRegistry)
}
Loading

0 comments on commit e9850d0

Please sign in to comment.