@Override protected void initWeb3Client(HttpService httpService) { web3j = Quorum.build(httpService); }
@Override public EthSendTransaction sendTransaction( BigInteger gasPrice, BigInteger gasLimit, String to, String data, BigInteger value) throws IOException { PrivateTransaction transaction = new PrivateTransaction( fromAddress, null, gasLimit, to, value, data, privateFrom, privateFor); return quorum.ethSendTransaction(transaction).send(); } }
@InvokeOnHeader(Web3jConstants.QUORUM_GET_PRIVATE_PAYLOAD) void quorumGetPrivatePayload(Message message) throws IOException { if (quorum == null) { setQuorumEndpointError(message); return; } Request<?, PrivatePayload> request = quorum.quorumGetPrivatePayload(message.getBody(String.class)); setRequestId(message, request); PrivatePayload response = request.send(); boolean hasError = checkForError(message, response); if (!hasError) { message.setBody(response.getPrivatePayload()); } }
@InvokeOnHeader(Web3jConstants.QUORUM_IS_BLOCK_MAKER) void quorumIsBlockMaker(Message message) throws IOException { if (quorum == null) { setQuorumEndpointError(message); return; } String address = message.getHeader(Web3jConstants.ADDRESS, configuration::getAddress, String.class); Request<?, BlockMaker> request = quorum.quorumIsBlockMaker(address); setRequestId(message, request); BlockMaker response = request.send(); boolean hasError = checkForError(message, response); if (!hasError) { message.setBody(response.isBlockMaker()); } }
@InvokeOnHeader(Web3jConstants.QUORUM_IS_VOTER) void quorumIsVoter(Message message) throws IOException { if (quorum == null) { setQuorumEndpointError(message); return; } String address = message.getHeader(Web3jConstants.ADDRESS, configuration::getAddress, String.class); Request<?, Voter> request = quorum.quorumIsVoter(address); setRequestId(message, request); Voter response = request.send(); boolean hasError = checkForError(message, response); if (!hasError) { message.setBody(response.isVoter()); } }
@InvokeOnHeader(Web3jConstants.QUORUM_CANONICAL_HASH) void quorumCanonicalHash(Message message) throws IOException { if (quorum == null) { setQuorumEndpointError(message); return; } Request<?, CanonicalHash> request = quorum.quorumCanonicalHash(message.getBody(BigInteger.class)); setRequestId(message, request); CanonicalHash response = request.send(); boolean hasError = checkForError(message, response); if (!hasError) { message.setBody(response.getCanonicalHash()); } }
@InvokeOnHeader(Web3jConstants.QUORUM_PAUSE_BLOCK_MAKER) void quorumPauseBlockMaker(Message message) throws IOException { if (quorum == null) { setQuorumEndpointError(message); return; } Request<?, VoidResponse> request = quorum.quorumPauseBlockMaker(); setRequestId(message, request); VoidResponse response = request.send(); boolean hasError = checkForError(message, response); if (!hasError) { message.setBody(response.isValid()); } }
@InvokeOnHeader(Web3jConstants.QUORUM_NODE_INFO) void quorumNodeInfo(Message message) throws IOException { if (quorum == null) { setQuorumEndpointError(message); return; } Request<?, QuorumNodeInfo> request = quorum.quorumNodeInfo(); setRequestId(message, request); QuorumNodeInfo response = request.send(); boolean hasError = checkForError(message, response); if (!hasError) { message.setBody(response.getNodeInfo()); } }
@InvokeOnHeader(Web3jConstants.QUORUM_MAKE_BLOCK) void quorumMakeBlock(Message message) throws IOException { if (quorum == null) { setQuorumEndpointError(message); return; } Request<?, MakeBlock> request = quorum.quorumMakeBlock(); setRequestId(message, request); MakeBlock response = request.send(); boolean hasError = checkForError(message, response); if (!hasError) { message.setBody(response.getBlockHash()); } }
@Test public void testGetPrivateTransaction() throws Exception { web3j.quorumGetPrivatePayload("0x").send(); verifyResult("{\"jsonrpc\":\"2.0\",\"method\":\"eth_getQuorumPayload\",\"params\":[\"0x\"],\"id\":1}"); } }
@Bean Quorum quorum() { String nodeEndpoint = nodeConfiguration.getNodeEndpoint(); Web3jService web3jService; if (nodeEndpoint == null || nodeEndpoint.equals("")) { web3jService = new HttpService(); } else if (nodeEndpoint.startsWith("http")) { web3jService = new HttpService(nodeEndpoint); } else if (System.getProperty("os.name").toLowerCase().startsWith("win")) { web3jService = new WindowsIpcService(nodeEndpoint); } else { web3jService = new UnixIpcService(nodeEndpoint); } return Quorum.build(web3jService); }
@InvokeOnHeader(Web3jConstants.QUORUM_ETH_SEND_TRANSACTION) void quorumEthSendTransaction(Message message) throws IOException { if (quorum == null) { setQuorumEndpointError(message); return; } //the same as a regular transaction, but there is no gasPrice, instead there is optional privateFor String fromAddress = message.getHeader(Web3jConstants.FROM_ADDRESS, configuration::getFromAddress, String.class); String toAddress = message.getHeader(Web3jConstants.TO_ADDRESS, configuration::getToAddress, String.class); BigInteger nonce = message.getHeader(Web3jConstants.NONCE, configuration::getNonce, BigInteger.class); BigInteger gasLimit = message.getHeader(Web3jConstants.GAS_LIMIT, configuration::getGasLimit, BigInteger.class); BigInteger value = message.getHeader(Web3jConstants.VALUE, configuration::getValue, BigInteger.class); String data = message.getHeader(Web3jConstants.DATA, configuration::getData, String.class); List<String> privateFor = message.getHeader(Web3jConstants.PRIVATE_FOR, configuration::getPrivateFor, List.class); PrivateTransaction transaction = new PrivateTransaction(fromAddress, nonce, gasLimit, toAddress, value, data, privateFor); Request<?, EthSendTransaction> request = quorum.ethSendTransaction(transaction); setRequestId(message, request); EthSendTransaction response = request.send(); boolean hasError = checkForError(message, response); if (!hasError) { message.setBody(response.getTransactionHash()); } }
private Web3j buildService(String clientAddress, Web3jConfiguration configuration) { LOG.info("Building service for endpoint: {}", clientAddress + configuration); if (configuration.getWeb3j() != null) { return configuration.getWeb3j(); } Web3jService web3jService; if (clientAddress == null || clientAddress.equals("")) { web3jService = new HttpService(); } else if (clientAddress.startsWith("http")) { web3jService = new HttpService(clientAddress); } else if (System.getProperty("os.name").toLowerCase().startsWith("win")) { web3jService = new WindowsIpcService(clientAddress); } else { web3jService = new UnixIpcService(clientAddress); } if (configuration.isQuorumAPI()) { return Quorum.build(web3jService); } return Web3j.build(web3jService); }
@Test public void testSendTransaction() throws Exception { web3j.ethSendTransaction( new PrivateTransaction( "FROM", BigInteger.ONE, BigInteger.TEN, "TO", BigInteger.TEN, "DATA", "privateFrom", Arrays.asList("privateFor1", "privateFor2") ) ).send(); verifyResult("{\"jsonrpc\":\"2.0\",\"method\":\"eth_sendTransaction\",\"params\":[{\"from\":\"FROM\",\"to\":\"TO\",\"gas\":\"0xa\",\"value\":\"0xa\",\"data\":\"0xDATA\",\"nonce\":\"0x1\",\"privateFrom\":\"privateFrom\",\"privateFor\":[\"privateFor1\",\"privateFor2\"]}],\"id\":1}"); }
private void runPrivateGreeterTest( Node sourceNode, Node destNode, String requestId) throws Exception { Quorum quorum = Quorum.build(new HttpService(sourceNode.getUrl())); ClientTransactionManager transactionManager = new ClientTransactionManager( quorum, sourceNode.getAddress(), sourceNode.getPublicKeys().get(0), destNode.getPublicKeys()); String greeting = "Hello Quorum world! [" + requestId + "]"; Greeter contract = Greeter.deploy( quorum, transactionManager, GAS_PRICE, GAS_LIMIT, greeting).send(); assertThat(contract.greet().send(), is(greeting)); }