use of com.hederahashgraph.api.proto.java.AccountAmount in project hedera-services by hashgraph.
the class UsageBasedFeeCalculator method estimatedNonFeePayerAdjustments.
@Override
public long estimatedNonFeePayerAdjustments(TxnAccessor accessor, Timestamp at) {
switch(accessor.getFunction()) {
case CryptoCreate:
var cryptoCreateOp = accessor.getTxn().getCryptoCreateAccount();
return -cryptoCreateOp.getInitialBalance();
case CryptoTransfer:
var payer = accessor.getPayer();
var cryptoTransferOp = accessor.getTxn().getCryptoTransfer();
var adjustments = cryptoTransferOp.getTransfers().getAccountAmountsList();
long cryptoTransferNet = 0L;
for (AccountAmount adjustment : adjustments) {
if (payer.equals(adjustment.getAccountID())) {
cryptoTransferNet += adjustment.getAmount();
}
}
return cryptoTransferNet;
case ContractCreate:
var contractCreateOp = accessor.getTxn().getContractCreateInstance();
return -contractCreateOp.getInitialBalance() - contractCreateOp.getGas() * estimatedGasPriceInTinybars(ContractCreate, at);
case ContractCall:
var contractCallOp = accessor.getTxn().getContractCall();
return -contractCallOp.getAmount() - contractCallOp.getGas() * estimatedGasPriceInTinybars(ContractCall, at);
default:
return 0L;
}
}
use of com.hederahashgraph.api.proto.java.AccountAmount in project hedera-services by hashgraph.
the class UtilVerbs method validateTransferListForBalances.
public static HapiSpecOperation validateTransferListForBalances(List<String> txns, List<String> accounts, Set<String> wereDeleted) {
return assertionsHold((spec, assertLog) -> {
Map<String, Long> actualBalances = accounts.stream().collect(Collectors.toMap((String account) -> asAccountString(spec.registry().getAccountID(account)), (String account) -> {
if (wereDeleted.contains(account)) {
return 0L;
}
long balance = -1L;
try {
BalanceSnapshot preOp = balanceSnapshot("x", account);
allRunFor(spec, preOp);
balance = spec.registry().getBalanceSnapshot("x");
} catch (Throwable ignore) {
}
return balance;
}));
List<AccountAmount> transfers = new ArrayList<>();
for (String txn : txns) {
HapiGetTxnRecord subOp = getTxnRecord(txn).logged().payingWith(EXCHANGE_RATE_CONTROL);
allRunFor(spec, subOp);
TransactionRecord record = subOp.getResponse().getTransactionGetRecord().getTransactionRecord();
transfers.addAll(record.getTransferList().getAccountAmountsList());
}
Map<String, Long> changes = changesAccordingTo(transfers);
assertLog.info("Balance changes according to transfer list: " + changes);
changes.entrySet().forEach(change -> {
String account = change.getKey();
long oldBalance = -1L;
/* The account/contract may have just been created, no snapshot was taken. */
try {
oldBalance = spec.registry().getBalanceSnapshot(account + "Snapshot");
} catch (Throwable ignore) {
}
long expectedBalance = change.getValue() + Math.max(0L, oldBalance);
long actualBalance = actualBalances.getOrDefault(account, -1L);
assertLog.info("Balance of " + account + " was expected to be " + expectedBalance + ", is actually " + actualBalance + "...");
Assertions.assertEquals(expectedBalance, actualBalance, "New balance for " + account + " should be " + expectedBalance + " tinyBars.");
});
});
}
use of com.hederahashgraph.api.proto.java.AccountAmount in project hedera-mirror-node by hashgraph.
the class PubSubMessageTest method testSerializationAllFieldsSet.
@Test
void testSerializationAllFieldsSet() throws Exception {
Iterable<AccountAmount> nonFeeTransfers = Lists.newArrayList(AccountAmount.newBuilder().setAccountID(ACCOUNT_ID).setAmount(INT64_VALUE).build(), AccountAmount.newBuilder().setAccountID(ACCOUNT_ID).setAmount(INT64_VALUE).build());
PubSubMessage pubSubMessage = new PubSubMessage(DEFAULT_TIMESTAMP_LONG, EntityId.of(TOPIC_ID), 10, new PubSubMessage.Transaction(getTransactionBody(), getSignatureMap()), getTransactionRecord(), nonFeeTransfers);
ObjectMapper objectMapper = new ObjectMapper();
String actual = objectMapper.writeValueAsString(pubSubMessage);
String expected = "{" + " \"consensusTimestamp\" : 123456789," + " \"entity\" : {" + " \"shardNum\" : 0," + " \"realmNum\" : 0," + " \"entityNum\" : 20," + " \"type\" : 4" + " }," + " \"transactionType\" : 10," + getExpectedTransactionJson() + "," + getExpectedTransactionRecord() + "," + " \"nonFeeTransfers\" : [ {" + " \"accountID\": {" + " \"shardNum\": \"0\"," + " \"realmNum\": \"0\"," + " \"accountNum\": \"10\"" + " }," + " \"amount\": \"100000000\"," + " \"isApproval\": false" + " }, {" + " \"accountID\": {" + " \"shardNum\": \"0\"," + " \"realmNum\": \"0\"," + " \"accountNum\": \"10\"" + " }," + " \"amount\": \"100000000\"," + " \"isApproval\": false" + " } ]" + "}";
JSONAssert.assertEquals(expected, actual, true);
}
Aggregations