@@ -23,83 +23,83 @@ abstract contract BaseScript is Script {
2323 }
2424
2525 function setUp () public virtual {
26- uint256 privateKey = vm.envOr ({
26+ broadcaster = vm.rememberKey (configurePrivateKey ());
27+ }
28+
29+ function configurePrivateKey () internal view virtual returns (uint256 privateKey ) {
30+ privateKey = vm.envOr ({
2731 name: "PRIVATE_KEY " ,
2832 defaultValue: vm.deriveKey ({
2933 mnemonic: vm.envOr ({name: "MNEMONIC " , defaultValue: DEFAULT_MNEMONIC}),
3034 index: uint8 (vm.envOr ({name: "EOA_INDEX " , defaultValue: uint256 (0 )}))
3135 })
3236 });
33-
34- broadcaster = vm.rememberKey (privateKey);
3537 }
3638
3739 function generateJson (string memory path , string memory name , address instance , bytes32 salt ) internal {
3840 string memory json = "json " ;
3941 json.serialize ("address " , instance);
4042 json.serialize ("blockNumber " , vm.getBlockNumber ());
4143 json.serialize ("name " , name);
42- json.serialize ("salt " , vm. toString ( salt) );
44+ json.serialize ("salt " , salt);
4345 json = json.serialize ("timestamp " , vm.getBlockTimestamp ());
4446 json.write (path);
4547 }
4648
49+ function prompt (string memory promptText ) internal returns (string memory input ) {
50+ return prompt (promptText, new string (0 ));
51+ }
52+
4753 function prompt (string memory promptText , string memory defaultValue ) internal returns (string memory input ) {
48- input = _prompt ( promptText, defaultValue);
54+ input = vm. prompt ( string . concat ( promptText, " (default: ` " , defaultValue, " `) " ) );
4955 if (bytes (input).length == 0 ) input = defaultValue;
5056 }
5157
5258 function promptAddress (string memory promptText , address defaultValue ) internal returns (address ) {
53- string memory input = _prompt (promptText, vm.toString (defaultValue));
54- if (bytes (input).length == 0 ) return defaultValue;
55- return vm.parseAddress (input);
59+ return vm.parseAddress (prompt (promptText, vm.toString (defaultValue)));
5660 }
5761
5862 function promptAddress (string memory promptText ) internal returns (address ) {
5963 return promptAddress (promptText, address (0 ));
6064 }
6165
6266 function promptBool (string memory promptText , bool defaultValue ) internal returns (bool ) {
63- string memory input = _prompt (promptText, vm.toString (defaultValue));
64- if (bytes (input).length == 0 ) return defaultValue;
65- return vm.parseBool (input);
67+ return vm.parseBool (prompt (promptText, vm.toString (defaultValue)));
6668 }
6769
6870 function promptBool (string memory promptText ) internal returns (bool ) {
6971 return promptBool (promptText, false );
7072 }
7173
72- function promptBytes (string memory promptText , bytes memory defaultValue ) internal returns (bytes memory ) {
73- string memory input = _prompt (promptText, vm.toString (defaultValue));
74- if (bytes (input).length == 0 ) return defaultValue;
75- return vm.parseBytes (input);
74+ function promptUint256 (string memory promptText , uint256 defaultValue ) internal returns (uint256 ) {
75+ return vm.parseUint (prompt (promptText, vm.toString (defaultValue)));
7676 }
7777
78- function promptBytes (string memory promptText ) internal returns (bytes memory ) {
79- return promptBytes (promptText, new bytes (0 ));
78+ function promptUint256 (string memory promptText ) internal returns (uint256 ) {
79+ return promptUint256 (promptText, uint256 (0 ));
80+ }
81+
82+ function promptInt256 (string memory promptText , int256 defaultValue ) internal returns (int256 ) {
83+ return vm.parseInt (prompt (promptText, vm.toString (defaultValue)));
84+ }
85+
86+ function promptInt256 (string memory promptText ) internal returns (int256 ) {
87+ return promptInt256 (promptText, int256 (0 ));
8088 }
8189
8290 function promptBytes32 (string memory promptText , bytes32 defaultValue ) internal returns (bytes32 ) {
83- string memory input = _prompt (promptText, vm.toString (defaultValue));
84- if (bytes (input).length == 0 ) return defaultValue;
85- return vm.parseBytes32 (input);
91+ return vm.parseBytes32 (prompt (promptText, vm.toString (defaultValue)));
8692 }
8793
8894 function promptBytes32 (string memory promptText ) internal returns (bytes32 ) {
8995 return promptBytes32 (promptText, bytes32 (0 ));
9096 }
9197
92- function promptUint (string memory promptText , uint256 defaultValue ) internal returns (uint256 ) {
93- string memory input = _prompt (promptText, vm.toString (defaultValue));
94- if (bytes (input).length == 0 ) return defaultValue;
95- return vm.parseUint (input);
96- }
97-
98- function promptUint (string memory promptText ) internal returns (uint256 ) {
99- return promptUint (promptText, uint256 (0 ));
98+ function promptBytes (string memory promptText , bytes memory defaultValue ) internal returns (bytes memory ) {
99+ return vm.parseBytes (prompt (promptText, vm.toString (defaultValue)));
100100 }
101101
102- function _prompt (string memory promptText , string memory defaultValue ) private returns (string memory input ) {
103- return vm. prompt ( string . concat ( promptText, " (default: ' " , defaultValue, " ') " ));
102+ function promptBytes (string memory promptText ) internal returns (bytes memory ) {
103+ return promptBytes ( promptText, new bytes ( 0 ));
104104 }
105105}
0 commit comments