-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CGKIELE-107] mallet #436
Merged
Merged
[CGKIELE-107] mallet #436
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
24021b1
[CGKIELE-107] mallet - a minimalist wallet
rtkaczyk 545dfa9
[CGKIELE-107] mallet - major refactoring of interpreter mechanics; ht…
rtkaczyk 4066cde
[CGKIELE-107] mallet - non-interactive mode; packaging
rtkaczyk 792e0af
[CGKIELE-107] mallet - fix sbt-verify
rtkaczyk be26a7e
[CGKIELE-107] mallet - added code comments (scaladoc)
rtkaczyk 8d1b8b0
[CGKIELE-107] mallet - help system for commands
rtkaczyk 06ea794
[CGKIELE-107] mallet - improved command line options
rtkaczyk 0494ee4
[CGKIELE-107] mallet - several fixes as per PR review
rtkaczyk 6e2352b
[CGKIELE-107] mallet - minor fix: use Constants.AppName
rtkaczyk 81f1d70
Merge remote-tracking branch 'origin/phase/iele_testnet' into feature…
rtkaczyk 3da9694
[CGKIELE-107] mallet - PR review fixes
rtkaczyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
akka { | ||
# to enable logging use: ["akka.event.slf4j.Slf4jLogger"] | ||
loggers = [] | ||
|
||
loglevel = OFF | ||
|
||
ssl-config { | ||
trustManager = { | ||
stores = [ | ||
# TODO: move to Wiki maybe? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we have to make some documentation elsewhere ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed, it will be done in #445 |
||
# When running Mantis with a self signed certificate as described in https://github.com/input-output-hk/mantis/wiki/Configuring-HTTPS-for-JSON-RPC, | ||
# we need to mark the public version of the certificate as trusted for mallet. To do that run: | ||
# | ||
# keytool -export -v \ | ||
# -alias mantis \ | ||
# -file path/to/mantis.crt \ | ||
# -keypass:env PW \ | ||
# -storepass:env PW \ | ||
# -keystore path/to/mantisCA.jks \ | ||
# -rfc | ||
# | ||
# and uncomment the entry below, adjusting the path: | ||
# | ||
# { type = "PEM", path = "path/to/mantis.crt" } | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/scala/io/iohk/ethereum/mallet/common/Constants.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.iohk.ethereum.mallet.common | ||
|
||
object Constants { | ||
val AppName = "mallet" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.iohk.ethereum.mallet.common | ||
|
||
sealed trait Err { | ||
def msg: String | ||
} | ||
|
||
case class ParserError(msg: String) extends Err | ||
|
||
case class RpcClientError(msg: String) extends Err | ||
|
24 changes: 24 additions & 0 deletions
24
src/main/scala/io/iohk/ethereum/mallet/common/StringUtil.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.iohk.ethereum.mallet.common | ||
|
||
import akka.util.ByteString | ||
import org.spongycastle.util.encoders.Hex | ||
|
||
object StringUtil { | ||
|
||
def unquote(s: String): String = { | ||
require(s.startsWith("\"") && s.endsWith("\"") && s.length > 1, s"[$s] is not quoted") | ||
s.substring(1, s.length - 1) | ||
} | ||
|
||
def prefix0x(s: String): String = | ||
if (s.startsWith("0x")) s else "0x" + s | ||
|
||
def drop0x(s: String): String = | ||
if (s.startsWith("0x")) s.substring(2) else s | ||
|
||
def hexToBytes(s: String): ByteString = { | ||
val digits = drop0x(s) | ||
val padded = if (digits.length % 2 == 0) digits else "0" + digits | ||
ByteString(Hex.decode(padded)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.iohk.ethereum.mallet.common | ||
|
||
import java.io.{PrintWriter, StringWriter} | ||
import scala.reflect.runtime.universe._ | ||
import scala.reflect.runtime.currentMirror | ||
|
||
object Util { | ||
|
||
/** | ||
* Finds sealed descendant objects of a base class/trait via reflection | ||
* @tparam T base type | ||
* @return a set of objects of type T | ||
*/ | ||
def sealedDescendants[T: TypeTag]: Set[T] = { | ||
val symbol = typeOf[T].typeSymbol | ||
val internal = symbol.asInstanceOf[scala.reflect.internal.Symbols#Symbol] | ||
val descendants = internal.sealedDescendants.map(_.asInstanceOf[Symbol]) - symbol | ||
descendants.map { d => | ||
val module = d.owner.typeSignature.member(d.name.toTermName) | ||
currentMirror.reflectModule(module.asModule).instance.asInstanceOf[T] | ||
} | ||
} | ||
|
||
def exceptionToString(ex: Throwable): String = { | ||
val sw = new StringWriter() | ||
sw.append(ex.getMessage + "\n") | ||
ex.printStackTrace(new PrintWriter(sw)) | ||
sw.toString | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/scala/io/iohk/ethereum/mallet/interpreter/AST.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.iohk.ethereum.mallet.interpreter | ||
|
||
import akka.util.ByteString | ||
import io.iohk.ethereum.mallet.common.StringUtil | ||
|
||
/** | ||
* Holds classes that represent constructs and literal types parsed from user input | ||
*/ | ||
object AST { | ||
|
||
case class Cmd(name: String, args: List[Argument]) | ||
|
||
case class Argument(name: Option[String], value: Literal) | ||
|
||
/** | ||
* Base trait for literal types of arguments from user input. | ||
* Note: these are different and require mapping to command parameter types | ||
*/ | ||
sealed trait Literal { | ||
def input: String | ||
} | ||
|
||
case class Quoted(input: String) extends Literal { | ||
def unquote: String = StringUtil.unquote(input) | ||
} | ||
|
||
case class Dec(input: String) extends Literal { | ||
def number: BigInt = BigInt(input) | ||
} | ||
|
||
case class Hex(input: String) extends Literal { | ||
def bytes: ByteString = StringUtil.hexToBytes(input) | ||
def digits: String = StringUtil.drop0x(input) | ||
def number: BigInt = BigInt(digits, 16) | ||
} | ||
|
||
case class Identifier(input: String) extends Literal | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
src/main/scala/io/iohk/ethereum/mallet/interpreter/CmdParser.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.iohk.ethereum.mallet.interpreter | ||
|
||
import io.iohk.ethereum.mallet.common.{Err, ParserError} | ||
import AST._ | ||
|
||
import scala.util.parsing.combinator.{JavaTokenParsers, RegexParsers} | ||
|
||
/** | ||
* EBNF syntax definition: | ||
* | ||
* cmd = identifier, { argument-list }; | ||
* argument-list = "(", (empty | argument, { ",", argument }), ")"; | ||
* argument = named-argument | literal; | ||
* named-argument = identifier, "=", literal; | ||
* literal = quoted | dec | hex | identifier; | ||
* empty = { whitespace }; | ||
* identifier = ? valid identifier ?; | ||
* dec = ? decimal number ?; | ||
* hex = 0x, ? hex digits ?; | ||
* quoted = ? " delimited string ?; | ||
*/ | ||
object CmdParser extends RegexParsers with JavaTokenParsers { | ||
|
||
val quoted: Parser[Quoted] = """\"([^"]|(?<=\\)")*\"""".r ^^ Quoted.apply | ||
|
||
val dec: Parser[Dec] = wholeNumber ^^ Dec.apply | ||
|
||
val hex: Parser[Hex] = "0x[A-Fa-f0-9]*".r ^^ Hex.apply | ||
|
||
val identifier: Parser[Identifier] = ident ^^ Identifier.apply | ||
|
||
val literal: Parser[Literal] = quoted | hex | dec | identifier | ||
|
||
val namedArgument: Parser[Argument] = (identifier <~ "=") ~ literal ^^ { | ||
case name ~ v => Argument(Some(name.input), v) | ||
} | ||
|
||
val argument: Parser[Argument] = namedArgument | literal ^^ (v => Argument(None, v)) | ||
|
||
val empty: Parser[List[Nothing]] = """\s*""".r ^^ (_ => Nil) | ||
|
||
val argumentList: Parser[List[Argument]] = (argument ~ ("," ~> argument).* ^^ { | ||
case a ~ as => a :: as | ||
}) | empty | ||
|
||
|
||
val funCall: Parser[Cmd] = ident ~ ("(" ~> argumentList <~ ")").? ^^ { | ||
case name ~ arguments => | ||
Cmd(name, arguments.getOrElse(Nil)) | ||
} | ||
|
||
|
||
def apply(line: String): Either[Err, Cmd] = parseAll(funCall, line) match { | ||
case NoSuccess(message, _) => | ||
val msg = if (line.trim.isEmpty) "" else message | ||
Left(ParserError(msg)) | ||
|
||
case Success(matched, _) => | ||
Right(matched) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change? it seems keeping it true is more secure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
false
means error instead of warning. I actually didn't plan on changing this, but it happened during some fixes I applied wrtsbt-verify
.I'm not having any problems with
sbt-verify
now, so I wouldn't mind staying withfalse
. WDYT?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, I didn't know it means an error :)