コード例 #1
0
ファイル: Address.cs プロジェクト: tuxcanfly/Paymetheus
        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 (BlockChainIdentity.IdentityForPubKeyHashID(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 (BlockChainIdentity.IdentityForScriptHashID(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;
            }
        }
コード例 #2
0
ファイル: Address.cs プロジェクト: tuxcanfly/Paymetheus
        public static bool TryFromOutputScript(OutputScript pkScript, BlockChainIdentity intendedBlockChain, out Address address)
        {
            var payToPubKeyHashScript = pkScript as OutputScript.PubKeyHash;
            if (payToPubKeyHashScript != null)
            {
                address = new PayToPubKeyHash(intendedBlockChain, payToPubKeyHashScript.Hash160);
                return true;
            }

            var payToScriptHashScript = pkScript as OutputScript.ScriptHash;
            if (payToScriptHashScript != null)
            {
                address = new PayToScriptHash(intendedBlockChain, payToScriptHashScript.Hash160);
                return true;
            }

            address = null;
            return false;
        }