All Products
Search
Document Center

Native Deposit Interface

Last Updated: Nov 04, 2019

To facilitate the development of the deposit scenario, the contract platform provides the native deposit interface.

depositData

You can call this synchronous operation to deposit data.

  • Function
  1. public MychainBaseResult<ReplyTransactionReceipt> depositData(DepositDataRequest request)
  • Request parameters
Parameter Require Type Description
request true DepositDataRequest Request to deposite transaction data
  • Return values
Field Type Description
result MychainBaseResult<ReplyTransactionReceipt> response in MychainBaseResult
  • Examples:
  1. // Deposit data
  2. private static String depositData() {
  3. // Prepare params
  4. MychainParams params = new MychainParams.Builder()
  5. .gas(BigInteger.valueOf(4000000))
  6. .privateKeyList(adminPrivateKeys)
  7. .build();
  8. // Deposited data
  9. byte[] data = ByteUtils.hexStringToBytes("0x1234");
  10. DepositDataRequest depositDataRequest = DepositDataRequest.build(adminAccount.getIdentity(),
  11. adminAccount.getIdentity(), BigInteger.ZERO, data, params);
  12. MychainBaseResult<ReplyTransactionReceipt> depositDataResult = sdk.getAccountService().depositData(depositDataRequest);
  13. if (!depositDataResult.isSuccess() || depositDataResult.getData().getTransactionReceipt().getResult() != 0) {
  14. exit("depositData", getErrorMsg((int)depositDataResult.getData().getTransactionReceipt().getResult()));
  15. }
  16. return depositDataResult.getTxHash();
  17. }
  18. // Query for deposited data
  19. private static String queryDepositData(String hash) {
  20. // Query for deposited data by QueryTransaction with trasaction hash.
  21. MychainBaseResult<ReplyTransaction> queryTxResult = sdk.getQueryService().queryTransaction(hash);
  22. if (!queryTxResult.isSuccess()) {
  23. exit("depositData", queryTxResult.getData().getErrorCode().toString());
  24. }
  25. MychainBaseResult<ReplyTransactionReceipt> queryTxReceiptResult = sdk.getQueryService().queryTransactionReceipt(hash);
  26. if (!queryTxReceiptResult.isSuccess() || queryTxReceiptResult.getData().getTransactionReceipt().getResult() != 0) {
  27. exit("depositData", getErrorMsg((int)queryTxReceiptResult.getData().getTransactionReceipt().getResult()));
  28. }
  29. return ByteUtils.toHexString(queryTxResult.getData().getTransactionDO().getData());
  30. }

asyncDepositData

You can call this asynchronous operation to deposit data.

  • Function
  1. public MychainBaseResult<Response> asyncDepositData(DepositDataRequest request, ICallback callback)
  • Request parameters
Parameter Require Type Description
request true DepositDataRequest Request to deposite transaction data
callback true ICallback Callback
  • Return values
Field Type Description
result MychainBaseResult<ReplyTransactionReceipt> response in MychainBaseResult

Note: Deposite data is capped, and it is a configuation option of contract blockchain. It is set to 1 MB as default and you can change it to suit the situation.

Examples:

  1. private static void depositDataAsync() {
  2. MychainParams params = new MychainParams.Builder()
  3. .gas(BigInteger.valueOf(4000000))
  4. .privateKeyList(adminPrivateKeys)
  5. .build();
  6. byte[] data = ByteUtils.hexStringToBytes("0x1234");
  7. DepositDataRequest request = DepositDataRequest.build(adminAccount.getIdentity(),
  8. adminAccount.getIdentity(), BigInteger.ZERO, data, params);
  9. MychainBaseResult<Response> depositDataResult = sdk.getAccountService().asyncDepositData(request, new ICallback() {
  10. @Override
  11. public void onResponse(String txHash, Response response) {
  12. System.out.println("depositDataAsync, txHash:" + txHash + ", result: "
  13. + response.getErrorCode());
  14. MychainBaseResult<ReplyTransaction> queryTxResult = sdk.getQueryService().queryTransaction(txHash);
  15. if (!queryTxResult.isSuccess()) {
  16. exit("depositDataAsync", queryTxResult.getData().getErrorCode().toString());
  17. }
  18. System.out.println("depositDataAsync success: " + ByteUtils.toHexString(queryTxResult.getData().getTransactionDO().getData()));
  19. }
  20. });
  21. }

DepositDataRequest

  • Request parameters
Parameter Type Description
identity Identity Transaction sender identity
identity Identity Transaction receiver identity
value BigInteger Transaction value
data byte[] Data to be stored, which can be customized, serializing deposited and deserialized
value MychainParams General parameter

Note: Deposite data is capped, and it is a configuation option of contract blockchain. It is set to 1 MB as default and you can change it to suit the situation.