Beispiel #1
0
        /// <summary>
        /// Creates an Address instance from a Protobuf representation of an address.
        /// </summary>
        /// <param name="protobufAddress"><see cref="Protobuf.Address"/> instance.</param>
        /// <returns>An address</returns>
        public static Address FromProtobufAddress(Protobuf.Address protobufAddress)
        {
            if (protobufAddress == null)
            {
                throw new ArgumentNullException(nameof(protobufAddress));
            }

            return(FromBytes(
                       protobufAddress.Local.ToByteArray(),
                       String.IsNullOrWhiteSpace(protobufAddress.ChainId) ? DefaultChainId : protobufAddress.ChainId));
        }
Beispiel #2
0
        /// <summary>
        /// Creates an Address instance from a Protobuf representation of an address.
        /// </summary>
        /// <param name="protobufAddress"><see cref="Protobuf.Address"/> instance.</param>
        /// <returns>An address</returns>
        public static Address FromProtobufAddress(Protobuf.Address protobufAddress)
        {
            if (protobufAddress == null)
            {
                throw new ArgumentNullException(nameof(protobufAddress));
            }

            if (protobufAddress.Local == null)
            {
                throw new ArgumentNullException(nameof(protobufAddress.Local));
            }

            if (protobufAddress.Local.Length != AddressLengthBytes)
            {
                throw new ArgumentException("Local address must have a length of 20 bytes", nameof(protobufAddress.Local));
            }

            return(new Address(
                       CryptoUtils.BytesToHexString(protobufAddress.Local.ToByteArray()),
                       String.IsNullOrWhiteSpace(protobufAddress.ChainId) ? DefaultChainId : protobufAddress.ChainId
                       ));
        }