All Products
Search
Document Center

Envelope transaction interface

Last Updated: May 08, 2020

An envelope transaction is executed in an independent group to protect privacy. The smart contract platform supports envelope transactions of deploying, calling, updating, and querying for contracts.

depositEnvelope

This API is called synchronously for envelope transactions.

  • Function prototype
  1. public DepositEnvelopeResponse depositEnvelope(DepositEnvelopeRequest request)
  • Request parameter
Parameter Required Type Description
request true DepositEnvelopeRequest The envelope transaction request.
  • Response field
Response field Field type Description
response DepositEnvelopeResponse The envelope transaction response.
  • Example
  1. // create Group
  2. CreateGroupRequest createGroupRequest = new CreateGroupRequest(new PublicKey(keypair.getPubkeyId()), adminAccount.getIdentity());
  3. createGroupResponse = sdk.getEnvelopeService().createGroup(createGroupRequest);
  4. // join group
  5. byte[] groupPrivateKey = createGroupResponse.getPrivateKey();
  6. PublicKey anoymousPublicKey = new PublicKey(keypair.getPubkeyId());
  7. JoinGroupRequest request = new JoinGroupRequest(groupPrivateKey, anoymousPublicKey, createGroupResponse.getGroupId(), adminAccount.getIdentity());
  8. JoinGroupResponse joinGroupResponse = sdk.getEnvelopeService().joinGroup(request);
  9. // get groupId by createGroupResponse
  10. BaseFixedSizeByteArray.Fixed20ByteArray groupId = createGroupResponse.getGroupId();
  11. // get keypair from createGroupResponse
  12. Pkcs8KeyOperator pkcs8KeyOperator = new Pkcs8KeyOperator();
  13. Keypair keypair = pkcs8KeyOperator.loadFromPrivkey(createGroupResponse.getPrivateKey());
  14. // create signerOption by keypair
  15. SignerOption signerOption = new SignerOption();
  16. List<SignerBase> signerBaseList = new ArrayList<>();
  17. signerBaseList.add(MyCrypto.getInstance().createSigner(keypair));
  18. signerOption.setSigners(signerBaseList);
  19. // create inner request
  20. CreateAccountRequest createAccountRequest = new CreateAccountRequest(accId, account);
  21. // create DepositEnvelopeRequest
  22. IHash hashTool = HashFactory.getHash();
  23. DepositEnvelopeRequest request = new DepositEnvelopeRequest(createAccountRequest, groupId, signerOption, keypair);
  24. request.setAnoymousIdentity(new Identity(hashTool.hash(keypair.getPubkeyId())));
  25. // Refer to the error message description document to check the returned data.
  26. DepositEnvelopeResponse response = sdk.getEnvelopeService().depositEnvelope(request);

asyncDepositRequest

This API is called asynchronously for envelope transactions.

  • Function prototype
  1. public int asyncDepositRequest(DepositEnvelopeRequest request, IAsyncCallback callback)
  • Request parameter
Parameter Required Type Description
request true DepositEnvelopeRequest The envelope transaction request.
callback true IAsyncCallback The callback function.
  • Response field
Response field Field type Description
result int The return value.
  • Example
  1. DepositEnvelopeRequest request = new DepositEnvelopeRequest(createAccountRequest, groupId, signerOption, keypair);
  2. request.setAnoymousIdentity(new Identity(hashTool.hash(keypair.getPubkeyId())));
  3. int result = sdk.getEnvelopeService().asyncDepositRequest(
  4. request,
  5. new IAsyncCallback() {
  6. @Override
  7. public void onResponse(int errorCode, Response response) {
  8. // Refer to the error messages in section 4.11 to check the returned data.
  9. System.out.println("async deposit envelope, errorCode:" + errorCode + ", response: " + response.getErrorCode());
  10. }
  11. });

Request parameters for an envelope transaction

  • DepositEnvelopeRequest
Parameter Type Description
anoymousIdentity Identity The anonymous identity.
signerOption SignerOption The signature configuration option.
keypair Keypair The key pair.
  • GroupTransactionRequest

GroupTransactionRequest is the parent class of DepositEnvelopeRequest.

Parameter Type Description
request AbstractTransactionRequest The inner transaction, including deploying, calling, and updating a contract.

Response parameters for an envelope transaction

  • DepositEnvelopeResponse
Parameter Type Description
transactionReceipt TransactionReceipt The transaction receipt.
blockNumber BigInteger The block number.