/
Chain.php
120 lines (92 loc) · 3.25 KB
/
Chain.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace EOSPHP\Plugins;
use EOSPHP\Types\Block;
use EOSPHP\Types\Info;
use GuzzleHttp\Client;
class Chain implements Plugin
{
private $client;
public function __construct(Client $client)
{
$this->client = $client;
}
public function getInfo()
{
return new Info($this->client->get('chain/get_info')->getBody());
}
public function getBlock($blockOrNumber = 1)
{
return new Block($this->client->post('chain/get_block',
['body' => '{"block_num_or_id": "'.$blockOrNumber.'"}'])->getBody()
);
}
public function getAccount(string $accountName)
{
$res = $this->client->post('chain/get_account', ['body' => '{"account_name": "'.$accountName.'"}']);
return json_decode($res->getBody());
}
public function getCode(string $accountName)
{
$res = $this->client->post('chain/get_code', ['body' => '{"account_name": "'.$accountName.'"}']);
return json_decode($res->getBody());
}
public function getTableRows(
string $scope,
string $code,
string $table,
bool $json = true,
int $lowerBound = 0,
int $upperBound = -1,
int $limit = 10
) {
$body = '{"scope":"'.$scope.'", "code":"'.$code.'", "table":"'.$table.'", "json": '.$json.', "lower_bound":'.$lowerBound.', "upper_bound":'.$upperBound.', "limit":'.$limit.'}';
$res = $this->client->post('chain/get_code', ['body' => $body]);
return json_decode($res->getBody());
}
public function abiJsonToBin(string $code, string $action, string $args)
{
$body = '{"code":"'.$code.'", "action":"'.$action.'", "args":'.$args.'}';
$res = $this->client->post('chain/abi_json_to_bin', ['body' => $body]);
return json_decode($res->getBody());
}
public function abiBinToJson(string $code, string $action, string $binArgs)
{
$body = '{"code":"'.$code.'", "action":"'.$action.'", "binargs":'.$binArgs.'}';
$res = $this->client->post('chain/abi_json_to_bin', ['body' => $body]);
return json_decode($res->getBody());
}
public function getProducers(int $lowerBound, int $limit, bool $json = true)
{
$body = '{"json":'.$json.', "lower_bound":"'.$lowerBound.'", "limit":'.$limit.'}';
$res = $this->client->post('chain/get_producers', ['body' => $body]);
return json_decode($res->getBody());
}
public function getCurrencyBalance(string $code, string $account, ?string $symbol)
{
$body = '{"code":"'.$code.'", "account":"'.$account.'", "symbol":"'.$symbol.'"}';
$res = $this->client->post('chain/get_currency_balance', ['body' => $body]);
return json_decode($res->getBody());
}
public function getCurrencyStats(string $code, string $symbol)
{
$body = '{"code":"'.$code.'", "symbol":"'.$symbol.'"}';
$res = $this->client->post('chain/get_currency_stats', ['body' => $body]);
return json_decode($res->getBody());
}
public function getRequiredKeys()
{
// TODO
}
public function pushBlock()
{
// TODO
}
public function pushTransaction()
{
// TODO
}
public function pushTransactions()
{
// TODO
}
}