Allow pure functions to be called

This commit is contained in:
fernandomg 2020-06-08 15:54:09 -03:00
parent 7d83843b96
commit 9db0d76fa1
1 changed files with 10 additions and 2 deletions

View File

@ -30,12 +30,20 @@ export const getMethodSignatureAndSignatureHash = (
return { methodSignature, signatureHash }
}
export const isAllowedMethod = ({ name, type }: AbiItem): boolean => {
return type === 'function' && !!name
}
export const getMethodAction = ({ stateMutability }: AbiItem): 'read' | 'write' => {
return ['view', 'pure'].includes(stateMutability) ? 'read' : 'write'
}
export const extractUsefulMethods = (abi: AbiItem[]): AbiItemExtended[] => {
return abi
.filter(({ stateMutability, name, type }) => type === 'function' && !!name && stateMutability !== 'pure')
.filter(isAllowedMethod)
.map(
(method): AbiItemExtended => ({
action: method.stateMutability === 'view' ? 'read' : 'write',
action: getMethodAction(method),
...getMethodSignatureAndSignatureHash(method),
...method,
}),