Skip to content

[FIX] Empty address handling #844

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

Merged
merged 1 commit into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/scala/io/iohk/ethereum/domain/Address.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object Address {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,14 @@ trait JsonMethodsImplicits {

for {
from <- input.get("from") match {
case Some(JString(s)) => extractAddress(s)
case Some(JString(s)) if s.nonEmpty => extractAddress(s)
case Some(_) => Left(InvalidAddress)
case _ => Left(InvalidParams("TX 'from' is required"))
}

to <- input.get("to") match {
case Some(JString(s)) =>
extractAddress(s).map(Some(_))

case Some(JString(s)) if s.nonEmpty => extractAddress(s).map(Option.apply)
case Some(JString(_)) => extractAddress("0x0").map(Option.apply)
case Some(_) => Left(InvalidAddress)
case None => Right(None)
}
Expand Down