Module: Coinbase
- Defined in:
- lib/coinbase.rb,
lib/coinbase/asset.rb,
lib/coinbase/trade.rb,
lib/coinbase/errors.rb,
lib/coinbase/wallet.rb,
lib/coinbase/address.rb,
lib/coinbase/balance.rb,
lib/coinbase/network.rb,
lib/coinbase/version.rb,
lib/coinbase/webhook.rb,
lib/coinbase/transfer.rb,
lib/coinbase/constants.rb,
lib/coinbase/validator.rb,
lib/coinbase/middleware.rb,
lib/coinbase/pagination.rb,
lib/coinbase/balance_map.rb,
lib/coinbase/correlation.rb,
lib/coinbase/destination.rb,
lib/coinbase/transaction.rb,
lib/coinbase/wallet/data.rb,
lib/coinbase/authenticator.rb,
lib/coinbase/server_signer.rb,
lib/coinbase/contract_event.rb,
lib/coinbase/smart_contract.rb,
lib/coinbase/sponsored_send.rb,
lib/coinbase/staking_reward.rb,
lib/coinbase/staking_balance.rb,
lib/coinbase/payload_signature.rb,
lib/coinbase/staking_operation.rb,
lib/coinbase/faucet_transaction.rb,
lib/coinbase/historical_balance.rb,
lib/coinbase/contract_invocation.rb,
lib/coinbase/address/wallet_address.rb,
lib/coinbase/address/external_address.rb
Overview
The Coinbase SDK.
Defined Under Namespace
Modules: Client, Middleware, Pagination Classes: APIError, Address, AddressCannotSignError, AlreadyExistsError, AlreadySignedError, Asset, Authenticator, Balance, BalanceMap, Configuration, ContractEvent, ContractInvocation, Correlation, Destination, ExternalAddress, FaucetLimitReachedError, FaucetTransaction, HistoricalBalance, InsufficientFundsError, InternalError, InvalidAddressError, InvalidAddressIDError, InvalidAmountError, InvalidAssetIDError, InvalidConfiguration, InvalidDestinationError, InvalidLimitError, InvalidNetworkIDError, InvalidPageError, InvalidSignedPayloadError, InvalidTransferIDError, InvalidTransferStatusError, InvalidWalletError, InvalidWalletIDError, MalformedRequestError, Network, NetworkFeatureUnsupportedError, NetworkUnsupportedError, NotFoundError, PayloadSignature, ResourceExhaustedError, ServerSigner, SmartContract, SponsoredSend, StakingBalance, StakingOperation, StakingReward, Trade, Transaction, TransactionNotSignedError, Transfer, UnauthorizedError, UnimplementedError, UnsupportedAssetError, Validator, Wallet, WalletAddress, Webhook
Constant Summary collapse
- ERROR_CODE_TO_ERROR_CLASS =
{ 'unimplemented' => UnimplementedError, 'unauthorized' => UnauthorizedError, 'internal' => InternalError, 'not_found' => NotFoundError, 'invalid_wallet_id' => InvalidWalletIDError, 'invalid_address_id' => InvalidAddressIDError, 'invalid_wallet' => InvalidWalletError, 'invalid_address' => InvalidAddressError, 'invalid_amount' => InvalidAmountError, 'invalid_transfer_id' => InvalidTransferIDError, 'invalid_page_token' => InvalidPageError, 'invalid_page_limit' => InvalidLimitError, 'already_exists' => AlreadyExistsError, 'malformed_request' => MalformedRequestError, 'unsupported_asset' => UnsupportedAssetError, 'invalid_asset_id' => InvalidAssetIDError, 'invalid_destination' => InvalidDestinationError, 'invalid_network_id' => InvalidNetworkIDError, 'resource_exhausted' => ResourceExhaustedError, 'faucet_limit_reached' => FaucetLimitReachedError, 'invalid_signed_payload' => InvalidSignedPayloadError, 'invalid_transfer_status' => InvalidTransferStatusError, 'network_feature_unsupported' => NetworkFeatureUnsupportedError }.freeze
- VERSION =
'0.6.0'
- GWEI_DECIMALS =
The number of decimal places in Gwei.
9
- DEFAULT_PAGE_LIMIT =
The default page limit for paginated API requests.
100
- DEFAULT_TRANSACTION_PAGE_LIMIT =
The default page limit for transaction paginated API request.
10
Class Method Summary collapse
-
.call_api ⇒ Object
Wraps a call to the Platform API to ensure that the error is caught and wrapped as an APIError.
-
.configuration ⇒ Configuration
Returns the configuration object.
-
.configure {|configuration| ... } ⇒ String
Configures the Coinbase SDK.
-
.configure_from_json(file_path = 'cdp_api_key.json') ⇒ String
Configures the Coinbase SDK from the given CDP API Key JSON file.
-
.configured? ⇒ bool
Returns whether the SDK is configured.
-
.default_network ⇒ Coinbase::Network
Returns the default network.
-
.normalize_network(network) ⇒ String
Converts a Network object or network symbol with the string representation of the network ID, replacing underscores with hyphens.
-
.pretty_print_object(klass, **details) ⇒ String
Returns a pretty-printed object string that contains the object's class name and the details of the object, filtering out nil values.
-
.to_sym(value) ⇒ Symbol
Converts a string to a symbol, replacing hyphens with underscores.
-
.use_server_signer? ⇒ bool
Returns whether to use a server signer to manage private keys.
Class Method Details
.call_api ⇒ Object
Wraps a call to the Platform API to ensure that the error is caught and wrapped as an APIError.
136 137 138 139 140 |
# File 'lib/coinbase.rb', line 136 def self.call_api yield rescue Coinbase::Client::ApiError => e raise Coinbase::APIError.from_error(e), cause: nil end |
.configuration ⇒ Configuration
Returns the configuration object.
44 45 46 |
# File 'lib/coinbase.rb', line 44 def self.configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ String
Configures the Coinbase SDK.
50 51 52 53 54 55 56 57 |
# File 'lib/coinbase.rb', line 50 def self.configure yield(configuration) raise InvalidConfiguration, 'API key private key is not set' unless configuration.api_key_private_key raise InvalidConfiguration, 'API key name is not set' unless configuration.api_key_name 'Successfully configured Coinbase SDK' end |
.configure_from_json(file_path = 'cdp_api_key.json') ⇒ String
Configures the Coinbase SDK from the given CDP API Key JSON file. file in the root directory by default.
63 64 65 66 67 68 69 70 |
# File 'lib/coinbase.rb', line 63 def self.configure_from_json(file_path = 'cdp_api_key.json') configuration.from_json(file_path) raise InvalidConfiguration, 'API key private key is not set' unless configuration.api_key_private_key raise InvalidConfiguration, 'API key name is not set' unless configuration.api_key_name 'Successfully configured Coinbase SDK' end |
.configured? ⇒ bool
Returns whether the SDK is configured.
167 168 169 |
# File 'lib/coinbase.rb', line 167 def self.configured? !Coinbase.configuration.api_key_name.nil? && !Coinbase.configuration.api_key_private_key.nil? end |
.default_network ⇒ Coinbase::Network
Returns the default network.
161 162 163 |
# File 'lib/coinbase.rb', line 161 def self.default_network Coinbase.configuration.default_network end |
.normalize_network(network) ⇒ String
Converts a Network object or network symbol with the string representation of the network ID, replacing underscores with hyphens.
128 129 130 131 132 |
# File 'lib/coinbase.rb', line 128 def self.normalize_network(network) network_sym = network.is_a?(Coinbase::Network) ? network.id : network network_sym.to_s.gsub('_', '-') end |
.pretty_print_object(klass, **details) ⇒ String
Returns a pretty-printed object string that contains the object's class name and the details of the object, filtering out nil values.
147 148 149 150 151 |
# File 'lib/coinbase.rb', line 147 def self.pretty_print_object(klass, **details) filtered_details = details.filter { |_, v| !v.nil? }.map { |k, v| "#{k}: '#{v}'" } "#{klass}{#{filtered_details.join(', ')}}" end |
.to_sym(value) ⇒ Symbol
Converts a string to a symbol, replacing hyphens with underscores.
120 121 122 |
# File 'lib/coinbase.rb', line 120 def self.to_sym(value) value.to_s.gsub('-', '_').to_sym end |
.use_server_signer? ⇒ bool
Returns whether to use a server signer to manage private keys.
155 156 157 |
# File 'lib/coinbase.rb', line 155 def self.use_server_signer? Coinbase.configuration.use_server_signer end |