public async Task <StakingInfo> GetStakingInfo() { if (UseCachedStakingInfo() && _stakingInfo != null) { return(_stakingInfo); } await Sem.WaitAsync(); try { _stakingInfo = await _blockchainProvider.GetStakingInfo(); _lastQueryGetStakingInfo = DateTime.UtcNow; return(_stakingInfo); } catch (Exception e) { _log.LogError(e.Message); return(new StakingInfo { Errors = "Exception" }); } finally { Sem.Release(); } }
public async Task <StakingInfo> GetStakingAsync(string accountId, string stakingAccountId) { var klWallet = CreateWallet(accountId); var result = await klWallet.GetStakingAsync(stakingAccountId); if (result != null) { var tb = result as TransactionBlock; var sgenresult = await _node.GetBlockByIndexAsync(stakingAccountId, 1); var sgen = sgenresult.GetBlock() as StakingGenesis; var stkinfo = new StakingInfo { owner = sgen.OwnerAccountId, stkid = sgen.AccountID, name = sgen.Name, start = sgen.Start, amount = tb.Balances[LyraGlobal.OFFICIALTICKERCODE].ToBalanceDecimal(), days = sgen.Days, voting = sgen.Voting, compound = sgen.CompoundMode }; return(stkinfo); } else { throw new Exception($"No such staking account"); } }
public async Task <StakingInfo> CreateStakingAccountAsync(string accountId, string Name, string voteFor, int daysToStake, bool compoundMode) { var klWallet = CreateWallet(accountId); var result = await klWallet.CreateStakingAccountAsync(Name, voteFor, daysToStake, compoundMode); if (result.ResultCode == APIResultCodes.Success) { var sgen = result.GetBlock() as StakingGenesis; var stkinfo = new StakingInfo { owner = sgen.OwnerAccountId, stkid = sgen.AccountID, name = sgen.Name, start = sgen.Start, amount = 0, days = sgen.Days, voting = sgen.Voting, compound = sgen.CompoundMode }; return(stkinfo); } else { throw new Exception($"{result.ResultCode}: {result.ResultMessage}"); } }
public async Task <StakingInfo> GetStakingInfo() { var rpcStakingInfo = await _client.GetStakingInfo(); var stakingInfo = new StakingInfo { CurrentBlockSize = rpcStakingInfo.CurrentBlockSize, CurrentBlockTx = rpcStakingInfo.CurrentBlockTx, PooledTx = rpcStakingInfo.PooledTx, Difficulty = rpcStakingInfo.Difficulty, SearchInterval = rpcStakingInfo.SearchInterval, Weight = rpcStakingInfo.Weight, NetStakeWeight = rpcStakingInfo.NetStakeWeight, ExpectedTime = rpcStakingInfo.ExpectedTime }; return(stakingInfo); }
StakingInfo GetStakingInfo() { if (this.stakingService == null) { return(new StakingInfo()); } var stakingInfo = new StakingInfo { Enabled = true, PosV3 = this.stakingService.PosV3, StakingStatus = this.stakingService.Status, LastStakedBlock = this.stakingService.LastStakedBlock, }; if (stakingInfo.LastStakedBlock.Hash == null) { stakingInfo.LastStakedBlock = null; } return(stakingInfo); }
public async Task <BrokerAccountsInfo> GetBrokerAccountsAsync(string accountId) { var result = await _node.GetAllBrokerAccountsForOwnerAsync(accountId); if (result.ResultCode == APIResultCodes.Success) { BrokerAccountsInfo accts = new BrokerAccountsInfo(); accts.owner = accountId; accts.profits = new List <ProfitInfo>(); accts.stakings = new List <StakingInfo>(); var blks = result.GetBlocks(); foreach (var blk in blks) { if (blk is IProfiting pft) { var pftinfo = new ProfitInfo { owner = pft.OwnerAccountId, pftid = (blk as TransactionBlock).AccountID, seats = pft.Seats, shareratio = pft.ShareRito, name = pft.Name, type = pft.PType.ToString() }; accts.profits.Add(pftinfo); } if (blk is IStaking stk) { decimal amt = 0; var lastblkret = await _node.GetLastBlockAsync((stk as TransactionBlock).AccountID); TransactionBlock lastblk = null; if (lastblkret.Successful()) { lastblk = lastblkret.GetBlock() as TransactionBlock; if (lastblk.Balances.ContainsKey(LyraGlobal.OFFICIALTICKERCODE)) { amt = lastblk.Balances[LyraGlobal.OFFICIALTICKERCODE].ToBalanceDecimal(); } } var laststk = lastblk as IStaking; var stkinfo = new StakingInfo { owner = stk.OwnerAccountId, stkid = (stk as TransactionBlock).AccountID, name = stk.Name, start = laststk.Start, amount = amt, days = laststk.Days, voting = laststk.Voting, compound = laststk.CompoundMode }; accts.stakings.Add(stkinfo); } } return(accts); } else { throw new Exception($"{result.ResultCode}: {result.ResultMessage}"); } }