Example #1
0
        /// <summary>
        ///     Decodes the given address into its constituting prefix, type and hash
        /// </summary>
        /// <param name="address">Address to decode. E.g.: 'bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a'</param>
        /// <returns>DecodeData</returns>
        public static CashAddrData Decode(string address)
        {
            var pieces = address.ToLower().Split(':');

            Validation.Validate(pieces.Length == 2, $"Missing prefix: {address}");
            var prefix  = pieces[0];
            var payload = Base32.Decode(pieces[1]);

            Validation.Validate(ValidChecksum(prefix, payload), $"Invalid checksum: {address}");
            var data        = payload.Take(payload.Length - 8).ToArray();
            var payloadData = FromByte5Array(data);
            var versionByte = payloadData[0];
            var hash        = payloadData.Skip(1).ToArray();

            Validation.Validate(GetHashSize(versionByte) == hash.Length * 8, $"Invalid hash size: {address}");
            var type = GetType(versionByte);

            return(new CashAddrData
            {
                Prefix = prefix,
                Type = type,
                Hash = hash
            });
        }