# Generated by API Builder - https://www.apibuilder.io # Service version: 0.0.1-SNAPSHOT # User agent: apibuilder app.apibuilder.io/gimbalabs/hilltop-api/0.0.1-SNAPSHOT/ruby_client require 'cgi' require 'net/http' require 'net/https' require 'uri' require 'base64' require 'date' require 'rubygems' require 'json' require 'bigdecimal' module Io module Gimbalabs module Hilltop module Api module V0 class Client module Constants BASE_URL = 'https://hilltop-api.mainnet.dandelion.link' unless defined?(Constants::BASE_URL) NAMESPACE = 'io.gimbalabs.hilltop.api.v0' unless defined?(Constants::NAMESPACE) USER_AGENT = 'apibuilder app.apibuilder.io/gimbalabs/hilltop-api/0.0.1-SNAPSHOT/ruby_client' unless defined?(Constants::USER_AGENT) VERSION = '0.0.1-SNAPSHOT' unless defined?(Constants::VERSION) VERSION_MAJOR = 0 unless defined?(VERSION_MAJOR) end attr_reader :url def initialize(url, opts={}) @url = HttpClient::Preconditions.assert_class('url', url, String) @base_url = URI(url) @authorization = HttpClient::Preconditions.assert_class_or_nil('authorization', opts.delete(:authorization), HttpClient::Authorization) @default_headers = HttpClient::Preconditions.assert_class('default_headers', opts.delete(:default_headers) || {}, Hash) @http_handler = opts.delete(:http_handler) || HttpClient::DefaultHttpHandler.new HttpClient::Preconditions.assert_empty_opts(opts) HttpClient::Preconditions.check_state(url.match(/http.+/i), "URL[%s] must start with http" % url) end # Creates an instance of the client using the base url specified in the API spec. def Client.at_base_url(opts={}) Client.new(Constants::BASE_URL, opts) end def request(path=nil) HttpClient::Preconditions.assert_class_or_nil('path', path, String) request = HttpClient::Request.new(@http_handler, @base_url, path.to_s).with_header('User-Agent', Constants::USER_AGENT).with_header('X-Apidoc-Version', Constants::VERSION).with_header('X-Apidoc-Version-Major', Constants::VERSION_MAJOR) @default_headers.each do |key, value| request = request.with_header(key, value) end if @authorization request = request.with_auth(@authorization) end request end def active_stake_amounts @active_stake_amounts ||= ::Io::Gimbalabs::Hilltop::Api::V0::Clients::ActiveStakeAmounts.new(self) end def blocks @blocks ||= ::Io::Gimbalabs::Hilltop::Api::V0::Clients::Blocks.new(self) end def delegations @delegations ||= ::Io::Gimbalabs::Hilltop::Api::V0::Clients::Delegations.new(self) end def delegators_counts @delegators_counts ||= ::Io::Gimbalabs::Hilltop::Api::V0::Clients::DelegatorsCounts.new(self) end def epochs @epochs ||= ::Io::Gimbalabs::Hilltop::Api::V0::Clients::Epochs.new(self) end def healthchecks @healthchecks ||= ::Io::Gimbalabs::Hilltop::Api::V0::Clients::Healthchecks.new(self) end def native_assets @native_assets ||= ::Io::Gimbalabs::Hilltop::Api::V0::Clients::NativeAssets.new(self) end def pool_updates @pool_updates ||= ::Io::Gimbalabs::Hilltop::Api::V0::Clients::PoolUpdates.new(self) end def rewards @rewards ||= ::Io::Gimbalabs::Hilltop::Api::V0::Clients::Rewards.new(self) end def sigmas @sigmas ||= ::Io::Gimbalabs::Hilltop::Api::V0::Clients::Sigmas.new(self) end def stakepools @stakepools ||= ::Io::Gimbalabs::Hilltop::Api::V0::Clients::Stakepools.new(self) end def stakepool_metadata @stakepool_metadata ||= ::Io::Gimbalabs::Hilltop::Api::V0::Clients::StakepoolMetadata.new(self) end def transactions @transactions ||= ::Io::Gimbalabs::Hilltop::Api::V0::Clients::Transactions.new(self) end def wallet_balances @wallet_balances ||= ::Io::Gimbalabs::Hilltop::Api::V0::Clients::WalletBalances.new(self) end end module Clients class ActiveStakeAmounts def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Gimbalabs::Hilltop::Api::V0::Client) end def get(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :epoch_number => (x = opts.delete(:epoch_number); x.nil? ? nil : HttpClient::Preconditions.assert_class('epoch_number', x, Integer)) }.delete_if { |k, v| v.nil? } r = @client.request("/active_stake_amounts").with_query(query).get ::Io::Gimbalabs::Hilltop::Api::V0::Models::ActiveStakeAmount.new(r) end def get_by_pool_bech32_id(pool_bech32_id, incoming={}) HttpClient::Preconditions.assert_class('pool_bech32_id', pool_bech32_id, String) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :epoch_number => (x = opts.delete(:epoch_number); x.nil? ? nil : HttpClient::Preconditions.assert_class('epoch_number', x, Integer)) }.delete_if { |k, v| v.nil? } r = @client.request("/active_stake_amounts/#{CGI.escape(pool_bech32_id)}").with_query(query).get ::Io::Gimbalabs::Hilltop::Api::V0::Models::ActiveStakeAmount.new(r) end def get_addresses_by_pool_bech32_id(pool_bech32_id, incoming={}) HttpClient::Preconditions.assert_class('pool_bech32_id', pool_bech32_id, String) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :epoch_number => HttpClient::Preconditions.assert_class('epoch_number', opts.delete(:epoch_number), Integer) }.delete_if { |k, v| v.nil? } r = @client.request("/active_stake_amounts/#{CGI.escape(pool_bech32_id)}/addresses").with_query(query).get r.map { |x| ::Io::Gimbalabs::Hilltop::Api::V0::Models::AddressStakeAmount.new(x) } end end class Blocks def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Gimbalabs::Hilltop::Api::V0::Client) end def get_blocks_in_day(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :date => HttpClient::Preconditions.assert_class('date', HttpClient::Helper.to_date_iso8601(opts.delete(:date)), Date) }.delete_if { |k, v| v.nil? } r = @client.request("/blocks/blocks_in_day").with_query(query).get ::Io::Gimbalabs::Hilltop::Api::V0::Models::DayBlock.new(r) end def get_by_block_number(block_number) HttpClient::Preconditions.assert_class('block_number', block_number, Integer) r = @client.request("/blocks/#{block_number}").get ::Io::Gimbalabs::Hilltop::Api::V0::Models::Block.new(r) end end class Delegations def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Gimbalabs::Hilltop::Api::V0::Client) end def get_safe_payment_by_staking_address(staking_address) HttpClient::Preconditions.assert_class('staking_address', staking_address, String) r = @client.request("/delegations/#{CGI.escape(staking_address)}/safe_payment").get r end def get_stakepool_by_staking_address(staking_address) HttpClient::Preconditions.assert_class('staking_address', staking_address, String) r = @client.request("/delegations/#{CGI.escape(staking_address)}/stakepool").get ::Io::Gimbalabs::Hilltop::Api::V0::Models::Delegation.new(r) end end class DelegatorsCounts def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Gimbalabs::Hilltop::Api::V0::Client) end def get_by_pool_bech32_id(pool_bech32_id) HttpClient::Preconditions.assert_class('pool_bech32_id', pool_bech32_id, String) r = @client.request("/delegators_counts/#{CGI.escape(pool_bech32_id)}").get ::Io::Gimbalabs::Hilltop::Api::V0::Models::DelegatorsCount.new(r) end end class Epochs def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Gimbalabs::Hilltop::Api::V0::Client) end def get_current r = @client.request("/epochs/current").get ::Io::Gimbalabs::Hilltop::Api::V0::Models::Epoch.new(r) end def get_by_epoch_number(epoch_number) HttpClient::Preconditions.assert_class('epoch_number', epoch_number, Integer) r = @client.request("/epochs/#{epoch_number}").get ::Io::Gimbalabs::Hilltop::Api::V0::Models::Epoch.new(r) end end class Healthchecks def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Gimbalabs::Hilltop::Api::V0::Client) end def get r = @client.request("/healthchecks").get ::Io::Gimbalabs::Hilltop::Api::V0::Models::Healthcheck.new(r) end end class NativeAssets def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Gimbalabs::Hilltop::Api::V0::Client) end def get_ids(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :block_number_from => (x = opts.delete(:block_number_from); x.nil? ? nil : HttpClient::Preconditions.assert_class('block_number_from', x, Integer)), :limit => (x = opts.delete(:limit); x.nil? ? nil : HttpClient::Preconditions.assert_class('limit', x, Integer)) }.delete_if { |k, v| v.nil? } r = @client.request("/native_assets/ids").with_query(query).get r.map { |x| ::Io::Gimbalabs::Hilltop::Api::V0::Models::NativeAssetId.new(x) } end def get_asset_names_by_policy_id(policy_id) HttpClient::Preconditions.assert_class('policy_id', policy_id, String) r = @client.request("/native_assets/#{CGI.escape(policy_id)}/asset_names").get r.map { |x| x } end def get_nfts(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :block_number_from => HttpClient::Preconditions.assert_class('block_number_from', opts.delete(:block_number_from), Integer), :block_number_to => HttpClient::Preconditions.assert_class('block_number_to', opts.delete(:block_number_to), Integer) }.delete_if { |k, v| v.nil? } r = @client.request("/native_assets/nfts").with_query(query).get r.map { |x| ::Io::Gimbalabs::Hilltop::Api::V0::Models::NftDetails.new(x) } end def post_native_assets_details(native_asset_details_request) (x = native_asset_details_request; x.is_a?(::Io::Gimbalabs::Hilltop::Api::V0::Models::NativeAssetDetailsRequest) ? x : ::Io::Gimbalabs::Hilltop::Api::V0::Models::NativeAssetDetailsRequest.new(x)) r = @client.request("/native_assets/native_assets_details").with_json(native_asset_details_request.to_json).post r.map { |x| ::Io::Gimbalabs::Hilltop::Api::V0::Models::NativeAssetDetails.new(x) } end def get_by_stake_address(stake_address) HttpClient::Preconditions.assert_class('stake_address', stake_address, String) r = @client.request("/native_assets/#{CGI.escape(stake_address)}").get r.map { |x| ::Io::Gimbalabs::Hilltop::Api::V0::Models::NativeAsset.new(x) } end end class PoolUpdates def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Gimbalabs::Hilltop::Api::V0::Client) end def get_retiring(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :block_number_from => (x = opts.delete(:block_number_from); x.nil? ? nil : HttpClient::Preconditions.assert_class('block_number_from', x, Integer)), :limit => (x = opts.delete(:limit); x.nil? ? nil : HttpClient::Preconditions.assert_class('limit', x, Integer)) }.delete_if { |k, v| v.nil? } r = @client.request("/pool_updates/retiring").with_query(query).get r.map { |x| ::Io::Gimbalabs::Hilltop::Api::V0::Models::PoolRetiring.new(x) } end def get_by_pool_id(pool_id, incoming={}) HttpClient::Preconditions.assert_class('pool_id', pool_id, String) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :block_number_from => (x = opts.delete(:block_number_from); x.nil? ? nil : HttpClient::Preconditions.assert_class('block_number_from', x, Integer)), :limit => (x = opts.delete(:limit); x.nil? ? nil : HttpClient::Preconditions.assert_class('limit', x, Integer)) }.delete_if { |k, v| v.nil? } r = @client.request("/pool_updates/#{CGI.escape(pool_id)}").with_query(query).get r.map { |x| ::Io::Gimbalabs::Hilltop::Api::V0::Models::PoolUpdate.new(x) } end def get(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :block_number_from => (x = opts.delete(:block_number_from); x.nil? ? nil : HttpClient::Preconditions.assert_class('block_number_from', x, Integer)), :limit => (x = opts.delete(:limit); x.nil? ? nil : HttpClient::Preconditions.assert_class('limit', x, Integer)) }.delete_if { |k, v| v.nil? } r = @client.request("/pool_updates").with_query(query).get r.map { |x| ::Io::Gimbalabs::Hilltop::Api::V0::Models::PoolUpdate.new(x) } end end class Rewards def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Gimbalabs::Hilltop::Api::V0::Client) end def get_by_staking_address(staking_address, incoming={}) HttpClient::Preconditions.assert_class('staking_address', staking_address, String) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :epoch_from => (x = opts.delete(:epoch_from); x.nil? ? nil : HttpClient::Preconditions.assert_class('epoch_from', x, Integer)), :epoch_to => (x = opts.delete(:epoch_to); x.nil? ? nil : HttpClient::Preconditions.assert_class('epoch_to', x, Integer)) }.delete_if { |k, v| v.nil? } r = @client.request("/rewards/#{CGI.escape(staking_address)}").with_query(query).get r.map { |x| ::Io::Gimbalabs::Hilltop::Api::V0::Models::Reward.new(x) } end end class Sigmas def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Gimbalabs::Hilltop::Api::V0::Client) end # can be either the pool_id (e.g. pool1wcwe923r...) or the pool_hash def get_by_pool_id(pool_id, incoming={}) HttpClient::Preconditions.assert_class('pool_id', pool_id, String) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :epoch_number => HttpClient::Preconditions.assert_class('epoch_number', opts.delete(:epoch_number), Integer) }.delete_if { |k, v| v.nil? } r = @client.request("/sigmas/#{CGI.escape(pool_id)}").with_query(query).get ::Io::Gimbalabs::Hilltop::Api::V0::Models::Sigma.new(r) end end class Stakepools def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Gimbalabs::Hilltop::Api::V0::Client) end # find pool details by vrf_vkey def get_vrf_vkey_by_vrf_vkey_hash(vrf_vkey_hash) HttpClient::Preconditions.assert_class('vrf_vkey_hash', vrf_vkey_hash, String) r = @client.request("/stakepools/vrf_vkey/#{CGI.escape(vrf_vkey_hash)}").get ::Io::Gimbalabs::Hilltop::Api::V0::Models::Stakepool.new(r) end # Epoch at which stake pool was originally registered def get_established_epoch_by_pool_id(pool_id) HttpClient::Preconditions.assert_class('pool_id', pool_id, String) r = @client.request("/stakepools/#{CGI.escape(pool_id)}/established_epoch").get r end # live stake in lovelaces def get_live_stake_by_pool_id(pool_id) HttpClient::Preconditions.assert_class('pool_id', pool_id, String) r = @client.request("/stakepools/#{CGI.escape(pool_id)}/live_stake").get r end # number minted blocks in epoch def get_blocks_by_pool_id(pool_id, incoming={}) HttpClient::Preconditions.assert_class('pool_id', pool_id, String) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :epoch => (x = opts.delete(:epoch); x.nil? ? nil : HttpClient::Preconditions.assert_class('epoch', x, Integer)) }.delete_if { |k, v| v.nil? } r = @client.request("/stakepools/#{CGI.escape(pool_id)}/blocks").with_query(query).get r end def get r = @client.request("/stakepools").get r.map { |x| ::Io::Gimbalabs::Hilltop::Api::V0::Models::Stakepool.new(x) } end end class StakepoolMetadata def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Gimbalabs::Hilltop::Api::V0::Client) end def get_by_pool_id_bech32(pool_id_bech32) HttpClient::Preconditions.assert_class('pool_id_bech32', pool_id_bech32, String) r = @client.request("/stakepool_metadata/#{CGI.escape(pool_id_bech32)}").get ::Io::Gimbalabs::Hilltop::Api::V0::Models::StakepoolMetadata.new(r) end end class Transactions def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Gimbalabs::Hilltop::Api::V0::Client) end def post_history(transaction_history_request) (x = transaction_history_request; x.is_a?(::Io::Gimbalabs::Hilltop::Api::V0::Models::TransactionHistoryRequest) ? x : ::Io::Gimbalabs::Hilltop::Api::V0::Models::TransactionHistoryRequest.new(x)) r = @client.request("/transactions/history").with_json(transaction_history_request.to_json).post r.map { |x| ::Io::Gimbalabs::Hilltop::Api::V0::Models::Transaction.new(x) } end end class WalletBalances def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Gimbalabs::Hilltop::Api::V0::Client) end def get_by_staking_address(staking_address) HttpClient::Preconditions.assert_class('staking_address', staking_address, String) r = @client.request("/wallet_balances/#{CGI.escape(staking_address)}").get ::Io::Gimbalabs::Hilltop::Api::V0::Models::WalletBalance.new(r) end end end module Models class Country attr_reader :value def initialize(value) @value = HttpClient::Preconditions.assert_class('value', value, String) end # Returns the instance of Country for this value, creating a new instance for an unknown value def Country.apply(value) if value.instance_of?(Country) value else HttpClient::Preconditions.assert_class_or_nil('value', value, String) value.nil? ? nil : (from_string(value) || Country.new(value)) end end # Returns the instance of Country for this value, or nil if not found def Country.from_string(value) HttpClient::Preconditions.assert_class('value', value, String) Country.ALL.find { |v| v.value == value } end def Country.ALL @@all ||= [Country.ie, Country.uk] end def Country.ie @@_ie ||= Country.new('IE') end def Country.uk @@_uk ||= Country.new('UK') end def to_hash value end end class ActiveStakeAmount attr_reader :amount_in_lovelaces def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:amount_in_lovelaces], 'ActiveStakeAmount') @amount_in_lovelaces = HttpClient::Preconditions.assert_class('amount_in_lovelaces', opts.delete(:amount_in_lovelaces), Integer) end def to_json JSON.dump(to_hash) end def copy(incoming={}) ActiveStakeAmount.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :amount_in_lovelaces => amount_in_lovelaces } end end class AddressStakeAmount attr_reader :stake_address, :amount_in_lovelaces def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:stake_address, :amount_in_lovelaces], 'AddressStakeAmount') @stake_address = HttpClient::Preconditions.assert_class('stake_address', opts.delete(:stake_address), String) @amount_in_lovelaces = HttpClient::Preconditions.assert_class('amount_in_lovelaces', opts.delete(:amount_in_lovelaces), Integer) end def to_json JSON.dump(to_hash) end def copy(incoming={}) AddressStakeAmount.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :stake_address => stake_address, :amount_in_lovelaces => amount_in_lovelaces } end end class Block attr_reader :number, :epoch_number, :slot_number, :epoch_slot_number, :size, :transaction_count, :time def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:number, :epoch_number, :slot_number, :epoch_slot_number, :size, :transaction_count, :time], 'Block') @number = HttpClient::Preconditions.assert_class('number', opts.delete(:number), Integer) @epoch_number = HttpClient::Preconditions.assert_class('epoch_number', opts.delete(:epoch_number), Integer) @slot_number = HttpClient::Preconditions.assert_class('slot_number', opts.delete(:slot_number), Integer) @epoch_slot_number = HttpClient::Preconditions.assert_class('epoch_slot_number', opts.delete(:epoch_slot_number), Integer) @size = HttpClient::Preconditions.assert_class('size', opts.delete(:size), Integer) @transaction_count = HttpClient::Preconditions.assert_class('transaction_count', opts.delete(:transaction_count), Integer) @time = HttpClient::Preconditions.assert_class('time', HttpClient::Helper.to_date_time_iso8601(opts.delete(:time)), DateTime) end def to_json JSON.dump(to_hash) end def copy(incoming={}) Block.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :number => number, :epoch_number => epoch_number, :slot_number => slot_number, :epoch_slot_number => epoch_slot_number, :size => size, :transaction_count => transaction_count, :time => time } end end class CnftMetadataV001 attr_reader :policyId, :tokens, :asset def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:policyId, :tokens, :asset], 'CnftMetadataV001') @policyId = HttpClient::Preconditions.assert_class('policyId', opts.delete(:policyId), String) @tokens = HttpClient::Preconditions.assert_class('tokens', opts.delete(:tokens), Hash).inject({}) { |h, d| h[d[0]] = HttpClient::Preconditions.assert_class('tokens', d[1], String); h } @asset = (x = opts.delete(:asset); x.is_a?(::Io::Gimbalabs::Hilltop::Api::V0::Models::CnftMetadataV001Asset) ? x : ::Io::Gimbalabs::Hilltop::Api::V0::Models::CnftMetadataV001Asset.new(x)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) CnftMetadataV001.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :policyId => policyId, :tokens => tokens, :asset => asset.to_hash } end end class CnftMetadataV001Asset attr_reader :assetName, :attributes, :ipfs, :mimeType def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:ipfs], 'CnftMetadataV001Asset') @assetName = (x = opts.delete(:assetName); x.nil? ? nil : HttpClient::Preconditions.assert_class('assetName', x, String)) @attributes = (x = opts.delete(:attributes); x.nil? ? nil : HttpClient::Preconditions.assert_class('attributes', x, BasicObject)) @ipfs = HttpClient::Preconditions.assert_class('ipfs', opts.delete(:ipfs), String) @mimeType = (x = opts.delete(:mimeType); x.nil? ? nil : HttpClient::Preconditions.assert_class('mimeType', x, String)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) CnftMetadataV001Asset.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :assetName => assetName, :attributes => attributes, :ipfs => ipfs, :mimeType => mimeType } end end class DayBlock attr_reader :first, :last def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:first, :last], 'DayBlock') @first = (x = opts.delete(:first); x.is_a?(::Io::Gimbalabs::Hilltop::Api::V0::Models::Block) ? x : ::Io::Gimbalabs::Hilltop::Api::V0::Models::Block.new(x)) @last = (x = opts.delete(:last); x.is_a?(::Io::Gimbalabs::Hilltop::Api::V0::Models::Block) ? x : ::Io::Gimbalabs::Hilltop::Api::V0::Models::Block.new(x)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) DayBlock.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :first => first.to_hash, :last => last.to_hash } end end class Delegation attr_reader :staking_address, :delegations def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:staking_address, :delegations], 'Delegation') @staking_address = HttpClient::Preconditions.assert_class('staking_address', opts.delete(:staking_address), String) @delegations = HttpClient::Preconditions.assert_class('delegations', opts.delete(:delegations), Array).map { |v| (x = v; x.is_a?(::Io::Gimbalabs::Hilltop::Api::V0::Models::StakepoolDelegation) ? x : ::Io::Gimbalabs::Hilltop::Api::V0::Models::StakepoolDelegation.new(x)) } end def to_json JSON.dump(to_hash) end def copy(incoming={}) Delegation.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :staking_address => staking_address, :delegations => delegations.map { |o| o.to_hash } } end end class DelegatorsCount attr_reader :delegators_count_total def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:delegators_count_total], 'DelegatorsCount') @delegators_count_total = HttpClient::Preconditions.assert_class('delegators_count_total', opts.delete(:delegators_count_total), Integer) end def to_json JSON.dump(to_hash) end def copy(incoming={}) DelegatorsCount.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :delegators_count_total => delegators_count_total } end end class Epoch attr_reader :out_sum, :fees, :tx_count, :blk_count, :number, :start_time, :end_time def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:out_sum, :fees, :tx_count, :blk_count, :number, :start_time, :end_time], 'Epoch') @out_sum = HttpClient::Preconditions.assert_class('out_sum', opts.delete(:out_sum), Integer) @fees = HttpClient::Preconditions.assert_class('fees', opts.delete(:fees), Integer) @tx_count = HttpClient::Preconditions.assert_class('tx_count', opts.delete(:tx_count), Integer) @blk_count = HttpClient::Preconditions.assert_class('blk_count', opts.delete(:blk_count), Integer) @number = HttpClient::Preconditions.assert_class('number', opts.delete(:number), Integer) @start_time = HttpClient::Preconditions.assert_class('start_time', HttpClient::Helper.to_date_time_iso8601(opts.delete(:start_time)), DateTime) @end_time = HttpClient::Preconditions.assert_class('end_time', HttpClient::Helper.to_date_time_iso8601(opts.delete(:end_time)), DateTime) end def to_json JSON.dump(to_hash) end def copy(incoming={}) Epoch.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :out_sum => out_sum, :fees => fees, :tx_count => tx_count, :blk_count => blk_count, :number => number, :start_time => start_time, :end_time => end_time } end end class GenericError attr_reader :description def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:description], 'GenericError') @description = HttpClient::Preconditions.assert_class('description', opts.delete(:description), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) GenericError.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :description => description } end end # Response for the healthcheck's endpoint of the service class Healthcheck attr_reader :status def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:status], 'Healthcheck') @status = HttpClient::Preconditions.assert_class('status', opts.delete(:status), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) Healthcheck.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :status => status } end end class NativeAsset attr_reader :transaction_id, :policy_id, :token_name, :metadata, :block_number, :epoch_slot_number, :epoch_number, :invalid_before, :invalid_hereafter, :quantity def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:transaction_id, :policy_id, :token_name, :metadata, :block_number, :epoch_slot_number, :epoch_number, :quantity], 'NativeAsset') @transaction_id = HttpClient::Preconditions.assert_class('transaction_id', opts.delete(:transaction_id), String) @policy_id = HttpClient::Preconditions.assert_class('policy_id', opts.delete(:policy_id), String) @token_name = HttpClient::Preconditions.assert_class('token_name', opts.delete(:token_name), String) @metadata = HttpClient::Preconditions.assert_class('metadata', opts.delete(:metadata), BasicObject) @block_number = HttpClient::Preconditions.assert_class('block_number', opts.delete(:block_number), Integer) @epoch_slot_number = HttpClient::Preconditions.assert_class('epoch_slot_number', opts.delete(:epoch_slot_number), Integer) @epoch_number = HttpClient::Preconditions.assert_class('epoch_number', opts.delete(:epoch_number), Integer) @invalid_before = (x = opts.delete(:invalid_before); x.nil? ? nil : HttpClient::Preconditions.assert_class('invalid_before', x, Integer)) @invalid_hereafter = (x = opts.delete(:invalid_hereafter); x.nil? ? nil : HttpClient::Preconditions.assert_class('invalid_hereafter', x, Integer)) @quantity = HttpClient::Preconditions.assert_class('quantity', opts.delete(:quantity), Integer) end def to_json JSON.dump(to_hash) end def copy(incoming={}) NativeAsset.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :transaction_id => transaction_id, :policy_id => policy_id, :token_name => token_name, :metadata => metadata, :block_number => block_number, :epoch_slot_number => epoch_slot_number, :epoch_number => epoch_number, :invalid_before => invalid_before, :invalid_hereafter => invalid_hereafter, :quantity => quantity } end end class NativeAssetDetails attr_reader :policy_id, :asset_name, :metadata, :minted_at, :last_minted_at, :first_minting_tx_block, :last_minting_tx_block, :minting_tx_hash, :circulating_supply, :fingerprint def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:policy_id, :asset_name, :metadata, :minted_at, :last_minted_at, :first_minting_tx_block, :last_minting_tx_block, :minting_tx_hash, :circulating_supply, :fingerprint], 'NativeAssetDetails') @policy_id = HttpClient::Preconditions.assert_class('policy_id', opts.delete(:policy_id), String) @asset_name = HttpClient::Preconditions.assert_class('asset_name', opts.delete(:asset_name), String) @metadata = HttpClient::Preconditions.assert_class('metadata', opts.delete(:metadata), BasicObject) @minted_at = HttpClient::Preconditions.assert_class('minted_at', HttpClient::Helper.to_date_time_iso8601(opts.delete(:minted_at)), DateTime) @last_minted_at = HttpClient::Preconditions.assert_class('last_minted_at', HttpClient::Helper.to_date_time_iso8601(opts.delete(:last_minted_at)), DateTime) @first_minting_tx_block = HttpClient::Preconditions.assert_class('first_minting_tx_block', opts.delete(:first_minting_tx_block), Integer) @last_minting_tx_block = HttpClient::Preconditions.assert_class('last_minting_tx_block', opts.delete(:last_minting_tx_block), Integer) @minting_tx_hash = HttpClient::Preconditions.assert_class('minting_tx_hash', opts.delete(:minting_tx_hash), String) @circulating_supply = HttpClient::Preconditions.assert_class('circulating_supply', opts.delete(:circulating_supply), Integer) @fingerprint = HttpClient::Preconditions.assert_class('fingerprint', opts.delete(:fingerprint), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) NativeAssetDetails.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :policy_id => policy_id, :asset_name => asset_name, :metadata => metadata, :minted_at => minted_at, :last_minted_at => last_minted_at, :first_minting_tx_block => first_minting_tx_block, :last_minting_tx_block => last_minting_tx_block, :minting_tx_hash => minting_tx_hash, :circulating_supply => circulating_supply, :fingerprint => fingerprint } end end class NativeAssetDetailsRequest attr_reader :policy_id, :asset_names def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:policy_id], 'NativeAssetDetailsRequest') @policy_id = HttpClient::Preconditions.assert_class('policy_id', opts.delete(:policy_id), String) @asset_names = (x = opts.delete(:asset_names); x.nil? ? nil : HttpClient::Preconditions.assert_class('asset_names', x, Array).map { |v| HttpClient::Preconditions.assert_class('asset_names', v, String) }) end def to_json JSON.dump(to_hash) end def copy(incoming={}) NativeAssetDetailsRequest.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :policy_id => policy_id, :asset_names => asset_names.nil? ? nil : asset_names } end end class NativeAssetId attr_reader :policy_id, :asset_name, :block_number, :block_time, :fingerprint def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:policy_id, :asset_name, :block_number, :block_time, :fingerprint], 'NativeAssetId') @policy_id = HttpClient::Preconditions.assert_class('policy_id', opts.delete(:policy_id), String) @asset_name = HttpClient::Preconditions.assert_class('asset_name', opts.delete(:asset_name), String) @block_number = HttpClient::Preconditions.assert_class('block_number', opts.delete(:block_number), Integer) @block_time = HttpClient::Preconditions.assert_class('block_time', HttpClient::Helper.to_date_time_iso8601(opts.delete(:block_time)), DateTime) @fingerprint = HttpClient::Preconditions.assert_class('fingerprint', opts.delete(:fingerprint), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) NativeAssetId.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :policy_id => policy_id, :asset_name => asset_name, :block_number => block_number, :block_time => block_time, :fingerprint => fingerprint } end end class NftDetails attr_reader :policy_id, :asset_name_raw, :asset_name, :metadata, :minted_at, :minted_at_block, :minting_tx_hash, :amount, :fingerprint def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:policy_id, :asset_name_raw, :metadata, :minted_at, :minted_at_block, :minting_tx_hash, :amount, :fingerprint], 'NftDetails') @policy_id = HttpClient::Preconditions.assert_class('policy_id', opts.delete(:policy_id), String) @asset_name_raw = HttpClient::Preconditions.assert_class('asset_name_raw', opts.delete(:asset_name_raw), String) @asset_name = (x = opts.delete(:asset_name); x.nil? ? nil : HttpClient::Preconditions.assert_class('asset_name', x, String)) @metadata = HttpClient::Preconditions.assert_class('metadata', opts.delete(:metadata), BasicObject) @minted_at = HttpClient::Preconditions.assert_class('minted_at', HttpClient::Helper.to_date_time_iso8601(opts.delete(:minted_at)), DateTime) @minted_at_block = HttpClient::Preconditions.assert_class('minted_at_block', opts.delete(:minted_at_block), Integer) @minting_tx_hash = HttpClient::Preconditions.assert_class('minting_tx_hash', opts.delete(:minting_tx_hash), String) @amount = HttpClient::Preconditions.assert_class('amount', opts.delete(:amount), Integer) @fingerprint = HttpClient::Preconditions.assert_class('fingerprint', opts.delete(:fingerprint), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) NftDetails.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :policy_id => policy_id, :asset_name_raw => asset_name_raw, :asset_name => asset_name, :metadata => metadata, :minted_at => minted_at, :minted_at_block => minted_at_block, :minting_tx_hash => minting_tx_hash, :amount => amount, :fingerprint => fingerprint } end end class NftMetadata attr_reader :name, :image, :mediaType, :files def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) @name = (x = opts.delete(:name); x.nil? ? nil : HttpClient::Preconditions.assert_class('name', x, String)) @image = (x = opts.delete(:image); x.nil? ? nil : HttpClient::Preconditions.assert_class('image', x, String)) @mediaType = (x = opts.delete(:mediaType); x.nil? ? nil : HttpClient::Preconditions.assert_class('mediaType', x, String)) @files = (x = opts.delete(:files); x.nil? ? nil : HttpClient::Preconditions.assert_class('files', x, Array).map { |v| (x = v; x.is_a?(::Io::Gimbalabs::Hilltop::Api::V0::Models::NftMetadataFile) ? x : ::Io::Gimbalabs::Hilltop::Api::V0::Models::NftMetadataFile.new(x)) }) end def to_json JSON.dump(to_hash) end def copy(incoming={}) NftMetadata.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :name => name, :image => image, :mediaType => mediaType, :files => files.nil? ? nil : files.map { |o| o.to_hash } } end end class NftMetadataFile attr_reader :name, :src, :mediaType def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) @name = (x = opts.delete(:name); x.nil? ? nil : HttpClient::Preconditions.assert_class('name', x, String)) @src = (x = opts.delete(:src); x.nil? ? nil : HttpClient::Preconditions.assert_class('src', x, String)) @mediaType = (x = opts.delete(:mediaType); x.nil? ? nil : HttpClient::Preconditions.assert_class('mediaType', x, String)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) NftMetadataFile.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :name => name, :src => src, :mediaType => mediaType } end end class NftMetadataFilesAsObject attr_reader :name, :image, :mediaType, :files def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) @name = (x = opts.delete(:name); x.nil? ? nil : HttpClient::Preconditions.assert_class('name', x, String)) @image = (x = opts.delete(:image); x.nil? ? nil : HttpClient::Preconditions.assert_class('image', x, String)) @mediaType = (x = opts.delete(:mediaType); x.nil? ? nil : HttpClient::Preconditions.assert_class('mediaType', x, String)) @files = (x = opts.delete(:files); x.nil? ? nil : (x = x; x.is_a?(::Io::Gimbalabs::Hilltop::Api::V0::Models::NftMetadataFile) ? x : ::Io::Gimbalabs::Hilltop::Api::V0::Models::NftMetadataFile.new(x))) end def to_json JSON.dump(to_hash) end def copy(incoming={}) NftMetadataFilesAsObject.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :name => name, :image => image, :mediaType => mediaType, :files => files.nil? ? nil : files.to_hash } end end class NftMetadataImgArray attr_reader :name, :image, :mediaType, :files def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) @name = (x = opts.delete(:name); x.nil? ? nil : HttpClient::Preconditions.assert_class('name', x, String)) @image = (x = opts.delete(:image); x.nil? ? nil : HttpClient::Preconditions.assert_class('image', x, Array).map { |v| HttpClient::Preconditions.assert_class('image', v, String) }) @mediaType = (x = opts.delete(:mediaType); x.nil? ? nil : HttpClient::Preconditions.assert_class('mediaType', x, String)) @files = (x = opts.delete(:files); x.nil? ? nil : HttpClient::Preconditions.assert_class('files', x, Array).map { |v| (x = v; x.is_a?(::Io::Gimbalabs::Hilltop::Api::V0::Models::NftMetadataFile) ? x : ::Io::Gimbalabs::Hilltop::Api::V0::Models::NftMetadataFile.new(x)) }) end def to_json JSON.dump(to_hash) end def copy(incoming={}) NftMetadataImgArray.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :name => name, :image => image.nil? ? nil : image, :mediaType => mediaType, :files => files.nil? ? nil : files.map { |o| o.to_hash } } end end class NftMetadataNoFiles attr_reader :name, :image, :mediaType def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) @name = (x = opts.delete(:name); x.nil? ? nil : HttpClient::Preconditions.assert_class('name', x, String)) @image = (x = opts.delete(:image); x.nil? ? nil : HttpClient::Preconditions.assert_class('image', x, String)) @mediaType = (x = opts.delete(:mediaType); x.nil? ? nil : HttpClient::Preconditions.assert_class('mediaType', x, String)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) NftMetadataNoFiles.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :name => name, :image => image, :mediaType => mediaType } end end class PoolRetiring attr_reader :ticker_name, :pool_id, :certificate_index, :epoch_number, :block_number, :retiring_at_epoch, :tx_hash def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:pool_id, :certificate_index, :epoch_number, :block_number, :retiring_at_epoch, :tx_hash], 'PoolRetiring') @ticker_name = (x = opts.delete(:ticker_name); x.nil? ? nil : HttpClient::Preconditions.assert_class('ticker_name', x, String)) @pool_id = HttpClient::Preconditions.assert_class('pool_id', opts.delete(:pool_id), String) @certificate_index = HttpClient::Preconditions.assert_class('certificate_index', opts.delete(:certificate_index), Integer) @epoch_number = HttpClient::Preconditions.assert_class('epoch_number', opts.delete(:epoch_number), Integer) @block_number = HttpClient::Preconditions.assert_class('block_number', opts.delete(:block_number), Integer) @retiring_at_epoch = HttpClient::Preconditions.assert_class('retiring_at_epoch', opts.delete(:retiring_at_epoch), Integer) @tx_hash = HttpClient::Preconditions.assert_class('tx_hash', opts.delete(:tx_hash), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) PoolRetiring.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :ticker_name => ticker_name, :pool_id => pool_id, :certificate_index => certificate_index, :epoch_number => epoch_number, :block_number => block_number, :retiring_at_epoch => retiring_at_epoch, :tx_hash => tx_hash } end end class PoolUpdate attr_reader :epoch_number, :block_number, :tx_hash, :pool_ticker_name, :pool_bech32_id, :certificate_index, :vrf_key_hash, :pledge, :reward_address, :active_epoch_number, :margin, :fixed_cost def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:epoch_number, :block_number, :tx_hash, :pool_bech32_id, :certificate_index, :vrf_key_hash, :pledge, :reward_address, :active_epoch_number, :margin, :fixed_cost], 'PoolUpdate') @epoch_number = HttpClient::Preconditions.assert_class('epoch_number', opts.delete(:epoch_number), Integer) @block_number = HttpClient::Preconditions.assert_class('block_number', opts.delete(:block_number), Integer) @tx_hash = HttpClient::Preconditions.assert_class('tx_hash', opts.delete(:tx_hash), String) @pool_ticker_name = (x = opts.delete(:pool_ticker_name); x.nil? ? nil : HttpClient::Preconditions.assert_class('pool_ticker_name', x, String)) @pool_bech32_id = HttpClient::Preconditions.assert_class('pool_bech32_id', opts.delete(:pool_bech32_id), String) @certificate_index = HttpClient::Preconditions.assert_class('certificate_index', opts.delete(:certificate_index), Integer) @vrf_key_hash = HttpClient::Preconditions.assert_class('vrf_key_hash', opts.delete(:vrf_key_hash), String) @pledge = HttpClient::Preconditions.assert_class('pledge', opts.delete(:pledge), Integer) @reward_address = HttpClient::Preconditions.assert_class('reward_address', opts.delete(:reward_address), String) @active_epoch_number = HttpClient::Preconditions.assert_class('active_epoch_number', opts.delete(:active_epoch_number), Integer) @margin = HttpClient::Preconditions.assert_class('margin', opts.delete(:margin), Numeric) @fixed_cost = HttpClient::Preconditions.assert_class('fixed_cost', opts.delete(:fixed_cost), Integer) end def to_json JSON.dump(to_hash) end def copy(incoming={}) PoolUpdate.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :epoch_number => epoch_number, :block_number => block_number, :tx_hash => tx_hash, :pool_ticker_name => pool_ticker_name, :pool_bech32_id => pool_bech32_id, :certificate_index => certificate_index, :vrf_key_hash => vrf_key_hash, :pledge => pledge, :reward_address => reward_address, :active_epoch_number => active_epoch_number, :margin => margin, :fixed_cost => fixed_cost } end end class Reward attr_reader :staking_address, :epoch, :amount, :pool_id def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:staking_address, :epoch, :amount, :pool_id], 'Reward') @staking_address = HttpClient::Preconditions.assert_class('staking_address', opts.delete(:staking_address), String) @epoch = HttpClient::Preconditions.assert_class('epoch', opts.delete(:epoch), Integer) @amount = HttpClient::Preconditions.assert_class('amount', opts.delete(:amount), Integer) @pool_id = HttpClient::Preconditions.assert_class('pool_id', opts.delete(:pool_id), String) end def to_json JSON.dump(to_hash) end def copy(incoming={}) Reward.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :staking_address => staking_address, :epoch => epoch, :amount => amount, :pool_id => pool_id } end end class Sigma attr_reader :sigma, :epoch, :total_staked, :active_stake, :nonce, :d def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:sigma, :epoch, :total_staked, :active_stake, :nonce, :d], 'Sigma') @sigma = HttpClient::Preconditions.assert_class('sigma', opts.delete(:sigma), Numeric) @epoch = HttpClient::Preconditions.assert_class('epoch', opts.delete(:epoch), Integer) @total_staked = HttpClient::Preconditions.assert_class('total_staked', opts.delete(:total_staked), Integer) @active_stake = HttpClient::Preconditions.assert_class('active_stake', opts.delete(:active_stake), Integer) @nonce = HttpClient::Preconditions.assert_class('nonce', opts.delete(:nonce), String) @d = HttpClient::Preconditions.assert_class('d', opts.delete(:d), Numeric) end def to_json JSON.dump(to_hash) end def copy(incoming={}) Sigma.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :sigma => sigma, :epoch => epoch, :total_staked => total_staked, :active_stake => active_stake, :nonce => nonce, :d => d } end end class Stakepool attr_reader :id, :pool_id_bech32, :metadata, :cost, :margin, :pledge, :active_stake, :saturation, :retiring_at_epoch def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:id, :pool_id_bech32, :cost, :margin, :pledge, :active_stake, :saturation], 'Stakepool') @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String) @pool_id_bech32 = HttpClient::Preconditions.assert_class('pool_id_bech32', opts.delete(:pool_id_bech32), String) @metadata = (x = opts.delete(:metadata); x.nil? ? nil : (x = x; x.is_a?(::Io::Gimbalabs::Hilltop::Api::V0::Models::StakepoolMetadata) ? x : ::Io::Gimbalabs::Hilltop::Api::V0::Models::StakepoolMetadata.new(x))) @cost = HttpClient::Preconditions.assert_class('cost', opts.delete(:cost), Integer) @margin = HttpClient::Preconditions.assert_class('margin', opts.delete(:margin), Numeric) @pledge = HttpClient::Preconditions.assert_class('pledge', opts.delete(:pledge), Integer) @active_stake = HttpClient::Preconditions.assert_class('active_stake', opts.delete(:active_stake), Integer) @saturation = HttpClient::Preconditions.assert_class('saturation', opts.delete(:saturation), Numeric) @retiring_at_epoch = (x = opts.delete(:retiring_at_epoch); x.nil? ? nil : HttpClient::Preconditions.assert_class('retiring_at_epoch', x, Integer)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) Stakepool.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :id => id, :pool_id_bech32 => pool_id_bech32, :metadata => metadata.nil? ? nil : metadata.to_hash, :cost => cost, :margin => margin, :pledge => pledge, :active_stake => active_stake, :saturation => saturation, :retiring_at_epoch => retiring_at_epoch } end end class StakepoolDelegation attr_reader :stakepool, :epoch def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:stakepool, :epoch], 'StakepoolDelegation') @stakepool = (x = opts.delete(:stakepool); x.is_a?(::Io::Gimbalabs::Hilltop::Api::V0::Models::Stakepool) ? x : ::Io::Gimbalabs::Hilltop::Api::V0::Models::Stakepool.new(x)) @epoch = HttpClient::Preconditions.assert_class('epoch', opts.delete(:epoch), Integer) end def to_json JSON.dump(to_hash) end def copy(incoming={}) StakepoolDelegation.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :stakepool => stakepool.to_hash, :epoch => epoch } end end # Stake Pool Offline Metadata class StakepoolMetadata attr_reader :name, :ticker, :homepage, :description, :extended def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:name, :ticker, :homepage, :description], 'StakepoolMetadata') @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String) @ticker = HttpClient::Preconditions.assert_class('ticker', opts.delete(:ticker), String) @homepage = HttpClient::Preconditions.assert_class('homepage', opts.delete(:homepage), String) @description = HttpClient::Preconditions.assert_class('description', opts.delete(:description), String) @extended = (x = opts.delete(:extended); x.nil? ? nil : HttpClient::Preconditions.assert_class('extended', x, String)) end def to_json JSON.dump(to_hash) end def copy(incoming={}) StakepoolMetadata.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :name => name, :ticker => ticker, :homepage => homepage, :description => description, :extended => extended } end end class Transaction attr_reader :hash, :block, :timestamp def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:hash, :block, :timestamp], 'Transaction') @hash = HttpClient::Preconditions.assert_class('hash', opts.delete(:hash), String) @block = HttpClient::Preconditions.assert_class('block', opts.delete(:block), Integer) @timestamp = HttpClient::Preconditions.assert_class('timestamp', HttpClient::Helper.to_date_time_iso8601(opts.delete(:timestamp)), DateTime) end def to_json JSON.dump(to_hash) end def copy(incoming={}) Transaction.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :hash => hash, :block => block, :timestamp => timestamp } end end class TransactionHistoryRequest attr_reader :addresses def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:addresses], 'TransactionHistoryRequest') @addresses = HttpClient::Preconditions.assert_class('addresses', opts.delete(:addresses), Array).map { |v| HttpClient::Preconditions.assert_class('addresses', v, String) } end def to_json JSON.dump(to_hash) end def copy(incoming={}) TransactionHistoryRequest.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :addresses => addresses } end end class WalletBalance attr_reader :balance def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:balance], 'WalletBalance') @balance = HttpClient::Preconditions.assert_class('balance', opts.delete(:balance), Integer) end def to_json JSON.dump(to_hash) end def copy(incoming={}) WalletBalance.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end def to_hash { :balance => balance } end end end # ===== END OF SERVICE DEFINITION ===== module HttpClient class HttpHandler # Returns a client instance to use # # @param base_uri The base URI for this API # @param path the Requested full http path (including any query strings) def instance(base_uri, path) raise "Override in subclass" end end class HttpHandlerInstance # Executes a request. The provided request object will be an # instance of Net::HTTP (e.g. Net::HTTP::Get) def execute(request) raise "Override in subclass" end end class DefaultHttpHandler < HttpHandler def instance(base_uri, path) DefaultHttpHandlerInstance.new(base_uri) end end class DefaultHttpHandlerInstance < HttpHandlerInstance attr_reader :client def initialize(base_uri) @base_uri = Preconditions.assert_class('base_uri', base_uri, URI) @client = Net::HTTP.new(@base_uri.host, @base_uri.port) if @base_uri.scheme == "https" configure_ssl end end def execute(request) response = begin @client.request(request) rescue SocketError => e raise StandardError.new("Error accessing uri[#{full_uri(request.path)}]: #{e}") end case response when Net::HTTPSuccess response.body else body = response.body rescue nil raise HttpClient::ServerError.new(response.code.to_i, response.message, :body => body, :uri => full_uri(request.path).to_s) end end def full_uri(path) path.start_with?(@base_uri.to_s) ? path : File.join(@base_uri.to_s, path) end # Called to configure SSL if the base uri requires it def configure_ssl @client.use_ssl = true @client.verify_mode = OpenSSL::SSL::VERIFY_PEER @client.cert_store = OpenSSL::X509::Store.new @client.cert_store.set_default_paths end end class Request attr_reader :base_uri, :path, :full_uri def initialize(http_handler, base_uri, path) @http_handler = http_handler @base_uri = Preconditions.assert_class('base_uri', base_uri, URI) @path = Preconditions.assert_class('path', path, String) @full_uri = @base_uri.to_s + @path @params = nil @body = nil @auth = nil @headers = {} @header_keys_lower_case = [] end def with_header(name, value) Preconditions.check_not_blank('name', name, "Header name is required") Preconditions.check_not_blank('value', value, "Header value is required") Preconditions.check_state(!@headers.has_key?(name), "Duplicate header named[%s]" % name) @headers[name] = value @header_keys_lower_case << name.downcase self end def with_auth(auth) Preconditions.assert_class('auth', auth, HttpClient::Authorization) Preconditions.check_state(@auth.nil?, "auth previously set") if auth.scheme.name == AuthScheme::BASIC.name @auth = auth else raise "Auth Scheme[#{auth.scheme.name}] not supported" end self end def with_query(params) Preconditions.assert_class('params', params, Hash) Preconditions.check_state(@params.nil?, "Already have query parameters") @params = params self end # Wrapper to set Content-Type header to application/json and set # the provided json document as the body def with_json(json) @headers['Content-Type'] ||= 'application/json; charset=UTF-8' with_body(json) end def with_body(body) Preconditions.check_not_blank('body', body) @body = body self end def get(&block) do_request(Net::HTTP::Get, &block) end def delete(&block) do_request(Net::HTTP::Delete, &block) end def options(&block) do_request(Net::HTTP::Options, &block) end def post(&block) do_request(Net::HTTP::Post, &block) end def put(&block) do_request(Net::HTTP::Put, &block) end class PATCH < Net::HTTP::Put METHOD = "PATCH" end def patch(&block) do_request(PATCH, &block) end def do_request(klass) Preconditions.assert_class('klass', klass, Class) uri = @full_uri.dup if q = to_query(@params) uri += "?%s" % q end request = klass.send(:new, uri) # DEBUG curl = ['curl'] # DEBUG if klass != Net::HTTP::Get # DEBUG curl << "-X%s" % klass.name.split("::").last.upcase # DEBUG end if @body # DEBUG tmpfile = "/tmp/rest_client.tmp" # DEBUG File.open(tmpfile, "w") { |os| os << @body.to_s } # DEBUG curl << "-d@%s" % tmpfile request.body = @body end if @auth # DEBUG curl << "-u \"%s:%s\"" % [@auth.username, @auth.password] Preconditions.check_state(!@header_keys_lower_case.include?("authorization"), "Cannot specify both an Authorization header and an auth instance") user_pass = "%s:%s" % [@auth.username, @auth.password] encoded = Base64.encode64(user_pass).to_s.split("\n").map(&:strip).join request.add_field("Authorization", "Basic %s" % encoded) end @headers.each { |key, value| # DEBUG curl << "-H \"%s: %s\"" % [key, value] request.add_field(key, value) } # DEBUG curl << "'%s%s'" % [@base_uri, path] # DEBUG puts curl.join(" ") raw_response = @http_handler.instance(@base_uri, request.path).execute(request) response = raw_response.to_s == "" ? nil : JSON.parse(raw_response) if block_given? yield response else response end end private def to_query(params={}) parts = (params || {}).map { |k,v| if v.is_a?(Enumerable) v.map { |el| "%s=%s" % [k, CGI.escape(el.to_s)] } else "%s=%s" % [k, CGI.escape(v.to_s)] end } parts.empty? ? nil : parts.join("&") end end class ServerError < StandardError attr_reader :code, :details, :body, :uri def initialize(code, details, incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) @code = HttpClient::Preconditions.assert_class('code', code, Integer) @details = HttpClient::Preconditions.assert_class('details', details, String) @body = HttpClient::Preconditions.assert_class_or_nil('body', opts.delete(:body), String) @uri = HttpClient::Preconditions.assert_class_or_nil('uri', opts.delete(:uri), String) HttpClient::Preconditions.assert_empty_opts(opts) super(self.message) end def message m = "%s %s" % [@code, @details] if @body m << ": %s" % @body end m end def body_json @body ? JSON.parse(@body) : nil end end class PreconditionException < StandardError attr_reader :message def initialize(message) super(message) @message = message end end module Preconditions def Preconditions.check_argument(expression, error_message=nil) if !expression raise PreconditionException.new(error_message || "check_argument failed") end nil end def Preconditions.check_state(expression, error_message=nil) if !expression raise PreconditionException.new(error_message || "check_state failed") end nil end def Preconditions.check_not_nil(field_name, reference, error_message=nil) if reference.nil? raise PreconditionException.new(error_message || "argument for %s cannot be nil" % field_name) end reference end def Preconditions.check_not_blank(field_name, reference, error_message=nil) if reference.to_s.strip == "" raise PreconditionException.new(error_message || "argument for %s cannot be blank" % field_name) end reference end # Throws an error if opts is not empty. Useful when parsing # arguments to a function def Preconditions.assert_empty_opts(opts) if !opts.empty? raise PreconditionException.new("Invalid opts: #{opts.keys.inspect}\n#{opts.inspect}") end end # Requires that the provided hash has the specified keys. # @param fields A list of symbols def Preconditions.require_keys(hash, fields, error_prefix=nil) missing = fields.select { |f| !hash.has_key?(f) } if !missing.empty? msg = "Missing required fields: " + missing.join(", ") raise PreconditionException.new(error_prefix.empty? ? msg : "#{error_prefix}: #{msg}") end end # Asserts that value is not nill and is_?(klass). Returns # value. Common use is # # amount = Preconditions.assert_class('amount', amount, BigDecimal) def Preconditions.assert_class(field_name, value, klass) Preconditions.check_not_nil('field_name', field_name) Preconditions.check_not_nil('klass', klass) Preconditions.check_not_nil('value', value, "Value for %s cannot be nil. Expected an instance of class %s" % [field_name, klass.name]) Preconditions.check_state(value.is_a?(klass), "Value for #{field_name} is of type[#{value.class}] - class[#{klass}] is required. value[#{value.inspect.to_s}]") value end def Preconditions.assert_class_or_nil(field_name, value, klass) if !value.nil? Preconditions.assert_class(field_name, value, klass) end end def Preconditions.assert_boolean(field_name, value) Preconditions.check_not_nil('field_name', field_name) Preconditions.check_not_nil('value', value, "Value for %s cannot be nil. Expected an instance of TrueClass or FalseClass" % field_name) Preconditions.check_state(value.is_a?(TrueClass) || value.is_a?(FalseClass), "Value for #{field_name} is of type[#{value.class}] - class[TrueClass or FalseClass] is required. value[#{value.inspect.to_s}]") value end def Preconditions.assert_boolean_or_nil(field_name, value) if !value.nil? Preconditions.assert_boolean(field_name, value) end end def Preconditions.assert_collection_of_class(field_name, values, klass) Preconditions.assert_class(field_name, values, Array) values.each { |v| Preconditions.assert_class(field_name, v, klass) } end def Preconditions.assert_hash_of_class(field_name, hash, klass) Preconditions.assert_class(field_name, hash, Hash) values.each { |k, v| Preconditions.assert_class(field_name, v, klass) } end end class AuthScheme attr_reader :name def initialize(name) @name = HttpClient::Preconditions.check_not_blank('name', name) end BASIC = AuthScheme.new("basic") unless defined?(BASIC) end class Authorization attr_reader :scheme, :username, :password def initialize(scheme, username, opts={}) @scheme = HttpClient::Preconditions.assert_class('schema', scheme, AuthScheme) @username = HttpClient::Preconditions.check_not_blank('username', username, "username is required") @password = HttpClient::Preconditions.assert_class_or_nil('password', opts.delete(:password), String) HttpClient::Preconditions.assert_empty_opts(opts) end def Authorization.basic(username, password=nil) Authorization.new(AuthScheme::BASIC, username, :password => password) end end module Helper def Helper.symbolize_keys(hash) Preconditions.assert_class('hash', hash, Hash) new_hash = {} hash.each { |k, v| new_hash[k.to_sym] = v } new_hash end def Helper.to_big_decimal(value) value ? BigDecimal(value.to_s) : nil end def Helper.to_object(value) value ? (value.is_a?(Hash) ? value : JSON.parse(value)) : nil end def Helper.to_uuid(value) Preconditions.check_state(value.nil? || value.match(/^\w\w\w\w\w\w\w\w\-\w\w\w\w\-\w\w\w\w\-\w\w\w\w\-\w\w\w\w\w\w\w\w\w\w\w\w$/), "Invalid guid[%s]" % value) value end def Helper.to_date_iso8601(value) if value.is_a?(Date) value elsif value Date.parse(value.to_s) else nil end end def Helper.to_date_time_iso8601(value) if value.is_a?(DateTime) value elsif value DateTime.parse(value.to_s) else nil end end def Helper.date_iso8601_to_string(value) value.nil? ? nil : value.strftime('%Y-%m-%d') end def Helper.date_time_iso8601_to_string(value) value.nil? ? nil : value.strftime('%Y-%m-%dT%H:%M:%S%z') end TRUE_STRINGS = ['t', 'true', 'y', 'yes', 'on', '1', 'trueclass'] unless defined?(TRUE_STRINGS) FALSE_STRINGS = ['f', 'false', 'n', 'no', 'off', '0', 'falseclass'] unless defined?(FALSE_STRINGS) def Helper.to_boolean(field_name, value) string = value.to_s.strip.downcase if TRUE_STRINGS.include?(string) true elsif FALSE_STRINGS.include?(string) false elsif string != "" raise PreconditionException.new("Unsupported boolean value[#{string}]. For true, must be one of: #{TRUE_STRINGS.inspect}. For false, must be one of: #{FALSE_STRINGS.inspect}") else nil end end end end end end end end end