Exemplo n.º 1
0
 public static bool VerifyFormattedAddress(string formattedAddress)
 {
     if (string.IsNullOrEmpty(formattedAddress))
     {
         return(false);
     }
     return(Base58CheckEncoding.Verify(formattedAddress));
 }
Exemplo n.º 2
0
 public string GetFormatted()
 {
     if (_formatted != null)
     {
         return(_formatted);
     }
     return(_formatted = (TypeConsts.AElfAddressPrefix + "_") + Address.GetFormatted() +
                         ("_" + Base58CheckEncoding.Encode(ChainId.DumpByteArray())));
 }
Exemplo n.º 3
0
        public static int ConvertBase58ToChainId(string base58String)
        {
            // Use int type to save chain id (4 base58 chars, default is 3 bytes)
            var bytes = Base58CheckEncoding.DecodePlain(base58String);

            if (bytes.Length < 4)
            {
                Array.Resize(ref bytes, 4);
            }

            return(bytes.ToInt32(false));
        }
Exemplo n.º 4
0
        public static ChainAddress Parse(string str)
        {
            var arr = str.Split('_');

            if (arr[0] != TypeConsts.AElfAddressPrefix)
            {
                throw new ArgumentException("invalid chain address", nameof(str));
            }

            var address = Address.Parse(arr[1]);

            var chainId = BitConverter.ToInt32(Base58CheckEncoding.Decode(arr[2]), 0);

            return(new ChainAddress(address, chainId));
        }
Exemplo n.º 5
0
        public string GetFormatted()
        {
            if (_formattedAddress != null)
            {
                return(_formattedAddress);
            }

            if (Value.Length != TypeConsts.AddressHashLength)
            {
                throw new ArgumentOutOfRangeException(
                          $"Serialized value does not represent a valid address. The input is {Value.Length} bytes long.");
            }

            var pubKeyHash = Base58CheckEncoding.Encode(Value.ToByteArray());

            return(_formattedAddress = pubKeyHash);
        }
Exemplo n.º 6
0
 public static byte[] DecodeBase58(this string value)
 {
     return(Base58CheckEncoding.DecodePlain(value));
 }
Exemplo n.º 7
0
 public static string ToPlainBase58(this byte[] value)
 {
     return(Base58CheckEncoding.EncodePlain(value));
 }
Exemplo n.º 8
0
 public static Address Base58StringToAddress(string inputStr)
 {
     return(Address.FromBytes(Base58CheckEncoding.Decode(inputStr)));
 }
Exemplo n.º 9
0
 public static Address Parse(string inputStr)
 {
     return(new Address(Base58CheckEncoding.Decode(inputStr)));
 }