Skip to content

Instantly share code, notes, and snippets.

@Freyert
Last active July 3, 2018 15:09
Show Gist options
  • Save Freyert/2ab154d65b04841c5f55925901c59fe3 to your computer and use it in GitHub Desktop.
Save Freyert/2ab154d65b04841c5f55925901c59fe3 to your computer and use it in GitHub Desktop.
web3j quorum public tx
package kaleido.quorum;
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.RemoteCall;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.protocol.exceptions.ClientConnectionException;
import org.web3j.protocol.http.HttpService;
import org.web3j.quorum.Quorum;
import org.web3j.quorum.tx.ClientTransactionManager;
import okhttp3.Authenticator;
import okhttp3.Credentials;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.Route;
public final class App {
private static final String USER = "xxxxxx";
private static final String PASS = "xxxxxxx";
private static final String RPC_ENDPOINT = "xxxxxxxx";
private static final String FROM_ADDRESS = "xxxxxxxxx";
public static void main(String[] args) throws Exception {
try {
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
clientBuilder.authenticator(new Authenticator() {
@Override public Request authenticate(Route route, Response response) throws IOException {
String credential = Credentials.basic(USER, PASS);
return response.request().newBuilder().header("Authorization", credential).build();
}
});
HttpService service = new HttpService(RPC_ENDPOINT, clientBuilder.build(), false);
Quorum quorum = Quorum.build(service);
String clientVersion = quorum.web3ClientVersion().send().getWeb3ClientVersion();
System.out.println(clientVersion);
org.web3j.tx.ClientTransactionManager transactionManager = new org.web3j.tx.ClientTransactionManager(quorum, FROM_ADDRESS);
Ownership owner = Ownership.deploy(quorum, transactionManager, BigInteger.ZERO, BigInteger.valueOf(9000000)).send();
TransactionReceipt txRcpt = owner.claim("socks").send();
System.out.println("TX HASH " +txRcpt.getTransactionHash().toString() + ", BLOCK NUMBER " + txRcpt.getBlockNumber().toString());
} catch (IOException | ClientConnectionException ex) {
Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
package kaleido.quorum;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collections;
import org.web3j.abi.TypeReference;
import org.web3j.abi.datatypes.Address;
import org.web3j.abi.datatypes.Function;
import org.web3j.abi.datatypes.Type;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.RemoteCall;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.tx.Contract;
import org.web3j.tx.TransactionManager;
/**
* <p>Auto generated code.
* <p><strong>Do not modify!</strong>
* <p>Please use the <a href="https://docs.web3j.io/command_line.html">web3j command line tools</a>,
* or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the
* <a href="https://github.com/web3j/web3j/tree/master/codegen">codegen module</a> to update.
*
* <p>Generated with web3j version 3.4.0.
*/
public class Ownership extends Contract {
private static final String BINARY = "608060405234801561001057600080fd5b5061054a806100206000396000f3006080604052600436106100565763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416634aaf4a12811461005b57806396b24043146100d0578063f3fe12c91461012b575b600080fd5b34801561006757600080fd5b506040805160206004803580820135601f81018490048402850184019095528484526100b49436949293602493928401919081908401838280828437509497506101989650505050505050565b60408051600160a060020a039092168252519081900360200190f35b3480156100dc57600080fd5b506040805160206004803580820135601f81018490048402850184019095528484526101299436949293602493928401919081908401838280828437509497506102089650505050505050565b005b34801561013757600080fd5b506040805160206004803580820135601f81018490048402850184019095528484526101849436949293602493928401919081908401838280828437509497506103169650505050505050565b604080519115158252519081900360200190f35b600080826040518082805190602001908083835b602083106101cb5780518252601f1990920191602091820191016101ac565b51815160209384036101000a6000190180199092169116179052920194855250604051938490030190922054600160a060020a0316949350505050565b33600160a060020a03166000826040518082805190602001908083835b602083106102445780518252601f199092019160209182019101610225565b51815160209384036101000a6000190180199092169116179052920194855250604051938490030190922054600160a060020a031692909214159150610313905057600080826040518082805190602001908083835b602083106102b95780518252601f19909201916020918201910161029a565b51815160209384036101000a60001901801990921691161790529201948552506040519384900301909220805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03949094169390931790925550505b50565b600080826040518082805190602001908083835b602083106103495780518252601f19909201916020918201910161032a565b51815160209384036101000a6000190180199092169116179052920194855250604051938490030190922054600160a060020a03161515915061041e905057336000836040518082805190602001908083835b602083106103bb5780518252601f19909201916020918201910161039c565b51815160209384036101000a60001901801990921691161790529201948552506040519384900301909220805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03949094169390931790925550600191506105199050565b6000826040518082805190602001908083835b602083106104505780518252601f199092019160209182019101610431565b51815160209384036101000a60001901801990921691161790529201948552506040519384900381018420548651600160a060020a039091169460009450879350918291908401908083835b602083106104bb5780518252601f19909201916020918201910161049c565b51815160209384036101000a60001901801990921691161790529201948552506040519384900301909220805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0394909416939093179092555060009150505b9190505600a165627a7a723058205f2b69ee6846e0582d98d727722a8e7107017c75f21c93d733d92b3e8dc523ea0029";
public static final String FUNC_GETOWNER = "getOwner";
public static final String FUNC_RELINQUISH = "relinquish";
public static final String FUNC_CLAIM = "claim";
protected Ownership(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
}
protected Ownership(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
public RemoteCall<String> getOwner(String id) {
final Function function = new Function(FUNC_GETOWNER,
Arrays.<Type>asList(new org.web3j.abi.datatypes.Utf8String(id)),
Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
return executeRemoteCallSingleValueReturn(function, String.class);
}
public RemoteCall<TransactionReceipt> relinquish(String id) {
final Function function = new Function(
FUNC_RELINQUISH,
Arrays.<Type>asList(new org.web3j.abi.datatypes.Utf8String(id)),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
public RemoteCall<TransactionReceipt> claim(String id) {
final Function function = new Function(
FUNC_CLAIM,
Arrays.<Type>asList(new org.web3j.abi.datatypes.Utf8String(id)),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
public static RemoteCall<Ownership> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
return deployRemoteCall(Ownership.class, web3j, credentials, gasPrice, gasLimit, BINARY, "");
}
public static RemoteCall<Ownership> deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
return deployRemoteCall(Ownership.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, "");
}
public static Ownership load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
return new Ownership(contractAddress, web3j, credentials, gasPrice, gasLimit);
}
public static Ownership load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
return new Ownership(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment