Search in sources :

Example 1 with HederaAccountCustomizer

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));
}
Also used : HederaAccountCustomizer(com.hedera.services.ledger.accounts.HederaAccountCustomizer) Test(org.junit.jupiter.api.Test)

Example 2 with HederaAccountCustomizer

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();
}
Also used : SystemUndeleteTransactionBody(com.hederahashgraph.api.proto.java.SystemUndeleteTransactionBody) RequestBuilder.getTransactionReceipt(com.hederahashgraph.builder.RequestBuilder.getTransactionReceipt) TransactionReceipt(com.hederahashgraph.api.proto.java.TransactionReceipt) ContractID(com.hederahashgraph.api.proto.java.ContractID) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RequestBuilder.getTransactionRecord(com.hederahashgraph.builder.RequestBuilder.getTransactionRecord) HederaAccountCustomizer(com.hedera.services.ledger.accounts.HederaAccountCustomizer)

Example 3 with HederaAccountCustomizer

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();
}
Also used : AccountID(com.hederahashgraph.api.proto.java.AccountID) RequestBuilder.getTransactionReceipt(com.hederahashgraph.builder.RequestBuilder.getTransactionReceipt) TransactionReceipt(com.hederahashgraph.api.proto.java.TransactionReceipt) ContractID(com.hederahashgraph.api.proto.java.ContractID) SystemDeleteTransactionBody(com.hederahashgraph.api.proto.java.SystemDeleteTransactionBody) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RequestBuilder.getTransactionRecord(com.hederahashgraph.builder.RequestBuilder.getTransactionRecord) HederaAccountCustomizer(com.hedera.services.ledger.accounts.HederaAccountCustomizer)

Example 4 with HederaAccountCustomizer

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());
}
Also used : HederaAccountCustomizer(com.hedera.services.ledger.accounts.HederaAccountCustomizer) Test(org.junit.jupiter.api.Test)

Example 5 with HederaAccountCustomizer

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());
}
Also used : MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) JContractIDKey(com.hedera.services.legacy.core.jproto.JContractIDKey) HederaAccountCustomizer(com.hedera.services.ledger.accounts.HederaAccountCustomizer) Test(org.junit.jupiter.api.Test)

Aggregations

HederaAccountCustomizer (com.hedera.services.ledger.accounts.HederaAccountCustomizer)11 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)4 Test (org.junit.jupiter.api.Test)4 JContractIDKey (com.hedera.services.legacy.core.jproto.JContractIDKey)2 JKey (com.hedera.services.legacy.core.jproto.JKey)2 AccountID (com.hederahashgraph.api.proto.java.AccountID)2 ContractID (com.hederahashgraph.api.proto.java.ContractID)2 TransactionReceipt (com.hederahashgraph.api.proto.java.TransactionReceipt)2 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)2 RequestBuilder.getTransactionReceipt (com.hederahashgraph.builder.RequestBuilder.getTransactionReceipt)2 RequestBuilder.getTransactionRecord (com.hederahashgraph.builder.RequestBuilder.getTransactionRecord)2 ByteString (com.google.protobuf.ByteString)1 JKeyList (com.hedera.services.legacy.core.jproto.JKeyList)1 MerkleToken (com.hedera.services.state.merkle.MerkleToken)1 EntityId (com.hedera.services.state.submerkle.EntityId)1 ExpirableTxnRecord (com.hedera.services.state.submerkle.ExpirableTxnRecord)1 FcTokenAllowance (com.hedera.services.state.submerkle.FcTokenAllowance)1 FcTokenAllowanceId (com.hedera.services.state.submerkle.FcTokenAllowanceId)1 EntityNum (com.hedera.services.utils.EntityNum)1 SystemDeleteTransactionBody (com.hederahashgraph.api.proto.java.SystemDeleteTransactionBody)1