org.web3j.utils.Restriction Java Examples

The following examples show how to use org.web3j.utils.Restriction. 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: RawPrivateTransaction.java    From web3j with Apache License 2.0 6 votes vote down vote up
public static RawPrivateTransaction createContractTransaction(
        final BigInteger nonce,
        final BigInteger gasPrice,
        final BigInteger gasLimit,
        final String init,
        final Base64String privateFrom,
        final Base64String privacyGroupId,
        final Restriction restriction) {

    return new RawPrivateTransaction(
            nonce,
            gasPrice,
            gasLimit,
            "",
            init,
            privateFrom,
            null,
            privacyGroupId,
            restriction);
}
 
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: SignedRawPrivateTransaction.java    From web3j with Apache License 2.0 6 votes vote down vote up
private SignedRawPrivateTransaction(
        final SignedRawTransaction signedRawTransaction,
        final Base64String privateFrom,
        final List<Base64String> privateFor,
        final Base64String privacyGroupId,
        final Restriction restriction) {
    this(
            signedRawTransaction.getNonce(),
            signedRawTransaction.getGasPrice(),
            signedRawTransaction.getGasLimit(),
            signedRawTransaction.getTo(),
            signedRawTransaction.getData(),
            signedRawTransaction.getSignatureData(),
            privateFrom,
            privateFor,
            privacyGroupId,
            restriction);
}
 
Example #4
Source File: SignedRawPrivateTransaction.java    From web3j with Apache License 2.0 6 votes vote down vote up
public SignedRawPrivateTransaction(
        final BigInteger nonce,
        final BigInteger gasPrice,
        final BigInteger gasLimit,
        final String to,
        final String data,
        final Sign.SignatureData signatureData,
        final Base64String privateFrom,
        final List<Base64String> privateFor,
        final Base64String privacyGroupId,
        final Restriction restriction) {
    super(
            nonce,
            gasPrice,
            gasLimit,
            to,
            data,
            privateFrom,
            privateFor,
            privacyGroupId,
            restriction);
    this.signatureData = signatureData;
}
 
Example #5
Source File: RawPrivateTransaction.java    From web3j with Apache License 2.0 6 votes vote down vote up
public static RawPrivateTransaction createTransactionEIP1559(
        final BigInteger nonce,
        final BigInteger gasPremium,
        final BigInteger feeCap,
        final BigInteger gasLimit,
        final String to,
        final String data,
        final Base64String privateFrom,
        final Base64String privacyGroupId,
        final Restriction restriction) {

    return new RawPrivateTransaction(
            nonce,
            gasPremium,
            feeCap,
            gasLimit,
            to,
            data,
            privateFrom,
            null,
            privacyGroupId,
            restriction);
}
 
Example #6
Source File: RawPrivateTransaction.java    From web3j with Apache License 2.0 6 votes vote down vote up
public static RawPrivateTransaction createTransaction(
        final BigInteger nonce,
        final BigInteger gasPrice,
        final BigInteger gasLimit,
        final String to,
        final String data,
        final Base64String privateFrom,
        final Base64String privacyGroupId,
        final Restriction restriction) {

    return new RawPrivateTransaction(
            nonce,
            gasPrice,
            gasLimit,
            to,
            data,
            privateFrom,
            null,
            privacyGroupId,
            restriction);
}
 
Example #7
Source File: RawPrivateTransaction.java    From web3j with Apache License 2.0 6 votes vote down vote up
public static RawPrivateTransaction createTransactionEIP1559(
        final BigInteger nonce,
        final BigInteger gasPremium,
        final BigInteger feeCap,
        final BigInteger gasLimit,
        final String to,
        final String data,
        final Base64String privateFrom,
        final List<Base64String> privateFor,
        final Restriction restriction) {

    return new RawPrivateTransaction(
            nonce,
            gasPremium,
            feeCap,
            gasLimit,
            to,
            data,
            privateFrom,
            privateFor,
            null,
            restriction);
}
 
