1 2017-04-24 03:55:14 <suryab> what's the difference between a scriptPubKey/scriptSig and scriptCode?
 2 2017-04-24 03:56:13 <suryab> the segwit dev guide says: "Please note that for a P2SH-P2WPKH, the scriptCode is always 26 bytes including the leading size byte, as 0x1976a914{20-byte keyhash}88ac, NOT the redeemScript nor scriptPubKey"
 3 2017-04-24 04:35:39 <arubi> suryab, scriptcode is kinda like a redeemscript for witness v0 (p2wpkh,p2wsh) scriptpubkeys.  when redeeming from a p2wpkh (or p2sh(p2wpkh)), the script you're actually signing will be a p2pkh script like the one in the example.  when redeeming a p2wsh (or p2sh(p2wsh)), the scripcode is the redeemscript for the p2wsh.  what the guide says not to do is to use the segwit scriptpubkeys themselves for the signing
 4 2017-04-24 09:35:40 <rugu> Anyone know how Insight API are able to index UTXO by address?
 5 2017-04-24 09:50:09 <rugu> I am trying to use the RPC commands to a full node as well as the bitcoin-lib repo from github, so far I can get the transactions per block as per the hash or block height, but not sure wht to do next, in order to get a UTXO mapping that can be queried by public address
 6 2017-04-24 10:00:26 <arubi> rugu, did you see https://github.com/btcdrak/bitcoin/tree/addrindex-0.14 ?
 7 2017-04-24 13:24:42 <suryab> arubi when you said that the guide is saying not to use the segwit scriptPubKey itself, you mean the don't use the p2sh(p2spkh) scriptPubKey as it's defined here: https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#p2wpkh-nested-in-bip16-p2sh correct? But instead use the byte that they say
 8 2017-04-24 13:55:07 <arubi> suryab, p2spkh?  do you mean p2wpkh or p2wsh?
 9 2017-04-24 13:56:16 <arubi> what the guide means is that for redeeming p2wpkh, either nested in p2sh or not, the scriptcode is the same as a p2pkh script with the hash160 taken from the p2wpkh script
10 2017-04-24 13:57:24 <arubi> a p2wpkh looks like '0 <hash160 pubkey>', so your scriptcode will be '0x19 DUP HASH160 <hash160 pubkey> EQUALVERIFY CHECKSIG' serialized
11 2017-04-24 13:57:44 <suryab> that was a typo, i mean p2wpkh not p2spkh
12 2017-04-24 13:58:24 <arubi> a p2wsh looks like '0 <sha256 hash>' , and the scriptcode will be the redeemscript that when serialized and sha256'ed, will have give that same <sha256 hash> value from the scriptpbukey
13 2017-04-24 13:59:09 <arubi> ( plus a first byte for its size )
14 2017-04-24 14:01:52 <suryab> okay, so my scriptPubKey looks like: HASH_160 <hash-160(pubkey)> EQUAL.  the scriptSig looks like: 0 <hash160(pubkey)> and the script that I use when I compute te sig hash I use the script you specified above
15 2017-04-24 14:02:21 <suryab> sorry scriptPubKey hash160 is of the redeem script: hash160( 0 hash160(pubkey) )
16 2017-04-24 14:02:48 <suryab> sorry scriptPubKey hash160 is of the redeem script: hash160( 0 <hash160(pubkey)> )
17 2017-04-24 14:03:02 <arubi> right, in scriptsig there should only be the segwit scriptpubkey as a single push
18 2017-04-24 14:03:23 <arubi> just like redeeming any other p2sh.  it doesn't come into contact with the signing itself
19 2017-04-24 14:05:02 <suryab> yeah i've been trying variations of this but it looks like i can never produce valid transactions... strange
20 2017-04-24 14:05:33 <arubi> can you show what it is you're trying to sign?
21 2017-04-24 14:05:41 <suryab> i'm pretty sure I've made a valid p2sh(p2wpkh) address as the output of a different transaction
22 2017-04-24 14:05:48 <suryab> okay, give me a sec
23 2017-04-24 14:06:43 <suryab> aside from the script that's being signed in the sighash, does anything else about computing the has change betwee p2wpkh and p2sh(p2wpkh)?
24 2017-04-24 14:06:58 <arubi> nothing
25 2017-04-24 14:07:11 <arubi> the mid state is completely the same
26 2017-04-24 14:07:43 <arubi> er, what do you mean aside from?
27 2017-04-24 14:08:01 <arubi> to redeem a p2wpkh, or a p2sh(p2wpkh) you will have the same exact signature
28 2017-04-24 14:08:44 <arubi> the only difference is in relay when the preimage to the p2sh hash160 is set in scriptsig as a single push
29 2017-04-24 14:09:08 <suryab> okay looks like the output I was making was wrong
30 2017-04-24 14:09:17 <suryab> tranasctions are valid now, hallelujah
31 2017-04-24 14:09:21 <arubi> \o/
32 2017-04-24 14:09:37 <suryab> i've been grinding at this for some time, thanks a ton arubi!
33 2017-04-24 14:09:43 <arubi> cheers suryab
34 2017-04-24 17:38:34 <suryab> p2sh(p2wpkh) is supposed be relay-able by all nodes, even nodes that aren't NODE_WITNESS
35 2017-04-24 17:38:38 <suryab> right?
36 2017-04-24 17:41:12 <arubi> not the spend
37 2017-04-24 17:42:58 <arubi> the backward compatibility is in the ability for old software to send to p2sh addresses, relay and mining of transactions with a witness is only possible with a segwit aware node