Search in sources :

Example 1 with Operation

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

the class CreateTokenDefinition method toOperationGroups.

@Override
public List<OperationGroup> toOperationGroups(EngineConfiguration configuration, Function<ConstructionDeriveRequestMetadata, EntityIdentifier> identifierFunction) {
    var entityIdentifier = identifierFunction.apply(new ConstructionDeriveRequestMetadataToken().symbol(symbol).type("Token"));
    var mintOperation = new Operation().type("Resource").amount(new ResourceAmount().value(amount.toString()).resourceIdentifier(new TokenResourceIdentifier().rri(entityIdentifier.getAddress()).type("Token"))).entityIdentifier(to);
    var createTokenGroup = new OperationGroup();
    createTokenGroup.addOperationsItem(new Operation().type("Data").data(new Data().action(Data.ActionEnum.CREATE).dataObject(new TokenData().isMutable(owner != null).granularity("1").owner(owner).type(PreparedValidatorRegistered.class.getSimpleName()))).entityIdentifier(entityIdentifier));
    if (owner == null) {
        createTokenGroup.addOperationsItem(mintOperation);
    }
    createTokenGroup.addOperationsItem(new Operation().type("Data").data(new Data().action(Data.ActionEnum.CREATE).dataObject(new TokenMetadata().symbol(symbol).name("some_name").description("some_description").url("").iconUrl(""))).entityIdentifier(entityIdentifier));
    if (owner == null) {
        return List.of(createTokenGroup);
    }
    var mintTokenGroup = new OperationGroup().addOperationsItem(mintOperation);
    return List.of(createTokenGroup, mintTokenGroup);
}
Also used : ResourceAmount(com.radixdlt.api.core.openapitools.model.ResourceAmount) OperationGroup(com.radixdlt.api.core.openapitools.model.OperationGroup) TokenResourceIdentifier(com.radixdlt.api.core.openapitools.model.TokenResourceIdentifier) Data(com.radixdlt.api.core.openapitools.model.Data) TokenData(com.radixdlt.api.core.openapitools.model.TokenData) TokenData(com.radixdlt.api.core.openapitools.model.TokenData) Operation(com.radixdlt.api.core.openapitools.model.Operation) PreparedValidatorRegistered(com.radixdlt.api.core.openapitools.model.PreparedValidatorRegistered) ConstructionDeriveRequestMetadataToken(com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataToken) TokenMetadata(com.radixdlt.api.core.openapitools.model.TokenMetadata)

Example 2 with Operation

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

the class UnstakeStakeUnits method toOperationGroups.

