Class: Coinbase::Address
- Inherits:
-
Object
- Object
- Coinbase::Address
- Defined in:
- lib/coinbase/address.rb
Overview
A representation of a blockchain Address, which is a user-controlled account on a Network. Addresses are used to send and receive Assets.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#id ⇒ String
readonly
The onchain Address ID.
-
#network_id ⇒ Symbol
readonly
The Network ID.
Instance Method Summary collapse
-
#balance(asset_id) ⇒ BigDecimal
Returns the balance of the provided Asset.
-
#balances ⇒ BalanceMap
Returns the balances of the Address.
-
#can_sign? ⇒ Boolean
Returns true if the Address can sign transactions.
-
#faucet ⇒ Coinbase::FaucetTransaction
Requests funds for the address from the faucet and returns the faucet transaction.
-
#initialize(network_id, id) ⇒ Address
constructor
Returns a new Address object.
-
#inspect ⇒ String
Same as to_s.
-
#to_s ⇒ String
Returns a String representation of the Address.
Constructor Details
Instance Attribute Details
#id ⇒ String (readonly)
The onchain Address ID
8 9 10 |
# File 'lib/coinbase/address.rb', line 8 def id @id end |
#network_id ⇒ Symbol (readonly)
The Network ID
8 9 10 |
# File 'lib/coinbase/address.rb', line 8 def network_id @network_id end |
Instance Method Details
#balance(asset_id) ⇒ BigDecimal
Returns the balance of the provided Asset.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/coinbase/address.rb', line 51 def balance(asset_id) response = Coinbase.call_api do addresses_api.get_external_address_balance( Coinbase.normalize_network(network_id), id, Coinbase::Asset.primary_denomination(asset_id).to_s ) end return BigDecimal('0') if response.nil? Coinbase::Balance.from_model_and_asset_id(response, asset_id).amount end |
#balances ⇒ BalanceMap
Returns the balances of the Address.
40 41 42 43 44 45 46 |
# File 'lib/coinbase/address.rb', line 40 def balances response = Coinbase.call_api do addresses_api.list_external_address_balances(Coinbase.normalize_network(network_id), id) end Coinbase::BalanceMap.from_balances(response.data) end |
#can_sign? ⇒ Boolean
Returns true if the Address can sign transactions.
33 34 35 |
# File 'lib/coinbase/address.rb', line 33 def can_sign? false end |
#faucet ⇒ Coinbase::FaucetTransaction
Requests funds for the address from the faucet and returns the faucet transaction. This is only supported on testnet networks.
70 71 72 73 74 75 76 |
# File 'lib/coinbase/address.rb', line 70 def faucet Coinbase.call_api do Coinbase::FaucetTransaction.new( addresses_api.request_external_faucet_funds(Coinbase.normalize_network(network_id), id) ) end end |
#inspect ⇒ String
Same as to_s.
27 28 29 |
# File 'lib/coinbase/address.rb', line 27 def inspect to_s end |
#to_s ⇒ String
Returns a String representation of the Address.
21 22 23 |
# File 'lib/coinbase/address.rb', line 21 def to_s "Coinbase::Address{id: '#{id}', network_id: '#{network_id}'}" end |