forked from QORT/qortal
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from kennycud/master
Foreign Blockchain Server Configuration Information Offered in the Core API
- Loading branch information
Showing
20 changed files
with
429 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/org/qortal/api/resource/CrossChainUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.qortal.api.resource; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.qortal.crosschain.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public class CrossChainUtils { | ||
private static final Logger LOGGER = LogManager.getLogger(CrossChainUtils.class); | ||
|
||
public static ServerConfigurationInfo buildServerConfigurationInfo(Bitcoiny blockchain) { | ||
|
||
BitcoinyBlockchainProvider blockchainProvider = blockchain.getBlockchainProvider(); | ||
ChainableServer currentServer = blockchainProvider.getCurrentServer(); | ||
|
||
return new ServerConfigurationInfo( | ||
buildInfos(blockchainProvider.getServers(), currentServer), | ||
buildInfos(blockchainProvider.getRemainingServers(), currentServer), | ||
buildInfos(blockchainProvider.getUselessServers(), currentServer) | ||
); | ||
} | ||
|
||
public static ServerInfo buildInfo(ChainableServer server, boolean isCurrent) { | ||
return new ServerInfo( | ||
server.averageResponseTime(), | ||
server.getHostName(), | ||
server.getPort(), | ||
server.getConnectionType().toString(), | ||
isCurrent); | ||
|
||
} | ||
|
||
public static List<ServerInfo> buildInfos(Collection<ChainableServer> servers, ChainableServer currentServer) { | ||
|
||
List<ServerInfo> infos = new ArrayList<>( servers.size() ); | ||
|
||
for( ChainableServer server : servers ) | ||
{ | ||
infos.add(buildInfo(server, server.equals(currentServer))); | ||
} | ||
|
||
return infos; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.qortal.crosschain; | ||
|
||
public interface ChainableServer { | ||
public void addResponseTime(long responseTime); | ||
|
||
public long averageResponseTime(); | ||
|
||
public String getHostName(); | ||
|
||
public int getPort(); | ||
|
||
public ConnectionType getConnectionType(); | ||
|
||
public enum ConnectionType {TCP, SSL} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.