Skip to content

Commit

Permalink
Merge pull request #69 from gnidan/hide-notice
Browse files Browse the repository at this point in the history
Add `--no-attribution` and `--no-source` flags
  • Loading branch information
gnidan authored Jun 21, 2022
2 parents f38d857 + 31f3edb commit e46d471
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## vNext

### New features

- Add `--no-attribution` and `--no-source` flags
([#69](https://github.com/gnidan/abi-to-sol/pull/69) by
[@gnidan](https://github.com/gnidan))

### Internal improvements

- Update to Node.js LTS ([#63](https://github.com/gnidan/abi-to-sol/pull/63) by
Expand Down
10 changes: 10 additions & 0 deletions packages/abi-to-sol/bin/abi-to-sol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Usage:
[--solidity-version=<solidityVersion>]
[--license=<license>]
[--validate]
[--no-attribution]
[--no-source]
[<name>]
abi-to-sol -h | --help
abi-to-sol --version
Expand All @@ -34,6 +36,12 @@ Options:
-L --license
SPDX license identifier. Default: ${defaults.license}
-A --no-attribution
Skip printing "AUTOGENERATED by abi-to-sol" as a header comment in output
-S --no-source
Skip printing source ABI JSON as footer comment in output
-h --help Show this screen.
--version Show version.
`;
Expand Down Expand Up @@ -71,6 +79,8 @@ const main = async () => {
name: args["<name>"],
license: args["-L"] || args["--license"],
validate: args["--validate"] || false,
outputAttribution: !(args["-A"] || args["--no-attribution"]),
outputSource: !(args["-S"] || args["--no-source"]),
};

const abi: SchemaAbi = (await readStdin()) as SchemaAbi;
Expand Down
2 changes: 2 additions & 0 deletions packages/abi-to-sol/src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export const name = "MyInterface";
export const license = "UNLICENSED";
export const solidityVersion = ">=0.7.0 <0.9.0";
export const prettifyOutput = true;
export const outputAttribution = true;
export const outputSource = true;
25 changes: 24 additions & 1 deletion packages/abi-to-sol/src/solidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export interface GenerateSolidityOptions {
name?: string;
solidityVersion?: string;
license?: string;
outputAttribution?: boolean;
outputSource?: boolean;
prettifyOutput?: boolean;
}

Expand All @@ -36,6 +38,8 @@ export const generateSolidity = ({
name = defaults.name,
solidityVersion = defaults.solidityVersion,
license = defaults.license,
outputAttribution = defaults.outputAttribution,
outputSource = defaults.outputSource,
prettifyOutput = prettier && defaults.prettifyOutput,
}: GenerateSolidityOptions) => {
if (!prettier && prettifyOutput) {
Expand All @@ -52,6 +56,8 @@ export const generateSolidity = ({
name,
solidityVersion,
license,
outputAttribution,
outputSource,
versionFeatures,
abiFeatures,
declarations,
Expand Down Expand Up @@ -94,6 +100,8 @@ class SolidityGenerator implements Visitor<string, Context | undefined> {
private name: string;
private license: string;
private solidityVersion: string;
private outputAttribution: boolean;
private outputSource: boolean;
private versionFeatures: VersionFeatures;
private abiFeatures: AbiFeatures;
private declarations: Declarations;
Expand All @@ -107,6 +115,8 @@ class SolidityGenerator implements Visitor<string, Context | undefined> {
constructor({
name,
license,
outputAttribution,
outputSource,
solidityVersion,
versionFeatures,
abiFeatures,
Expand All @@ -118,6 +128,8 @@ class SolidityGenerator implements Visitor<string, Context | undefined> {
this.versionFeatures = versionFeatures;
this.abiFeatures = abiFeatures;
this.declarations = declarations;
this.outputAttribution = outputAttribution;
this.outputSource = outputSource;

this.identifiers = {};
let index = 0;
Expand Down Expand Up @@ -295,9 +307,16 @@ class SolidityGenerator implements Visitor<string, Context | undefined> {
this.abiFeatures["needs-abiencoder-v2"] &&
this.versionFeatures["abiencoder-v2"] !== "default";

const attribution =
!this.outputAttribution
? []
: !this.outputSource
? [`// !! THIS FILE WAS AUTOGENERATED BY abi-to-sol v${version}. !!`]
: [`// !! THIS FILE WAS AUTOGENERATED BY abi-to-sol v${version}. SEE SOURCE BELOW. !!`];

return [
`// SPDX-License-Identifier: ${this.license}`,
`// !! THIS FILE WAS AUTOGENERATED BY abi-to-sol v${version}. SEE SOURCE BELOW. !!`,
...attribution,
`pragma solidity ${this.solidityVersion};`,
...(
includeExperimentalPragma
Expand All @@ -308,6 +327,10 @@ class SolidityGenerator implements Visitor<string, Context | undefined> {
}

private generateAutogeneratedNotice(abi: Abi.Abi): string {
if (!this.outputSource) {
return "";
}

return [
``,
`// THIS FILE WAS AUTOGENERATED FROM THE FOLLOWING ABI JSON:`,
Expand Down

0 comments on commit e46d471

Please sign in to comment.