1: <?php
2:
3: namespace Liberty;
4:
5: use Liberty\LECDSA;
6: use Liberty\Transaction;
7: use Exception;
8:
9: 10: 11: 12: 13: 14: 15: 16: 17: 18:
19:
20:
21: class Block {
22:
23: public $index;
24:
25: public $sender;
26: public $receiver;
27: public $amount;
28: public $fee;
29:
30: public $time;
31: public $signature;
32: public $previousHash;
33:
34:
35:
36: public function __construct($index, $sender, $receiver, $amount, $fee, $time, $signature, $previousHash)
37: {
38: $this->index = $index;
39:
40: $this->sender = $sender;
41: $this->receiver = $receiver;
42: $this->amount = $amount;
43: $this->fee = $fee;
44: $this->time = $time;
45: $this->signature = $signature;
46:
47: $this->previousHash = $previousHash;
48:
49: 50: 51: 52: 53:
54: }
55:
56:
57:
58: public function hash()
59: {
60: $ec = new LECDSA();
61: $hash = hash("sha256", $this->index . $this->sender . $this->receiver . $this->amount . $this->fee .
62: $this->time . $this->signature . $this->previousHash);
63: return $ec->base58_encode($hash);
64: }
65:
66:
67:
68: public function block()
69: {
70: $block = $this->index . " ";
71: $block .= $this->sender . " ";
72: $block .= $this->receiver . " ";
73: $block .= $this->amount . " ";
74: $block .= $this->fee . " ";
75: $block .= $this->time . " ";
76: $block .= $this->signature . " ";
77: $block .= $this->previousHash . " ";
78: $block .= $this->hash();
79: return $block;
80: }
81:
82: }
83:
84: ?>