Skip to content

Commit dbf189b

Browse files
adjust min/max length for bytes/string arrays in interfaces
1 parent cddf350 commit dbf189b

1 file changed

Lines changed: 12 additions & 16 deletions

File tree

vyper/signatures/interface.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030
from vyper.signatures.function_signature import (
3131
FunctionSignature,
3232
)
33-
from vyper.typing import (
34-
InterfaceImports,
35-
SourceCode,
36-
)
3733
from vyper.types.types import (
3834
ByteArrayLike,
3935
TupleLike,
4036
)
37+
from vyper.typing import (
38+
InterfaceImports,
39+
SourceCode,
40+
)
4141

4242

4343
# Populate built-in interfaces.
@@ -60,20 +60,16 @@ def render_return(sig):
6060
return ""
6161

6262

63-
def abi_type_to_ast(atype):
63+
def abi_type_to_ast(atype, idx):
6464
if atype in ('int128', 'uint256', 'bool', 'address', 'bytes32'):
6565
return ast.Name(id=atype)
6666
elif atype == 'fixed168x10':
6767
return ast.Name(id='decimal')
68-
elif atype == 'bytes':
69-
return ast.Subscript(
70-
value=ast.Name(id='bytes'),
71-
slice=ast.Index(value=ast.Num(n=256))
72-
)
73-
elif atype == 'string':
68+
elif atype in ('bytes', 'string'):
69+
# idx is the maximum length for inputs, minimum length for outputs
7470
return ast.Subscript(
75-
value=ast.Name(id='string'),
76-
slice=ast.Index(value=ast.Num(n=256))
71+
value=ast.Name(id=atype),
72+
slice=ast.Index(value=ast.Num(n=idx))
7773
)
7874
else:
7975
raise ParserException(f'Type {atype} not supported by vyper.')
@@ -89,18 +85,18 @@ def mk_full_signature_from_json(abi):
8985
for a in func['inputs']:
9086
arg = ast.arg(
9187
arg=a['name'],
92-
annotation=abi_type_to_ast(a['type']),
88+
annotation=abi_type_to_ast(a['type'], 1048576),
9389
lineno=0,
9490
col_offset=0
9591
)
9692
args.append(arg)
9793

9894
if len(func['outputs']) == 1:
99-
returns = abi_type_to_ast(func['outputs'][0]['type'])
95+
returns = abi_type_to_ast(func['outputs'][0]['type'], 1)
10096
elif len(func['outputs']) > 1:
10197
returns = ast.Tuple(
10298
elts=[
103-
abi_type_to_ast(a['type'])
99+
abi_type_to_ast(a['type'], 1)
104100
for a in func['outputs']
105101
]
106102
)

0 commit comments

Comments
 (0)