This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 970
Removes transition btc->bat code #13039
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,6 @@ const appActions = require('../../../js/actions/appActions') | |
// State | ||
const ledgerState = require('../../common/state/ledgerState') | ||
const pageDataState = require('../../common/state/pageDataState') | ||
const migrationState = require('../../common/state/migrationState') | ||
const updateState = require('../../common/state/updateState') | ||
|
||
// Constants | ||
|
@@ -85,7 +84,6 @@ let verifiedTimeoutId = false | |
let v2RulesetDB | ||
const v2RulesetPath = 'ledger-rulesV2.leveldb' | ||
const statePath = 'ledger-state.json' | ||
const newClientPath = 'ledger-newstate.json' | ||
|
||
// Definitions | ||
const clientOptions = { | ||
|
@@ -1223,8 +1221,6 @@ const checkPromotions = () => { | |
|
||
const enable = (state, paymentsEnabled) => { | ||
if (paymentsEnabled) { | ||
state = checkBtcBatMigrated(state, paymentsEnabled) | ||
|
||
if (!getSetting(settings.PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED)) { | ||
appActions.changeSetting(settings.PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED, true) | ||
} | ||
|
@@ -1505,7 +1501,7 @@ const getStateInfo = (state, parsedData) => { | |
const info = parsedData.paymentInfo | ||
const then = new Date().getTime() - ledgerUtil.milliseconds.year | ||
|
||
if (!parsedData.properties.wallet) { | ||
if (!parsedData.properties || !parsedData.properties.wallet) { | ||
return state | ||
} | ||
|
||
|
@@ -1915,19 +1911,6 @@ const onCallback = (state, result, delayTime) => { | |
// persist the new ledger state | ||
muonWriter(statePath, regularResults) | ||
|
||
// delete the temp file used during transition (if it still exists) | ||
if (client && client.options && client.options.version === 'v2') { | ||
const fs = require('fs') | ||
fs.access(pathName(newClientPath), fs.FF_OK, (err) => { | ||
if (err) { | ||
return | ||
} | ||
fs.unlink(pathName(newClientPath), (err) => { | ||
if (err) console.error('unlink error: ' + err.toString()) | ||
}) | ||
}) | ||
} | ||
|
||
run(state, delayTime) | ||
|
||
return state | ||
|
@@ -2019,7 +2002,6 @@ const initialize = (state, paymentsEnabled) => { | |
|
||
if (!paymentsEnabled) { | ||
client = null | ||
newClient = false | ||
return ledgerState.resetInfo(state, true) | ||
} | ||
|
||
|
@@ -2075,6 +2057,22 @@ const getContributionAmount = (state) => { | |
} | ||
|
||
const onInitRead = (state, parsedData) => { | ||
const isBTC = parsedData && | ||
parsedData.properties && | ||
parsedData.properties.wallet && | ||
parsedData.properties.wallet.keychains | ||
|
||
if (isBTC) { | ||
const fs = require('fs') | ||
fs.renameSync(pathName(statePath), pathName('ledger-state-btc.json')) | ||
state = ledgerState.resetInfo(state) | ||
clientprep() | ||
client = ledgerClient(null, underscore.extend({roundtrip: roundtrip}, clientOptions), null) | ||
parsedData = client.state | ||
getPaymentInfo(state) | ||
muonWriter(statePath, parsedData) | ||
} | ||
|
||
if (Array.isArray(parsedData.transactions)) { | ||
parsedData.transactions.sort((transaction1, transaction2) => { | ||
return transaction1.submissionStamp - transaction2.submissionStamp | ||
|
@@ -2393,147 +2391,6 @@ const deleteSynopsis = () => { | |
synopsis.publishers = {} | ||
} | ||
|
||
// fix for incorrectly persisted state (see #11585) | ||
const yoDawg = (stateState) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RIP the yoDawg bug fix 💯 |
||
while (stateState.hasOwnProperty('state') && stateState.state.persona) { | ||
stateState = stateState.state | ||
} | ||
return stateState | ||
} | ||
|
||
const checkBtcBatMigrated = (state, paymentsEnabled) => { | ||
if (!paymentsEnabled) { | ||
return state | ||
} | ||
|
||
// One time conversion of wallet | ||
const isNewInstall = migrationState.isNewInstall(state) | ||
const hasUpgradedWallet = migrationState.hasUpgradedWallet(state) | ||
if (!isNewInstall && !hasUpgradedWallet) { | ||
state = migrationState.setTransitionStatus(state, true) | ||
module.exports.transitionWalletToBat() | ||
} else { | ||
state = migrationState.setTransitionStatus(state, false) | ||
} | ||
|
||
return state | ||
} | ||
|
||
let newClient = null | ||
const getNewClient = () => { | ||
return newClient | ||
} | ||
|
||
let busyRetryCount = 0 | ||
|
||
const transitionWalletToBat = () => { | ||
let newPaymentId, result | ||
|
||
if (newClient === true) return | ||
clientprep() | ||
|
||
if (!client) { | ||
console.log('Client is not initialized, will try again') | ||
return | ||
} | ||
|
||
// only attempt this transition if the wallet is v1 | ||
if (client.options && client.options.version !== 'v1') { | ||
// older versions incorrectly marked this for transition | ||
// this will clean them up (no more bouncy ball) | ||
appActions.onBitcoinToBatTransitioned() | ||
return | ||
} | ||
|
||
// Restore newClient from the file (if one exists) | ||
if (!newClient) { | ||
const fs = require('fs') | ||
try { | ||
fs.accessSync(pathName(newClientPath), fs.FF_OK) | ||
fs.readFile(pathName(newClientPath), (error, data) => { | ||
if (error) { | ||
console.error(`ledger client: can't read ${newClientPath} to restore newClient`) | ||
return | ||
} | ||
const parsedData = JSON.parse(data) | ||
const state = yoDawg(parsedData) | ||
newClient = ledgerClient(state.personaId, | ||
underscore.extend(state.options, {roundtrip: module.exports.roundtrip}, clientOptions), | ||
state) | ||
transitionWalletToBat() | ||
}) | ||
return | ||
} catch (err) {} | ||
} | ||
|
||
// Create new client | ||
if (!newClient) { | ||
try { | ||
newClient = ledgerClient(null, underscore.extend({roundtrip: module.exports.roundtrip}, clientOptions), null) | ||
muonWriter(newClientPath, newClient.state) | ||
} catch (ex) { | ||
console.error('ledger client creation error(2): ', ex) | ||
return | ||
} | ||
} | ||
|
||
newPaymentId = newClient.getPaymentId() | ||
if (!newPaymentId) { | ||
newClient.sync((err, result, delayTime) => { | ||
if (err) { | ||
return console.error('ledger client error(3): ' + JSON.stringify(err, null, 2) + (err.stack ? ('\n' + err.stack) : '')) | ||
} | ||
|
||
if (typeof delayTime === 'undefined') delayTime = random.randomInt({ min: 1, max: 500 }) | ||
|
||
if (newClient) { | ||
muonWriter(newClientPath, newClient.state) | ||
} | ||
|
||
setTimeout(() => transitionWalletToBat(), delayTime) | ||
}) | ||
return | ||
} | ||
|
||
if (client.busyP()) { | ||
if (++busyRetryCount > 3) { | ||
console.log('ledger client is currently busy; transition will be retried on next launch') | ||
return | ||
} | ||
const delayTime = random.randomInt({ | ||
min: ledgerUtil.milliseconds.minute, | ||
max: 10 * ledgerUtil.milliseconds.minute | ||
}) | ||
console.log('ledger client is currently busy; transition will be retried shortly (this was attempt ' + busyRetryCount + ')') | ||
setTimeout(() => transitionWalletToBat(), delayTime) | ||
return | ||
} | ||
|
||
appActions.onBitcoinToBatBeginTransition() | ||
|
||
try { | ||
client.transition(newPaymentId, (err, properties) => { | ||
if (err || !newClient) { | ||
console.error('ledger client transition error: ', err) | ||
} else { | ||
result = newClient.transitioned(properties) | ||
client = newClient | ||
newClient = true | ||
// NOTE: onLedgerCallback will save latest client to disk as ledger-state.json | ||
appActions.onLedgerCallback(result, random.randomInt({ | ||
min: ledgerUtil.milliseconds.minute, | ||
max: 10 * ledgerUtil.milliseconds.minute | ||
})) | ||
appActions.onBitcoinToBatTransitioned() | ||
ledgerNotifications.showBraveWalletUpdated() | ||
getPublisherTimestamp() | ||
} | ||
}) | ||
} catch (ex) { | ||
console.error('exception during ledger client transition: ', ex) | ||
} | ||
} | ||
|
||
let currentMediaKey = null | ||
const onMediaRequest = (state, xhr, type, tabId) => { | ||
if (!xhr || type == null) { | ||
|
@@ -2872,13 +2729,10 @@ const getMethods = () => { | |
migration, | ||
onInitRead, | ||
deleteSynopsis, | ||
transitionWalletToBat, | ||
getNewClient, | ||
normalizePinned, | ||
roundToTarget, | ||
savePublisherData, | ||
pruneSynopsis, | ||
checkBtcBatMigrated, | ||
onMediaRequest, | ||
onMediaPublisher, | ||
saveVisit, | ||
|
@@ -2900,7 +2754,6 @@ const getMethods = () => { | |
privateMethods = { | ||
enable, | ||
addSiteVisit, | ||
checkBtcBatMigrated, | ||
clearVisitsByPublisher: function () { | ||
visitsByPublisher = {} | ||
}, | ||
|
@@ -2911,9 +2764,6 @@ const getMethods = () => { | |
setSynopsis: (data) => { | ||
synopsis = data | ||
}, | ||
resetNewClient: () => { | ||
newClient = false | ||
}, | ||
getClient: () => { | ||
return client | ||
}, | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add verbose logging here- something like:
Bitcoin wallet detected; backing up to "ledger-state-btc.json" and creating new BAT wallet