wallet – Segwit Bitcoin Transaction Signing

As I could understand, we can retrieve the R and S values ​​of any transaction that follows the ScriptSig where we have DER serialization.

  1. The segwit transactions, where the signature will be in the witness section, recovering R and S follow the same steps?
  2. If I use the compressed public key (starting with 0x02 or 0x03), how can I verify the signature, since I don't have the Y coordinate of the public key?
  3. For transactions of multiple signatures that use P2SH, as I understand it, we must sign with the first key, then obtain the exit transaction with the first signature and sign it with the other key, but using the signature math we use the hash of the message that is the txId, but in segwit the txid will not change after signing since the witness does not count as part of the hash for txid?

Anything else you should look at when signing a transaction?

scalability: problem caused by unconfirmed transaction chains

I want to create a service that requires sending many small bitcoin transactions to multiple wallets (like a tap).

Since the transactions are small, the rates must also be kept small, so it takes time to confirm them.

The system would need to send many transactions, which naturally creates long chains of unconfirmed transactions. If I understand correctly, after 25 unconfirmed transactions, the network begins to reject new ones and the system is basically stuck until the previous ones are confirmed.

This limits the performance of said system to 25 transactions per confirmation time (which is at least a few hours due to low rates), which makes it completely inscrutable.

Given the above, is there a way to build a scalable (something) service that can send many small transactions? (without having to manage many wallets)

segregated witness – Sign unprocessed Segwit transaction summary (P2WPKH)

I have a simple transaction from which I want to sign the summary, but I am not sure I have the correct raw transaction, therefore, my summary is incorrect.

The transaction has an entry and an exit, but with a P2WPKH transaction, I am not sure what to use in the SigScript field so you can sha256 (sha256) and get the correct summary to sign. (for P2PKH you use an OP_DUP, OP_HASH160 PUBKEY_HASH OP_EQUALVERIFY OP_CHECKSIG that you can get from the UTXO entry in the SigScript field)

This is my raw transaction:
02000000010a02214430acee2ed509798187210171bb387075ce2c82ef5a73774d6159387500000000
00
ffffffff018ca1b404000000001976a914906ec1c4804632c0b067e5a2732c41cdf620c4e688ac0000000001000000

These are the bytes in which I am calculating the sha256 (sha256) and, as you can see, I have 00 bytes in the SigScript field. Is this correct? Should I be using something else here?

I take my signature and then create the signed transaction like this:
020000000001010a02214430acee2ed509798187210171bb387075ce2c82ef5a73774d6159387500000000
17160014d99f1ea19e98d9ed10e5d442be37a44b6b63c477ffffffff  (hash160 of public key)
018ca1b404000000001976a914906ec1c4804632c0b067e5a2732c41cdf620c4e688ac
02 (number of stack items)    
(signature)
4830460221009f5d0f24faff44fc6ffd364ef4af87d366b95058c60497b87f9fd51bb3e60f59022100f768fb09286f8c9f5aba7295e6a2ce243f2f1eac29b717feb18108b6e8c0003a
(public key)    
41047d011958b661181242addd300b6d5c51f80d62674555831dd855b34358b57e05fb46477ba167a57b23bf8a492305c0085d8c34aa04d483b7f15a2d551e2ff66200000000

But this does not seem to work and says that my signature is not valid, so I can only assume that my summary is not correct. Any help would be appreciated.

Is it possible, with bitcoin-core or btcd, to manually configure the scriptSig field in a coinbase transaction?

I'm talking when I use regtest or simnet modes.

By context, it is so that you can create coinbase transactions with reproducible txids.

Client – How do I get Raw Transaction Txid, Scriptpubkey using the Bitcoin Core console?

I just downloaded Bitcoin Core in Windows 7 and I am trying to create a raw transaction. When I wrote listunspent 0 or listunspent 1 on the console, I did not receive any messages (empty message) on the console. How do I get the raw transaction txid, scriptpubkey using the bitcoin center console?

Can a coinbase transaction have a segwit output?

And, more generally, is there any restriction on the output of a coinbase transaction?

bitcoin core: bitcoind multigrade transaction is not shown as multigrade transaction / shown as "signed" by 2: 3

It seems that there was a change in the way multigrade transactions are created. Executing a node using bitcoind v0.16.3 and another using the last bitcoind (v.0.19.0.1).

