-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: eventID check, endpoint to get airdrop, new fields for tx handling
- Loading branch information
Showing
14 changed files
with
263 additions
and
41 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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,32 @@ | ||
allOf: | ||
- $ref: '#/components/schemas/AirdropKey' | ||
- type: object | ||
required: | ||
- attributes | ||
properties: | ||
attributes: | ||
type: object | ||
required: | ||
- address | ||
- status | ||
- created_at | ||
- updated_at | ||
properties: | ||
address: | ||
type: string | ||
description: Destination address for the airdrop | ||
example: "rarimo1qlyq3ej7j7rrkw6sluz658pzne88ymf66vjcap" | ||
status: | ||
type: string | ||
description: Status of the airdrop transaction | ||
enum: [ pending, completed ] | ||
created_at: | ||
type: string | ||
format: time.Time | ||
description: RFC3339 UTC timestamp of the airdrop creation | ||
example: "2021-09-01T00:00:00Z" | ||
updated_at: | ||
type: string | ||
format: time.Time | ||
description: RFC3339 UTC timestamp of the airdrop successful tx | ||
example: "2021-09-01T00:00:00Z" |
This file contains 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,12 @@ | ||
type: object | ||
required: | ||
- id | ||
- type | ||
properties: | ||
id: | ||
type: string | ||
description: User nullifier | ||
example: "0x04a32216f2425dc7343031352de3d62a7b0d3b4bf7a66d6c8c2aa8c9f4f2632b" | ||
type: | ||
type: string | ||
enum: [ airdrop ] |
This file contains 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
37 changes: 37 additions & 0 deletions
37
docs/spec/paths/integrations@airdrop-svc@airdrops@{id}.yaml
This file contains 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,37 @@ | ||
get: | ||
tags: | ||
- Airdrop | ||
summary: Create airdrop | ||
description: Create an airdrop for unique user. The proof will be verified. | ||
operationId: createAirdrop | ||
parameters: | ||
- in: path | ||
name: id | ||
description: User nullifier | ||
required: true | ||
schema: | ||
type: string | ||
example: "0x04a32216f2425dc7343031352de3d62a7b0d3b4bf7a66d6c8c2aa8c9f4f2632b" | ||
responses: | ||
200: | ||
content: | ||
application/vnd.api+json: | ||
schema: | ||
type: object | ||
required: | ||
- data | ||
properties: | ||
data: | ||
$ref: '#/components/schemas/Airdrop' | ||
400: | ||
$ref: '#/components/responses/invalidParameter' | ||
404: | ||
$ref: '#/components/responses/notFound' | ||
409: | ||
description: Airdrop was already done | ||
content: | ||
application/vnd.api+json: | ||
schema: | ||
$ref: '#/components/schemas/Errors' | ||
500: | ||
$ref: '#/components/responses/internalError' |
This file contains 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 |
---|---|---|
@@ -1,10 +1,15 @@ | ||
-- +migrate Up | ||
CREATE TYPE tx_status AS ENUM ('pending', 'completed'); | ||
|
||
CREATE TABLE participants | ||
( | ||
nullifier text PRIMARY KEY, | ||
address text NOT NULL, | ||
created_at timestamp without time zone NOT NULL default NOW() | ||
status tx_status NOT NULL, | ||
created_at timestamp without time zone NOT NULL default NOW(), | ||
updated_at timestamp without time zone NOT NULL default NOW() | ||
); | ||
|
||
-- +migrate Down | ||
DROP TABLE participants; | ||
DROP TYPE tx_status; |
This file contains 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 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 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,53 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/go-chi/chi" | ||
validation "github.com/go-ozzo/ozzo-validation/v4" | ||
data "github.com/rarimo/airdrop-svc/internal/data" | ||
"github.com/rarimo/airdrop-svc/resources" | ||
"gitlab.com/distributed_lab/ape" | ||
"gitlab.com/distributed_lab/ape/problems" | ||
) | ||
|
||
func GetAirdrop(w http.ResponseWriter, r *http.Request) { | ||
var ( | ||
id = chi.URLParam(r, "id") | ||
err error = validation.Errors{"{id}": validation.Validate(id, validation.Required)} | ||
) | ||
if err != nil { | ||
ape.RenderErr(w, problems.BadRequest(err)...) | ||
return | ||
} | ||
|
||
participant, err := ParticipantsQ(r).Get(id) | ||
if err != nil { | ||
Log(r).WithError(err).Error("Failed to get participant by ID") | ||
ape.RenderErr(w, problems.InternalError()) | ||
return | ||
} | ||
if participant == nil { | ||
ape.RenderErr(w, problems.NotFound()) | ||
return | ||
} | ||
|
||
ape.Render(w, toAirdropResponse(*participant)) | ||
} | ||
|
||
func toAirdropResponse(p data.Participant) resources.AirdropResponse { | ||
return resources.AirdropResponse{ | ||
Data: resources.Airdrop{ | ||
Key: resources.Key{ | ||
ID: p.Nullifier, | ||
Type: resources.AIRDROP, | ||
}, | ||
Attributes: resources.AirdropAttributes{ | ||
Address: p.Address, | ||
Status: p.Status, | ||
CreatedAt: p.CreatedAt, | ||
UpdatedAt: p.UpdatedAt, | ||
}, | ||
}, | ||
} | ||
} |
This file contains 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 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
Oops, something went wrong.