Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit fe539a3

Browse files
committed
wip: depencendies deployment
1 parent ee777d9 commit fe539a3

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

ethereum/_solidity.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def solc_arguments(libraries=None, combined='bin,abi', optimize=True):
4646
if optimize:
4747
args.append('--optmize')
4848

49-
if libraries is not None:
49+
if libraries is not None and len(libraries):
5050
addresses = [
5151
'{name}:{address}'.format(name=name, address=address)
5252
for name, address in libraries.items()
@@ -155,12 +155,17 @@ def solidity_library_symbol(library_name):
155155
# the symbol is always 40 characters in length with the minimum of two
156156
# leading and trailing underscores
157157
length = min(len(library_name), 36)
158-
symbol = bytearray('_' * 40)
159-
symbol[2:length] = library_name[:length]
160-
return str(symbol)
161158

159+
library_piece = library_name[:length]
160+
hold_piece = '_' * (36 - length)
162161

163-
def solidity_resolve_address(hex_code, library_name, library_address):
162+
return '__{library}{hold}__'.format(
163+
library=library_piece,
164+
hold=hold_piece,
165+
)
166+
167+
168+
def solidity_resolve_address(hex_code, library_symbol, library_address):
164169
""" Change the bytecode to use the given library address.
165170
166171
Args:
@@ -172,12 +177,32 @@ def solidity_resolve_address(hex_code, library_name, library_address):
172177
bin: The bytecode encoded in hexadecimal with the library references
173178
resolved.
174179
"""
175-
symbol = solidity_library_symbol(library_name)
176-
return hex_code.replace(symbol, library_address)
180+
return hex_code.replace(library_symbol, library_address)
181+
182+
183+
def solidity_resolve_symbols(hex_code, libraries):
184+
symbol_address = {
185+
solidity_library_symbol(library_name): address
186+
for library_name, address in libraries.items()
187+
}
188+
189+
for unresolved in solidity_unresolved_symbols(hex_code):
190+
address = symbol_address[unresolved]
191+
hex_code = solidity_resolve_address(hex_code, unresolved, address)
192+
193+
return hex_code
177194

178195

179196
def solidity_unresolved_symbols(hex_code):
180-
""" Return the unresolved symbols contained in the `hex_code`. """
197+
""" Return the unresolved symbols contained in the `hex_code`.
198+
199+
Note:
200+
The binary representation should not be provided since this function
201+
relies on the fact that the '_' is invalid in hex encoding.
202+
203+
Args:
204+
hex_code (str): The bytecode encoded as hexadecimal.
205+
"""
181206
iterator = iter(hex_code)
182207
symbol_names = []
183208

0 commit comments

Comments
 (0)