From 6620e4cec288090746a3f2aa206bb25d54b36d96 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 04:04:00 -1100 Subject: [PATCH] marmara_settlement skeleton --- src/cc/CCMarmara.h | 1 + src/cc/marmara.cpp | 73 ++++++++++++++++++++++++++++------------ src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 15 +++++++++ 5 files changed, 70 insertions(+), 21 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 1d61a86d4..753f8edb6 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -28,6 +28,7 @@ uint64_t komodo_block_prg(uint32_t nHeight); int32_t MarmaraGetcreatetxid(uint256 &createtxid,uint256 txid); int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid,uint256 txid); UniValue MarmaraCreditloop(uint256 txid); +UniValue MarmaraSettlement(uint64_t txfee,uint256 batontxid); 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); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 1e16532d4..ff4d0dc32 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -479,34 +479,65 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a return(result); } -// get creditloop pubkeys - -/*UniValue Marmara(uint64_t txfee,uint256 batontxid) +UniValue MarmaraSettlement(uint64_t txfee,uint256 batontxid) { - UniValue result(UniValue::VOBJ); int64_t avail,amount,paid=0; int32_t i,n = 0; uint256 txid,*revcreditloop=0; CPubKey Marmarapk; struct CCcontract_info *cp,C; - result.push_back(Pair("result","success")); + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey senderpk,pk; std::string currency,refcurrency; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); - Marmarapk = GetUnspendable(cp,0); - txid = batontxid; - while ( txid.hasprev() != 0 ) + if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) { - txid = txid.prev(); - // check for unique, else error - revcreditloop[n++] = txid; - } - for (i=0; i= amount ) + if ( GetTransaction(batontxid,batontx,hashBlock,false) != 0 && (numvouts= batontx.vout.size()) > 1 ) { - change = (amount - paid); - break; + if ( (funcid= MarmaraDecodeLoopOpret(batontx.vout[numvouts-1].scriptPubKey,refcreatetxid,pk,refamount,refmatures,refcurrency)) != 0 ) + { + if ( refcreatetxid != creditloop[0] ) + { + fprintf(stderr,"invalid refcreatetxid, setting to creditloop[0]\n"); + refcreatetxid = creditloop[0]; + numerrs++; + } + GetCCaddress(cp,myCCaddr,Mypubkey()); + Getscriptaddress(batonCCaddr,batontx.vout[0].scriptPubKey); + if ( strcmp(myCCaddr,batonCCaddr) == 0 ) + { + for (i=0; i 1 ) + { + if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,pk,amount,matures,currency)) != 0 ) + { + GetCCaddress(cp,coinaddr,pk); + fprintf(stderr,"get locked funds of %s %.8f\n",coinaddr,(double)CCaddress_balance(coinaddr)/COIN); + } + } + } + } + else + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"this node does not have the baton")); + result.push_back(Pair("myCCaddr",myCCaddr)); + result.push_back(Pair("batonCCaddr",batonCCaddr)); + } + } + else + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"couldnt get batontxid opret")); + } + } + else + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"couldnt find batontxid")); } } - + else + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"couldnt get creditloop")); + } return(result); -}*/ +} UniValue MarmaraCreditloop(uint256 txid) { diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index c8e2c4113..94403bcc0 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -449,6 +449,7 @@ static const CRPCCommand vRPCCommands[] = { "marmara", "marmaratransfer", &marmara_transfer, true }, { "marmara", "marmarainfo", &marmara_info, true }, { "marmara", "marmaracreditloop", &marmara_creditloop, true }, + { "marmara", "marmarasettlement", &marmara_settlement, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 1bc6bd582..920aac970 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -278,6 +278,7 @@ extern UniValue marmara_issue(const UniValue& params, bool fHelp); 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 paymentsaddress(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); extern UniValue gatewayslist(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 81b692dc0..b9186f5c7 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5668,6 +5668,21 @@ UniValue marmara_creditloop(const UniValue& params, bool fHelp) return(result); } +UniValue marmara_settlement(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); uint256 batontxid; + if ( fHelp || params.size() != 1 ) + { + // marmaracreditloop cc23bf81733556dc06db2fd9c9f4178cad44bdc237d6e62101cf0cdafb5195f7 + throw runtime_error("marmarasettlement batontxid\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"); + batontxid = Parseuint256((char *)params[0].get_str().c_str()); + result = MarmaraSettlement(batontxid); + return(result); +} + UniValue channelslist(const UniValue& params, bool fHelp) { if ( fHelp || params.size() > 0 )