mirror of
https://github.com/hackku21/loc-chain-backend.git
synced 2024-10-27 20:34:03 +00:00
Implement basic chain validation and stub PoW
This commit is contained in:
parent
289f184b4d
commit
29f9fe9f1f
1
.gitignore
vendored
1
.gitignore
vendored
@ -104,3 +104,4 @@ dist
|
|||||||
.tern-port
|
.tern-port
|
||||||
|
|
||||||
lib/*
|
lib/*
|
||||||
|
*.gpg.key
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
"@extollo/lib": "^0.1.2",
|
"@extollo/lib": "^0.1.2",
|
||||||
"@extollo/orm": "^0.1.1",
|
"@extollo/orm": "^0.1.1",
|
||||||
"@extollo/util": "^0.3.1",
|
"@extollo/util": "^0.3.1",
|
||||||
|
"bcrypt": "^5.0.1",
|
||||||
"copyfiles": "^2.4.1",
|
"copyfiles": "^2.4.1",
|
||||||
"firebase-admin": "^9.6.0",
|
"firebase-admin": "^9.6.0",
|
||||||
"openpgp": "^5.0.0-1",
|
"openpgp": "^5.0.0-1",
|
||||||
|
1714
pnpm-lock.yaml
1714
pnpm-lock.yaml
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 {BlockResource, BlockResourceItem, BlockTransaction} from "../rtdb/BlockResource"
|
||||||
import {TransactionResourceItem} from "../rtdb/TransactionResource"
|
import {TransactionResourceItem} from "../rtdb/TransactionResource"
|
||||||
import * as crypto from "crypto"
|
import * as crypto from "crypto"
|
||||||
|
import {collect} from "@extollo/util";
|
||||||
|
|
||||||
export class Block implements BlockResourceItem {
|
export class Block implements BlockResourceItem {
|
||||||
seqID: number;
|
seqID: number;
|
||||||
@ -80,7 +81,12 @@ export class Blockchain extends Unit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async validate(chain: Block[]) {
|
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() {
|
public async refresh() {
|
||||||
@ -107,4 +113,12 @@ export class Blockchain extends Unit {
|
|||||||
public async down() {
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user