-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlock.php
39 lines (32 loc) · 920 Bytes
/
Block.php
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
<?php
/**
* Block class for php blockchain platform
*
* @author exevior
*/
class Block {
public $nonce;
public $timestamp;
public $data;
public $index;
public $hash;
public $previousHash;
//Used when creating a new block
function block($index, $timestamp, $data, $previoushash = null){
$this->index = $index;
$this->timestamp = $timestamp;
$this->data = $data;
$this->previousHash = $previousHash;
$this->hash = $this->calculateHash();
$this->nonce = 0;
}
/**
* Hash encryption algorithm
*/
public function calculateHash()
{
//Using sha256. Could be altered with any encryption algorithm
//*tip For php the argon2 library is fast and efficient
return hash("sha256", $this->index.$this->previousHash.$this->timestamp.((string)$this->data).$this->nonce);
}
}