universum 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ed79bd806a5db0f1d5a92a0dfd2e7f3f3b3db56
4
- data.tar.gz: 89afee15e5c5800220c13f8f7b58dffb190a4177
3
+ metadata.gz: 9961651cc18f32bfc222fef5624575241469923a
4
+ data.tar.gz: ab74188d3a3324451981a8f67693ae494265ff39
5
5
  SHA512:
6
- metadata.gz: ed45e6ab943f70fcd6a9c43c4faa98ab6f6e606f5808e188276b16efc1464603d393ccb4763484c4f33e8f0386a0644a83a6c0856b6197054240f67f486884bf
7
- data.tar.gz: f9f0fe016eb2113b1705ec86aed96530690b250e8b83dbff0751b43b7d901ef404dd3bb769ef5e7ae66d75e9ec26cedca6e219fc6561c42e99355e17320be980
6
+ metadata.gz: 8317f92d3e8ad3e96f28fc29da3eb7964f624c443f1cc315fac1bcceb9a943a8894f29643c847254c0b8a5be2861e319f408147e88ecf020878d6736460098d6
7
+ data.tar.gz: 88481a56b4b6675c2039122b4dca23ec241f9c7fc5882e3c614726ba9201cb1bece06b5d2c14db8cbef250edf3ba87cf05bb6e64be2ac90783232c81ef860178
@@ -8,15 +8,12 @@ lib/universum/account.rb
8
8
  lib/universum/address.rb
9
9
  lib/universum/contract.rb
10
10
  lib/universum/convert.rb
11
- lib/universum/enum.rb
12
11
  lib/universum/event.rb
13
12
  lib/universum/function.rb
14
13
  lib/universum/receipt.rb
15
14
  lib/universum/storage.rb
16
15
  lib/universum/transaction.rb
17
16
  lib/universum/type.rb
18
- lib/universum/units_money.rb
19
- lib/universum/units_time.rb
20
17
  lib/universum/universum.rb
21
18
  lib/universum/version.rb
22
19
  test/contracts/ballot.rb
@@ -24,11 +21,8 @@ test/contracts/greeter.rb
24
21
  test/contracts/mytoken.rb
25
22
  test/helper.rb
26
23
  test/test_ballot.rb
27
- test/test_enum.rb
28
24
  test/test_event.rb
29
25
  test/test_greeter.rb
30
26
  test/test_mytoken.rb
31
27
  test/test_storage.rb
32
- test/test_units_money.rb
33
- test/test_units_time.rb
34
28
  test/test_version.rb
data/Rakefile CHANGED
@@ -18,7 +18,9 @@ Hoe.spec 'universum' do
18
18
  self.history_file = 'CHANGELOG.md'
19
19
 
20
20
  self.extra_deps = [
21
- ['safestruct', '>=1.0.0'],
21
+ ['safestruct', '>=1.2.0'],
22
+ ['units-time', '>=1.0.2'],
23
+ ['units-money', '>=0.1.1'],
22
24
  ]
23
25
 
24
26
  self.licenses = ['Public Domain']
@@ -10,19 +10,20 @@ require 'uri'
10
10
 
11
11
 
12
12
  ## 3rd party gems
13
- require 'safestruct' # SafeArray, SafeHash, SafeStruct, etc.
13
+ require 'safestruct' # SafeArray, SafeHash, SafeStruct, Enum, etc.
14
14
 
15
15
  ## note: make Mapping an alias for Hash (lets you use Mapping.of() for Hash.of)
16
16
  Mapping = Hash
17
17
 
18
+ require 'units-time' # Timestamp, Timedelta, etc.
19
+ require 'units-money' # Money, etc.
20
+
21
+
18
22
 
19
23
  ## our own code
20
24
  require 'universum/version' # note: let version always go first
21
25
 
22
- require 'universum/units_time'
23
- require 'universum/units_money'
24
26
 
25
- require 'universum/enum'
26
27
  require 'universum/event'
27
28
 
28
29
  require 'universum/function'
@@ -3,9 +3,5 @@
3
3
 
4
4
  ## add more dummy classes for mapping and (payable) method signature
5
5
 
6
- class Money
7
- def self.zero() 0; end
8
- end
9
-
10
6
  class Void ## only used (reserved) for (payable) method signature now
