Skip to content
This repository was archived by the owner on Nov 10, 2021. It is now read-only.

Commit cafbb86

Browse files
Merge pull request #7 from anonymoussprocket/rollup
Rollup
2 parents 020eb2e + 2f50962 commit cafbb86

File tree

8 files changed

+143
-39
lines changed

8 files changed

+143
-39
lines changed

.env

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
REACT_APP_FEED='http://localhost:3001/feed'
2-
REACT_APP_TZ='http://localhost:3001/tz'
3-
REACT_APP_OBJKT='http://localhost:3001/objkt'
1+
TIMESTAMP=''
2+
BUFFER=''

.serverless/cloudformation-template-update-stack.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
"S3Bucket": {
147147
"Ref": "ServerlessDeploymentBucket"
148148
},
149-
"S3Key": "serverless/hicetnunc-apiv2/dev/1615880662823-2021-03-16T07:44:22.823Z/hicetnunc-apiv2.zip"
149+
"S3Key": "serverless/hicetnunc-apiv2/dev/1616132797292-2021-03-19T05:46:37.292Z/hicetnunc-apiv2.zip"
150150
},
151151
"FunctionName": "hicetnunc-apiv2-dev-handler",
152152
"Handler": "index.handler",
@@ -158,20 +158,26 @@
158158
]
159159
},
160160
"Runtime": "nodejs12.x",
161-
"Timeout": 120
161+
"Timeout": 120,
162+
"Environment": {
163+
"Variables": {
164+
"TIMESTAMP": "",
165+
"BUFFER": ""
166+
}
167+
}
162168
},
163169
"DependsOn": [
164170
"HandlerLogGroup"
165171
]
166172
},
167-
"HandlerLambdaVersion9JxeJVymMLadKim0CA2xts3Sq7MjDv9hgb8Kjy21D9E": {
173+
"HandlerLambdaVersionl43NXxTCsqpysRMWyXSvU0lsarIv6k41EVMGBVAAAI": {
168174
"Type": "AWS::Lambda::Version",
169175
"DeletionPolicy": "Retain",
170176
"Properties": {
171177
"FunctionName": {
172178
"Ref": "HandlerLambdaFunction"
173179
},
174-
"CodeSha256": "A5PEtCLwbB+fMx1VYq50HcNNaaGwfrVhq2LCEwgYZbk="
180+
"CodeSha256": "yP30UhwdABdpM1UtDvnZ21GW5zg9jII05figW7uS74k="
175181
}
176182
},
177183
"ApiGatewayRestApi": {
@@ -383,7 +389,7 @@
383389
"MethodResponses": []
384390
}
385391
},
386-
"ApiGatewayDeployment1615880658144": {
392+
"ApiGatewayDeployment1616132791720": {
387393
"Type": "AWS::ApiGateway::Deployment",
388394
"Properties": {
389395
"RestApiId": {
@@ -445,7 +451,7 @@
445451
"HandlerLambdaFunctionQualifiedArn": {
446452
"Description": "Current Lambda function version",
447453
"Value": {
448-
"Ref": "HandlerLambdaVersion9JxeJVymMLadKim0CA2xts3Sq7MjDv9hgb8Kjy21D9E"
454+
"Ref": "HandlerLambdaVersionl43NXxTCsqpysRMWyXSvU0lsarIv6k41EVMGBVAAAI"
449455
}
450456
},
451457
"ServiceEndpoint": {

.serverless/hicetnunc-apiv2.zip

31.8 KB
Binary file not shown.

.serverless/serverless-state.json

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"runtime": "nodejs12.x",
1212
"region": "us-east-1",
1313
"versionFunctions": true,
14+
"environment": {
15+
"TIMESTAMP": "",
16+
"BUFFER": ""
17+
},
1418
"compiledCloudFormationTemplate": {
1519
"AWSTemplateFormatVersion": "2010-09-09",
1620
"Description": "The AWS CloudFormation template for this Serverless application",
@@ -159,7 +163,7 @@
159163
"S3Bucket": {
160164
"Ref": "ServerlessDeploymentBucket"
161165
},
162-
"S3Key": "serverless/hicetnunc-apiv2/dev/1615880662823-2021-03-16T07:44:22.823Z/hicetnunc-apiv2.zip"
166+
"S3Key": "serverless/hicetnunc-apiv2/dev/1616132797292-2021-03-19T05:46:37.292Z/hicetnunc-apiv2.zip"
163167
},
164168
"FunctionName": "hicetnunc-apiv2-dev-handler",
165169
"Handler": "index.handler",
@@ -171,20 +175,26 @@
171175
]
172176
},
173177
"Runtime": "nodejs12.x",
174-
"Timeout": 120
178+
"Timeout": 120,
179+
"Environment": {
180+
"Variables": {
181+
"TIMESTAMP": "",
182+
"BUFFER": ""
183+
}
184+
}
175185
},
176186
"DependsOn": [
177187
"HandlerLogGroup"
178188
]
179189
},
180-
"HandlerLambdaVersion9JxeJVymMLadKim0CA2xts3Sq7MjDv9hgb8Kjy21D9E": {
190+
"HandlerLambdaVersionl43NXxTCsqpysRMWyXSvU0lsarIv6k41EVMGBVAAAI": {
181191
"Type": "AWS::Lambda::Version",
182192
"DeletionPolicy": "Retain",
183193
"Properties": {
184194
"FunctionName": {
185195
"Ref": "HandlerLambdaFunction"
186196
},
187-
"CodeSha256": "A5PEtCLwbB+fMx1VYq50HcNNaaGwfrVhq2LCEwgYZbk="
197+
"CodeSha256": "yP30UhwdABdpM1UtDvnZ21GW5zg9jII05figW7uS74k="
188198
}
189199
},
190200
"ApiGatewayRestApi": {
@@ -396,7 +406,7 @@
396406
"MethodResponses": []
397407
}
398408
},
399-
"ApiGatewayDeployment1615880658144": {
409+
"ApiGatewayDeployment1616132791720": {
400410
"Type": "AWS::ApiGateway::Deployment",
401411
"Properties": {
402412
"RestApiId": {
@@ -458,7 +468,7 @@
458468
"HandlerLambdaFunctionQualifiedArn": {
459469
"Description": "Current Lambda function version",
460470
"Value": {
461-
"Ref": "HandlerLambdaVersion9JxeJVymMLadKim0CA2xts3Sq7MjDv9hgb8Kjy21D9E"
471+
"Ref": "HandlerLambdaVersionl43NXxTCsqpysRMWyXSvU0lsarIv6k41EVMGBVAAAI"
462472
}
463473
},
464474
"ServiceEndpoint": {
@@ -556,7 +566,8 @@
556566
"vpc": {}
557567
},
558568
"plugins": [
559-
"serverless-plugin-include-dependencies"
569+
"serverless-plugin-include-dependencies",
570+
"serverless-dotenv-plugin"
560571
],
561572
"pluginsData": {},
562573
"functions": {
@@ -616,7 +627,7 @@
616627
"memory": 1024,
617628
"runtime": "nodejs12.x",
618629
"vpc": {},
619-
"versionLogicalId": "HandlerLambdaVersion9JxeJVymMLadKim0CA2xts3Sq7MjDv9hgb8Kjy21D9E"
630+
"versionLogicalId": "HandlerLambdaVersionl43NXxTCsqpysRMWyXSvU0lsarIv6k41EVMGBVAAAI"
620631
}
621632
},
622633
"configValidationMode": "warn",
@@ -1010,6 +1021,45 @@
10101021
"node_modules/big-integer/package.json",
10111022
"node_modules/big-integer/README.md",
10121023
"node_modules/big-integer/tsconfig.json",
1024+
"node_modules/dotenv/CHANGELOG.md",
1025+
"node_modules/dotenv/config.js",
1026+
"node_modules/dotenv/lib/cli-options.js",
1027+
"node_modules/dotenv/lib/env-options.js",
1028+
"node_modules/dotenv/lib/main.js",
1029+
"node_modules/dotenv/LICENSE",
1030+
"node_modules/dotenv/package.json",
1031+
"node_modules/dotenv/README.md",
1032+
"node_modules/dotenv/types/index.d.ts",
1033+
"node_modules/dotenv/types/test.ts",
1034+
"node_modules/dotenv/types/tsconfig.json",
1035+
"node_modules/dotenv/types/tslint.json",
1036+
"node_modules/cloud-local-storage/lib/commands/create.d.ts",
1037+
"node_modules/cloud-local-storage/lib/commands/create.js",
1038+
"node_modules/cloud-local-storage/lib/commands/get-all-keys.d.ts",
1039+
"node_modules/cloud-local-storage/lib/commands/get-all-keys.js",
1040+
"node_modules/cloud-local-storage/lib/commands/get-item.d.ts",
1041+
"node_modules/cloud-local-storage/lib/commands/get-item.js",
1042+
"node_modules/cloud-local-storage/lib/commands/init.d.ts",
1043+
"node_modules/cloud-local-storage/lib/commands/init.js",
1044+
"node_modules/cloud-local-storage/lib/commands/list.d.ts",
1045+
"node_modules/cloud-local-storage/lib/commands/list.js",
1046+
"node_modules/cloud-local-storage/lib/commands/reset-password.d.ts",
1047+
"node_modules/cloud-local-storage/lib/commands/reset-password.js",
1048+
"node_modules/cloud-local-storage/lib/commands/set-item.d.ts",
1049+
"node_modules/cloud-local-storage/lib/commands/set-item.js",
1050+
"node_modules/cloud-local-storage/lib/index.d.ts",
1051+
"node_modules/cloud-local-storage/lib/index.js",
1052+
"node_modules/cloud-local-storage/lib/utils/consts.d.ts",
1053+
"node_modules/cloud-local-storage/lib/utils/consts.js",
1054+
"node_modules/cloud-local-storage/package.json",
1055+
"node_modules/cloud-local-storage/readme.md",
1056+
"node_modules/cloud-local-storage/src/commands/create.ts",
1057+
"node_modules/cloud-local-storage/src/commands/get-all-keys.ts",
1058+
"node_modules/cloud-local-storage/src/commands/get-item.ts",
1059+
"node_modules/cloud-local-storage/src/commands/set-item.ts",
1060+
"node_modules/cloud-local-storage/src/index.ts",
1061+
"node_modules/cloud-local-storage/src/utils/consts.ts",
1062+
"node_modules/cloud-local-storage/tsconfig.json",
10131063
"node_modules/lodash/_apply.js",
10141064
"node_modules/lodash/_arrayAggregator.js",
10151065
"node_modules/lodash/_arrayEach.js",
@@ -2507,7 +2557,7 @@
25072557
"node_modules/@types/aws-lambda/trigger/sqs.d.ts"
25082558
],
25092559
"artifact": "/home/crzy/Desktop/programs/lambdas-aws/api-final/new2/hicetnunc-api/.serverless/hicetnunc-apiv2.zip",
2510-
"artifactDirectoryName": "serverless/hicetnunc-apiv2/dev/1615880662823-2021-03-16T07:44:22.823Z"
2560+
"artifactDirectoryName": "serverless/hicetnunc-apiv2/dev/1616132797292-2021-03-19T05:46:37.292Z"
25112561
},
25122562
"plugins": {
25132563
"$ref": "$[\"service\"][\"plugins\"]"
@@ -2524,7 +2574,7 @@
25242574
"artifact": "/home/crzy/Desktop/programs/lambdas-aws/api-final/new2/hicetnunc-api/.serverless/hicetnunc-apiv2.zip"
25252575
},
25262576
"package": {
2527-
"artifactDirectoryName": "serverless/hicetnunc-apiv2/dev/1615880662823-2021-03-16T07:44:22.823Z",
2577+
"artifactDirectoryName": "serverless/hicetnunc-apiv2/dev/1616132797292-2021-03-19T05:46:37.292Z",
25282578
"artifact": "hicetnunc-apiv2.zip"
25292579
}
25302580
}

conseilUtil.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,12 @@ const getArtisticOutputForAddress = async (address) => {
208208
return objectInfo.flat(1).sort((a, b) => parseInt(b.objectId) - parseInt(a.objectId))
209209
}
210210

211-
const getArtisticUniverse = async (offset) => {
211+
const getArtisticUniverse = async (max_time) => {
212212
let mintOperationQuery = conseiljs.ConseilQueryBuilder.blankQuery();
213213
mintOperationQuery = conseiljs.ConseilQueryBuilder.addFields(mintOperationQuery, 'operation_group_hash');
214214
mintOperationQuery = conseiljs.ConseilQueryBuilder.addPredicate(mintOperationQuery, 'kind', conseiljs.ConseilOperator.EQ, ['transaction'])
215215
mintOperationQuery = conseiljs.ConseilQueryBuilder.addPredicate(mintOperationQuery, 'timestamp', conseiljs.ConseilOperator.AFTER, [1612240919000]) // 2021 Feb 1
216+
mintOperationQuery = conseiljs.ConseilQueryBuilder.addPredicate(mintOperationQuery, 'timestamp', conseiljs.ConseilOperator.BEFORE, [max_time]) // quantized time (1min)
216217
mintOperationQuery = conseiljs.ConseilQueryBuilder.addPredicate(mintOperationQuery, 'status', conseiljs.ConseilOperator.EQ, ['applied'])
217218
mintOperationQuery = conseiljs.ConseilQueryBuilder.addPredicate(mintOperationQuery, 'destination', conseiljs.ConseilOperator.EQ, [mainnet.protocol])
218219
mintOperationQuery = conseiljs.ConseilQueryBuilder.addPredicate(mintOperationQuery, 'parameters_entrypoints', conseiljs.ConseilOperator.EQ, ['mint_OBJKT'])

index.js

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ const axios = require('axios')
33
const express = require('express')
44
const cors = require('cors')
55
const _ = require('lodash')
6-
76
const conseilUtil = require('./conseilUtil')
7+
const cls = require('cloud-local-storage')
8+
require('dotenv').config()
89

910
const reducer = (accumulator, currentValue) => accumulator + currentValue;
1011

@@ -34,10 +35,10 @@ const getTokenHoldersArr = async (arr) => {
3435
return await arr.map(async e => await axios.get('https://api.better-call.dev/v1/contract/mainnet/KT1RJ6PbjHpwc3M5rw5s2Nbmefwbuwbdxton/tokens/holders?token_id=' + e).then(res => res.data))
3536
/* await axios.get('https://api.better-call.dev/v1/contract/mainnet/KT1RJ6PbjHpwc3M5rw5s2Nbmefwbuwbdxton/tokens/holders?token_id=' + arr[0]).then(res => console.log(res.data))
3637
*//* var result = arr.map(async e => {
37-
return await axios.get('https://api.better-call.dev/v1/contract/mainnet/KT1RJ6PbjHpwc3M5rw5s2Nbmefwbuwbdxton/tokens/holders?token_id=' + e).then(res => res.data)
38-
})
39-
40-
console.log(result) */
38+
return await axios.get('https://api.better-call.dev/v1/contract/mainnet/KT1RJ6PbjHpwc3M5rw5s2Nbmefwbuwbdxton/tokens/holders?token_id=' + e).then(res => res.data)
39+
})
40+
41+
console.log(result) */
4142
}
4243

4344
const owners = async (obj) => {
@@ -127,8 +128,21 @@ const filterTz = (data, tz) => _.filter(data, { tz: tz })
127128

128129
const test = async () => console.log(desc(await getObjkts()))
129130

130-
const getFeed = async (counter, res) => {
131-
var arr = await conseilUtil.getArtisticUniverse(0)
131+
const customFloor = function (value, roundTo) {
132+
return Math.floor(value / roundTo) * roundTo;
133+
}
134+
135+
const ONE_MINUTE_MILLIS = 60 * 1000
136+
137+
138+
const getFeed = async (counter, max_time, res) => {
139+
140+
const now_time = Date.now()
141+
const immutable = (typeof max_time !== 'undefined') && (max_time < now_time)
142+
max_time = (typeof max_time !== 'undefined') ? max_time : customFloor(now_time, ONE_MINUTE_MILLIS)
143+
144+
var arr = await conseilUtil.getArtisticUniverse(max_time)
145+
132146
var feed = offset(desc(arr), counter)
133147
console.log(feed)
134148
feed = await feed.map(async e => {
@@ -138,12 +152,20 @@ const getFeed = async (counter, res) => {
138152
return e
139153
})
140154
//console.log(feed)
141-
155+
var cache_time
156+
if (immutable) {
157+
cache_time = 60 * 10
158+
}
159+
else {
160+
cache_time = (int)(((max_time + ONE_MINUTE_MILLIS) - now_time) / 1000)
161+
}
142162
var promise = Promise.all(feed.map(e => e))
143163
promise.then(async (results) => {
144164
var aux_arr = results.map(e => e)
145165

146-
//console.log(aux_arr)
166+
res.set('Cache-Control', `public, max-age=${cache_time}`)
167+
168+
console.log(aux_arr)
147169
res.json({ result: aux_arr })
148170
})
149171
}
@@ -163,16 +185,19 @@ const getTzLedger = async (tz, res) => {
163185
console.log(hdao)
164186

165187
var arr = []
166-
167-
var arr = _.union(collection, creations[0])
188+
console.log([...collection, ...creations])
189+
var arr = [...collection, ...creations]
168190

169191
var result = arr.map(async e => {
170192
e.token_info = await getIpfsHash(e.ipfsHash)
193+
171194
if (e.piece != undefined) {
172195
e.token_id = parseInt(e.piece)
173196
} else {
174197
e.token_id = parseInt(e.objectId)
198+
175199
}
200+
console.log(e)
176201
return e
177202
})
178203

@@ -184,7 +209,7 @@ const getTzLedger = async (tz, res) => {
184209
result: _.uniqBy(result, (e) => {
185210
return e.token_id
186211
}),
187-
hdao : hdao
212+
hdao: hdao
188213
})
189214
})
190215

@@ -247,27 +272,49 @@ const app = express()
247272
app.use(express.json())
248273
app.use(cors({ origin: '*' }))
249274

250-
app.post('/feed', async (req, res) => {
251-
await getFeed(req.body.counter, res)
275+
app.get('/feed', async (req, res) => {
276+
var counter = req.query.counter
277+
var max_time = req.query.hasOwnProperty('time') ? customFloor(req.query.time, ONE_MINUTE_MILLIS) : null
278+
const now_time_qt = customFloor(Date.now(), ONE_MINUTE_MILLIS)
279+
if (max_time != null & max_time > now_time_qt) {
280+
max_time = null
281+
}
282+
await getFeed(counter, max_time, res)
252283
})
253284

254285
app.post('/tz', async (req, res) => {
255286
console.log(req.body.tz)
256-
await getTzLedger(req.body.tz, res)
287+
var list = await axios.get('https://raw.githubusercontent.com/hicetnunc2000/hicetnunc/main/filters/w.json').then(res => res.data)
288+
289+
list.includes(req.body.tz)
290+
?
291+
res.json({ result: [] })
292+
:
293+
await getTzLedger(req.body.tz, res)
257294

258295
})
259296

260297
app.post('/objkt', async (req, res) => {
261-
res.json({ result: await getObjktById(req.body.objkt_id) })
298+
var list = await axios.get('https://raw.githubusercontent.com/hicetnunc2000/hicetnunc/main/filters/o.json').then(res => res.data)
299+
300+
list.includes(parseInt(req.body.objkt_id))
301+
?
302+
res.json({ result: [] })
303+
:
304+
res.json({ result: await getObjktById(req.body.objkt_id) })
262305
})
263306

264307
app.post('/hdao', async (req, res) => {
265308
await hDAOFeed(parseInt(req.body.counter), res)
266309
})
267310

268311
app.listen(3001)
269-
module.exports.handler = serverless(app)
312+
//module.exports.handler = serverless(app)
270313

314+
/* const test2 = async () => {
315+
await axios.get('https://raw.githubusercontent.com/hicetnunc2000/hicetnunc/main/filters/o.json').then(res => console.log(res.data))
316+
}
317+
test2() */
271318
//testTkHolder([{'kt' : 2020}, {'kt' : 2021}])
272319
//getFeed(1)
273320
//getObjktById(2000)

0 commit comments

Comments
 (0)