Skip to content

Commit

Permalink
feat: copy from tari main repo
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler committed Aug 5, 2022
0 parents commit 128f610
Show file tree
Hide file tree
Showing 51 changed files with 14,460 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"plugins": ["prettier", "@babel"],
"env": {
"browser": true,
"commonjs": true,
"node": true,
"es2021": true
},
"parser": "@babel/eslint-parser", // Tell ESLint that you want to use the @babel/eslint-parser.
"parserOptions": {
"ecmaVersion": 2021,
"sourceType": "module",
"allowImportExportEverywhere": false,
"ecmaFeatures": {
"globalReturn": false
},
"requireConfigFile": false
},
"rules": {
"no-undef": "error",
"no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_"
}
],
"prettier/prettier": [
"error",
{
"doubleQuote": true,
"endOfLine": "auto"
}
]
}
}
130 changes: 130 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
partials
views/blocks.hbs
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"endOfLine": "auto"
}
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Tari explorer

## No client-side JavaScript block explorer

### Dependencies

- `npm i`

### Development (nodemon reload)

- `npm run dev`

### Start server

- `npm start`
115 changes: 115 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright 2022 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

const createError = require("http-errors");
const express = require("express");
const path = require("path");
const cookieParser = require("cookie-parser");
const logger = require("morgan");
const asciichart = require("asciichart");

var indexRouter = require("./routes/index");
var blocksRouter = require("./routes/blocks");
var mempoolRouter = require("./routes/mempool");
var searchRouter = require("./routes/search");

var assetsRouter = require("./routes/assets");
var validatorRouter = require("./routes/validator");

var hbs = require("hbs");
const [hex, script] = require("./script");
hbs.registerHelper("hex", hex);
hbs.registerHelper("script", script);

hbs.registerHelper("json", function (obj) {
return Buffer.from(JSON.stringify(obj)).toString("base64");
});

hbs.registerHelper("timestamp", function (timestamp) {
var dateObj = new Date(timestamp.seconds * 1000);
const day = dateObj.getUTCDate();
const month = dateObj.getUTCMonth() + 1;
const year = dateObj.getUTCFullYear();
const hours = dateObj.getUTCHours();
const minutes = dateObj.getUTCMinutes();
const seconds = dateObj.getSeconds();

return (
year.toString() +
"-" +
month.toString().padStart(2, "0") +
"-" +
day.toString().padStart(2, "0") +
" " +
hours.toString().padStart(2, "0") +
":" +
minutes.toString().padStart(2, "0") +
":" +
seconds.toString().padStart(2, "0")
);
});

hbs.registerHelper("percentbar", function (a, b) {
var percent = (a / (a + b)) * 100;
var barWidth = percent / 10;
var bar = "**********".slice(0, barWidth);
var space = "...........".slice(0, 10 - barWidth);
return bar + space + " " + parseInt(percent) + "% ";
});

hbs.registerHelper("chart", function (data, height) {
if (data.length > 0) {
return asciichart.plot(data, {
height: height,
});
} else {
return "**No data**";
}
});

hbs.registerHelper("json", function (obj) {
return JSON.stringify(obj);
});

hbs.registerPartials(path.join(__dirname, "partials"));

var app = express();

// view engine setup
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "hbs");

app.use(logger("dev"));
app.use(express.json());
app.use(
express.urlencoded({
extended: false,
})
);
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));

app.use("/", indexRouter);
app.use("/blocks", blocksRouter);
app.use("/assets", assetsRouter);
app.use("/validator", validatorRouter);
app.use("/mempool", mempoolRouter);
app.use("/search", searchRouter);

// catch 404 and forward to error handler
app.use(function (req, res, next) {
next(createError(404));
});

// error handler
app.use(function (err, req, res) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get("env") === "development" ? err : {};

// render the error page
res.status(err.status || 500);
res.render("error");
});

module.exports = app;
12 changes: 12 additions & 0 deletions baseNodeClient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2022 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

var { Client } = require("base-node-grpc-client");

function createClient() {
return Client.connect("localhost:18142");
}

module.exports = {
createClient,
};
Loading

0 comments on commit 128f610

Please sign in to comment.