Created
April 8, 2018 16:50
-
-
Save azamsharp/9ef504cd8af45c62dcf5fbec0390c04d to your computer and use it in GitHub Desktop.
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 : Codable { | |
var index :Int = 0 | |
var previousHash :String = "" | |
var hash :String! | |
var nonce :Int | |
private (set) var transactions :[Transaction] = [Transaction]() | |
var key :String { | |
get { | |
let transactionsData = try! JSONEncoder().encode(self.transactions) | |
let transactionsJSONString = String(data: transactionsData, encoding: .utf8) | |
return String(self.index) + self.previousHash + String(self.nonce) + transactionsJSONString! | |
} | |
} | |
func addTransaction(transaction :Transaction) { | |
self.transactions.append(transaction) | |
} | |
init() { | |
self.nonce = 0 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment