Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ custom:
path: doges-on-trial,
description: 'Microservices for the Doges on Trial dapp.',
}
- {
path: tokens-on-trial,
description: 'Microservices for the Tokens on Trial dapp.',
}
models:
- {
name: ErrorResponse,
Expand Down Expand Up @@ -74,6 +78,18 @@ custom:
contentType: application/json,
schema: '${file(src/doges-on-trial/models/doge-images.json):post.response}',
}
- {
name: PatchTokenRequest,
description: 'The request for patchToken.',
contentType: application/json,
schema: '${file(src/tokens-on-trial/models/token.json):patch.request}',
}
- {
name: PatchTokenResponse,
description: 'The response for patchToken.',
contentType: application/json,
schema: '${file(src/tokens-on-trial/models/token.json):patch.response}',
}
functions:
postCFS:
handler: src/global/cfs.post
Expand Down Expand Up @@ -173,3 +189,36 @@ functions:
responseModels: { application/json: ErrorResponse },
},
]
patchToken:
handler: src/tokens-on-trial/token.patch
events:
- { http: { path: token, method: patch, cors: true } }
environment:
INFURA_URL: '${self:custom.kmsSecrets.secrets.${self:custom.environments.${self:provider.stage}}_INFURA_URL}'
iamRoleStatementsName: 'patchToken-${self:provider.stage}-lambda-role'
iamRoleStatements:
- {
Effect: Allow,
Action: ['KMS:Decrypt'],
Resource: '${self:custom.kmsSecrets.keyArn}',
}
- {
Effect: Allow,
Action: ['dynamodb:UpdateItem'],
Resource: 'arn:aws:dynamodb:us-east-2:547511976516:table/token',
}
documentation:
summary: 'Upload token data.'
description: 'Takes token data and stores it by content-address.'
requestModels: { application/json: PatchTokenRequest }
methodResponses:
[
{
statusCode: '200',
responseModels: { application/json: PatchTokenResponse },
},
{
statusCode: '400',
responseModels: { application/json: ErrorResponse },
},
]
48 changes: 48 additions & 0 deletions src/tokens-on-trial/models/token.json
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."
},
"address": {
"type": "string",
"description": "The token Ethereum address."
},
"uri": {
"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."
}
}
}
}
}
}
}
36 changes: 36 additions & 0 deletions src/tokens-on-trial/token.js
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) => {
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(', '),
ExpressionAttributeValues: keys.reduce((acc, k) => {
acc[`:_${k}`] = payload.token[k]
return acc
}, {}),
ReturnValues: 'ALL_NEW'
})
}
})
})
}
Loading