Search in sources :

Example 1 with FileAppendTransaction

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

the class FileAppendIntegrationTest method canAppendLargeContentsToFileDespiteExpiration.

@Test
@DisplayName("Can append large contents to file despite TRANSACTION_EXPIRATION response codes")
void canAppendLargeContentsToFileDespiteExpiration() throws Exception {
    // There are potential bugs in FileAppendTransaction which require more than one node to trigger.
    var testEnv = new IntegrationTestEnv(2);
    var response = new FileCreateTransaction().setKeys(testEnv.operatorKey).setContents("[e2e::FileCreateTransaction]").execute(testEnv.client);
    var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId);
    Thread.sleep(5000);
    @Var var info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client);
    assertThat(info.fileId).isEqualTo(fileId);
    assertThat(info.size).isEqualTo(28);
    assertThat(info.isDeleted).isFalse();
    assertThat(info.keys).isNotNull();
    assertThat(info.keys.getThreshold()).isNull();
    assertThat(info.keys).isEqualTo(KeyList.of(testEnv.operatorKey));
    var appendTx = new FileAppendTransaction().setFileId(fileId).setContents(Contents.BIG_CONTENTS).setTransactionValidDuration(Duration.ofSeconds(25)).execute(testEnv.client).getReceipt(testEnv.client);
    var contents = new FileContentsQuery().setFileId(fileId).execute(testEnv.client);
    assertThat(contents.toStringUtf8()).isEqualTo("[e2e::FileCreateTransaction]" + Contents.BIG_CONTENTS);
    info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client);
    assertThat(info.fileId).isEqualTo(fileId);
    assertThat(info.size).isEqualTo(13522);
    assertThat(info.isDeleted).isFalse();
    assertThat(info.keys).isNotNull();
    assertThat(info.keys.getThreshold()).isNull();
    assertThat(info.keys).isEqualTo(KeyList.of(testEnv.operatorKey));
    new FileDeleteTransaction().setFileId(fileId).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close();
}
Also used : FileContentsQuery(com.hedera.hashgraph.sdk.FileContentsQuery) FileCreateTransaction(com.hedera.hashgraph.sdk.FileCreateTransaction) FileInfoQuery(com.hedera.hashgraph.sdk.FileInfoQuery) Var(com.google.errorprone.annotations.Var) FileDeleteTransaction(com.hedera.hashgraph.sdk.FileDeleteTransaction) FileAppendTransaction(com.hedera.hashgraph.sdk.FileAppendTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with FileAppendTransaction

use of com.hedera.hashgraph.sdk.FileAppendTransaction in project hedera-mirror-node by hashgraph.

the class FileClient method appendFile.

public NetworkTransactionResponse appendFile(FileId fileId, byte[] byteCode) {
    String memo = "Append file";
    log.debug(memo);
    FileAppendTransaction fileAppendTransaction = new FileAppendTransaction().setFileId(fileId).setContents(byteCode).setTransactionMemo(getMemo(memo));
    NetworkTransactionResponse networkTransactionResponse = executeTransactionAndRetrieveReceipt(fileAppendTransaction);
    log.debug("Appended to file {}", fileId);
    return networkTransactionResponse;
}
Also used : NetworkTransactionResponse(com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse) FileAppendTransaction(com.hedera.hashgraph.sdk.FileAppendTransaction)

Example 3 with FileAppendTransaction

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

the class FileAppendIntegrationTest method canAppendLargeContentsToFile.

@Test
@DisplayName("Can append large contents to file")
void canAppendLargeContentsToFile() throws Exception {
    // There are potential bugs in FileAppendTransaction which require more than one node to trigger.
    var testEnv = new IntegrationTestEnv(2);
    var response = new FileCreateTransaction().setKeys(testEnv.operatorKey).setContents("[e2e::FileCreateTransaction]").execute(testEnv.client);
    var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId);
    Thread.sleep(5000);
    @Var var info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client);
    assertThat(info.fileId).isEqualTo(fileId);
    assertThat(info.size).isEqualTo(28);
    assertThat(info.isDeleted).isFalse();
    assertThat(info.keys).isNotNull();
    assertThat(info.keys.getThreshold()).isNull();
    assertThat(info.keys).isEqualTo(KeyList.of(testEnv.operatorKey));
    new FileAppendTransaction().setFileId(fileId).setContents(Contents.BIG_CONTENTS).execute(testEnv.client).getReceipt(testEnv.client);
    var contents = new FileContentsQuery().setFileId(fileId).execute(testEnv.client);
    assertThat(contents.toStringUtf8()).isEqualTo("[e2e::FileCreateTransaction]" + Contents.BIG_CONTENTS);
    info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client);
    assertThat(info.fileId).isEqualTo(fileId);
    assertThat(info.size).isEqualTo(13522);
    assertThat(info.isDeleted).isFalse();
    assertThat(info.keys).isNotNull();
    assertThat(info.keys.getThreshold()).isNull();
    assertThat(info.keys).isEqualTo(KeyList.of(testEnv.operatorKey));
    new FileDeleteTransaction().setFileId(fileId).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close();
}
Also used : FileContentsQuery(com.hedera.hashgraph.sdk.FileContentsQuery) FileCreateTransaction(com.hedera.hashgraph.sdk.FileCreateTransaction) FileInfoQuery(com.hedera.hashgraph.sdk.FileInfoQuery) Var(com.google.errorprone.annotations.Var) FileDeleteTransaction(com.hedera.hashgraph.sdk.FileDeleteTransaction) FileAppendTransaction(com.hedera.hashgraph.sdk.FileAppendTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with FileAppendTransaction

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

the class FileAppendIntegrationTest method canAppendToFile.

@Test
@DisplayName("Can append to file")
void canAppendToFile() throws Exception {
    // There are potential bugs in FileAppendTransaction which require more than one node to trigger.
    var testEnv = new IntegrationTestEnv(1);
    var response = new FileCreateTransaction().setKeys(testEnv.operatorKey).setContents("[e2e::FileCreateTransaction]").execute(testEnv.client);
    var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId);
    @Var var info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client);
    assertThat(info.fileId).isEqualTo(fileId);
    assertThat(info.size).isEqualTo(28);
    assertThat(info.isDeleted).isFalse();
    assertThat(info.keys).isNotNull();
    assertThat(info.keys.getThreshold()).isNull();
    assertThat(info.keys).isEqualTo(KeyList.of(testEnv.operatorKey));
    new FileAppendTransaction().setFileId(fileId).setContents("[e2e::FileAppendTransaction]").execute(testEnv.client).getReceipt(testEnv.client);
    info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client);
    assertThat(info.fileId).isEqualTo(fileId);
    assertThat(info.size).isEqualTo(56);
    assertThat(info.isDeleted).isFalse();
    assertThat(info.keys).isNotNull();
    assertThat(info.keys.getThreshold()).isNull();
    assertThat(info.keys).isEqualTo(KeyList.of(testEnv.operatorKey));
    new FileDeleteTransaction().setFileId(fileId).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close();
}
Also used : FileCreateTransaction(com.hedera.hashgraph.sdk.FileCreateTransaction) FileInfoQuery(com.hedera.hashgraph.sdk.FileInfoQuery) Var(com.google.errorprone.annotations.Var) FileDeleteTransaction(com.hedera.hashgraph.sdk.FileDeleteTransaction) FileAppendTransaction(com.hedera.hashgraph.sdk.FileAppendTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with FileAppendTransaction

use of com.hedera.hashgraph.sdk.FileAppendTransaction 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

FileAppendTransaction (com.hedera.hashgraph.sdk.FileAppendTransaction)5 FileCreateTransaction (com.hedera.hashgraph.sdk.FileCreateTransaction)4 FileInfoQuery (com.hedera.hashgraph.sdk.FileInfoQuery)4 Var (com.google.errorprone.annotations.Var)3 FileDeleteTransaction (com.hedera.hashgraph.sdk.FileDeleteTransaction)3 DisplayName (org.junit.jupiter.api.DisplayName)3 Test (org.junit.jupiter.api.Test)3 FileContentsQuery (com.hedera.hashgraph.sdk.FileContentsQuery)2 Client (com.hedera.hashgraph.sdk.Client)1 FileId (com.hedera.hashgraph.sdk.FileId)1 FileInfo (com.hedera.hashgraph.sdk.FileInfo)1 Hbar (com.hedera.hashgraph.sdk.Hbar)1 TransactionReceipt (com.hedera.hashgraph.sdk.TransactionReceipt)1 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)1 NetworkTransactionResponse (com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse)1