2

I've created a p2wsh-in-p2sh multisig address using an offline node. I have the address and redeem script, as provided by bitcoin-cli addmultisigaddress on the offline node. How do I import this as a watch-only address on an online node, so I can use the online node to create transactions?

I have tried the following:

$ bitcoin-cli -testnet -rpcwallet=glacier importmulti '[{ "scriptPubKey": { "address": "2MzqiaZzpLT2SSBfsFqqo3FpZsP8g6WTvyC" }, "timestamp":"now", "redeemscript":"5221029f531503facdac2496f50a446d9bd29846a06a04a45e3845b656bb471df422fc2102e30787703a990e4015a2cb9071fcfd1c7d4641fb294e4b4c3f5f6b450a1925132102da28088a8022651171c4f13429b98709dabe13bc6da526537fdd2d0730dd2dbb2103286c96ecaa850a6ba43cc45fbb539c1fb1d65c23cc0f3cd09fcf9765826ff9de54ae", "watchonly":true, "label":"Glacier 2012-12-21" }]'
[
  {
    "success": true
  }
]

That seemed to work, but getaddressinfo doesn't look correct:

$ bitcoin-cli -testnet -rpcwallet=glacier getaddressinfo "2MzqiaZzpLT2SSBfsFqqo3FpZsP8g6WTvyC"
{
    "address": "2MzqiaZzpLT2SSBfsFqqo3FpZsP8g6WTvyC",
    "scriptPubKey": "a914534ee3ce21b8f805128f76b9d977e351bbbea20d87",
    "ismine": false,
    "iswatchonly": false,
    "isscript": true,
    "iswitness": false,
    "label": "Glacier 2012-12-21",
    "labels": [
       {
           "name": "Glacier 2012-12-21",
           "purpose": "receive"
       }
    ]
}

Shouldn't ismine and iswatchonly be true, and more details appear, such as hex and script?

Note that the glacier wallet was created with disable_private_keys=true. I'm running Bitcoin Core v0.17.0.1.

  • I had a similar problem with p2sh-segwit before, and I wonder if this is a similar kind of issue: https://github.com/bitcoin/bitcoin/issues/12418 – Bitcoin Hodler Dec 22 '18 at 03:46

2 Answers2

2

The issue here is that you've provided the p2wsh redeemscript as the script for the p2sh level of the nesting. The redeemscript for the p2sh address is

0020dabea3445c14e4a08d6705db4373bef467d4c64e7c8ddf149be50670de6878ae

This can be seen by running

bitcoin-cli -testnet decodescript 5221029f531503facdac2496f50a446d9bd29846a06a04a45e3845b656bb471df422fc2102e30787703a990e4015a2cb9071fcfd1c7d4641fb294e4b4c3f5f6b450a1925132102da28088a8022651171c4f13429b98709dabe13bc6da526537fdd2d0730dd2dbb2103286c96ecaa850a6ba43cc45fbb539c1fb1d65c23cc0f3cd09fcf9765826ff9de54ae

With it, you can import the p2sh-p2wsh by setting the redeemscript for each level of the nesting :

$ bitcoin-cli -testnet importmulti '[{ "scriptPubKey": { "address": "2MzqiaZzpLT2SSBfsFqqo3FpZsP8g6WTvyC" }, "timestamp":"now", "redeemscript":"0020DABEA3445C14E4A08D6705DB4373BEF467D4C64E7C8DDF149BE50670DE6878AE", "label":"Glacier 2012-12-21" }, {"scriptPubKey": { "address": "2MzqiaZzpLT2SSBfsFqqo3FpZsP8g6WTvyC" }, "redeemscript": "5221029f531503facdac2496f50a446d9bd29846a06a04a45e3845b656bb471df422fc2102e30787703a990e4015a2cb9071fcfd1c7d4641fb294e4b4c3f5f6b450a1925132102da28088a8022651171c4f13429b98709dabe13bc6da526537fdd2d0730dd2dbb2103286c96ecaa850a6ba43cc45fbb539c1fb1d65c23cc0f3cd09fcf9765826ff9de54ae", "label":"Glacier 2012-12-21", "timestamp":"now"}]'
[
  {
    "success": true
  },
  {
    "success": true
  }
]

Then you'll see the expected result from getaddressinfo :

