From 886003602724ed4a3ae9ac8058f7013ac770b458 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 28 Jan 2019 22:36:34 -1100 Subject: [PATCH] Autocalc all cclib cp --- src/cc/CCcustom.cpp | 24 ++++++++++++++++++++---- src/wallet/rpcwallet.cpp | 19 +++++++++++++------ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/cc/CCcustom.cpp b/src/cc/CCcustom.cpp index e60ed2997..e00b5a0a0 100644 --- a/src/cc/CCcustom.cpp +++ b/src/cc/CCcustom.cpp @@ -245,13 +245,13 @@ uint8_t CClibCCpriv[32] = { 0x57, 0xcf, 0x49, 0x71, 0x7d, 0xb4, 0x15, 0x1b, 0x4f int32_t CClib_initcp(struct CCcontract_info *cp,uint8_t evalcode) { - CPubKey pk; uint8_t pub33[33],check33[33]; char CCaddr[64],checkaddr[64],str[67]; + CPubKey pk; int32_t i; uint8_t pub33[33],check33[33],hash[32]; char CCaddr[64],checkaddr[64],str[67]; + cp->evalcode = evalcode; + cp->ismyvin = IsCClibInput; + memcpy(cp->CCpriv,CClibCCpriv,32); if ( evalcode == EVAL_FIRSTUSER ) // eventually make a hashchain for each evalcode { - cp->evalcode = evalcode; - cp->ismyvin = IsCClibInput; strcpy(cp->CChexstr,CClibCChexstr); - memcpy(cp->CCpriv,CClibCCpriv,32); decode_hex(pub33,33,cp->CChexstr); pk = buf2pk(pub33); Getscriptaddress(cp->normaladdr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); @@ -267,6 +267,22 @@ int32_t CClib_initcp(struct CCcontract_info *cp,uint8_t evalcode) } else fprintf(stderr,"CClib_initcp mismatched privkey -> addr %s vs %s\n",checkaddr,cp->normaladdr); } } + else + { + for (i=EVAL_FIRSTUSER; iCCpriv,32); + memcpy(cp->CCpriv,hash,32); + } + if ( priv2addr(cp->normaladdr,pub33,cp->CCpriv) != 0 ) + { + pk = buf2pk(pub33); + for (i=0; i<33; i++) + sprintf(&cp->CChexstr[i*2],"%02x",pub33[i]); + cp->CChexstr[i*2] = 0; + GetCCaddress(cp,cp->unspendableCCaddr,pk); + } + } return(-1); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 0ffc370e2..b799c6672 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5327,13 +5327,20 @@ UniValue channelsaddress(const UniValue& params, bool fHelp) UniValue cclibaddress(const UniValue& params, bool fHelp) { struct CCcontract_info *cp,C; std::vector pubkey; - cp = CCinit(&C,EVAL_FIRSTUSER); - if ( fHelp || params.size() > 1 ) - throw runtime_error("cclibaddress [pubkey]\n"); + if ( fHelp || params.size() > 2 ) + throw runtime_error("cclibaddress [evalcode] [pubkey]\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"); - if ( params.size() == 1 ) - pubkey = ParseHex(params[0].get_str().c_str()); + cp = CCinit(&C,EVAL_FIRSTUSER); + if ( params.size() >= 1 ) + { + evalcode = atoi(params[0].get_str().c_str()); + if ( evalcode < EVAL_FIRSTUSER || evalcode > EVAL_LASTUSER ) + throw runtime_error("evalcode not between EVAL_FIRSTUSER and EVAL_LASTUSER\n"); + cp = CCinit(&C,evalcode); + if ( params.size() == 2 ) + pubkey = ParseHex(params[1].get_str().c_str()); + } return(CCaddress(cp,(char *)"CClib",pubkey)); } @@ -7695,4 +7702,4 @@ UniValue test_heirmarker(const UniValue& params, bool fHelp) cp = CCinit(&C, EVAL_HEIR); return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, opret)); -} \ No newline at end of file +}