module Api

Copyright 2020 Nimiq community.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Attributes

rpc[RW]

Public Instance Methods

accounts() click to toggle source

accounts - Returns a list of addresses owned by client.

# File lib/api.rb, line 21
def accounts
  result = @rpc.request("accounts")
  return result
end
block_number() click to toggle source

block_number - Returns the height of most recent block.

# File lib/api.rb, line 27
def block_number
  result = @rpc.request("blockNumber")
  return result
end
consensus() click to toggle source

consensus - Returns information on the current consensus state.

# File lib/api.rb, line 33
def consensus
  result = @rpc.request("consensus")
  return result
end
constant(name, value = nil) click to toggle source

constant - Returns or overrides a constant value. When no parameter is given, it returns the value of the constant. When giving a value as parameter, it sets the constant to the given value. To reset the constant to the default value, the parameter “reset” should be used.

  • @param [String] name - The class and name of the constant. (format should be Class.CONSTANT)

  • @param [Integer] value - The new value of the constant or “reset”. (optional)

# File lib/api.rb, line 44
def constant(name, value = nil)
  if value
    result = @rpc.request("constant", name, value)
  else
    result = @rpc.request("constant", name)
  end
  return result
end
create_account() click to toggle source

create_account - Creates a new account and stores its private key in the client store.

# File lib/api.rb, line 54
def create_account
  result = @rpc.request("createAccount")
  return result
end
create_raw_transaction(transaction) click to toggle source

create_raw_transaction - Creates and signs a transaction without sending it. The transaction can then be send via `send_raw_transaction` without accidentally replaying it.

  • @param [TransactionObject] transaction - The transaction object.

# File lib/api.rb, line 62
def create_raw_transaction(transaction)
  result = @rpc.request("createRawTransaction", transaction)
  return result
end
get_account(address) click to toggle source

get_account - Returns details for the account of given address.

  • @param [String] address - Address to get account details.

# File lib/api.rb, line 77
def get_account(address)
  result = @rpc.request("getAccount", address)
  return result
end
get_balance(address) click to toggle source

get_balance - Returns the balance of the account of given address.

  • @param [String] address - Address to check for balance.

# File lib/api.rb, line 84
def get_balance(address)
  result = @rpc.request("getBalance", address)
  return result
end
get_block_by_hash(block_hash, full_transactions = nil) click to toggle source

get_block_by_hash - Returns information about a block by hash.

  • @param [String] block_hash - Hash of the block to gather information on.

  • @param [Boolean] full_transactions (optional) - If true it returns the full transaction objects, if false only the hashes of the transactions. (default false)

# File lib/api.rb, line 92
def get_block_by_hash(block_hash, full_transactions = nil)
  if full_transactions
    result = @rpc.request("getBlockByHash", block_hash, full_transactions)
  else
    result = @rpc.request("getBlockByHash", block_hash)
  end
  return result
end
get_block_by_number(block_number, full_transactions = nil) click to toggle source

get_block_by_number - Returns information about a block by block number.

  • @param [Integer] block_number - The height of the block to gather information on.

  • @param [Boolean] full_transactions (optional) - If true it returns the full transaction objects, if false only the hashes of the transactions. (default false)

# File lib/api.rb, line 104
def get_block_by_number(block_number, full_transactions = nil)
  if full_transactions
    result = @rpc.request("getBlockByNumber", block_number, full_transactions)
  else
    result = @rpc.request("getBlockByNumber", block_number)
  end
  return result
end
get_block_template(address = nil, dada_field = nil) click to toggle source

get_block_template - Returns a template to build the next block for mining. This will consider pool instructions when connected to a pool.

  • @param [String] address (optional) - Address to use as a miner for this block. This overrides the address provided during startup or from the pool.

  • @param [String] dada_field (optional) - Hex-encoded value for the extra data field. This overrides the address provided during startup or from the pool.

# File lib/api.rb, line 117
def get_block_template(address = nil, dada_field = nil)
  result = @rpc.request("getBlockTemplate")
  return result
end
get_block_transaction_count_by_hash(block_hash) click to toggle source

get_block_transaction_count_by_hash - Returns the number of transactions in a block from a block matching the given block hash.

  • @param [String] block_hash - Hash of the block.