bitcoin-cli -testnet getaddressinfo 2MzqiaZzpLT2SSBfsFqqo3FpZsP8g6WTvyC
{
  "address": "2MzqiaZzpLT2SSBfsFqqo3FpZsP8g6WTvyC",
  "scriptPubKey": "a914534ee3ce21b8f805128f76b9d977e351bbbea20d87",
  "ismine": false,
  "iswatchonly": true,
  "isscript": true,
  "iswitness": false,
  "script": "witness_v0_scripthash",
  "hex": "0020dabea3445c14e4a08d6705db4373bef467d4c64e7c8ddf149be50670de6878ae",
  "embedded": {
    "isscript": true,
    "iswitness": true,
    "witness_version": 0,
    "witness_program": "dabea3445c14e4a08d6705db4373bef467d4c64e7c8ddf149be50670de6878ae",
    "script": "multisig",
    "hex": "5221029f531503facdac2496f50a446d9bd29846a06a04a45e3845b656bb471df422fc2102e30787703a990e4015a2cb9071fcfd1c7d4641fb294e4b4c3f5f6b450a1925132102da28088a8022651171c4f13429b98709dabe13bc6da526537fdd2d0730dd2dbb2103286c96ecaa850a6ba43cc45fbb539c1fb1d65c23cc0f3cd09fcf9765826ff9de54ae",
    "sigsrequired": 2,
    "pubkeys": [
      "029f531503facdac2496f50a446d9bd29846a06a04a45e3845b656bb471df422fc",
      "02e30787703a990e4015a2cb9071fcfd1c7d4641fb294e4b4c3f5f6b450a192513",
      "02da28088a8022651171c4f13429b98709dabe13bc6da526537fdd2d0730dd2dbb",
      "03286c96ecaa850a6ba43cc45fbb539c1fb1d65c23cc0f3cd09fcf9765826ff9de"
    ],
    "address": "tb1qm2l2x3zuznj2prt8qhd5xua773naf3jw0jxa79ymu5r8phng0zhqrkkueu",
    "scriptPubKey": "0020dabea3445c14e4a08d6705db4373bef467d4c64e7c8ddf149be50670de6878ae"
  },
  "label": "Glacier 2012-12-21",
  "timestamp": 1296688602,
  "labels": [
    {
      "name": "Glacier 2012-12-21",
      "purpose": "receive"
    }
  ]
}

Note, ismine is never true for scripts\addresses for which you can't sign completely on your own.

arubi
  • 1,864
  • 8
  • 21
  • This worked, but sure is ugly. I had the same problem with signrawtransaction at first, but they fixed it: https://github.com/bitcoin/bitcoin/issues/12418 – Bitcoin Hodler Dec 22 '18 at 23:43
  • 1
    Apparently this behavior is considered a bug by the core developers: https://github.com/bitcoin/bitcoin/issues/15392 There is no supported way to import this kind of address into Bitcoin Core v0.17.1. This will change in v0.18 and I'll come back here to add a new answer at that time. – Bitcoin Hodler Feb 12 '19 at 20:31
  • @BitcoinHodler Interesting. Thanks for the followup. – arubi Feb 13 '19 at 21:16
0

As @arubi's answer said, first I must decode the witness script (which I originally got from addmultisigaddress) to get the accompanying redeem script:

bitcoin-cli -testnet -decodescript "5221029f531503facdac2496f50a446d9bd29846a06a04a45e3845b656bb471df422fc2102e30787703a990e4015a2cb9071fcfd1c7d4641fb294e4b4c3f5f6b450a1925132102da28088a8022651171c4f13429b98709dabe13bc6da526537fdd2d0730dd2dbb2103286c96ecaa850a6ba43cc45fbb539c1fb1d65c23cc0f3cd09fcf9765826ff9de54ae"

Get the redeemscript from the JSON results["segwit"]["hex"], then provide both scripts to importmulti:

bitcoin-cli -testnet importmulti \
    '[
      {
        "scriptPubKey": { "address": "2MzqiaZzpLT2SSBfsFqqo3FpZsP8g6WTvyC" },
        "timestamp":1545413762,
        "redeemscript":"0020dabea3445c14e4a08d6705db4373bef467d4c64e7c8ddf149be50670de6878ae",
        "witnessscript":"5221029f531503facdac2496f50a446d9bd29846a06a04a45e3845b656bb471df422fc2102e30787703a990e4015a2cb9071fcfd1c7d4641fb294e4b4c3f5f6b450a1925132102da28088a8022651171c4f13429b98709dabe13bc6da526537fdd2d0730dd2dbb2103286c96ecaa850a6ba43cc45fbb539c1fb1d65c23cc0f3cd09fcf9765826ff9de54ae",
        "watchonly":true
      }
    ]'

This works in Bitcoin Core v0.18. Importing this kind of address as watch-only was not officially supported in earlier versions.