Browse Source

Add types

web-api
garritfra 6 years ago
parent
commit
d3f92f6cb6
  1. 2
      src/daemon/app.ts
  2. 13
      src/model/Block.ts
  3. 2
      src/model/Blockchain.ts
  4. 8
      src/model/Transaction.ts
  5. 3
      tsconfig.json

2
src/daemon/app.ts

@ -14,7 +14,7 @@ const server = net.createServer(c => {
c.on("data", data => {
try {
console.log(JSON.parse(data.toString()).message);
console.log(JSON.parse(data.toString()));
} catch (e) {
console.log("Request was not a JSON Object!");
}

13
src/model/Block.ts

@ -1,19 +1,20 @@
import { SHA256 } from "crypto-js";
import Transaction from "./Transaction";
import { Hash } from "crypto";
export default class Block {
id: any;
id: number;
timestamp: Date;
data: any[];
previousHash: any;
hash: any;
data: Transaction[];
previousHash: string;
hash: string;
/**
* Construct a Block object
* @constructor
* @param {number} id
* @param {string} previousHash
*/
constructor(id, previousHash) {
constructor(id: number, previousHash: string) {
this.id = id;
this.timestamp = new Date();
this.data = [];
@ -52,7 +53,7 @@ export default class Block {
* Pushes a transaction to the Block
* @param {Transaction} transaction
*/
addTransaction(transaction) {
addTransaction(transaction: Transaction) {
this.data.push(transaction);
}
}

2
src/model/Blockchain.ts

@ -10,7 +10,7 @@ export default class Blockchain {
this.addBlock(this.genesisBlock);
}
addBlock(block) {
addBlock(block: Block) {
this.blocks.push(block);
}

8
src/model/Transaction.ts

@ -1,9 +1,9 @@
export default class Transaction {
sender: any;
receiver: any;
amount: any;
sender: string;
receiver: string;
amount: number;
constructor(sender, receiver, amount) {
constructor(sender: string, receiver: string, amount: number) {
this.sender = sender;
this.receiver = receiver;
this.amount = amount;

3
tsconfig.json

@ -5,6 +5,5 @@
"noImplicitAny": true,
"rootDir": "src",
"moduleResolution": "node"
},
"include": ["** /*"]
}
}

Loading…
Cancel
Save