Java Code Examples for org.web3j.protocol.eea.crypto.RawPrivateTransaction#createTransaction()

The following examples show how to use org.web3j.protocol.eea.crypto.RawPrivateTransaction#createTransaction() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrivacyRequestFactory.java    From besu with Apache License 2.0 6 votes vote down vote up
public String privxAddToPrivacyGroup(
    final Base64String privacyGroupId, final PrivacyNode adder, final List<String> addresses)
    throws IOException, TransactionException {

  final BigInteger nonce =
      besuClient
          .privGetTransactionCount(adder.getAddress().toHexString(), privacyGroupId)
          .send()
          .getTransactionCount();

  final Bytes payload =
      encodeAddToGroupFunctionCall(
          Bytes.fromBase64String(adder.getEnclaveKey()),
          addresses.stream().map(Bytes::fromBase64String).collect(Collectors.toList()));

  final RawPrivateTransaction privateTransaction =
      RawPrivateTransaction.createTransaction(
          nonce,
          BigInteger.valueOf(1000),
          BigInteger.valueOf(3000000),
          Address.ONCHAIN_PRIVACY_PROXY.toHexString(),
          payload.toHexString(),
          Base64String.wrap(adder.getEnclaveKey()),
          privacyGroupId,
          org.web3j.utils.Restriction.RESTRICTED);

  return besuClient
      .eeaSendRawTransaction(
          Numeric.toHexString(
              PrivateTransactionEncoder.signMessage(
                  privateTransaction, Credentials.create(adder.getTransactionSigningKey()))))
      .send()
      .getTransactionHash();
}
 
Example 2
Source File: OnChainPrivacyTransactionBuilder.java    From web3j with Apache License 2.0 6 votes vote down vote up
public static String buildOnChainPrivateTransaction(
        Base64String privacyGroupId,
        Credentials credentials,
        Base64String enclaveKey,
        final BigInteger nonce,
        String call) {

    RawPrivateTransaction rawTransaction =
            RawPrivateTransaction.createTransaction(
                    nonce,
                    ZERO_GAS_PROVIDER.getGasPrice(),
                    ZERO_GAS_PROVIDER.getGasLimit(),
                    "0x000000000000000000000000000000000000007c",
                    call,
                    enclaveKey,
                    privacyGroupId,
                    Restriction.RESTRICTED);

    return Numeric.toHexString(
            PrivateTransactionEncoder.signMessage(rawTransaction, 2018, credentials));
}
 
Example 3
Source File: EeaPrivateTransaction.java    From ethsigner with Apache License 2.0 5 votes vote down vote up
@Override
protected RawPrivateTransaction createTransaction() {
  return RawPrivateTransaction.createTransaction(
      nonce,
      transactionJsonParameters.gasPrice().orElse(DEFAULT_GAS_PRICE),
      transactionJsonParameters.gas().orElse(DEFAULT_GAS),
      transactionJsonParameters.receiver().orElse(DEFAULT_TO),
      transactionJsonParameters.data().orElse(DEFAULT_DATA),
      transactionJsonParameters.privateFrom(),
      privateFor,
      Restriction.fromString(transactionJsonParameters.restriction()));
}
 
Example 4
Source File: BesuPrivateTransaction.java    From ethsigner with Apache License 2.0 5 votes vote down vote up
@Override
protected RawPrivateTransaction createTransaction() {
  return RawPrivateTransaction.createTransaction(
      nonce,
      transactionJsonParameters.gasPrice().orElse(DEFAULT_GAS_PRICE),
      transactionJsonParameters.gas().orElse(DEFAULT_GAS),
      transactionJsonParameters.receiver().orElse(DEFAULT_TO),
      transactionJsonParameters.data().orElse(DEFAULT_DATA),
      transactionJsonParameters.privateFrom(),
      privacyGroupId,
      Restriction.fromString(transactionJsonParameters.restriction()));
}
 
Example 5
Source File: EeaSendRawTransaction.java    From ethsigner with Apache License 2.0 5 votes vote down vote up
private RawPrivateTransaction createBesuRawPrivateTransaction(
    final JsonObject transaction, final String privacyGroupId) {
  return RawPrivateTransaction.createTransaction(
      valueToBigDecimal(transaction.getString("nonce")),
      valueToBigDecimal(transaction.getString("gasPrice")),
      valueToBigDecimal(transaction.getString("gas")),
      transaction.getString("to"),
      transaction.getString("data"),
      valueToBase64String(transaction.getString("privateFrom")),
      valueToBase64String(privacyGroupId),
      Restriction.fromString(transaction.getString("restriction")));
}
 
Example 6
Source File: EeaSendRawTransaction.java    From ethsigner with Apache License 2.0 5 votes vote down vote up
private RawPrivateTransaction createEeaRawPrivateTransaction(final JsonObject transaction) {
  return RawPrivateTransaction.createTransaction(
      valueToBigDecimal(transaction.getString("nonce")),
      valueToBigDecimal(transaction.getString("gasPrice")),
      valueToBigDecimal(transaction.getString("gas")),
      transaction.getString("to"),
      transaction.getString("data"),
      valueToBase64String(transaction.getString("privateFrom")),
      privateFor(transaction.getJsonArray("privateFor")),
      Restriction.fromString(transaction.getString("restriction")));
}
 
