From 048e692c6ce9308d10d2e0f1213276d9f989257b Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 26 Mar 2020 18:57:11 +0100 Subject: [PATCH 1/9] initial commit --- .editorconfig | 12 + .github/workflows/php.yml | 24 + .gitignore | 13 + composer.json | 32 + docs/README.md | 1176 +++++++++++++++++ phpdoc.xml | 16 + phpunit.xml | 18 + src/Client.php | 126 ++ src/Constants/AccountType.php | 21 + src/Constants/AddressState.php | 31 + src/Constants/ConnectionState.php | 36 + src/Constants/ConsensusState.php | 21 + src/Constants/PeerStateCommand.php | 26 + src/Constants/PoolConnectionState.php | 21 + src/Models/Account.php | 26 + src/Models/Block.php | 101 ++ src/Models/Mempool.php | 38 + src/Models/Model.php | 37 + src/Models/OutgoingTransaction.php | 61 + src/Models/Peer.php | 56 + src/Models/SyncingStatus.php | 21 + src/Models/Transaction.php | 83 ++ src/Models/TransactionReceipt.php | 36 + src/Models/Wallet.php | 26 + src/NimiqClient.php | 625 +++++++++ src/NimiqResponse.php | 84 ++ src/functions.php | 31 + tests/ClientTest.php | 113 ++ tests/FunctionsTest.php | 55 + tests/NimiqClientTest.php | 1100 +++++++++++++++ tests/ResponseTest.php | 64 + tests/fixtures/accounts/accounts.json | 24 + tests/fixtures/blockNumber/block-number.json | 5 + .../fixtures/blockTransactionCount/found.json | 5 + .../blockTransactionCount/not-found.json | 5 + tests/fixtures/consensus/syncing.json | 5 + tests/fixtures/constant/constant.json | 5 + tests/fixtures/createAccount/new-account.json | 9 + .../fixtures/createRawTransaction/basic.json | 5 + tests/fixtures/getAccount/account.json | 10 + tests/fixtures/getBalance/balance.json | 5 + tests/fixtures/getBlock/block-found.json | 24 + tests/fixtures/getBlock/block-not-found.json | 5 + .../getBlock/block-with-transactions.json | 54 + .../basic-transaction.json | 18 + .../getTransaction/full-transaction.json | 20 + tests/fixtures/getTransaction/not-found.json | 5 + .../getTransactionReceipt/not-found.json | 5 + .../getTransactionReceipt/receipt.json | 12 + .../no-transactions-found.json | 5 + .../getTransactions/transactions-found.json | 51 + tests/fixtures/getWork/block-template.json | 28 + tests/fixtures/getWork/work.json | 10 + tests/fixtures/hashrate/hashrate.json | 5 + tests/fixtures/log/log.json | 5 + tests/fixtures/mempool/mempool-empty.json | 8 + tests/fixtures/mempool/mempool.json | 9 + .../mempoolContent/full-transactions.json | 39 + .../fixtures/mempoolContent/hashes-only.json | 9 + tests/fixtures/minFeePerByte/fee.json | 5 + tests/fixtures/minerAddress/address.json | 5 + tests/fixtures/minerThreads/threads.json | 5 + tests/fixtures/miningState/mining.json | 5 + tests/fixtures/peerCount/count.json | 5 + tests/fixtures/peerList/empty-list.json | 5 + tests/fixtures/peerList/list.json | 23 + tests/fixtures/peerState/error.json | 8 + tests/fixtures/peerState/failed.json | 9 + tests/fixtures/peerState/normal.json | 16 + tests/fixtures/pool/confirmed-balance.json | 5 + tests/fixtures/pool/connection-state.json | 5 + tests/fixtures/pool/no-pool.json | 5 + tests/fixtures/pool/sushipool.json | 5 + .../fixtures/sendTransaction/transaction.json | 5 + tests/fixtures/submitBlock/submit.json | 4 + tests/fixtures/syncing/not-syncing.json | 5 + tests/fixtures/syncing/syncing.json | 9 + 77 files changed, 4649 insertions(+) create mode 100644 .editorconfig create mode 100644 .github/workflows/php.yml create mode 100644 .gitignore create mode 100644 composer.json create mode 100644 docs/README.md create mode 100644 phpdoc.xml create mode 100644 phpunit.xml create mode 100644 src/Client.php create mode 100644 src/Constants/AccountType.php create mode 100644 src/Constants/AddressState.php create mode 100644 src/Constants/ConnectionState.php create mode 100644 src/Constants/ConsensusState.php create mode 100644 src/Constants/PeerStateCommand.php create mode 100644 src/Constants/PoolConnectionState.php create mode 100644 src/Models/Account.php create mode 100644 src/Models/Block.php create mode 100644 src/Models/Mempool.php create mode 100644 src/Models/Model.php create mode 100644 src/Models/OutgoingTransaction.php create mode 100644 src/Models/Peer.php create mode 100644 src/Models/SyncingStatus.php create mode 100644 src/Models/Transaction.php create mode 100644 src/Models/TransactionReceipt.php create mode 100644 src/Models/Wallet.php create mode 100644 src/NimiqClient.php create mode 100644 src/NimiqResponse.php create mode 100644 src/functions.php create mode 100644 tests/ClientTest.php create mode 100644 tests/FunctionsTest.php create mode 100644 tests/NimiqClientTest.php create mode 100644 tests/ResponseTest.php create mode 100644 tests/fixtures/accounts/accounts.json create mode 100644 tests/fixtures/blockNumber/block-number.json create mode 100644 tests/fixtures/blockTransactionCount/found.json create mode 100644 tests/fixtures/blockTransactionCount/not-found.json create mode 100644 tests/fixtures/consensus/syncing.json create mode 100644 tests/fixtures/constant/constant.json create mode 100644 tests/fixtures/createAccount/new-account.json create mode 100644 tests/fixtures/createRawTransaction/basic.json create mode 100644 tests/fixtures/getAccount/account.json create mode 100644 tests/fixtures/getBalance/balance.json create mode 100644 tests/fixtures/getBlock/block-found.json create mode 100644 tests/fixtures/getBlock/block-not-found.json create mode 100644 tests/fixtures/getBlock/block-with-transactions.json create mode 100644 tests/fixtures/getRawTransactionInfo/basic-transaction.json create mode 100644 tests/fixtures/getTransaction/full-transaction.json create mode 100644 tests/fixtures/getTransaction/not-found.json create mode 100644 tests/fixtures/getTransactionReceipt/not-found.json create mode 100644 tests/fixtures/getTransactionReceipt/receipt.json create mode 100644 tests/fixtures/getTransactions/no-transactions-found.json create mode 100644 tests/fixtures/getTransactions/transactions-found.json create mode 100644 tests/fixtures/getWork/block-template.json create mode 100644 tests/fixtures/getWork/work.json create mode 100644 tests/fixtures/hashrate/hashrate.json create mode 100644 tests/fixtures/log/log.json create mode 100644 tests/fixtures/mempool/mempool-empty.json create mode 100644 tests/fixtures/mempool/mempool.json create mode 100644 tests/fixtures/mempoolContent/full-transactions.json create mode 100644 tests/fixtures/mempoolContent/hashes-only.json create mode 100644 tests/fixtures/minFeePerByte/fee.json create mode 100644 tests/fixtures/minerAddress/address.json create mode 100644 tests/fixtures/minerThreads/threads.json create mode 100644 tests/fixtures/miningState/mining.json create mode 100644 tests/fixtures/peerCount/count.json create mode 100644 tests/fixtures/peerList/empty-list.json create mode 100644 tests/fixtures/peerList/list.json create mode 100644 tests/fixtures/peerState/error.json create mode 100644 tests/fixtures/peerState/failed.json create mode 100644 tests/fixtures/peerState/normal.json create mode 100644 tests/fixtures/pool/confirmed-balance.json create mode 100644 tests/fixtures/pool/connection-state.json create mode 100644 tests/fixtures/pool/no-pool.json create mode 100644 tests/fixtures/pool/sushipool.json create mode 100644 tests/fixtures/sendTransaction/transaction.json create mode 100644 tests/fixtures/submitBlock/submit.json create mode 100644 tests/fixtures/syncing/not-syncing.json create mode 100644 tests/fixtures/syncing/syncing.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..31b7a10 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +# https://editorconfig.org/ + +root = true + +[*] +trim_trailing_whitespace = true +insert_final_newline = true +end_of_line = lf +charset = utf-8 +tab_width = 4 +indent_size = 4 +indent_style = space diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..1f29bc3 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,24 @@ +name: ci + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest + + - name: Run test suite + run: composer run-script test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..efd689e --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +.DS_Store +Thumbs.db +/.idea +/.vscode + +/vendor +/coverage +/build +composer.phar +composer.lock +.phpunit.result.cache +sample.php +phpDocumentor.phar diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..e3c9f56 --- /dev/null +++ b/composer.json @@ -0,0 +1,32 @@ +{ + "name": "lunanimous/php-rpc-client", + "description": "Nimiq RPC Client for PHP", + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "Mario", + "email": "builtbysplash@gmail.com" + } + ], + "scripts": { + "test": "vendor/bin/phpunit", + "docs": "vendor/bin/phpdoc" + }, + "require": { + "php": ">=7.1", + "guzzlehttp/guzzle": "^6.5" + }, + "require-dev": { + "phpunit/phpunit": "^8.0", + "cvuorinen/phpdoc-markdown-public": "^0.2" + }, + "autoload": { + "psr-4": { + "Lunanimous\\Rpc\\": "src" + }, + "files": [ + "src/functions.php" + ] + } +} diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..2f943a8 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,1176 @@ +# Nimiq RPC Client for PHP + +## Table of Contents + +* [NimiqClient](#nimiqclient) + * [__construct](#__construct) + * [getPeerCount](#getpeercount) + * [getSyncingState](#getsyncingstate) + * [getConsensusState](#getconsensusstate) + * [getPeerList](#getpeerlist) + * [getPeer](#getpeer) + * [setPeerState](#setpeerstate) + * [sendRawTransaction](#sendrawtransaction) + * [createRawTransaction](#createrawtransaction) + * [sendTransaction](#sendtransaction) + * [getRawTransactionInfo](#getrawtransactioninfo) + * [getTransactionByBlockHashAndIndex](#gettransactionbyblockhashandindex) + * [getTransactionByBlockNumberAndIndex](#gettransactionbyblocknumberandindex) + * [getTransactionByHash](#gettransactionbyhash) + * [getTransactionReceipt](#gettransactionreceipt) + * [getTransactionsByAddress](#gettransactionsbyaddress) + * [getMempoolContent](#getmempoolcontent) + * [getMempool](#getmempool) + * [getMinFeePerByte](#getminfeeperbyte) + * [setMinFeePerByte](#setminfeeperbyte) + * [getMiningState](#getminingstate) + * [setMiningState](#setminingstate) + * [getHashrate](#gethashrate) + * [getMinerThreads](#getminerthreads) + * [setMinerThreads](#setminerthreads) + * [getMinerAddress](#getmineraddress) + * [getPool](#getpool) + * [setPool](#setpool) + * [getPoolConnectionState](#getpoolconnectionstate) + * [getPoolConfirmedBalance](#getpoolconfirmedbalance) + * [getWork](#getwork) + * [getBlockTemplate](#getblocktemplate) + * [submitBlock](#submitblock) + * [getAccounts](#getaccounts) + * [createAccount](#createaccount) + * [getBalance](#getbalance) + * [getAccount](#getaccount) + * [getBlockNumber](#getblocknumber) + * [getBlockTransactionCountByHash](#getblocktransactioncountbyhash) + * [getBlockTransactionCountByNumber](#getblocktransactioncountbynumber) + * [getBlockByHash](#getblockbyhash) + * [getBlockByNumber](#getblockbynumber) + * [getConstant](#getconstant) + * [setConstant](#setconstant) + * [resetConstant](#resetconstant) + * [setLogLevel](#setloglevel) + +## NimiqClient + +RPC Client to communicate with a Nimiq Node. + + + +* Full name: \Lunanimous\Rpc\NimiqClient +* Parent class: + + +### __construct + +Creates a new instance of the Nimiq client. + +```php +NimiqClient::__construct( array $config = array() ): \Lunanimous\Rpc\NimiqClient +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$config` | **array** | client config array (optional) | + + +**Return Value:** + +new client instance + + + +--- + +### getPeerCount + +Returns number of peers currently connected to the client. + +```php +NimiqClient::getPeerCount( ): integer +``` + + + + + +**Return Value:** + +number of connected peers + + + +--- + +### getSyncingState + +Returns an object with data about the sync status or false. + +```php +NimiqClient::getSyncingState( ): boolean|\Lunanimous\Rpc\Models\SyncingStatus +``` + + + + + +**Return Value:** + +object with sync status data or false, when not syncing + + + +--- + +### getConsensusState + +Returns information on the current consensus state. + +```php +NimiqClient::getConsensusState( ): string +``` + + + + + +**Return Value:** + +string describing the consensus state. ConsensusState::Established is the value for a good state, other values indicate bad state. + + + +--- + +### getPeerList + +Returns list of peers known to the client. + +```php +NimiqClient::getPeerList( ): array<mixed,\Lunanimous\Rpc\Models\Peer> +``` + + + + + +**Return Value:** + +list of peers + + + +--- + +### getPeer + +Returns the state of the peer. + +```php +NimiqClient::getPeer( string $peer ): \Lunanimous\Rpc\Models\Peer +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$peer` | **string** | address of the peer | + + +**Return Value:** + +current state of the peer + + + +--- + +### setPeerState + +Sets the state of the peer. + +```php +NimiqClient::setPeerState( string $peer, string $command ): \Lunanimous\Rpc\Models\Peer +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$peer` | **string** | address of the peer | +| `$command` | **string** | command to perform (one of PeerStateCommand::Connect, PeerStateCommand::Disconnect, PeerStateCommand::Ban, PeerStateCommand::Unban) | + + +**Return Value:** + +new state of the peer + + + +--- + +### sendRawTransaction + +Sends a signed message call transaction or a contract creation, if the data field contains code. + +```php +NimiqClient::sendRawTransaction( string $txHex ): string +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$txHex` | **string** | hex-encoded signed transaction | + + +**Return Value:** + +hex-encoded transaction hash + + + +--- + +### createRawTransaction + +Creates and signs a transaction without sending it. The transaction can then be send via sendRawTransaction +without accidentally replaying it. + +```php +NimiqClient::createRawTransaction( \Lunanimous\Rpc\Models\OutgoingTransaction $tx ): string +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$tx` | **\Lunanimous\Rpc\Models\OutgoingTransaction** | transaction object | + + +**Return Value:** + +hex-encoded transaction + + + +--- + +### sendTransaction + +Creates new message call transaction or a contract creation, if the data field contains code. + +```php +NimiqClient::sendTransaction( \Lunanimous\Rpc\Models\OutgoingTransaction $tx ): string +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$tx` | **\Lunanimous\Rpc\Models\OutgoingTransaction** | transaction object | + + +**Return Value:** + +hex-encoded transaction hash + + + +--- + +### getRawTransactionInfo + +Deserializes hex-encoded transaction and returns a transaction object. + +```php +NimiqClient::getRawTransactionInfo( string $txHex ): \Lunanimous\Rpc\Models\Transaction +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$txHex` | **string** | hex-encoded transaction | + + +**Return Value:** + +transaction object + + + +--- + +### getTransactionByBlockHashAndIndex + +Returns information about a transaction by block hash and transaction index position. + +```php +NimiqClient::getTransactionByBlockHashAndIndex( string $blockHash, integer $txIndex ): null|\Lunanimous\Rpc\Models\Transaction +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$blockHash` | **string** | hash of the block containing the transaction | +| `$txIndex` | **integer** | index of the transaction in the block | + + +**Return Value:** + +transaction object, or null when no transaction was found + + + +--- + +### getTransactionByBlockNumberAndIndex + +Returns information about a transaction by block number and transaction index position. + +```php +NimiqClient::getTransactionByBlockNumberAndIndex( integer $blockNumber, integer $txIndex ): null|\Lunanimous\Rpc\Models\Transaction +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$blockNumber` | **integer** | height of the block containing the transaction | +| `$txIndex` | **integer** | index of the transaction in the block | + + +**Return Value:** + +transaction object, or null when no transaction was found + + + +--- + +### getTransactionByHash + +Returns the information about a transaction requested by transaction hash. + +```php +NimiqClient::getTransactionByHash( string $hash ): null|\Lunanimous\Rpc\Models\Transaction +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$hash` | **string** | hash of the transaction | + + +**Return Value:** + +transaction object, or null when no transaction was found + + + +--- + +### getTransactionReceipt + +Returns the receipt of a transaction by transaction hash. The receipt is not available for pending transactions. + +```php +NimiqClient::getTransactionReceipt( string $hash ): \Lunanimous\Rpc\Models\TransactionReceipt +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$hash` | **string** | hash of the transaction | + + +**Return Value:** + +transaction receipt + + + +--- + +### getTransactionsByAddress + +Returns the latest transactions successfully performed by or for an address. This information might change +when blocks are rewinded on the local state due to forks. + +```php +NimiqClient::getTransactionsByAddress( string $address, integer $limit = 1000 ): array<mixed,\Lunanimous\Rpc\Models\Transaction> +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$address` | **string** | account address | +| `$limit` | **integer** | (optional, default 1000) number of transactions to return | + + +**Return Value:** + +array of transactions linked to the requested address + + + +--- + +### getMempoolContent + +Returns transactions that are currently in the mempool. + +```php +NimiqClient::getMempoolContent( boolean $includeTransactions = false ): array<mixed,string>|array<mixed,\Lunanimous\Rpc\Models\Transaction> +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$includeTransactions` | **boolean** | if true includes full transactions, if false includes only transaction hashes | + + +**Return Value:** + +array of transactions (either represented by the transaction hash or a transaction object) + + + +--- + +### getMempool + +Returns information on the current mempool situation. This will provide an overview of the number of +transactions sorted into buckets based on their fee per byte (in smallest unit). + +```php +NimiqClient::getMempool( ): \Lunanimous\Rpc\Models\Mempool +``` + + + + + +**Return Value:** + +mempool information + + + +--- + +### getMinFeePerByte + +Returns the current minimum fee per byte. + +```php +NimiqClient::getMinFeePerByte( ): integer +``` + + + + + +**Return Value:** + +current minimum fee per byte + + + +--- + +### setMinFeePerByte + +Sets the minimum fee per byte. + +```php +NimiqClient::setMinFeePerByte( integer $minFee ): integer +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$minFee` | **integer** | minimum fee per byte | + + +**Return Value:** + +new minimum fee per byte + + + +--- + +### getMiningState + +Returns true if client is actively mining new blocks. + +```php +NimiqClient::getMiningState( ): boolean +``` + + + + + +**Return Value:** + +true if the client is mining, otherwise false + + + +--- + +### setMiningState + +Enables or disables the miner. + +```php +NimiqClient::setMiningState( boolean $enabled ): boolean +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$enabled` | **boolean** | true to start the miner, false to stop | + + +**Return Value:** + +true if the client is mining, otherwise false + + + +--- + +### getHashrate + +Returns the number of hashes per second that the node is mining with. + +```php +NimiqClient::getHashrate( ): float +``` + + + + + +**Return Value:** + +number of hashes per second + + + +--- + +### getMinerThreads + +Returns the number of CPU threads the miner is using. + +```php +NimiqClient::getMinerThreads( ): integer +``` + + + + + +**Return Value:** + +current number of miner threads + + + +--- + +### setMinerThreads + +Sets the number of CPU threads the miner can use. + +```php +NimiqClient::setMinerThreads( integer $threads ): integer +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$threads` | **integer** | number of threads to allocate | + + +**Return Value:** + +new number of miner threads + + + +--- + +### getMinerAddress + +Returns the miner address. + +```php +NimiqClient::getMinerAddress( ): string +``` + + + + + +**Return Value:** + +miner address + + + +--- + +### getPool + +Returns the current pool. + +```php +NimiqClient::getPool( ): null|string +``` + + + + + +**Return Value:** + +current pool, or null if not set + + + +--- + +### setPool + +Sets the mining pool. + +```php +NimiqClient::setPool( boolean|string $pool ): null|string +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$pool` | **boolean|string** | mining pool string (url:port) or boolean to enable/disable pool mining | + + +**Return Value:** + +new mining pool, or null if not enabled + + + +--- + +### getPoolConnectionState + +Returns the connection state to mining pool. + +```php +NimiqClient::getPoolConnectionState( ): integer +``` + + + + + +**Return Value:** + +mining pool connection state (0: connected, 1: connecting, 2: closed) + + + +--- + +### getPoolConfirmedBalance + +Returns the confirmed mining pool balance. + +```php +NimiqClient::getPoolConfirmedBalance( ): float +``` + + + + + +**Return Value:** + +confirmed mining pool balance (in smallest unit) + + + +--- + +### getWork + +Returns instructions to mine the next block. This will consider pool instructions when connected to a pool. + +```php +NimiqClient::getWork( string $address = null, string $extraDataHex = null ): array +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$address` | **string** | address to use as a miner for this block. this overrides the address provided during startup or from the pool. | +| `$extraDataHex` | **string** | hex-encoded value for the extra data field. this overrides the address provided during startup or from the pool. | + + +**Return Value:** + +mining work instructions + + + +--- + +### getBlockTemplate + +Returns a template to build the next block for mining. This will consider pool instructions when connected +to a pool. + +```php +NimiqClient::getBlockTemplate( string $address = null, string $extraDataHex = null ): array +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$address` | **string** | address to use as a miner for this block. this overrides the address provided during startup or from the pool. | +| `$extraDataHex` | **string** | hex-encoded value for the extra data field. this overrides the address provided during startup or from the pool. | + + +**Return Value:** + +mining block template + + + +--- + +### submitBlock + +Submits a block to the node. When the block is valid, the node will forward it to other nodes in the network. + +```php +NimiqClient::submitBlock( string $blockHex ) +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$blockHex` | **string** | hex-encoded full block (including header, interlink and body). when submitting work from getWork, remember to include the suffix. | + + + + +--- + +### getAccounts + +Returns a list of addresses owned by client. + +```php +NimiqClient::getAccounts( ): array<mixed,\Lunanimous\Rpc\Models\Account> +``` + + + + + +**Return Value:** + +array of accounts owned by the client + + + +--- + +### createAccount + +Creates a new account and stores its private key in the client store. + +```php +NimiqClient::createAccount( ): \Lunanimous\Rpc\Models\Wallet +``` + + + + + +**Return Value:** + +information on the wallet that was created using the command + + + +--- + +### getBalance + +Returns the balance of the account of given address. + +```php +NimiqClient::getBalance( string $address ): float +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$address` | **string** | address to check for balance | + + +**Return Value:** + +the current balance at the specified address (in smallest unit) + + + +--- + +### getAccount + +Returns details for the account of given address. + +```php +NimiqClient::getAccount( string $address ): \Lunanimous\Rpc\Models\Account +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$address` | **string** | address for which to get account details | + + +**Return Value:** + +details about the account. returns the default empty basic account for non-existing accounts. + + + +--- + +### getBlockNumber + +Returns the height of most recent block. + +```php +NimiqClient::getBlockNumber( ): integer +``` + + + + + +**Return Value:** + +current block height the client is on + + + +--- + +### getBlockTransactionCountByHash + +Returns the number of transactions in a block from a block matching the given block hash. + +```php +NimiqClient::getBlockTransactionCountByHash( string $blockHash ): null|integer +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$blockHash` | **string** | hash of the block | + + +**Return Value:** + +number of transactions in the block found, or null when no block was found + + + +--- + +### getBlockTransactionCountByNumber + +Returns the number of transactions in a block matching the given block number. + +```php +NimiqClient::getBlockTransactionCountByNumber( integer $blockNumber ): null|integer +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$blockNumber` | **integer** | height of the block | + + +**Return Value:** + +number of transactions in the block found, or null when no block was found + + + +--- + +### getBlockByHash + +Returns information about a block by hash. + +```php +NimiqClient::getBlockByHash( string $blockHash, boolean $includeTransactions = false ): null|\Lunanimous\Rpc\Models\Block +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$blockHash` | **string** | hash of the block to gather information on | +| `$includeTransactions` | **boolean** | if true includes full transactions, if false (default) includes only transaction hashes | + + +**Return Value:** + +block object, or null when no block was found + + + +--- + +### getBlockByNumber + +Returns information about a block by block number. + +```php +NimiqClient::getBlockByNumber( integer $blockNumber, boolean $includeTransactions = false ): null|\Lunanimous\Rpc\Models\Block +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$blockNumber` | **integer** | height of the block to gather information on | +| `$includeTransactions` | **boolean** | if true includes full transactions, if false (default) includes only transaction hashes | + + +**Return Value:** + +block object, or null when no block was found + + + +--- + +### getConstant + +Returns the value of a constant. + +```php +NimiqClient::getConstant( string $constant ): integer +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$constant` | **string** | name of the constant | + + +**Return Value:** + +current value of the constant + + + +--- + +### setConstant + +Sets the value of a constants. + +```php +NimiqClient::setConstant( string $constant, integer $value ): integer +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$constant` | **string** | name of the constant | +| `$value` | **integer** | value to set | + + +**Return Value:** + +new value of the constant + + + +--- + +### resetConstant + +Resets the constant to default value. + +```php +NimiqClient::resetConstant( string $constant ): integer +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$constant` | **string** | name of the constant | + + +**Return Value:** + +new value of the constant + + + +--- + +### setLogLevel + +Sets the log level of the node. + +```php +NimiqClient::setLogLevel( string $tag, string $level ): boolean +``` + + + + +**Parameters:** + +| Parameter | Type | Description | +|-----------|------|-------------| +| `$tag` | **string** | if '*' the log level is set globally, otherwise the log level is applied only on this tag | +| `$level` | **string** | minimum log level to display (trace, verbose, debug, info, warn, error, assert) | + + +**Return Value:** + +true if set successfully, otherwise false + + + +--- + + + +-------- +> This document was automatically generated from source code comments on 2020-03-21 using [phpDocumentor](http://www.phpdoc.org/) and [cvuorinen/phpdoc-markdown-public](https://github.com/cvuorinen/phpdoc-markdown-public) diff --git a/phpdoc.xml b/phpdoc.xml new file mode 100644 index 0000000..ac4fb79 --- /dev/null +++ b/phpdoc.xml @@ -0,0 +1,16 @@ + + + Nimiq RPC Client for PHP + + build + + + docs + + +