mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-22 23:44:21 +01:00
add open height to channel details
This commit is contained in:
@@ -45,6 +45,10 @@ public final class ChannelId implements Comparable<ChannelId> {
|
||||
return shortChannelId;
|
||||
}
|
||||
|
||||
public int getBlockHeight() {
|
||||
return (int) (shortChannelId >> 40);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
@@ -73,7 +77,7 @@ public final class ChannelId implements Comparable<ChannelId> {
|
||||
}
|
||||
|
||||
private String getCompactFormWithDelimiter(String delimiter) {
|
||||
long block = shortChannelId >> 40;
|
||||
long block = getBlockHeight();
|
||||
long transaction = shortChannelId >> 16 & 0xFFFFFF;
|
||||
long output = shortChannelId & 0xFFFF;
|
||||
return block + delimiter + transaction + delimiter + output;
|
||||
|
||||
@@ -137,6 +137,11 @@ class ChannelIdTest {
|
||||
assertThat(CHANNEL_ID.getCompactFormLnd()).isEqualTo("712345:123:1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getBlocKHeight() {
|
||||
assertThat(CHANNEL_ID.getBlockHeight()).isEqualTo(712_345);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEquals() {
|
||||
EqualsVerifier.forClass(ChannelId.class).verify();
|
||||
|
||||
@@ -71,6 +71,7 @@ class ChannelDetailsControllerIT {
|
||||
.andExpect(jsonPath("$.remotePubkey", is(PUBKEY_2.toString())))
|
||||
.andExpect(jsonPath("$.remoteAlias", is(ALIAS_2)))
|
||||
.andExpect(jsonPath("$.capacity", is(String.valueOf(CAPACITY.satoshis()))))
|
||||
.andExpect(jsonPath("$.openHeight", is(CHANNEL_ID.getBlockHeight())))
|
||||
.andExpect(jsonPath("$.private", is(true)))
|
||||
.andExpect(jsonPath("$.onChainCosts.openCosts", is("1000")))
|
||||
.andExpect(jsonPath("$.onChainCosts.closeCosts", is("2000")))
|
||||
|
||||
@@ -11,6 +11,7 @@ public record ChannelDetailsDto(
|
||||
String channelIdCompact,
|
||||
String channelIdCompactLnd,
|
||||
ChannelPoint channelPoint,
|
||||
int openHeight,
|
||||
Pubkey remotePubkey,
|
||||
String remoteAlias,
|
||||
String capacity,
|
||||
@@ -29,6 +30,7 @@ public record ChannelDetailsDto(
|
||||
localChannel.getId().getCompactForm(),
|
||||
localChannel.getId().getCompactFormLnd(),
|
||||
localChannel.getChannelPoint(),
|
||||
localChannel.getId().getBlockHeight(),
|
||||
localChannel.getRemotePubkey(),
|
||||
remoteAlias,
|
||||
String.valueOf(localChannel.getCapacity().satoshis()),
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package de.cotto.lndmanagej.controller.dto;
|
||||
|
||||
import de.cotto.lndmanagej.model.Coins;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static de.cotto.lndmanagej.model.BalanceInformationFixtures.BALANCE_INFORMATION;
|
||||
import static de.cotto.lndmanagej.model.ChannelFixtures.CAPACITY;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID;
|
||||
import static de.cotto.lndmanagej.model.ChannelPointFixtures.CHANNEL_POINT;
|
||||
import static de.cotto.lndmanagej.model.CoopClosedChannelFixtures.CLOSED_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL_PRIVATE;
|
||||
import static de.cotto.lndmanagej.model.NodeFixtures.ALIAS;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class ChannelDetailsDtoTest {
|
||||
|
||||
private static final OnChainCostsDto ON_CHAIN_COSTS = new OnChainCostsDto(Coins.ofSatoshis(1), Coins.ofSatoshis(2));
|
||||
private static final ChannelDetailsDto CHANNEL_DETAILS_DTO =
|
||||
new ChannelDetailsDto(CLOSED_CHANNEL, ALIAS, BALANCE_INFORMATION, ON_CHAIN_COSTS);
|
||||
|
||||
@Test
|
||||
void channelIdShort() {
|
||||
assertThat(CHANNEL_DETAILS_DTO.channelIdShort()).isEqualTo(String.valueOf(CHANNEL_ID.getShortChannelId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void channelIdCompact() {
|
||||
assertThat(CHANNEL_DETAILS_DTO.channelIdCompact()).isEqualTo(CHANNEL_ID.getCompactForm());
|
||||
}
|
||||
|
||||
@Test
|
||||
void channelIdCompactLnd() {
|
||||
assertThat(CHANNEL_DETAILS_DTO.channelIdCompactLnd()).isEqualTo(CHANNEL_ID.getCompactFormLnd());
|
||||
}
|
||||
|
||||
@Test
|
||||
void channelPoint() {
|
||||
assertThat(CHANNEL_DETAILS_DTO.channelPoint()).isEqualTo(CHANNEL_POINT);
|
||||
}
|
||||
|
||||
@Test
|
||||
void openHeight() {
|
||||
assertThat(CHANNEL_DETAILS_DTO.openHeight()).isEqualTo(CHANNEL_ID.getBlockHeight());
|
||||
}
|
||||
|
||||
@Test
|
||||
void remotePubkey() {
|
||||
assertThat(CHANNEL_DETAILS_DTO.remotePubkey()).isEqualTo(PUBKEY_2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void remoteAlias() {
|
||||
assertThat(CHANNEL_DETAILS_DTO.remoteAlias()).isEqualTo(ALIAS);
|
||||
}
|
||||
|
||||
@Test
|
||||
void capacity() {
|
||||
assertThat(CHANNEL_DETAILS_DTO.capacity()).isEqualTo(String.valueOf(CAPACITY.satoshis()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void privateChannel_false() {
|
||||
assertThat(CHANNEL_DETAILS_DTO.privateChannel()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void privateChannel_true() {
|
||||
ChannelDetailsDto dto =
|
||||
new ChannelDetailsDto(LOCAL_OPEN_CHANNEL_PRIVATE, ALIAS, BALANCE_INFORMATION, ON_CHAIN_COSTS);
|
||||
assertThat(dto.privateChannel()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void balance() {
|
||||
assertThat(CHANNEL_DETAILS_DTO.balance()).isEqualTo(BalanceInformationDto.createFrom(BALANCE_INFORMATION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void onChainCosts() {
|
||||
assertThat(CHANNEL_DETAILS_DTO.onChainCosts()).isEqualTo(ON_CHAIN_COSTS);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user