Ejemplo n.º 1
0
        internal static void AdvanceTip(DBConnection conn, HDWallet wallet, ChainedHeader newTip, uint256 prevTipHash)
        {
            uint256 lastBlockSyncedHash   = newTip?.HashBlock ?? uint256.Zero;
            int     lastBlockSyncedHeight = newTip?.Height ?? -1;
            string  blockLocator          = "";

            if (newTip != null)
            {
                blockLocator = string.Join(",", newTip?.GetLocator().Blocks);
            }

            conn.Execute($@"
                    UPDATE HDWallet
                    SET    LastBlockSyncedHash = ?,
                           LastBlockSyncedHeight = ?,
                           BlockLocator = ?
                    WHERE  LastBlockSyncedHash = ? {
                    // Respect the wallet name if provided.
                    ((wallet?.Name != null) ? $@"
                    AND    Name = {DBParameter.Create(wallet?.Name)}" : "")}",
                         lastBlockSyncedHash.ToString(),
                         lastBlockSyncedHeight,
                         blockLocator,
                         prevTipHash.ToString());
        }
Ejemplo n.º 2
0
        /*
         * internal static HeightHashPair GreatestBlockHeightBeforeOrAt(SQLiteConnection conn, int walletId, int height)
         * {
         *  return conn.FindWithQuery<HeightHashPair>($@"
         *      SELECT  OutputBlockHeight BlockHeight
         *      ,       OutputBlockHash BlockHash
         *      FROM    HDTransactionData
         *      WHERE   WalletId = { walletId }
         *      AND     OutputBlockHeight <= { height }
         *      UNION   ALL
         *      SELECT  SpendBlockHeight BlockHeight
         *      ,       SpendBlockHash BlockHash
         *      FROM    HDTransactionData
         *      WHERE   WalletId = { walletId }
         *      AND     SpendBlockHeight <= { height }
         *      ORDER   BY BlockHeight desc
         *      LIMIT   1");
         * }
         */

        internal static void AdvanceTip(SQLiteConnection conn, HDWallet wallet, ChainedHeader newTip, uint256 prevTipHash)
        {
            uint256 lastBlockSyncedHash   = newTip?.HashBlock ?? uint256.Zero;
            int     lastBlockSyncedHeight = newTip?.Height ?? -1;
            string  blockLocator          = "";

            if (newTip != null)
            {
                blockLocator = string.Join(",", newTip?.GetLocator().Blocks);
            }

            conn.Execute($@"
                    UPDATE HDWallet
                    SET    LastBlockSyncedHash = '{lastBlockSyncedHash}',
                           LastBlockSyncedHeight = {lastBlockSyncedHeight},
                           BlockLocator = '{blockLocator}'
                    WHERE  LastBlockSyncedHash = '{prevTipHash}' {
                    // Respect the wallet name if provided.
                    ((wallet?.Name != null) ? $@"
                    AND    Name = '{wallet?.Name}'" : "")}");
        }