-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server: Add sendRawTransaction method to XSNService
This is a part for #26.
- Loading branch information
Showing
6 changed files
with
124 additions
and
1 deletion.
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,16 @@ | ||
package com.xsn.explorer.models | ||
|
||
class HexString private (val string: String) extends AnyVal | ||
|
||
object HexString { | ||
|
||
private val RegEx = "^[A-Fa-f0-9]+$" | ||
|
||
def from(string: String): Option[HexString] = { | ||
if (string.length % 2 == 0 && string.matches(RegEx)) { | ||
Option(new HexString(string)) | ||
} else { | ||
None | ||
} | ||
} | ||
} |
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
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,56 @@ | ||
package com.xsn.explorer.models | ||
|
||
import org.scalatest.{MustMatchers, OptionValues, WordSpec} | ||
|
||
class HexStringSpec extends WordSpec with MustMatchers with OptionValues { | ||
|
||
"from" should { | ||
"accept a valid hex" in { | ||
val string = "0100000001d036c70b1df769fa3205f8ff4e361af84073aa14c89de80488048b6ae4904ce9010000006a47304402201f1f9aef5d60f6e84714dfb98ca87ca8a146a2e04a3811d8f0aa770d8ac1c906022054e27a26f806a5d0c0e08332be186a96ee1ac951b8d1e6e3b10072d51eb6dd300121026648fd298f1cc06c474db0864720a9774efbe789dd67b2a46086f9754e4cc3f2ffffffff030000000000000000000e77b9932d0000001976a91436e0c51c93a357e23621bb993d28e5c18f95bb5588ac00d2496b000000001976a9149d1fef13c02f2f23cf9a09ba11987e90Dbf5910d88ac00000000" | ||
val result = HexString.from(string) | ||
result.value.string mustEqual string | ||
} | ||
|
||
"accept a valid hex with mixed case" in { | ||
val string = "0100000001d036c70b1df769fA3205f8fF4e361af84073aa14c89de80488048b6aE4904ce9010000006a47304402201f1f9aef5d60f6e84714dfb98ca87ca8a146a2e04a3811d8f0aa770d8ac1c906022054e27a26f806a5d0c0e08332be186a96ee1ac951b8d1e6e3b10072d51eb6dd300121026648fd298f1cc06c474db0864720a9774efbe789dd67b2a46086f9754e4cc3f2ffffffff030000000000000000000e77b9932d0000001976a91436e0c51c93a357e23621bb993d28e5c18f95bb5588ac00d2496b000000001976a9149d1fef13c02f2f23cf9a09ba11987e90Dbf5910d88ac00000000" | ||
val result = HexString.from(string) | ||
result.value.string mustEqual string | ||
} | ||
|
||
"accept a string with all hex characters" in { | ||
val string = "abcdef0123456789ABCDEF" | ||
val result = HexString.from(string) | ||
result.value.string mustEqual string | ||
} | ||
|
||
"accept a two characters string" in { | ||
val string = "0f" | ||
val result = HexString.from(string) | ||
result.value.string mustEqual string | ||
} | ||
|
||
"reject an empty string" in { | ||
val string = "" | ||
val result = HexString.from(string) | ||
result.isEmpty mustEqual true | ||
} | ||
|
||
"reject a single character" in { | ||
val string = "a" | ||
val result = HexString.from(string) | ||
result.isEmpty mustEqual true | ||
} | ||
|
||
"reject spaces" in { | ||
val string = "a " | ||
val result = HexString.from(string) | ||
result.isEmpty mustEqual true | ||
} | ||
|
||
"reject non-hex characters" in { | ||
val string = "abcdefg" | ||
val result = HexString.from(string) | ||
result.isEmpty mustEqual true | ||
} | ||
} | ||
} |