@@ -2,6 +2,7 @@ import fs from 'fs'
2
2
import YAML from 'yaml'
3
3
4
4
import { AddressBook } from './address-book'
5
+ import { CLIEnvironment } from './env'
5
6
6
7
const ABRefMatcher = / \$ { { ( [ A - Z ] \w .+ ) } } /
7
8
@@ -14,9 +15,9 @@ interface ContractConfig {
14
15
proxy : boolean
15
16
}
16
17
17
- function parseConfigValue ( value : string , addressBook : AddressBook ) {
18
+ function parseConfigValue ( value : string , addressBook : AddressBook , cli : CLIEnvironment ) {
18
19
if ( isAddressBookRef ( value ) ) {
19
- return parseAddressBookRef ( addressBook , value )
20
+ return parseAddressBookRef ( addressBook , value , cli )
20
21
}
21
22
return value
22
23
}
@@ -25,9 +26,16 @@ function isAddressBookRef(value: string): boolean {
25
26
return ABRefMatcher . test ( value )
26
27
}
27
28
28
- function parseAddressBookRef ( addressBook : AddressBook , value : string ) : string {
29
+ function parseAddressBookRef ( addressBook : AddressBook , value : string , cli : CLIEnvironment ) : string {
29
30
const ref : string = ABRefMatcher . exec ( value as string ) [ 1 ]
30
31
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
+ }
31
39
// eslint-disable-next-line @typescript-eslint/no-explicit-any
32
40
const entry = addressBook . getEntry ( contractName ) as { [ key : string ] : any }
33
41
return entry [ contractAttr ]
@@ -42,14 +50,16 @@ export function readConfig(path: string): any {
42
50
export function loadCallParams (
43
51
values : Array < ContractCallParam > ,
44
52
addressBook : AddressBook ,
53
+ cli : CLIEnvironment ,
45
54
) : Array < ContractCallParam > {
46
- return values . map ( ( value ) => parseConfigValue ( value as string , addressBook ) )
55
+ return values . map ( ( value ) => parseConfigValue ( value as string , addressBook , cli ) )
47
56
}
48
57
49
58
export function getContractConfig (
50
59
config : any ,
51
60
addressBook : AddressBook ,
52
61
name : string ,
62
+ cli : CLIEnvironment ,
53
63
) : ContractConfig {
54
64
const contractConfig = config . contracts [ name ] || { }
55
65
const contractParams : Array < ContractParam > = [ ]
@@ -62,7 +72,10 @@ export function getContractConfig(
62
72
if ( name . startsWith ( 'init' ) ) {
63
73
const initList = Object . entries ( contractConfig . init ) as Array < Array < string > >
64
74
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 {
66
79
name : string
67
80
value : string
68
81
} )
0 commit comments