From 54690bb04e8bfdc1e26cbe5f4aa086468db8212c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 29 Aug 2018 01:17:57 -1100 Subject: [PATCH] Channelsinfo stub --- src/cc/channels.cpp | 29 ++++++++++++++++++++--------- src/rpcserver.cpp | 1 + src/rpcserver.h | 1 + src/wallet/rpcwallet.cpp | 13 ++++++++++--- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index fef4553d9..1f82bcc55 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -43,6 +43,21 @@ Also, in order to be able to track open channels, a tag is needed to be sent and better to send to a normal CC address for a pubkey to isolate the transactions for channel opens. +Possible third iteration: + Let us try to setup a single "hot wallet" address to have all the channel funds and use it for payments to any destination. If there are no problems with reorgs and double spends, this would allow everyone to be "connected" to everyone else via the single special address. + + So funds -> user's CC address along with hashchain, but likely best to have several utxo to span order of magnitudes. + + a micropayment would then spend a utxo and attach a shared secret encoded unhashed link from the hashchain. That makes the receiver the only one that can decode the actual hashchain's prior value. + + however, since this spend is only spendable by the sender, it is subject to a double spend attack. It seems it is a dead end. Alternative is to use the global CC address, but that commingles all funds from all users and any accounting error puts all funds at risk. + + So, back to the second iteration, which is the only one so far that is immune from doublespend attack as the funds are already in the destination's CC address. One complication is that due to CC sorting of pubkeys, the address for sending and receiving is the same, so the destination pubkey needs to be attached to each opreturn. + + Now when the prior hashchain value is sent via payment, it allows the receiver to spend the utxo, so the only protection needed is to prevent channel close from invalidating already made payments. + + In order to allow multiple payments included in a single transaction, presentation of the N prior hashchain value can be used to get N payments and all the spends create a spending chain in sequential order of the hashchain. + */ // start of consensus code @@ -137,10 +152,10 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & // helper functions for rpc calls in rpcwallet.cpp -CScript EncodeChannelsOpRet(uint8_t funcid,int32_t numpayments,int32_t payment,uint256 hashchain) +CScript EncodeChannelsOpRet(CPubKey destpub,uint8_t funcid,int32_t numpayments,int32_t payment,uint256 hashchain) { CScript opret; uint8_t evalcode = EVAL_CHANNELS; - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << numpayments << payment << hashchain); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << destpub << numpayments << payment << hashchain); return(opret); } @@ -198,22 +213,18 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 endiancpy((uint8_t *)&hashchain,hashdest,32); mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS,funds,mypk,destpub)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('O',numpayments,payment,hashchain))); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('O',destpub,numpayments,payment,hashchain))); } return(""); } UniValue ChannelsInfo() { - UniValue result(UniValue::VOBJ); char numstr[64]; - CMutableTransaction mtx; CPubKey Channelspk; struct CCcontract_info *cp,C; int64_t funding; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; char myCCaddr[64]; result.push_back(Pair("result","success")); result.push_back(Pair("name","Channels")); cp = CCinit(&C,EVAL_CHANNELS); - Channelspk = GetUnspendable(cp,0); - funding = AddChannelsInputs(cp,mtx,Channelspk,0,0); - sprintf(numstr,"%.8f",(double)funding/COIN); - result.push_back(Pair("funding",numstr)); + // set myCCaddr, scan all tagged funding tx, display send vs recv return(result); } diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index cdff9aa86..eb6aa9b34 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -376,6 +376,7 @@ static const CRPCCommand vRPCCommands[] = /* Channels */ { "channels", "channelsaddress", &channelsaddress, true }, + { "channels", "channelsinfo", &channelsinfo, true }, { "channels", "channelsopen", &channelsopen, true }, /* Oracles */ diff --git a/src/rpcserver.h b/src/rpcserver.h index ff2a8e4e0..0f3744681 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -229,6 +229,7 @@ extern UniValue pegsaddress(const UniValue& params, bool fHelp); extern UniValue triggersaddress(const UniValue& params, bool fHelp); extern UniValue paymentsaddress(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); +extern UniValue channelsinfo(const UniValue& params, bool fHelp); extern UniValue channelsopen(const UniValue& params, bool fHelp); //extern UniValue tokenswapask(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c05f01d1a..945c30dea 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4897,9 +4897,7 @@ UniValue channelsaddress(const UniValue& params, bool fHelp) result = CCaddress(cp,(char *)"Channels",destpubkey); result.push_back(Pair("otherpubkey", params[0].get_str())); GetCCaddress1of2(cp,destaddr,pk,pk2); - result.push_back(Pair("sendaddr",destaddr)); - GetCCaddress1of2(cp,destaddr,pk2,pk); - result.push_back(Pair("recvaddr",destaddr)); + result.push_back(Pair("channeladdress",destaddr)); return(result); } @@ -5087,6 +5085,15 @@ UniValue tokenaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Assets",pubkey)); } +UniValue channelsinfo(const UniValue& params, bool fHelp) +{ + if ( fHelp || params.size() != 0 ) + throw runtime_error("channelsinfo\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"); + return(ChannelsInfo()); +} + UniValue channelsopen(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); char destaddr[64]; int32_t numpayments; int64_t payment; std::vector destpub; struct CCcontract_info *cp,C; std::string hex;