From 08318626f353c2b0985ef87975de0348ff3ec21d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 4 Mar 2019 01:17:04 -1100 Subject: [PATCH] Handleinfo --- src/cc/cclib.cpp | 4 ++++ src/cc/dilithium.c | 51 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 3a6fba108..651723e44 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -83,6 +83,7 @@ CClib_methods[] = { (char *)"musig", (char *)"spend", (char *)"sendtxid sig scriptPubKey", 3, 3, 'y', EVAL_MUSIG }, { (char *)"dilithium", (char *)"keypair", (char *)"[hexseed]", 0, 1, 'K', EVAL_DILITHIUM }, { (char *)"dilithium", (char *)"register", (char *)"handle, [hexseed]", 1, 2, 'R', EVAL_DILITHIUM }, + { (char *)"dilithium", (char *)"handleinfo", (char *)"handle", 1, 1, 'I', EVAL_DILITHIUM }, { (char *)"dilithium", (char *)"sign", (char *)"msg [hexseed]", 1, 2, 'S', EVAL_DILITHIUM }, { (char *)"dilithium", (char *)"verify", (char *)"pubtxid msg sig", 3, 3, 'V', EVAL_DILITHIUM }, { (char *)"dilithium", (char *)"send", (char *)"handle pubtxid amount", 3, 3, 'x', EVAL_DILITHIUM }, @@ -130,6 +131,7 @@ UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); bool dilithium_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx); UniValue dilithium_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue dilithium_handleinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue dilithium_send(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue dilithium_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue dilithium_keypair(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); @@ -273,6 +275,8 @@ UniValue CClib_method(struct CCcontract_info *cp,char *method,char *jsonstr) return(dilithium_keypair(txfee,cp,params)); else if ( strcmp(method,"register") == 0 ) return(dilithium_register(txfee,cp,params)); + else if ( strcmp(method,"handleinfo") == 0 ) + return(dilithium_handleinfo(txfee,cp,params)); else if ( strcmp(method,"sign") == 0 ) return(dilithium_sign(txfee,cp,params)); else if ( strcmp(method,"verify") == 0 ) diff --git a/src/cc/dilithium.c b/src/cc/dilithium.c index a82113ebc..5f79e2e50 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -2936,22 +2936,30 @@ struct dilithium_handle char handle[32]; } *Dilithium_handles; -struct dilithium_handle *dilithium_handlenew(std::string handle) +struct dilithium_handle *dilithium_handlenew(char *handle) { - struct dilithium_handle *hashstr = 0; - if ( handle.size() < sizeof(Dilithium_handles[0].handle)-1 ) + struct dilithium_handle *hashstr = 0; int32_t len = (int32_t)strlen(handle); + if ( len < sizeof(Dilithium_handles[0].handle)-1 ) { - HASH_FIND(hh,Dilithium_handles,handle.c_str(),(int32_t)handle.size(),hashstr); + HASH_FIND(hh,Dilithium_handles,handle,len,hashstr); if ( hashstr == 0 ) { hashstr = (struct dilithium_handle *)calloc(1,sizeof(*hashstr)); - strncpy(hashstr->handle,handle.c_str(),sizeof(hashstr->handle)); - HASH_ADD_KEYPTR(hh,Dilithium_handles,hashstr->handle,(int32_t)handle.size(),hashstr); + strncpy(hashstr->handle,handle,sizeof(hashstr->handle)); + HASH_ADD_KEYPTR(hh,Dilithium_handles,hashstr->handle,len,hashstr); } } return(hashstr); } +struct dilithium_handle *dilithium_handlefind(char *handle) +{ + struct dilithium_handle *hashstr = 0; int32_t len = (int32_t)strlen(handle); + if ( len < sizeof(Dilithium_handles[0].handle)-1 ) + HASH_FIND(hh,Dilithium_handles,handle,len,hashstr); + return(hashstr); +} + int32_t dilithium_Qmsghash(uint8_t *msg,CTransaction tx,int32_t numvouts,std::vector voutpubtxids) { CScript data; uint256 hash; int32_t i,numvins,len = 0; std::vector vintxids; std::vector vinprevns; std::vector vouts; @@ -3503,6 +3511,33 @@ int32_t dilithium_registrationpub33(CPubKey &pub33,uint256 txid) return(-1); } +UniValue dilithium_handleinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); CPubKey pub33; int32_t i,n; char *handlestr,str[67]; struct dilithium_handle *hashstr; + if ( params != 0 && (n= cJSON_GetArraySize(params)) == 1 ) + { + if ( (handlestr= jstr(jitem(params,0),0)) != 0 ) + { + result.push_back(Pair("result","success")); + result.push_back(Pair("handle",handlestr)); + if ( (hashstr= dilithium_handlefind(handlestr)) != 0 ) + { + result.push_back(Pair("destpubtxid",hashstr->destpubtxid.GetHex().c_str())); + if ( dilithium_registrationpub33(pub33,hashstr->destpubtxid) == 0 ) + { + for (i=0; i<33; i++) + sprintf(&str[i<<1],"%02x",((uint8_t *)pub33.data())[i]); + str[i<<1] = 0; + } + result.push_back(Pair("pubkey",str)); + } else result.push_back(Pair("status","available")); + return(result); + } + } + result.push_back(Pair("result","error")); + return(result); +} + bool dilithium_Rvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { static int32_t didinit; @@ -3522,7 +3557,7 @@ bool dilithium_Rvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,co { if ( dilithium_registeropretdecode(handle,pub33,bigpub,txi.vout[numvouts-1].scriptPubKey) == 'R' ) { - if ( (hashstr= dilithium_handlenew(handle)) != 0 ) + if ( (hashstr= dilithium_handlenew(handle.c_str())) != 0 ) { if ( hashstr->destpubtxid != txid ) { @@ -3551,7 +3586,7 @@ bool dilithium_Rvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,co return eval->Invalid("vout1 for register not txfee"); else if ( tx.vout[2] != vout ) return eval->Invalid("register not sending to faucet"); - else if ( (hashstr= dilithium_handlenew(handle)) == 0 ) + else if ( (hashstr= dilithium_handlenew(handle.c_str())) == 0 ) return eval->Invalid("error creating dilithium handle"); else if ( hashstr->destpubtxid == zeroid ) {