-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
70 lines (52 loc) · 1.07 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
require "bootstrap.php";
use Merkle\{Tree, Leaf};
$customer = sha1("John Smith");
$retailer = sha1("John Doe");
$merchant = sha1("Amazon");
$taxman = sha1("Tax Revenue");
$courier = sha1("Shiply");
$exchange = sha1("Coinbase");
$transactions = array(
"purchase"=>new Leaf(array(
"sender"=>$customer,
"recipient"=>$retailer,
"amount"=>100
)),
"w/h-tax"=>new Leaf(array(
"sender"=>$customer,
"recipient"=>$taxman,
"amount"=>10
)),
"commission"=>new Leaf(array(
"sender"=>$customer,
"recipient"=>$merchant,
"amount"=>5
)),
"freight"=>new Leaf(array(
"sender"=>$customer,
"recipient"=>$courier,
"amount"=>5
)),
"trx-fees"=>new Leaf(array(
"sender"=>$customer,
"recipient"=>$exchange,
"amount"=>1
))
);
$hash = function($data){
return sha1($data);
};
$treeA = new Tree($hash);
$treeB = new Tree($hash);
foreach($transactions as $name=>$trx){
$nodeA = $treeA->add($trx);
// Make inconsistent trx
if($name != "freight")
$nodeB = $treeB->add($trx);
if($nodeA != $nodeB){
// Print inconsistent trx
print_r($trx);
break;
}
}