diff --git a/bin/main b/bin/main index 58cd334..fe641a0 100755 Binary files a/bin/main and b/bin/main differ diff --git a/src/script.h b/src/script.h index 8d5e413..6300f0a 100644 --- a/src/script.h +++ b/src/script.h @@ -442,21 +442,21 @@ int verify_txn(Json::Value &txn) { valid = p2pkh_verify(scriptPubKeyOps, scriptSigOps, txn); } else if (scriptPubKeyType == "p2sh") { - serialized_txn = serialize_segwit_1(txn) + serialize_segwit_inp(inp) + serialize_segwit_2(txn); + serialized_txn = serialize_segwit_1(txn) + serialize_segwit_inp(inp, "p2sh") + serialize_segwit_2(txn); std::vector scriptSigOps = getOps(inp["scriptsig_asm"].asString()); std::vector redeemScriptOps = getOps(inp["inner_redeemscript_asm"].asString()); valid = p2sh_verify(scriptPubKeyOps, scriptSigOps, redeemScriptOps, txn, inp); } // DONE else if (scriptPubKeyType == "v0_p2wpkh") { - serialized_txn = serialize_segwit_1(txn) + serialize_segwit_inp(inp) + serialize_segwit_2(txn); + serialized_txn = serialize_segwit_1(txn) + serialize_segwit_inp(inp, "p2wpkh") + serialize_segwit_2(txn); std::vector witness; for (auto &wtns : inp["witness"]) witness.push_back(wtns.asString()); valid = p2wpkh_verify(scriptPubKeyOps, witness, txn); } else if (scriptPubKeyType == "v0_p2wsh") { - serialized_txn = serialize_segwit_1(txn) + serialize_segwit_inp(inp) + serialize_segwit_2(txn); + serialized_txn = serialize_segwit_1(txn) + serialize_segwit_inp(inp, "p2wsh") + serialize_segwit_2(txn); std::vector witness; for (auto &wtns : inp["witness"]) witness.push_back(wtns.asString()); diff --git a/src/serialize.h b/src/serialize.h index e7feb60..f4a84ff 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -12,6 +12,9 @@ using namespace std; #define IS_UINT32_T 0 #define IS_INT64_T 1 +extern string identifyScriptType(std::vector &ops); +extern std::vector getOps(std::string asmScript); + typedef basic_string ustring; uint8_t hex2int(char ch) @@ -184,7 +187,7 @@ string serialize_segwit_1 (Json::Value txn) { } -string serialize_segwit_inp (Json::Value inp) { +string serialize_segwit_inp (Json::Value inp, string scriptType) { string ser_inp = ""; ser_inp = hexstr2bstr(inp["txid"].asString()); @@ -193,7 +196,13 @@ string serialize_segwit_inp (Json::Value inp) { // Need to find the PKH from prevout's scriptpubkey string scriptcode = "1976a914"; - scriptcode += inp["prevout"]["scriptpubkey"].asString().substr(4); + if (scriptType == "p2sh") { + vector ops = getOps(inp["inner_redeemscript_asm"].asString()); + if (identifyScriptType(ops) == "p2wpkh") + scriptcode += ops[2]; + } + else if (scriptType == "p2wpkh") + scriptcode += inp["prevout"]["scriptpubkey"].asString().substr(4); scriptcode += "88ac"; ser_inp += hexstr2bstr(scriptcode);