abiparser 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: 43f7d1f45a66ea6fd2deb690979c26f4289a666692bcb84c81420dbab5c2ab8b
4
- data.tar.gz: 487f1407542dc6d6f5e22b2975f4a7828fc0f08f5147961dc44230486bccbe71
3
+ metadata.gz: 9f938a2858e7da14cc5a8b42f4691a93c4721cef9e271168de78535c64f70115
4
+ data.tar.gz: 8450885be9f443548be957d0815bb31e3c56862f0368eb17f574ab176ea9e4b0
5
5
  SHA512:
6
- metadata.gz: 5fc14d110513a91161272beb5a9e8d41401fe8ba5407d52beb43b782ac2b173108aaea79738b4f75d00439bf17908257376100c1d4166dc34434f936019eddbf
7
- data.tar.gz: ed21d7bcdbb58144832ba46c82d6fae1c1ec22f501936b34902e68c56ab44a556f219c35294cf09a836382252d77e67de231476b027724fcb60e681d3925d90f
6
+ metadata.gz: bc52799f38979a1e8b77b21d711e0ff935510ce7988bdec34e5ad0a09a5dde8db522df3038808f165dcd4178051ef49f7f832d1b76fc9fac0ef5c4f3331fd92b
7
+ data.tar.gz: 6a6d1e03041d70e7080c38ad3e534c5e57a0cd49af187c4a16dfe1f19ae7fa55d4c8a3068b12968dd64a3d23f3c08c8f4c5fd47ac96e83f9bc7da695e0dfef7b
data/Rakefile CHANGED
@@ -22,6 +22,7 @@ Hoe.spec 'abiparser' do
22
22
  ['cocos'],
23
23
  ['bytes'],
24
24
  ['digest-lite'],
25
+ ['abicoder'],
25
26
  ]
26
27
 
27
28
  self.licenses = ['Public Domain']
@@ -47,14 +47,20 @@ class Constructor
47
47
  end
48
48
 
49
49
 
50
- attr_reader :inputs
50
+ attr_reader :inputs, :input_types
51
51
 
52
52
  def initialize( inputs: [],
53
53
  payable: false )
54
54
  @inputs = inputs
55
55
  @payable = payable
56
+
57
+ ## parse inputs into types
58
+ ## note: use "calculated" sig(nature) and NOT the type
59
+ ## (differs for tuples, that is, types with components !!!)
60
+ @input_types = @inputs.map {|param| Type.parse( param.sig ) }
56
61
  end
57
62
 
63
+
58
64
  ## add - why? why not?
59
65
  ## def constant?() false; end
60
66
  ## alias_method :readonly?, :constant?
@@ -54,10 +54,11 @@ class Function
54
54
 
55
55
 
56
56
  attr_reader :name,
57
- :inputs, :outputs
57
+ :inputs, :outputs,
58
+ :input_types, :output_types
58
59
 
59
60
  def initialize( name,
60
- inputs: [],
61
+ inputs: [],
61
62
  outputs: [],
62
63
  payable: false,
63
64
  constant: false,
@@ -65,10 +66,21 @@ class Function
65
66
  @name = name
66
67
  @inputs = inputs
67
68
  @outputs = outputs
68
-
69
69
  @payable = payable
70
70
  @constant = constant
71
71
  @pure = pure
72
+
73
+ ## parse inputs & outputs into types
74
+ ## note: use "calculated" sig(nature) and NOT the type
75
+ ## (differs for tuples, that is, types with components !!!)
76
+ @input_types = @inputs.map do |param|
77
+ Type.parse( param.sig )
78
+ end
79
+ @output_types = @outputs.map do |param|
80
+ ## pp param
81
+ ## puts "sig: #{param.sig}"
82
+ Type.parse( param.sig )
83
+ end
72
84
  end
73
85
 
74
86
 
@@ -1,20 +1,25 @@
1
1
  module ABI
2
2
  class Param
3
- attr_reader :type, :name, :internal_type
3
+ attr_reader :type, :name,
4
+ :internal_type,
5
+ :components
4
6
 
5
7
  def self.parse( o )
6
8
  type = o['type']
7
9
  internal_type = o['internalType']
8
10
  name = o['name']
11
+ components = o['components'] ? o['components'].map { |c| parse( c ) } : nil
9
12
 
10
13
  new( type, name,
11
- internal_type: internal_type )
14
+ internal_type: internal_type,
15
+ components: components )
12
16
  end
