Class: Universum
- Inherits:
-
Object
- Object
- Universum
- Defined in:
- lib/universum/version.rb,
lib/universum/universum.rb
Overview
Uni short for Universum
Constant Summary collapse
Class Method Summary collapse
- .accounts ⇒ Object
- .banner ⇒ Object
- .block ⇒ Object
- .block=(value) ⇒ Object
- .blockhash(number) ⇒ Object
- .contracts ⇒ Object
-
.handlers ⇒ Object
use listeners/observers/subscribers/…
- .log(event) ⇒ Object
- .msg ⇒ Object
- .msg=(value) ⇒ Object
- .root ⇒ Object
-
.send_transaction(from:, to: '0x0000', value: 0, data: []) ⇒ Object
convenience helpers.
-
.this ⇒ Object
returns current contract.
- .this=(value) ⇒ Object
- .version ⇒ Object
Class Method Details
.accounts ⇒ Object
530 |
# File 'lib/universum/universum.rb', line 530 def self.accounts() Account.all; end |
.banner ⇒ Object
18 19 20 |
# File 'lib/universum/version.rb', line 18 def self. "universum/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]" end |
.block ⇒ Object
553 554 555 |
# File 'lib/universum/universum.rb', line 553 def self.block @@block ||= Block.new end |
.block=(value) ⇒ Object
557 558 559 560 561 562 563 564 |
# File 'lib/universum/universum.rb', line 557 def self.block=( value ) if value.is_a? Hash kwargs = value @@block = Block.new( kwargs ) else ## assume Block class/type @@block = value end end |
.blockhash(number) ⇒ Object
548 549 550 551 |
# File 'lib/universum/universum.rb', line 548 def self.blockhash( number ) ## for now return "dummy" blockhash sha256( "blockhash #{number}" ) end |
.contracts ⇒ Object
531 |
# File 'lib/universum/universum.rb', line 531 def self.contracts() Contract.all; end |
.handlers ⇒ Object
use listeners/observers/subscribers/… - why? why not?
576 577 578 |
# File 'lib/universum/universum.rb', line 576 def self.handlers ## use listeners/observers/subscribers/... - why? why not? @@handlers ||= [] end |
.log(event) ⇒ Object
580 581 582 |
# File 'lib/universum/universum.rb', line 580 def self.log( event ) handlers.each { |h| h.call( event ) } end |
.msg ⇒ Object
534 535 536 |
# File 'lib/universum/universum.rb', line 534 def self.msg @@msg ||= Msg.new end |
.msg=(value) ⇒ Object
538 539 540 541 542 543 544 545 |
# File 'lib/universum/universum.rb', line 538 def self.msg=( value ) if value.is_a? Hash kwargs = value @@msg = Msg.new( kwargs ) else ## assume Msg class/type @@msg = value end end |
.root ⇒ Object
22 23 24 |
# File 'lib/universum/version.rb', line 22 def self.root "#{File.( File.dirname(File.dirname(File.dirname(__FILE__))) )}" end |
.send_transaction(from:, to: '0x0000', value: 0, data: []) ⇒ Object
convenience helpers
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 |
# File 'lib/universum/universum.rb', line 459 def self.send_transaction( from:, to: '0x0000', value: 0, data: [] ) counter = @@counter ||= 0 ## total tx counter for debugging (start with 0) @@counter += 1 ## note: always lookup (use) account for now if from.is_a?( Account ) account = from else account = Account.at( from ) end ## setup contract msg context self.msg = { sender: account.address, value: value } ## allow shortcut for Class (without ctor arguments) - no need to wrap in array data = [data] if data.is_a? Class tx = Transaction.new( from: account, to: to, value: value, data: data ) ## special case - contract creation transaction if to == '0x0000' klass = data[0] ## contract class - todo/fix: check if data[] is a contract class!!! args = data[1..-1] ## arguments puts "** tx ##{counter} (block ##{block.number}): #{tx.log_str}" contract = klass.new( *args ) ## note: balance and this (and msg.send/transfer) NOT available/possible !!!! if value > 0 ## move value to msg (todo/fix: restore if exception) account._sub( value ) # (sub)tract / debit from the sender (account) contract._add( value ) # add / credit to the recipient end puts " new #{contract.class.name} contract adddress: #{contract.address.inspect}" ## add new contract to (lookup) directory Contract.store( contract.address, contract ) ## issue (mined) transaction receipt receipt = Receipt.new( tx: tx, block: block, contract: contract ) else if value > 0 ## move value to msg (todo/fix: restore if exception) account._sub( value ) # (sub)tract / debit from the sender (account) to._add( value ) # add / credit to the recipient end self.this = to ## assumes for now that to is always a contract (and NOT an account)!!! data = [:receive] if data.empty? ## assume receive (default method) for now if data empty (no method specified) m = data[0] ## method name / signature args = data[1..-1] ## arguments puts "** tx ##{counter} (block ##{block.number}): #{tx.log_str}" to.__send__( m, *args ) ## note: use __send__ to avoid clash with send( value ) for sending payments!!! ## issue (mined) transaction receipt receipt = Receipt.new( tx: tx, block: block ) end Receipt.store( receipt ) tx # return transaction end |
.this ⇒ Object
returns current contract
566 567 568 |
# File 'lib/universum/universum.rb', line 566 def self.this ## returns current contract @@this end |
.this=(value) ⇒ Object
570 571 572 573 |
# File 'lib/universum/universum.rb', line 570 def self.this=(value) ## todo/fix: check that value is a contract @@this = value end |
.version ⇒ Object
14 15 16 |
# File 'lib/universum/version.rb', line 14 def self.version VERSION end |