are you SHA256 hashing twice?
Here's my Java code. This calculation does not work for P2SH transactions. This affects multisignature address with the 3 at the beginning.
To fix the method, I need a reference. So I need to know what's right. Hence my questions here.
{
if(isWitness)
{
byte[][] txPrev = getTxPrevHashNoSwap();
byte[][] prevIndex = getTxPrevIndexByte();
ByteArrayList list = new ByteArrayList(new byte[0]);
for(int i=0; i
list.add(txPrev[i]);
list.add(prevIndex[i]);
}
byte[] nVersion = getVersion_byte();
byte[] hashPrevouts = Calc.getHashSHA256(Calc.getHashSHA256(list.getArrayAll()));
list = new ByteArrayList(new byte[0]);
for(int i=0; i
list = new ByteArrayList(new byte[0]);
list.add(txPrev[txIndex]); list.add(prevIndex[txIndex]);
byte[] outpoint = list.getArrayAll();
PkScript pk = new PkScript(pkScript);
byte[] b = {0x19,0x76,(byte)0xa9,0x14};
list = new ByteArrayList(b);
list.add(pk.getHash160());
list.add((byte) 0x88); list.add((byte) 0xac);
byte[] scriptCode = list.getArrayAll();
byte[] amount = valueRaw;
byte[] nSequence = getSequence()[txIndex];
byte[] hashOutputs = new byte[witness_pos-value_pos[0]];
System.arraycopy(data, value_pos[0], hashOutputs, 0, hashOutputs.length);
hashOutputs = Calc.getHashSHA256(Calc.getHashSHA256(hashOutputs));
byte[] nLockTime = getLockTime();
byte[] nHashType = {1,0,0,0};
list = new ByteArrayList(nVersion);
list.add(hashPrevouts);
list.add(hashSequence);
list.add(outpoint);
list.add(scriptCode);
list.add(amount);
list.add(nSequence);
list.add(hashOutputs);
list.add(nLockTime);
list.add(nHashType);
return Calc.getHashSHA256(Calc.getHashSHA256(list.getArrayAll()));
}
else
{
ByteArrayList list = new ByteArrayList(data);
for(int i=txIn_count-1; i>=0;i--)
{
int pos = sigScript_pos[i]-1;
list.remove(pos, pos + sigScript_len[i]+1);
if(i==txIndex)
{
list.insert(pkScript, pos);
list.insert((byte)pkScript.length,pos);
}
else list.insert((byte)0x00, pos);
}
byte[] b = {0x01, 0x00, 0x00, 0x00};
list.add(b);
byte[] uSigTx = list.getArrayAll();
return Calc.getHashSHA256(Calc.getHashSHA256(uSigTx));
}
}