-
Notifications
You must be signed in to change notification settings - Fork 2
Add endpoint for saving token data #4
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
Closed
Closed
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
981e855
chore(t2cr): update yarn.lock
eccentricexit 127ba02
feat(t2cr): add tokens-on-trial resource scaffolding
eccentricexit 2e2091f
feat(t2cr): store token data and return
eccentricexit 4a3ec0e
fix(t2cr): be consistent with request type
eccentricexit 8afdf09
fix(t2cr): be consistent with request type (patch)
eccentricexit 1d45250
fix: typo in resource path
eccentricexit fa26947
fix(t2cr): typos and description
eccentricexit 4da31f9
fix(t2cr): missing properties
eccentricexit 8df4478
fix(t2cr): revert change in yarn.lock due to old yarn version
eccentricexit 8e16a33
fix(t2cr): swap patch for put
eccentricexit f4ec7b4
Merge branch 'feat/token-data' of https://github.com/mtsalenc/kleros-…
eccentricexit 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
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,48 @@ | ||
| { | ||
| "patch": { | ||
| "request": { | ||
| "type": "object", | ||
| "properties": { | ||
| "payload": { | ||
| "type": "object", | ||
| "properties": { | ||
| "name": { | ||
| "type": "string", | ||
| "description": "The name of the token." | ||
| }, | ||
| "ticker": { | ||
| "type": "string", | ||
| "description": "The token ticker symbol." | ||
eccentricexit marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| "address": { | ||
| "type": "string", | ||
| "description": "The token Ethereum address." | ||
| }, | ||
| "uri": { | ||
eccentricexit marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "type": "string", | ||
| "description": "A URI to the token logo." | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "response": { | ||
| "type": "object", | ||
| "properties": { | ||
| "payload": { | ||
| "type": "object", | ||
| "properties": { | ||
| "tokenID": { | ||
| "type": "string", | ||
| "description": "The tokenID for the uploaded token data." | ||
| }, | ||
| "token": { | ||
| "type": "object", | ||
| "description": "The uploaded token data." | ||
eccentricexit marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
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,36 @@ | ||
| const _web3 = require('../utils/web3') | ||
|
|
||
| module.exports.patch = async (event, _context, callback) => { | ||
eccentricexit marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const web3 = await _web3() | ||
|
|
||
| const payload = JSON.parse(event.body).payload | ||
| const tokenID = web3.sha3(JSON.stringify(payload.token)) | ||
|
|
||
| const keys = [ | ||
| 'name', | ||
| 'ticker', | ||
| 'address', | ||
| 'uri', | ||
| ].filter( | ||
| k => payload.token[k] | ||
| ) | ||
| callback(null, { | ||
| statusCode: 200, | ||
| headers: { 'Access-Control-Allow-Origin': '*' }, | ||
| body: JSON.stringify({ | ||
| payload: { | ||
| tokenID, | ||
| token: await dynamoDB.putItem({ | ||
| Key: { tokenID: { S: tokenID } }, | ||
| TableName: 'token', | ||
| UpdateExpression: keys.map(k => `SET ${k} = :_${k}`).join(', '), | ||
eccentricexit marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ExpressionAttributeValues: keys.reduce((acc, k) => { | ||
| acc[`:_${k}`] = payload.token[k] | ||
| return acc | ||
| }, {}), | ||
| ReturnValues: 'ALL_NEW' | ||
| }) | ||
| } | ||
| }) | ||
| }) | ||
| } | ||
Oops, something went wrong.
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.