use of com.hederahashgraph.api.proto.java.Transaction in project hedera-services by hashgraph.
the class PlatformTxnAccessorTest method getsCorrectLoggableForm.
@Test
void getsCorrectLoggableForm() throws Exception {
Transaction signedTxnWithBody = Transaction.newBuilder().setBodyBytes(someTxn.toByteString()).setSigMap(SignatureMap.newBuilder().addSigPair(SignaturePair.newBuilder().setPubKeyPrefix(ByteString.copyFrom("UNREAL".getBytes())).setEd25519(ByteString.copyFrom("FAKE".getBytes())))).build();
SwirldTransaction platformTxn = new SwirldTransaction(signedTxnWithBody.toByteArray());
// when:
PlatformTxnAccessor subject = new PlatformTxnAccessor(platformTxn);
Transaction signedTxn4Log = subject.getSignedTxnWrapper();
Transaction asBodyBytes = signedTxn4Log.toBuilder().setBodyBytes(CommonUtils.extractTransactionBodyByteString(signedTxn4Log)).build();
// then:
assertEquals(someTxn, CommonUtils.extractTransactionBody(signedTxn4Log));
assertEquals(signedTxnWithBody, asBodyBytes);
}
use of com.hederahashgraph.api.proto.java.Transaction in project hedera-services by hashgraph.
the class PlatformTxnAccessorTest method sigMetaGetterSetterCheck.
@Test
void sigMetaGetterSetterCheck() throws InvalidProtocolBufferException {
// setup:
Transaction signedTxnWithBody = Transaction.newBuilder().setBodyBytes(someTxn.toByteString()).build();
SwirldTransaction platformTxn = new SwirldTransaction(signedTxnWithBody.toByteArray());
// given:
SignedTxnAccessor subject = new PlatformTxnAccessor(platformTxn);
// when:
subject.setSigMeta(RationalizedSigMeta.noneAvailable());
// then:
assertSame(RationalizedSigMeta.noneAvailable(), subject.getSigMeta());
}
use of com.hederahashgraph.api.proto.java.Transaction in project hedera-services by hashgraph.
the class PlatformTxnAccessorTest method failsOnInvalidTxn.
@Test
void failsOnInvalidTxn() {
// given:
Transaction signedNonsenseTxn = Transaction.newBuilder().setBodyBytes(ByteString.copyFrom(NONSENSE)).build();
// and:
SwirldTransaction platformTxn = new SwirldTransaction(signedNonsenseTxn.toByteArray());
// expect:
assertThrows(InvalidProtocolBufferException.class, () -> new PlatformTxnAccessor(platformTxn));
}
use of com.hederahashgraph.api.proto.java.Transaction in project hedera-services by hashgraph.
the class PlatformTxnAccessorTest method allowsUncheckedConstruction.
@Test
void allowsUncheckedConstruction() {
// setup:
Transaction validTxn = Transaction.getDefaultInstance();
// expect:
assertDoesNotThrow(() -> SignedTxnAccessor.uncheckedFrom(validTxn));
}
use of com.hederahashgraph.api.proto.java.Transaction in project hedera-services by hashgraph.
the class HapiTokenUpdate method feeFor.
@Override
protected long feeFor(HapiApiSpec spec, Transaction txn, int numPayerKeys) throws Throwable {
try {
final TokenInfo info = HapiTokenFeeScheduleUpdate.lookupInfo(spec, token, log, loggingOff);
FeeCalculator.ActivityMetrics metricsCalc = (_txn, svo) -> {
var estimate = TokenUpdateUsage.newEstimate(_txn, suFrom(svo));
estimate.givenCurrentExpiry(info.getExpiry().getSeconds()).givenCurrentMemo(info.getMemo()).givenCurrentName(info.getName()).givenCurrentSymbol(info.getSymbol());
if (info.hasFreezeKey()) {
estimate.givenCurrentFreezeKey(Optional.of(info.getFreezeKey()));
}
if (info.hasAdminKey()) {
estimate.givenCurrentAdminKey(Optional.of(info.getAdminKey()));
}
if (info.hasSupplyKey()) {
estimate.givenCurrentSupplyKey(Optional.of(info.getSupplyKey()));
}
if (info.hasKycKey()) {
estimate.givenCurrentKycKey(Optional.of(info.getKycKey()));
}
if (info.hasWipeKey()) {
estimate.givenCurrentWipeKey(Optional.of(info.getWipeKey()));
}
if (info.hasFeeScheduleKey()) {
estimate.givenCurrentFeeScheduleKey(Optional.of(info.getFeeScheduleKey()));
}
if (info.hasPauseKey()) {
estimate.givenCurrentPauseKey(Optional.of(info.getPauseKey()));
}
if (info.hasAutoRenewAccount()) {
estimate.givenCurrentlyUsingAutoRenewAccount();
}
return estimate.get();
};
return spec.fees().forActivityBasedOp(HederaFunctionality.TokenUpdate, metricsCalc, txn, numPayerKeys);
} catch (Throwable t) {
log.warn("Couldn't estimate usage", t);
return HapiApiSuite.ONE_HBAR;
}
}
Aggregations