Search in sources :

Example 6 with Transaction

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

the class HapiSpecOperation method finalizedTxn.

protected Transaction finalizedTxn(HapiApiSpec spec, Consumer<TransactionBody.Builder> opDef, boolean forCost) throws Throwable {
    if ((forCost && useDefaultTxnAsCostAnswerPayment) || (!forCost && useDefaultTxnAsAnswerOnlyPayment)) {
        return Transaction.getDefaultInstance();
    }
    Transaction txn;
    Consumer<TransactionBody.Builder> minDef = bodyDef(spec);
    if (usdFee.isPresent()) {
        double centsFee = usdFee.getAsDouble() * 100.0;
        double tinybarFee = centsFee / spec.ratesProvider().rates().getCentEquiv() * spec.ratesProvider().rates().getHbarEquiv() * HapiApiSuite.ONE_HBAR;
        fee = Optional.of((long) tinybarFee);
    }
    Consumer<TransactionBody.Builder> netDef = fee.map(amount -> minDef.andThen(b -> b.setTransactionFee(amount))).orElse(minDef).andThen(opDef);
    setKeyControlOverrides(spec);
    List<Key> keys = signersToUseFor(spec);
    Transaction.Builder builder = spec.txns().getReadyToSign(netDef);
    Transaction provisional = getSigned(spec, builder, keys);
    if (fee.isPresent()) {
        txn = provisional;
    } else {
        Key payerKey = spec.registry().getKey(payer.orElse(spec.setup().defaultPayerName()));
        int numPayerKeys = hardcodedNumPayerKeys.orElse(spec.keys().controlledKeyCount(payerKey, overrides));
        long customFee = feeFor(spec, provisional, numPayerKeys);
        netDef = netDef.andThen(b -> b.setTransactionFee(customFee));
        txn = getSigned(spec, spec.txns().getReadyToSign(netDef), keys);
    }
    return finalizedTxnFromTxnWithBodyBytesAndSigMap(txn);
}
Also used : Arrays(java.util.Arrays) SigControl(com.hedera.services.bdd.spec.keys.SigControl) SignatureMap(com.hederahashgraph.api.proto.java.SignatureMap) Random(java.util.Random) ScheduleOpsUsage(com.hedera.services.usage.schedule.ScheduleOpsUsage) Duration(com.hederahashgraph.api.proto.java.Duration) HapiGetTxnRecord(com.hedera.services.bdd.spec.queries.meta.HapiGetTxnRecord) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) CommonUtils(com.hedera.services.legacy.proto.utils.CommonUtils) FileFeeBuilder(com.hederahashgraph.fee.FileFeeBuilder) Map(java.util.Map) EMPTY_LIST(java.util.Collections.EMPTY_LIST) ConsensusOpsUsage(com.hedera.services.usage.consensus.ConsensusOpsUsage) SigMapGenerator(com.hedera.services.bdd.spec.keys.SigMapGenerator) OpObs(com.hedera.services.bdd.spec.stats.OpObs) ControlForKey(com.hedera.services.bdd.spec.keys.ControlForKey) SmartContractFeeBuilder(com.hederahashgraph.fee.SmartContractFeeBuilder) UUID(java.util.UUID) UtilOp(com.hedera.services.bdd.spec.utilops.UtilOp) ByteString(com.google.protobuf.ByteString) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) Transaction(com.hederahashgraph.api.proto.java.Transaction) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) FeeBuilder(com.hederahashgraph.fee.FeeBuilder) OptionalDouble(java.util.OptionalDouble) HashMap(java.util.HashMap) Function(java.util.function.Function) Supplier(java.util.function.Supplier) NodeConnectInfo(com.hedera.services.bdd.spec.props.NodeConnectInfo) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) AccountID(com.hederahashgraph.api.proto.java.AccountID) MoreObjects(com.google.common.base.MoreObjects) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) HexFormat(java.util.HexFormat) CryptoFeeBuilder(com.hederahashgraph.fee.CryptoFeeBuilder) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) Collectors.toList(java.util.stream.Collectors.toList) FileOpsUsage(com.hedera.services.usage.file.FileOpsUsage) TxnUtils.extractTxnId(com.hedera.services.bdd.spec.transactions.TxnUtils.extractTxnId) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) CryptoOpsUsage(com.hedera.services.usage.crypto.CryptoOpsUsage) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) FileFeeBuilder(com.hederahashgraph.fee.FileFeeBuilder) SmartContractFeeBuilder(com.hederahashgraph.fee.SmartContractFeeBuilder) FeeBuilder(com.hederahashgraph.fee.FeeBuilder) CryptoFeeBuilder(com.hederahashgraph.fee.CryptoFeeBuilder) ControlForKey(com.hedera.services.bdd.spec.keys.ControlForKey) Key(com.hederahashgraph.api.proto.java.Key)

Example 7 with Transaction

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

the class PlatformTxnAccessorTest method hasSpanMap.

