mirror of
https://github.com/hackku21/loc-chain-backend.git
synced 2026-03-02 03:40:09 +00:00
Implement basic chain validation and stub PoW
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -104,3 +104,4 @@ dist
|
||||
.tern-port
|
||||
|
||||
lib/*
|
||||
*.gpg.key
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"@extollo/lib": "^0.1.2",
|
||||
"@extollo/orm": "^0.1.1",
|
||||
"@extollo/util": "^0.3.1",
|
||||
"bcrypt": "^5.0.1",
|
||||
"copyfiles": "^2.4.1",
|
||||
"firebase-admin": "^9.6.0",
|
||||
"openpgp": "^5.0.0-1",
|
||||
|
||||
1714
pnpm-lock.yaml
generated
1714
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,7 @@ import {FirebaseUnit} from "./FirebaseUnit"
|
||||
import {BlockResource, BlockResourceItem, BlockTransaction} from "../rtdb/BlockResource"
|
||||
import {TransactionResourceItem} from "../rtdb/TransactionResource"
|
||||
import * as crypto from "crypto"
|
||||
import {collect} from "@extollo/util";
|
||||
|
||||
export class Block implements BlockResourceItem {
|
||||
seqID: number;
|
||||
@@ -80,7 +81,12 @@ export class Blockchain extends Unit {
|
||||
}
|
||||
|
||||
public async validate(chain: Block[]) {
|
||||
const blocks = collect<Block>(chain)
|
||||
return blocks.every((block: Block, idx: number) => {
|
||||
if ( idx === 0 ) return true; // TODO handle genesis
|
||||
|
||||
return block.lastBlockHash === blocks.at(idx)!.hash()
|
||||
})
|
||||
}
|
||||
|
||||
public async refresh() {
|
||||
@@ -107,4 +113,12 @@ export class Blockchain extends Unit {
|
||||
public async down() {
|
||||
|
||||
}
|
||||
|
||||
protected async generateProofOfWork(lastBlock: Block): Promise<string> {
|
||||
const hash = lastBlock.hash()
|
||||
|
||||
// Create a signature from the hash using the server's private key
|
||||
|
||||
return hash
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user