Example #8
Source File: RawPrivateTransaction.java    From web3j with Apache License 2.0 6 votes vote down vote up
private RawPrivateTransaction(
        final RawTransaction rawTransaction,
        final Base64String privateFrom,
        final List<Base64String> privateFor,
        final Base64String privacyGroupId,
        final Restriction restriction) {
    this(
            rawTransaction.getNonce(),
            rawTransaction.getGasPrice(),
            rawTransaction.getGasLimit(),
            rawTransaction.getTo(),
            rawTransaction.getData(),
            privateFrom,
            privateFor,
            privacyGroupId,
            restriction);
}
 
Example #9
Source File: RawPrivateTransaction.java    From web3j with Apache License 2.0 6 votes vote down vote up
protected RawPrivateTransaction(
        final BigInteger nonce,
        final BigInteger gasPrice,
        final BigInteger gasLimit,
        final String to,
        final String data,
        final Base64String privateFrom,
        final List<Base64String> privateFor,
        final Base64String privacyGroupId,
        final Restriction restriction) {
    super(nonce, gasPrice, gasLimit, to, BigInteger.ZERO, data);
    this.privateFrom = privateFrom;
    this.privateFor = privateFor;
    this.privacyGroupId = privacyGroupId;
    this.restriction = restriction;
}
 
Example #10
Source File: RawPrivateTransaction.java    From web3j with Apache License 2.0 6 votes vote down vote up
protected RawPrivateTransaction(
        final BigInteger nonce,
        final BigInteger gasPremium,
        final BigInteger feeCap,
        final BigInteger gasLimit,
        final String to,
        final String data,
        final Base64String privateFrom,
        final List<Base64String> privateFor,
        final Base64String privacyGroupId,
        final Restriction restriction) {
    super(nonce, null, gasLimit, to, BigInteger.ZERO, data, gasPremium, feeCap);
    this.privateFrom = privateFrom;
    this.privateFor = privateFor;
    this.privacyGroupId = privacyGroupId;
    this.restriction = restriction;
}
 
Example #11
Source File: EeaPrivateTransactionTest.java    From ethsigner with Apache License 2.0 5 votes vote down vote up
@Test
public void rlpEncodesTransaction() {
  final SignatureData signatureData =
      new SignatureData(new byte[] {1}, new byte[] {2}, new byte[] {3});
  final byte[] rlpEncodedBytes = privateTransaction.rlpEncode(signatureData);
  final String rlpString = Numeric.toHexString(rlpEncodedBytes);

  final SignedRawPrivateTransaction decodedTransaction =
      (SignedRawPrivateTransaction) PrivateTransactionDecoder.decode(rlpString);
  assertThat(decodedTransaction.getTo()).isEqualTo("0xd46e8dd67c5d32be8058bb8eb970870f07244567");
  assertThat(decodedTransaction.getGasLimit()).isEqualTo(decodeQuantity("0x76c0"));
  assertThat(decodedTransaction.getGasPrice()).isEqualTo(decodeQuantity("0x9184e72a000"));
  assertThat(decodedTransaction.getNonce()).isEqualTo(decodeQuantity("0x1"));
  assertThat(decodedTransaction.getValue()).isEqualTo(decodeQuantity("0x0"));
  assertThat(decodedTransaction.getData())
      .isEqualTo(
          "d46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675");
  assertThat(decodedTransaction.getRestriction()).isEqualTo(Restriction.RESTRICTED);

  final Base64String expectedDecodedPrivateFrom = params.privateFrom();
  final Base64String expectedDecodedPrivateFor = params.privateFor().get().get(0);

  assertThat(decodedTransaction.getPrivateFrom()).isEqualTo(expectedDecodedPrivateFrom);
  assertThat(decodedTransaction.getPrivateFor().get().get(0))
      .isEqualTo(expectedDecodedPrivateFor);

  final SignatureData decodedSignatureData = decodedTransaction.getSignatureData();
  assertThat(trimLeadingZeroes(decodedSignatureData.getV())).isEqualTo(new byte[] {1});
  assertThat(trimLeadingZeroes(decodedSignatureData.getR())).isEqualTo(new byte[] {2});
  assertThat(trimLeadingZeroes(decodedSignatureData.getS())).isEqualTo(new byte[] {3});
}
 