Example 7
Source File: PrivacyRequestFactory.java    From besu with Apache License 2.0 5 votes vote down vote up
public String privxRemoveFromPrivacyGroup(
    final Base64String privacyGroupId, final PrivacyNode remover, final String toRemove)
    throws IOException, TransactionException {

  final BigInteger nonce =
      besuClient
          .privGetTransactionCount(remover.getAddress().toHexString(), privacyGroupId)
          .send()
          .getTransactionCount();

  final Bytes payload =
      encodeRemoveFromGroupFunctionCall(
          Bytes.fromBase64String(remover.getEnclaveKey()), Bytes.fromBase64String(toRemove));

  final RawPrivateTransaction privateTransaction =
      RawPrivateTransaction.createTransaction(
          nonce,
          BigInteger.valueOf(1000),
          BigInteger.valueOf(3000000),
          Address.ONCHAIN_PRIVACY_PROXY.toHexString(),
          payload.toHexString(),
          Base64String.wrap(remover.getEnclaveKey()),
          privacyGroupId,
          org.web3j.utils.Restriction.RESTRICTED);

  return besuClient
      .eeaSendRawTransaction(
          Numeric.toHexString(
              PrivateTransactionEncoder.signMessage(
                  privateTransaction, Credentials.create(remover.getTransactionSigningKey()))))
      .send()
      .getTransactionHash();
}
 
Example 8
Source File: PrivacyRequestFactory.java    From besu with Apache License 2.0 5 votes vote down vote up
public String privxLockPrivacyGroup(final PrivacyNode locker, final Base64String privacyGroupId)
    throws IOException, TransactionException {
  final BigInteger nonce =
      besuClient
          .privGetTransactionCount(locker.getAddress().toHexString(), privacyGroupId)
          .send()
          .getTransactionCount();

  final RawPrivateTransaction privateTransaction =
      RawPrivateTransaction.createTransaction(
          nonce,
          BigInteger.valueOf(1000),
          BigInteger.valueOf(3000000),
          Address.ONCHAIN_PRIVACY_PROXY.toHexString(),
          OnChainGroupManagement.LOCK_GROUP_METHOD_SIGNATURE.toHexString(),
          Base64String.wrap(locker.getEnclaveKey()),
          privacyGroupId,
          org.web3j.utils.Restriction.RESTRICTED);

  final String transactionHash =
      besuClient
          .eeaSendRawTransaction(
              Numeric.toHexString(
                  PrivateTransactionEncoder.signMessage(
                      privateTransaction, Credentials.create(locker.getTransactionSigningKey()))))
          .send()
          .getTransactionHash();

  final PrivateTransactionReceipt privateTransactionReceipt =
      new PollingPrivateTransactionReceiptProcessor(besuClient, 3000, 10)
          .waitForTransactionReceipt(transactionHash);

  assertThat(privateTransactionReceipt.getStatus()).isEqualTo("0x1");

  return privateTransactionReceipt.getcommitmentHash();
}
 
Example 9
Source File: PrivacyRequestFactory.java    From besu with Apache License 2.0 4 votes vote down vote up
public PrivxCreatePrivacyGroupResponse privxCreatePrivacyGroup(
    final PrivacyNode creator, final List<String> addresses) throws IOException {

  final byte[] bytes = new byte[32];
  secureRandom.nextBytes(bytes);
  final Bytes privacyGroupId = Bytes.wrap(bytes);

  final BigInteger nonce =
      besuClient
          .privGetTransactionCount(
              creator.getAddress().toHexString(),
              Base64String.wrap(privacyGroupId.toArrayUnsafe()))
          .send()
          .getTransactionCount();

  final Bytes payload =
      encodeAddToGroupFunctionCall(
          Bytes.fromBase64String(creator.getEnclaveKey()),
          addresses.stream().map(Bytes::fromBase64String).collect(Collectors.toList()));

  final RawPrivateTransaction privateTransaction =
      RawPrivateTransaction.createTransaction(
          nonce,
          BigInteger.valueOf(1000),
          BigInteger.valueOf(3000000),
          Address.ONCHAIN_PRIVACY_PROXY.toHexString(),
          payload.toHexString(),
          Base64String.wrap(creator.getEnclaveKey()),
          Base64String.wrap(privacyGroupId.toArrayUnsafe()),
          org.web3j.utils.Restriction.RESTRICTED);

  final String transactionHash =
      besuClient
          .eeaSendRawTransaction(
              Numeric.toHexString(
                  PrivateTransactionEncoder.signMessage(
                      privateTransaction,
                      Credentials.create(creator.getTransactionSigningKey()))))
          .send()
          .getTransactionHash();
  return new PrivxCreatePrivacyGroupResponse(privacyGroupId.toBase64String(), transactionHash);
}
 
Example 10
Source File: PrivateTransactionManager.java    From web3j with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public EthSendTransaction sendTransaction(
        final BigInteger gasPrice,
        final BigInteger gasLimit,
        final String to,
        final String data,
        final BigInteger value,
        boolean constructor)
        throws IOException {

    final BigInteger nonce =
            besu.privGetTransactionCount(credentials.getAddress(), getPrivacyGroupId())
                    .send()
                    .getTransactionCount();

    final Object privacyGroupIdOrPrivateFor = privacyGroupIdOrPrivateFor();

    final RawPrivateTransaction transaction;
    if (privacyGroupIdOrPrivateFor instanceof Base64String) {
        transaction =
                RawPrivateTransaction.createTransaction(
                        nonce,
                        gasPrice,
                        gasLimit,
                        to,
                        data,
                        privateFrom,
                        (Base64String) privacyGroupIdOrPrivateFor,
                        RESTRICTED);
    } else {
        transaction =
                RawPrivateTransaction.createTransaction(
                        nonce,
                        gasPrice,
                        gasLimit,
                        to,
                        data,
                        privateFrom,
                        (List<Base64String>) privacyGroupIdOrPrivateFor,
                        RESTRICTED);
    }

    return signAndSend(transaction);
}