diff --git a/server.ts b/server.ts index c4777be..225cb52 100644 --- a/server.ts +++ b/server.ts @@ -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"); } }); diff --git a/server/utils/common.ts b/server/utils/common.ts index 3a2e546..438830a 100644 --- a/server/utils/common.ts +++ b/server/utils/common.ts @@ -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}; \ No newline at end of file +export {latestBlockDetails}; +export {Details}; \ No newline at end of file diff --git a/src/app/view/api-view/api-view.component.css b/src/app/view/api-view/api-view.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/view/api-view/api-view.component.html b/src/app/view/api-view/api-view.component.html new file mode 100644 index 0000000..312c561 --- /dev/null +++ b/src/app/view/api-view/api-view.component.html @@ -0,0 +1 @@ +

api-view works!

diff --git a/src/app/view/api-view/api-view.component.spec.ts b/src/app/view/api-view/api-view.component.spec.ts new file mode 100644 index 0000000..b58309b --- /dev/null +++ b/src/app/view/api-view/api-view.component.spec.ts @@ -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; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ApiViewComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ApiViewComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/view/api-view/api-view.component.ts b/src/app/view/api-view/api-view.component.ts new file mode 100644 index 0000000..97ac34f --- /dev/null +++ b/src/app/view/api-view/api-view.component.ts @@ -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() { + } + +} diff --git a/src/app/view/view-routing.module.ts b/src/app/view/view-routing.module.ts index 9690f7e..6f47895 100755 --- a/src/app/view/view-routing.module.ts +++ b/src/app/view/view-routing.module.ts @@ -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 = [ diff --git a/src/app/view/view.module.ts b/src/app/view/view.module.ts index bfe97be..7f73b8f 100755 --- a/src/app/view/view.module.ts +++ b/src/app/view/view.module.ts @@ -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]}, diff --git a/src/assets/css/style.css b/src/assets/css/style.css index d4ab43f..485df95 100644 --- a/src/assets/css/style.css +++ b/src/assets/css/style.css @@ -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 {