# File lib/api.rb, line 124
def get_block_transaction_count_by_hash(block_hash)
  result = @rpc.request("getBlockTransactionCountByHash", block_hash)
  return result
end
get_block_transaction_count_by_number(block_number) click to toggle source

get_block_transaction_count_by_number - Returns the number of transactions in a block matching the given block number.

# File lib/api.rb, line 131
def get_block_transaction_count_by_number(block_number)
  result = @rpc.request("getBlockTransactionCountByNumber", block_number)
  return result
end
get_transaction_by_block_hash_and_index(block_hash, transaction_index) click to toggle source

get_transaction_by_block_hash_and_index - Returns information about a transaction by block hash and transaction index position.

  • @param [Integer] block_hash - Hash of the block containing the transaction.

  • @param [Integer] transaction_index - Index of the transaction in the block.

# File lib/api.rb, line 139
def get_transaction_by_block_hash_and_index(block_hash, transaction_index)
  result = @rpc.request("getTransactionByBlockHashAndIndex", block_hash, transaction_index)
  return result
end
get_transaction_by_block_number_and_index(block_height, transaction_index) click to toggle source

get_transaction_by_block_number_and_index - Returns information about a transaction by block number and transaction index position.

  • @param [Integer] block_height - Height of the block containing the transaction.

  • @param [Integer] transaction_index - Index of the transaction in the block.

# File lib/api.rb, line 147
def get_transaction_by_block_number_and_index(block_height, transaction_index)
  result = @rpc.request("getTransactionByBlockNumberAndIndex", block_height, transaction_index)
  return result
end
get_transaction_by_hash(transaction_hash) click to toggle source

get_transaction_by_hash - Returns the information about a transaction requested by transaction hash.

  • @param [String] transaction_hash - Hash of a transaction.

# File lib/api.rb, line 154
def get_transaction_by_hash(transaction_hash)
  result = @rpc.request("getTransactionByHash", transaction_hash)
  return result
end
get_transaction_receipt(transaction_hash) click to toggle source

get_transaction_receipt - Returns the receipt of a transaction by transaction hash. Note That the receipt is not available for pending transactions.

  • @param [String] transaction_hash - Hash of a transaction.

# File lib/api.rb, line 162
def get_transaction_receipt(transaction_hash)
  result = @rpc.request("getTransactionReceipt", transaction_hash)
  return result
end
get_transactions_by_address(address, transactions_number = nil) click to toggle source

get_transactions_by_address - Returns the latest transactions successfully performed by or for an address.

  • @param [String] address - Address of which transactions should be gathered.

  • @param [Integer] transactions_number (optional) - Number of transactions that shall be returned. (default 1000)

# File lib/api.rb, line 170
def get_transactions_by_address(address, transactions_number = nil)
  if transactions_number
    result = @rpc.request("getTransactionsByAddress", address, transactions_number)
  else
    result = @rpc.request("getTransactionsByAddress", address)
  end
  return result
end
get_work(address = nil, dada_field = nil) click to toggle source

get_work - Returns instructions to mine the next block. This will consider pool instructions when connected to a pool.

  • @param [String] address (optional) - Address to use as a miner for this block. This overrides the address provided during startup or from the pool.

  • @param [String] dada_field (optional) - Hex-encoded value for the extra data field. This overrides the address provided during startup or from the pool.

# File lib/api.rb, line 182
def get_work(address = nil, dada_field = nil)
  result = @rpc.request("getWork", address, dada_field)
  return result
end
hashrate() click to toggle source

hashrate - Returns the number of hashes per second that the node is mining with.

# File lib/api.rb, line 188
def hashrate
  result = @rpc.request("hashrate")
  return result
end
log(tag, log_level) click to toggle source

log - Sets the log level of the node.

  • @param [String] tag - If the tag is '*' the log level will be set globally, otherwise the log level is applied only on this tag.

  • @param [String] log_level - Log levels valid options: `trace`, `verbose`, `debug`, `info`, `warn`, `error`, `assert`.

# File lib/api.rb, line 196
def log(tag, log_level)
  result = @rpc.request("log", tag, log_level)
  return result
end
mempool() click to toggle source

mempool - 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).

# File lib/api.rb, line 202
def mempool
  result = @rpc.request("mempool")
  return result
end
mempool_content() click to toggle source

