bitcoin core – get better and sweep P2PK cash

0
68


You possibly can obtain this with none script, merely utilizing the Bitcoin Core pockets. For every public key you obtained funds on you’ll be able to import a pk() descriptor containing the corresponding non-public key, WIF-encoded. Then you’ll be able to rescan the block chain for the pockets to get information of the outputs paying to you. Lastly you’ll be able to sweep these funds as you’d usually spend from a Bitcoin Core pockets.


Let me information you thru an instance to realize this on regtest. Be aware the WIF encoding differs on check networks, however the course of is identical on mainnet. I will be utilizing the non-public key cSWVo8YMehg6STxqw6xGgmMJE6Ac6RCJ7owcrBZRAT7QANtyAAEj, similar to public key 023ad6336ae257527ff59ec4356fa5d2ac33fff5e04be9e5958dfed9b0100b7948.

First, create a descriptor for the non-public key and get its checksum utilizing getdescriptorinfo:

$ bitcoin-cli -regtest getdescriptorinfo "pk(cSWVo8YMehg6STxqw6xGgmMJE6Ac6RCJ7owcrBZRAT7QANtyAAEj)"                                                                                                                                                                                                               
{                                                                                                                                                                                  
  "descriptor": "pk(023ad6336ae257527ff59ec4356fa5d2ac33fff5e04be9e5958dfed9b0100b7948)#vl2598s2",                                                                                 
  "checksum": "0hjwa0sj",                                                                                                                                                          
  "isrange": false,                                                                       
  "issolvable": true,                                                                                                                                                              
  "hasprivatekeys": true                                                                                                                                                           
}

Then create a pockets and import this descriptor:

$ bitcoin-cli -regtest createwallet p2pk_recovery false true                                                                                                                                                                                                                                                                               
{                                                                                                                                                                                                                                                                                                                                                                          
  "identify": "p2pk_recovery",                                                                                                                                                                                                                                                                                                                                                 
  "warning": ""                                                                                                                                                                                                                                                                                                                                                            
}
$ bitcoin-cli -regtest -rpcwallet=p2pk_recovery importdescriptors '[{"desc":"pk(cSWVo8YMehg6STxqw6xGgmMJE6Ac6RCJ7owcrBZRAT7QANtyAAEj)#0hjwa0sj","timestamp":"now"}]'                                                                                                                                                                       
[                                                                                                                                                                                                                                                                                                                                                                          
  {                                                                                                                                                                                                                                                                                                                                                                        
    "success": true                                                                                                                                                                                                                                                                                                                                                        
  }                                                                                                                                                                                                                                                                                                                                                                        
]
$ bitcoin-cli -regtest -rpcwallet=p2pk_recovery listdescriptors                                                                                                                                                                                                                                                                            
{                                                                                                                                                                                                                                                                                                                                                                          
  "wallet_name": "p2pk_recovery",                                                                                                                                                                                                                                                                                                                                          
  "descriptors": [                                                                                                                                                                                                                                                                                                                                                         
    {                                                                                                                                                                                                                                                                                                                                                                      
      "desc": "pk(023ad6336ae257527ff59ec4356fa5d2ac33fff5e04be9e5958dfed9b0100b7948)#vl2598s2",                                                                                                                                                                                                                                                                           
      "timestamp": 1681809105,                                                                                                                                                                                                                                                                                                                                             
      "active": false                                                                                                                                                                                                                                                                                                                                                      
    }                                                                                                                                                                                                                                                                                                                                                                      
  ]                                                                                                                                                                                                                                                                                                                                                                        
}

Then rescan the chain. I did not have to do that on my finish, however you should utilize rescanblockchain. Should you already know the peak of the outputs you might be on the lookout for i strongly advise you specify a spread to hurry up the rescan. As an illustration if you recognize you’ve got solely bought outputs between blocks 100 and 150:

$ bitcoin-cli -regtest -rpcwallet=p2pk_recovery rescanblockchain 100 150                                                                                                                                                                                                                                                                   
{
  "start_height": 100,
  "stop_height": 150
}

By now you need to have at the least one utxo for at the least one of many imported descriptors in your pockets:

$ bitcoin-cli -regtest -rpcwallet=p2pk_recovery listunspent                                                                                                                                                                                                                                                                                
[                                                                                                                                                                                                                                                                                                                                                                          
  {                                                                                                                                                                                                                                                                                                                                                                        
    "txid": "29c3b60341cff26bdce49c3611259ac50cddde4225307c6a130f12abfdb7e22a",                                                                                                                                                                                                                                                                                            
    "vout": 0,                                                                                                                                                                                                                                                                                                                                                             
    "address": "myzWnxTFbp4La7uSAK4ppyg45bTw96hQ2S",                                                                                                                                                                                                                                                                                                                       
    "label": "",                                                                                                                                                                                                                                                                                                                                                           
    "scriptPubKey": "21023ad6336ae257527ff59ec4356fa5d2ac33fff5e04be9e5958dfed9b0100b7948ac",                                                                                                                                                                                                                                                                              
    "amount": 0.00051000,                                                                                                                                                                                                                                                                                                                                                  
    "confirmations": 1,                                                                                                                                                                                                                                                                                                                                                    
    "spendable": true,                                                                                                                                                                                                                                                                                                                                                     
    "solvable": true,                                                                                                                                                                                                                                                                                                                                                      
    "desc": "pk([caa89f91]023ad6336ae257527ff59ec4356fa5d2ac33fff5e04be9e5958dfed9b0100b7948)#kmv3ht9h",                                                                                                                                                                                                                                                                   
    "parent_descs": [                                                                                                                                                                                                                                                                                                                                                      
      "pk(023ad6336ae257527ff59ec4356fa5d2ac33fff5e04be9e5958dfed9b0100b7948)#vl2598s2"                                                                                                                                                                                                                                                                                    
    ],                                                                                                                                                                                                                                                                                                                                                                     
    "secure": true                                                                                                                                                                                                                                                                                                                                                           
  }                                                                                                                                                                                                                                                                                                                                                                        
]

You possibly can then trivially spend the cash out of your pockets. As an illustration:

$ bitcoin-cli -named -regtest -rpcwallet=p2pk_recovery sendtoaddress handle=bcrt1pne0s48y6akyw2zd4uzua033u9dxeywxu7wd6fzu3l2dcf7sc3qhsd87l2x quantity=0.0005 fee_rate=1
de3c9371404c07493e8c5f43149b91c5c1ed556ebc93ace47617d96026d4902d

If you’re utilizing Bitcoin Core model 24 or increased you can even use the sendall command that enables for a better sweep of all confirmed cash within the pockets since you do not have to set the quantity. As an illustration (with the identical worth as above):

bitcoin-cli -named -regtest -rpcwallet=p2pk_recovery sendall recipients="["bcrt1pne0s48y6akyw2zd4uzua033u9dxeywxu7wd6fzu3l2dcf7sc3qhsd87l2x"]" fee_rate=1

Be aware additionally that i am utilizing a 1sat/vb feerate on regtest, however on mainnet you wish to use an correct price estimation as an alternative of this arbitrary worth.

LEAVE A REPLY

Please enter your comment!
Please enter your name here