use of com.hederahashgraph.api.proto.java.TokenID in project hedera-services by hashgraph.
the class HapiCryptoTransfer method fullyAggregateTokenTransfersList.
private Map<TokenID, Pair<Integer, List<AccountAmount>>> fullyAggregateTokenTransfersList(final HapiApiSpec spec) {
Map<TokenID, Pair<Integer, List<AccountAmount>>> map = new HashMap<>();
for (TokenMovement xfer : tokenAwareProviders) {
if (xfer.isFungibleToken()) {
var list = xfer.specializedFor(spec);
if (map.containsKey(list.getToken())) {
var existingVal = map.get(list.getToken());
List<AccountAmount> newList = Stream.of(existingVal.getRight(), list.getTransfersList()).flatMap(Collection::stream).collect(Collectors.toList());
map.put(list.getToken(), Pair.of(existingVal.getLeft(), aggregateTransfers(newList)));
} else {
map.put(list.getToken(), Pair.of(list.getExpectedDecimals().getValue(), aggregateTransfers(list.getTransfersList())));
}
}
}
return map;
}
use of com.hederahashgraph.api.proto.java.TokenID in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerTokenTest method tokenTransfersMustHaveCorrectIsApprovalValue.
@Test
void tokenTransfersMustHaveCorrectIsApprovalValue() {
// given
createAndAssociateToken(TOKEN_ID, FUNGIBLE_COMMON, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, INITIAL_SUPPLY);
TokenID tokenId2 = TokenID.newBuilder().setTokenNum(7).build();
createTokenEntity(tokenId2, FUNGIBLE_COMMON, "MIRROR", 10L, false, false, false);
AccountID accountId = AccountID.newBuilder().setAccountNum(1).build();
TokenTransferList transferList1 = TokenTransferList.newBuilder().setToken(TOKEN_ID).addTransfers(AccountAmount.newBuilder().setAccountID(PAYER).setAmount(-1000).build()).addTransfers(AccountAmount.newBuilder().setAccountID(PAYER2).setAmount(-100).build()).addTransfers(AccountAmount.newBuilder().setAccountID(accountId).setAmount(1000).build()).build();
TokenTransferList transferList2 = TokenTransferList.newBuilder().setToken(tokenId2).addTransfers(AccountAmount.newBuilder().setAccountID(PAYER).setAmount(333).build()).addTransfers(AccountAmount.newBuilder().setAccountID(accountId).setAmount(-333).build()).build();
List<TokenTransferList> transferLists = List.of(transferList1, transferList2);
// when
Transaction transaction = buildTransaction(builder -> {
TokenTransferList bodyTransferList1 = TokenTransferList.newBuilder().setToken(TOKEN_ID).addTransfers(AccountAmount.newBuilder().setAccountID(PAYER).setAmount(-600).setIsApproval(true).build()).addTransfers(AccountAmount.newBuilder().setAccountID(PAYER2).setAmount(-100).setIsApproval(true).build()).addTransfers(AccountAmount.newBuilder().setAccountID(accountId).setAmount(-333).build()).build();
builder.getCryptoTransferBuilder().addTokenTransfers(bodyTransferList1);
});
insertAndParseTransaction(TRANSFER_TIMESTAMP, transaction, builder -> {
builder.addAllTokenTransferLists(transferLists);
});
// then
assertTokenTransferInRepository(TOKEN_ID, PAYER, TRANSFER_TIMESTAMP, -1000, true);
assertTokenTransferInRepository(TOKEN_ID, PAYER2, TRANSFER_TIMESTAMP, -100, true);
assertTokenTransferInRepository(TOKEN_ID, accountId, TRANSFER_TIMESTAMP, 1000);
assertTokenTransferInRepository(tokenId2, PAYER, TRANSFER_TIMESTAMP, 333);
assertTokenTransferInRepository(tokenId2, accountId, TRANSFER_TIMESTAMP, -333);
}
use of com.hederahashgraph.api.proto.java.TokenID in project hedera-mirror-node by hashgraph.
the class TokenUpdateTransactionHandlerTest method updateTransactionWithAliasNotFoundAndPartialDataActionSkip.
@Test
void updateTransactionWithAliasNotFoundAndPartialDataActionSkip() {
recordParserProperties.setPartialDataAction(PartialDataAction.SKIP);
var alias = DomainUtils.fromBytes(domainBuilder.key());
var recordItem = recordItemBuilder.tokenUpdate().transactionBody(b -> b.getAutoRenewAccountBuilder().setAlias(alias)).build();
var tokenId = EntityId.of(recordItem.getTransactionBody().getTokenUpdate().getToken());
var timestamp = recordItem.getConsensusTimestamp();
var transaction = domainBuilder.transaction().customize(t -> t.consensusTimestamp(timestamp).entityId(tokenId)).get();
when(entityIdService.lookup(AccountID.newBuilder().setAlias(alias).build())).thenThrow(new AliasNotFoundException("alias", ACCOUNT));
transactionHandler.updateTransaction(transaction, recordItem);
assertTokenUpdate(timestamp, tokenId, Assertions::assertNull);
}
use of com.hederahashgraph.api.proto.java.TokenID in project hedera-mirror-node by hashgraph.
the class TokenUpdateTransactionHandlerTest method updateTransactionThrowsWithAliasNotFound.
@ParameterizedTest(name = "{0}")
@EnumSource(value = PartialDataAction.class, names = { "DEFAULT", "ERROR" })
void updateTransactionThrowsWithAliasNotFound(PartialDataAction partialDataAction) {
// given
recordParserProperties.setPartialDataAction(partialDataAction);
var alias = DomainUtils.fromBytes(domainBuilder.key());
var recordItem = recordItemBuilder.tokenUpdate().transactionBody(b -> b.getAutoRenewAccountBuilder().setAlias(alias)).build();
var tokenId = EntityId.of(recordItem.getTransactionBody().getTokenUpdate().getToken());
var timestamp = recordItem.getConsensusTimestamp();
var transaction = domainBuilder.transaction().customize(t -> t.consensusTimestamp(timestamp).entityId(tokenId)).get();
when(entityIdService.lookup(AccountID.newBuilder().setAlias(alias).build())).thenThrow(new AliasNotFoundException("alias", ACCOUNT));
// when, then
assertThrows(AliasNotFoundException.class, () -> transactionHandler.updateTransaction(transaction, recordItem));
}
use of com.hederahashgraph.api.proto.java.TokenID in project hedera-mirror-node by hashgraph.
the class TokenUpdateTransactionHandlerTest method updateTreasury.
@Test
void updateTreasury() {
AbstractEntity entity = getExpectedUpdatedEntity();
AccountID previousAccountId = AccountID.newBuilder().setAccountNum(1L).build();
AccountID newAccountId = AccountID.newBuilder().setAccountNum(2L).build();
TokenID tokenID = TokenID.newBuilder().setTokenNum(3L).build();
long consensusTimestamp = DomainUtils.timestampInNanosMax(MODIFIED_TIMESTAMP);
TokenTransferList tokenTransferList = TokenTransferList.newBuilder().setToken(tokenID).addNftTransfers(NftTransfer.newBuilder().setReceiverAccountID(newAccountId).setSenderAccountID(previousAccountId).setSerialNumber(NftTransferId.WILDCARD_SERIAL_NUMBER).build()).build();
TransactionRecord record = getDefaultTransactionRecord().addTokenTransferLists(tokenTransferList).build();
RecordItem recordItem = getRecordItem(getDefaultTransactionBody().build(), record);
when(entityIdService.lookup(AccountID.newBuilder().setAccountNum(DEFAULT_AUTO_RENEW_ACCOUNT_NUM).build())).thenReturn(EntityIdEndec.decode(DEFAULT_AUTO_RENEW_ACCOUNT_NUM, EntityType.ACCOUNT));
Transaction transaction = new Transaction();
transaction.setEntityId(entity.toEntityId());
transactionHandler.updateTransaction(transaction, recordItem);
TransactionBody body = recordItem.getTransactionBody();
var payerAccount = EntityId.of(body.getTransactionID().getAccountID()).toEntity().getId();
verify(nftRepository).updateTreasury(tokenID.getTokenNum(), previousAccountId.getAccountNum(), newAccountId.getAccountNum(), consensusTimestamp, payerAccount, false);
}
Aggregations