From a9da5951b5d1c5a49bba1f7c50d8b6918a6ae4ce Mon Sep 17 00:00:00 2001 From: Alexis Hernandez Date: Sat, 17 Mar 2018 18:46:00 -0600 Subject: [PATCH] web-ui: Add the BlocksService --- web-ui/src/app/app.module.ts | 2 ++ web-ui/src/app/models/block.ts | 36 +++++++++++++++++++++++ web-ui/src/app/services/blocks.service.ts | 24 +++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 web-ui/src/app/models/block.ts create mode 100644 web-ui/src/app/services/blocks.service.ts diff --git a/web-ui/src/app/app.module.ts b/web-ui/src/app/app.module.ts index 32cb68b..4ff6a71 100644 --- a/web-ui/src/app/app.module.ts +++ b/web-ui/src/app/app.module.ts @@ -13,6 +13,7 @@ import { ToastrModule } from 'ngx-toastr'; import { NgHttpLoaderModule } from 'ng-http-loader/ng-http-loader.module' import { AddressesService } from './services/addresses.service'; +import { BlocksService } from './services/blocks.service'; import { ErrorService } from './services/error.service'; import { LanguageService } from './services/language.service'; import { NavigatorService } from './services/navigator.service'; @@ -58,6 +59,7 @@ import { BlockDetailsComponent } from './components/block-details/block-details. ], providers: [ AddressesService, + BlocksService, ErrorService, LanguageService, NavigatorService, diff --git a/web-ui/src/app/models/block.ts b/web-ui/src/app/models/block.ts new file mode 100644 index 0000000..5622659 --- /dev/null +++ b/web-ui/src/app/models/block.ts @@ -0,0 +1,36 @@ + + +export class BlockDetails { + block: Block; + rewards: BlockRewards; +} + +class Block { + hash: string; + previousBlockhash: string; + nextBlockhash: string; + merkleRoot: string; + transactions: string[]; + confirmations: number; + size: number; + height: number; + version: number; + time: number; + medianTime: number; + nonce: number; + bits: string; + chainwork: string; + difficulty: number; + tposContract: string; +} + +class BlockRewards { + reward: BlockReward; + coinstake: BlockReward; + masternode: BlockReward; +} + +class BlockReward { + address: string; + value: number; +} diff --git a/web-ui/src/app/services/blocks.service.ts b/web-ui/src/app/services/blocks.service.ts new file mode 100644 index 0000000..3a45b71 --- /dev/null +++ b/web-ui/src/app/services/blocks.service.ts @@ -0,0 +1,24 @@ +import { Injectable } from '@angular/core'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { Observable } from 'rxjs/Observable'; + +import { environment } from '../../environments/environment'; + +import { BlockDetails } from '../models/block'; + +const httpOptions = { + headers: new HttpHeaders({ 'Content-Type': 'application/json' }) +}; + +@Injectable() +export class BlocksService { + + private baseUrl = environment.api.url + '/blocks'; + + constructor(private http: HttpClient) { } + + get(blockhash: string): Observable { + const url = `${this.baseUrl}/${blockhash}`; + return this.http.get(url); + } +}