This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Router{ | |
routes: [] | |
mode: null | |
root: '/' | |
constructor(){ | |
this.mode = !!(history.pushState) ? 'history' : 'hash'; | |
} | |
add: (path, cb) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Router{ | |
routes: [] | |
mode: null | |
root: '/' | |
constructor(){ | |
this.mode = !!(history.pushState) ? 'history' : 'hash'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Blockchain = require('./blockchain') | |
const { validationResult } = require('express-validator/check') | |
class Chiccocoin { | |
constructor () { | |
this.blockchain = new Blockchain() | |
this.getChain = this.getChain.bind(this) | |
this.mine = this.mine.bind(this) | |
this.newTransaction = this.newTransaction.bind(this) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validProof (lastProof, proof) { | |
const guessHash = crypto.createHmac(process.env.HASH_TYPE, process.env.CRYPTO_SECRET) | |
.update(`${lastProof}${proof}`) | |
.digest('hex') | |
return guessHash.substr(0, 5) === process.env.RESOLUTION_HASH | |
} | |
proofOfWork (lastProof) { | |
let proof = 0 | |
while (true) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Blockchain { | |
constructor () { | |
// Create chain and transaction | |
this.chain = [] | |
this.current_transactions = [] | |
// Binding of this | |
this.newBlock = this.newBlock.bind(this) | |
this.newTransaction = this.newTransaction.bind(this) | |
this.lastBlock = this.lastBlock.bind(this) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const block = { | |
'index': 1, | |
'timestamp': 1506057125.900785, | |
'transactions': [ | |
{ | |
'sender': "8527147fe1f5426f9dd545de4b27ee00", | |
'recipient': "a77f5cdfa2934df3954a5c7c7da5df1f", | |
'amount': 5, | |
} | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Blockchain { | |
constructor () { | |
// Create chain and transaction | |
this.chain = [] | |
this.current_transactions = [] | |
// Binding of this | |
this.newBlock = this.newBlock.bind(this) | |
this.newTransaction = this.newTransaction.bind(this) | |
this.lastBlock = this.lastBlock.bind(this) |