Example #1
0
            public override string Encode()
            {
                var buffer = new byte[1 + Ripemd160Hash.Length + Checksum.SumLength];

                buffer[0] = AddressPrefix.PayToScriptHashPrefix(IntendedBlockChain);
                Array.Copy(ScriptHash, 0, buffer, 1, Ripemd160Hash.Length);
                Checksum.WriteSum(buffer);
                return(Base58.Encode(buffer));
            }
Example #2
0
        public static bool TryDecode(string encodedAddress, out Address address)
        {
            byte[] base58DecodedAddress;
            if (!Base58.TryDecode(encodedAddress, out base58DecodedAddress))
            {
                address = null;
                return(false);
            }

            if (base58DecodedAddress.Length != 1 + Ripemd160Hash.Length + Checksum.SumLength)
            {
                address = null;
                return(false);
            }

            if (!Checksum.Verify(base58DecodedAddress))
            {
                address = null;
                return(false);
            }

            var addressID = base58DecodedAddress[0];
            BlockChainIdentity intendedBlockChain;

            if (AddressPrefix.IdentityForPubkeyHashPrefix(addressID, out intendedBlockChain))
            {
                var pubKeyHash = new byte[Ripemd160Hash.Length];
                Array.Copy(base58DecodedAddress, 1, pubKeyHash, 0, Ripemd160Hash.Length);
                address = new PayToPubKeyHash(intendedBlockChain, pubKeyHash);
                return(true);
            }
            else if (AddressPrefix.IdentityForScriptHashPrefix(addressID, out intendedBlockChain))
            {
                var scriptHash = new byte[Ripemd160Hash.Length];
                Array.Copy(base58DecodedAddress, 1, scriptHash, 0, Ripemd160Hash.Length);
                address = new PayToScriptHash(intendedBlockChain, scriptHash);
                return(true);
            }
            else
            {
                address = null;
                return(false);
            }
        }
Example #3
0
 public static bool IdentityForPubkeyHashPrefix(AddressPrefix prefix, out BlockChainIdentity identity)
 {
     if (prefix == MainNetPayToPubKeyHashPrefix)
     {
         identity = BlockChainIdentity.MainNet;
         return(true);
     }
     else if (prefix == TestNet3PayToPubKeyHashPrefix)
     {
         identity = BlockChainIdentity.TestNet3;
         return(true);
     }
     else if (prefix == SimNetPayToPubKeyHashPrefix)
     {
         identity = BlockChainIdentity.SimNet;
         return(true);
     }
     else
     {
         identity = null;
         return(false);
     }
 }
Example #4
0
 public static bool IdentityForScriptHashPrefix(AddressPrefix prefix, out BlockChainIdentity identity)
 {
     if (prefix == MainNetPayToScriptHashPrefix)
     {
         identity = BlockChainIdentity.MainNet;
         return true;
     }
     else if (prefix == TestNet3PayToScriptHashPrefix)
     {
         identity = BlockChainIdentity.TestNet3;
         return true;
     }
     else if (prefix == SimNetPayToScriptHashPrefix)
     {
         identity = BlockChainIdentity.SimNet;
         return true;
     }
     else
     {
         identity = null;
         return false;
     }
 }