( artifact: Artifact, libraries: LibraryLink[], )
| 73 | * @returns The linked bytecode with all provided libraries correctly linked. |
| 74 | */ |
| 75 | export function linkBytecode( |
| 76 | artifact: Artifact, |
| 77 | libraries: LibraryLink[], |
| 78 | ): PrefixedHexString { |
| 79 | const { bytecode, linkReferences } = artifact; |
| 80 | const replacements: BytecodeReplacement[] = []; |
| 81 | |
| 82 | for (const { sourceName, libraryName, address } of libraries) { |
| 83 | const contractLinkReferences = |
| 84 | linkReferences[sourceName]?.[libraryName] ?? []; |
| 85 | const unprefixedAddress = getUnprefixedHexString(address); |
| 86 | |
| 87 | for (const { start, length } of contractLinkReferences) { |
| 88 | replacements.push({ |
| 89 | start: 2 + start * 2, |
| 90 | length: length * 2, |
| 91 | value: unprefixedAddress, |
| 92 | }); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | return getPrefixedHexString( |
| 97 | applyBytecodeReplacements(bytecode, replacements), |
| 98 | ); |
| 99 | } |
no test coverage detected