Bitcoin Forum
May 04, 2024, 10:56:48 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: importmulti Command Help  (Read 79 times)
BitcoinCanSaveUsAll (OP)
Member
**
Offline Offline

Activity: 104
Merit: 120


View Profile
September 01, 2021, 06:26:10 PM
 #1

Hi all,

I posted this earlier in the hardware wallet section but thought this might perhaps be a better area to post in.  Basically I'm trying to ensure that my modified version of the importmulti command which was generated by my ColdCard wallet and structured for wpkh (m/84'/0') was properly modified to not only import a watch only wallet wallet for psbt transactions into bitcoin core (v.20.0) for P2PKH spends, but also so that it should be routing the change to the same P2PKH addresses from this same wallet when initiating psbt transaction from bitcoin core.

Here's the command that I modified and entered in the core console with two success notifications:


importmulti'[{"range": [0, 1000], "timestamp": "now","keypool": true, "watchonly": true, "desc":"pkh([fingerprint/44h/0h/0h]privatexpub/0/*)#correctchecksum", "internal":false}, {"range": [0, 1000], "timestamp": "now","keypool": true, "watchonly": true, "desc":"pkh([fingerprint/44h/0h/0h]privatexpub/1/*)#correctchecksum ", "internal":true}]'


Note that the fingerprints, xpubs, and checksums were removed in the above command for privacy reasons.

The odd thing is that after running the above command and trying to sign my core generated psbt transaction on the ColdCard generated from the bitcoin core wallet that I disabled private key wallet which I created and imported the command above to, I was able to spend from the correct imported addresses in the psbt from the Coldcard but the change address shown on the ColdCard during the signing verification is a native segwit (bc prefix).  I assumed that the psbt created in core after my modified importmulti command would have told core to structure psbt transactions from this wallet so that it would route the change into a change address with another P2PKH address from the ColdCard wallet but for some reason that isn't the case. 

Perhaps someone on this board could have a look at this command and see if there was something structured wrong here?  I honestly have never used this command before and don't have much experience there. 

Side note:  I noticed is that when pasting an address into the "customer change address" field in bitcoin core's GUI where I had crafted the previously noted psbt from that core gave me a warning that the selected address is not part of that wallet (which it was).  Not sure if this is a bitcoin core bug or something else going on here.  Either way thanks to everyone for their feedback in advance.
1714820208
Hero Member
*
Offline Offline

Posts: 1714820208

View Profile Personal Message (Offline)

Ignore
1714820208
Reply with quote  #2

1714820208
Report to moderator
"The nature of Bitcoin is such that once version 0.1 was released, the core design was set in stone for the rest of its lifetime." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714820208
Hero Member
*
Offline Offline

Posts: 1714820208

View Profile Personal Message (Offline)

Ignore
1714820208
Reply with quote  #2

1714820208
Report to moderator
1714820208
Hero Member
*
Offline Offline

Posts: 1714820208

View Profile Personal Message (Offline)

Ignore
1714820208
Reply with quote  #2

1714820208
Report to moderator
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6581


Just writing some code


View Profile WWW
September 01, 2021, 10:28:50 PM
Merited by HCP (5), o_e_l_e_o (4)
 #2

When it comes to imported keys and address types, legacy wallets behave unintuitively (this is partially why they are slowly being phased out). The main thing is that the address type is not controlled by your import but rather by runtime options to Bitcoin Core itself. With importmulti, the type of addresses the descriptors that you import will create is completely irrelevant. The keys are imported into the keystore directly, and then the typical key to address type mutation is done when an address is requested. This is controlled by the -addresstype and -changetype command line options (or bitcoin.conf options), or by address type and change type options for the particular action you are doing.

If you want only p2pkh addresses, you need to tell Bitcoin Core to do that by setting -addresstype=legacy and -changetype=legacy when you start Bitcoin Core (or add them to your bitcoin.conf without the leading dash (-)).

