Add /api/v1/chain endpoint to read blockchain

working-state
Garrett Mills 3 years ago
parent f0570a6101
commit 5f3a1940e5
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

@ -1,7 +1,8 @@
import {Controller} from "@extollo/lib"
import {Injectable} from "@extollo/di"
import {Injectable, Inject} from "@extollo/di"
import {TransactionResource, TransactionResourceItem} from "../../../rtdb/TransactionResource"
import {one} from "@extollo/util"
import {many, one} from "@extollo/util"
import {Blockchain as BlockchainService} from "../../../units/Blockchain"
/**
* Blockchain Controller
@ -10,6 +11,20 @@ import {one} from "@extollo/util"
*/
@Injectable()
export class Blockchain extends Controller {
@Inject()
protected readonly blockchain!: BlockchainService
/**
* Read the version of the blockchain held by this host, as it currently exists.
*/
public async readBlockchain() {
return many((await this.blockchain.read()).map(x => {
// @ts-ignore
delete x.firebaseID
return x
}))
}
/**
* Post a new transaction to the blockchain. This is only intended for testing.
*/

@ -4,4 +4,6 @@ Route.group('/api/v1', () => {
Route.post('/encounter', 'api:Blockchain.postTransaction')
.pre('DebugOnly')
.pre('api:ValidateEncounterTransaction')
Route.get('/chain', 'api:Blockchain.readBlockchain')
})

@ -213,6 +213,13 @@ export class Blockchain extends Unit {
return new Block(genesis)
}
/**
* Get a list of all blocks in the chain, in order.
*/
public async read(): Promise<BlockResourceItem[]> {
return BlockResource.collect().all()
}
/**
* Given a client-submitted transaction, generate a block encounter transaction record.
* @param item

Loading…
Cancel
Save