Class: Coinbase::Network
- Inherits:
-
Object
- Object
- Coinbase::Network
- Defined in:
- lib/coinbase/network.rb
Overview
A blockchain network.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
-
.from_id(network_id) ⇒ Network
Returns the Network object for the given ID, if supported.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Returns the equality of the Network object with another Network object by ID.
-
#address_path_prefix ⇒ String
The address path prefix of the Network.
-
#chain_id ⇒ Integer
The Chain ID of the Network.
-
#display_name ⇒ String
The display name of the Network.
-
#get_asset(asset_id) ⇒ Asset
Gets the Asset with the given ID.
-
#initialize(id) ⇒ Network
constructor
Constructs a new Network object.
- #inspect ⇒ Object
-
#native_asset ⇒ Asset
Gets the native Asset of the Network.
- #normalized_id ⇒ Object
-
#protocol_family ⇒ String
The protocol family to which the Network belongs.
-
#testnet? ⇒ Boolean
Whether the Network is a testnet.
- #to_s ⇒ Object
Constructor Details
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
36 37 38 |
# File 'lib/coinbase/network.rb', line 36 def id @id end |
Class Method Details
.from_id(network_id) ⇒ Network
Returns the Network object for the given ID, if supported.
9 10 11 12 13 14 15 16 17 |
# File 'lib/coinbase/network.rb', line 9 def self.from_id(network_id) return network_id if network_id.is_a?(Network) network = NETWORK_MAP.fetch(Coinbase.to_sym(network_id), nil) return network unless network.nil? raise NetworkUnsupportedError, network_id end |
Instance Method Details
#==(other) ⇒ Boolean
Returns the equality of the Network object with another Network object by ID.
30 31 32 33 34 |
# File 'lib/coinbase/network.rb', line 30 def ==(other) return false unless other.is_a?(Network) id == other.id end |
#address_path_prefix ⇒ String
The address path prefix of the Network.
78 79 80 |
# File 'lib/coinbase/network.rb', line 78 def address_path_prefix model.address_path_prefix end |
#chain_id ⇒ Integer
The Chain ID of the Network.
46 47 48 |
# File 'lib/coinbase/network.rb', line 46 def chain_id model.chain_id end |
#display_name ⇒ String
The display name of the Network.
62 63 64 |
# File 'lib/coinbase/network.rb', line 62 def display_name model.display_name end |
#get_asset(asset_id) ⇒ Asset
Gets the Asset with the given ID.
85 86 87 |
# File 'lib/coinbase/network.rb', line 85 def get_asset(asset_id) Asset.fetch(@id, asset_id) end |
#inspect ⇒ Object
108 109 110 |
# File 'lib/coinbase/network.rb', line 108 def inspect to_s end |
#native_asset ⇒ Asset
Gets the native Asset of the Network.
91 92 93 |
# File 'lib/coinbase/network.rb', line 91 def native_asset @native_asset ||= Coinbase::Asset.from_model(model.native_asset) end |
#normalized_id ⇒ Object
38 39 40 |
# File 'lib/coinbase/network.rb', line 38 def normalized_id id.to_s.gsub('_', '-') end |
#protocol_family ⇒ String
The protocol family to which the Network belongs. Example: `evm`.
70 71 72 |
# File 'lib/coinbase/network.rb', line 70 def protocol_family model.protocol_family end |
#testnet? ⇒ Boolean
Whether the Network is a testnet.
54 55 56 |
# File 'lib/coinbase/network.rb', line 54 def testnet? model.is_testnet end |
#to_s ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/coinbase/network.rb', line 95 def to_s details = { id: id } # Only include optional details if the model is already fetched. unless @model.nil? Coinbase::Client::Network.attribute_map.each_key do |attr| details[attr] = @model.send(attr) end end Coinbase.pretty_print_object(self.class, **details) end |