//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 <string> GetBalance(string scriptHash, string decimals) { string balance = string.Empty; var result = await GetTokenBalance.SendRequestAsync(scriptHash); if (result != null) { balance = result.Stack[0].Value.ToString(); var supplyValueArray = balance.HexToBytes().Reverse().ToArray(); // todo, add explanation for this balance = BitConverter.ToString(supplyValueArray).Replace("-", ""); balance = GetDecimal(HexToBigInteger(balance), (int)DecimalStringToBigInteger(decimals)); } return(balance); }
public async Task <decimal> GetBalance(string tokenScriptHash, string addressScriptHash, int decimals = 0) { var result = await GetTokenBalance.SendRequestAsync(addressScriptHash, tokenScriptHash); if (result.State == "FAULT, BREAK") { throw new RpcResponseException(new RpcError(0, "RPC state response: FAULT, BREAK ")); } var balanceBigInteger = new BigInteger(result.Stack[0].Value.ToString().HexStringToBytes()); if (decimals.Equals(0)) { return((decimal)balanceBigInteger); } var balance = Nep5Helper.CalculateDecimalFromBigInteger(balanceBigInteger, decimals); return(balance); }
public async Task <string> GetBalance(string addressScriptHash) { var result = await GetTokenBalance.SendRequestAsync(addressScriptHash).ConfigureAwait(false); return(result.Stack[0].Value.ToString()); }