Skip to content

Commit 16ea575

Browse files
authored
Merge pull request #7 from tintinweb/cmdlinArgsPassthru
Generic Commandline Passthru - specify any ganache-cli settings as options to solidity-shell
2 parents 642714b + 1148b5e commit 16ea575

File tree

7 files changed

+71
-16
lines changed

7 files changed

+71
-16
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
# Change Log
22
All notable changes will be documented in this file.
33

4+
## v0.0.8
5+
- new: Passthru ganache-cli settings as options to solidity-shell #7
6+
```shell
7+
solidity-shell -- -fork https://mainnet.infura.io/v3/yourToken
8+
```
9+
10+
Query a live contracts `ERC20.name()`:
11+
```solidity
12+
13+
» interface ERC20 {
14+
multi> function name() external view returns (string memory);
15+
multi> }
16+
17+
» ERC20(0xB8c77482e45F1F44dE1745F52C74426C631bDD52).name()
18+
BNB
19+
20+
```
21+
- fix: `.config set` handling of strings and multi-word arguments
422

523
## v0.0.7
624
- fix: rework remote compiler

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ An interactive Solidity shell with lightweight session recording and remote comp
2727
352
2828
```
2929

30-
Oh, did you know that we automatically fetch a matching remote compiler when you change the solidity pragma? It is as easy as typing `pgrama solidity 0.5.0` and solidity-shell will do the rest 🙌
30+
Oh, did you know that we automatically fetch a matching remote compiler when you change the solidity pragma? It is as easy as typing `pgrama solidity 0.5.0` and solidity-shell will do the rest 🙌.
3131

32-
### Hints
3332

3433

34+
### Hints
3535

3636
* `pragma solidity <version>` attempts to dynamically load the selected compiler version (remote compiler, may take a couple of seconds).
3737
* Sessions can be saved and restored using the `.session` command. Your previous session is always stored and can be loaded via `.session load previous` (not safe when running concurrent shells).
@@ -41,8 +41,19 @@ Oh, did you know that we automatically fetch a matching remote compiler when you
4141
* `$_` is a placeholder for the last known result. Feel free to use that placeholder in your scripts :)
4242
* Special commands are dot-prefixed. Everything else is evaluated as Solidity code.
4343

44+
4445
### Usage
4546

47+
#### Cmdline Passthru
48+
49+
Any arguments provided after an empty `--` are directly passed to `ganacheCmd` (default: `ganache-cli`). This way, for example, you can start a solidity shell on a ganache fork of mainnet via infura. Check `ganache-cli --help` for a list of available options.
50+
51+
```shell
52+
⇒ solidity-shell -- --fork https://mainnet.infura.io/v3/yourApiToken
53+
```
54+
55+
#### Repl
56+
4657
```shell
4758
🚀 Entering interactive Solidity shell. '.help' and '.exit' are your friends.
4859
» ℹ️ ganache-mgr: starting temp. ganache instance ...

bin/main.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,32 @@ function saveFile(name, data){
4242
}
4343

4444
/** MAIN */
45+
const argv = require('minimist')(process.argv, {'--': true});
46+
var config = loadFile(CONFIG_FILE);
47+
const oldGanacheArgs = config.ganacheArgs;
48+
if(argv['--'].length){ // temporarily override ganache args
49+
config.ganacheArgs = argv['--'];
50+
}
4551

46-
const shell = new InteractiveSolidityShell(loadFile(CONFIG_FILE));
52+
const shell = new InteractiveSolidityShell(config);
4753

48-
const vorpal = new Vorpal()
49-
.delimiter('')
50-
.show()
51-
.parse(process.argv);
5254

5355
process.on('exit', () => {
5456
shell.blockchain.stopService();
57+
if(argv['--'].length){ //restore old ganache args
58+
shell.settings.ganacheArgs = oldGanacheArgs;
59+
}
5560
saveFile(CONFIG_FILE, shell.settings)
5661
saveFile(SESSION, shell.dumpSession())
5762
});
5863

5964

65+
66+
const vorpal = new Vorpal()
67+
.delimiter('')
68+
.show()
69+
.parse(argv._);
70+
6071
vorpal
6172
.mode('repl', 'Enters Solidity Shell Mode')
6273
.delimiter(c.bold('» '))
@@ -116,7 +127,7 @@ cheers 🙌
116127
case '.undo': shell.revert(); break; //revert last action
117128
case '.config':
118129
switch(commandParts[1]){
119-
case 'set': shell.setSetting(commandParts[2], convert(commandParts[3])); break;
130+
case 'set': shell.setSetting(commandParts[2], convert(commandParts.slice(3).join(' '))); break;
120131
case 'unset': delete shell.settings[commandParts[2]]; break;
121132
default: return cb(shell.settings);
122133
} break;

package-lock.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "solidity-shell",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"description": "",
55
"main": "src/index.js",
66
"bin": {
@@ -25,6 +25,7 @@
2525
],
2626
"license": "MIT",
2727
"dependencies": {
28+
"minimist": "^1.2.5",
2829
"readline-sync": "^1.4.10",
2930
"request": "^2.88.2",
3031
"solc": "^0.8.10",

src/handler.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,15 @@ class InteractiveSolidityShell {
113113

114114
constructor(settings, log) {
115115
this.log = log || console.log;
116+
116117
const defaults = {
117118
templateContractName: 'MainContract',
118119
templateFuncMain: 'main',
119120
installedSolidityVersion: null, // overridden after merging settings; never use configured value
120121
providerUrl: 'http://localhost:8545',
121122
autostartGanache: true,
122123
ganacheCmd: 'ganache-cli',
124+
ganacheArgs: [],
123125
debugShowContract: false
124126
}
125127

@@ -153,7 +155,19 @@ class InteractiveSolidityShell {
153155
}
154156

155157
setSetting(key, value){
156-
if(key === 'installedSolidityVersion') return;
158+
switch(key){
159+
case 'installedSolidityVersion': return;
160+
case 'ganacheArgs':
161+
if(!value) {
162+
value = [];
163+
}
164+
else if(!Array.isArray(value)){
165+
value = value.split(' ');
166+
}
167+
break;
168+
case 'ganacheCmd':
169+
value = value.trim();
170+
}
157171
this.settings[key] = value;
158172
}
159173

@@ -395,7 +409,7 @@ class Blockchain {
395409
if (this.proc) {
396410
return this.proc;
397411
}
398-
this.proc = require('child_process').spawn(this.settings.ganacheCmd);
412+
this.proc = require('child_process').spawn(this.settings.ganacheCmd, this.settings.ganacheArgs);
399413
}
400414

401415
stopService() {

src/utils.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ function convert(str){
1111
case 'false': return false;
1212
}
1313
try {
14-
return parseInt(str);
14+
let num = parseInt(str);
15+
if(!isNaN(num)) return num;
1516
} catch {}
1617

1718
return str;
@@ -33,8 +34,6 @@ function multilineInput(command){
3334
return command;
3435
}
3536

36-
37-
3837
module.exports = {
3938
convert,
4039
multilineInput

0 commit comments

Comments
 (0)