Marmaralock

This commit is contained in:
jl777
2019-01-17 22:46:56 -11:00
parent 81c866f1e8
commit e555995f19
5 changed files with 54 additions and 6 deletions

View File

@@ -31,6 +31,7 @@ int32_t MarmaraGetcreatetxid(uint256 &createtxid,uint256 txid);
int32_t MarmaraGetbatontxid(std::vector<uint256> &creditloop,uint256 &batontxid,uint256 txid);
UniValue MarmaraCreditloop(uint256 txid);
UniValue MarmaraSettlement(uint64_t txfee,uint256 batontxid);
UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height);
UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...]
UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid,bool automaticflag);

View File

@@ -395,6 +395,41 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector<CPubKey> &pubkeys,
return(totalinputs);
}
UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height)
{
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk; int64_t inputsum,change = 0; std::string rawtx,errorstr;
// scan all unlocked
// total capped at amount, change -> unlocked, if no change then scan all locked 'C' and 'P' for unlockht < refunlockht
if ( txfee == 0 )
txfee = 10000;
cp = CCinit(&C,EVAL_MARMARA);
mypk = pubkey2pk(Mypubkey());
Marmarapk = GetUnspendable(cp,0);
if ( (inputsum= AddNormalinputs(mtx,mypk,amount + txfee,1)) > 0 )
{
if ( inputsum > amount+txfee )
{
change = (inputsum - amount);
mtx.vout.push_back(CTxOut(change,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
}
rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraCoinbaseOpret('L',height,mypk));
if ( rawtx.size() == 0 )
errorstr = (char *)"couldnt finalize CCtx";
else
{
result.push_back(Pair("result",(char *)"success"));
result.push_back(Pair("rawtx",rawtx));
return(result);
}
}
result.push_back(Pair("result",(char *)"error"));
result.push_back(Pair("error",errorstr));
return(result);
}
// decide on what unlockht settlement change should have
UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid)
{
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
@@ -459,7 +494,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid)
mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
if ( change > txfee )
mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,change,Marmarapk,pk));
rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,0,height,currency),pubkeys);
rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,0,unlockht,currency),pubkeys);
result.push_back(Pair("result",(char *)"success"));
result.push_back(Pair("rawtx",rawtx));
return(result);
@@ -474,7 +509,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid)
mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,createtxid))) << OP_CHECKSIG)); // failure marker
if ( refamount-remaining > 3*txfee )
mtx.vout.push_back(CTxOut(refamount-remaining-2*txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,-remaining,height,currency),pubkeys);
rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,-remaining,unlockht,currency),pubkeys);
result.push_back(Pair("result",(char *)"error"));
result.push_back(Pair("error",(char *)"insufficient funds"));
result.push_back(Pair("rawtx",rawtx));
@@ -902,10 +937,6 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *
return(result);
}
// MarmaraLock(uint64_t txfee,int64_t amount,int32_t refunlockht)
// scan all unlocked
// total capped at amount, change -> unlocked, if no change then scan all locked 'C' and 'P' for unlockht < refunlockht
// get all tx, constrain by vout, issuances[] and closed[]
UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency)

View File

@@ -458,6 +458,7 @@ static const CRPCCommand vRPCCommands[] =
{ "marmara", "marmarainfo", &marmara_info, true },
{ "marmara", "marmaracreditloop", &marmara_creditloop, true },
{ "marmara", "marmarasettlement", &marmara_settlement, true },
{ "marmara", "marmaralock", &marmara_lock, true },
// Payments
{ "payments", "paymentsaddress", &paymentsaddress, true },

View File

@@ -285,6 +285,7 @@ extern UniValue marmara_transfer(const UniValue& params, bool fHelp);
extern UniValue marmara_info(const UniValue& params, bool fHelp);
extern UniValue marmara_creditloop(const UniValue& params, bool fHelp);
extern UniValue marmara_settlement(const UniValue& params, bool fHelp);
extern UniValue marmara_lock(const UniValue& params, bool fHelp);
extern UniValue paymentsaddress(const UniValue& params, bool fHelp);
extern UniValue gatewaysaddress(const UniValue& params, bool fHelp);
extern UniValue gatewayslist(const UniValue& params, bool fHelp);

View File

@@ -5692,6 +5692,20 @@ UniValue marmara_settlement(const UniValue& params, bool fHelp)
return(result);
}
UniValue marmara_lock(const UniValue& params, bool fHelp)
{
UniValue result(UniValue::VOBJ); int64_t amount; int32_t height;
if ( fHelp || params.size() > 2 || params.size() == 0 )
{
throw runtime_error("marmaralock amount unlockht\n");
}
amount = atof(params[0].get_str().c_str()) * COIN + 0.00000000499999;
if ( params.size() == 2 )
height = atol(params[1].get_str().c_str());
else height = chainActive.LastTip()->GetHeight() + 1;
return(MarmaraLock(0,amount,height));
}
UniValue channelslist(const UniValue& params, bool fHelp)
{
if ( fHelp || params.size() > 0 )