From 396d9d6a80daf6f37f341993baf04e4f34130ac3 Mon Sep 17 00:00:00 2001 From: kanoi Date: Wed, 10 Sep 2014 17:09:35 +1000 Subject: [PATCH] sql - script to show the diffacc of a block for verification --- sql/bs.sql | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 sql/bs.sql diff --git a/sql/bs.sql b/sql/bs.sql new file mode 100644 index 00000000..9c948f20 --- /dev/null +++ b/sql/bs.sql @@ -0,0 +1,44 @@ +SET SESSION AUTHORIZATION 'postgres'; + +DO $$ +DECLARE + hi INT; + hi0 INT; + wi BIGINT; + wi0 BIGINT; + ssc INT; + da BIGINT; +BEGIN + hi := 318177; + + -- This will randomly choose between multiple blocks of the same height + -- if we happen to orphan ourselves + select workinfoid from blocks where height = hi + and expirydate > '6666-06-01' into wi; + IF NOT found THEN + RAISE EXCEPTION 'Block % not found', hi; + END IF; + + select max(height) from blocks where height < hi into hi0; + IF found THEN + wi0 := -1; + ELSE + select workinfoid from blocks where height = hi0 + and expirydate > '6666-06-01' into Wi0; + END IF; + + RAISE WARNING 'Block: %(%)', hi, wi; + RAISE WARNING 'Previous block: %(%)', hi0, wi0; + + select count(*) from sharesummary where workinfoid > wi0 + and workinfoid <= wi and complete = 'n' into ssc; + + IF ssc > 0 THEN + RAISE EXCEPTION 'Unaged sharesummary records: %', ssc; + ELSE + select sum(diffacc) from sharesummary where workinfoid > wi0 + and workinfoid <= wi into da; + + RAISE WARNING 'diffacc: %', da; + END IF; +END $$;