mempool_content - Returns transactions that are currently in the mempool.

# File lib/api.rb, line 208
def mempool_content
  result = @rpc.request("mempoolContent")
  return result
end
min_fee_per_byte(set_min_fee = nil) click to toggle source

min_fee_per_byte - Returns or sets the minimum fee per byte.

  • @param [Integer] set_min_fee (optional) - The new minimum fee per byte.

# File lib/api.rb, line 232
def min_fee_per_byte(set_min_fee = nil)
  if set_min_fee
    result = @rpc.request("minFeePerByte", set_min_fee)
  else
    result = @rpc.request("minFeePerByte")
  end
  return result
end
miner_address() click to toggle source

miner_address - Returns the miner address.

# File lib/api.rb, line 214
def miner_address
  result = @rpc.request("minerAddress")
  return result
end
miner_threads(set_threads = nil) click to toggle source

miner_threads - Returns or sets the number of CPU threads for the miner.

  • @param [Integer] set_threads (optional) - The number of threads to allocate for mining.

# File lib/api.rb, line 221
def miner_threads(set_threads = nil)
  if set_threads
    result = @rpc.request("minerThreads", set_threads)
  else
    result = @rpc.request("minerThreads")
  end
  return result
end
mining() click to toggle source

mining - Returns `true` if client is actively mining new blocks.

# File lib/api.rb, line 242
def mining
  result = @rpc.request("mining")
  return result
end
peer_count() click to toggle source

peer_count - Returns number of peers currently connected to the client.

# File lib/api.rb, line 248
def peer_count
  result = @rpc.request("peerCount")
  return result
end
peer_list() click to toggle source

peer_list - Returns list of peers known to the client.

# File lib/api.rb, line 254
def peer_list
  result = @rpc.request("peerList")
  return result
end
peer_state(peer_address) click to toggle source

peer_state - Returns the state of the peer.

  • @param [String] peer_address - The address of the peer.

# File lib/api.rb, line 261
def peer_state(peer_address)
  result = @rpc.request("peerState", peer_address)
  return result
end
pool(pool_address = nil) click to toggle source

pool - Returns or sets the mining pool. When no parameter is given, it returns the current mining pool. When a value is given as parameter, it sets the mining pool to that value.

  • @param [String/Boolean] pool_address (optional) - The mining pool connection string (url:port) or boolean to enable/disable pool mining.

# File lib/api.rb, line 269
def pool(pool_address = nil)
  if pool_address
    result = @rpc.request("pool", pool_address)
  else
    result = @rpc.request("pool")
  end
  return result
end
pool_confirmed_balance() click to toggle source

pool_confirmed_balance - Returns the confirmed mining pool balance.

# File lib/api.rb, line 279
def pool_confirmed_balance
  result = @rpc.request("poolConfirmedBalance")
  return result
end
pool_connection_state() click to toggle source

pool_connection_state - Returns the connection state to mining pool.

# File lib/api.rb, line 285
def pool_connection_state
  result = @rpc.request("poolConnectionState")
  return result
end
send_raw_transaction(signed_transaction) click to toggle source

send_raw_transaction - Sends a signed message call transaction or a contract creation, if the data field contains code.

  • @param [String] signed_transaction - The hex encoded signed transaction.

# File lib/api.rb, line 292
def send_raw_transaction(signed_transaction)
  result = @rpc.request("sendRawTransaction", signed_transaction)
  return result
end
send_transaction(transaction) click to toggle source

send_transaction - Creates new message call transaction or a contract creation, if the data field contains code.

  • @param [TransactionObject] transaction - The transaction object.

# File lib/api.rb, line 299
def send_transaction(transaction)
  result = @rpc.request("sendTransaction", transaction)
  return result
end
submit_block(block) click to toggle source

submit_block - Submits a block to the node. When the block is valid, the node will forward it to other nodes in the network. When submitting work from getWork, remember to include the suffix.

  • @param [String] block - Hex-encoded full block (including header, interlink and body).

# File lib/api.rb, line 307
def submit_block(block)
  result = @rpc.request("submitBlock", block)
  return result
end
syncing() click to toggle source

syncing - Returns an object with data about the sync status or `false`.

# File lib/api.rb, line 313
def syncing
  result = @rpc.request("syncing")
  return result
end