Browse Source

server: Relax asm format on ScriptPubKey

scalafmt-draft
Alexis Hernandez 7 years ago
parent
commit
9707e40038
  1. 10
      server/app/com/xsn/explorer/models/rpc/ScriptPubKey.scala
  2. 15
      server/test/com/xsn/explorer/models/rpc/ScriptPubKeySpec.scala

10
server/app/com/xsn/explorer/models/rpc/ScriptPubKey.scala

@ -15,10 +15,16 @@ case class ScriptPubKey(
* @return (owner address, merchant address)
*/
def getTPoSAddresses: Option[(Address, Address)] = {
// "asm": "OP_RETURN 5869337351664d51737932437a4d5a54726e4b573648464770315671465468644c77 58794a4338786e664672484e634d696e68366778755052595939484361593944416f 99"
/**
* expected:
* - "asm": "OP_RETURN 5869337351664d51737932437a4d5a54726e4b573648464770315671465468644c77 58794a4338786e664672484e634d696e68366778755052595939484361593944416f 99"
*
* new format:
*- "asm": "OP_RETURN 586a55587938507a55464d78534c37594135767866574a587365746b354d5638676f 58794a4338786e664672484e634d696e68366778755052595939484361593944416f 99 1f60a6a385a4e5163ffef65dd873f17452bb0d9f89da701ffcc5a0f72287273c0571485c29123fef880d2d8169cfdb884bf95a18a0b36461517acda390ce4cf441"
*/
Option(asm)
.map(_ split " ")
.filter(_.size == 4)
.filter(_.size >= 4) // relax size check
.map(_.toList)
.flatMap {
case op :: owner :: merchant :: commission if op == "OP_RETURN" =>

15
server/test/com/xsn/explorer/models/rpc/ScriptPubKeySpec.scala

@ -17,6 +17,13 @@ class ScriptPubKeySpec extends WordSpec with MustMatchers with OptionValues {
result.value mustEqual expected
}
"support more than 4 values if we have the addresses" in {
val script = ScriptPubKey("nulldata", "OP_RETURN 586a55587938507a55464d78534c37594135767866574a587365746b354d5638676f 58794a4338786e664672484e634d696e68366778755052595939484361593944416f 99 1f60a6a385a4e5163ffef65dd873f17452bb0d9f89da701ffcc5a0f72287273c0571485c29123fef880d2d8169cfdb884bf95a18a0b36461517acda390ce4cf441", List.empty)
val result = script.getTPoSAddresses
result.nonEmpty mustEqual true
}
"fail if OP_RETURN is not present" in {
val script = ScriptPubKey("nulldata", "OP_RTURN 5869337351664d51737932437a4d5a54726e4b573648464770315671465468644c77 58794a4338786e664672484e634d696e68366778755052595939484361593944416f 99", List.empty)
@ -44,13 +51,5 @@ class ScriptPubKeySpec extends WordSpec with MustMatchers with OptionValues {
val result = script.getTPoSAddresses
result.isEmpty mustEqual true
}
"fail if there are more than 4 values" in {
val script = ScriptPubKey("nulldata", "OP_RETURN 5869337351664d51737932437a4d5a54726e4b573648464770315671465468644c77 58794a4338786e664672484e634d696e68366778755052595939484361593944416f 99 x", List.empty)
val result = script.getTPoSAddresses
result.isEmpty mustEqual true
}
}
}

Loading…
Cancel
Save