Esempio n. 1
0
        public override async Task <GetTransferSigningRequestsResponse> Get(GetTransferSigningRequestsRequest request,
                                                                            ServerCallContext context)
        {
            var vaultType = context.GetVaultType();

            if (!vaultType.HasValue)
            {
                return(GetErrorResponse(GetTransferSigningRequestsErrorResponseBody.Types.ErrorCode.InvalidParameters,
                                        "Vault type required"));
            }

            var vaultId = context.GetVaultId();

            if (!vaultId.HasValue && vaultType == VaultType.Private)
            {
                return(GetErrorResponse(GetTransferSigningRequestsErrorResponseBody.Types.ErrorCode.InvalidParameters,
                                        "Private vault id required"));
            }

            var pendingTransactionSigningRequests = vaultType == VaultType.Shared
                ? await _transferSigningRequestsRepository.GetPendingForSharedVaultAsync()
                : await _transferSigningRequestsRepository.GetPendingForPrivateVaultAsync(vaultId.Value);

            var response = new GetTransferSigningRequestsResponseBody();

            foreach (var transactionSigningRequest in pendingTransactionSigningRequests)
            {
                var item = new TransferSigningRequest
                {
                    Id           = transactionSigningRequest.Id,
                    BlockchainId = transactionSigningRequest.Blockchain.Id,
                    NetworkType  = transactionSigningRequest.Blockchain.NetworkType switch
                    {
                        Swisschain.Sirius.Sdk.Primitives.NetworkType.Private =>
                        Swisschain.Sirius.VaultApi.ApiContract.Common.NetworkType.Private,
                        Swisschain.Sirius.Sdk.Primitives.NetworkType.Public =>
                        Swisschain.Sirius.VaultApi.ApiContract.Common.NetworkType.Public,
                        Swisschain.Sirius.Sdk.Primitives.NetworkType.Test =>
                        Swisschain.Sirius.VaultApi.ApiContract.Common.NetworkType.Test,
                        _ => throw new InvalidEnumArgumentException(
                                  nameof(transactionSigningRequest.Blockchain.NetworkType),
                                  (int)transactionSigningRequest.Blockchain.NetworkType,
                                  typeof(Swisschain.Sirius.Sdk.Primitives.NetworkType))
                    },
        public override async Task <GetWalletGenerationRequestResponse> Get(GetWalletGenerationRequestRequest request,
                                                                            ServerCallContext context)
        {
            var vaultType = context.GetVaultType();

            if (!vaultType.HasValue)
            {
                return(GetErrorResponse(GetWalletGenerationRequestErrorResponseBody.Types.ErrorCode.InvalidParameters,
                                        "Vault type required"));
            }

            var vaultId = context.GetVaultId();

            if (!vaultId.HasValue && vaultType == VaultType.Private)
            {
                return(GetErrorResponse(GetWalletGenerationRequestErrorResponseBody.Types.ErrorCode.InvalidParameters,
                                        "Private vault id required"));
            }

            var pendingWalletGenerationRequests = vaultType == VaultType.Shared
                ? await _walletGenerationRequestRepository.GetPendingForSharedVaultAsync()
                : await _walletGenerationRequestRepository.GetPendingForPrivateVaultAsync(vaultId.Value);

            var response = new GetWalletGenerationRequestResponseBody();

            response.Requests.AddRange(pendingWalletGenerationRequests
                                       .Select(walletGenerationRequest => new WalletGenerationRequest
            {
                Id           = walletGenerationRequest.Id,
                BlockchainId = walletGenerationRequest.BlockchainId,
                NetworkType  = walletGenerationRequest.NetworkType switch
                {
                    Swisschain.Sirius.Sdk.Primitives.NetworkType.Private =>
                    Swisschain.Sirius.VaultApi.ApiContract.Common.NetworkType.Private,
                    Swisschain.Sirius.Sdk.Primitives.NetworkType.Public =>
                    Swisschain.Sirius.VaultApi.ApiContract.Common.NetworkType.Public,
                    Swisschain.Sirius.Sdk.Primitives.NetworkType.Test =>
                    Swisschain.Sirius.VaultApi.ApiContract.Common.NetworkType.Test,
                    _ => throw new InvalidEnumArgumentException(nameof(walletGenerationRequest.NetworkType),
                                                                (int)walletGenerationRequest.NetworkType,
                                                                typeof(Swisschain.Sirius.Sdk.Primitives.NetworkType))
                },
        public override async Task <GetTransferValidationRequestsResponse> Get(
            GetTransferValidationRequestsRequest request,
            ServerCallContext context)
        {
            var vaultType = context.GetVaultType();

            if (!vaultType.HasValue)
            {
                return(GetErrorResponse(
                           GetTransferValidationRequestsErrorResponseBody.Types.ErrorCode.InvalidParameters,
                           "Vault type required"));
            }

            var vaultId = context.GetVaultId();

            if (!vaultId.HasValue && vaultType == VaultType.Private)
            {
                return(GetErrorResponse(
                           GetTransferValidationRequestsErrorResponseBody.Types.ErrorCode.InvalidParameters,
                           "Private vault id required"));
            }

            IReadOnlyCollection <VaultApi.Common.ReadModels.TransferValidationRequests.TransferValidationRequest>
            requests;

            if (vaultType == VaultType.Shared)
            {
                requests = await _transferValidationRequestRepository.GetPendingForSharedVaultAsync();
            }
            else
            {
                requests = await _transferValidationRequestRepository.GetPendingForPrivateVaultAsync(vaultId.Value);
            }

            var response = new GetTransferValidationRequestsResponse
            {
                Response = new GetTransferValidationRequestsResponseBody()
            };

            if (requests.Any())
            {
                response.Response.Requests.AddRange(requests.Select(x => new TransferValidationRequest
                {
                    Id          = x.Id,
                    OperationId = x.TransferId,
                    TenantId    = x.TenantId,
                    Blockchain  = new Blockchain
                    {
                        Id          = x.Blockchain.Id,
                        NetworkType = x.Blockchain.NetworkType switch
                        {
                            Swisschain.Sirius.Sdk.Primitives.NetworkType.Private =>
                            Swisschain.Sirius.VaultApi.ApiContract.Common.NetworkType.Private,
                            Swisschain.Sirius.Sdk.Primitives.NetworkType.Test =>
                            Swisschain.Sirius.VaultApi.ApiContract.Common.NetworkType.Test,
                            Swisschain.Sirius.Sdk.Primitives.NetworkType.Public =>
                            Swisschain.Sirius.VaultApi.ApiContract.Common.NetworkType.Public,
                            _ => throw new ArgumentOutOfRangeException(nameof(x.Blockchain.NetworkType),
                                                                       x.Blockchain.NetworkType,
                                                                       null)
                        },