Skip to content

Commit

Permalink
bugfix: do not skip empty outputs, required for LN
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Otto committed Nov 9, 2023
1 parent 01617de commit db9b488
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Transaction(
this.time = time.withNano(0);
this.fees = fees;
this.inputs = inputs.stream().filter(input -> input.getValue().satoshis() > 0).collect(toList());
this.outputs = outputs.stream().filter(output -> output.getValue().satoshis() > 0).collect(toList());
this.outputs = new ArrayList<>(outputs);
this.chain = chain;
validateCoinsSum(hash, fees, inputs, outputs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void forCoinbase() {
List.of(OUTPUT_1, OUTPUT_2, new Output(Coins.NONE, new Address("xxx"))),
BTC
);
assertThat(coinbaseTransaction.getOutputs()).hasSize(2);
assertThat(coinbaseTransaction.getOutputs()).hasSize(3);
}

@Test
Expand Down Expand Up @@ -259,7 +259,9 @@ void getOutputs() {
}

@Test
void ignoresEmptyOutputs() {
void includes_empty_outputs() {
// Even though outputs not spending anything, they count when considering the output index.
// As the output index is used to identify lightning network channels, empty outputs must not be ignored.
List<Output> outputs = List.of(
Output.EMPTY,
new Output(Coins.NONE, new Address("xx")),
Expand All @@ -268,7 +270,9 @@ void ignoresEmptyOutputs() {
);
Transaction transaction =
new Transaction(TRANSACTION_HASH, BLOCK_HEIGHT, DATE_TIME, FEES, TRANSACTION.getInputs(), outputs, BTC);
assertThat(transaction.getOutputs()).isEqualTo(TRANSACTION.getOutputs());
assertThat(transaction.getOutputs())
.containsAll(TRANSACTION.getOutputs())
.hasSize(4);
}

@Test
Expand Down Expand Up @@ -345,4 +349,4 @@ private Transaction getTransaction(Coins inFromAddress, Coins outToAddress2) {
BTC
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,6 @@ void deserialization_zero_output_with_d_address() throws Exception {
}""";
BlockchairTransactionDto blockchairTransactionDto =
objectMapper.readValue(json, BlockchairTransactionDto.class);
assertThat(blockchairTransactionDto.toModel(BTC).getOutputs()).isEmpty();
assertThat(blockchairTransactionDto.toModel(BTC).getOutputs()).hasSize(1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,6 @@ void deserialization_zero_output_with_null_data() throws Exception {
}""";
BtcComTransactionDto btcComTransactionDto =
objectMapper.readValue(json, BtcComTransactionDto.class);
assertThat(btcComTransactionDto.toModel(BTC).getOutputs()).isEmpty();
assertThat(btcComTransactionDto.toModel(BTC).getOutputs()).hasSize(1);
}
}
}

0 comments on commit db9b488

Please sign in to comment.