signrawtransaction – Signing uncooked transaction with p2pk inputs sending to p2pkh output

0
61


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


Let me information you thru an instance to realize this on regtest. Notice the WIF encoding differs on take a look at networks, however the course of is identical on mainnet. I will be utilizing the personal key cSWVo8YMehg6STxqw6xGgmMJE6Ac6RCJ7owcrBZRAT7QANtyAAEj, akin to public key 023ad6336ae257527ff59ec4356fa5d2ac33fff5e04be9e5958dfed9b0100b7948.

First, create a descriptor for the personal 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                                                                                                                                                                                                                                                                               
{                                                                                                                                                                                                                                                                                                                                                                          
  "title": "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 need to use rescanblockchain. In the event you already know the peak of the outputs you’re searching for i strongly advise you specify a variety to hurry up the rescan. As an example if you recognize you’ve got solely acquired 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 no less than one utxo for no less than 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 may then trivially spend the cash out of your pockets. As an example:

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

In case you are utilizing Bitcoin Core model 24 or increased you too can 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 example (with the identical worth as above):

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

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here