2727 'ksize' : '20' ,
2828 'alpha' : '3' ,
2929 'transaction_fee' : '10000' ,
30- 'libbitcoin_server ' : 'tcp://libbitcoin1.openbazaar.org:9091' ,
31- 'libbitcoin_server_testnet ' : 'tcp://libbitcoin2.openbazaar.org:9091' ,
30+ 'libbitcoin_servers ' : 'tcp://libbitcoin1.openbazaar.org:9091,None ' ,
31+ 'libbitcoin_servers_testnet ' : 'tcp://libbitcoin2.openbazaar.org:9091, <Z&{.=LJSPySefIKgCu99w.L%b^6VvuVp0+pbnOM ' ,
3232 'resolver' : 'http://resolver.onename.com/' ,
3333 'ssl_cert' : None ,
3434 'ssl_key' : None ,
@@ -137,18 +137,21 @@ def _validate_key(key):
137137 return True
138138
139139
140- def _is_seed_tuple (tup ):
140+ def _is_tuple (tup , key ):
141141 if isinstance (tup , tuple ):
142- return 'seed' in tup [0 ]
142+ return key in tup [0 ]
143143
144144 return False
145145
146146
147- def _tuple_from_seed_string (string ):
147+ def _tuple_from_string (string ):
148148 '''
149149 Accepts well formed seed string, returns tuple (url:port, key)
150150 '''
151- return tuple (string .split (',' ))
151+ l = string .split (',' )
152+ if len (l ) == 1 :
153+ l .append (None )
154+ return tuple (l )
152155
153156
154157cfg = ConfigParser (DEFAULTS )
@@ -162,27 +165,53 @@ def _tuple_from_seed_string(string):
162165KSIZE = int (cfg .get ('CONSTANTS' , 'KSIZE' ))
163166ALPHA = int (cfg .get ('CONSTANTS' , 'ALPHA' ))
164167TRANSACTION_FEE = int (cfg .get ('CONSTANTS' , 'TRANSACTION_FEE' ))
165- LIBBITCOIN_SERVER = cfg .get ('CONSTANTS' , 'LIBBITCOIN_SERVER' )
166- LIBBITCOIN_SERVER_TESTNET = cfg .get ('CONSTANTS' , 'LIBBITCOIN_SERVER_TESTNET' )
167168RESOLVER = cfg .get ('CONSTANTS' , 'RESOLVER' )
168169SSL = str_to_bool (cfg .get ('AUTHENTICATION' , 'SSL' ))
169170SSL_CERT = cfg .get ('AUTHENTICATION' , 'SSL_CERT' )
170171SSL_KEY = cfg .get ('AUTHENTICATION' , 'SSL_KEY' )
171172USERNAME = cfg .get ('AUTHENTICATION' , 'USERNAME' )
172173PASSWORD = cfg .get ('AUTHENTICATION' , 'PASSWORD' )
174+ LIBBITCOIN_SERVERS = []
175+ LIBBITCOIN_SERVERS_TESTNET = []
173176SEEDS = []
174177
175178items = cfg .items ('SEEDS' ) # this also includes items in DEFAULTS
176179for item in items :
177- if _is_seed_tuple (item ):
180+ if _is_tuple (item , "seed" ):
178181 seed = item [1 ]
179182 if _is_well_formed_seed_string (seed ):
180- new_seed = _tuple_from_seed_string (seed )
183+ new_seed = _tuple_from_string (seed )
181184 if new_seed not in SEEDS :
182185 SEEDS .append (new_seed )
183186 else :
184187 print 'Warning: please check your configuration file: %s' % seed
185188
189+ items = cfg .items ('LIBBITCOIN_SERVERS' ) # this also includes items in DEFAULTS
190+ for item in items :
191+ if _is_tuple (item , "server" ):
192+ server = item [1 ]
193+ new_server = _tuple_from_string (server )
194+ if item [0 ] == "server_custom" :
195+ LIBBITCOIN_SERVERS = [new_server ]
196+ break
197+ elif new_server not in LIBBITCOIN_SERVERS :
198+ LIBBITCOIN_SERVERS .append (new_server )
199+ else :
200+ print 'Warning: please check your configuration file: %s' % server
201+
202+ items = cfg .items ('LIBBITCOIN_SERVERS_TESTNET' ) # this also includes items in DEFAULTS
203+ for item in items :
204+ if _is_tuple (item , "testnet_server" ):
205+ server = item [1 ]
206+ new_server = _tuple_from_string (server )
207+ if item [0 ] == "testnet_server_custom" :
208+ LIBBITCOIN_SERVERS_TESTNET = [new_server ]
209+ break
210+ elif new_server not in LIBBITCOIN_SERVERS_TESTNET :
211+ LIBBITCOIN_SERVERS_TESTNET .append (new_server )
212+ else :
213+ print 'Warning: please check your configuration file: %s' % server
214+
186215
187216def set_value (section , name , value ):
188217 config = ConfigParser ()
@@ -197,8 +226,19 @@ def get_value(section, name):
197226 config = ConfigParser ()
198227 if isfile (CONFIG_FILE ):
199228 config .read (CONFIG_FILE )
200- return config .get (section , name )
229+ try :
230+ return config .get (section , name )
231+ except Exception :
232+ return None
233+
201234
235+ def delete_value (section , name ):
236+ config = ConfigParser ()
237+ if isfile (CONFIG_FILE ):
238+ config .read (CONFIG_FILE )
239+ config .remove_option (section , name )
240+ with open (CONFIG_FILE , 'wb' ) as configfile :
241+ config .write (configfile )
202242
203243if __name__ == '__main__' :
204244
@@ -221,9 +261,9 @@ def test_is_seed_tuple():
221261 good = ('seed.openbazaar.org:8080' , '5b44be5c18ced1bc9400fe5e79c8ab90204f06bebacc04dd9c70a95eaca6e117' )
222262 bad_not_tuple = 'seed.openbazaar.org:8080,5b44be5c18ced1bc9400fe5e79c8ab90204f06bebacc04dd9c70a95eaca6e117'
223263 bad_not_seed_tuple = ('aoioai' , 'aoioai' )
224- assert _is_seed_tuple (good )
225- assert not _is_seed_tuple (bad_not_tuple )
226- assert not _is_seed_tuple (bad_not_seed_tuple )
264+ assert _is_tuple (good )
265+ assert not _is_tuple (bad_not_tuple )
266+ assert not _is_tuple (bad_not_seed_tuple )
227267
228268
229269 _is_linux ()
0 commit comments