char *SuperNET_gotpacket(char *msg,int32_t duration,char *ip_port) { static int flood,duplicates; cJSON *json; uint16_t p2pport; struct pserver_info *pserver; uint64_t txid; struct sockaddr prevaddr; int32_t len,createdflag,valid; unsigned char packet[2*MAX_JSON_FIELD]; char ipaddr[64],txidstr[64],retjsonstr[2*MAX_JSON_FIELD],verifiedNXTaddr[64],*cmdstr,*retstr; if ( SUPERNET_PORT != _SUPERNET_PORT ) return(clonestr("{\"error\":private SuperNET}")); strcpy(retjsonstr,"{\"result\":null}"); if ( Debuglevel > 2 ) printf("gotpacket.(%s) duration.%d from (%s)\n",msg,duration,ip_port); if ( Finished_loading == 0 ) { if ( is_hexstr(msg) == 0 ) { //printf("QUEUE.(%s)\n",msg); return(block_on_SuperNET(0,msg)); } return(clonestr(retjsonstr)); } p2pport = parse_ipaddr(ipaddr,ip_port); uv_ip4_addr(ipaddr,0,(struct sockaddr_in *)&prevaddr); pserver = get_pserver(0,ipaddr,0,p2pport); len = (int32_t)strlen(msg); if ( is_hexstr(msg) != 0 ) { len >>= 1; len = decode_hex(packet,len,msg); txid = calc_txid(packet,len);//hash,sizeof(hash)); sprintf(txidstr,"%llu",(long long)txid); MTadd_hashtable(&createdflag,&Global_pNXT->msg_txids,txidstr); if ( createdflag == 0 ) { duplicates++; return(clonestr("{\"error\":\"duplicate msg\"}")); } if ( (len<<1) == 30 ) // hack against flood flood++; if ( Debuglevel > 0 ) printf("gotpacket %d | Finished_loading.%d | flood.%d duplicates.%d\n",duration,Finished_loading,flood,duplicates); if ( is_encrypted_packet(packet,len) != 0 ) process_packet(0,retjsonstr,packet,len,0,&prevaddr,ipaddr,0); /*else if ( (obookid= is_orderbook_tx(packet,len)) != 0 ) { if ( update_orderbook_tx(1,obookid,(struct orderbook_tx *)packet,txid) == 0 ) { ((struct orderbook_tx *)packet)->txid = txid; sprintf(retjsonstr,"{\"result\":\"SuperNET_gotpacket got obbokid.%llu packet txid.%llu\"}",(long long)obookid,(long long)txid); } else sprintf(retjsonstr,"{\"result\":\"SuperNET_gotpacket error updating obookid.%llu\"}",(long long)obookid); }*/ else sprintf(retjsonstr,"{\"error\":\"SuperNET_gotpacket cant find obookid\"}"); }
uint8_t is_macaddr(uint8_t * macstr, uint8_t * digitstr, uint8_t * mac) { uint8_t tmp_mac[6]; uint8_t tmp_hexstr[4]; uint8_t i = 0; uint8_t len = strlen((char *)macstr); if(macstr[0] == 0 || len != 17) return 0; for( i = 0; i < 6; i++) { memcpy(tmp_hexstr, macstr+i*3, 3); if(tmp_hexstr[2] == 0 || strchr((char *)digitstr, tmp_hexstr[2])) { tmp_hexstr[2] = 0; if(is_hexstr(tmp_hexstr)) { //sscanf(tmp_hexstr,"%x", &tmp_mac[i]); str_to_hex(tmp_hexstr, &tmp_mac[i]); } else return 0; } else return 0; } memcpy(mac, tmp_mac, sizeof(tmp_mac)); return 1; }
char *SuperNET_parsemainargs(struct supernet_info *myinfo,bits256 *wallethashp,bits256 *wallet2privp,char *argjsonstr) { cJSON *exchanges=0,*json = 0; char *wallet2fname,*coinargs=0,*secret,*filestr; long allocsize; bits256 wallethash,wallet2priv; int32_t n,len; uint8_t secretbuf[8192]; wallethash = wallet2priv = GENESIS_PRIVKEY; if ( argjsonstr != 0 ) { if ( (filestr= OS_filestr(&allocsize,argjsonstr)) != 0 ) { json = cJSON_Parse(filestr); free(filestr); } if ( json != 0 || (json= cJSON_Parse(argjsonstr)) != 0 ) { printf("ARGSTR.(%s)\n",argjsonstr); if ( jobj(json,"numhelpers") != 0 ) IGUANA_NUMHELPERS = juint(json,"numhelpers"); if ( (secret= jstr(json,"passphrase")) != 0 ) { len = (int32_t)strlen(secret); if ( is_hexstr(secret,0) != 0 && len == 128 ) { len >>= 1; decode_hex(secretbuf,len,secret); } else vcalc_sha256(0,secretbuf,(void *)secret,len), len = sizeof(bits256);
uint8_t *get_dataptr(int32_t hdroffset,uint8_t **ptrp,int32_t *datalenp,uint8_t *space,int32_t spacesize,char *hexstr) { *ptrp = 0; uint8_t *data = 0; if ( hexstr != 0 && (*datalenp= is_hexstr(hexstr,0)) > 0 ) { *datalenp >>= 1; if ( (*datalenp+hdroffset) <= spacesize ) { memset(space,0,hdroffset); data = &space[hdroffset]; } else *ptrp = data = calloc(1,*datalenp + hdroffset); decode_hex(&data[hdroffset],*datalenp,hexstr); }
int32_t basilisk_message_returned(uint8_t *data,int32_t maxlen,cJSON *item) { char *hexstr=0; cJSON *msgobj; int32_t datalen=0,retval = -1; if ( (msgobj= jobj(item,"message")) != 0 ) { if ( (hexstr= jstr(msgobj,"data")) != 0 && (datalen= is_hexstr(hexstr,0)) > 0 ) { datalen >>= 1; if ( datalen < maxlen ) { decode_hex(data,datalen,hexstr); printf("decoded hexstr.[%d]\n",datalen); retval = datalen; } else printf("datalen.%d < maxlen.%d\n",datalen,maxlen); } else printf("no hexstr.%p or datalen.%d\n",hexstr,datalen);
int main(int argc, char *argv[]) { char *from, *to, *what; const struct format *input_format, *output_format; struct tag tag; char output[OUTPUT_MAX_LEN + 1]; default_cust_id = DEFAULT_CUST_ID; if (argc != 4 && argc != 5) { usage(argv[0]); return (EXIT_FAILURE); } from = argv[1]; to = argv[2]; what = argv[3]; // optional cust_id argument if (argc == 5) { if (!is_hexstr(argv[4])) die("%s: cust_id is expected to be a hex byte\n", argv[0]); default_cust_id = strtol(argv[4], NULL, 16); if (default_cust_id < 0 || default_cust_id > 255) die("%s: cust_id must be non-negative and less than 255\n", argv[0]); } if ((input_format = select_format(from)) == NULL) die("%s: unknown input format: %s.\n", argv[0], from); if ((output_format = select_format(to)) == NULL) die("%s: unknown output format: %s.\n", argv[0], to); if (input_format->from(what, &tag) != 0) die("%s: error when parsing RFID of format %s.\n", argv[0], input_format->keyword); if (output_format->to(&tag, output) != 0) die("%s: error when converting RFID to format %s.\n", argv[0], output_format->keyword); printf("%s\n", output); return (EXIT_SUCCESS); }
char *_sign_and_sendmoney(char *cointxid,struct ramchain_info *ram,struct cointx_info *cointx,char *othersignedtx,uint64_t *redeems,uint64_t *amounts,int32_t numredeems) { uint64_t get_sender(uint64_t *amountp,char *txidstr); void *extract_jsonkey(cJSON *item,void *arg,void *arg2); void set_MGW_moneysentfname(char *fname,char *NXTaddr); int32_t jsonstrcmp(void *ref,void *item); char txidstr[64],NXTaddr[64],jsonstr[4096],*retstr = 0; int32_t i; uint64_t amount,senderbits,redeemtxid; fprintf(stderr,"achieved consensus and sign! (%s)\n",othersignedtx); if ( (retstr= _submit_withdraw(ram,cointx,othersignedtx)) != 0 ) { if ( is_hexstr(retstr) != 0 ) { strcpy(cointxid,retstr); //*AMtxidp = _broadcast_moneysentAM(ram,height); for (i=0; i<numredeems; i++) { if ( (redeemtxid = redeems[i]) != 0 && amounts[i] != 0 ) { printf("signed and sent.%d: %llu %.8f\n",i,(long long)redeemtxid,dstr(amounts[i])); _ram_update_redeembits(ram,redeemtxid,0,cointxid,0); expand_nxt64bits(txidstr,redeemtxid); senderbits = get_sender(&amount,txidstr); expand_nxt64bits(NXTaddr,senderbits); sprintf(jsonstr,"{\"NXT\":\"%s\",\"redeemtxid\":\"%llu\",\"amount\":\"%.8f\",\"coin\":\"%s\",\"cointxid\":\"%s\",\"vout\":\"%d\"}",NXTaddr,(long long)redeemtxid,dstr(amounts[i]),ram->name,txidstr,i); update_MGW_jsonfile(set_MGW_moneysentfname,extract_jsonkey,jsonstrcmp,0,jsonstr,"redeemtxid",0); update_MGW_jsonfile(set_MGW_moneysentfname,extract_jsonkey,jsonstrcmp,NXTaddr,jsonstr,"redeemtxid",0); } } //backupwallet(cp,ram->coinid); } else { for (i=0; i<numredeems; i++) printf("(%llu %.8f) ",(long long)redeems[i],dstr(amounts[i])); printf("_sign_and_sendmoney: unexpected return.(%s)\n",retstr); exit(1); } return(retstr); } else printf("sign_and_sendmoney: error sending rawtransaction %s\n",othersignedtx); return(0); }
void SuperNET_hexmsgprocess(struct supernet_info *myinfo,cJSON *retjson,cJSON *json,char *hexmsg,char *remoteaddr) { int32_t len,flag=0; char *str; uint8_t _buf[8192],*buf = _buf; bits256 categoryhash,subhash; struct private_chain *cat; if ( hexmsg != 0 ) { len = (int32_t)strlen(hexmsg); if ( is_hexstr(hexmsg,len) > 0 ) { len >>= 1; if ( len > sizeof(_buf) ) buf = malloc(len); decode_hex(buf,len,hexmsg); //printf("hex.(%s) -> (%s)\n",hexmsg,buf); categoryhash = jbits256(json,"categoryhash"); subhash = jbits256(json,"categoryhash"); if ( bits256_nonz(subhash) == 0 ) subhash = GENESIS_PUBKEY; if ( (cat= category_find(categoryhash,subhash)) != 0 ) { if ( cat->processfunc != 0 ) { if ( (str= (*cat->processfunc)(myinfo,cat,buf,len,remoteaddr)) != 0 ) { if ( retjson != 0 ) jaddstr(retjson,"processfunc",str); else free(str); } flag = 1; //printf("PROCESSFUNC\n"); } } if ( flag == 0 ) { printf("no processfunc, posthexmsg\n"); category_posthexmsg(myinfo,categoryhash,jbits256(json,"subhash"),hexmsg,tai_now(),remoteaddr); } //char str[65]; printf("HEXPROCESS.(%s) -> %s\n",hexmsg,bits256_str(str,categoryhash)); if ( buf != _buf ) free(buf); }
GString *parse_script_str(const char *enc) { char **tokens = g_strsplit_set(enc, " \t\n", 0); assert (tokens != NULL); GString *script = g_string_sized_new(64); unsigned int idx; for (idx = 0; tokens[idx] != NULL; idx++) { char *token = tokens[idx]; if (is_digitstr(token)) { int64_t v = strtoll(token, NULL, 10); bsp_push_int64(script, v); } else if (is_hexstr(token, true)) { GString *raw = hex2str(token); g_string_append_len(script, raw->str, raw->len); g_string_free(raw, TRUE); } else if ((strlen(token) >= 2) && (token[0] == '\'') && (token[strlen(token) - 1] == '\'')) bsp_push_data(script, &token[1], strlen(token) - 2); else if (GetOpType(token) != OP_INVALIDOPCODE) bsp_push_op(script, GetOpType(token)); else assert(!"parse error"); } g_strfreev(tokens); return script; }
int32_t teleport_idle(struct plugin_info *plugin) { int32_t pmlen; char *pmstr,*decoded; cJSON *decodedjson; uint64_t r; if ( TELEPORT.availablemilli == 0 ) { randombytes((void *)&r,sizeof(r)); TELEPORT.availablemilli = (uint64_t)(milliseconds() + SUPERNET.telepathicdelay + (r % SUPERNET.telepathicdelay)); } if ( milliseconds() > TELEPORT.availablemilli && (pmstr= queue_dequeue(&TelepathyQ,1)) != 0 ) { if ( is_hexstr(pmstr) != 0 ) { pmlen = (int32_t)strlen(pmstr); decoded = malloc((pmlen >> 1) + 1); decode_hex((void *)decoded,pmlen,pmstr); decoded[pmlen] = 0; if ( (decodedjson= cJSON_Parse(decoded)) != 0 ) { telepathic_remotejson(decodedjson); free_json(decodedjson); } else telepathic_remotebinary(pmstr,decoded,pmlen); free(decoded); } else telepathic_remotestr(pmstr);
void dpow_statemachinestart(void *ptr) { void **ptrs = ptr; struct supernet_info *myinfo; struct dpow_info *dp; struct dpow_checkpoint checkpoint; int32_t i,j,ht,extralen,destprevvout0,srcprevvout0,numratified=0,kmdheight,myind = -1; uint8_t extras[10000],pubkeys[64][33]; cJSON *ratified=0,*item; struct iguana_info *src,*dest; char *jsonstr,*handle,*hexstr,str[65],str2[65],srcaddr[64],destaddr[64]; bits256 zero,srchash,destprevtxid0,srcprevtxid0; struct dpow_block *bp; struct dpow_entry *ep = 0; uint32_t duration,minsigs,starttime,srctime; memset(&zero,0,sizeof(zero)); srcprevtxid0 = destprevtxid0 = zero; srcprevvout0 = destprevvout0 = -1; myinfo = ptrs[0]; dp = ptrs[1]; minsigs = (uint32_t)(long)ptrs[2]; duration = (uint32_t)(long)ptrs[3]; jsonstr = ptrs[4]; kmdheight = -1; memcpy(&checkpoint,&ptrs[5],sizeof(checkpoint)); src = iguana_coinfind(dp->symbol); dest = iguana_coinfind(dp->dest); dpow_getchaintip(myinfo,&srchash,&srctime,dp->srctx,&dp->numsrctx,src); dpow_getchaintip(myinfo,&srchash,&srctime,dp->desttx,&dp->numdesttx,dest); if ( src == 0 || dest == 0 ) { printf("null coin ptr? (%s %p or %s %p)\n",dp->symbol,src,dp->dest,dest); return; } if ( strcmp(src->symbol,"KMD") == 0 ) kmdheight = checkpoint.blockhash.height; else if ( strcmp(dest->symbol,"KMD") == 0 ) kmdheight = dest->longestchain; if ( (bp= dp->blocks[checkpoint.blockhash.height]) == 0 ) { bp = calloc(1,sizeof(*bp)); bp->minsigs = minsigs; bp->duration = duration; bp->srccoin = src; bp->destcoin = dest; bp->myind = -1; bp->opret_symbol = dp->symbol; if ( jsonstr != 0 && (ratified= cJSON_Parse(jsonstr)) != 0 ) { bp->isratify = 1; if ( (numratified= cJSON_GetArraySize(ratified)) > 0 ) { if ( numratified > 64 ) { fprintf(stderr,"cant ratify more than 64 notaries ratified has %d\n",numratified); return; } for (i=0; i<numratified; i++) { item = jitem(ratified,i); hexstr = handle = 0; if ( (hexstr= jstr(item,"pubkey")) != 0 && is_hexstr(hexstr,0) == 66 ) { decode_hex(bp->ratified_pubkeys[i],33,hexstr); for (j=0; j<i; j++) if ( memcmp(bp->ratified_pubkeys[j],bp->ratified_pubkeys[i],33) == 0 ) { printf("ratification.%d is the same as %d, reject this donkey\n",j,i); exit(-1); } if ( (handle= jstr(item,"handle")) != 0 ) safecopy(bp->handles[i],handle,sizeof(bp->handles[i])); if ( i == 0 ) { destprevtxid0 = jbits256(item,"destprevtxid0"); destprevvout0 = jint(item,"destprevvout0"); srcprevtxid0 = jbits256(item,"srcprevtxid0"); srcprevvout0 = jint(item,"srcprevvout0"); if ( bits256_nonz(destprevtxid0) != 0 && bits256_nonz(srcprevtxid0) != 0 ) bp->require0 = 1; } } else { printf("break loop hexstr.%p handle.%p\n",hexstr,handle); break; } } if ( i == numratified ) { bp->numratified = numratified; bp->ratified = ratified; printf("numratified.%d %s\n",numratified,jprint(ratified,0)); } else { printf("i.%d numratified.%d\n",i,numratified); free_json(ratified); } } } bp->bestk = -1; dp->blocks[checkpoint.blockhash.height] = bp; bp->beacon = rand256(0); vcalc_sha256(0,bp->commit.bytes,bp->beacon.bytes,sizeof(bp->beacon)); /*if ( checkpoint.blockhash.height >= DPOW_FIRSTRATIFY && dp->blocks[checkpoint.blockhash.height - DPOW_FIRSTRATIFY] != 0 ) { printf("purge %s.%d\n",dp->dest,checkpoint.blockhash.height - DPOW_FIRSTRATIFY); free(dp->blocks[checkpoint.blockhash.height - DPOW_FIRSTRATIFY]); dp->blocks[checkpoint.blockhash.height - DPOW_FIRSTRATIFY] = 0; }*/ } if ( bp->isratify != 0 && dp->ratifying != 0 ) { printf("new ratification starting dp->ratifying.%d\n",dp->ratifying); dp->ratifying++; while ( dp->ratifying > 1 ) sleep(3); printf("other ratifications stopped\n"); } if ( dp->ratifying != 0 && bp->isratify == 0 ) { printf("skip notarization ht.%d when ratifying\n",bp->height); free(ptr); return; } dp->ratifying += bp->isratify; bitcoin_address(srcaddr,src->chain->pubtype,dp->minerkey33,33); bitcoin_address(destaddr,dest->chain->pubtype,dp->minerkey33,33); if ( kmdheight >= 0 ) { ht = kmdheight;///strcmp("KMD",src->symbol) == 0 ? kmdheight : bp->height; if ( strcmp("KMD",dest->symbol) == 0 ) { bp->numnotaries = komodo_notaries(dest->symbol,pubkeys,ht); } else { if ( ht == 0 ) ht = strcmp("KMD",src->symbol) == 0 ? src->longestchain : dest->longestchain; bp->numnotaries = komodo_notaries(src->symbol,pubkeys,ht); } for (i=0; i<bp->numnotaries; i++) { //int32_t j; for (j=0; j<33; j++) // printf("%02x",pubkeys[i][j]); //printf(" <= pubkey[%d]\n",i); memcpy(bp->notaries[i].pubkey,pubkeys[i],33); if ( strcmp("KMD",src->symbol) == 0 ) memcpy(myinfo->notaries[i],pubkeys[i],33); if ( memcmp(bp->notaries[i].pubkey,dp->minerkey33,33) == 0 ) { myind = i; ep = &bp->notaries[myind]; for (j=0; j<33; j++) printf("%02x",dp->minerkey33[j]); printf(" MYIND.%d <<<<<<<<<<<<<<<<<<<<<<\n",myind); } } if ( strcmp("KMD",src->symbol) == 0 ) myinfo->numnotaries = bp->numnotaries; if ( myind < 0 || ep == 0 ) { printf("minerkey33-> "); for (i=0; i<33; i++) printf("%02x",dp->minerkey33[i]); printf(" statemachinestart this node %s %s is not official notary numnotaries.%d kmdht.%d bpht.%d\n",srcaddr,destaddr,bp->numnotaries,kmdheight,bp->height); free(ptr); dp->ratifying -= bp->isratify; return; } printf("myind.%d\n",myind); } else { printf("statemachinestart no kmdheight.%d\n",kmdheight); free(ptr); dp->ratifying -= bp->isratify; return; } bp->myind = myind; printf("[%d] notarize %s->%s %s ht.%d minsigs.%d duration.%d start.%u\n",bp->myind,dp->symbol,dp->dest,bits256_str(str,checkpoint.blockhash.hash),checkpoint.blockhash.height,minsigs,duration,checkpoint.timestamp); if ( bp->isratify != 0 && memcmp(bp->notaries[0].pubkey,bp->ratified_pubkeys[0],33) != 0 ) { for (i=0; i<33; i++) printf("%02x",bp->notaries[0].pubkey[i]); printf(" current vs "); for (i=0; i<33; i++) printf("%02x",bp->ratified_pubkeys[0][i]); printf(" new, cant change notary0\n"); dp->ratifying -= bp->isratify; return; } //printf(" myind.%d myaddr.(%s %s)\n",myind,srcaddr,destaddr); if ( myind == 0 && bits256_nonz(destprevtxid0) != 0 && bits256_nonz(srcprevtxid0) != 0 && destprevvout0 >= 0 && srcprevvout0 >= 0 ) { ep->dest.prev_hash = destprevtxid0; ep->dest.prev_vout = destprevvout0; ep->src.prev_hash = srcprevtxid0; ep->src.prev_vout = srcprevvout0; bp->notaries[myind].ratifysrcutxo = srcprevtxid0; bp->notaries[myind].ratifysrcvout = srcprevvout0; bp->notaries[myind].ratifydestutxo = destprevtxid0; bp->notaries[myind].ratifydestvout = destprevvout0; printf("Use override utxo %s/v%d %s/v%d\n",bits256_str(str,destprevtxid0),destprevvout0,bits256_str(str2,srcprevtxid0),srcprevvout0); } else { if ( dpow_checkutxo(myinfo,dp,bp,bp->destcoin,&ep->dest.prev_hash,&ep->dest.prev_vout,destaddr) < 0 ) { printf("dont have %s %s utxo, please send funds\n",dp->dest,destaddr); free(ptr); dp->ratifying -= bp->isratify; return; } if ( dpow_checkutxo(myinfo,dp,bp,bp->srccoin,&ep->src.prev_hash,&ep->src.prev_vout,srcaddr) < 0 ) { printf("dont have %s %s utxo, please send funds\n",dp->symbol,srcaddr); free(ptr); dp->ratifying -= bp->isratify; return; } if ( bp->isratify != 0 ) { bp->notaries[myind].ratifysrcutxo = ep->src.prev_hash; bp->notaries[myind].ratifysrcvout = ep->src.prev_vout; bp->notaries[myind].ratifydestutxo = ep->dest.prev_hash; bp->notaries[myind].ratifydestvout = ep->dest.prev_vout; } } bp->recvmask |= (1LL << myind); bp->notaries[myind].othermask |= (1LL << myind); dp->checkpoint = checkpoint; bp->height = checkpoint.blockhash.height; bp->timestamp = checkpoint.timestamp; bp->hashmsg = checkpoint.blockhash.hash; bp->myind = myind; while ( bp->isratify == 0 && dp->destupdated == 0 ) { if ( dp->checkpoint.blockhash.height > checkpoint.blockhash.height ) { printf("abort %s ht.%d due to new checkpoint.%d\n",dp->symbol,checkpoint.blockhash.height,dp->checkpoint.blockhash.height); dp->ratifying -= bp->isratify; return; } sleep(1); } starttime = (uint32_t)time(NULL); if ( bp->isratify == 0 ) { //if ( (starttime= checkpoint.timestamp) == 0 ) bp->starttime = starttime; extralen = dpow_paxpending(extras,&bp->paxwdcrc); bp->notaries[bp->myind].paxwdcrc = bp->paxwdcrc; } printf("PAXWDCRC.%x myind.%d isratify.%d DPOW.%s statemachine checkpoint.%d %s start.%u+dur.%d vs %ld\n",bp->paxwdcrc,bp->myind,bp->isratify,src->symbol,checkpoint.blockhash.height,bits256_str(str,checkpoint.blockhash.hash),starttime,bp->duration,time(NULL)); for (i=0; i<sizeof(srchash); i++) srchash.bytes[i] = dp->minerkey33[i+1]; //printf("start utxosync start.%u %u\n",starttime,(uint32_t)time(NULL)); //dpow_utxosync(myinfo,dp,bp,0,myind,srchash); //printf("done utxosync start.%u %u\n",starttime,(uint32_t)time(NULL)); while ( time(NULL) < starttime+bp->duration && src != 0 && dest != 0 && bp->state != 0xffffffff ) { if ( bp->isratify == 0 ) { if ( myinfo->DPOWS[0].ratifying != 0 ) { printf("break due to already ratifying\n"); break; } extralen = dpow_paxpending(extras,&bp->paxwdcrc); bp->notaries[bp->myind].paxwdcrc = bp->paxwdcrc; } sleep(13); if ( dp->checkpoint.blockhash.height > checkpoint.blockhash.height ) { if ( bp->isratify == 0 ) { printf("abort %s ht.%d due to new checkpoint.%d\n",dp->symbol,checkpoint.blockhash.height,dp->checkpoint.blockhash.height); break; } } if ( dp->ratifying > 1 ) { printf("new ratification started. abort ht.%d\n",bp->height); break; } if ( bp->isratify == 0 ) { bits256 checkhash; checkhash = dpow_getblockhash(myinfo,bp->srccoin,bp->height); if ( bits256_cmp(checkhash,bp->hashmsg) != 0 ) { printf("%s ht.%d %s got reorged to %s, abort notarization\n",bp->srccoin->symbol,bp->height,bits256_str(str,bp->hashmsg),bits256_str(str2,checkhash)); bp->state = 0xffffffff; } } if ( bp->state != 0xffffffff ) { dpow_send(myinfo,dp,bp,srchash,bp->hashmsg,0,bp->height,(void *)"ping",0); dpow_nanomsg_update(myinfo); } else { dp->lastnotarized = checkpoint.blockhash.hash; printf("notarized %s %s\n",dp->symbol,bits256_str(str,checkpoint.blockhash.hash)); } if ( 0 && dp->cancelratify != 0 && bp->isratify != 0 ) { printf("abort pending ratify\n"); break; } } printf("END isratify.%d:%d bestk.%d %llx sigs.%llx state.%x machine ht.%d completed state.%x %s.%s %s.%s recvmask.%llx paxwdcrc.%x %p %p\n",bp->isratify,dp->ratifying,bp->bestk,(long long)bp->bestmask,(long long)(bp->bestk>=0?bp->destsigsmasks[bp->bestk]:0),bp->state,bp->height,bp->state,dp->dest,bits256_str(str,bp->desttxid),dp->symbol,bits256_str(str2,bp->srctxid),(long long)bp->recvmask,bp->paxwdcrc,src,dest); bp->state = 0xffffffff; dp->lastrecvmask = bp->recvmask; dp->ratifying -= bp->isratify; dp->blocks[bp->height] = 0; free(ptr); }
static const char *parse_string(cJSON *item,const char *str) { const char *ptr=str+1;char *ptr2;char *out;int32_t len=0;unsigned uc,uc2; if (*str!='\"') {ep=str;return 0;} /* not a string! */ while (*ptr!='\"' && *ptr && ++len) if (*ptr++ == '\\') ptr++; // Skip escaped quotes out=(char*)cJSON_malloc(len+2); /* This is how long we need for the string, roughly. */ if (!out) return 0; ptr=str+1;ptr2=out; while (*ptr!='\"' && *ptr) { if (*ptr!='\\') { if ( *ptr == '%' && is_hexstr((char *)&ptr[1],2) && isprint(_decode_hex((char *)&ptr[1])) != 0 ) *ptr2++ = _decode_hex((char *)&ptr[1]), ptr += 3; else *ptr2++ = *ptr++; } else { ptr++; switch (*ptr) { case 'b': *ptr2++='\b'; break; case 'f': *ptr2++='\f'; break; case 'n': *ptr2++='\n'; break; case 'r': *ptr2++='\r'; break; case 't': *ptr2++='\t'; break; case 'u': // transcode utf16 to utf8 uc=parse_hex4(ptr+1);ptr+=4; // get the unicode char if ((uc>=0xDC00 && uc<=0xDFFF) || uc==0) break; // check for invalid if (uc>=0xD800 && uc<=0xDBFF) // UTF16 surrogate pairs { if (ptr[1]!='\\' || ptr[2]!='u') break; // missing second-half of surrogate. uc2=parse_hex4(ptr+3);ptr+=6; if (uc2<0xDC00 || uc2>0xDFFF) break; // invalid second-half of surrogate uc=0x10000 + (((uc&0x3FF)<<10) | (uc2&0x3FF)); } len=4;if (uc<0x80) len=1;else if (uc<0x800) len=2;else if (uc<0x10000) len=3; ptr2+=len; switch (len) { case 4: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6; case 3: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6; case 2: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6; case 1: *--ptr2 =(uc | firstByteMark[len]); } ptr2+=len; break; default: *ptr2++=*ptr; break; } ptr++; } } *ptr2=0; if (*ptr=='\"') ptr++; item->valuestring=out; item->type=cJSON_String; return ptr; }
static error_t parse_opt (int key, char *arg, struct argp_state *state) { switch(key) { case 1001: // --locktime=NNNNN opt_locktime = arg; break; case 1002: // --nversion=NNNNN opt_version = arg; break; case 1003: // --blank opt_blank = true; break; case 1030: // --output-json opt_decode_json = true; break; case 1040: // --strict-free opt_strict_free = true; break; case 1010: { // --txin=TXID:VOUT char *colon = strchr(arg, ':'); if (!colon) return ARGP_ERR_UNKNOWN; if ((colon - arg) != 64) return ARGP_ERR_UNKNOWN; if (!is_digitstr(colon + 1)) return ARGP_ERR_UNKNOWN; char hexstr[65]; memcpy(hexstr, arg, 64); hexstr[64] = 0; if (!is_hexstr(hexstr, false)) return ARGP_ERR_UNKNOWN; opt_txin = clist_append(opt_txin, strdup(arg)); break; } case 1011: { // --delete-txin=INDEX if (!is_digitstr(arg)) return ARGP_ERR_UNKNOWN; opt_del_txin = clist_append(opt_del_txin, int_to_ptr(atoi(arg))); break; } case 1020: { // --txout=ADDRESS:AMOUNT char *colon = strchr(arg, ':'); if (!colon) return ARGP_ERR_UNKNOWN; unsigned int partlen = colon - arg; if (!is_digitstr(colon + 1)) return ARGP_ERR_UNKNOWN; char addrstr[partlen + 1]; memcpy(addrstr, arg, partlen); addrstr[partlen] = 0; cstring *payload = base58_decode_check(NULL, addrstr); bool payload_invalid = (!payload || (payload->len != 21)); cstr_free(payload, true); if (payload_invalid) return ARGP_ERR_UNKNOWN; opt_txout = clist_append(opt_txout, strdup(arg)); break; } case 1021: { // --delete-txout=INDEX if (!is_digitstr(arg)) return ARGP_ERR_UNKNOWN; opt_del_txout = clist_append(opt_del_txout, int_to_ptr(atoi(arg))); break; } case ARGP_KEY_ARG: if (opt_hexdata) return ARGP_ERR_UNKNOWN; opt_hexdata = arg; break; default: return ARGP_ERR_UNKNOWN; } return 0; }
TWO_STRINGS(iguana,dpow,symbol,pubkey) { char *retstr,srcaddr[64],destaddr[64]; struct iguana_info *src,*dest; cJSON *ismine; int32_t i,srcvalid,destvalid; struct dpow_info *dp = &myinfo->DPOWS[myinfo->numdpows]; destvalid = srcvalid = 0; if ( myinfo->NOTARY.RELAYID < 0 ) { if ( (retstr= basilisk_addrelay_info(myinfo,0,(uint32_t)calc_ipbits(myinfo->ipaddr),myinfo->myaddr.persistent)) != 0 ) { printf("addrelay.(%s)\n",retstr); free(retstr); } if ( myinfo->NOTARY.RELAYID < 0 ) return(clonestr("{\"error\":\"must be running as notary node\"}")); } if ( dp->symbol[0] != 0 ) return(clonestr("{\"error\":\"cant dPoW more than one coin at a time\"}")); if ( pubkey == 0 || pubkey[0] == 0 || is_hexstr(pubkey,0) != 66 ) return(clonestr("{\"error\":\"need 33 byte pubkey\"}")); if ( symbol == 0 || symbol[0] == 0 ) symbol = "KMD"; //if ( myinfo->numdpows == 1 ) // komodo_assetcoins(-1); if ( iguana_coinfind(symbol) == 0 ) return(clonestr("{\"error\":\"cant dPoW an inactive coin\"}")); if ( strcmp(symbol,"KMD") == 0 && iguana_coinfind("BTC") == 0 ) return(clonestr("{\"error\":\"cant dPoW KMD without BTC\"}")); else if ( myinfo->numdpows == 0 && strcmp(symbol,"KMD") != 0 && iguana_coinfind("KMD") == 0 ) return(clonestr("{\"error\":\"cant dPoW without KMD\"}")); if ( myinfo->numdpows > 1 ) { if ( strcmp(symbol,"KMD") == 0 || iguana_coinfind("BTC") == 0 ) { dp->symbol[0] = 0; return(clonestr("{\"error\":\"cant dPoW KMD or BTC again\"}")); } for (i=1; i<myinfo->numdpows; i++) if ( strcmp(symbol,myinfo->DPOWS[i].symbol) == 0 ) { dp->symbol[0] = 0; return(clonestr("{\"error\":\"cant dPoW same coin again\"}")); } } strcpy(dp->symbol,symbol); if ( strcmp(dp->symbol,"KMD") == 0 ) { strcpy(dp->dest,"BTC"); dp->srcconfirms = DPOW_KOMODOCONFIRMS; } else { strcpy(dp->dest,"KMD"); dp->srcconfirms = DPOW_THIRDPARTY_CONFIRMS; } if ( dp->srcconfirms > DPOW_FIFOSIZE ) dp->srcconfirms = DPOW_FIFOSIZE; src = iguana_coinfind(dp->symbol); dest = iguana_coinfind(dp->dest); if ( src == 0 || dest == 0 ) { dp->symbol[0] = 0; return(clonestr("{\"error\":\"source coin or dest coin not there\"}")); } char tmp[67]; safecopy(tmp,pubkey,sizeof(tmp)); decode_hex(dp->minerkey33,33,tmp); bitcoin_address(srcaddr,src->chain->pubtype,dp->minerkey33,33); if ( (retstr= dpow_validateaddress(myinfo,src,srcaddr)) != 0 ) { json = cJSON_Parse(retstr); if ( (ismine= jobj(json,"ismine")) != 0 && is_cJSON_True(ismine) != 0 ) srcvalid = 1; else srcvalid = 0; free(retstr); retstr = 0; } bitcoin_address(destaddr,dest->chain->pubtype,dp->minerkey33,33); if ( (retstr= dpow_validateaddress(myinfo,dest,destaddr)) != 0 ) { json = cJSON_Parse(retstr); if ( (ismine= jobj(json,"ismine")) != 0 && is_cJSON_True(ismine) != 0 ) destvalid = 1; else destvalid = 0; free(retstr); retstr = 0; } for (i=0; i<33; i++) printf("%02x",dp->minerkey33[i]); printf(" DPOW with pubkey.(%s) %s.valid%d %s -> %s %s.valid%d\n",tmp,srcaddr,srcvalid,dp->symbol,dp->dest,destaddr,destvalid); if ( srcvalid <= 0 || destvalid <= 0 ) { dp->symbol[0] = 0; return(clonestr("{\"error\":\"source address or dest address has no privkey, importprivkey\"}")); } if ( bitcoin_pubkeylen(dp->minerkey33) <= 0 ) { dp->symbol[0] = 0; return(clonestr("{\"error\":\"illegal pubkey\"}")); } if ( dp->blocks == 0 ) { dp->maxblocks = 1000000; dp->blocks = calloc(dp->maxblocks,sizeof(*dp->blocks)); } portable_mutex_init(&dp->paxmutex); portable_mutex_init(&dp->dexmutex); PAX_init(); //printf(">>>>>>>>>>>>>>> call paxpending\n"); //uint8_t buf[32768]; //dpow_paxpending(buf); myinfo->numdpows++; return(clonestr("{\"result\":\"success\"}")); }