universum 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +2 -2
- data/lib/universum/contract.rb +11 -2
- data/lib/universum/convert.rb +6 -10
- data/lib/universum/event.rb +25 -2
- data/lib/universum/version.rb +1 -1
- data/test/contracts/ballot.rb +8 -6
- data/test/test_event.rb +5 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8948db2f1aea78f74fb4f7b28cb3fc9a71305f5
|
4
|
+
data.tar.gz: c30a20c747c63c936198d708d577ee83814c5cff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c558a3f8bc24ad303de084f126bf75b7d7cb40c32d6ba8311cb7afbd959072fa8777b6c84ee339b735db91fa79f35af2a926cd16a1fdb7d012b255c58ff00258
|
7
|
+
data.tar.gz: 0dd4ed89cf4fe5d82b725c5fe6dde84b92b9488caf03c3acef08de94323fb3048fdf5545ff3cd79539cb9b2d93a8e7ec14c797c17b5e5cb89ae5d3ceabc81a35
|
data/Rakefile
CHANGED
data/lib/universum/contract.rb
CHANGED
@@ -105,15 +105,24 @@ class Contract
|
|
105
105
|
# def receive ## @payable default fallback - use different name - why? why not? (e.g. handle/process/etc.)
|
106
106
|
# end
|
107
107
|
|
108
|
-
|
108
|
+
|
109
|
+
####
|
110
|
+
### todo/fix: use module Assertions and include in contract class
|
111
|
+
def assert( condition, message=nil )
|
112
|
+
## note: use message to avoid conflict with msg helper/builtin in contract!!!
|
109
113
|
if condition == true
|
110
114
|
## do nothing
|
111
115
|
else
|
112
|
-
|
116
|
+
if message
|
117
|
+
raise "Contract Assertion Failed; Contract Halted (Stopped): #{message}"
|
118
|
+
else
|
119
|
+
raise 'Contract Assertion Failed; Contract Halted (Stopped)'
|
120
|
+
end
|
113
121
|
end
|
114
122
|
end
|
115
123
|
|
116
124
|
|
125
|
+
|
117
126
|
def log( event ) Universum.log( event ); end
|
118
127
|
def msg() Universum.msg; end
|
119
128
|
def block() Universum.block; end
|
data/lib/universum/convert.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
###
|
4
|
-
# e.g. use Address(0)
|
5
3
|
|
4
|
+
## note: put all "global" Kernel converter methods into Kernel module
|
5
|
+
module Kernel
|
6
|
+
|
7
|
+
###
|
8
|
+
# e.g. use Address(0)
|
6
9
|
def Address( arg )
|
7
10
|
if arg == 0 || arg == '0x0' || arg == '0x0000'
|
8
11
|
'0x0000' ## note: return a string for now and NOT (typed) Address.zero
|
@@ -16,11 +19,4 @@ def Address( arg )
|
|
16
19
|
end
|
17
20
|
end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
###
|
22
|
-
## todo - add a global method_missing handler for (auto-)adding converters for Structs - why? why not?
|
23
|
-
## e.g. how to auto-create Vote(0) for Vote.zero or Bet(0) for Bet.zero and so on - why? why not?
|
24
|
-
##
|
25
|
-
## def Vote( arg ) Vote.zero; end
|
26
|
-
|
22
|
+
end # module Kernel
|
data/lib/universum/event.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
## auto-create/builds struct-like class.
|
5
5
|
##
|
6
6
|
## Example:
|
7
|
-
##
|
7
|
+
## Event.new( :Roll, :id, :rolled )
|
8
8
|
## auto-creates/builds:
|
9
9
|
##
|
10
10
|
## class Event; end
|
@@ -23,6 +23,7 @@
|
|
23
23
|
## pp roll.rolled #=> 2345
|
24
24
|
|
25
25
|
|
26
|
+
module Safe
|
26
27
|
## base class for events
|
27
28
|
class Event
|
28
29
|
## return a new Struct-like read-only class
|
@@ -30,7 +31,7 @@ class Event
|
|
30
31
|
###################
|
31
32
|
## meta-programming "macro" - build class (on the fly)
|
32
33
|
##
|
33
|
-
def self.build_class( *fields )
|
34
|
+
def self.build_class( class_name, *fields )
|
34
35
|
klass = Class.new( Event ) do
|
35
36
|
define_method( :initialize ) do |*args|
|
36
37
|
fields.zip( args ).each do |field, arg|
|
@@ -51,6 +52,10 @@ class Event
|
|
51
52
|
old_new( *args )
|
52
53
|
end
|
53
54
|
|
55
|
+
## note: use Safe (module) and NOT Object for namespacing
|
56
|
+
## use include Safe to make all structs global
|
57
|
+
Safe.const_set( class_name, klass ) ## returns klass (plus sets global constant class name)
|
58
|
+
|
54
59
|
klass
|
55
60
|
end
|
56
61
|
|
@@ -59,3 +64,21 @@ class Event
|
|
59
64
|
alias_method :new, :build_class # replace original version with create
|
60
65
|
end
|
61
66
|
end # class Event
|
67
|
+
|
68
|
+
module SafeHelper
|
69
|
+
def event( class_name, *args )
|
70
|
+
########################################
|
71
|
+
# note: lets you use:
|
72
|
+
# enum :Color, :red, :green, :blue
|
73
|
+
# -or-
|
74
|
+
# enum :Color, [:red, :green, :blue]
|
75
|
+
if args[0].is_a?( Array )
|
76
|
+
fields = args[0]
|
77
|
+
else
|
78
|
+
fields = args
|
79
|
+
end
|
80
|
+
|
81
|
+
Event.new( class_name, *fields )
|
82
|
+
end
|
83
|
+
end # module SafeHelper
|
84
|
+
end # module Safe
|
data/lib/universum/version.rb
CHANGED
data/test/contracts/ballot.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
#########################
|
2
2
|
# Ballot Contract
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
struct :Voter,
|
5
|
+
weight: 0,
|
6
|
+
voted: false,
|
7
|
+
vote: 0,
|
8
|
+
delegate: Address(0)
|
9
|
+
|
10
|
+
struct :Proposal,
|
11
|
+
vote_count: 0
|
9
12
|
|
10
|
-
Struct.new( :Proposal, vote_count: 0 )
|
11
13
|
|
12
14
|
## Create a new ballot with $(num_proposals) different proposals.
|
13
15
|
def setup( num_proposals )
|
data/test/test_event.rb
CHANGED
@@ -9,9 +9,12 @@ require 'helper'
|
|
9
9
|
|
10
10
|
|
11
11
|
class TestEvent < MiniTest::Test
|
12
|
+
include Safe
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
## Event.new( :BetPlaced, :id, :user, :cap, :amount )
|
15
|
+
## Event.new( :Roll, :id, :rolled )
|
16
|
+
event :BetPlaced, :id, :user, :cap, :amount
|
17
|
+
event :Roll, :id, :rolled
|
15
18
|
|
16
19
|
|
17
20
|
def test_bet_placed
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: universum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: safestruct
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.2.
|
19
|
+
version: 1.2.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.2.
|
26
|
+
version: 1.2.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: units-time
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.0
|
33
|
+
version: 1.1.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.0
|
40
|
+
version: 1.1.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: units-money
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|