Exemplo n.º 1
0
        /// <summary>
        /// Encodes the given decoded address into cashaddr format
        /// </summary>
        /// <param name="decoded"></param>
        /// <returns></returns>
        public static string EncodeAsCashaddr(BchAddrData decoded)
        {
            var prefix = GetCashaddrkPrefix(decoded);
            var type   = decoded.Type == CashType.P2PKH ? "P2PKH" : "P2SH";
            var hash   = decoded.Hash;

            return(CashAddr.Encode(prefix, type, hash));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Attempts to decode the given address assuming it is a cashaddr address with explicit prefix
        /// </summary>
        /// <param name="address">A valid Bitcoin Cash address in any format</param>
        /// <returns></returns>
        private static BchAddrData DecodeCashAddressWithPrefix(string address)
        {
            var decoded = CashAddr.Decode(address);
            var type    = decoded.Type == "P2PKH" ? CashType.P2PKH : CashType.P2SH;

            switch (decoded.Prefix)
            {
            case "bitcoincash":
                return(BchAddrData.Create(CashFormat.Cashaddr, CashNetwork.Mainnet, type, decoded.Hash));

            case "bchtest":
                return(BchAddrData.Create(CashFormat.Cashaddr, CashNetwork.Testnet, type, decoded.Hash));

            case "regtest":
                return(BchAddrData.Create(CashFormat.Cashaddr, CashNetwork.RegTest, type, decoded.Hash));
            }
            throw new Validation.ValidationError($"Invalid address {address}");
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Attempts to decode the given address assuming it is a cashaddr address with explicit prefix
        /// </summary>
        /// <param name="address">A valid Bitcoin Cash address in any format</param>
        /// <returns></returns>
        private static BchAddrData DecodeCashAddressWithPrefix(string address, Network network)
        {
            var decoded = CashAddr.Decode(address);

            return(BchAddrData.Create(CashFormat.Cashaddr, network, decoded.Type, decoded.Hash));
        }
Exemplo n.º 4
0
 /// <summary>
 ///     Encodes the given decoded address into cashaddr format
 /// </summary>
 /// <param name="decoded"></param>
 /// <returns></returns>
 public static string EncodeAsCashaddr(BchAddrData decoded)
 {
     return(CashAddr.Encode(decoded.Prefix, decoded.Type, decoded.Hash));
 }