-
Notifications
You must be signed in to change notification settings - Fork 201
Push only required contract during create command #1426
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { ZWeb3 } from '@openzeppelin/upgrades'; | |
|
||
import add from './add'; | ||
import push from '../scripts/push'; | ||
import { PushParams } from '../scripts/interfaces'; | ||
import Session from '../models/network/Session'; | ||
import { compile } from '../models/compiler/Compiler'; | ||
import Dependency from '../models/dependency/Dependency'; | ||
|
@@ -42,6 +43,7 @@ async function commandActions(options: any): Promise<void> { | |
|
||
async function action(options: any): Promise<void> { | ||
const { | ||
contractAlias, | ||
force, | ||
deployDependencies, | ||
reset: reupload, | ||
|
@@ -66,7 +68,7 @@ async function action(options: any): Promise<void> { | |
}); | ||
const promptDeployDependencies = await promptForDeployDependencies(deployDependencies, network, interactive); | ||
|
||
const pushArguments = { | ||
const pushArguments: PushParams = { | ||
deployProxyAdmin, | ||
deployProxyFactory, | ||
force, | ||
|
@@ -76,7 +78,10 @@ async function action(options: any): Promise<void> { | |
...promptDeployDependencies, | ||
}; | ||
|
||
if (!options.skipTelemetry) await Telemetry.report('push', pushArguments, interactive); | ||
if (contractAlias) pushArguments.contractAliases = [contractAlias]; | ||
|
||
if (!options.skipTelemetry) | ||
await Telemetry.report('push', (pushArguments as unknown) as Record<string, unknown>, interactive); | ||
await push(pushArguments); | ||
if (!options.dontExitProcess && process.env.NODE_ENV !== 'test') process.exit(0); | ||
} | ||
|
@@ -89,9 +94,9 @@ async function runActionIfRequested(externalOptions: any): Promise<void> { | |
return action(options); | ||
} | ||
|
||
async function runActionIfNeeded(contractName: string, network: string, options: any): Promise<void> { | ||
async function runActionIfNeeded(contractAlias: string, network: string, options: any): Promise<void> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. |
||
if (!options.interactive) return; | ||
await action({ ...options, dontExitProcess: true, skipTelemetry: true }); | ||
await action({ ...options, dontExitProcess: true, skipTelemetry: true, contractAlias }); | ||
} | ||
|
||
async function promptForDeployDependencies( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,13 +122,13 @@ export default class NetworkController { | |
} | ||
|
||
// DeployerController | ||
public async push(reupload = false, force = false): Promise<void | never> { | ||
public async push(aliases: string[], { reupload = false, force = false } = {}): Promise<void | never> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I was thinking there are all the null checks. I completely forgot about that our |
||
const changedLibraries = this._solidityLibsForPush(!reupload); | ||
const contracts = this._contractsListForPush(!reupload, changedLibraries); | ||
const contractObjects = this._contractsListForPush(aliases, !reupload, changedLibraries); | ||
const buildArtifacts = getBuildArtifacts(); | ||
|
||
// ValidateContracts also extends each contract class with validation errors and storage info | ||
if (!this.validateContracts(contracts, buildArtifacts) && !force) { | ||
if (!this.validateContracts(contractObjects, buildArtifacts) && !force) { | ||
throw Error( | ||
'One or more contracts have validation errors. Please review the items listed above and fix them, or run this command again with the --force option.', | ||
); | ||
|
@@ -140,11 +140,11 @@ export default class NetworkController { | |
|
||
this.checkNotFrozen(); | ||
await this.uploadSolidityLibs(changedLibraries); | ||
await Promise.all([this.uploadContracts(contracts), this.unsetContracts()]); | ||
await Promise.all([this.uploadContracts(contractObjects), this.unsetContracts()]); | ||
|
||
await this._unsetSolidityLibs(); | ||
|
||
if (isEmpty(contracts) && isEmpty(changedLibraries)) { | ||
if (isEmpty(contractObjects) && isEmpty(changedLibraries)) { | ||
Loggy.noSpin(__filename, 'push', `after-push`, `All contracts are up to date`); | ||
} else { | ||
Loggy.noSpin(__filename, 'push', `after-push`, `All contracts have been deployed`); | ||
|
@@ -179,10 +179,17 @@ export default class NetworkController { | |
} | ||
|
||
// Contract model | ||
private _contractsListForPush(onlyChanged = false, changedLibraries: Contract[] = []): [string, Contract][] { | ||
private _contractsListForPush( | ||
aliases: string[], | ||
onlyChanged = false, | ||
changedLibraries: Contract[] = [], | ||
): [string, Contract][] { | ||
const newVersion = this._newVersionRequired(); | ||
|
||
return toPairs(this.projectFile.contracts) | ||
aliases = aliases || Object.keys(this.projectFile.contracts); | ||
|
||
return aliases | ||
.map(alias => [alias, this.projectFile.contracts[alias]]) | ||
.map(([contractAlias, contractName]): [string, Contract] => [contractAlias, Contracts.getFromLocal(contractName)]) | ||
.filter( | ||
([contractAlias, contract]) => | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious: why was this cast needed when changing from
{ [key: string]: unknown }
toRecord<string, unknown>
in thereport
method definition? I thought that both were semantically the same.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cast is needed not because of the change of
report
method but because of changepushParams
to typePushParams
which doesn't have required index signature.