Skip to content

Commit

Permalink
eosio missing methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kesar committed May 19, 2018
1 parent 16c328b commit ae206c9
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 20 deletions.
7 changes: 6 additions & 1 deletion README.md
Expand Up @@ -19,6 +19,11 @@ $info = $client->chain()->getInfo();
$block = $client->chain()->getBlock(2);
$account = $client->chain()->getAccount('eosio');
$code = $client->chain()->getCode('eosio');
print_r($account);
$stats = $client->chain()->getCurrencyStats('eosio.token', 'EOS');
$balance = $client->chain()->getCurrencyBalance('eosio.token', 'eosio.token', 'EOS');
$transaction = $client->history()->getTransaction('29716ecdd6a8555fab509321faabfb5d06e0bf25db678347c360e7f85159ca38');
$actions = $client->history()->getActions('eosio.token');

print_r($actions);

```
6 changes: 5 additions & 1 deletion example.php
Expand Up @@ -10,4 +10,8 @@
$block = $client->chain()->getBlock(2);
$account = $client->chain()->getAccount('eosio');
$code = $client->chain()->getCode('eosio');
print_r($account);
$stats = $client->chain()->getCurrencyStats('eosio.token', 'EOS');
$balance = $client->chain()->getCurrencyBalance('eosio.token', 'eosio.token', 'EOS');
$transaction = $client->history()->getTransaction('29716ecdd6a8555fab509321faabfb5d06e0bf25db678347c360e7f85159ca38');
$actions = $client->history()->getActions('eosio.token');
print_r($actions);
46 changes: 33 additions & 13 deletions src/EOSPHP/Plugins/Chain.php
Expand Up @@ -15,15 +15,6 @@ public function __construct(Client $client)
$this->client = $client;
}

/* TODO:
3569548ms thread-1 http_plugin.cpp:325 add_handler ] add api url: /v1/chain/get_currency_balance
3569548ms thread-1 http_plugin.cpp:325 add_handler ] add api url: /v1/chain/get_currency_stats
3569548ms thread-1 http_plugin.cpp:325 add_handler ] add api url: /v1/chain/get_producers
3569548ms thread-1 http_plugin.cpp:325 add_handler ] add api url: /v1/chain/push_block
3569548ms thread-1 http_plugin.cpp:325 add_handler ] add api url: /v1/chain/push_transaction
3569548ms thread-1 http_plugin.cpp:325 add_handler ] add api url: /v1/chain/push_transactions
*/

public function getInfo()
{
return new Info($this->client->get('chain/get_info')->getBody());
Expand Down Expand Up @@ -83,18 +74,47 @@ public function abiBinToJson(string $code, string $action, string $binArgs)
return json_decode($res->getBody());
}

public function pushTransaction()
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 pushTransactions()
public function pushBlock()
{
// TODO
}

public function getRequiredKeys()
public function pushTransaction()
{
// TODO
}

public function pushTransactions()
{
// TODO
}
}
}
16 changes: 15 additions & 1 deletion src/EOSPHP/Plugins/History.php
Expand Up @@ -13,5 +13,19 @@ public function __construct(Client $client)
$this->client = $client;
}

// TODO: /v1/history/get_actions /v1/history/get_transaction
public function getActions(string $accountName, int $pos = 0, int $offset = 0)
{
$body = '{"account_name":"'.$accountName.'", "pos":'.$pos.', "offset": '.$offset.'}';
$res = $this->client->post('history/get_actions', ['body' => $body]);

return json_decode($res->getBody());
}

public function getTransaction(string $transactionId)
{
$body = '{"id":"'.$transactionId.'"}';
$res = $this->client->post('history/get_transaction', ['body' => $body]);

return json_decode($res->getBody());
}
}
30 changes: 28 additions & 2 deletions src/EOSPHP/Types/Block.php
Expand Up @@ -16,6 +16,10 @@ class Block
private $producerSignature;
private $id;
private $blockNum;
private $headerExtensions;
private $transactions;
private $blockExtensions;
private $refBlockPrefix;

public function __construct($response)
{
Expand All @@ -29,9 +33,11 @@ public function __construct($response)
$this->actionMroot = $responseObj->action_mroot;
$this->scheduleVersion = $responseObj->schedule_version;
$this->newProducers = $responseObj->new_producers;
// TODO: header_extensions
$this->headerExtensions = $responseObj->header_extensions;
$this->producerSignature = $responseObj->producer_signature;
// TODO: transactions block_extensions ref_block_prefix
$this->transactions = $responseObj->transactions;
$this->blockExtensions = $responseObj->block_extensions;
$this->refBlockPrefix = $responseObj->ref_block_prefix;
$this->id = $responseObj->id;
$this->blockNum = $responseObj->block_num;
}
Expand Down Expand Up @@ -95,4 +101,24 @@ public function producerSignature(): string
{
return $this->producerSignature;
}

public function headerExtensions(): array
{
return $this->headerExtensions;
}

public function transactions(): array
{
return $this->headerExtensions;
}

public function blockExtensions(): array
{
return $this->headerExtensions;
}

public function refBlockPrefix(): int
{
return $this->headerExtensions;
}
}
31 changes: 29 additions & 2 deletions src/EOSPHP/Types/Info.php
Expand Up @@ -11,6 +11,10 @@ class Info
private $headBlockId;
private $headBlockTime;
private $headBlockProducer;
private $virtualBlockCpuLimit;
private $virtualBlockNetLimit;
private $blockCpuLimit;
private $blockNetLimit;

public function __construct($response)
{
Expand All @@ -22,7 +26,10 @@ public function __construct($response)
$this->headBlockId = $responseObj->head_block_id;
$this->headBlockTime = new \DateTime($responseObj->head_block_time);
$this->headBlockProducer = $responseObj->head_block_producer;
// TODO: virtual_block_cpu_limit virtual_block_net_limit block_cpu_limit block_net_limit
$this->virtualBlockCpuLimit = $responseObj->virtual_block_cpu_limit;
$this->virtualBlockNetLimit = $responseObj->virtual_block_net_limit;
$this->blockCpuLimit = $responseObj->block_cpu_limit;
$this->blockNetLimit = $responseObj->block_net_limit;
}

public function serverVersion(): string
Expand Down Expand Up @@ -59,4 +66,24 @@ public function headBlockProducer(): string
{
return $this->headBlockProducer;
}
}

public function virtualBlockCpuLimit(): int
{
return $this->virtualBlockCpuLimit;
}

public function virtualBlockNetLimit(): int
{
return $this->virtualBlockNetLimit;
}

public function blockCpuLimit(): int
{
return $this->blockCpuLimit;
}

public function blockNetLimit(): int
{
return $this->blockNetLimit;
}
}

0 comments on commit ae206c9

Please sign in to comment.