Created
January 4, 2018 19:36
-
-
Save azamsharp/3a4948189487fc300110969572eed28c to your computer and use it in GitHub Desktop.
Block Model
This file contains hidden or 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 Block { | |
var index :Int = 0 | |
var dateCreated :String | |
var previousHash :String = "" | |
var hash :String! | |
var nonce :Int | |
var key :String { | |
get { | |
let transactionData = try! JSONEncoder().encode(self.transactions) | |
let transactionsJSONString = String(data: transactionData, encoding: .utf8) | |
let keyPart = String(self.index) + self.dateCreated + self.previousHash + String(self.nonce) | |
return (keyPart + transactionsJSONString!) | |
} | |
} | |
private (set) var transactions :[Transaction] = [Transaction]() | |
func addTransaction(transaction :Transaction, contracts :[SmartContract]) { | |
self.transactions.append(transaction) | |
} | |
init() { | |
self.dateCreated = Date().toString() | |
self.nonce = 0 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment