abidoc 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: f4b3c3f3938f6b54d21344990071ae5e3681a831e890f78889a17ad447f14e34
4
- data.tar.gz: 8688881c905501c39cb4bbb38c2eca48fcac093108a9ab8c2ec5bb3439bcdc65
3
+ metadata.gz: 63f3e9a48dff69f7a1b40cfdb0576a6780c80a7e789969996a93987263769c8c
4
+ data.tar.gz: 934f1f64b48b26106b16511f775b7353356128cc6236a9e8cde97747ccb207d7
5
5
  SHA512:
6
- metadata.gz: 0a2d6a0c7dedaa90b6e0afcd164cbd4a1ff69833f0d54eb580a25c9340ec2af338281455e941277efe1c98196166b8596b07f9e67381bcfc63302f1c3fb43a39
7
- data.tar.gz: 59285ecbaf3bee17cd11c9ad6a2d1b35e67fe9c9bb5adab7ae5946f0624182254596040eadc47922998486241533b5c819c0c222130324e4ac53a2c9b35b703a
6
+ metadata.gz: 2cc8363ca326724f2afd6f950f2a4556f8fbff67682f05ddbf400ef5bd3a8cc160e498816483c0b2ffb5115dd3a86c9164009382b8dcb9e36409299623315dda
7
+ data.tar.gz: c72388140e2e625c264817fafab023a80b5ee4641fa70c1b6285e2149b3bcb1e23cba42593f04a2cdc4542bc8fc169a252964683e7546c3f1df92bf86f283f64
data/Manifest.txt CHANGED
@@ -3,4 +3,6 @@ Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
5
  lib/abidoc.rb
6
+ lib/abidoc/generate.rb
7
+ lib/abidoc/model.rb
6
8
  lib/abidoc/version.rb
data/README.md CHANGED
@@ -119,7 +119,7 @@ and so on.
119
119
 
120
120
  ## Bonus - Awesome Contracts
121
121
 
