-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wdb: use layout back up instead of wdb layout. Generate migration data.
- Loading branch information
Showing
4 changed files
with
206 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
'use strict'; | ||
|
||
/** | ||
* This migration is for v4 -> v5. | ||
*/ | ||
|
||
const bdb = require('bdb'); | ||
const Network = require('../../../lib/protocol/network'); | ||
const WalletDB = require('../../../lib/wallet/walletdb'); | ||
const wutils = require('../../util/wallet'); | ||
const mutils = require('../../util/migrations'); | ||
|
||
const layout = { | ||
wdb: { | ||
// W[wid] -> wallet id | ||
W: bdb.key('W', ['uint32']), | ||
|
||
// a[wid][index] -> account | ||
a: bdb.key('a', ['uint32', 'uint32']) | ||
} | ||
}; | ||
|
||
const NETWORK = Network.get('regtest'); | ||
const LOOKAHEAD1 = 10; | ||
const LOOKAHEAD2 = 200; | ||
|
||
const wallet1priv = 'rprvKE8qsHtkmUxUSPQdn2sFKFUcKyUQz9pKQhxjEWecnXg9hgJMsmJXcw' | ||
+ 'J77SqmHT1R6mcuNqVPzgT2EoGStsXaUN92VJKhQWUB6uZdL8gAZvez'; | ||
const wallet2priv = 'rprvKE8qsHtkmUxUSR4jE7Lti9XV77hv7xxacAShw5MvxY6RfsAYVeB1WL' | ||
+ 'WtjiebDmqTruVJxmMeQUMkk61e83WDZbZidDnNPhHyQpeEwxjuSZuG'; | ||
const rpub = 'rpubKBAPj83PkcGYSz3GR9xfzXBfTFTPtERb2x7fKvbikH9utGMvr6HDd4sTxt5zo' | ||
+ 'arw4bzzgH1VDzBUoX9fotzmPrrngFyLMz3ozAi1ozAbJjSY'; | ||
|
||
(async () => { | ||
const wdb = new WalletDB({ | ||
network: NETWORK, | ||
memory: true | ||
}); | ||
|
||
await wdb.open(); | ||
|
||
const wallet1 = await wdb.create({ | ||
id: 'wallet1', | ||
master: wallet1priv, | ||
lookahead: LOOKAHEAD1 | ||
}); | ||
|
||
await wallet1.createAccount({ | ||
name: 'alt', | ||
lookahead: LOOKAHEAD2 | ||
}); | ||
|
||
const wallet2 = await wdb.create({ | ||
id: 'wallet2', | ||
master: wallet2priv, | ||
lookahead: LOOKAHEAD2, | ||
m: 1, | ||
n: 2 | ||
}); | ||
|
||
await wallet2.addSharedKey(0, rpub); | ||
|
||
for (let i = 0; i < 100; i++) { | ||
const entry = wutils.nextEntry(wdb); | ||
await wdb.addBlock(entry, []); | ||
} | ||
|
||
console.log(JSON.stringify({ | ||
data: await getMigrationDump(wdb) | ||
}, null, 2)); | ||
|
||
await wdb.close(); | ||
})().catch((e) => { | ||
console.error(e); | ||
}); | ||
|
||
async function getMigrationDump(wdb) { | ||
const prefixes = []; | ||
|
||
// skip primary wallet. | ||
for (let i = 1; i < 3; i++) { | ||
prefixes.push(layout.wdb.W.encode(i).toString('hex')); | ||
prefixes.push(layout.wdb.a.encode(i, 0).slice(0, 5).toString('hex')); | ||
} | ||
|
||
return await mutils.dumpWDB(wdb, prefixes); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"before": { | ||
"5700000001": "0777616c6c657431", | ||
"5700000002": "0777616c6c657432", | ||
"610000000100000000": "0100010101000000010000000a03875c90a480000000fdc9691244b5dc0636ce0eabd905556c333e208b2815e463a6e65db29833c15d024a4400453207366ed8567bf78fdda5dccc1a0f8b1398f9925b744cc563575a7400", | ||
"610000000100000001": "010001010100000001000000c803875c90a480000001fc7d26586b3e6e082df9d01051258b8809960d5434d1abfe088ab507a0cfbbf003f44993e0ed4638fb5d32a272cca586ffe85040755d95568e01ca5c4845e27c9e00", | ||
"610000000200000000": "010101020100000001000000c8034a0c1e1180000000bda10baaccd9189fb3a56e2950ad198c45611cd3dbf0f154f699fa1c9ddc4b89022e05837732c62feb49896bc8b3cd8fd2f1b9b6bc415074ba31d858a810bbb29401032ac4ec93800000008921a0a732ac09e78b4f51464880ca9fc3e09a129564c0d8aef9fb1fd2ff175302f2b8aebdc25d17815420662ff8e2b9e24202a9b628f07ce2671cedac5f8001e1" | ||
|
||
}, | ||
"after": { | ||
"5700000001": "0777616c6c657431", | ||
"5700000002": "0777616c6c657432", | ||
"610000000100000000": "0100010101000000010000000a00000003875c90a480000000fdc9691244b5dc0636ce0eabd905556c333e208b2815e463a6e65db29833c15d024a4400453207366ed8567bf78fdda5dccc1a0f8b1398f9925b744cc563575a7400", | ||
"610000000100000001": "010001010100000001000000c800000003875c90a480000001fc7d26586b3e6e082df9d01051258b8809960d5434d1abfe088ab507a0cfbbf003f44993e0ed4638fb5d32a272cca586ffe85040755d95568e01ca5c4845e27c9e00", | ||
"610000000200000000": "010101020100000001000000c8000000034a0c1e1180000000bda10baaccd9189fb3a56e2950ad198c45611cd3dbf0f154f699fa1c9ddc4b89022e05837732c62feb49896bc8b3cd8fd2f1b9b6bc415074ba31d858a810bbb29401032ac4ec93800000008921a0a732ac09e78b4f51464880ca9fc3e09a129564c0d8aef9fb1fd2ff175302f2b8aebdc25d17815420662ff8e2b9e24202a9b628f07ce2671cedac5f8001e1" | ||
} | ||
} |
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