@@ -2,6 +2,7 @@ import fs from 'fs'
22import YAML from 'yaml'
33
44import { AddressBook } from './address-book'
5+ import { CLIEnvironment } from './env'
56
67const ABRefMatcher = / \$ { { ( [ A - Z ] \w .+ ) } } /
78
@@ -14,9 +15,9 @@ interface ContractConfig {
1415 proxy : boolean
1516}
1617
17- function parseConfigValue ( value : string , addressBook : AddressBook ) {
18+ function parseConfigValue ( value : string , addressBook : AddressBook , cli : CLIEnvironment ) {
1819 if ( isAddressBookRef ( value ) ) {
19- return parseAddressBookRef ( addressBook , value )
20+ return parseAddressBookRef ( addressBook , value , cli )
2021 }
2122 return value
2223}
@@ -25,9 +26,16 @@ function isAddressBookRef(value: string): boolean {
2526 return ABRefMatcher . test ( value )
2627}
2728
28- function parseAddressBookRef ( addressBook : AddressBook , value : string ) : string {
29+ function parseAddressBookRef ( addressBook : AddressBook , value : string , cli : CLIEnvironment ) : string {
2930 const ref : string = ABRefMatcher . exec ( value as string ) [ 1 ]
3031 const [ contractName , contractAttr ] = ref . split ( '.' )
32+ // This is a convention to use the inject CLI-env variables into the config
33+ if ( contractName === 'Env' ) {
34+ if ( contractAttr == 'deployer' ) {
35+ return cli . walletAddress
36+ }
37+ throw new Error ( 'Attribute not found in the CLI env' )
38+ }
3139 // eslint-disable-next-line @typescript-eslint/no-explicit-any
3240 const entry = addressBook . getEntry ( contractName ) as { [ key : string ] : any }
3341 return entry [ contractAttr ]
@@ -42,14 +50,16 @@ export function readConfig(path: string): any {
4250export function loadCallParams (
4351 values : Array < ContractCallParam > ,
4452 addressBook : AddressBook ,
53+ cli : CLIEnvironment ,
4554) : Array < ContractCallParam > {
46- return values . map ( ( value ) => parseConfigValue ( value as string , addressBook ) )
55+ return values . map ( ( value ) => parseConfigValue ( value as string , addressBook , cli ) )
4756}
4857
4958export function getContractConfig (
5059 config : any ,
5160 addressBook : AddressBook ,
5261 name : string ,
62+ cli : CLIEnvironment ,
5363) : ContractConfig {
5464 const contractConfig = config . contracts [ name ] || { }
5565 const contractParams : Array < ContractParam > = [ ]
@@ -62,7 +72,10 @@ export function getContractConfig(
6272 if ( name . startsWith ( 'init' ) ) {
6373 const initList = Object . entries ( contractConfig . init ) as Array < Array < string > >
6474 for ( const [ initName , initValue ] of initList ) {
65- contractParams . push ( { name : initName , value : parseConfigValue ( initValue , addressBook ) } as {
75+ contractParams . push ( {
76+ name : initName ,
77+ value : parseConfigValue ( initValue , addressBook , cli ) ,
78+ } as {
6679 name : string
6780 value : string
6881 } )
0 commit comments