garritfra
6 years ago
13 changed files with 8 additions and 9181 deletions
@ -1,2 +0,0 @@
|
||||
# Auto detect text files and perform LF normalization |
||||
* text=auto |
@ -1,79 +1 @@
|
||||
# Logs |
||||
logs |
||||
*.log |
||||
npm-debug.log* |
||||
yarn-debug.log* |
||||
yarn-error.log* |
||||
|
||||
# Runtime data |
||||
pids |
||||
*.pid |
||||
*.seed |
||||
*.pid.lock |
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover |
||||
lib-cov |
||||
|
||||
# Coverage directory used by tools like istanbul |
||||
coverage |
||||
|
||||
# nyc test coverage |
||||
.nyc_output |
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) |
||||
.grunt |
||||
|
||||
# Bower dependency directory (https://bower.io/) |
||||
bower_components |
||||
|
||||
# node-waf configuration |
||||
.lock-wscript |
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html) |
||||
build/Release |
||||
|
||||
# Dependency directories |
||||
node_modules/ |
||||
jspm_packages/ |
||||
|
||||
# TypeScript v1 declaration files |
||||
typings/ |
||||
|
||||
# Optional npm cache directory |
||||
.npm |
||||
|
||||
# Optional eslint cache |
||||
.eslintcache |
||||
|
||||
# Optional REPL history |
||||
.node_repl_history |
||||
|
||||
# Output of 'npm pack' |
||||
*.tgz |
||||
|
||||
# Yarn Integrity file |
||||
.yarn-integrity |
||||
|
||||
# dotenv environment variables file |
||||
.env |
||||
|
||||
# parcel-bundler cache (https://parceljs.org/) |
||||
.cache |
||||
|
||||
# next.js build output |
||||
.next |
||||
|
||||
# nuxt.js build output |
||||
.nuxt |
||||
|
||||
# vuepress build output |
||||
.vuepress/dist |
||||
|
||||
# Serverless directories |
||||
.serverless |
||||
|
||||
# FuseBox cache |
||||
.fusebox/ |
||||
|
||||
# build |
||||
dist/ |
||||
blockchain-project |
@ -1,12 +0,0 @@
|
||||
const gulp = require("gulp"); |
||||
const ts = require("gulp-typescript"); |
||||
|
||||
gulp.task("typescript", function() { |
||||
return gulp |
||||
.src("./src/**/*.ts") |
||||
.pipe(ts()) |
||||
.pipe(gulp.dest("dist")); |
||||
}); |
||||
|
||||
gulp.task("build", ["typescript"]); |
||||
gulp.task("default", ["build"]); |
@ -0,0 +1,7 @@
|
||||
package main |
||||
|
||||
import "fmt" |
||||
|
||||
func main() { |
||||
fmt.Printf("hello, world\n") |
||||
} |
@ -1,31 +0,0 @@
|
||||
{ |
||||
"name": "blockchain-project", |
||||
"version": "1.0.0", |
||||
"description": "Blockchain", |
||||
"scripts": { |
||||
"start": "npm run build && node ./dist/app.js", |
||||
"build": "gulp build" |
||||
}, |
||||
"author": "@garritfra", |
||||
"license": "ISC", |
||||
"dependencies": { |
||||
"@types/body-parser": "^1.17.0", |
||||
"@types/cors": "^2.8.4", |
||||
"@types/crypto-js": "^3.1.43", |
||||
"@types/express": "^4.16.0", |
||||
"@types/socket.io": "^2.1.0", |
||||
"body-parser": "^1.18.3", |
||||
"cors": "^2.8.5", |
||||
"crypto-js": "^3.1.9-1", |
||||
"express": "^4.16.4", |
||||
"gulp-typescript": "^5.0.0-alpha.3", |
||||
"parcel": "^1.10.3", |
||||
"parcel-bundler": "^1.10.3", |
||||
"socket.io": "^2.1.1", |
||||
"ts-node": "^7.0.1" |
||||
}, |
||||
"devDependencies": { |
||||
"gulp": "^3.9.1", |
||||
"typescript": "^3.1.6" |
||||
} |
||||
} |
@ -1,30 +0,0 @@
|
||||
import * as net from "net"; |
||||
import Blockchain from "../model/Blockchain"; |
||||
|
||||
const blockchain = new Blockchain(); |
||||
|
||||
const server = net.createServer(c => { |
||||
//'connection' listener
|
||||
|
||||
console.log("client connected"); |
||||
|
||||
c.on("end", () => { |
||||
console.log("client disconnected"); |
||||
}); |
||||
|
||||
c.on("data", data => { |
||||
try { |
||||
console.log(JSON.parse(data.toString())); |
||||
} catch (e) { |
||||
console.log("Request was not a JSON Object!"); |
||||
} |
||||
}); |
||||
|
||||
c.write("Hi!"); |
||||
c.pipe(c); |
||||
}); |
||||
|
||||
server.listen(42000, () => { |
||||
//'listening' listener
|
||||
console.log("server bound"); |
||||
}); |
@ -1,59 +0,0 @@
|
||||
import { SHA256 } from "crypto-js"; |
||||
import Transaction from "./Transaction"; |
||||
import { Hash } from "crypto"; |
||||
|
||||
export default class Block { |
||||
id: number; |
||||
timestamp: Date; |
||||
data: Transaction[]; |
||||
previousHash: string; |
||||
hash: string; |
||||
/** |
||||
* Construct a Block object |
||||
* @constructor |
||||
* @param {number} id |
||||
* @param {string} previousHash |
||||
*/ |
||||
constructor(id: number, previousHash: string) { |
||||
this.id = id; |
||||
this.timestamp = new Date(); |
||||
this.data = []; |
||||
this.previousHash = previousHash; |
||||
this.hash = this.calculateHash(); |
||||
} |
||||
|
||||
/** |
||||
* Concatenates the timestamp, previous hash and transaction data of a block and |
||||
* calculates the according SHA256 Hash |
||||
* @returns hash |
||||
*/ |
||||
calculateHash() { |
||||
let hashStr = this.timestamp + this.previousHash + this.data; |
||||
let hash = SHA256(hashStr).toString(); |
||||
return hash; |
||||
} |
||||
|
||||
/** |
||||
* Creates the first block in a blockchain. |
||||
* It has a stub transaction with an amount of 0 coins. |
||||
* |
||||
* Called automatically upon blockchain creation |
||||
* |
||||
* @returns genesisBlock |
||||
*/ |
||||
static createGenesisBlock() { |
||||
let date = new Date(); |
||||
let genesisTransaction = new Transaction("Genesis", "Genesis", 0); |
||||
let genesisBlock = new Block(0, "0"); |
||||
genesisBlock.addTransaction(genesisTransaction); |
||||
return genesisBlock; |
||||
} |
||||
|
||||
/** |
||||
* Pushes a transaction to the Block |
||||
* @param {Transaction} transaction |
||||
*/ |
||||
addTransaction(transaction: Transaction) { |
||||
this.data.push(transaction); |
||||
} |
||||
} |
@ -1,21 +0,0 @@
|
||||
import Block from "./Block"; |
||||
|
||||
export default class Blockchain { |
||||
blocks: any[]; |
||||
genesisBlock: Block; |
||||
constructor() { |
||||
this.blocks = []; |
||||
this.genesisBlock = Block.createGenesisBlock(); |
||||
|
||||
this.addBlock(this.genesisBlock); |
||||
} |
||||
|
||||
addBlock(block: Block) { |
||||
this.blocks.push(block); |
||||
} |
||||
|
||||
getLastBlock() { |
||||
let lastBlock = this.blocks[this.blocks.length - 1]; |
||||
return lastBlock; |
||||
} |
||||
} |
@ -1,11 +0,0 @@
|
||||
import { RequestType } from "./RequestType"; |
||||
|
||||
export default class Data { |
||||
requestType: RequestType; |
||||
data: any; |
||||
|
||||
constructor(requestType: RequestType, data: any) { |
||||
this.requestType = requestType; |
||||
this.data = data; |
||||
} |
||||
} |
@ -1,4 +0,0 @@
|
||||
export enum RequestType { |
||||
CREATE_BLOCK, |
||||
GET_BLOCKS |
||||
} |
@ -1,11 +0,0 @@
|
||||
export default class Transaction { |
||||
sender: string; |
||||
receiver: string; |
||||
amount: number; |
||||
|
||||
constructor(sender: string, receiver: string, amount: number) { |
||||
this.sender = sender; |
||||
this.receiver = receiver; |
||||
this.amount = amount; |
||||
} |
||||
} |
Loading…
Reference in new issue