Skip to content

Commit

Permalink
Moved mainnet segwit blocking code to prevent an assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
chiguireitor committed Dec 21, 2018
1 parent 9e88792 commit b987afd
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/js/components/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,37 @@ function WalletViewModel() {
self.addresses.push(new AddressViewModel(type, key, address, label)); //add new
$.jqlog.debug("Wallet address added: " + address + " -- hash: "
+ addressHash + " -- label: " + label + " -- index: " + i);
} else if (type == 'segwit' && (USE_TESTNET || USE_REGTEST)) {
} else if (type == 'segwit') {
//adds a key to the wallet, making a new address object on the wallet in the process
//(assets must still be attached to this address, with updateBalances() or other means...)
//also, a label should already exist for the address in PREFERENCES.address_aliases by the time this is called

//derive an address from the key (for the appropriate network)
var i = self.addresses().length;

// m : masterkery / 0' : first private derivation / 0 : external account / i : index
var key = self.BITCOIN_WALLET.getAddressKey(i);
var networkName = key.priv.network.alias
if (USE_TESTNET && ! USE_REGTEST) {
networkName = key.priv.network.name
if (USE_TESTNET || USE_REGTEST) {
var i = self.addresses().length;

// m : masterkery / 0' : first private derivation / 0 : external account / i : index
var key = self.BITCOIN_WALLET.getAddressKey(i);
var networkName = key.priv.network.alias
if (USE_TESTNET && ! USE_REGTEST) {
networkName = key.priv.network.name
}
var address = bitcoinjs.payments.p2wpkh({ pubkey: key.priv.publicKey.toBuffer(), network: bitcoinjs.networks[networkName] }).address;

//Make sure this address doesn't already exist in the wallet (sanity check)
assert(!self.getAddressObj(address), "Cannot addAddress: address already exists in wallet!");
//see if there's a label already for this address that's stored in PREFERENCES, and use that if so
var addressHash = hashToB64(address);
//^ we store in prefs by a hash of the address so that the server data (if compromised) cannot reveal address associations
var label = PREFERENCES.address_aliases[addressHash] || i18n.t("default_address_label", (i + 1));
//^ an alias is made when a watch address is made, so this should always be found

self.addresses.push(new AddressViewModel(type, key, address, label)); //add new
$.jqlog.debug("Wallet address added: " + address + " -- hash: "
+ addressHash + " -- label: " + label + " -- index: " + i);
} else {
$.jqlog.debug("Segwit not enabled on mainnet yet");
}
var address = bitcoinjs.payments.p2wpkh({ pubkey: key.priv.publicKey.toBuffer(), network: bitcoinjs.networks[networkName] }).address;

//Make sure this address doesn't already exist in the wallet (sanity check)
assert(!self.getAddressObj(address), "Cannot addAddress: address already exists in wallet!");
//see if there's a label already for this address that's stored in PREFERENCES, and use that if so
var addressHash = hashToB64(address);
//^ we store in prefs by a hash of the address so that the server data (if compromised) cannot reveal address associations
var label = PREFERENCES.address_aliases[addressHash] || i18n.t("default_address_label", (i + 1));
//^ an alias is made when a watch address is made, so this should always be found

self.addresses.push(new AddressViewModel(type, key, address, label)); //add new
$.jqlog.debug("Wallet address added: " + address + " -- hash: "
+ addressHash + " -- label: " + label + " -- index: " + i);
} else {
//adds a watch only address to the wallet
//a label should already exist for the address in PREFERENCES.address_aliases by the time this is called
Expand Down

0 comments on commit b987afd

Please sign in to comment.