Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: deceive3w on September 06, 2020, 11:48:45 AM



Title: Import New Address BitcoinCore Without Rescan
Post by: deceive3w on September 06, 2020, 11:48:45 AM
i am have external wallet with hdwallet every time user create new address i am call JSON rpc import address this is not efficient because that is new address


Title: Re: Import New Address BitcoinCore Without Rescan
Post by: bob123 on September 06, 2020, 12:20:58 PM
Core is also a HD wallet.
Why would you create an address outside of core, just to import it into core afterwards?

You are right, that's definitely not efficient.
What wallet are you using to generate the addresses? Electrum? If so, then why do you import them into core?


Title: Re: Import New Address BitcoinCore Without Rescan
Post by: deceive3w on September 06, 2020, 01:40:16 PM
i am using bitcoinjs to generate address that's on my backend server. since i am new using bitcoin node i am insecure to import my private key. i am using bitcoin node just for get all my balances and matching my unspent with my backend


Title: Re: Import New Address BitcoinCore Without Rescan
Post by: bob123 on September 06, 2020, 01:52:08 PM
i am using bitcoinjs to generate address that's on my backend server. since i am new using bitcoin node i am insecure to import my private key. i am using bitcoin node just for get all my balances and matching my unspent with my backend

Since i don't know how your backend works, a general how-to would be:
  • Have the xpriv backed up offline
  • Use the xpub on an online server go generate addresses on-the-fly
  • Assign addresses generated from the xpub to customers and save that in the database
  • Use walletnotify and blocknotify with core to check for new blocks/transactions and update database entries based on that (e.g. customer has paid, transaction has X confirmations, ...)

You don't need to import private keys into core.
Either use cores HD wallet or only use core to check for transactions.


Title: Re: Import New Address BitcoinCore Without Rescan
Post by: gmaxwell on September 06, 2020, 03:08:31 PM
i am using bitcoinjs to generate address

FWIW, bitcoinjs has several times had bugs where it would generate incorrect pubkeys which no one could sign for. Personally I would be extremely wary about using it for any serious application.

Most other implementations of bitcoin's crypto are extremely scary-- e.g. contain very little to no testing, had no rigorous review, were subject to no formal validation, are not implemented in a fault tolerant way, and are (IMO) unfit for high value usage compared to Bitcoin Core.

I'm aware of at least one non-public incident where over 10,000 BTC was lost due to less thoughtfully created "HD wallet" crypto code generating bad pubkeys.

I would strongly suggest that at a minimum to implement a redundant check of some sort.  Bitcoin core signs and verifies a message after generating each key.

When you import an address you can set a flag to force it to not rescan-- see the help for importmulti. So long as you're sure that you import it before any use was possible there is no need to rescan.