use of com.hedera.services.ledger.accounts.HederaAccountCustomizer in project hedera-services by hashgraph.
the class HederaLedgerLiveTest method showsInconsistentStateIfSpawnFails.
@Test
void showsInconsistentStateIfSpawnFails() {
subject.begin();
subject.create(genesis, 1_000L, new HederaAccountCustomizer().memo("a"));
subject.commit();
ids.reclaimLastId();
liveSideEffects.reset();
subject.begin();
final var customizer = new HederaAccountCustomizer().memo("a");
assertThrows(IllegalArgumentException.class, () -> subject.create(genesis, 1_000L, customizer));
}
use of com.hedera.services.ledger.accounts.HederaAccountCustomizer in project hedera-services by hashgraph.
the class SmartContractRequestHandler method systemUndelete.
/**
* System account undoes the deletion marker on a smart contract that has been deleted but
* not yet removed.
*
* @param txBody
* API reuest to undelete the contract
* @param consensusTimestamp
* Platform consensus time
* @return Details of contract undeletion result
*/
public TransactionRecord systemUndelete(TransactionBody txBody, Instant consensusTimestamp) {
SystemUndeleteTransactionBody op = txBody.getSystemUndelete();
ContractID cid = op.getContractID();
var entity = EntityId.fromGrpcContractId(cid);
TransactionReceipt receipt = getTransactionReceipt(SUCCESS, exchange.activeRates());
long oldExpiry = 0;
try {
if (entityExpiries.containsKey(entity)) {
oldExpiry = entityExpiries.get(entity);
} else {
receipt = getTransactionReceipt(INVALID_FILE_ID, exchange.activeRates());
}
if (oldExpiry > 0) {
HederaAccountCustomizer customizer = new HederaAccountCustomizer().expiry(oldExpiry);
ledger.customizePotentiallyDeleted(asAccount(cid), customizer);
}
if (receipt.getStatus() == SUCCESS) {
try {
receipt = updateDeleteFlag(cid, false);
} catch (Exception e) {
receipt = getTransactionReceipt(FAIL_INVALID, exchange.activeRates());
if (log.isDebugEnabled()) {
log.debug("systemUndelete exception: can't serialize or deserialize! tx= {} {}", txBody, e);
}
}
}
entityExpiries.remove(entity);
} catch (Exception e) {
log.warn("Unhandled exception in SystemUndelete", e);
log.debug("File System Exception {} tx= {}", () -> e, () -> TextFormat.shortDebugString(op));
receipt = getTransactionReceipt(FILE_SYSTEM_EXCEPTION, exchange.activeRates());
}
TransactionRecord.Builder transactionRecord = getTransactionRecord(txBody.getTransactionFee(), txBody.getMemo(), txBody.getTransactionID(), getTimestamp(consensusTimestamp), receipt);
return transactionRecord.build();
}
use of com.hedera.services.ledger.accounts.HederaAccountCustomizer in project hedera-services by hashgraph.
the class SmartContractRequestHandler method systemDelete.
/**
* System account deletes any contract. This simply marks the contract as deleted.
*
* @param txBody
* API request to delete the contract
* @param consensusTimestamp
* Platform consensus time
* @return Details of contract deletion result
*/
public TransactionRecord systemDelete(TransactionBody txBody, Instant consensusTimestamp) {
SystemDeleteTransactionBody op = txBody.getSystemDelete();
ContractID cid = op.getContractID();
long newExpiry = op.getExpirationTime().getSeconds();
TransactionReceipt receipt;
receipt = updateDeleteFlag(cid, true);
try {
if (receipt.getStatus().equals(ResponseCodeEnum.SUCCESS)) {
AccountID id = asAccount(cid);
long oldExpiry = ledger.expiry(id);
var entity = EntityId.fromGrpcContractId(cid);
entityExpiries.put(entity, oldExpiry);
HederaAccountCustomizer customizer = new HederaAccountCustomizer().expiry(newExpiry);
ledger.customizePotentiallyDeleted(id, customizer);
}
} catch (Exception e) {
log.warn("Unhandled exception in SystemDelete", e);
log.debug("File System Exception {} tx= {}", () -> e, () -> TextFormat.shortDebugString(op));
receipt = getTransactionReceipt(ResponseCodeEnum.FILE_SYSTEM_EXCEPTION, exchange.activeRates());
}
TransactionRecord.Builder transactionRecord = getTransactionRecord(txBody.getTransactionFee(), txBody.getMemo(), txBody.getTransactionID(), getTimestamp(consensusTimestamp), receipt);
return transactionRecord.build();
}
use of com.hedera.services.ledger.accounts.HederaAccountCustomizer in project hedera-services by hashgraph.
the class MutableEntityAccessTest method customizesAccount.
@Test
void customizesAccount() {
// when:
subject.customize(id, new HederaAccountCustomizer());
// then:
verify(ledger).customizePotentiallyDeleted(eq(id), any());
}
use of com.hedera.services.ledger.accounts.HederaAccountCustomizer in project hedera-services by hashgraph.
the class HederaWorldStateTest method usesContractKeyWhenSponsorDid.
@Test
void usesContractKeyWhenSponsorDid() {
final var sponsorId = AccountID.newBuilder().setAccountNum(123L).build();
final var sponsoredId = AccountID.newBuilder().setAccountNum(321L).build();
final var sponsorAddress = EntityIdUtils.asEvmAddress(sponsorId);
final var sponsoredAddress = EntityIdUtils.asEvmAddress(sponsoredId);
givenNonNullWorldLedgers();
given(entityAccess.isExtant(any())).willReturn(true);
given(entityAccess.getKey(sponsorId)).willReturn(new JContractIDKey(0, 0, 123L));
final var updater = subject.updater();
updater.getSponsorMap().put(Address.fromHexString(Hex.encodeHexString(sponsoredAddress)), Address.fromHexString(Hex.encodeHexString(sponsorAddress)));
final ArgumentCaptor<HederaAccountCustomizer> captor = forClass(HederaAccountCustomizer.class);
updater.commit();
subject.customizeSponsoredAccounts();
verify(entityAccess).customize(eq(sponsoredId), captor.capture());
final var customizer = captor.getValue();
final var standin = new MerkleAccount();
customizer.customizing(standin);
final var key = standin.getAccountKey();
assertInstanceOf(JContractIDKey.class, key);
assertEquals(sponsoredId.getAccountNum(), ((JContractIDKey) key).getContractID().getContractNum());
}
Aggregations