-
Notifications
You must be signed in to change notification settings - Fork 0
/
TODO.todo
62 lines (61 loc) · 4.23 KB
/
TODO.todo
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
60
61
62
block.js:
validate():
The `validate()` method will validate if the block has been tampered or not.
Been tampered means that someone from outside the application tried to change values in the block data as a consecuence the hash of the block should be different.
Steps:
[x] 1. Return a new promise to allow the method be called asynchronous. @done (19-07-22 19:45)
[x] 2. Save the in auxiliary variable the current hash of the block (`this` represent the block object) @done (19-07-22 19:55)
[x] 3. Recalculate the hash of the entire block (Use SHA256 from crypto-js library) @done (19-07-22 19:55)
[x] 4. Compare if the auxiliary hash value is different from the calculated one. @done (19-07-22 19:55)
[x] 5. Resolve true or false depending if it is valid or not. @done (19-07-22 19:55)
Note: to access the class values inside a Promise code you need to create an auxiliary value `let self = this;`
getBData():
Auxiliary Method to return the block body (decoding the data)
Steps:
[x] Use hex2ascii module to decode the data @done (19-07-29 13:05)
[x] Because data is a javascript object use JSON.parse(string) to get the Javascript Object @done (19-07-29 13:05)
[x] Resolve with the data and make sure that you don't need to return the data for the `genesis block` or Reject with an error. @done (19-07-29 13:05)
blockchain.js:
_addBlock(block):
[x] _addBlock(block) will store a block in the chain @done (19-07-29 14:22)
@param {*} block
The method will return a Promise that will resolve with the block added or reject if an error happen during the execution.
You will need to check for the height to assign the `previousBlockHash`, assign the `timestamp` and the correct `height`...At the end you need to create the `block hash` and push the block into the chain array. Don't for get
to update the `this.height`
Note: the symbol `_` in the method name indicates in the javascript convention
that this method is a private method.
requestMessageOwnershipVerification(address):
The requestMessageOwnershipVerification(address) method will allow you to request a message that you will use to sign it with your Bitcoin Wallet (Electrum or Bitcoin Core)
This is the first step before submit your Block.
The method return a Promise that will resolve with the message to be signed
@param {*} address
[x] requestMessageOwnershipVerification @done (19-07-29 15:13)
submitStar(address, message, signature, star):
The submitStar(address, message, signature, star) method will allow users to register a new Block with the star object into the chain. This method will resolve with the Block added or reject with an error.
Algorithm steps:
[x] 1. Get the time from the message sent as a parameter example: `parseInt(message.split(':')[1])` @done (19-07-29 17:41)
[x] 2. Get the current time: `let currentTime = parseInt(new Date().getTime().toString().slice(0, -3));` @done (19-07-29 17:41)
[x] 3. Check if the time elapsed is less than 5 minutes @done (19-07-29 17:41)
[x] 4. Veify the message with wallet address and signature: `bitcoinMessage.verify(message, address, signature)` @done (19-07-29 17:41)
[x] 5. Create the block and add it to the chain @done (19-07-29 17:41)
[x] 6. Resolve with the block added. @done (19-07-29 17:41)
@param {*} address
@param {*} message
@param {*} signature
@param {*} star
getBlockByHash(hash):
This method will return a Promise that will resolve with the Block with the hash passed as a parameter.
Search on the chain array for the block that has the hash.
@param {*} hash
[x] done @done (19-07-29 18:27)
getStarsByWalletAddress (address):
This method will return a Promise that will resolve with an array of Stars objects existing in the chain
and are belongs to the owner with the wallet address passed as parameter.
@param {*} address
[x] done @done (19-07-29 18:55)
validateChain():
This method will return a Promise that will resolve with the list of errors when validating the chain.
[ ] done
Steps to validate:
[ ] 1. You should validate each block using `validateBlock`
[ ] 2. Each Block should check the with the previousBlockHash