Class: Transaction
- Inherits:
-
Object
- Object
- Transaction
- Defined in:
- lib/universum/universum.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#nonce ⇒ Object
readonly
Returns the value of attribute nonce.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
-
.send(**kwargs) ⇒ Object
convenience helper for Uni.send_transaction.
Instance Method Summary collapse
-
#contract ⇒ Object
convenience helper (quick contract lookup).
-
#initialize(from:, to:, value:, data:, nonce: nil) ⇒ Transaction
constructor
A new instance of Transaction.
- #log_str ⇒ Object
- #receipt ⇒ Object
Constructor Details
#initialize(from:, to:, value:, data:, nonce: nil) ⇒ Transaction
Returns a new instance of Transaction.
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/universum/universum.rb', line 291 def initialize( from:, to:, value:, data:, nonce: nil ) ## note: from only allows accounts if from.is_a?( Account ) account = from else account = Account.at( from ) ## lookup account by address end @from = account.address if to.is_a?( Contract ) @to = "#{to.address} (#{to.class.name})" elsif to.is_a?( Account ) ## note: to allows Contracts AND Accounts @to = to.address else @to = to # might be a contract or account (pass through for now) end @value = value @data = data if nonce @nonce = nonce else ## auto-add nonce (that is, tx counter - auto-increment) @nonce = account.tx ## get transaction (tx) counter (starts with 0) account._auto_inc_tx end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
289 290 291 |
# File 'lib/universum/universum.rb', line 289 def data @data end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
289 290 291 |
# File 'lib/universum/universum.rb', line 289 def from @from end |
#nonce ⇒ Object (readonly)
Returns the value of attribute nonce.
289 290 291 |
# File 'lib/universum/universum.rb', line 289 def nonce @nonce end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
289 290 291 |
# File 'lib/universum/universum.rb', line 289 def to @to end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
289 290 291 |
# File 'lib/universum/universum.rb', line 289 def value @value end |
Class Method Details
.send(**kwargs) ⇒ Object
convenience helper for Uni.send_transaction
284 285 286 |
# File 'lib/universum/universum.rb', line 284 def self.send( **kwargs ) ## convenience helper for Uni.send_transaction Universum.send_transaction( **kwargs ) end |
Instance Method Details
#contract ⇒ Object
convenience helper (quick contract lookup)
357 358 359 360 361 362 363 364 |
# File 'lib/universum/universum.rb', line 357 def contract # convenience helper (quick contract lookup) rec = receipt if rec rec.contract else nil end end |
#log_str ⇒ Object
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/universum/universum.rb', line 321 def log_str ## for debug add transaction (tx) args (e.g. from, value, etc.) tx_args_str = "" tx_args_str << "from: #{@from} ##{@nonce}" tx_args_str << ", value: #{@value}" if @value > 0 if @to == '0x0000' ## special case - contract creation transaction klass = @data[0] ## contract class - todo/fix: check if data[] is a contract class!!! call_args = @data[1..-1] ## arguments ## convert all args to string (with inspect) for debugging ## check if pretty_inspect adds trailing newline? why? why not? possible? call_args_str = call_args.reduce( [] ) { |ary,arg| ary; ary << arg.inspect }.join( ', ' ) "#{tx_args_str} => to: #{@to} create contract #{klass.name}.new( #{call_args_str} )" else if @data.empty? ## assume receive (default method) for now if data empty (no method specified) "#{tx_args_str} => to: #{@to} call default fallback" else m = @data[0] ## method name / signature call_args = @data[1..-1] ## arguments ## convert all args to string (with inspect) for debugging ## check if pretty_inspect adds trailing newline? why? why not? possible? call_args_str = call_args.reduce( [] ) { |ary,arg| ary; ary << arg.inspect }.join( ', ' ) "#{tx_args_str} => to: #{@to} call #{m}( #{call_args_str} )" end end end |