api updated

This commit is contained in:
root 2019-09-06 18:52:10 +05:30
parent 1019ebb535
commit 00916c0658
9 changed files with 140 additions and 46 deletions

101
server.ts
View File

@ -56,7 +56,7 @@ BlockchainOutput
import { universalGetLatestBlockDetails } from "./server/socket";
import { dbConfig } from "./server/ormconfig";
import { config } from "dotenv";
import {latestBlockDetails} from './server/utils';
import {latestBlockDetails, Details} from './server/utils';
config({ path: resolve(__dirname, "../.env") });
// const connectionManager = getConnectionManager();
@ -144,13 +144,31 @@ try {
{
let height = req.query.height;
if(height) {
let apiresponse = await request('http://116.203.116.37:3413/v1/blocks/'+height);
result = "Value soon";
let heighthash = await Details(height);
if(heighthash[0].hash)
result = heighthash[0].hash;
else
result = 'Invalid height';
} else if(height <0) {
result = '"height" parameter missing or invalid';
} else {
result = '"height" parameter missing or invalid';
}
result = 21000000;
}
else if(option == "getblockheight")
{
let hash = req.query.hash;
if(hash) {
let heighthash = await Details(hash);
if(heighthash[0].height)
result = heighthash[0].height;
else
result = 'Invalid hash';
} else {
result = '"hash" parameter missing or invalid';
}
}
else if(option == "getblockheight")
result = "";
@ -158,59 +176,60 @@ try {
result = 60;
else if(option == "info")
{
result = { "Name": "Epic Cash",
"Symbol": "EPIC",
"TotalSupply": 21000000,
"CurrentSupply": blockDetails.coin_existence,
"FoundationContribution" : blockDetails.foundationReward,
"CurrentBlockReward": blockDetails.userReward,
"Algorithms": "Cuckoo, RandomX, ProgPow",
"Target_Difficulty": {
"Cuckoo": blockDetails.targetdifficultycuckaroo + blockDetails.targetdifficultycuckatoo,
"RandomX": blockDetails.targetdifficultyrandomx,
"ProgPow": blockDetails.targetdifficultyprogpow
},
"Total_Difficulty": {
"Cuckoo": blockDetails.TotalCuckoo,
"RandomX": blockDetails.TotalDifficultyRandomx,
"ProgPow": blockDetails.TotalDifficultyProgpow
},
"BlockHeight": blockDetails.block_height,
"Blockchain": "MimbleWimble",
"Homepage": "https://epic.tech",
"Explorer": "https://explorer.epic.tech",
"API": "https://explorer.epic.tech/api",
"Logo": "https://explorer.epic.tech/assets/img/logo.png",
"ICO": "NO",
"Premine": "NO",
"Mainnet": "YES",
"Genesis": "09-03-2019, 02:09:00 UTC",
"BlockInterval": 60,
"GIT": "https://gitlab.com/epiccash",
"Whitepaper":"https://epic.tech/whitepaper",
"Colors": { "off-white": "#f3f4f2", "off-black": "#222223", "gold" :"#bf9b30" }
};
}
result = {
"Name": "Epic Cash",
"Symbol": "EPIC",
"TotalSupply": 21000000,
"CurrentSupply": blockDetails.coin_existence,
"MinerCurrentBlockReward": blockDetails.userReward,
"Algorithms": "Cuckoo, RandomX, ProgPow",
"Target_Difficulty": {
"Cuckoo": blockDetails.targetdifficultycuckaroo + blockDetails.targetdifficultycuckatoo,
"RandomX": blockDetails.targetdifficultyrandomx,
"ProgPow": blockDetails.targetdifficultyprogpow
},
"Total_Difficulty": {
"Cuckoo": blockDetails.TotalCuckoo,
"RandomX": blockDetails.TotalDifficultyRandomx,
"ProgPow": blockDetails.TotalDifficultyProgpow
},
"BlockHeight": blockDetails.block_height,
"Blockchain": "MimbleWimble",
"Homepage": "https://epic.tech",
"Explorer": "https://explorer.epic.tech",
"API": "https://explorer.epic.tech/api",
"Logo": "https://explorer.epic.tech/assets/img/logo.png",
"ICO": "NO",
"Premine": "NO",
"Mainnet": "YES",
"Genesis": "09-03-2019, 02:09:00 UTC",
"BlockInterval": 60,
"GIT": "https://gitlab.com/epiccash",
"Whitepaper":"https://epic.tech/whitepaper",
"Colors": { "off-white": "#f3f4f2", "off-black": "#222223", "gold" :"#bf9b30" }
};
}
else
result= "Invalid Option";
var type = typeof result;
console.log("Type of the result is", type);
if (type == "object") {
res.status(200).json({...result});
}
else {
res.status(200).send(result);
res.status(200).json(result);
}
}
else
{
let result= 5;
//let result= 5;
//window.redirect('/');
}
}
catch(err){
res.status(200).send("Internal Server Error");
res.status(500).send("Internal Server Error");
}
});

