mirror of
				https://github.com/hackku21/loc-chain-backend.git
				synced 2025-06-13 12:53:59 +00:00 
			
		
		
		
	Add /api/v1/chain endpoint to read blockchain
This commit is contained in:
		
							parent
							
								
									f0570a6101
								
							
						
					
					
						commit
						5f3a1940e5
					
				| @ -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…
	
		Reference in New Issue
	
	Block a user