diff --git a/crypto777/OS_portable.h b/crypto777/OS_portable.h index 90ddda7c6..422a8314a 100755 --- a/crypto777/OS_portable.h +++ b/crypto777/OS_portable.h @@ -356,7 +356,7 @@ uint8_t *iguana_varint32(int32_t rwflag,uint8_t *serialized,uint16_t *varint16p) uint8_t *iguana_varint64(int32_t rwflag,uint8_t *serialized,uint32_t *varint32p); int32_t iguana_rwvarint(int32_t rwflag,uint8_t *serialized,uint64_t *varint64p); int32_t iguana_rwvarint32(int32_t rwflag,uint8_t *serialized,uint32_t *int32p); -int32_t iguana_rwstr(int32_t rwflag,uint8_t *serialized,int32_t maxlen,char *endianedp); +int32_t iguana_rwvarstr(int32_t rwflag,uint8_t *serialized,int32_t maxlen,char *endianedp); int32_t iguana_rwmem(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp); bits256 bits256_doublesha256(char *hashstr,uint8_t *data,int32_t datalen); diff --git a/crypto777/iguana_serdes.c b/crypto777/iguana_serdes.c index f8430ea2e..eff6f3e5f 100755 --- a/crypto777/iguana_serdes.c +++ b/crypto777/iguana_serdes.c @@ -186,7 +186,7 @@ int32_t iguana_rwvarint32(int32_t rwflag,uint8_t *serialized,uint32_t *int32p) return(len); } -int32_t iguana_rwstr(int32_t rwflag,uint8_t *serialized,int32_t maxlen,char *endianedp) +int32_t iguana_rwvarstr(int32_t rwflag,uint8_t *serialized,int32_t maxlen,char *endianedp) { int32_t vlen; uint64_t n; if ( rwflag == 0 ) diff --git a/iguana/iguana777.h b/iguana/iguana777.h index 032ca9a86..5ab4fa09d 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -227,6 +227,7 @@ struct iguana_chain char use_addmultisig,do_opreturn; int32_t estblocktime; bits256 PoWtarget,PoStargets[16]; int32_t numPoStargets,PoSheights[16]; + uint8_t alertpubkey[65]; }; struct iguana_msgaddress { uint32_t nTime; uint64_t nServices; uint8_t ip[16]; uint16_t port; } __attribute__((packed)); @@ -243,6 +244,20 @@ struct iguana_msgversion uint8_t relayflag; } __attribute__((packed)); +struct iguana_msgalert // warning, many varints/variable length fields, struct is 1:1 +{ + int32_t version; + int64_t relayuntil,expiration; + int32_t ID,cancel; + uint32_t numcancellist; + int32_t minver,maxver; + uint32_t setsubvervar; char subver[1024]; + int32_t priority; + char comment[1024],statusbar[1024],reserved[1024]; + uint8_t siglen,sig[74]; + uint32_t list[64]; +}; + struct iguana_VPNversion { uint32_t nVersion; @@ -1019,6 +1034,7 @@ char *bitcoin_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJ char *bitcoin_blockhashstr(char *coinstr,char *serverport,char *userpass,int32_t height); bits256 basilisk_blockhash(struct iguana_info *coin,bits256 prevhash2); void calc_scrypthash(uint32_t *hash,void *data); +int32_t iguana_rwvarstr(int32_t rwflag,uint8_t *serialized,int32_t maxlen,char *endianedp); extern int32_t HDRnet,netBLOCKS; diff --git a/iguana/iguana_chains.c b/iguana/iguana_chains.c index 3ceeebbda..0f55694ea 100755 --- a/iguana/iguana_chains.c +++ b/iguana/iguana_chains.c @@ -393,9 +393,12 @@ void iguana_chaininit(struct iguana_chain *chain,int32_t hasheaders,cJSON *argjs } chain->hasheaders = hasheaders; chain->minoutput = 10000; - if ( strcmp(chain->symbol,"LTC") == 0 || strcmp(chain->symbol,"VPN") == 0 ) - chain->hashalgo = blockhash_sha256;//blockhash_scrypt; - else chain->hashalgo = blockhash_sha256; + if ( strcmp(chain->symbol,"LTC") == 0 ) + { + char *pubkeystr = "040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9"; + decode_hex(chain->alertpubkey,(int32_t)strlen(pubkeystr)>>1,pubkeystr); + } + chain->hashalgo = blockhash_sha256; // most all coins seem to use this for blockchain if ( strcmp(chain->symbol,"BTC") == 0 ) { chain->unitval = 0x1d; diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index 0b825b713..31ba3c166 100755 --- a/iguana/iguana_init.c +++ b/iguana/iguana_init.c @@ -266,7 +266,7 @@ void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp) { j = (int32_t)strlen(line) - 1; line[j] = 0; - printf("parse line.(%s) maxpeers.%d\n",line,coin->MAXPEERS); + //printf("parse line.(%s) maxpeers.%d\n",line,coin->MAXPEERS); if ( iter == 0 ) { if ( m < coin->MAXPEERS-3 )//&& m < 77.7 ) diff --git a/iguana/iguana_instantdex.c b/iguana/iguana_instantdex.c index 9d924db2a..c78080286 100755 --- a/iguana/iguana_instantdex.c +++ b/iguana/iguana_instantdex.c @@ -356,8 +356,8 @@ bits256 instantdex_rwoffer(int32_t rwflag,int32_t *lenp,uint8_t *serialized,stru { memset(offer,0,sizeof(*offer)); } - len += iguana_rwstr(rwflag,&serialized[len],sizeof(offer->base),offer->base); - len += iguana_rwstr(rwflag,&serialized[len],sizeof(offer->rel),offer->rel); + len += iguana_rwvarstr(rwflag,&serialized[len],sizeof(offer->base),offer->base); + len += iguana_rwvarstr(rwflag,&serialized[len],sizeof(offer->rel),offer->rel); len += iguana_rwnum(rwflag,&serialized[len],sizeof(offer->price64),&offer->price64); len += iguana_rwnum(rwflag,&serialized[len],sizeof(offer->basevolume64),&offer->basevolume64); len += iguana_rwnum(rwflag,&serialized[len],sizeof(offer->account),&offer->account); diff --git a/iguana/iguana_msg.c b/iguana/iguana_msg.c index 22d3a0a74..54f1c8c2e 100755 --- a/iguana/iguana_msg.c +++ b/iguana/iguana_msg.c @@ -41,7 +41,7 @@ int32_t iguana_rwversion(int32_t rwflag,uint8_t *serialized,struct iguana_msgver len += iguana_rwaddr(rwflag,&serialized[len],&msg->addrTo,MIN_PROTO_VERSION); len += iguana_rwaddr(rwflag,&serialized[len],&msg->addrFrom,MIN_PROTO_VERSION); len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->nonce),&msg->nonce); - len += iguana_rwstr(rwflag,&serialized[len],sizeof(msg->strSubVer),msg->strSubVer); + len += iguana_rwvarstr(rwflag,&serialized[len],sizeof(msg->strSubVer),msg->strSubVer); len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->nStartingHeight),&msg->nStartingHeight); if ( readsize == 117 ) { @@ -136,6 +136,49 @@ int32_t iguana_rwblockhash(int32_t rwflag,uint8_t *serialized,uint32_t *nVersion return(len); } +int32_t iguana_rwmsgalert(struct iguana_info *coin,int32_t rwflag,uint8_t *serialized,struct iguana_msgalert *msg) +{ + bits256 alerthash2; int32_t i,plen,isvalid,len = 0; + len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->version),&msg->version); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->relayuntil),&msg->relayuntil); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->expiration),&msg->expiration); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->ID),&msg->ID); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->cancel),&msg->cancel); + len += iguana_rwvarint32(rwflag,&serialized[len],&msg->numcancellist); + if ( msg->numcancellist != 0 ) + { + for (i=0; inumcancellist; i++) + len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->version),&msg->list[i]); + } + len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->minver),&msg->minver); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->maxver),&msg->maxver); + len += iguana_rwvarint32(rwflag,&serialized[len],&msg->setsubvervar); + len += iguana_rwvarstr(rwflag,&serialized[len],sizeof(msg->subver),msg->subver); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->priority),&msg->priority); + len += iguana_rwvarstr(rwflag,&serialized[len],sizeof(msg->comment),msg->comment); + len += iguana_rwvarstr(rwflag,&serialized[len],sizeof(msg->statusbar),msg->statusbar); + len += iguana_rwvarstr(rwflag,&serialized[len],sizeof(msg->reserved),msg->reserved); + alerthash2 = bits256_doublesha256(0,serialized,len); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->siglen),&msg->siglen); + if ( msg->siglen >= 70 && msg->siglen < 74 ) + { + if ( rwflag == 0 ) + memcpy(msg->sig,&serialized[len],msg->siglen); + else memcpy(&serialized[len],msg->sig,msg->siglen); + len += msg->siglen; + plen = bitcoin_pubkeylen(coin->chain->alertpubkey); + isvalid = (bitcoin_verify(coin->ctx,msg->sig,msg->siglen,alerthash2,coin->chain->alertpubkey,plen) == 0); + for (i=0; isiglen; i++) + printf("%02x",msg->sig[i]); + printf(" %s\n",isvalid != 0 ? "VALIDSIG" : "SIGERROR"); + for (i=0; ichain->alertpubkey[i]); + char str[65]; printf(" alertpubkey.%d, alerthash2.%s\n",plen,bits256_str(str,alerthash2)); + } else msg->siglen = 0; + printf(" ALERT v.%d relay.%llu expires.%llu ID.%d cancel.%d numlist.%d minver.%d maxver.%d subver.(%s) priority.%d comment.(%s) STATUS.(%s) reserved.(%s)\n",msg->version,msg->relayuntil,msg->expiration,msg->ID,msg->cancel,msg->numcancellist,msg->minver,msg->maxver,msg->subver,msg->priority,msg->comment,msg->statusbar,msg->reserved); + return(len); +} + /*int32_t iguana_request_data(struct iguana_info *coin,struct iguana_peer *addr,bits256 *hashes,int32_t n,uint32_t type,int32_t forceflag) { uint32_t len,i; uint8_t serialized[sizeof(struct iguana_msghdr) + (sizeof(uint32_t) + sizeof(bits256))*32 + sizeof(uint64_t)]; @@ -838,10 +881,9 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc } else if ( strcmp(H->command,"alert") == 0 ) { - for (i=0; imsgcounts.alert++; } diff --git a/iguana/main.c b/iguana/main.c index a72134cf3..8e8aaeaf7 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -1154,7 +1154,7 @@ void iguana_appletests(struct supernet_info *myinfo) //iguana_chaingenesis("VPN",0,bits256_conv("00000ac7d764e7119da60d3c832b1d4458da9bc9ef9d5dd0d91a15f690a46d99"),genesisblock,"scrypt",1,1409839200,0x1e0fffff,64881664,bits256_conv("698a93a1cacd495a7a4fb3864ad8d06ed4421dedbc57f9aaad733ea53b1b5828")); // VPN iguana_chaingenesis("LTC",0,bits256_conv("12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2"),genesisblock,"sha256",1,1317972665,0x1e0ffff0,2084524493,bits256_conv("97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9")); // LTC - char *Str = "01000000f615f7ce3b4fc6b8f61e8f89aedb1d0852507650533a9e3b10b9bbcc30639f279fcaa86746e1ef52d3edb3c4ad8259920d509bd073605c9bf1d59983752a6b06b817bb4ea78e011d012d59d4"; + //char *Str = "01000000f615f7ce3b4fc6b8f61e8f89aedb1d0852507650533a9e3b10b9bbcc30639f279fcaa86746e1ef52d3edb3c4ad8259920d509bd073605c9bf1d59983752a6b06b817bb4ea78e011d012d59d4"; // https://litecoin.info/Scrypt 0000000110c8357966576df46f3b802ca897deb7ad18b12f1c24ecff6386ebd9 //uint8_t buf[1000]; bits256 shash,hash2; char str[65],str2[65]; //decode_hex(buf,(int32_t)strlen(Str)>>1,Str);