Class: Simulacrum

Inherits:
Object
  • Object
show all
Includes:
Types
Defined in:
lib/soliscript/simulacrum.rb

Overview

make it an module - why? why not?

Defined Under Namespace

Classes: Block, Message, Receipt

Class Method Summary collapse

Class Method Details

.blockObject



45
# File 'lib/soliscript/simulacrum.rb', line 45

def self.block() @block  ||= Block.new; end

.msgObject



44
# File 'lib/soliscript/simulacrum.rb', line 44

def self.msg()   @msg    ||= Message.new; end

.send_transaction(from:, to: Typed::ADDRESS_ZERO, data: [], value: 0) ⇒ Object Also known as: transact



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/soliscript/simulacrum.rb', line 59

def self.send_transaction( from:, 
                           to: Typed::ADDRESS_ZERO,
                           data: [], 
                           value: 0 )
    ## setup transaction "context"                       
    msg.sender = from
    msg.value  = value
    ## up tx counter (nonce/number used once)
    Account[ from ].nonce += 1   

   if to == Typed::ADDRESS_ZERO && data.is_a?( Class )  ## contract creation
       ## todo/fix: allow constructor args
       ##  check (data.is_a?(Array) && data[0].is_a?(Class)
       klass = data
       contract = klass.new
       contract.constructor

       Receipt.new( contract: contract )
   else
       ## note: for now assume to is always a contract instance
       contract = to
       if data.empty?  ## assume default receive!!!
          contract.receive
          Receipt.new
       else
          ## to be done
          ## contract.send
       end
   end
end