mirror of
https://github.com/hackku21/loc-chain-backend.git
synced 2024-10-27 20:34:03 +00:00
Added check api to retrieve blocks for certain timeframe
This commit is contained in:
parent
71b4fefef7
commit
fbc3711560
1579
pnpm-lock.yaml
1579
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,7 @@ import * as fs from "fs"
|
||||
|
||||
export default {
|
||||
name: env('APP_NAME', 'Extollo'),
|
||||
defaultTime: env('DEFAULT_TIME', 1.21e+9),
|
||||
|
||||
gpg: {
|
||||
key: {
|
||||
|
@ -1,9 +1,11 @@
|
||||
import {Controller} from "@extollo/lib"
|
||||
import {Controller, Config} from "@extollo/lib"
|
||||
import {Injectable, Inject} from "@extollo/di"
|
||||
import {TransactionResource, TransactionResourceItem} from "../../../rtdb/TransactionResource"
|
||||
import {many, one} from "@extollo/util"
|
||||
import {Iterable, many, one} from "@extollo/util"
|
||||
import {Block, Blockchain as BlockchainService} from "../../../units/Blockchain"
|
||||
import {ExposureResource, ExposureResourceItem} from "../../../rtdb/ExposureResource";
|
||||
import {FirebaseUnit} from "../../../units/FirebaseUnit"
|
||||
import { BlockResource, BlockResourceItem } from "../../../rtdb/BlockResource"
|
||||
|
||||
/**
|
||||
* Blockchain Controller
|
||||
@ -15,6 +17,11 @@ export class Blockchain extends Controller {
|
||||
@Inject()
|
||||
protected readonly blockchain!: BlockchainService
|
||||
|
||||
@Inject()
|
||||
protected readonly config!: Config
|
||||
|
||||
@Inject()
|
||||
protected readonly firebase!: FirebaseUnit
|
||||
/**
|
||||
* Read the version of the blockchain held by this host, as it currently exists.
|
||||
*/
|
||||
@ -68,4 +75,18 @@ export class Blockchain extends Controller {
|
||||
await (<ExposureResource> this.make(ExposureResource)).push(item)
|
||||
return one(item)
|
||||
}
|
||||
|
||||
public async check() {
|
||||
let minTime = this.request.input('minTime')
|
||||
if (!minTime) {
|
||||
minTime = (new Date).getTime() - this.config.get('app.defaultTime')
|
||||
}
|
||||
const snapshot = await (<BlockResource> this.make(BlockResource)).ref()
|
||||
.orderByChild('timestamp')
|
||||
.startAt(minTime)
|
||||
.once('value')
|
||||
|
||||
let blocks = (Object.values(snapshot.val()) as BlockResourceItem[]).filter((item: BlockResourceItem) => item.seqID !== 0)
|
||||
return many(blocks)
|
||||
}
|
||||
}
|
||||
|
@ -13,4 +13,8 @@ Route.group('/api/v1', () => {
|
||||
.pre('DebugOnly')
|
||||
|
||||
Route.get('/chain', 'api:Blockchain.readBlockchain')
|
||||
Route.get('/check', 'api:Blockchain.check')
|
||||
.pre('api:FirebaseUserOnly')
|
||||
Route.get('/check-debug', 'api:Blockchain.check')
|
||||
.pre('DebugOnly')
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user