Example #12
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 #13
Source File: PrivateTransaction.java    From web3j with Apache License 2.0 5 votes vote down vote up
public PrivateTransaction(
        final String hash,
        final String nonce,
        final String from,
        final String to,
        final String value,
        final String gas,
        final String gasPrice,
        final String input,
        final String r,
        final String s,
        final String v,
        final Base64String privateFrom,
        final String restriction) {

    this.hash = hash;
    this.nonce = Numeric.decodeQuantity(nonce);
    this.from = from;
    this.to = to;
    this.value = Numeric.decodeQuantity(value);
    this.gasPrice = Numeric.decodeQuantity(gasPrice);
    this.gas = Numeric.decodeQuantity(gas);
    this.input = input;
    this.r = r;
    this.s = s;
    this.v = Numeric.decodeQuantity(v).longValue();
    this.privateFrom = privateFrom;
    this.restriction = Restriction.fromString(restriction);
}
 
Example #14
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 #15
Source File: SignedRawPrivateTransaction.java    From web3j with Apache License 2.0 5 votes vote down vote up
public SignedRawPrivateTransaction(
        final SignedRawTransaction signedRawTransaction,
        final Base64String privateFrom,
        final Base64String privacyGroupId,
        final Restriction restriction) {
    this(signedRawTransaction, privateFrom, null, privacyGroupId, restriction);
}
 
Example #16
Source File: SignedRawPrivateTransaction.java    From web3j with Apache License 2.0 5 votes vote down vote up
public SignedRawPrivateTransaction(
        final SignedRawTransaction signedRawTransaction,
        final Base64String privateFrom,
        final List<Base64String> privateFor,
        final Restriction restriction) {
    this(signedRawTransaction, privateFrom, privateFor, null, restriction);
}
 
Example #17
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 #18
Source File: RawPrivateTransaction.java    From web3j with Apache License 2.0 5 votes vote down vote up
public static RawPrivateTransaction createTransaction(
        final BigInteger nonce,
        final BigInteger gasPrice,
        final BigInteger gasLimit,
        final String to,
        final String data,
        final Base64String privateFrom,
        final List<Base64String> privateFor,
        final Restriction restriction) {

    return new RawPrivateTransaction(
            nonce, gasPrice, gasLimit, to, data, privateFrom, privateFor, null, restriction);
}
 
Example #19
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 #20
Source File: RawPrivateTransaction.java    From web3j with Apache License 2.0 5 votes vote down vote up
public static RawPrivateTransaction createContractTransaction(
        final BigInteger nonce,
        final BigInteger gasPrice,
        final BigInteger gasLimit,
        final String init,
        final Base64String privateFrom,
        final List<Base64String> privateFor,
        final Restriction restriction) {

    return new RawPrivateTransaction(
            nonce, gasPrice, gasLimit, "", init, privateFrom, privateFor, null, restriction);
}
 
Example #21
Source File: RawPrivateTransaction.java    From web3j with Apache License 2.0 5 votes vote down vote up
protected RawPrivateTransaction(
        final RawTransaction rawTransaction,
        final Base64String privateFrom,
        final List<Base64String> privateFor,
        final Restriction restriction) {
    this(rawTransaction, privateFrom, privateFor, null, restriction);
}
 
Example #22
Source File: RawPrivateTransaction.java    From web3j with Apache License 2.0 5 votes vote down vote up
protected RawPrivateTransaction(
        final RawTransaction rawTransaction,
        final Base64String privateFrom,
        final Base64String privacyGroupId,
        final Restriction restriction) {
    this(rawTransaction, privateFrom, null, privacyGroupId, restriction);
}
 
