Browse Source

Alt myprivkey method

warmup
jl777 5 years ago
parent
commit
3bcfaf37a6
  1. 24
      src/cc/CCtx.cpp
  2. 8
      src/cc/CCutils.cpp
  3. 2
      src/komodo_nSPV_wallet.h
  4. 5
      src/script/sign.cpp

24
src/cc/CCtx.cpp

@ -175,11 +175,11 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran
else
{
Getscriptaddress(destaddr,vintx.vout[utxovout].scriptPubKey);
fprintf(stderr,"FinalizeCCTx() vin.%d is CC %.8f -> (%s) vs %s\n",i,(double)utxovalues[i]/COIN,destaddr,mysingletokensaddr);
//fprintf(stderr,"FinalizeCCTx() vin.%d is CC %.8f -> (%s) vs %s\n",i,(double)utxovalues[i]/COIN,destaddr,mysingletokensaddr);
//std::cerr << "FinalizeCCtx() searching destaddr=" << destaddr << " for vin[" << i << "] satoshis=" << utxovalues[i] << std::endl;
if( strcmp(destaddr, myaddr) == 0 )
{
fprintf(stderr, "FinalizeCCTx() matched cc myaddr (%s)\n", myaddr);
//fprintf(stderr, "FinalizeCCTx() matched cc myaddr (%s)\n", myaddr);
privkey = myprivkey;
cond = mycond;
}
@ -187,30 +187,30 @@ fprintf(stderr, "FinalizeCCTx() matched cc myaddr (%s)\n", myaddr);
{
privkey = myprivkey;
cond = mytokenscond;
fprintf(stderr,"FinalizeCCTx() matched dual-eval TokensCC1vout my token addr.(%s)\n",mytokensaddr);
//fprintf(stderr,"FinalizeCCTx() matched dual-eval TokensCC1vout my token addr.(%s)\n",mytokensaddr);
}
else if (strcmp(destaddr, mysingletokensaddr) == 0) // if this is TokensCC1vout
{
privkey = myprivkey;
cond = mysingletokenscond;
fprintf(stderr, "FinalizeCCTx() matched single-eval token CC1vout my token addr.(%s)\n", mytokensaddr);
//fprintf(stderr, "FinalizeCCTx() matched single-eval token CC1vout my token addr.(%s)\n", mytokensaddr);
}
else if ( strcmp(destaddr,unspendable) == 0 )
{
privkey = unspendablepriv;
cond = othercond;
fprintf(stderr,"FinalizeCCTx evalcode(%d) matched unspendable CC addr.(%s)\n",cp->evalcode,unspendable);
//fprintf(stderr,"FinalizeCCTx evalcode(%d) matched unspendable CC addr.(%s)\n",cp->evalcode,unspendable);
}
else if (strcmp(destaddr, unspendabletokensaddr) == 0)
{
privkey = unspendablepriv;
cond = othertokenscond;
fprintf(stderr,"FinalizeCCTx() matched unspendabletokensaddr dual/three-eval CC addr.(%s)\n",unspendabletokensaddr);
//fprintf(stderr,"FinalizeCCTx() matched unspendabletokensaddr dual/three-eval CC addr.(%s)\n",unspendabletokensaddr);
}
// check if this is the 2nd additional evalcode + 'unspendable' cc addr:
else if ( strcmp(destaddr, cp->unspendableaddr2) == 0)
{
fprintf(stderr,"FinalizeCCTx() matched %s unspendable2!\n",cp->unspendableaddr2);
//fprintf(stderr,"FinalizeCCTx() matched %s unspendable2!\n",cp->unspendableaddr2);
privkey = cp->unspendablepriv2;
if( othercond2 == 0 )
othercond2 = MakeCCcond1(cp->unspendableEvalcode2, cp->unspendablepk2);
@ -219,7 +219,7 @@ fprintf(stderr,"FinalizeCCTx() matched %s unspendable2!\n",cp->unspendableaddr2)
// check if this is 3rd additional evalcode + 'unspendable' cc addr:
else if ( strcmp(destaddr,cp->unspendableaddr3) == 0 )
{
fprintf(stderr,"FinalizeCCTx() matched %s unspendable3!\n",cp->unspendableaddr3);
//fprintf(stderr,"FinalizeCCTx() matched %s unspendable3!\n",cp->unspendableaddr3);
privkey = cp->unspendablepriv3;
if( othercond3 == 0 )
othercond3 = MakeCCcond1(cp->unspendableEvalcode3, cp->unspendablepk3);
@ -228,7 +228,7 @@ fprintf(stderr,"FinalizeCCTx() matched %s unspendable3!\n",cp->unspendableaddr3)
// check if this is spending from 1of2 cc coins addr:
else if (strcmp(cp->coins1of2addr, destaddr) == 0)
{
fprintf(stderr,"FinalizeCCTx() matched %s unspendable1of2!\n",cp->coins1of2addr);
//fprintf(stderr,"FinalizeCCTx() matched %s unspendable1of2!\n",cp->coins1of2addr);
privkey = cp->coins1of2priv;//myprivkey;
if (othercond1of2 == 0)
othercond1of2 = MakeCCcond1of2(cp->evalcode, cp->coins1of2pk[0], cp->coins1of2pk[1]);
@ -236,7 +236,7 @@ fprintf(stderr,"FinalizeCCTx() matched %s unspendable1of2!\n",cp->coins1of2addr)
}
else if ( strcmp(CC1of2CCaddr,destaddr) == 0 )
{
fprintf(stderr,"FinalizeCCTx() matched %s CC1of2CCaddr!\n",CC1of2CCaddr);
//fprintf(stderr,"FinalizeCCTx() matched %s CC1of2CCaddr!\n",CC1of2CCaddr);
privkey = unspendablepriv;
if (condCC2 == 0)
condCC2 = MakeCCcond1of2(cp->evalcode,unspendablepk,unspendablepk);
@ -245,7 +245,7 @@ fprintf(stderr,"FinalizeCCTx() matched %s CC1of2CCaddr!\n",CC1of2CCaddr);
// check if this is spending from 1of2 cc tokens addr:
else if (strcmp(cp->tokens1of2addr, destaddr) == 0)
{
fprintf(stderr,"FinalizeCCTx() matched %s cp->tokens1of2addr!\n", cp->tokens1of2addr);
//fprintf(stderr,"FinalizeCCTx() matched %s cp->tokens1of2addr!\n", cp->tokens1of2addr);
privkey = cp->tokens1of2priv;//myprivkey;
if (othercond1of2tokens == 0)
// NOTE: if additionalEvalcode2 is not set then it is dual-eval cc else three-eval cc
@ -293,6 +293,7 @@ fprintf(stderr,"FinalizeCCTx() matched %s cp->tokens1of2addr!\n", cp->tokens1of2
else
{
fprintf(stderr,"vini.%d has CC signing error address.(%s) %s\n",i,destaddr,EncodeHexTx(mtx).c_str());
memset(myprivkey,0,sizeof(myprivkey));
return("");
}
}
@ -320,6 +321,7 @@ fprintf(stderr,"FinalizeCCTx() matched %s cp->tokens1of2addr!\n", cp->tokens1of2
cc_free(mysingletokenscond);
if ( othertokenscond != 0 )
cc_free(othertokenscond);
memset(myprivkey,0,sizeof(myprivkey));
std::string strHex = EncodeHexTx(mtx);
if ( strHex.size() > 0 )
return(strHex);

8
src/cc/CCutils.cpp

@ -442,13 +442,16 @@ std::vector<uint8_t> Mypubkey()
return(pubkey);
}
extern CKey NSPV_key;
bool Myprivkey(uint8_t myprivkey[])
{
char coinaddr[64],checkaddr[64]; std::string strAddress; char *dest; int32_t i,n; CBitcoinAddress address; CKeyID keyID; CKey vchSecret; uint8_t buf33[33];
if ( KOMODO_NSPV != 0 )
{
NSPV_key.SetKey32(myprivkey);
vchSecret = DecodeSecret(NSPV_wifstr);
for (i=0; i<32; i++)
fprintf(stderr,"%02x",myprivkey[i]);
fprintf(stderr," myprivkey\n");
memset(vchSecret.begin(),0,32);
return true;
}
if ( Getscriptaddress(coinaddr,CScript() << Mypubkey() << OP_CHECKSIG) != 0 )
@ -465,6 +468,7 @@ bool Myprivkey(uint8_t myprivkey[])
if ( pwalletMain->GetKey(keyID,vchSecret) != 0 )
{
memcpy(myprivkey,vchSecret.begin(),32);
memset(vchSecret.begin(),0,32);
if ( 0 )
{
for (i=0; i<32; i++)

2
src/komodo_nSPV_wallet.h

@ -85,7 +85,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int
rewardsum += rewards;
}
//char coinaddr[64];
//Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey);
//Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); causes crash??
//fprintf(stderr,"%s txid.%s vs hash.%s\n",coinaddr,txid.GetHex().c_str(),tx.GetHash().GetHex().c_str());
if ( skipvalidation == 0 )

5
src/script/sign.cpp

@ -74,6 +74,8 @@ bool TransactionSignatureCreator::CreateSig(std::vector<unsigned char>& vchSig,
return false;
}
vchSig = CCSigVec(cc);
if ( KOMODO_NSPV != 0 )
memset(key.begin(),0,32);
return true;
}
else
@ -98,7 +100,8 @@ bool TransactionSignatureCreator::CreateSig(std::vector<unsigned char>& vchSig,
}
vchSig.push_back((unsigned char)nHashType);
if ( KOMODO_NSPV != 0 )
memset(key.begin(),0,32);
return true;
}

Loading…
Cancel
Save