use of com.hederahashgraph.api.proto.java.AccountAmount in project hedera-services by hashgraph.
the class RequestBuilder method getCryptoTransferRequest.
public static Transaction getCryptoTransferRequest(Long payerAccountNum, Long payerRealmNum, Long payerShardNum, Long nodeAccountNum, Long nodeRealmNum, Long nodeShardNum, long transactionFee, Timestamp timestamp, Duration transactionDuration, boolean generateRecord, String memo, Long senderActNum, Long amountSend, Long receiverAcctNum, Long amountReceived) {
AccountAmount a1 = AccountAmount.newBuilder().setAccountID(getAccountIdBuild(senderActNum, 0l, 0l)).setAmount(amountSend).build();
AccountAmount a2 = AccountAmount.newBuilder().setAccountID(getAccountIdBuild(receiverAcctNum, 0l, 0l)).setAmount(amountReceived).build();
TransferList transferList = TransferList.newBuilder().addAccountAmounts(a1).addAccountAmounts(a2).build();
return getCryptoTransferRequest(payerAccountNum, payerRealmNum, payerShardNum, nodeAccountNum, nodeRealmNum, nodeShardNum, transactionFee, timestamp, transactionDuration, generateRecord, memo, transferList);
}
use of com.hederahashgraph.api.proto.java.AccountAmount in project hedera-services by hashgraph.
the class SigRequirements method cryptoTransfer.
private <T> SigningOrderResult<T> cryptoTransfer(final AccountID payer, final CryptoTransferTransactionBody op, final SigningOrderResultFactory<T> factory, @Nullable final LinkedRefs linkedRefs) {
List<JKey> required = new ArrayList<>();
KeyOrderingFailure failure;
for (TokenTransferList xfers : op.getTokenTransfersList()) {
for (AccountAmount adjust : xfers.getTransfersList()) {
if ((failure = includeIfNecessary(payer, adjust, required, false, linkedRefs)) != NONE) {
return accountFailure(failure, factory);
}
}
final var token = xfers.getToken();
for (NftTransfer adjust : xfers.getNftTransfersList()) {
final var sender = adjust.getSenderAccountID();
if ((failure = nftIncludeIfNecessary(payer, sender, null, adjust.getIsApproval(), required, token, op, linkedRefs)) != NONE) {
return accountFailure(failure, factory);
}
final var receiver = adjust.getReceiverAccountID();
if ((failure = nftIncludeIfNecessary(payer, receiver, sender, false, required, token, op, linkedRefs)) != NONE) {
return (failure == MISSING_TOKEN) ? factory.forMissingToken() : accountFailure(failure, factory);
}
}
}
for (AccountAmount adjust : op.getTransfers().getAccountAmountsList()) {
if ((failure = includeIfNecessary(payer, adjust, required, true, linkedRefs)) != NONE) {
return accountFailure(failure, factory);
}
}
return factory.forValidOrder(required);
}
use of com.hederahashgraph.api.proto.java.AccountAmount in project hedera-services by hashgraph.
the class AliasResolver method resolveInternalFungible.
private Result resolveInternalFungible(final AliasManager aliasManager, final AccountAmount adjust, final Consumer<AccountAmount> resolvingAction) {
AccountAmount resolvedAdjust = adjust;
var isEvmAddress = false;
var result = Result.KNOWN_ALIAS;
if (isAlias(adjust.getAccountID())) {
final var alias = adjust.getAccountID().getAlias();
if (alias.size() == EntityIdUtils.EVM_ADDRESS_SIZE) {
final var evmAddress = alias.toByteArray();
if (aliasManager.isMirror(evmAddress)) {
offerMirrorId(evmAddress, id -> resolvingAction.accept(adjust.toBuilder().setAccountID(id).build()));
return Result.KNOWN_ALIAS;
} else {
isEvmAddress = true;
}
}
final var resolution = aliasManager.lookupIdBy(alias);
if (resolution == MISSING_NUM) {
result = netOf(isEvmAddress, alias);
} else {
resolvedAdjust = adjust.toBuilder().setAccountID(resolution.toGrpcAccountId()).build();
}
resolutions.put(alias, resolution);
}
resolvingAction.accept(resolvedAdjust);
return result;
}
use of com.hederahashgraph.api.proto.java.AccountAmount in project hedera-services by hashgraph.
the class HapiCryptoTransfer method aggregateOnTokenIds.
private Map<TokenID, Pair<Integer, List<AccountAmount>>> aggregateOnTokenIds(final HapiApiSpec spec) {
Map<TokenID, Pair<Integer, List<AccountAmount>>> map = new HashMap<>();
for (TokenMovement tm : tokenAwareProviders) {
if (tm.isFungibleToken()) {
var list = tm.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(), newList));
} else {
map.put(list.getToken(), Pair.of(list.getExpectedDecimals().getValue(), list.getTransfersList()));
}
}
}
return map;
}
use of com.hederahashgraph.api.proto.java.AccountAmount in project hedera-services by hashgraph.
the class TokenAssociationSpecs method dissociationFromExpiredTokensAsExpected.
public HapiApiSpec dissociationFromExpiredTokensAsExpected() {
final String treasury = "accountA";
final String frozenAccount = "frozen";
final String unfrozenAccount = "unfrozen";
final String expiringToken = "expiringToken";
long lifetimeSecs = 10;
AtomicLong now = new AtomicLong();
return defaultHapiSpec("DissociationFromExpiredTokensAsExpected").given(newKeyNamed("freezeKey"), cryptoCreate(treasury), cryptoCreate(frozenAccount).via("creation"), cryptoCreate(unfrozenAccount).via("creation"), withOpContext((spec, opLog) -> {
var subOp = getTxnRecord("creation");
allRunFor(spec, subOp);
var record = subOp.getResponseRecord();
now.set(record.getConsensusTimestamp().getSeconds());
}), sourcing(() -> tokenCreate(expiringToken).freezeKey("freezeKey").freezeDefault(true).treasury(treasury).initialSupply(1000L).expiry(now.get() + lifetimeSecs))).when(tokenAssociate(unfrozenAccount, expiringToken), tokenAssociate(frozenAccount, expiringToken), tokenUnfreeze(expiringToken, unfrozenAccount), cryptoTransfer(moving(100L, expiringToken).between(treasury, unfrozenAccount))).then(getAccountBalance(treasury).hasTokenBalance(expiringToken, 900L), sleepFor(lifetimeSecs * 1_000L), tokenDissociate(treasury, expiringToken).hasKnownStatus(ACCOUNT_IS_TREASURY), tokenDissociate(unfrozenAccount, expiringToken).via("dissociateTxn"), getTxnRecord("dissociateTxn").hasPriority(recordWith().tokenTransfers(new BaseErroringAssertsProvider<>() {
@Override
public ErroringAsserts<List<TokenTransferList>> assertsFor(HapiApiSpec spec) {
return tokenXfers -> {
try {
assertEquals(1, tokenXfers.size(), "Wrong number of tokens transferred!");
TokenTransferList xfers = tokenXfers.get(0);
assertEquals(spec.registry().getTokenID(expiringToken), xfers.getToken(), "Wrong token transferred!");
AccountAmount toTreasury = xfers.getTransfers(0);
assertEquals(spec.registry().getAccountID(treasury), toTreasury.getAccountID(), "Treasury should come first!");
assertEquals(100L, toTreasury.getAmount(), "Treasury should get 100 tokens back!");
AccountAmount fromAccount = xfers.getTransfers(1);
assertEquals(spec.registry().getAccountID(unfrozenAccount), fromAccount.getAccountID(), "Account should come second!");
assertEquals(-100L, fromAccount.getAmount(), "Account should send 100 tokens back!");
} catch (Throwable error) {
return List.of(error);
}
return Collections.emptyList();
};
}
})), getAccountBalance(treasury).hasTokenBalance(expiringToken, 1000L), getAccountInfo(frozenAccount).hasToken(relationshipWith(expiringToken).freeze(Frozen)), tokenDissociate(frozenAccount, expiringToken).hasKnownStatus(ACCOUNT_FROZEN_FOR_TOKEN));
}
Aggregations