public async Task <WalletDTO> GetNewWallet(CreateWalletModel model) { Wallet wallet = new Wallet(); bool isUserRegistered = await _commonContext.Users.AnyAsync(u => u.PhoneNumber == model.PhoneNumber); if (isUserRegistered) { throw new ValidationException("شماره همراه وارد شده در حال حاضر ثبت شده."); } WalletDTO result = new WalletDTO { PublicKey = wallet.PublicKey, PrivateKey = wallet.KeyPair.GetPrivateKey() }; _commonContext.Users.Add(new User { Name = model.Name, PhoneNumber = model.PhoneNumber, Role = Role.Voter, PublicKey = result.PublicKey }); await _commonContext.SaveChangesAsync(); return(result); }
//public static void TransferTokenFrontTest(string FromAddress_Buyer, string ToAddress_Owner, string Amount) //{ // Task task = System.Threading.Tasks.Task.Run(async () => await (DoTransaction(FromAddress_Buyer, ToAddress_Owner, Amount))); //} public async static Task <CreateWalletModel> CreateUserWallet() { ITrace telemetria = new Trace(); CreateWalletModel _walletModel = new CreateWalletModel(); try { //Generate RandomPassword string _passphrase = Guid.NewGuid().ToString().Replace("-", "") + GetRandomNumber(1842).ToString(); string _blobname = BlobManager.CreateUsrWalletBlobFile(_passphrase, ConfigurationManager.AppSettings["azure-storage-connectionstring"]); var web3 = new Nethereum.Web3.Web3(ConfigurationManager.AppSettings["BlockchainURL"]); var _walletAddress = await web3.Personal.NewAccount.SendRequestAsync(_passphrase); _walletModel = new CreateWalletModel() { blobname = _blobname, walletaddress = _walletAddress }; } catch (Exception e) { var messageException = telemetria.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name); telemetria.Critical(messageException); } return(_walletModel); }
public WalletModel Register(CreateWalletModel walletModel) { var wallet = walletModel.ConvertToWalletEntity(); _walletRepository.Save(wallet); return(wallet.ConvertToWalletModel()); }
public async Task <WalletQRDTO> GetNewWalletWithQRcode(CreateWalletModel model) { Wallet wallet = new Wallet(); bool isUserRegistered = await _commonContext.Users.AnyAsync(u => u.PhoneNumber == model.PhoneNumber); if (isUserRegistered) { throw new ValidationException("The entered mobile number is already registered."); } WalletQRDTO result = new WalletQRDTO { QRCodeBase64 = QRCodeGenerate(wallet.KeyPair.GetPrivateKey()), PublicKey = wallet.PublicKey, PrivateKey = wallet.KeyPair.GetPrivateKey() }; _commonContext.Users.Add(new User { Name = model.Name, PhoneNumber = model.PhoneNumber, Role = Role.Voter, PublicKey = result.PublicKey }); await _commonContext.SaveChangesAsync(); return(result); }
public IActionResult Register([FromBody] CreateWalletModel walletModel) { try { var wallet = _walletService.Register(walletModel); return(Ok(wallet?.Id)); } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <IActionResult> CreateWalletAsync(CreateWalletModel wallet) { var userId = GetUserId(); var walletDto = Mapper.Map <WalletDto>(wallet); var createdWalletEntity = await walletService.CreateWalletAsync(userId, walletDto); var createdWallet = Mapper.Map <Wallet>(createdWalletEntity); return(CreatedAtRoute( Routes.ShowWallet, new { id = createdWallet.WalletId }, createdWallet)); }
public static Wallet ConvertToWalletEntity(this CreateWalletModel walletModel) => new Wallet(walletModel.Name);
public async Task <IActionResult> GetNewWalletWithQR(CreateWalletModel model) { var wallet = await _profileService.GetNewWalletWithQRcode(model); return(Ok(wallet)); }
public async Task <IActionResult> GetNewWallet([FromBody] CreateWalletModel model) { var wallet = await _profileService.GetNewWallet(model); return(Ok(wallet)); }
private async Task CreateWalletAsync(IUserNameCredentials credentials) { var oldView = this.View; var createWalletModel = new CreateWalletModel(); this.View = createWalletModel; try { var wallet = await createWalletModel.CreateWallet(); var syncContent = await syncModel.EnterSync(); try { syncContent.SetTextView("Your wallet is almost ready. We are creating the first address for you."); var tabItem = new Models.TabItem() { Name = wallet.Name, IsSelected = false, }; var walletProvider = new Iota.IotaWalletManager(wallet, tabItem); await walletProvider.EnsureFirstAddressAsync(); if (wallet.IsImported) { walletProvider.InitializeAsync(true); } var passwordHash = credentials.GetPasswordHash(); storageManager.SaveWallet(credentials.UserName, passwordHash, wallet); tabItem.Selected = (t) => View = walletProvider.Wallet; Header.TabItems.Add(tabItem); foreach (var tab in Header.TabItems) // don't know why but need { tab.IsSelected = false; } tabItem.IsSelected = true; return; } catch (OperationCanceledException) { // do nothing } catch (Exception e) { await syncContent.SetCancelView(e.Message).WaitAsync(); } finally { syncContent.Dispose(); } } catch (OperationCanceledException) { // do nothing } this.View = oldView; }