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

View File

@ -56,7 +56,7 @@ BlockchainOutput
import { universalGetLatestBlockDetails } from "./server/socket"; import { universalGetLatestBlockDetails } from "./server/socket";
import { dbConfig } from "./server/ormconfig"; import { dbConfig } from "./server/ormconfig";
import { config } from "dotenv"; import { config } from "dotenv";
import {latestBlockDetails} from './server/utils'; import {latestBlockDetails, Details} from './server/utils';
config({ path: resolve(__dirname, "../.env") }); config({ path: resolve(__dirname, "../.env") });
// const connectionManager = getConnectionManager(); // const connectionManager = getConnectionManager();
@ -144,13 +144,31 @@ try {
{ {
let height = req.query.height; let height = req.query.height;
if(height) { if(height) {
let apiresponse = await request('http://116.203.116.37:3413/v1/blocks/'+height); let heighthash = await Details(height);
result = "Value soon"; if(heighthash[0].hash)
result = heighthash[0].hash;
else
result = 'Invalid height';
} else if(height <0) {
result = '"height" parameter missing or invalid';
} else { } else {
result = '"height" parameter missing or invalid'; 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") else if(option == "getblockheight")
result = ""; result = "";
@ -158,12 +176,12 @@ try {
result = 60; result = 60;
else if(option == "info") else if(option == "info")
{ {
result = { "Name": "Epic Cash", result = {
"Name": "Epic Cash",
"Symbol": "EPIC", "Symbol": "EPIC",
"TotalSupply": 21000000, "TotalSupply": 21000000,
"CurrentSupply": blockDetails.coin_existence, "CurrentSupply": blockDetails.coin_existence,
"FoundationContribution" : blockDetails.foundationReward, "MinerCurrentBlockReward": blockDetails.userReward,
"CurrentBlockReward": blockDetails.userReward,
"Algorithms": "Cuckoo, RandomX, ProgPow", "Algorithms": "Cuckoo, RandomX, ProgPow",
"Target_Difficulty": { "Target_Difficulty": {
"Cuckoo": blockDetails.targetdifficultycuckaroo + blockDetails.targetdifficultycuckatoo, "Cuckoo": blockDetails.targetdifficultycuckaroo + blockDetails.targetdifficultycuckatoo,
@ -195,22 +213,23 @@ try {
result= "Invalid Option"; result= "Invalid Option";
var type = typeof result; var type = typeof result;
console.log("Type of the result is", type);
if (type == "object") { if (type == "object") {
res.status(200).json({...result}); res.status(200).json({...result});
} }
else { else {
res.status(200).send(result); res.status(200).json(result);
} }
} }
else else
{ {
let result= 5; //let result= 5;
//window.redirect('/');
} }
} }
catch(err){ catch(err){
res.status(200).send("Internal Server Error"); res.status(500).send("Internal Server Error");
} }
}); });

View File

@ -307,4 +307,33 @@ let currentReward = 16;
}; };
} }
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 { Routes, RouterModule } from '@angular/router';
import { HomeLayoutComponent } from '../shared/components/layouts/home-layout/home-layout.component'; import { HomeLayoutComponent } from '../shared/components/layouts/home-layout/home-layout.component';
import { SiteLayoutComponent } from '../shared/components/layouts/site-layout/site-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 = [ const viewRoutes: Routes = [
{ {
path: '', path: '',
@ -35,6 +35,10 @@ const siteRoutes: Routes = [
title: 'Epic Explorer', title: 'Epic Explorer',
}, },
}, },
{
path: 'api-view',
component: ApiViewComponent
}
]; ];
const routes: Routes = [ 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 { TransServiceService } from '../shared/services/trans-service.service';
import { ChartService} from '../shared/services/chart.service'; import { ChartService} from '../shared/services/chart.service';
import { CustomLoader } from '../app.module'; import { CustomLoader } from '../app.module';
import { ApiViewComponent } from './api-view/api-view.component';
@NgModule({ @NgModule({
declarations: [], declarations: [ApiViewComponent],
imports: [CommonModule, ViewRoutingModule, SharedModule, imports: [CommonModule, ViewRoutingModule, SharedModule,
TranslateModule.forChild({ TranslateModule.forChild({
loader: {provide: TranslateLoader, useClass: CustomLoader, deps : [HttpClient]}, loader: {provide: TranslateLoader, useClass: CustomLoader, deps : [HttpClient]},

View File

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