Skip to content

Commit 6f74777

Browse files
author
Michal Mrozek
committed
[FIX] Empty address handling
1 parent 233d547 commit 6f74777

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ 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)
98+
case Some(JString(_)) => extractAddress("0x0")
9899
case Some(_) => Left(InvalidAddress)
99100
case _ => Left(InvalidParams("TX 'from' is required"))
100101
}
101102

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

0 commit comments

Comments
 (0)