aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-09-27 17:57:42 +0800
committerFabio Berger <me@fabioberger.com>2018-09-27 17:57:42 +0800
commitc55a41917851e66e3803883cf10b1e336e2dfc21 (patch)
treecd77458e457b6ac99237551d9347ab8c83932b08
parent1402119c840dcb634efd99c02e76007ed013b54a (diff)
downloaddexon-0x-contracts-c55a41917851e66e3803883cf10b1e336e2dfc21.tar.gz
dexon-0x-contracts-c55a41917851e66e3803883cf10b1e336e2dfc21.tar.zst
dexon-0x-contracts-c55a41917851e66e3803883cf10b1e336e2dfc21.zip
Split _genMethodDoc into it and _genFallbackDoc for clarity. Add isFallback boolean
-rw-r--r--packages/sol-doc/src/solidity_doc_generator.ts54
-rw-r--r--packages/types/src/index.ts1
2 files changed, 33 insertions, 22 deletions
diff --git a/packages/sol-doc/src/solidity_doc_generator.ts b/packages/sol-doc/src/solidity_doc_generator.ts
index 5ddf001a6..d2fb5b083 100644
--- a/packages/sol-doc/src/solidity_doc_generator.ts
+++ b/packages/sol-doc/src/solidity_doc_generator.ts
@@ -117,8 +117,10 @@ function _genDocSection(compiledContract: StandardContractOutput, contractName:
// that's because the type of the events array doesn't have any fields for documentation!
break;
case 'function':
+ docSection.methods.push(_genMethodDoc(abiDefinition as MethodAbi, compiledContract.devdoc));
+ break;
case 'fallback':
- docSection.methods.push(_genMethodDoc(abiDefinition, compiledContract.devdoc));
+ docSection.methods.push(_genFallbackDoc(abiDefinition as FallbackAbi, compiledContract.devdoc));
break;
default:
throw new Error(
@@ -173,39 +175,47 @@ function _devdocMethodDetailsIfExist(
return details;
}
-function _genMethodDoc(
- abiDefinition: MethodAbi | FallbackAbi,
- devdocIfExists: DevdocOutput | undefined,
-): SolidityMethod {
- const name = abiDefinition.type === 'fallback' ? '' : abiDefinition.name;
-
- const { parameters, methodSignature } =
- abiDefinition.type === 'fallback'
- ? { parameters: [], methodSignature: `${name}()` }
- : _genMethodParamsDoc(name, abiDefinition.inputs, devdocIfExists);
-
+function _genFallbackDoc(abiDefinition: FallbackAbi, devdocIfExists: DevdocOutput | undefined): SolidityMethod {
+ const methodSignature = `${name}()`;
const comment = _devdocMethodDetailsIfExist(methodSignature, devdocIfExists);
- const returnType =
- abiDefinition.type === 'fallback'
- ? { name: '', typeDocType: TypeDocTypes.Intrinsic }
- : _genMethodReturnTypeDoc(abiDefinition.outputs, methodSignature, devdocIfExists);
-
const returnComment =
_.isUndefined(devdocIfExists) || _.isUndefined(devdocIfExists.methods[methodSignature])
? undefined
: devdocIfExists.methods[methodSignature].return;
- const isConstant = abiDefinition.type === 'fallback' ? true : abiDefinition.constant;
+ const methodDoc: SolidityMethod = {
+ isConstructor: false,
+ name: '',
+ callPath: '',
+ parameters: [],
+ returnType: { name: 'void', typeDocType: TypeDocTypes.Intrinsic },
+ returnComment,
+ isConstant: true,
+ isPayable: abiDefinition.payable,
+ isFallback: true,
+ comment,
+ };
+ return methodDoc;
+}
+
+function _genMethodDoc(abiDefinition: MethodAbi, devdocIfExists: DevdocOutput | undefined): SolidityMethod {
+ const { parameters, methodSignature } = _genMethodParamsDoc(name, abiDefinition.inputs, devdocIfExists);
+ const comment = _devdocMethodDetailsIfExist(methodSignature, devdocIfExists);
+ const returnType = _genMethodReturnTypeDoc(abiDefinition.outputs, methodSignature, devdocIfExists);
+ const returnComment =
+ _.isUndefined(devdocIfExists) || _.isUndefined(devdocIfExists.methods[methodSignature])
+ ? undefined
+ : devdocIfExists.methods[methodSignature].return;
const methodDoc: SolidityMethod = {
isConstructor: false,
- name,
+ name: abiDefinition.name,
callPath: '',
parameters,
returnType,
returnComment,
- isConstant,
+ isConstant: abiDefinition.constant,
isPayable: abiDefinition.payable,
comment,
};
@@ -254,7 +264,7 @@ function _genMethodParamsDoc(
for (const abiParam of abiParams) {
const parameter: Parameter = {
name: abiParam.name,
- comment: '',
+ comment: '<No comment>',
isOptional: false, // Unsupported in Solidity, until resolution of https://github.com/ethereum/solidity/issues/232
type: { name: abiParam.type, typeDocType: TypeDocTypes.Intrinsic },
};
@@ -288,7 +298,7 @@ function _genMethodReturnTypeDoc(
devdocIfExists: DevdocOutput | undefined,
): Type {
const methodReturnTypeDoc: Type = {
- name: '',
+ name: 'void',
typeDocType: TypeDocTypes.Intrinsic,
tupleElements: undefined,
};
diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts
index 5ef8b54a4..3ae0536d5 100644
--- a/packages/types/src/index.ts
+++ b/packages/types/src/index.ts
@@ -519,6 +519,7 @@ export interface TypescriptFunction extends BaseFunction {
export interface SolidityMethod extends BaseMethod {
isConstant?: boolean;
isPayable?: boolean;
+ isFallback?: boolean;
}
export interface Source {