Coinb.in can correctly decode the multigrade transaction created in the previous node (it is shown as a 2: 3 multigrade transaction). Using the newest bitcoind to create the coinb.in transaction cannot display it correctly.

Anyone involved in this / is there any way to use the latest version of bitcoind to create a multigrade transaction that can be decoded in coinb.in (maybe using signing parameters)?

Example using the latest version of bitcoind (v.0.19.0.1)

./bitcoin-cli createmultisig 2 "("02ab224d0d8de7d5ad5568bf4f66b9c29ea7afd0f196176f9b09a311c11da6377e","037b3ccfb03f8dc58598619b2f3a91e33012444469fc69b4459760d04c20c4d69c","034254badc6cd5c4fa4e0ca10fb88d289bd7260331c5355ec2361312eafb26eb67")"
{
  "address": "3Cvczsgf3JTCHSjPgRACCia5gtyQKJWng8",
  "redeemScript": "522102ab224d0d8de7d5ad5568bf4f66b9c29ea7afd0f196176f9b09a311c11da6377e21037b3ccfb03f8dc58598619b2f3a91e33012444469fc69b4459760d04c20c4d69c21034254badc6cd5c4fa4e0ca10fb88d289bd7260331c5355ec2361312eafb26eb6753ae"
}

Now I found the address using TX 63c8c68a3cbf693a2601854496ffd687334c205bcc0e52811ef9c552d0641c01

Important part using getrawtransaction:

