generated from NomicFoundation/hardhat-ts-plugin-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
106 additions
and
89 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { TxParams } from "@zilliqa-js/account"; | ||
import { HardhatPluginError } from "hardhat/plugins"; | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
|
||
import { | ||
OptionalUserDefinedLibraryList, | ||
ScillaContract, | ||
UserDefinedLibrary, | ||
} from "./ScillaContractDeployer"; | ||
|
||
export class ContractDeployer { | ||
private contractName: string; | ||
private compress: boolean; | ||
private userDefinedLibraries: OptionalUserDefinedLibraryList; | ||
private txParams: TxParams | null; | ||
private contractParams: any[]; | ||
|
||
constructor(private hre: HardhatRuntimeEnvironment) { | ||
this.contractName = ""; | ||
this.compress = false; | ||
this.userDefinedLibraries = null; | ||
this.txParams = null; | ||
this.contractParams = []; | ||
} | ||
|
||
reset(): ContractDeployer { | ||
this.contractName = ""; | ||
this.compress = false; | ||
this.userDefinedLibraries = null; | ||
this.txParams = null; | ||
this.contractParams = []; | ||
return this; | ||
} | ||
|
||
withName(contractName: string): ContractDeployer { | ||
this.contractName = contractName; | ||
return this; | ||
} | ||
|
||
withContractParams(params: any[]): ContractDeployer { | ||
this.contractParams = params; | ||
return this; | ||
} | ||
|
||
withTxParams(params: TxParams): ContractDeployer { | ||
this.txParams = params; | ||
return this; | ||
} | ||
|
||
withContractCompression(): ContractDeployer { | ||
this.compress = true; | ||
return this; | ||
} | ||
|
||
withUserDefinedLibraries(libraries: UserDefinedLibrary[]) { | ||
this.userDefinedLibraries = libraries; | ||
return this; | ||
} | ||
|
||
async deploy(): Promise<ScillaContract> { | ||
if (!!this.contractName.trim()) { | ||
throw new HardhatPluginError( | ||
"hardhat-scilla-plugin", | ||
"You must specify the contract name in order to deploy it." | ||
); | ||
} | ||
if (this.txParams) { | ||
this.contractParams.push(this.txParams); | ||
} | ||
|
||
let contract; | ||
if (this.userDefinedLibraries) { | ||
contract = await this.hre.deployScillaContractWithLib( | ||
this.contractName, | ||
this.userDefinedLibraries, | ||
...this.contractParams | ||
); | ||
} else { | ||
contract = await this.hre.deployScillaContract( | ||
this.contractName, | ||
...this.contractParams | ||
); | ||
} | ||
|
||
this.reset(); | ||
return contract; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters