Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 1x 1x 1x 33x 3x 3x 3x 33x 1x 1x 1x 33x 1x 1x 1x 33x 1x 1x 33x 1x 1x 33x | import { Types } from 'cafe-utility' import getMajorSemver from 'semver/functions/major.js' import { BeeRequestOptions } from '../../index' import type { DebugStatus, Health, NodeInfo, Readiness } from '../../types/debug' import { BeeVersions, toBeeMode } from '../../types/debug' import { http } from '../../utils/http' export const SUPPORTED_BEE_VERSION_EXACT = '2.4.0-390a402e' export const SUPPORTED_BEE_VERSION = SUPPORTED_BEE_VERSION_EXACT.split('-')[0] export const SUPPORTED_API_VERSION = '7.2.0' const NODE_INFO_URL = 'node' const STATUS_URL = 'status' const HEALTH_URL = 'health' const READINESS_URL = 'readiness' export async function getDebugStatus(requestOptions: BeeRequestOptions): Promise<DebugStatus> { const response = await http<unknown>(requestOptions, { method: 'get', url: STATUS_URL, responseType: 'json', }) const body = Types.asObject(response.data, { name: 'response.data' }) return { overlay: Types.asString(body.overlay, { name: 'overlay' }), proximity: Types.asNumber(body.proximity, { name: 'proximity' }), beeMode: toBeeMode(Types.asString(body.beeMode, { name: 'beeMode' })), reserveSize: Types.asNumber(body.reserveSize, { name: 'reserveSize' }), reserveSizeWithinRadius: Types.asNumber(body.reserveSizeWithinRadius, { name: 'reserveSizeWithinRadius' }), pullsyncRate: Types.asNumber(body.pullsyncRate, { name: 'pullsyncRate' }), storageRadius: Types.asNumber(body.storageRadius, { name: 'storageRadius' }), connectedPeers: Types.asNumber(body.connectedPeers, { name: 'connectedPeers' }), neighborhoodSize: Types.asNumber(body.neighborhoodSize, { name: 'neighborhoodSize' }), batchCommitment: Types.asNumber(body.batchCommitment, { name: 'batchCommitment' }), isReachable: Types.asBoolean(body.isReachable, { name: 'isReachable' }), lastSyncedBlock: Types.asNumber(body.lastSyncedBlock, { name: 'lastSyncedBlock' }), committedDepth: Types.asNumber(body.committedDepth, { name: 'committedDepth' }), } } /** * Get health of node * * @param requestOptions Options for making requests */ export async function getHealth(requestOptions: BeeRequestOptions): Promise<Health> { const response = await http<unknown>(requestOptions, { method: 'get', url: HEALTH_URL, responseType: 'json', }) const body = Types.asObject(response.data, { name: 'response.data' }) return { apiVersion: Types.asString(body.apiVersion, { name: 'apiVersion' }), version: Types.asString(body.version, { name: 'version' }), status: Types.asString(body.status, { name: 'status' }) as 'ok', } } /** * Get readiness of node * * @param requestOptions Options for making requests */ export async function getReadiness(requestOptions: BeeRequestOptions): Promise<Readiness> { const response = await http<unknown>(requestOptions, { method: 'get', url: READINESS_URL, }) const body = Types.asObject(response.data, { name: 'response.data' }) return { apiVersion: Types.asString(body.apiVersion, { name: 'apiVersion' }), version: Types.asString(body.version, { name: 'version' }), status: Types.asString(body.status, { name: 'status' }), } } /** * Get information about Bee node * * @param requestOptions Options for making requests */ export async function getNodeInfo(requestOptions: BeeRequestOptions): Promise<NodeInfo> { const response = await http<unknown>(requestOptions, { method: 'get', url: NODE_INFO_URL, responseType: 'json', }) const body = Types.asObject(response.data, { name: 'response.data' }) return { beeMode: toBeeMode(Types.asString(body.beeMode, { name: 'beeMode' })), chequebookEnabled: Types.asBoolean(body.chequebookEnabled, { name: 'chequebookEnabled' }), swapEnabled: Types.asBoolean(body.swapEnabled, { name: 'swapEnabled' }), } } /** * Connects to a node and checks if its version matches with the one that bee-js supports. * * This is the most strict version check and most probably you will * want to use the relaxed API-versions check `isSupportedApiVersion`. * * @param requestOptions Options for making requests */ export async function isSupportedExactVersion(requestOptions: BeeRequestOptions): Promise<boolean> { const { version } = await getHealth(requestOptions) return version === SUPPORTED_BEE_VERSION_EXACT } /** * Connects to a node and checks if its Main API versions matches with the one that bee-js supports. * * This should be the main way how to check compatibility for your app and Bee node. * * @param requestOptions Options for making requests */ export async function isSupportedApiVersion(requestOptions: BeeRequestOptions): Promise<boolean> { const { apiVersion } = await getHealth(requestOptions) return getMajorSemver(apiVersion) === getMajorSemver(SUPPORTED_API_VERSION) } /** * Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`) * and versions that bee-js supports (properties prefixed with `supported*`). * * @param requestOptions Options for making requests */ export async function getVersions(requestOptions: BeeRequestOptions): Promise<BeeVersions> { const { version, apiVersion } = await getHealth(requestOptions) return { supportedBeeVersion: SUPPORTED_BEE_VERSION_EXACT, supportedBeeApiVersion: SUPPORTED_API_VERSION, beeVersion: version, beeApiVersion: apiVersion, } } |