Skip to content

Commit

Permalink
server: Discard 0-value outputs while building a persisted transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexITC committed Apr 29, 2019
1 parent 149601d commit 46779c9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ object Transaction {

val outputs = tx.vout.flatMap { vout =>
for {
addresses <- vout.addresses
addresses <- vout.addresses if vout.value > 0
script <- vout.scriptPubKey.map(_.hex)
} yield Output(
tx.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,35 @@ class TransactionSpec extends WordSpec {
result.outputs must be(List(expected))
}

"discard outputs with 0 value" in {
val address = DataGenerator.randomAddress
val hex = HexString.from("00").get
val script = ScriptPubKey(
"nulldata",
"",
hex,
List(address))

val vout = List(
rpc.TransactionVOUT(0, 1, Some(script)),
rpc.TransactionVOUT(10, 2, Some(script)),
)

val tx = rpc.Transaction[rpc.TransactionVIN.HasValues](
id = DataGenerator.randomTransactionId,
size = Size(200),
blockhash = DataGenerator.randomBlockhash,
time = 10L,
blocktime = 10L,
confirmations = Confirmations(10),
vin = List.empty,
vout = vout)

val expected = Transaction.Output(tx.id, 2, 10, address, hex)
val (result, _) = persisted.Transaction.fromRPC(tx)
result.outputs must be(List(expected))
}

"extract the possible TPoS contracts" in {
val address = DataGenerator.randomAddress
val addressHex = DatatypeConverter.printHexBinary(address.string.getBytes)
Expand Down

0 comments on commit 46779c9

Please sign in to comment.