Skip to content

Commit 75a5a71

Browse files
author
Michał Mrożek
authored
Merge pull request #844 from input-output-hk/fix/empty-address-handling
[FIX] Empty address handling
2 parents 233d547 + 72841fd commit 75a5a71

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/main/scala/io/iohk/ethereum/domain/Address.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ object Address {
3131

3232
def apply(hexString: String): Address = {
3333
val bytes = Hex.decode(hexString.replaceFirst("^0x", ""))
34-
require(bytes.length <= Length, s"Invalid address: $hexString")
34+
require(bytes.nonEmpty && bytes.length <= Length, s"Invalid address: $hexString")
3535
Address(bytes)
3636
}
3737

src/main/scala/io/iohk/ethereum/jsonrpc/JsonMethodsImplicits.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,14 @@ trait JsonMethodsImplicits {
9494

9595
for {
9696
from <- input.get("from") match {
97-
case Some(JString(s)) => extractAddress(s)
97+
case Some(JString(s)) if s.nonEmpty => extractAddress(s)
9898
case Some(_) => Left(InvalidAddress)
9999
case _ => Left(InvalidParams("TX 'from' is required"))
100100
}
101101

102102
to <- input.get("to") match {
103-
case Some(JString(s)) =>
104-
extractAddress(s).map(Some(_))
105-
103+
case Some(JString(s)) if s.nonEmpty => extractAddress(s).map(Option.apply)
104+
case Some(JString(_)) => extractAddress("0x0").map(Option.apply)
106105
case Some(_) => Left(InvalidAddress)
107106
case None => Right(None)
108107
}

0 commit comments

Comments
 (0)