Browse Source

1of2 signing

pull/4/head
jl777 5 years ago
parent
commit
2fcf3f3f0f
  1. 4
      src/cc/CCinclude.h
  2. 2
      src/cc/CCtx.cpp
  3. 5
      src/cc/CCutils.cpp
  4. 2
      src/cc/channels.cpp
  5. 7
      src/cc/heir_validate.h
  6. 4
      src/cc/marmara.cpp
  7. 17
      src/cc/rogue_rpc.cpp

4
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);

2
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;

5
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:

2
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;

7
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);
}
};

4
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<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
{
txid = it->first.txhash;

17
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<uint8_t> 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<uint8_t> 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"));

Loading…
Cancel
Save