Make default constructor non-payable (#684).

This commit is contained in:
Richard Moore 2020-04-24 03:02:57 -04:00
parent 47e4655f6b
commit 017ea0d6bd
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651
2 changed files with 41 additions and 8 deletions

@ -391,6 +391,14 @@ function parseParams(value: string, allowIndex: boolean): Array<ParamType> {
return splitNesting(value).map((param) => ParamType.fromString(param, allowIndex));
}
type TypeCheck<T> = { -readonly [ K in keyof T ]: T[K] };
interface _Fragment {
readonly type: string;
readonly name: string;
readonly inputs: Array<ParamType>;
}
export abstract class Fragment {
readonly type: string;
@ -465,6 +473,10 @@ export abstract class Fragment {
}
}
interface _EventFragment extends _Fragment {
readonly anonymous: boolean;
}
export class EventFragment extends Fragment {
readonly anonymous: boolean;
@ -516,12 +528,14 @@ export class EventFragment extends Fragment {
logger.throwArgumentError("invalid event object", "value", value);
}
return new EventFragment(_constructorGuard, {
const params: TypeCheck<_EventFragment> = {
name: verifyIdentifier(value.name),
anonymous: value.anonymous,
inputs: (value.inputs ? value.inputs.map(ParamType.fromObject) : []),
type: "event"
});
};
return new EventFragment(_constructorGuard, params);
}
static fromString(value: string): EventFragment {
@ -678,6 +692,12 @@ function verifyState(value: StateInputValue): StateOutputValue {
return result;
}
interface _ConstructorFragment extends _Fragment {
stateMutability: string;
payable: boolean;
gas?: BigNumber;
}
export class ConstructorFragment extends Fragment {
stateMutability: string;
payable: boolean;
@ -735,13 +755,16 @@ export class ConstructorFragment extends Fragment {
logger.throwArgumentError("constructor cannot be constant", "value", value);
}
return new ConstructorFragment(_constructorGuard, {
const params: TypeCheck<_ConstructorFragment> = {
name: null,
type: value.type,
inputs: (value.inputs ? value.inputs.map(ParamType.fromObject): []),
payable: state.payable,
stateMutability: state.stateMutability,
gas: (value.gas ? BigNumber.from(value.gas): null)
});
};
return new ConstructorFragment(_constructorGuard, params);
}
static fromString(value: string): ConstructorFragment {
@ -766,6 +789,11 @@ export class ConstructorFragment extends Fragment {
}
}
interface _FunctionFragment extends _ConstructorFragment {
constant: boolean;
outputs?: Array<ParamType>;
}
export class FunctionFragment extends ConstructorFragment {
constant: boolean;
outputs?: Array<ParamType>;
@ -838,7 +866,7 @@ export class FunctionFragment extends ConstructorFragment {
let state = verifyState(value);
return new FunctionFragment(_constructorGuard, {
const params: TypeCheck<_FunctionFragment> = {
type: value.type,
name: verifyIdentifier(value.name),
constant: state.constant,
@ -847,7 +875,9 @@ export class FunctionFragment extends ConstructorFragment {
payable: state.payable,
stateMutability: state.stateMutability,
gas: (value.gas ? BigNumber.from(value.gas): null)
});
};
return new FunctionFragment(_constructorGuard, params);
}
static fromString(value: string): FunctionFragment {

@ -108,9 +108,12 @@ export class Interface {
bucket[signature] = fragment;
});
// If we do not have a constructor use the default "constructor() payable"
// If we do not have a constructor add a default
if (!this.deploy) {
defineReadOnly(this, "deploy", ConstructorFragment.from({ type: "constructor" }));
defineReadOnly(this, "deploy", ConstructorFragment.from({
payable: false,
type: "constructor"
}));
}
defineReadOnly(this, "_isInterface", true);