solidity-typed 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/Manifest.txt +3 -0
- data/README.md +5 -3
- data/Rakefile +1 -1
- data/lib/solidity/typed/conversion.rb +24 -3
- data/lib/solidity/typed/error.rb +81 -0
- data/lib/solidity/typed/error_builder.rb +103 -0
- data/lib/solidity/typed/integer.rb +58 -0
- data/lib/solidity/typed/metatypes/types.rb +52 -0
- data/lib/solidity/typed/numbers.rb +11 -0
- data/lib/solidity/typed/values.rb +33 -0
- data/lib/solidity/typed/version.rb +1 -1
- data/lib/solidity/typed.rb +6 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87b1228588a659eb48208556c664337bdcc1297fef7caf31c337a64f5fd67cac
|
4
|
+
data.tar.gz: 751ea77f7d80035cb0d8592b1ca4bfe33c22bac624aabe9a9bdfa68c069cdb78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d0f52e49d76845b977b6e231094e8c224e2005bb462bd11d96cce0b34d4b214af6f2ab9e76ca20aff7f5d7933d25f3c1e45f26199335ab18542776a543381a2
|
7
|
+
data.tar.gz: e2c573374311bcc119a149e7923a52e4c254e110bb929fb804fff0327ecd40306e3329ea1b8c2ef72d1cd66ddba26f7b6b91e2a2670798774e99e31a91b26065
|
data/CHANGELOG.md
CHANGED
data/Manifest.txt
CHANGED
@@ -9,8 +9,11 @@ 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/error.rb
|
13
|
+
lib/solidity/typed/error_builder.rb
|
12
14
|
lib/solidity/typed/event.rb
|
13
15
|
lib/solidity/typed/event_builder.rb
|
16
|
+
lib/solidity/typed/integer.rb
|
14
17
|
lib/solidity/typed/mapping.rb
|
15
18
|
lib/solidity/typed/mapping_builder.rb
|
16
19
|
lib/solidity/typed/metatypes/array.rb
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Solidity Typed
|
2
2
|
|
3
|
-
solidity-typed - "zero-dependency" 100%-solidity compatible data type and application binary interface (abi) machinery incl. bool, (frozen) string, address, bytes, uint, int, enum, struct, array, mapping, event, and more for solidity-inspired contract (blockchain) programming languages incl. rubidity et al
|
3
|
+
solidity-typed - "zero-dependency" 100%-solidity compatible data type and application binary interface (abi) machinery incl. bool, (frozen) string, address, bytes, uint, int, enum, struct, array, mapping, event, and more for solidity-inspired contract (blockchain) programming languages incl. rubidity, rubysol et al
|
4
4
|
|
5
5
|
|
6
6
|
|
@@ -11,12 +11,14 @@ solidity-typed - "zero-dependency" 100%-solidity compatible data type and applic
|
|
11
11
|
* rdoc :: [rubydoc.info/gems/solidity-typed](http://rubydoc.info/gems/solidity-typed)
|
12
12
|
|
13
13
|
|
14
|
-
## What's Solidity?! What's Rubidity?!
|
14
|
+
## What's Solidity?! What's Rubidity?! What's Rubysol?!
|
15
15
|
|
16
16
|
See [**Solidity - Contract Application Binary Interface (ABI) Specification** »](https://docs.soliditylang.org/en/latest/abi-spec.html)
|
17
17
|
|
18
18
|
See [**Rubidity - Ruby for Layer 1 (L1) Contracts / Protocols with "Off-Chain" Indexer** »](https://github.com/s6ruby/rubidity)
|
19
19
|
|
20
|
+
See [**Rubysol - Ruby for Layer 1 (L1) Contracts / Protocols with "Off-Chain" Indexer** »](https://github.com/s6ruby/rubidity/tree/master/rubysol)
|
21
|
+
|
20
22
|
|
21
23
|
|
22
24
|
|
@@ -311,7 +313,7 @@ at the ruby code commons (rubycocos) org.
|
|
311
313
|
|
312
314
|
## Questions? Comments?
|
313
315
|
|
314
|
-
Join us in the [Rubidity (community) discord (chat server)](https://discord.gg/3JRnDUap6y). Yes you can.
|
316
|
+
Join us in the [Rubidity & Rubysol (community) discord (chat server)](https://discord.gg/3JRnDUap6y). Yes you can.
|
315
317
|
Your questions and commentary welcome.
|
316
318
|
|
317
319
|
Or post them over at the [Help & Support](https://github.com/geraldb/help) page. Thanks.
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require './lib/solidity/typed/version.rb'
|
|
5
5
|
Hoe.spec 'solidity-typed' do
|
6
6
|
self.version = Solidity::Module::Typed::VERSION
|
7
7
|
|
8
|
-
self.summary = 'solidity-typed - "zero-dependency" 100%-solidity compatible data type and application binary interface (abi) machinery incl. bool, (frozen) string, address, bytes, uint, int, enum, struct, array, mapping, event, and more for solidity-inspired contract (blockchain) programming languages incl. rubidity et al'
|
8
|
+
self.summary = 'solidity-typed - "zero-dependency" 100%-solidity compatible data type and application binary interface (abi) machinery incl. bool, (frozen) string, address, bytes, uint, int, enum, struct, array, mapping, event, and more for solidity-inspired contract (blockchain) programming languages incl. rubidity, rubysol et al'
|
9
9
|
self.description = summary
|
10
10
|
|
11
11
|
self.urls = { home: 'https://github.com/s6ruby/rubidity' }
|
@@ -7,15 +7,27 @@
|
|
7
7
|
module ConversionFunctions
|
8
8
|
#####
|
9
9
|
# todo/check: use AddressType.try_convert( literal_or_obj ) or such - why? why not?
|
10
|
-
def address(
|
10
|
+
def address( obj )
|
11
11
|
## hack for now support address(0)
|
12
12
|
## todo/fix: address( '0x0' ) too!!!!
|
13
|
-
return Types::
|
13
|
+
return Types::Address.zero if obj.is_a?(::Integer) && obj == 0
|
14
14
|
|
15
|
-
|
15
|
+
## note: for now assume contract is always "construct"ed (and, thus, has an address assigned)
|
16
|
+
return Types::Address.new( obj.__address__ ) if obj.is_a?( Contract )
|
17
|
+
|
18
|
+
Types::Address.new( obj )
|
16
19
|
end # methdod address
|
17
20
|
|
18
21
|
|
22
|
+
def uint( obj )
|
23
|
+
return obj.to_uint if obj.is_a?( Types::Address )
|
24
|
+
return obj if obj.is_a?( Types::UInt )
|
25
|
+
|
26
|
+
Types::UInt.new( obj ) ## assume obj is a integer number
|
27
|
+
end
|
28
|
+
alias_method :uint256, :uint
|
29
|
+
alias_method :uint224, :uint
|
30
|
+
alias_method :uint112, :uint ## note: for now all are uint256 - fix? - why? why not?
|
19
31
|
=begin
|
20
32
|
def uint( obj=0 )
|
21
33
|
## check if typed?
|
@@ -24,6 +36,15 @@ end
|
|
24
36
|
=end
|
25
37
|
|
26
38
|
|
39
|
+
def bytes( obj )
|
40
|
+
return obj if obj.is_a?( Types::Bytes )
|
41
|
+
|
42
|
+
Types::Bytes.new( obj )
|
43
|
+
end
|
44
|
+
alias_method :bytes4, :bytes ## fix-fix-fix - cut of bytes (only first 4 bytes/8 hexchars)
|
45
|
+
|
46
|
+
|
47
|
+
|
27
48
|
|
28
49
|
=begin
|
29
50
|
def string(i)
|
@@ -0,0 +1,81 @@
|
|
1
|
+
|
2
|
+
module Types
|
3
|
+
|
4
|
+
## note: CANNOT derive from Typed
|
5
|
+
##
|
6
|
+
|
7
|
+
##
|
8
|
+
## why StandardError base?
|
9
|
+
## StandardError is default for rescue
|
10
|
+
|
11
|
+
|
12
|
+
class Error < StandardError
|
13
|
+
|
14
|
+
def type() self.class.type; end
|
15
|
+
def self.zero
|
16
|
+
raise "error cannot be zero (by defintion); sorry"
|
17
|
+
end
|
18
|
+
def zero?() false; end
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
def initialize( *args, **kwargs )
|
23
|
+
## fix-fix-fix: first check for matching args - why? why not?
|
24
|
+
if kwargs.size > 0 ## assume kwargs
|
25
|
+
## note: kwargs.size check matching attributes "upstream" in new!!!
|
26
|
+
self.class.attributes.each do |key, type|
|
27
|
+
value = kwargs[ key ]
|
28
|
+
raise ArgumentError, "error arg with key >#{key}< missing; sorry" if value.nil?
|
29
|
+
value = if value.is_a?(Typed)
|
30
|
+
## fix-fix-fix - check type match here!!!
|
31
|
+
value
|
32
|
+
else
|
33
|
+
type.new( value )
|
34
|
+
end
|
35
|
+
instance_variable_set( "@#{key}", value )
|
36
|
+
end
|
37
|
+
else
|
38
|
+
self.class.attributes.zip( args ).each do |(key, type), value|
|
39
|
+
value = if value.is_a?(Typed)
|
40
|
+
## fix-fix-fix - check type match here!!!
|
41
|
+
value
|
42
|
+
else
|
43
|
+
type.new( value )
|
44
|
+
end
|
45
|
+
instance_variable_set( "@#{key}", value )
|
46
|
+
end
|
47
|
+
end
|
48
|
+
self ## note: return reference to self for chaining method calls
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def as_data
|
53
|
+
self.class.attributes.keys.map do |key|
|
54
|
+
ivar = instance_variable_get( "@#{key}" )
|
55
|
+
puts " @#{key}:"
|
56
|
+
pp ivar
|
57
|
+
ivar.as_data
|
58
|
+
end
|
59
|
+
end
|
60
|
+
## keep serialize and/or as_json - why? why not?
|
61
|
+
def serialize() as_data; end
|
62
|
+
def as_json() as_data; end
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
def ==(other)
|
67
|
+
if other.is_a?( self.class )
|
68
|
+
self.class.attributes.keys.all? do |key|
|
69
|
+
__send__( key ) == other.__send__( key )
|
70
|
+
end
|
71
|
+
else
|
72
|
+
false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
## do note override eql? why? why not?
|
76
|
+
# default is object id equality???
|
77
|
+
## alias_method :eql?, :==
|
78
|
+
|
79
|
+
|
80
|
+
end # class Error
|
81
|
+
end # module Types
|
@@ -0,0 +1,103 @@
|
|
1
|
+
|
2
|
+
module Types
|
3
|
+
class Error
|
4
|
+
|
5
|
+
# todo/fix: scope: keep empty by default
|
6
|
+
|
7
|
+
def self.build_class( class_name, scope: Types, **attributes )
|
8
|
+
|
9
|
+
## todo/fix:
|
10
|
+
## check if valid class_name MUST start with uppercase letter etc.
|
11
|
+
## todo/fix: check if constant is undefined in scoped namespace!!!!
|
12
|
+
|
13
|
+
attributes = attributes.map do |key,type|
|
14
|
+
[key, typeof( type )]
|
15
|
+
end.to_h
|
16
|
+
|
17
|
+
|
18
|
+
## note: error is a like a value type e.g. only getters
|
19
|
+
## no setters (can only initialized via constructor or such)
|
20
|
+
klass = Class.new( Error ) do
|
21
|
+
attributes.each do |key,type|
|
22
|
+
define_method( key ) do
|
23
|
+
instance_variable_get( "@#{key}" )
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
alias_method :old_freeze, :freeze # note: store "old" orginal version of freeze
|
29
|
+
define_method( :freeze ) do
|
30
|
+
old_freeze ## same as calling super
|
31
|
+
attributes.keys.each do |key|
|
32
|
+
instance_variable_get( "@#{key}" ).freeze
|
33
|
+
end
|
34
|
+
self # return reference to self
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
## check - if Typed:: qualifier needed here?
|
40
|
+
## note Error class NOT derived from Typed (but StandardError)!!!!
|
41
|
+
## thus requires qualifier!!!
|
42
|
+
type = Typed::ErrorType.new( class_name, klass )
|
43
|
+
klass.define_singleton_method( :type ) do
|
44
|
+
@type ||= type
|
45
|
+
end
|
46
|
+
|
47
|
+
## add attributes (with keys / types) class method
|
48
|
+
klass.define_singleton_method( :attributes ) do
|
49
|
+
attributes
|
50
|
+
end
|
51
|
+
|
52
|
+
### todo/fix:
|
53
|
+
## auto-add support for kwargs too!!!
|
54
|
+
|
55
|
+
## add self.new too - note: call/forward to "old" orginal self.new of Error (base) class
|
56
|
+
klass.define_singleton_method( :new ) do |*args, **kwargs|
|
57
|
+
if kwargs.size > 0 ## assume kwargs
|
58
|
+
if kwargs.size != attributes.size
|
59
|
+
raise ArgumentError, "[Error] wrong number of arguments for #{name}.new - #{kwargs.size} for #{attributes.size}"
|
60
|
+
end
|
61
|
+
## check for matching names too - why? why not?
|
62
|
+
if kwargs.keys.sort != attributes.keys.sort
|
63
|
+
raise ArgumentError, "[Error] argument key (names) not matching for #{name}.new - #{kwargs.key.sort} != #{attributes.key.sort} for #{attributes.size}"
|
64
|
+
end
|
65
|
+
old_new( **kwargs )
|
66
|
+
else
|
67
|
+
if args.size != attributes.size
|
68
|
+
## check for required args/params - all MUST be passed in!!!
|
69
|
+
raise ArgumentError, "[Error] wrong number of arguments for #{name}.new - #{args.size} for #{attributes.size}"
|
70
|
+
end
|
71
|
+
old_new( *args )
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
=begin
|
76
|
+
## note: use Kernel for "namespacing"
|
77
|
+
## make all enums convenience converters (always) global
|
78
|
+
## including uppercase methods (e.g. State(), Color(), etc.) does NOT work otherwise (with other module includes)
|
79
|
+
|
80
|
+
## add global "Kernel" convenience converter function
|
81
|
+
## e.g. Vote(0) is same as Vote.convert(0)
|
82
|
+
Kernel.class_eval( <<RUBY )
|
83
|
+
def #{class_name}( arg )
|
84
|
+
#{class_name}.convert( arg )
|
85
|
+
end
|
86
|
+
RUBY
|
87
|
+
=end
|
88
|
+
|
89
|
+
## note: use scoped (module) and NOT Object for namespacing
|
90
|
+
## use include Safe to make all structs global
|
91
|
+
## fix-fix-fix - make class_name unique across contracts (e.g. reuse same name in different contract)
|
92
|
+
scope.const_set( class_name, klass ) ## returns klass (plus sets global constant class name)
|
93
|
+
end # method build_class
|
94
|
+
|
95
|
+
|
96
|
+
class << self
|
97
|
+
alias_method :old_new, :new # note: store "old" orginal version of new
|
98
|
+
alias_method :new, :build_class # replace original version with create
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
end # class Error
|
103
|
+
end # module Types
|
@@ -0,0 +1,58 @@
|
|
1
|
+
###
|
2
|
+
# integer exponential and ether money unit extensions / helper
|
3
|
+
#
|
4
|
+
# include via module - why? why not?
|
5
|
+
|
6
|
+
#
|
7
|
+
# now with Float included here - change to numeric.rb or such - why? why not?
|
8
|
+
# or move to core_ext/numbers or such?
|
9
|
+
|
10
|
+
|
11
|
+
class Integer
|
12
|
+
def e2() self * 10**2; end # 100
|
13
|
+
def e3() self * 10**3; end # 1000
|
14
|
+
def e4() self * 10**4; end # 10_000
|
15
|
+
def e5() self * 10**5; end # 100_000
|
16
|
+
def e6() self * 10**6; end # 1_000_000
|
17
|
+
def e7() self * 10**7; end # 10_000_000
|
18
|
+
def e8() self * 10**8; end # 100_000_000
|
19
|
+
def e9() self * 10**9; end # 1_000_000_000
|
20
|
+
def e10() self * 10**10; end # 10_000_000_000
|
21
|
+
def e11() self * 10**11; end # 100_000_000_000
|
22
|
+
def e12() self * 10**12; end # 1_000_000_000_000
|
23
|
+
def e13() self * 10**13; end # 10_000_000_000_000
|
24
|
+
def e14() self * 10**14; end # 100_000_000_000_000
|
25
|
+
def e15() self * 10**15; end # 1_000_000_000_000_000
|
26
|
+
def e16() self * 10**16; end # 10_000_000_000_000_000
|
27
|
+
def e17() self * 10**17; end # 100_000_000_000_000_000
|
28
|
+
def e18() self * 10**18; end # 1_000_000_000_000_000_000
|
29
|
+
def e19() self * 10**19; end
|
30
|
+
def e20() self * 10**20; end
|
31
|
+
def e21() self * 10**21; end
|
32
|
+
def e22() self * 10**22; end
|
33
|
+
def e23() self * 10**23; end
|
34
|
+
def e24() self * 10**24; end # 1_000_000_000_000_000_000_000_000
|
35
|
+
|
36
|
+
###########
|
37
|
+
# Ethereum money units
|
38
|
+
# add more - why? why not?
|
39
|
+
# use alias_method :ether, :e18 - why? why not?
|
40
|
+
def ether() self * 10**18; end
|
41
|
+
alias_method :eth, :ether
|
42
|
+
end # class Integer
|
43
|
+
|
44
|
+
|
45
|
+
class Float
|
46
|
+
def e18() (self *10**18).to_i; end
|
47
|
+
|
48
|
+
## note: add e6 (zeros) after conversion to int
|
49
|
+
## 21e24.to_i = 20999999999999999110807552 !!!!
|
50
|
+
## 21.0.e24 = 21000000000000000000000000
|
51
|
+
def e24() (self *10**18).to_i.e6; end
|
52
|
+
|
53
|
+
# use alias_method :ether, :e18 - why? why not?
|
54
|
+
def ether() (self *10**18).to_i; end
|
55
|
+
alias_method :eth, :ether
|
56
|
+
end
|
57
|
+
|
58
|
+
|
@@ -440,6 +440,58 @@ end # class EventType
|
|
440
440
|
|
441
441
|
|
442
442
|
|
443
|
+
###
|
444
|
+
# error for now kind of like a struct - why? why not?
|
445
|
+
## but MUST be initialized (and than frozen)
|
446
|
+
## and no zero possible etc.
|
447
|
+
|
448
|
+
class ErrorType < ReferenceType
|
449
|
+
attr_reader :error_name
|
450
|
+
attr_reader :error_class ## reference error_class here - why? why not?
|
451
|
+
def initialize( error_name, error_class )
|
452
|
+
@error_name = error_name
|
453
|
+
@error_class = error_class
|
454
|
+
end
|
455
|
+
def format
|
456
|
+
## use tuple here (not error) - why? why not?
|
457
|
+
named_types = @error_class.attributes.map {|key,type| "#{key} #{type.format}" }
|
458
|
+
"#{@error_name} error(#{named_types.join(',')})"
|
459
|
+
end
|
460
|
+
alias_method :to_s, :format
|
461
|
+
|
462
|
+
## check what abi looks like if possible for error
|
463
|
+
## is like tuple?
|
464
|
+
|
465
|
+
def ==(other)
|
466
|
+
other.is_a?( ErrorType ) &&
|
467
|
+
@error_name == other.error_name && ## check for name too - why? why not?
|
468
|
+
@error_class == other.error_class
|
469
|
+
end
|
470
|
+
|
471
|
+
|
472
|
+
def typedclass_name() @error_class.name; end
|
473
|
+
def typedclass() @error_class; end
|
474
|
+
|
475
|
+
## note: mut? == true MUST use new_zero (dup)
|
476
|
+
## mut? == false MUST use zero (frozen/shared/singelton)
|
477
|
+
def mut?() false; end
|
478
|
+
def zero
|
479
|
+
raise "error cannot be zero (by defintion); sorry"
|
480
|
+
end
|
481
|
+
alias_method :new_zero, :zero
|
482
|
+
|
483
|
+
def new( initial_values ) ## todo/check: change to values with splat - why? why not?
|
484
|
+
## note: use "splat" here - must be empty or matching number of fields/attributes
|
485
|
+
## change - why? why not?
|
486
|
+
@error_class.new( *initial_values )
|
487
|
+
end
|
488
|
+
end # class ErrorType
|
489
|
+
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
|
494
|
+
|
443
495
|
|
444
496
|
|
445
497
|
|
@@ -24,6 +24,8 @@ class UInt < TypedValue
|
|
24
24
|
def -(other) UInt.new( @value - other.to_int); end
|
25
25
|
def *(other) UInt.new( @value * other.to_int); end
|
26
26
|
def /(other) UInt.new( @value / other.to_int); end
|
27
|
+
|
28
|
+
def div(other) UInt.new( @value.div(other.to_int)); end
|
27
29
|
## add more Integer forwards here!!!!
|
28
30
|
##def_delegators :@value, :+, :-
|
29
31
|
|
@@ -83,6 +85,15 @@ class Timestamp < TypedValue
|
|
83
85
|
@value.freeze ## freeze here (and freeze self!) - why? why not?
|
84
86
|
@value
|
85
87
|
end
|
88
|
+
|
89
|
+
## todo/check - only allow other if Timestamp - why? why not?
|
90
|
+
include Comparable
|
91
|
+
def <=>(other) @value <=> other.to_int; end
|
92
|
+
|
93
|
+
def +(other) Timestamp.new( @value + other.to_int); end
|
94
|
+
def -(other) Timestamp.new( @value - other.to_int); end
|
95
|
+
|
96
|
+
def to_int() @value; end ## "automagilally" support implicit integer conversion - why? why not?
|
86
97
|
end # class Timestamp
|
87
98
|
|
88
99
|
|
@@ -30,6 +30,20 @@ class String < TypedValue
|
|
30
30
|
:+
|
31
31
|
|
32
32
|
def to_str() @value; end ## "automagilally" support implicit string conversion - why? why not?
|
33
|
+
|
34
|
+
|
35
|
+
## allow compare with "plain" string too - why? why not?
|
36
|
+
def ==(other)
|
37
|
+
if other.is_a?(String) ## typed (frozen) string
|
38
|
+
@value == other.instance_variable_get( :@value ) ## compare value via as_data!!!
|
39
|
+
elsif other.is_a?( ::String ) ## ruby "literal" string
|
40
|
+
@value == other
|
41
|
+
else
|
42
|
+
false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
33
47
|
end # class String
|
34
48
|
|
35
49
|
|
@@ -50,9 +64,28 @@ class Address < TypedValue
|
|
50
64
|
@value.freeze ## freeze here - why? why not?
|
51
65
|
@value
|
52
66
|
end
|
67
|
+
|
68
|
+
## add compare - why? why not?
|
69
|
+
include Comparable
|
70
|
+
def <=>(other)
|
71
|
+
## compare hexstring instead of unint? - why? why not?
|
72
|
+
if other.is_a?(Address)
|
73
|
+
to_uint <=> other.to_uint
|
74
|
+
else
|
75
|
+
## use type error or retur nil?
|
76
|
+
raise ArgumentError, "Address#<=>(other) expects Address; got #{other.class.name}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
def to_uint ## add helper here - why? why not?
|
82
|
+
num = @value.to_i(16)
|
83
|
+
UInt.new( num )
|
84
|
+
end
|
53
85
|
end # class Address
|
54
86
|
|
55
87
|
|
88
|
+
|
56
89
|
class InscriptionId < TypedValue
|
57
90
|
def self.type() InscriptionIdType.instance; end
|
58
91
|
def self.zero() @zero ||= new; end
|
data/lib/solidity/typed.rb
CHANGED
@@ -8,7 +8,7 @@ require 'forwardable' ## def_delegate
|
|
8
8
|
class ValueError < StandardError; end
|
9
9
|
## if type is ok, but value of type not in range (e.g. uint with negative numbers)
|
10
10
|
## or maybe enum out-of-range - why? why not?
|
11
|
-
|
11
|
+
## todo/check - where ValueError gets used
|
12
12
|
|
13
13
|
|
14
14
|
|
@@ -43,6 +43,8 @@ require_relative 'typed/struct'
|
|
43
43
|
require_relative 'typed/struct_builder'
|
44
44
|
require_relative 'typed/event'
|
45
45
|
require_relative 'typed/event_builder'
|
46
|
+
require_relative 'typed/error'
|
47
|
+
require_relative 'typed/error_builder'
|
46
48
|
|
47
49
|
|
48
50
|
require_relative 'typed/enum'
|
@@ -50,6 +52,9 @@ require_relative 'typed/enum_builder'
|
|
50
52
|
|
51
53
|
require_relative 'typed/conversion'
|
52
54
|
|
55
|
+
###
|
56
|
+
## more helpers / core extensions
|
57
|
+
require_relative 'typed/integer' # e.g. 1.e18, 1.ether, etc.
|
53
58
|
|
54
59
|
|
55
60
|
#############
|
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.2.
|
4
|
+
version: 0.2.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-
|
11
|
+
date: 2023-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|
@@ -47,7 +47,7 @@ dependencies:
|
|
47
47
|
description: solidity-typed - "zero-dependency" 100%-solidity compatible data type
|
48
48
|
and application binary interface (abi) machinery incl. bool, (frozen) string, address,
|
49
49
|
bytes, uint, int, enum, struct, array, mapping, event, and more for solidity-inspired
|
50
|
-
contract (blockchain) programming languages incl. rubidity et al
|
50
|
+
contract (blockchain) programming languages incl. rubidity, rubysol et al
|
51
51
|
email: gerald.bauer@gmail.com
|
52
52
|
executables: []
|
53
53
|
extensions: []
|
@@ -67,8 +67,11 @@ 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/error.rb
|
71
|
+
- lib/solidity/typed/error_builder.rb
|
70
72
|
- lib/solidity/typed/event.rb
|
71
73
|
- lib/solidity/typed/event_builder.rb
|
74
|
+
- lib/solidity/typed/integer.rb
|
72
75
|
- lib/solidity/typed/mapping.rb
|
73
76
|
- lib/solidity/typed/mapping_builder.rb
|
74
77
|
- lib/solidity/typed/metatypes/array.rb
|
@@ -109,5 +112,5 @@ specification_version: 4
|
|
109
112
|
summary: solidity-typed - "zero-dependency" 100%-solidity compatible data type and
|
110
113
|
application binary interface (abi) machinery incl. bool, (frozen) string, address,
|
111
114
|
bytes, uint, int, enum, struct, array, mapping, event, and more for solidity-inspired
|
112
|
-
contract (blockchain) programming languages incl. rubidity et al
|
115
|
+
contract (blockchain) programming languages incl. rubidity, rubysol et al
|
113
116
|
test_files: []
|