use of com.hedera.services.legacy.core.jproto.JContractIDKey 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());
}
use of com.hedera.services.legacy.core.jproto.JContractIDKey in project hedera-services by hashgraph.
the class ContractCreateTransitionLogic method doStateTransition.
@Override
public void doStateTransition() {
/* --- Translate from gRPC types --- */
var contractCreateTxn = txnCtx.accessor().getTxn();
var op = contractCreateTxn.getContractCreateInstance();
final var senderId = Id.fromGrpcAccount(contractCreateTxn.getTransactionID().getAccountID());
final var proxyAccount = op.hasProxyAccountID() ? Id.fromGrpcAccount(op.getProxyAccountID()) : Id.DEFAULT;
var key = op.hasAdminKey() ? validator.attemptToDecodeOrThrow(op.getAdminKey(), SERIALIZATION_FAILED) : STANDIN_CONTRACT_ID_KEY;
/* --- Load the model objects --- */
final var sender = accountStore.loadAccount(senderId);
final var codeWithConstructorArgs = prepareCodeWithConstructorArguments(op);
long expiry = RequestBuilder.getExpirationTime(txnCtx.consensusTime(), op.getAutoRenewPeriod()).getSeconds();
/* --- Do the business logic --- */
final var newContractAddress = worldState.newContractAddress(sender.getId().asEvmAddress());
final var result = evmTxProcessor.execute(sender, newContractAddress, op.getGas(), op.getInitialBalance(), codeWithConstructorArgs, txnCtx.consensusTime(), expiry);
/* --- Persist changes into state --- */
final var createdContracts = worldState.persistProvisionalContractCreations();
result.setCreatedContracts(createdContracts);
if (result.isSuccessful()) {
/* --- Create customizer for the newly created contract --- */
final var account = EntityIdUtils.accountIdFromEvmAddress(newContractAddress);
if (key == STANDIN_CONTRACT_ID_KEY) {
key = new JContractIDKey(account.getShardNum(), account.getRealmNum(), account.getAccountNum());
}
final var customizer = new HederaAccountCustomizer().key(key).memo(op.getMemo()).proxy(proxyAccount.asEntityId()).expiry(expiry).autoRenewPeriod(op.getAutoRenewPeriod().getSeconds()).isSmartContract(true);
hederaLedger.customizePotentiallyDeleted(account, customizer);
} else {
worldState.reclaimContractId();
}
/* --- Customize sponsored Accounts */
worldState.customizeSponsoredAccounts();
/* --- Externalise changes --- */
for (final var createdContract : createdContracts) {
sigImpactHistorian.markEntityChanged(createdContract.getContractNum());
}
if (result.isSuccessful()) {
final var newEvmAddress = newContractAddress.toArrayUnsafe();
final var newContractId = contractIdFromEvmAddress(newEvmAddress);
sigImpactHistorian.markEntityChanged(newContractId.getContractNum());
txnCtx.setTargetedContract(newContractId);
recordService.externalizeSuccessfulEvmCreate(result, newEvmAddress);
} else {
recordService.externalizeUnsuccessfulEvmCreate(result);
}
}
Aggregations