You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.7 KiB
59 lines
1.7 KiB
import {FirebaseResource, FirebaseResourceItem} from "../FirebaseResource"
|
|
import {Injectable} from "@extollo/di"
|
|
import {RTDBRef} from "../units/FirebaseUnit"
|
|
import {AsyncCollection} from "@extollo/util"
|
|
|
|
export interface BlockEncounterTransaction {
|
|
combinedHash: string;
|
|
timestamp: number;
|
|
encodedGPSLocation: string;
|
|
}
|
|
|
|
export interface BlockInfectionTransaction {
|
|
clientID: string;
|
|
timestamp: number;
|
|
}
|
|
|
|
export type BlockTransaction = BlockInfectionTransaction | BlockEncounterTransaction
|
|
|
|
export function isBlockEncounterTransaction(what: any): what is BlockEncounterTransaction {
|
|
return (
|
|
what
|
|
&& typeof what.combinedHash === 'string'
|
|
&& typeof what.timestamp === 'number'
|
|
&& typeof what.encodedGPSLocation === 'string'
|
|
)
|
|
}
|
|
|
|
export function isBlockInfectionTransaction(what: any): what is BlockInfectionTransaction {
|
|
return (
|
|
what
|
|
&& typeof what.clientID === 'string'
|
|
&& typeof what.timestamp === 'number'
|
|
)
|
|
}
|
|
|
|
export function isBlockTransaction(what: any): what is BlockTransaction {
|
|
return isBlockEncounterTransaction(what) || isBlockInfectionTransaction(what)
|
|
}
|
|
|
|
export interface BlockResourceItem extends FirebaseResourceItem {
|
|
uuid: string;
|
|
combinedHash: string;
|
|
timestamp: number;
|
|
encodedGPSLocation: string;
|
|
transactions: BlockTransaction[];
|
|
lastBlockHash: string;
|
|
lastBlockUUID: string;
|
|
proof: string;
|
|
}
|
|
|
|
@Injectable()
|
|
export class BlockResource extends FirebaseResource<BlockResourceItem> {
|
|
public static collect(): AsyncCollection<BlockResourceItem> {
|
|
return new AsyncCollection<BlockResourceItem>(new BlockResource())
|
|
}
|
|
|
|
protected refName: RTDBRef = 'block'
|
|
}
|