public async Task <bool> SendAsset(NETWORK_TYPE type, string wif, ASSET_NAME assetName, string addr, int amount) { var asset = (assetName == ASSET_NAME.NEO) ? "NEO" : "GAS"; var res = await nodeServices.InvokeExportAsync <bool>(GetScriptLocation(), "SendAsset", GetNetwork(type), wif, asset, addr, amount); return(res); }
public async Task <bool> SendAsset(NETWORK_TYPE type, ASSET_NAME assetName, string addr, int amount) { var user = await _userManager.GetUserAsync(User); if (assetName == ASSET_NAME.SC) { var toSh = await SmartPromiseConverter.GetScriptHashReversed(addr, _blockchain); var fromSh = await SmartPromiseConverter.GetScriptHashReversed(user.Address, _blockchain); var res = await _blockchain.InvokeContractTransfer(type, user.Wif, fromSh, toSh, amount, 1); return(res); } else { return(await _blockchain.SendAsset(type, user.Wif, assetName, addr, amount)); } }
public async Task <IActionResult> Withdraw(WithdrawViewModel model) { if (ModelState.IsValid) { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } bool send; ViewData["Message"] = ""; var balance = await _blockchainRepository.GetBalance(NETWORK_TYPE.TESTNET, user.Address); ASSET_NAME a = model.Asset == 1 ? ASSET_NAME.GAS : ASSET_NAME.NEO; double b = model.Asset == 1 ? balance.GAS : balance.NEO; if (b < model.Amount) { ViewData["Message"] = "insufficient funds"; return(View(model)); } send = await _blockchainRepository.SendAsset(NETWORK_TYPE.TESTNET, user.Wif, a, model.Address, model.Amount); if (send) { ViewData["Message"] = "Success"; return(View(model)); } ViewData["Message"] = "Failed to withdraw"; } // If we got this far, something failed, redisplay form return(View(model)); }