/// <summary> /// Parse Message from Doge transaction (from OP_RETURN) /// </summary> /// <param name="txinfo"></param> /// <returns></returns> public static CommonReturnTypeDto ParseDogeMessage(GetTransactionInfoResponse txinfo) { if (txinfo == null) { return(CommonReturnTypeDto.GetNew(false, "No input data provided.")); } if (txinfo.Success != "success") { return(CommonReturnTypeDto.GetNew(false, "No input data provided.")); } if (txinfo.Transaction.Vout == null || txinfo.Transaction.Vout.Count == 0) { return(CommonReturnTypeDto.GetNew(false, "No outputs in transaction.")); } foreach (var o in txinfo.Transaction.Vout) { if (!string.IsNullOrEmpty(o.Script) && o.Script.Contains("OP_RETURN")) { var message = o.Script.Replace("OP_RETURN ", string.Empty); var bytes = HexStringToBytes(message); var msg = Encoding.UTF8.GetString(bytes); return(CommonReturnTypeDto.GetNew(true, msg)); } } return(CommonReturnTypeDto.GetNew <string>()); }
/// <summary> /// Parse the total sent value from Doge Tx Info. It takes all outputs together. /// </summary> /// <param name="txinfo"></param> /// <returns></returns> public static CommonReturnTypeDto ParseTotalSentValue(GetTransactionInfoResponse txinfo) { if (txinfo == null) { return(CommonReturnTypeDto.GetNew <double>()); } if (txinfo.Success != "success") { return(CommonReturnTypeDto.GetNew <double>()); } if (txinfo.Transaction.Vout == null || txinfo.Transaction.Vout.Count == 0) { return(CommonReturnTypeDto.GetNew <double>()); } var value = 0.0; var vouts = txinfo.Transaction.Vout.ToList(); for (var i = 0; i < (vouts.Count - 2); i++) { var o = vouts[i]; if (!string.IsNullOrEmpty(o.Script) && !o.Script.Contains("OP_RETURN")) { var v = Convert.ToDouble(o.Value, CultureInfo.InvariantCulture); value += v; } } return(CommonReturnTypeDto.GetNew(true, value)); }
/// <summary> /// Get Address from Dogecoin private key /// </summary> /// <param name="privatekey">Excpected Dogecoin private key</param> /// <returns>true and Address if it is correct Dogecoin private key</returns> public static CommonReturnTypeDto GetAddressFromPrivateKey(string privatekey) { try { var p = IsPrivateKeyValid(privatekey); if (p.Success) { BitcoinSecret secret = (BitcoinSecret)p.Value; var address = secret.PubKey.GetAddress(ScriptPubKeyType.Legacy, Network); if (address != null) { return(CommonReturnTypeDto.GetNew <string>(true, address.ToString())); } } } catch (Exception) { return(CommonReturnTypeDto.GetNew <string>()); } return(CommonReturnTypeDto.GetNew <string>()); }
/////////////////////////////////////////// // Tools for addresses /// <summary> /// Verify the Dogecoin address /// </summary> /// <param name="dogeAddress">Excpected Dogecoin address</param> /// <returns>true and Address if it is correct Dogecoin Address</returns> public static CommonReturnTypeDto ValidateDogeAddress(string dogeAddress) { try { if (string.IsNullOrEmpty(dogeAddress) || dogeAddress.Length < 34 || dogeAddress[0] != 'D') { return(CommonReturnTypeDto.GetNew <string>());; } var add = BitcoinAddress.Create(dogeAddress, Network); if (!string.IsNullOrEmpty(add.ToString())) { return(CommonReturnTypeDto.GetNew(true, add.ToString())); } } catch (Exception) { return(CommonReturnTypeDto.GetNew <string>()); } return(CommonReturnTypeDto.GetNew <string>()); }
/// <summary> /// Verify the Dogecoin private key /// </summary> /// <param name="privatekey">Excpected Dogecoin private key</param> /// <returns>true and NBitcoin.BitcoinSecret if it is correct Dogecoin private key</returns> public static CommonReturnTypeDto IsPrivateKeyValid(string privatekey) { try { if (string.IsNullOrEmpty(privatekey) || privatekey.Length < 52 || privatekey[0] != 'Q') { return(CommonReturnTypeDto.GetNew <BitcoinSecret>()); } var sec = new BitcoinSecret(privatekey, Network); if (sec != null) { return(CommonReturnTypeDto.GetNew(true, sec)); } } catch (Exception) { return(CommonReturnTypeDto.GetNew <BitcoinSecret>()); } return(CommonReturnTypeDto.GetNew <BitcoinSecret>()); }