View File

@ -306,5 +306,34 @@ let currentReward = 16;
userReward
};
}
async function Details (height) {
if(height){
const BlockchainLatestBlockQuery2 = await getConnection(Global.network)
.query(
"Select hash, height from blockchain_block Where height =" +height.replace(/[a-z]/gi, '')+" OR hash ='"+height+"'",
)
.catch(err_msg => {
return(err_msg);
});
return BlockchainLatestBlockQuery2;
}
}
async function GetBlocktime(height){
if(height){
const BlockchainLatestBlockQuery3 = await getConnection(Global.network)
.query(
"SELECT height, EXTRACT(EPOCH FROM (timestamp - LAG(timestamp) OVER (ORDER BY timestamp))) AS alter FROM blockchain_block where height="+height,
)
.catch(err_msg => {
return(err_msg);
});
return BlockchainLatestBlockQuery3;
}
}
export {latestBlockDetails};
export {latestBlockDetails};
export {Details};

View File

@ -0,0 +1 @@
<p>api-view works!</p>

View File

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ApiViewComponent } from './api-view.component';
describe('ApiViewComponent', () => {
let component: ApiViewComponent;
let fixture: ComponentFixture<ApiViewComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ApiViewComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ApiViewComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-api-view',
templateUrl: './api-view.component.html',
styleUrls: ['./api-view.component.css']
})
export class ApiViewComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}

View File

@ -2,7 +2,7 @@ import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomeLayoutComponent } from '../shared/components/layouts/home-layout/home-layout.component';
import { SiteLayoutComponent } from '../shared/components/layouts/site-layout/site-layout.component';
import { ApiViewComponent } from '../view/api-view/api-view.component';
const viewRoutes: Routes = [
{
path: '',
@ -35,6 +35,10 @@ const siteRoutes: Routes = [
title: 'Epic Explorer',
},
},
{
path: 'api-view',
component: ApiViewComponent
}
];
const routes: Routes = [

View File

@ -9,10 +9,11 @@ import {TranslateModule, TranslateLoader} from '@ngx-translate/core';
import { TransServiceService } from '../shared/services/trans-service.service';
import { ChartService} from '../shared/services/chart.service';
import { CustomLoader } from '../app.module';
import { ApiViewComponent } from './api-view/api-view.component';
@NgModule({
declarations: [],
declarations: [ApiViewComponent],
imports: [CommonModule, ViewRoutingModule, SharedModule,
TranslateModule.forChild({
loader: {provide: TranslateLoader, useClass: CustomLoader, deps : [HttpClient]},

View File

@ -190,7 +190,7 @@ a:focus {
.headerbg {
background: url(/assets/img/body_bg.png);
overflow: hidden;
}
background-position-y: -22%;}
.body_bg {
background: url(/assets/img/body_bg.png);
background-position-y: -22%;
@ -567,7 +567,7 @@ body.dark_theme {
}
.dark_theme .body_bg {
background: url(/assets/img/dark_bg1.png);
background-position-y: -22%;
/* background-position-y: -22%; */
}
.dark_theme .logo_txt,
.dark_theme .ip_filter a {