mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-21 06:54:29 +01:00
load more transaction details in background
This commit is contained in:
@@ -19,8 +19,8 @@ import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_3;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_COMPACT;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_COMPACT_3;
|
||||
import static de.cotto.lndmanagej.model.ClosedChannelFixtures.CLOSED_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.ClosedChannelFixtures.CLOSED_CHANNEL_3;
|
||||
import static de.cotto.lndmanagej.model.CoopClosedChannelFixtures.CLOSED_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.CoopClosedChannelFixtures.CLOSED_CHANNEL_3;
|
||||
import static de.cotto.lndmanagej.model.ForceClosingChannelFixtures.FORCE_CLOSING_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.ForceClosingChannelFixtures.FORCE_CLOSING_CHANNEL_3;
|
||||
import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL;
|
||||
|
||||
@@ -3,7 +3,7 @@ package de.cotto.lndmanagej.service;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import de.cotto.lndmanagej.caching.CacheBuilder;
|
||||
import de.cotto.lndmanagej.grpc.GrpcChannels;
|
||||
import de.cotto.lndmanagej.model.ClosedChannel;
|
||||
import de.cotto.lndmanagej.model.CoopClosedChannel;
|
||||
import de.cotto.lndmanagej.model.ForceClosingChannel;
|
||||
import de.cotto.lndmanagej.model.LocalChannel;
|
||||
import de.cotto.lndmanagej.model.LocalOpenChannel;
|
||||
@@ -21,7 +21,7 @@ public class ChannelService {
|
||||
private static final int CACHE_EXPIRY_MINUTES = 1;
|
||||
|
||||
private final LoadingCache<Object, Set<LocalOpenChannel>> channelsCache;
|
||||
private final LoadingCache<Object, Set<ClosedChannel>> closedChannelsCache;
|
||||
private final LoadingCache<Object, Set<CoopClosedChannel>> closedChannelsCache;
|
||||
private final LoadingCache<Object, Set<ForceClosingChannel>> forceClosingChannelsCache;
|
||||
private final LoadingCache<Object, Set<WaitingCloseChannel>> waitingCloseChannelsCache;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ChannelService {
|
||||
return channelsCache.getUnchecked("");
|
||||
}
|
||||
|
||||
public Set<ClosedChannel> getClosedChannels() {
|
||||
public Set<CoopClosedChannel> getClosedChannels() {
|
||||
return closedChannelsCache.getUnchecked("");
|
||||
}
|
||||
|
||||
@@ -66,8 +66,8 @@ public class ChannelService {
|
||||
Set<LocalOpenChannel> openChannels = getOpenChannelsWith(pubkey);
|
||||
Set<WaitingCloseChannel> waitingCloseChannels = getWaitingCloseChannels();
|
||||
Set<ForceClosingChannel> forceClosingChannels = getForceClosingChannels();
|
||||
Set<ClosedChannel> closedChannels = getClosedChannels();
|
||||
return Stream.of(openChannels, closedChannels, waitingCloseChannels, forceClosingChannels)
|
||||
Set<CoopClosedChannel> coopClosedChannels = getClosedChannels();
|
||||
return Stream.of(openChannels, coopClosedChannels, waitingCloseChannels, forceClosingChannels)
|
||||
.flatMap(Collection::stream)
|
||||
.filter(c -> c.getRemotePubkey().equals(pubkey))
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
@@ -2,10 +2,14 @@ package de.cotto.lndmanagej.service;
|
||||
|
||||
import de.cotto.lndmanagej.model.Channel;
|
||||
import de.cotto.lndmanagej.model.ChannelPoint;
|
||||
import de.cotto.lndmanagej.model.ClosedChannel;
|
||||
import de.cotto.lndmanagej.transactions.service.TransactionService;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
|
||||
@Component
|
||||
@@ -20,11 +24,34 @@ public class TransactionBackgroundLoader {
|
||||
|
||||
@Scheduled(fixedDelay = 5, timeUnit = MINUTES)
|
||||
public void loadTransactionForOneChannel() {
|
||||
channelService.getOpenChannels().stream()
|
||||
.map(Channel::getChannelPoint)
|
||||
.map(ChannelPoint::getTransactionHash)
|
||||
getTransactionHashes()
|
||||
.filter(transactionService::isUnknown)
|
||||
.findAny()
|
||||
.ifPresent(transactionService::getTransaction);
|
||||
}
|
||||
|
||||
private Stream<String> getTransactionHashes() {
|
||||
Stream<String> openTransactionHashes = getOpenTransactionHashes();
|
||||
Stream<String> closeTransactionHashes = getCloseTransactionHashes();
|
||||
return Stream.concat(openTransactionHashes, closeTransactionHashes);
|
||||
}
|
||||
|
||||
private Stream<String> getOpenTransactionHashes() {
|
||||
return Stream.of(
|
||||
channelService.getOpenChannels(),
|
||||
channelService.getClosedChannels(),
|
||||
channelService.getForceClosingChannels(),
|
||||
channelService.getWaitingCloseChannels()
|
||||
)
|
||||
.flatMap(Collection::stream)
|
||||
.map(Channel::getChannelPoint)
|
||||
.map(ChannelPoint::getTransactionHash);
|
||||
}
|
||||
|
||||
private Stream<String> getCloseTransactionHashes() {
|
||||
return Stream.of(channelService.getClosedChannels(), channelService.getForceClosingChannels())
|
||||
.flatMap(Collection::stream)
|
||||
.map(ClosedChannel::getCloseTransactionHash);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_3;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_COMPACT;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_COMPACT_3;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_COMPACT_4;
|
||||
import static de.cotto.lndmanagej.model.ClosedChannelFixtures.CLOSED_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.ClosedChannelFixtures.CLOSED_CHANNEL_3;
|
||||
import static de.cotto.lndmanagej.model.CoopClosedChannelFixtures.CLOSED_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.CoopClosedChannelFixtures.CLOSED_CHANNEL_3;
|
||||
import static de.cotto.lndmanagej.model.ForceClosingChannelFixtures.FORCE_CLOSING_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.ForceClosingChannelFixtures.FORCE_CLOSING_CHANNEL_3;
|
||||
import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL;
|
||||
|
||||
@@ -9,10 +9,10 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static de.cotto.lndmanagej.model.ClosedChannelFixtures.CLOSED_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.ClosedChannelFixtures.CLOSED_CHANNEL_2;
|
||||
import static de.cotto.lndmanagej.model.ClosedChannelFixtures.CLOSED_CHANNEL_3;
|
||||
import static de.cotto.lndmanagej.model.ClosedChannelFixtures.CLOSED_CHANNEL_TO_NODE_3;
|
||||
import static de.cotto.lndmanagej.model.CoopClosedChannelFixtures.CLOSED_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.CoopClosedChannelFixtures.CLOSED_CHANNEL_2;
|
||||
import static de.cotto.lndmanagej.model.CoopClosedChannelFixtures.CLOSED_CHANNEL_3;
|
||||
import static de.cotto.lndmanagej.model.CoopClosedChannelFixtures.CLOSED_CHANNEL_TO_NODE_3;
|
||||
import static de.cotto.lndmanagej.model.ForceClosingChannelFixtures.FORCE_CLOSING_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.ForceClosingChannelFixtures.FORCE_CLOSING_CHANNEL_2;
|
||||
import static de.cotto.lndmanagej.model.ForceClosingChannelFixtures.FORCE_CLOSING_CHANNEL_TO_NODE_3;
|
||||
|
||||
@@ -18,10 +18,13 @@ import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_3;
|
||||
import static de.cotto.lndmanagej.model.ChannelPointFixtures.CHANNEL_POINT;
|
||||
import static de.cotto.lndmanagej.model.ChannelPointFixtures.CHANNEL_POINT_2;
|
||||
import static de.cotto.lndmanagej.model.ChannelPointFixtures.CHANNEL_POINT_3;
|
||||
import static de.cotto.lndmanagej.model.CoopClosedChannelFixtures.CLOSED_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.ForceClosingChannelFixtures.FORCE_CLOSING_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL_2;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2;
|
||||
import static de.cotto.lndmanagej.model.WaitingCloseChannelFixtures.WAITING_CLOSE_CHANNEL;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -46,7 +49,7 @@ class TransactionBackgroundLoaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_all_known() {
|
||||
void update_from_open_channels_all_known() {
|
||||
when(channelService.getOpenChannels()).thenReturn(Set.of(LOCAL_OPEN_CHANNEL, LOCAL_OPEN_CHANNEL_2));
|
||||
when(transactionService.isUnknown(any())).thenReturn(false);
|
||||
transactionBackgroundLoader.loadTransactionForOneChannel();
|
||||
@@ -54,13 +57,61 @@ class TransactionBackgroundLoaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_all_unknown() {
|
||||
void update_from_open_channels_all_unknown() {
|
||||
when(channelService.getOpenChannels()).thenReturn(Set.of(LOCAL_OPEN_CHANNEL, LOCAL_OPEN_CHANNEL_2));
|
||||
when(transactionService.isUnknown(any())).thenReturn(true);
|
||||
transactionBackgroundLoader.loadTransactionForOneChannel();
|
||||
verify(transactionService, times(1)).getTransaction(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_from_closed_channels() {
|
||||
String transactionHash = CLOSED_CHANNEL.getChannelPoint().getTransactionHash();
|
||||
when(channelService.getClosedChannels()).thenReturn(Set.of(CLOSED_CHANNEL));
|
||||
when(transactionService.isUnknown(transactionHash)).thenReturn(true);
|
||||
transactionBackgroundLoader.loadTransactionForOneChannel();
|
||||
verify(transactionService).getTransaction(transactionHash);
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_from_closed_channels_close_transaction() {
|
||||
String closeTransactionHash = CLOSED_CHANNEL.getCloseTransactionHash();
|
||||
when(channelService.getClosedChannels()).thenReturn(Set.of(CLOSED_CHANNEL));
|
||||
when(transactionService.isUnknown(CLOSED_CHANNEL.getChannelPoint().getTransactionHash())).thenReturn(false);
|
||||
when(transactionService.isUnknown(closeTransactionHash)).thenReturn(true);
|
||||
transactionBackgroundLoader.loadTransactionForOneChannel();
|
||||
verify(transactionService).getTransaction(closeTransactionHash);
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_from_waiting_close_channels() {
|
||||
String transactionHash = WAITING_CLOSE_CHANNEL.getChannelPoint().getTransactionHash();
|
||||
when(channelService.getWaitingCloseChannels()).thenReturn(Set.of(WAITING_CLOSE_CHANNEL));
|
||||
when(transactionService.isUnknown(transactionHash)).thenReturn(true);
|
||||
transactionBackgroundLoader.loadTransactionForOneChannel();
|
||||
verify(transactionService).getTransaction(transactionHash);
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_from_force_closing_channels() {
|
||||
String transactionHash = FORCE_CLOSING_CHANNEL.getChannelPoint().getTransactionHash();
|
||||
when(channelService.getForceClosingChannels()).thenReturn(Set.of(FORCE_CLOSING_CHANNEL));
|
||||
when(transactionService.isUnknown(transactionHash)).thenReturn(true);
|
||||
transactionBackgroundLoader.loadTransactionForOneChannel();
|
||||
verify(transactionService).getTransaction(transactionHash);
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_from_force_closing_channels_close_transaction() {
|
||||
String closeTransactionHash = FORCE_CLOSING_CHANNEL.getCloseTransactionHash();
|
||||
String openTransactionHash = FORCE_CLOSING_CHANNEL.getChannelPoint().getTransactionHash();
|
||||
when(channelService.getForceClosingChannels()).thenReturn(Set.of(FORCE_CLOSING_CHANNEL));
|
||||
when(transactionService.isUnknown(openTransactionHash)).thenReturn(false);
|
||||
when(transactionService.isUnknown(closeTransactionHash)).thenReturn(true);
|
||||
transactionBackgroundLoader.loadTransactionForOneChannel();
|
||||
verify(transactionService).getTransaction(closeTransactionHash);
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_one_unknown() {
|
||||
LocalOpenChannel channel1 =
|
||||
@@ -71,10 +122,11 @@ class TransactionBackgroundLoaderTest {
|
||||
new LocalOpenChannel(CHANNEL_ID_3, CHANNEL_POINT_3, CAPACITY, PUBKEY, PUBKEY_2, BALANCE_INFORMATION);
|
||||
when(channelService.getOpenChannels()).thenReturn(Set.of(channel1, channel2, channel3));
|
||||
String unknownHash = CHANNEL_POINT_3.getTransactionHash();
|
||||
when(transactionService.isUnknown(any())).thenReturn(false);
|
||||
when(transactionService.isUnknown(unknownHash)).thenReturn(true);
|
||||
|
||||
transactionBackgroundLoader.loadTransactionForOneChannel();
|
||||
|
||||
verify(transactionService, times(1)).getTransaction(unknownHash);
|
||||
verify(transactionService).getTransaction(unknownHash);
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,8 @@ import de.cotto.lndmanagej.model.BalanceInformation;
|
||||
import de.cotto.lndmanagej.model.ChannelId;
|
||||
import de.cotto.lndmanagej.model.ChannelIdResolver;
|
||||
import de.cotto.lndmanagej.model.ChannelPoint;
|
||||
import de.cotto.lndmanagej.model.ClosedChannel;
|
||||
import de.cotto.lndmanagej.model.Coins;
|
||||
import de.cotto.lndmanagej.model.CoopClosedChannel;
|
||||
import de.cotto.lndmanagej.model.ForceClosingChannel;
|
||||
import de.cotto.lndmanagej.model.LocalOpenChannel;
|
||||
import de.cotto.lndmanagej.model.Pubkey;
|
||||
@@ -45,7 +45,7 @@ public class GrpcChannels {
|
||||
.collect(toSet());
|
||||
}
|
||||
|
||||
public Set<ClosedChannel> getClosedChannels() {
|
||||
public Set<CoopClosedChannel> getClosedChannels() {
|
||||
Pubkey ownPubkey = grpcGetInfo.getPubkey();
|
||||
return grpcService.getClosedChannels().stream()
|
||||
.filter(this::hasSupportedCloseType)
|
||||
@@ -98,7 +98,8 @@ public class GrpcChannels {
|
||||
channelPoint,
|
||||
Coins.ofSatoshis(pendingChannel.getCapacity()),
|
||||
ownPubkey,
|
||||
Pubkey.create(pendingChannel.getRemoteNodePub())
|
||||
Pubkey.create(pendingChannel.getRemoteNodePub()),
|
||||
forceClosedChannel.getClosingTxid()
|
||||
));
|
||||
}
|
||||
|
||||
@@ -125,7 +126,7 @@ public class GrpcChannels {
|
||||
return new LocalOpenChannel(channelId, channelPoint, capacity, ownPubkey, remotePubkey, balanceInformation);
|
||||
}
|
||||
|
||||
private Optional<ClosedChannel> toClosedChannel(
|
||||
private Optional<CoopClosedChannel> toClosedChannel(
|
||||
ChannelCloseSummary channelCloseSummary,
|
||||
Pubkey ownPubkey
|
||||
) {
|
||||
@@ -134,7 +135,14 @@ public class GrpcChannels {
|
||||
Coins capacity = Coins.ofSatoshis(channelCloseSummary.getCapacity());
|
||||
return getChannelId(channelCloseSummary)
|
||||
.or(() -> channelIdResolver.resolveFromChannelPoint(channelPoint))
|
||||
.map(id -> new ClosedChannel(id, channelPoint, capacity, ownPubkey, remotePubkey));
|
||||
.map(id -> new CoopClosedChannel(
|
||||
id,
|
||||
channelPoint,
|
||||
capacity,
|
||||
ownPubkey,
|
||||
remotePubkey,
|
||||
channelCloseSummary.getClosingTxHash()
|
||||
));
|
||||
}
|
||||
|
||||
private Optional<ChannelId> getChannelId(ChannelCloseSummary channelCloseSummary) {
|
||||
|
||||
@@ -26,9 +26,11 @@ import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_3;
|
||||
import static de.cotto.lndmanagej.model.ChannelPointFixtures.CHANNEL_POINT;
|
||||
import static de.cotto.lndmanagej.model.ChannelPointFixtures.CHANNEL_POINT_2;
|
||||
import static de.cotto.lndmanagej.model.ChannelPointFixtures.CHANNEL_POINT_3;
|
||||
import static de.cotto.lndmanagej.model.ClosedChannelFixtures.CLOSED_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.ClosedChannelFixtures.CLOSED_CHANNEL_2;
|
||||
import static de.cotto.lndmanagej.model.ClosedChannelFixtures.CLOSED_CHANNEL_3;
|
||||
import static de.cotto.lndmanagej.model.ChannelPointFixtures.TRANSACTION_HASH_2;
|
||||
import static de.cotto.lndmanagej.model.ChannelPointFixtures.TRANSACTION_HASH_3;
|
||||
import static de.cotto.lndmanagej.model.CoopClosedChannelFixtures.CLOSED_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.CoopClosedChannelFixtures.CLOSED_CHANNEL_2;
|
||||
import static de.cotto.lndmanagej.model.CoopClosedChannelFixtures.CLOSED_CHANNEL_3;
|
||||
import static de.cotto.lndmanagej.model.ForceClosingChannelFixtures.FORCE_CLOSING_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.ForceClosingChannelFixtures.FORCE_CLOSING_CHANNEL_2;
|
||||
import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL;
|
||||
@@ -202,12 +204,14 @@ class GrpcChannelsTest {
|
||||
.setRemotePubkey(PUBKEY_2.toString())
|
||||
.setCapacity(CAPACITY.satoshis())
|
||||
.setChannelPoint(CHANNEL_POINT.toString())
|
||||
.setClosingTxHash(TRANSACTION_HASH_2)
|
||||
.build();
|
||||
}
|
||||
|
||||
private ForceClosedChannel forceClosingChannel(ChannelPoint channelPoint) {
|
||||
return ForceClosedChannel.newBuilder()
|
||||
.setChannel(pendingChannel(channelPoint))
|
||||
.setClosingTxid(TRANSACTION_HASH_3)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,44 @@
|
||||
package de.cotto.lndmanagej.model;
|
||||
|
||||
public final class ClosedChannel extends LocalChannel {
|
||||
public ClosedChannel(
|
||||
import java.util.Objects;
|
||||
|
||||
public class ClosedChannel extends LocalChannel {
|
||||
private final String closeTransactionHash;
|
||||
|
||||
protected ClosedChannel(
|
||||
ChannelId channelId,
|
||||
ChannelPoint channelPoint,
|
||||
Coins capacity,
|
||||
Pubkey ownPubkey,
|
||||
Pubkey remotePubkey
|
||||
Pubkey remotePubkey,
|
||||
String closeTransactionHash
|
||||
) {
|
||||
super(channelId, channelPoint, capacity, ownPubkey, remotePubkey);
|
||||
this.closeTransactionHash = closeTransactionHash;
|
||||
}
|
||||
|
||||
public String getCloseTransactionHash() {
|
||||
return closeTransactionHash;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("CPD-START")
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (other == null || getClass() != other.getClass()) {
|
||||
return false;
|
||||
}
|
||||
if (!super.equals(other)) {
|
||||
return false;
|
||||
}
|
||||
ClosedChannel that = (ClosedChannel) other;
|
||||
return Objects.equals(closeTransactionHash, that.closeTransactionHash);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), closeTransactionHash);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package de.cotto.lndmanagej.model;
|
||||
|
||||
public class CoopClosedChannel extends ClosedChannel {
|
||||
public CoopClosedChannel(
|
||||
ChannelId channelId,
|
||||
ChannelPoint channelPoint,
|
||||
Coins capacity,
|
||||
Pubkey ownPubkey,
|
||||
Pubkey remotePubkey,
|
||||
String closeTransactionHash
|
||||
) {
|
||||
super(channelId, channelPoint, capacity, ownPubkey, remotePubkey, closeTransactionHash);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
package de.cotto.lndmanagej.model;
|
||||
|
||||
public final class ForceClosingChannel extends LocalChannel {
|
||||
public final class ForceClosingChannel extends ClosedChannel {
|
||||
public ForceClosingChannel(
|
||||
ChannelId channelId,
|
||||
ChannelPoint channelPoint,
|
||||
Coins capacity,
|
||||
Pubkey ownPubkey,
|
||||
Pubkey remotePubkey
|
||||
Pubkey remotePubkey,
|
||||
String closeTransactionHash
|
||||
) {
|
||||
super(channelId, channelPoint, capacity, ownPubkey, remotePubkey);
|
||||
super(channelId, channelPoint, capacity, ownPubkey, remotePubkey, closeTransactionHash);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,15 +6,17 @@ import org.junit.jupiter.api.Test;
|
||||
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.ClosedChannelFixtures.CLOSED_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.ChannelPointFixtures.TRANSACTION_HASH_2;
|
||||
import static de.cotto.lndmanagej.model.CoopClosedChannelFixtures.CLOSED_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class ClosedChannelTest {
|
||||
class CoopClosedChannelTest {
|
||||
@Test
|
||||
void create() {
|
||||
assertThat(new ClosedChannel(CHANNEL_ID, CHANNEL_POINT, CAPACITY, PUBKEY, PUBKEY_2)).isEqualTo(CLOSED_CHANNEL);
|
||||
assertThat(new CoopClosedChannel(CHANNEL_ID, CHANNEL_POINT, CAPACITY, PUBKEY, PUBKEY_2, TRANSACTION_HASH_2))
|
||||
.isEqualTo(CLOSED_CHANNEL);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -42,8 +44,13 @@ class ClosedChannelTest {
|
||||
assertThat(CLOSED_CHANNEL.getPubkeys()).containsExactlyInAnyOrder(PUBKEY, PUBKEY_2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getCloseTransactionHash() {
|
||||
assertThat(CLOSED_CHANNEL.getCloseTransactionHash()).isEqualTo(TRANSACTION_HASH_2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEquals() {
|
||||
EqualsVerifier.forClass(ClosedChannel.class).usingGetClass().verify();
|
||||
EqualsVerifier.forClass(CoopClosedChannel.class).usingGetClass().verify();
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import org.junit.jupiter.api.Test;
|
||||
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.ChannelPointFixtures.TRANSACTION_HASH_3;
|
||||
import static de.cotto.lndmanagej.model.ForceClosingChannelFixtures.FORCE_CLOSING_CHANNEL;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2;
|
||||
@@ -14,7 +15,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class ForceClosingChannelTest {
|
||||
@Test
|
||||
void create() {
|
||||
assertThat(new ForceClosingChannel(CHANNEL_ID, CHANNEL_POINT, CAPACITY, PUBKEY, PUBKEY_2))
|
||||
assertThat(new ForceClosingChannel(CHANNEL_ID, CHANNEL_POINT, CAPACITY, PUBKEY, PUBKEY_2, TRANSACTION_HASH_3))
|
||||
.isEqualTo(FORCE_CLOSING_CHANNEL);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package de.cotto.lndmanagej.model;
|
||||
public class ChannelPointFixtures {
|
||||
public static final String TRANSACTION_HASH = "abc000abc000abc000abc000abc000abc000abc000abc000abc000abc000abc0";
|
||||
public static final String TRANSACTION_HASH_2 = "abc111abc000abc000abc000abc000abc000abc000abc000abc000abc000abc0";
|
||||
public static final String TRANSACTION_HASH_3 = "abc222abc000abc000abc000abc000abc000abc000abc000abc000abc000abc0";
|
||||
public static final int OUTPUT = 1;
|
||||
public static final int OUTPUT_2 = 123;
|
||||
public static final ChannelPoint CHANNEL_POINT = ChannelPoint.create(TRANSACTION_HASH + ":" + OUTPUT);
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package de.cotto.lndmanagej.model;
|
||||
|
||||
import static de.cotto.lndmanagej.model.ChannelFixtures.CAPACITY;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_2;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_3;
|
||||
import static de.cotto.lndmanagej.model.ChannelPointFixtures.CHANNEL_POINT;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_3;
|
||||
|
||||
public class ClosedChannelFixtures {
|
||||
public static final ClosedChannel CLOSED_CHANNEL =
|
||||
new ClosedChannel(CHANNEL_ID, CHANNEL_POINT, CAPACITY, PUBKEY, PUBKEY_2);
|
||||
public static final ClosedChannel CLOSED_CHANNEL_2
|
||||
= new ClosedChannel(CHANNEL_ID_2, CHANNEL_POINT, CAPACITY, PUBKEY, PUBKEY_2);
|
||||
public static final ClosedChannel CLOSED_CHANNEL_3 =
|
||||
new ClosedChannel(CHANNEL_ID_3, CHANNEL_POINT, CAPACITY, PUBKEY, PUBKEY_2);
|
||||
public static final ClosedChannel CLOSED_CHANNEL_TO_NODE_3 =
|
||||
new ClosedChannel(CHANNEL_ID_3, CHANNEL_POINT, CAPACITY, PUBKEY, PUBKEY_3);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package de.cotto.lndmanagej.model;
|
||||
|
||||
import static de.cotto.lndmanagej.model.ChannelFixtures.CAPACITY;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_2;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_3;
|
||||
import static de.cotto.lndmanagej.model.ChannelPointFixtures.CHANNEL_POINT;
|
||||
import static de.cotto.lndmanagej.model.ChannelPointFixtures.TRANSACTION_HASH_2;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_3;
|
||||
|
||||
public class CoopClosedChannelFixtures {
|
||||
public static final CoopClosedChannel CLOSED_CHANNEL =
|
||||
new CoopClosedChannel(CHANNEL_ID, CHANNEL_POINT, CAPACITY, PUBKEY, PUBKEY_2, TRANSACTION_HASH_2);
|
||||
public static final CoopClosedChannel CLOSED_CHANNEL_2
|
||||
= new CoopClosedChannel(CHANNEL_ID_2, CHANNEL_POINT, CAPACITY, PUBKEY, PUBKEY_2, TRANSACTION_HASH_2);
|
||||
public static final CoopClosedChannel CLOSED_CHANNEL_3 =
|
||||
new CoopClosedChannel(CHANNEL_ID_3, CHANNEL_POINT, CAPACITY, PUBKEY, PUBKEY_2, TRANSACTION_HASH_2);
|
||||
public static final CoopClosedChannel CLOSED_CHANNEL_TO_NODE_3 =
|
||||
new CoopClosedChannel(CHANNEL_ID_3, CHANNEL_POINT, CAPACITY, PUBKEY, PUBKEY_3, TRANSACTION_HASH_2);
|
||||
}
|
||||
@@ -6,17 +6,18 @@ import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_2;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_3;
|
||||
import static de.cotto.lndmanagej.model.ChannelPointFixtures.CHANNEL_POINT;
|
||||
import static de.cotto.lndmanagej.model.ChannelPointFixtures.CHANNEL_POINT_2;
|
||||
import static de.cotto.lndmanagej.model.ChannelPointFixtures.TRANSACTION_HASH_3;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_3;
|
||||
|
||||
public class ForceClosingChannelFixtures {
|
||||
public static final ForceClosingChannel FORCE_CLOSING_CHANNEL =
|
||||
new ForceClosingChannel(CHANNEL_ID, CHANNEL_POINT, CAPACITY, PUBKEY, PUBKEY_2);
|
||||
new ForceClosingChannel(CHANNEL_ID, CHANNEL_POINT, CAPACITY, PUBKEY, PUBKEY_2, TRANSACTION_HASH_3);
|
||||
public static final ForceClosingChannel FORCE_CLOSING_CHANNEL_2
|
||||
= new ForceClosingChannel(CHANNEL_ID_2, CHANNEL_POINT_2, CAPACITY, PUBKEY, PUBKEY_2);
|
||||
= new ForceClosingChannel(CHANNEL_ID_2, CHANNEL_POINT_2, CAPACITY, PUBKEY, PUBKEY_2, TRANSACTION_HASH_3);
|
||||
public static final ForceClosingChannel FORCE_CLOSING_CHANNEL_3 =
|
||||
new ForceClosingChannel(CHANNEL_ID_3, CHANNEL_POINT, CAPACITY, PUBKEY, PUBKEY_2);
|
||||
new ForceClosingChannel(CHANNEL_ID_3, CHANNEL_POINT, CAPACITY, PUBKEY, PUBKEY_2, TRANSACTION_HASH_3);
|
||||
public static final ForceClosingChannel FORCE_CLOSING_CHANNEL_TO_NODE_3 =
|
||||
new ForceClosingChannel(CHANNEL_ID_3, CHANNEL_POINT, CAPACITY, PUBKEY, PUBKEY_3);
|
||||
new ForceClosingChannel(CHANNEL_ID_3, CHANNEL_POINT, CAPACITY, PUBKEY, PUBKEY_3, TRANSACTION_HASH_3);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user