Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
Address review comments and regenerate contract-wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
merklejerk committed Feb 8, 2020
1 parent 5aa0202 commit 7da2d0b
Show file tree
Hide file tree
Showing 17 changed files with 1,458 additions and 127 deletions.
10 changes: 2 additions & 8 deletions packages/abi-gen/templates/TypeScript/contract.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,9 @@ export class {{contractName}}Contract extends BaseContract {
txDefaults
);
const bytecode = linkLibrariesInBytecode(
artifact.compilerOutput.evm.bytecode,
artifact,
libraryAddresses,
);
if (!hexUtils.isHex(bytecode)) {
throw new Error(`Bytecode for "${artifact.contractName}" was not fully linked.`);
}
return {{contractName}}Contract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly, {{> params inputs=ctor.inputs}});
}

Expand Down Expand Up @@ -236,12 +233,9 @@ export class {{contractName}}Contract extends BaseContract {
);
// Deploy this library.
const linkedLibraryBytecode = linkLibrariesInBytecode(
libraryArtifact.compilerOutput.evm.bytecode,
libraryArtifact,
libraryAddresses,
);
if (!hexUtils.isHex(linkedLibraryBytecode)) {
throw new Error(`Bytecode for library "${libraryArtifact.contractName}" was not fully linked.`);
}
const txDataWithDefaults = await BaseContract._applyDefaultsToContractTxDataAsync(
{
data: linkedLibraryBytecode,
Expand Down
13 changes: 2 additions & 11 deletions packages/abi-gen/test-cli/output/typescript/abi_gen_dummy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ export class AbiGenDummyContract extends BaseContract {
new Web3Wrapper(provider),
txDefaults,
);
const bytecode = linkLibrariesInBytecode(artifact.compilerOutput.evm.bytecode, libraryAddresses);
if (!hexUtils.isHex(bytecode)) {
throw new Error(`Bytecode for "${artifact.contractName}" was not fully linked.`);
}
const bytecode = linkLibrariesInBytecode(artifact, libraryAddresses);
return AbiGenDummyContract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly);
}

Expand Down Expand Up @@ -933,13 +930,7 @@ export class AbiGenDummyContract extends BaseContract {
libraryAddresses,
);
// Deploy this library.
const linkedLibraryBytecode = linkLibrariesInBytecode(
libraryArtifact.compilerOutput.evm.bytecode,
libraryAddresses,
);
if (!hexUtils.isHex(linkedLibraryBytecode)) {
throw new Error(`Bytecode for library "${libraryArtifact.contractName}" was not fully linked.`);
}
const linkedLibraryBytecode = linkLibrariesInBytecode(libraryArtifact, libraryAddresses);
const txDataWithDefaults = await BaseContract._applyDefaultsToContractTxDataAsync(
{
data: linkedLibraryBytecode,
Expand Down
13 changes: 2 additions & 11 deletions packages/abi-gen/test-cli/output/typescript/lib_dummy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ export class LibDummyContract extends BaseContract {
new Web3Wrapper(provider),
txDefaults,
);
const bytecode = linkLibrariesInBytecode(artifact.compilerOutput.evm.bytecode, libraryAddresses);
if (!hexUtils.isHex(bytecode)) {
throw new Error(`Bytecode for "${artifact.contractName}" was not fully linked.`);
}
const bytecode = linkLibrariesInBytecode(artifact, libraryAddresses);
return LibDummyContract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly);
}

Expand Down Expand Up @@ -180,13 +177,7 @@ export class LibDummyContract extends BaseContract {
libraryAddresses,
);
// Deploy this library.
const linkedLibraryBytecode = linkLibrariesInBytecode(
libraryArtifact.compilerOutput.evm.bytecode,
libraryAddresses,
);
if (!hexUtils.isHex(linkedLibraryBytecode)) {
throw new Error(`Bytecode for library "${libraryArtifact.contractName}" was not fully linked.`);
}
const linkedLibraryBytecode = linkLibrariesInBytecode(libraryArtifact, libraryAddresses);
const txDataWithDefaults = await BaseContract._applyDefaultsToContractTxDataAsync(
{
data: linkedLibraryBytecode,
Expand Down
13 changes: 2 additions & 11 deletions packages/abi-gen/test-cli/output/typescript/test_lib_dummy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ export class TestLibDummyContract extends BaseContract {
new Web3Wrapper(provider),
txDefaults,
);
const bytecode = linkLibrariesInBytecode(artifact.compilerOutput.evm.bytecode, libraryAddresses);
if (!hexUtils.isHex(bytecode)) {
throw new Error(`Bytecode for "${artifact.contractName}" was not fully linked.`);
}
const bytecode = linkLibrariesInBytecode(artifact, libraryAddresses);
return TestLibDummyContract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly);
}

Expand Down Expand Up @@ -220,13 +217,7 @@ export class TestLibDummyContract extends BaseContract {
libraryAddresses,
);
// Deploy this library.
const linkedLibraryBytecode = linkLibrariesInBytecode(
libraryArtifact.compilerOutput.evm.bytecode,
libraryAddresses,
);
if (!hexUtils.isHex(linkedLibraryBytecode)) {
throw new Error(`Bytecode for library "${libraryArtifact.contractName}" was not fully linked.`);
}
const linkedLibraryBytecode = linkLibrariesInBytecode(libraryArtifact, libraryAddresses);
const txDataWithDefaults = await BaseContract._applyDefaultsToContractTxDataAsync(
{
data: linkedLibraryBytecode,
Expand Down
15 changes: 10 additions & 5 deletions packages/base-contract/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbiEncoder } from '@0x/utils';
import { DataItem, EvmBytecodeOutput, MethodAbi } from 'ethereum-types';
import { ContractArtifact, DataItem, EvmBytecodeOutput, MethodAbi } from 'ethereum-types';

// tslint:disable-next-line:completed-docs
export function formatABIDataItem(abi: DataItem, value: any, formatter: (type: string, value: any) => any): any {
Expand Down Expand Up @@ -40,19 +40,24 @@ export function methodAbiToFunctionSignature(methodAbi: MethodAbi): string {
}

/**
* Replaces unliked library references in bytecode with real addresses
* and returns the bytecode.
* Replaces unliked library references in the bytecode of a contract artifact
* with real addresses and returns the bytecode.
*/
export function linkLibrariesInBytecode(
bytecodeArtifact: EvmBytecodeOutput,
artifact: ContractArtifact,
libraryAddresses: { [libraryName: string]: string },
): string {
const bytecodeArtifact = artifact.compilerOutput.evm.bytecode;
let bytecode = bytecodeArtifact.object.substr(2);
for (const link of Object.values(bytecodeArtifact.linkReferences)) {
for (const [libraryName, libraryRefs] of Object.entries(link)) {
const libraryAddress = libraryAddresses[libraryName];
if (!libraryAddress) {
continue;
throw new Error(
`${
artifact.contractName
} has an unlinked reference library ${libraryName} but no addresses was provided'.`,
);
}
for (const ref of libraryRefs) {
bytecode = [
Expand Down
115 changes: 112 additions & 3 deletions packages/contract-wrappers/src/generated-wrappers/coordinator.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7da2d0b

Please sign in to comment.