Skip to content

Commit 560c2ba

Browse files
committed
refactor sqlthread and add test cases
1 parent ec2143f commit 560c2ba

26 files changed

+993
-297
lines changed

src/bmconfigparser.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
from six import string_types
1111
from six.moves import configparser
1212

13-
import state
14-
from singleton import Singleton
13+
try:
14+
import state
15+
from singleton import Singleton
16+
except ImportError:
17+
from . import state
18+
from .singleton import Singleton
1519

1620
SafeConfigParser = configparser.SafeConfigParser
1721

src/class_sqlThread.py

Lines changed: 183 additions & 282 deletions
Large diffs are not rendered by default.

src/helper_startup.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
"""
22
Startup operations.
33
"""
4-
# pylint: disable=too-many-branches,too-many-statements
5-
64
import logging
75
import os
86
import platform
9-
import sys
107
import time
118
from distutils.version import StrictVersion
12-
139
import sys
1410
if sys.version_info[0] == 3:
1511
from . import defaults
@@ -29,6 +25,8 @@
2925
except ImportError:
3026
get_plugin = None
3127

28+
# pylint: disable=too-many-branches,too-many-statements
29+
3230

3331
logger = logging.getLogger('default')
3432

src/sql/__init__.py

Whitespace-only changes.

src/sql/init_version_1.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
--
3+
-- Alter table `inventory`
4+
--
5+
6+
ALTER TABLE inventory ADD tag blob DEFAULT '';

src/sql/init_version_10.sql

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
-- --
2+
-- -- Alter table `addressbook`
3+
-- --
4+
5+
ALTER TABLE addressbook RENAME TO old_addressbook;
6+
7+
8+
-- --
9+
-- -- Table structure for table `addressbook`
10+
-- --
11+
12+
CREATE TABLE `addressbook` (
13+
`label` text NOT NULL,
14+
`address` text NOT NULL,
15+
UNIQUE(address) ON CONFLICT IGNORE
16+
) ;
17+
18+
-- --
19+
-- -- Table Query for `pubkeys_backup`
20+
-- --
21+
22+
INSERT INTO addressbook SELECT label, address FROM old_addressbook;
23+
24+
25+
-- --
26+
-- -- Drop table `old_addressbook`
27+
-- --
28+
29+
DROP TABLE old_addressbook;

src/sql/init_version_2.sql

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
--
2+
-- Temp Table structure for table `inventory_backup`
3+
--
4+
5+
CREATE TEMP TABLE `inventory_backup` (
6+
`hash` blob NOT NULL,
7+
`objecttype` text DEFAULT NULL,
8+
`streamnumber` int NOT NULL,
9+
`receivedtime` int NOT NULL,
10+
`payload` blob DEFAULT NULL,
11+
-- `integer` integer NOT NULL,
12+
-- `tag` blob DEFAULT NULL,
13+
UNIQUE(hash) ON CONFLICT REPLACE
14+
) ;
15+
16+
--
17+
-- Dumping data for table `inventory_backup`
18+
--
19+
20+
INSERT INTO `inventory_backup` SELECT hash, objecttype, streamnumber, payload, receivedtime FROM inventory;
21+
22+
23+
--
24+
-- Drop table `inventory`
25+
--
26+
27+
DROP TABLE inventory;
28+
29+
30+
--
31+
-- Table structure for table `inventory`
32+
--
33+
34+
35+
CREATE TABLE `inventory` (
36+
`hash` blob NOT NULL,
37+
`objecttype` text DEFAULT NULL,
38+
`streamnumber` int NOT NULL,
39+
`receivedtime` int NOT NULL,
40+
`payload` blob DEFAULT NULL,
41+
UNIQUE(hash) ON CONFLICT REPLACE
42+
) ;
43+
44+
45+
--
46+
-- Dumping data for table `inventory`
47+
--
48+
49+
INSERT INTO inventory SELECT hash, objecttype, streamnumber, payload, receivedtime FROM inventory_backup;
50+
51+
--
52+
-- Drop data for table `inventory_backup`
53+
--
54+
55+
DROP TABLE inventory_backup;

