import { sha256 } from "js-sha256" ; import { serialize } from "serializer.ts/Serializer" ; export type Address = string ; export class Transaction { public senderAddress : Address ; public recipientAddress : Address ; public value : number ; constructor ( senderAddress , recipientAddress , value ) { this . senderAddress = senderAddress ; this . recipientAddress = recipientAddress ; this . value = value ; } } export class Block { public blockNumber : number ; public transactions : Array < Transaction > ; public timestamp : number ; public nonce : number ; public prevBlock : string ; constructor ( blockNumber , transactions , timestamp , nonce , prevBlock ) { this . blockNumber = blockNumber ; this . transactions = transactions ; this . timestamp = timestamp ; this . nonce = nonce ; this . prevBlock = prevBlock ; } public sha256 ( ) { return sha256 ( JSON . stringify ( serialize < Block > ( this ) ) ) ; } } export class Blockchain { public nodeId : string ; public blocks : Array < Block > ; public transactionPool : Array < Transaction > ; constructor ( nodeId ) { this . nodeId = nodeId ; this . blocks = [ ] ; this . transactionPool = [ ] ; } public submitTransaction ( senderAddress , recipientAddress , value ) { this . transactionPool . push ( new Transaction ( senderAddress , recipientAddress , value ) ) ; } public createBlock ( ) { } }