Esempio n. 1
0
        public async Task <ActionResult <IList <Address> > > CreateAddress([FromBody] CreateWalletAddress request)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(request.Email))
                {
                    return(BadRequest(new ArgumentNullException(nameof(request.Email)).Message));
                }

                if (string.IsNullOrWhiteSpace(request.Label))
                {
                    return(BadRequest(new ArgumentNullException(nameof(request.Label)).Message));
                }

                if (User.Identity.Name != request.Email)
                {
                    return(BadRequest(RequestResponse.BadRequest()));
                }

                var result = await walletManagementService.CreateAddress(request);

                return(Ok(result));
            }
            catch (Exception)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, RequestResponse.InternalServerError()));
            }
        }
        public async Task <Address> CreateAddress(CreateWalletAddress request)
        {
            var wallet = await firebaseDbService.GetWallet(request.Id);

            var privateKey = new BitcoinSecret(wallet.PrivateKey);
            var extKey     = new ExtKey(privateKey.PubKey.ToHex());
            var newAddress = new Address(Guid.NewGuid(), wallet.WalletId, extKey.PrivateKey.PubKey.GetAddress(network).ToString(), request.Label);

            wallet.Addresses.Add(newAddress);

            var walletKey = await firebaseDbService.GetWalletKey(request.Id);

            if (string.IsNullOrWhiteSpace(walletKey))
            {
                throw new InvalidOperationException("Could not get the wallet you are looking for.");
            }

            var updateWallet = await firebaseDbService.UpdateWallet(walletKey, wallet);

            return(newAddress);
        }