-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: token details endpoint (#8)
* add: token image config * add: token details endpoint
- Loading branch information
Showing
9 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
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,31 @@ | ||
allOf: | ||
- $ref: '#/components/schemas/TokenKey' | ||
- type: object | ||
required: | ||
- attributes | ||
properties: | ||
attributes: | ||
type: object | ||
required: | ||
- name | ||
- symbol | ||
- decimals | ||
- image | ||
properties: | ||
name: | ||
type: string | ||
description: ERC20 token name | ||
example: "USD Dollar" | ||
symbol: | ||
type: string | ||
description: ERC20 token symbol | ||
example: "USDD" | ||
decimals: | ||
type: integer | ||
format: uint8 | ||
description: ERC20 token decimals | ||
example: 12 | ||
image: | ||
type: string | ||
description: ERC20 token symbol image | ||
example: "https://image_link/usdd.png" |
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,21 @@ | ||
get: | ||
tags: | ||
- Tokens | ||
summary: Get details | ||
description: Get service token's details | ||
operationId: GetDetails | ||
responses: | ||
200: | ||
content: | ||
application/vnd.api+json: | ||
schema: | ||
type: object | ||
required: | ||
- data | ||
properties: | ||
data: | ||
$ref: '#/components/schemas/TokenDetails' | ||
400: | ||
$ref: '#/components/responses/invalidParameter' | ||
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
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,42 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/rarimo/evm-airdrop-svc/internal/service/api" | ||
"github.com/rarimo/evm-airdrop-svc/internal/service/api/models" | ||
"gitlab.com/distributed_lab/ape" | ||
"gitlab.com/distributed_lab/ape/problems" | ||
) | ||
|
||
func GetTokenDetails(w http.ResponseWriter, r *http.Request) { | ||
name, err := api.ERC20Permit(r).Name(&bind.CallOpts{}) | ||
if err != nil { | ||
api.Log(r).WithError(err).Error("failed to get token name") | ||
ape.RenderErr(w, problems.InternalError()) | ||
return | ||
} | ||
|
||
symbol, err := api.ERC20Permit(r).Symbol(&bind.CallOpts{}) | ||
if err != nil { | ||
api.Log(r).WithError(err).Error("failed to get token symbol") | ||
ape.RenderErr(w, problems.InternalError()) | ||
return | ||
} | ||
|
||
decimals, err := api.ERC20Permit(r).Decimals(&bind.CallOpts{}) | ||
if err != nil { | ||
api.Log(r).WithError(err).Error("failed to get token decimals") | ||
ape.RenderErr(w, problems.InternalError()) | ||
return | ||
} | ||
|
||
ape.Render(w, models.NewTokenDetailsResponse( | ||
api.AirdropConfig(r).TokenAddress.String(), | ||
name, | ||
symbol, | ||
api.AirdropConfig(r).TokenImage.String(), | ||
decimals, | ||
)) | ||
} |
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,43 @@ | ||
/* | ||
* GENERATED. Do not modify. Your changes might be overwritten! | ||
*/ | ||
|
||
package resources | ||
|
||
import "encoding/json" | ||
|
||
type TokenDetails struct { | ||
Key | ||
Attributes TokenDetailsAttributes `json:"attributes"` | ||
} | ||
type TokenDetailsResponse struct { | ||
Data TokenDetails `json:"data"` | ||
Included Included `json:"included"` | ||
} | ||
|
||
type TokenDetailsListResponse struct { | ||
Data []TokenDetails `json:"data"` | ||
Included Included `json:"included"` | ||
Links *Links `json:"links"` | ||
Meta json.RawMessage `json:"meta,omitempty"` | ||
} | ||
|
||
func (r *TokenDetailsListResponse) PutMeta(v interface{}) (err error) { | ||
r.Meta, err = json.Marshal(v) | ||
return err | ||
} | ||
|
||
func (r *TokenDetailsListResponse) GetMeta(out interface{}) error { | ||
return json.Unmarshal(r.Meta, out) | ||
} | ||
|
||
// MustTokenDetails - returns TokenDetails from include collection. | ||
// if entry with specified key does not exist - returns nil | ||
// if entry with specified key exists but type or ID mismatches - panics | ||
func (c *Included) MustTokenDetails(key Key) *TokenDetails { | ||
var tokenDetails TokenDetails | ||
if c.tryFindEntry(key, &tokenDetails) { | ||
return &tokenDetails | ||
} | ||
return nil | ||
} |
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,16 @@ | ||
/* | ||
* GENERATED. Do not modify. Your changes might be overwritten! | ||
*/ | ||
|
||
package resources | ||
|
||
type TokenDetailsAttributes struct { | ||
// ERC20 token decimals | ||
Decimals uint8 `json:"decimals"` | ||
// ERC20 token symbol image | ||
Image string `json:"image"` | ||
// ERC20 token name | ||
Name string `json:"name"` | ||
// ERC20 token symbol | ||
Symbol string `json:"symbol"` | ||
} |