Class: Coinbase::ContractInvocation
- Inherits:
-
Object
- Object
- Coinbase::ContractInvocation
- Defined in:
- lib/coinbase/contract_invocation.rb
Overview
A representation of a Contract Invocation.
Class Method Summary collapse
-
.create(address_id:, wallet_id:, contract_address:, abi:, method:, args: {}) ⇒ ContractInvocation
Creates a new ContractInvocation object.
-
.list(wallet_id:, address_id:) ⇒ Enumerable<Coinbase::ContractInvocation>
Enumerates the payload signatures for a given address belonging to a wallet.
Instance Method Summary collapse
-
#abi ⇒ Array<Hash>
Returns the ABI of the Contract Invocation.
-
#address_id ⇒ String
Returns the Address ID of the Contract Invocation.
-
#args ⇒ Hash
Returns the arguments of the Contract Invocation.
-
#broadcast! ⇒ ContractInvocation
Broadcasts the ContractInvocation to the Network.
-
#contract_address ⇒ String
Returns the Contract Address of the Contract Invocation.
-
#id ⇒ String
Returns the Contract Invocation ID.
-
#initialize(model) ⇒ ContractInvocation
constructor
Returns a new ContractInvocation object.
-
#inspect ⇒ String
Same as to_s.
-
#method ⇒ String
Returns the method of the Contract Invocation.
-
#network ⇒ Coinbase::Network
Returns the Network of the Contract Invocation.
-
#reload ⇒ ContractInvocation
# Reload reloads the Contract Invocation model with the latest version from the server side.
-
#sign(key) ⇒ ContractInvocation
Signs the Contract Invocation transaction with the given key.
-
#status ⇒ String
Returns the status of the Contract Invocation.
-
#to_s ⇒ String
Returns a String representation of the Contract Invocation.
-
#transaction ⇒ Coinbase::Transaction
Returns the transaction.
-
#wait!(interval_seconds = 0.2, timeout_seconds = 20) ⇒ ContractInvocation
Waits until the Contract Invocation is signed or failed by polling the server at the given interval.
-
#wallet_id ⇒ String
Returns the Wallet ID of the Contract Invocation.
Constructor Details
#initialize(model) ⇒ ContractInvocation
Returns a new ContractInvocation object. Do not use this method directly. Instead use Coinbase::ContractInvocation.create.
70 71 72 73 74 |
# File 'lib/coinbase/contract_invocation.rb', line 70 def initialize(model) raise unless model.is_a?(Coinbase::Client::ContractInvocation) @model = model end |
Class Method Details
.create(address_id:, wallet_id:, contract_address:, abi:, method:, args: {}) ⇒ ContractInvocation
Creates a new ContractInvocation object.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/coinbase/contract_invocation.rb', line 17 def create( address_id:, wallet_id:, contract_address:, abi:, method:, args: {} ) model = Coinbase.call_api do contract_invocation_api.create_contract_invocation( wallet_id, address_id, contract_address: contract_address, abi: abi.to_json, method: method, args: args.to_json ) end new(model) end |
.list(wallet_id:, address_id:) ⇒ Enumerable<Coinbase::ContractInvocation>
Enumerates the payload signatures for a given address belonging to a wallet. The result is an enumerator that lazily fetches from the server, and can be iterated over, converted an array, etc…
43 44 45 46 47 48 49 |
# File 'lib/coinbase/contract_invocation.rb', line 43 def list(wallet_id:, address_id:) Coinbase::Pagination.enumerate( ->(page) { fetch_page(wallet_id, address_id, page) } ) do |contract_invocation| new(contract_invocation) end end |
Instance Method Details
#abi ⇒ Array<Hash>
Returns the ABI of the Contract Invocation.
108 109 110 |
# File 'lib/coinbase/contract_invocation.rb', line 108 def abi JSON.parse(@model.abi) end |
#address_id ⇒ String
Returns the Address ID of the Contract Invocation.
90 91 92 |
# File 'lib/coinbase/contract_invocation.rb', line 90 def address_id @model.address_id end |
#args ⇒ Hash
Returns the arguments of the Contract Invocation.
120 121 122 |
# File 'lib/coinbase/contract_invocation.rb', line 120 def args JSON.parse(@model.args).transform_keys(&:to_sym) end |
#broadcast! ⇒ ContractInvocation
Broadcasts the ContractInvocation to the Network.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/coinbase/contract_invocation.rb', line 153 def broadcast! raise TransactionNotSignedError unless transaction.signed? @model = Coinbase.call_api do contract_invocation_api.broadcast_contract_invocation( wallet_id, address_id, id, { signed_payload: transaction.signature } ) end @transaction = Coinbase::Transaction.new(@model.transaction) self end |
#contract_address ⇒ String
Returns the Contract Address of the Contract Invocation.
102 103 104 |
# File 'lib/coinbase/contract_invocation.rb', line 102 def contract_address @model.contract_address end |
#id ⇒ String
Returns the Contract Invocation ID.
78 79 80 |
# File 'lib/coinbase/contract_invocation.rb', line 78 def id @model.contract_invocation_id end |
#inspect ⇒ String
Same as to_s.
224 225 226 |
# File 'lib/coinbase/contract_invocation.rb', line 224 def inspect to_s end |
#method ⇒ String
Returns the method of the Contract Invocation.
114 115 116 |
# File 'lib/coinbase/contract_invocation.rb', line 114 def method @model.method end |
#network ⇒ Coinbase::Network
Returns the Network of the Contract Invocation.
96 97 98 |
# File 'lib/coinbase/contract_invocation.rb', line 96 def network @network ||= Coinbase::Network.from_id(@model.network_id) end |
#reload ⇒ ContractInvocation
# Reload reloads the Contract Invocation model with the latest version from the server side.
172 173 174 175 176 177 178 179 180 |
# File 'lib/coinbase/contract_invocation.rb', line 172 def reload @model = Coinbase.call_api do contract_invocation_api.get_contract_invocation(wallet_id, address_id, id) end @transaction = Coinbase::Transaction.new(@model.transaction) self end |
#sign(key) ⇒ ContractInvocation
Signs the Contract Invocation transaction with the given key. This is required before broadcasting the Contract Invocation when not using a Server-Signer.
142 143 144 145 146 147 148 |
# File 'lib/coinbase/contract_invocation.rb', line 142 def sign(key) raise unless key.is_a?(Eth::Key) transaction.sign(key) self end |
#status ⇒ String
Returns the status of the Contract Invocation.
132 133 134 |
# File 'lib/coinbase/contract_invocation.rb', line 132 def status transaction.status end |
#to_s ⇒ String
Returns a String representation of the Contract Invocation.
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/coinbase/contract_invocation.rb', line 206 def to_s Coinbase.pretty_print_object( self.class, id: id, wallet_id: wallet_id, address_id: address_id, network_id: network.id, status: status, abi: abi.to_json, method: method, args: args.to_json, transaction_hash: transaction.transaction_hash, transaction_link: transaction.transaction_link ) end |
#transaction ⇒ Coinbase::Transaction
Returns the transaction.
126 127 128 |
# File 'lib/coinbase/contract_invocation.rb', line 126 def transaction @transaction ||= Coinbase::Transaction.new(@model.transaction) end |
#wait!(interval_seconds = 0.2, timeout_seconds = 20) ⇒ ContractInvocation
Waits until the Contract Invocation is signed or failed by polling the server at the given interval. Raises a Timeout::Error if the Contract Invocation takes longer than the given timeout. in seconds.
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/coinbase/contract_invocation.rb', line 188 def wait!(interval_seconds = 0.2, timeout_seconds = 20) start_time = Time.now loop do reload return self if transaction.terminal_state? raise Timeout::Error, 'Contract Invocation timed out' if Time.now - start_time > timeout_seconds self.sleep interval_seconds end self end |
#wallet_id ⇒ String
Returns the Wallet ID of the Contract Invocation.
84 85 86 |
# File 'lib/coinbase/contract_invocation.rb', line 84 def wallet_id @model.wallet_id end |