Class: Coinbase::SmartContract

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

Overview

A representation of a SmartContract on the blockchain.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ SmartContract

Returns a new SmartContract object.

Parameters:

  • model (Coinbase::Client::SmartContract)

    The underlying SmartContract object



36
37
38
# File 'lib/coinbase/smart_contract.rb', line 36

def initialize(model)
  @model = model
end

Class Method Details

.contract_events_apiObject



80
81
82
# File 'lib/coinbase/smart_contract.rb', line 80

def self.contract_events_api
  Coinbase::Client::ContractEventsApi.new(Coinbase.configuration.api_client)
end

.list_events(network_id:, protocol_name:, contract_address:, contract_name:, event_name:, from_block_height:, to_block_height:) ⇒ Enumerable<Coinbase::ContractEvent>

Returns a list of ContractEvents for the provided network, contract, and event details.

Parameters:

  • network_id (Symbol)

    The network ID

  • protocol_name (String)

    The protocol name

  • contract_address (String)

    The contract address

  • contract_name (String)

    The contract name

  • event_name (String)

    The event name

  • from_block_height (Integer)

    The start block height

  • to_block_height (Integer)

    The end block height

Returns:



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

def self.list_events(
  network_id:,
  protocol_name:,
  contract_address:,
  contract_name:,
  event_name:,
  from_block_height:,
  to_block_height:
)
  Coinbase::Pagination.enumerate(
    lambda { |page|
      list_events_page(network_id, protocol_name, contract_address, contract_name, event_name, from_block_height,
                       to_block_height, page)
    }
  ) do |contract_event|
    Coinbase::ContractEvent.new(contract_event)
  end
end

.list_events_page(network_id, protocol_name, contract_address, contract_name, event_name, from_block_height, to_block_height, page) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/coinbase/smart_contract.rb', line 84

def self.list_events_page(
  network_id,
  protocol_name,
  contract_address,
  contract_name,
  event_name,
  from_block_height,
  to_block_height,
  page
)
  contract_events_api.list_contract_events(
    Coinbase.normalize_network(network_id),
    protocol_name,
    contract_address,
    contract_name,
    event_name,
    from_block_height,
    to_block_height,
    { next_page: page }
  )
end

Instance Method Details

#addressString

Returns the address of the SmartContract.

Returns:

  • (String)

    The contract address



60
61
62
# File 'lib/coinbase/smart_contract.rb', line 60

def address
  @model.address
end

#contract_nameString

Returns the contract name of the SmartContract.

Returns:

  • (String)

    The contract name



54
55
56
# File 'lib/coinbase/smart_contract.rb', line 54

def contract_name
  @model.contract_name
end

#inspectString

Same as to_s.

Returns:

  • (String)

    a string representation of the SmartContract



76
77
78
# File 'lib/coinbase/smart_contract.rb', line 76

def inspect
  to_s
end

#network_idString

Returns the network ID of the SmartContract.

Returns:

  • (String)

    The network ID



42
43
44
# File 'lib/coinbase/smart_contract.rb', line 42

def network_id
  Coinbase.to_sym(@model.network_id)
end

#protocol_nameString

Returns the protocol name of the SmartContract.

Returns:

  • (String)

    The protocol name



48
49
50
# File 'lib/coinbase/smart_contract.rb', line 48

def protocol_name
  @model.protocol_name
end

#to_sString

Returns a string representation of the SmartContract.

Returns:

  • (String)

    a string representation of the SmartContract



66
67
68
69
70
71
72
# File 'lib/coinbase/smart_contract.rb', line 66

def to_s
  "Coinbase::SmartContract{
    network_id: '#{network_id}',
    protocol_name: '#{protocol_name}',
    contract_name: '#{contract_name}',
    address: '#{address}'}"
end