-
Notifications
You must be signed in to change notification settings - Fork 0
/
getBlockHeaders.js
executable file
·87 lines (83 loc) · 2.7 KB
/
getBlockHeaders.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const Validator = require('../../utils/Validator');
const argsSchema = require('../schemas/getBlockHeaders');
const validator = new Validator(argsSchema);
/**
* @param coreAPI
* @return {getBlockHeaders}
*/
const getBlockHeadersFactory = (coreAPI) => {
/**
* Layer 1 endpoint
* Returns block headers
* @typedef getBlockHeaders
* @param args - command arguments
* @param {number} args.offset - block height starting point
* @param {number} args.limit - number of block headers to return
* @return {Promise<Array<Object>>}
*/
async function getBlockHeaders(args) {
validator.validate(args);
const { offset, limit } = args;
return coreAPI.getBlockHeaders(typeof offset === 'number' ? await coreAPI.getBlockHash(offset) : offset, limit);
}
return getBlockHeaders;
};
/* eslint-disable max-len */
/**
* @swagger
* /getBlockHeaders:
* post:
* operationId: getBlockHeaders
* deprecated: false
* summary: getBlockHeaders
* description: Returns the requested number of block headers starting at the requested height
* tags:
* - L1
* responses:
* 200:
* description: Successful response. Promise (object array) containing an array of block headers.
* requestBody:
* content:
* application/json:
* schema:
* type: object
* required:
* - method
* - id
* - jsonrpc
* - params
* properties:
* method:
* type: string
* default: getBlockHeaders
* description: Method name
* id:
* type: integer
* default: 1
* format: int32
* description: Request ID
* jsonrpc:
* type: string
* default: '2.0'
* description: JSON-RPC Version (2.0)
* params:
* title: Parameters
* type: object
* required:
* - offset
* - limit
* properties:
* offset:
* type: integer
* default: 1
* description: Lowest block height to include
* minimum: 0
* limit:
* type: integer
* default: 1
* description: The number of headers to return (0 < limit <=25)
* minimum: 1
* maximum: 25
*/
/* eslint-enable max-len */
module.exports = getBlockHeadersFactory;