Search in sources :

Example 6 with OperationGroup

use of com.radixdlt.api.core.openapitools.model.OperationGroup in project radixdlt by radixdlt.

the class TransferTokens method toOperationGroups.

@Override
public List<OperationGroup> toOperationGroups(EngineConfiguration configuration, Function<ConstructionDeriveRequestMetadata, EntityIdentifier> identifierFunction) {
    var from = identifierFunction.apply(new ConstructionDeriveRequestMetadataAccount().type("Account"));
    var operationGroup = new OperationGroup().addOperationsItem(new Operation().type("Resource").amount(new ResourceAmount().resourceIdentifier(tokenResourceIdentifier).value("-" + amount.toSubunits().toString())).entityIdentifier(from)).addOperationsItem(new Operation().type("Resource").amount(new ResourceAmount().resourceIdentifier(tokenResourceIdentifier).value(amount.toSubunits().toString())).entityIdentifier(to));
    return List.of(operationGroup);
}
Also used : ConstructionDeriveRequestMetadataAccount(com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataAccount) ResourceAmount(com.radixdlt.api.core.openapitools.model.ResourceAmount) OperationGroup(com.radixdlt.api.core.openapitools.model.OperationGroup) Operation(com.radixdlt.api.core.openapitools.model.Operation)

Example 7 with OperationGroup

use of com.radixdlt.api.core.openapitools.model.OperationGroup in project radixdlt by radixdlt.

the class TransactionsHandler method construct.

private CommittedTransaction construct(Txn txn, RecoverableProcessedTxn recoveryInfo, AccumulatorState accumulatorState) {
    var parser = radixEngineProvider.get().getParser();
    ParsedTxn parsedTxn;
    try {
        parsedTxn = parser.parse(txn);
    } catch (TxnParseException e) {
        throw new IllegalStateException("Could not parse already committed transaction", e);
    }
    var committedTransaction = new CommittedTransaction();
    recoveryInfo.recoverStateUpdates(parsedTxn).stream().map(stateUpdateGroup -> {
        var operationGroup = new OperationGroup();
        stateUpdateGroup.stream().map(stateUpdate -> {
            var substateOperation = stateUpdate.recover(radixEngineProvider);
            return coreModelMapper.operation(substateOperation.getSubstate(), substateOperation.getSubstateId(), substateOperation.isBootUp(), this::symbol);
        }).forEach(operationGroup::addOperationsItem);
        return operationGroup;
    }).forEach(committedTransaction::addOperationGroupsItem);
    var signedBy = parsedTxn.getPayloadHashAndSig().map(hashAndSig -> {
        var hash = hashAndSig.getFirst();
        var sig = hashAndSig.getSecond();
        return ECPublicKey.recoverFrom(hash, sig).orElseThrow(() -> new IllegalStateException("Invalid signature on already committed transaction"));
    });
    var transactionIdentifier = coreModelMapper.transactionIdentifier(txn.getId());
    return committedTransaction.committedStateIdentifier(coreModelMapper.stateIdentifier(accumulatorState)).metadata(new CommittedTransactionMetadata().fee(coreModelMapper.nativeTokenAmount(parsedTxn.getFeePaid())).message(parsedTxn.getMsg().map(Bytes::toHexString).orElse(null)).size(txn.getPayload().length).hex(Bytes.toHexString(txn.getPayload())).signedBy(signedBy.map(coreModelMapper::publicKey).orElse(null))).transactionIdentifier(transactionIdentifier);
}
Also used : SubstateTypeId(com.radixdlt.atom.SubstateTypeId) LedgerAndBFTProof(com.radixdlt.statecomputer.LedgerAndBFTProof) Inject(com.google.inject.Inject) RecoverableProcessedTxn(com.radixdlt.api.core.reconstruction.RecoverableProcessedTxn) StateIdentifier(com.radixdlt.api.core.openapitools.model.StateIdentifier) ECPublicKey(com.radixdlt.crypto.ECPublicKey) OperationGroup(com.radixdlt.api.core.openapitools.model.OperationGroup) ParsedTxn(com.radixdlt.engine.parser.ParsedTxn) CommittedTransaction(com.radixdlt.api.core.openapitools.model.CommittedTransaction) CoreJsonRpcHandler(com.radixdlt.api.core.CoreJsonRpcHandler) BerkeleyLedgerEntryStore(com.radixdlt.store.berkeley.BerkeleyLedgerEntryStore) SystemMapKey(com.radixdlt.constraintmachine.SystemMapKey) AccumulatorState(com.radixdlt.ledger.AccumulatorState) BerkeleyRecoverableProcessedTxnStore(com.radixdlt.api.core.reconstruction.BerkeleyRecoverableProcessedTxnStore) CoreModelMapper(com.radixdlt.api.core.model.CoreModelMapper) TokenResourceMetadata(com.radixdlt.application.tokens.state.TokenResourceMetadata) CoreApiException(com.radixdlt.api.core.model.CoreApiException) RadixEngine(com.radixdlt.engine.RadixEngine) Txn(com.radixdlt.atom.Txn) REAddr(com.radixdlt.identifiers.REAddr) CommittedTransactionsRequest(com.radixdlt.api.core.openapitools.model.CommittedTransactionsRequest) Provider(com.google.inject.Provider) Bytes(com.radixdlt.utils.Bytes) CommittedTransactionMetadata(com.radixdlt.api.core.openapitools.model.CommittedTransactionMetadata) CommittedTransactionsResponse(com.radixdlt.api.core.openapitools.model.CommittedTransactionsResponse) TxnParseException(com.radixdlt.engine.parser.exceptions.TxnParseException) LedgerAccumulator(com.radixdlt.ledger.LedgerAccumulator) OperationGroup(com.radixdlt.api.core.openapitools.model.OperationGroup) TxnParseException(com.radixdlt.engine.parser.exceptions.TxnParseException) CommittedTransactionMetadata(com.radixdlt.api.core.openapitools.model.CommittedTransactionMetadata) CommittedTransaction(com.radixdlt.api.core.openapitools.model.CommittedTransaction) ParsedTxn(com.radixdlt.engine.parser.ParsedTxn)

