This repository has been archived by the owner on Jan 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 370
/
validation.js
59 lines (49 loc) · 1.49 KB
/
validation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict';
const { createHash } = require('crypto');
const signing = require('./signing');
/**
* A simple validation function for transactions. Accepts a transaction
* and returns true or false. It should reject transactions that:
* - have negative amounts
* - were improperly signed
* - have been modified since signing
*/
const isValidTransaction = transaction => {
// Enter your solution here
};
/**
* Validation function for blocks. Accepts a block and returns true or false.
* It should reject blocks if:
* - their hash or any other properties were altered
* - they contain any invalid transactions
*/
const isValidBlock = block => {
// Your code here
};
/**
* One more validation function. Accepts a blockchain, and returns true
* or false. It should reject any blockchain that:
* - is a missing genesis block
* - has any block besides genesis with a null hash
* - has any block besides genesis with a previousHash that does not match
* the previous hash
* - contains any invalid blocks
* - contains any invalid transactions
*/
const isValidChain = blockchain => {
// Your code here
};
/**
* This last one is just for fun. Become a hacker and tamper with the passed in
* blockchain, mutating it for your own nefarious purposes. This should
* (in theory) make the blockchain fail later validation checks;
*/
const breakChain = blockchain => {
// Your code here
};
module.exports = {
isValidTransaction,
isValidBlock,
isValidChain,
breakChain
};