-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandler.js
35 lines (26 loc) · 905 Bytes
/
handler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const { Validator } = require('@chainlink/external-adapter')
const axios = require('axios')
const bigInt = require('big-integer')
const customParams = {}
const call_drand = async (input, callback) => {
// initialize validator
const validator = new Validator(callback, input, customParams)
const jobRunId = validator.validated.id
// latest round from drand.love
await axios.get('https://api.drand.sh/public/latest')
.then(res => {
callback(200, {
"jobRunID": jobRunId,
"data": bigInt(res.data.randomness, 16).toString()
})
})
}
module.exports.drand_ea = (event, context, callback) => {
call_drand(JSON.parse(event.body), (statusCode, data) => {
callback(null, {
statusCode: statusCode,
body: JSON.stringify(data),
isBase64Encoded: false
})
})
}