update packages

add some docs
This commit is contained in:
vbodinaud
2021-03-04 15:45:45 +01:00
parent 00bc56adc3
commit 33d508fb44
7 changed files with 216 additions and 5 deletions

View File

@@ -17,6 +17,19 @@ class Block {
var nonce: Int
var timestamp: Int
/**
Initialize a block with the provided parts and specifications.
- parameters:
- hash: The hash of the block
- data: The data of the block
- previousHash: The hash of the previous block
- index: The index of the block
- nonce: The nonce of the block
- timestamp: The timestamp of the block
- returns: A beautiful new block for the blockchain.
*/
init(hash: String = "", data: String = "", previousHash: String = "", index: Int = 0, nonce: Int = 0, timestamp: Int = 0) {
self.data = data
self.previousHash = previousHash
@@ -26,10 +39,20 @@ class Block {
self.hash = hash
}
/**
Generate the hash of the block.
- returns: The hash of the block
*/
func generateHash() -> String {
return data.sha256()
}
/**
Generate the timestamp of the block
- returns: The timestamp of the block
*/
func generateTimestamp() -> Int {
return Int(Date().timeIntervalSince1970)
}