Allow pure functions to be called
This commit is contained in:
parent
7d83843b96
commit
9db0d76fa1
|
@ -30,12 +30,20 @@ export const getMethodSignatureAndSignatureHash = (
|
||||||
return { methodSignature, signatureHash }
|
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[] => {
|
export const extractUsefulMethods = (abi: AbiItem[]): AbiItemExtended[] => {
|
||||||
return abi
|
return abi
|
||||||
.filter(({ stateMutability, name, type }) => type === 'function' && !!name && stateMutability !== 'pure')
|
.filter(isAllowedMethod)
|
||||||
.map(
|
.map(
|
||||||
(method): AbiItemExtended => ({
|
(method): AbiItemExtended => ({
|
||||||
action: method.stateMutability === 'view' ? 'read' : 'write',
|
action: getMethodAction(method),
|
||||||
...getMethodSignatureAndSignatureHash(method),
|
...getMethodSignatureAndSignatureHash(method),
|
||||||
...method,
|
...method,
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in New Issue