Skip to content

Commit

Permalink
Allow storage class in Human-Readable ABI (#476).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed May 24, 2019
1 parent 044554b commit cf39adb
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions packages/abi/src.ts/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type ParseNode = {
components?: Array<ParseNode>
};

let storageClasses: { [ name: string ]: boolean } = { calldata: true, memory: true, storage: true };

// @TODO: Make sure that children of an indexed tuple are marked with a null indexed
function parseParamType(param: string, allowIndexed: boolean): ParseNode {
Expand Down Expand Up @@ -82,12 +83,15 @@ function parseParamType(param: string, allowIndexed: boolean): ParseNode {

case ")":
delete node.state;
if (allowIndexed) {
if (node.name === "indexed") {
node.indexed = true;
node.name = "";
}

if (node.name === "indexed") {
if (!allowIndexed) { throwError(i); }
node.indexed = true;
node.name = "";
}

if (storageClasses[node.name]) { node.name = ""; }

node.type = verifyType(node.type);

let child = node;
Expand All @@ -101,12 +105,15 @@ function parseParamType(param: string, allowIndexed: boolean): ParseNode {

case ",":
delete node.state;
if (allowIndexed) {
if (node.name === "indexed") {
node.indexed = true;
node.name = "";
}

if (node.name === "indexed") {
if (!allowIndexed) { throwError(i); }
node.indexed = true;
node.name = "";
}

if (storageClasses[node.name]) { node.name = ""; }

node.type = verifyType(node.type);

let sibling: ParseNode = newNode(node.parent);
Expand All @@ -132,12 +139,13 @@ function parseParamType(param: string, allowIndexed: boolean): ParseNode {
// If reading name, the name is done
if (node.state.allowName) {
if (node.name !== "") {
if (allowIndexed) {
if (node.name === "indexed") {
if (node.indexed) { throwError(i); }
node.indexed = true;
node.name = "";
}
if (node.name === "indexed") {
if (!allowIndexed) { throwError(i); }
if (node.indexed) { throwError(i); }
node.indexed = true;
node.name = "";
} else if (storageClasses[node.name]) {
node.name = "";
} else {
node.state.allowName = false;
}
Expand Down Expand Up @@ -186,13 +194,15 @@ function parseParamType(param: string, allowIndexed: boolean): ParseNode {

delete parent.state;

if (allowIndexed) {
if (node.name === "indexed") {
if (node.indexed) { throwError(originalParam.length - 7); }
node.indexed = true;
node.name = "";
}
if (node.name === "indexed") {
if (!allowIndexed) { throwError(originalParam.length - 7); }
if (node.indexed) { throwError(originalParam.length - 7); }
node.indexed = true;
node.name = "";
} else if (storageClasses[node.name]) {
node.name = "";
}

parent.type = verifyType(parent.type);

return parent;
Expand Down Expand Up @@ -476,7 +486,7 @@ function parseModifiers(value: string, params: any): void {
params.constant = false;
params.payable = false;
// @TODO: Should this be initialized to "nonpayable"?
params.stateMutability = null;
params.stateMutability = "nonpayable";

value.split(" ").forEach((modifier) => {
switch (modifier.trim()) {
Expand Down

0 comments on commit cf39adb

Please sign in to comment.