Skip to content

Commit 2bdd3ea

Browse files
committed
init
0 parents  commit 2bdd3ea

File tree

9 files changed

+4082
-0
lines changed

9 files changed

+4082
-0
lines changed

.gitignore

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
66+
*.tgz
67+
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
78+
# Next.js build output
79+
.next
80+
81+
# Nuxt.js build / generate output
82+
.nuxt
83+
dist
84+
85+
# Gatsby files
86+
.cache/
87+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88+
# https://nextjs.org/blog/next-9-1#public-directory-support
89+
# public
90+
91+
# vuepress build output
92+
.vuepress/dist
93+
94+
# Serverless directories
95+
.serverless/
96+
97+
# FuseBox cache
98+
.fusebox/
99+
100+
# DynamoDB Local files
101+
.dynamodb/
102+
103+
# TernJS port file
104+
.tern-port

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
examples
2+
scripts

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[<img width="200" alt="get in touch with Consensys Diligence" src="https://user-images.githubusercontent.com/2865694/56826101-91dcf380-685b-11e9-937c-af49c2510aa0.png">](https://diligence.consensys.net)<br/>
2+
<sup>
3+
[[ 🌐 ](https://diligence.consensys.net) [ 📩 ](https://github.com/ConsenSys/vscode-solidity-doppelganger/blob/master/mailto:diligence@consensys.net) [ 🔥 ](https://consensys.github.io/diligence/)]
4+
</sup><br/><br/>
5+
6+
7+
# Solidity Interactive Shell
8+
9+
[🌐](https://www.npmjs.com/package/solidity-shell) `npm install solidity-shell`
10+
11+
An interactive Solidity shell.
12+
13+
![solidity-shell](https://user-images.githubusercontent.com/2865694/131328119-e363f20a-f627-43fc-8801-8d6613ad740f.gif)
14+
15+
![solidity-shell2](https://user-images.githubusercontent.com/2865694/131328490-e211e89b-ac59-4729-972b-3e3b19b75cfc.gif)

bin/main.js

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/env node
2+
'use strict'
3+
/**
4+
* @author github.com/tintinweb
5+
* @license MIT
6+
* */
7+
const Vorpal = require('vorpal');
8+
const c = require('chalk');
9+
const fs = require('fs');
10+
const os = require('os');
11+
const path = require('path');
12+
13+
const { InteractiveSolidityShell, SolidityStatement } = require('../src/handler');
14+
const { convert, multilineInput } = require('../src/utils');
15+
16+
const CONFIG_HOME = path.join(os.homedir(), '.solidity-shell');
17+
const CONFIG_FILE = path.join(CONFIG_HOME, '.config');
18+
19+
/** static funcs */
20+
function tryLoadSettings(){
21+
let settings = {};
22+
23+
if(fs.existsSync(CONFIG_FILE)){
24+
settings = JSON.parse(fs.readFileSync(CONFIG_FILE));
25+
}
26+
return settings;
27+
}
28+
29+
function trySaveSettings(settings){
30+
if(!fs.existsSync(CONFIG_HOME)){
31+
fs.mkdirSync(CONFIG_HOME);
32+
}
33+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(settings));
34+
}
35+
36+
/** MAIN */
37+
38+
const shell = new InteractiveSolidityShell(tryLoadSettings());
39+
40+
const vorpal = new Vorpal()
41+
.delimiter('')
42+
.show()
43+
.parse(process.argv);
44+
45+
process.on('exit', () => { shell.blockchain.stopService(); trySaveSettings(shell.settings) });
46+
47+
48+
vorpal
49+
.mode('repl', 'Enters Solidity Shell Mode')
50+
.delimiter(c.bold('» '))
51+
.init(function (args, cb) {
52+
this.log('🚀 Entering interactive Solidity shell. Type \'.help\' for help, \'.exit\' to exit.');
53+
return cb();
54+
})
55+
.action(function (input, cb) {
56+
let command = multilineInput(input);
57+
if (command.startsWith('.')) {
58+
let commandParts = command.split(' ');
59+
switch (commandParts[0]) {
60+
case '.help':
61+
cb(`
62+
📚 Help:
63+
-----
64+
65+
.help ... this help :)
66+
.exit ... exit the shell
67+
68+
.config ... show settings
69+
.set <key> <value> ... set setting
70+
.unset <key> ... clear setting
71+
72+
.reset ... reset cmd history. start from scratch.
73+
.undo ... undo last command
74+
75+
76+
cheers 🙌
77+
@tintinweb
78+
ConsenSys Diligence @ https://diligence.consensys.net/
79+
`);
80+
81+
break; //show usage
82+
case '.exit': process.exit(); return; //exit -> no more cb()
83+
case '.reset': shell.reset(); break; //reset complete state
84+
case '.undo': shell.revert(); break; //revert last action
85+
case '.set': shell.setSetting(commandParts[1], convert(commandParts[2])); break;
86+
case '.unset': shell.setSetting(commandParts[1], undefined); break;
87+
case '.config': return cb(shell.settings); break;
88+
default:
89+
console.error(`unknown command: ${command}. type '.help' for a list of commands.`);
90+
}
91+
// meta commands
92+
return cb();
93+
}
94+
95+
const statement = new SolidityStatement(command);
96+
97+
/* REPL cmd */
98+
shell.run(statement).then(res => {
99+
cb(c.bold(c.yellow(res)));
100+
}).catch(errors => {
101+
console.error(errors)
102+
cb()
103+
})
104+
});
105+
106+
107+
vorpal.execSync("repl")

0 commit comments

Comments
 (0)