diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 3f8d8f672..982f5aa77 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -222,6 +222,7 @@ std::vector Mypubkey(); bool Myprivkey(uint8_t myprivkey[]); int64_t CCduration(int32_t &numblocks,uint256 txid); bool komodo_txnotarizedconfirmed(uint256 txid); +CPubKey check_signing_pubkey(CScript scriptSig); // CCtx bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey); std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret); diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 5d72b6b53..e9c30acc1 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -599,3 +599,34 @@ bool komodo_txnotarizedconfirmed(uint256 txid) return (true); return (false); } + +CPubKey check_signing_pubkey(CScript scriptSig) +{ + + bool found = false; + CPubKey pubkey; + + auto findEval = [](CC *cond, struct CCVisitor _) { + bool r = false; + + if (cc_typeId(cond) == CC_Secp256k1) { + *(CPubKey*)_.context=buf2pk(cond->publicKey); + r = true; + } + // false for a match, true for continue + return r ? 0 : 1; + }; + + CC *cond = GetCryptoCondition(scriptSig); + + if (cond) { + CCVisitor visitor = { findEval, (uint8_t*)"", 0, &pubkey }; + bool out = !cc_visit(cond, visitor); + cc_free(cond); + + if (pubkey.IsValid()) { + return pubkey; + } + } + return CPubKey(); +} diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 2a7ebc931..a375edbda 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -422,8 +422,8 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C if ( (int32_t)it->first.index==0 && GetTransaction(it->first.txhash,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0) { if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && - (tmp_txid==openTx.GetHash() || tx.GetHash()==openTx.GetHash()) && - (totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0)+IsChannelsMarkervout(cp,tx,srcpub,marker))>0) + (tmp_txid==openTx.GetHash() || tx.GetHash()==openTx.GetHash()) && IsChannelsMarkervout(cp,tx,marker==1?srcpub:destpub,marker)>0 && + (totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0))>0) { txid = it->first.txhash; break; @@ -443,7 +443,7 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C tmp_txid==openTx.GetHash() && param1 < mindepth) { txid=hash; - totalinputs=txmempool.vout[0].nValue+txmempool.vout[1].nValue; + totalinputs=txmempool.vout[0].nValue; mindepth=param1; } } @@ -543,7 +543,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 } if (AddNormalinputs(mtx,mypk,2*txfee,3) > 0) { - if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid,mypk)) !=0 && (change=funds-amount-txfee)>=0) + if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid,mypk)) !=0 && (change=funds-amount)>=0) { numpayments=amount/payment; if (GetTransaction(prevtxid,prevTx,hashblock,false) != 0 && (numvouts=prevTx.vout.size()) > 0 &&