use of com.hederahashgraph.api.proto.java.AccountID in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerCryptoTest method groupCryptoTransfersByAccountId.
private void groupCryptoTransfersByAccountId(TransactionRecord.Builder recordBuilder, List<AccountAmount.Builder> amountsToBeAdded) {
var accountAmounts = recordBuilder.getTransferListBuilder().getAccountAmountsBuilderList();
var transfers = new HashMap<AccountID, Long>();
Stream.concat(accountAmounts.stream(), amountsToBeAdded.stream()).forEach(accountAmount -> transfers.compute(accountAmount.getAccountID(), (k, v) -> {
long currentValue = (v == null) ? 0 : v;
return currentValue + accountAmount.getAmount();
}));
TransferList.Builder transferListBuilder = TransferList.newBuilder();
transfers.entrySet().forEach(entry -> {
AccountAmount accountAmount = AccountAmount.newBuilder().setAccountID(entry.getKey()).setAmount(entry.getValue()).build();
transferListBuilder.addAccountAmounts(accountAmount);
});
recordBuilder.setTransferList(transferListBuilder);
}
use of com.hederahashgraph.api.proto.java.AccountID in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerCryptoTest method cryptoDeleteAllowance.
@Test
void cryptoDeleteAllowance() {
// given
var delegatingSpender = EntityId.of(recordItemBuilder.accountId());
var ownerAccountId = EntityId.of(recordItemBuilder.accountId());
var spender1 = EntityId.of(recordItemBuilder.accountId());
var spender2 = EntityId.of(recordItemBuilder.accountId());
var tokenId1 = EntityId.of(recordItemBuilder.tokenId());
var tokenId2 = EntityId.of(recordItemBuilder.tokenId());
List<NftRemoveAllowance> nftRemoveAllowances = List.of(NftRemoveAllowance.newBuilder().setOwner(AccountID.newBuilder().setAccountNum(ownerAccountId.getEntityNum())).setTokenId(TokenID.newBuilder().setTokenNum(tokenId1.getEntityNum())).addSerialNumbers(1L).addSerialNumbers(2L).build(), NftRemoveAllowance.newBuilder().setOwner(AccountID.newBuilder().setAccountNum(ownerAccountId.getEntityNum())).setTokenId(TokenID.newBuilder().setTokenNum(tokenId2.getEntityNum())).addSerialNumbers(1L).addSerialNumbers(2L).addSerialNumbers(2L).build());
RecordItem recordItem = recordItemBuilder.cryptoDeleteAllowance().transactionBody(b -> b.clearNftAllowances().addAllNftAllowances(nftRemoveAllowances)).build();
var nft1 = Nft.builder().accountId(ownerAccountId).createdTimestamp(10L).deleted(false).id(new NftId(1L, tokenId1)).modifiedTimestamp(recordItem.getConsensusTimestamp()).build();
var nft2 = Nft.builder().accountId(ownerAccountId).createdTimestamp(11L).deleted(false).id(new NftId(2L, tokenId1)).modifiedTimestamp(recordItem.getConsensusTimestamp()).build();
var nft3 = Nft.builder().accountId(ownerAccountId).createdTimestamp(12L).deleted(false).id(new NftId(1L, tokenId2)).modifiedTimestamp(recordItem.getConsensusTimestamp()).build();
var nft4 = Nft.builder().accountId(ownerAccountId).createdTimestamp(13L).deleted(false).id(new NftId(2L, tokenId2)).modifiedTimestamp(recordItem.getConsensusTimestamp()).build();
List<Nft> nftsWithAllowance = Stream.of(nft1.toBuilder().delegatingSpender(delegatingSpender).modifiedTimestamp(15L).spender(spender1), nft2.toBuilder().modifiedTimestamp(16L).spender(spender2), nft3.toBuilder().modifiedTimestamp(17L).spender(spender1), nft4.toBuilder().modifiedTimestamp(18L).spender(spender2)).map(Nft.NftBuilder::build).collect(Collectors.toList());
nftRepository.saveAll(nftsWithAllowance);
// when
parseRecordItemAndCommit(recordItem);
// then
assertAll(() -> assertEquals(0, entityRepository.count()), () -> assertTransactionAndRecord(recordItem.getTransactionBody(), recordItem.getRecord()), () -> assertThat(nftRepository.findAll()).containsExactlyInAnyOrder(nft1, nft2, nft3, nft4));
}
use of com.hederahashgraph.api.proto.java.AccountID 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.AccountID in project hedera-mirror-node by hashgraph.
the class ContractCreateTransactionHandlerTest method updateTransactionStakedAccountId.
@Test
void updateTransactionStakedAccountId() {
// given
final AccountID accountID = AccountID.newBuilder().setAccountNum(1L).build();
var recordItem = recordItemBuilder.contractCreate().transactionBody(b -> b.clearAutoRenewAccountId().setDeclineReward(false).setStakedAccountId(accountID)).build();
// when
transactionHandler.updateTransaction(transaction(recordItem), recordItem);
// then
verify(entityListener).onContract(contracts.capture());
assertThat(contracts.getValue()).isNotNull().returns(false, Contract::isDeclineReward).returns(accountID.getAccountNum(), Contract::getStakedAccountId).returns(-1L, Contract::getStakedNodeId).returns(Utility.getEpochDay(recordItem.getConsensusTimestamp()), Contract::getStakePeriodStart);
}
use of com.hederahashgraph.api.proto.java.AccountID in project hedera-mirror-node by hashgraph.
the class ContractUpdateTransactionHandlerTest method updateTransactionStakedAccountId.
@Test
void updateTransactionStakedAccountId() {
AccountID accountId = AccountID.newBuilder().setAccountNum(1L).build();
RecordItem withStakedNodeIdSet = recordItemBuilder.contractUpdate().transactionBody(body -> body.clear().setStakedAccountId(accountId)).build();
setupForContractUpdateTransactionTest(withStakedNodeIdSet, t -> assertThat(t).returns(1L, Contract::getStakedAccountId).returns(false, Contract::isDeclineReward).returns(-1L, Contract::getStakedNodeId).returns(Utility.getEpochDay(withStakedNodeIdSet.getConsensusTimestamp()), Contract::getStakePeriodStart));
}
Aggregations