<commit_before>using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using Nethereum.Hex.HexConvertors.Extensions;

namespace Nethereum.ABI.Decoders
{
    public class AddressTypeDecoder : TypeDecoder
    {
        private IntTypeDecoder intTypeDecoder;

        public AddressTypeDecoder()
        {
            this.intTypeDecoder = new IntTypeDecoder();

        }
        public override bool IsSupportedType(Type type)
        {
            return type == typeof(string);
        }

        public override object Decode(byte[] encoded, Type type)
        {
            if (!IsSupportedType(type)) throw new NotSupportedException(type + " is not supported");
            return intTypeDecoder.DecodeBigInteger(encoded).ToHex(false);
        }

    }

    public class IntTypeDecoder: TypeDecoder
    {
        public override bool IsSupportedType(Type type)
        {
            return type == typeof (int) || type == typeof (ulong) || type == typeof (long) || type == typeof (uint) ||
                   type == typeof (BigInteger);
        }


        public override object Decode(byte[] encoded, Type type)
        {
            if (type == typeof(int))
            {
                return DecodeInt(encoded);
            }

            if (type == typeof(long))
            {
                return DecodeLong(encoded);
            }

            if (type == typeof(ulong))
            {
                return DecodeULong(encoded);
            }

            if (type == typeof(uint))
            {
                return DecodeUInt(encoded);
            }

            if (type == typeof(BigInteger))
            {
                return DecodeBigInteger(encoded);
            }

            throw new NotSupportedException(type.ToString() + " is not a supported decoding type for IntType");
        }

        public int DecodeInt(byte[] encoded)
        {
            return (int)DecodeBigInteger(encoded);
        }

        public uint DecodeUInt(byte[] encoded)
        {
            return (uint)DecodeBigInteger(encoded);
        }

        public long DecodeLong(byte[] encoded)
        {
            return (long)DecodeBigInteger(encoded);
        }

        public ulong DecodeULong(byte[] encoded)
        {
            return (ulong)DecodeBigInteger(encoded);
        }

        public BigInteger DecodeBigInteger(string hexString)
        {
            if (!hexString.StartsWith("0x"))
            {
                hexString = "0x" + hexString;
            }

            return DecodeBigInteger(hexString.HexToByteArray());
        }

        public BigInteger DecodeBigInteger(byte[] encoded)
        {
            bool paddedPrefix = true;
            var unpaddedBytes = new List<byte>();

            bool negative = encoded.First() == 0xFF;

            if (BitConverter.IsLittleEndian)
            {
                encoded = encoded.Reverse().ToArray();
            }

            if (negative)
            {
                return new BigInteger(encoded) - new BigInteger("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff".HexToByteArray()) - 1;
            }

            //foreach (byte item in encoded)
            //{
            //    if ((item == 0 || item == 0xFF) && paddedPrefix)
            //    {
            //        if (item == 0xFF)
            //        {
            //            negative = true;
            //        }
            //    }

            //    if (!(item == 0 || item == 0xFF) && paddedPrefix)
            //    {
            //        paddedPrefix = false;
            //    }

            //    if (!paddedPrefix)
            //    {
            //        unpaddedBytes.Add(item);
            //    }
            //}

            //if (!unpaddedBytes.Any()) unpaddedBytes.Add(encoded.Last());

            //if (BitConverter.IsLittleEndian)
            //{
            //    if (!negative)
            //    {
            //        unpaddedBytes.Insert(0, 0x00);
            //    }
            //    encoded = unpaddedBytes.ToArray().Reverse().ToArray();
            //}

            return new BigInteger(encoded);
        }

      
    }
}<commit_msg>Tidying up<commit_after>using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using Nethereum.Hex.HexConvertors.Extensions;

namespace Nethereum.ABI.Decoders
{
    public class AddressTypeDecoder : TypeDecoder
    {
        private IntTypeDecoder intTypeDecoder;

        public AddressTypeDecoder()
        {
            this.intTypeDecoder = new IntTypeDecoder();

        }
        public override bool IsSupportedType(Type type)
        {
            return type == typeof(string);
        }

        public override object Decode(byte[] encoded, Type type)
        {
            if (!IsSupportedType(type)) throw new NotSupportedException(type + " is not supported");
            return intTypeDecoder.DecodeBigInteger(encoded).ToHex(false);
        }

    }

    public class IntTypeDecoder: TypeDecoder
    {
        public override bool IsSupportedType(Type type)
        {
            return type == typeof (int) || type == typeof (ulong) || type == typeof (long) || type == typeof (uint) ||
                   type == typeof (BigInteger);
        }


        public override object Decode(byte[] encoded, Type type)
        {
            if (type == typeof(int))
            {
                return DecodeInt(encoded);
            }

            if (type == typeof(long))
            {
                return DecodeLong(encoded);
            }

            if (type == typeof(ulong))
            {
                return DecodeULong(encoded);
            }

            if (type == typeof(uint))
            {
                return DecodeUInt(encoded);
            }

            if (type == typeof(BigInteger))
            {
                return DecodeBigInteger(encoded);
            }

            throw new NotSupportedException(type.ToString() + " is not a supported decoding type for IntType");
        }

        public int DecodeInt(byte[] encoded)
        {
            return (int)DecodeBigInteger(encoded);
        }

        public uint DecodeUInt(byte[] encoded)
        {
            return (uint)DecodeBigInteger(encoded);
        }

        public long DecodeLong(byte[] encoded)
        {
            return (long)DecodeBigInteger(encoded);
        }

        public ulong DecodeULong(byte[] encoded)
        {
            return (ulong)DecodeBigInteger(encoded);
        }

        public BigInteger DecodeBigInteger(string hexString)
        {
            if (!hexString.StartsWith("0x"))
            {
                hexString = "0x" + hexString;
            }

            return DecodeBigInteger(hexString.HexToByteArray());
        }

        public BigInteger DecodeBigInteger(byte[] encoded)
        {
            bool paddedPrefix = true;

            bool negative = encoded.First() == 0xFF;

            if (BitConverter.IsLittleEndian)
            {
                encoded = encoded.Reverse().ToArray();
            }
            
            if (negative)
            {
                return new BigInteger(encoded) - new BigInteger("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff".HexToByteArray()) - 1;
            }

            return new BigInteger(encoded);
        }

      
    }
}
{'fraction_non_alphanumeric': 0.09886086248982913, 'fraction_numerical': 0.0025766205587198264, 'mean_word_length': 1.454242928452579, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6637039', 'n_tokens_mistral': 1923, 'n_tokens_neox': 1812, 'n_words': 399}