Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: TheArchaeologist on August 27, 2018, 09:33:23 AM



Title: Segwit and decoderawtransaction
Post by: TheArchaeologist on August 27, 2018, 09:33:23 AM
Am I right to assume when the response of a the bitcoin-cli request for decoderawtransaction contains at least one txinwitness in the input section ("vin") the transaction is a segwit transaction? And the other way around: when there is no txinwitness in the vin-section it should not be considered a segwit transaction?

Any input is appreciated!


Title: Re: Segwit and decoderawtransaction
Post by: HCP on August 28, 2018, 01:23:14 AM
That is a fairly safe assumption.

If there are no "txinwitness" blocks, then none of the inputs being used are "SegWit" inputs... therefore, it isn't a SegWit "transaction"... or more correctly, it doesn't contain any SegWit data.


Title: Re: Segwit and decoderawtransaction
Post by: TheArchaeologist on August 28, 2018, 06:40:02 AM
That is a fairly safe assumption.

If there are no "txinwitness" blocks, then none of the inputs being used are "SegWit" inputs... therefore, it isn't a SegWit "transaction"... or more correctly, it doesn't contain any SegWit data.
Thanks for your input! Good to know I didn't make a false assumption.

BTW: I will use this to check the number transactions containing Segwit data vs number of transactions without Segwit data in a block.


Title: Re: Segwit and decoderawtransaction
Post by: nc50lc on August 28, 2018, 06:50:25 AM
BTW: I will use this to check the number transactions containing Segwit data vs number of transactions without Segwit data in a block.
In that case, start from block cluster (blk.dat files) blk00971.dat onwards.
Check for the dates, since SegWit was started on August 24, 2017, you might save some time by skipping the older blocks.  ;)


Title: Re: Segwit and decoderawtransaction
Post by: TheArchaeologist on August 28, 2018, 07:06:50 AM
In that case, start from block cluster (blk.dat files) blk00971.dat onwards.
Check for the dates, since SegWit was started on August 24, 2017, you might save some time by skipping the older blocks.  ;)
Thanks, I'm aware of when Segwit activated ;) I already marked all transactions from blocks prior to 481,824 being "Non segwit".   


Title: Re: Segwit and decoderawtransaction
Post by: Thirdspace on August 28, 2018, 10:09:46 AM
Code:
    "txid": "c7da009b85f48502023e5be467bef367092ed7d3ce25ce0b3b13f9a4945d932a",
    "hash": "7f8e80ea576384721538ead7ef47a3e6004171dbfb3b8e29cf191c39be5b8e51",
another thing that I notice on a segwit transaction is its txid differs from its (tx)hash
@TheArchaeologist you've done the "blockhash as private key" experiment on the other thread
while you're compiling data on segwit vs non-segwit txs in all blocks,
you should also do "private key" experiment on segwit txhashes too ;D
segwit tx has 2 possible hex numbers (txid and hash) that can be used as private keys


Title: Re: Segwit and decoderawtransaction
Post by: TheArchaeologist on August 28, 2018, 12:15:28 PM
Code:
    "txid": "c7da009b85f48502023e5be467bef367092ed7d3ce25ce0b3b13f9a4945d932a",
    "hash": "7f8e80ea576384721538ead7ef47a3e6004171dbfb3b8e29cf191c39be5b8e51",
another thing that I notice on a segwit transaction is its txid differs from its (tx)hash
@TheArchaeologist you've done the "blockhash as private key" experiment on the other thread
while you're compiling data on segwit vs non-segwit txs in all blocks,
you should also do "private key" experiment on segwit txhashes too ;D
segwit tx has 2 possible hex numbers (txid and hash) that can be used as private keys
Good idea. I will add it to my list of things-to-do. I'm currently working on adding extra data to my database so it might be a while when I get to this. I will update in the other thread when I performed the experiment.


Title: Re: Segwit and decoderawtransaction
Post by: TheArchaeologist on September 14, 2018, 11:58:24 AM
That is a fairly safe assumption.

If there are no "txinwitness" blocks, then none of the inputs being used are "SegWit" inputs... therefore, it isn't a SegWit "transaction"... or more correctly, it doesn't contain any SegWit data.
I am currently doing some more research into this and maybe there is at least one other scenario where a transaction is a "Segwit transaction" without a single "txwitness" block. That scenario is  when the coinbase reward is collected by a native Segwit address (bc1...).

An example:
Code:
bitcoin-cli getrawtransaction 2d531f2d4bf1227a6492656b4b340d36c810d313d94a413a965524ae71086bb9 1

Returns:
{
  "txid": "2d531f2d4bf1227a6492656b4b340d36c810d313d94a413a965524ae71086bb9",
  "hash": "157d1c3bf4860855a6f98792d459f83ad3bd8844cf729c8d9a6ec3accc5e2d7f",
  "version": 2,
  "size": 290,
  "vsize": 263,
  "locktime": 0,
  "vin": [
    {
      "coinbase": "039b4208045c2b9b5b642f4254432e434f4d2ffabe6d6d91102119a0522dda683a998f05620ba4beb1f5372a04689d07d47a291dbd25c20100000000000000653f93327a0200fd00000000",
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 12.50253935,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 97cfc76442fe717f2a3f0cc9c175f7561b661997",
        "hex": "001497cfc76442fe717f2a3f0cc9c175f7561b661997",
        "reqSigs": 1,
        "type": "witness_v0_keyhash",
        "addresses": [
          "bc1qjl8uwezzlech723lpnyuza0h2cdkvxvh54v3dn"
        ]
      }
    },
    {
      "value": 0.00000000,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_RETURN aa21a9ed1892392fc479aa2479df651f83a83c625ae23d35876a9fac6d9c617c8d602d9f",
        "hex": "6a24aa21a9ed1892392fc479aa2479df651f83a83c625ae23d35876a9fac6d9c617c8d602d9f",
        "type": "nulldata"
      }
    },
    {
      "value": 0.00000000,
      "n": 2,
      "scriptPubKey": {
        "asm": "2 3 [error]",
        "hex": "52534b424c4f434b3ad1087f5ba5c0e6d2c0ebe90d2ef35033860dfa99aec1afe04dfd11fa70ebd1a2",
        "type": "nonstandard"
      }
    }
  ],
  "hex": "020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff4b039b4208045c2b9b5b642f4254432e434f4d2ffabe6d6d91102119a0522dda683a998f05620ba4beb1f5372a04689d07d47a291dbd25c20100000000000000653f93327a0200fd00000000ffffffff036f5c854a0000000016001497cfc76442fe717f2a3f0cc9c175f7561b6619970000000000000000266a24aa21a9ed1892392fc479aa2479df651f83a83c625ae23d35876a9fac6d9c617c8d602d9f00000000000000002952534b424c4f434b3ad1087f5ba5c0e6d2c0ebe90d2ef35033860dfa99aec1afe04dfd11fa70ebd1a20120000000000000000000000000000000000000000000000000000000000000000000000000",
  "blockhash": "0000000000000000000b616cd42f140420d47544464ea9e59f72ff4d124f903a",
  "confirmations": 48,
  "time": 1536895846,
  "blocktime": 1536895846
}

Note: the vout-part mentions a type of "witness_v0_keyhash".

I'm not sure if this should be counted as a "Segwit transaction" or not. I guess it all comes down to the question if a coinbase transaction always counts as a non-segwit input or not.

Any feedback is welcome!