solidity-typed 0.1.0 → 0.1.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/CHANGELOG.md +1 -1
- data/Manifest.txt +2 -0
- data/README.md +1 -1
- data/lib/solidity/typed/event.rb +68 -0
- data/lib/solidity/typed/event_builder.rb +101 -0
- data/lib/solidity/typed/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c209d69069ab4c0be94317f5318c388111486624b5b58c4939a11e65daa96009
|
4
|
+
data.tar.gz: 4082fa24ca6d8dca5f41380eabc72eabf73fc495f3856b667e10b1dcdfc25d06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9cd172d11fa9623a5f2ad591dde7cb91288438d28630a7320ac4bfffbcc8ecf23b0c3d8bff8c454e0ef0b40d07ed4b1e31b8f12b6d34f78e81b4528e2af7c0d
|
7
|
+
data.tar.gz: 06c6ba058fc6d2dbd33f4e3a2d652519a8df9646deabbf481457ddced39033b93c83fbc4c34982b56400d12975b6aa67797b4d51716ca751828e551c956854d8
|
data/CHANGELOG.md
CHANGED
data/Manifest.txt
CHANGED
@@ -9,6 +9,8 @@ lib/solidity/typed/bool.rb
|
|
9
9
|
lib/solidity/typed/conversion.rb
|
10
10
|
lib/solidity/typed/enum.rb
|
11
11
|
lib/solidity/typed/enum_builder.rb
|
12
|
+
lib/solidity/typed/event.rb
|
13
|
+
lib/solidity/typed/event_builder.rb
|
12
14
|
lib/solidity/typed/mapping.rb
|
13
15
|
lib/solidity/typed/mapping_builder.rb
|
14
16
|
lib/solidity/typed/metatypes/array.rb
|
data/README.md
CHANGED
@@ -312,7 +312,7 @@ at the ruby code commons (rubycocos) org.
|
|
312
312
|
## Questions? Comments?
|
313
313
|
|
314
314
|
Join us in the [Rubidity (community) discord (chat server)](https://discord.gg/3JRnDUap6y). Yes you can.
|
315
|
-
Your questions and
|
315
|
+
Your questions and commentary welcome.
|
316
316
|
|
317
317
|
Or post them over at the [Help & Support](https://github.com/geraldb/help) page. Thanks.
|
318
318
|
|
@@ -0,0 +1,68 @@
|
|
1
|
+
|
2
|
+
module Types
|
3
|
+
class Event < Typed
|
4
|
+
|
5
|
+
def self.zero
|
6
|
+
raise "event cannot be zero (by defintion); sorry"
|
7
|
+
end
|
8
|
+
|
9
|
+
def zero?() false; end
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
def initialize( *args, **kwargs )
|
14
|
+
## fix-fix-fix: first check for matching args - why? why not?
|
15
|
+
if kwargs.size > 0 ## assume kwargs
|
16
|
+
## note: kwargs.size check matching attributes "upstream" in new!!!
|
17
|
+
self.class.attributes.each do |key, type|
|
18
|
+
value = kwargs[ key ]
|
19
|
+
raise ArgumentError, "event arg with key >#{key}< missing; sorry" if value.nil?
|
20
|
+
value = if value.is_a?(Typed)
|
21
|
+
## fix-fix-fix - check type match here!!!
|
22
|
+
value
|
23
|
+
else
|
24
|
+
type.new( value )
|
25
|
+
end
|
26
|
+
instance_variable_set( "@#{key}", value )
|
27
|
+
end
|
28
|
+
else
|
29
|
+
self.class.attributes.zip( args ).each do |(key, type), value|
|
30
|
+
value = if value.is_a?(Typed)
|
31
|
+
## fix-fix-fix - check type match here!!!
|
32
|
+
value
|
33
|
+
else
|
34
|
+
type.new( value )
|
35
|
+
end
|
36
|
+
instance_variable_set( "@#{key}", value )
|
37
|
+
end
|
38
|
+
end
|
39
|
+
self ## note: return reference to self for chaining method calls
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def as_data
|
44
|
+
self.class.attributes.keys.map do |key|
|
45
|
+
ivar = instance_variable_get( "@#{key}" )
|
46
|
+
puts " @#{key}:"
|
47
|
+
pp ivar
|
48
|
+
ivar.as_data
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def ==(other)
|
54
|
+
if other.is_a?( self.class )
|
55
|
+
self.class.attributes.keys.all? do |key|
|
56
|
+
__send__( key ) == other.__send__( key )
|
57
|
+
end
|
58
|
+
else
|
59
|
+
false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
## do note override eql? why? why not?
|
63
|
+
# default is object id equality???
|
64
|
+
## alias_method :eql?, :==
|
65
|
+
|
66
|
+
|
67
|
+
end # class Event
|
68
|
+
end # module Types
|
@@ -0,0 +1,101 @@
|
|
1
|
+
|
2
|
+
module Types
|
3
|
+
class Event
|
4
|
+
|
5
|
+
|
6
|
+
# todo/fix: scope: keep empty by default
|
7
|
+
|
8
|
+
def self.build_class( class_name, scope: Types, **attributes )
|
9
|
+
|
10
|
+
## todo/fix:
|
11
|
+
## check if valid class_name MUST start with uppercase letter etc.
|
12
|
+
## todo/fix: check if constant is undefined in scoped namespace!!!!
|
13
|
+
|
14
|
+
attributes = attributes.map do |key,type|
|
15
|
+
[key, typeof( type )]
|
16
|
+
end.to_h
|
17
|
+
|
18
|
+
|
19
|
+
## note: event is a like a value type e.g. only getters
|
20
|
+
## no setters (can only initialized via constructor or such)
|
21
|
+
klass = Class.new( Event ) do
|
22
|
+
attributes.each do |key,type|
|
23
|
+
define_method( key ) do
|
24
|
+
instance_variable_get( "@#{key}" )
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
alias_method :old_freeze, :freeze # note: store "old" orginal version of freeze
|
30
|
+
define_method( :freeze ) do
|
31
|
+
old_freeze ## same as calling super
|
32
|
+
attributes.keys.each do |key|
|
33
|
+
instance_variable_get( "@#{key}" ).freeze
|
34
|
+
end
|
35
|
+
self # return reference to self
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
type = EventType.new( class_name, klass )
|
41
|
+
klass.define_singleton_method( :type ) do
|
42
|
+
@type ||= type
|
43
|
+
end
|
44
|
+
|
45
|
+
## add attributes (with keys / types) class method
|
46
|
+
klass.define_singleton_method( :attributes ) do
|
47
|
+
attributes
|
48
|
+
end
|
49
|
+
|
50
|
+
### todo/fix:
|
51
|
+
## auto-add support for kwargs too!!!
|
52
|
+
|
53
|
+
## add self.new too - note: call/forward to "old" orginal self.new of Event (base) class
|
54
|
+
klass.define_singleton_method( :new ) do |*args, **kwargs|
|
55
|
+
if kwargs.size > 0 ## assume kwargs
|
56
|
+
if kwargs.size != attributes.size
|
57
|
+
raise ArgumentError, "[Event] wrong number of arguments for #{name}.new - #{kwargs.size} for #{attributes.size}"
|
58
|
+
end
|
59
|
+
## check for matching names too - why? why not?
|
60
|
+
if kwargs.keys.sort != attributes.keys.sort
|
61
|
+
raise ArgumentError, "[Event] argument key (names) not matching for #{name}.new - #{kwargs.key.sort} != #{attributes.key.sort} for #{attributes.size}"
|
62
|
+
end
|
63
|
+
old_new( **kwargs )
|
64
|
+
else
|
65
|
+
if args.size != attributes.size
|
66
|
+
## check for required args/params - all MUST be passed in!!!
|
67
|
+
raise ArgumentError, "[Event] wrong number of arguments for #{name}.new - #{args.size} for #{attributes.size}"
|
68
|
+
end
|
69
|
+
old_new( *args )
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
=begin
|
74
|
+
## note: use Kernel for "namespacing"
|
75
|
+
## make all enums convenience converters (always) global
|
76
|
+
## including uppercase methods (e.g. State(), Color(), etc.) does NOT work otherwise (with other module includes)
|
77
|
+
|
78
|
+
## add global "Kernel" convenience converter function
|
79
|
+
## e.g. Vote(0) is same as Vote.convert(0)
|
80
|
+
Kernel.class_eval( <<RUBY )
|
81
|
+
def #{class_name}( arg )
|
82
|
+
#{class_name}.convert( arg )
|
83
|
+
end
|
84
|
+
RUBY
|
85
|
+
=end
|
86
|
+
|
87
|
+
## note: use scoped (module) and NOT Object for namespacing
|
88
|
+
## use include Safe to make all structs global
|
89
|
+
## fix-fix-fix - make class_name unique across contracts (e.g. reuse same name in different contract)
|
90
|
+
scope.const_set( class_name, klass ) ## returns klass (plus sets global constant class name)
|
91
|
+
end # method build_class
|
92
|
+
|
93
|
+
|
94
|
+
class << self
|
95
|
+
alias_method :old_new, :new # note: store "old" orginal version of new
|
96
|
+
alias_method :new, :build_class # replace original version with create
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
end # class Event
|
101
|
+
end # module Types
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidity-typed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.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: 2023-10-
|
11
|
+
date: 2023-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|
@@ -67,6 +67,8 @@ files:
|
|
67
67
|
- lib/solidity/typed/conversion.rb
|
68
68
|
- lib/solidity/typed/enum.rb
|
69
69
|
- lib/solidity/typed/enum_builder.rb
|
70
|
+
- lib/solidity/typed/event.rb
|
71
|
+
- lib/solidity/typed/event_builder.rb
|
70
72
|
- lib/solidity/typed/mapping.rb
|
71
73
|
- lib/solidity/typed/mapping_builder.rb
|
72
74
|
- lib/solidity/typed/metatypes/array.rb
|