Search in sources :

Example 1 with FileCreateTransactionBody

use of com.hederahashgraph.api.proto.java.FileCreateTransactionBody in project hedera-services by hashgraph.

the class HapiFileCreate method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    if (!immutable) {
        generateWaclKey(spec);
    }
    if (contentsPathFn.isPresent()) {
        var loc = contentsPathFn.get().apply(spec);
        contents = Optional.of(Files.toByteArray(new File(loc)));
    }
    FileCreateTransactionBody opBody = spec.txns().<FileCreateTransactionBody, FileCreateTransactionBody.Builder>body(FileCreateTransactionBody.class, builder -> {
        if (!immutable) {
            builder.setKeys(waclKey.getKeyList());
        }
        memo.ifPresent(builder::setMemo);
        contents.ifPresent(b -> builder.setContents(ByteString.copyFrom(b)));
        lifetime.ifPresent(s -> builder.setExpirationTime(TxnFactory.expiryGiven(s)));
        expiry.ifPresent(t -> builder.setExpirationTime(Timestamp.newBuilder().setSeconds(t).build()));
    });
    return b -> {
        expiryUsed.set(opBody.getExpirationTime());
        b.setFileCreate(opBody);
    };
}
Also used : FileCreateTransactionBody(com.hederahashgraph.api.proto.java.FileCreateTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) Arrays(java.util.Arrays) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SigControl(com.hedera.services.bdd.spec.keys.SigControl) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) OptionalLong(java.util.OptionalLong) TxnFactory(com.hedera.services.bdd.spec.transactions.TxnFactory) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Files(com.google.common.io.Files) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) SigValueObj(com.hederahashgraph.fee.SigValueObj) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) FileCreateTransactionBody(com.hederahashgraph.api.proto.java.FileCreateTransactionBody) KeyGenerator(com.hedera.services.bdd.spec.keys.KeyGenerator) FeeData(com.hederahashgraph.api.proto.java.FeeData) MoreObjects(com.google.common.base.MoreObjects) IOException(java.io.IOException) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) File(java.io.File) LongConsumer(java.util.function.LongConsumer) ByteString(com.google.protobuf.ByteString) KeyFactory(com.hedera.services.bdd.spec.keys.KeyFactory) Consumer(java.util.function.Consumer) TxnFactory.bannerWith(com.hedera.services.bdd.spec.transactions.TxnFactory.bannerWith) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) File(java.io.File)

Example 2 with FileCreateTransactionBody

use of com.hederahashgraph.api.proto.java.FileCreateTransactionBody in project hedera-services by hashgraph.

the class RequestBuilder method getFileCreateBuilder.

/**
 * Builds a file create transaction
 *
 * @param payerAccountNum
 * 		payer account number
 * @param payerRealmNum
 * 		payer realm number
 * @param payerShardNum
 * 		payer shard number
 * @param nodeAccountNum
 * 		node account number
 * @param nodeRealmNum
 * 		node realm number
 * @param nodeShardNum
 * 		node shard number
 * @param transactionFee
 * 		transaction fee
 * @param timestamp
 * 		timestamp
 * @param transactionDuration
 * 		transaction duration
 * @param generateRecord
 * 		generate record boolean
 * @param memo
 * 		memo
 * @param fileData
 * 		content of the file
 * @param fileExpirationTime
 * 		expiration for the file
 * @param waclKeyList
 * 		WACL keys
 * @return transaction for file create
 */
public static Transaction getFileCreateBuilder(Long payerAccountNum, Long payerRealmNum, Long payerShardNum, Long nodeAccountNum, Long nodeRealmNum, Long nodeShardNum, long transactionFee, Timestamp timestamp, Duration transactionDuration, boolean generateRecord, String memo, ByteString fileData, Timestamp fileExpirationTime, List<Key> waclKeyList) {
    FileCreateTransactionBody fileCreateTransactionBody = FileCreateTransactionBody.newBuilder().setExpirationTime(fileExpirationTime).setKeys(KeyList.newBuilder().addAllKeys(waclKeyList).build()).setContents(fileData).build();
    TransactionBody.Builder body = getTransactionBody(payerAccountNum, payerRealmNum, payerShardNum, nodeAccountNum, nodeRealmNum, nodeShardNum, transactionFee, timestamp, transactionDuration, generateRecord, memo);
    body.setFileCreate(fileCreateTransactionBody);
    byte[] bodyBytesArr = body.build().toByteArray();
    ByteString bodyBytes = ByteString.copyFrom(bodyBytesArr);
    return Transaction.newBuilder().setBodyBytes(bodyBytes).build();
}
Also used : FileCreateTransactionBody(com.hederahashgraph.api.proto.java.FileCreateTransactionBody) FileDeleteTransactionBody(com.hederahashgraph.api.proto.java.FileDeleteTransactionBody) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) FileAppendTransactionBody(com.hederahashgraph.api.proto.java.FileAppendTransactionBody) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) CryptoTransferTransactionBody(com.hederahashgraph.api.proto.java.CryptoTransferTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) FileUpdateTransactionBody(com.hederahashgraph.api.proto.java.FileUpdateTransactionBody) FileCreateTransactionBody(com.hederahashgraph.api.proto.java.FileCreateTransactionBody) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) ByteString(com.google.protobuf.ByteString)

Aggregations

ByteString (com.google.protobuf.ByteString)2 FileCreateTransactionBody (com.hederahashgraph.api.proto.java.FileCreateTransactionBody)2 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)2 MoreObjects (com.google.common.base.MoreObjects)1 Files (com.google.common.io.Files)1 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 KeyFactory (com.hedera.services.bdd.spec.keys.KeyFactory)1 KeyGenerator (com.hedera.services.bdd.spec.keys.KeyGenerator)1 SigControl (com.hedera.services.bdd.spec.keys.SigControl)1 HapiTxnOp (com.hedera.services.bdd.spec.transactions.HapiTxnOp)1 TxnFactory (com.hedera.services.bdd.spec.transactions.TxnFactory)1 TxnFactory.bannerWith (com.hedera.services.bdd.spec.transactions.TxnFactory.bannerWith)1 TxnUtils.suFrom (com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom)1 ContractCallTransactionBody (com.hederahashgraph.api.proto.java.ContractCallTransactionBody)1 ContractCreateTransactionBody (com.hederahashgraph.api.proto.java.ContractCreateTransactionBody)1 ContractUpdateTransactionBody (com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody)1 CryptoCreateTransactionBody (com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody)1 CryptoTransferTransactionBody (com.hederahashgraph.api.proto.java.CryptoTransferTransactionBody)1 CryptoUpdateTransactionBody (com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)1 FeeData (com.hederahashgraph.api.proto.java.FeeData)1