diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index 236a8652b..79bd31d1c 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -25,6 +25,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds); std::string DiceLoser(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid); +std::string DiceRefund(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid); std::string DiceWinner(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid); std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t forfeitblocks); std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 439ded4ef..e1c3dc1eb 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -576,6 +576,27 @@ std::string DiceLoser(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 b return(0); } +std::string DiceRefund(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid) +{ + CMutableTransaction mtx; uint256 entropy,hentropy; CPubKey mypk,dicepk; CScript opret; uint64_t sbits; struct CCcontract_info *cp,C; uint64_t amount = 0; + if ( amount < 0 ) + { + fprintf(stderr,"negative parameter error\n"); + return(0); + } + if ( (cp= Diceinit(&C,planstr,txfee,mypk,dicepk,sbits)) == 0 ) + return(0); + if ( AddNormalinputs(mtx,mypk,amount+2*txfee,64) > 0 ) + { + hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); + mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,dicepk)); + mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceOpRet('W',sbits,fundingtxid,hentropy))); + } else fprintf(stderr,"cant find enough inputs\n"); + fprintf(stderr,"cant find fundingtxid\n"); + return(0); +} + std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds) { CMutableTransaction mtx; CPubKey mypk,dicepk; CScript opret; uint64_t sbits,entropyval; int64_t funding,minbet,maxbet,maxodds,forfeitblocks; uint256 entropytxid,entropy,hentropy; struct CCcontract_info *cp,C; diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 9e911d210..9790af78b 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -375,6 +375,7 @@ static const CRPCCommand vRPCCommands[] = { "dice", "dicebet", &dicebet, true }, { "dice", "dicewinner", &dicewinner, true }, { "dice", "diceloser", &diceloser, true }, + { "dice", "dicerefund", &dicerefund, true }, { "dice", "diceaddress", &diceaddress, true }, /* tokens */ diff --git a/src/rpcserver.h b/src/rpcserver.h index 4423df345..b7aa32044 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -241,6 +241,7 @@ extern UniValue diceaddfunds(const UniValue& params, bool fHelp); extern UniValue dicebet(const UniValue& params, bool fHelp); extern UniValue dicewinner(const UniValue& params, bool fHelp); extern UniValue diceloser(const UniValue& params, bool fHelp); +extern UniValue dicerefund(const UniValue& params, bool fHelp); extern UniValue lottoaddress(const UniValue& params, bool fHelp); extern UniValue ponziaddress(const UniValue& params, bool fHelp); extern UniValue auctionaddress(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 90d63a83b..629b9409e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5207,6 +5207,25 @@ UniValue diceloser(const UniValue& params, bool fHelp) return(result); } +UniValue dicerefund(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; uint64_t amount; std::string hex; + if ( fHelp || params.size() != 3 ) + throw runtime_error("dicerefund name fundingtxid bettxid\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + name = (char *)params[0].get_str().c_str(); + fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); + bettxid = Parseuint256((char *)params[2].get_str().c_str()); + hex = DiceRefund(0,name,fundingtxid,bettxid); + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else result.push_back(Pair("error", "couldnt create diceloser transaction")); + return(result); +} + UniValue dicelist(const UniValue& params, bool fHelp) { uint256 tokenid;