122
- See the [**Awesome (Ethereum) Contracts / Blockchain Services**](https://github.com/rubycocos/awesome-contracts) repo.
122
+ See the [**Awesome (Ethereum) Contracts / Blockchain Services @ Open Blockchains**](https://github.com/openblockchains/awesome-contracts) repo.
123
123
  that is a cache of (ethereum) contract ABIs (application binary interfaces)
124
124
  and open source code (if verified / available)
125
125
  with auto-generated docs via abidoc & friends.
@@ -0,0 +1,85 @@
1
+ module ABI
2
+ class Contract
3
+
4
+
5
+ def generate_doc( title: 'Contract ABI',
6
+ natspec: nil )
7
+ buf = ''
8
+ buf << "# #{title}\n\n"
9
+
10
+ if natspec && natspec.head.size > 0
11
+ natspec.head.each do |line|
12
+ buf << (line.empty? ? "\n" : "#{line}\n")
13
+ end
14
+ end
15
+ buf << "\n\n"
16
+
17
+
18
+ if events.size > 0
19
+ buf << "\n"
20
+ buf << "**#{events.size} Event Log Type(s)**\n\n"
21
+ events.each do |event|
22
+ buf << "- #{event.doc}\n"
23
+ end
24
+ end
25
+
26
+
27
+
28
+ if @ctor
29
+ buf << "\n"
30
+ buf << "**Constructor**\n\n"
31
+ buf << "- #{@ctor.doc}\n"
32
+ ## buf << " - sig #{@ctor.sig} => 0x#{sig(@ctor.sig).hexdigest}\n"
33
+ end
34
+
35
+ if payable_functions.size > 0
36
+ buf << "\n"
37
+ buf << "**#{payable_functions.size} Payable Function(s)**\n\n"
38
+ payable_functions.each do |func|
39
+ buf << "- #{func.doc} _payable_\n"
40
+ ## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n"
41
+ end
42
+ end
43
+
44
+ if transact_functions.size > 0
45
+ buf << "\n"
46
+ buf << "**#{transact_functions.size} Transact Functions(s)**\n\n"
47
+ transact_functions.each do |func|
48
+ buf << "- #{func.doc}\n"
49
+ ## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n"
50
+ end
51
+ end
52
+
53
+
54
+ if query_functions.size > 0
55
+ buf << "\n"
56
+ buf << "**#{query_functions.size} Query Functions(s)**\n\n"
57
+ query_functions.each do |func|
58
+ if natspec && (natspec.storage[ func.name] || natspec.functions[ func.name ])
59
+ sect = natspec.storage[ func.name ] || natspec.functions[ func.name ]
60
+ buf << "- #{sect[0]}"
61
+ sect[1].each do |line|
62
+ buf << (line.empty? ? " <br>" : " <br> #{line}")
63
+ end
64
+ buf << "\n"
65
+ else
66
+ buf << "- #{func.doc} _readonly_\n"
67
+ ## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n"
68
+ end
69
+ end
70
+ end
71
+
72
+ if helper_functions.size > 0
73
+ buf << "\n"
74
+ buf << "**#{helper_functions.size} Helper Functions(s)**\n\n"
75
+ helper_functions.each do |func|
76
+ buf << "- #{func.doc}\n"
77
+ ## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n"
78
+ end
79
+ end
80
+
81
+ buf
82
+ end
83
+
84
+ end ## class Contract
85
+ end ## module ABI
@@ -0,0 +1,67 @@
1
+ module ABI
2
+
3
+ class Param
4
+ def doc
5
+ buf = ''
6
+ if @internal_type && @internal_type != sig
7
+ buf << "#{@internal_type} "
8
+ else
9
+ buf << "#{sig} "
10
+ end
11
+ buf << (@name ? @name : '_')
12
+ buf
13
+ end
14
+ end
15
+
16
+
17
+ class Constructor
18
+ def doc
19
+ buf = "constructor"
20
+ if @inputs.empty?
21
+ buf << "()"
22
+ else
23
+ params = @inputs.map {|param| param.doc }
24
+ buf << "(#{params.join(', ')})"
25
+ end
26
+ buf
27
+ end
28
+ end ## class Constructor
29
+
30
+ class Function
31
+ def doc
32
+ ## note: text with markdown formatting
33
+ buf = "function **#{@name}**"
34
+ if @inputs.empty?
35
+ buf << "()"
36
+ else
37
+ params = @inputs.map {|param| param.doc }
38
+ buf << "(#{params.join(', ')})"
39
+ end
40
+ if @outputs.empty?
41
+ ## do nothing
42
+ else
43
+ buf << " ⇒ "
44
+ params = @outputs.map {|param| param.doc }
45
+ buf << "(#{params.join(', ')})"
46
+ end
47
+ buf
48
+ end
49
+ end ## class Function
50
+
51
+
52
+ class Event
53
+ def doc
54
+ ## note: text with markdown formatting
55
+ buf = "event **#{@name}**"
56
+ if @inputs.empty?
57
+ buf << "()"
58
+ else
59
+ params = @inputs.map {|param| param.doc }
60
+ buf << "(#{params.join(', ')})"
61
+ end
62
+ buf
63
+ end
64
+ end ## class Event
65
+
66
+
67
+ end ## module ABI
@@ -3,7 +3,7 @@ module ABIDoc
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- PATCH = 0
6
+ PATCH = 1
7
7
  VERSION = [MAJOR,MINOR,PATCH].join('.')
8
8
 
9
9
  def self.version
data/lib/abidoc.rb CHANGED
@@ -1,64 +1,11 @@
1
1
  require 'abiparser'
2
+ require 'natspec'
2
3
 
3
4
 
4
5
  ## our own code
5
6
  require_relative 'abidoc/version' # note: let version always go first
7
+ require_relative 'abidoc/model'
8
+ require_relative 'abidoc/generate'
6
9
 
7
10
 
8
11
 
9
- module ABI
10
- class Contract
11
-
12
-
13
- def generate_doc( title: 'Contract ABI' )
14
- buf = ''
15
- buf << "# #{title}\n\n"
16
-
17
- if @ctor
18
- buf << "\n"
19
- buf << "**Constructor**\n\n"
20
- buf << "- #{@ctor.doc}\n"
21
- ## buf << " - sig #{@ctor.sig} => 0x#{sig(@ctor.sig).hexdigest}\n"
22
- end
23
-
24
- if payable_functions.size > 0
25
- buf << "\n"
26
- buf << "**#{payable_functions.size} Payable Function(s)**\n\n"
27
- payable_functions.each do |func|
28
- buf << "- #{func.doc} _payable_\n"
29
- ## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n"
30
- end
31
- end
32
-
33
- if transact_functions.size > 0
34
- buf << "\n"
35
- buf << "**#{transact_functions.size} Transact Functions(s)**\n\n"
36
- transact_functions.each do |func|
37
- buf << "- #{func.doc}\n"
38
- ## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n"
39
- end
40
- end
41
-
42
- if query_functions.size > 0
43
- buf << "\n"
44
- buf << "**#{query_functions.size} Query Functions(s)**\n\n"
45
- query_functions.each do |func|
46
- buf << "- #{func.doc} _readonly_\n"
47
- ## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n"
48
- end
49
- end
50
-
51
- if helper_functions.size > 0
52
- buf << "\n"
53
- buf << "**#{helper_functions.size} Helper Functions(s)**\n\n"
54
- helper_functions.each do |func|
55
- buf << "- #{func.doc}\n"
56
- ## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n"
57
- end
58
- end
59
-
60
- buf
61
- end
62
-
63
- end ## class Contract
64
- end ## module ABI
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abidoc
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-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: abiparser
@@ -73,6 +73,8 @@ files:
73
73
  - README.md
74
74
  - Rakefile
75
75
  - lib/abidoc.rb
76
+ - lib/abidoc/generate.rb
77
+ - lib/abidoc/model.rb
76
78
  - lib/abidoc/version.rb
77
79
  homepage: https://github.com/rubycocos/blockchain
78
80
  licenses: