From 9db0d76fa13b2c3380608ca815368b773d3e6387 Mon Sep 17 00:00:00 2001 From: fernandomg Date: Mon, 8 Jun 2020 15:54:09 -0300 Subject: [PATCH] Allow pure functions to be called --- .../contractInteraction/sources/ABIService/index.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/logic/contractInteraction/sources/ABIService/index.ts b/src/logic/contractInteraction/sources/ABIService/index.ts index 5c2a999a..bfc1f7ed 100644 --- a/src/logic/contractInteraction/sources/ABIService/index.ts +++ b/src/logic/contractInteraction/sources/ABIService/index.ts @@ -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, }),