Ejemplo n.º 1
0
        public static bool IsAddress(string _address, out byte?_version)
        {
            if (_address.ToLower().StartsWith("bc") || _address.ToLower().StartsWith("tb"))
            {
                _version = null; return(false);
            }

            return(Bitcoin.IsAddress(_address, out _version));
        }
Ejemplo n.º 2
0
        public static bool IsAddress(string _address, out byte?_version)
        {
            string _prefix = "";

            if (_address.IndexOf(':') > 0)
            {
                _prefix  = _address.Split(':')[0].ToLower();
                _address = _address.Split(':')[1].ToLower();
            }

            if (_address.ToLower().StartsWith("bc1") || _address.ToLower().StartsWith("tb1"))
            {
                _version = null; return(false);
            }
            if (Bitcoin.IsAddress(_address, out _version))
            {
                return(true);
            }

            bool _mainnet = false;

            if (_prefix == "bitcoincash" || _prefix == "")
            {
                _mainnet = true;
            }
            else if (_prefix == "bchtest")
            {
                _mainnet = false;
            }
            else
            {
                throw new Exception("Unexpected colon character.");
            }

            byte[] _decoded = new byte[42];
            for (int i = 0; i < _decoded.Length; i++)
            {
                int value = DICT_CASHADDR[_address[i]];
                if (value != -1)
                {
                    _decoded[i] = (byte)value;
                }
                else
                {
                    throw new Exception("Address contains unexpected character.");
                }
            }
            _decoded = Bits5to8(_decoded);

            bool _isP2PKH = false;

            switch (_decoded[0])
            {
            case 0x00:
                _isP2PKH = true;
                break;

            case 0x08:
                _isP2PKH = false;
                break;

            default:
                throw new Exception("Unexpected address byte.");
            }

            if (_mainnet && _isP2PKH)
            {
                _decoded[0] = 0x00;
            }
            else if (_mainnet && !_isP2PKH)
            {
                _decoded[0] = 0x05;
            }
            else if (!_mainnet && _isP2PKH)
            {
                _decoded[0] = 0x6f;
            }
            else
            {
                _decoded[0] = 0xc4;
            }

            _version = _decoded[0];
            return(true);
        }