From 7b5a471296877b026abcb88edb3ca5a1b4115af3 Mon Sep 17 00:00:00 2001 From: Gerald Bauer Date: Tue, 7 Feb 2023 15:59:30 +0100 Subject: [PATCH] up --- abidump/README.md | 148 +++++++++++++---------------------------- abidump/Rakefile | 2 +- abidump/lib/abidump.rb | 44 ++++++------ 3 files changed, 72 insertions(+), 122 deletions(-) diff --git a/abidump/README.md b/abidump/README.md index 016c358..92017b8 100644 --- a/abidump/README.md +++ b/abidump/README.md @@ -60,82 +60,56 @@ resulting in: ==> constructor: payable: true - inputs (0): - [] + inputs (0) ==> event Assign: anonymous: false inputs (2): - - type: address - indexed: true - name: to - - type: uint256 - indexed: false - name: punkIndex + address indexed to + uint256 punkIndex ==> event Transfer: anonymous: false inputs (3): - - type: address - indexed: true - name: from - - type: address - indexed: true - name: to - - type: uint256 - indexed: false - name: value + address indexed from + address indexed to + uint256 value ==> event PunkTransfer: anonymous: false inputs (3): - - type: address - indexed: true - name: from - - type: address - indexed: true - name: to - - type: uint256 - indexed: false - name: punkIndex + address indexed from + address indexed to + uint256 punkIndex ... + ==> function name: constant: true payable: false - inputs (0): - [] + inputs (0) outputs (1): - - type: string - name: _ + string _ ==> function reservePunksForOwner: constant: false payable: false inputs (1): - - type: uint256 - name: maxForThisRun - outputs (0): - [] + uint256 maxForThisRun + outputs (0) ==> function punksOfferedForSale: constant: true payable: false inputs (1): - - type: uint256 - name: _ + uint256 _ outputs (5): - - type: bool - name: isForSale - - type: uint256 - name: punkIndex - - type: address - name: seller - - type: uint256 - name: minValue - - type: address - name: onlySellTo + bool isForSale + uint256 punkIndex + address seller + uint256 minValue + address onlySellTo ... ``` @@ -162,94 +136,64 @@ resulting in: ==> constructor: stateMutability: nonpayable - inputs (0): - [] + inputs (0) ==> event NewBlock: anonymous: false inputs (3): - - type: address - indexed: false - name: _ - - type: uint256 - indexed: false - name: _ - - type: string - indexed: false - name: _ + address _ + uint256 _ + string _ ==> function blocks: stateMutability: view inputs (1): - - type: bytes32 - name: _ + bytes32 _ outputs (3): - - type: uint8 (enum PunkBlocks.Layer) - name: layer - - type: bytes - name: dataMale - - type: bytes - name: dataFemale + uint8 layer - enum PunkBlocks.Layer + bytes dataMale + bytes dataFemale ==> function getBlocks: stateMutability: view inputs (2): - - type: uint256 - name: _fromID - - type: uint256 - name: _count + uint256 _fromID + uint256 _count outputs (2): - - type: tuple[] (struct PunkBlocks.Block[]) - name: _ - components: - - type: uint8 (enum PunkBlocks.Layer) - name: layer - - type: bytes - name: dataMale - - type: bytes - name: dataFemale - - type: uint256 - name: _ + tuple[] _ - struct PunkBlocks.Block[] + uint8 layer - enum PunkBlocks.Layer + bytes dataMale + bytes dataFemale + uint256 _ ==> function index: stateMutability: view inputs (1): - - type: uint256 - name: _ + uint256 _ outputs (1): - - type: bytes32 - name: _ + bytes32 _ ==> function nextId: stateMutability: view - inputs (0): - [] + inputs (0) outputs (1): - - type: uint256 - name: _ + uint256 _ ==> function registerBlock: stateMutability: nonpayable inputs (4): - - type: bytes - name: _dataMale - - type: bytes - name: _dataFemale - - type: uint8 - name: _layer - - type: string - name: _name - outputs (0): - [] + bytes _dataMale + bytes _dataFemale + uint8 _layer + string _name + outputs (0) ==> function svgFromIDs: stateMutability: view inputs (1): - - type: uint256[] - name: _ids + uint256[] _ids outputs (1): - - type: string - name: _ + string _ ... ``` diff --git a/abidump/Rakefile b/abidump/Rakefile index a4ad225..bf8a7cd 100644 --- a/abidump/Rakefile +++ b/abidump/Rakefile @@ -10,7 +10,7 @@ end Hoe.spec 'abidump' do - self.version = '0.1.0' + self.version = '0.1.1' self.summary = "abidump gem - command-line tool to dump / pretty print or (re)format application binary interfaces (abi) for Ethereum & Co." self.description = summary diff --git a/abidump/lib/abidump.rb b/abidump/lib/abidump.rb index 688f6aa..7afc0c9 100644 --- a/abidump/lib/abidump.rb +++ b/abidump/lib/abidump.rb @@ -72,7 +72,7 @@ def self.do_dump_json( data ) puts buf end - def self._norm_types( data ) + def self._dump_types( data, indent: 2 ) ## hack: remove items and re-add to sort key order!!! ## ## clean-up / normalize type @@ -91,26 +91,24 @@ def self._norm_types( data ) exit 1 end - h['type'] = type if type - if type && internal_type && type != internal_type - h['type'] += " (#{internal_type})" - end - - h['indexed'] = indexed unless indexed.nil? ## note: indexed is a true/false prop - + print ' ' * indent + print type + print ' indexed' if indexed ## note: indexed is a true/false prop ## note: change empty name e.g. '' to _ - why? why not? if name - h['name'] = name.empty? ? "_" : name + print ' ' + print name.empty? ? "_" : name end - if components - h['components'] = components - _norm_types( components) - end + print " - #{internal_type}" if type && internal_type && type != internal_type + print "\n" + + _dump_types( components, indent: indent+2 ) if components end end + def self._dump( data, indent: 2 ) buf = YAML.dump( data ) buf = buf.sub( /^---\n?/, '' ) ## remove leading --- if present @@ -153,15 +151,23 @@ def self.do_dump( data ) _dump( h, indent: 6 ) if inputs - puts " inputs (#{inputs.size}):" - _norm_types( inputs ) - _dump( inputs, indent: 6 ) + print " inputs (#{inputs.size})" + if inputs.size > 0 + print ":\n" + _dump_types( inputs, indent: 6 ) + else + print "\n" + end end if outputs - puts " outputs (#{outputs.size}):" - _norm_types( outputs ) - _dump( outputs, indent: 6 ) + print " outputs (#{outputs.size})" + if outputs.size > 0 + print ":\n" + _dump_types( outputs, indent: 6 ) + else + print "\n" + end end end