src/sql/init_version_4.sql

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--
2+
-- Drop Table `pubkeys`
3+
--
4+
5+
DROP TABLE pubkeys;
6+
7+
8+
--
9+
-- Table structure for table `pubkeys`
10+
--
11+
12+
13+
CREATE TABLE `pubkeys` (
14+
`hash` blob NOT NULL,
15+
`addressversion` int DEFAULT NULL,
16+
`transmitdata` blob NOT NULL,
17+
`time` int NOT NULL,
18+
`usedpersonally` text DEFAULT NULL,
19+
UNIQUE(hash, addressversion) ON CONFLICT REPLACE
20+
) ;
21+
22+
--
23+
-- Drop from Table `pubkeys`
24+
--
25+
26+
DELETE FROM inventory WHERE objecttype = 'pubkey';

src/sql/init_version_5.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--
2+
-- Drop Table `knownnodes`
3+
--
4+
5+
DROP TABLE knownnodes;
6+
7+
8+
--
9+
-- Table structure for table `objectprocessorqueue`
10+
--
11+
12+
13+
CREATE TABLE `objectprocessorqueue` (
14+
`objecttype` text DEFAULT NULL,
15+
`data` blob DEFAULT NULL,
16+
UNIQUE(objecttype, data) ON CONFLICT REPLACE
17+
) ;

src/sql/init_version_6.sql

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
-- --
2+
-- -- Drop table `inventory`
3+
-- --
4+
5+
DROP TABLE inventory;
6+
7+
8+
-- --
9+
-- -- Table structure for table `inventory`
10+
-- --
11+
12+
13+
CREATE TABLE `inventory` (
14+
`hash` blob NOT NULL,
15+
`objecttype` int DEFAULT NULL,
16+
`streamnumber` int NOT NULL,
17+
`payload` blob NOT NULL,
18+
`expirestime` integer DEFAULT NULL,
19+
`tag` blob DEFAULT NULL,
20+
UNIQUE(hash) ON CONFLICT REPLACE
21+
) ;
22+
23+
-- --
24+
-- -- Drop table `inventory`
25+
-- --
26+
27+
DROP TABLE objectprocessorqueue;
28+
29+
30+
-- --
31+
-- -- Table structure for table `objectprocessorqueue`
32+
-- --
33+
34+
35+
CREATE TABLE `objectprocessorqueue` (
36+
`objecttype` int DEFAULT NULL,
37+
`data` blob DEFAULT NULL,
38+
UNIQUE(objecttype, data) ON CONFLICT REPLACE
39+
) ;

src/sql/init_version_7.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- --
2+
-- -- Drop table `inventory`
3+
-- --
4+
5+
DELETE FROM inventory WHERE objecttype = 1;
6+
7+
-- --
8+
-- -- Drop table `pubkeys`
9+
-- --
10+
11+
DELETE FROM pubkeys;
12+
13+
14+
-- --
15+
-- -- Update table `pubkeys`
16+
-- --
17+
18+
UPDATE sent SET status='msgqueued' WHERE status='doingmsgpow' or status='badkey';

src/sql/init_version_8.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- --
2+
-- -- Alter table `inbox`
3+
-- --
4+
5+
ALTER TABLE inbox ADD sighash blob DEFAULT '';

