├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── composer.json ├── examples ├── authorPayments.php ├── composer.json ├── composer.phar └── conversionRate.php ├── phpunit.xml ├── src ├── SteemApi.php └── SteemLayer.php └── tests ├── SteemApiTest.php └── SteemLayerTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | examples/vendor/ 3 | examples/composer.lock 4 | examples/composer.phar 5 | composer.lock 6 | .DS_Store 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.4 5 | - 5.5 6 | - 5.6 7 | - hhvm 8 | 9 | before_script: 10 | - composer self-update 11 | - composer install --prefer-source --no-interaction --dev 12 | 13 | script: phpunit 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | DON'T BE A DICK PUBLIC LICENSE 2 | 3 | Version 1, September 2017 4 | 5 | Copyright (C) 2009 Dragos Roua dragosroua@gmail.com 6 | 7 | Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. 8 | 9 | DON'T BE A DICK PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 10 | 11 | Do whatever you like with the original work, just don't be a dick. 12 | 13 | Being a dick includes - but is not limited to - the following instances: 14 | 15 | 1a. Outright copyright infringement - Don't just copy this and change the name. 16 | 1b. Selling the unmodified original with no work done what-so-ever, that's REALLY being a dick. 17 | 1c. Modifying the original work to contain hidden harmful content. That would make you a PROPER dick. 18 | 19 | If you become rich through modifications, related works/services, or supporting the original work, share the love. Only a dick would make loads off this work and not buy the original works creator(s) a pint. 20 | 21 | Code is provided with no warranty. Using somebody else's code and bitching when it goes wrong makes you a DONKEY dick. Fix the problem yourself. A non-dick would submit the fix back. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PHP HIVE Tools 2 | ========================= 3 | 4 | A collection of PHP tools to interact with the [Hive](https://github.com/openhive-network/hive) blockchain. **PHP Hive Tools** is in a very early stage. 5 | 6 | Features 7 | -------- 8 | 9 | * cURL and websocket transport layers 10 | * debug mode 11 | * modular design 12 | 13 | Dependencies 14 | ------------ 15 | 16 | Websocket: "textalk/websocket": "1.0.*" (added by default to composer.json). 17 | 18 | Installation 19 | ------------ 20 | 21 | `composer require dragos-roua/php-hive-tools` 22 | 23 | Examples 24 | -------- 25 | 26 | There are a few small examples in the `examples` folder, I will add more as more use cases will appear. 27 | 28 | How to contribute 29 | ----------------- 30 | 31 | Fork this, implement an awesome feature, test it and then submit a pull request. 32 | 33 | 34 | Projects using PHP Hive Tools 35 | ------------------------------ 36 | 37 | * [hive.supply](http://hive.supply) 38 | 39 | 40 | Related Projects 41 | ----------------------------- 42 | 43 | * [php Hive tools](https://github.com/dragosroua/php-steem-tools) - initial release for the Steem blockchain 44 | * [steem.supply](https://steem.supply) 45 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dragos-roua/php-hive-tools", 3 | "description": "Tools to interact with the Hive blockchain.", 4 | "keywords": ["hive", "blockchain", "package"], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Dragos Roua", 9 | "email": "dragosroua@gmail.com" 10 | } 11 | ], 12 | "type": "library", 13 | "require": { 14 | "php": ">=5.4", 15 | "textalk/websocket": "1.0.*" 16 | }, 17 | "require-dev": { 18 | "phpunit/phpunit": "5.2.*" 19 | }, 20 | "autoload": { 21 | "psr-4": { 22 | "DragosRoua\\PHPHiveTools\\": "src/" 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/authorPayments.php: -------------------------------------------------------------------------------- 1 | format('Y-m-d\TH:i:s'); 12 | $date_8days_ago = date('Y-m-d\TH:i:s', strtotime('-8 days', strtotime($dateNow))); 13 | $params = [$author, '', $date_8days_ago, 100]; 14 | 15 | $remote_content = $api->getDiscussionsByAuthorBeforeDate($params, 'websocket'); 16 | //print_r($remote_content); 17 | 18 | if(isset($remote_content)){ 19 | if (array_key_exists('error', $remote_content)){ 20 | echo "Something is not ok. You should investigate more.\n"; 21 | } 22 | else 23 | { 24 | $total_value = 0; 25 | 26 | foreach($remote_content as $rkey => $rvalue){ 27 | if($rvalue['pending_payout_value'] !== '0.000 SBD' && $rvalue['max_accepted_payout'] != 0){ 28 | 29 | $tmp = explode(" ", $rvalue['pending_payout_value']); 30 | $payout = $tmp[0]; 31 | 32 | // check to see if we have something in the beneficaries array 33 | if(count($rvalue['beneficiaries'] != 0)){ 34 | foreach($rvalue['beneficiaries'] as $kk => $vv){ 35 | if($vv['account'] == $author){ 36 | $payout = $payout*($vv['weight']/10000); 37 | } 38 | } 39 | } 40 | $author_payout = $payout * 0.75; 41 | echo "Author payout: ".$author_payout.", Total post payout: ".$payout."\n"; 42 | $total_value += $author_payout; 43 | } 44 | } 45 | echo "Total payout for $author: ".$total_value." (SBD + STEEM)\n"; 46 | } 47 | } 48 | 49 | ?> 50 | -------------------------------------------------------------------------------- /examples/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "minimum-stability" : "dev", 3 | "require": { 4 | "dragos-roua/php-steem-tools": "v0.0.4-alpha" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/composer.phar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dragosroua/php-steem-tools/ff31020397c9786f35a1e0cd971a2a3657aaed25/examples/composer.phar -------------------------------------------------------------------------------- /examples/conversionRate.php: -------------------------------------------------------------------------------- 1 | getFollowerCount($account); 12 | $returned_follower_count = $follower_count['followers']; 13 | $cache_folder = "./"; 14 | $file_name = $cache_folder.$author.".txt"; 15 | $cache_interval = 86400; // seconds for the cache file to live 16 | if(file_exists($file_name)){ 17 | 18 | // if the file was modified less than $cache_interval, we do nothing 19 | 20 | $current_time = time(); 21 | if($current_time - filemtime($file_name) > $cache_interval){ 22 | $follower_count = $api->getFollowerCount($author); 23 | // write to the file again 24 | $handle = fopen($file_name, 'w+') or die('Cannot open file: '.$file_name); 25 | fwrite($handle, "followers|".$follower_count); 26 | fclose($handle); 27 | $returned_follower_count = $follower_count; 28 | } 29 | else { 30 | // get the data from the cache file 31 | $cache_contents = file($file_name); 32 | $first_line = $cache_contents[0]; 33 | $content = explode("|", $first_line); 34 | $returned_follower_count = $content[1]; 35 | } 36 | 37 | } 38 | else { 39 | $follower_count = $api->getFollowerCount($author); 40 | // write the data to cache file 41 | $handle = fopen($file_name, 'w+') or die('Cannot open file: '.$file_name); 42 | fwrite($handle, "followers|".$follower_count); 43 | fclose($handle); 44 | $returned_follower_count = $follower_count; 45 | } 46 | /** 47 | 48 | ** Get content for the last 7 days and calculate the number of votes 49 | 50 | */ 51 | 52 | date_default_timezone_set('UTC'); 53 | $dateNow = (new \DateTime())->format('Y-m-d\TH:i:s'); 54 | $date_8days_ago = date('Y-m-d\TH:i:s', strtotime('-8 days', strtotime($dateNow))); 55 | $params = [$author, '', $date_8days_ago, 100]; 56 | $remote_content = $api->getDiscussionsByAuthorBeforeDate($params, 'websocket'); 57 | //print_r($remote_content); 58 | if(isset($remote_content)){ 59 | if (array_key_exists('error', $remote_content)){ 60 | echo "Something is not ok. You should investigate more.\n"; 61 | } 62 | else 63 | { 64 | $votes_number = array(); 65 | $total_posts = 0; 66 | 67 | foreach($remote_content as $rkey => $rvalue){ 68 | 69 | if($rvalue['pending_payout_value'] !== '0.000 SBD' && $rvalue['max_accepted_payout'] != 0){ 70 | 71 | foreach($rvalue['active_votes'] as $idx => $voter){ 72 | $voter_nickname = $voter['voter']; 73 | 74 | if($voter_nickname != $author){ 75 | 76 | if(array_key_exists($voter['voter'], $votes_number)){ 77 | 78 | $votes_number[$voter['voter']] += 1; 79 | } 80 | else { 81 | 82 | $votes_number[$voter['voter']] = 1; 83 | } 84 | } 85 | } 86 | } 87 | $total_posts++; 88 | } 89 | echo "\n**************\n"; 90 | echo "Total number of posts during the last 7 days: ".$total_posts."\n"; 91 | echo "Total number of voters: ".count($votes_number)." \n"; 92 | echo "Total followers: ".$returned_follower_count."\n"; 93 | 94 | echo "**************\n"; 95 | echo "Engagement rate: ".number_format((count($votes_number) * 100)/$returned_follower_count, 2)."%\n**************\n"; 96 | } 97 | } 98 | ?> 99 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | tests 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/SteemApi.php: -------------------------------------------------------------------------------- 1 | SteemLayer = new SteemLayer($config); 15 | } 16 | 17 | public function getDiscussionsByAuthorBeforeDate($params, $transport='curl'){ 18 | $result = $this->SteemLayer->call('get_discussions_by_author_before_date', $params, $transport); 19 | return $result; 20 | } 21 | 22 | public function getRepliesByLastUpdate($params){ 23 | $result = $this->SteemLayer->call('get_replies_by_last_update', $params); 24 | return $result; 25 | } 26 | 27 | public function getCurrentMedianHistoryPrice($currency = 'STEEM') 28 | { 29 | // TEMP: until I figure this out... 30 | if ($currency == 'STEEM') { 31 | return 0.80; 32 | } 33 | if ($currency == 'SBD') { 34 | return 0.92; 35 | } 36 | $result = $this->SteemLayer->call('get_current_median_history_price'); 37 | $price = 0; 38 | if ($currency == 'STEEM') { 39 | $price = $result['base'] * $result['quote']; 40 | } 41 | if ($currency == 'SBD') { 42 | $price = $result['base'] * $result['quote']; 43 | } 44 | return $price; 45 | } 46 | 47 | public function getContent($params) 48 | { 49 | $result = $this->SteemLayer->call('get_content', $params); 50 | return $result; 51 | } 52 | 53 | public function getContentReplies($params) 54 | { 55 | $result = $this->SteemLayer->call('get_content_replies', $params); 56 | return $result; 57 | } 58 | 59 | public function getDiscussionsByComments($params, $transport='curl') 60 | { 61 | $result = $this->SteemLayer->call('get_discussions_by_comments', $params, $transport); 62 | return $result; 63 | } 64 | 65 | public function getAccountVotes($params) 66 | { 67 | $result = $this->SteemLayer->call('get_account_votes', $params); 68 | return $result; 69 | } 70 | 71 | public function getAccountHistory($params) 72 | { 73 | $result = $this->SteemLayer->call('get_account_history', $params); 74 | return $result; 75 | } 76 | 77 | public function getFollowerCount($account) 78 | { 79 | $followers = $this->getFollowers($account); 80 | return count($followers); 81 | } 82 | public function getFollowers($account, $start = '') 83 | { 84 | $limit = 100; 85 | $followers = array(); 86 | $params = array($this->getFollowAPIID(),'get_followers',array($account,$start,'blog',$limit)); 87 | $followers = $this->SteemLayer->call('call', $params); 88 | if (count($followers) == $limit) { 89 | $last_account = $followers[$limit-1]; 90 | $more_followers = $this->getFollowers($account, $last_account['follower']); 91 | array_pop($followers); 92 | $followers = array_merge($followers, $more_followers); 93 | } 94 | return $followers; 95 | } 96 | 97 | public function lookupAccounts($params) 98 | { 99 | $accounts = $this->SteemLayer->call('lookup_accounts', $params); 100 | return $accounts; 101 | } 102 | 103 | public function getAccounts($accounts) 104 | { 105 | $get_accounts_results = $this->SteemLayer->call('get_accounts', array($accounts)); 106 | return $get_accounts_results; 107 | } 108 | public function getFollowAPIID() 109 | { 110 | return $this->getAPIID('follow_api'); 111 | } 112 | public function getAPIID($api_name) 113 | { 114 | if (array_key_exists($api_name, $this->api_ids)) { 115 | return $this->api_ids[$api_name]; 116 | } 117 | $response = $this->SteemLayer->call('call', array(1,'get_api_by_name',array($api_name))); 118 | $this->api_ids[$api_name] = $response; 119 | return $response; 120 | } 121 | public function cachedCall($call, $params, $serialize = false, $batch = false, $batch_size = 100) 122 | { 123 | $data = @file_get_contents($call . '_data.txt'); 124 | if ($data) { 125 | if ($serialize) { 126 | $data = unserialize($data); 127 | } 128 | return $data; 129 | } 130 | $data = $this->{$call}($params); 131 | if ($serialize) { 132 | $data_for_file = serialize($data); 133 | } else { 134 | $data_for_file = $data; 135 | } 136 | file_put_contents($call . '_data.txt',$data_for_file); 137 | return $data; 138 | 139 | } 140 | 141 | public function getResultInfo($blocks) 142 | { 143 | $max_timestamp = 0; 144 | $min_timestamp = 0; 145 | $max_id = 0; 146 | $min_id = 0; 147 | foreach($blocks as $block) { 148 | $timestamp = strtotime($block[1]['timestamp']); 149 | if ($timestamp >= $max_timestamp) { 150 | $max_timestamp = $timestamp; 151 | $max_id = $block[0]; 152 | } 153 | if (!$min_timestamp) { 154 | $min_timestamp = $max_timestamp; 155 | } 156 | if ($timestamp <= $min_timestamp) { 157 | $min_timestamp = $timestamp; 158 | $min_id = $block[0]; 159 | } 160 | } 161 | return array( 162 | 'max_id' => $max_id, 163 | 'max_timestamp' => $max_timestamp, 164 | 'min_id' => $min_id, 165 | 'min_timestamp' => $min_timestamp 166 | ); 167 | } 168 | public function getAccountHistoryFiltered($account, $types, $start, $end) 169 | { 170 | $start_timestamp = strtotime($start); 171 | $end_timestamp = strtotime($end); 172 | $limit = 2000; 173 | $params = array($account, -1, $limit); 174 | $result = $this->getAccountHistory($params); 175 | $info = $this->getResultInfo($result); 176 | $filtered_results = $this->filterAccountHistory($result,$start_timestamp,$end_timestamp,$types); 177 | while ($start_timestamp < $info['min_timestamp']) { 178 | $from = $info['min_id']; 179 | if ($limit > $from) { 180 | $limit = $from; 181 | } 182 | $params = array($account, $info['min_id'], $limit); 183 | $result = $this->getAccountHistory($params); 184 | $filtered_results = array_merge( 185 | $filtered_results, 186 | $this->filterAccountHistory($result,$start_timestamp,$end_timestamp,$types) 187 | ); 188 | $info = $this->getResultInfo($result); 189 | } 190 | return $filtered_results; 191 | } 192 | public function filterAccountHistory($result, $start_timestamp, $end_timestamp, $ops) 193 | { 194 | $filtered_results = array(); 195 | if (count($result)) { 196 | foreach($result as $block) { 197 | $timestamp = strtotime($block[1]['timestamp']); 198 | if (in_array($block[1]['op'][0], $ops) 199 | && $timestamp >= $start_timestamp 200 | && $timestamp <= $end_timestamp 201 | ) { 202 | $filtered_results[] = $block; 203 | } 204 | } 205 | } 206 | return $filtered_results; 207 | } 208 | public function getOpData($result) 209 | { 210 | $data = array(); 211 | foreach($result as $block) { 212 | $data[] = $block[1]['op'][1]; 213 | } 214 | return $data; 215 | } 216 | private $dynamic_global_properties = array(); 217 | 218 | public function getProps($refresh = false) 219 | { 220 | if ($refresh || count($this->dynamic_global_properties) == 0) { 221 | $this->dynamic_global_properties = $this->SteemLayer->call('get_dynamic_global_properties', array()); 222 | } 223 | return $this->dynamic_global_properties; 224 | } 225 | 226 | public function getConversionRate() { 227 | $props = $this->getProps(); 228 | $values = array( 229 | 'total_vests' => (float) $props['total_vesting_shares'], 230 | 'total_vest_steem' => (float) $props['total_vesting_fund_steem'], 231 | ); 232 | return $values; 233 | } 234 | 235 | public function vest2sp($value) 236 | { 237 | $values = $this->getConversionRate(); 238 | return round($values['total_vest_steem'] * ($value / $values['total_vests']), 3); 239 | } 240 | 241 | /* exchange related functions */ 242 | 243 | public function getCurrentValue($coin){ 244 | // calls CoinMarketCap Api and returns the current curse 245 | $url = "https://api.coinmarketcap.com/v1/ticker/".$coin."/"; 246 | 247 | $ch = curl_init(); 248 | curl_setopt($ch, CURLOPT_URL, $url); 249 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 250 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 251 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true ); 252 | curl_setopt($ch, CURLOPT_ENCODING, "gzip,deflate"); 253 | $response = curl_exec($ch); 254 | curl_close($ch); 255 | return $response; 256 | } 257 | 258 | public function getUserJSONData($user){ 259 | // calls CoinMarketCap Api and returns the current curse 260 | $url = "https://steemit.com/@".$user.".json"; 261 | 262 | $ch = curl_init(); 263 | curl_setopt($ch, CURLOPT_URL, $url); 264 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 265 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 266 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true ); 267 | curl_setopt($ch, CURLOPT_ENCODING, "gzip,deflate"); 268 | $response = curl_exec($ch); 269 | curl_close($ch); 270 | return $response; 271 | } 272 | 273 | 274 | // Contributions by @profchydon 275 | // Getting this tool up to date with all available methods on api.steemjs documentation 276 | 277 | public function setSubscribeCallback ($params) 278 | { 279 | $result = $this->SteemLayer->call('set_subscribe_callback', $params); 280 | return $result; 281 | } 282 | 283 | public function setPendingTransactionCallback ($params) 284 | { 285 | $result = $this->SteemLayer->call('set_pending_transaction_callback', $params); 286 | return $result; 287 | } 288 | 289 | public function setBlockAppliedCallback ($params) 290 | { 291 | $result = $this->SteemLayer->call('set_block_applied_callback', $params); 292 | return $result; 293 | } 294 | 295 | public function cancelAllSubscriptions ($params) 296 | { 297 | $result = $this->SteemLayer->call('cancel_all_subscriptions', $params); 298 | return $result; 299 | } 300 | 301 | public function getTrendingTags ($params) 302 | { 303 | $result = $this->SteemLayer->call('get_trending_tags', $params); 304 | return $result; 305 | } 306 | 307 | public function getTagsUsedByAuthor ($params) 308 | { 309 | $result = $this->SteemLayer->call('get_tags_used_by_author', $params); 310 | return $result; 311 | } 312 | 313 | public function getPostDiscussionsByPayout ($params) 314 | { 315 | $result = $this->SteemLayer->call('get_post_discussions_by_payout', $params); 316 | return $result; 317 | } 318 | 319 | public function getCommentDiscussionsByPayout ($params) 320 | { 321 | $result = $this->SteemLayer->call('get_comment_discussions_by_payout', $params); 322 | return $result; 323 | } 324 | 325 | public function getDiscussionsByTrending ($params) 326 | { 327 | $result = $this->SteemLayer->call('get_discussions_by_trending', $params); 328 | return $result; 329 | } 330 | 331 | public function getDiscussionsByTrending30 ($params) 332 | { 333 | $result = $this->SteemLayer->call('get_discussions_by_trending30', $params); 334 | return $result; 335 | } 336 | 337 | public function getDiscussionsByCreated ($params) 338 | { 339 | $result = $this->SteemLayer->call('get_discussions_by_created', $params); 340 | return $result; 341 | } 342 | 343 | public function getDiscussionsByActive ($params) 344 | { 345 | $result = $this->SteemLayer->call('get_discussions_by_active', $params); 346 | return $result; 347 | } 348 | 349 | public function getDiscussionsByCashout ($params) 350 | { 351 | $result = $this->SteemLayer->call('get_discussions_by_cashout', $params); 352 | return $result; 353 | } 354 | 355 | public function getDiscussionsByPayout ($params) 356 | { 357 | $result = $this->SteemLayer->call('get_discussions_by_payout', $params); 358 | return $result; 359 | } 360 | 361 | public function getDiscussionsByVotes ($params) 362 | { 363 | $result = $this->SteemLayer->call('get_discussions_by_votes', $params); 364 | return $result; 365 | } 366 | 367 | public function getDiscussionsByChildren ($params) 368 | { 369 | $result = $this->SteemLayer->call('get_discussions_by_children', $params); 370 | return $result; 371 | } 372 | 373 | public function getDiscussionsByHot ($params) 374 | { 375 | $result = $this->SteemLayer->call('get_post_discussions_by_hot', $params); 376 | return $result; 377 | } 378 | 379 | public function getDiscussionsByFeed ($params) 380 | { 381 | $result = $this->SteemLayer->call('get_discussions_by_feed', $params); 382 | return $result; 383 | } 384 | 385 | public function getDiscussionsByBlog ($params) 386 | { 387 | $result = $this->SteemLayer->call('get_discussions_by_blog', $params); 388 | return $result; 389 | } 390 | 391 | public function getDiscussionsByPromoted ($params) 392 | { 393 | $result = $this->SteemLayer->call('get_discussions_by_promoted', $params); 394 | return $result; 395 | } 396 | 397 | public function getBlockHeader ($params) 398 | { 399 | $result = $this->SteemLayer->call('get_block_header', $params); 400 | return $result; 401 | } 402 | 403 | public function getBlock ($params) 404 | { 405 | $result = $this->SteemLayer->call('get_block', $params); 406 | return $result; 407 | } 408 | 409 | public function getOpsInBlock ($params) 410 | { 411 | $result = $this->SteemLayer->call('get_ops_in_block', $params); 412 | return $result; 413 | } 414 | 415 | public function getState ($params) 416 | { 417 | $result = $this->SteemLayer->call('get_state', $params); 418 | return $result; 419 | } 420 | 421 | public function getTrendingCategories ($params) 422 | { 423 | $result = $this->SteemLayer->call('get_trending_categories', $params); 424 | return $result; 425 | } 426 | 427 | public function getBestCategories ($params) 428 | { 429 | $result = $this->SteemLayer->call('get_best_categories', $params); 430 | return $result; 431 | } 432 | 433 | public function getActiveCategories ($params) 434 | { 435 | $result = $this->SteemLayer->call('get_active_categories', $params); 436 | return $result; 437 | } 438 | 439 | public function getRecentCategories ($params) 440 | { 441 | $result = $this->SteemLayer->call('get_recent_categories', $params); 442 | return $result; 443 | } 444 | 445 | public function getConfig ($params) 446 | { 447 | $result = $this->SteemLayer->call('get_config', $params); 448 | return $result; 449 | } 450 | 451 | public function getDynamicGlobalProperties ($params) 452 | { 453 | $result = $this->SteemLayer->call('get_dynamic_global_properties', $params); 454 | return $result; 455 | } 456 | 457 | public function getChainProperties ($params) 458 | { 459 | $result = $this->SteemLayer->call('get_chain_properties', $params); 460 | return $result; 461 | } 462 | 463 | public function getFeedHistory ($params) 464 | { 465 | $result = $this->SteemLayer->call('get_feed_history', $params); 466 | return $result; 467 | } 468 | 469 | public function getWitnessSchedule ($params) 470 | { 471 | $result = $this->SteemLayer->call('get_witness_schedule', $params); 472 | return $result; 473 | } 474 | 475 | public function getHardforkVersion ($params) 476 | { 477 | $result = $this->SteemLayer->call('get_hardfork_version', $params); 478 | return $result; 479 | } 480 | 481 | public function getNextScheduledHardfork ($params) 482 | { 483 | $result = $this->SteemLayer->call('get_next_scheduled_hardfork', $params); 484 | return $result; 485 | } 486 | 487 | public function getKeyReferences ($params) 488 | { 489 | $result = $this->SteemLayer->call('get_key_references', $params); 490 | return $result; 491 | } 492 | 493 | public function getAccountReferences ($params) 494 | { 495 | $result = $this->SteemLayer->call('get_account_references', $params); 496 | return $result; 497 | } 498 | 499 | public function lookupAccountNames ($params) 500 | { 501 | $result = $this->SteemLayer->call('lookup_account_names', $params); 502 | return $result; 503 | } 504 | 505 | // start here 506 | 507 | public function getAccountCount ($params) 508 | { 509 | $result = $this->SteemLayer->call('get_account_count', $params); 510 | return $result; 511 | } 512 | 513 | public function getConversionRequests ($params) 514 | { 515 | $result = $this->SteemLayer->call('get_conversion_requests', $params); 516 | return $result; 517 | } 518 | 519 | public function getOwnerHistory ($params) 520 | { 521 | $result = $this->SteemLayer->call('get_owner_history', $params); 522 | return $result; 523 | } 524 | 525 | public function getRecoveryRequest ($params) 526 | { 527 | $result = $this->SteemLayer->call('get_recovery_request', $params); 528 | return $result; 529 | } 530 | 531 | public function getEscrow ($params) 532 | { 533 | $result = $this->SteemLayer->call('get_escrow', $params); 534 | return $result; 535 | } 536 | 537 | public function getWithdrawRoutes ($params) 538 | { 539 | $result = $this->SteemLayer->call('get_withdraw_routes', $params); 540 | return $result; 541 | } 542 | 543 | public function getAccountBandwidth ($params) 544 | { 545 | $result = $this->SteemLayer->call('get_account_bandwidth', $params); 546 | return $result; 547 | } 548 | 549 | public function getSavingsWithdrawFrom ($params) 550 | { 551 | $result = $this->SteemLayer->call('get_savings_withdraw_from', $params); 552 | return $result; 553 | } 554 | 555 | public function getSavingsWithdrawTo ($params) 556 | { 557 | $result = $this->SteemLayer->call('get_savings_withdraw_to', $params); 558 | return $result; 559 | } 560 | 561 | public function getOrderBook ($params) 562 | { 563 | $result = $this->SteemLayer->call('get_order_book', $params); 564 | return $result; 565 | } 566 | 567 | public function getOpenOrders ($params) 568 | { 569 | $result = $this->SteemLayer->call('get_open_orders', $params); 570 | return $result; 571 | } 572 | 573 | public function getLiquidityQueue ($params) 574 | { 575 | $result = $this->SteemLayer->call('get_liquidity_queue', $params); 576 | return $result; 577 | } 578 | 579 | public function getTransactionHex ($params) 580 | { 581 | $result = $this->SteemLayer->call('get_transaction_hex', $params); 582 | return $result; 583 | } 584 | 585 | public function getTransaction ($params) 586 | { 587 | $result = $this->SteemLayer->call('get_transaction', $params); 588 | return $result; 589 | } 590 | 591 | public function getRequiredSignatures ($params) 592 | { 593 | $result = $this->SteemLayer->call('get_required_signatures', $params); 594 | return $result; 595 | } 596 | 597 | public function getPotentialSignatures ($params) 598 | { 599 | $result = $this->SteemLayer->call('get_potential_signatures', $params); 600 | return $result; 601 | } 602 | 603 | public function verifyAuthority ($params) 604 | { 605 | $result = $this->SteemLayer->call('verify_authority', $params); 606 | return $result; 607 | } 608 | 609 | public function verifyAccountAuthority ($params) 610 | { 611 | $result = $this->SteemLayer->call('verify_account_authority', $params); 612 | return $result; 613 | } 614 | 615 | public function getActiveVotes ($params) 616 | { 617 | $result = $this->SteemLayer->call('get_active_votes', $params); 618 | return $result; 619 | } 620 | 621 | public function getWitnesses ($params) 622 | { 623 | $result = $this->SteemLayer->call('get_witnesses', $params); 624 | return $result; 625 | } 626 | 627 | public function getWitnessByAccount ($params) 628 | { 629 | $result = $this->SteemLayer->call('get_witness_by_account', $params); 630 | return $result; 631 | } 632 | 633 | public function getWitnessesByVote ($params) 634 | { 635 | $result = $this->SteemLayer->call('get_witnesses_by_vote', $params); 636 | return $result; 637 | } 638 | 639 | public function lookupWitnessAccounts ($params) 640 | { 641 | $result = $this->SteemLayer->call('lookup_witness_accounts', $params); 642 | return $result; 643 | } 644 | 645 | public function getWitnessCount ($params) 646 | { 647 | $result = $this->SteemLayer->call('get_witness_count', $params); 648 | return $result; 649 | } 650 | 651 | public function getActiveWitnesses ($params) 652 | { 653 | $result = $this->SteemLayer->call('get_active_witnesses', $params); 654 | return $result; 655 | } 656 | 657 | public function getMinerQueue ($params) 658 | { 659 | $result = $this->SteemLayer->call('get_miner_queue', $params); 660 | return $result; 661 | } 662 | 663 | public function getRewardFund ($params) 664 | { 665 | $result = $this->SteemLayer->call('get_reward_fund', $params); 666 | return $result; 667 | } 668 | 669 | public function getVestingDelegations ($params) 670 | { 671 | $result = $this->SteemLayer->call('get_vesting_delegations', $params); 672 | return $result; 673 | } 674 | 675 | public function login ($params) 676 | { 677 | $result = $this->SteemLayer->call('login', $params); 678 | return $result; 679 | } 680 | 681 | public function getApiByName ($params) 682 | { 683 | $result = $this->SteemLayer->call('get_api_by_name', $params); 684 | return $result; 685 | } 686 | 687 | public function getVersion ($params) 688 | { 689 | $result = $this->SteemLayer->call('get_version', $params); 690 | return $result; 691 | } 692 | 693 | public function getFollowing ($params) 694 | { 695 | $result = $this->SteemLayer->call('get_following', $params); 696 | return $result; 697 | } 698 | 699 | public function getFollowCount ($params) 700 | { 701 | $result = $this->SteemLayer->call('get_follow_count', $params); 702 | return $result; 703 | } 704 | 705 | public function getFeedEntries ($params) 706 | { 707 | $result = $this->SteemLayer->call('get_feed_entries', $params); 708 | return $result; 709 | } 710 | 711 | public function getFeed ($params) 712 | { 713 | $result = $this->SteemLayer->call('get_feed', $params); 714 | return $result; 715 | } 716 | 717 | public function getBlogEntries ($params) 718 | { 719 | $result = $this->SteemLayer->call('get_blog_entries', $params); 720 | return $result; 721 | } 722 | 723 | public function getBlog ($params) 724 | { 725 | $result = $this->SteemLayer->call('get_blog', $params); 726 | return $result; 727 | } 728 | 729 | public function getAccountReputations ($params) 730 | { 731 | $result = $this->SteemLayer->call('get_account_reputations', $params); 732 | return $result; 733 | } 734 | 735 | public function getRebloggedBy ($params) 736 | { 737 | $result = $this->SteemLayer->call('get_reblogged_by', $params); 738 | return $result; 739 | } 740 | 741 | public function getBlogAuthors ($params) 742 | { 743 | $result = $this->SteemLayer->call('get_blog_authors', $params); 744 | return $result; 745 | } 746 | 747 | public function broadcastTransaction ($params) 748 | { 749 | $result = $this->SteemLayer->call('broadcast_transaction', $params); 750 | return $result; 751 | } 752 | 753 | public function broadcastTransactionWithCallback ($params) 754 | { 755 | $result = $this->SteemLayer->call('broadcast_transaction_with_callback', $params); 756 | return $result; 757 | } 758 | 759 | public function broadcastTransactionSynchronous ($params) 760 | { 761 | $result = $this->SteemLayer->call('broadcast_transaction_synchronous', $params); 762 | return $result; 763 | } 764 | 765 | public function broadcastBlock ($params) 766 | { 767 | $result = $this->SteemLayer->call('broadcast_block', $params); 768 | return $result; 769 | } 770 | 771 | public function setMaxBlockAge ($params) 772 | { 773 | $result = $this->SteemLayer->call('set_max_block_age', $params); 774 | return $result; 775 | } 776 | 777 | public function getTicker ($params) 778 | { 779 | $result = $this->SteemLayer->call('get_ticker', $params); 780 | return $result; 781 | } 782 | 783 | public function getVolume ($params) 784 | { 785 | $result = $this->SteemLayer->call('get_volume', $params); 786 | return $result; 787 | } 788 | 789 | public function getTradeHistory ($params) 790 | { 791 | $result = $this->SteemLayer->call('get_trade_history', $params); 792 | return $result; 793 | } 794 | 795 | public function getRecentTrades ($params) 796 | { 797 | $result = $this->SteemLayer->call('get_recent_trades', $params); 798 | return $result; 799 | } 800 | 801 | public function getMarketHistory ($params) 802 | { 803 | $result = $this->SteemLayer->call('get_market_history', $params); 804 | return $result; 805 | } 806 | 807 | public function getMarketHistoryBuckets ($params) 808 | { 809 | $result = $this->SteemLayer->call('get_market_history_buckets', $params); 810 | return $result; 811 | } 812 | 813 | // Broadcast Methods 814 | public function vote ($params) 815 | { 816 | $result = $this->SteemLayer->call('vote', $params); 817 | return $result; 818 | } 819 | 820 | public function comment ($params) 821 | { 822 | $result = $this->SteemLayer->call('comment', $params); 823 | return $result; 824 | } 825 | 826 | public function transfer ($params) 827 | { 828 | $result = $this->SteemLayer->call('transfer', $params); 829 | return $result; 830 | } 831 | 832 | public function transferToVesting ($params) 833 | { 834 | $result = $this->SteemLayer->call('transfer_to_vesting', $params); 835 | return $result; 836 | } 837 | 838 | public function withdrawVesting ($params) 839 | { 840 | $result = $this->SteemLayer->call('withdraw_vesting', $params); 841 | return $result; 842 | } 843 | 844 | public function limitOrderCreate ($params) 845 | { 846 | $result = $this->SteemLayer->call('limit_order_create', $params); 847 | return $result; 848 | } 849 | 850 | public function limitOrderCancel ($params) 851 | { 852 | $result = $this->SteemLayer->call('limit_order_cancel', $params); 853 | return $result; 854 | } 855 | 856 | public function price ($params) 857 | { 858 | $result = $this->SteemLayer->call('price', $params); 859 | return $result; 860 | } 861 | 862 | public function feedPublish ($params) 863 | { 864 | $result = $this->SteemLayer->call('feed_publish', $params); 865 | return $result; 866 | } 867 | 868 | public function convert ($params) 869 | { 870 | $result = $this->SteemLayer->call('convert', $params); 871 | return $result; 872 | } 873 | 874 | public function accountCreate ($params) 875 | { 876 | $result = $this->SteemLayer->call('account_create', $params); 877 | return $result; 878 | } 879 | 880 | public function accountUpdate ($params) 881 | { 882 | $result = $this->SteemLayer->call('account_update', $params); 883 | return $result; 884 | } 885 | 886 | public function witnessUpdate ($params) 887 | { 888 | $result = $this->SteemLayer->call('witness_update', $params); 889 | return $result; 890 | } 891 | 892 | public function accountWitnessVote ($params) 893 | { 894 | $result = $this->SteemLayer->call('account_witness_vote', $params); 895 | return $result; 896 | } 897 | 898 | public function accountWitnessProxy ($params) 899 | { 900 | $result = $this->SteemLayer->call('account_witness_proxy', $params); 901 | return $result; 902 | } 903 | 904 | public function pow ($params) 905 | { 906 | $result = $this->SteemLayer->call('pow', $params); 907 | return $result; 908 | } 909 | 910 | public function custom ($params) 911 | { 912 | $result = $this->SteemLayer->call('custom', $params); 913 | return $result; 914 | } 915 | 916 | public function deleteComment ($params) 917 | { 918 | $result = $this->SteemLayer->call('delete_comment', $params); 919 | return $result; 920 | } 921 | 922 | public function customJson ($params) 923 | { 924 | $result = $this->SteemLayer->call('custom_json', $params); 925 | return $result; 926 | } 927 | 928 | public function commentOptions ($params) 929 | { 930 | $result = $this->SteemLayer->call('comment_options', $params); 931 | return $result; 932 | } 933 | 934 | public function setWithdrawVestingRoute ($params) 935 | { 936 | $result = $this->SteemLayer->call('set_withdraw_vesting_route', $params); 937 | return $result; 938 | } 939 | 940 | public function limitOrderCreate2 ($params) 941 | { 942 | $result = $this->SteemLayer->call('limit_order_create2', $params); 943 | return $result; 944 | } 945 | 946 | public function challengeAuthority ($params) 947 | { 948 | $result = $this->SteemLayer->call('challenge_authority', $params); 949 | return $result; 950 | } 951 | 952 | public function proveAuthority ($params) 953 | { 954 | $result = $this->SteemLayer->call('prove_authority', $params); 955 | return $result; 956 | } 957 | 958 | public function requestAccountRecovery ($params) 959 | { 960 | $result = $this->SteemLayer->call('request_account_recovery', $params); 961 | return $result; 962 | } 963 | 964 | public function recoverAccount ($params) 965 | { 966 | $result = $this->SteemLayer->call('recover_account', $params); 967 | return $result; 968 | } 969 | 970 | public function changeRecoveryAccount ($params) 971 | { 972 | $result = $this->SteemLayer->call('change_recovery_account', $params); 973 | return $result; 974 | } 975 | 976 | public function escrowTransfer ($params) 977 | { 978 | $result = $this->SteemLayer->call('escrow_transfer', $params); 979 | return $result; 980 | } 981 | 982 | public function escrowDispute ($params) 983 | { 984 | $result = $this->SteemLayer->call('escrow_dispute', $params); 985 | return $result; 986 | } 987 | 988 | public function escrowRelease ($params) 989 | { 990 | $result = $this->SteemLayer->call('escrow_release', $params); 991 | return $result; 992 | } 993 | 994 | public function pow2 ($params) 995 | { 996 | $result = $this->SteemLayer->call('pow2', $params); 997 | return $result; 998 | } 999 | 1000 | public function escrowApprove ($params) 1001 | { 1002 | $result = $this->SteemLayer->call('escrow_approve', $params); 1003 | return $result; 1004 | } 1005 | 1006 | public function transferToSavings ($params) 1007 | { 1008 | $result = $this->SteemLayer->call('transfer_to_savings', $params); 1009 | return $result; 1010 | } 1011 | 1012 | public function transferFromSavings ($params) 1013 | { 1014 | $result = $this->SteemLayer->call('transfer_from_savings', $params); 1015 | return $result; 1016 | } 1017 | 1018 | public function cancelTransferFromSavings ($params) 1019 | { 1020 | $result = $this->SteemLayer->call('cancel_transfer_from_savings', $params); 1021 | return $result; 1022 | } 1023 | 1024 | public function customBinary ($params) 1025 | { 1026 | $result = $this->SteemLayer->call('custom_binary', $params); 1027 | return $result; 1028 | } 1029 | 1030 | public function declineVotingRights ($params) 1031 | { 1032 | $result = $this->SteemLayer->call('decline_voting_rights', $params); 1033 | return $result; 1034 | } 1035 | 1036 | public function resetAccount ($params) 1037 | { 1038 | $result = $this->SteemLayer->call('reset_account', $params); 1039 | return $result; 1040 | } 1041 | 1042 | public function setResetAccount ($params) 1043 | { 1044 | $result = $this->SteemLayer->call('set_reset_account', $params); 1045 | return $result; 1046 | } 1047 | 1048 | public function claimRewardBalance ($params) 1049 | { 1050 | $result = $this->SteemLayer->call('claim_reward_balance', $params); 1051 | return $result; 1052 | } 1053 | 1054 | public function delegateVestingShares ($params) 1055 | { 1056 | $result = $this->SteemLayer->call('delegate_vesting_shares', $params); 1057 | return $result; 1058 | } 1059 | 1060 | public function accountCreateWithDelegation ($params) 1061 | { 1062 | $result = $this->SteemLayer->call('account_create_with_delegation', $params); 1063 | return $result; 1064 | } 1065 | 1066 | public function fillConvertRequest ($params) 1067 | { 1068 | $result = $this->SteemLayer->call('fill_convert_request', $params); 1069 | return $result; 1070 | } 1071 | 1072 | public function commentReward ($params) 1073 | { 1074 | $result = $this->SteemLayer->call('comment_reward', $params); 1075 | return $result; 1076 | } 1077 | 1078 | public function liquidityReward ($params) 1079 | { 1080 | $result = $this->SteemLayer->call('liquidity_reward', $params); 1081 | return $result; 1082 | } 1083 | 1084 | public function interest ($params) 1085 | { 1086 | $result = $this->SteemLayer->call('interest', $params); 1087 | return $result; 1088 | } 1089 | 1090 | public function fillVestingWithdraw ($params) 1091 | { 1092 | $result = $this->SteemLayer->call('fill_vesting_withdraw', $params); 1093 | return $result; 1094 | } 1095 | 1096 | public function fillOrder ($params) 1097 | { 1098 | $result = $this->SteemLayer->call('fill_order', $params); 1099 | return $result; 1100 | } 1101 | 1102 | public function fillTransferFromSavings ($params) 1103 | { 1104 | $result = $this->SteemLayer->call('fill_transfer_from_savings', $params); 1105 | return $result; 1106 | } 1107 | 1108 | // Resource Credit APIs 1109 | 1110 | public function findRCAccounts ($params) 1111 | { 1112 | $result = $this->SteemLayer->call('rc.find_rc_accounts', $params); 1113 | return $result; 1114 | } 1115 | 1116 | public function getResourcePools ($params) 1117 | { 1118 | $result = $this->SteemLayer->call('rc.get_resource_pools', $params); 1119 | return $result; 1120 | } 1121 | 1122 | public function getResourceParams ($params) 1123 | { 1124 | $result = $this->SteemLayer->call('rc.get_resource_params', $params); 1125 | return $result; 1126 | } 1127 | 1128 | } 1129 | -------------------------------------------------------------------------------- /src/SteemLayer.php: -------------------------------------------------------------------------------- 1 | debug = $config['debug']; 27 | } 28 | if (array_key_exists('webservice_url', $config)) { 29 | $this->webservice_url = $config['webservice_url']; 30 | } 31 | if (array_key_exists('throw_exception', $config)) { 32 | $this->throw_exception = $config['throw_exception']; 33 | } 34 | } 35 | 36 | public function call($method, $params = array(), $transport='curl') { 37 | $request = $this->getRequest($method, $params); 38 | $response = ''; 39 | if($transport == 'curl'){ 40 | $response = $this->curl($request); 41 | } 42 | else if($transport == 'websocket'){ 43 | $response = $this->websocket($request); 44 | } 45 | if (array_key_exists('error', $response)) { 46 | if ($this->throw_exception) { 47 | throw new Exception($response['error']); 48 | } else { 49 | return $response; 50 | } 51 | } 52 | return $response['result']; 53 | } 54 | 55 | public function getRequest($method, $params) { 56 | $request = array( 57 | "jsonrpc" => "2.0", 58 | "method" => $method, 59 | "params" => $params, 60 | "id" => 0 61 | ); 62 | 63 | $request_json = json_encode($request); 64 | 65 | if ($this->debug) { 66 | echo "

request_json
"; 67 | print $request_json . "\n"; 68 | echo "
"; 69 | } 70 | return $request_json; 71 | } 72 | 73 | public function curl($data) { 74 | $ch = curl_init(); 75 | $this->scheme = 'https://'; 76 | curl_setopt($ch, CURLOPT_URL, $this->scheme.$this->webservice_url); 77 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 78 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 79 | $result = curl_exec($ch); 80 | 81 | if ($this->debug) { 82 | echo "

result
"; 83 | print $result . "\n"; 84 | echo "
"; 85 | } 86 | 87 | $result = json_decode($result, true); 88 | 89 | return $result; 90 | } 91 | 92 | public function websocket($data){ 93 | $this->scheme = 'wss://'; 94 | $client = new Client($this->scheme.$this->webservice_url); 95 | $client->send($data); 96 | $result = $client->receive(); 97 | if ($this->debug) { 98 | echo "

result
"; 99 | print $result . "\n"; 100 | echo "
"; 101 | } 102 | 103 | $result = json_decode($result, true); 104 | 105 | return $result; 106 | } 107 | 108 | } -------------------------------------------------------------------------------- /tests/SteemApiTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(is_object($var)); 23 | unset($var); 24 | } 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /tests/SteemLayerTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(is_object($var)); 23 | unset($var); 24 | } 25 | 26 | /** 27 | * Just check if the YourClass has no syntax error 28 | * 29 | * This is just a simple check to make sure your library has no syntax error. This helps you troubleshoot 30 | * any typo before you even use this library in a real project. 31 | * 32 | */ 33 | 34 | public function testgetRequest(){ 35 | $var = new DragosRoua\PHPSteemTools\SteemLayer; 36 | $method = 'method'; 37 | $params = 'params'; 38 | $request = array( 39 | "jsonrpc" => "2.0", 40 | "method" => $method, 41 | "params" => $params, 42 | "id" => 0 43 | ); 44 | $request_json = json_encode($request); 45 | $this->assertTrue($var->getRequest('method','params') == $request_json); 46 | unset($var); 47 | } 48 | 49 | } --------------------------------------------------------------------------------