Side note:  I noticed is that when pasting an address into the "customer change address" field in bitcoin core's GUI where I had crafted the previously noted psbt from that core gave me a warning that the selected address is not part of that wallet (which it was).  Not sure if this is a bitcoin core bug or something else going on here.  Either way thanks to everyone for their feedback in advance.
This warning is because a private key is not available for that address so the wallet thinks it is not spendable.

BitcoinCanSaveUsAll (OP)
Member
**
Offline Offline

Activity: 104
Merit: 120


View Profile
September 01, 2021, 11:24:20 PM
 #3

Thank you for the excellent comment and information.  This command (importmulti) is still quite new to me and I'm still trying to understand exactly how this works and understand the syntax. 

Unfortunately it seems as though after adding both of those options to my bitcoin.conf file (without the dashes) and even restarting core, I still have the same problem as far as it routing my change to a bc address (native SEGWIT).  I wonder if there might be any other ideas as to how to have bitcoin core route to my P2PKH change addresses that should have been imported with my importmulti command or if the only way is to manually select another address and copy it into the customer change address.

Lastly, is there any good resources you can suggest for learning more in-depth about the various CLI commands for bitcoin core that you can recommend?  Thanks again.
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4316

<insert witty quote here>


View Profile
September 03, 2021, 06:19:16 AM
Merited by o_e_l_e_o (4)
 #4

I've been experimenting with this over the last couple of days... and I cannot replicate the issue (NOTE: I am using TestNet running with -addresstype=legacy -changetype=legacy)

I created an empty wallet via the GUI ("Disable Private Keys" and "Make Blank Wallet" both CHECKED) and then used the following importmulti commands:
Import "Receive":
Code:
importmulti '[{"range": [0,10], "timestamp": "now", "keypool": true, "watchonly": true, "desc":"pkh(tpubDCcc5nEEx6ucT4ZsFbcfQoQniLzLKKMCDWBJmCyE3pxdJB1FSFodzQHyugTT9jVye9JSw4Z1fh5G9muHGbxuWCKJ2FYLfwguAxxMRUfn614/0/*)#x7l9hvyy", "internal":false}]'

Import "Change":
Code:
importmulti '[{"range": [0,10], "timestamp": "now", "keypool": true, "watchonly": true, "desc":"pkh(tpubDCcc5nEEx6ucT4ZsFbcfQoQniLzLKKMCDWBJmCyE3pxdJB1FSFodzQHyugTT9jVye9JSw4Z1fh5G9muHGbxuWCKJ2FYLfwguAxxMRUfn614/1/*)#h26y2e5u", "internal":true}]'


Then used rescanblockchain to pick up the transaction from this morning:
Code:
rescanblockchain 2901100


After that, I created an unsigned transaction sending 0.01 to "2N6Q5ThfiXBmCVtZctMrFdKh9NMKr4cvyNg" (no custom change address was specified)... which gave the following PSBT:
Code:
cHNidP8BAHUCAAAAAVwhQewlwfvoiFbIydddXePzvtLzxBkzOXASTZWtRMjjAAAAAAD9////AkBCDwAAAAAAF6kUkEZCuOxPJG3zAKLTIV1TEN0YKH2HYFOJAAAAAAAZdqkUgCugI7DhN6kQIULHp6jDpmO8+gKIrL7oHwAAAQC0AgAAAAL82FDhLhyM/oJXAJmphrqLdLwD4MhwFxmR3Hruy2n5TQEAAAAXFgAUsu40KEA0l7oQpkJB+ooQyjStqPv9////+KVvbXApkx7p35PrK7GPJXJ1iqVZftZIU7Nn6bMi9VkAAAAAAP3///8CgJaYAAAAAAAZdqkUuS49DijnI5Ot/mlEnLKoS24hzeqIrFNEhgAAAAAAFgAUJEZdVeL7wB0YpLnr2Pi4vfK0lhRn6B8AIgYCjv3jMS7f2EYTRRkhLQrPJNr2zE4NmKXC7XvKUPLOl9YMfjvIKQAAAAAAAAAAAAAiAgOyXgEY4CfaMolHM/xI8X0Kjiq3bED+NdPznEbcJyL4FQx+O8gpAQAAAAEAAAAA

