Class: ContractCall
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ContractCall
- Defined in:
- lib/facetq/models/contract_call.rb
Overview
Schema Information
Table name: contract_calls
id :bigint not null, primary key
transaction_hash :string not null
internal_transaction_index :bigint not null
from_address :string not null
to_contract_address :string
created_contract_address :string
effective_contract_address :string
function :string
args :jsonb not null
call_type :string not null
return_value :jsonb
logs :jsonb not null
error :jsonb
status :string not null
block_number :bigint not null
block_timestamp :bigint not null
block_blockhash :string not null
transaction_index :bigint not null
start_time :datetime not null
end_time :datetime not null
runtime_ms :integer not null
created_at :datetime not null
updated_at :datetime not null
Indexes
idx_on_block_number_txi_internal_txi (block_number,transaction_index,internal_transaction_index) UNIQUE
idx_on_tx_hash_internal_txi (transaction_hash,internal_transaction_index) UNIQUE
index_contract_calls_on_call_type (call_type)
index_contract_calls_on_created_contract_address (created_contract_address) UNIQUE
index_contract_calls_on_effective_contract_address (effective_contract_address)
index_contract_calls_on_from_address (from_address)
index_contract_calls_on_internal_transaction_index (internal_transaction_index)
index_contract_calls_on_status (status)
index_contract_calls_on_to_contract_address (to_contract_address)
Foreign Keys
fk_rails_... (block_number => eth_blocks.block_number) ON DELETE => cascade
fk_rails_... (transaction_hash => ethscriptions.transaction_hash) ON DELETE => cascade
Instance Attribute Summary collapse
-
#pending_logs ⇒ Object
Returns the value of attribute pending_logs.
-
#salt ⇒ Object
Returns the value of attribute salt.
-
#to_contract ⇒ Object
Returns the value of attribute to_contract.
-
#to_contract_init_code_hash ⇒ Object
Returns the value of attribute to_contract_init_code_hash.
-
#to_contract_source_code ⇒ Object
Returns the value of attribute to_contract_source_code.
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #calculated_runtime_ms ⇒ Object
- #contract_address ⇒ Object
- #contract_initiated? ⇒ Boolean
- #contract_nonce ⇒ Object
- #current_nonce ⇒ Object
- #eoa_nonce ⇒ Object
- #failure? ⇒ Boolean
- #from ⇒ Object
- #is_call? ⇒ Boolean
- #is_create? ⇒ Boolean
- #is_static_call? ⇒ Boolean
- #success? ⇒ Boolean
- #to ⇒ Object
- #to_or_contract_address ⇒ Object
Instance Attribute Details
#pending_logs ⇒ Object
Returns the value of attribute pending_logs.
49 50 51 |
# File 'lib/facetq/models/contract_call.rb', line 49 def pending_logs @pending_logs end |
#salt ⇒ Object
Returns the value of attribute salt.
49 50 51 |
# File 'lib/facetq/models/contract_call.rb', line 49 def salt @salt end |
#to_contract ⇒ Object
Returns the value of attribute to_contract.
49 50 51 |
# File 'lib/facetq/models/contract_call.rb', line 49 def to_contract @to_contract end |
#to_contract_init_code_hash ⇒ Object
Returns the value of attribute to_contract_init_code_hash.
49 50 51 |
# File 'lib/facetq/models/contract_call.rb', line 49 def to_contract_init_code_hash @to_contract_init_code_hash end |
#to_contract_source_code ⇒ Object
Returns the value of attribute to_contract_source_code.
49 50 51 |
# File 'lib/facetq/models/contract_call.rb', line 49 def to_contract_source_code @to_contract_source_code end |
Instance Method Details
#as_json(options = {}) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/facetq/models/contract_call.rb', line 120 def as_json( = {}) super( .merge( only: [ :transaction_hash, :block_blockhash, :block_timestamp, :block_number, :transaction_index, :internal_transaction_index, :function, :args, :call_type, :return_value, :logs, :error, :status, :runtime_ms, :effective_contract_address ], methods: [:to, :from, :contract_address, :to_or_contract_address] ) ) end |
#calculated_runtime_ms ⇒ Object
145 146 147 |
# File 'lib/facetq/models/contract_call.rb', line 145 def calculated_runtime_ms (end_time - start_time) * 1000 end |
#contract_address ⇒ Object
112 113 114 |
# File 'lib/facetq/models/contract_call.rb', line 112 def contract_address created_contract_address end |
#contract_initiated? ⇒ Boolean
99 100 101 |
# File 'lib/facetq/models/contract_call.rb', line 99 def contract_initiated? internal_transaction_index > 0 end |
#contract_nonce ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/facetq/models/contract_call.rb', line 68 def contract_nonce in_memory = contract_transaction.contract_calls.count do |call| call.from_address == from_address && call.is_create? && call.success? end scope = ContractCall.where( from_address: from_address, call_type: :create, status: :success ) in_memory + scope.count end |
#current_nonce ⇒ Object
93 94 95 96 97 |
# File 'lib/facetq/models/contract_call.rb', line 93 def current_nonce raise "Not possible" unless is_create? contract_initiated? ? contract_nonce : eoa_nonce end |
#eoa_nonce ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/facetq/models/contract_call.rb', line 84 def eoa_nonce scope = ContractCall.where( from_address: from_address, call_type: [:create, :call] ) scope.count end |
#failure? ⇒ Boolean
161 162 163 |
# File 'lib/facetq/models/contract_call.rb', line 161 def failure? status.to_s == 'failure' end |
#from ⇒ Object
108 109 110 |
# File 'lib/facetq/models/contract_call.rb', line 108 def from from_address end |
#is_call? ⇒ Boolean
157 158 159 |
# File 'lib/facetq/models/contract_call.rb', line 157 def is_call? call_type.to_s == "call" end |
#is_create? ⇒ Boolean
153 154 155 |
# File 'lib/facetq/models/contract_call.rb', line 153 def is_create? call_type.to_s == "create" end |
#is_static_call? ⇒ Boolean
149 150 151 |
# File 'lib/facetq/models/contract_call.rb', line 149 def is_static_call? call_type.to_s == "static_call" end |
#success? ⇒ Boolean
165 166 167 |
# File 'lib/facetq/models/contract_call.rb', line 165 def success? status.to_s == 'success' end |
#to ⇒ Object
104 105 106 |
# File 'lib/facetq/models/contract_call.rb', line 104 def to to_contract_address end |
#to_or_contract_address ⇒ Object
116 117 118 |
# File 'lib/facetq/models/contract_call.rb', line 116 def to_or_contract_address to || contract_address end |