Skip to content

Commit

Permalink
chore: improvements to homepage/docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Lemmmy committed Mar 28, 2023
1 parent 5f45d2d commit 6a1cfcd
Show file tree
Hide file tree
Showing 18 changed files with 42 additions and 514 deletions.
1 change: 1 addition & 0 deletions apidoc-template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

<!-- Vuepress-esque top navbar -->
<header class="krist-navbar">
<img src="/logo2.svg" id="logo" />
<a href="/" class="home-link"><span class="site-name">Krist HTTP API reference</span></a>

<div class="krist-links">
Expand Down
7 changes: 7 additions & 0 deletions apidoc-template/src/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -615,3 +615,10 @@ body.container-fluid {
top: -1px;
overflow: hidden;
}

#logo {
display: inline;
width: 24px;
height: 24px;
margin-right: 2rem;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "krist",
"version": "3.3.0",
"version": "3.3.1",
"description": "The new Krist node written in TypeScript.",
"main": "dist/src/index.js",
"scripts": {
Expand Down
13 changes: 10 additions & 3 deletions src/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { redis, rKey } from "../database/redis";
import { GITHUB_TOKEN } from "./constants";

const MESSAGE_TYPE_RE = /^(\w+): (.+)/;
const EXCLUDE_COMMITS_RE = /block|submi/gi;

const octokit = GITHUB_TOKEN ? new Octokit({
auth: GITHUB_TOKEN,
Expand All @@ -44,7 +45,7 @@ export interface FormattedCommit extends CommitBase {
export async function getCommits(): Promise<FormattedCommit[]> {
const commits = await gitlog({
repo: path.join(__dirname, "../../"),
number: 10,
number: 20,
fields: [
"subject", "body", "hash",
"authorName", "authorEmail", "authorDate", "authorDateRel"
Expand All @@ -60,7 +61,13 @@ async function formatCommits(commits: CommitBase[]): Promise<FormattedCommit[]>
for (const baseCommit of commits) {
const commit: FormattedCommit = { ...baseCommit };

if (!commit.subject) continue;
if (
!commit.subject
|| EXCLUDE_COMMITS_RE.test(commit.subject)
|| (commit.body && EXCLUDE_COMMITS_RE.test(commit.body))
) {
continue;
}

const [, type, rest] = MESSAGE_TYPE_RE.exec(commit.subject) || [];
if (type) {
Expand All @@ -84,7 +91,7 @@ async function formatCommits(commits: CommitBase[]): Promise<FormattedCommit[]>
});
}

return newCommits;
return newCommits.slice(0, 10);
}

async function getAvatar(commit: FormattedCommit): Promise<string | undefined> {
Expand Down
209 changes: 0 additions & 209 deletions src/webserver/routes/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,189 +26,24 @@ import { ctrlGetBlock, ctrlGetLastBlock } from "../../controllers/blocks";
import { blockToJson, getBlock, getBlocks, getBlockValue, getLastBlock, getLowestHashes } from "../../krist/blocks";
import { getBaseBlockValue, padDigits } from "../../utils";

/**
* @apiDefine BlockGroup Blocks
*
* All Block related endpoints.
*/

/**
* @apiDefine Block
*
* @apiSuccess {Object} block
* @apiSuccess {Number} block.height The height (ID) of this block.
* @apiSuccess {String} block.address The address which submitted this block.
* @apiSuccess {String} block.hash The full-length SHA-256 hash of this block.
* The hash is calculated by the SHA-256 of the submitter's address,
* the 12-char SHA-256 of the last block, and the nonce.
* @apiSuccess {String} block.short_hash The hash trimmed to 12 characters.
* @apiSuccess {Number} block.value The reward value of this block.
* @apiSuccess {Number} block.difficulty The difficulty at the time the block
* was mined.
* @apiSuccess {Date} block.time The time this block was submitted, as an
* ISO-8601 string.
*/

/**
* @apiDefine Blocks
*
* @apiSuccess {Object[]} blocks
* @apiSuccess {Number} blocks.height The height (ID) of this block.
* @apiSuccess {String} blocks.address The address which submitted this block.
* @apiSuccess {String} blocks.hash The full-length SHA-256 hash of this block.
* The hash is calculated by the SHA-256 of the submitter's address,
* the 12-char SHA-256 of the last block, and the nonce.
* @apiSuccess {String} blocks.short_hash The hash trimmed to 12 characters.
* @apiSuccess {Number} blocks.value The reward value of this block.
* @apiSuccess {Number} blocks.difficulty The difficulty at the time the block
* was mined.
* @apiSuccess {Date} blocks.time The time this block was submitted, as an
* ISO-8601 string.
*/

export default (): Router => {
const router = Router();

/**
* @api {get} /blocks List all blocks
* @apiName GetBlocks
* @apiGroup BlockGroup
* @apiVersion 2.0.0
*
* @apiUse LimitOffset
*
* @apiSuccess {Number} count The count of results.
* @apiSuccess {Number} total The total amount of blocks.
* @apiUse Blocks
*
* @apiSuccessExample {json} Success
* {
* "ok": true,
* "count": 49,
* "total": 100000
* "blocks": [
* {
* "height": 2,
* "address": "a5dfb396d3",
* "hash": "00480dc35dc111d9953e5182df7d7f404a62d2b0d71ed51a873a81d89e78fbd8",
* "short_hash": "00480dc35dc1",
* "value": 50,
* "time": "2015-02-14T20:42:30.000Z"
* },
* {
* "height": 3,
* "address": "a5dfb396d3",
* "hash": "0046a3582fed130ee18c05e7e278992678d46e311465a4af6b787f5c014640a9",
* "short_hash": "0046a3582fed",
* "value": 50,
* "time": "2015-02-14T20:48:43.000Z"
* },
* ...
*/
router.get("/blocks", async (req: PaginatedQuery, res) => {
const results = await getBlocks(req.query.limit, req.query.offset, true);
returnPaginatedResult(res, "blocks", blockToJson, results);
});

/**
* @api {get} /blocks/latest List latest blocks
* @apiName GetLatestBlocks
* @apiGroup BlockGroup
* @apiVersion 2.0.0
*
* @apiUse LimitOffset
*
* @apiSuccess {Number} count The count of results.
* @apiUse Blocks
*
* @apiSuccessExample {json} Success
* {
* "ok": true,
* "count": 50,
* "blocks": [
* {
* "height": 122225,
* "address": "kre3w0i79j",
* "hash": "1aa36f210f2e07b666646ac7dac3ea972262a6a474419edfc058e4402d40538d",
* "short_hash": "1aa36f210f2e",
* "value": 12,
* "time": "2016-02-02T17:55:35.000Z"
* },
* {
* "height": 122224,
* "address": "k123456789",
* "hash": "000000f31b3ca2cf166d0ee669cd2ae2be6ea0fc35d1cf1e7b52811ecb358796",
* "short_hash": "000000f31b3c",
* "value": 12,
* "time": "2016-02-01T14:18:47.000Z"
* },
* ...
*/
router.get("/blocks/latest", async (req: PaginatedQuery, res) => {
const results = await getBlocks(req.query.limit, req.query.offset);
returnPaginatedResult(res, "blocks", blockToJson, results);
});

/**
* @api {get} /blocks/lowest List blocks with the lowest hash
* @apiName GetLowestBlocks
* @apiGroup BlockGroup
* @apiVersion 2.0.0
*
* @apiUse LimitOffset
*
* @apiSuccess {Number} count The count of results.
* @apiUse Blocks
*
* @apiSuccessExample {json} Success
* {
* "ok": true,
* "count": 43,
* "blocks": [
* {
* "height": 110128,
* "address": "k5ztameslf",
* "hash": "000000000000fd42f2c046d9c0f99b6534c1e04a87902ebff7ed4396d1f5b4ea",
* "short_hash": "000000000000",
* "value": 12,
* "time": "2016-01-22T00:09:17.000Z"
* },
* {
* "height": 113253,
* "address": "k5ztameslf",
* "hash": "000000000001285d349f8781ac4f1d155472178e1150c0eb6a1cf4e441320f2c",
* "short_hash": "000000000001",
* "value": 14,
* "time": "2016-01-24T22:10:49.000Z"
* },
* ...
*/
router.get("/blocks/lowest", async (req: PaginatedQuery, res) => {
const results = await getLowestHashes(req.query.limit, req.query.offset);
returnPaginatedResult(res, "blocks", blockToJson, results);
});

/**
* @api {get} /blocks/last Get the last block
* @apiName GetLastBlock
* @apiGroup BlockGroup
* @apiVersion 2.0.0
*
* @apiUse Block
*
* @apiSuccessExample {json} Success
* {
* "ok": true,
* "block": {
* "height": 122225,
* "address": "kre3w0i79j",
* "hash": "1aa36f210f2e07b666646ac7dac3ea972262a6a474419edfc058e4402d40538d",
* "short_hash": "1aa36f210f2e",
* "value": 12,
* "time": "2016-02-02T17:55:35.000Z"
* }
* }
*/
router.get("/blocks/last", async (req, res) => {
const block = await ctrlGetLastBlock();
res.json({
Expand All @@ -217,27 +52,6 @@ export default (): Router => {
});
});

/**
*
* @api {get} /blocks/value Get the block reward
* @apiName GetBlockValue
* @apiGroup BlockGroup
* @apiVersion 2.0.6
*
* @apiSuccess {Number} value - The current block reward.
* @apiSuccess {Number} base_value - The base block reward.
*
* @apiDescription Returns the block reward - the base value plus the amount
* of unpaid names (names registered in the last 500 blocks). This
* is how much Krist will be rewarded for mining a block right now.
*
* @apiSuccessExample {json} Success
* {
* "ok": true,
* "value": 2,
* "base_value": 1
* }
*/
router.get(["/blocks/value", "/blocks/basevalue"], async (req, res) => {
const block = await ctrlGetLastBlock();
const blockValue = await getBlockValue();
Expand All @@ -249,29 +63,6 @@ export default (): Router => {
});
});

/**
* @api {get} /blocks/:height Get a block
* @apiName GetBlock
* @apiGroup BlockGroup
* @apiVersion 2.0.0
*
* @apiParam {String} height The height of the block.
*
* @apiUse Block
*
* @apiSuccessExample {json} Success
* {
* "ok": true,
* "block": {
* "height": 5000,
* "address": "b5591107c4",
* "hash": "0000003797c090eb72d87a391aeedbef89957f9627aea9807870df46eb13a7e3",
* "short_hash": "0000003797c0",
* "value": 50,
* "time": "2015-02-21T11:05:47.000Z"
* }
* }
*/
router.get("/blocks/:height", async (req, res) => {
const block = await ctrlGetBlock(req.params.height);
res.json({
Expand Down
48 changes: 0 additions & 48 deletions src/webserver/routes/lookup/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,54 +33,6 @@ import {
export default (): Router => {
const router = Router();

/**
* @api {get} /lookup/blocks Lookup blocks
* @apiName LookupBlocks
* @apiGroup LookupGroup
* @apiVersion 2.1.3
*
* @apiDescription Return all the blocks.
*
* **WARNING:** The Lookup API is in Beta, and is subject to change at any
* time without warning.
*
* @apiUse LimitOffset
* @apiQuery {String} [orderBy=height] The field to order the
* results by. Must be one of `height`, `address`, `hash`, `value`,
* `time` or `difficulty`.
* @apiQuery {String} [order=ASC] The direction to order
* the results in. Must be one of `ASC` or `DESC`.
*
* @apiSuccess {Number} count The count of results returned.
* @apiSuccess {Number} total The total count of results available.
* @apiUse Blocks
*
* @apiSuccessExample {json} Success
* {
* "ok": true,
* "count": 20,
* "total": 1397410,
* "blocks": [
* {
* "height": 101496,
* "address": "k5ztameslf",
* "hash": "00000000224f08def4a2cef05fed91abdf8eb03feb79d80fe2b187487d2ad06b",
* "short_hash": "00000000224f",
* "value": 3013,
* "time": "2016-01-11T22:16:09.000Z",
* "difficulty": 18758
* },
* {
* "height": 1187992,
* "address": "kristallie",
* "hash": "00000000004fd4ededc6edc7528c99f10e74cdecd88627a5a98df9431f52473b",
* "short_hash": "00000000004f",
* "value": 152,
* "time": "2020-02-09T04:02:58.000Z",
* "difficulty": 100
* },
* ...
*/
router.get("/blocks", async (req: LookupQuery, res) => {
// Query filtering parameters
const limit = validateLimit(req.query.limit);
Expand Down
Loading

0 comments on commit 6a1cfcd

Please sign in to comment.