Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
geraldb committed Jan 31, 2023
1 parent 8ab1135 commit 00b2afd
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 5 deletions.
110 changes: 105 additions & 5 deletions abibase/lib/abibase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

require 'etherscan-lite'
require 'abidoc'
require 'solidity'



require_relative 'abibase/directory'


def format_code( txt )
## {{ to {
## and }} to }
Expand Down Expand Up @@ -130,9 +134,13 @@ def self.main( args=ARGV )
puts "args:"
pp args

command = args[0] || 'download'
command = args[0] || 'add'

if ['d', 'dl', 'download'].include?( command )
if ['a', 'add'].include?( command )
do_add
elsif ['l', 'ls', 'list'].include?( command )
do_list
elsif ['d', 'dl', 'download'].include?( command )
do_download_abis
elsif ['code'].include?( command )
do_download_code
Expand All @@ -148,6 +156,40 @@ def self.main( args=ARGV )
end


def self.do_add
puts "==> add abis..."

recs = read_csv( "./contracts.csv" )
puts " #{recs.size} record(s)"
end

def self.do_list
puts "==> list contracts..."

# recs = read_meta( "./address" )

each_contract do |meta|
puts "==> #{meta.addr}"

print " name: "
puts meta.name
print " names (#{meta.names.size}): "
puts meta.names.join(' | ' )

print " timestamp: "
puts meta.timestamp

print " created: "
puts meta.created

print " block: "
puts meta.block
print " txid: "
puts meta.txid
print " creator: "
puts meta.creator
end
end



Expand Down Expand Up @@ -237,16 +279,73 @@ def self.do_download_code
end
end

def self.do_generate_docs
puts "==> generate docs..."

each_contract do |meta|

addr = meta.addr
## add solidity contract outline
parser = Solidity::Parser.read( "./address/#{addr}/contract.sol" )

def self.do_generate_docs
buf = String.new( '' )
buf << "Contract outline - [contract.sol](contract.sol):\n\n"
buf << "```\n"
buf << parser.outline
buf << "```\n"
buf << "\n\n"

## add some more metadata
buf << "Created on Ethereum Mainnet:\n"
buf << "- Block #{meta.block} @ #{meta.created} (#{meta.timestamp})\n"
buf << "- Tx Id #{meta.txid}\n"
buf << "- By #{meta.creator}\n"
buf << "\n\n"


abi = ABI.read( "./address/#{addr}/abi.json" )

natspec = if File.exist?( "./address/#{addr}/contract.md" )
Natspec.read( "./address/#{addr}/contract.md" )
else
nil
end

buf << abi.generate_doc( title: "#{meta.names.join(' | ')} - Contract ABI @ #{addr}",
natspec: natspec )
puts buf

write_text( "./address/#{addr}/README.md", buf )

buf = abi.generate_interface( name: '' ) # solidity interface declarations (source code)
write_text( "./address/#{addr}/interface.sol", buf )
end
end




def self.do_generate_docs_old
puts "==> generate docs..."

paths = Dir.glob( "./address/**/abi.json" )
## paths = paths[0..2]
paths.each do |path|
basename = File.basename( File.dirname( path ))


## add solidity contract outline
parser = Solidity::Parser.read( "./address/#{basename}/contract.sol" )

buf = String.new( '' )
buf << "Contract outline:\n\n"
buf << "```\n"
buf << parser.outline
buf << "```\n"
buf << "(source: [contract.sol](contract.sol))\n"
buf << "\n\n"


abi = ABI.read( path )

natspec = if File.exist?( "./address/#{basename}/contract.md" )
Expand All @@ -255,9 +354,10 @@ def self.do_generate_docs
nil
end

buf = abi.generate_doc( title: "Contract ABI - #{basename}",
natspec: natspec )
buf << abi.generate_doc( title: "Contract ABI - #{basename}",
natspec: natspec )
puts buf

write_text( "./address/#{basename}/README.md", buf )

buf = abi.generate_interface( name: '' ) # solidity interface declarations (source code)
Expand Down
68 changes: 68 additions & 0 deletions abibase/lib/abibase/directory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

###
# read all contract metadata


class Meta
def initialize( data )
@data = data
## split and normalize names
@names = (data['name'] || data['names'])
.split( '|' )
.map { |name| name.gsub(/[ \t]+/, ' ' ).strip }
end

def name() @names[0]; end
def names() @names; end

def timestamp() @data['timestamp']; end
def created()
## use timestamp for now and ignore created for now - why? why not?
Time.at( @data['timestamp'] ).utc
end

def address() @data['address']; end
alias_method :addr, :address
def txid() @data['txid']; end
def creator() @data['creator']; end
def block() @data['block']; end ## add blocknumber alias - why? why not?
end # class Meta


def each_contract( &block )
recs = read_meta
recs.each do |rec|
block.call( Meta.new( rec ) )
end
end


def read_meta( basedir='./address' )
puts "==> read contract metadata..."

## collection all addresses
recs = []
paths = Dir.glob( "#{basedir}/**/contract.yml" )
## paths = paths[0..2]
paths.each do |path|
data = read_yaml( path )

## auto-add basedir or such - why? why not?

## auto-add addr or dobule check - why? why not?
## basename = File.basename( File.dirname( path ))

recs << data
end

############
## sort by block (reverse chronological)
recs = recs.sort do |l,r|
l['block'] <=> r['block']
end

## pp recs
## puts " #{recs.size} record(s)"

recs
end
16 changes: 16 additions & 0 deletions solidity/NOTES.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
# Notes About Solidity


## Todos

fix moonbirds scan

```
interface ITokenURIGenerator
contract Moonbirds is ERC721ACommon, BaseTokenURI, FixedPriceSeller, SignerManager, ERC2981, AccessControlEnumerable
contract) external onlyOwner
contract; } /** @notice If renderingContract is set then returns its tokenURI(tokenId) return value, otherwise returns the standard baseTokenURI + tokenId. */ function tokenURI(uint256 tokenId) public view override returns (string memory)
contract ERC721A is Context, ERC165, IERC721, IERC721Metadata
```



## More

Solidity by Example -

Solidity in x Minutes -

Awesome Solidity - <https://github.com/bkrem/awesome-solidity>

0 comments on commit 00b2afd

Please sign in to comment.