public int getSigInsertionIndex ( Sha256Hash hash , ECKey signingKey ) { // Iterate over existing signatures, skipping the initial OP_0, the final redeem script // and any placeholder OP_0 sigs. List < ScriptChunk > existingChunks = chunks . subList ( 1 , chunks . size ( ) - 1 ) ; ScriptChunk redeemScriptChunk = chunks . get ( chunks . size ( ) - 1 ) ; checkNotNull ( redeemScriptChunk . data ) ; Script redeemScript = new Script ( redeemScriptChunk . data ) ; int sigCount = 0 ; int myIndex = redeemScript . findKeyInRedeem ( signingKey ) ; for ( ScriptChunk chunk : existingChunks ) { if ( chunk . opcode == OP_0 ) { // OP_0, skip } else { checkNotNull ( chunk . data ) ; try { if ( myIndex < redeemScript . findSigInRedeem ( chunk . data , hash ) ) return sigCount ; } catch ( SignatureDecodeException e ) { // ignore } sigCount ++ ; } } return sigCount ; }
Returns the index where a signature by the key should be inserted . Only applicable to a P2SH scriptSig .