Example #23
Source File: PrivacyClusterAcceptanceTest.java    From besu with Apache License 2.0 4 votes vote down vote up
@Test
public void aliceCanUsePrivDistributeTransaction() {
  // Contract address is generated from sender address and transaction nonce
  final String contractAddress = "0xebf56429e6500e84442467292183d4d621359838";

  final RawPrivateTransaction rawPrivateTransaction =
      RawPrivateTransaction.createContractTransaction(
          BigInteger.ZERO,
          BigInteger.ZERO,
          BigInteger.ZERO,
          Numeric.prependHexPrefix(EventEmitter.BINARY),
          Base64String.wrap(alice.getEnclaveKey()),
          Collections.singletonList(Base64String.wrap(bob.getEnclaveKey())),
          Restriction.RESTRICTED);

  final String signedPrivateTransaction =
      Numeric.toHexString(
          PrivateTransactionEncoder.signMessage(
              rawPrivateTransaction,
              POW_CHAIN_ID,
              Credentials.create(alice.getTransactionSigningKey())));
  final String transactionKey =
      alice.execute(privacyTransactions.privDistributeTransaction(signedPrivateTransaction));

  final Enclave aliceEnclave = enclaveFactory.createVertxEnclave(alice.getOrion().clientUrl());
  final ReceiveResponse aliceRR =
      aliceEnclave.receive(
          Bytes.fromHexString(transactionKey).toBase64String(), alice.getEnclaveKey());

  final Enclave bobEnclave = enclaveFactory.createVertxEnclave(bob.getOrion().clientUrl());
  final ReceiveResponse bobRR =
      bobEnclave.receive(
          Bytes.fromHexString(transactionKey).toBase64String(), bob.getEnclaveKey());

  assertThat(bobRR).isEqualToComparingFieldByField(aliceRR);

  final RawTransaction pmt =
      RawTransaction.createTransaction(
          BigInteger.ZERO,
          BigInteger.valueOf(1000),
          BigInteger.valueOf(65000),
          Address.DEFAULT_PRIVACY.toString(),
          transactionKey);

  final String signedPmt =
      Numeric.toHexString(
          TransactionEncoder.signMessage(
              pmt, POW_CHAIN_ID, Credentials.create(alice.getTransactionSigningKey())));

  final String transactionHash = alice.execute(ethTransactions.sendRawTransaction(signedPmt));

  final PrivateTransactionReceipt expectedReceipt =
      new PrivateTransactionReceipt(
          contractAddress,
          "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73",
          null,
          eventEmmitterDeployed,
          Collections.emptyList(),
          "0x023955c49d6265c579561940287449242704d5fd239ff07ea36a3fc7aface61c",
          "0x82e521ee16ff13104c5f81e8354ecaaafd5450b710b07f620204032bfe76041a",
          "A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=",
          new ArrayList<>(
              Collections.singletonList("Ko2bVqD+nNlNYL5EE7y3IdOnviftjiizpjRt+HTuFBs=")),
          null,
          "0x1",
          null);

  alice.verify(
      privateTransactionVerifier.validPrivateTransactionReceipt(
          transactionHash, expectedReceipt));

  bob.verify(
      privateTransactionVerifier.validPrivateTransactionReceipt(
          transactionHash, expectedReceipt));
}
 
Example #24
Source File: RawPrivateTransaction.java    From web3j with Apache License 2.0 4 votes vote down vote up
public Restriction getRestriction() {
    return restriction;
}
 
Example #25
Source File: PrivateTransactionDecoder.java    From web3j with Apache License 2.0 4 votes vote down vote up
private static Restriction extractRestriction(final RlpType value) {
    return Restriction.fromString(new String(((RlpString) value).getBytes(), UTF_8));
}
 
Example #26
Source File: PrivateTransaction.java    From web3j with Apache License 2.0 4 votes vote down vote up
public Restriction getRestriction() {
    return restriction;
}