src/sql/init_version_9.sql

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
-- --
2+
-- -- Table structure for table `sent_backup`
3+
-- --
4+
5+
6+
CREATE TEMPORARY TABLE `sent_backup` (
7+
`msgid` blob DEFAULT NULL,
8+
`toaddress` text DEFAULT NULL,
9+
`toripe` blob DEFAULT NULL,
10+
`fromaddress` text DEFAULT NULL,
11+
`subject` text DEFAULT NULL,
12+
`message` text DEFAULT NULL,
13+
`ackdata` blob DEFAULT NULL,
14+
`lastactiontime` integer DEFAULT NULL,
15+
`status` text DEFAULT NULL,
16+
`retrynumber` integer DEFAULT NULL,
17+
`folder` text DEFAULT NULL,
18+
`encodingtype` int DEFAULT NULL
19+
) ;
20+
21+
22+
-- --
23+
-- -- Dumping data for table `sent_backup`
24+
-- --
25+
26+
INSERT INTO sent_backup SELECT msgid, toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, status, 0, folder, encodingtype FROM sent;
27+
28+
29+
-- --
30+
-- -- Drope table `sent`
31+
-- --
32+
33+
DROP TABLE sent;
34+
35+
36+
-- --
37+
-- -- Table structure for table `sent_backup`
38+
-- --
39+
40+
41+
CREATE TABLE `sent` (
42+
`msgid` blob DEFAULT NULL,
43+
`toaddress` text DEFAULT NULL,
44+
`toripe` blob DEFAULT NULL,
45+
`fromaddress` text DEFAULT NULL,
46+
`subject` text DEFAULT NULL,
47+
`message` text DEFAULT NULL,
48+
`ackdata` blob DEFAULT NULL,
49+
`senttime` integer DEFAULT NULL,
50+
`lastactiontime` integer DEFAULT NULL,
51+
`sleeptill` int DEFAULT NULL,
52+
`status` text DEFAULT NULL,
53+
`retrynumber` integer DEFAULT NULL,
54+
`folder` text DEFAULT NULL,
55+
`encodingtype` int DEFAULT NULL,
56+
`ttl` int DEFAULT NULL
57+
) ;
58+
59+
60+
-- --
61+
-- -- Dumping data for table `sent`
62+
-- --
63+
64+
65+
INSERT INTO sent SELECT msgid, toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, lastactiontime, 0, status, 0, folder, encodingtype, 216000 FROM sent_backup;
66+
67+
68+
--UPDATE pubkeys SET address= (select enaddr(?, ?, ?)", (addressVersion, 1, addressHash)) WHERE hash=?
69+
70+
-- --
71+
-- -- Drop table `sent`
72+
-- --
73+
74+
DROP TABLE sent_backup;
75+
76+
-- --
77+
-- -- Update Table `pubkeys`
78+
-- -- We're going to have to calculate the address for each row in the pubkeys
79+
-- -- table. Then we can take out the hash field.
80+
-- --
81+
82+
ALTER TABLE pubkeys ADD address text DEFAULT '' ;
83+
84+
-- --
85+
-- -- Update Table `pubkeys`
86+
-- -- replica for loop to update hashed address
87+
-- --
88+
89+
UPDATE pubkeys SET address=(enaddr(pubkeys.addressversion, 1, hash));
90+
91+
-- --
92+
-- -- Table structure for table `pubkeys_backup`
93+
-- --
94+
95+
CREATE TEMPORARY TABLE `pubkeys_backup` (
96+
`address` text DEFAULT NULL,
97+
`addressversion` int DEFAULT NULL,
98+
`transmitdata` blob DEFAULT NULL,
99+
`time` int DEFAULT NULL,
100+
`usedpersonally` text DEFAULT NULL,
101+
UNIQUE(address) ON CONFLICT REPLACE
102+
) ;
103+
104+
105+
-- --
106+
-- -- Dumping data for table `pubkeys_backup`
107+
-- --
108+
109+
INSERT INTO pubkeys_backup SELECT address, addressversion, transmitdata, time, usedpersonally FROM pubkeys;
110+
111+
112+
-- --
113+
-- -- Drope table `pubkeys`
114+
-- --
115+
116+
DROP TABLE pubkeys;
117+
118+
-- --
119+
-- -- Table structure for table `pubkeys`
120+
-- --
121+
122+
CREATE TABLE `pubkeys` (
123+
`address` text DEFAULT NULL,
124+
`addressversion` int DEFAULT NULL,
125+
`transmitdata` blob DEFAULT NULL,
126+
`time` int DEFAULT NULL,
127+
`usedpersonally` text DEFAULT NULL,
128+
UNIQUE(address) ON CONFLICT REPLACE
129+
) ;
130+
131+
-- --
132+
-- -- Dumping data for table `pubkeys`
133+
-- --
134+
135+
INSERT INTO pubkeys SELECT address, addressversion, transmitdata, time, usedpersonally FROM pubkeys_backup;
136+
137+
-- --
138+
-- -- Dropping table `pubkeys_backup`
139+
-- --
140+
141+
DROP TABLE pubkeys_backup;

0 commit comments

Comments
 (0)