//TODO: can refractor this more public void ChangeTokenScripHash(string tokenScriptHash) { if (string.IsNullOrEmpty(tokenScriptHash)) { throw new ArgumentNullException(nameof(tokenScriptHash)); } TokenScriptHash = tokenScriptHash; GetTokenBalance.ChangeScriptHash(tokenScriptHash); GetTokenDecimals.ChangeScriptHash(tokenScriptHash); GetTokenName.ChangeScriptHash(tokenScriptHash); GetTokenTotalSupply.ChangeScriptHash(tokenScriptHash); GetTokenSymbol.ChangeScriptHash(tokenScriptHash); }
public async Task <decimal> GetTotalSupply(string tokenScriptHash, int decimals = 8) { var result = await GetTokenTotalSupply.SendRequestAsync(tokenScriptHash); if (result.State == "FAULT, BREAK") { throw new RpcResponseException(new RpcError(0, "RPC state response: FAULT, BREAK ")); } var totalSupplyBigInteger = new BigInteger(result.Stack[0].Value.ToString().HexStringToBytes()); if (decimals.Equals(0)) { return((decimal)totalSupplyBigInteger); } var totalSupply = Nep5Helper.CalculateDecimalFromBigInteger(totalSupplyBigInteger, decimals); return(totalSupply); }
public async Task <string> GetTotalSupply(string decimals) { string totalSupply = string.Empty; if (string.IsNullOrEmpty(decimals)) { return(totalSupply); } var result = await GetTokenTotalSupply.SendRequestAsync(); if (result != null) { var value = result.Stack[0].Value.ToString(); var supplyValueArray = value.HexToBytes().Reverse().ToArray(); // todo, add explanation for this value = BitConverter.ToString(supplyValueArray).Replace("-", ""); totalSupply = (HexToBigInteger(value) / DecimalStringToBigInteger(decimals)).ToString(); } return(totalSupply); }
public async Task <string> GetTotalSupply() { var result = await GetTokenTotalSupply.SendRequestAsync().ConfigureAwait(false); return(result.Stack[0].Value.ToString()); }