{
  "value": 0.00053938,
  "n": 1,
  "scriptPubKey": {
    "asm": "OP_HASH160 7b3c11ea9596776b98f1d7e68ffcf891e860216f OP_EQUAL",
    "hex": "a9147b3c11ea9596776b98f1d7e68ffcf891e860216f87",
    "reqSigs": 1,
    "type": "scripthash",
    "addresses": (
      "3Cvczsgf3JTCHSjPgRACCia5gtyQKJWng8"
    )
  }

Create a transaction using the information

./bitcoin-cli createrawtransaction "({"txid":"63c8c68a3cbf693a2601854496ffd687334c205bcc0e52811ef9c552d0641c01","vout":1})" "({"1GAFEtKWhwn5wQTt53kFMgd4b7xEyCxHHg":0.00048961})"

Transaction generated (unsigned) Decoding in coinb.in does not show details of multiple designs:

0200000001011c64d052c5f91e81520ecc5b204c3387d6ff96448501263a69bf3c8ac6c8630100000000ffffffff0141bf0000000000001976a914a6498450eb421d3926fcf12366e5abe2e7dfb93688ac00000000

After signing, there are still no details about multisig in coinb.in, using bitcoind v0.16.3 the transaction itself is shown as type multisig correctly. Any idea how to get the same result using the last bitcoind?

To update

Signing the transaction with 1 key:

'signrawtransactionwithkey',(
            "0200000001011c64d052c5f91e81520ecc5b204c3387d6ff96448501263a69bf3c8ac6c8630100000000ffffffff0141bf0000000000001976a914a6498450eb421d3926fcf12366e5abe2e7dfb93688ac00000000",
            (
                "privkey",
            ),
            (
                "txid"              => "63c8c68a3cbf693a2601854496ffd687334c205bcc0e52811ef9c552d0641c01",
                "vout"              => 1,
                "scriptPubKey"      => "a9147b3c11ea9596776b98f1d7e68ffcf891e860216f87",
                "redeemScript"      => "522102ab224d0d8de7d5ad5568bf4f66b9c29ea7afd0f196176f9b09a311c11da6377e21037b3ccfb03f8dc58598619b2f3a91e33012444469fc69b4459760d04c20c4d69c21034254badc6cd5c4fa4e0ca10fb88d289bd7260331c5355ec2361312eafb26eb6753ae",
                "amount"            => 0.00053938,
            ),
        )

Returns:

{
"result":{
"hex":"0200000001011c64d052c5f91e81520ecc5b204c3387d6ff96448501263a69bf3c8ac6c86301000000b50047304402200e83a051845ff6d5d20fd9cab5c6e15e8ae99ab0b2ac14bcf991f4f3bad3b4a00220555c7c3d419e80165e8f42385b158ca01a125686e19bf01a522332c35e689dd701004c69522102ab224d0d8de7d5ad5568bf4f66b9c29ea7afd0f196176f9b09a311c11da6377e21037b3ccfb03f8dc58598619b2f3a91e33012444469fc69b4459760d04c20c4d69c21034254badc6cd5c4fa4e0ca10fb88d289bd7260331c5355ec2361312eafb26eb6753aeffffffff0141bf0000000000001976a914a6498450eb421d3926fcf12366e5abe2e7dfb93688ac00000000",
"complete":false,
"errors":(
{
"txid":"63c8c68a3cbf693a2601854496ffd687334c205bcc0e52811ef9c552d0641c01",
"vout":1,
"witness":(
),
"scriptSig":"0047304402200e83a051845ff6d5d20fd9cab5c6e15e8ae99ab0b2ac14bcf991f4f3bad3b4a00220555c7c3d419e80165e8f42385b158ca01a125686e19bf01a522332c35e689dd701004c69522102ab224d0d8de7d5ad5568bf4f66b9c29ea7afd0f196176f9b09a311c11da6377e21037b3ccfb03f8dc58598619b2f3a91e33012444469fc69b4459760d04c20c4d69c21034254badc6cd5c4fa4e0ca10fb88d289bd7260331c5355ec2361312eafb26eb6753ae",
"sequence":4294967295,
"error":"CHECK(MULTI)SIG failing with non-zero signature (possibly need more signatures)"
}
)
},
"error":null,
"id":null
}

The transaction can be decoded using coinb.in but says signed by 2 parts which is incorrect sure

Is the transaction itself signed correctly?

bitcoin core: bitcoind multigrade transaction is not shown as multigrade transaction

It seems that there was a change in the way multigrade transactions are created. Executing a node using bitcoind v0.16.3 and another using the last bitcoind (v.0.19.0.1).

Coinb.in can correctly decode the multigrade transaction created in the previous node (it is shown as a 2: 3 multigrade transaction). Using the newest bitcoind to create the coinb.in transaction cannot display it correctly.

Anyone involved in this / is there any way to use the latest version of bitcoind to create a multigrade transaction that can be decoded in coinb.in (maybe using signing parameters)?

Example using the latest version of bitcoind (v.0.19.0.1)

./bitcoin-cli createmultisig 2 "("02ab224d0d8de7d5ad5568bf4f66b9c29ea7afd0f196176f9b09a311c11da6377e","037b3ccfb03f8dc58598619b2f3a91e33012444469fc69b4459760d04c20c4d69c","034254badc6cd5c4fa4e0ca10fb88d289bd7260331c5355ec2361312eafb26eb67")"
{
  "address": "3Cvczsgf3JTCHSjPgRACCia5gtyQKJWng8",
  "redeemScript": "522102ab224d0d8de7d5ad5568bf4f66b9c29ea7afd0f196176f9b09a311c11da6377e21037b3ccfb03f8dc58598619b2f3a91e33012444469fc69b4459760d04c20c4d69c21034254badc6cd5c4fa4e0ca10fb88d289bd7260331c5355ec2361312eafb26eb6753ae"
}

Now I found the address using TX 63c8c68a3cbf693a2601854496ffd687334c205bcc0e52811ef9c552d0641c01

Important part using getrawtransaction:

{
  "value": 0.00053938,
  "n": 1,
  "scriptPubKey": {
    "asm": "OP_HASH160 7b3c11ea9596776b98f1d7e68ffcf891e860216f OP_EQUAL",
    "hex": "a9147b3c11ea9596776b98f1d7e68ffcf891e860216f87",
    "reqSigs": 1,
    "type": "scripthash",
    "addresses": (
      "3Cvczsgf3JTCHSjPgRACCia5gtyQKJWng8"
    )
  }

Create a transaction using the information

./bitcoin-cli createrawtransaction "({"txid":"63c8c68a3cbf693a2601854496ffd687334c205bcc0e52811ef9c552d0641c01","vout":1})" "({"1GAFEtKWhwn5wQTt53kFMgd4b7xEyCxHHg":0.00048961})"

Transaction generated (unsigned) Decoding in coinb.in does not show details of multiple designs:

0200000001011c64d052c5f91e81520ecc5b204c3387d6ff96448501263a69bf3c8ac6c8630100000000ffffffff0141bf0000000000001976a914a6498450eb421d3926fcf12366e5abe2e7dfb93688ac00000000

After signing, there are still no details about multisig in coinb.in, using bitcoind v0.16.3 the transaction itself is shown as type multisig correctly. Any idea how to get the same result using the last bitcoind?

To update

Signing the transaction with 1 key:

'signrawtransactionwithkey',(
            "0200000001011c64d052c5f91e81520ecc5b204c3387d6ff96448501263a69bf3c8ac6c8630100000000ffffffff0141bf0000000000001976a914a6498450eb421d3926fcf12366e5abe2e7dfb93688ac00000000",
            (
                "privkey",
            ),
            (
                "txid"              => "63c8c68a3cbf693a2601854496ffd687334c205bcc0e52811ef9c552d0641c01",
                "vout"              => 1,
                "scriptPubKey"      => "a9147b3c11ea9596776b98f1d7e68ffcf891e860216f87",
                "redeemScript"      => "522102ab224d0d8de7d5ad5568bf4f66b9c29ea7afd0f196176f9b09a311c11da6377e21037b3ccfb03f8dc58598619b2f3a91e33012444469fc69b4459760d04c20c4d69c21034254badc6cd5c4fa4e0ca10fb88d289bd7260331c5355ec2361312eafb26eb6753ae",
                "amount"            => 0.00053938,
            ),
        )

Returns:

{
"result":{
"hex":"0200000001011c64d052c5f91e81520ecc5b204c3387d6ff96448501263a69bf3c8ac6c86301000000b50047304402200e83a051845ff6d5d20fd9cab5c6e15e8ae99ab0b2ac14bcf991f4f3bad3b4a00220555c7c3d419e80165e8f42385b158ca01a125686e19bf01a522332c35e689dd701004c69522102ab224d0d8de7d5ad5568bf4f66b9c29ea7afd0f196176f9b09a311c11da6377e21037b3ccfb03f8dc58598619b2f3a91e33012444469fc69b4459760d04c20c4d69c21034254badc6cd5c4fa4e0ca10fb88d289bd7260331c5355ec2361312eafb26eb6753aeffffffff0141bf0000000000001976a914a6498450eb421d3926fcf12366e5abe2e7dfb93688ac00000000",
"complete":false,
"errors":(
{
"txid":"63c8c68a3cbf693a2601854496ffd687334c205bcc0e52811ef9c552d0641c01",
"vout":1,
"witness":(
),
"scriptSig":"0047304402200e83a051845ff6d5d20fd9cab5c6e15e8ae99ab0b2ac14bcf991f4f3bad3b4a00220555c7c3d419e80165e8f42385b158ca01a125686e19bf01a522332c35e689dd701004c69522102ab224d0d8de7d5ad5568bf4f66b9c29ea7afd0f196176f9b09a311c11da6377e21037b3ccfb03f8dc58598619b2f3a91e33012444469fc69b4459760d04c20c4d69c21034254badc6cd5c4fa4e0ca10fb88d289bd7260331c5355ec2361312eafb26eb6753ae",
"sequence":4294967295,
"error":"CHECK(MULTI)SIG failing with non-zero signature (possibly need more signatures)"
}
)
},
"error":null,
"id":null
}

The transaction can be decoded using coinb.in but says signed by 2 parts which is incorrect sure

Is the transaction itself signed correctly?

bitcoind: sending transaction error with blocking time: 64: txid not final

I just found the same problem and the solution is almost stupid. Since the clue is not found elsewhere, I would add my two cents in case others step on the same trap.

It turns out that, in addition to the usual reasons related to time (for example, the time block has not expired, the sequence number is not set correctly, etc.), trying to spend an unconfirmed UTXO also causes non-final error. I didn't delve into the source code to see why this happens, but the misleading error message cost me a good afternoon.

Why would you try to spend unconfirmed products? Well, when you are busy trying things and gradually lose patience …

bitcoin core – Calculate transaction confirmations

I am writing an API for one of my systems that can verify if a monitored address is receiving Bitcoin, I can already verify if the address is in the newly received block, save it in a database for future use like UTXO, it is being managed very well .

I am encountering a problem. Since the raw blocks do not contain the height information, how can I calculate (without using any external API) the confirmations of stored transactions from my database? It makes no sense also in my architecture RPC asks for that.