Merge pull request #996 from gnosis/fix/#994-contractInteraction-no_data-for-abi-field

(Fix) Properly identify methods to interact with
This commit is contained in:
Mikhail Mikheev 2020-06-09 12:49:24 +04:00 committed by GitHub
commit cdbdf69829
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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(({ constant, name, type }) => type === 'function' && !!name && typeof constant === 'boolean')
.filter(isAllowedMethod)
.map(
(method): AbiItemExtended => ({
action: method.constant ? 'read' : 'write',
action: getMethodAction(method),
...getMethodSignatureAndSignatureHash(method),
...method,
}),