Fix ChannelsPayment when destpub issues payment,add check_signing_pubkey
This commit is contained in:
@@ -222,6 +222,7 @@ std::vector<uint8_t> Mypubkey();
|
|||||||
bool Myprivkey(uint8_t myprivkey[]);
|
bool Myprivkey(uint8_t myprivkey[]);
|
||||||
int64_t CCduration(int32_t &numblocks,uint256 txid);
|
int64_t CCduration(int32_t &numblocks,uint256 txid);
|
||||||
bool komodo_txnotarizedconfirmed(uint256 txid);
|
bool komodo_txnotarizedconfirmed(uint256 txid);
|
||||||
|
CPubKey check_signing_pubkey(CScript scriptSig);
|
||||||
// CCtx
|
// CCtx
|
||||||
bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey);
|
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);
|
std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret);
|
||||||
|
|||||||
@@ -599,3 +599,34 @@ bool komodo_txnotarizedconfirmed(uint256 txid)
|
|||||||
return (true);
|
return (true);
|
||||||
return (false);
|
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();
|
||||||
|
}
|
||||||
|
|||||||
@@ -222,6 +222,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &
|
|||||||
//vout.3: normal output of payment amount to receiver pubkey
|
//vout.3: normal output of payment amount to receiver pubkey
|
||||||
//vout.n-2: normal change
|
//vout.n-2: normal change
|
||||||
//vout.n-1: opreturn - 'P' opentxid senderspubkey receiverspubkey depth numpayments secret
|
//vout.n-1: opreturn - 'P' opentxid senderspubkey receiverspubkey depth numpayments secret
|
||||||
|
check_signing_pubkey(tx.vin[1].scriptSig);
|
||||||
if (komodo_txnotarizedconfirmed(opentxid) == 0)
|
if (komodo_txnotarizedconfirmed(opentxid) == 0)
|
||||||
return eval->Invalid("channelOpen is not yet confirmed(notarised)!");
|
return eval->Invalid("channelOpen is not yet confirmed(notarised)!");
|
||||||
else if ( IsCCInput(tx.vin[0].scriptSig) != 0 )
|
else if ( IsCCInput(tx.vin[0].scriptSig) != 0 )
|
||||||
@@ -422,8 +423,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 ( (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 &&
|
if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 &&
|
||||||
(tmp_txid==openTx.GetHash() || tx.GetHash()==openTx.GetHash()) &&
|
(tmp_txid==openTx.GetHash() || tx.GetHash()==openTx.GetHash()) && IsChannelsMarkervout(cp,tx,marker==1?srcpub:destpub,marker)>0 &&
|
||||||
(totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0)+IsChannelsMarkervout(cp,tx,srcpub,marker))>0)
|
(totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0))>0)
|
||||||
{
|
{
|
||||||
txid = it->first.txhash;
|
txid = it->first.txhash;
|
||||||
break;
|
break;
|
||||||
@@ -443,7 +444,7 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C
|
|||||||
tmp_txid==openTx.GetHash() && param1 < mindepth)
|
tmp_txid==openTx.GetHash() && param1 < mindepth)
|
||||||
{
|
{
|
||||||
txid=hash;
|
txid=hash;
|
||||||
totalinputs=txmempool.vout[0].nValue+txmempool.vout[1].nValue;
|
totalinputs=txmempool.vout[0].nValue;
|
||||||
mindepth=param1;
|
mindepth=param1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -543,7 +544,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2
|
|||||||
}
|
}
|
||||||
if (AddNormalinputs(mtx,mypk,2*txfee,3) > 0)
|
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;
|
numpayments=amount/payment;
|
||||||
if (GetTransaction(prevtxid,prevTx,hashblock,false) != 0 && (numvouts=prevTx.vout.size()) > 0 &&
|
if (GetTransaction(prevtxid,prevTx,hashblock,false) != 0 && (numvouts=prevTx.vout.size()) > 0 &&
|
||||||
|
|||||||
Reference in New Issue
Block a user