11
7
  end
@@ -17,7 +17,7 @@ end # class Msg
17
17
  class Block
18
18
  attr_reader :timestamp, :number
19
19
 
20
- def initialize( timestamp: Time.now.to_i, number: 0 )
20
+ def initialize( timestamp: Timestamp.now, number: 0 )
21
21
  @timestamp = timestamp # unix epoch time (in seconds since 1970)
22
22
  @number = number # block height (start with 0 - genesis block)
23
23
  end
@@ -7,7 +7,7 @@
7
7
  class Universum
8
8
 
9
9
  MAJOR = 0
10
- MINOR = 4
10
+ MINOR = 5
11
11
  PATCH = 0
12
12
  VERSION = [MAJOR,MINOR,PATCH].join('.')
13
13
 
@@ -1,12 +1,13 @@
1
1
  #########################
2
2
  # Ballot Contract
3
3
 
4
- Voter = Struct.new( weight: 0,
5
- voted: false,
6
- vote: 0,
7
- delegate: Address(0))
4
+ Struct.new( :Voter,
5
+ weight: 0,
6
+ voted: false,
7
+ vote: 0,
8
+ delegate: Address(0))
8
9
 
9
- Proposal = Struct.new( vote_count: 0 )
10
+ Struct.new( :Proposal, vote_count: 0 )
10
11
 
11
12
  ## Create a new ballot with $(num_proposals) different proposals.
12
13
  def setup( num_proposals )
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.4.0
4
+ version: 0.5.0
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-02-19 00:00:00.000000000 Z
11
+ date: 2019-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: safestruct
@@ -16,14 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.0
19
+ version: 1.2.0
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.0.0
26
+ version: 1.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: units-time
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: units-money
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.1
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: rdoc
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -75,15 +103,12 @@ files:
75
103
  - lib/universum/address.rb
76
104
  - lib/universum/contract.rb
77
105
  - lib/universum/convert.rb
78
- - lib/universum/enum.rb
79
106
  - lib/universum/event.rb
80
107
  - lib/universum/function.rb
81
108
  - lib/universum/receipt.rb
82
109
  - lib/universum/storage.rb
83
110
  - lib/universum/transaction.rb
84
111
  - lib/universum/type.rb
85
- - lib/universum/units_money.rb
86
- - lib/universum/units_time.rb
87
112
  - lib/universum/universum.rb
88
113
  - lib/universum/version.rb
89
114
  - test/contracts/ballot.rb
@@ -91,13 +116,10 @@ files:
91
116
  - test/contracts/mytoken.rb
92
117
  - test/helper.rb
93
118
  - test/test_ballot.rb
94
- - test/test_enum.rb
95
119
  - test/test_event.rb
96
120
  - test/test_greeter.rb
97
121
  - test/test_mytoken.rb
98
122
  - test/test_storage.rb
99
- - test/test_units_money.rb
100
- - test/test_units_time.rb
101
123
  - test/test_version.rb
102
124
  homepage: https://github.com/s6ruby/universum
103
125
  licenses:
