From 7ed260058400d37e5e44b19f514875eecceb6d5f Mon Sep 17 00:00:00 2001 From: Peter Robinson Date: Fri, 20 May 2022 11:21:22 +1000 Subject: [PATCH] Simplify configuration of blockchains for example code plus add WS URI messaging manager interface (#121) * Refactor messaging manager group code to use a common base class. Add ability to store and get WS APIs * Pass around BlockchainConfig objects rather than individual pieces of configuration as many parameters. Add ability to determine WS URI from MessagingManagerInterface. * Token supply is not needed for minter burner contract --- .../crosscontrol/TwentyActsManager.java | 14 +--- .../crosscontrol/TwentyActsManagerGroup.java | 16 +--- .../twentyacts/Abstract20ActsTest.java | 16 +--- .../twentyacts/helpers/ERC20Manager.java | 13 +-- .../examples/gpact/conditional/Main.java | 7 +- .../examples/gpact/conditional/OtherBc.java | 12 +-- .../examples/gpact/conditional/RootBc.java | 12 +-- ...idge.java => ERC20TokenBridgeExample.java} | 20 +---- .../SourceAndDestinationBlockchain.java | 16 ++-- .../gpact/erc20bridge/Erc20BridgeTest.java | 4 +- .../examples/gpact/hoteltrain/EntityBase.java | 12 +-- .../gpact/hoteltrain/EntityHotel.java | 8 +- .../gpact/hoteltrain/EntityTrain.java | 8 +- .../gpact/hoteltrain/EntityTravelAgency.java | 6 +- .../examples/gpact/hoteltrain/HotelTrain.java | 10 +-- .../examples/gpact/read/Bc1ContractA.java | 12 +-- .../examples/gpact/read/Bc2ContractB.java | 12 +-- .../gpact/examples/gpact/read/Main.java | 8 +- .../examples/gpact/trade/Bc1TradeWallet.java | 11 +-- .../examples/gpact/trade/Bc2BusLogic.java | 11 +-- .../examples/gpact/trade/Bc3Balances.java | 12 +-- .../gpact/examples/gpact/trade/Bc4Oracle.java | 12 +-- .../gpact/examples/gpact/trade/Bc5Stock.java | 12 +-- .../gpact/examples/gpact/trade/Main.java | 18 ++--- .../examples/gpact/write/Bc1ContractA.java | 11 +-- .../examples/gpact/write/Bc2ContractB.java | 12 +-- .../gpact/write/GpactCrosschainWrite.java | 8 +- .../sfc/erc20bridge/AbstractERC20Bridge.java | 16 +--- .../erc20bridge/ERC20TokenBridgeExample.java | 26 +----- .../MassConservationERC20Bridge.java | 17 ++-- .../erc20bridge/MinterBurnerERC20Bridge.java | 12 +-- .../erc721bridge/AbstractERC721Bridge.java | 11 +-- .../Erc721TokenBridgeExample.java | 18 +---- .../sfc/erc721bridge/HomeBcERC721Bridge.java | 12 +-- .../erc721bridge/RemoteBcERC721Bridge.java | 12 +-- .../examples/sfc/write/Bc1ContractA.java | 11 +-- .../examples/sfc/write/Bc2ContractB.java | 12 +-- .../sfc/write/SfcCrosschainWrite.java | 8 +- .../singlebc/hoteltrain/EntityBase.java | 9 +-- .../singlebc/hoteltrain/EntityHotel.java | 9 +-- .../singlebc/hoteltrain/EntityTrain.java | 9 +-- .../hoteltrain/EntityTravelAgency.java | 6 +- .../singlebc/hoteltrain/HotelTrain.java | 10 +-- .../singlebc/read/Bc1ContractA.java | 12 +-- .../singlebc/read/Bc2ContractB.java | 12 +-- .../gpact/performance/singlebc/read/Main.java | 8 +- .../singlebc/trade/Bc1TradeWallet.java | 12 +-- .../performance/singlebc/trade/Main.java | 4 +- .../singlebc/write/Bc1ContractA.java | 12 +-- .../singlebc/write/Bc2ContractB.java | 14 +--- .../performance/singlebc/write/Main.java | 8 +- .../gpact/common/AbstractBlockchain.java | 35 ++++---- .../gpact/GpactCrossControlManager.java | 9 +-- .../gpact/GpactCrossControlManagerGroup.java | 34 +++----- .../sfc/SimpleCrossControlManager.java | 9 +-- .../sfc/SimpleCrossControlManagerGroup.java | 28 ++----- .../messaging/BaseMessagingManagerGroup.java | 79 +++++++++++++++++++ .../messaging/MessagingManagerGroup.java | 11 +++ .../messaging/MessagingManagerInterface.java | 2 + .../messaging/common/RegistrarManager.java | 14 +--- .../attestorrelayer/AttestorRelayer.java | 52 +++++++++++- .../AttestorRelayerWebApi.java | 56 ++++++++++++- .../eventattest/AttestorSignerManager.java | 12 +-- .../AttestorSignerManagerGroup.java | 74 +++-------------- .../messaging/txrootrelay/TxRootRelayer.java | 9 +-- .../txrootrelay/TxRootRelayerGroup.java | 8 +- .../messaging/txrootrelay/TxRootTransfer.java | 13 ++- .../txrootrelay/TxRootTransferGroup.java | 10 +-- .../txrootrelay/TxRootTransferManager.java | 12 +-- .../TxRootTransferManagerGroup.java | 75 +++--------------- .../AttestorRelayerConfigurerTest.java | 2 +- 71 files changed, 428 insertions(+), 709 deletions(-) rename examples/gpact/erc20bridge/java/src/main/java/net/consensys/gpact/examples/gpact/erc20bridge/{TokenBridge.java => ERC20TokenBridgeExample.java} (91%) create mode 100644 sdk/java/src/main/java/net/consensys/gpact/messaging/BaseMessagingManagerGroup.java diff --git a/applications/20acts/javatest/src/main/java/net/consensys/gpact/applications/twentyacts/crosscontrol/TwentyActsManager.java b/applications/20acts/javatest/src/main/java/net/consensys/gpact/applications/twentyacts/crosscontrol/TwentyActsManager.java index 3c55853f..d7a3ff7e 100644 --- a/applications/20acts/javatest/src/main/java/net/consensys/gpact/applications/twentyacts/crosscontrol/TwentyActsManager.java +++ b/applications/20acts/javatest/src/main/java/net/consensys/gpact/applications/twentyacts/crosscontrol/TwentyActsManager.java @@ -60,14 +60,8 @@ public class TwentyActsManager extends AbstractBlockchain implements CrossContro private TwentyActs twentyActs; - public TwentyActsManager( - Credentials credentials, - BlockchainId bcId, - String uri, - DynamicGasProvider.Strategy gasPriceStrategy, - int blockPeriod) - throws IOException { - super(credentials, bcId, uri, gasPriceStrategy, blockPeriod); + public TwentyActsManager(Credentials credentials, BlockchainConfig bcConfig) throws IOException { + super(credentials, bcConfig); } public void deploy20ActsContract(BigInteger withdrawWaitPeriod, String infrastructureAccount) @@ -261,9 +255,7 @@ public Tuple blockchains = new HashMap<>(); + + @Override + public void registerSignerOnAllBlockchains(String signersAddress) throws Exception { + for (BlockchainId bcId1 : this.blockchains.keySet()) { + registerSigner(signersAddress, bcId1); + } + } + + @Override + public void registerSigner(String signersAddress, BlockchainId bcId1) throws Exception { + // Add the signer (their address / public key) to each blockchain + for (BlockchainId bcId2 : this.blockchains.keySet()) { + MessagingManagerInterface manager = this.blockchains.get(bcId2); + manager.registerSigner(bcId1, signersAddress); + } + } + + @Override + public void registerFirstSignerOnAllBlockchains(String signersAddress) throws Exception { + for (BlockchainId bcId1 : this.blockchains.keySet()) { + registerFirstSigner(signersAddress, bcId1); + } + } + + @Override + public void registerFirstSigner(String signersAddress, BlockchainId bcId1) throws Exception { + // Add the signer (their address / public key) to each blockchain + for (BlockchainId bcId2 : this.blockchains.keySet()) { + MessagingManagerInterface manager = this.blockchains.get(bcId2); + manager.registerSigner(bcId1, signersAddress, BigInteger.ONE); + } + } + + @Override + public String getVerifierAddress(final BlockchainId bcId) throws Exception { + if (!this.blockchains.containsKey(bcId)) { + throw new Exception("Blockchain not found: " + bcId); + } + return this.blockchains.get(bcId).getVerifierAddress(); + } + + @Override + public String getWsUri(final BlockchainId bcId) throws Exception { + if (!this.blockchains.containsKey(bcId)) { + throw new Exception("Blockchain not found: " + bcId); + } + return this.blockchains.get(bcId).getWsUri(); + } + + @Override + public Set getSupportedBlockchains() { + return this.blockchains.keySet(); + } +} diff --git a/sdk/java/src/main/java/net/consensys/gpact/messaging/MessagingManagerGroup.java b/sdk/java/src/main/java/net/consensys/gpact/messaging/MessagingManagerGroup.java index 85515140..820c32eb 100644 --- a/sdk/java/src/main/java/net/consensys/gpact/messaging/MessagingManagerGroup.java +++ b/sdk/java/src/main/java/net/consensys/gpact/messaging/MessagingManagerGroup.java @@ -15,6 +15,7 @@ package net.consensys.gpact.messaging; import java.util.ArrayList; +import java.util.Set; import net.consensys.gpact.common.BlockchainConfig; import net.consensys.gpact.common.BlockchainId; import org.web3j.crypto.Credentials; @@ -31,6 +32,12 @@ public interface MessagingManagerGroup { */ void addBlockchainAndDeployContracts(Credentials creds, BlockchainConfig bcInfo) throws Exception; + default void addBlockchainAndDeployContracts( + Credentials creds, BlockchainConfig bcInfo, String additionalContractAddress) + throws Exception { + throw new RuntimeException("Not implemented"); + } + /** * Add a blockchain to be managed by this class. Load contracts that have previously been * deployed. @@ -51,5 +58,9 @@ void addBlockchainAndLoadContracts( void registerFirstSigner(String signersAddress, BlockchainId bcId1) throws Exception; + String getWsUri(final BlockchainId bcId) throws Exception; + String getVerifierAddress(final BlockchainId bcId) throws Exception; + + Set getSupportedBlockchains(); } diff --git a/sdk/java/src/main/java/net/consensys/gpact/messaging/MessagingManagerInterface.java b/sdk/java/src/main/java/net/consensys/gpact/messaging/MessagingManagerInterface.java index 5e52688f..87d4ecb9 100644 --- a/sdk/java/src/main/java/net/consensys/gpact/messaging/MessagingManagerInterface.java +++ b/sdk/java/src/main/java/net/consensys/gpact/messaging/MessagingManagerInterface.java @@ -50,4 +50,6 @@ void registerSigners(BlockchainId bcId, List signers, BigInteger newThre void removeSigner(BlockchainId bcId, String signer) throws Exception; void removeSigner(BlockchainId bcId, String signer, BigInteger newThreshold) throws Exception; + + String getWsUri() throws Exception; } diff --git a/sdk/java/src/main/java/net/consensys/gpact/messaging/common/RegistrarManager.java b/sdk/java/src/main/java/net/consensys/gpact/messaging/common/RegistrarManager.java index 77c351f9..962fd58f 100644 --- a/sdk/java/src/main/java/net/consensys/gpact/messaging/common/RegistrarManager.java +++ b/sdk/java/src/main/java/net/consensys/gpact/messaging/common/RegistrarManager.java @@ -18,10 +18,7 @@ import java.math.BigInteger; import java.util.ArrayList; import java.util.List; -import net.consensys.gpact.common.AbstractBlockchain; -import net.consensys.gpact.common.BlockchainId; -import net.consensys.gpact.common.DynamicGasProvider; -import net.consensys.gpact.common.RevertReason; +import net.consensys.gpact.common.*; import net.consensys.gpact.messaging.MessagingManagerInterface; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -36,14 +33,9 @@ public abstract class RegistrarManager extends AbstractBlockchain protected MessagingRegistrar registrarContract; - public RegistrarManager( - Credentials credentials, - BlockchainId bcId, - String uri, - DynamicGasProvider.Strategy gasPriceStrategy, - int blockPeriod) + public RegistrarManager(final Credentials credentials, final BlockchainConfig bcConfig) throws IOException { - super(credentials, bcId, uri, gasPriceStrategy, blockPeriod); + super(credentials, bcConfig); } @Override diff --git a/sdk/java/src/main/java/net/consensys/gpact/messaging/common/attestorrelayer/AttestorRelayer.java b/sdk/java/src/main/java/net/consensys/gpact/messaging/common/attestorrelayer/AttestorRelayer.java index b0ae31dc..6029d1c5 100644 --- a/sdk/java/src/main/java/net/consensys/gpact/messaging/common/attestorrelayer/AttestorRelayer.java +++ b/sdk/java/src/main/java/net/consensys/gpact/messaging/common/attestorrelayer/AttestorRelayer.java @@ -61,6 +61,31 @@ public String getCrosschainControlAddr() { } } + public static class Dest { + BlockchainId sourceBcId; + BlockchainId targetBcId; + String targetBcWsUri; + byte[] txPKey; + String targetChainVerifierAddr; + + public Dest( + BlockchainId sourceBcId, + BlockchainId targetBcId, + String targetBcWsUri, + byte[] txPKey, + String targetChainVerifierAddr) { + this.sourceBcId = sourceBcId; + this.targetBcId = targetBcId; + this.targetBcWsUri = targetBcWsUri; + this.txPKey = txPKey; + this.targetChainVerifierAddr = targetChainVerifierAddr; + } + + public String getDestId() { + return this.sourceBcId.toString() + this.targetBcId.toString(); + } + } + Map sources = new HashMap<>(); public AttestorRelayer(String relayerUri, byte[] signingKey) { @@ -100,10 +125,35 @@ public void addNewSource(Source source) throws CrosschainProtocolStackException public void addMessageStore( String msgDispatcherUrl, String msgStoreAddrFromDispatcher, String msgStoreAddrFromUser) throws CrosschainProtocolStackException { - AttestorRelayerWebApi.setupDispatcher(msgDispatcherUrl, msgStoreAddrFromDispatcher); + AttestorRelayerWebApi.setupDispatcherForMsgStore(msgDispatcherUrl, msgStoreAddrFromDispatcher); this.msgStoreAddr = msgStoreAddrFromUser; } + public void setDispatcher( + String msgDispatcherUrl, + BlockchainId sourceChainBcId, + BlockchainId targetChainBcId, + String targetChainWsUrl, + byte[] txPKey, + String targetChainVerifierAddr) + throws CrosschainProtocolStackException { + Dest dest = + new Dest( + sourceChainBcId, targetChainBcId, targetChainWsUrl, txPKey, targetChainVerifierAddr); + setDispatcher(msgDispatcherUrl, dest); + } + + public void setDispatcher(String msgDispatcherUrl, Dest dest) + throws CrosschainProtocolStackException { + AttestorRelayerWebApi.setupDispatcherForRelayingEvents( + msgDispatcherUrl, + dest.sourceBcId, + dest.targetBcId, + dest.targetBcWsUri, + dest.txPKey, + dest.targetChainVerifierAddr); + } + public void addMessageStoreRoute(String relayerUri, String sourceNetwork, String sourceAddress) throws CrosschainProtocolStackException { AttestorRelayerWebApi.addMessageStoreRoute(relayerUri, sourceNetwork, sourceAddress); diff --git a/sdk/java/src/main/java/net/consensys/gpact/messaging/common/attestorrelayer/AttestorRelayerWebApi.java b/sdk/java/src/main/java/net/consensys/gpact/messaging/common/attestorrelayer/AttestorRelayerWebApi.java index fda23b67..97917625 100644 --- a/sdk/java/src/main/java/net/consensys/gpact/messaging/common/attestorrelayer/AttestorRelayerWebApi.java +++ b/sdk/java/src/main/java/net/consensys/gpact/messaging/common/attestorrelayer/AttestorRelayerWebApi.java @@ -159,7 +159,7 @@ public static void setupRelayer( config("Relayer", relayerUrl, requestBody); } - public static void setupDispatcher(String msgDispatcherUrl, String msgStoreAddr) + public static void setupDispatcherForMsgStore(String msgDispatcherUrl, String msgStoreAddr) throws CrosschainProtocolStackException { LOG.info("SetupDispatcher: MsgStore: {}, DispatcherURL: {}", msgStoreAddr, msgDispatcherUrl); @@ -182,6 +182,60 @@ public static void setupDispatcher(String msgDispatcherUrl, String msgStoreAddr) config("Dispatcher", msgDispatcherUrl, requestBody); } + public static void setupDispatcherForRelayingEvents( + String msgDispatcherUrl, + BlockchainId sourceChainBcId, + BlockchainId targetChainBcId, + String targetChainWsUrl, + byte[] txPKey, + String targetChainVerifierAddr) + throws CrosschainProtocolStackException { + LOG.info( + "SetupDispatcher: DispatcherURL: {}, Source Chain Id: {}, Target Chain Id: {}, Target Chain Ws: {}, Target Verifier: {}", + msgDispatcherUrl, + sourceChainBcId.toDecimalString(), + targetChainBcId.toDecimalString(), + targetChainWsUrl, + targetChainVerifierAddr); + + ObjectMapper mapper1 = new ObjectMapper(); + ObjectNode setEthTxKey = mapper1.createObjectNode(); + setEthTxKey.put("chain_id", targetChainBcId.toDecimalString()); + setEthTxKey.put("chain_ap", targetChainWsUrl); + setEthTxKey.put("key", txPKey); + byte[] json; + try { + json = mapper1.writer().writeValueAsBytes(setEthTxKey); + } catch (JsonProcessingException ex) { + throw new CrosschainProtocolStackException("Dispatcher", ex); + } + + Bytes type = Bytes.of(SET_TRANSACTION_OPT_REQ_TYPE); + Bytes body = Bytes.wrap(json); + Bytes all = Bytes.concatenate(type, body); + byte[] requestBody = all.toArray(); + + config("Dispatcher", msgDispatcherUrl, requestBody); + + ObjectMapper mapper2 = new ObjectMapper(); + ObjectNode setVerifier = mapper2.createObjectNode(); + setVerifier.put("source_chain_id", sourceChainBcId.toDecimalString()); + setVerifier.put("target_chain_id", targetChainBcId.toDecimalString()); + setVerifier.put("verifier_addr", targetChainVerifierAddr); + try { + json = mapper1.writer().writeValueAsBytes(setVerifier); + } catch (JsonProcessingException ex) { + throw new CrosschainProtocolStackException("Dispatcher", ex); + } + + type = Bytes.of(SET_VERIFIER_ADDR_REQ_TYPE); + body = Bytes.wrap(json); + all = Bytes.concatenate(type, body); + requestBody = all.toArray(); + + config("Dispatcher", msgDispatcherUrl, requestBody); + } + private static void config(String component, String uri, byte[] requestBody) throws CrosschainProtocolStackException { HttpResponse response; diff --git a/sdk/java/src/main/java/net/consensys/gpact/messaging/eventattest/AttestorSignerManager.java b/sdk/java/src/main/java/net/consensys/gpact/messaging/eventattest/AttestorSignerManager.java index 835b5303..8d61699c 100644 --- a/sdk/java/src/main/java/net/consensys/gpact/messaging/eventattest/AttestorSignerManager.java +++ b/sdk/java/src/main/java/net/consensys/gpact/messaging/eventattest/AttestorSignerManager.java @@ -16,8 +16,7 @@ import java.io.IOException; import java.util.ArrayList; -import net.consensys.gpact.common.BlockchainId; -import net.consensys.gpact.common.DynamicGasProvider; +import net.consensys.gpact.common.BlockchainConfig; import net.consensys.gpact.messaging.common.RegistrarManager; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -29,14 +28,9 @@ public class AttestorSignerManager extends RegistrarManager { private EventAttestationVerifier verifier; - public AttestorSignerManager( - Credentials credentials, - BlockchainId bcId, - String uri, - DynamicGasProvider.Strategy gasPriceStrategy, - int blockPeriod) + public AttestorSignerManager(final Credentials credentials, final BlockchainConfig bcConfig) throws IOException { - super(credentials, bcId, uri, gasPriceStrategy, blockPeriod); + super(credentials, bcConfig); } @Override diff --git a/sdk/java/src/main/java/net/consensys/gpact/messaging/eventattest/AttestorSignerManagerGroup.java b/sdk/java/src/main/java/net/consensys/gpact/messaging/eventattest/AttestorSignerManagerGroup.java index d7ce7bdf..2ebe4976 100644 --- a/sdk/java/src/main/java/net/consensys/gpact/messaging/eventattest/AttestorSignerManagerGroup.java +++ b/sdk/java/src/main/java/net/consensys/gpact/messaging/eventattest/AttestorSignerManagerGroup.java @@ -14,38 +14,29 @@ */ package net.consensys.gpact.messaging.eventattest; -import java.math.BigInteger; import java.util.*; import net.consensys.gpact.common.BlockchainConfig; import net.consensys.gpact.common.BlockchainId; -import net.consensys.gpact.messaging.MessagingManagerGroup; +import net.consensys.gpact.messaging.BaseMessagingManagerGroup; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.web3j.crypto.Credentials; /** Manage multiple blockchains, each holding a set of registrar and verification contracts */ -public class AttestorSignerManagerGroup implements MessagingManagerGroup { +public class AttestorSignerManagerGroup extends BaseMessagingManagerGroup { static final Logger LOG = LogManager.getLogger(AttestorSignerManagerGroup.class); - Map blockchains = new HashMap<>(); - @Override - public void addBlockchainAndDeployContracts(Credentials creds, BlockchainConfig bcInfo) - throws Exception { - BlockchainId blockchainId = bcInfo.bcId; + public void addBlockchainAndDeployContracts( + final Credentials creds, final BlockchainConfig bcConfig) throws Exception { + BlockchainId blockchainId = bcConfig.bcId; if (this.blockchains.containsKey(blockchainId)) { return; // throw new Exception("Blockchain already added: " + blockchainId); } LOG.debug("Deploying Cross-Blockchain Control contracts for blockchain id {}", blockchainId); - AttestorSignerManager manager = - new AttestorSignerManager( - creds, - blockchainId, - bcInfo.blockchainNodeRpcUri, - bcInfo.gasPriceStrategy, - bcInfo.period); + AttestorSignerManager manager = new AttestorSignerManager(creds, bcConfig); manager.deployContracts(); this.blockchains.put(blockchainId, manager); @@ -53,61 +44,16 @@ public void addBlockchainAndDeployContracts(Credentials creds, BlockchainConfig @Override public void addBlockchainAndLoadContracts( - Credentials creds, BlockchainConfig bcInfo, ArrayList addresses) throws Exception { - BlockchainId blockchainId = bcInfo.bcId; + final Credentials creds, final BlockchainConfig bcConfig, final ArrayList addresses) + throws Exception { + BlockchainId blockchainId = bcConfig.bcId; if (this.blockchains.containsKey(blockchainId)) { throw new Exception("Blockchain already added: " + blockchainId); } - AttestorSignerManager manager = - new AttestorSignerManager( - creds, - blockchainId, - bcInfo.blockchainNodeRpcUri, - bcInfo.gasPriceStrategy, - bcInfo.period); + AttestorSignerManager manager = new AttestorSignerManager(creds, bcConfig); manager.loadContracts(addresses); this.blockchains.put(blockchainId, manager); } - - @Override - public void registerSignerOnAllBlockchains(String signersAddress) throws Exception { - for (BlockchainId bcId1 : this.blockchains.keySet()) { - registerSigner(signersAddress, bcId1); - } - } - - @Override - public void registerSigner(String signersAddress, BlockchainId bcId1) throws Exception { - // Add the signer (their address / public key) to each blockchain - for (BlockchainId bcId2 : this.blockchains.keySet()) { - AttestorSignerManager manager = this.blockchains.get(bcId2); - manager.registerSigner(bcId1, signersAddress); - } - } - - @Override - public void registerFirstSignerOnAllBlockchains(String signersAddress) throws Exception { - for (BlockchainId bcId1 : this.blockchains.keySet()) { - registerFirstSigner(signersAddress, bcId1); - } - } - - @Override - public void registerFirstSigner(String signersAddress, BlockchainId bcId1) throws Exception { - // Add the signer (their address / public key) to each blockchain - for (BlockchainId bcId2 : this.blockchains.keySet()) { - AttestorSignerManager manager = this.blockchains.get(bcId2); - manager.registerSigner(bcId1, signersAddress, BigInteger.ONE); - } - } - - @Override - public String getVerifierAddress(final BlockchainId bcId) throws Exception { - if (!this.blockchains.containsKey(bcId)) { - throw new Exception("Blockchain not found: " + bcId); - } - return this.blockchains.get(bcId).getVerifierAddress(); - } } diff --git a/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootRelayer.java b/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootRelayer.java index 85ad1139..3ebb31cf 100644 --- a/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootRelayer.java +++ b/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootRelayer.java @@ -33,14 +33,9 @@ public class TxRootRelayer extends AbstractBlockchain { List signers = new ArrayList<>(); - public TxRootRelayer( - Credentials credentials, - BlockchainId bcId, - String uri, - DynamicGasProvider.Strategy gasPriceStrategy, - int blockPeriod) + public TxRootRelayer(final Credentials credentials, final BlockchainConfig bcConfig) throws IOException { - super(credentials, bcId, uri, gasPriceStrategy, blockPeriod); + super(credentials, bcConfig); } public void loadContract(String address) { diff --git a/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootRelayerGroup.java b/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootRelayerGroup.java index 034fd994..ec881592 100644 --- a/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootRelayerGroup.java +++ b/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootRelayerGroup.java @@ -41,13 +41,7 @@ public void loadContractForBlockchain( // throw new Exception("Blockchain already added: " + blockchainId); } - TxRootRelayer manager = - new TxRootRelayer( - creds, - blockchainId, - bcInfo.blockchainNodeRpcUri, - bcInfo.gasPriceStrategy, - bcInfo.period); + TxRootRelayer manager = new TxRootRelayer(creds, bcInfo); manager.loadContract(txRootContract); this.blockchains.put(blockchainId, manager); diff --git a/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootTransfer.java b/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootTransfer.java index 1c231607..5ee76b0c 100644 --- a/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootTransfer.java +++ b/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootTransfer.java @@ -18,8 +18,8 @@ import java.math.BigInteger; import java.util.*; import net.consensys.gpact.common.AbstractBlockchain; +import net.consensys.gpact.common.BlockchainConfig; import net.consensys.gpact.common.BlockchainId; -import net.consensys.gpact.common.DynamicGasProvider; import net.consensys.gpact.messaging.MessagingVerificationInterface; import net.consensys.gpact.messaging.SignedEvent; import net.consensys.gpact.messaging.txrootrelay.besuethereum.core.Hash; @@ -51,14 +51,11 @@ public class TxRootTransfer extends AbstractBlockchain implements MessagingVerif TxRootRelayerGroup relayerGroup; public TxRootTransfer( - TxRootRelayerGroup relayerGroup, - Credentials credentials, - BlockchainId bcId, - String uri, - DynamicGasProvider.Strategy gasPriceStrategy, - int blockPeriod) + final TxRootRelayerGroup relayerGroup, + final Credentials credentials, + final BlockchainConfig bcConfig) throws IOException { - super(credentials, bcId, uri, gasPriceStrategy, blockPeriod); + super(credentials, bcConfig); this.relayerGroup = relayerGroup; } diff --git a/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootTransferGroup.java b/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootTransferGroup.java index c05b2687..33bef489 100644 --- a/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootTransferGroup.java +++ b/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootTransferGroup.java @@ -36,15 +36,7 @@ public void addBlockchain( // throw new Exception("Blockchain already in TxRoot Transfer Group: " + bcInfo.bcId); } - this.blockchains.put( - bcInfo.bcId, - new TxRootTransfer( - relayerGroup, - creds, - bcInfo.bcId, - bcInfo.blockchainNodeRpcUri, - bcInfo.gasPriceStrategy, - bcInfo.period)); + this.blockchains.put(bcInfo.bcId, new TxRootTransfer(relayerGroup, creds, bcInfo)); } public MessagingVerificationInterface getVerifier(BlockchainId bcId) throws Exception { diff --git a/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootTransferManager.java b/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootTransferManager.java index eab77343..791d8a15 100644 --- a/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootTransferManager.java +++ b/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootTransferManager.java @@ -16,8 +16,7 @@ import java.io.IOException; import java.util.ArrayList; -import net.consensys.gpact.common.BlockchainId; -import net.consensys.gpact.common.DynamicGasProvider; +import net.consensys.gpact.common.BlockchainConfig; import net.consensys.gpact.messaging.common.RegistrarManager; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -30,14 +29,9 @@ public class TxRootTransferManager extends RegistrarManager { private TxRootRelayVerifier verifier; private TxReceiptsRootStorage txReceiptsRootStorage; - public TxRootTransferManager( - Credentials credentials, - BlockchainId bcId, - String uri, - DynamicGasProvider.Strategy gasPriceStrategy, - int blockPeriod) + public TxRootTransferManager(final Credentials credentials, final BlockchainConfig bcConfig) throws IOException { - super(credentials, bcId, uri, gasPriceStrategy, blockPeriod); + super(credentials, bcConfig); } @Override diff --git a/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootTransferManagerGroup.java b/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootTransferManagerGroup.java index 8b39784f..59e8d2b9 100644 --- a/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootTransferManagerGroup.java +++ b/sdk/java/src/main/java/net/consensys/gpact/messaging/txrootrelay/TxRootTransferManagerGroup.java @@ -14,38 +14,29 @@ */ package net.consensys.gpact.messaging.txrootrelay; -import java.math.BigInteger; import java.util.*; import net.consensys.gpact.common.BlockchainConfig; import net.consensys.gpact.common.BlockchainId; -import net.consensys.gpact.messaging.MessagingManagerGroup; +import net.consensys.gpact.messaging.BaseMessagingManagerGroup; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.web3j.crypto.Credentials; /** Manage multiple blockchains, each holding a set of registrar and verification contracts */ -public class TxRootTransferManagerGroup implements MessagingManagerGroup { +public class TxRootTransferManagerGroup extends BaseMessagingManagerGroup { static final Logger LOG = LogManager.getLogger(TxRootTransferManagerGroup.class); - Map blockchains = new HashMap<>(); - @Override - public void addBlockchainAndDeployContracts(Credentials creds, BlockchainConfig bcInfo) - throws Exception { - BlockchainId blockchainId = bcInfo.bcId; + public void addBlockchainAndDeployContracts( + final Credentials creds, final BlockchainConfig bcConfig) throws Exception { + BlockchainId blockchainId = bcConfig.bcId; if (this.blockchains.containsKey(blockchainId)) { return; // throw new Exception("Blockchain already added: " + blockchainId); } LOG.debug("Deploying Cross-Blockchain Control contracts for blockchain id {}", blockchainId); - TxRootTransferManager manager = - new TxRootTransferManager( - creds, - blockchainId, - bcInfo.blockchainNodeRpcUri, - bcInfo.gasPriceStrategy, - bcInfo.period); + TxRootTransferManager manager = new TxRootTransferManager(creds, bcConfig); manager.deployContracts(); this.blockchains.put(blockchainId, manager); @@ -53,69 +44,23 @@ public void addBlockchainAndDeployContracts(Credentials creds, BlockchainConfig @Override public void addBlockchainAndLoadContracts( - Credentials creds, BlockchainConfig bcInfo, ArrayList addresses) throws Exception { - BlockchainId blockchainId = bcInfo.bcId; + Credentials creds, BlockchainConfig bcConfig, ArrayList addresses) throws Exception { + BlockchainId blockchainId = bcConfig.bcId; if (this.blockchains.containsKey(blockchainId)) { return; // throw new Exception("Blockchain already added: " + blockchainId); } - TxRootTransferManager manager = - new TxRootTransferManager( - creds, - blockchainId, - bcInfo.blockchainNodeRpcUri, - bcInfo.gasPriceStrategy, - bcInfo.period); + TxRootTransferManager manager = new TxRootTransferManager(creds, bcConfig); manager.loadContracts(addresses); this.blockchains.put(blockchainId, manager); } - @Override - public void registerSignerOnAllBlockchains(String signersAddress) throws Exception { - for (BlockchainId bcId1 : this.blockchains.keySet()) { - registerSigner(signersAddress, bcId1); - } - } - - @Override - public void registerSigner(String signersAddress, BlockchainId bcId1) throws Exception { - // Add the signer (their address / public key) to each blockchain - for (BlockchainId bcId2 : this.blockchains.keySet()) { - TxRootTransferManager manager = this.blockchains.get(bcId2); - manager.registerSigner(bcId1, signersAddress); - } - } - - @Override - public void registerFirstSignerOnAllBlockchains(String signersAddress) throws Exception { - for (BlockchainId bcId1 : this.blockchains.keySet()) { - registerFirstSigner(signersAddress, bcId1); - } - } - - @Override - public void registerFirstSigner(String signersAddress, BlockchainId bcId1) throws Exception { - // Add the signer (their address / public key) to each blockchain - for (BlockchainId bcId2 : this.blockchains.keySet()) { - TxRootTransferManager manager = this.blockchains.get(bcId2); - manager.registerSigner(bcId1, signersAddress, BigInteger.ONE); - } - } - - @Override - public String getVerifierAddress(final BlockchainId bcId) throws Exception { - if (!this.blockchains.containsKey(bcId)) { - throw new Exception("Blockchain not found: " + bcId); - } - return this.blockchains.get(bcId).getVerifierAddress(); - } - public String getTxRootContractAddress(BlockchainId bcId) throws Exception { if (!this.blockchains.containsKey(bcId)) { throw new Exception("Unknown blockchain: " + bcId); } - return this.blockchains.get(bcId).getTxRootContractAddress(); + return ((TxRootTransferManager) this.blockchains.get(bcId)).getTxRootContractAddress(); } } diff --git a/sdk/java/src/test/java/net/consensys/gpact/messaging/common/attestorrelayer/AttestorRelayerConfigurerTest.java b/sdk/java/src/test/java/net/consensys/gpact/messaging/common/attestorrelayer/AttestorRelayerConfigurerTest.java index c4cf796d..6fcf92d1 100644 --- a/sdk/java/src/test/java/net/consensys/gpact/messaging/common/attestorrelayer/AttestorRelayerConfigurerTest.java +++ b/sdk/java/src/test/java/net/consensys/gpact/messaging/common/attestorrelayer/AttestorRelayerConfigurerTest.java @@ -26,6 +26,6 @@ public void testSetupRelayer() throws Exception { @Test public void testSetupDispatcher() throws Exception { - AttestorRelayerWebApi.setupDispatcher("http://127.0.0.1:9725", "msgstore:8080"); + AttestorRelayerWebApi.setupDispatcherForMsgStore("http://127.0.0.1:9725", "msgstore:8080"); } }