From 2fcf3f3f0f7c05a7fa285b22f90ffab140f1be43 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 5 Feb 2019 21:29:18 -1100 Subject: [PATCH] 1of2 signing --- src/cc/CCinclude.h | 4 ++-- src/cc/CCtx.cpp | 2 +- src/cc/CCutils.cpp | 5 +++-- src/cc/channels.cpp | 2 +- src/cc/heir_validate.h | 7 +++++-- src/cc/marmara.cpp | 4 +++- src/cc/rogue_rpc.cpp | 17 +++++++++++++---- 7 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 52f2d7c1f..bc5ed20ed 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -95,7 +95,7 @@ struct CCcontract_info // this for 1of2 keys coins cryptocondition (for this evalcode) // NOTE: only one evalcode is allowed at this time char coins1of2addr[64]; - CPubKey coins1of2pk[2]; + CPubKey coins1of2pk[2]; uint8_t coins1of2priv[32]; // the same for tokens 1of2 keys cc char tokens1of2addr[64]; @@ -195,7 +195,7 @@ CC *MakeCCcond1of2(uint8_t evalcode,CPubKey pk1,CPubKey pk2); CC* GetCryptoCondition(CScript const& scriptSig); void CCaddr2set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); void CCaddr3set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); -void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); +void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2,uint8_t *priv,char *coinaddr); CTxOut MakeTokensCC1of2vout(uint8_t evalcode, CAmount nValue, CPubKey pk1, CPubKey pk2); CTxOut MakeTokensCC1vout(uint8_t evalcode, CAmount nValue, CPubKey pk); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 630c887f0..932677e20 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -207,7 +207,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran else if (strcmp(cp->coins1of2addr, destaddr) == 0) { //fprintf(stderr,"FinalizeCCTx() matched %s unspendable1of2!\n",cp->coins1of2addr); - privkey = myprivkey; + privkey = cp->coins1of2priv;//myprivkey; if (othercond1of2 == 0) othercond1of2 = MakeCCcond1of2(cp->evalcode, cp->coins1of2pk[0], cp->coins1of2pk[1]); cond = othercond1of2; diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 6dff5d3cd..88231fcd9 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -244,11 +244,12 @@ void CCaddr3set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t * } // set pubkeys, myprivkey and 1of2 cc addr for spending from 1of2 cryptocondition vout: -void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) +void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2,uint8_t *priv,char *coinaddr) { cp->coins1of2pk[0] = pk1; cp->coins1of2pk[1] = pk2; - strcpy(cp->coins1of2addr, coinaddr); + memcpy(cp->coins1of2priv,priv,32); + strcpy(cp->coins1of2addr,coinaddr); } // set pubkeys, myprivkey and 1of2 cc addr for spending from 1of2 tokens cryptocondition vout: diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index e6f4b48c6..ca069ee57 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -455,7 +455,7 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C mtx.vin.push_back(CTxIn(txid,marker,CScript())); Myprivkey(myprivkey); if (tokenid!=zeroid) CCaddrTokens1of2set(cp,srcpub,destpub,coinaddr); - else CCaddr1of2set(cp,srcpub,destpub,coinaddr); + else CCaddr1of2set(cp,srcpub,destpub,myprivkey,coinaddr); return totalinputs; } else return 0; diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 15ab133e4..890e2b710 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -51,8 +51,11 @@ public: cpHeir = CCinit(&heirC, EVAL_HEIR); return GetCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); } - static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { - CCaddr1of2set(cp, ownerPubkey, heirPubkey, coinaddr); + static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) + { + uint8_t mypriv[32]; + Myprivkey(mypriv); + CCaddr1of2set(cp, ownerPubkey, heirPubkey,mypriv, coinaddr); } }; diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8bb306d9b..f43f3a559 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -455,7 +455,9 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) GetCCaddress1of2(cp,coinaddr,Marmarapk,mypk); SetCCunspents(unspentOutputs,coinaddr); threshold = remains / (MARMARA_VINS+1); - CCaddr1of2set(cp,Marmarapk,mypk,coinaddr); + uint8_t mypriv[32]; + Myprivkey(mypriv); + CCaddr1of2set(cp,Marmarapk,mypk,mypriv,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index 0c9b9d70a..9ef8e7814 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -173,10 +173,15 @@ void rogue_univalue(UniValue &result,const char *method,int64_t maxplayers,int64 } } -void rogue_gamefields(UniValue &obj,int64_t maxplayers,int64_t buyin,uint256 txid) +int32_t rogue_iamregistered(CTransaction tx) +{ + return(0); +} + +void rogue_gamefields(UniValue &obj,int64_t maxplayers,int64_t buyin,uint256 gametxid) { CBlockIndex *pindex; int32_t ht; uint256 hashBlock; uint64_t seed; char cmd[512]; CTransaction tx; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (pindex= komodo_blockindex(hashBlock)) != 0 ) + if ( GetTransaction(gametxid,tx,hashBlock,false) != 0 && (pindex= komodo_blockindex(hashBlock)) != 0 ) { ht = pindex->GetHeight(); obj.push_back(Pair("height",ht)); @@ -190,7 +195,9 @@ void rogue_gamefields(UniValue &obj,int64_t maxplayers,int64_t buyin,uint256 txi memcpy(&seed,&hashBlock,sizeof(seed)); seed &= (1LL << 62) - 1; obj.push_back(Pair("seed",(int64_t)seed)); - sprintf(cmd,"./rogue %llu gui",(long long)seed); + if ( rogue_iamregistered(tx) > 0 ) + sprintf(cmd,"./rogue %llu gui",(long long)seed); + else sprintf(cmd,"./komodo-cli -ac_name=%s cclib register \\\"[%22%s%22]\\\" %d",ASSETCHAINS_SYMBOL,gametxid.ToString().c_str(),EVAL_ROGUE); obj.push_back(Pair("run",cmd)); } } @@ -470,7 +477,7 @@ UniValue rogue_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) // vin3+ -> buyin // vout0 -> keystrokes/completion baton CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); uint256 gametxid,origplayergame,playertxid,hashBlock; int32_t maxplayers,n,numvouts; int64_t inputsum,buyin,CCchange=0; CPubKey pk,mypk,roguepk; CTransaction tx; std::vector playerdata; std::string rawtx; bits256 t; + UniValue result(UniValue::VOBJ); char destaddr[64]; uint256 gametxid,origplayergame,playertxid,hashBlock; int32_t maxplayers,n,numvouts; int64_t inputsum,buyin,CCchange=0; CPubKey pk,mypk,roguepk; CTransaction tx; std::vector playerdata; std::string rawtx; bits256 t; if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); @@ -498,6 +505,8 @@ UniValue rogue_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) else if ( buyin > 0 && AddNormalinputs(mtx,mypk,buyin,64) < buyin ) return(cclib_error(result,"couldnt find enough normal funds for buyin")); mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,inputsum-txfee,roguepk,mypk)); + GetCCaddress1of2(cp,destaddr,roguepk,roguepk); + CCaddr1of2set(cp,roguepk,roguepk,cp->CCpriv,destaddr); rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,rogue_registeropret(gametxid,playertxid)); return(rogue_rawtxresult(result,rawtx,0)); } else return(cclib_error(result,"invalid gametxid"));