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);
}
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);
}
Aggregations