public async Task <NewTransactionDTO> LoadInfoFromAPI() { if (string.IsNullOrEmpty(WalletName)) { return(null); } if (string.IsNullOrEmpty(Address)) { return(null); } if (string.IsNullOrEmpty(TxId)) { return(null); } try { var txd = await NeblioTransactionHelpers.TransactionInfoAsync(null, TransactionTypes.Neblio, TxId, Address); if (txd != null) { var dto = new NewTransactionDTO(); dto.AccountAddress = Address; dto.WalletName = WalletName; dto.Type = TransactionTypes.Neblio; dto.TxId = TxId; dto.TransactionDetails = txd; VinTokens = dto.TransactionDetails.VinTokens; VoutTokens = dto.TransactionDetails.VoutTokens; Amount = dto.TransactionDetails.Amount; Confirmations = dto.TransactionDetails.Confirmations; Direction = dto.TransactionDetails.Direction; From = dto.TransactionDetails.From; To = dto.TransactionDetails.To; TimeStamp = dto.TransactionDetails.TimeStamp; Metadata = dto.TransactionDetails.Metadata; if (dto.TransactionDetails != null) { DetailsLoaded?.Invoke(this, dto); } return(dto); } } catch (Exception ex) { attempts--; //log.Error("Cannot load tx details: ", ex); } return(null); }
public override async Task <string> StartShop() { _ = Task.Run(async() => { // todo cancel while (true) { IsRunning = true; try { if (IsActive) { var mainItem = ShopItems.FirstOrDefault(); if (mainItem != null) { var neblUtxos = await NeblioTransactionHelpers.GetAddressNeblUtxo(Address, 0.0001, 1000000); if (neblUtxos?.Count > 0) { foreach (var u in neblUtxos) { var value = (u.Value / neblio.FromSatToMainRatio); if (value >= (mainItem.Price - 0.0002) && value <= (mainItem.Price + 0.0002)) { // todo load from account which creates the shop var txinfo = await NeblioTransactionHelpers.TransactionInfoAsync(null, TransactionTypes.Neblio, u.Txid); if ((txinfo.From[0] != Address && txinfo.To[0] != Address) && !string.IsNullOrEmpty(txinfo.From[0])) // this is received order from some address { var resp = await processOrder(u, txinfo, mainItem); } } } } } } await Task.Delay(shopRefresh); } catch (Exception ex) { log.Error("Error during refreshing shop", ex); } } }); return(await Task.FromResult("Running!")); }
private async Task <IAccount> GetTransactionsDetails(string accountAddr, GetAddressResponse accnt, IAccount acc) { foreach (var item in accnt.Transactions) { //Console.WriteLine($"Transaction: {item}"); var tr = await NeblioTransactionHelpers.TransactionInfoAsync(client, TransactionTypes.Neblio, item, acc.Address); if (tr != null) { acc.Transactions.TryAdd(tr.TxId, tr); } } return(acc); }
private async Task <bool> findSettingToken() { var utxos = await NeblioTransactionHelpers.GetAddressNFTsUtxos(Address); var txId = string.Empty; if (utxos != null) { foreach (var u in utxos) { if (u.Tokens?.ToList()?[0]?.TokenId == TokenId) { var info = await NeblioTransactionHelpers.TransactionInfoAsync(null, TransactionTypes.Neblio, u.Txid, Address); if (info != null) { // owner txs if (info.To[0] == info.From[0]) // to prevent another person will send setting token with wrong setting { if (info.VoutTokens[0].Metadata != null) { if (info.VoutTokens[0].Metadata.TryGetValue("ShopSettingToken", out string value)) { if (value == "true") { SettingToken = info.VoutTokens[0]; loadSettingsFromToken(); return(true); } } } } } } } } return(false); }
public override async Task <ITransaction> GetTxDetails() { if (!string.IsNullOrEmpty(TxId)) { var tx = await NeblioTransactionHelpers.TransactionInfoAsync(null, TransactionTypes.Neblio, TxId); if (tx != null) { Amount = tx.Amount; TxDetails = tx; return(tx); } else { return(null); } } else { log.Error("Cannot load Neblio tx details for receipt, TxId is empty!"); Console.WriteLine("Cannot load Neblio tx details for receipt, TxId is empty!"); return(null); } }
public async Task <string> LoadHistoryFromActualTx() { try { var allLoaded = false; var actualTxLoading = ActualStateTxId; while (!allLoaded) { var info = await NeblioTransactionHelpers.TransactionInfoAsync(null, TransactionTypes.Neblio, actualTxLoading); if (info == null) { return(await Task.FromResult("OK - No History yet.")); } if (info.VoutTokens != null) { if (info.VoutTokens.Count > 0) { var token = info.VoutTokens[0]; if (token.Metadata != null) { if (token.Metadata.Count > 0) { if (token.Metadata.TryGetValue("GameId", out var gameid)) { if (gameid == Id.ToString()) { if (token.Metadata.TryGetValue("GameData", out var gameData)) { if (!string.IsNullOrEmpty(gameData)) { try { var parsedData = JsonConvert.DeserializeObject <ChessGameDto>(gameData); if (parsedData != null) { if (parsedData.GameId == Id.ToString() && parsedData.Type == GameDtoTypes.ChessGame) { GameHistoryTxIds.Add(actualTxLoading); if (Players.Count == 0 && parsedData.Players.Count > 0) { Players = parsedData.Players; } GameHistory.Add(parsedData); if (parsedData.LastGameRecordTxId != "StartOfNewGame") { actualTxLoading = parsedData.LastGameRecordTxId; } else { allLoaded = true; } } } } catch (Exception ex) { log.Error("Chess Game - wrong format of gameData in token metadata. Cannot load history", ex); return(null); } } } } } } } } } } // loading is going from newset to oldest one, so it is important to reverse whole list GameHistoryTxIds.Reverse(); GameHistory.Reverse(); return(await Task.FromResult("OK")); } catch (Exception ex) { log.Error("Chess Game - Cannot load game History!", ex); return(await Task.FromResult("ERROR")); } }
// todo - find just in the already loaded tx in all accounts public override async Task <ITransaction> GetTxDetails(string txid) { var tx = await NeblioTransactionHelpers.TransactionInfoAsync(client, TransactionTypes.Neblio, txid); return(tx); }