@@ -1,92 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ##################################
4
- ## auto-create/builds enum class.
5
- ##
6
- ## Example:
7
- ## State = Enum.new( :fundraising, :expired_refund, :successful)
8
- ## auto-creates/builds:
9
- ##
10
- ## class Enum
11
- ## def initialize( key, value )
12
- ## @key = key
13
- ## @value = value
14
- ## end
15
- ## end
16
- ##
17
- ## class State < Enum
18
- ##
19
- ## FUNDRAISING = new(:fundraising, 0)
20
- ## EXPIRED_REFUND = new(:expired_refund, 1)
21
- ## SUCCESSFUL = new(:successful, 2)
22
- ##
23
- ## def self.fundraising() FUNDRAISING; end
24
- ## def self.expired_refund() EXPIRED_REFUND; end
25
- ## def self.successful() SUCCESSFUL; end
26
- ##
27
- ## def fundraising?() self == FUNDRAISING; end
28
- ## def expired_refund?() self == EXPIRED_REFUND; end
29
- ## def successful?() self == SUCCESSFUL; end
30
- ## end
31
- ##
32
- ## pp state = State.fundraising #=> #<State @key=:fundraising, @value=0>
33
- ## pp state.fundraising? #=> true
34
- ## pp state.expired_refund? #=> false
35
- ## pp state.successful? #=> false
36
- ## pp state = State.expired_refund #=> #<State @key=:expired_refund, @value=1>
37
- ## pp state.fundraising? #=> false
38
- ## pp state.expired_refund? #=> true
39
- ## pp state.successful? #=> false
40
-
41
-
42
- ## base class for enum
43
- class Enum
44
- ## return a new Enum read-only class
45
-
46
- def initialize( key, value )
47
- @key = key
48
- @value = value
49
- end
50
-
51
-
52
- ###################
53
- ## meta-programming "macro" - build class (on the fly)
54
- def self.build_class( *keys )
55
-
56
- ## check if all keys are symbols and follow the ruby id(entifier) naming rules
57
- keys.each do |key|
58
- if key.is_a?( Symbol ) && key =~ /\A[a-z][a-zA-Z0-9_]*\z/
59
- else
60
- raise ArgumentError.new( "[Enum] arguments to Enum.new must be all symbols following the ruby id naming rules; >#{key}< failed" )
61
- end
62
- end
63
-
64
- klass = Class.new( Enum )
65
-
66
- ## add self.new too - note: call/forward to "old" orginal self.new of Event (base) class
67
- klass.define_singleton_method( :new ) do |*args|
68
- old_new( *args )
69
- end
70
-
71
- keys.each_with_index do |key,index|
72
- klass.class_eval( <<RUBY )
73
- #{key.upcase} = new( :#{key}, #{index} )
74
-
75
- def #{key}?
76
- self == #{key.upcase}
77
- end
78
-
79
- def self.#{key}
80
- #{key.upcase}
81
- end
82
- RUBY
83
- end
84
-
85
- klass
86
- end
87
-
88
- class << self
89
- alias_method :old_new, :new # note: store "old" orginal version of new
90
- alias_method :new, :build_class # replace original version with create
91
- end
92
- end # class Enum
@@ -1,63 +0,0 @@
1
- # encoding: utf-8
2
-
3
- class Integer
4
-
5
- E3 = 10**3 # 1_000
6
- E6 = 10**6 # 1_000_000
7
- E9 = 10**9 # 1_000_000_000
8
- E12 = 10**12 # 1_000_000_000_000
9
- E15 = 10**15 # 1_000_000_000_000_000
10
- E18 = 10**18 # 1_000_000_000_000_000_000
11
-
12
- def e3() self * E3; end
13
- def e6() self * E6; end
14
- def e9() self * E9; end
15
- def e12() self * E12; end
16
- def e15() self * E15; end
17
- def e18() self * E18; end
18
-
19
-
20
- ## todo/fix: move ethereum money units to a module and include here
21
-
22
- ###########
23
- # Ethereum money units
24
- #
25
- # wei 1 wei | 1
26
- # kwei (babbage) 1e3 wei | 1_000
27
- # mwei (lovelace) 1e6 wei | 1_000_000
28
- # gwei (shannon) 1e9 wei | 1_000_000_000
29
- # microether (szabo) 1e12 wei | 1_000_000_000_000
30
- # milliether (finney) 1e15 wei | 1_000_000_000_000_000
31
- # ether 1e18 wei | 1_000_000_000_000_000_000
32
- #
33
- # Names in Honor:
34
- # wei => Wei Dai
35
- # lovelace => Ada Lovelace (1815-1852)
36
- # babbage => Charles Babbage (1791-1871)
37
- # shannon => Claude Shannon (1916-2001)
38
- # szabo => Nick Szabo
39
- # finney => Hal Finney (1956-2014)
40
-
41
- def wei() self; end
42
- def kwei() self * E3; end
43
- def mwei() self * E6; end
44
- def gwei() self * E9; end
45
- def microether() self * E12; end
46
- def milliether() self * E15; end
47
- def ether() self * E18; end
48
-
49
- ########################################################
50
- ## alias - use alias or alias_method - why? why not?
51
- def babbage() kwei; end
52
- def lovelace() mwei; end
53
- def shannon() gwei; end
54
- def szabo() microether; end
55
- def finney() milliether; end
56
-
57
- def microeth() microether; end
58
- def micro() microether; end
59
- def millieth() milliether; end
60
- def milli() milliether; end
61
- def eth() ether; end
62
-
63
- end # class Integer
@@ -1,51 +0,0 @@
1
- # encoding: utf-8
2
-
3
-
4
- class Integer
5
-
6
- ######################################
7
- ## note: there's NO month (for now)!!!
8
- ## why? month might be 28,29,30,31 days
9
- ## use days e.g. 30.days or 31.days etc.
10
-
11
- HOUR_IN_SECONDS = 60 * 60 # 60 minutes * 60 seconds
12
- DAY_IN_SECONDS = 24 * HOUR_IN_SECONDS # 24 hours * 60 * 60
13
- WEEK_IN_SECONDS = 7 * DAY_IN_SECONDS # 7 days * 24 * 60 * 60
14
- FORTNIGHT_IN_SECONDS = 14 * DAY_IN_SECONDS # 14 days * 24 * 60 * 60
15
- YEAR_IN_SECONDS = 365 * DAY_IN_SECONDS # 365 days * 24 * 60 * 60
16
-
17
- def second() self; end
18
- def minute() self * 60; end
19
- def hour() self * HOUR_IN_SECONDS; end
20
- def day() self * DAY_IN_SECONDS; end
21
- def week() self * WEEK_IN_SECONDS; end
22
- def fortnight() self * FORTNIGHT_IN_SECONDS; end
23
- def year() self * YEAR_IN_SECONDS; end
24
-
25
- ########################################################
26
- ## alias - use alias or alias_method - why? why not?
27
- def seconds() second; end
28
- def secs() second; end
29
- def sec() second; end
30
- def s() second; end
31
-
32
- def minutes() minute; end
33
- def mins() minute; end
34
- def min() minute; end
35
- def m() minute; end
36
-
37
- def hours() hour; end
38
- def h() hour; end
39
-
40
- def days() day; end
41
- def d() day; end
42
-
43
- def weeks() week; end
44
- def w() week; end
45
-
46
- def fortnights() fortnight; end
47
-
48
- def years() year; end
49
- def y() year; end
50
-
51
- end # class Integer
@@ -1,30 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_enum.rb
6
-
7
-
8
- require 'helper'
9
-
10
-
11
- class TestEnum < MiniTest::Test
12
-
13
- State = Enum.new( :fundraising, :expired_refund, :successful )
14
-
15
- def test_state
16
- pp State
17
-
18
- state = State.fundraising
19
- assert state.is_a?( Enum )
20
-
21
- assert_equal true, state.fundraising?
22
- assert_equal false, state.expired_refund?
23
- assert_equal false, state.successful?
24
-
25
- state = State.expired_refund
26
- assert_equal false, state.fundraising?
27
- assert_equal true, state.expired_refund?
28
- assert_equal false, state.successful?
29
- end
30
- end # class TestEnum
@@ -1,59 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_units_money.rb
6
-
7
-
8
- require 'helper'
9
-
10
-
11
- class TestUnitsMoney < MiniTest::Test
12
-
13
- def test_money
14
- assert_equal 1_000_000_000_000_000_000, 1.e18
15
- assert_equal 1_000_000_000_000_000, 1.e15
16
- assert_equal 1_000_000_000_000, 1.e12
17
- assert_equal 1_000_000_000, 1.e9
18
- assert_equal 1_000_000, 1.e6
19
- assert_equal 1_000, 1.e3
20
-
21
-
22
- value = rand( 1_000_000_000 )
23
-
24
- assert_equal 1_000_000_000_000_000_000, 1.ether
25
- assert_equal 1_000_000_000_000_000_000, 1.eth
26
- assert_equal 1_000_000_000_000_000_000*2, 1.ether*2
27
- assert_equal value+1_000_000_000_000_000_000, value+1.ether
28
-
29
- assert_equal 1_000_000_000_000_000, 1.milliether
30
- assert_equal 1_000_000_000_000_000, 1.millieth
31
- assert_equal 1_000_000_000_000_000, 1.milli
32
- assert_equal 1_000_000_000_000_000, 1.finney
33
- assert_equal 1_000_000_000_000_000*2, 1.milliether*2
34
- assert_equal value+1_000_000_000_000_000, value+1.milliether
35
-
36
- assert_equal 1_000_000_000_000, 1.microether
37
- assert_equal 1_000_000_000_000, 1.microeth
38
- assert_equal 1_000_000_000_000, 1.micro
39
- assert_equal 1_000_000_000_000, 1.szabo
40
- assert_equal 1_000_000_000_000*2, 1.microether*2
41
- assert_equal value+1_000_000_000_000, value+1.microether
42
-
43
- assert_equal 1_000_000_000, 1.gwei
44
- assert_equal 1_000_000_000, 1.shannon
45
- assert_equal 1_000_000_000*2, 1.gwei*2
46
- assert_equal value+1_000_000_000, value+1.gwei
47
-
48
- assert_equal 1_000_000, 1.mwei
49
- assert_equal 1_000_000, 1.lovelace
50
- assert_equal 1_000_000*2, 1.mwei*2
51
- assert_equal value+1_000_000, value+1.mwei
52
-
53
- assert_equal 1_000, 1.kwei
54
- assert_equal 1_000, 1.babbage
55
- assert_equal 1_000*2, 1.kwei*2
56
- assert_equal value+1_000, value+1.kwei
57
- end
58
-
59
- end # class TestUnitsMoney
@@ -1,75 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_units_time.rb
6
-
7
-
8
- require 'helper'
9
-
10
-
11
- class TestUnitsTime < MiniTest::Test
12
-
13
- def test_time
14
- now = Time.now.to_i
15
-
16
- assert_equal 31_536_000, 1.year
17
- assert_equal 31_536_000, 1.y
18
- assert_equal 31_536_000*2, 2.years
19
- assert_equal 31_536_000*2, 1.y*2
20
- assert_equal now+31_536_000, now+1.year
21
- assert_equal 31_536_000, 365.days
22
- assert_equal 31_536_000, 365*24.hours
23
-
24
- assert_equal 1_209_600, 1.fortnight
25
- assert_equal 1_209_600*2, 2.fortnights
26
- assert_equal 1_209_600*2, 1.fortnight*2
27
- assert_equal now+1_209_600, now+1.fortnight
28
- assert_equal 1_209_600, 2.weeks
29
- assert_equal 1_209_600, 14.days
30
- assert_equal 1_209_600, 14*24.hours
31
-
32
- assert_equal 604_800, 1.week
33
- assert_equal 604_800, 1.w
34
- assert_equal 604_800*2, 2.weeks
35
- assert_equal 604_800*2, 1.week*2
36
- assert_equal now+604_800, now+1.week
37
- assert_equal 604_800, 7.days
38
- assert_equal 604_800, 7*24.hours
39
-
40
- assert_equal 86_400, 1.day
41
- assert_equal 86_400, 1.d
42
- assert_equal 86_400*2, 2.days
43
- assert_equal 86_400*2, 1.day*2
44
- assert_equal now+86_400, now+1.day
45
- assert_equal 86_400, 24.hours
46
- assert_equal 86_400, 24*1.hour
47
-
48
- assert_equal 3600, 1.hour
49
- assert_equal 3600, 1.h
50
- assert_equal 3600*2, 2.hours
51
- assert_equal 3600*2, 1.hour*2
52
- assert_equal now+3600, now+1.hour
53
- assert_equal 3600, 60.minutes
54
- assert_equal 3600, 60*1.minute
55
-
56
- assert_equal 60, 1.minute
57
- assert_equal 60, 1.min
58
- assert_equal 60, 1.m
59
- assert_equal 60*2, 2.minutes
60
- assert_equal 60*2, 2.mins
61
- assert_equal 60*2, 1.minute*2
62
- assert_equal now+60, now+1.minute
63
- assert_equal 60, 60.seconds
64
- assert_equal 60, 60*1.second
65
-
66
- assert_equal 1, 1.second
67
- assert_equal 1, 1.sec
68
- assert_equal 1, 1.s
69
- assert_equal 1*2, 2.seconds
70
- assert_equal 1*2, 2.secs
71
- assert_equal 1*2, 1.second*2
72
- assert_equal now+1, now+1.second
73
- end
74
-
75
- end # class TestUnitsTime