Aggregations

OperationGroup (com.radixdlt.api.core.openapitools.model.OperationGroup)7 Operation (com.radixdlt.api.core.openapitools.model.Operation)6 ResourceAmount (com.radixdlt.api.core.openapitools.model.ResourceAmount)4 ConstructionDeriveRequestMetadataAccount (com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataAccount)3 ConstructionBuildRequest (com.radixdlt.api.core.openapitools.model.ConstructionBuildRequest)2 NetworkIdentifier (com.radixdlt.api.core.openapitools.model.NetworkIdentifier)2 Inject (com.google.inject.Inject)1 Provider (com.google.inject.Provider)1 CoreJsonRpcHandler (com.radixdlt.api.core.CoreJsonRpcHandler)1 CoreApiException (com.radixdlt.api.core.model.CoreApiException)1 CoreModelMapper (com.radixdlt.api.core.model.CoreModelMapper)1 CommittedTransaction (com.radixdlt.api.core.openapitools.model.CommittedTransaction)1 CommittedTransactionMetadata (com.radixdlt.api.core.openapitools.model.CommittedTransactionMetadata)1 CommittedTransactionsRequest (com.radixdlt.api.core.openapitools.model.CommittedTransactionsRequest)1 CommittedTransactionsResponse (com.radixdlt.api.core.openapitools.model.CommittedTransactionsResponse)1 ConstructionDeriveRequestMetadataPreparedStakes (com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataPreparedStakes)1 ConstructionDeriveRequestMetadataPreparedUnstakes (com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataPreparedUnstakes)1 ConstructionDeriveRequestMetadataToken (com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataToken)1 Data (com.radixdlt.api.core.openapitools.model.Data)1 PreparedValidatorRegistered (com.radixdlt.api.core.openapitools.model.PreparedValidatorRegistered)1