Class: Coinbase::Network

Inherits:
Object
  • Object
show all
Defined in:
lib/coinbase/network.rb

Overview

A blockchain network.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(network_id:, display_name:, protocol_family:, is_testnet:, assets:, native_asset_id:, chain_id:) ⇒ Network

Returns a new Network object. Do not use this method directly. Instead, use the Network constants defined in the Coinbase module.

Parameters:

  • network_id (Symbol)

    The Network ID

  • display_name (String)

    The Network’s display name

  • protocol_family (String)

    The protocol family to which the Network belongs (e.g., “evm”)

  • is_testnet (Boolean)

    Whether the Network is a testnet

  • assets (Array<Asset>)

    The Assets supported by the Network

  • native_asset_id (String)

    The ID of the Network’s native Asset

  • chain_id (Integer)

    The Chain ID of the Network

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/coinbase/network.rb', line 18

def initialize(network_id:, display_name:, protocol_family:, is_testnet:, assets:, native_asset_id:, chain_id:)
  @network_id = network_id
  @display_name = display_name
  @protocol_family = protocol_family
  @is_testnet = is_testnet
  @chain_id = chain_id

  @asset_map = {}
  assets.each do |asset|
    @asset_map[asset.asset_id] = asset
  end

  raise ArgumentError, 'Native Asset not found' unless @asset_map.key?(native_asset_id)

  @native_asset = @asset_map[native_asset_id]
end

Instance Attribute Details

#chain_idObject (readonly)

Returns the value of attribute chain_id.



6
7
8
# File 'lib/coinbase/network.rb', line 6

def chain_id
  @chain_id
end

#native_assetAsset (readonly)

Gets the native Asset of the Network.

Returns:

  • (Asset)

    The native Asset of the Network



53
54
55
# File 'lib/coinbase/network.rb', line 53

def native_asset
  @native_asset
end

Instance Method Details

#get_asset(asset_id) ⇒ Asset

Gets the Asset with the given ID.

Parameters:

  • asset_id (Symbol)

    The ID of the Asset

Returns:

  • (Asset)

    The Asset with the given ID



46
47
48
# File 'lib/coinbase/network.rb', line 46

def get_asset(asset_id)
  @asset_map[asset_id]
end

#list_assetsArray<Asset>

Lists the Assets supported by the Network.

Returns:

  • (Array<Asset>)

    The Assets supported by the Network



38
39
40
# File 'lib/coinbase/network.rb', line 38

def list_assets
  @asset_map.values
end