Class: Transaction
- Inherits:
-
Object
- Object
- Transaction
- Defined in:
- lib/universum/transaction.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.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/universum/transaction.rb', line 13 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.hex if to.is_a?( Contract ) @to = "#{to.address.hex} (#{to.class.name})" elsif to.is_a?( Account ) ## note: to allows Contracts AND Accounts @to = to.address.hex 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.
11 12 13 |
# File 'lib/universum/transaction.rb', line 11 def data @data end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
11 12 13 |
# File 'lib/universum/transaction.rb', line 11 def from @from end |
#nonce ⇒ Object (readonly)
Returns the value of attribute nonce.
11 12 13 |
# File 'lib/universum/transaction.rb', line 11 def nonce @nonce end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
11 12 13 |
# File 'lib/universum/transaction.rb', line 11 def to @to end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
11 12 13 |
# File 'lib/universum/transaction.rb', line 11 def value @value end |
Class Method Details
.send(**kwargs) ⇒ Object
convenience helper for Uni.send_transaction
6 7 8 |
# File 'lib/universum/transaction.rb', line 6 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)
79 80 81 82 83 84 85 86 |
# File 'lib/universum/transaction.rb', line 79 def contract # convenience helper (quick contract lookup) rec = receipt if rec rec.contract else nil end end |
#log_str ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/universum/transaction.rb', line 43 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 |