Created
September 6, 2017 06:41
-
-
Save junderw/cfc288985d6b814af48880b05fd920a7 to your computer and use it in GitHub Desktop.
Convert all your existing addresses from bitcoind to segwit P2SH addresses (multisig will not work)
This file contains hidden or 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
'use strict'; | |
// first, run sudo apt-get install jq nodejs npm | |
// second, run npm install bluebird co to install dependencies, and make sure bitcoin-cli can run these commands. | |
// third, run node thisScript.js and it will change all the addresses on your bitcoind into segwit addresses. | |
var Promise = require('bluebird'); | |
var co = require('co'); | |
var exec = Promise.promisify(require('child_process').exec); | |
var main = function() { | |
return co(function*() { | |
var accountsString = yield exec("bitcoin-cli listaccounts | jq -r 'keys'"); | |
var accountsArray = JSON.parse(accountsString); | |
var finalData = {}; | |
for (var i = 0; i < accountsArray.length; i++) { | |
var addressesString = yield exec("bitcoin-cli getaddressesbyaccount \"" + accountsArray[i] + "\" | jq -r '.'"); | |
var addressesArray = JSON.parse(addressesString); | |
finalData[accountsArray[i]] = {}; | |
for (var j = 0; j < addressesArray.length; j++) { | |
if (addressesArray[j].slice(0,1) == "1") { | |
var segWitAddress = yield exec("bitcoin-cli addwitnessaddress " + addressesArray[j]); | |
finalData[accountsArray[i]][addressesArray[j]] = segWitAddress.trim(); | |
} | |
} | |
} | |
return JSON.stringify(finalData, null, 2); | |
}); | |
}; | |
main().then(function (result) { console.log(result) }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment