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);
}
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));
}
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;
}
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());
}
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());
}
Aggregations