@Override
public List<OperationGroup> toOperationGroups(EngineConfiguration configuration, Function<ConstructionDeriveRequestMetadata, EntityIdentifier> identifierFunction) {
    var from = identifierFunction.apply(new ConstructionDeriveRequestMetadataAccount().type("Account"));
    var to = identifierFunction.apply(new ConstructionDeriveRequestMetadataPreparedUnstakes().type("PreparedUnstakes"));
    var resourceIdentifier = new StakeUnitResourceIdentifier().validatorAddress(validatorAddress).type("StakeUnits");
    var operationGroup = new OperationGroup().addOperationsItem(new Operation().type("Resource").amount(new ResourceAmount().resourceIdentifier(resourceIdentifier).value("-" + amount.toSubunits().toString())).entityIdentifier(from)).addOperationsItem(new Operation().type("Resource").amount(new ResourceAmount().resourceIdentifier(resourceIdentifier).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) ConstructionDeriveRequestMetadataPreparedUnstakes(com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataPreparedUnstakes) StakeUnitResourceIdentifier(com.radixdlt.api.core.openapitools.model.StakeUnitResourceIdentifier) Operation(com.radixdlt.api.core.openapitools.model.Operation)

Example 3 with Operation

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

the class ConstructionParseTransferTest method parsing_transaction_with_transfer_should_have_proper_substates.

@Test
public void parsing_transaction_with_transfer_should_have_proper_substates() throws Exception {
    // Arrange
    start();
    // Act
    var accountAddress = REAddr.ofPubKeyAccount(self);
    var otherAddress = REAddr.ofPubKeyAccount(PrivateKeys.ofNumeric(2).getPublicKey());
    var unsignedTxn = buildUnsignedTransferTxn(accountAddress, otherAddress);
    var request = new ConstructionParseRequest().signed(false).networkIdentifier(new NetworkIdentifier().network("localnet")).transaction(Bytes.toHexString(unsignedTxn));
    var response = handleRequestWithExpectedResponse(sut, request, ConstructionParseResponse.class);
    // Assert
    assertThat(response.getMetadata()).isNotNull();
    assertThat(response.getMetadata().getMessage()).isNull();
    var feeValue = new BigInteger(response.getMetadata().getFee().getValue());
    assertThat(feeValue).isGreaterThan(BigInteger.ZERO);
    var entityHoldings = response.getOperationGroups().stream().flatMap(g -> g.getOperations().stream()).peek(op -> {
        assertThat(op.getSubstate()).isNotNull();
        assertThat(op.getSubstate().getSubstateIdentifier()).isNotNull();
        assertThat(op.getAmount()).isNotNull();
        assertThat(op.getAmount().getResourceIdentifier()).isEqualTo(coreModelMapper.nativeToken());
    }).collect(Collectors.groupingBy(Operation::getEntityIdentifier, Collectors.mapping(op -> new BigInteger(op.getAmount().getValue()), Collectors.reducing(BigInteger.ZERO, BigInteger::add))));
    var accountEntityIdentifier = coreModelMapper.entityIdentifier(accountAddress);
    var otherEntityIdentifier = coreModelMapper.entityIdentifier(otherAddress);
    var transferAmount = new BigInteger(transferAmount().toString());
    var expectedChange = transferAmount.negate().subtract(feeValue);
    assertThat(entityHoldings).containsExactlyInAnyOrderEntriesOf(Map.of(accountEntityIdentifier, expectedChange, otherEntityIdentifier, transferAmount));
}
Also used : NotEnoughNativeTokensForFeesException(com.radixdlt.api.core.model.NotEnoughNativeTokensForFeesException) OperationTxBuilder(com.radixdlt.api.core.model.OperationTxBuilder) LedgerAndBFTProof(com.radixdlt.statecomputer.LedgerAndBFTProof) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Inject(com.google.inject.Inject) ResourceOperation(com.radixdlt.api.core.model.ResourceOperation) ApiTest(com.radixdlt.api.ApiTest) ECPublicKey(com.radixdlt.crypto.ECPublicKey) ConstructionParseRequest(com.radixdlt.api.core.openapitools.model.ConstructionParseRequest) CurrentForkView(com.radixdlt.statecomputer.forks.CurrentForkView) Operation(com.radixdlt.api.core.openapitools.model.Operation) Map(java.util.Map) AccountVaultEntity(com.radixdlt.api.core.model.entities.AccountVaultEntity) BigInteger(java.math.BigInteger) UInt256(com.radixdlt.utils.UInt256) CoreModelMapper(com.radixdlt.api.core.model.CoreModelMapper) PrivateKeys(com.radixdlt.utils.PrivateKeys) RadixEngine(com.radixdlt.engine.RadixEngine) Test(org.junit.Test) TokenResource(com.radixdlt.api.core.model.TokenResource) REAddr(com.radixdlt.identifiers.REAddr) Collectors(java.util.stream.Collectors) List(java.util.List) Bytes(com.radixdlt.utils.Bytes) ConstructionParseResponse(com.radixdlt.api.core.openapitools.model.ConstructionParseResponse) NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) ConstructionParseHandler(com.radixdlt.api.core.handlers.ConstructionParseHandler) Self(com.radixdlt.hotstuff.bft.Self) Amount(com.radixdlt.application.tokens.Amount) EntityOperation(com.radixdlt.api.core.model.EntityOperation) NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) BigInteger(java.math.BigInteger) ConstructionParseRequest(com.radixdlt.api.core.openapitools.model.ConstructionParseRequest) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Example 4 with Operation

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

the class ConstructionBuildFeePayerTest method buildRequestWithFeePayer.