13
17
 
14
18
  ### check - find a "better" name for internal_type
15
19
  ## use a keyword param - why? why not?
16
20
  def initialize( type, name=nil,
17
- internal_type: nil ) ## note: type goes first!!!
21
+ internal_type: nil,
22
+ components: nil ) ## note: type goes first!!!
18
23
  @type = type
19
24
  ## note: convert empty string "" to nil - why? why not?
20
25
  @name = if name && name.empty?
@@ -27,20 +32,31 @@ class Param
27
32
  else
28
33
  internal_type
29
34
  end
35
+ @components = components
30
36
  end
31
37
 
32
38
 
33
39
  def sig
34
- buf = "#{@type}"
35
- buf
40
+ @sig ||= begin
41
+ if @components
42
+ ## replace tuple with (type,...)
43
+ ## e.g. tuple[] becomes (type,...)[] etc.
44
+ tuple = @components.map {|c| c.sig }.join(',')
45
+ @type.sub( "tuple", "(#{tuple})" )
46
+ else
47
+ "#{@type}"
48
+ end
49
+ end
50
+ @sig
36
51
  end
37
52
 
53
+
38
54
  def doc
39
55
  buf = ''
40
- if @internal_type && @internal_type != @type
56
+ if @internal_type && @internal_type != sig
41
57
  buf << "#{@internal_type} "
42
58
  else
43
- buf << "#{@type} "
59
+ buf << "#{sig} "
44
60
  end
45
61
  buf << (@name ? @name : '_')
46
62
  buf
@@ -48,10 +64,10 @@ class Param
48
64
 
49
65
  def decl
50
66
  buf = ''
51
- buf << "#{@type} "
67
+ buf << "#{sig} "
52
68
  buf << (@name ? @name : '_')
53
69
  ## use inline comment - why? why not?
54
- if @internal_type && @internal_type != @type
70
+ if @internal_type && @internal_type != sig
55
71
  buf << " /* #{@internal_type} */"
56
72
  end
57
73
  buf
@@ -2,7 +2,7 @@
2
2
  module ABIParser
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- PATCH = 0
5
+ PATCH = 1
6
6
  VERSION = [MAJOR,MINOR,PATCH].join('.')
7
7
 
8
8
  def self.version
data/lib/abiparser.rb CHANGED
@@ -36,9 +36,12 @@ def sig( bin )
36
36
  end
37
37
 
38
38
 
39
+ require 'abicoder'
40
+
39
41
 
40
42
  ## our own code
41
43
  require_relative 'abiparser/version' # note: let version always go first
44
+
42
45
  require_relative 'abiparser/param'
43
46
  require_relative 'abiparser/constructor'
44
47
  require_relative 'abiparser/function'
@@ -46,7 +49,7 @@ require_relative 'abiparser/utils'
46
49
  require_relative 'abiparser/contract'
47
50
  require_relative 'abiparser/interface'
48
51
 
49
- require_relative 'abiparser/export/interface.rb'
52
+ require_relative 'abiparser/export/interface'
50
53
 
51
54
 
52
55
 
@@ -121,9 +124,6 @@ module ABI
121
124
  end # module ABI
122
125
 
123
126
 
124
- ## add convenience alternate spellings - why? why not?
125
- Abi = ABI
126
-
127
127
 
128
- puts AbiParser.banner
128
+ puts ABIParser.banner
129
129
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abiparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
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: 2022-12-27 00:00:00.000000000 Z
11
+ date: 2023-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocos
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: abicoder
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rdoc
57
71
  requirement: !ruby/object:Gem::Requirement