Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run import keys genesis filter as non-worker (fixes FF < v41, breaks …
…UI % complete reporting) #319
- Loading branch information
James Calfee
committed
Oct 29, 2015
1 parent
085c300
commit 6ff8353
Showing
3 changed files
with
144 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,16 @@ | ||
|
||
var config = require( "chain/config" ) | ||
var key_utils = require( "common/key_utils" ) | ||
var GenesisFilter = require( "chain/GenesisFilter" ) | ||
var genesis_filter = new GenesisFilter | ||
|
||
onmessage = function(event) { try { | ||
console.log("GenesisFilterWorker start"); | ||
var { account_keys } = event.data | ||
filter( account_keys, status => { | ||
var { account_keys, bloom_filter } = event.data | ||
var genesis_filter = new GenesisFilter( bloom_filter ) | ||
genesis_filter.filter( account_keys, status => { | ||
if( status.success ) { | ||
postMessage({ account_keys, status }) | ||
console.log("GenesisFilterWorker done") | ||
return | ||
} | ||
postMessage({ status }) | ||
}) | ||
} catch( e ) { console.error("GenesisFilterWorker", e) } } | ||
|
||
var filter = function( account_keys, status ) { | ||
if( ! genesis_filter.isAvailable() ) { | ||
console.log("WARN: Missing bloom filter for BTS 0.9.x wallets") | ||
status({ error: "missing_bloom" }) | ||
return | ||
} | ||
var initalizing = true | ||
status({ initalizing }) | ||
genesis_filter.init(()=> { | ||
var previous_address_prefix = config.address_prefix | ||
config.address_prefix = "BTS" | ||
try { | ||
initalizing = false | ||
status({ initalizing }) | ||
var running_count_progress = 1 | ||
for(var a = 0; a < account_keys.length; a++) { | ||
var removed_count = 0, count = 0 | ||
var keys = account_keys[a] | ||
var total = keys.encrypted_private_keys.length | ||
status({ importing: true, account_name: keys.account_name, count, total }) | ||
for(var k = keys.encrypted_private_keys.length - 1; k >= 0; k--) { | ||
count++ | ||
if( count % running_count_progress === 0 ) { | ||
running_count_progress = 47 | ||
status({ importing: true, account_name: keys.account_name, count, total }) | ||
} | ||
if( ! keys.public_keys) { | ||
// un-released format, just for testing | ||
status({ error: "missing_public_keys" }) | ||
return | ||
} | ||
var key = keys.public_keys[k] | ||
if( /^GPH/.test(key) ) key = "BTS" + key.substring(3) | ||
if(genesis_filter.inGenesis( key )) continue | ||
var addresses = key_utils.addresses(key) | ||
var addy_found = false | ||
for(var i = 0; i < addresses.length; i++) { | ||
if(genesis_filter.inGenesis( addresses[i] )) { | ||
addy_found = true | ||
break | ||
} | ||
} | ||
if( addy_found ) continue | ||
delete keys.encrypted_private_keys[k] | ||
delete keys.public_keys[k] | ||
removed_count++ | ||
} | ||
var encrypted_private_keys = [], public_keys = [] | ||
for(var k = keys.encrypted_private_keys.length - 1; k >= 0; k--) { | ||
if( ! keys.encrypted_private_keys[k]) continue | ||
encrypted_private_keys.push( keys.encrypted_private_keys[k] ) | ||
public_keys.push( keys.public_keys[k] ) | ||
} | ||
keys.encrypted_private_keys = encrypted_private_keys | ||
status({ importing: false, account_name: keys.account_name, | ||
count: count - removed_count, total }) | ||
keys.public_keys = public_keys | ||
} | ||
status({ success: true }) | ||
} finally { | ||
config.address_prefix = previous_address_prefix | ||
if( initalizing ) { | ||
initalizing = false | ||
status({ initalizing }) | ||
} | ||
} | ||
}) | ||
} | ||
} catch( e ) { console.error("GenesisFilterWorker", e) } } |