This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
abi-gen/Py: fix incorrect method return types
Fixes #2298 .
- Loading branch information
Showing
7 changed files
with
152 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import * as Handlebars from 'handlebars'; | ||
|
||
import { DataItem } from 'ethereum-types'; | ||
|
||
import { utils } from './utils'; | ||
|
||
export const pythonHandlebarsHelpers = { | ||
/** | ||
* Produces a Python expression representing the return value from a | ||
* Solidity function. | ||
* @param pythonVariable the name of the Python variable holding the value | ||
* to be used to populate the output expression. | ||
* @param abiOutputs the "outputs" object of the function's ABI. | ||
*/ | ||
makeOutputsValue: (pythonVariable: string, abiOutputs: DataItem[]) => { | ||
if (abiOutputs.length === 1) { | ||
return new Handlebars.SafeString(solValueToPyValue(pythonVariable, abiOutputs[0])); | ||
} else { | ||
let tupleValue = '('; | ||
for (let i = 0; i < abiOutputs.length; i++) { | ||
tupleValue += `${pythonVariable}[${i}],`; | ||
} | ||
tupleValue += ')'; | ||
return new Handlebars.SafeString(tupleValue); | ||
} | ||
}, | ||
}; | ||
|
||
function solValueToPyValue(pythonVariable: string, abiItem: DataItem): string { | ||
const pythonTypeName = utils.solTypeToPyType(abiItem.type, abiItem.components); | ||
if (pythonTypeName.match(/List\[.*\]/) !== null) { | ||
return `[${solValueToPyValue('element', { | ||
...abiItem, | ||
type: abiItem.type.replace('[]', ''), | ||
})} for element in ${pythonVariable}]`; | ||
} else { | ||
let pyValue = `${pythonTypeName}(`; | ||
if (abiItem.components) { | ||
let i = 0; | ||
for (const component of abiItem.components) { | ||
pyValue += `${component.name}=${pythonVariable}[${i}],`; | ||
i++; | ||
} | ||
} else { | ||
pyValue += pythonVariable; | ||
} | ||
pyValue += ')'; | ||
return pyValue; | ||
} | ||
} |
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.