This repository has been archived by the owner on Feb 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
445 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export '../src/generated/erc20.g.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import 'dart:convert'; | ||
|
||
import '../../contracts.dart'; | ||
|
||
/// Parses solidity documentation comments from the generated compiler | ||
/// output. | ||
class Documentation { | ||
final String? contractDetails; | ||
final Map<ContractEvent, String> events; | ||
final Map<ContractFunction, String> functions; | ||
|
||
Documentation._(this.contractDetails, this.events, this.functions); | ||
|
||
String? forContract() => contractDetails?.asDartDoc; | ||
String? forEvent(ContractEvent e) => events[e]?.asDartDoc; | ||
String? forFunction(ContractFunction m) => functions[m]?.asDartDoc; | ||
|
||
static Documentation? fromJson(Map<String, Object?> json, ContractAbi abi) { | ||
if (json['version'] != 1) return null; | ||
|
||
final rawEvents = json['events'] as Map; | ||
final rawMethods = json['methods'] as Map; | ||
|
||
final details = json['details'] as String?; | ||
final methods = <ContractFunction, String>{}; | ||
final events = <ContractEvent, String>{}; | ||
|
||
for (final event in abi.events) { | ||
final signature = event.stringSignature; | ||
final match = (rawEvents[signature] as Map?)?.details; | ||
|
||
if (match != null) { | ||
events[event] = match; | ||
} | ||
} | ||
|
||
for (final method in abi.functions) { | ||
final signature = method.encodeName(); | ||
final match = (rawMethods[signature] as Map?)?.details; | ||
|
||
if (match != null) { | ||
methods[method] = match; | ||
} | ||
} | ||
|
||
return Documentation._(details, events, methods); | ||
} | ||
} | ||
|
||
extension on Map { | ||
String? get details => this['details'] as String?; | ||
} | ||
|
||
extension on String { | ||
String get asDartDoc { | ||
return const LineSplitter() | ||
.convert(this) | ||
.map((line) => '/// $line') | ||
.join('\n'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.