From a4c61f3bc3b8dc95632b56ca2838fc88b7483333 Mon Sep 17 00:00:00 2001 From: DavidKevork Date: Mon, 24 Jul 2017 17:27:23 +1000 Subject: [PATCH] SteemBlock and SteemMarket added --- src/SteemPHP/SteemArticle.php | 4 +- src/SteemPHP/SteemBlock.php | 351 +++++++++++++++++++++++++++++++ src/SteemPHP/SteemChain.php | 2 +- src/SteemPHP/SteemConnection.php | 23 ++ src/SteemPHP/SteemMarket.php | 122 +++++++++++ src/SteemPHP/SteemWitness.php | 2 +- 6 files changed, 500 insertions(+), 4 deletions(-) create mode 100644 src/SteemPHP/SteemBlock.php create mode 100644 src/SteemPHP/SteemMarket.php diff --git a/src/SteemPHP/SteemArticle.php b/src/SteemPHP/SteemArticle.php index 091f3e6..2426486 100644 --- a/src/SteemPHP/SteemArticle.php +++ b/src/SteemPHP/SteemArticle.php @@ -7,7 +7,7 @@ use SteemPHP\SteemHelper; /** -* SteemConnection +* SteemArticle * * This Class contains functions for fetching articles from steeemit blockchain */ @@ -32,7 +32,7 @@ class SteemArticle * Initialize the connection to the host * @param String $host * - * $host = ['https://node.steem.ws', 'https://steemd.steemit.com'] + * $host = ['https://steemd.steemitdev.com', 'https://steemd.steemit.com'] */ public function __construct($host = 'https://steemd.steemit.com') { diff --git a/src/SteemPHP/SteemBlock.php b/src/SteemPHP/SteemBlock.php new file mode 100644 index 0000000..ce4481f --- /dev/null +++ b/src/SteemPHP/SteemBlock.php @@ -0,0 +1,351 @@ +host = trim($host); + $this->httpClient = new HttpClient($this->host); + $this->httpClient->withoutSslVerification(); + $this->client = new Client($this->host, false, $this->httpClient); + } + + /** + * Get Api number + * @param String $name + * @return int + */ + public function getApi($name) + { + try { + return $this->client->call(1, 'get_api_by_name', [$name]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + /** + * Get Block by block number + * @param int $blockNumber + * @return array + */ + public function getBlock($blockNumber) + { + try { + $this->api = $this->getApi('database_api'); + return $this->client->call($this->api, 'get_block', [SteemHelper::filterInt($blockNumber)]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + /** + * Get Block header by block number + * @param int $blockNumber + * @return array + */ + public function getBlockHeader($blockNumber) + { + try { + $this->api = $this->getApi('database_api'); + return $this->client->call($this->api, 'get_block_header', [SteemHelper::filterInt($blockNumber)]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + /** + * Get Block header by block number + * @param int $blockNumber + * @param boolean $onlyVirtual + * @return array + */ + public function getOpsInBlock($blockNumber, $onlyVirtual = false) + { + try { + $this->api = $this->getApi('database_api'); + return $this->client->call($this->api, 'get_ops_in_block', [SteemHelper::filterInt($blockNumber), $onlyVirtual]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + /** + * Get Transaction Hex from a transaction + * std::string get_transaction_hex(const signed_transaction& trx)const; + * @param string $trx + * @return array + */ + public function getTransactionHex($trx) + { + try { + $this->api = $this->getApi('database_api'); + return $this->client->call($this->api, 'get_transaction_hex', [$trx]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + /** + * Get transaction by transaction id + * annotated_signed_transaction database_api::get_transaction( transaction_id_type id )const + * @param string $trx_id + * @return array + */ + public function getTransaction($trx_id) + { + try { + $this->api = $this->getApi('database_api'); + return $this->client->call($this->api, 'get_transaction', [$trx_id]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + /** + * set get_required_signatures( const signed_transaction& trx, const flat_set& available_keys )const; + * @param signed_transaction $trx + * @param flat_set $availableKeys + * @return array + */ + public function getRequiredSignatures($trx, $availableKeys) + { + try { + $this->api = $this->getApi('database_api'); + return $this->client->call($this->api, 'get_required_signatures', [$trx, $availableKeys]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + /** + * set get_potential_signatures( const signed_transaction& trx )const; + * @param signed_transaction $trx + * @return array + */ + public function getPotentialSignatures($trx) + { + try { + $this->api = $this->getApi('database_api'); + return $this->client->call($this->api, 'get_potential_signatures', [$trx]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + /** + * bool verify_authority( const signed_transaction& trx )const; + * @param signed_transaction $trx + * @return array on failure - boolean if successful + */ + public function verifyAuthority($trx) + { + try { + $this->api = $this->getApi('database_api'); + return $this->client->call($this->api, 'verify_authority', [$trx]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + /** + * bool verify_account_authority( const string& name_or_id, const flat_set& signers )const; + * @param string $NameOrId + * @param flat_set $singers + * @return array on failure - boolean if successful + */ + public function verifyAccountAuthority($NameOrId, $singers) + { + try { + $this->api = $this->getApi('account_by_key_api'); + return $this->client->call($this->api, 'verify_account_authority', [$NameOrId, $singers]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + /** + * vector> get_key_references( vector key )const; + * @param vector $key + * @return array + */ + public function getKeyReferences($key) + { + if (!is_array($key)) { + $this->key[] = $key; + } else { + $this->key = $key; + } + try { + $this->api = $this->getApi('account_by_key_api'); + return $this->client->call($this->api, 'get_key_references', [$this->key]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + /** + * @brief Broadcast a transaction to the network + * @param trx The transaction to broadcast + * + * The transaction will be checked for validity in the local database prior to broadcasting. If it fails to + * apply locally, an error will be thrown and the transaction will not be broadcast. + * + * void broadcast_transaction(const signed_transaction& trx); + * @param string $trx + * @return array + */ + public function broadcastTransaction($trx) + { + try { + $this->api = $this->getApi('network_broadcast_api'); + return $this->client->call($this->api, 'broadcast_transaction', [$trx]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + /** + * @brief Broadcast a transaction to the network + * @param trx The transaction to broadcast + * + * The transaction will be checked for validity in the local database prior to broadcasting. If it fails to + * apply locally, an error will be thrown and the transaction will not be broadcast. + * + * void broadcast_transaction(const signed_transaction& trx); + * @param string $trx + * @return array + */ + public function broadcastTransactionSynchronous($trx) + { + try { + $this->api = $this->getApi('network_broadcast_api'); + return $this->client->call($this->api, 'broadcast_transaction_synchronous', [$trx]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + /** + * void broadcast_block( const signed_block& block ); + * @param array $block + * @return array + * @failure array['instance'] = 'JsonRPC\Exception\ResponseException'; + */ + public function broadcastBlock($block) + { + try { + $this->api = $this->getApi('network_broadcast_api'); + return $this->client->call($this->api, 'broadcast_block', [$block]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + /** + * void broadcast_block( const signed_block& block ); + * @param array $block + * @return array + */ + public function broadcastTransactionWithCallback($confirmationCallback, $trx) + { + try { + $this->api = $this->getApi('network_broadcast_api'); + return $this->client->call($this->api, 'broadcast_transaction_with_callback', [$confirmationCallback, $trx]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + // To be documented + public function setMaxBlockAge($maxBlcokAge) + { + try { + $this->api = $this->getApi('network_broadcast_api'); + return $this->client->call($this->api, 'set_max_block_age', [$maxBlcokAge]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + // To be documented + public function setSubscribeCallback($callBack, $clearFilter) + { + try { + $this->api = $this->getApi('database_api'); + return $this->client->call($this->api, 'set_subscribe_callback', [$callBack, $clearFilter]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + // To be documented + public function setPendingTransactionCallback($cb) + { + try { + $this->api = $this->getApi('database_api'); + return $this->client->call($this->api, 'set_pending_transaction_callback', [$cb]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + // To be documented + public function setBlockAppliedCallback($cb) + { + try { + $this->api = $this->getApi('database_api'); + return $this->client->call($this->api, 'set_block_applied_callback', [$cb]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + // To be documented + public function cancelAllSubscriptions() + { + try { + $this->api = $this->getApi('database_api'); + return $this->client->call($this->api, 'cancel_all_subscriptions', []); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + +} + +?> \ No newline at end of file diff --git a/src/SteemPHP/SteemChain.php b/src/SteemPHP/SteemChain.php index 0b6cb5b..535044c 100644 --- a/src/SteemPHP/SteemChain.php +++ b/src/SteemPHP/SteemChain.php @@ -31,7 +31,7 @@ class SteemChain * Initialize the connection to the host * @param String $host * - * $host = ['https://node.steem.ws', 'https://steemd.steemit.com'] + * $host = ['https://steemd.steemitdev.com', 'https://steemd.steemit.com'] */ public function __construct($host = 'https://node.steem.ws') { diff --git a/src/SteemPHP/SteemConnection.php b/src/SteemPHP/SteemConnection.php index 6c2a67d..35a4b2f 100644 --- a/src/SteemPHP/SteemConnection.php +++ b/src/SteemPHP/SteemConnection.php @@ -209,6 +209,29 @@ public function countFollows($account) } } + /** + * get the estimated account value of $account + * + * $state = $SteemArticle->getState('/@'.$account.'/transfers') + * $market = $SteemMaket->getOpenOrders($account); + * + * NOTE: This function only gets the estimated amount of money inside the $accounts wallet + * + * @param array $state + * @param array $openOrders + * @param String $account + * @return int on success + * @return array on failure + */ + public function estimateAccountValue($state, $openOrders, $account) + { + try { + return SteemHelper::estimateAccountValue($state, $openOrders, $account); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + } ?> \ No newline at end of file diff --git a/src/SteemPHP/SteemMarket.php b/src/SteemPHP/SteemMarket.php new file mode 100644 index 0000000..314c1a5 --- /dev/null +++ b/src/SteemPHP/SteemMarket.php @@ -0,0 +1,122 @@ +host = trim($host); + $this->httpClient = new HttpClient($this->host); + $this->httpClient->withoutSslVerification(); + $this->client = new Client($this->host, false, $this->httpClient); + } + + /** + * Get Api number + * @param String $name + * @return int + */ + public function getApi($name) + { + try{ + return $this->client->call(1, 'get_api_by_name', [$name]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + /** + * Get the list of sell & buy for STEEM & SBD + * @param int $limit + * @return array + */ + public function getOrderBook($limit = 100) + { + try { + $this->api = $this->getApi('database_api'); + return $this->client->call($this->api, 'get_order_book', [SteemHelper::filterInt($limit)]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + /** + * Get open orders for $account + * @param String $account + * @return array + */ + public function getOpenOrders($account) + { + try { + $this->api = $this->getApi('database_api'); + return $this->client->call($this->api, 'get_open_orders', [$account]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + /** + * Get liquidity reward Queue starting from $startAccount and get upto $limit list + * @param String $startAccount + * @param int $limit + * @return array + */ + public function getLiquidityQueue($startAccount, $limit = 100) + { + try { + $this->api = $this->getApi('database_api'); + return $this->client->call($this->api, 'get_liquidity_queue', [$startAccount, $limit]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + + /** + * Get owner history + * @param String $account + * @return array + */ + public function getOwnerHistory($account) + { + try { + $this->api = $this->getApi('database_api'); + return $this->client->call($this->api, 'get_owner_history', [$account]); + } catch (\Exception $e) { + return SteemHelper::handleError($e); + } + } + +} + +?> \ No newline at end of file diff --git a/src/SteemPHP/SteemWitness.php b/src/SteemPHP/SteemWitness.php index ff26efd..26e90bb 100644 --- a/src/SteemPHP/SteemWitness.php +++ b/src/SteemPHP/SteemWitness.php @@ -32,7 +32,7 @@ class SteemWitness * Initialize the connection to the host * @param String $host * - * $host = ['https://node.steem.ws', 'https://steemd.steemit.com'] + * $host = ['https://steemd.steemitdev.com', 'https://steemd.steemit.com'] */ public function __construct($host = 'https://steemd.steemit.com') {