Merge pull request #43 from jl777/jl777

Jl777
This commit is contained in:
blackjok3rtt
2019-03-25 19:52:46 +08:00
committed by GitHub
4 changed files with 68 additions and 13 deletions

View File

@@ -45,6 +45,16 @@ uint8_t games_opretdecode(CPubKey &pk,CScript scriptPubKey)
return(0);
}
uint8_t games_eventdecode(CPubKey &pk,std::vector<uint8_t> &sig,std::vector<uint8_t> &payload,std::vector<uint8_t> message)
{
uint8_t e,f;
if ( message.size() > 2 && E_UNMARSHAL(message,ss >> e; ss >> f; ss >> pk; ss >> sig; ss >> payload) != 0 && e == EVAL_GAMES )
{
return(f);
}
return(0);
}
UniValue games_rawtxresult(UniValue &result,std::string rawtx,int32_t broadcastflag)
{
CTransaction tx;
@@ -154,15 +164,49 @@ UniValue games_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
return(result);
}
int32_t games_eventsign(std::vector<uint8_t> &sig,std::vector<uint8_t> payload,CPubKey pk)
{
bool signSuccess; SignatureData sigdata; int32_t i,siglen; uint256 hash; uint8_t *ptr; auto consensusBranchId = 0; CMutableTransaction txNew;
const CKeyStore& keystore = *pwalletMain;
txNew.vin.resize(1);
txNew.vout.resize(1);
txNew.vin[0].prevout.hash = payload.GetHash();
txNew.vin[0].prevout.n = 0;
txNew.vout[0].scriptPubKey = CScript() << payload << OP_DROP << ParseHex(HexStr(pk)) << OP_CHECKSIG;
txNew.vout[0].nValue = payload.size();
txNew.nLockTime = 0;
CTransaction txNewConst(txNew);
signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, payload.size(), SIGHASH_ALL), txNew.vout[0].scriptPubKey, sigdata, consensusBranchId);
if ( signSuccess > 0 )
{
UpdateTransaction(txNew,0,sigdata);
ptr = (uint8_t *)&sigdata.scriptSig[0];
siglen = sigdata.scriptSig.size();
sig.resize(siglen);
for (i=0; i<siglen; i++)
sig[i] = ptr[i];
return(0);
} else return(-1);
}
UniValue games_events(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
{
UniValue result(UniValue::VOBJ); std::vector<uint8_t> payload; int32_t n;
UniValue result(UniValue::VOBJ); std::vector<uint8_t> sig,payload; int32_t n; CPubKey mypk; uint256 hash;
if ( params != 0 && (n= cJSON_GetArraySize(params)) == 1 )
{
if ( payments_parsehexdata(payload,jitem(params,0),0) == 0 )
{
komodo_sendmessage(4,8,"events",payload);
result.push_back(Pair("result","success"));
mypk = pubkey2pk(Mypubkey());
if ( games_eventsign(sig,payload,mypk) == 0 )
{
komodo_sendmessage(4,8,"events",E_MARSHAL(ss << EVAL_GAMES << 'E' << mypk << sig << payload));
result.push_back(Pair("result","success"));
}
else
{
result.push_back(Pair("result","error"));
result.push_back(Pair("error","signing ereror"));
}
}
else
{
@@ -178,12 +222,21 @@ UniValue games_events(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
return(result);
}
void komodo_netevent(std::vector<uint8_t> payload)
void komodo_netevent(std::vector<uint8_t> message)
{
int32_t i;
for (i=0; i<payload.size(); i++)
fprintf(stderr,"%02x",payload[i]);
fprintf(stderr," got event[%d]\n",(int32_t)payload.size());
int32_t i; CPubKey pk; std::vector<uint8_t> sig,payload; char str[67];
if ( games_eventdecode(pk,sig,payload,message) == 'E' )
{
for (i=0; i<payload.size(); i++)
fprintf(stderr,"%02x",payload[i]);
fprintf(stderr," payload, got pk.%s siglen.%d\n",pubkey_str(str,pk),(int32_t)sig.size());
}
else
{
for (i=0; i<payload.size(); i++)
fprintf(stderr,"%02x",payload[i]);
fprintf(stderr," got RAW message[%d]\n",(int32_t)payload.size());
}
}
bool games_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx)

View File

@@ -1,3 +1,5 @@
#define ENABLE_WALLET
#include "CCinclude.h"
std::string MYCCLIBNAME = (char *)"gamescc";

View File

@@ -569,7 +569,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr)
UniValue PaymentsFund(struct CCcontract_info *cp,char *jsonstr)
{
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); UniValue result(UniValue::VOBJ);
CPubKey Paymentspk,mypk,txidpk; uint256 txid,hashBlock; int64_t amount; CScript opret; CTransaction tx; char txidaddr[64]; std::string rawtx; int32_t n,useopret = 0,lockedblocks,minrelease,totalallocations; std::vector<uint256> txidoprets;
CPubKey Paymentspk,mypk,txidpk; uint256 txid,hashBlock; int64_t amount,totalallocations; CScript opret; CTransaction tx; char txidaddr[64]; std::string rawtx; int32_t n,useopret = 0,lockedblocks,minrelease; std::vector<uint256> txidoprets;
cJSON *params = payments_reparse(&n,jsonstr);
mypk = pubkey2pk(Mypubkey());
Paymentspk = GetUnspendable(cp,0);
@@ -662,7 +662,7 @@ UniValue PaymentsTxidopret(struct CCcontract_info *cp,char *jsonstr)
UniValue PaymentsCreate(struct CCcontract_info *cp,char *jsonstr)
{
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
UniValue result(UniValue::VOBJ); CTransaction tx; CPubKey Paymentspk,mypk; char markeraddr[64]; std::vector<uint256> txidoprets; uint256 hashBlock; int32_t i,n,numoprets=0,lockedblocks,minrelease,totalallocations=0; std::string rawtx;
UniValue result(UniValue::VOBJ); CTransaction tx; CPubKey Paymentspk,mypk; char markeraddr[64]; std::vector<uint256> txidoprets; uint256 hashBlock; int32_t i,n,numoprets=0,lockedblocks,minrelease; std::string rawtx; int64_t totalallocations = 0;
cJSON *params = payments_reparse(&n,jsonstr);
if ( params != 0 && n >= 4 )
{
@@ -680,7 +680,7 @@ UniValue PaymentsCreate(struct CCcontract_info *cp,char *jsonstr)
txidoprets.push_back(payments_juint256(jitem(params,2+i)));
for (i=0; i<txidoprets.size(); i++)
{
std::vector<uint8_t> scriptPubKey,opret; int32_t allocation;
std::vector<uint8_t> scriptPubKey,opret; int64_t allocation;
if ( myGetTransaction(txidoprets[i],tx,hashBlock) != 0 && tx.vout.size() > 1 && DecodePaymentsTxidOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,allocation,scriptPubKey,opret) == 'T' )
{
totalallocations += allocation;
@@ -732,7 +732,7 @@ UniValue PaymentsCreate(struct CCcontract_info *cp,char *jsonstr)
UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr)
{
UniValue result(UniValue::VOBJ),a(UniValue::VARR); CTransaction tx,txO; CPubKey Paymentspk,txidpk; int32_t i,j,n,flag=0,allocation,numoprets=0,lockedblocks,minrelease,totalallocations; std::vector<uint256> txidoprets; int64_t funds,fundsopret; char fundsaddr[64],fundsopretaddr[64],txidaddr[64],*outstr; uint256 createtxid,hashBlock;
UniValue result(UniValue::VOBJ),a(UniValue::VARR); CTransaction tx,txO; CPubKey Paymentspk,txidpk; int32_t i,j,n,flag=0,numoprets=0,lockedblocks,minrelease; std::vector<uint256> txidoprets; int64_t funds,fundsopret,totalallocations=0,allocation; char fundsaddr[64],fundsopretaddr[64],txidaddr[64],*outstr; uint256 createtxid,hashBlock;
cJSON *params = payments_reparse(&n,jsonstr);
if ( params != 0 && n == 1 )
{

View File

@@ -2079,7 +2079,7 @@ void komodo_args(char *argv0)
while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 )
{
fprintf(stderr,"waiting for datadir\n");
fprintf(stderr,"waiting for datadir (%s)\n",dirname);
#ifndef _WIN32
sleep(3);
#else