@Test
void hasSpanMap() throws InvalidProtocolBufferException {
    // setup:
    Transaction signedTxnWithBody = Transaction.newBuilder().setBodyBytes(someTxn.toByteString()).build();
    SwirldTransaction platformTxn = new SwirldTransaction(signedTxnWithBody.toByteArray());
    // given:
    SignedTxnAccessor subject = new PlatformTxnAccessor(platformTxn);
    // expect:
    assertThat(subject.getSpanMap(), instanceOf(HashMap.class));
}
Also used : SwirldTransaction(com.swirlds.common.SwirldTransaction) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) SwirldTransaction(com.swirlds.common.SwirldTransaction) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 8 with Transaction

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

the class PlatformTxnAccessorTest method usesExtractorToGetFunctionAsExpected.

@Test
void usesExtractorToGetFunctionAsExpected() {
    // setup:
    var memory = SignedTxnAccessor.functionExtractor;
    Function<TransactionBody, HederaFunctionality> mockFn = (Function<TransactionBody, HederaFunctionality>) mock(Function.class);
    SignedTxnAccessor.functionExtractor = mockFn;
    // and:
    someTxn = someTxn.toBuilder().setConsensusCreateTopic(ConsensusCreateTopicTransactionBody.newBuilder()).build();
    Transaction signedTxn = Transaction.newBuilder().setBodyBytes(someTxn.toByteString()).build();
    given(mockFn.apply(any())).willReturn(ConsensusCreateTopic);
    var subject = SignedTxnAccessor.uncheckedFrom(signedTxn);
    // when:
    var first = subject.getFunction();
    var second = subject.getFunction();
    // then:
    assertEquals(ConsensusCreateTopic, first);
    assertEquals(second, first);
    // and:
    verify(mockFn, times(1)).apply(any());
    // cleanup:
    SignedTxnAccessor.functionExtractor = memory;
}
Also used : HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Function(java.util.function.Function) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ConsensusCreateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusCreateTopicTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) SwirldTransaction(com.swirlds.common.SwirldTransaction) Test(org.junit.jupiter.api.Test)

Example 9 with Transaction

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

the class PlatformTxnAccessorTest method getsPayer.

@Test
void getsPayer() throws Exception {
    // given:
    AccountID payer = asAccount("0.0.2");
    Transaction signedTxnWithBody = Transaction.newBuilder().setBodyBytes(someTxn.toByteString()).build();
    SwirldTransaction platformTxn = new SwirldTransaction(signedTxnWithBody.toByteArray());
    // when:
    PlatformTxnAccessor subject = new PlatformTxnAccessor(platformTxn);
    // then:
    assertEquals(payer, subject.getPayer());
}
Also used : SwirldTransaction(com.swirlds.common.SwirldTransaction) AccountID(com.hederahashgraph.api.proto.java.AccountID) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) SwirldTransaction(com.swirlds.common.SwirldTransaction) Test(org.junit.jupiter.api.Test)

Example 10 with Transaction

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

the class PlatformTxnAccessorTest method hasExpectedSignedBytes.

@Test
void hasExpectedSignedBytes() throws InvalidProtocolBufferException {
    // given:
    Transaction signedTxnWithBody = Transaction.newBuilder().setBodyBytes(someTxn.toByteString()).build();
    // when:
    SignedTxnAccessor subject = new SignedTxnAccessor(signedTxnWithBody);
    // then:
    assertArrayEquals(signedTxnWithBody.toByteArray(), subject.getSignedTxnWrapperBytes());
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) SwirldTransaction(com.swirlds.common.SwirldTransaction) Test(org.junit.jupiter.api.Test)

Aggregations

Transaction (com.hederahashgraph.api.proto.java.Transaction)174 Test (org.junit.jupiter.api.Test)128 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)108 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)93 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)91 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)84 SignedTransaction (com.hederahashgraph.api.proto.java.SignedTransaction)63 FileAppendTransactionBody (com.hederahashgraph.api.proto.java.FileAppendTransactionBody)28 FileCreateTransactionBody (com.hederahashgraph.api.proto.java.FileCreateTransactionBody)28 FileUpdateTransactionBody (com.hederahashgraph.api.proto.java.FileUpdateTransactionBody)28 UtilityTest (com.hedera.mirror.importer.util.UtilityTest)26 CryptoUpdateTransactionBody (com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)26 CryptoAddLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody)25 CryptoCreateTransactionBody (com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody)25 CryptoDeleteLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody)25 Entity (com.hedera.mirror.common.domain.entity.Entity)22 TokenTransferList (com.hederahashgraph.api.proto.java.TokenTransferList)21 ContractUpdateTransactionBody (com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody)18 ContractCallTransactionBody (com.hederahashgraph.api.proto.java.ContractCallTransactionBody)17 ContractCreateTransactionBody (com.hederahashgraph.api.proto.java.ContractCreateTransactionBody)17