-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c05f8d
commit 3d1aedd
Showing
24 changed files
with
436 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 0 additions & 49 deletions
49
hedera-base/src/main/java/com/openelements/hedera/base/HederaClient.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
hedera-base/src/main/java/com/openelements/hedera/base/data/ContractVerificationState.java
This file was deleted.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
hedera-base/src/main/java/com/openelements/hedera/base/implementation/FileClientImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.openelements.hedera.base.implementation; | ||
|
||
import com.hedera.hashgraph.sdk.FileId; | ||
import com.openelements.hedera.base.FileClient; | ||
import com.openelements.hedera.base.HederaException; | ||
import com.openelements.hedera.base.protocol.FileAppendRequest; | ||
import com.openelements.hedera.base.protocol.FileAppendResult; | ||
import com.openelements.hedera.base.protocol.FileContentsRequest; | ||
import com.openelements.hedera.base.protocol.FileContentsResponse; | ||
import com.openelements.hedera.base.protocol.FileCreateRequest; | ||
import com.openelements.hedera.base.protocol.FileCreateResult; | ||
import com.openelements.hedera.base.protocol.FileDeleteRequest; | ||
import com.openelements.hedera.base.protocol.ProtocolLevelClient; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import java.util.Arrays; | ||
import java.util.Objects; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class FileClientImpl implements FileClient { | ||
|
||
private final static Logger log = LoggerFactory.getLogger(FileClientImpl.class); | ||
|
||
private final ProtocolLevelClient protocolLevelClient; | ||
|
||
public FileClientImpl(@NonNull final ProtocolLevelClient protocolLevelClient) { | ||
this.protocolLevelClient = Objects.requireNonNull(protocolLevelClient, "protocolLevelClient must not be null"); | ||
} | ||
|
||
@Override | ||
public FileId createFile(byte[] contents) throws HederaException { | ||
if(contents.length <= FileCreateRequest.FILE_CREATE_MAX_BYTES) { | ||
final FileCreateRequest request = FileCreateRequest.of(contents); | ||
final FileCreateResult result = protocolLevelClient.executeFileCreateTransaction(request); | ||
return result.fileId(); | ||
} else { | ||
if(log.isDebugEnabled()) { | ||
final int appendCount = Math.floorDiv(contents.length, FileCreateRequest.FILE_CREATE_MAX_BYTES); | ||
log.debug("Content of size {} is to big for 1 FileCreate transaction. Will append {} FileAppend transactions", contents.length, appendCount); | ||
} | ||
byte[] start = Arrays.copyOf(contents, FileCreateRequest.FILE_CREATE_MAX_BYTES); | ||
final FileCreateRequest request = FileCreateRequest.of(start); | ||
final FileCreateResult result = protocolLevelClient.executeFileCreateTransaction(request); | ||
FileId fileId = result.fileId(); | ||
byte[] remaining = Arrays.copyOfRange(contents, FileCreateRequest.FILE_CREATE_MAX_BYTES, contents.length); | ||
while(remaining.length > 0) { | ||
final int length = Math.min(remaining.length, FileCreateRequest.FILE_CREATE_MAX_BYTES); | ||
byte[] next = Arrays.copyOf(remaining, length); | ||
final FileAppendRequest appendRequest = FileAppendRequest.of(fileId, next); | ||
final FileAppendResult appendResult = protocolLevelClient.executeFileAppendRequestTransaction(appendRequest); | ||
remaining = Arrays.copyOfRange(remaining, length, remaining.length); | ||
} | ||
return fileId; | ||
} | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public byte[] readFile(@NonNull FileId fileId) throws HederaException { | ||
try { | ||
final FileContentsRequest request = FileContentsRequest.of(fileId); | ||
final FileContentsResponse response = protocolLevelClient.executeFileContentsQuery(request); | ||
return response.contents(); | ||
} catch (Exception e) { | ||
throw new HederaException("Failed to read file with fileId " + fileId, e); | ||
} | ||
} | ||
|
||
@Override | ||
public void deleteFile(@NonNull FileId fileId) throws HederaException { | ||
try { | ||
final FileDeleteRequest request = FileDeleteRequest.of(fileId); | ||
protocolLevelClient.executeFileDeleteTransaction(request); | ||
} catch (Exception e) { | ||
throw new HederaException("Failed to delete file with fileId " + fileId, e); | ||
} | ||
} | ||
} |
Oops, something went wrong.