/// <inheritdoc />
        public void AddAll(int?walletId = null, int?accountIndex = null, int?addressType = null)
        {
            Guard.Assert((walletId ?? this.walletId) == (this.walletId ?? walletId));

            walletId = this.walletId ?? walletId;

            string strWalletId     = DBParameter.Create(walletId);
            string strAccountIndex = DBParameter.Create(accountIndex);
            string strAddressType  = DBParameter.Create(addressType);

            List <HDAddress> addresses = this.conn.Query <HDAddress>($@"
                SELECT  *
                FROM    HDAddress {
                // Restrict to wallet if provided.
                ((walletId != null) ? $@"
                WHERE   WalletId = {strWalletId}" : "")} {
                // Restrict to account if provided.
                ((accountIndex != null) ? $@"
                AND     AccountIndex = {strAccountIndex}" : "")} {
                // Restrict to account if provided.
                ((addressType != null) ? $@"
                AND     AddressType = {strAddressType}" : "")}");

            foreach (HDAddress address in addresses)
            {
                this.Add(Script.FromHex(address.ScriptPubKey));
            }
        }
예제 #2
0
        /// <inheritdoc />
        public void AddAll(int?walletId = null, int?accountIndex = null)
        {
            Guard.Assert((walletId ?? this.walletId) == (this.walletId ?? walletId));

            walletId = this.walletId ?? walletId;

            string strWalletId     = DBParameter.Create(walletId);
            string strAccountIndex = DBParameter.Create(accountIndex);

            List <HDTransactionData> spendableTransactions = this.conn.Query <HDTransactionData>($@"
                SELECT  *
                FROM    HDTransactionData
                WHERE   SpendBlockHash IS NULL
                AND     SpendBlockHeight IS NULL {
                // Restrict to wallet if provided.
                ((walletId != null) ? $@"
                AND      WalletId = {strWalletId}" : "")}{
                // Restrict to account if provided.
                ((accountIndex != null) ? $@"
                AND     AccountIndex = {strAccountIndex}" : "")}");

            foreach (HDTransactionData transactionData in spendableTransactions)
            {
                this.Add(new OutPoint(uint256.Parse(transactionData.OutputTxId), transactionData.OutputIndex));
            }
        }
        /// <inheritdoc />
        public void AddSpendableTransactions(int?walletId = null, int?accountIndex = null, int?fromBlock = null)
        {
            Guard.Assert((walletId ?? this.walletId) == (this.walletId ?? walletId));

            walletId = this.walletId ?? walletId;

            string strWalletId     = DBParameter.Create(walletId);
            string strAccountIndex = DBParameter.Create(accountIndex);

            List <HDTransactionData> spendableTransactions = this.conn.Query <HDTransactionData>($@"
                SELECT  *
                FROM    HDTransactionData{((fromBlock == null) ? $@"
                WHERE   SpendBlockHash IS NULL
                AND     SpendBlockHeight IS NULL" : $@"
                WHERE   SpendBlockHeight > {fromBlock} ")}{
        public void DBParameterFormatsNumbersWithoutCommas()
        {
            CultureInfo culture   = Thread.CurrentThread.CurrentCulture;
            CultureInfo cultureUI = Thread.CurrentThread.CurrentUICulture;

            foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.AllCultures))
            {
                Thread.CurrentThread.CurrentCulture   = ci;
                Thread.CurrentThread.CurrentUICulture = ci;

                Assert.Equal("1234", DBParameter.Create((int)1234));
                Assert.Equal("1234", DBParameter.Create((long)1234));
            }

            Thread.CurrentThread.CurrentCulture   = culture;
            Thread.CurrentThread.CurrentUICulture = cultureUI;
        }
        private bool Exists(Script scriptPubKey, out AddressIdentifier address)
        {
            string strWalletId = DBParameter.Create(this.walletId);
            string strHex      = DBParameter.Create(scriptPubKey.ToHex());

            address = this.conn.FindWithQuery <AddressIdentifier>($@"
                        SELECT  WalletId
                        ,       AccountIndex
                        ,       AddressType
                        ,       AddressIndex
                        ,       ScriptPubKey
                        FROM    HDAddress
                        WHERE   ScriptPubKey = {strHex} {
                    // Restrict to wallet if provided.
                    // "BETWEEN" boosts performance from half a seconds to 2ms.
                    ((this.walletId != null) ? $@"
                        AND     WalletId BETWEEN {strWalletId} AND {strWalletId}" : "")};");

            return(address != null);
        }
예제 #6
0
        private bool Exists(OutPoint outPoint, out HashSet <AddressIdentifier> addresses)
        {
            string strWalletId = DBParameter.Create(this.walletId);

            addresses = new HashSet <AddressIdentifier>(
                this.conn.Query <AddressIdentifier>($@"
                SELECT  WalletId
                ,       AccountIndex
                ,       AddressType
                ,       AddressIndex
                ,       ScriptPubKey
                FROM    HDTransactionData
                WHERE   OutputTxId = ?
                AND     OutputIndex = ? {
                // Restrict to wallet if provided.
                // "BETWEEN" boosts performance from half a seconds to 2ms.
                ((this.walletId != null) ? $@"
                AND     WalletId BETWEEN {strWalletId} AND {strWalletId}" : $@"
                AND     WalletId IN (SELECT WalletId FROM HDWallet)")}",
                                                    outPoint.Hash.ToString(),
                                                    outPoint.N));

            return(addresses.Count != 0);
        }