private ConstructionBuildRequest buildRequestWithFeePayer(EntityIdentifier feePayer) {
    var transferAmount = getLiquidAmount().toSubunits().subtract(Amount.ofTokens(1).toSubunits());
    var accountAddress = REAddr.ofPubKeyAccount(self);
    var otherKey = PrivateKeys.ofNumeric(2).getPublicKey();
    var otherAddress = REAddr.ofPubKeyAccount(otherKey);
    return new ConstructionBuildRequest().networkIdentifier(new NetworkIdentifier().network("localnet")).feePayer(feePayer).addOperationGroupsItem(new OperationGroup().addOperationsItem(new Operation().entityIdentifier(coreModelMapper.entityIdentifier(accountAddress)).amount(coreModelMapper.nativeTokenAmount(false, transferAmount))).addOperationsItem(new Operation().entityIdentifier(coreModelMapper.entityIdentifier(otherAddress)).amount(coreModelMapper.nativeTokenAmount(true, transferAmount))));
}
Also used : OperationGroup(com.radixdlt.api.core.openapitools.model.OperationGroup) ConstructionBuildRequest(com.radixdlt.api.core.openapitools.model.ConstructionBuildRequest) NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) Operation(com.radixdlt.api.core.openapitools.model.Operation)

Example 5 with Operation

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

the class ConstructionBuildMessageTest method buildRequestWithMessage.

private ConstructionBuildRequest buildRequestWithMessage(String message) {
    var transferAmount = UInt256.ONE;
    var accountAddress = REAddr.ofPubKeyAccount(self);
    var otherKey = PrivateKeys.ofNumeric(2).getPublicKey();
    var otherAddress = REAddr.ofPubKeyAccount(otherKey);
    return new ConstructionBuildRequest().message(message).networkIdentifier(new NetworkIdentifier().network("localnet")).feePayer(coreModelMapper.entityIdentifier(accountAddress)).addOperationGroupsItem(new OperationGroup().addOperationsItem(new Operation().entityIdentifier(coreModelMapper.entityIdentifier(accountAddress)).amount(coreModelMapper.nativeTokenAmount(false, transferAmount))).addOperationsItem(new Operation().entityIdentifier(coreModelMapper.entityIdentifier(otherAddress)).amount(coreModelMapper.nativeTokenAmount(true, transferAmount))));
}
Also used : OperationGroup(com.radixdlt.api.core.openapitools.model.OperationGroup) ConstructionBuildRequest(com.radixdlt.api.core.openapitools.model.ConstructionBuildRequest) NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) Operation(com.radixdlt.api.core.openapitools.model.Operation)

Aggregations

Operation (com.radixdlt.api.core.openapitools.model.Operation)7 OperationGroup (com.radixdlt.api.core.openapitools.model.OperationGroup)6 ResourceAmount (com.radixdlt.api.core.openapitools.model.ResourceAmount)4 ConstructionDeriveRequestMetadataAccount (com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataAccount)3 NetworkIdentifier (com.radixdlt.api.core.openapitools.model.NetworkIdentifier)3 ConstructionBuildRequest (com.radixdlt.api.core.openapitools.model.ConstructionBuildRequest)2 Inject (com.google.inject.Inject)1 ApiTest (com.radixdlt.api.ApiTest)1 ConstructionParseHandler (com.radixdlt.api.core.handlers.ConstructionParseHandler)1 CoreModelMapper (com.radixdlt.api.core.model.CoreModelMapper)1 EntityOperation (com.radixdlt.api.core.model.EntityOperation)1 NotEnoughNativeTokensForFeesException (com.radixdlt.api.core.model.NotEnoughNativeTokensForFeesException)1 OperationTxBuilder (com.radixdlt.api.core.model.OperationTxBuilder)1 ResourceOperation (com.radixdlt.api.core.model.ResourceOperation)1 TokenResource (com.radixdlt.api.core.model.TokenResource)1 AccountVaultEntity (com.radixdlt.api.core.model.entities.AccountVaultEntity)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 ConstructionParseRequest (com.radixdlt.api.core.openapitools.model.ConstructionParseRequest)1