Search in sources :

Example 16 with FileInfoQuery

use of com.hedera.hashgraph.sdk.FileInfoQuery in project hedera-sdk-java by hashgraph.

the class FileAppendChunkedExample method main.

public static void main(String[] args) throws TimeoutException, PrecheckStatusException, ReceiptStatusException {
    Client client = Client.forName(HEDERA_NETWORK);
    // Defaults the operator account ID and key such that all generated transactions will be paid for
    // by this account and be signed by this key
    client.setOperator(OPERATOR_ID, OPERATOR_KEY);
    TransactionResponse transactionResponse = new FileCreateTransaction().setKeys(OPERATOR_KEY.getPublicKey()).setContents("Hello from Hedera.").setMaxTransactionFee(// 2 HBAR
    new Hbar(2)).execute(client);
    TransactionReceipt receipt = transactionResponse.getReceipt(client);
    FileId newFileId = Objects.requireNonNull(receipt.fileId);
    System.out.println("fileId: " + newFileId);
    StringBuilder contents = new StringBuilder();
    for (int i = 0; i <= 4096 * 9; i++) {
        contents.append("1");
    }
    TransactionReceipt fileAppendReceipt = new FileAppendTransaction().setNodeAccountIds(Collections.singletonList(transactionResponse.nodeId)).setFileId(newFileId).setContents(contents.toString()).setMaxChunks(40).setMaxTransactionFee(new Hbar(1000)).freezeWith(client).execute(client).getReceipt(client);
    System.out.println(fileAppendReceipt.toString());
    FileInfo info = new FileInfoQuery().setFileId(newFileId).execute(client);
    System.out.println("File size according to `FileInfoQuery`: " + info.size);
}
Also used : FileCreateTransaction(com.hedera.hashgraph.sdk.FileCreateTransaction) FileInfoQuery(com.hedera.hashgraph.sdk.FileInfoQuery) TransactionResponse(com.hedera.hashgraph.sdk.TransactionResponse) FileInfo(com.hedera.hashgraph.sdk.FileInfo) TransactionReceipt(com.hedera.hashgraph.sdk.TransactionReceipt) FileAppendTransaction(com.hedera.hashgraph.sdk.FileAppendTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) FileId(com.hedera.hashgraph.sdk.FileId) Client(com.hedera.hashgraph.sdk.Client)

Aggregations

FileCreateTransaction (com.hedera.hashgraph.sdk.FileCreateTransaction)16 FileInfoQuery (com.hedera.hashgraph.sdk.FileInfoQuery)16 DisplayName (org.junit.jupiter.api.DisplayName)14 Test (org.junit.jupiter.api.Test)14 FileDeleteTransaction (com.hedera.hashgraph.sdk.FileDeleteTransaction)12 Var (com.google.errorprone.annotations.Var)4 FileAppendTransaction (com.hedera.hashgraph.sdk.FileAppendTransaction)4 Hbar (com.hedera.hashgraph.sdk.Hbar)3 Client (com.hedera.hashgraph.sdk.Client)2 FileContentsQuery (com.hedera.hashgraph.sdk.FileContentsQuery)2 FileId (com.hedera.hashgraph.sdk.FileId)2 FileUpdateTransaction (com.hedera.hashgraph.sdk.FileUpdateTransaction)2 TransactionReceipt (com.hedera.hashgraph.sdk.TransactionReceipt)2 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)2 FileInfo (com.hedera.hashgraph.sdk.FileInfo)1 MaxQueryPaymentExceededException (com.hedera.hashgraph.sdk.MaxQueryPaymentExceededException)1