Decoding that with decodepsbt, we can see that the change generated is:
Code:
{
        "value": 0.08999776,
        "n": 1,
        "scriptPubKey": {
          "asm": "OP_DUP OP_HASH160 802ba023b0e137a9102142c7a7a8c3a663bcfa02 OP_EQUALVERIFY OP_CHECKSIG",
          "hex": "76a914802ba023b0e137a9102142c7a7a8c3a663bcfa0288ac",
          "reqSigs": 1,
          "type": "pubkeyhash",
          "addresses": [
            "msCf3mHLTXqrwyrnZVpzyZPkatzN5htrEb"
          ]
        }
      }

Which is a P2PKH output... and is the m/1/1 change address... which we can check using getaddressinfo:
Code:
{
  "address": "msCf3mHLTXqrwyrnZVpzyZPkatzN5htrEb",
  "scriptPubKey": "76a914802ba023b0e137a9102142c7a7a8c3a663bcfa0288ac",
  "ismine": false,
  "solvable": true,
  "desc": "pkh([7e3bc829/1/1]03b25e0118e027da32894733fc48f17d0a8e2ab76c40fe35d3f39c46dc2722f815)#9a8l6nhz",
  "iswatchonly": true,
  "isscript": false,
  "iswitness": false,
  "pubkey": "03b25e0118e027da32894733fc48f17d0a8e2ab76c40fe35d3f39c46dc2722f815",
  "iscompressed": true,
  "ischange": true,
  "timestamp": 1630645010,
  "hdkeypath": "m/1/1",
  "hdseedid": "0000000000000000000000000000000000000000",
  "hdmasterfingerprint": "7e3bc829",
  "labels": [
  ]
}


I also tried creating a "descriptor" wallet... Again, using the "create wallet" option in the GUI but ticked all the boxes (disabled private keys, make blank wallet, and descriptor wallet)...

Then, imported the "external" descriptor:
Code:
importdescriptors '[{"desc":"pkh(tpubDCcc5nEEx6ucT4ZsFbcfQoQniLzLKKMCDWBJmCyE3pxdJB1FSFodzQHyugTT9jVye9JSw4Z1fh5G9muHGbxuWCKJ2FYLfwguAxxMRUfn614/0/*)#x7l9hvyy","active":true,"range":[0,10],"timestamp":1630566000,"internal":false}]'

and "internal" descriptor:
Code:
importdescriptors '[{"desc":"pkh(tpubDCcc5nEEx6ucT4ZsFbcfQoQniLzLKKMCDWBJmCyE3pxdJB1FSFodzQHyugTT9jVye9JSw4Z1fh5G9muHGbxuWCKJ2FYLfwguAxxMRUfn614/1/*)#h26y2e5u","active":true,"range":[0,10],"timestamp":1630566000,"internal":true}]'


After creating a PSBT that attempts to send out 0.01... and then decoding it, we again get:
Code:
{
        "value": 0.08999776,
        "n": 1,
        "scriptPubKey": {
          "asm": "OP_DUP OP_HASH160 802ba023b0e137a9102142c7a7a8c3a663bcfa02 OP_EQUALVERIFY OP_CHECKSIG",
          "hex": "76a914802ba023b0e137a9102142c7a7a8c3a663bcfa0288ac",
          "reqSigs": 1,
          "type": "pubkeyhash",
          "addresses": [
            "msCf3mHLTXqrwyrnZVpzyZPkatzN5htrEb"
          ]
        }
      }

Same change address as before...


Unfortunately, I don't have a coldcard to attempt to try and import the PSBT and see what the Coldcard says the address is... but, did you try decoding the PSBT with Bitcoin Core (decodepsbt) and checking what the change address being generated is? Huh

If the decoded PSBT looks OK in Bitcoin Core... then it's likely a Coldcard issue.




SIDE NOTE: Interestingly... "ismine" is "false" when checking the change address for the "legacy" wallet... but is "true" for the "descriptor" wallet. Huh


█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!