【PHP】Solidityのソースコードから関数定義を抽出するスクリプト
solidityのソースコードから関数定義部分だけ抜き出すスクリプトを作った(だいぶやっつけだけど)。
試しにCryptoKittiesのソースコードに対して使ってみた。
制限事項として
/*コメント*/ function() public {
のような行は表示されない。
https://ethfiddle.com/09YbyJRfiI
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
<?php function isLineCommentLine($line) { return (substr(trim($line), 0, 2) === "//"); } function isCommentStartLine($line) { return (substr(trim($line), 0, 2) === "/*"); } function isCommentEndLine($line) { return (substr(trim($line), -2, 2) === "*/"); } function isFunctionDefinitionStartLine($line) { return (strpos($line, 'function') !== false); } function isFunctionDefinitionEndLine($line) { return ( (strpos($line, '{') !== false) || (strpos($line, ';') !== false) ); } function myprint($line){ echo $line; } $filename = $argv[1]; $file = fopen($filename, "r"); /* ファイルを1行ずつ出力 */ if($file){ $printflg = false; $commentflg = false; while ($line = fgets($file)) { if(isLineCommentLine($line)){ continue; } if(isCommentStartLine($line)){ $commentflg = true; } if($printflg && false === $commentflg){ myprint($line); if(isFunctionDefinitionEndLine($line)){ $printflg = false; } } if(isFunctionDefinitionStartLine($line) && false === $commentflg){ myprint($line); if(false === isFunctionDefinitionEndLine($line)){ $printflg = true; } } if(isCommentEndLine($line)){ $commentflg = false; } } } /* ファイルポインタをクローズ */ fclose($file); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
function Ownable() { function transferOwnership(address newOwner) onlyOwner { function totalSupply() public view returns (uint256 total); function balanceOf(address _owner) public view returns (uint256 balance); function ownerOf(uint256 _tokenId) external view returns (address owner); function approve(address _to, uint256 _tokenId) external; function transfer(address _to, uint256 _tokenId) external; function transferFrom(address _from, address _to, uint256 _tokenId) external; function supportsInterface(bytes4 _interfaceID) external view returns (bool); function isGeneScience() public pure returns (bool); function mixGenes(uint256 genes1, uint256 genes2, uint256 targetBlock) public returns (uint256); function setCEO(address _newCEO) external onlyCEO { function setCFO(address _newCFO) external onlyCEO { function setCOO(address _newCOO) external onlyCEO { function pause() external onlyCLevel whenNotPaused { function unpause() public onlyCEO whenPaused { function _transfer(address _from, address _to, uint256 _tokenId) internal { function _createKitty( uint256 _matronId, uint256 _sireId, uint256 _generation, uint256 _genes, address _owner ) internal returns (uint) { function setSecondsPerBlock(uint256 secs) external onlyCLevel { function getMetadata(uint256 _tokenId, string) public view returns (bytes32[4] buffer, uint256 count) { function supportsInterface(bytes4 _interfaceID) external view returns (bool) { function setMetadataAddress(address _contractAddress) public onlyCEO { function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) { function _approvedFor(address _claimant, uint256 _tokenId) internal view returns (bool) { function _approve(uint256 _tokenId, address _approved) internal { function balanceOf(address _owner) public view returns (uint256 count) { function transfer( address _to, uint256 _tokenId ) external whenNotPaused { function approve( address _to, uint256 _tokenId ) external whenNotPaused { function transferFrom( address _from, address _to, uint256 _tokenId ) external whenNotPaused { function totalSupply() public view returns (uint) { function ownerOf(uint256 _tokenId) external view returns (address owner) { function tokensOfOwner(address _owner) external view returns(uint256[] ownerTokens) { function _memcpy(uint _dest, uint _src, uint _len) private view { function _toString(bytes32[4] _rawBytes, uint256 _stringLength) private view returns (string) { function tokenMetadata(uint256 _tokenId, string _preferredTransport) external view returns (string infoUrl) { function setGeneScienceAddress(address _address) external onlyCEO { function _isReadyToBreed(Kitty _kit) internal view returns (bool) { function _isSiringPermitted(uint256 _sireId, uint256 _matronId) internal view returns (bool) { function _triggerCooldown(Kitty storage _kitten) internal { function approveSiring(address _addr, uint256 _sireId) external whenNotPaused { function setAutoBirthFee(uint256 val) external onlyCOO { function _isReadyToGiveBirth(Kitty _matron) private view returns (bool) { function isReadyToBreed(uint256 _kittyId) public view returns (bool) { function isPregnant(uint256 _kittyId) public view returns (bool) { function _isValidMatingPair( Kitty storage _matron, uint256 _matronId, Kitty storage _sire, uint256 _sireId ) private view returns(bool) { function _canBreedWithViaAuction(uint256 _matronId, uint256 _sireId) internal view returns (bool) { function canBreedWith(uint256 _matronId, uint256 _sireId) external view returns(bool) { function _breedWith(uint256 _matronId, uint256 _sireId) internal { function breedWithAuto(uint256 _matronId, uint256 _sireId) external payable whenNotPaused { function giveBirth(uint256 _matronId) external whenNotPaused returns(uint256) { function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) { function _escrow(address _owner, uint256 _tokenId) internal { function _transfer(address _receiver, uint256 _tokenId) internal { function _addAuction(uint256 _tokenId, Auction _auction) internal { function _cancelAuction(uint256 _tokenId, address _seller) internal { function _bid(uint256 _tokenId, uint256 _bidAmount) internal returns (uint256) { function _removeAuction(uint256 _tokenId) internal { function _isOnAuction(Auction storage _auction) internal view returns (bool) { function _currentPrice(Auction storage _auction) internal view returns (uint256) { function _computeCurrentPrice( uint256 _startingPrice, uint256 _endingPrice, uint256 _duration, uint256 _secondsPassed ) internal pure returns (uint256) { function _computeCut(uint256 _price) internal view returns (uint256) { function pause() onlyOwner whenNotPaused returns (bool) { function unpause() onlyOwner whenPaused returns (bool) { function ClockAuction(address _nftAddress, uint256 _cut) public { function withdrawBalance() external { function createAuction( uint256 _tokenId, uint256 _startingPrice, uint256 _endingPrice, uint256 _duration, address _seller ) external whenNotPaused { function bid(uint256 _tokenId) external payable whenNotPaused { function cancelAuction(uint256 _tokenId) external { function cancelAuctionWhenPaused(uint256 _tokenId) whenPaused onlyOwner external { function getAuction(uint256 _tokenId) external view returns ( address seller, uint256 startingPrice, uint256 endingPrice, uint256 duration, uint256 startedAt ) { function getCurrentPrice(uint256 _tokenId) external view returns (uint256) { function SiringClockAuction(address _nftAddr, uint256 _cut) public ClockAuction(_nftAddr, _cut) {} function createAuction( uint256 _tokenId, uint256 _startingPrice, uint256 _endingPrice, uint256 _duration, address _seller ) external { function bid(uint256 _tokenId) external payable { function SaleClockAuction(address _nftAddr, uint256 _cut) public ClockAuction(_nftAddr, _cut) {} function createAuction( uint256 _tokenId, uint256 _startingPrice, uint256 _endingPrice, uint256 _duration, address _seller ) external { function bid(uint256 _tokenId) external payable { function averageGen0SalePrice() external view returns (uint256) { function setSaleAuctionAddress(address _address) external onlyCEO { function setSiringAuctionAddress(address _address) external onlyCEO { function createSaleAuction( uint256 _kittyId, uint256 _startingPrice, uint256 _endingPrice, uint256 _duration ) external whenNotPaused { function createSiringAuction( uint256 _kittyId, uint256 _startingPrice, uint256 _endingPrice, uint256 _duration ) external whenNotPaused { function bidOnSiringAuction( uint256 _sireId, uint256 _matronId ) external payable whenNotPaused { function withdrawAuctionBalances() external onlyCLevel { function createPromoKitty(uint256 _genes, address _owner) external onlyCOO { function createGen0Auction(uint256 _genes) external onlyCOO { function _computeNextGen0Price() internal view returns (uint256) { function KittyCore() public { function setNewAddress(address _v2Address) external onlyCEO whenPaused { function() external payable { function getKitty(uint256 _id) external view returns ( bool isGestating, bool isReady, uint256 cooldownIndex, uint256 nextActionAt, uint256 siringWithId, uint256 birthTime, uint256 matronId, uint256 sireId, uint256 generation, uint256 genes ) { function unpause() public onlyCEO whenPaused { function withdrawBalance() external onlyCFO { |