From 910405ceed0a3d10c828713915a7c045048d51bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 11:12:25 +0200 Subject: [PATCH 001/162] test --- src/komodo.h | 4 +--- src/komodo_notary.h | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 5b45126a5..20755a257 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -19,9 +19,7 @@ // Todo: // verify: reorgs -// non komodod (non-hardfork) todo: -// a. automate notarization fee payouts -// b. automated distribution of test REVS snapshot +#define KOMODO_MAINNET_START 156720 #define KOMODO_ASSETCHAINS_WAITNOTARIZE #define KOMODO_PAXMAX (10000 * COIN) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index b6de38df8..259a5aee5 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -52,6 +52,12 @@ const char *Notaries_genesis[][2] = { "titomane_SH", "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960" }, }; +const char *Notaries_elected[][2] = +{ + { "jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" }, + { "jl777_testB", "02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344" }, +}; + int32_t komodo_ratify_threshold(int32_t height,uint64_t signedmask) { int32_t htind,numnotaries,i,wt = 0; @@ -246,6 +252,18 @@ void komodo_init(int32_t height) // Minerids[i] = -2; didinit = 1; } + else if ( height == KOMODO_MAINNET_START ) + { + n = (int32_t)(sizeof(Notaries_elected)/sizeof(*Notaries_elected)); + for (k=0; k Date: Mon, 16 Jan 2017 11:14:34 +0200 Subject: [PATCH 002/162] test --- src/komodo_notary.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 259a5aee5..843776512 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -13,6 +13,8 @@ * * ******************************************************************************/ +#define KOMODO_MAINNET_START 156720 + const char *Notaries_genesis[][2] = { { "jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" }, From f4bc5a9ae9198fd3dc484e0fcfa86870030b9bc3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 11:21:15 +0200 Subject: [PATCH 003/162] test --- src/komodo_notary.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 843776512..0322ca50c 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -13,7 +13,7 @@ * * ******************************************************************************/ -#define KOMODO_MAINNET_START 156720 +#define KOMODO_MAINNET_START 156730 const char *Notaries_genesis[][2] = { @@ -116,7 +116,7 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) memcpy(kp->pubkey,pubkeys[k],33); kp->notaryid = k; HASH_ADD_KEYPTR(hh,N.Notaries,kp->pubkey,33,kp); - if ( 0 && height > 10000 ) + if ( 1 && height > 10000 ) { for (i=0; i<33; i++) printf("%02x",pubkeys[k][i]); @@ -234,6 +234,7 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n void komodo_init(int32_t height) { static int didinit; uint256 zero; int32_t i,k,n; uint8_t pubkeys[64][33]; + printf("komodo_init ht.%d didinit.%d mainnet.%d\n",height,didinit,KOMODO_MAINNET_START); if ( didinit == 0 ) { pthread_mutex_init(&komodo_mutex,NULL); From 1ba18c2d213dbbc76eda3d72365ca0aab203bd04 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 11:22:09 +0200 Subject: [PATCH 004/162] test --- src/komodo.h | 2 +- src/komodo_notary.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 20755a257..cf0226633 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -19,7 +19,7 @@ // Todo: // verify: reorgs -#define KOMODO_MAINNET_START 156720 +#define KOMODO_MAINNET_START 156730 #define KOMODO_ASSETCHAINS_WAITNOTARIZE #define KOMODO_PAXMAX (10000 * COIN) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 0322ca50c..3a5a6e142 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -13,7 +13,6 @@ * * ******************************************************************************/ -#define KOMODO_MAINNET_START 156730 const char *Notaries_genesis[][2] = { From c9e772875833c6bf47819146c72381367f159463 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 11:24:42 +0200 Subject: [PATCH 005/162] test --- src/komodo_notary.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 3a5a6e142..971d2a823 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -233,7 +233,8 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n void komodo_init(int32_t height) { static int didinit; uint256 zero; int32_t i,k,n; uint8_t pubkeys[64][33]; - printf("komodo_init ht.%d didinit.%d mainnet.%d\n",height,didinit,KOMODO_MAINNET_START); + if ( height != 0 ) + printf("komodo_init ht.%d didinit.%d\n",height,didinit); if ( didinit == 0 ) { pthread_mutex_init(&komodo_mutex,NULL); From 1d3c302743d216ef23e326b479262e600e60f5b9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 11:26:33 +0200 Subject: [PATCH 006/162] test --- src/komodo.h | 1 - src/komodo_notary.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index cf0226633..482c00012 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -19,7 +19,6 @@ // Todo: // verify: reorgs -#define KOMODO_MAINNET_START 156730 #define KOMODO_ASSETCHAINS_WAITNOTARIZE #define KOMODO_PAXMAX (10000 * COIN) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 971d2a823..876bc88ce 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -13,6 +13,7 @@ * * ******************************************************************************/ +#define KOMODO_MAINNET_START 156735 const char *Notaries_genesis[][2] = { From 483c56f8bdad7704068c6d0f2d17891c4eeda6ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 11:31:50 +0200 Subject: [PATCH 007/162] test --- src/komodo_notary.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 876bc88ce..1aeea0137 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -13,7 +13,7 @@ * * ******************************************************************************/ -#define KOMODO_MAINNET_START 156735 +#define KOMODO_MAINNET_START 156742 const char *Notaries_genesis[][2] = { @@ -266,7 +266,7 @@ void komodo_init(int32_t height) decode_hex(pubkeys[k],33,(char *)Notaries_elected[k][1]); } printf("set MAINNET notaries.%d\n",k); - komodo_notarysinit(0,pubkeys,k); + komodo_notarysinit(KOMODO_MAINNET_START,pubkeys,k); } komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,0,0,0,0,0); } From 35dd11f0c188bc1137363b29b3d294688670dff8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 11:38:29 +0200 Subject: [PATCH 008/162] support hardcoded elected notaries --- src/komodo_notary.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 1aeea0137..c4acbb44b 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -13,7 +13,7 @@ * * ******************************************************************************/ -#define KOMODO_MAINNET_START 156742 +#define KOMODO_MAINNET_START 156999 const char *Notaries_genesis[][2] = { @@ -54,7 +54,7 @@ const char *Notaries_genesis[][2] = { "titomane_SH", "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960" }, }; -const char *Notaries_elected[][2] = +const char *Notaries_elected[][2] = // update with all elected notaries { { "jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" }, { "jl777_testB", "02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344" }, @@ -116,7 +116,7 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) memcpy(kp->pubkey,pubkeys[k],33); kp->notaryid = k; HASH_ADD_KEYPTR(hh,N.Notaries,kp->pubkey,33,kp); - if ( 1 && height > 10000 ) + if ( 0 && height > 10000 ) { for (i=0; i<33; i++) printf("%02x",pubkeys[k][i]); @@ -234,7 +234,7 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n void komodo_init(int32_t height) { static int didinit; uint256 zero; int32_t i,k,n; uint8_t pubkeys[64][33]; - if ( height != 0 ) + if ( 0 && height != 0 ) printf("komodo_init ht.%d didinit.%d\n",height,didinit); if ( didinit == 0 ) { From b55c23673678cd8385a180228618f305b6a85da1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 12:30:34 +0200 Subject: [PATCH 009/162] test --- src/komodo.h | 3 +-- src/komodo_bitcoind.h | 50 +++++++++++++++++++++++++++++++++++++++ src/komodo_globals.h | 2 +- src/komodo_utils.h | 55 ++++++++++++++++++++++++++++++------------- 4 files changed, 91 insertions(+), 19 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 482c00012..39a40ca02 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -19,7 +19,6 @@ // Todo: // verify: reorgs - #define KOMODO_ASSETCHAINS_WAITNOTARIZE #define KOMODO_PAXMAX (10000 * COIN) @@ -303,7 +302,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar else if ( height != 0 ) { //printf("ht.%d func N ht.%d errs.%d\n",height,NOTARIZED_HEIGHT,errs); - if ( sp != 0 ) + if ( sp != 0 && (height < sp->CURRENT_HEIGHT-1000 || komodo_verifynotarization(symbol,dest,height,sp->NOTARIZED_HEIGHT,sp->NOTARIZED_HASH,sp->NOTARIZED_DESTTXID) == 0) ) { fputc('N',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index dbb887963..c304bcae2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -346,6 +346,56 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) return(retstr2); } +int32_t komodo_verifynotarizedscript(uint8_t *script,int32_t len,uint256 NOTARIZED_HASH) +{ + int32_t i; uint256 hash; char params[256]; + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&NOTARIZED_HASH)[i]); + printf(" notarized, "); + for (i=0; i<32; i++) + { + ((uint8_t *)&hash)[i] = script[31+2-i]; + printf("%02x",script[31+2-i]); + } + printf(" <- opreturn?\n"); + if ( hash == NOTARIZED_HASH ) + return(0); + else return(-1); +} + +int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t NOTARIZED_HEIGHT,uint256 NOTARIZED_HASH,uint256 NOTARIZED_DESTTXID) +{ + char params[256],*jsonstr,*hexstr; uint8_t script[8192]; int32_t n,len,retval = -1; cJSON *txjson,*vouts,*vout,*skey; + sprintf(params,"[\"%s\", 1]",NOTARIZED_DESTTXID.ToString().c_str()); + if ( strcmp(dest,"KMD") == 0 ) + jsonstr = komodo_issuemethod(KMDUSERPASS,(char *)"getrawtransaction",params,7771); + else if ( strcmp(dest,"BTC") == 0 ) + jsonstr = komodo_issuemethod(BTCUSERPASS,(char *)"getrawtransaction",params,8332); + else return(-1); + if ( jsonstr != 0 ) + { + if ( (txjson= cJSON_Parse(jsonstr)) != 0 ) + { + if ( (vouts= jarray(&n,txjson,"vout")) > 0 ) + { + vout = jitem(vouts,n-1); + if ( (skey= jobj(vout,"scriptPubKey")) != 0 ) + { + if ( (hexstr= jstr(skey,"hex")) != 0 ) + { + len = strlen(hexstr) >> 1; + decode_hex(script,len,hexstr); + retval = komodo_verifynotarizedscript(script,len,NOTARIZED_HASH); + } + } + } + free_json(txjson); + } + free(jsonstr); + } + return(retval); +} + uint256 komodo_getblockhash(int32_t height) { uint256 hash; char params[128],*hexstr,*jsonstr; cJSON *result; int32_t i; uint8_t revbuf[32]; diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 1e985da6b..08c80ff79 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -47,5 +47,5 @@ uint32_t ASSETCHAINS_MAGIC = 2387029918; uint64_t ASSETCHAINS_SUPPLY = 10; uint32_t KOMODO_INITDONE; -char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771; +char KMDUSERPASS[4096],BTCUSERPASS[4096]; uint16_t BITCOIND_PORT = 7771; uint64_t PENDING_KOMODO_TX; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 198caccd8..0f7392e56 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1347,7 +1347,11 @@ void komodo_configfile(char *symbol,uint16_t port) #else while ( fname[strlen(fname)-1] != '/' ) fname[strlen(fname)-1] = 0; +#ifdef __APPLE__ + strcat(fname,"Komodo.conf"); +#else strcat(fname,"komodo.conf"); +#endif #endif if ( (fp= fopen(fname,"rb")) != 0 ) { @@ -1363,7 +1367,13 @@ int32_t komodo_userpass(char *userpass,char *symbol) FILE *fp; char fname[512],username[512],password[512],confname[16]; userpass[0] = 0; if ( strcmp("KMD",symbol) == 0 ) + { +#ifdef __APPLE__ + sprintf(confname,"Komodo.conf"); +#else sprintf(confname,"komodo.conf"); +#endif + } else sprintf(confname,"%s.conf",symbol); komodo_statefname(fname,symbol,confname); if ( (fp= fopen(fname,"rb")) != 0 ) @@ -1494,23 +1504,36 @@ void komodo_args() { char fname[512],username[512],password[4096]; FILE *fp; ASSETCHAINS_PORT = 8777; - strcpy(fname,GetDataDir().string().c_str()); -#ifdef WIN32 - while ( fname[strlen(fname)-1] != '\\' ) - fname[strlen(fname)-1] = 0; - strcat(fname,".komodo/komodo.conf"); -#else - while ( fname[strlen(fname)-1] != '/' ) - fname[strlen(fname)-1] = 0; - strcat(fname,".komodo/komodo.conf"); -#endif - if ( (fp= fopen(fname,"rb")) != 0 ) + for (iter=0; iter<2; iter++) { - komodo_userpass(username,password,fp); - sprintf(KMDUSERPASS,"%s:%s",username,password); - fclose(fp); - //printf("KOMODO.(%s) -> userpass.(%s)\n",fname,KMDUSERPASS); - } else printf("couldnt open.(%s)\n",fname); + strcpy(fname,GetDataDir().string().c_str()); +#ifdef WIN32 + while ( fname[strlen(fname)-1] != '\\' ) + fname[strlen(fname)-1] = 0; + if ( iter == 0 ) + strcat(fname,".komodo\\komodo.conf"); + else strcat(fname,".bitcoin\\bitcoin.conf"); +#else + while ( fname[strlen(fname)-1] != '/' ) + fname[strlen(fname)-1] = 0; +#ifdef __APPLE__ + if ( iter == 0 ) + strcat(fname,"Komodo/Komodo.conf"); + else strcat(fname,"Bitcoin/Bitcoin.conf"); +#else + if ( iter == 0 ) + strcat(fname,".komodo/komodo.conf"); + else strcat(fname,".bitcoin/bitcoin.conf"); +#endif +#endif + if ( (fp= fopen(fname,"rb")) != 0 ) + { + komodo_userpass(username,password,fp); + sprintf(iter == 0 ? KMDUSERPASS : BTCUSERPASS,"%s:%s",username,password); + fclose(fp); + //printf("KOMODO.(%s) -> userpass.(%s)\n",fname,KMDUSERPASS); + } else printf("couldnt open.(%s)\n",fname); + } } //fprintf(stderr,"%s chain params initialized\n",ASSETCHAINS_SYMBOL); } From 523a5dc7e09a6c87a658b5a107cca505b2afd453 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 12:32:20 +0200 Subject: [PATCH 010/162] test --- src/komodo_bitcoind.h | 6 +++--- src/komodo_utils.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c304bcae2..165cc0657 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -376,12 +376,12 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t { if ( (txjson= cJSON_Parse(jsonstr)) != 0 ) { - if ( (vouts= jarray(&n,txjson,"vout")) > 0 ) + if ( (vouts= jarray(&n,txjson,(char *)"vout")) > 0 ) { vout = jitem(vouts,n-1); - if ( (skey= jobj(vout,"scriptPubKey")) != 0 ) + if ( (skey= jobj(vout,(char *)"scriptPubKey")) != 0 ) { - if ( (hexstr= jstr(skey,"hex")) != 0 ) + if ( (hexstr= jstr(skey,(char *)"hex")) != 0 ) { len = strlen(hexstr) >> 1; decode_hex(script,len,hexstr); diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 0f7392e56..81a116eda 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1502,7 +1502,7 @@ void komodo_args() } else { - char fname[512],username[512],password[4096]; FILE *fp; + char fname[512],username[512],password[4096]; int32_t iter; FILE *fp; ASSETCHAINS_PORT = 8777; for (iter=0; iter<2; iter++) { From b148643e801300b19740e69ab5f2f09a41a7c972 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 12:46:04 +0200 Subject: [PATCH 011/162] test --- src/komodo.h | 4 ++-- src/komodo_bitcoind.h | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 39a40ca02..29f7ecb26 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -302,7 +302,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar else if ( height != 0 ) { //printf("ht.%d func N ht.%d errs.%d\n",height,NOTARIZED_HEIGHT,errs); - if ( sp != 0 && (height < sp->CURRENT_HEIGHT-1000 || komodo_verifynotarization(symbol,dest,height,sp->NOTARIZED_HEIGHT,sp->NOTARIZED_HASH,sp->NOTARIZED_DESTTXID) == 0) ) + if ( sp != 0 ) { fputc('N',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) @@ -376,7 +376,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid); len += iguana_rwnum(0,&scriptbuf[len],sizeof(*notarizedheightp),(uint8_t *)notarizedheightp); len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid); - if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height ) + if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && (height < sp->CURRENT_HEIGHT-1000 || komodo_verifynotarization(symbol,dest,height,*notarizedheightp,kmdtxid,desttxid) == 0) ) { sp->NOTARIZED_HEIGHT = *notarizedheightp; sp->NOTARIZED_HASH = kmdtxid; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 165cc0657..9031d89c1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -368,9 +368,17 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t char params[256],*jsonstr,*hexstr; uint8_t script[8192]; int32_t n,len,retval = -1; cJSON *txjson,*vouts,*vout,*skey; sprintf(params,"[\"%s\", 1]",NOTARIZED_DESTTXID.ToString().c_str()); if ( strcmp(dest,"KMD") == 0 ) - jsonstr = komodo_issuemethod(KMDUSERPASS,(char *)"getrawtransaction",params,7771); + { + if ( KMDUSERPASS[0] != 0 ) + jsonstr = komodo_issuemethod(KMDUSERPASS,(char *)"getrawtransaction",params,7771); + //else jsonstr = _dex_getrawtransaction(); + } else if ( strcmp(dest,"BTC") == 0 ) - jsonstr = komodo_issuemethod(BTCUSERPASS,(char *)"getrawtransaction",params,8332); + { + if ( BTCUSERPASS[0] != 0 ) + jsonstr = komodo_issuemethod(BTCUSERPASS,(char *)"getrawtransaction",params,8332); + //else jsonstr = _dex_getrawtransaction(); + } else return(-1); if ( jsonstr != 0 ) { From 48d0e5df77b54a8db1c202ea820399d76c54e4bb Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 13:16:19 +0200 Subject: [PATCH 012/162] test --- src/komodo.h | 2 +- src/komodo_bitcoind.h | 9 +++++++++ src/komodo_utils.h | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 29f7ecb26..0036299e2 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -409,7 +409,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen-len+4+3+(scriptbuf[1] == 0x4d),j); } } - } else printf("notarized.%d %llx reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",notarized,(long long)signedmask,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); + } else printf("notarized.%d %llx reject ht.%d NOTARIZED.%d prev.%d %s.%s DESTTXID.%s (%s)\n",notarized,(long long)signedmask,height,*notarizedheightp,sp->NOTARIZED_HEIGHT,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); } else if ( i == 0 && j == 1 && opretlen == 149 ) { diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9031d89c1..7334ab154 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -367,30 +367,39 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t { char params[256],*jsonstr,*hexstr; uint8_t script[8192]; int32_t n,len,retval = -1; cJSON *txjson,*vouts,*vout,*skey; sprintf(params,"[\"%s\", 1]",NOTARIZED_DESTTXID.ToString().c_str()); + printf("src.%s dest.%s params.[%s] ht.%d notarized.%d\n",src,dest,params,height,NOTARIZED_HEIGHT); if ( strcmp(dest,"KMD") == 0 ) { if ( KMDUSERPASS[0] != 0 ) jsonstr = komodo_issuemethod(KMDUSERPASS,(char *)"getrawtransaction",params,7771); //else jsonstr = _dex_getrawtransaction(); + else return(0); // need universal way to issue DEX* API, since notaries mine most blocks, this ok } else if ( strcmp(dest,"BTC") == 0 ) { if ( BTCUSERPASS[0] != 0 ) + { + printf("BTCUSERPASS.(%s)\n",BTCUSERPASS); jsonstr = komodo_issuemethod(BTCUSERPASS,(char *)"getrawtransaction",params,8332); + } //else jsonstr = _dex_getrawtransaction(); + else return(0); } else return(-1); if ( jsonstr != 0 ) { + printf("GOT.(%s)\n",jsonstr); if ( (txjson= cJSON_Parse(jsonstr)) != 0 ) { if ( (vouts= jarray(&n,txjson,(char *)"vout")) > 0 ) { vout = jitem(vouts,n-1); + printf("vout.(%s)\n",jprint(vout,0)); if ( (skey= jobj(vout,(char *)"scriptPubKey")) != 0 ) { if ( (hexstr= jstr(skey,(char *)"hex")) != 0 ) { + printf("HEX.(%s)\n",hexstr); len = strlen(hexstr) >> 1; decode_hex(script,len,hexstr); retval = komodo_verifynotarizedscript(script,len,NOTARIZED_HASH); diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 81a116eda..0364dcbf6 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1534,6 +1534,7 @@ void komodo_args() //printf("KOMODO.(%s) -> userpass.(%s)\n",fname,KMDUSERPASS); } else printf("couldnt open.(%s)\n",fname); } + printf("BTCUSERPASS.(%s)\n",BTCUSERPASS); } //fprintf(stderr,"%s chain params initialized\n",ASSETCHAINS_SYMBOL); } From de28264f07de6c3514c0aec5326c19ea25c1dc26 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 13:17:18 +0200 Subject: [PATCH 013/162] test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7334ab154..d0eed2afe 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -367,7 +367,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t { char params[256],*jsonstr,*hexstr; uint8_t script[8192]; int32_t n,len,retval = -1; cJSON *txjson,*vouts,*vout,*skey; sprintf(params,"[\"%s\", 1]",NOTARIZED_DESTTXID.ToString().c_str()); - printf("src.%s dest.%s params.[%s] ht.%d notarized.%d\n",src,dest,params,height,NOTARIZED_HEIGHT); + printf("src.%s dest.%s params.[%s] ht.%d notarized.%d\n",symbol,dest,params,height,NOTARIZED_HEIGHT); if ( strcmp(dest,"KMD") == 0 ) { if ( KMDUSERPASS[0] != 0 ) From eee286628f26d3e5ab67323900dd7df6164141bf Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 13:34:40 +0200 Subject: [PATCH 014/162] test --- src/komodo.h | 2 ++ src/komodo_bitcoind.h | 9 +++++++-- src/komodo_utils.h | 1 - 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 0036299e2..5956ae9f0 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -99,6 +99,8 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char if ( 0 && sp != 0 ) printf("%s load[%s.%d] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,notarized_height,notarized_hash.ToString().c_str()); //if ( matched != 0 ) global independent states -> inside *sp + if ( komodo_verifynotarization(symbol,dest,height,notarized_height,notarized_hash,notarized_desttxid) != 0 ) + printf("error validating notarization\n"); komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height); } else if ( func == 'U' ) // deprecated diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d0eed2afe..93fe2f05d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -366,7 +366,12 @@ int32_t komodo_verifynotarizedscript(uint8_t *script,int32_t len,uint256 NOTARIZ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t NOTARIZED_HEIGHT,uint256 NOTARIZED_HASH,uint256 NOTARIZED_DESTTXID) { char params[256],*jsonstr,*hexstr; uint8_t script[8192]; int32_t n,len,retval = -1; cJSON *txjson,*vouts,*vout,*skey; - sprintf(params,"[\"%s\", 1]",NOTARIZED_DESTTXID.ToString().c_str()); + params[0] = '['; + params[1] = '"'; + for (i=0; i<32; i++) + sprintf(¶ms[i*2 + 2],"%02x",((uint8_t *)&NOTARIZED_DESTTXID)[i]); + strcat(params,"\", 1]"); + //sprintf(params,"[\"%s\", 1]",NOTARIZED_DESTTXID.ToString().c_str()); printf("src.%s dest.%s params.[%s] ht.%d notarized.%d\n",symbol,dest,params,height,NOTARIZED_HEIGHT); if ( strcmp(dest,"KMD") == 0 ) { @@ -379,7 +384,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t { if ( BTCUSERPASS[0] != 0 ) { - printf("BTCUSERPASS.(%s)\n",BTCUSERPASS); + //printf("BTCUSERPASS.(%s)\n",BTCUSERPASS); jsonstr = komodo_issuemethod(BTCUSERPASS,(char *)"getrawtransaction",params,8332); } //else jsonstr = _dex_getrawtransaction(); diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 0364dcbf6..81a116eda 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1534,7 +1534,6 @@ void komodo_args() //printf("KOMODO.(%s) -> userpass.(%s)\n",fname,KMDUSERPASS); } else printf("couldnt open.(%s)\n",fname); } - printf("BTCUSERPASS.(%s)\n",BTCUSERPASS); } //fprintf(stderr,"%s chain params initialized\n",ASSETCHAINS_SYMBOL); } From 88432f13d49c8d79a7f31e09d4d09c715ee9c593 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 13:36:00 +0200 Subject: [PATCH 015/162] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 5956ae9f0..df9e68727 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -99,7 +99,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char if ( 0 && sp != 0 ) printf("%s load[%s.%d] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,notarized_height,notarized_hash.ToString().c_str()); //if ( matched != 0 ) global independent states -> inside *sp - if ( komodo_verifynotarization(symbol,dest,height,notarized_height,notarized_hash,notarized_desttxid) != 0 ) + if ( komodo_verifynotarization(symbol,dest,ht,notarized_height,notarized_hash,notarized_desttxid) != 0 ) printf("error validating notarization\n"); komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height); } From 731f2c845012fd9586c24ca38e3f3b1aa7958e1c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 13:36:22 +0200 Subject: [PATCH 016/162] test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 93fe2f05d..af2560837 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -365,7 +365,7 @@ int32_t komodo_verifynotarizedscript(uint8_t *script,int32_t len,uint256 NOTARIZ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t NOTARIZED_HEIGHT,uint256 NOTARIZED_HASH,uint256 NOTARIZED_DESTTXID) { - char params[256],*jsonstr,*hexstr; uint8_t script[8192]; int32_t n,len,retval = -1; cJSON *txjson,*vouts,*vout,*skey; + char params[256],*jsonstr,*hexstr; uint8_t script[8192]; int32_t i,n,len,retval = -1; cJSON *txjson,*vouts,*vout,*skey; params[0] = '['; params[1] = '"'; for (i=0; i<32; i++) From 13b64fd60662cd3dbb1cb90291072025c289629c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 13:40:20 +0200 Subject: [PATCH 017/162] test --- src/komodo.h | 2 -- src/komodo_bitcoind.h | 7 +++---- src/komodo_events.h | 21 +++++++++++++-------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index df9e68727..0036299e2 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -99,8 +99,6 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char if ( 0 && sp != 0 ) printf("%s load[%s.%d] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,notarized_height,notarized_hash.ToString().c_str()); //if ( matched != 0 ) global independent states -> inside *sp - if ( komodo_verifynotarization(symbol,dest,ht,notarized_height,notarized_hash,notarized_desttxid) != 0 ) - printf("error validating notarization\n"); komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height); } else if ( func == 'U' ) // deprecated diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index af2560837..dbbc5a178 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -365,7 +365,7 @@ int32_t komodo_verifynotarizedscript(uint8_t *script,int32_t len,uint256 NOTARIZ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t NOTARIZED_HEIGHT,uint256 NOTARIZED_HASH,uint256 NOTARIZED_DESTTXID) { - char params[256],*jsonstr,*hexstr; uint8_t script[8192]; int32_t i,n,len,retval = -1; cJSON *txjson,*vouts,*vout,*skey; + char params[256],*jsonstr,*hexstr; uint8_t script[8192]; int32_t i,n,len,retval = -1; cJSON *json,*txjson,*vouts,*vout,*skey; params[0] = '['; params[1] = '"'; for (i=0; i<32; i++) @@ -393,10 +393,9 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t else return(-1); if ( jsonstr != 0 ) { - printf("GOT.(%s)\n",jsonstr); - if ( (txjson= cJSON_Parse(jsonstr)) != 0 ) + if ( (json= cJSON_Parse(jsonstr)) != 0 ) { - if ( (vouts= jarray(&n,txjson,(char *)"vout")) > 0 ) + if ( (txjson= jobj(json,"result")) != 0 && (vouts= jarray(&n,txjson,(char *)"vout")) > 0 ) { vout = jitem(vouts,n-1); printf("vout.(%s)\n",jprint(vout,0)); diff --git a/src/komodo_events.h b/src/komodo_events.h index cb7861107..60fb6ad2c 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -39,14 +39,19 @@ struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t height,char *dest,uint256 notarized_hash,uint256 notarized_desttxid,int32_t notarizedheight) { struct komodo_event_notarized N; - memset(&N,0,sizeof(N)); - N.blockhash = notarized_hash; - N.desttxid = notarized_desttxid; - N.notarizedheight = notarizedheight; - strcpy(N.dest,dest); - komodo_eventadd(sp,height,symbol,KOMODO_EVENT_NOTARIZED,(uint8_t *)&N,sizeof(N)); - if ( sp != 0 ) - komodo_notarized_update(sp,height,notarizedheight,notarized_hash,notarized_desttxid); + if ( komodo_verifynotarization(symbol,dest,ht,notarized_height,notarized_hash,notarized_desttxid) != 0 ) + printf("error validating notarization\n"); + else + { + memset(&N,0,sizeof(N)); + N.blockhash = notarized_hash; + N.desttxid = notarized_desttxid; + N.notarizedheight = notarizedheight; + strcpy(N.dest,dest); + komodo_eventadd(sp,height,symbol,KOMODO_EVENT_NOTARIZED,(uint8_t *)&N,sizeof(N)); + if ( sp != 0 ) + komodo_notarized_update(sp,height,notarizedheight,notarized_hash,notarized_desttxid); + } } void komodo_eventadd_pubkeys(struct komodo_state *sp,char *symbol,int32_t height,uint8_t num,uint8_t pubkeys[64][33]) From 4a6c805b0d280cb3d609878de1e734f274b42364 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 13:41:35 +0200 Subject: [PATCH 018/162] test --- src/komodo_events.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_events.h b/src/komodo_events.h index 60fb6ad2c..0e600f32e 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -39,7 +39,7 @@ struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t height,char *dest,uint256 notarized_hash,uint256 notarized_desttxid,int32_t notarizedheight) { struct komodo_event_notarized N; - if ( komodo_verifynotarization(symbol,dest,ht,notarized_height,notarized_hash,notarized_desttxid) != 0 ) + if ( komodo_verifynotarization(symbol,dest,height,notarized_height,notarized_hash,notarized_desttxid) != 0 ) printf("error validating notarization\n"); else { From fa73aa673ed507b6896632246e79d14dc70c049d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 13:42:48 +0200 Subject: [PATCH 019/162] test --- src/komodo_bitcoind.h | 2 +- src/komodo_events.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index dbbc5a178..241e453b2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -395,7 +395,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t { if ( (json= cJSON_Parse(jsonstr)) != 0 ) { - if ( (txjson= jobj(json,"result")) != 0 && (vouts= jarray(&n,txjson,(char *)"vout")) > 0 ) + if ( (txjson= jobj(json,(char *)"result")) != 0 && (vouts= jarray(&n,txjson,(char *)"vout")) > 0 ) { vout = jitem(vouts,n-1); printf("vout.(%s)\n",jprint(vout,0)); diff --git a/src/komodo_events.h b/src/komodo_events.h index 0e600f32e..aeb038f99 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -39,7 +39,7 @@ struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t height,char *dest,uint256 notarized_hash,uint256 notarized_desttxid,int32_t notarizedheight) { struct komodo_event_notarized N; - if ( komodo_verifynotarization(symbol,dest,height,notarized_height,notarized_hash,notarized_desttxid) != 0 ) + if ( komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid) != 0 ) printf("error validating notarization\n"); else { From c315390018481a600154e810e0488f12d5ed5216 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 13:45:57 +0200 Subject: [PATCH 020/162] test --- src/komodo_bitcoind.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 241e453b2..f3d589c29 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -365,13 +365,13 @@ int32_t komodo_verifynotarizedscript(uint8_t *script,int32_t len,uint256 NOTARIZ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t NOTARIZED_HEIGHT,uint256 NOTARIZED_HASH,uint256 NOTARIZED_DESTTXID) { - char params[256],*jsonstr,*hexstr; uint8_t script[8192]; int32_t i,n,len,retval = -1; cJSON *json,*txjson,*vouts,*vout,*skey; - params[0] = '['; + char params[256],*jsonstr,*hexstr; uint8_t script[8192]; int32_t n,len,retval = -1; cJSON *json,*txjson,*vouts,*vout,*skey; + /*params[0] = '['; params[1] = '"'; for (i=0; i<32; i++) - sprintf(¶ms[i*2 + 2],"%02x",((uint8_t *)&NOTARIZED_DESTTXID)[i]); - strcat(params,"\", 1]"); - //sprintf(params,"[\"%s\", 1]",NOTARIZED_DESTTXID.ToString().c_str()); + sprintf(¶ms[i*2 + 2],"%02x",((uint8_t *)&NOTARIZED_DESTTXID)[31-i]); + strcat(params,"\", 1]");*/ + sprintf(params,"[\"%s\", 1]",NOTARIZED_DESTTXID.ToString().c_str()); printf("src.%s dest.%s params.[%s] ht.%d notarized.%d\n",symbol,dest,params,height,NOTARIZED_HEIGHT); if ( strcmp(dest,"KMD") == 0 ) { From ebd189442f629a8e451c2ae4aec682b0f70642e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 13:50:42 +0200 Subject: [PATCH 021/162] test --- src/komodo_bitcoind.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f3d589c29..7314557ad 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -354,8 +354,8 @@ int32_t komodo_verifynotarizedscript(uint8_t *script,int32_t len,uint256 NOTARIZ printf(" notarized, "); for (i=0; i<32; i++) { - ((uint8_t *)&hash)[i] = script[31+2-i]; - printf("%02x",script[31+2-i]); + ((uint8_t *)&hash)[i] = script[2+i]; + printf("%02x",script[2+i]); } printf(" <- opreturn?\n"); if ( hash == NOTARIZED_HASH ) @@ -398,12 +398,12 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t if ( (txjson= jobj(json,(char *)"result")) != 0 && (vouts= jarray(&n,txjson,(char *)"vout")) > 0 ) { vout = jitem(vouts,n-1); - printf("vout.(%s)\n",jprint(vout,0)); + //printf("vout.(%s)\n",jprint(vout,0)); if ( (skey= jobj(vout,(char *)"scriptPubKey")) != 0 ) { if ( (hexstr= jstr(skey,(char *)"hex")) != 0 ) { - printf("HEX.(%s)\n",hexstr); + //printf("HEX.(%s)\n",hexstr); len = strlen(hexstr) >> 1; decode_hex(script,len,hexstr); retval = komodo_verifynotarizedscript(script,len,NOTARIZED_HASH); From b556919ac5595058662d68ea6de9f4a98b1555dc Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 13:53:52 +0200 Subject: [PATCH 022/162] test --- src/komodo_bitcoind.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7314557ad..6927de309 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -349,18 +349,17 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) int32_t komodo_verifynotarizedscript(uint8_t *script,int32_t len,uint256 NOTARIZED_HASH) { int32_t i; uint256 hash; char params[256]; + for (i=0; i<32; i++) + ((uint8_t *)&hash)[i] = script[2+i]; + if ( hash == NOTARIZED_HASH ) + return(0); for (i=0; i<32; i++) printf("%02x",((uint8_t *)&NOTARIZED_HASH)[i]); printf(" notarized, "); for (i=0; i<32; i++) - { - ((uint8_t *)&hash)[i] = script[2+i]; - printf("%02x",script[2+i]); - } - printf(" <- opreturn?\n"); - if ( hash == NOTARIZED_HASH ) - return(0); - else return(-1); + printf("%02x",((uint8_t *)&hash)[i]); + printf(" opreturn\n"); + return(-1); } int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t NOTARIZED_HEIGHT,uint256 NOTARIZED_HASH,uint256 NOTARIZED_DESTTXID) @@ -372,7 +371,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t sprintf(¶ms[i*2 + 2],"%02x",((uint8_t *)&NOTARIZED_DESTTXID)[31-i]); strcat(params,"\", 1]");*/ sprintf(params,"[\"%s\", 1]",NOTARIZED_DESTTXID.ToString().c_str()); - printf("src.%s dest.%s params.[%s] ht.%d notarized.%d\n",symbol,dest,params,height,NOTARIZED_HEIGHT); + //printf("src.%s dest.%s params.[%s] ht.%d notarized.%d\n",symbol,dest,params,height,NOTARIZED_HEIGHT); if ( strcmp(dest,"KMD") == 0 ) { if ( KMDUSERPASS[0] != 0 ) From 1bb3eff053ebcdb9c7eb12b611a7c4834d01e51a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 13:59:14 +0200 Subject: [PATCH 023/162] test --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 6927de309..bda5b47b1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -351,14 +351,14 @@ int32_t komodo_verifynotarizedscript(uint8_t *script,int32_t len,uint256 NOTARIZ int32_t i; uint256 hash; char params[256]; for (i=0; i<32; i++) ((uint8_t *)&hash)[i] = script[2+i]; - if ( hash == NOTARIZED_HASH ) - return(0); for (i=0; i<32; i++) printf("%02x",((uint8_t *)&NOTARIZED_HASH)[i]); printf(" notarized, "); for (i=0; i<32; i++) printf("%02x",((uint8_t *)&hash)[i]); printf(" opreturn\n"); + if ( hash == NOTARIZED_HASH ) + return(0); return(-1); } From d56e594584182cd76002984b6f992106c33f0664 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 14:02:43 +0200 Subject: [PATCH 024/162] test --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index bda5b47b1..6927de309 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -351,14 +351,14 @@ int32_t komodo_verifynotarizedscript(uint8_t *script,int32_t len,uint256 NOTARIZ int32_t i; uint256 hash; char params[256]; for (i=0; i<32; i++) ((uint8_t *)&hash)[i] = script[2+i]; + if ( hash == NOTARIZED_HASH ) + return(0); for (i=0; i<32; i++) printf("%02x",((uint8_t *)&NOTARIZED_HASH)[i]); printf(" notarized, "); for (i=0; i<32; i++) printf("%02x",((uint8_t *)&hash)[i]); printf(" opreturn\n"); - if ( hash == NOTARIZED_HASH ) - return(0); return(-1); } From 9674c671d081ada9b19f18090e94cc5e7823a9ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 14:13:12 +0200 Subject: [PATCH 025/162] test --- src/komodo_bitcoind.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 6927de309..0a8cac099 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -358,7 +358,7 @@ int32_t komodo_verifynotarizedscript(uint8_t *script,int32_t len,uint256 NOTARIZ printf(" notarized, "); for (i=0; i<32; i++) printf("%02x",((uint8_t *)&hash)[i]); - printf(" opreturn\n"); + printf(" opreturn from [%s]\n",ASSETCHAINS_SYMBOL); return(-1); } @@ -389,7 +389,11 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t //else jsonstr = _dex_getrawtransaction(); else return(0); } - else return(-1); + else + { + printf("[%s] verifynotarization error unexpected dest.(%s)\n",ASSETCHAINS_SYMBOL,dest); + return(-1); + } if ( jsonstr != 0 ) { if ( (json= cJSON_Parse(jsonstr)) != 0 ) From 20a5cb84d97d278f8cd615545b9c2a6d66516d9c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 14:19:34 +0200 Subject: [PATCH 026/162] test --- src/komodo_bitcoind.h | 10 +++++----- src/komodo_events.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0a8cac099..1a8dd56a4 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -346,7 +346,7 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) return(retstr2); } -int32_t komodo_verifynotarizedscript(uint8_t *script,int32_t len,uint256 NOTARIZED_HASH) +int32_t komodo_verifynotarizedscript(int32_t height,uint8_t *script,int32_t len,uint256 NOTARIZED_HASH) { int32_t i; uint256 hash; char params[256]; for (i=0; i<32; i++) @@ -358,7 +358,7 @@ int32_t komodo_verifynotarizedscript(uint8_t *script,int32_t len,uint256 NOTARIZ printf(" notarized, "); for (i=0; i<32; i++) printf("%02x",((uint8_t *)&hash)[i]); - printf(" opreturn from [%s]\n",ASSETCHAINS_SYMBOL); + printf(" opreturn from [%s] ht.%d\n",ASSETCHAINS_SYMBOL,height); return(-1); } @@ -371,7 +371,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t sprintf(¶ms[i*2 + 2],"%02x",((uint8_t *)&NOTARIZED_DESTTXID)[31-i]); strcat(params,"\", 1]");*/ sprintf(params,"[\"%s\", 1]",NOTARIZED_DESTTXID.ToString().c_str()); - //printf("src.%s dest.%s params.[%s] ht.%d notarized.%d\n",symbol,dest,params,height,NOTARIZED_HEIGHT); + printf("src.%s dest.%s params.[%s] ht.%d notarized.%d\n",symbol,dest,params,height,NOTARIZED_HEIGHT); if ( strcmp(dest,"KMD") == 0 ) { if ( KMDUSERPASS[0] != 0 ) @@ -401,7 +401,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t if ( (txjson= jobj(json,(char *)"result")) != 0 && (vouts= jarray(&n,txjson,(char *)"vout")) > 0 ) { vout = jitem(vouts,n-1); - //printf("vout.(%s)\n",jprint(vout,0)); + printf("vout.(%s)\n",jprint(vout,0)); if ( (skey= jobj(vout,(char *)"scriptPubKey")) != 0 ) { if ( (hexstr= jstr(skey,(char *)"hex")) != 0 ) @@ -409,7 +409,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t //printf("HEX.(%s)\n",hexstr); len = strlen(hexstr) >> 1; decode_hex(script,len,hexstr); - retval = komodo_verifynotarizedscript(script,len,NOTARIZED_HASH); + retval = komodo_verifynotarizedscript(height,script,len,NOTARIZED_HASH); } } } diff --git a/src/komodo_events.h b/src/komodo_events.h index aeb038f99..d8aafb333 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -40,7 +40,7 @@ void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t heig { struct komodo_event_notarized N; if ( komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid) != 0 ) - printf("error validating notarization\n"); + printf("%s error validating notarization\n",ASSETCHAINS_SYMBOL); else { memset(&N,0,sizeof(N)); From 5697258b95fffc07ef253f728e33e484000352e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 14:28:09 +0200 Subject: [PATCH 027/162] test --- src/komodo_bitcoind.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1a8dd56a4..2af89b864 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -370,8 +370,10 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t for (i=0; i<32; i++) sprintf(¶ms[i*2 + 2],"%02x",((uint8_t *)&NOTARIZED_DESTTXID)[31-i]); strcat(params,"\", 1]");*/ + if ( strcmp(ASSETCHAINS_SYMBOL,symbol) != 0 ) + return(0); sprintf(params,"[\"%s\", 1]",NOTARIZED_DESTTXID.ToString().c_str()); - printf("src.%s dest.%s params.[%s] ht.%d notarized.%d\n",symbol,dest,params,height,NOTARIZED_HEIGHT); + printf("[%s] src.%s dest.%s params.[%s] ht.%d notarized.%d\n",ASSETCHAINS_SYMBOL,symbol,dest,params,height,NOTARIZED_HEIGHT); if ( strcmp(dest,"KMD") == 0 ) { if ( KMDUSERPASS[0] != 0 ) From 51ecd3f99f51c108c6a584eedb2c0f8b8a6b413e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 14:33:06 +0200 Subject: [PATCH 028/162] test --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2af89b864..70c363b29 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -373,7 +373,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t if ( strcmp(ASSETCHAINS_SYMBOL,symbol) != 0 ) return(0); sprintf(params,"[\"%s\", 1]",NOTARIZED_DESTTXID.ToString().c_str()); - printf("[%s] src.%s dest.%s params.[%s] ht.%d notarized.%d\n",ASSETCHAINS_SYMBOL,symbol,dest,params,height,NOTARIZED_HEIGHT); + //printf("[%s] src.%s dest.%s params.[%s] ht.%d notarized.%d\n",ASSETCHAINS_SYMBOL,symbol,dest,params,height,NOTARIZED_HEIGHT); if ( strcmp(dest,"KMD") == 0 ) { if ( KMDUSERPASS[0] != 0 ) @@ -403,7 +403,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t if ( (txjson= jobj(json,(char *)"result")) != 0 && (vouts= jarray(&n,txjson,(char *)"vout")) > 0 ) { vout = jitem(vouts,n-1); - printf("vout.(%s)\n",jprint(vout,0)); + //printf("vout.(%s)\n",jprint(vout,0)); if ( (skey= jobj(vout,(char *)"scriptPubKey")) != 0 ) { if ( (hexstr= jstr(skey,(char *)"hex")) != 0 ) From 447744dc8bcef41c278bcbd8dc4e531b70ac498e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 14:42:50 +0200 Subject: [PATCH 029/162] test --- src/komodo.h | 2 +- src/komodo_bitcoind.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 0036299e2..ed0d44f50 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -376,7 +376,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid); len += iguana_rwnum(0,&scriptbuf[len],sizeof(*notarizedheightp),(uint8_t *)notarizedheightp); len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid); - if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && (height < sp->CURRENT_HEIGHT-1000 || komodo_verifynotarization(symbol,dest,height,*notarizedheightp,kmdtxid,desttxid) == 0) ) + if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && (height < sp->CURRENT_HEIGHT-1000 || komodo_verifynotarization(ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,ASSETCHAINS_SYMBOL[0] == 0 ? "BTC" : "KMD",height,*notarizedheightp,kmdtxid,desttxid) == 0) ) { sp->NOTARIZED_HEIGHT = *notarizedheightp; sp->NOTARIZED_HASH = kmdtxid; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 70c363b29..3e5d3727e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -370,10 +370,10 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t for (i=0; i<32; i++) sprintf(¶ms[i*2 + 2],"%02x",((uint8_t *)&NOTARIZED_DESTTXID)[31-i]); strcat(params,"\", 1]");*/ + printf("[%s] src.%s dest.%s params.[%s] ht.%d notarized.%d\n",ASSETCHAINS_SYMBOL,symbol,dest,params,height,NOTARIZED_HEIGHT); if ( strcmp(ASSETCHAINS_SYMBOL,symbol) != 0 ) return(0); sprintf(params,"[\"%s\", 1]",NOTARIZED_DESTTXID.ToString().c_str()); - //printf("[%s] src.%s dest.%s params.[%s] ht.%d notarized.%d\n",ASSETCHAINS_SYMBOL,symbol,dest,params,height,NOTARIZED_HEIGHT); if ( strcmp(dest,"KMD") == 0 ) { if ( KMDUSERPASS[0] != 0 ) From 42af20bb9b86c6a723131c3c0ec6c2a198d2d7b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 14:44:36 +0200 Subject: [PATCH 030/162] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index ed0d44f50..9fe331708 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -376,7 +376,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid); len += iguana_rwnum(0,&scriptbuf[len],sizeof(*notarizedheightp),(uint8_t *)notarizedheightp); len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid); - if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && (height < sp->CURRENT_HEIGHT-1000 || komodo_verifynotarization(ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,ASSETCHAINS_SYMBOL[0] == 0 ? "BTC" : "KMD",height,*notarizedheightp,kmdtxid,desttxid) == 0) ) + if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && (height < sp->CURRENT_HEIGHT-1000 || komodo_verifynotarization(ASSETCHAINS_SYMBOL[0]==0?(char *)"KMD":ASSETCHAINS_SYMBOL,(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "BTC" : "KMD"),height,*notarizedheightp,kmdtxid,desttxid) == 0) ) { sp->NOTARIZED_HEIGHT = *notarizedheightp; sp->NOTARIZED_HASH = kmdtxid; From 67c0495a9dce1c143839a9637440f40c66df5e4a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 14:47:16 +0200 Subject: [PATCH 031/162] test --- src/komodo_bitcoind.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 3e5d3727e..f4e44e862 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -370,10 +370,8 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t for (i=0; i<32; i++) sprintf(¶ms[i*2 + 2],"%02x",((uint8_t *)&NOTARIZED_DESTTXID)[31-i]); strcat(params,"\", 1]");*/ - printf("[%s] src.%s dest.%s params.[%s] ht.%d notarized.%d\n",ASSETCHAINS_SYMBOL,symbol,dest,params,height,NOTARIZED_HEIGHT); - if ( strcmp(ASSETCHAINS_SYMBOL,symbol) != 0 ) - return(0); sprintf(params,"[\"%s\", 1]",NOTARIZED_DESTTXID.ToString().c_str()); + printf("[%s] src.%s dest.%s params.[%s] ht.%d notarized.%d\n",ASSETCHAINS_SYMBOL,symbol,dest,params,height,NOTARIZED_HEIGHT); if ( strcmp(dest,"KMD") == 0 ) { if ( KMDUSERPASS[0] != 0 ) From 81e91b43c1f35d000390dd4e10aff9c73ecd7b1d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 14:49:56 +0200 Subject: [PATCH 032/162] test --- src/komodo_events.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_events.h b/src/komodo_events.h index d8aafb333..e9c34576a 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -39,7 +39,7 @@ struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t height,char *dest,uint256 notarized_hash,uint256 notarized_desttxid,int32_t notarizedheight) { struct komodo_event_notarized N; - if ( komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid) != 0 ) + if ( komodo_verifynotarization(ASSETCHAINS_SYMBOL[0]==0?(char *)"KMD":ASSETCHAINS_SYMBOL,(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "BTC" : "KMD"),height,notarizedheight,notarized_hash,notarized_desttxid) != 0 ) printf("%s error validating notarization\n",ASSETCHAINS_SYMBOL); else { @@ -48,7 +48,7 @@ void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t heig N.desttxid = notarized_desttxid; N.notarizedheight = notarizedheight; strcpy(N.dest,dest); - komodo_eventadd(sp,height,symbol,KOMODO_EVENT_NOTARIZED,(uint8_t *)&N,sizeof(N)); + komodo_eventadd(sp,height,ASSETCHAINS_SYMBOL[0]==0?(char *)"KMD":ASSETCHAINS_SYMBOL,KOMODO_EVENT_NOTARIZED,(uint8_t *)&N,sizeof(N)); if ( sp != 0 ) komodo_notarized_update(sp,height,notarizedheight,notarized_hash,notarized_desttxid); } From ed9376455790481b7c07779dbcb4a562d31b9f1a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 14:53:36 +0200 Subject: [PATCH 033/162] test --- src/komodo_bitcoind.h | 3 +++ src/komodo_events.h | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f4e44e862..7b1435fa8 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -371,7 +371,10 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t sprintf(¶ms[i*2 + 2],"%02x",((uint8_t *)&NOTARIZED_DESTTXID)[31-i]); strcat(params,"\", 1]");*/ sprintf(params,"[\"%s\", 1]",NOTARIZED_DESTTXID.ToString().c_str()); + if ( strcmp(symbol,ASSETCHAINS_SYMBOL[0]==0?(char *)"KMD":ASSETCHAINS_SYMBOL) != 0 ) + return(0); printf("[%s] src.%s dest.%s params.[%s] ht.%d notarized.%d\n",ASSETCHAINS_SYMBOL,symbol,dest,params,height,NOTARIZED_HEIGHT); + if ( strcmp(dest,"KMD") == 0 ) { if ( KMDUSERPASS[0] != 0 ) diff --git a/src/komodo_events.h b/src/komodo_events.h index e9c34576a..d8aafb333 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -39,7 +39,7 @@ struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t height,char *dest,uint256 notarized_hash,uint256 notarized_desttxid,int32_t notarizedheight) { struct komodo_event_notarized N; - if ( komodo_verifynotarization(ASSETCHAINS_SYMBOL[0]==0?(char *)"KMD":ASSETCHAINS_SYMBOL,(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "BTC" : "KMD"),height,notarizedheight,notarized_hash,notarized_desttxid) != 0 ) + if ( komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid) != 0 ) printf("%s error validating notarization\n",ASSETCHAINS_SYMBOL); else { @@ -48,7 +48,7 @@ void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t heig N.desttxid = notarized_desttxid; N.notarizedheight = notarizedheight; strcpy(N.dest,dest); - komodo_eventadd(sp,height,ASSETCHAINS_SYMBOL[0]==0?(char *)"KMD":ASSETCHAINS_SYMBOL,KOMODO_EVENT_NOTARIZED,(uint8_t *)&N,sizeof(N)); + komodo_eventadd(sp,height,symbol,KOMODO_EVENT_NOTARIZED,(uint8_t *)&N,sizeof(N)); if ( sp != 0 ) komodo_notarized_update(sp,height,notarizedheight,notarized_hash,notarized_desttxid); } From dff9ec91d792ec6c17d865cecf797fe07f4424db Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 15:06:43 +0200 Subject: [PATCH 034/162] test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e00357ee7..a327ca08a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -763,7 +763,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 } } } - else if ( kmdheight > 91800 ) + else if ( kmdheight > 91800 && strcmp(base,ASSETCHAINS_SYMBOL) == 0 ) printf("pax %s deposit %.8f rejected kmdheight.%d %.8f KMD\n",base,dstr(fiatoshis),kmdheight,dstr(value)); } } @@ -965,7 +965,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { basesp->redeemed += value; pax->didstats = 1; - //if ( strcmp(CURRENCIES[baseids[i]],ASSETCHAINS_SYMBOL) == 0 ) + if ( strcmp(CURRENCIES[baseids[i]],ASSETCHAINS_SYMBOL) == 0 ) printf("ht.%d %.8f ########### %p redeemed %s += %.8f %.8f kht.%d ht.%d\n",height,dstr(value),basesp,CURRENCIES[baseids[i]],dstr(value),dstr(srcvalues[i]),kmdheights[i],otherheights[i]); } } From a82f9da16e6da87a5059fec92da6f7a9304c563a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 15:07:37 +0200 Subject: [PATCH 035/162] test --- src/komodo_bitcoind.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7b1435fa8..5af538d9b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -373,8 +373,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t sprintf(params,"[\"%s\", 1]",NOTARIZED_DESTTXID.ToString().c_str()); if ( strcmp(symbol,ASSETCHAINS_SYMBOL[0]==0?(char *)"KMD":ASSETCHAINS_SYMBOL) != 0 ) return(0); - printf("[%s] src.%s dest.%s params.[%s] ht.%d notarized.%d\n",ASSETCHAINS_SYMBOL,symbol,dest,params,height,NOTARIZED_HEIGHT); - + //printf("[%s] src.%s dest.%s params.[%s] ht.%d notarized.%d\n",ASSETCHAINS_SYMBOL,symbol,dest,params,height,NOTARIZED_HEIGHT); if ( strcmp(dest,"KMD") == 0 ) { if ( KMDUSERPASS[0] != 0 ) From 7641baed4d398793f268374ade92eb4a81253a1a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 15:16:56 +0200 Subject: [PATCH 036/162] test --- src/komodo_notary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index c4acbb44b..fc77d1222 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -13,7 +13,7 @@ * * ******************************************************************************/ -#define KOMODO_MAINNET_START 156999 +#define KOMODO_MAINNET_START 178999 const char *Notaries_genesis[][2] = { From 73678c97f56d61c78aa63d05e2e31f1a5923cf2f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jan 2017 18:08:50 +0200 Subject: [PATCH 037/162] test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a327ca08a..cef75d663 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -819,11 +819,11 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 } else if ( opretbuf[0] == 'W' )//&& opretlen >= 38 ) { - if ( komodo_baseid((char *)&opretbuf[opretlen-4]) >= 0 ) + if ( komodo_baseid((char *)&opretbuf[opretlen-4]) >= 0 && strcmp("KMD",(char *)&opretbuf[opretlen-4]) != 0 ) { for (i=0; i Date: Mon, 16 Jan 2017 18:12:35 +0200 Subject: [PATCH 038/162] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index cef75d663..007b16b0b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -823,7 +823,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { for (i=0; i Date: Tue, 17 Jan 2017 10:50:36 +0200 Subject: [PATCH 039/162] fix RWM3UrsRP4WtH6DTetm5KmUyBASvFCV6wH --- src/REVS.snapshot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/REVS.snapshot b/src/REVS.snapshot index 68a85514b..06c57a1f1 100644 --- a/src/REVS.snapshot +++ b/src/REVS.snapshot @@ -5443,7 +5443,7 @@ fiat/revs sendtoaddress RURYZ8FhS5oJ1h1xuv78EXe8rA32SiM4Dy 304.32862968 fiat/revs sendtoaddress RGba6AJogyFQGuMAzD1czE67KR6eW5PV2k 304.98070893 fiat/revs sendtoaddress RXMtwrMXyimRU5CWSdtWzHwWmcCeAc62ua 306.73973391 fiat/revs sendtoaddress RYEmXCS9D2qR71XKzzWbsiAMZGg5E2UWt3 307.15599818 -fiat/revs sendtoaddress RWM3UrsRP4WtH6DTetm5KmUyBASvFCV6wH 313.40690770 +fiat/revs sendtoaddress RWM3UrsRP4WtH6DTetm5KmUyBASvFCV6wH 3005.5069077 fiat/revs sendtoaddress RL4hFVzdntZQ2DM59QXZc619boZV45YFdk 316.05434626 fiat/revs sendtoaddress RG3vbi2TJp9jeqn8qDSnL1W5eFUeTGQJmu 317.33569076 fiat/revs sendtoaddress RQYgriDwRUuUbfw3E1AecAHZXryGSx1BdN 337.23469627 From 2f5fa4823acf097d947550fbee6de0b1300d0cb6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 17 Jan 2017 11:16:56 +0200 Subject: [PATCH 040/162] pause between assetchains --- src/assetchains | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/assetchains b/src/assetchains index ac817bde3..0533ed4cb 100755 --- a/src/assetchains +++ b/src/assetchains @@ -4,48 +4,90 @@ source pubkey.txt echo $pubkey ./komodod -pubkey=$pubkey -ac_name=REVS -ac_supply=1300000 -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=SUPERNET -ac_supply=816061 -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=DEX -ac_supply=999999 -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=PANGEA -ac_supply=999999 -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=JUMBLR -ac_supply=999999 -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=BET -ac_supply=999999 -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=CRYPTO -ac_supply=999999 -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=HODL -ac_supply=9999999 -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=SHARK -ac_supply=1401 -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=BOTS -ac_supply=999999 -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=MGW -ac_supply=999999 -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=MVP -ac_supply=1000000 -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=USD -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=EUR -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=JPY -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=GBP -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=AUD -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=CAD -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=CHF -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=NZD -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=CNY -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=RUB -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=MXN -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=BRL -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=INR -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=HKD -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=TRY -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=ZAR -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=PLN -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=NOK -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=SEK -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=DKK -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=CZK -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=HUF -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=ILS -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=KRW -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=MYR -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=PHP -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=RON -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=SGD -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=THB -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=BGN -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=IDR -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=HRK -addnode=78.47.196.146 $1 -gen & - From 112dc7b154cfee57bd0233a8847996edc8cf460f Mon Sep 17 00:00:00 2001 From: Joel Barker Date: Tue, 17 Jan 2017 12:51:38 +0000 Subject: [PATCH 041/162] added script to make static binaries for mac --- README-mac.md | 3 +++ makeDistrib.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100755 makeDistrib.sh diff --git a/README-mac.md b/README-mac.md index f6b6f8a10..c085cb617 100644 --- a/README-mac.md +++ b/README-mac.md @@ -26,6 +26,9 @@ cd komodo git checkout dev ./zcutil/build-mac.sh ``` + +To build a distributable version of komodo then run the makeDistrib.sh script after building. + When you are done building, you need to do a few things in the [Configuration](https://github.com/zcash/zcash/wiki/1.0-User-Guide#configuration) section of the Zcash User Guide differently because we are on the Mac. All instances of `~/.zcash` need to be replaced by `~/Library/Application\ Support/Zcash` The fetch-params.sh script, however, has already been altered to fetch the proving keys into the correct directory to conform to Mac specific naming conventions. diff --git a/makeDistrib.sh b/makeDistrib.sh new file mode 100755 index 000000000..ad72fbb16 --- /dev/null +++ b/makeDistrib.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +TMP_DIR=~/tmp/komodo + +# make a tmp directory +mkdir -p $TMP_DIR +echo "making $TMP_DIR" + +binaries=("komodo-cli" "komodod") + +for binary in "${binaries[@]}"; +do + echo "copying $binary to $TMP_DIR" + + cp src/$binary $TMP_DIR + + # find the dylibs to copy for komodod + DYLIBS=`otool -L $TMP_DIR/$binary | grep "/usr/local" | awk -F' ' '{ print $1 }'` + echo "copying $DYLIBS to $TMP_DIR" + + # copy the dylibs to the tmpdir + for dylib in $DYLIBS; do cp -rf $dylib $TMP_DIR/; done + + # modify komodod to point to dylibs + echo "modifying $binary to use local libraries" + for dylib in $DYLIBS; do install_name_tool -change $dylib @executable_path/`basename $dylib` $TMP_DIR/$binary; done; +done + + + + + + + + From eea23236bd7232167a0483802fe629cf62b5b56e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 13:04:53 +0200 Subject: [PATCH 042/162] ma60 paxprice --- src/REVS.snapshot | 2 +- src/komodo_pax.h | 20 +++++++++++++++++++- src/komodo_utils.h | 2 ++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/REVS.snapshot b/src/REVS.snapshot index 06c57a1f1..d150a91c1 100644 --- a/src/REVS.snapshot +++ b/src/REVS.snapshot @@ -5587,7 +5587,7 @@ fiat/revs sendtoaddress RWU752dM2s3sjpPZCaWpihUEYmbL6m7Pne 2537.07064054 fiat/revs sendtoaddress RTCq8NorFo4bNwUTNnyKg9YwYgxH49SbbY 2556.94031291 fiat/revs sendtoaddress RNiUNTzDtBgQyA64txPH3W7gMXAjJriM1T 2597.18712886 fiat/revs sendtoaddress RHuJvZphT6ZhKP3hxCRDDsCnNmCMtDy43r 2603.59182293 -fiat/revs sendtoaddress RKxJ7a2J8faQ7VD5dAyFFjMU9DxMDFqv3D 2692.10000000 +fiat/revs sendtoaddress RKxJ7a2J8faQ7VD5dAyFFjMU9DxMDFqv3D 1.10000000 fiat/revs sendtoaddress RGyC2cGKrTbv1zQq4f6fbMc2byCNdUAwBX 2700.00000000 fiat/revs sendtoaddress RWJPh9C4WQGuT8UDMXb4u278Teqzcq3zQt 2784.22122603 fiat/revs sendtoaddress RNjNREuiLJ3D5eWGqLcsMvjno5RBsBxqKN 2894.22787069 diff --git a/src/komodo_pax.h b/src/komodo_pax.h index cc835dc05..85212e593 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -451,7 +451,7 @@ uint64_t _komodo_paxprice(uint64_t *kmdbtcp,uint64_t *btcusdp,int32_t height,cha return(0); } -uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) +uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) { int32_t i,j,k,ind,zeroes,numvotes,wt,nonz; int64_t delta; uint64_t lastprice,tolerance,den,densum,sum=0,votes[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],btcusds[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],kmdbtcs[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],kmdbtc,btcusd; *seedp = komodo_seed(height); @@ -491,6 +491,24 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin return(komodo_paxcorrelation(votes,numvotes,*seedp) * basevolume / 100000); } +uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) +{ + int32_t i,nonz=0; uint64_t price,seed,sum = 0; + for (i=0; i<64; i++) + { + if ( (price= komodo_paxpriceB(&seed,height-i,base,rel,basevolume)) != 0 ) + { + sum += price; + nonz++; + } + if ( height < 150000 ) + break; + } + if ( nonz != 0 ) + sum /= nonz; + return(sum); +} + int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *base,char *rel) { int32_t baseid=-1,relid=-1,i,num = 0; uint32_t *ptr; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 81a116eda..57171e2cb 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1533,6 +1533,8 @@ void komodo_args() fclose(fp); //printf("KOMODO.(%s) -> userpass.(%s)\n",fname,KMDUSERPASS); } else printf("couldnt open.(%s)\n",fname); + if ( IS_KOMODO_NOTARY == 0 ) + break; } } //fprintf(stderr,"%s chain params initialized\n",ASSETCHAINS_SYMBOL); From 49db2cbbe10ab1f641fd96c99ac044cd21c41c52 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 13:35:32 +0200 Subject: [PATCH 043/162] test --- src/komodo_pax.h | 2 +- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 85212e593..159980cd7 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -501,7 +501,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin sum += price; nonz++; } - if ( height < 150000 ) + if ( height < 1500 ) // set to future height break; } if ( nonz != 0 ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 604391023..9a9bd637c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2510,7 +2510,7 @@ uint64_t komodo_interestsum() BOOST_FOREACH(const COutput& out,vecOutputs) { CAmount nValue = out.tx->vout[out.i].nValue; - if ( out.tx->nLockTime != 0 ) + if ( out.tx->nLockTime != 0 && out.fSpendable != 0 ) { BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); CBlockIndex *tipindex,*pindex = it->second; From e87f553f7d33e3992db57c9219b8be19abfa6997 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 13:46:36 +0200 Subject: [PATCH 044/162] test --- src/komodo_events.h | 2 +- src/komodo_pax.h | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/komodo_events.h b/src/komodo_events.h index d8aafb333..14a9478af 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -40,7 +40,7 @@ void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t heig { struct komodo_event_notarized N; if ( komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid) != 0 ) - printf("%s error validating notarization\n",ASSETCHAINS_SYMBOL); + printf("[%s] error validating notarization ht.%d notarized_height.%d\n",ASSETCHAINS_SYMBOL,height,notarizedheight); else { memset(&N,0,sizeof(N)); diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 159980cd7..3c06a5958 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -451,7 +451,7 @@ uint64_t _komodo_paxprice(uint64_t *kmdbtcp,uint64_t *btcusdp,int32_t height,cha return(0); } -uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) +uint64_t komodo_paxpriceC(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) { int32_t i,j,k,ind,zeroes,numvotes,wt,nonz; int64_t delta; uint64_t lastprice,tolerance,den,densum,sum=0,votes[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],btcusds[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],kmdbtcs[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],kmdbtc,btcusd; *seedp = komodo_seed(height); @@ -491,12 +491,28 @@ uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,ui return(komodo_paxcorrelation(votes,numvotes,*seedp) * basevolume / 100000); } +uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) +{ + int32_t i,nonz=0; uint64_t price,seed,sum = 0; + for (i=0; i<2; i++) + { + if ( (price= komodo_paxpriceC(&seed,height-i,base,rel,basevolume)) != 0 ) + { + sum += price; + nonz++; + } + } + if ( nonz != 0 ) + sum /= nonz; + return(sum); +} + uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) { int32_t i,nonz=0; uint64_t price,seed,sum = 0; - for (i=0; i<64; i++) + for (i=0; i<2; i++) { - if ( (price= komodo_paxpriceB(&seed,height-i,base,rel,basevolume)) != 0 ) + if ( (price= komodo_paxpriceB(&seed,height-i*16,base,rel,basevolume)) != 0 ) { sum += price; nonz++; From a8dabad5e6121fcce8fe3155799666d9edd8231c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 13:51:58 +0200 Subject: [PATCH 045/162] test --- src/komodo_pax.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 3c06a5958..595e8480a 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -494,7 +494,7 @@ uint64_t komodo_paxpriceC(uint64_t *seedp,int32_t height,char *base,char *rel,ui uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) { int32_t i,nonz=0; uint64_t price,seed,sum = 0; - for (i=0; i<2; i++) + for (i=0; i<3; i++) { if ( (price= komodo_paxpriceC(&seed,height-i,base,rel,basevolume)) != 0 ) { @@ -510,9 +510,9 @@ uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,ui uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) { int32_t i,nonz=0; uint64_t price,seed,sum = 0; - for (i=0; i<2; i++) + for (i=0; i<3; i++) { - if ( (price= komodo_paxpriceB(&seed,height-i*16,base,rel,basevolume)) != 0 ) + if ( (price= komodo_paxpriceB(&seed,height-i*17,base,rel,basevolume)) != 0 ) { sum += price; nonz++; From b21d816c5f62eacf99fc4618c69f3c000c55f18f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 13:55:30 +0200 Subject: [PATCH 046/162] test --- src/komodo_pax.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 595e8480a..ed4ef4d8d 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -494,7 +494,7 @@ uint64_t komodo_paxpriceC(uint64_t *seedp,int32_t height,char *base,char *rel,ui uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) { int32_t i,nonz=0; uint64_t price,seed,sum = 0; - for (i=0; i<3; i++) + for (i=0; i<2; i++) { if ( (price= komodo_paxpriceC(&seed,height-i,base,rel,basevolume)) != 0 ) { From d5a61fcabb6be8802ce2d289a8d083b06e9e7d4d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 14:00:28 +0200 Subject: [PATCH 047/162] test --- src/komodo_pax.h | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index ed4ef4d8d..b2ac8cad0 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -451,7 +451,7 @@ uint64_t _komodo_paxprice(uint64_t *kmdbtcp,uint64_t *btcusdp,int32_t height,cha return(0); } -uint64_t komodo_paxpriceC(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) +uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) { int32_t i,j,k,ind,zeroes,numvotes,wt,nonz; int64_t delta; uint64_t lastprice,tolerance,den,densum,sum=0,votes[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],btcusds[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],kmdbtcs[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],kmdbtc,btcusd; *seedp = komodo_seed(height); @@ -491,28 +491,12 @@ uint64_t komodo_paxpriceC(uint64_t *seedp,int32_t height,char *base,char *rel,ui return(komodo_paxcorrelation(votes,numvotes,*seedp) * basevolume / 100000); } -uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) -{ - int32_t i,nonz=0; uint64_t price,seed,sum = 0; - for (i=0; i<2; i++) - { - if ( (price= komodo_paxpriceC(&seed,height-i,base,rel,basevolume)) != 0 ) - { - sum += price; - nonz++; - } - } - if ( nonz != 0 ) - sum /= nonz; - return(sum); -} - uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) { int32_t i,nonz=0; uint64_t price,seed,sum = 0; - for (i=0; i<3; i++) + for (i=0; i<16; i++) { - if ( (price= komodo_paxpriceB(&seed,height-i*17,base,rel,basevolume)) != 0 ) + if ( (price= komodo_paxpriceB(&seed,height-i,base,rel,basevolume)) != 0 ) { sum += price; nonz++; From bba30a43a5998b1e9aa9211136a097b008c8d905 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 14:05:01 +0200 Subject: [PATCH 048/162] test --- src/komodo_pax.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index b2ac8cad0..700546453 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -429,7 +429,7 @@ uint64_t _komodo_paxprice(uint64_t *kmdbtcp,uint64_t *btcusdp,int32_t height,cha height -= 10; if ( (baseid= komodo_baseid(base)) >= 0 && (relid= komodo_baseid(rel)) >= 0 ) { - portable_mutex_lock(&komodo_mutex); + //portable_mutex_lock(&komodo_mutex); for (i=NUM_PRICES-1; i>=0; i--) { ptr = &PVALS[36 * i]; @@ -440,13 +440,13 @@ uint64_t _komodo_paxprice(uint64_t *kmdbtcp,uint64_t *btcusdp,int32_t height,cha *kmdbtcp = ptr[MAX_CURRENCIES + 1] / 539; *btcusdp = ptr[MAX_CURRENCIES + 2] / 539; } - portable_mutex_unlock(&komodo_mutex); + //portable_mutex_unlock(&komodo_mutex); if ( kmdbtc != 0 && btcusd != 0 ) return(komodo_paxcalc(&ptr[1],baseid,relid,basevolume,kmdbtc,btcusd)); else return(0); } } - portable_mutex_unlock(&komodo_mutex); + //portable_mutex_unlock(&komodo_mutex); } //else printf("paxprice invalid base.%s %d, rel.%s %d\n",base,baseid,rel,relid); return(0); } @@ -494,7 +494,8 @@ uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,ui uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) { int32_t i,nonz=0; uint64_t price,seed,sum = 0; - for (i=0; i<16; i++) + portable_mutex_lock(&komodo_mutex); + for (i=0; i<64; i++) { if ( (price= komodo_paxpriceB(&seed,height-i,base,rel,basevolume)) != 0 ) { @@ -504,6 +505,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin if ( height < 1500 ) // set to future height break; } + portable_mutex_unlock(&komodo_mutex); if ( nonz != 0 ) sum /= nonz; return(sum); From e08169c4b32ff4a031b8172ee5d45da0bf16e928 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 14:18:28 +0200 Subject: [PATCH 049/162] test --- src/komodo_pax.h | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 700546453..063a12636 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -451,6 +451,32 @@ uint64_t _komodo_paxprice(uint64_t *kmdbtcp,uint64_t *btcusdp,int32_t height,cha return(0); } +int32_t komodo_kmdbtcusd(int32_t rwflag,uint64_t *kmdbtcp,uint64_t *btcusdp,int32_t height) +{ + static uint64_t *KMDBTCS,*BTCUSDS; static int32_t maxheight; int32_t incr = 10000; + if ( height >= maxheight ) + { + KMDBTCS = realloc(KMDBTCS,((incr + maxheight) * sizeof(*KMDBTCS))); + memset(&KMDBTCS[maxheight],0,(incr * sizeof(*KMDBTCS))); + BTCUSDS = realloc(BTCUSDS,((incr + maxheight) * sizeof(*BTCUSDS))); + memset(&BTCUSDS[maxheight],0,(incr * sizeof(*BTCUSDS))); + maxheight += incr; + } + if ( rwflag == 0 ) + { + *kmdbtcp = KMDBTCS[height]; + *btcusdp = BTCUSDS[height]; + } + else + { + KMDBTCS[height] = *kmdbtcp; + BTCUSDS[height] = *btcusdp; + } + if ( *kmdbtcp != 0 && *btcusdp != 0 ) + return(0); + else return(-1); +} + uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) { int32_t i,j,k,ind,zeroes,numvotes,wt,nonz; int64_t delta; uint64_t lastprice,tolerance,den,densum,sum=0,votes[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],btcusds[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],kmdbtcs[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],kmdbtc,btcusd; @@ -467,15 +493,19 @@ uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,ui } numvotes = (int32_t)(sizeof(Peggy_inds)/sizeof(*Peggy_inds)); memset(votes,0,sizeof(votes)); - memset(btcusds,0,sizeof(btcusds)); - memset(kmdbtcs,0,sizeof(kmdbtcs)); - for (i=0; i Date: Wed, 18 Jan 2017 14:29:36 +0200 Subject: [PATCH 050/162] test --- src/komodo_pax.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 063a12636..86a07adbb 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -493,7 +493,7 @@ uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,ui } numvotes = (int32_t)(sizeof(Peggy_inds)/sizeof(*Peggy_inds)); memset(votes,0,sizeof(votes)); - if ( komodo_kmdbtcusd(0,&kmdbtc,&btcusd,height) < 0 ) + //if ( komodo_kmdbtcusd(0,&kmdbtc,&btcusd,height) < 0 ) { memset(btcusds,0,sizeof(btcusds)); memset(kmdbtcs,0,sizeof(kmdbtcs)); @@ -504,7 +504,7 @@ uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,ui } kmdbtc = komodo_paxcorrelation(kmdbtcs,numvotes,*seedp) * 539; btcusd = komodo_paxcorrelation(btcusds,numvotes,*seedp) * 539; - komodo_kmdbtcusd(1,&kmdbtc,&btcusd,height); + //komodo_kmdbtcusd(1,&kmdbtc,&btcusd,height); } for (i=nonz=0; i> 1)) * SATOSHIDEN) / price; + if ( diff < 0 ) + diff = -diff; + if ( diff < (SATOSHIDEN / 1000) ) + break; + } } portable_mutex_unlock(&komodo_mutex); if ( nonz != 0 ) From acd6ccf4629427e6b08febf8a787021842b1a64f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 14:35:55 +0200 Subject: [PATCH 051/162] test --- src/komodo_pax.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 86a07adbb..1653a381e 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -523,7 +523,7 @@ uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,ui uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) { - int32_t i,nonz=0; uint64_t price,seed,sum = 0; + int32_t i,nonz=0; int64_t diff; uint64_t price,seed,sum = 0; portable_mutex_lock(&komodo_mutex); for (i=0; i<64; i++) { @@ -532,8 +532,8 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin sum += price; nonz++; } - if ( height < KOMODO_MAINNET_START ) - break; + //if ( height < KOMODO_MAINNET_START ) + // break; if ( i == 1 && nonz == 2 ) { diff = ((price - (sum >> 1)) * SATOSHIDEN) / price; From c9da2420936d803cc4cedc11d88f6979340b28e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 14:37:35 +0200 Subject: [PATCH 052/162] test --- src/komodo_pax.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 1653a381e..9c90a6649 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -456,9 +456,9 @@ int32_t komodo_kmdbtcusd(int32_t rwflag,uint64_t *kmdbtcp,uint64_t *btcusdp,int3 static uint64_t *KMDBTCS,*BTCUSDS; static int32_t maxheight; int32_t incr = 10000; if ( height >= maxheight ) { - KMDBTCS = realloc(KMDBTCS,((incr + maxheight) * sizeof(*KMDBTCS))); + KMDBTCS = (uint64_t *)realloc(KMDBTCS,((incr + maxheight) * sizeof(*KMDBTCS))); memset(&KMDBTCS[maxheight],0,(incr * sizeof(*KMDBTCS))); - BTCUSDS = realloc(BTCUSDS,((incr + maxheight) * sizeof(*BTCUSDS))); + BTCUSDS = (uint64_t *)realloc(BTCUSDS,((incr + maxheight) * sizeof(*BTCUSDS))); memset(&BTCUSDS[maxheight],0,(incr * sizeof(*BTCUSDS))); maxheight += incr; } @@ -493,7 +493,7 @@ uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,ui } numvotes = (int32_t)(sizeof(Peggy_inds)/sizeof(*Peggy_inds)); memset(votes,0,sizeof(votes)); - //if ( komodo_kmdbtcusd(0,&kmdbtc,&btcusd,height) < 0 ) + if ( komodo_kmdbtcusd(0,&kmdbtc,&btcusd,height) < 0 ) { memset(btcusds,0,sizeof(btcusds)); memset(kmdbtcs,0,sizeof(kmdbtcs)); @@ -504,7 +504,7 @@ uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,ui } kmdbtc = komodo_paxcorrelation(kmdbtcs,numvotes,*seedp) * 539; btcusd = komodo_paxcorrelation(btcusds,numvotes,*seedp) * 539; - //komodo_kmdbtcusd(1,&kmdbtc,&btcusd,height); + komodo_kmdbtcusd(1,&kmdbtc,&btcusd,height); } for (i=nonz=0; i Date: Wed, 18 Jan 2017 14:43:23 +0200 Subject: [PATCH 053/162] test --- src/komodo_pax.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 9c90a6649..401de3019 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -453,9 +453,11 @@ uint64_t _komodo_paxprice(uint64_t *kmdbtcp,uint64_t *btcusdp,int32_t height,cha int32_t komodo_kmdbtcusd(int32_t rwflag,uint64_t *kmdbtcp,uint64_t *btcusdp,int32_t height) { - static uint64_t *KMDBTCS,*BTCUSDS; static int32_t maxheight; int32_t incr = 10000; + static uint64_t *KMDBTCS,*BTCUSDS; static int32_t maxheight = -1; int32_t incr = 10000; if ( height >= maxheight ) { + if ( height >= maxheight+incr ) + incr = (height - (maxheight+incr) + 1000); KMDBTCS = (uint64_t *)realloc(KMDBTCS,((incr + maxheight) * sizeof(*KMDBTCS))); memset(&KMDBTCS[maxheight],0,(incr * sizeof(*KMDBTCS))); BTCUSDS = (uint64_t *)realloc(BTCUSDS,((incr + maxheight) * sizeof(*BTCUSDS))); From f6f2beb9a527fdeaa7fb91087ea77f73476ab200 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 14:46:35 +0200 Subject: [PATCH 054/162] test --- src/komodo_pax.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 401de3019..3c1e0aee8 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -456,6 +456,7 @@ int32_t komodo_kmdbtcusd(int32_t rwflag,uint64_t *kmdbtcp,uint64_t *btcusdp,int3 static uint64_t *KMDBTCS,*BTCUSDS; static int32_t maxheight = -1; int32_t incr = 10000; if ( height >= maxheight ) { + printf("height.%d maxheight.%d incr.%d\n",height,maxheight,incr); if ( height >= maxheight+incr ) incr = (height - (maxheight+incr) + 1000); KMDBTCS = (uint64_t *)realloc(KMDBTCS,((incr + maxheight) * sizeof(*KMDBTCS))); From 703cc8c9bb351ac58f38985ffb9f97babb4e86d2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 14:48:03 +0200 Subject: [PATCH 055/162] test --- src/komodo_pax.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 3c1e0aee8..329d26e10 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -453,7 +453,7 @@ uint64_t _komodo_paxprice(uint64_t *kmdbtcp,uint64_t *btcusdp,int32_t height,cha int32_t komodo_kmdbtcusd(int32_t rwflag,uint64_t *kmdbtcp,uint64_t *btcusdp,int32_t height) { - static uint64_t *KMDBTCS,*BTCUSDS; static int32_t maxheight = -1; int32_t incr = 10000; + static uint64_t *KMDBTCS,*BTCUSDS; static int32_t maxheight = 0; int32_t incr = 10000; if ( height >= maxheight ) { printf("height.%d maxheight.%d incr.%d\n",height,maxheight,incr); From 86600f3bdf3e32a90aea5401c31a858ac312427e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 14:53:00 +0200 Subject: [PATCH 056/162] test --- src/komodo_pax.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 329d26e10..4a881d856 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -542,7 +542,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin diff = ((price - (sum >> 1)) * SATOSHIDEN) / price; if ( diff < 0 ) diff = -diff; - if ( diff < (SATOSHIDEN / 1000) ) + if ( diff < (SATOSHIDEN / 333) ) break; } } From 108542828359c8602c3b1536a74fa61296c67cb1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 14:54:25 +0200 Subject: [PATCH 057/162] test --- src/komodo_pax.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 4a881d856..e6452bc9c 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -527,6 +527,8 @@ uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,ui uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) { int32_t i,nonz=0; int64_t diff; uint64_t price,seed,sum = 0; + if ( height > chainActive.Tip()->nHeight ) + return(0); portable_mutex_lock(&komodo_mutex); for (i=0; i<64; i++) { From 5218a9c4392fa4987e082b09ec6340891d5d4f6d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 14:57:48 +0200 Subject: [PATCH 058/162] test --- src/komodo_pax.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index e6452bc9c..a07d17b0e 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -530,7 +530,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin if ( height > chainActive.Tip()->nHeight ) return(0); portable_mutex_lock(&komodo_mutex); - for (i=0; i<64; i++) + for (i=0; i<32; i++) { if ( (price= komodo_paxpriceB(&seed,height-i,base,rel,basevolume)) != 0 ) { @@ -544,13 +544,24 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin diff = ((price - (sum >> 1)) * SATOSHIDEN) / price; if ( diff < 0 ) diff = -diff; + printf("%lld ",(long long)diff); if ( diff < (SATOSHIDEN / 333) ) break; } + else if ( i == 3 && nonz == 4 ) + { + diff = ((price - (sum >> 2)) * SATOSHIDEN) / price; + if ( diff < 0 ) + diff = -diff; + printf("%lld ",(long long)diff); + if ( diff < (SATOSHIDEN / 500) ) + break; + } } portable_mutex_unlock(&komodo_mutex); if ( nonz != 0 ) sum /= nonz; + printf("-> %lld\n",(long long)sum); return(sum); } From 1f2ae07564b85cbfe6b455c04a41128294271207 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 15:01:38 +0200 Subject: [PATCH 059/162] test --- src/komodo_pax.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index a07d17b0e..352408cfd 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -527,7 +527,7 @@ uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,ui uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) { int32_t i,nonz=0; int64_t diff; uint64_t price,seed,sum = 0; - if ( height > chainActive.Tip()->nHeight ) + if ( chainActive.Tip() != 0 && height > chainActive.Tip()->nHeight ) return(0); portable_mutex_lock(&komodo_mutex); for (i=0; i<32; i++) From e8bd824b16d128fdf0c198a9b900cd5baf3aeae8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 15:06:25 +0200 Subject: [PATCH 060/162] test --- src/komodo_pax.h | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 352408cfd..070ef4eba 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -536,27 +536,27 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin { sum += price; nonz++; + if ( i == 1 && nonz == 2 ) + { + diff = ((price - (sum >> 1)) * SATOSHIDEN) / price; + if ( diff < 0 ) + diff = -diff; + if ( diff < (SATOSHIDEN / 333) ) + break; + else printf("(%llu %llu).%lld ",price,sum>>1,diff); + } + else if ( i == 3 && nonz == 4 ) + { + diff = ((price - (sum >> 2)) * SATOSHIDEN) / price; + if ( diff < 0 ) + diff = -diff; + if ( diff < (SATOSHIDEN / 500) ) + break; + else printf("(%llu %llu).%lld ",price,sum>>2,diff); + } } //if ( height < KOMODO_MAINNET_START ) // break; - if ( i == 1 && nonz == 2 ) - { - diff = ((price - (sum >> 1)) * SATOSHIDEN) / price; - if ( diff < 0 ) - diff = -diff; - printf("%lld ",(long long)diff); - if ( diff < (SATOSHIDEN / 333) ) - break; - } - else if ( i == 3 && nonz == 4 ) - { - diff = ((price - (sum >> 2)) * SATOSHIDEN) / price; - if ( diff < 0 ) - diff = -diff; - printf("%lld ",(long long)diff); - if ( diff < (SATOSHIDEN / 500) ) - break; - } } portable_mutex_unlock(&komodo_mutex); if ( nonz != 0 ) From 7bdc3386a77d221117bafa886a30c3043ad4a3f9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 15:08:03 +0200 Subject: [PATCH 061/162] test --- src/komodo_pax.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 070ef4eba..28f2497b3 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -543,7 +543,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin diff = -diff; if ( diff < (SATOSHIDEN / 333) ) break; - else printf("(%llu %llu).%lld ",price,sum>>1,diff); + else printf("(%llu %llu).%lld ",(long long)price,(long long)(sum>>1),(long long)diff); } else if ( i == 3 && nonz == 4 ) { @@ -552,7 +552,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin diff = -diff; if ( diff < (SATOSHIDEN / 500) ) break; - else printf("(%llu %llu).%lld ",price,sum>>2,diff); + else printf("(%llu %llu).%lld ",(long long)price,(long long)(sum>>2),(long long)diff); } } //if ( height < KOMODO_MAINNET_START ) From f63b4a4660c322fb3df14f64571ce184b2f4915c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 15:13:16 +0200 Subject: [PATCH 062/162] test --- src/komodo_pax.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 28f2497b3..f19b65817 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -538,19 +538,19 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin nonz++; if ( i == 1 && nonz == 2 ) { - diff = ((price - (sum >> 1)) * SATOSHIDEN) / price; + diff = ((price - (sum >> 1)) * 10000) / price; if ( diff < 0 ) diff = -diff; - if ( diff < (SATOSHIDEN / 333) ) + if ( diff < 50 ) break; else printf("(%llu %llu).%lld ",(long long)price,(long long)(sum>>1),(long long)diff); } else if ( i == 3 && nonz == 4 ) { - diff = ((price - (sum >> 2)) * SATOSHIDEN) / price; + diff = ((price - (sum >> 2)) * 10000) / price; if ( diff < 0 ) diff = -diff; - if ( diff < (SATOSHIDEN / 500) ) + if ( diff < 40 ) break; else printf("(%llu %llu).%lld ",(long long)price,(long long)(sum>>2),(long long)diff); } From d19f6c0e02793b781efd23f52654303908e1c6ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 15:18:56 +0200 Subject: [PATCH 063/162] test --- src/komodo_pax.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index f19b65817..60bf523cf 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -538,21 +538,21 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin nonz++; if ( i == 1 && nonz == 2 ) { - diff = ((price - (sum >> 1)) * 10000) / price; + diff = (((int64_t)price - (sum >> 1)) * 10000) / price; if ( diff < 0 ) diff = -diff; + printf("(%llu %llu %lld).%lld ",(long long)price,(long long)(sum>>1),(long long)(((int64_t)price - (sum >> 1)) * 10000),(long long)diff); if ( diff < 50 ) break; - else printf("(%llu %llu).%lld ",(long long)price,(long long)(sum>>1),(long long)diff); } else if ( i == 3 && nonz == 4 ) { - diff = ((price - (sum >> 2)) * 10000) / price; + diff = (((int64_t)price - (sum >> 2)) * 10000) / price; if ( diff < 0 ) diff = -diff; + printf("(%llu %llu).%lld ",(long long)price,(long long)(sum>>2),(long long)diff); if ( diff < 40 ) break; - else printf("(%llu %llu).%lld ",(long long)price,(long long)(sum>>2),(long long)diff); } } //if ( height < KOMODO_MAINNET_START ) From 395fae6b5dbe216dea628248d0dfd0df8d597db3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 15:23:10 +0200 Subject: [PATCH 064/162] test --- src/komodo_pax.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 60bf523cf..ec7026fb6 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -538,19 +538,21 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin nonz++; if ( i == 1 && nonz == 2 ) { - diff = (((int64_t)price - (sum >> 1)) * 10000) / price; + diff = (((int64_t)price - (sum >> 1)) * 10000); if ( diff < 0 ) diff = -diff; + diff /= price; printf("(%llu %llu %lld).%lld ",(long long)price,(long long)(sum>>1),(long long)(((int64_t)price - (sum >> 1)) * 10000),(long long)diff); if ( diff < 50 ) break; } else if ( i == 3 && nonz == 4 ) { - diff = (((int64_t)price - (sum >> 2)) * 10000) / price; + diff = (((int64_t)price - (sum >> 2)) * 10000); if ( diff < 0 ) diff = -diff; - printf("(%llu %llu).%lld ",(long long)price,(long long)(sum>>2),(long long)diff); + diff /= price; + printf("(%llu %llu %lld).%lld ",(long long)price,(long long)(sum>>2),(long long) (((int64_t)price - (sum >> 2)) * 10000),(long long)diff); if ( diff < 40 ) break; } From e24bce329e860ed43f096c5c37ecae49ef859789 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 15:25:19 +0200 Subject: [PATCH 065/162] test --- src/komodo_pax.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index ec7026fb6..bc6108868 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -542,7 +542,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin if ( diff < 0 ) diff = -diff; diff /= price; - printf("(%llu %llu %lld).%lld ",(long long)price,(long long)(sum>>1),(long long)(((int64_t)price - (sum >> 1)) * 10000),(long long)diff); + //printf("(%llu %llu %lld).%lld ",(long long)price,(long long)(sum>>1),(long long)(((int64_t)price - (sum >> 1)) * 10000),(long long)diff); if ( diff < 50 ) break; } @@ -552,7 +552,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin if ( diff < 0 ) diff = -diff; diff /= price; - printf("(%llu %llu %lld).%lld ",(long long)price,(long long)(sum>>2),(long long) (((int64_t)price - (sum >> 2)) * 10000),(long long)diff); + //printf("(%llu %llu %lld).%lld ",(long long)price,(long long)(sum>>2),(long long) (((int64_t)price - (sum >> 2)) * 10000),(long long)diff); if ( diff < 40 ) break; } @@ -563,7 +563,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin portable_mutex_unlock(&komodo_mutex); if ( nonz != 0 ) sum /= nonz; - printf("-> %lld\n",(long long)sum); + //printf("-> %lld\n",(long long)sum); return(sum); } From f12b4a5989ff8236c106a1259c1535a13445e9ae Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 15:27:11 +0200 Subject: [PATCH 066/162] test --- src/komodo_pax.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index bc6108868..c6200d048 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -543,7 +543,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin diff = -diff; diff /= price; //printf("(%llu %llu %lld).%lld ",(long long)price,(long long)(sum>>1),(long long)(((int64_t)price - (sum >> 1)) * 10000),(long long)diff); - if ( diff < 50 ) + if ( diff < 20 ) break; } else if ( i == 3 && nonz == 4 ) @@ -553,7 +553,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin diff = -diff; diff /= price; //printf("(%llu %llu %lld).%lld ",(long long)price,(long long)(sum>>2),(long long) (((int64_t)price - (sum >> 2)) * 10000),(long long)diff); - if ( diff < 40 ) + if ( diff < 25 ) break; } } From d854fae228a28ea923e01ad33b4643601793464b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 15:30:52 +0200 Subject: [PATCH 067/162] test --- src/komodo_pax.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index c6200d048..722a99c57 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -456,7 +456,7 @@ int32_t komodo_kmdbtcusd(int32_t rwflag,uint64_t *kmdbtcp,uint64_t *btcusdp,int3 static uint64_t *KMDBTCS,*BTCUSDS; static int32_t maxheight = 0; int32_t incr = 10000; if ( height >= maxheight ) { - printf("height.%d maxheight.%d incr.%d\n",height,maxheight,incr); + //printf("height.%d maxheight.%d incr.%d\n",height,maxheight,incr); if ( height >= maxheight+incr ) incr = (height - (maxheight+incr) + 1000); KMDBTCS = (uint64_t *)realloc(KMDBTCS,((incr + maxheight) * sizeof(*KMDBTCS))); @@ -543,7 +543,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin diff = -diff; diff /= price; //printf("(%llu %llu %lld).%lld ",(long long)price,(long long)(sum>>1),(long long)(((int64_t)price - (sum >> 1)) * 10000),(long long)diff); - if ( diff < 20 ) + if ( diff < 10 ) break; } else if ( i == 3 && nonz == 4 ) @@ -553,7 +553,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin diff = -diff; diff /= price; //printf("(%llu %llu %lld).%lld ",(long long)price,(long long)(sum>>2),(long long) (((int64_t)price - (sum >> 2)) * 10000),(long long)diff); - if ( diff < 25 ) + if ( diff < 15 ) break; } } From 4f8c77e95cffc56f0e5bffda0a4dbbfad80b361d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 15:35:03 +0200 Subject: [PATCH 068/162] test --- src/komodo_pax.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 722a99c57..abd85d5f8 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -530,7 +530,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin if ( chainActive.Tip() != 0 && height > chainActive.Tip()->nHeight ) return(0); portable_mutex_lock(&komodo_mutex); - for (i=0; i<32; i++) + for (i=0; i<64; i++) { if ( (price= komodo_paxpriceB(&seed,height-i,base,rel,basevolume)) != 0 ) { @@ -553,7 +553,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin diff = -diff; diff /= price; //printf("(%llu %llu %lld).%lld ",(long long)price,(long long)(sum>>2),(long long) (((int64_t)price - (sum >> 2)) * 10000),(long long)diff); - if ( diff < 15 ) + if ( diff < 9 ) break; } } From 6b9b9aca38103206b4cd5ba0335ff34eb5b84aa5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 15:41:13 +0200 Subject: [PATCH 069/162] test --- src/komodo_pax.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index abd85d5f8..f112bbd46 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -530,7 +530,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin if ( chainActive.Tip() != 0 && height > chainActive.Tip()->nHeight ) return(0); portable_mutex_lock(&komodo_mutex); - for (i=0; i<64; i++) + for (i=0; i<32; i++) { if ( (price= komodo_paxpriceB(&seed,height-i,base,rel,basevolume)) != 0 ) { @@ -542,8 +542,8 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin if ( diff < 0 ) diff = -diff; diff /= price; - //printf("(%llu %llu %lld).%lld ",(long long)price,(long long)(sum>>1),(long long)(((int64_t)price - (sum >> 1)) * 10000),(long long)diff); - if ( diff < 10 ) + printf("(%llu %llu %lld).%lld ",(long long)price,(long long)(sum>>1),(long long)(((int64_t)price - (sum >> 1)) * 10000),(long long)diff); + if ( diff < 33 ) break; } else if ( i == 3 && nonz == 4 ) @@ -552,8 +552,8 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin if ( diff < 0 ) diff = -diff; diff /= price; - //printf("(%llu %llu %lld).%lld ",(long long)price,(long long)(sum>>2),(long long) (((int64_t)price - (sum >> 2)) * 10000),(long long)diff); - if ( diff < 9 ) + printf("(%llu %llu %lld).%lld ",(long long)price,(long long)(sum>>2),(long long) (((int64_t)price - (sum >> 2)) * 10000),(long long)diff); + if ( diff < 20 ) break; } } From bebd2d5c80bb9beb742b17f489e85310c85c8fe5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 15:44:15 +0200 Subject: [PATCH 070/162] test --- src/komodo_pax.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index f112bbd46..dc0d2b804 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -563,7 +563,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin portable_mutex_unlock(&komodo_mutex); if ( nonz != 0 ) sum /= nonz; - //printf("-> %lld\n",(long long)sum); + printf("-> %lld %s/%s\n",(long long)sum,base,rel); return(sum); } From fd801c67b3d48d42943128785af3374c2406b192 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 15:48:49 +0200 Subject: [PATCH 071/162] test --- src/komodo_pax.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index dc0d2b804..f3d1f7262 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -536,7 +536,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin { sum += price; nonz++; - if ( i == 1 && nonz == 2 ) + if ( 0 && i == 1 && nonz == 2 ) { diff = (((int64_t)price - (sum >> 1)) * 10000); if ( diff < 0 ) @@ -563,7 +563,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin portable_mutex_unlock(&komodo_mutex); if ( nonz != 0 ) sum /= nonz; - printf("-> %lld %s/%s\n",(long long)sum,base,rel); + printf("-> %lld %s/%s i.%d\n",(long long)sum,base,rel,i); return(sum); } From 93139074297f24e6d8e5ecbcb244ea2c58111a6d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 15:53:47 +0200 Subject: [PATCH 072/162] test --- src/komodo_pax.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index f3d1f7262..625768082 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -530,7 +530,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin if ( chainActive.Tip() != 0 && height > chainActive.Tip()->nHeight ) return(0); portable_mutex_lock(&komodo_mutex); - for (i=0; i<32; i++) + for (i=0; i<17; i++) { if ( (price= komodo_paxpriceB(&seed,height-i,base,rel,basevolume)) != 0 ) { @@ -546,7 +546,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin if ( diff < 33 ) break; } - else if ( i == 3 && nonz == 4 ) + else if ( 0 && i == 3 && nonz == 4 ) { diff = (((int64_t)price - (sum >> 2)) * 10000); if ( diff < 0 ) @@ -563,7 +563,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin portable_mutex_unlock(&komodo_mutex); if ( nonz != 0 ) sum /= nonz; - printf("-> %lld %s/%s i.%d\n",(long long)sum,base,rel,i); + //printf("-> %lld %s/%s i.%d ht.%d\n",(long long)sum,base,rel,i,height); return(sum); } From e5c73f9a1c222cd48cf42d32ac5c43df41f74046 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jan 2017 22:11:10 +0200 Subject: [PATCH 073/162] test --- src/komodo_pax.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 625768082..c12544cb0 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -496,7 +496,7 @@ uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,ui } numvotes = (int32_t)(sizeof(Peggy_inds)/sizeof(*Peggy_inds)); memset(votes,0,sizeof(votes)); - if ( komodo_kmdbtcusd(0,&kmdbtc,&btcusd,height) < 0 ) + //if ( komodo_kmdbtcusd(0,&kmdbtc,&btcusd,height) < 0 ) { memset(btcusds,0,sizeof(btcusds)); memset(kmdbtcs,0,sizeof(kmdbtcs)); @@ -507,7 +507,7 @@ uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,ui } kmdbtc = komodo_paxcorrelation(kmdbtcs,numvotes,*seedp) * 539; btcusd = komodo_paxcorrelation(btcusds,numvotes,*seedp) * 539; - komodo_kmdbtcusd(1,&kmdbtc,&btcusd,height); + //komodo_kmdbtcusd(1,&kmdbtc,&btcusd,height); } for (i=nonz=0; i Date: Wed, 18 Jan 2017 22:16:30 +0200 Subject: [PATCH 074/162] test --- src/komodo_pax.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index c12544cb0..625768082 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -496,7 +496,7 @@ uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,ui } numvotes = (int32_t)(sizeof(Peggy_inds)/sizeof(*Peggy_inds)); memset(votes,0,sizeof(votes)); - //if ( komodo_kmdbtcusd(0,&kmdbtc,&btcusd,height) < 0 ) + if ( komodo_kmdbtcusd(0,&kmdbtc,&btcusd,height) < 0 ) { memset(btcusds,0,sizeof(btcusds)); memset(kmdbtcs,0,sizeof(kmdbtcs)); @@ -507,7 +507,7 @@ uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,ui } kmdbtc = komodo_paxcorrelation(kmdbtcs,numvotes,*seedp) * 539; btcusd = komodo_paxcorrelation(btcusds,numvotes,*seedp) * 539; - //komodo_kmdbtcusd(1,&kmdbtc,&btcusd,height); + komodo_kmdbtcusd(1,&kmdbtc,&btcusd,height); } for (i=nonz=0; i Date: Wed, 18 Jan 2017 22:18:26 +0200 Subject: [PATCH 075/162] test --- src/komodo_pax.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 625768082..c12544cb0 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -496,7 +496,7 @@ uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,ui } numvotes = (int32_t)(sizeof(Peggy_inds)/sizeof(*Peggy_inds)); memset(votes,0,sizeof(votes)); - if ( komodo_kmdbtcusd(0,&kmdbtc,&btcusd,height) < 0 ) + //if ( komodo_kmdbtcusd(0,&kmdbtc,&btcusd,height) < 0 ) { memset(btcusds,0,sizeof(btcusds)); memset(kmdbtcs,0,sizeof(kmdbtcs)); @@ -507,7 +507,7 @@ uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,ui } kmdbtc = komodo_paxcorrelation(kmdbtcs,numvotes,*seedp) * 539; btcusd = komodo_paxcorrelation(btcusds,numvotes,*seedp) * 539; - komodo_kmdbtcusd(1,&kmdbtc,&btcusd,height); + //komodo_kmdbtcusd(1,&kmdbtc,&btcusd,height); } for (i=nonz=0; i Date: Wed, 18 Jan 2017 23:26:17 +0200 Subject: [PATCH 076/162] test --- src/komodo_pax.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index c12544cb0..79f01aefe 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -496,7 +496,7 @@ uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,ui } numvotes = (int32_t)(sizeof(Peggy_inds)/sizeof(*Peggy_inds)); memset(votes,0,sizeof(votes)); - //if ( komodo_kmdbtcusd(0,&kmdbtc,&btcusd,height) < 0 ) + //if ( komodo_kmdbtcusd(0,&kmdbtc,&btcusd,height) < 0 ) crashes when via passthru GUI use { memset(btcusds,0,sizeof(btcusds)); memset(kmdbtcs,0,sizeof(kmdbtcs)); @@ -557,8 +557,8 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin break; } } - //if ( height < KOMODO_MAINNET_START ) - // break; + if ( height < 165000 ) + break; } portable_mutex_unlock(&komodo_mutex); if ( nonz != 0 ) From f5ee72bf2b6ab99b75cc929745bcf09bc2d2a96f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 00:12:43 +0200 Subject: [PATCH 077/162] WIRELESS --- src/assetchains | 2 ++ src/dpowassets | 1 + src/fiat-cli | 1 + src/fiat/wireless | 2 ++ 4 files changed, 6 insertions(+) create mode 100755 src/fiat/wireless diff --git a/src/assetchains b/src/assetchains index 0533ed4cb..f1acd3601 100755 --- a/src/assetchains +++ b/src/assetchains @@ -27,6 +27,8 @@ sleep 10 sleep 10 ./komodod -pubkey=$pubkey -ac_name=MVP -ac_supply=1000000 -addnode=78.47.196.146 $1 -gen & sleep 10 +./komodod -pubkey=$pubkey -ac_name=WIRELESS -ac_supply=21000000 -addnode=78.47.196.146 $1 -gen & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=USD -addnode=78.47.196.146 $1 -gen & sleep 10 diff --git a/src/dpowassets b/src/dpowassets index eaa79c750..9e11bfde4 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -17,6 +17,7 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BOTS\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MGW\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MVP\",\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"WIRELESS\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"USD\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"EUR\",\"pubkey\":\"$pubkey\"}" diff --git a/src/fiat-cli b/src/fiat-cli index 62b23faee..16e121244 100755 --- a/src/fiat-cli +++ b/src/fiat-cli @@ -44,3 +44,4 @@ echo shark; fiat/shark $1 $2 $3 $4 echo bots; fiat/bots $1 $2 $3 $4 echo mgw; fiat/mgw $1 $2 $3 $4 echo mvp; fiat/mvp $1 $2 $3 $4 +echo wireless; fiat/wireless $1 $2 $3 $4 diff --git a/src/fiat/wireless b/src/fiat/wireless new file mode 100755 index 000000000..a4869b189 --- /dev/null +++ b/src/fiat/wireless @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=WIRELESS $1 $2 $3 $4 From 9f4c2607d8d132c0b5dd995e07d5ab31e784149e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 11:14:17 +0200 Subject: [PATCH 078/162] KV --- src/assetchains | 13 +------------ src/dpowassets | 1 + src/fiat-cli | 1 + src/fiat/kv | 2 ++ 4 files changed, 5 insertions(+), 12 deletions(-) create mode 100755 src/fiat/kv diff --git a/src/assetchains b/src/assetchains index f1acd3601..ebd732782 100755 --- a/src/assetchains +++ b/src/assetchains @@ -4,30 +4,19 @@ source pubkey.txt echo $pubkey ./komodod -pubkey=$pubkey -ac_name=REVS -ac_supply=1300000 -addnode=78.47.196.146 $1 -gen & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=SUPERNET -ac_supply=816061 -addnode=78.47.196.146 $1 -gen & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=DEX -ac_supply=999999 -addnode=78.47.196.146 $1 -gen & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=PANGEA -ac_supply=999999 -addnode=78.47.196.146 $1 -gen & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=JUMBLR -ac_supply=999999 -addnode=78.47.196.146 $1 -gen & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=BET -ac_supply=999999 -addnode=78.47.196.146 $1 -gen & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=CRYPTO -ac_supply=999999 -addnode=78.47.196.146 $1 -gen & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=HODL -ac_supply=9999999 -addnode=78.47.196.146 $1 -gen & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=SHARK -ac_supply=1401 -addnode=78.47.196.146 $1 -gen & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=BOTS -ac_supply=999999 -addnode=78.47.196.146 $1 -gen & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=MGW -ac_supply=999999 -addnode=78.47.196.146 $1 -gen & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=MVP -ac_supply=1000000 -addnode=78.47.196.146 $1 -gen & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=WIRELESS -ac_supply=21000000 -addnode=78.47.196.146 $1 -gen & +./komodod -pubkey=$pubkey -ac_name=KV -ac_supply=1000000 -addnode=78.47.196.146 $1 -gen & sleep 10 ./komodod -pubkey=$pubkey -ac_name=USD -addnode=78.47.196.146 $1 -gen & diff --git a/src/dpowassets b/src/dpowassets index 9e11bfde4..03e489864 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -18,6 +18,7 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MGW\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MVP\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"WIRELESS\",\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"KV\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"USD\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"EUR\",\"pubkey\":\"$pubkey\"}" diff --git a/src/fiat-cli b/src/fiat-cli index 16e121244..f88958d31 100755 --- a/src/fiat-cli +++ b/src/fiat-cli @@ -45,3 +45,4 @@ echo bots; fiat/bots $1 $2 $3 $4 echo mgw; fiat/mgw $1 $2 $3 $4 echo mvp; fiat/mvp $1 $2 $3 $4 echo wireless; fiat/wireless $1 $2 $3 $4 +echo kv; fiat/kv $1 $2 $3 $4 diff --git a/src/fiat/kv b/src/fiat/kv new file mode 100755 index 000000000..c735138e3 --- /dev/null +++ b/src/fiat/kv @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=KV $1 $2 $3 $4 From 15d0fbd4079a213d648687aa945ddc8618af0450 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 19:57:12 +0200 Subject: [PATCH 079/162] test --- src/komodo.h | 7 ++++++- src/komodo_gateway.h | 45 +++++++++++++++++++++++++++++++++++++++++++- src/komodo_globals.h | 4 ++++ src/komodo_structs.h | 2 ++ 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 9fe331708..e1c62bfa8 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -187,8 +187,13 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint32_t KMDtimestamp,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout) { - static FILE *fp; static int32_t errs; + static FILE *fp; static int32_t errs,didinit; struct komodo_state *sp; char fname[512],symbol[16],dest[16]; int32_t ht,func; uint8_t num,pubkeys[64][33]; + if ( didinit == 0 ) + { + portable_mutex_init(&KOMODO_KV_mutex); + didinit = 1; + } if ( (sp= komodo_stateptr(symbol,dest)) == 0 ) { KOMODO_INITDONE = (uint32_t)time(NULL); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 007b16b0b..304315104 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -671,6 +671,20 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above return(0); } +int32_t komodo_kvsearch(uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen) +{ + struct komodo_kv *ptr; int32_t retval = -1; + portable_mutex_lock(&KOMODO_KV_mutex); + HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); + if ( ptr != 0 ) + { + if ( (retval= ptr->valuesize) != 0 ) + memcpy(value,ptr->value,retval); + } + portable_mutex_unlock(&KOMODO_KV_mutex); + return(retval); +} + const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout,char *source) { uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff; @@ -689,7 +703,36 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 memset(kmdheights,0,sizeof(kmdheights)); memset(otherheights,0,sizeof(otherheights)); tokomodo = (komodo_is_issuer() == 0); - if ( opretbuf[0] == 'D' ) + if ( opretbuf[0] == 'K' ) + { + uint16_t keylen,valuesize; uint8_t *key,*value; struct komodo_kv *ptr; + iguana_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen); + iguana_rwnum(0,&opretbuf[3],sizeof(valuesize),&valuesize); + key = &opretbuf[5]; + value = &key[keylen]; + if ( sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1 == opretlen ) + { + portable_mutex_lock(&KOMODO_KV_mutex); + HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); + if ( ptr == 0 ) + { + ptr = calloc(1,sizeof(*ptr)); + ptr->key = calloc(1,keylen); + ptr->keylen = keylen; + memcpy(ptr->key,key,keylen); + HASH_ADD_KEYPTR(hh,KOMODO_KV,ptr->key,ptr->keylen,ptr); + } + if ( ptr->value != 0 ) + free(ptr->value), ptr->value = 0; + if ( (ptr->valuesize= valuesize) != 0 ) + { + ptr->value = calloc(1,valuesize); + memcpy(ptr->value,value,valuesize); + } + portable_mutex_unlock(&KOMODO_KV_mutex); + } else printf("opretlen.%d mismatch keylen.%d valuesize.%d\n",opretln,keylen,valuesize); + } + else if ( opretbuf[0] == 'D' ) { tokomodo = 0; if ( opretlen == 38 ) // any KMD tx diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 08c80ff79..71d62eac1 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -27,6 +27,7 @@ int32_t komodo_longestchain(); pthread_mutex_t komodo_mutex; #define KOMODO_ELECTION_GAP 2000 //((ASSETCHAINS_SYMBOL[0] == 0) ? 2000 : 100) +#define IGUANA_MAXSCRIPTSIZE 10001 struct pax_transaction *PAX; int32_t NUM_PRICES; uint32_t *PVALS; @@ -49,3 +50,6 @@ uint64_t ASSETCHAINS_SUPPLY = 10; uint32_t KOMODO_INITDONE; char KMDUSERPASS[4096],BTCUSERPASS[4096]; uint16_t BITCOIND_PORT = 7771; uint64_t PENDING_KOMODO_TX; + +struct komodo_kv *KOMODO_KV; +portable_mutex_t KOMODO_KV_mutex; \ No newline at end of file diff --git a/src/komodo_structs.h b/src/komodo_structs.h index d1da1d4c4..2bb827849 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -37,6 +37,8 @@ #define KOMODO_OPRETURN_WITHDRAW 'W' // assetchain #define KOMODO_OPRETURN_REDEEMED 'X' +struct komodo_kv { UT_hash_handle hh; uint8_t *key,*value; uint16_t keylen,valuesize; }; + struct komodo_event_notarized { uint256 blockhash,desttxid; int32_t notarizedheight; char dest[16]; }; struct komodo_event_pubkeys { uint8_t num; uint8_t pubkeys[64][33]; }; struct komodo_event_opreturn { uint256 txid; uint64_t value; uint16_t vout,oplen; uint8_t opret[]; }; From 313b7381a9cecac57a21f3c1753fe9183ee0bee1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 20:00:34 +0200 Subject: [PATCH 080/162] test --- src/komodo_gateway.h | 6 +++--- src/komodo_globals.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 304315104..0ee5d1011 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -716,7 +716,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); if ( ptr == 0 ) { - ptr = calloc(1,sizeof(*ptr)); + ptr = (struct komodo_kv *)calloc(1,sizeof(*ptr)); ptr->key = calloc(1,keylen); ptr->keylen = keylen; memcpy(ptr->key,key,keylen); @@ -726,11 +726,11 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 free(ptr->value), ptr->value = 0; if ( (ptr->valuesize= valuesize) != 0 ) { - ptr->value = calloc(1,valuesize); + ptr->value = (uint8_t *)calloc(1,valuesize); memcpy(ptr->value,value,valuesize); } portable_mutex_unlock(&KOMODO_KV_mutex); - } else printf("opretlen.%d mismatch keylen.%d valuesize.%d\n",opretln,keylen,valuesize); + } else printf("opretlen.%d mismatch keylen.%d valuesize.%d\n",opretlen,keylen,valuesize); } else if ( opretbuf[0] == 'D' ) { diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 71d62eac1..a63c4c754 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -52,4 +52,4 @@ char KMDUSERPASS[4096],BTCUSERPASS[4096]; uint16_t BITCOIND_PORT = 7771; uint64_t PENDING_KOMODO_TX; struct komodo_kv *KOMODO_KV; -portable_mutex_t KOMODO_KV_mutex; \ No newline at end of file +pthread_mutex_t KOMODO_KV_mutex; \ No newline at end of file From e77a3b30d2fb2abe2cc9a665229635e84d550216 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 20:01:40 +0200 Subject: [PATCH 081/162] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0ee5d1011..0cac2631e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -717,7 +717,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 if ( ptr == 0 ) { ptr = (struct komodo_kv *)calloc(1,sizeof(*ptr)); - ptr->key = calloc(1,keylen); + ptr->key = (uint8_t *)calloc(1,keylen); ptr->keylen = keylen; memcpy(ptr->key,key,keylen); HASH_ADD_KEYPTR(hh,KOMODO_KV,ptr->key,ptr->keylen,ptr); From d20fb2db484433e03f8e8d0662dd26b4fe240acd Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 20:18:31 +0200 Subject: [PATCH 082/162] test --- src/rpcblockchain.cpp | 27 +++++++++++++++++++++++++++ src/rpcclient.cpp | 1 + src/rpcserver.cpp | 1 + src/rpcserver.h | 1 + 4 files changed, 30 insertions(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 62ac42675..dc0218e5b 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -404,6 +404,33 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len); uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n); int32_t komodo_minerids(uint8_t *minerids,int32_t height); +int32_t komodo_kvsearch(uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); + +Value kvsearch(const Array& params, bool fHelp) +{ + Object ret; uint8_t value[IGUANA_MAXSCRIPTSIZE],key[IGUANA_MAXSCRIPTSIZE]; int32_t j,valuesize,keylen; + LOCK(cs_main); + if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) + { + if ( keylen < sizeof(key) ) + { + memcpy(key,params[0].get_str().c_str(),keylen); + if ( (valuesize= komodo_kvsearch(value,key,keylen)) >= 0 ) + { + std::string value; char *valuestr; int32_t m; + value.resize(valuesize+1); + hexstr = (char *)value.data(); + memcpy(valuestr,value,valuesize); + valuestr[valuesize] = 0; + ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); + ret.push_back(Pair("key",params[0].get_str())); + ret.push_back(Pair("value",value)); + ret.push_back(Pair("height", (int64_t)chainActive.Tip()->nHeight)); + } else ret.push_back(Pair("error",(char *)"cant find key")); + } else ret.push_back(Pair("error",(char *)"key too big")); + } else ret.push_back(Pair("error",(char *)"null key")); + return ret; +} Value minerids(const Array& params, bool fHelp) { diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index 824ad602a..495b4addd 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -112,6 +112,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "paxpending", 0 }, { "notaries", 1 }, { "minerids", 1 }, + { "kvsearch", 1 }, }; class CRPCConvertTable diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index d7f049280..e360b7164 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -305,6 +305,7 @@ static const CRPCCommand vRPCCommands[] = { "blockchain", "paxprices", &paxprices, true }, { "blockchain", "notaries", ¬aries, true }, { "blockchain", "minerids", &minerids, true }, + { "blockchain", "kvsearch", &kvsearch, true }, /* Mining */ { "mining", "getblocktemplate", &getblocktemplate, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index 15a35a1d5..1bc3e48b3 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -247,6 +247,7 @@ extern json_spirit::Value gettxoutsetinfo(const json_spirit::Array& params, bool extern json_spirit::Value gettxout(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value notaries(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value minerids(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value kvsearch(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value paxprice(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value paxpending(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value paxprices(const json_spirit::Array& params, bool fHelp); From ed440b5eb842a5f8936dd63bbc4f23c4d2ee9f22 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 20:20:55 +0200 Subject: [PATCH 083/162] test --- src/rpcblockchain.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index dc0218e5b..b06ee16c3 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -417,14 +417,14 @@ Value kvsearch(const Array& params, bool fHelp) memcpy(key,params[0].get_str().c_str(),keylen); if ( (valuesize= komodo_kvsearch(value,key,keylen)) >= 0 ) { - std::string value; char *valuestr; int32_t m; - value.resize(valuesize+1); - hexstr = (char *)value.data(); + std::string val; char *valuestr; + val.resize(valuesize+1); + valuestr = (char *)val.data(); memcpy(valuestr,value,valuesize); valuestr[valuesize] = 0; ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); ret.push_back(Pair("key",params[0].get_str())); - ret.push_back(Pair("value",value)); + ret.push_back(Pair("value",val)); ret.push_back(Pair("height", (int64_t)chainActive.Tip()->nHeight)); } else ret.push_back(Pair("error",(char *)"cant find key")); } else ret.push_back(Pair("error",(char *)"key too big")); From 88b08214c4923e56e582d97a554638231ebd7b05 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 20:22:08 +0200 Subject: [PATCH 084/162] test --- src/rpcblockchain.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index b06ee16c3..1110ba99d 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -405,6 +405,8 @@ char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160, uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n); int32_t komodo_minerids(uint8_t *minerids,int32_t height); int32_t komodo_kvsearch(uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); +extern char ASSETCHAINS_SYMBOL[16]; +#define IGUANA_MAXSCRIPTSIZE 10001 Value kvsearch(const Array& params, bool fHelp) { @@ -417,7 +419,7 @@ Value kvsearch(const Array& params, bool fHelp) memcpy(key,params[0].get_str().c_str(),keylen); if ( (valuesize= komodo_kvsearch(value,key,keylen)) >= 0 ) { - std::string val; char *valuestr; + std::string val; char *valuestr; val.resize(valuesize+1); valuestr = (char *)val.data(); memcpy(valuestr,value,valuesize); From 88c3681cabcfce3993bfc31bef8fd0f208ff727c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 20:23:02 +0200 Subject: [PATCH 085/162] test --- src/rpcblockchain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 1110ba99d..019e1565a 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -396,6 +396,8 @@ Value gettxoutsetinfo(const Array& params, bool fHelp) return ret; } +#define IGUANA_MAXSCRIPTSIZE 10001 +extern char ASSETCHAINS_SYMBOL[16]; uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); uint32_t komodo_txtime(uint256 hash); uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume); @@ -405,8 +407,6 @@ char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160, uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n); int32_t komodo_minerids(uint8_t *minerids,int32_t height); int32_t komodo_kvsearch(uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); -extern char ASSETCHAINS_SYMBOL[16]; -#define IGUANA_MAXSCRIPTSIZE 10001 Value kvsearch(const Array& params, bool fHelp) { From ab6e81ec8fc5252fabfce3dc1638dc37826c9d18 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 20:53:57 +0200 Subject: [PATCH 086/162] test --- src/komodo_gateway.h | 2 +- src/rpcblockchain.cpp | 6 +++--- src/rpcclient.cpp | 1 + src/rpcserver.cpp | 1 + src/rpcserver.h | 1 + src/wallet/rpcwallet.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0cac2631e..a26efaab2 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -703,7 +703,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 memset(kmdheights,0,sizeof(kmdheights)); memset(otherheights,0,sizeof(otherheights)); tokomodo = (komodo_is_issuer() == 0); - if ( opretbuf[0] == 'K' ) + if ( opretbuf[0] == 'K' && opretlen != 40 ) { uint16_t keylen,valuesize; uint8_t *key,*value; struct komodo_kv *ptr; iguana_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 019e1565a..fcc28e125 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -414,6 +414,9 @@ Value kvsearch(const Array& params, bool fHelp) LOCK(cs_main); if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) { + ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); + ret.push_back(Pair("height", (int64_t)chainActive.Tip()->nHeight)); + ret.push_back(Pair("key",params[0].get_str())); if ( keylen < sizeof(key) ) { memcpy(key,params[0].get_str().c_str(),keylen); @@ -424,10 +427,7 @@ Value kvsearch(const Array& params, bool fHelp) valuestr = (char *)val.data(); memcpy(valuestr,value,valuesize); valuestr[valuesize] = 0; - ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); - ret.push_back(Pair("key",params[0].get_str())); ret.push_back(Pair("value",val)); - ret.push_back(Pair("height", (int64_t)chainActive.Tip()->nHeight)); } else ret.push_back(Pair("error",(char *)"cant find key")); } else ret.push_back(Pair("error",(char *)"key too big")); } else ret.push_back(Pair("error",(char *)"null key")); diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index 495b4addd..241adbdec 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -113,6 +113,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "notaries", 1 }, { "minerids", 1 }, { "kvsearch", 1 }, + { "kvupdate", 2 }, }; class CRPCConvertTable diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index e360b7164..7f677fcf8 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -306,6 +306,7 @@ static const CRPCCommand vRPCCommands[] = { "blockchain", "notaries", ¬aries, true }, { "blockchain", "minerids", &minerids, true }, { "blockchain", "kvsearch", &kvsearch, true }, + { "blockchain", "kvupdate", &kvupdate, true }, /* Mining */ { "mining", "getblocktemplate", &getblocktemplate, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index 1bc3e48b3..0fda9571f 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -248,6 +248,7 @@ extern json_spirit::Value gettxout(const json_spirit::Array& params, bool fHelp) extern json_spirit::Value notaries(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value minerids(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value kvsearch(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value kvupdate(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value paxprice(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value paxpending(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value paxprices(const json_spirit::Array& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 9a9bd637c..82aef4f50 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -475,6 +475,7 @@ Value sendtoaddress(const Array& params, bool fHelp) return wtx.GetHash().GetHex(); } +#define IGUANA_MAXSCRIPTSIZE 10001 uint64_t PAX_fiatdest(uint64_t *seedp,int32_t tokomodo,char *destaddr,uint8_t pubkey37[37],char *coinaddr,int32_t height,char *base,int64_t fiatoshis); int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_t opretlen); #define CRYPTO777_KMDADDR "RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA" @@ -557,6 +558,45 @@ Value paxwithdraw(const Array& params, bool fHelp) return wtx.GetHash().GetHex(); } +Value kvupdate(const Array& params, bool fHelp) +{ + Object ret; uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t opretlen,j; + uint16_t keylen,valuesize; uint8_t *key,*value=0; struct komodo_kv *ptr; uint64_t fee; + if (!EnsureWalletIsAvailable(fHelp)) + return 0; + LOCK2(cs_main, pwalletMain->cs_wallet); + if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) + { + key = (uint8_t *)params[0].get_str().c_str(); + ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); + ret.push_back(Pair("height", (int64_t)chainActive.Tip()->nHeight)); + ret.push_back(Pair("key",params[0].get_str())); + if ( params.size() == 2 && params[1].get_str().c_str() != 0 ) + { + ret.push_back(Pair("value",params[1].get_str())); + value = (uint8_t *)params[1].get_str().c_str(); + } + iguana_rwnum(1,&keyvalue[0],sizeof(keylen),&keylen); + iguana_rwnum(1,&keyvalue[2],sizeof(valuesize),&valuesize); + memcpy(&keyvalue[4],key,keylen); + if ( value != 0 ) + memcpy(&keyvalue[4 + keylen],value,valuesize); + opretlen = komodo_opreturnscript(opretbuf,'W',keyvalue,sizeof(uint16_t)*2+keylen+valuelen); + for (i=0; i Date: Fri, 20 Jan 2017 20:59:51 +0200 Subject: [PATCH 087/162] test --- src/rpcblockchain.cpp | 2 ++ src/wallet/rpcwallet.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index fcc28e125..e395f6db8 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -411,6 +411,8 @@ int32_t komodo_kvsearch(uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t Value kvsearch(const Array& params, bool fHelp) { Object ret; uint8_t value[IGUANA_MAXSCRIPTSIZE],key[IGUANA_MAXSCRIPTSIZE]; int32_t j,valuesize,keylen; + if (fHelp || params.size() != 1 ) + throw runtime_error("kvsearch key"); LOCK(cs_main); if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 82aef4f50..46e41d475 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -562,6 +562,8 @@ Value kvupdate(const Array& params, bool fHelp) { Object ret; uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t opretlen,j; uint16_t keylen,valuesize; uint8_t *key,*value=0; struct komodo_kv *ptr; uint64_t fee; + if (fHelp || params.size() != 2 ) + throw runtime_error("kvupdate key value"); if (!EnsureWalletIsAvailable(fHelp)) return 0; LOCK2(cs_main, pwalletMain->cs_wallet); From 6685bab2bbe6fa378bdb900d38c87ee2493094b9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 21:02:23 +0200 Subject: [PATCH 088/162] test --- src/wallet/rpcwallet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 46e41d475..ce80ebea2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -560,7 +560,7 @@ Value paxwithdraw(const Array& params, bool fHelp) Value kvupdate(const Array& params, bool fHelp) { - Object ret; uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t opretlen,j; + CWalletTx wtx; Object ret; uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t opretlen,i; uint16_t keylen,valuesize; uint8_t *key,*value=0; struct komodo_kv *ptr; uint64_t fee; if (fHelp || params.size() != 2 ) throw runtime_error("kvupdate key value"); @@ -583,7 +583,7 @@ Value kvupdate(const Array& params, bool fHelp) memcpy(&keyvalue[4],key,keylen); if ( value != 0 ) memcpy(&keyvalue[4 + keylen],value,valuesize); - opretlen = komodo_opreturnscript(opretbuf,'W',keyvalue,sizeof(uint16_t)*2+keylen+valuelen); + opretlen = komodo_opreturnscript(opretbuf,'W',keyvalue,sizeof(uint16_t)*2+keylen+valuesize); for (i=0; i Date: Fri, 20 Jan 2017 21:13:07 +0200 Subject: [PATCH 089/162] test --- src/wallet/rpcwallet.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ce80ebea2..935d1de93 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -561,7 +561,7 @@ Value paxwithdraw(const Array& params, bool fHelp) Value kvupdate(const Array& params, bool fHelp) { CWalletTx wtx; Object ret; uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t opretlen,i; - uint16_t keylen,valuesize; uint8_t *key,*value=0; struct komodo_kv *ptr; uint64_t fee; + uint16_t keylen,valuesize=0; uint8_t *key,*value=0; struct komodo_kv *ptr; uint64_t fee; if (fHelp || params.size() != 2 ) throw runtime_error("kvupdate key value"); if (!EnsureWalletIsAvailable(fHelp)) @@ -573,10 +573,13 @@ Value kvupdate(const Array& params, bool fHelp) ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); ret.push_back(Pair("height", (int64_t)chainActive.Tip()->nHeight)); ret.push_back(Pair("key",params[0].get_str())); + ret.push_back(Pair("keylen",keylen)); if ( params.size() == 2 && params[1].get_str().c_str() != 0 ) { - ret.push_back(Pair("value",params[1].get_str())); value = (uint8_t *)params[1].get_str().c_str(); + valuesize = (int32_t)strlen(params[1].get_str().c_str(); + ret.push_back(Pair("value",params[1].get_str())); + ret.push_back(Pair("valuesize",valuesize)); } iguana_rwnum(1,&keyvalue[0],sizeof(keylen),&keylen); iguana_rwnum(1,&keyvalue[2],sizeof(valuesize),&valuesize); @@ -594,8 +597,8 @@ Value kvupdate(const Array& params, bool fHelp) if (!destaddress.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid dest Bitcoin address"); SendMoney(destaddress.Get(),10000,false,wtx,opretbuf,opretlen,fee); - return wtx.GetHash().GetHex(); - } else ret.push_back(Pair("error",(char *)"null key")); + ret.push_back(Pair("txid",wtx.GetHash())); + } else ret.push_back(Pair("error",(char *)"null key")); return ret; } From 380b8ee0dd6015e9de06553d5cd4a3bc6b7fd8cf Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 21:14:57 +0200 Subject: [PATCH 090/162] test --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 935d1de93..1c3e0582d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -577,7 +577,7 @@ Value kvupdate(const Array& params, bool fHelp) if ( params.size() == 2 && params[1].get_str().c_str() != 0 ) { value = (uint8_t *)params[1].get_str().c_str(); - valuesize = (int32_t)strlen(params[1].get_str().c_str(); + valuesize = (int32_t)strlen(params[1].get_str().c_str()); ret.push_back(Pair("value",params[1].get_str())); ret.push_back(Pair("valuesize",valuesize)); } @@ -586,7 +586,7 @@ Value kvupdate(const Array& params, bool fHelp) memcpy(&keyvalue[4],key,keylen); if ( value != 0 ) memcpy(&keyvalue[4 + keylen],value,valuesize); - opretlen = komodo_opreturnscript(opretbuf,'W',keyvalue,sizeof(uint16_t)*2+keylen+valuesize); + opretlen = komodo_opreturnscript(opretbuf,'K',keyvalue,sizeof(uint16_t)*2+keylen+valuesize); for (i=0; i Date: Fri, 20 Jan 2017 21:15:28 +0200 Subject: [PATCH 091/162] test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1c3e0582d..d203e63e2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -597,7 +597,7 @@ Value kvupdate(const Array& params, bool fHelp) if (!destaddress.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid dest Bitcoin address"); SendMoney(destaddress.Get(),10000,false,wtx,opretbuf,opretlen,fee); - ret.push_back(Pair("txid",wtx.GetHash())); + ret.push_back(Pair("txid",wtx.GetHash().GetHex())); } else ret.push_back(Pair("error",(char *)"null key")); return ret; } From 92bd71eed00f6e29d17e3dfd1566e85798e066f2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 21:19:24 +0200 Subject: [PATCH 092/162] test --- src/rpcblockchain.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index e395f6db8..8d3253b45 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -425,10 +425,9 @@ Value kvsearch(const Array& params, bool fHelp) if ( (valuesize= komodo_kvsearch(value,key,keylen)) >= 0 ) { std::string val; char *valuestr; - val.resize(valuesize+1); + val.resize(valuesize); valuestr = (char *)val.data(); memcpy(valuestr,value,valuesize); - valuestr[valuesize] = 0; ret.push_back(Pair("value",val)); } else ret.push_back(Pair("error",(char *)"cant find key")); } else ret.push_back(Pair("error",(char *)"key too big")); From 368da363c407e6b879abfab509278add978b2489 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 21:26:46 +0200 Subject: [PATCH 093/162] test --- src/komodo_gateway.h | 10 +++++++--- src/komodo_structs.h | 2 +- src/rpcblockchain.cpp | 11 +++++++---- src/wallet/rpcwallet.cpp | 12 +++++++----- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a26efaab2..5f4fb5302 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -671,13 +671,15 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above return(0); } -int32_t komodo_kvsearch(uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen) +int32_t komodo_kvsearch(int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen) { struct komodo_kv *ptr; int32_t retval = -1; + *heightp = -1; portable_mutex_lock(&KOMODO_KV_mutex); HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); if ( ptr != 0 ) { + *heightp = ptr->height; if ( (retval= ptr->valuesize) != 0 ) memcpy(value,ptr->value,retval); } @@ -708,9 +710,10 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 uint16_t keylen,valuesize; uint8_t *key,*value; struct komodo_kv *ptr; iguana_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen); iguana_rwnum(0,&opretbuf[3],sizeof(valuesize),&valuesize); - key = &opretbuf[5]; + iguana_rwnum(0,&opretbuf[5],sizeof(kmdheight),&kmdheight); + key = &opretbuf[9]; value = &key[keylen]; - if ( sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1 == opretlen ) + if ( sizeof(kmdheight)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1 == opretlen ) { portable_mutex_lock(&KOMODO_KV_mutex); HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); @@ -729,6 +732,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 ptr->value = (uint8_t *)calloc(1,valuesize); memcpy(ptr->value,value,valuesize); } + ptr->height = kmdheight; portable_mutex_unlock(&KOMODO_KV_mutex); } else printf("opretlen.%d mismatch keylen.%d valuesize.%d\n",opretlen,keylen,valuesize); } diff --git a/src/komodo_structs.h b/src/komodo_structs.h index 2bb827849..73c325de2 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -37,7 +37,7 @@ #define KOMODO_OPRETURN_WITHDRAW 'W' // assetchain #define KOMODO_OPRETURN_REDEEMED 'X' -struct komodo_kv { UT_hash_handle hh; uint8_t *key,*value; uint16_t keylen,valuesize; }; +struct komodo_kv { UT_hash_handle hh; uint8_t *key,*value; int32_t height; uint16_t keylen,valuesize; }; struct komodo_event_notarized { uint256 blockhash,desttxid; int32_t notarizedheight; char dest[16]; }; struct komodo_event_pubkeys { uint8_t num; uint8_t pubkeys[64][33]; }; diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 8d3253b45..50b17e171 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -406,29 +406,32 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len); uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n); int32_t komodo_minerids(uint8_t *minerids,int32_t height); -int32_t komodo_kvsearch(uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); +int32_t komodo_kvsearch(int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); Value kvsearch(const Array& params, bool fHelp) { - Object ret; uint8_t value[IGUANA_MAXSCRIPTSIZE],key[IGUANA_MAXSCRIPTSIZE]; int32_t j,valuesize,keylen; + Object ret; uint8_t value[IGUANA_MAXSCRIPTSIZE],key[IGUANA_MAXSCRIPTSIZE]; int32_t j,height,valuesize,keylen; if (fHelp || params.size() != 1 ) throw runtime_error("kvsearch key"); LOCK(cs_main); if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) { ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); - ret.push_back(Pair("height", (int64_t)chainActive.Tip()->nHeight)); + ret.push_back(Pair("currentheight", (int64_t)chainActive.Tip()->nHeight)); ret.push_back(Pair("key",params[0].get_str())); + ret.push_back(Pair("keylen",keylen)); if ( keylen < sizeof(key) ) { memcpy(key,params[0].get_str().c_str(),keylen); - if ( (valuesize= komodo_kvsearch(value,key,keylen)) >= 0 ) + if ( (valuesize= komodo_kvsearch(&height,value,key,keylen)) >= 0 ) { std::string val; char *valuestr; val.resize(valuesize); valuestr = (char *)val.data(); memcpy(valuestr,value,valuesize); + ret.push_back(Pair("height",height)); ret.push_back(Pair("value",val)); + ret.push_back(Pair("valuesize",valuesize)); } else ret.push_back(Pair("error",(char *)"cant find key")); } else ret.push_back(Pair("error",(char *)"key too big")); } else ret.push_back(Pair("error",(char *)"null key")); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d203e63e2..6e1f2ed7b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -560,7 +560,7 @@ Value paxwithdraw(const Array& params, bool fHelp) Value kvupdate(const Array& params, bool fHelp) { - CWalletTx wtx; Object ret; uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t opretlen,i; + CWalletTx wtx; Object ret; uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t opretlen,i,height; uint16_t keylen,valuesize=0; uint8_t *key,*value=0; struct komodo_kv *ptr; uint64_t fee; if (fHelp || params.size() != 2 ) throw runtime_error("kvupdate key value"); @@ -571,7 +571,8 @@ Value kvupdate(const Array& params, bool fHelp) { key = (uint8_t *)params[0].get_str().c_str(); ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); - ret.push_back(Pair("height", (int64_t)chainActive.Tip()->nHeight)); + height = chainActive.Tip()->nHeight; + ret.push_back(Pair("height", (int64_t)height)); ret.push_back(Pair("key",params[0].get_str())); ret.push_back(Pair("keylen",keylen)); if ( params.size() == 2 && params[1].get_str().c_str() != 0 ) @@ -583,10 +584,11 @@ Value kvupdate(const Array& params, bool fHelp) } iguana_rwnum(1,&keyvalue[0],sizeof(keylen),&keylen); iguana_rwnum(1,&keyvalue[2],sizeof(valuesize),&valuesize); - memcpy(&keyvalue[4],key,keylen); + iguana_rwnum(1,&keyvalue[4],sizeof(height),&height); + memcpy(&keyvalue[8],key,keylen); if ( value != 0 ) - memcpy(&keyvalue[4 + keylen],value,valuesize); - opretlen = komodo_opreturnscript(opretbuf,'K',keyvalue,sizeof(uint16_t)*2+keylen+valuesize); + memcpy(&keyvalue[8 + keylen],value,valuesize); + opretlen = komodo_opreturnscript(opretbuf,'K',keyvalue,sizeof(height)+sizeof(uint16_t)*2+keylen+valuesize); for (i=0; i Date: Fri, 20 Jan 2017 21:38:18 +0200 Subject: [PATCH 094/162] test --- src/komodo_gateway.h | 1 + src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5f4fb5302..7ee920089 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -713,6 +713,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 iguana_rwnum(0,&opretbuf[5],sizeof(kmdheight),&kmdheight); key = &opretbuf[9]; value = &key[keylen]; + printf("keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",keylen,valuesize,kmdheight,key[0],key[1],key[2],value[0],value[1],value[2]); if ( sizeof(kmdheight)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1 == opretlen ) { portable_mutex_lock(&KOMODO_KV_mutex); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6e1f2ed7b..126a98efc 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -591,7 +591,7 @@ Value kvupdate(const Array& params, bool fHelp) opretlen = komodo_opreturnscript(opretbuf,'K',keyvalue,sizeof(height)+sizeof(uint16_t)*2+keylen+valuesize); for (i=0; i Date: Fri, 20 Jan 2017 22:15:38 +0200 Subject: [PATCH 095/162] test --- src/komodo_gateway.h | 14 +++++++++----- src/komodo_structs.h | 2 +- src/rpcblockchain.cpp | 7 ++++--- src/wallet/rpcwallet.cpp | 29 +++++++++++++++++------------ 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7ee920089..a048a597b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -671,15 +671,17 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above return(0); } -int32_t komodo_kvsearch(int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen) +int32_t komodo_kvsearch(uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen) { struct komodo_kv *ptr; int32_t retval = -1; *heightp = -1; + *flagsp = 0; portable_mutex_lock(&KOMODO_KV_mutex); HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); if ( ptr != 0 ) { *heightp = ptr->height; + *flagsp = ptr->flags; if ( (retval= ptr->valuesize) != 0 ) memcpy(value,ptr->value,retval); } @@ -689,7 +691,7 @@ int32_t komodo_kvsearch(int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uin const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout,char *source) { - uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff; + uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff; uint32_t flags; const char *typestr = "unknown"; if ( KOMODO_PAX == 0 ) return("nopax"); @@ -711,16 +713,18 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 iguana_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen); iguana_rwnum(0,&opretbuf[3],sizeof(valuesize),&valuesize); iguana_rwnum(0,&opretbuf[5],sizeof(kmdheight),&kmdheight); - key = &opretbuf[9]; + iguana_rwnum(0,&opretbuf[9],sizeof(flags),&flags); + key = &opretbuf[13]; value = &key[keylen]; - printf("keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",keylen,valuesize,kmdheight,key[0],key[1],key[2],value[0],value[1],value[2]); - if ( sizeof(kmdheight)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1 == opretlen ) + //printf("keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",keylen,valuesize,kmdheight,key[0],key[1],key[2],value[0],value[1],value[2]); + if ( sizeof(flags)+sizeof(kmdheight)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1 == opretlen ) { portable_mutex_lock(&KOMODO_KV_mutex); HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); if ( ptr == 0 ) { ptr = (struct komodo_kv *)calloc(1,sizeof(*ptr)); + ptr->flags = flags; ptr->key = (uint8_t *)calloc(1,keylen); ptr->keylen = keylen; memcpy(ptr->key,key,keylen); diff --git a/src/komodo_structs.h b/src/komodo_structs.h index 73c325de2..73194ab8e 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -37,7 +37,7 @@ #define KOMODO_OPRETURN_WITHDRAW 'W' // assetchain #define KOMODO_OPRETURN_REDEEMED 'X' -struct komodo_kv { UT_hash_handle hh; uint8_t *key,*value; int32_t height; uint16_t keylen,valuesize; }; +struct komodo_kv { UT_hash_handle hh; uint8_t *key,*value; int32_t height; uint32_t flags; uint16_t keylen,valuesize; }; struct komodo_event_notarized { uint256 blockhash,desttxid; int32_t notarizedheight; char dest[16]; }; struct komodo_event_pubkeys { uint8_t num; uint8_t pubkeys[64][33]; }; diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 50b17e171..27b074085 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -406,11 +406,11 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len); uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n); int32_t komodo_minerids(uint8_t *minerids,int32_t height); -int32_t komodo_kvsearch(int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); +int32_t komodo_kvsearch(uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); Value kvsearch(const Array& params, bool fHelp) { - Object ret; uint8_t value[IGUANA_MAXSCRIPTSIZE],key[IGUANA_MAXSCRIPTSIZE]; int32_t j,height,valuesize,keylen; + Object ret; uint32_t flags; uint8_t value[IGUANA_MAXSCRIPTSIZE],key[IGUANA_MAXSCRIPTSIZE]; int32_t j,height,valuesize,keylen; if (fHelp || params.size() != 1 ) throw runtime_error("kvsearch key"); LOCK(cs_main); @@ -423,13 +423,14 @@ Value kvsearch(const Array& params, bool fHelp) if ( keylen < sizeof(key) ) { memcpy(key,params[0].get_str().c_str(),keylen); - if ( (valuesize= komodo_kvsearch(&height,value,key,keylen)) >= 0 ) + if ( (valuesize= komodo_kvsearch(&flags,&height,value,key,keylen)) >= 0 ) { std::string val; char *valuestr; val.resize(valuesize); valuestr = (char *)val.data(); memcpy(valuestr,value,valuesize); ret.push_back(Pair("height",height)); + ret.push_back(Pair("flags",flags)); ret.push_back(Pair("value",val)); ret.push_back(Pair("valuesize",valuesize)); } else ret.push_back(Pair("error",(char *)"cant find key")); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 126a98efc..29ee929bc 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -404,9 +404,9 @@ static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtr for (i=0; ics_wallet); if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) { @@ -573,6 +576,7 @@ Value kvupdate(const Array& params, bool fHelp) ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); height = chainActive.Tip()->nHeight; ret.push_back(Pair("height", (int64_t)height)); + ret.push_back(Pair("flags",flags)); ret.push_back(Pair("key",params[0].get_str())); ret.push_back(Pair("keylen",keylen)); if ( params.size() == 2 && params[1].get_str().c_str() != 0 ) @@ -585,13 +589,14 @@ Value kvupdate(const Array& params, bool fHelp) iguana_rwnum(1,&keyvalue[0],sizeof(keylen),&keylen); iguana_rwnum(1,&keyvalue[2],sizeof(valuesize),&valuesize); iguana_rwnum(1,&keyvalue[4],sizeof(height),&height); - memcpy(&keyvalue[8],key,keylen); + iguana_rwnum(1,&keyvalue[8],sizeof(flags),&flags); + memcpy(&keyvalue[12],key,keylen); if ( value != 0 ) - memcpy(&keyvalue[8 + keylen],value,valuesize); - opretlen = komodo_opreturnscript(opretbuf,'K',keyvalue,sizeof(height)+sizeof(uint16_t)*2+keylen+valuesize); - for (i=0; i Date: Fri, 20 Jan 2017 22:19:15 +0200 Subject: [PATCH 096/162] test --- src/wallet/rpcwallet.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 29ee929bc..597ddf1d0 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -573,12 +573,17 @@ Value kvupdate(const Array& params, bool fHelp) if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) { key = (uint8_t *)params[0].get_str().c_str(); + if ( (valuesize= komodo_kvsearch(&flags,&height,&keyvalue[keylen],key,keylen)) >= 0 && (flags & 1) != 0 ) + { + ret.push_back(Pair("error",(char *)"cant modify write once key")); + return ret; + } ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); height = chainActive.Tip()->nHeight; ret.push_back(Pair("height", (int64_t)height)); - ret.push_back(Pair("flags",flags)); + ret.push_back(Pair("flags",(int64_t)flags)); ret.push_back(Pair("key",params[0].get_str())); - ret.push_back(Pair("keylen",keylen)); + ret.push_back(Pair("keylen",(int64_t)keylen)); if ( params.size() == 2 && params[1].get_str().c_str() != 0 ) { value = (uint8_t *)params[1].get_str().c_str(); From b17d44f3541b43154d0859d4558308fa9f704ca2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 22:20:13 +0200 Subject: [PATCH 097/162] test --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 27b074085..9c01e3b9b 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -430,7 +430,7 @@ Value kvsearch(const Array& params, bool fHelp) valuestr = (char *)val.data(); memcpy(valuestr,value,valuesize); ret.push_back(Pair("height",height)); - ret.push_back(Pair("flags",flags)); + ret.push_back(Pair("flags",(int64_t)flags)); ret.push_back(Pair("value",val)); ret.push_back(Pair("valuesize",valuesize)); } else ret.push_back(Pair("error",(char *)"cant find key")); From 69e5f7bbf3c980952c74d2069a1e54565980abc1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 22:21:30 +0200 Subject: [PATCH 098/162] test --- src/wallet/rpcwallet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 597ddf1d0..81f598447 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -484,6 +484,7 @@ int32_t komodo_is_issuer(); int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp); int32_t komodo_isrealtime(int32_t *kmdheightp); int32_t pax_fiatstatus(uint64_t *available,uint64_t *deposited,uint64_t *issued,uint64_t *withdrawn,uint64_t *approved,uint64_t *redeemed,char *base); +int32_t komodo_kvsearch(uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); Value paxdeposit(const Array& params, bool fHelp) { @@ -563,7 +564,7 @@ Value kvupdate(const Array& params, bool fHelp) CWalletTx wtx; Object ret; uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t opretlen,height; uint16_t keylen,valuesize=0; uint8_t *key,*value=0; uint32_t flags; struct komodo_kv *ptr; uint64_t fee; if (fHelp || params.size() < 2 ) - throw runtime_error("kvupdate key value"); + throw runtime_error("kvupdate key value [flags]"); if (!EnsureWalletIsAvailable(fHelp)) return 0; if ( params.size() == 3 ) From 64449ba8197bccc800ba627a72e35a018c36a99e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 22:39:49 +0200 Subject: [PATCH 099/162] test --- src/komodo_gateway.h | 40 ++++++++++++++++++++++++++++------------ src/komodo_structs.h | 4 ++++ src/rpcblockchain.cpp | 4 ++-- src/wallet/rpcwallet.cpp | 7 ++++--- 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a048a597b..d7a7c4a39 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -671,19 +671,32 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above return(0); } -int32_t komodo_kvsearch(uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen) +int32_t komodo_kvsearch(int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen) { - struct komodo_kv *ptr; int32_t retval = -1; + struct komodo_kv *ptr; int32_t duration,retval = -1; *heightp = -1; *flagsp = 0; portable_mutex_lock(&KOMODO_KV_mutex); HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); if ( ptr != 0 ) { - *heightp = ptr->height; - *flagsp = ptr->flags; - if ( (retval= ptr->valuesize) != 0 ) - memcpy(value,ptr->value,retval); + duration = ((ptr->flags >> 2) + 1) * KOMODO_KVDURATION; + if ( current_height > (ptr->height + duration) ) + { + HASH_DELETE(hh,KOMODO_KV,ptr); + if ( ptr->value != 0 ) + free(ptr->value); + if ( ptr->key != 0 ) + free(ptr->key); + free(ptr); + } + else + { + *heightp = ptr->height; + *flagsp = ptr->flags; + if ( (retval= ptr->valuesize) != 0 ) + memcpy(value,ptr->value,retval); + } } portable_mutex_unlock(&KOMODO_KV_mutex); return(retval); @@ -730,14 +743,17 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 memcpy(ptr->key,key,keylen); HASH_ADD_KEYPTR(hh,KOMODO_KV,ptr->key,ptr->keylen,ptr); } - if ( ptr->value != 0 ) - free(ptr->value), ptr->value = 0; - if ( (ptr->valuesize= valuesize) != 0 ) + else if ( (ptr->flags & KOMODO_KVPROTECTED) == 0 ) { - ptr->value = (uint8_t *)calloc(1,valuesize); - memcpy(ptr->value,value,valuesize); + if ( ptr->value != 0 ) + free(ptr->value), ptr->value = 0; + if ( (ptr->valuesize= valuesize) != 0 ) + { + ptr->value = (uint8_t *)calloc(1,valuesize); + memcpy(ptr->value,value,valuesize); + } + ptr->height = kmdheight; } - ptr->height = kmdheight; portable_mutex_unlock(&KOMODO_KV_mutex); } else printf("opretlen.%d mismatch keylen.%d valuesize.%d\n",opretlen,keylen,valuesize); } diff --git a/src/komodo_structs.h b/src/komodo_structs.h index 73194ab8e..672516ee3 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -37,6 +37,10 @@ #define KOMODO_OPRETURN_WITHDRAW 'W' // assetchain #define KOMODO_OPRETURN_REDEEMED 'X' +#define KOMODO_KVPROTECTED 1 +#define KOMODO_KVBINARY 2 +#define KOMODO_KVDURATION 1440 + struct komodo_kv { UT_hash_handle hh; uint8_t *key,*value; int32_t height; uint32_t flags; uint16_t keylen,valuesize; }; struct komodo_event_notarized { uint256 blockhash,desttxid; int32_t notarizedheight; char dest[16]; }; diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 9c01e3b9b..3fa60b80e 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -406,7 +406,7 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len); uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n); int32_t komodo_minerids(uint8_t *minerids,int32_t height); -int32_t komodo_kvsearch(uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); +int32_t komodo_kvsearch(int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); Value kvsearch(const Array& params, bool fHelp) { @@ -423,7 +423,7 @@ Value kvsearch(const Array& params, bool fHelp) if ( keylen < sizeof(key) ) { memcpy(key,params[0].get_str().c_str(),keylen); - if ( (valuesize= komodo_kvsearch(&flags,&height,value,key,keylen)) >= 0 ) + if ( (valuesize= komodo_kvsearch(chainActive.Tip()->nHeight,&flags,&height,value,key,keylen)) >= 0 ) { std::string val; char *valuestr; val.resize(valuesize); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 81f598447..141729f6a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -475,6 +475,7 @@ Value sendtoaddress(const Array& params, bool fHelp) return wtx.GetHash().GetHex(); } +#define KOMODO_KVPROTECTED 1 #define IGUANA_MAXSCRIPTSIZE 10001 uint64_t PAX_fiatdest(uint64_t *seedp,int32_t tokomodo,char *destaddr,uint8_t pubkey37[37],char *coinaddr,int32_t height,char *base,int64_t fiatoshis); int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_t opretlen); @@ -484,7 +485,7 @@ int32_t komodo_is_issuer(); int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp); int32_t komodo_isrealtime(int32_t *kmdheightp); int32_t pax_fiatstatus(uint64_t *available,uint64_t *deposited,uint64_t *issued,uint64_t *withdrawn,uint64_t *approved,uint64_t *redeemed,char *base); -int32_t komodo_kvsearch(uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); +int32_t komodo_kvsearch(int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); Value paxdeposit(const Array& params, bool fHelp) { @@ -574,7 +575,7 @@ Value kvupdate(const Array& params, bool fHelp) if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) { key = (uint8_t *)params[0].get_str().c_str(); - if ( (valuesize= komodo_kvsearch(&flags,&height,&keyvalue[keylen],key,keylen)) >= 0 && (flags & 1) != 0 ) + if ( (valuesize= komodo_kvsearch(chainActive.Tip()->nHeight,&flags,&height,&keyvalue[keylen],key,keylen)) >= 0 && (flags & KOMODO_KVPROTECTED) != 0 ) { ret.push_back(Pair("error",(char *)"cant modify write once key")); return ret; @@ -604,7 +605,7 @@ Value kvupdate(const Array& params, bool fHelp) // printf("%02x",opretbuf[i]); //printf(" opretbuf keylen.%d valuesize.%d height.%d (%02x %02x %02x)\n",*(uint16_t *)&keyvalue[0],*(uint16_t *)&keyvalue[2],*(uint32_t *)&keyvalue[4],keyvalue[8],keyvalue[9],keyvalue[10]); EnsureWalletIsUnlocked(); - if ( (fee= opretlen * opretlen / keylen) < 100000 ) + if ( (fee= ((flags>>2)+1)*(opretlen * opretlen / keylen)) < 100000 ) fee = 100000; CBitcoinAddress destaddress(CRYPTO777_KMDADDR); if (!destaddress.IsValid()) From 4b111c219f3fea187fa7106ffd61ac61de716e9d Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 22:47:35 +0200 Subject: [PATCH 100/162] test --- src/komodo_gateway.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d7a7c4a39..8249daa49 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -681,6 +681,7 @@ int32_t komodo_kvsearch(int32_t current_height,uint32_t *flagsp,int32_t *heightp if ( ptr != 0 ) { duration = ((ptr->flags >> 2) + 1) * KOMODO_KVDURATION; + printf("duration.%d flags.%d current.%d ht.%d\n",duration,ptr->flags,current_height,ptr->height); if ( current_height > (ptr->height + duration) ) { HASH_DELETE(hh,KOMODO_KV,ptr); From 28a37cb90746cdcb246dcda964a95a9572bcbb07 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 22:51:35 +0200 Subject: [PATCH 101/162] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 8249daa49..b121de101 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -730,7 +730,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 iguana_rwnum(0,&opretbuf[9],sizeof(flags),&flags); key = &opretbuf[13]; value = &key[keylen]; - //printf("keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",keylen,valuesize,kmdheight,key[0],key[1],key[2],value[0],value[1],value[2]); + printf("keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",keylen,valuesize,kmdheight,key[0],key[1],key[2],value[0],value[1],value[2]); if ( sizeof(flags)+sizeof(kmdheight)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1 == opretlen ) { portable_mutex_lock(&KOMODO_KV_mutex); From 0b748e97fc6b0a87a67399d6887fff9f8c8ca359 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 22:54:47 +0200 Subject: [PATCH 102/162] test --- src/rpcclient.cpp | 2 +- src/wallet/rpcwallet.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index 241adbdec..a384b063d 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -113,7 +113,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "notaries", 1 }, { "minerids", 1 }, { "kvsearch", 1 }, - { "kvupdate", 2 }, + { "kvupdate", 3 }, }; class CRPCConvertTable diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 141729f6a..39fefecd1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -600,7 +600,8 @@ Value kvupdate(const Array& params, bool fHelp) memcpy(&keyvalue[12],key,keylen); if ( value != 0 ) memcpy(&keyvalue[12 + keylen],value,valuesize); - opretlen = komodo_opreturnscript(opretbuf,'K',keyvalue,sizeof(flags)+sizeof(height)+sizeof(uint16_t)*2+keylen+valuesize); + if ( (opretlen= komodo_opreturnscript(opretbuf,'K',keyvalue,sizeof(flags)+sizeof(height)+sizeof(uint16_t)*2+keylen+valuesize)) == 40 ) + opretlen++; //for (i=0; i Date: Fri, 20 Jan 2017 22:59:07 +0200 Subject: [PATCH 103/162] test --- src/wallet/rpcwallet.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 39fefecd1..70a261bf7 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -569,8 +569,10 @@ Value kvupdate(const Array& params, bool fHelp) if (!EnsureWalletIsAvailable(fHelp)) return 0; if ( params.size() == 3 ) + { flags = atoi(params[2].get_str().c_str()); - else flags = 0; + printf("flags.%d (%s)\n",flags,params[2].get_str().c_str()); + } else flags = 0; LOCK2(cs_main, pwalletMain->cs_wallet); if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) { From 5658d39db6a1ed9b28eee69cf7d9bf481bc47879 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 23:04:04 +0200 Subject: [PATCH 104/162] test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 70a261bf7..2428c9cf2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -588,7 +588,7 @@ Value kvupdate(const Array& params, bool fHelp) ret.push_back(Pair("flags",(int64_t)flags)); ret.push_back(Pair("key",params[0].get_str())); ret.push_back(Pair("keylen",(int64_t)keylen)); - if ( params.size() == 2 && params[1].get_str().c_str() != 0 ) + if ( params.size() >= 2 && params[1].get_str().c_str() != 0 ) { value = (uint8_t *)params[1].get_str().c_str(); valuesize = (int32_t)strlen(params[1].get_str().c_str()); From d3a30109611eaf7d87992abde03fefec083c28b9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 23:13:40 +0200 Subject: [PATCH 105/162] test --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 2428c9cf2..bbaf05656 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -563,7 +563,7 @@ Value paxwithdraw(const Array& params, bool fHelp) Value kvupdate(const Array& params, bool fHelp) { CWalletTx wtx; Object ret; - uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t opretlen,height; uint16_t keylen,valuesize=0; uint8_t *key,*value=0; uint32_t flags; struct komodo_kv *ptr; uint64_t fee; + uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t opretlen,height; uint16_t keylen,valuesize=0; uint8_t *key,*value=0; uint32_t flags,tmpflags; struct komodo_kv *ptr; uint64_t fee; if (fHelp || params.size() < 2 ) throw runtime_error("kvupdate key value [flags]"); if (!EnsureWalletIsAvailable(fHelp)) @@ -577,7 +577,7 @@ Value kvupdate(const Array& params, bool fHelp) if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) { key = (uint8_t *)params[0].get_str().c_str(); - if ( (valuesize= komodo_kvsearch(chainActive.Tip()->nHeight,&flags,&height,&keyvalue[keylen],key,keylen)) >= 0 && (flags & KOMODO_KVPROTECTED) != 0 ) + if ( (valuesize= komodo_kvsearch(chainActive.Tip()->nHeight,&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 && (tmpflags & KOMODO_KVPROTECTED) != 0 ) { ret.push_back(Pair("error",(char *)"cant modify write once key")); return ret; From 667f6dd525627e470682b71ab369a1e4f817ec80 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 23:21:58 +0200 Subject: [PATCH 106/162] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b121de101..a08cdb758 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -730,7 +730,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 iguana_rwnum(0,&opretbuf[9],sizeof(flags),&flags); key = &opretbuf[13]; value = &key[keylen]; - printf("keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",keylen,valuesize,kmdheight,key[0],key[1],key[2],value[0],value[1],value[2]); + printf("flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",flags,keylen,valuesize,kmdheight,key[0],key[1],key[2],value[0],value[1],value[2]); if ( sizeof(flags)+sizeof(kmdheight)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1 == opretlen ) { portable_mutex_lock(&KOMODO_KV_mutex); From eb651307cb887c76b8cc09df5f70a80786706cdf Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 23:24:35 +0200 Subject: [PATCH 107/162] test --- src/komodo_gateway.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a08cdb758..7723d689a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -754,6 +754,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 memcpy(ptr->value,value,valuesize); } ptr->height = kmdheight; + ptr->flags = flags; } portable_mutex_unlock(&KOMODO_KV_mutex); } else printf("opretlen.%d mismatch keylen.%d valuesize.%d\n",opretlen,keylen,valuesize); From a6b182bd5dfc8cc1f1640626f6c0140dc50ecf78 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 23:29:22 +0200 Subject: [PATCH 108/162] test --- src/rpcblockchain.cpp | 4 +++- src/wallet/rpcwallet.cpp | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 3fa60b80e..ec36a9962 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -410,7 +410,7 @@ int32_t komodo_kvsearch(int32_t current_height,uint32_t *flagsp,int32_t *heightp Value kvsearch(const Array& params, bool fHelp) { - Object ret; uint32_t flags; uint8_t value[IGUANA_MAXSCRIPTSIZE],key[IGUANA_MAXSCRIPTSIZE]; int32_t j,height,valuesize,keylen; + Object ret; uint32_t flags; uint8_t value[IGUANA_MAXSCRIPTSIZE],key[IGUANA_MAXSCRIPTSIZE]; int32_t duration,j,height,valuesize,keylen; if (fHelp || params.size() != 1 ) throw runtime_error("kvsearch key"); LOCK(cs_main); @@ -430,6 +430,8 @@ Value kvsearch(const Array& params, bool fHelp) valuestr = (char *)val.data(); memcpy(valuestr,value,valuesize); ret.push_back(Pair("height",height)); + duration = ((flags >> 2) + 1) * KOMODO_KVDURATION; + ret.push_back(Pair("expiration", (int64_t)(height+duration))); ret.push_back(Pair("flags",(int64_t)flags)); ret.push_back(Pair("value",val)); ret.push_back(Pair("valuesize",valuesize)); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index bbaf05656..1032116a8 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -563,7 +563,7 @@ Value paxwithdraw(const Array& params, bool fHelp) Value kvupdate(const Array& params, bool fHelp) { CWalletTx wtx; Object ret; - uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t opretlen,height; uint16_t keylen,valuesize=0; uint8_t *key,*value=0; uint32_t flags,tmpflags; struct komodo_kv *ptr; uint64_t fee; + uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t duration,opretlen,height; uint16_t keylen,valuesize=0; uint8_t *key,*value=0; uint32_t flags,tmpflags; struct komodo_kv *ptr; uint64_t fee; if (fHelp || params.size() < 2 ) throw runtime_error("kvupdate key value [flags]"); if (!EnsureWalletIsAvailable(fHelp)) @@ -585,6 +585,8 @@ Value kvupdate(const Array& params, bool fHelp) ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); height = chainActive.Tip()->nHeight; ret.push_back(Pair("height", (int64_t)height)); + duration = ((flags >> 2) + 1) * KOMODO_KVDURATION; + ret.push_back(Pair("expiration", (int64_t)(height+duration))); ret.push_back(Pair("flags",(int64_t)flags)); ret.push_back(Pair("key",params[0].get_str())); ret.push_back(Pair("keylen",(int64_t)keylen)); @@ -610,6 +612,7 @@ Value kvupdate(const Array& params, bool fHelp) EnsureWalletIsUnlocked(); if ( (fee= ((flags>>2)+1)*(opretlen * opretlen / keylen)) < 100000 ) fee = 100000; + ret.push_back(Pair("fee",(double)fee/COIN)); CBitcoinAddress destaddress(CRYPTO777_KMDADDR); if (!destaddress.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid dest Bitcoin address"); From 638ac3ba55ae8112bf1eabdf8985a0fb0ce0a2ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 23:32:11 +0200 Subject: [PATCH 109/162] test --- src/rpcblockchain.cpp | 2 ++ src/wallet/rpcwallet.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index ec36a9962..82e5d21e6 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -397,6 +397,8 @@ Value gettxoutsetinfo(const Array& params, bool fHelp) } #define IGUANA_MAXSCRIPTSIZE 10001 +#define KOMODO_KVDURATION 1440 +#define KOMODO_KVBINARY 2 extern char ASSETCHAINS_SYMBOL[16]; uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); uint32_t komodo_txtime(uint256 hash); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1032116a8..113dc7936 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -476,6 +476,8 @@ Value sendtoaddress(const Array& params, bool fHelp) } #define KOMODO_KVPROTECTED 1 +#define KOMODO_KVBINARY 2 +#define KOMODO_KVDURATION 1440 #define IGUANA_MAXSCRIPTSIZE 10001 uint64_t PAX_fiatdest(uint64_t *seedp,int32_t tokomodo,char *destaddr,uint8_t pubkey37[37],char *coinaddr,int32_t height,char *base,int64_t fiatoshis); int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_t opretlen); From ca493c508b13413c18a532d4958ce56f6ddf40ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 23:43:18 +0200 Subject: [PATCH 110/162] test --- src/komodo_gateway.h | 53 ++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7723d689a..72e8ba4c7 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -705,7 +705,7 @@ int32_t komodo_kvsearch(int32_t current_height,uint32_t *flagsp,int32_t *heightp const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout,char *source) { - uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff; uint32_t flags; + uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fee,fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff; uint32_t flags; const char *typestr = "unknown"; if ( KOMODO_PAX == 0 ) return("nopax"); @@ -730,33 +730,38 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 iguana_rwnum(0,&opretbuf[9],sizeof(flags),&flags); key = &opretbuf[13]; value = &key[keylen]; - printf("flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",flags,keylen,valuesize,kmdheight,key[0],key[1],key[2],value[0],value[1],value[2]); - if ( sizeof(flags)+sizeof(kmdheight)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1 == opretlen ) + if ( (fee= ((flags>>2)+1)*(opretlen * opretlen / keylen)) < 100000 ) + fee = 100000; + printf("fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,kmdheight,key[0],key[1],key[2],value[0],value[1],value[2]); + if ( value >= fee ) { - portable_mutex_lock(&KOMODO_KV_mutex); - HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); - if ( ptr == 0 ) + if ( sizeof(flags)+sizeof(kmdheight)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1 == opretlen ) { - ptr = (struct komodo_kv *)calloc(1,sizeof(*ptr)); - ptr->flags = flags; - ptr->key = (uint8_t *)calloc(1,keylen); - ptr->keylen = keylen; - memcpy(ptr->key,key,keylen); - HASH_ADD_KEYPTR(hh,KOMODO_KV,ptr->key,ptr->keylen,ptr); - } - else if ( (ptr->flags & KOMODO_KVPROTECTED) == 0 ) - { - if ( ptr->value != 0 ) - free(ptr->value), ptr->value = 0; - if ( (ptr->valuesize= valuesize) != 0 ) + portable_mutex_lock(&KOMODO_KV_mutex); + HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); + if ( ptr == 0 ) { - ptr->value = (uint8_t *)calloc(1,valuesize); - memcpy(ptr->value,value,valuesize); + ptr = (struct komodo_kv *)calloc(1,sizeof(*ptr)); + ptr->flags = flags; + ptr->key = (uint8_t *)calloc(1,keylen); + ptr->keylen = keylen; + memcpy(ptr->key,key,keylen); + HASH_ADD_KEYPTR(hh,KOMODO_KV,ptr->key,ptr->keylen,ptr); } - ptr->height = kmdheight; - ptr->flags = flags; - } - portable_mutex_unlock(&KOMODO_KV_mutex); + else if ( (ptr->flags & KOMODO_KVPROTECTED) == 0 ) + { + if ( ptr->value != 0 ) + free(ptr->value), ptr->value = 0; + if ( (ptr->valuesize= valuesize) != 0 ) + { + ptr->value = (uint8_t *)calloc(1,valuesize); + memcpy(ptr->value,value,valuesize); + } + ptr->height = kmdheight; + ptr->flags = flags; + } + portable_mutex_unlock(&KOMODO_KV_mutex); + } else printf("insufficient fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,kmdheight,key[0],key[1],key[2],value[0],value[1],value[2]); } else printf("opretlen.%d mismatch keylen.%d valuesize.%d\n",opretlen,keylen,valuesize); } else if ( opretbuf[0] == 'D' ) From 07906eb94c3ef25968e31492b06b9fee58c8a70e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 20 Jan 2017 23:45:35 +0200 Subject: [PATCH 111/162] test --- src/komodo_gateway.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 72e8ba4c7..4950c4e6d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -723,16 +723,16 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 tokomodo = (komodo_is_issuer() == 0); if ( opretbuf[0] == 'K' && opretlen != 40 ) { - uint16_t keylen,valuesize; uint8_t *key,*value; struct komodo_kv *ptr; + uint16_t keylen,valuesize; uint8_t *key,*valueptr; struct komodo_kv *ptr; iguana_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen); iguana_rwnum(0,&opretbuf[3],sizeof(valuesize),&valuesize); iguana_rwnum(0,&opretbuf[5],sizeof(kmdheight),&kmdheight); iguana_rwnum(0,&opretbuf[9],sizeof(flags),&flags); key = &opretbuf[13]; - value = &key[keylen]; + valueptr = &key[keylen]; if ( (fee= ((flags>>2)+1)*(opretlen * opretlen / keylen)) < 100000 ) fee = 100000; - printf("fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,kmdheight,key[0],key[1],key[2],value[0],value[1],value[2]); + printf("fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,kmdheight,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); if ( value >= fee ) { if ( sizeof(flags)+sizeof(kmdheight)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1 == opretlen ) @@ -755,13 +755,13 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 if ( (ptr->valuesize= valuesize) != 0 ) { ptr->value = (uint8_t *)calloc(1,valuesize); - memcpy(ptr->value,value,valuesize); + memcpy(ptr->value,valueptr,valuesize); } ptr->height = kmdheight; ptr->flags = flags; } portable_mutex_unlock(&KOMODO_KV_mutex); - } else printf("insufficient fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,kmdheight,key[0],key[1],key[2],value[0],value[1],value[2]); + } else printf("insufficient fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,kmdheight,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); } else printf("opretlen.%d mismatch keylen.%d valuesize.%d\n",opretlen,keylen,valuesize); } else if ( opretbuf[0] == 'D' ) From 399ebd854ed9419c32d8d294a0f4d8edcb4fbf57 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 21 Jan 2017 12:38:06 +0200 Subject: [PATCH 112/162] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 4950c4e6d..a6c9a4766 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -681,7 +681,7 @@ int32_t komodo_kvsearch(int32_t current_height,uint32_t *flagsp,int32_t *heightp if ( ptr != 0 ) { duration = ((ptr->flags >> 2) + 1) * KOMODO_KVDURATION; - printf("duration.%d flags.%d current.%d ht.%d\n",duration,ptr->flags,current_height,ptr->height); + printf("duration.%d flags.%d current.%d ht.%d keylen.%d valuesize.%d\n",duration,ptr->flags,current_height,ptr->height,ptr->keylen,ptr->valuesize); if ( current_height > (ptr->height + duration) ) { HASH_DELETE(hh,KOMODO_KV,ptr); From 51ff33a485fe859487606be9c76e5f8b08c80d86 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 21 Jan 2017 13:01:54 +0200 Subject: [PATCH 113/162] test --- src/komodo_gateway.h | 31 +++++++++++++++++++++++-------- src/wallet/rpcwallet.cpp | 14 +++++++++----- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a6c9a4766..f9d058799 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -703,6 +703,17 @@ int32_t komodo_kvsearch(int32_t current_height,uint32_t *flagsp,int32_t *heightp return(retval); } +int32_t komodo_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint16_t valuesize) +{ + if ( refvalue == 0 && value == 0 ) + return(0); + else if ( refvalue == 0 || value == 0 ) + return(-1); + else if ( refvaluesize != valuesize ) + return(-1); + else return(memcmp(refvalue,value,valuesize); +} + const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout,char *source) { uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fee,fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff; uint32_t flags; @@ -723,7 +734,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 tokomodo = (komodo_is_issuer() == 0); if ( opretbuf[0] == 'K' && opretlen != 40 ) { - uint16_t keylen,valuesize; uint8_t *key,*valueptr; struct komodo_kv *ptr; + uint16_t keylen,valuesize,newflag = 0,cmpval = 1; uint8_t *key,*valueptr; struct komodo_kv *ptr; iguana_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen); iguana_rwnum(0,&opretbuf[3],sizeof(valuesize),&valuesize); iguana_rwnum(0,&opretbuf[5],sizeof(kmdheight),&kmdheight); @@ -732,6 +743,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 valueptr = &key[keylen]; if ( (fee= ((flags>>2)+1)*(opretlen * opretlen / keylen)) < 100000 ) fee = 100000; + // 6a164b040005006a00000000000000746573743834393333 printf("fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,kmdheight,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); if ( value >= fee ) { @@ -742,20 +754,23 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 if ( ptr == 0 ) { ptr = (struct komodo_kv *)calloc(1,sizeof(*ptr)); - ptr->flags = flags; ptr->key = (uint8_t *)calloc(1,keylen); ptr->keylen = keylen; memcpy(ptr->key,key,keylen); + newflag = 1; HASH_ADD_KEYPTR(hh,KOMODO_KV,ptr->key,ptr->keylen,ptr); } - else if ( (ptr->flags & KOMODO_KVPROTECTED) == 0 ) + if ( newflag != 0 || (ptr->flags & KOMODO_KVPROTECTED) == 0 || (cmpval= komodo_kvcmp(ptr->value,ptr->valuesize,value,valuesize)) == 0 ) { - if ( ptr->value != 0 ) - free(ptr->value), ptr->value = 0; - if ( (ptr->valuesize= valuesize) != 0 ) + if ( cmpval != 0 ) { - ptr->value = (uint8_t *)calloc(1,valuesize); - memcpy(ptr->value,valueptr,valuesize); + if ( ptr->value != 0 ) + free(ptr->value), ptr->value = 0; + if ( (ptr->valuesize= valuesize) != 0 ) + { + ptr->value = (uint8_t *)calloc(1,valuesize); + memcpy(ptr->value,valueptr,valuesize); + } } ptr->height = kmdheight; ptr->flags = flags; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 113dc7936..2c04a53e0 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -488,6 +488,7 @@ int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endian int32_t komodo_isrealtime(int32_t *kmdheightp); int32_t pax_fiatstatus(uint64_t *available,uint64_t *deposited,uint64_t *issued,uint64_t *withdrawn,uint64_t *approved,uint64_t *redeemed,char *base); int32_t komodo_kvsearch(int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); +int32_t komodo_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint16_t valuesize); Value paxdeposit(const Array& params, bool fHelp) { @@ -565,7 +566,7 @@ Value paxwithdraw(const Array& params, bool fHelp) Value kvupdate(const Array& params, bool fHelp) { CWalletTx wtx; Object ret; - uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t duration,opretlen,height; uint16_t keylen,valuesize=0; uint8_t *key,*value=0; uint32_t flags,tmpflags; struct komodo_kv *ptr; uint64_t fee; + uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t duration,opretlen,height; uint16_t keylen,valuesize=0,refvaluesize=0; uint8_t *key,*value=0; uint32_t flags,tmpflags; struct komodo_kv *ptr; uint64_t fee; if (fHelp || params.size() < 2 ) throw runtime_error("kvupdate key value [flags]"); if (!EnsureWalletIsAvailable(fHelp)) @@ -573,13 +574,18 @@ Value kvupdate(const Array& params, bool fHelp) if ( params.size() == 3 ) { flags = atoi(params[2].get_str().c_str()); - printf("flags.%d (%s)\n",flags,params[2].get_str().c_str()); + //printf("flags.%d (%s)\n",flags,params[2].get_str().c_str()); } else flags = 0; LOCK2(cs_main, pwalletMain->cs_wallet); if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) { key = (uint8_t *)params[0].get_str().c_str(); - if ( (valuesize= komodo_kvsearch(chainActive.Tip()->nHeight,&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 && (tmpflags & KOMODO_KVPROTECTED) != 0 ) + if ( params.size() >= 2 && params[1].get_str().c_str() != 0 ) + { + value = (uint8_t *)params[1].get_str().c_str(); + valuesize = (int32_t)strlen(params[1].get_str().c_str()); + } + if ( (refvaluesize= komodo_kvsearch(chainActive.Tip()->nHeight,&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 && (tmpflags & KOMODO_KVPROTECTED) != 0 && komodo_kvcmp(refvaluesize==0?0:&keyvalue[keylen],refvaluesize,value,valuesize) != 0 ) { ret.push_back(Pair("error",(char *)"cant modify write once key")); return ret; @@ -594,8 +600,6 @@ Value kvupdate(const Array& params, bool fHelp) ret.push_back(Pair("keylen",(int64_t)keylen)); if ( params.size() >= 2 && params[1].get_str().c_str() != 0 ) { - value = (uint8_t *)params[1].get_str().c_str(); - valuesize = (int32_t)strlen(params[1].get_str().c_str()); ret.push_back(Pair("value",params[1].get_str())); ret.push_back(Pair("valuesize",valuesize)); } From 13382b822d980d2075e62a43bbadd1d8ad5a50fe Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 21 Jan 2017 13:19:33 +0200 Subject: [PATCH 114/162] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index e1c62bfa8..40d71f291 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -256,7 +256,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; if ( fwrite(opretbuf,1,olen,fp) != olen ) errs++; - //printf("ht.%d R opret[%d]\n",height,olen); +printf("ht.%d R opret[%d] sp.%p\n",height,olen,sp); //komodo_opreturn(height,opretvalue,opretbuf,olen,txhash,vout); komodo_eventadd_opreturn(sp,symbol,height,txhash,opretvalue,vout,opretbuf,olen); } From 28221080bb10fb299e8b0a5a31d72f34c8c1cf72 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 21 Jan 2017 13:21:57 +0200 Subject: [PATCH 115/162] test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index f9d058799..7d80d64cf 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -711,7 +711,7 @@ int32_t komodo_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint return(-1); else if ( refvaluesize != valuesize ) return(-1); - else return(memcmp(refvalue,value,valuesize); + else return(memcmp(refvalue,value,valuesize)); } const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout,char *source) @@ -760,7 +760,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 newflag = 1; HASH_ADD_KEYPTR(hh,KOMODO_KV,ptr->key,ptr->keylen,ptr); } - if ( newflag != 0 || (ptr->flags & KOMODO_KVPROTECTED) == 0 || (cmpval= komodo_kvcmp(ptr->value,ptr->valuesize,value,valuesize)) == 0 ) + if ( newflag != 0 || (ptr->flags & KOMODO_KVPROTECTED) == 0 || (cmpval= komodo_kvcmp(ptr->value,ptr->valuesize,valueptr,valuesize)) == 0 ) { if ( cmpval != 0 ) { From 088b1fa80164f65ef80f68179330196875512dab Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 21 Jan 2017 13:26:47 +0200 Subject: [PATCH 116/162] test --- src/komodo.h | 2 +- src/komodo_gateway.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 40d71f291..f963ab819 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -256,7 +256,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; if ( fwrite(opretbuf,1,olen,fp) != olen ) errs++; -printf("ht.%d R opret[%d] sp.%p\n",height,olen,sp); +//printf("ht.%d R opret[%d] sp.%p\n",height,olen,sp); //komodo_opreturn(height,opretvalue,opretbuf,olen,txhash,vout); komodo_eventadd_opreturn(sp,symbol,height,txhash,opretvalue,vout,opretbuf,olen); } diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7d80d64cf..1ac4165fd 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -718,13 +718,13 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fee,fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff; uint32_t flags; const char *typestr = "unknown"; - if ( KOMODO_PAX == 0 ) - return("nopax"); - if ( ASSETCHAINS_SYMBOL[0] != 0 && komodo_baseid(ASSETCHAINS_SYMBOL) < 0 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 && komodo_baseid(ASSETCHAINS_SYMBOL) < 0 && opretbuf[0] != 'K' ) { //printf("komodo_opreturn skip %s\n",ASSETCHAINS_SYMBOL); return("assetchain"); } + else if ( KOMODO_PAX == 0 ) + return("nopax"); memset(baseids,0xff,sizeof(baseids)); memset(values,0,sizeof(values)); memset(srcvalues,0,sizeof(srcvalues)); From 96e95a2adc5f49ad3fadb7c7689ecbe432ab7726 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 21 Jan 2017 13:30:28 +0200 Subject: [PATCH 117/162] KV support --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1ac4165fd..35dbba2fa 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -681,7 +681,7 @@ int32_t komodo_kvsearch(int32_t current_height,uint32_t *flagsp,int32_t *heightp if ( ptr != 0 ) { duration = ((ptr->flags >> 2) + 1) * KOMODO_KVDURATION; - printf("duration.%d flags.%d current.%d ht.%d keylen.%d valuesize.%d\n",duration,ptr->flags,current_height,ptr->height,ptr->keylen,ptr->valuesize); + //printf("duration.%d flags.%d current.%d ht.%d keylen.%d valuesize.%d\n",duration,ptr->flags,current_height,ptr->height,ptr->keylen,ptr->valuesize); if ( current_height > (ptr->height + duration) ) { HASH_DELETE(hh,KOMODO_KV,ptr); @@ -744,7 +744,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 if ( (fee= ((flags>>2)+1)*(opretlen * opretlen / keylen)) < 100000 ) fee = 100000; // 6a164b040005006a00000000000000746573743834393333 - printf("fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,kmdheight,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); + //printf("fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,kmdheight,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); if ( value >= fee ) { if ( sizeof(flags)+sizeof(kmdheight)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1 == opretlen ) From 37712133225dd37c176d965ffe3febe1eeb5e747 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 21 Jan 2017 21:39:30 +0200 Subject: [PATCH 118/162] test --- src/komodo_gateway.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 35dbba2fa..e51db53a5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -716,7 +716,7 @@ int32_t komodo_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout,char *source) { - uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fee,fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff; uint32_t flags; + uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33],valuebuf[IGUANA_MAXSCRIPTSIZE]; int32_t didstats,i,j,n,kvheight,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fee,fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff; uint32_t flags; const char *typestr = "unknown"; if ( ASSETCHAINS_SYMBOL[0] != 0 && komodo_baseid(ASSETCHAINS_SYMBOL) < 0 && opretbuf[0] != 'K' ) { @@ -749,6 +749,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { if ( sizeof(flags)+sizeof(kmdheight)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1 == opretlen ) { + komodo_kvsearch(height,&flags,&kvheight,valuebuf,key,keylen); // expire if needed portable_mutex_lock(&KOMODO_KV_mutex); HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); if ( ptr == 0 ) From 46222318d68f553108d75a7151f13643031d85a4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 00:29:29 +0200 Subject: [PATCH 119/162] test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e51db53a5..26e046a25 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -723,8 +723,8 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 //printf("komodo_opreturn skip %s\n",ASSETCHAINS_SYMBOL); return("assetchain"); } - else if ( KOMODO_PAX == 0 ) - return("nopax"); + //else if ( KOMODO_PAX == 0 ) + // return("nopax"); memset(baseids,0xff,sizeof(baseids)); memset(values,0,sizeof(values)); memset(srcvalues,0,sizeof(srcvalues)); From 6b5cfbb4b02010e133ba5bdf4d18b661353bc14b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 13:45:34 +0200 Subject: [PATCH 120/162] signed KV --- src/komodo.h | 2 + src/komodo_curve25519.h | 1154 ++++++++++++++++++++++++++++++++++++++ src/komodo_gateway.h | 91 +-- src/komodo_kv.h | 175 ++++++ src/komodo_structs.h | 8 +- src/rpcblockchain.cpp | 8 +- src/rpcclient.cpp | 2 +- src/wallet/rpcwallet.cpp | 59 +- 8 files changed, 1394 insertions(+), 105 deletions(-) create mode 100644 src/komodo_curve25519.h create mode 100644 src/komodo_kv.h diff --git a/src/komodo.h b/src/komodo.h index f963ab819..ed90ffccd 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -36,6 +36,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block); #include "komodo_structs.h" #include "komodo_globals.h" #include "komodo_utils.h" +#include "komodo_curve25519.h" #include "cJSON.c" #include "komodo_bitcoind.h" @@ -44,6 +45,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block); #include "komodo_notary.h" int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char *dest); +#include "komodo_kv.h" #include "komodo_gateway.h" #include "komodo_events.h" diff --git a/src/komodo_curve25519.h b/src/komodo_curve25519.h new file mode 100644 index 000000000..1b97328b2 --- /dev/null +++ b/src/komodo_curve25519.h @@ -0,0 +1,1154 @@ +/****************************************************************************** + * Copyright © 2014-2017 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#ifndef H_KOMODO25519_H +#define H_KOMODO25519_H +// derived from curve25519_donna + +#include +#include +#include + +bits320 fmul(const bits320 in2,const bits320 in); +bits320 fexpand(bits256 basepoint); +bits256 fcontract(const bits320 input); +void cmult(bits320 *resultx,bits320 *resultz,bits256 secret,const bits320 q); +bits320 crecip(const bits320 z); +bits256 curve25519(bits256 mysecret,bits256 basepoint); + +// Sum two numbers: output += in +static inline bits320 fsum(bits320 output,bits320 in) +{ + int32_t i; + for (i=0; i<5; i++) + output.ulongs[i] += in.ulongs[i]; + return(output); +} + +static inline void fdifference_backwards(uint64_t *out,const uint64_t *in) +{ + static const uint64_t two54m152 = (((uint64_t)1) << 54) - 152; // 152 is 19 << 3 + static const uint64_t two54m8 = (((uint64_t)1) << 54) - 8; + int32_t i; + out[0] = in[0] + two54m152 - out[0]; + for (i=1; i<5; i++) + out[i] = in[i] + two54m8 - out[i]; +} + +void store_limb(uint8_t *out,uint64_t in) +{ + int32_t i; + for (i=0; i<8; i++,in>>=8) + out[i] = (in & 0xff); +} + +static inline uint64_t load_limb(uint8_t *in) +{ + return + ((uint64_t)in[0]) | + (((uint64_t)in[1]) << 8) | + (((uint64_t)in[2]) << 16) | + (((uint64_t)in[3]) << 24) | + (((uint64_t)in[4]) << 32) | + (((uint64_t)in[5]) << 40) | + (((uint64_t)in[6]) << 48) | + (((uint64_t)in[7]) << 56); +} + +// Take a little-endian, 32-byte number and expand it into polynomial form +bits320 fexpand(bits256 basepoint) +{ + bits320 out; + out.ulongs[0] = load_limb(basepoint.bytes) & 0x7ffffffffffffLL; + out.ulongs[1] = (load_limb(basepoint.bytes+6) >> 3) & 0x7ffffffffffffLL; + out.ulongs[2] = (load_limb(basepoint.bytes+12) >> 6) & 0x7ffffffffffffLL; + out.ulongs[3] = (load_limb(basepoint.bytes+19) >> 1) & 0x7ffffffffffffLL; + out.ulongs[4] = (load_limb(basepoint.bytes+24) >> 12) & 0x7ffffffffffffLL; + return(out); +} + +#if __amd64__ +// donna: special gcc mode for 128-bit integers. It's implemented on 64-bit platforms only as far as I know. +typedef unsigned uint128_t __attribute__((mode(TI))); + +// Multiply a number by a scalar: output = in * scalar +static inline bits320 fscalar_product(const bits320 in,const uint64_t scalar) +{ + int32_t i; uint128_t a = 0; bits320 output; + a = ((uint128_t)in.ulongs[0]) * scalar; + output.ulongs[0] = ((uint64_t)a) & 0x7ffffffffffffLL; + for (i=1; i<5; i++) + { + a = ((uint128_t)in.ulongs[i]) * scalar + ((uint64_t) (a >> 51)); + output.ulongs[i] = ((uint64_t)a) & 0x7ffffffffffffLL; + } + output.ulongs[0] += (a >> 51) * 19; + return(output); +} + +// Multiply two numbers: output = in2 * in +// output must be distinct to both inputs. The inputs are reduced coefficient form, the output is not. +// Assumes that in[i] < 2**55 and likewise for in2. On return, output[i] < 2**52 +bits320 fmul(const bits320 in2,const bits320 in) +{ + uint128_t t[5]; uint64_t r0,r1,r2,r3,r4,s0,s1,s2,s3,s4,c; bits320 out; + r0 = in.ulongs[0], r1 = in.ulongs[1], r2 = in.ulongs[2], r3 = in.ulongs[3], r4 = in.ulongs[4]; + s0 = in2.ulongs[0], s1 = in2.ulongs[1], s2 = in2.ulongs[2], s3 = in2.ulongs[3], s4 = in2.ulongs[4]; + t[0] = ((uint128_t) r0) * s0; + t[1] = ((uint128_t) r0) * s1 + ((uint128_t) r1) * s0; + t[2] = ((uint128_t) r0) * s2 + ((uint128_t) r2) * s0 + ((uint128_t) r1) * s1; + t[3] = ((uint128_t) r0) * s3 + ((uint128_t) r3) * s0 + ((uint128_t) r1) * s2 + ((uint128_t) r2) * s1; + t[4] = ((uint128_t) r0) * s4 + ((uint128_t) r4) * s0 + ((uint128_t) r3) * s1 + ((uint128_t) r1) * s3 + ((uint128_t) r2) * s2; + r4 *= 19, r1 *= 19, r2 *= 19, r3 *= 19; + t[0] += ((uint128_t) r4) * s1 + ((uint128_t) r1) * s4 + ((uint128_t) r2) * s3 + ((uint128_t) r3) * s2; + t[1] += ((uint128_t) r4) * s2 + ((uint128_t) r2) * s4 + ((uint128_t) r3) * s3; + t[2] += ((uint128_t) r4) * s3 + ((uint128_t) r3) * s4; + t[3] += ((uint128_t) r4) * s4; + r0 = (uint64_t)t[0] & 0x7ffffffffffffLL; c = (uint64_t)(t[0] >> 51); + t[1] += c; r1 = (uint64_t)t[1] & 0x7ffffffffffffLL; c = (uint64_t)(t[1] >> 51); + t[2] += c; r2 = (uint64_t)t[2] & 0x7ffffffffffffLL; c = (uint64_t)(t[2] >> 51); + t[3] += c; r3 = (uint64_t)t[3] & 0x7ffffffffffffLL; c = (uint64_t)(t[3] >> 51); + t[4] += c; r4 = (uint64_t)t[4] & 0x7ffffffffffffLL; c = (uint64_t)(t[4] >> 51); + r0 += c * 19; c = r0 >> 51; r0 = r0 & 0x7ffffffffffffLL; + r1 += c; c = r1 >> 51; r1 = r1 & 0x7ffffffffffffLL; + r2 += c; + out.ulongs[0] = r0, out.ulongs[1] = r1, out.ulongs[2] = r2, out.ulongs[3] = r3, out.ulongs[4] = r4; + return(out); +} + +bits320 fsquare_times(const bits320 in,uint64_t count) +{ + uint128_t t[5]; uint64_t r0,r1,r2,r3,r4,c,d0,d1,d2,d4,d419; bits320 out; + r0 = in.ulongs[0], r1 = in.ulongs[1], r2 = in.ulongs[2], r3 = in.ulongs[3], r4 = in.ulongs[4]; + do + { + d0 = r0 * 2; + d1 = r1 * 2; + d2 = r2 * 2 * 19; + d419 = r4 * 19; + d4 = d419 * 2; + t[0] = ((uint128_t) r0) * r0 + ((uint128_t) d4) * r1 + (((uint128_t) d2) * (r3 )); + t[1] = ((uint128_t) d0) * r1 + ((uint128_t) d4) * r2 + (((uint128_t) r3) * (r3 * 19)); + t[2] = ((uint128_t) d0) * r2 + ((uint128_t) r1) * r1 + (((uint128_t) d4) * (r3 )); + t[3] = ((uint128_t) d0) * r3 + ((uint128_t) d1) * r2 + (((uint128_t) r4) * (d419 )); + t[4] = ((uint128_t) d0) * r4 + ((uint128_t) d1) * r3 + (((uint128_t) r2) * (r2 )); + + r0 = (uint64_t)t[0] & 0x7ffffffffffffLL; c = (uint64_t)(t[0] >> 51); + t[1] += c; r1 = (uint64_t)t[1] & 0x7ffffffffffffLL; c = (uint64_t)(t[1] >> 51); + t[2] += c; r2 = (uint64_t)t[2] & 0x7ffffffffffffLL; c = (uint64_t)(t[2] >> 51); + t[3] += c; r3 = (uint64_t)t[3] & 0x7ffffffffffffL; c = (uint64_t)(t[3] >> 51); + t[4] += c; r4 = (uint64_t)t[4] & 0x7ffffffffffffLL; c = (uint64_t)(t[4] >> 51); + r0 += c * 19; c = r0 >> 51; r0 = r0 & 0x7ffffffffffffLL; + r1 += c; c = r1 >> 51; r1 = r1 & 0x7ffffffffffffLL; + r2 += c; + } while( --count ); + out.ulongs[0] = r0, out.ulongs[1] = r1, out.ulongs[2] = r2, out.ulongs[3] = r3, out.ulongs[4] = r4; + return(out); +} + +static inline void fcontract_iter(uint128_t t[5],int32_t flag) +{ + int32_t i; uint64_t mask = 0x7ffffffffffffLL; + for (i=0; i<4; i++) + t[i+1] += t[i] >> 51, t[i] &= mask; + if ( flag != 0 ) + t[0] += 19 * (t[4] >> 51); t[4] &= mask; +} + +// donna: Take a fully reduced polynomial form number and contract it into a little-endian, 32-byte array +bits256 fcontract(const bits320 input) +{ + uint128_t t[5]; int32_t i; bits256 out; + for (i=0; i<5; i++) + t[i] = input.ulongs[i]; + fcontract_iter(t,1), fcontract_iter(t,1); + // donna: now t is between 0 and 2^255-1, properly carried. + // donna: case 1: between 0 and 2^255-20. case 2: between 2^255-19 and 2^255-1. + t[0] += 19, fcontract_iter(t,1); + // now between 19 and 2^255-1 in both cases, and offset by 19. + t[0] += 0x8000000000000 - 19; + for (i=1; i<5; i++) + t[i] += 0x8000000000000 - 1; + // now between 2^255 and 2^256-20, and offset by 2^255. + fcontract_iter(t,0); + store_limb(out.bytes,t[0] | (t[1] << 51)); + store_limb(out.bytes+8,(t[1] >> 13) | (t[2] << 38)); + store_limb(out.bytes+16,(t[2] >> 26) | (t[3] << 25)); + store_limb(out.bytes+24,(t[3] >> 39) | (t[4] << 12)); + return(out); +} + +bits256 curve25519(bits256 mysecret,bits256 basepoint) +{ + bits320 bp,x,z; + mysecret.bytes[0] &= 0xf8, mysecret.bytes[31] &= 0x7f, mysecret.bytes[31] |= 0x40; + bp = fexpand(basepoint); + cmult(&x,&z,mysecret,bp); + return(fcontract(fmul(x,crecip(z)))); +} + +#else +// from curve25519-donna.c +typedef uint8_t u8; +typedef int32_t s32; +typedef int64_t limb; + +/* Multiply a number by a scalar: output = in * scalar */ +static void fscalar_product32(limb *output, const limb *in, const limb scalar) { + unsigned i; + for (i = 0; i < 10; ++i) { + output[i] = in[i] * scalar; + } +} + +/* Multiply two numbers: output = in2 * in + * + * output must be distinct to both inputs. The inputs are reduced coefficient + * form, the output is not. + * + * output[x] <= 14 * the largest product of the input limbs. + static void fproduct(limb *output, const limb *in2, const limb *in) { + output[0] = ((limb) ((s32) in2[0])) * ((s32) in[0]); + output[1] = ((limb) ((s32) in2[0])) * ((s32) in[1]) + + ((limb) ((s32) in2[1])) * ((s32) in[0]); + output[2] = 2 * ((limb) ((s32) in2[1])) * ((s32) in[1]) + + ((limb) ((s32) in2[0])) * ((s32) in[2]) + + ((limb) ((s32) in2[2])) * ((s32) in[0]); + output[3] = ((limb) ((s32) in2[1])) * ((s32) in[2]) + + ((limb) ((s32) in2[2])) * ((s32) in[1]) + + ((limb) ((s32) in2[0])) * ((s32) in[3]) + + ((limb) ((s32) in2[3])) * ((s32) in[0]); + output[4] = ((limb) ((s32) in2[2])) * ((s32) in[2]) + + 2 * (((limb) ((s32) in2[1])) * ((s32) in[3]) + + ((limb) ((s32) in2[3])) * ((s32) in[1])) + + ((limb) ((s32) in2[0])) * ((s32) in[4]) + + ((limb) ((s32) in2[4])) * ((s32) in[0]); + output[5] = ((limb) ((s32) in2[2])) * ((s32) in[3]) + + ((limb) ((s32) in2[3])) * ((s32) in[2]) + + ((limb) ((s32) in2[1])) * ((s32) in[4]) + + ((limb) ((s32) in2[4])) * ((s32) in[1]) + + ((limb) ((s32) in2[0])) * ((s32) in[5]) + + ((limb) ((s32) in2[5])) * ((s32) in[0]); + output[6] = 2 * (((limb) ((s32) in2[3])) * ((s32) in[3]) + + ((limb) ((s32) in2[1])) * ((s32) in[5]) + + ((limb) ((s32) in2[5])) * ((s32) in[1])) + + ((limb) ((s32) in2[2])) * ((s32) in[4]) + + ((limb) ((s32) in2[4])) * ((s32) in[2]) + + ((limb) ((s32) in2[0])) * ((s32) in[6]) + + ((limb) ((s32) in2[6])) * ((s32) in[0]); + output[7] = ((limb) ((s32) in2[3])) * ((s32) in[4]) + + ((limb) ((s32) in2[4])) * ((s32) in[3]) + + ((limb) ((s32) in2[2])) * ((s32) in[5]) + + ((limb) ((s32) in2[5])) * ((s32) in[2]) + + ((limb) ((s32) in2[1])) * ((s32) in[6]) + + ((limb) ((s32) in2[6])) * ((s32) in[1]) + + ((limb) ((s32) in2[0])) * ((s32) in[7]) + + ((limb) ((s32) in2[7])) * ((s32) in[0]); + output[8] = ((limb) ((s32) in2[4])) * ((s32) in[4]) + + 2 * (((limb) ((s32) in2[3])) * ((s32) in[5]) + + ((limb) ((s32) in2[5])) * ((s32) in[3]) + + ((limb) ((s32) in2[1])) * ((s32) in[7]) + + ((limb) ((s32) in2[7])) * ((s32) in[1])) + + ((limb) ((s32) in2[2])) * ((s32) in[6]) + + ((limb) ((s32) in2[6])) * ((s32) in[2]) + + ((limb) ((s32) in2[0])) * ((s32) in[8]) + + ((limb) ((s32) in2[8])) * ((s32) in[0]); + output[9] = ((limb) ((s32) in2[4])) * ((s32) in[5]) + + ((limb) ((s32) in2[5])) * ((s32) in[4]) + + ((limb) ((s32) in2[3])) * ((s32) in[6]) + + ((limb) ((s32) in2[6])) * ((s32) in[3]) + + ((limb) ((s32) in2[2])) * ((s32) in[7]) + + ((limb) ((s32) in2[7])) * ((s32) in[2]) + + ((limb) ((s32) in2[1])) * ((s32) in[8]) + + ((limb) ((s32) in2[8])) * ((s32) in[1]) + + ((limb) ((s32) in2[0])) * ((s32) in[9]) + + ((limb) ((s32) in2[9])) * ((s32) in[0]); + output[10] = 2 * (((limb) ((s32) in2[5])) * ((s32) in[5]) + + ((limb) ((s32) in2[3])) * ((s32) in[7]) + + ((limb) ((s32) in2[7])) * ((s32) in[3]) + + ((limb) ((s32) in2[1])) * ((s32) in[9]) + + ((limb) ((s32) in2[9])) * ((s32) in[1])) + + ((limb) ((s32) in2[4])) * ((s32) in[6]) + + ((limb) ((s32) in2[6])) * ((s32) in[4]) + + ((limb) ((s32) in2[2])) * ((s32) in[8]) + + ((limb) ((s32) in2[8])) * ((s32) in[2]); + output[11] = ((limb) ((s32) in2[5])) * ((s32) in[6]) + + ((limb) ((s32) in2[6])) * ((s32) in[5]) + + ((limb) ((s32) in2[4])) * ((s32) in[7]) + + ((limb) ((s32) in2[7])) * ((s32) in[4]) + + ((limb) ((s32) in2[3])) * ((s32) in[8]) + + ((limb) ((s32) in2[8])) * ((s32) in[3]) + + ((limb) ((s32) in2[2])) * ((s32) in[9]) + + ((limb) ((s32) in2[9])) * ((s32) in[2]); + output[12] = ((limb) ((s32) in2[6])) * ((s32) in[6]) + + 2 * (((limb) ((s32) in2[5])) * ((s32) in[7]) + + ((limb) ((s32) in2[7])) * ((s32) in[5]) + + ((limb) ((s32) in2[3])) * ((s32) in[9]) + + ((limb) ((s32) in2[9])) * ((s32) in[3])) + + ((limb) ((s32) in2[4])) * ((s32) in[8]) + + ((limb) ((s32) in2[8])) * ((s32) in[4]); + output[13] = ((limb) ((s32) in2[6])) * ((s32) in[7]) + + ((limb) ((s32) in2[7])) * ((s32) in[6]) + + ((limb) ((s32) in2[5])) * ((s32) in[8]) + + ((limb) ((s32) in2[8])) * ((s32) in[5]) + + ((limb) ((s32) in2[4])) * ((s32) in[9]) + + ((limb) ((s32) in2[9])) * ((s32) in[4]); + output[14] = 2 * (((limb) ((s32) in2[7])) * ((s32) in[7]) + + ((limb) ((s32) in2[5])) * ((s32) in[9]) + + ((limb) ((s32) in2[9])) * ((s32) in[5])) + + ((limb) ((s32) in2[6])) * ((s32) in[8]) + + ((limb) ((s32) in2[8])) * ((s32) in[6]); + output[15] = ((limb) ((s32) in2[7])) * ((s32) in[8]) + + ((limb) ((s32) in2[8])) * ((s32) in[7]) + + ((limb) ((s32) in2[6])) * ((s32) in[9]) + + ((limb) ((s32) in2[9])) * ((s32) in[6]); + output[16] = ((limb) ((s32) in2[8])) * ((s32) in[8]) + + 2 * (((limb) ((s32) in2[7])) * ((s32) in[9]) + + ((limb) ((s32) in2[9])) * ((s32) in[7])); + output[17] = ((limb) ((s32) in2[8])) * ((s32) in[9]) + + ((limb) ((s32) in2[9])) * ((s32) in[8]); + output[18] = 2 * ((limb) ((s32) in2[9])) * ((s32) in[9]); + }*/ + +/* Reduce a long form to a short form by taking the input mod 2^255 - 19. + * + * On entry: |output[i]| < 14*2^54 + * On exit: |output[0..8]| < 280*2^54 */ +static void freduce_degree(limb *output) { + /* Each of these shifts and adds ends up multiplying the value by 19. + * + * For output[0..8], the absolute entry value is < 14*2^54 and we add, at + * most, 19*14*2^54 thus, on exit, |output[0..8]| < 280*2^54. */ + output[8] += output[18] << 4; + output[8] += output[18] << 1; + output[8] += output[18]; + output[7] += output[17] << 4; + output[7] += output[17] << 1; + output[7] += output[17]; + output[6] += output[16] << 4; + output[6] += output[16] << 1; + output[6] += output[16]; + output[5] += output[15] << 4; + output[5] += output[15] << 1; + output[5] += output[15]; + output[4] += output[14] << 4; + output[4] += output[14] << 1; + output[4] += output[14]; + output[3] += output[13] << 4; + output[3] += output[13] << 1; + output[3] += output[13]; + output[2] += output[12] << 4; + output[2] += output[12] << 1; + output[2] += output[12]; + output[1] += output[11] << 4; + output[1] += output[11] << 1; + output[1] += output[11]; + output[0] += output[10] << 4; + output[0] += output[10] << 1; + output[0] += output[10]; +} + +#if (-1 & 3) != 3 +#error "This code only works on a two's complement system" +#endif + +/* return v / 2^26, using only shifts and adds. + * + * On entry: v can take any value. */ +static inline limb +div_by_2_26(const limb v) +{ + /* High word of v; no shift needed. */ + const uint32_t highword = (uint32_t) (((uint64_t) v) >> 32); + /* Set to all 1s if v was negative; else set to 0s. */ + const int32_t sign = ((int32_t) highword) >> 31; + /* Set to 0x3ffffff if v was negative; else set to 0. */ + const int32_t roundoff = ((uint32_t) sign) >> 6; + /* Should return v / (1<<26) */ + return (v + roundoff) >> 26; +} + +/* return v / (2^25), using only shifts and adds. + * + * On entry: v can take any value. */ +static inline limb +div_by_2_25(const limb v) +{ + /* High word of v; no shift needed*/ + const uint32_t highword = (uint32_t) (((uint64_t) v) >> 32); + /* Set to all 1s if v was negative; else set to 0s. */ + const int32_t sign = ((int32_t) highword) >> 31; + /* Set to 0x1ffffff if v was negative; else set to 0. */ + const int32_t roundoff = ((uint32_t) sign) >> 7; + /* Should return v / (1<<25) */ + return (v + roundoff) >> 25; +} + +/* Reduce all coefficients of the short form input so that |x| < 2^26. + * + * On entry: |output[i]| < 280*2^54 */ +static void freduce_coefficients(limb *output) { + unsigned i; + + output[10] = 0; + + for (i = 0; i < 10; i += 2) { + limb over = div_by_2_26(output[i]); + /* The entry condition (that |output[i]| < 280*2^54) means that over is, at + * most, 280*2^28 in the first iteration of this loop. This is added to the + * next limb and we can approximate the resulting bound of that limb by + * 281*2^54. */ + output[i] -= over << 26; + output[i+1] += over; + + /* For the first iteration, |output[i+1]| < 281*2^54, thus |over| < + * 281*2^29. When this is added to the next limb, the resulting bound can + * be approximated as 281*2^54. + * + * For subsequent iterations of the loop, 281*2^54 remains a conservative + * bound and no overflow occurs. */ + over = div_by_2_25(output[i+1]); + output[i+1] -= over << 25; + output[i+2] += over; + } + /* Now |output[10]| < 281*2^29 and all other coefficients are reduced. */ + output[0] += output[10] << 4; + output[0] += output[10] << 1; + output[0] += output[10]; + + output[10] = 0; + + /* Now output[1..9] are reduced, and |output[0]| < 2^26 + 19*281*2^29 + * So |over| will be no more than 2^16. */ + { + limb over = div_by_2_26(output[0]); + output[0] -= over << 26; + output[1] += over; + } + + /* Now output[0,2..9] are reduced, and |output[1]| < 2^25 + 2^16 < 2^26. The + * bound on |output[1]| is sufficient to meet our needs. */ +} + +/* A helpful wrapper around fproduct: output = in * in2. + * + * On entry: |in[i]| < 2^27 and |in2[i]| < 2^27. + * + * output must be distinct to both inputs. The output is reduced degree + * (indeed, one need only provide storage for 10 limbs) and |output[i]| < 2^26. + static void fmul32(limb *output, const limb *in, const limb *in2) + { + limb t[19]; + fproduct(t, in, in2); + //|t[i]| < 14*2^54 + freduce_degree(t); + freduce_coefficients(t); + // |t[i]| < 2^26 + memcpy(output, t, sizeof(limb) * 10); + }*/ + +/* Square a number: output = in**2 + * + * output must be distinct from the input. The inputs are reduced coefficient + * form, the output is not. + * + * output[x] <= 14 * the largest product of the input limbs. */ +static void fsquare_inner(limb *output, const limb *in) { + output[0] = ((limb) ((s32) in[0])) * ((s32) in[0]); + output[1] = 2 * ((limb) ((s32) in[0])) * ((s32) in[1]); + output[2] = 2 * (((limb) ((s32) in[1])) * ((s32) in[1]) + + ((limb) ((s32) in[0])) * ((s32) in[2])); + output[3] = 2 * (((limb) ((s32) in[1])) * ((s32) in[2]) + + ((limb) ((s32) in[0])) * ((s32) in[3])); + output[4] = ((limb) ((s32) in[2])) * ((s32) in[2]) + + 4 * ((limb) ((s32) in[1])) * ((s32) in[3]) + + 2 * ((limb) ((s32) in[0])) * ((s32) in[4]); + output[5] = 2 * (((limb) ((s32) in[2])) * ((s32) in[3]) + + ((limb) ((s32) in[1])) * ((s32) in[4]) + + ((limb) ((s32) in[0])) * ((s32) in[5])); + output[6] = 2 * (((limb) ((s32) in[3])) * ((s32) in[3]) + + ((limb) ((s32) in[2])) * ((s32) in[4]) + + ((limb) ((s32) in[0])) * ((s32) in[6]) + + 2 * ((limb) ((s32) in[1])) * ((s32) in[5])); + output[7] = 2 * (((limb) ((s32) in[3])) * ((s32) in[4]) + + ((limb) ((s32) in[2])) * ((s32) in[5]) + + ((limb) ((s32) in[1])) * ((s32) in[6]) + + ((limb) ((s32) in[0])) * ((s32) in[7])); + output[8] = ((limb) ((s32) in[4])) * ((s32) in[4]) + + 2 * (((limb) ((s32) in[2])) * ((s32) in[6]) + + ((limb) ((s32) in[0])) * ((s32) in[8]) + + 2 * (((limb) ((s32) in[1])) * ((s32) in[7]) + + ((limb) ((s32) in[3])) * ((s32) in[5]))); + output[9] = 2 * (((limb) ((s32) in[4])) * ((s32) in[5]) + + ((limb) ((s32) in[3])) * ((s32) in[6]) + + ((limb) ((s32) in[2])) * ((s32) in[7]) + + ((limb) ((s32) in[1])) * ((s32) in[8]) + + ((limb) ((s32) in[0])) * ((s32) in[9])); + output[10] = 2 * (((limb) ((s32) in[5])) * ((s32) in[5]) + + ((limb) ((s32) in[4])) * ((s32) in[6]) + + ((limb) ((s32) in[2])) * ((s32) in[8]) + + 2 * (((limb) ((s32) in[3])) * ((s32) in[7]) + + ((limb) ((s32) in[1])) * ((s32) in[9]))); + output[11] = 2 * (((limb) ((s32) in[5])) * ((s32) in[6]) + + ((limb) ((s32) in[4])) * ((s32) in[7]) + + ((limb) ((s32) in[3])) * ((s32) in[8]) + + ((limb) ((s32) in[2])) * ((s32) in[9])); + output[12] = ((limb) ((s32) in[6])) * ((s32) in[6]) + + 2 * (((limb) ((s32) in[4])) * ((s32) in[8]) + + 2 * (((limb) ((s32) in[5])) * ((s32) in[7]) + + ((limb) ((s32) in[3])) * ((s32) in[9]))); + output[13] = 2 * (((limb) ((s32) in[6])) * ((s32) in[7]) + + ((limb) ((s32) in[5])) * ((s32) in[8]) + + ((limb) ((s32) in[4])) * ((s32) in[9])); + output[14] = 2 * (((limb) ((s32) in[7])) * ((s32) in[7]) + + ((limb) ((s32) in[6])) * ((s32) in[8]) + + 2 * ((limb) ((s32) in[5])) * ((s32) in[9])); + output[15] = 2 * (((limb) ((s32) in[7])) * ((s32) in[8]) + + ((limb) ((s32) in[6])) * ((s32) in[9])); + output[16] = ((limb) ((s32) in[8])) * ((s32) in[8]) + + 4 * ((limb) ((s32) in[7])) * ((s32) in[9]); + output[17] = 2 * ((limb) ((s32) in[8])) * ((s32) in[9]); + output[18] = 2 * ((limb) ((s32) in[9])) * ((s32) in[9]); +} + +/* fsquare sets output = in^2. + * + * On entry: The |in| argument is in reduced coefficients form and |in[i]| < + * 2^27. + * + * On exit: The |output| argument is in reduced coefficients form (indeed, one + * need only provide storage for 10 limbs) and |out[i]| < 2^26. */ +static void +fsquare32(limb *output, const limb *in) { + limb t[19]; + fsquare_inner(t, in); + /* |t[i]| < 14*2^54 because the largest product of two limbs will be < + * 2^(27+27) and fsquare_inner adds together, at most, 14 of those + * products. */ + freduce_degree(t); + freduce_coefficients(t); + /* |t[i]| < 2^26 */ + memcpy(output, t, sizeof(limb) * 10); +} + +#if (-32 >> 1) != -16 +#error "This code only works when >> does sign-extension on negative numbers" +#endif + +/* s32_eq returns 0xffffffff iff a == b and zero otherwise. */ +static s32 s32_eq(s32 a, s32 b) { + a = ~(a ^ b); + a &= a << 16; + a &= a << 8; + a &= a << 4; + a &= a << 2; + a &= a << 1; + return a >> 31; +} + +/* s32_gte returns 0xffffffff if a >= b and zero otherwise, where a and b are + * both non-negative. */ +static s32 s32_gte(s32 a, s32 b) { + a -= b; + /* a >= 0 iff a >= b. */ + return ~(a >> 31); +} + +/* Take a fully reduced polynomial form number and contract it into a + * little-endian, 32-byte array. + * + * On entry: |input_limbs[i]| < 2^26 */ +static void fcontract32(u8 *output, limb *input_limbs) +{ + int i; + int j; + s32 input[10]; + s32 mask; + + /* |input_limbs[i]| < 2^26, so it's valid to convert to an s32. */ + for (i = 0; i < 10; i++) + input[i] = (s32)input_limbs[i]; + + for (j = 0; j < 2; ++j) { + for (i = 0; i < 9; ++i) { + if ((i & 1) == 1) { + /* This calculation is a time-invariant way to make input[i] + * non-negative by borrowing from the next-larger limb. */ + const s32 mask = input[i] >> 31; + const s32 carry = -((input[i] & mask) >> 25); + input[i] = input[i] + (carry << 25); + input[i+1] = input[i+1] - carry; + } else { + const s32 mask = input[i] >> 31; + const s32 carry = -((input[i] & mask) >> 26); + input[i] = input[i] + (carry << 26); + input[i+1] = input[i+1] - carry; + } + } + + /* There's no greater limb for input[9] to borrow from, but we can multiply + * by 19 and borrow from input[0], which is valid mod 2^255-19. */ + { + const s32 mask = input[9] >> 31; + const s32 carry = -((input[9] & mask) >> 25); + input[9] = input[9] + (carry << 25); + input[0] = input[0] - (carry * 19); + } + + /* After the first iteration, input[1..9] are non-negative and fit within + * 25 or 26 bits, depending on position. However, input[0] may be + * negative. */ + } + + /* The first borrow-propagation pass above ended with every limb + except (possibly) input[0] non-negative. + + If input[0] was negative after the first pass, then it was because of a + carry from input[9]. On entry, input[9] < 2^26 so the carry was, at most, + one, since (2**26-1) >> 25 = 1. Thus input[0] >= -19. + + In the second pass, each limb is decreased by at most one. Thus the second + borrow-propagation pass could only have wrapped around to decrease + input[0] again if the first pass left input[0] negative *and* input[1] + through input[9] were all zero. In that case, input[1] is now 2^25 - 1, + and this last borrow-propagation step will leave input[1] non-negative. */ + { + const s32 mask = input[0] >> 31; + const s32 carry = -((input[0] & mask) >> 26); + input[0] = input[0] + (carry << 26); + input[1] = input[1] - carry; + } + + /* All input[i] are now non-negative. However, there might be values between + * 2^25 and 2^26 in a limb which is, nominally, 25 bits wide. */ + for (j = 0; j < 2; j++) { + for (i = 0; i < 9; i++) { + if ((i & 1) == 1) { + const s32 carry = input[i] >> 25; + input[i] &= 0x1ffffff; + input[i+1] += carry; + } else { + const s32 carry = input[i] >> 26; + input[i] &= 0x3ffffff; + input[i+1] += carry; + } + } + + { + const s32 carry = input[9] >> 25; + input[9] &= 0x1ffffff; + input[0] += 19*carry; + } + } + + /* If the first carry-chain pass, just above, ended up with a carry from + * input[9], and that caused input[0] to be out-of-bounds, then input[0] was + * < 2^26 + 2*19, because the carry was, at most, two. + * + * If the second pass carried from input[9] again then input[0] is < 2*19 and + * the input[9] -> input[0] carry didn't push input[0] out of bounds. */ + + /* It still remains the case that input might be between 2^255-19 and 2^255. + * In this case, input[1..9] must take their maximum value and input[0] must + * be >= (2^255-19) & 0x3ffffff, which is 0x3ffffed. */ + mask = s32_gte(input[0], 0x3ffffed); + for (i = 1; i < 10; i++) { + if ((i & 1) == 1) { + mask &= s32_eq(input[i], 0x1ffffff); + } else { + mask &= s32_eq(input[i], 0x3ffffff); + } + } + + /* mask is either 0xffffffff (if input >= 2^255-19) and zero otherwise. Thus + * this conditionally subtracts 2^255-19. */ + input[0] -= mask & 0x3ffffed; + + for (i = 1; i < 10; i++) { + if ((i & 1) == 1) { + input[i] -= mask & 0x1ffffff; + } else { + input[i] -= mask & 0x3ffffff; + } + } + + input[1] <<= 2; + input[2] <<= 3; + input[3] <<= 5; + input[4] <<= 6; + input[6] <<= 1; + input[7] <<= 3; + input[8] <<= 4; + input[9] <<= 6; +#define F(i, s) \ +output[s+0] |= input[i] & 0xff; \ +output[s+1] = (input[i] >> 8) & 0xff; \ +output[s+2] = (input[i] >> 16) & 0xff; \ +output[s+3] = (input[i] >> 24) & 0xff; + output[0] = 0; + output[16] = 0; + F(0,0); + F(1,3); + F(2,6); + F(3,9); + F(4,12); + F(5,16); + F(6,19); + F(7,22); + F(8,25); + F(9,28); +#undef F +} + +bits320 bits320_limbs(limb limbs[10]) +{ + bits320 output; int32_t i; + for (i=0; i<10; i++) + output.uints[i] = limbs[i]; + return(output); +} + +static inline bits320 fscalar_product(const bits320 in,const uint64_t scalar) +{ + limb output[10],input[10]; int32_t i; + for (i=0; i<10; i++) + input[i] = in.uints[i]; + fscalar_product32(output,input,scalar); + return(bits320_limbs(output)); +} + +static inline bits320 fsquare_times(const bits320 in,uint64_t count) +{ + limb output[10],input[10]; int32_t i; + for (i=0; i<10; i++) + input[i] = in.uints[i]; + for (i=0; i Output: 2Q, Q+Q' +// x2 z2: long form && x3 z3: long form +// x z: short form, destroyed && xprime zprime: short form, destroyed +// qmqp: short form, preserved +static inline void +fmonty(bits320 *x2, bits320 *z2, // output 2Q + bits320 *x3, bits320 *z3, // output Q + Q' + bits320 *x, bits320 *z, // input Q + bits320 *xprime, bits320 *zprime, // input Q' + const bits320 qmqp) // input Q - Q' +{ + bits320 origx,origxprime,zzz,xx,zz,xxprime,zzprime; + origx = *x; + *x = fsum(*x,*z), fdifference_backwards(z->ulongs,origx.ulongs); // does x - z + origxprime = *xprime; + *xprime = fsum(*xprime,*zprime), fdifference_backwards(zprime->ulongs,origxprime.ulongs); + xxprime = fmul(*xprime,*z), zzprime = fmul(*x,*zprime); + origxprime = xxprime; + xxprime = fsum(xxprime,zzprime), fdifference_backwards(zzprime.ulongs,origxprime.ulongs); + *x3 = fsquare_times(xxprime,1), *z3 = fmul(fsquare_times(zzprime,1),qmqp); + xx = fsquare_times(*x,1), zz = fsquare_times(*z,1); + *x2 = fmul(xx,zz); + fdifference_backwards(zz.ulongs,xx.ulongs); // does zz = xx - zz + zzz = fscalar_product(zz,121665); + *z2 = fmul(zz,fsum(zzz,xx)); +} + +// ----------------------------------------------------------------------------- +// Maybe swap the contents of two limb arrays (@a and @b), each @len elements +// long. Perform the swap iff @swap is non-zero. +// This function performs the swap without leaking any side-channel information. +// ----------------------------------------------------------------------------- +static inline void swap_conditional(bits320 *a,bits320 *b,uint64_t iswap) +{ + int32_t i; const uint64_t swap = -iswap; + for (i=0; i<5; ++i) + { + const uint64_t x = swap & (a->ulongs[i] ^ b->ulongs[i]); + a->ulongs[i] ^= x, b->ulongs[i] ^= x; + } +} + +// Calculates nQ where Q is the x-coordinate of a point on the curve +// resultx/resultz: the x coordinate of the resulting curve point (short form) +// n: a little endian, 32-byte number +// q: a point of the curve (short form) +void cmult(bits320 *resultx,bits320 *resultz,bits256 secret,const bits320 q) +{ + int32_t i,j; bits320 a,b,c,d,e,f,g,h,*t; + bits320 Zero320bits,One320bits, *nqpqx = &a,*nqpqz = &b,*nqx = &c,*nqz = &d,*nqpqx2 = &e,*nqpqz2 = &f,*nqx2 = &g,*nqz2 = &h; + memset(&Zero320bits,0,sizeof(Zero320bits)); + memset(&One320bits,0,sizeof(One320bits)), One320bits.ulongs[0] = 1; + a = d = e = g = Zero320bits, b = c = f = h = One320bits; + *nqpqx = q; + for (i=0; i<32; i++) + { + uint8_t byte = secret.bytes[31 - i]; + for (j=0; j<8; j++) + { + const uint64_t bit = byte >> 7; + swap_conditional(nqx,nqpqx,bit), swap_conditional(nqz,nqpqz,bit); + fmonty(nqx2,nqz2,nqpqx2,nqpqz2,nqx,nqz,nqpqx,nqpqz,q); + swap_conditional(nqx2,nqpqx2,bit), swap_conditional(nqz2,nqpqz2,bit); + t = nqx, nqx = nqx2, nqx2 = t; + t = nqz, nqz = nqz2, nqz2 = t; + t = nqpqx, nqpqx = nqpqx2, nqpqx2 = t; + t = nqpqz, nqpqz = nqpqz2, nqpqz2 = t; + byte <<= 1; + } + } + *resultx = *nqx, *resultz = *nqz; +} + +// Shamelessly copied from donna's code that copied djb's code, changed a little +inline bits320 crecip(const bits320 z) +{ + bits320 a,t0,b,c; + /* 2 */ a = fsquare_times(z, 1); // a = 2 + /* 8 */ t0 = fsquare_times(a, 2); + /* 9 */ b = fmul(t0, z); // b = 9 + /* 11 */ a = fmul(b, a); // a = 11 + /* 22 */ t0 = fsquare_times(a, 1); + /* 2^5 - 2^0 = 31 */ b = fmul(t0, b); + /* 2^10 - 2^5 */ t0 = fsquare_times(b, 5); + /* 2^10 - 2^0 */ b = fmul(t0, b); + /* 2^20 - 2^10 */ t0 = fsquare_times(b, 10); + /* 2^20 - 2^0 */ c = fmul(t0, b); + /* 2^40 - 2^20 */ t0 = fsquare_times(c, 20); + /* 2^40 - 2^0 */ t0 = fmul(t0, c); + /* 2^50 - 2^10 */ t0 = fsquare_times(t0, 10); + /* 2^50 - 2^0 */ b = fmul(t0, b); + /* 2^100 - 2^50 */ t0 = fsquare_times(b, 50); + /* 2^100 - 2^0 */ c = fmul(t0, b); + /* 2^200 - 2^100 */ t0 = fsquare_times(c, 100); + /* 2^200 - 2^0 */ t0 = fmul(t0, c); + /* 2^250 - 2^50 */ t0 = fsquare_times(t0, 50); + /* 2^250 - 2^0 */ t0 = fmul(t0, b); + /* 2^255 - 2^5 */ t0 = fsquare_times(t0, 5); + /* 2^255 - 21 */ return(fmul(t0, a)); +} + +void OS_randombytes(unsigned char *x,long xlen); + +bits256 rand256(int32_t privkeyflag) +{ + bits256 randval; + OS_randombytes(randval.bytes,sizeof(randval)); + if ( privkeyflag != 0 ) + randval.bytes[0] &= 0xf8, randval.bytes[31] &= 0x7f, randval.bytes[31] |= 0x40; + return(randval); +} + +bits256 curve25519_basepoint9() +{ + bits256 basepoint; + memset(&basepoint,0,sizeof(basepoint)); + basepoint.bytes[0] = 9; + return(basepoint); +} + +bits256 curve25519_keypair(bits256 *pubkeyp) +{ + bits256 privkey; + privkey = rand256(1); + *pubkeyp = curve25519(privkey,curve25519_basepoint9()); + //printf("[%llx %llx] ",privkey.txid,(*pubkeyp).txid); + return(privkey); +} + +bits256 curve25519_shared(bits256 privkey,bits256 otherpub) +{ + bits256 shared,hash; + shared = curve25519(privkey,otherpub); + vcalc_sha256(0,hash.bytes,shared.bytes,sizeof(shared)); + //printf("priv.%llx pub.%llx shared.%llx -> hash.%llx\n",privkey.txid,pubkey.txid,shared.txid,hash.txid); + //hash.bytes[0] &= 0xf8, hash.bytes[31] &= 0x7f, hash.bytes[31] |= 64; + return(hash); +} + +int32_t curve25519_donna(uint8_t *mypublic,const uint8_t *secret,const uint8_t *basepoint) +{ + bits256 val,p,bp; + memcpy(p.bytes,secret,sizeof(p)); + memcpy(bp.bytes,basepoint,sizeof(bp)); + val = curve25519(p,bp); + memcpy(mypublic,val.bytes,sizeof(val)); + return(0); +} + +uint64_t conv_NXTpassword(unsigned char *mysecret,unsigned char *mypublic,uint8_t *pass,int32_t passlen) +{ + static uint8_t basepoint[32] = {9}; + uint64_t addr; uint8_t hash[32]; + if ( pass != 0 && passlen != 0 ) + vcalc_sha256(0,mysecret,pass,passlen); + mysecret[0] &= 248, mysecret[31] &= 127, mysecret[31] |= 64; + curve25519_donna(mypublic,mysecret,basepoint); + vcalc_sha256(0,hash,mypublic,32); + memcpy(&addr,hash,sizeof(addr)); + return(addr); +} + +bits256 komodo_kvprivkey(bits256 *pubkeyp,char *passphrase) +{ + bits256 privkey; + conv_NXTpassword(privkey.bytes,pubkeyp->bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); + return(privkey); +} + +bits256 komodo_kvsig(uint8_t *buf,int32_t len,bits256 privkey) +{ + bits256 sig,hash,otherpub; + vcalc_sha256(0,hash.bytes,buf,len); + otherpub = curve25519(hash,curve25519_basepoint9()); + sig = curve25519_shared(privkey,otherpub); + return(sig); +} + +int32_t komodo_kvsigverify(uint8_t *buf,int32_t len,bits256 pubkey,bits256 sig) +{ + bits256 hash,checksig; + vcalc_sha256(0,hash.bytes,buf,len); + checksig = curve25519_shared(hash,pubkey); + if ( memcmp(&checksig,&sig,sizeof(sig)) != 0 ) + return(-1); + else return(0); +} + +/* +#include + +bits256 GENESIS_PUBKEY,GENESIS_PRIVKEY; + +bits256 acct777_pubkey(bits256 privkey) +{ + static uint8_t basepoint[32] = {9}; + bits256 pubkey; + privkey.bytes[0] &= 248, privkey.bytes[31] &= 127, privkey.bytes[31] |= 64; + curve25519_donna(pubkey.bytes,privkey.bytes,basepoint); + return(pubkey); +} + +uint64_t acct777_nxt64bits(bits256 pubkey) +{ + bits256 acct; + vcalc_sha256(0,acct.bytes,pubkey.bytes,sizeof(pubkey)); + return(acct.txid); +} + +bits256 acct777_msgprivkey(uint8_t *data,int32_t datalen) +{ + bits256 hash; + vcalc_sha256(0,hash.bytes,data,datalen); + return(hash); +} + +bits256 acct777_msgpubkey(uint8_t *data,int32_t datalen) +{ + return(acct777_pubkey(acct777_msgprivkey(data,datalen))); +} + +bits256 acct777_hashiter(bits256 privkey,bits256 pubkey,int32_t lockdays,uint8_t chainlen) +{ + uint16_t lockseed,signlen = 0; uint8_t signbuf[16]; bits256 shared,lockhash; + lockseed = (chainlen & 0x7f) | (lockdays << 7); + signlen = 0, signbuf[signlen++] = lockseed & 0xff, signbuf[signlen++] = (lockseed >> 8) & 0xff; + + privkey.bytes[0] &= 248, privkey.bytes[31] &= 127, privkey.bytes[31] |= 64; + shared = curve25519(privkey,pubkey); + vcalc_sha256cat(lockhash.bytes,shared.bytes,sizeof(shared),signbuf,signlen); + return(lockhash); +} + +bits256 acct777_lockhash(bits256 pubkey,int32_t lockdays,uint8_t chainlen) +{ + bits256 lockhash = GENESIS_PRIVKEY; + while ( chainlen > 0 ) + lockhash = acct777_hashiter(lockhash,pubkey,lockdays,chainlen--); + return(lockhash); +} + +bits256 acct777_invoicehash(bits256 *invoicehash,uint16_t lockdays,uint8_t chainlen) +{ + int32_t i; bits256 lockhash,privkey; + OS_randombytes(privkey.bytes,sizeof(privkey)); // both privkey and pubkey are sensitive. pubkey allows verification, privkey proves owner + lockhash = privkey; + for (i=0; isigbits.bytes), len += sizeof(bits256); + iguana_rwbignum(rwflag,&serialized[len],sizeof(bits256),sig->pubkey.bytes),len += sizeof(bits256); + iguana_rwnum(rwflag,&serialized[len],sizeof(sig->signer64bits),&sig->signer64bits),len += sizeof(sig->signer64bits); + iguana_rwnum(rwflag,&serialized[len],sizeof(sig->timestamp),&sig->timestamp),len += sizeof(sig->timestamp); + iguana_rwnum(rwflag,&serialized[len],sizeof(sig->allocsize),&sig->allocsize),len += sizeof(sig->allocsize); +} + +int32_t acct777_sigcheck(struct acct777_sig *sig) +{ +#define IGUANA_GENESIS 1453075200 +#define IGUANA_MAXPACKETSIZE (1024 * 1024 * 2) +#define TEN_YEARS (10 * 365 * 24 * 3600) + if ( sig->allocsize < sizeof(*sig) || sig->allocsize > IGUANA_MAXPACKETSIZE ) + { + //printf("acct777_sign: invalid datalen.%d hex.%08x\n",sig->allocsize,sig->allocsize); + return(-1); + } + if ( sig->timestamp < IGUANA_GENESIS || sig->timestamp > (long)IGUANA_GENESIS+TEN_YEARS ) + { + printf("acct777_sign: invalid timestamp.%u (%u %u)\n",sig->timestamp,IGUANA_GENESIS,IGUANA_GENESIS+TEN_YEARS); + return(-1); + } + return(sig->allocsize); +} + +uint64_t acct777_sign(struct acct777_sig *sig,bits256 privkey,bits256 otherpubkey,uint32_t timestamp,uint8_t *serialized,int32_t datalen) +{ + bits256 pubkey; bits256 shared; uint8_t buf[sizeof(*sig)]; + pubkey = acct777_pubkey(privkey); + if ( memcmp(sig->pubkey.bytes,otherpubkey.bytes,sizeof(bits256)) != 0 ) + { + //char str[65],str2[65]; + //printf("set sig fields.(%s) != (%s)\n",bits256_str(str,sig->pubkey),bits256_str(str2,otherpubkey)); + sig->pubkey = pubkey; + sig->timestamp = timestamp; + sig->allocsize = (int32_t)(datalen + sizeof(*sig)); + sig->signer64bits = acct777_nxt64bits(sig->pubkey); + } + sig->sigbits = shared = curve25519(privkey,otherpubkey); + if ( acct777_sigcheck(sig) < 0 ) + return(0); + memset(buf,0,sizeof(buf)); + acct777_rwsig(1,buf,sig); + //int32_t i; for (i=0; iallocsize,(long long)sig->signer64bits,sig->timestamp); + //char str[65]; printf("shared.(%s) crc.%u datalen.%d\n",bits256_str(str,shared),calc_crc32(0,buf,sizeof(buf)),datalen); + vcalc_sha256cat(sig->sigbits.bytes,buf,sizeof(buf),serialized,datalen); + //printf(" calcsig.%llx pubkey.%llx signer.%llu | t%u crc.%08x len.%d shared.%llx <- %llx * %llx\n",(long long)sig->sigbits.txid,(long long)sig->pubkey.txid,(long long)sig->signer64bits,timestamp,calc_crc32(0,serialized,datalen),datalen,(long long)shared.txid,(long long)privkey.txid,(long long)otherpubkey.txid); + return(sig->signer64bits); +} + +uint64_t acct777_validate(struct acct777_sig *sig,bits256 privkey,bits256 pubkey) +{ + struct acct777_sig checksig; uint64_t signerbits; int32_t datalen; uint8_t *serialized; + datalen = (int32_t)(sig->allocsize - sizeof(*sig)); + checksig = *sig; +#if defined(_M_X64) + serialized = (uint8_t *)((unsigned char *)sig + sizeof(*sig)); +#else + serialized = (uint8_t *)((long)sig + sizeof(*sig)); +#endif + //{ int32_t i; for (i=0; itimestamp,serialized,datalen); + if ( memcmp(checksig.sigbits.bytes,sig->sigbits.bytes,sizeof(checksig.sigbits)) != 0 ) + { + //char *bits256_str(); + //char str[65],str2[65]; printf("sig compare error using sig->pub from %llu\n>>>>>>>> sig.(%s) vs (%s)",(long long)acct777_nxt64bits(sig->pubkey),bits256_str(str,checksig.sigbits),bits256_str(str2,sig->sigbits)); + return(0); + } + signerbits = acct777_nxt64bits(sig->pubkey); + if ( signerbits == checksig.signer64bits ) + return(signerbits); + else return(0); +} + +uint64_t acct777_signtx(struct acct777_sig *sig,bits256 privkey,uint32_t timestamp,uint8_t *data,int32_t datalen) +{ + return(acct777_sign(sig,privkey,acct777_msgpubkey(data,datalen),timestamp,data,datalen)); +} + +uint64_t acct777_swaptx(bits256 privkey,struct acct777_sig *sig,uint32_t timestamp,uint8_t *data,int32_t datalen) + { + uint64_t othernxt; + if ( (othernxt= acct777_validate(sig)) != sig->signer64bits ) + return(0); + return(acct777_sign(sig,privkey,acct777_msgpubkey(data,datalen),timestamp,data,datalen)); + }*/ + +int32_t _SuperNET_cipher(uint8_t nonce[crypto_box_NONCEBYTES],uint8_t *cipher,uint8_t *message,int32_t len,bits256 destpub,bits256 srcpriv,uint8_t *buf) +{ + memset(cipher,0,len+crypto_box_ZEROBYTES); + memset(buf,0,crypto_box_ZEROBYTES); + memcpy(buf+crypto_box_ZEROBYTES,message,len); + crypto_box(cipher,buf,len+crypto_box_ZEROBYTES,nonce,destpub.bytes,srcpriv.bytes); + return(len + crypto_box_ZEROBYTES); +} + +uint8_t *_SuperNET_decipher(uint8_t nonce[crypto_box_NONCEBYTES],uint8_t *cipher,uint8_t *message,int32_t len,bits256 srcpub,bits256 mypriv) +{ + int32_t err; + if ( (err= crypto_box_open(message,cipher,len,nonce,srcpub.bytes,mypriv.bytes)) == 0 ) + { + message += crypto_box_ZEROBYTES; + len -= crypto_box_ZEROBYTES; + return(message); + } + return(0); +} + +//#undef force_inline + +#endif diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 26e046a25..4ec0b0f04 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -671,52 +671,9 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above return(0); } -int32_t komodo_kvsearch(int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen) -{ - struct komodo_kv *ptr; int32_t duration,retval = -1; - *heightp = -1; - *flagsp = 0; - portable_mutex_lock(&KOMODO_KV_mutex); - HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); - if ( ptr != 0 ) - { - duration = ((ptr->flags >> 2) + 1) * KOMODO_KVDURATION; - //printf("duration.%d flags.%d current.%d ht.%d keylen.%d valuesize.%d\n",duration,ptr->flags,current_height,ptr->height,ptr->keylen,ptr->valuesize); - if ( current_height > (ptr->height + duration) ) - { - HASH_DELETE(hh,KOMODO_KV,ptr); - if ( ptr->value != 0 ) - free(ptr->value); - if ( ptr->key != 0 ) - free(ptr->key); - free(ptr); - } - else - { - *heightp = ptr->height; - *flagsp = ptr->flags; - if ( (retval= ptr->valuesize) != 0 ) - memcpy(value,ptr->value,retval); - } - } - portable_mutex_unlock(&KOMODO_KV_mutex); - return(retval); -} - -int32_t komodo_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint16_t valuesize) -{ - if ( refvalue == 0 && value == 0 ) - return(0); - else if ( refvalue == 0 || value == 0 ) - return(-1); - else if ( refvaluesize != valuesize ) - return(-1); - else return(memcmp(refvalue,value,valuesize)); -} - const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout,char *source) { - uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33],valuebuf[IGUANA_MAXSCRIPTSIZE]; int32_t didstats,i,j,n,kvheight,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fee,fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff; uint32_t flags; + uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,kvheight,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fee,fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff; const char *typestr = "unknown"; if ( ASSETCHAINS_SYMBOL[0] != 0 && komodo_baseid(ASSETCHAINS_SYMBOL) < 0 && opretbuf[0] != 'K' ) { @@ -734,51 +691,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 tokomodo = (komodo_is_issuer() == 0); if ( opretbuf[0] == 'K' && opretlen != 40 ) { - uint16_t keylen,valuesize,newflag = 0,cmpval = 1; uint8_t *key,*valueptr; struct komodo_kv *ptr; - iguana_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen); - iguana_rwnum(0,&opretbuf[3],sizeof(valuesize),&valuesize); - iguana_rwnum(0,&opretbuf[5],sizeof(kmdheight),&kmdheight); - iguana_rwnum(0,&opretbuf[9],sizeof(flags),&flags); - key = &opretbuf[13]; - valueptr = &key[keylen]; - if ( (fee= ((flags>>2)+1)*(opretlen * opretlen / keylen)) < 100000 ) - fee = 100000; - // 6a164b040005006a00000000000000746573743834393333 - //printf("fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,kmdheight,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); - if ( value >= fee ) - { - if ( sizeof(flags)+sizeof(kmdheight)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1 == opretlen ) - { - komodo_kvsearch(height,&flags,&kvheight,valuebuf,key,keylen); // expire if needed - portable_mutex_lock(&KOMODO_KV_mutex); - HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); - if ( ptr == 0 ) - { - ptr = (struct komodo_kv *)calloc(1,sizeof(*ptr)); - ptr->key = (uint8_t *)calloc(1,keylen); - ptr->keylen = keylen; - memcpy(ptr->key,key,keylen); - newflag = 1; - HASH_ADD_KEYPTR(hh,KOMODO_KV,ptr->key,ptr->keylen,ptr); - } - if ( newflag != 0 || (ptr->flags & KOMODO_KVPROTECTED) == 0 || (cmpval= komodo_kvcmp(ptr->value,ptr->valuesize,valueptr,valuesize)) == 0 ) - { - if ( cmpval != 0 ) - { - if ( ptr->value != 0 ) - free(ptr->value), ptr->value = 0; - if ( (ptr->valuesize= valuesize) != 0 ) - { - ptr->value = (uint8_t *)calloc(1,valuesize); - memcpy(ptr->value,valueptr,valuesize); - } - } - ptr->height = kmdheight; - ptr->flags = flags; - } - portable_mutex_unlock(&KOMODO_KV_mutex); - } else printf("insufficient fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,kmdheight,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); - } else printf("opretlen.%d mismatch keylen.%d valuesize.%d\n",opretlen,keylen,valuesize); + komodo_kvupdate(opretbuf,opretlen,value); } else if ( opretbuf[0] == 'D' ) { diff --git a/src/komodo_kv.h b/src/komodo_kv.h new file mode 100644 index 000000000..ad8bb1ee4 --- /dev/null +++ b/src/komodo_kv.h @@ -0,0 +1,175 @@ +/****************************************************************************** + * Copyright © 2014-2017 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#ifndef H_KOMODOKV_H +#define H_KOMODOKV_H + +int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen) +{ + struct komodo_kv *ptr; int32_t duration,retval = -1; + *heightp = -1; + *flagsp = 0; + memset(pubkeyp,0,sizeof(*pubkeyp)); + portable_mutex_lock(&KOMODO_KV_mutex); + HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); + if ( ptr != 0 ) + { + duration = ((ptr->flags >> 2) + 1) * KOMODO_KVDURATION; + //printf("duration.%d flags.%d current.%d ht.%d keylen.%d valuesize.%d\n",duration,ptr->flags,current_height,ptr->height,ptr->keylen,ptr->valuesize); + if ( current_height > (ptr->height + duration) ) + { + HASH_DELETE(hh,KOMODO_KV,ptr); + if ( ptr->value != 0 ) + free(ptr->value); + if ( ptr->key != 0 ) + free(ptr->key); + free(ptr); + } + else + { + *heightp = ptr->height; + *flagsp = ptr->flags; + memcpy(pubkeyp,ptr->pubkey,sizeof(*pubkeyp)); + if ( (retval= ptr->valuesize) != 0 ) + memcpy(value,ptr->value,retval); + } + } + portable_mutex_unlock(&KOMODO_KV_mutex); + return(retval); +} + +int32_t komodo_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint16_t valuesize) +{ + if ( refvalue == 0 && value == 0 ) + return(0); + else if ( refvalue == 0 || value == 0 ) + return(-1); + else if ( refvaluesize != valuesize ) + return(-1); + else return(memcmp(refvalue,value,valuesize)); +} + +int32_t komodo_kvnumdays(uint32_t flags) +{ + int32_t numdays; + if ( (numdays= ((flags>>2)&0x3ff)+1) > 365 ) + numdays = 365; + return(numdays); +} + +int32_t komodo_kvduration(uint32_t flags) +{ + return(komodo_kvnumdays(flags) * KOMODO_KVDURATION); +} + +uint64_t komodo_kvfee(uint32_t flags,int32_t opretlen,int32_t keylen) +{ + int32_t numdays; uint64_t fee; + numdays = komodo_kvnumdays(flags); + if ( (fee= (numdays*(opretlen * opretlen / keylen))) < 100000 ) + fee = 100000; + return(fee); +} + +void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) +{ + static bits256 zeroes; + uint32_t flags; bits256 pubkey,sig; int32_t i,transferflag,hassig,coresize,haspubkey,height,kvheight; uint16_t keylen,valuesize,newflag = 0; uint8_t *key,*valueptr,valuebuf[IGUANA_MAXSCRIPTSIZE]; struct komodo_kv *ptr; char *transferpubstr; + iguana_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen); + iguana_rwnum(0,&opretbuf[3],sizeof(valuesize),&valuesize); + iguana_rwnum(0,&opretbuf[5],sizeof(height),&height); + iguana_rwnum(0,&opretbuf[9],sizeof(flags),&flags); + key = &opretbuf[13]; + valueptr = &key[keylen]; + fee = komodo_kvfee(flags,opretlen,keylen); + //printf("fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); + if ( value >= fee ) + { + coresize = (int32_t)(sizeof(flags)+sizeof(height)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1); + if ( opretlen == coresize || opretlen == coresize+sizeof(bits256) || opretlen == coresize+2*sizeof(bits256) ) + { + memset(&pubkey,0,sizeof(pubkey)); + memset(&sig,0,sizeof(sig)); + if ( (haspubkey= (opretlen >= coresize+sizeof(bits256))) != 0 ) + { + for (i=0; i<32; i++) + ((uint8_t *)&pubkey)[i] = opretbuf[coresize+i]; + } + if ( (hassig= (opretlen == coresize+sizeof(bits256)*2)) != 0 ) + { + for (i=0; i<32; i++) + ((uint8_t *)&sig)[i] = opretbuf[coresize+sizeof(bits256)+i]; + } + if ( komodo_kvsearch(&refpubkey,height,&flags,&kvheight,valuebuf,key,keylen) >= 0 ) + { + if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) + { + if ( pubkey != refpubkey || komodo_kvsigverify(opretbuf+13,coresize-13,refpubkey,sig) < 0 ) + { + printf("komodo_kvsigverify error [%d]\n",coresize-13); + return; + } + } + } + portable_mutex_lock(&KOMODO_KV_mutex); + HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); + transferflag = 0; + if ( ptr != 0 ) + { + if ( (ptr->flags & KOMODO_KVPROTECTED) != 0 && memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) + { + transferpubstr = (char *)&value[strlen((char *)"transfer:")]; + if ( strncmp((char *)"transfer:",value,strlen((char *)"transfer:")) == 0 && is_hexstr(transferpubstr,0) == 64 ) + { + transferflag = 1; + printf("transfer.(%s) to [%s]\n",key,transferpubstr); + for (i=0; i<32; i++) + ((uint8_t *)&pubkey)[31-i] = _decode_hex(&transferpubstr[i*2]); + } + } + } + else if ( ptr == 0 ) + { + ptr = (struct komodo_kv *)calloc(1,sizeof(*ptr)); + ptr->pubkey = pubkey; + ptr->key = (uint8_t *)calloc(1,keylen); + ptr->keylen = keylen; + memcpy(ptr->key,key,keylen); + newflag = 1; + HASH_ADD_KEYPTR(hh,KOMODO_KV,ptr->key,ptr->keylen,ptr); + } + if ( transferflag != 0 ) + { + ptr->pubkey = pubkey; + ptr->height = height; + } + else if ( newflag != 0 || (ptr->flags & KOMODO_KVPROTECTED) == 0 ) + { + if ( ptr->value != 0 ) + free(ptr->value), ptr->value = 0; + if ( (ptr->valuesize= valuesize) != 0 ) + { + ptr->value = (uint8_t *)calloc(1,valuesize); + memcpy(ptr->value,valueptr,valuesize); + } + ptr->height = height; + ptr->flags = flags; + } + portable_mutex_unlock(&KOMODO_KV_mutex); + } else printf("insufficient fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); + } else printf("opretlen.%d mismatch keylen.%d valuesize.%d\n",opretlen,keylen,valuesize); +} + +#endif diff --git a/src/komodo_structs.h b/src/komodo_structs.h index 672516ee3..a35e7e008 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -41,7 +41,13 @@ #define KOMODO_KVBINARY 2 #define KOMODO_KVDURATION 1440 -struct komodo_kv { UT_hash_handle hh; uint8_t *key,*value; int32_t height; uint32_t flags; uint16_t keylen,valuesize; }; +union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; +typedef union _bits256 bits256; + +union _bits320 { uint8_t bytes[40]; uint16_t ushorts[20]; uint32_t uints[10]; uint64_t ulongs[5]; uint64_t txid; }; +typedef union _bits320 bits320; + +struct komodo_kv { UT_hash_handle hh; bits256 pubkey; uint8_t *key,*value; int32_t height; uint32_t flags; uint16_t keylen,valuesize; }; struct komodo_event_notarized { uint256 blockhash,desttxid; int32_t notarizedheight; char dest[16]; }; struct komodo_event_pubkeys { uint8_t num; uint8_t pubkeys[64][33]; }; diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 82e5d21e6..8f3e67ef9 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -408,11 +408,11 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len); uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n); int32_t komodo_minerids(uint8_t *minerids,int32_t height); -int32_t komodo_kvsearch(int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); +int32_t komodo_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); Value kvsearch(const Array& params, bool fHelp) { - Object ret; uint32_t flags; uint8_t value[IGUANA_MAXSCRIPTSIZE],key[IGUANA_MAXSCRIPTSIZE]; int32_t duration,j,height,valuesize,keylen; + Object ret; uint32_t flags; uint8_t value[IGUANA_MAXSCRIPTSIZE],key[IGUANA_MAXSCRIPTSIZE]; int32_t duration,j,height,valuesize,keylen; uint256 refpubkey; static uint256 zeroes; if (fHelp || params.size() != 1 ) throw runtime_error("kvsearch key"); LOCK(cs_main); @@ -425,12 +425,14 @@ Value kvsearch(const Array& params, bool fHelp) if ( keylen < sizeof(key) ) { memcpy(key,params[0].get_str().c_str(),keylen); - if ( (valuesize= komodo_kvsearch(chainActive.Tip()->nHeight,&flags,&height,value,key,keylen)) >= 0 ) + if ( (valuesize= komodo_kvsearch(&refpubkey,chainActive.Tip()->nHeight,&flags,&height,value,key,keylen)) >= 0 ) { std::string val; char *valuestr; val.resize(valuesize); valuestr = (char *)val.data(); memcpy(valuestr,value,valuesize); + if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) + ret.push_back(Pair("owner",refpubkey.GetHex())); ret.push_back(Pair("height",height)); duration = ((flags >> 2) + 1) * KOMODO_KVDURATION; ret.push_back(Pair("expiration", (int64_t)(height+duration))); diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index a384b063d..5b89b18c4 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -113,7 +113,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "notaries", 1 }, { "minerids", 1 }, { "kvsearch", 1 }, - { "kvupdate", 3 }, + { "kvupdate", 4 }, }; class CRPCConvertTable diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 2c04a53e0..93a168931 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -487,8 +487,12 @@ int32_t komodo_is_issuer(); int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp); int32_t komodo_isrealtime(int32_t *kmdheightp); int32_t pax_fiatstatus(uint64_t *available,uint64_t *deposited,uint64_t *issued,uint64_t *withdrawn,uint64_t *approved,uint64_t *redeemed,char *base); -int32_t komodo_kvsearch(int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); +int32_t komodo_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); int32_t komodo_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint16_t valuesize); +uint64_t komodo_kvfee(uint32_t flags,int32_t opretlen,int32_t keylen); +uint256 komodo_kvsig(uint8_t *buf,int32_t len,uint256 privkey); +int32_t komodo_kvduration(uint32_t flags); +uint256 komodo_kvprivkey(uint256 *pubkeyp,char *passphrase); Value paxdeposit(const Array& params, bool fHelp) { @@ -566,16 +570,27 @@ Value paxwithdraw(const Array& params, bool fHelp) Value kvupdate(const Array& params, bool fHelp) { CWalletTx wtx; Object ret; - uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t duration,opretlen,height; uint16_t keylen,valuesize=0,refvaluesize=0; uint8_t *key,*value=0; uint32_t flags,tmpflags; struct komodo_kv *ptr; uint64_t fee; + uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t coresize,haveprivkey,duration,opretlen,height; uint16_t keylen,valuesize=0,refvaluesize=0; uint8_t *key,*value=0; uint32_t flags,tmpflags; struct komodo_kv *ptr; uint64_t fee; uint256 privkey,pubkey,refpubkey,sig; if (fHelp || params.size() < 2 ) - throw runtime_error("kvupdate key value [flags]"); + throw runtime_error("kvupdate key value [flags] [passphrase]"); if (!EnsureWalletIsAvailable(fHelp)) return 0; - if ( params.size() == 3 ) + if ( params.size() >= 3 ) { flags = atoi(params[2].get_str().c_str()); //printf("flags.%d (%s)\n",flags,params[2].get_str().c_str()); } else flags = 0; + haveprivkey = 0; + memset(&sig,0,sizeof(sig)); + memset(&privkey,0,sizeof(privkey)); + memset(&pubkey,0,sizeof(pubkey)); + if ( params.size() >= 4 ) + { + privkey = komodo_kvprivkey(&pubkey,params[3].get_str().c_str()); + haveprivkey = 1; + flags |= 1; + //printf("flags.%d (%s)\n",flags,params[2].get_str().c_str()); + } LOCK2(cs_main, pwalletMain->cs_wallet); if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) { @@ -585,15 +600,25 @@ Value kvupdate(const Array& params, bool fHelp) value = (uint8_t *)params[1].get_str().c_str(); valuesize = (int32_t)strlen(params[1].get_str().c_str()); } - if ( (refvaluesize= komodo_kvsearch(chainActive.Tip()->nHeight,&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 && (tmpflags & KOMODO_KVPROTECTED) != 0 && komodo_kvcmp(refvaluesize==0?0:&keyvalue[keylen],refvaluesize,value,valuesize) != 0 ) + memcpy(keyvalue,key,keylen); + if ( (refvaluesize= komodo_kvsearch(&refpubkey,chainActive.Tip()->nHeight,&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 ) { - ret.push_back(Pair("error",(char *)"cant modify write once key")); - return ret; + if ( (tmpflags & KOMODO_KVPROTECTED) != 0 ) + { + if ( refpubkey != pubkey ) + { + ret.push_back(Pair("error",(char *)"cant modify write once key without passphrase")); + return ret; + } + sig = komodo_kvsig(keyvalue,keylen+valuesize,privkey); + } } ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); height = chainActive.Tip()->nHeight; + if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) + ret.push_back(Pair("owner",refpubkey.GetHex())); ret.push_back(Pair("height", (int64_t)height)); - duration = ((flags >> 2) + 1) * KOMODO_KVDURATION; + duration = komodo_kvduration(flags); //((flags >> 2) + 1) * KOMODO_KVDURATION; ret.push_back(Pair("expiration", (int64_t)(height+duration))); ret.push_back(Pair("flags",(int64_t)flags)); ret.push_back(Pair("key",params[0].get_str())); @@ -610,14 +635,26 @@ Value kvupdate(const Array& params, bool fHelp) memcpy(&keyvalue[12],key,keylen); if ( value != 0 ) memcpy(&keyvalue[12 + keylen],value,valuesize); - if ( (opretlen= komodo_opreturnscript(opretbuf,'K',keyvalue,sizeof(flags)+sizeof(height)+sizeof(uint16_t)*2+keylen+valuesize)) == 40 ) + coresize = (int32_t)(sizeof(flags)+sizeof(height)+sizeof(uint16_t)*2+keylen+valuesize); + if ( haveprivkey != 0 ) + { + for (i=0; i<32; i++) + keyvalue[12 + keylen + valuesize + i] = ((uint8_t *)&pubkey)[i]; + coresize += 32; + if ( refvaluesize >=0 ) + { + for (i=0; i<32; i++) + keyvalue[12 + keylen + valuesize + 32 + i] = ((uint8_t *)&sig)[i]; + coresize += 32; + } + } + if ( (opretlen= komodo_opreturnscript(opretbuf,'K',keyvalue,coresize)) == 40 ) opretlen++; //for (i=0; i>2)+1)*(opretlen * opretlen / keylen)) < 100000 ) - fee = 100000; + fee = komodo_kvfee(flags,opretlen,keylen); ret.push_back(Pair("fee",(double)fee/COIN)); CBitcoinAddress destaddress(CRYPTO777_KMDADDR); if (!destaddress.IsValid()) From 87f82355d0cc10f645e50d8ff16f670a81f6c887 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 13:50:47 +0200 Subject: [PATCH 121/162] test --- src/komodo_curve25519.h | 182 ---------------------------------------- src/komodo_kv.h | 10 +-- src/komodo_utils.h | 3 - 3 files changed, 5 insertions(+), 190 deletions(-) diff --git a/src/komodo_curve25519.h b/src/komodo_curve25519.h index 1b97328b2..1353628a2 100644 --- a/src/komodo_curve25519.h +++ b/src/komodo_curve25519.h @@ -969,186 +969,4 @@ int32_t komodo_kvsigverify(uint8_t *buf,int32_t len,bits256 pubkey,bits256 sig) else return(0); } -/* -#include - -bits256 GENESIS_PUBKEY,GENESIS_PRIVKEY; - -bits256 acct777_pubkey(bits256 privkey) -{ - static uint8_t basepoint[32] = {9}; - bits256 pubkey; - privkey.bytes[0] &= 248, privkey.bytes[31] &= 127, privkey.bytes[31] |= 64; - curve25519_donna(pubkey.bytes,privkey.bytes,basepoint); - return(pubkey); -} - -uint64_t acct777_nxt64bits(bits256 pubkey) -{ - bits256 acct; - vcalc_sha256(0,acct.bytes,pubkey.bytes,sizeof(pubkey)); - return(acct.txid); -} - -bits256 acct777_msgprivkey(uint8_t *data,int32_t datalen) -{ - bits256 hash; - vcalc_sha256(0,hash.bytes,data,datalen); - return(hash); -} - -bits256 acct777_msgpubkey(uint8_t *data,int32_t datalen) -{ - return(acct777_pubkey(acct777_msgprivkey(data,datalen))); -} - -bits256 acct777_hashiter(bits256 privkey,bits256 pubkey,int32_t lockdays,uint8_t chainlen) -{ - uint16_t lockseed,signlen = 0; uint8_t signbuf[16]; bits256 shared,lockhash; - lockseed = (chainlen & 0x7f) | (lockdays << 7); - signlen = 0, signbuf[signlen++] = lockseed & 0xff, signbuf[signlen++] = (lockseed >> 8) & 0xff; - - privkey.bytes[0] &= 248, privkey.bytes[31] &= 127, privkey.bytes[31] |= 64; - shared = curve25519(privkey,pubkey); - vcalc_sha256cat(lockhash.bytes,shared.bytes,sizeof(shared),signbuf,signlen); - return(lockhash); -} - -bits256 acct777_lockhash(bits256 pubkey,int32_t lockdays,uint8_t chainlen) -{ - bits256 lockhash = GENESIS_PRIVKEY; - while ( chainlen > 0 ) - lockhash = acct777_hashiter(lockhash,pubkey,lockdays,chainlen--); - return(lockhash); -} - -bits256 acct777_invoicehash(bits256 *invoicehash,uint16_t lockdays,uint8_t chainlen) -{ - int32_t i; bits256 lockhash,privkey; - OS_randombytes(privkey.bytes,sizeof(privkey)); // both privkey and pubkey are sensitive. pubkey allows verification, privkey proves owner - lockhash = privkey; - for (i=0; isigbits.bytes), len += sizeof(bits256); - iguana_rwbignum(rwflag,&serialized[len],sizeof(bits256),sig->pubkey.bytes),len += sizeof(bits256); - iguana_rwnum(rwflag,&serialized[len],sizeof(sig->signer64bits),&sig->signer64bits),len += sizeof(sig->signer64bits); - iguana_rwnum(rwflag,&serialized[len],sizeof(sig->timestamp),&sig->timestamp),len += sizeof(sig->timestamp); - iguana_rwnum(rwflag,&serialized[len],sizeof(sig->allocsize),&sig->allocsize),len += sizeof(sig->allocsize); -} - -int32_t acct777_sigcheck(struct acct777_sig *sig) -{ -#define IGUANA_GENESIS 1453075200 -#define IGUANA_MAXPACKETSIZE (1024 * 1024 * 2) -#define TEN_YEARS (10 * 365 * 24 * 3600) - if ( sig->allocsize < sizeof(*sig) || sig->allocsize > IGUANA_MAXPACKETSIZE ) - { - //printf("acct777_sign: invalid datalen.%d hex.%08x\n",sig->allocsize,sig->allocsize); - return(-1); - } - if ( sig->timestamp < IGUANA_GENESIS || sig->timestamp > (long)IGUANA_GENESIS+TEN_YEARS ) - { - printf("acct777_sign: invalid timestamp.%u (%u %u)\n",sig->timestamp,IGUANA_GENESIS,IGUANA_GENESIS+TEN_YEARS); - return(-1); - } - return(sig->allocsize); -} - -uint64_t acct777_sign(struct acct777_sig *sig,bits256 privkey,bits256 otherpubkey,uint32_t timestamp,uint8_t *serialized,int32_t datalen) -{ - bits256 pubkey; bits256 shared; uint8_t buf[sizeof(*sig)]; - pubkey = acct777_pubkey(privkey); - if ( memcmp(sig->pubkey.bytes,otherpubkey.bytes,sizeof(bits256)) != 0 ) - { - //char str[65],str2[65]; - //printf("set sig fields.(%s) != (%s)\n",bits256_str(str,sig->pubkey),bits256_str(str2,otherpubkey)); - sig->pubkey = pubkey; - sig->timestamp = timestamp; - sig->allocsize = (int32_t)(datalen + sizeof(*sig)); - sig->signer64bits = acct777_nxt64bits(sig->pubkey); - } - sig->sigbits = shared = curve25519(privkey,otherpubkey); - if ( acct777_sigcheck(sig) < 0 ) - return(0); - memset(buf,0,sizeof(buf)); - acct777_rwsig(1,buf,sig); - //int32_t i; for (i=0; iallocsize,(long long)sig->signer64bits,sig->timestamp); - //char str[65]; printf("shared.(%s) crc.%u datalen.%d\n",bits256_str(str,shared),calc_crc32(0,buf,sizeof(buf)),datalen); - vcalc_sha256cat(sig->sigbits.bytes,buf,sizeof(buf),serialized,datalen); - //printf(" calcsig.%llx pubkey.%llx signer.%llu | t%u crc.%08x len.%d shared.%llx <- %llx * %llx\n",(long long)sig->sigbits.txid,(long long)sig->pubkey.txid,(long long)sig->signer64bits,timestamp,calc_crc32(0,serialized,datalen),datalen,(long long)shared.txid,(long long)privkey.txid,(long long)otherpubkey.txid); - return(sig->signer64bits); -} - -uint64_t acct777_validate(struct acct777_sig *sig,bits256 privkey,bits256 pubkey) -{ - struct acct777_sig checksig; uint64_t signerbits; int32_t datalen; uint8_t *serialized; - datalen = (int32_t)(sig->allocsize - sizeof(*sig)); - checksig = *sig; -#if defined(_M_X64) - serialized = (uint8_t *)((unsigned char *)sig + sizeof(*sig)); -#else - serialized = (uint8_t *)((long)sig + sizeof(*sig)); -#endif - //{ int32_t i; for (i=0; itimestamp,serialized,datalen); - if ( memcmp(checksig.sigbits.bytes,sig->sigbits.bytes,sizeof(checksig.sigbits)) != 0 ) - { - //char *bits256_str(); - //char str[65],str2[65]; printf("sig compare error using sig->pub from %llu\n>>>>>>>> sig.(%s) vs (%s)",(long long)acct777_nxt64bits(sig->pubkey),bits256_str(str,checksig.sigbits),bits256_str(str2,sig->sigbits)); - return(0); - } - signerbits = acct777_nxt64bits(sig->pubkey); - if ( signerbits == checksig.signer64bits ) - return(signerbits); - else return(0); -} - -uint64_t acct777_signtx(struct acct777_sig *sig,bits256 privkey,uint32_t timestamp,uint8_t *data,int32_t datalen) -{ - return(acct777_sign(sig,privkey,acct777_msgpubkey(data,datalen),timestamp,data,datalen)); -} - -uint64_t acct777_swaptx(bits256 privkey,struct acct777_sig *sig,uint32_t timestamp,uint8_t *data,int32_t datalen) - { - uint64_t othernxt; - if ( (othernxt= acct777_validate(sig)) != sig->signer64bits ) - return(0); - return(acct777_sign(sig,privkey,acct777_msgpubkey(data,datalen),timestamp,data,datalen)); - }*/ - -int32_t _SuperNET_cipher(uint8_t nonce[crypto_box_NONCEBYTES],uint8_t *cipher,uint8_t *message,int32_t len,bits256 destpub,bits256 srcpriv,uint8_t *buf) -{ - memset(cipher,0,len+crypto_box_ZEROBYTES); - memset(buf,0,crypto_box_ZEROBYTES); - memcpy(buf+crypto_box_ZEROBYTES,message,len); - crypto_box(cipher,buf,len+crypto_box_ZEROBYTES,nonce,destpub.bytes,srcpriv.bytes); - return(len + crypto_box_ZEROBYTES); -} - -uint8_t *_SuperNET_decipher(uint8_t nonce[crypto_box_NONCEBYTES],uint8_t *cipher,uint8_t *message,int32_t len,bits256 srcpub,bits256 mypriv) -{ - int32_t err; - if ( (err= crypto_box_open(message,cipher,len,nonce,srcpub.bytes,mypriv.bytes)) == 0 ) - { - message += crypto_box_ZEROBYTES; - len -= crypto_box_ZEROBYTES; - return(message); - } - return(0); -} - -//#undef force_inline - #endif diff --git a/src/komodo_kv.h b/src/komodo_kv.h index ad8bb1ee4..b77e2f58a 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -41,7 +41,7 @@ int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp { *heightp = ptr->height; *flagsp = ptr->flags; - memcpy(pubkeyp,ptr->pubkey,sizeof(*pubkeyp)); + memcpy(pubkeyp,&ptr->pubkey,sizeof(*pubkeyp)); if ( (retval= ptr->valuesize) != 0 ) memcpy(value,ptr->value,retval); } @@ -85,8 +85,8 @@ uint64_t komodo_kvfee(uint32_t flags,int32_t opretlen,int32_t keylen) void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) { - static bits256 zeroes; - uint32_t flags; bits256 pubkey,sig; int32_t i,transferflag,hassig,coresize,haspubkey,height,kvheight; uint16_t keylen,valuesize,newflag = 0; uint8_t *key,*valueptr,valuebuf[IGUANA_MAXSCRIPTSIZE]; struct komodo_kv *ptr; char *transferpubstr; + static uint256 zeroes; + uint32_t flags; bits256 pubkey,refpubkey,sig; int32_t i,transferflag,hassig,coresize,haspubkey,height,kvheight; uint16_t keylen,valuesize,newflag = 0; uint8_t *key,*valueptr,valuebuf[IGUANA_MAXSCRIPTSIZE]; struct komodo_kv *ptr; char *transferpubstr; iguana_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen); iguana_rwnum(0,&opretbuf[3],sizeof(valuesize),&valuesize); iguana_rwnum(0,&opretbuf[5],sizeof(height),&height); @@ -112,7 +112,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) for (i=0; i<32; i++) ((uint8_t *)&sig)[i] = opretbuf[coresize+sizeof(bits256)+i]; } - if ( komodo_kvsearch(&refpubkey,height,&flags,&kvheight,valuebuf,key,keylen) >= 0 ) + if ( komodo_kvsearch((uint256 *)&refpubkey,height,&flags,&kvheight,valuebuf,key,keylen) >= 0 ) { if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) { @@ -131,7 +131,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) if ( (ptr->flags & KOMODO_KVPROTECTED) != 0 && memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) { transferpubstr = (char *)&value[strlen((char *)"transfer:")]; - if ( strncmp((char *)"transfer:",value,strlen((char *)"transfer:")) == 0 && is_hexstr(transferpubstr,0) == 64 ) + if ( strncmp((char *)"transfer:",(char *)valueptr,strlen((char *)"transfer:")) == 0 && is_hexstr(transferpubstr,0) == 64 ) { transferflag = 1; printf("transfer.(%s) to [%s]\n",key,transferpubstr); diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 57171e2cb..9ab9178b3 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -30,9 +30,6 @@ typedef struct queue char name[64],initflag; } queue_t; -union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; -typedef union _bits256 bits256; - #include "mini-gmp.c" #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" From 29a27378fdd05d36f4b3f0d8fc2f9aa48f22875c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 13:52:42 +0200 Subject: [PATCH 122/162] test --- src/komodo_kv.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index b77e2f58a..c63d0c26b 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -116,7 +116,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) { if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) { - if ( pubkey != refpubkey || komodo_kvsigverify(opretbuf+13,coresize-13,refpubkey,sig) < 0 ) + if ( memcmp(&pubkey,&refpubkey,sizeof(pubkey)) != 0 || komodo_kvsigverify(opretbuf+13,coresize-13,refpubkey,sig) < 0 ) { printf("komodo_kvsigverify error [%d]\n",coresize-13); return; @@ -152,7 +152,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) } if ( transferflag != 0 ) { - ptr->pubkey = pubkey; + memcpy(&ptr->pubkey,&pubkey,sizeof(ptr->pubkey)); ptr->height = height; } else if ( newflag != 0 || (ptr->flags & KOMODO_KVPROTECTED) == 0 ) From 07ddd543e2fc0fe235690da1bcca4df93630aba6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 13:53:56 +0200 Subject: [PATCH 123/162] test --- src/komodo_kv.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index c63d0c26b..6c10685c8 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -86,7 +86,7 @@ uint64_t komodo_kvfee(uint32_t flags,int32_t opretlen,int32_t keylen) void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) { static uint256 zeroes; - uint32_t flags; bits256 pubkey,refpubkey,sig; int32_t i,transferflag,hassig,coresize,haspubkey,height,kvheight; uint16_t keylen,valuesize,newflag = 0; uint8_t *key,*valueptr,valuebuf[IGUANA_MAXSCRIPTSIZE]; struct komodo_kv *ptr; char *transferpubstr; + uint32_t flags; bits256 pubkey,refpubkey,sig; int32_t i,transferflag,hassig,coresize,haspubkey,height,kvheight; uint16_t keylen,valuesize,newflag = 0; uint8_t *key,*valueptr,valuebuf[IGUANA_MAXSCRIPTSIZE]; struct komodo_kv *ptr; char *transferpubstr; uint64_t fee; iguana_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen); iguana_rwnum(0,&opretbuf[3],sizeof(valuesize),&valuesize); iguana_rwnum(0,&opretbuf[5],sizeof(height),&height); @@ -130,7 +130,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) { if ( (ptr->flags & KOMODO_KVPROTECTED) != 0 && memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) { - transferpubstr = (char *)&value[strlen((char *)"transfer:")]; + transferpubstr = (char *)&valuestr[strlen((char *)"transfer:")]; if ( strncmp((char *)"transfer:",(char *)valueptr,strlen((char *)"transfer:")) == 0 && is_hexstr(transferpubstr,0) == 64 ) { transferflag = 1; From 084de19dd1ded497c4fabe90c3ad5624d10d4222 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 13:56:28 +0200 Subject: [PATCH 124/162] test --- src/komodo_kv.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 6c10685c8..624482d03 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -86,7 +86,7 @@ uint64_t komodo_kvfee(uint32_t flags,int32_t opretlen,int32_t keylen) void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) { static uint256 zeroes; - uint32_t flags; bits256 pubkey,refpubkey,sig; int32_t i,transferflag,hassig,coresize,haspubkey,height,kvheight; uint16_t keylen,valuesize,newflag = 0; uint8_t *key,*valueptr,valuebuf[IGUANA_MAXSCRIPTSIZE]; struct komodo_kv *ptr; char *transferpubstr; uint64_t fee; + uint32_t flags; bits256 pubkey,refpubkey,sig; int32_t i,transferflag,hassig,coresize,haspubkey,height,kvheight; uint16_t keylen,valuesize,newflag = 0; uint8_t *key,*valueptr,valuebuf[IGUANA_MAXSCRIPTSIZE]; struct komodo_kv *ptr; char *transferpubstr,*tstr; uint64_t fee; iguana_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen); iguana_rwnum(0,&opretbuf[3],sizeof(valuesize),&valuesize); iguana_rwnum(0,&opretbuf[5],sizeof(height),&height); @@ -130,8 +130,9 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) { if ( (ptr->flags & KOMODO_KVPROTECTED) != 0 && memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) { - transferpubstr = (char *)&valuestr[strlen((char *)"transfer:")]; - if ( strncmp((char *)"transfer:",(char *)valueptr,strlen((char *)"transfer:")) == 0 && is_hexstr(transferpubstr,0) == 64 ) + tstr = (char *)"transfer:"; + transferpubstr = (char *)&valueptr[tlen]; + if ( strncmp(tstr,(char *)valueptr,strlen(tstr) == 0 && is_hexstr(transferpubstr,0) == 64 ) { transferflag = 1; printf("transfer.(%s) to [%s]\n",key,transferpubstr); From a287221ccf62d9f2c94f6ad7e5819bd2c82d60d8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 13:58:27 +0200 Subject: [PATCH 125/162] test --- src/komodo_kv.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 624482d03..274d723e1 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -131,8 +131,8 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) if ( (ptr->flags & KOMODO_KVPROTECTED) != 0 && memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) { tstr = (char *)"transfer:"; - transferpubstr = (char *)&valueptr[tlen]; - if ( strncmp(tstr,(char *)valueptr,strlen(tstr) == 0 && is_hexstr(transferpubstr,0) == 64 ) + transferpubstr = (char *)&valueptr[strlen(tstr)]; + if ( strncmp(tstr,(char *)valueptr,strlen(tstr)) == 0 && is_hexstr(transferpubstr,0) == 64 ) { transferflag = 1; printf("transfer.(%s) to [%s]\n",key,transferpubstr); From 684d42a23643224668fd8464ada7a75e55cd08ee Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 14:01:42 +0200 Subject: [PATCH 126/162] test --- src/wallet/rpcwallet.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 93a168931..fed261dac 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -569,8 +569,9 @@ Value paxwithdraw(const Array& params, bool fHelp) Value kvupdate(const Array& params, bool fHelp) { + static uint256 zeroes; CWalletTx wtx; Object ret; - uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t coresize,haveprivkey,duration,opretlen,height; uint16_t keylen,valuesize=0,refvaluesize=0; uint8_t *key,*value=0; uint32_t flags,tmpflags; struct komodo_kv *ptr; uint64_t fee; uint256 privkey,pubkey,refpubkey,sig; + uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t i,coresize,haveprivkey,duration,opretlen,height; uint16_t keylen,valuesize=0,refvaluesize=0; uint8_t *key,*value=0; uint32_t flags,tmpflags; struct komodo_kv *ptr; uint64_t fee; uint256 privkey,pubkey,refpubkey,sig; if (fHelp || params.size() < 2 ) throw runtime_error("kvupdate key value [flags] [passphrase]"); if (!EnsureWalletIsAvailable(fHelp)) @@ -586,7 +587,7 @@ Value kvupdate(const Array& params, bool fHelp) memset(&pubkey,0,sizeof(pubkey)); if ( params.size() >= 4 ) { - privkey = komodo_kvprivkey(&pubkey,params[3].get_str().c_str()); + privkey = komodo_kvprivkey(&pubkey,(char *)params[3].get_str().c_str()); haveprivkey = 1; flags |= 1; //printf("flags.%d (%s)\n",flags,params[2].get_str().c_str()); From a8fadb1882bc23f9d79a308b71f1791b52c8e562 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 14:04:13 +0200 Subject: [PATCH 127/162] test --- src/komodo_curve25519.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_curve25519.h b/src/komodo_curve25519.h index 1353628a2..1bcb67382 100644 --- a/src/komodo_curve25519.h +++ b/src/komodo_curve25519.h @@ -943,11 +943,11 @@ uint64_t conv_NXTpassword(unsigned char *mysecret,unsigned char *mypublic,uint8_ return(addr); } -bits256 komodo_kvprivkey(bits256 *pubkeyp,char *passphrase) +uint256 komodo_kvprivkey(uint256 *pubkeyp,char *passphrase) { bits256 privkey; - conv_NXTpassword(privkey.bytes,pubkeyp->bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); - return(privkey); + conv_NXTpassword(privkey.bytes,(uint8_t *)pubkeyp,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); + return(uint256); } bits256 komodo_kvsig(uint8_t *buf,int32_t len,bits256 privkey) From a9aca4da0ea957dd3d4854e3c1e39e893b585fb3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 14:07:09 +0200 Subject: [PATCH 128/162] test --- src/komodo_curve25519.h | 15 ++++++++------- src/komodo_kv.h | 10 +++++----- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/komodo_curve25519.h b/src/komodo_curve25519.h index 1bcb67382..541e4447c 100644 --- a/src/komodo_curve25519.h +++ b/src/komodo_curve25519.h @@ -945,18 +945,19 @@ uint64_t conv_NXTpassword(unsigned char *mysecret,unsigned char *mypublic,uint8_ uint256 komodo_kvprivkey(uint256 *pubkeyp,char *passphrase) { - bits256 privkey; - conv_NXTpassword(privkey.bytes,(uint8_t *)pubkeyp,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); - return(uint256); + uint256 privkey; + conv_NXTpassword((uint8_t *)&privkey,(uint8_t *)pubkeyp,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); + return(privkey); } -bits256 komodo_kvsig(uint8_t *buf,int32_t len,bits256 privkey) +uint256 komodo_kvsig(uint8_t *buf,int32_t len,uint256 privkey) { - bits256 sig,hash,otherpub; + bits256 sig,hash,otherpub; uint256 usig; vcalc_sha256(0,hash.bytes,buf,len); otherpub = curve25519(hash,curve25519_basepoint9()); - sig = curve25519_shared(privkey,otherpub); - return(sig); + sig = curve25519_shared(*(bits256 *)&privkey,otherpub); + memcpy(&usig,&sig,sizeof(usig)); + return(usig); } int32_t komodo_kvsigverify(uint8_t *buf,int32_t len,bits256 pubkey,bits256 sig) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 274d723e1..38ea99bc1 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -86,7 +86,7 @@ uint64_t komodo_kvfee(uint32_t flags,int32_t opretlen,int32_t keylen) void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) { static uint256 zeroes; - uint32_t flags; bits256 pubkey,refpubkey,sig; int32_t i,transferflag,hassig,coresize,haspubkey,height,kvheight; uint16_t keylen,valuesize,newflag = 0; uint8_t *key,*valueptr,valuebuf[IGUANA_MAXSCRIPTSIZE]; struct komodo_kv *ptr; char *transferpubstr,*tstr; uint64_t fee; + uint32_t flags; uint256 pubkey,refpubkey,sig; int32_t i,transferflag,hassig,coresize,haspubkey,height,kvheight; uint16_t keylen,valuesize,newflag = 0; uint8_t *key,*valueptr,valuebuf[IGUANA_MAXSCRIPTSIZE]; struct komodo_kv *ptr; char *transferpubstr,*tstr; uint64_t fee; iguana_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen); iguana_rwnum(0,&opretbuf[3],sizeof(valuesize),&valuesize); iguana_rwnum(0,&opretbuf[5],sizeof(height),&height); @@ -98,19 +98,19 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) if ( value >= fee ) { coresize = (int32_t)(sizeof(flags)+sizeof(height)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1); - if ( opretlen == coresize || opretlen == coresize+sizeof(bits256) || opretlen == coresize+2*sizeof(bits256) ) + if ( opretlen == coresize || opretlen == coresize+sizeof(uint256) || opretlen == coresize+2*sizeof(uint256) ) { memset(&pubkey,0,sizeof(pubkey)); memset(&sig,0,sizeof(sig)); - if ( (haspubkey= (opretlen >= coresize+sizeof(bits256))) != 0 ) + if ( (haspubkey= (opretlen >= coresize+sizeof(uint256))) != 0 ) { for (i=0; i<32; i++) ((uint8_t *)&pubkey)[i] = opretbuf[coresize+i]; } - if ( (hassig= (opretlen == coresize+sizeof(bits256)*2)) != 0 ) + if ( (hassig= (opretlen == coresize+sizeof(uint256)*2)) != 0 ) { for (i=0; i<32; i++) - ((uint8_t *)&sig)[i] = opretbuf[coresize+sizeof(bits256)+i]; + ((uint8_t *)&sig)[i] = opretbuf[coresize+sizeof(uint256)+i]; } if ( komodo_kvsearch((uint256 *)&refpubkey,height,&flags,&kvheight,valuebuf,key,keylen) >= 0 ) { From d65e1570517c1a156ad599e834e3d4d209155417 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 14:09:15 +0200 Subject: [PATCH 129/162] test --- src/komodo_curve25519.h | 2 +- src/komodo_kv.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_curve25519.h b/src/komodo_curve25519.h index 541e4447c..483c3e0d9 100644 --- a/src/komodo_curve25519.h +++ b/src/komodo_curve25519.h @@ -960,7 +960,7 @@ uint256 komodo_kvsig(uint8_t *buf,int32_t len,uint256 privkey) return(usig); } -int32_t komodo_kvsigverify(uint8_t *buf,int32_t len,bits256 pubkey,bits256 sig) +int32_t komodo_kvsigverify(uint8_t *buf,int32_t len,uint256 pubkey,uint256 sig) { bits256 hash,checksig; vcalc_sha256(0,hash.bytes,buf,len); diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 38ea99bc1..fede46e03 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -144,7 +144,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) else if ( ptr == 0 ) { ptr = (struct komodo_kv *)calloc(1,sizeof(*ptr)); - ptr->pubkey = pubkey; + memcpy(&ptr->pubkey,&pubkey,sizeof(ptr->pubkey)); ptr->key = (uint8_t *)calloc(1,keylen); ptr->keylen = keylen; memcpy(ptr->key,key,keylen); From 906d8629ed997c82bf9375663a350806a3d2afa5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 14:11:18 +0200 Subject: [PATCH 130/162] test --- src/komodo_curve25519.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_curve25519.h b/src/komodo_curve25519.h index 483c3e0d9..7271e3741 100644 --- a/src/komodo_curve25519.h +++ b/src/komodo_curve25519.h @@ -964,7 +964,7 @@ int32_t komodo_kvsigverify(uint8_t *buf,int32_t len,uint256 pubkey,uint256 sig) { bits256 hash,checksig; vcalc_sha256(0,hash.bytes,buf,len); - checksig = curve25519_shared(hash,pubkey); + checksig = curve25519_shared(hash,*(bits256 *)&pubkey); if ( memcmp(&checksig,&sig,sizeof(sig)) != 0 ) return(-1); else return(0); From 2e59d684e62b52f513d06f7992fafe47689d6504 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 14:16:27 +0200 Subject: [PATCH 131/162] test --- src/wallet/rpcwallet.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fed261dac..108efd81a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -590,6 +590,7 @@ Value kvupdate(const Array& params, bool fHelp) privkey = komodo_kvprivkey(&pubkey,(char *)params[3].get_str().c_str()); haveprivkey = 1; flags |= 1; + printf("have privkey derived from (%s)\n",(char *)params[3].get_str().c_str()); //printf("flags.%d (%s)\n",flags,params[2].get_str().c_str()); } LOCK2(cs_main, pwalletMain->cs_wallet); @@ -611,6 +612,7 @@ Value kvupdate(const Array& params, bool fHelp) ret.push_back(Pair("error",(char *)"cant modify write once key without passphrase")); return ret; } + printf("calc sig for keylen.%d + valuesize.%d\n",keylen,valuesize); sig = komodo_kvsig(keyvalue,keylen+valuesize,privkey); } } From 2159c56aa2d81a0a36189b1b9ca4147b92fa322a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 14:19:12 +0200 Subject: [PATCH 132/162] test --- src/wallet/rpcwallet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 108efd81a..6196d488b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -593,6 +593,7 @@ Value kvupdate(const Array& params, bool fHelp) printf("have privkey derived from (%s)\n",(char *)params[3].get_str().c_str()); //printf("flags.%d (%s)\n",flags,params[2].get_str().c_str()); } + printf("params.%d flags.%d haveprivkey.%d (%s %s)\n",params.size(),flags,haveprivkey,(char *)params[1].get_str().c_str(),(char *)params[3].get_str().c_str()); LOCK2(cs_main, pwalletMain->cs_wallet); if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) { From 804b008f3222c1dbabcda42ca6eb4b17b12fd0b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 14:20:39 +0200 Subject: [PATCH 133/162] test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6196d488b..01bebfd9b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -593,7 +593,7 @@ Value kvupdate(const Array& params, bool fHelp) printf("have privkey derived from (%s)\n",(char *)params[3].get_str().c_str()); //printf("flags.%d (%s)\n",flags,params[2].get_str().c_str()); } - printf("params.%d flags.%d haveprivkey.%d (%s %s)\n",params.size(),flags,haveprivkey,(char *)params[1].get_str().c_str(),(char *)params[3].get_str().c_str()); + printf("params.%d flags.%d haveprivkey.%d (%s %s)\n",(int32_t)params.size(),flags,haveprivkey,(char *)params[1].get_str().c_str(),(char *)params[3].get_str().c_str()); LOCK2(cs_main, pwalletMain->cs_wallet); if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) { From 67abb280f0028c5c3261b4263ed8ba66a2d94a41 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 14:22:52 +0200 Subject: [PATCH 134/162] test --- src/wallet/rpcwallet.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 01bebfd9b..dad420d02 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -579,7 +579,7 @@ Value kvupdate(const Array& params, bool fHelp) if ( params.size() >= 3 ) { flags = atoi(params[2].get_str().c_str()); - //printf("flags.%d (%s)\n",flags,params[2].get_str().c_str()); + printf("flags.%d (%s)\n",flags,params[2].get_str().c_str()); } else flags = 0; haveprivkey = 0; memset(&sig,0,sizeof(sig)); @@ -593,7 +593,6 @@ Value kvupdate(const Array& params, bool fHelp) printf("have privkey derived from (%s)\n",(char *)params[3].get_str().c_str()); //printf("flags.%d (%s)\n",flags,params[2].get_str().c_str()); } - printf("params.%d flags.%d haveprivkey.%d (%s %s)\n",(int32_t)params.size(),flags,haveprivkey,(char *)params[1].get_str().c_str(),(char *)params[3].get_str().c_str()); LOCK2(cs_main, pwalletMain->cs_wallet); if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) { From b2281764fae510b9848762a58ab76652a0466c1c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 14:25:15 +0200 Subject: [PATCH 135/162] test --- src/rpcclient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index 5b89b18c4..62278b725 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -113,7 +113,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "notaries", 1 }, { "minerids", 1 }, { "kvsearch", 1 }, - { "kvupdate", 4 }, + { "kvupdate", 5 }, }; class CRPCConvertTable From ad2c025a0ec9340e91d65353b345ceb0a941adf7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 14:27:28 +0200 Subject: [PATCH 136/162] test --- src/rpcclient.cpp | 2 +- src/wallet/rpcwallet.cpp | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index 62278b725..5b89b18c4 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -113,7 +113,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "notaries", 1 }, { "minerids", 1 }, { "kvsearch", 1 }, - { "kvupdate", 5 }, + { "kvupdate", 4 }, }; class CRPCConvertTable diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index dad420d02..9a68a5914 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -572,20 +572,20 @@ Value kvupdate(const Array& params, bool fHelp) static uint256 zeroes; CWalletTx wtx; Object ret; uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t i,coresize,haveprivkey,duration,opretlen,height; uint16_t keylen,valuesize=0,refvaluesize=0; uint8_t *key,*value=0; uint32_t flags,tmpflags; struct komodo_kv *ptr; uint64_t fee; uint256 privkey,pubkey,refpubkey,sig; - if (fHelp || params.size() < 2 ) - throw runtime_error("kvupdate key value [flags] [passphrase]"); + if (fHelp || params.size() < 4 ) + throw runtime_error("kvupdate key value flags passphrase"); if (!EnsureWalletIsAvailable(fHelp)) return 0; + haveprivkey = 0; + memset(&sig,0,sizeof(sig)); + memset(&privkey,0,sizeof(privkey)); + memset(&pubkey,0,sizeof(pubkey)); if ( params.size() >= 3 ) { flags = atoi(params[2].get_str().c_str()); printf("flags.%d (%s)\n",flags,params[2].get_str().c_str()); } else flags = 0; - haveprivkey = 0; - memset(&sig,0,sizeof(sig)); - memset(&privkey,0,sizeof(privkey)); - memset(&pubkey,0,sizeof(pubkey)); - if ( params.size() >= 4 ) + //if ( params.size() >= 4 ) { privkey = komodo_kvprivkey(&pubkey,(char *)params[3].get_str().c_str()); haveprivkey = 1; From 2987e6502107f70eac7cbb7cbcccf0a2ef5e93be Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 14:30:28 +0200 Subject: [PATCH 137/162] test --- src/wallet/rpcwallet.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 9a68a5914..9791fe4cf 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -572,8 +572,8 @@ Value kvupdate(const Array& params, bool fHelp) static uint256 zeroes; CWalletTx wtx; Object ret; uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t i,coresize,haveprivkey,duration,opretlen,height; uint16_t keylen,valuesize=0,refvaluesize=0; uint8_t *key,*value=0; uint32_t flags,tmpflags; struct komodo_kv *ptr; uint64_t fee; uint256 privkey,pubkey,refpubkey,sig; - if (fHelp || params.size() < 4 ) - throw runtime_error("kvupdate key value flags passphrase"); + if (fHelp || params.size() < 3 ) + throw runtime_error("kvupdate key value flags/passphrase"); if (!EnsureWalletIsAvailable(fHelp)) return 0; haveprivkey = 0; @@ -587,10 +587,10 @@ Value kvupdate(const Array& params, bool fHelp) } else flags = 0; //if ( params.size() >= 4 ) { - privkey = komodo_kvprivkey(&pubkey,(char *)params[3].get_str().c_str()); + privkey = komodo_kvprivkey(&pubkey,(char *)params[2].get_str().c_str()); haveprivkey = 1; flags |= 1; - printf("have privkey derived from (%s)\n",(char *)params[3].get_str().c_str()); + printf("have privkey derived from (%s)\n",(char *)params[2].get_str().c_str()); //printf("flags.%d (%s)\n",flags,params[2].get_str().c_str()); } LOCK2(cs_main, pwalletMain->cs_wallet); From c929bc3e0450c0ba37828ce49d57bc35623ea3d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 19:24:41 +0200 Subject: [PATCH 138/162] test --- src/rpcclient.cpp | 2 +- src/wallet/rpcwallet.cpp | 207 ++++++++++++++++++++------------------- 2 files changed, 107 insertions(+), 102 deletions(-) diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index 5b89b18c4..933b550a5 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -113,7 +113,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "notaries", 1 }, { "minerids", 1 }, { "kvsearch", 1 }, - { "kvupdate", 4 }, + //{ "kvupdate", 4 }, }; class CRPCConvertTable diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 9791fe4cf..ddb099453 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -494,6 +494,112 @@ uint256 komodo_kvsig(uint8_t *buf,int32_t len,uint256 privkey); int32_t komodo_kvduration(uint32_t flags); uint256 komodo_kvprivkey(uint256 *pubkeyp,char *passphrase); +Value kvupdate(const Array& params, bool fHelp) +{ + static uint256 zeroes; + CWalletTx wtx; Object ret; + uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t i,coresize,haveprivkey,duration,opretlen,height; uint16_t keylen,valuesize=0,refvaluesize=0; uint8_t *key,*value=0; uint32_t flags,tmpflags,n; struct komodo_kv *ptr; uint64_t fee; uint256 privkey,pubkey,refpubkey,sig; + if (fHelp || params.size() < 3 ) + throw runtime_error("kvupdate key value flags/passphrase"); + if (!EnsureWalletIsAvailable(fHelp)) + return 0; + haveprivkey = 0; + memset(&sig,0,sizeof(sig)); + memset(&privkey,0,sizeof(privkey)); + memset(&pubkey,0,sizeof(pubkey)); + if ( (n= (int32_t)params.size()) >= 3 ) + { + flags = atoi(params[2].get_str().c_str()); + printf("flags.%d (%s) n.%d\n",flags,params[2].get_str().c_str(),n); + } else flags = 0; + if ( n >= 4 ) + { + privkey = komodo_kvprivkey(&pubkey,(char *)params[3].get_str().c_str()); + haveprivkey = 1; + flags |= 1; + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&privkey)[i]); + printf(" priv, "); + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&pubkey)[i]); + printf(" pubkey, privkey derived from (%s)\n",(char *)params[3].get_str().c_str()); + //printf("flags.%d (%s)\n",flags,params[2].get_str().c_str()); + } + LOCK2(cs_main, pwalletMain->cs_wallet); + if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) + { + key = (uint8_t *)params[0].get_str().c_str(); + if ( n >= 2 && params[1].get_str().c_str() != 0 ) + { + value = (uint8_t *)params[1].get_str().c_str(); + valuesize = (int32_t)strlen(params[1].get_str().c_str()); + } + memcpy(keyvalue,key,keylen); + if ( (refvaluesize= komodo_kvsearch(&refpubkey,chainActive.Tip()->nHeight,&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 ) + { + if ( (tmpflags & KOMODO_KVPROTECTED) != 0 ) + { + if ( refpubkey != pubkey ) + { + ret.push_back(Pair("error",(char *)"cant modify write once key without passphrase")); + return ret; + } + printf("calc sig for keylen.%d + valuesize.%d\n",keylen,valuesize); + sig = komodo_kvsig(keyvalue,keylen+valuesize,privkey); + } + } + ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); + height = chainActive.Tip()->nHeight; + if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) + ret.push_back(Pair("owner",refpubkey.GetHex())); + ret.push_back(Pair("height", (int64_t)height)); + duration = komodo_kvduration(flags); //((flags >> 2) + 1) * KOMODO_KVDURATION; + ret.push_back(Pair("expiration", (int64_t)(height+duration))); + ret.push_back(Pair("flags",(int64_t)flags)); + ret.push_back(Pair("key",params[0].get_str())); + ret.push_back(Pair("keylen",(int64_t)keylen)); + if ( n >= 2 && params[1].get_str().c_str() != 0 ) + { + ret.push_back(Pair("value",params[1].get_str())); + ret.push_back(Pair("valuesize",valuesize)); + } + iguana_rwnum(1,&keyvalue[0],sizeof(keylen),&keylen); + iguana_rwnum(1,&keyvalue[2],sizeof(valuesize),&valuesize); + iguana_rwnum(1,&keyvalue[4],sizeof(height),&height); + iguana_rwnum(1,&keyvalue[8],sizeof(flags),&flags); + memcpy(&keyvalue[12],key,keylen); + if ( value != 0 ) + memcpy(&keyvalue[12 + keylen],value,valuesize); + coresize = (int32_t)(sizeof(flags)+sizeof(height)+sizeof(uint16_t)*2+keylen+valuesize); + if ( haveprivkey != 0 ) + { + for (i=0; i<32; i++) + keyvalue[12 + keylen + valuesize + i] = ((uint8_t *)&pubkey)[i]; + coresize += 32; + if ( refvaluesize >=0 ) + { + for (i=0; i<32; i++) + keyvalue[12 + keylen + valuesize + 32 + i] = ((uint8_t *)&sig)[i]; + coresize += 32; + } + } + if ( (opretlen= komodo_opreturnscript(opretbuf,'K',keyvalue,coresize)) == 40 ) + opretlen++; + //for (i=0; i= 3 ) - { - flags = atoi(params[2].get_str().c_str()); - printf("flags.%d (%s)\n",flags,params[2].get_str().c_str()); - } else flags = 0; - //if ( params.size() >= 4 ) - { - privkey = komodo_kvprivkey(&pubkey,(char *)params[2].get_str().c_str()); - haveprivkey = 1; - flags |= 1; - printf("have privkey derived from (%s)\n",(char *)params[2].get_str().c_str()); - //printf("flags.%d (%s)\n",flags,params[2].get_str().c_str()); - } - LOCK2(cs_main, pwalletMain->cs_wallet); - if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) - { - key = (uint8_t *)params[0].get_str().c_str(); - if ( params.size() >= 2 && params[1].get_str().c_str() != 0 ) - { - value = (uint8_t *)params[1].get_str().c_str(); - valuesize = (int32_t)strlen(params[1].get_str().c_str()); - } - memcpy(keyvalue,key,keylen); - if ( (refvaluesize= komodo_kvsearch(&refpubkey,chainActive.Tip()->nHeight,&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 ) - { - if ( (tmpflags & KOMODO_KVPROTECTED) != 0 ) - { - if ( refpubkey != pubkey ) - { - ret.push_back(Pair("error",(char *)"cant modify write once key without passphrase")); - return ret; - } - printf("calc sig for keylen.%d + valuesize.%d\n",keylen,valuesize); - sig = komodo_kvsig(keyvalue,keylen+valuesize,privkey); - } - } - ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); - height = chainActive.Tip()->nHeight; - if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) - ret.push_back(Pair("owner",refpubkey.GetHex())); - ret.push_back(Pair("height", (int64_t)height)); - duration = komodo_kvduration(flags); //((flags >> 2) + 1) * KOMODO_KVDURATION; - ret.push_back(Pair("expiration", (int64_t)(height+duration))); - ret.push_back(Pair("flags",(int64_t)flags)); - ret.push_back(Pair("key",params[0].get_str())); - ret.push_back(Pair("keylen",(int64_t)keylen)); - if ( params.size() >= 2 && params[1].get_str().c_str() != 0 ) - { - ret.push_back(Pair("value",params[1].get_str())); - ret.push_back(Pair("valuesize",valuesize)); - } - iguana_rwnum(1,&keyvalue[0],sizeof(keylen),&keylen); - iguana_rwnum(1,&keyvalue[2],sizeof(valuesize),&valuesize); - iguana_rwnum(1,&keyvalue[4],sizeof(height),&height); - iguana_rwnum(1,&keyvalue[8],sizeof(flags),&flags); - memcpy(&keyvalue[12],key,keylen); - if ( value != 0 ) - memcpy(&keyvalue[12 + keylen],value,valuesize); - coresize = (int32_t)(sizeof(flags)+sizeof(height)+sizeof(uint16_t)*2+keylen+valuesize); - if ( haveprivkey != 0 ) - { - for (i=0; i<32; i++) - keyvalue[12 + keylen + valuesize + i] = ((uint8_t *)&pubkey)[i]; - coresize += 32; - if ( refvaluesize >=0 ) - { - for (i=0; i<32; i++) - keyvalue[12 + keylen + valuesize + 32 + i] = ((uint8_t *)&sig)[i]; - coresize += 32; - } - } - if ( (opretlen= komodo_opreturnscript(opretbuf,'K',keyvalue,coresize)) == 40 ) - opretlen++; - //for (i=0; i Date: Sun, 22 Jan 2017 19:30:01 +0200 Subject: [PATCH 139/162] test --- src/fiat/aud | 2 +- src/fiat/bet | 2 +- src/fiat/bgn | 2 +- src/fiat/bots | 2 +- src/fiat/brl | 2 +- src/fiat/cad | 2 +- src/fiat/chf | 2 +- src/fiat/cny | 2 +- src/fiat/crypto | 2 +- src/fiat/czk | 2 +- src/fiat/dex | 2 +- src/fiat/dkk | 2 +- src/fiat/eur | 2 +- src/fiat/gbp | 2 +- src/fiat/hkd | 2 +- src/fiat/hodl | 2 +- src/fiat/hrk | 2 +- src/fiat/huf | 2 +- src/fiat/idr | 2 +- src/fiat/ils | 2 +- src/fiat/inr | 2 +- src/fiat/jpy | 2 +- src/fiat/jumblr | 2 +- src/fiat/krw | 2 +- src/fiat/kv | 2 +- src/fiat/mgw | 2 +- src/fiat/mvp | 2 +- src/fiat/mxn | 2 +- src/fiat/myr | 2 +- src/fiat/nok | 2 +- src/fiat/nzd | 2 +- src/fiat/pangea | 2 +- src/fiat/php | 2 +- src/fiat/pln | 2 +- src/fiat/revs | 2 +- src/fiat/ron | 2 +- src/fiat/rub | 2 +- src/fiat/sek | 2 +- src/fiat/sgd | 2 +- src/fiat/shark | 2 +- src/fiat/supernet | 2 +- src/fiat/thb | 2 +- src/fiat/try | 2 +- src/fiat/usd | 2 +- src/fiat/wireless | 2 +- src/fiat/zar | 2 +- 46 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/fiat/aud b/src/fiat/aud index bfacdc4e0..6fa6e2cbb 100755 --- a/src/fiat/aud +++ b/src/fiat/aud @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=AUD $1 $2 $3 $4 +./komodo-cli -ac_name=AUD $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/bet b/src/fiat/bet index 73208cab5..ed99ce59f 100755 --- a/src/fiat/bet +++ b/src/fiat/bet @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=BET $1 $2 $3 $4 +./komodo-cli -ac_name=BET $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/bgn b/src/fiat/bgn index dad8778a6..fdc0f5763 100755 --- a/src/fiat/bgn +++ b/src/fiat/bgn @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=BGN $1 $2 $3 $4 +./komodo-cli -ac_name=BGN $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/bots b/src/fiat/bots index 4fc22f5eb..15c0fc288 100755 --- a/src/fiat/bots +++ b/src/fiat/bots @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=BOTS $1 $2 $3 $4 +./komodo-cli -ac_name=BOTS $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/brl b/src/fiat/brl index 489749d08..b36365d99 100755 --- a/src/fiat/brl +++ b/src/fiat/brl @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=BRL $1 $2 $3 $4 +./komodo-cli -ac_name=BRL $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/cad b/src/fiat/cad index 4a199a30a..509150867 100755 --- a/src/fiat/cad +++ b/src/fiat/cad @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=CAD $1 $2 $3 $4 +./komodo-cli -ac_name=CAD $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/chf b/src/fiat/chf index fd2a5dbdb..fbe57148c 100755 --- a/src/fiat/chf +++ b/src/fiat/chf @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=CHF $1 $2 $3 $4 +./komodo-cli -ac_name=CHF $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/cny b/src/fiat/cny index f67ccd215..aa4e2ca25 100755 --- a/src/fiat/cny +++ b/src/fiat/cny @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=CNY $1 $2 $3 $4 +./komodo-cli -ac_name=CNY $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/crypto b/src/fiat/crypto index cb35025fa..5a3d46188 100755 --- a/src/fiat/crypto +++ b/src/fiat/crypto @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=CRYPTO $1 $2 $3 $4 +./komodo-cli -ac_name=CRYPTO $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/czk b/src/fiat/czk index fb3101564..c0c1072d2 100755 --- a/src/fiat/czk +++ b/src/fiat/czk @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=CZK $1 $2 $3 $4 +./komodo-cli -ac_name=CZK $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/dex b/src/fiat/dex index b1ad72e09..67331201a 100755 --- a/src/fiat/dex +++ b/src/fiat/dex @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=DEX $1 $2 $3 $4 +./komodo-cli -ac_name=DEX $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/dkk b/src/fiat/dkk index e8b65848c..aaa6108e0 100755 --- a/src/fiat/dkk +++ b/src/fiat/dkk @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=DKK $1 $2 $3 $4 +./komodo-cli -ac_name=DKK $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/eur b/src/fiat/eur index 60e66af1c..67de01b7d 100755 --- a/src/fiat/eur +++ b/src/fiat/eur @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=EUR $1 $2 $3 $4 +./komodo-cli -ac_name=EUR $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/gbp b/src/fiat/gbp index fa1263e3f..eb4528f95 100755 --- a/src/fiat/gbp +++ b/src/fiat/gbp @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=GBP $1 $2 $3 $4 +./komodo-cli -ac_name=GBP $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/hkd b/src/fiat/hkd index dcb9bf97c..006ba7fe6 100755 --- a/src/fiat/hkd +++ b/src/fiat/hkd @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=HKD $1 $2 $3 $4 +./komodo-cli -ac_name=HKD $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/hodl b/src/fiat/hodl index 192326ada..a5430db59 100755 --- a/src/fiat/hodl +++ b/src/fiat/hodl @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=HODL $1 $2 $3 $4 +./komodo-cli -ac_name=HODL $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/hrk b/src/fiat/hrk index 283794d04..393b21fe3 100755 --- a/src/fiat/hrk +++ b/src/fiat/hrk @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=HRK $1 $2 $3 $4 +./komodo-cli -ac_name=HRK $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/huf b/src/fiat/huf index 336a75bb4..55a4f7c50 100755 --- a/src/fiat/huf +++ b/src/fiat/huf @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=HUF $1 $2 $3 $4 +./komodo-cli -ac_name=HUF $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/idr b/src/fiat/idr index 34b7a204c..62ce7968d 100755 --- a/src/fiat/idr +++ b/src/fiat/idr @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=IDR $1 $2 $3 $4 +./komodo-cli -ac_name=IDR $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/ils b/src/fiat/ils index c06588689..de1e552b8 100755 --- a/src/fiat/ils +++ b/src/fiat/ils @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=ILS $1 $2 $3 $4 +./komodo-cli -ac_name=ILS $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/inr b/src/fiat/inr index b4d230622..10ffc9d51 100755 --- a/src/fiat/inr +++ b/src/fiat/inr @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=INR $1 $2 $3 $4 +./komodo-cli -ac_name=INR $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/jpy b/src/fiat/jpy index 6d437f02b..5b8fd3768 100755 --- a/src/fiat/jpy +++ b/src/fiat/jpy @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=JPY $1 $2 $3 $4 +./komodo-cli -ac_name=JPY $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/jumblr b/src/fiat/jumblr index 24d332184..2969c5009 100755 --- a/src/fiat/jumblr +++ b/src/fiat/jumblr @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=JUMBLR $1 $2 $3 $4 +./komodo-cli -ac_name=JUMBLR $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/krw b/src/fiat/krw index 51b59dc12..7b895b1f4 100755 --- a/src/fiat/krw +++ b/src/fiat/krw @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=KRW $1 $2 $3 $4 +./komodo-cli -ac_name=KRW $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/kv b/src/fiat/kv index c735138e3..997fccb33 100755 --- a/src/fiat/kv +++ b/src/fiat/kv @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=KV $1 $2 $3 $4 +./komodo-cli -ac_name=KV $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/mgw b/src/fiat/mgw index d498ed85a..9afa86b7a 100755 --- a/src/fiat/mgw +++ b/src/fiat/mgw @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=MGW $1 $2 $3 $4 +./komodo-cli -ac_name=MGW $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/mvp b/src/fiat/mvp index 3bbe64bfb..998d700a3 100755 --- a/src/fiat/mvp +++ b/src/fiat/mvp @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=MVP $1 $2 $3 $4 +./komodo-cli -ac_name=MVP $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/mxn b/src/fiat/mxn index a4f119517..d5d8d97fb 100755 --- a/src/fiat/mxn +++ b/src/fiat/mxn @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=MXN $1 $2 $3 $4 +./komodo-cli -ac_name=MXN $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/myr b/src/fiat/myr index 5de0c80da..8c700a53c 100755 --- a/src/fiat/myr +++ b/src/fiat/myr @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=MYR $1 $2 $3 $4 +./komodo-cli -ac_name=MYR $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/nok b/src/fiat/nok index fb1a25430..e0e35b444 100755 --- a/src/fiat/nok +++ b/src/fiat/nok @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=NOK $1 $2 $3 $4 +./komodo-cli -ac_name=NOK $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/nzd b/src/fiat/nzd index af598570a..c9610b218 100755 --- a/src/fiat/nzd +++ b/src/fiat/nzd @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=NZD $1 $2 $3 $4 +./komodo-cli -ac_name=NZD $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/pangea b/src/fiat/pangea index de19a2d6d..9920189ea 100755 --- a/src/fiat/pangea +++ b/src/fiat/pangea @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=PANGEA $1 $2 $3 $4 +./komodo-cli -ac_name=PANGEA $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/php b/src/fiat/php index f333251fd..c22e73293 100755 --- a/src/fiat/php +++ b/src/fiat/php @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=PHP $1 $2 $3 $4 +./komodo-cli -ac_name=PHP $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/pln b/src/fiat/pln index 5fcc12ba4..6dfb0debb 100755 --- a/src/fiat/pln +++ b/src/fiat/pln @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=PLN $1 $2 $3 $4 +./komodo-cli -ac_name=PLN $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/revs b/src/fiat/revs index 5c8782ae5..b898eb5dc 100755 --- a/src/fiat/revs +++ b/src/fiat/revs @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=REVS $1 $2 $3 $4 +./komodo-cli -ac_name=REVS $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/ron b/src/fiat/ron index 3ea339896..0b2a6effd 100755 --- a/src/fiat/ron +++ b/src/fiat/ron @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=RON $1 $2 $3 $4 +./komodo-cli -ac_name=RON $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/rub b/src/fiat/rub index 367dbf46d..8d1575578 100755 --- a/src/fiat/rub +++ b/src/fiat/rub @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=RUB $1 $2 $3 $4 +./komodo-cli -ac_name=RUB $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/sek b/src/fiat/sek index 9fb37e674..25a14d414 100755 --- a/src/fiat/sek +++ b/src/fiat/sek @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=SEK $1 $2 $3 $4 +./komodo-cli -ac_name=SEK $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/sgd b/src/fiat/sgd index f9c75ade8..89a1bc5ae 100755 --- a/src/fiat/sgd +++ b/src/fiat/sgd @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=SGD $1 $2 $3 $4 +./komodo-cli -ac_name=SGD $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/shark b/src/fiat/shark index 4c25f6a7e..4bda53889 100755 --- a/src/fiat/shark +++ b/src/fiat/shark @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=SHARK $1 $2 $3 $4 +./komodo-cli -ac_name=SHARK $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/supernet b/src/fiat/supernet index 8afb833ca..d841ffa0e 100755 --- a/src/fiat/supernet +++ b/src/fiat/supernet @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=SUPERNET $1 $2 $3 $4 +./komodo-cli -ac_name=SUPERNET $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/thb b/src/fiat/thb index a5a7eb017..ed72913c1 100755 --- a/src/fiat/thb +++ b/src/fiat/thb @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=THB $1 $2 $3 $4 +./komodo-cli -ac_name=THB $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/try b/src/fiat/try index a06a2050d..dcfa574a6 100755 --- a/src/fiat/try +++ b/src/fiat/try @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=TRY $1 $2 $3 $4 +./komodo-cli -ac_name=TRY $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/usd b/src/fiat/usd index 12eb06e0d..81b9e16c6 100755 --- a/src/fiat/usd +++ b/src/fiat/usd @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=USD $1 $2 $3 $4 +./komodo-cli -ac_name=USD $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/wireless b/src/fiat/wireless index a4869b189..c6e092a41 100755 --- a/src/fiat/wireless +++ b/src/fiat/wireless @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=WIRELESS $1 $2 $3 $4 +./komodo-cli -ac_name=WIRELESS $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/zar b/src/fiat/zar index e5fa51785..a3dd891c0 100755 --- a/src/fiat/zar +++ b/src/fiat/zar @@ -1,2 +1,2 @@ #!/bin/bash -./komodo-cli -ac_name=ZAR $1 $2 $3 $4 +./komodo-cli -ac_name=ZAR $1 $2 $3 $4 $5 $6 From 36a759fc5ce9cf153661cbe553636df23510eb11 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 19:37:01 +0200 Subject: [PATCH 140/162] test --- src/komodo_kv.h | 14 ++++---------- src/wallet/rpcwallet.cpp | 7 +++++-- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index fede46e03..f4f312724 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -86,7 +86,7 @@ uint64_t komodo_kvfee(uint32_t flags,int32_t opretlen,int32_t keylen) void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) { static uint256 zeroes; - uint32_t flags; uint256 pubkey,refpubkey,sig; int32_t i,transferflag,hassig,coresize,haspubkey,height,kvheight; uint16_t keylen,valuesize,newflag = 0; uint8_t *key,*valueptr,valuebuf[IGUANA_MAXSCRIPTSIZE]; struct komodo_kv *ptr; char *transferpubstr,*tstr; uint64_t fee; + uint32_t flags; uint256 pubkey,refpubkey,sig; int32_t i,hassig,coresize,haspubkey,height,kvheight; uint16_t keylen,valuesize,newflag = 0; uint8_t *key,*valueptr,valuebuf[IGUANA_MAXSCRIPTSIZE]; struct komodo_kv *ptr; char *transferpubstr,*tstr; uint64_t fee; iguana_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen); iguana_rwnum(0,&opretbuf[3],sizeof(valuesize),&valuesize); iguana_rwnum(0,&opretbuf[5],sizeof(height),&height); @@ -125,7 +125,6 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) } portable_mutex_lock(&KOMODO_KV_mutex); HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); - transferflag = 0; if ( ptr != 0 ) { if ( (ptr->flags & KOMODO_KVPROTECTED) != 0 && memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) @@ -134,7 +133,8 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) transferpubstr = (char *)&valueptr[strlen(tstr)]; if ( strncmp(tstr,(char *)valueptr,strlen(tstr)) == 0 && is_hexstr(transferpubstr,0) == 64 ) { - transferflag = 1; + memcpy(&ptr->pubkey,&pubkey,sizeof(ptr->pubkey)); + ptr->height = height; printf("transfer.(%s) to [%s]\n",key,transferpubstr); for (i=0; i<32; i++) ((uint8_t *)&pubkey)[31-i] = _decode_hex(&transferpubstr[i*2]); @@ -144,19 +144,13 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) else if ( ptr == 0 ) { ptr = (struct komodo_kv *)calloc(1,sizeof(*ptr)); - memcpy(&ptr->pubkey,&pubkey,sizeof(ptr->pubkey)); ptr->key = (uint8_t *)calloc(1,keylen); ptr->keylen = keylen; memcpy(ptr->key,key,keylen); newflag = 1; HASH_ADD_KEYPTR(hh,KOMODO_KV,ptr->key,ptr->keylen,ptr); } - if ( transferflag != 0 ) - { - memcpy(&ptr->pubkey,&pubkey,sizeof(ptr->pubkey)); - ptr->height = height; - } - else if ( newflag != 0 || (ptr->flags & KOMODO_KVPROTECTED) == 0 ) + if ( newflag != 0 || (ptr->flags & KOMODO_KVPROTECTED) == 0 ) { if ( ptr->value != 0 ) free(ptr->value), ptr->value = 0; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ddb099453..4acdacea4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -544,10 +544,13 @@ Value kvupdate(const Array& params, bool fHelp) ret.push_back(Pair("error",(char *)"cant modify write once key without passphrase")); return ret; } - printf("calc sig for keylen.%d + valuesize.%d\n",keylen,valuesize); - sig = komodo_kvsig(keyvalue,keylen+valuesize,privkey); + sig = komodo_kvsig(keyvalue,keylen+refvaluesize,privkey); + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&sig)[i]); + printf(" sig for keylen.%d + valuesize.%d\n",keylen,refvaluesize); } } + printf("refvaluesize.%d tmpflags.%d\n",refvaluesize,tmpflags); ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); height = chainActive.Tip()->nHeight; if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) From a9d3adf5a49b2de8b9062dfec60bd7f0f3c60ae7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 19:42:51 +0200 Subject: [PATCH 141/162] test --- src/komodo_kv.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index f4f312724..166063a47 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -133,8 +133,6 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) transferpubstr = (char *)&valueptr[strlen(tstr)]; if ( strncmp(tstr,(char *)valueptr,strlen(tstr)) == 0 && is_hexstr(transferpubstr,0) == 64 ) { - memcpy(&ptr->pubkey,&pubkey,sizeof(ptr->pubkey)); - ptr->height = height; printf("transfer.(%s) to [%s]\n",key,transferpubstr); for (i=0; i<32; i++) ((uint8_t *)&pubkey)[31-i] = _decode_hex(&transferpubstr[i*2]); @@ -159,9 +157,10 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) ptr->value = (uint8_t *)calloc(1,valuesize); memcpy(ptr->value,valueptr,valuesize); } - ptr->height = height; - ptr->flags = flags; } + memcpy(&ptr->pubkey,&pubkey,sizeof(ptr->pubkey)); + ptr->height = height; + ptr->flags = flags; portable_mutex_unlock(&KOMODO_KV_mutex); } else printf("insufficient fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); } else printf("opretlen.%d mismatch keylen.%d valuesize.%d\n",opretlen,keylen,valuesize); From d5f1c653841a8ab2b75fa9ff85545a8cee5d8bec Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 19:47:33 +0200 Subject: [PATCH 142/162] test --- src/komodo_curve25519.h | 15 +++++++++------ src/wallet/rpcwallet.cpp | 10 +++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/komodo_curve25519.h b/src/komodo_curve25519.h index 7271e3741..8bca4e7fb 100644 --- a/src/komodo_curve25519.h +++ b/src/komodo_curve25519.h @@ -962,12 +962,15 @@ uint256 komodo_kvsig(uint8_t *buf,int32_t len,uint256 privkey) int32_t komodo_kvsigverify(uint8_t *buf,int32_t len,uint256 pubkey,uint256 sig) { - bits256 hash,checksig; - vcalc_sha256(0,hash.bytes,buf,len); - checksig = curve25519_shared(hash,*(bits256 *)&pubkey); - if ( memcmp(&checksig,&sig,sizeof(sig)) != 0 ) - return(-1); - else return(0); + bits256 hash,checksig; static uint256 zeroes; + if ( memcmp(&pubkey,&zeroes,sizeof(pubkey)) != 0 ) + { + vcalc_sha256(0,hash.bytes,buf,len); + checksig = curve25519_shared(hash,*(bits256 *)&pubkey); + if ( memcmp(&checksig,&sig,sizeof(sig)) != 0 ) + return(-1); + } + return(0); } #endif diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 4acdacea4..838c8a963 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -506,6 +506,7 @@ Value kvupdate(const Array& params, bool fHelp) haveprivkey = 0; memset(&sig,0,sizeof(sig)); memset(&privkey,0,sizeof(privkey)); + memset(&refprivkey,0,sizeof(refpubkey)); memset(&pubkey,0,sizeof(pubkey)); if ( (n= (int32_t)params.size()) >= 3 ) { @@ -544,13 +545,12 @@ Value kvupdate(const Array& params, bool fHelp) ret.push_back(Pair("error",(char *)"cant modify write once key without passphrase")); return ret; } - sig = komodo_kvsig(keyvalue,keylen+refvaluesize,privkey); - for (i=0; i<32; i++) - printf("%02x",((uint8_t *)&sig)[i]); - printf(" sig for keylen.%d + valuesize.%d\n",keylen,refvaluesize); } + sig = komodo_kvsig(keyvalue,keylen+refvaluesize,privkey); + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&sig)[i]); + printf(" sig for keylen.%d + valuesize.%d\n",keylen,refvaluesize); } - printf("refvaluesize.%d tmpflags.%d\n",refvaluesize,tmpflags); ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); height = chainActive.Tip()->nHeight; if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) From 3bd135000243ac52a5c297e2b254d657e04ae34f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 19:49:53 +0200 Subject: [PATCH 143/162] test --- src/rpcclient.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index 933b550a5..5b89b18c4 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -113,7 +113,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "notaries", 1 }, { "minerids", 1 }, { "kvsearch", 1 }, - //{ "kvupdate", 4 }, + { "kvupdate", 4 }, }; class CRPCConvertTable diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 838c8a963..9395ab64c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -506,7 +506,7 @@ Value kvupdate(const Array& params, bool fHelp) haveprivkey = 0; memset(&sig,0,sizeof(sig)); memset(&privkey,0,sizeof(privkey)); - memset(&refprivkey,0,sizeof(refpubkey)); + memset(&refpubkey,0,sizeof(refpubkey)); memset(&pubkey,0,sizeof(pubkey)); if ( (n= (int32_t)params.size()) >= 3 ) { From 66dc0c54b422f2f0aaa589eeee8632f4a49cc0f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 20:03:15 +0200 Subject: [PATCH 144/162] test --- src/komodo_curve25519.h | 29 ++++++++++++++++++++++++----- src/wallet/rpcwallet.cpp | 28 +++++++++++++--------------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/komodo_curve25519.h b/src/komodo_curve25519.h index 8bca4e7fb..906c343a5 100644 --- a/src/komodo_curve25519.h +++ b/src/komodo_curve25519.h @@ -950,23 +950,42 @@ uint256 komodo_kvprivkey(uint256 *pubkeyp,char *passphrase) return(privkey); } -uint256 komodo_kvsig(uint8_t *buf,int32_t len,uint256 privkey) +uint256 komodo_kvsig(uint8_t *buf,int32_t len,uint256 _privkey) { - bits256 sig,hash,otherpub; uint256 usig; + bits256 sig,hash,otherpub,checksig,pubkey,privkey; uint256 usig; + memcpy(&privkey,&_privkey,sizeof(privkey)); vcalc_sha256(0,hash.bytes,buf,len); otherpub = curve25519(hash,curve25519_basepoint9()); - sig = curve25519_shared(*(bits256 *)&privkey,otherpub); + pubkey = curve25519(privkey,curve25519_basepoint9()); + sig = curve25519_shared(privkey,otherpub); + checksig = curve25519_shared(hash,pubkey); + int32_t i; for (i=0; i "); + for (i=0; i "); + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&checksig)[i]); + printf(" checksig\n"); memcpy(&usig,&sig,sizeof(usig)); return(usig); } -int32_t komodo_kvsigverify(uint8_t *buf,int32_t len,uint256 pubkey,uint256 sig) +int32_t komodo_kvsigverify(uint8_t *buf,int32_t len,uint256 _pubkey,uint256 sig) { - bits256 hash,checksig; static uint256 zeroes; + bits256 hash,checksig,pubkey; static uint256 zeroes; + memcpy(&pubkey,&_pubkey,sizeof(pubkey)); if ( memcmp(&pubkey,&zeroes,sizeof(pubkey)) != 0 ) { vcalc_sha256(0,hash.bytes,buf,len); checksig = curve25519_shared(hash,*(bits256 *)&pubkey); + int32_t i; for (i=0; i "); + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&checksig)[i]); + printf(" sig\n"); if ( memcmp(&checksig,&sig,sizeof(sig)) != 0 ) return(-1); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 9395ab64c..4414452a8 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -514,18 +514,16 @@ Value kvupdate(const Array& params, bool fHelp) printf("flags.%d (%s) n.%d\n",flags,params[2].get_str().c_str(),n); } else flags = 0; if ( n >= 4 ) - { - privkey = komodo_kvprivkey(&pubkey,(char *)params[3].get_str().c_str()); - haveprivkey = 1; - flags |= 1; - for (i=0; i<32; i++) - printf("%02x",((uint8_t *)&privkey)[i]); - printf(" priv, "); - for (i=0; i<32; i++) - printf("%02x",((uint8_t *)&pubkey)[i]); - printf(" pubkey, privkey derived from (%s)\n",(char *)params[3].get_str().c_str()); + privkey = komodo_kvprivkey(&pubkey,(char *)(n >= 4 ? params[3].get_str().c_str() : "password")); + haveprivkey = 1; + flags |= 1; + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&privkey)[i]); + printf(" priv, "); + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&pubkey)[i]); + printf(" pubkey, privkey derived from (%s)\n",(char *)params[3].get_str().c_str()); //printf("flags.%d (%s)\n",flags,params[2].get_str().c_str()); - } LOCK2(cs_main, pwalletMain->cs_wallet); if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) { @@ -546,11 +544,11 @@ Value kvupdate(const Array& params, bool fHelp) return ret; } } - sig = komodo_kvsig(keyvalue,keylen+refvaluesize,privkey); - for (i=0; i<32; i++) - printf("%02x",((uint8_t *)&sig)[i]); - printf(" sig for keylen.%d + valuesize.%d\n",keylen,refvaluesize); } + sig = komodo_kvsig(keyvalue,keylen+refvaluesize,privkey); + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&sig)[i]); + printf(" sig for keylen.%d + valuesize.%d\n",keylen,refvaluesize); ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); height = chainActive.Tip()->nHeight; if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) From 33cdc2e49c049d21c6048540f09d61a27755d483 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 20:14:08 +0200 Subject: [PATCH 145/162] test --- src/komodo_curve25519.h | 2 +- src/komodo_kv.h | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_curve25519.h b/src/komodo_curve25519.h index 906c343a5..4c11d74d5 100644 --- a/src/komodo_curve25519.h +++ b/src/komodo_curve25519.h @@ -962,7 +962,7 @@ uint256 komodo_kvsig(uint8_t *buf,int32_t len,uint256 _privkey) int32_t i; for (i=0; i "); - for (i=0; i "); for (i=0; i<32; i++) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 166063a47..b054adc5a 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -116,7 +116,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) { if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) { - if ( memcmp(&pubkey,&refpubkey,sizeof(pubkey)) != 0 || komodo_kvsigverify(opretbuf+13,coresize-13,refpubkey,sig) < 0 ) + if ( komodo_kvsigverify(opretbuf+13,coresize-13,refpubkey,sig) < 0 ) { printf("komodo_kvsigverify error [%d]\n",coresize-13); return; @@ -162,7 +162,8 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) ptr->height = height; ptr->flags = flags; portable_mutex_unlock(&KOMODO_KV_mutex); - } else printf("insufficient fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); + } else printf("size mismatch %d vs %d\n",opretlen,coresize); + } else printf("insufficient fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); } else printf("opretlen.%d mismatch keylen.%d valuesize.%d\n",opretlen,keylen,valuesize); } From 161001e50aecf3fa8ffc1185dee3b772cebcdece Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 20:15:34 +0200 Subject: [PATCH 146/162] test --- src/komodo_kv.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index b054adc5a..116714878 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -164,7 +164,6 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) portable_mutex_unlock(&KOMODO_KV_mutex); } else printf("size mismatch %d vs %d\n",opretlen,coresize); } else printf("insufficient fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); - } else printf("opretlen.%d mismatch keylen.%d valuesize.%d\n",opretlen,keylen,valuesize); } #endif From 467666f5b27044f54f8ad9b96570090ec2723159 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 20:20:43 +0200 Subject: [PATCH 147/162] test --- src/komodo_curve25519.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/komodo_curve25519.h b/src/komodo_curve25519.h index 4c11d74d5..70f58137b 100644 --- a/src/komodo_curve25519.h +++ b/src/komodo_curve25519.h @@ -963,11 +963,11 @@ uint256 komodo_kvsig(uint8_t *buf,int32_t len,uint256 _privkey) printf("%02x",buf[i]); printf(" -> "); for (i=0; i<32; i++) - printf("%02x",((uint8_t *)&sig)[i]); + printf("%02x",((uint8_t *)&hash)[i]); printf(" -> "); for (i=0; i<32; i++) - printf("%02x",((uint8_t *)&checksig)[i]); - printf(" checksig\n"); + printf("%02x",((uint8_t *)&pubkey)[i]); + printf(" pubkey\n"); memcpy(&usig,&sig,sizeof(usig)); return(usig); } @@ -979,13 +979,16 @@ int32_t komodo_kvsigverify(uint8_t *buf,int32_t len,uint256 _pubkey,uint256 sig) if ( memcmp(&pubkey,&zeroes,sizeof(pubkey)) != 0 ) { vcalc_sha256(0,hash.bytes,buf,len); - checksig = curve25519_shared(hash,*(bits256 *)&pubkey); + checksig = curve25519_shared(hash,pubkey); int32_t i; for (i=0; i "); for (i=0; i<32; i++) - printf("%02x",((uint8_t *)&checksig)[i]); - printf(" sig\n"); + printf("%02x",((uint8_t *)&hash)[i]); + printf(" -> "); + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&pubkey)[i]); + printf(" pubkey\n"); if ( memcmp(&checksig,&sig,sizeof(sig)) != 0 ) return(-1); } From 557917929127202f41b708c9af1e0227fbe1e4bc Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 20:31:26 +0200 Subject: [PATCH 148/162] test --- src/komodo_curve25519.h | 2 +- src/wallet/rpcwallet.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_curve25519.h b/src/komodo_curve25519.h index 70f58137b..897cb53c1 100644 --- a/src/komodo_curve25519.h +++ b/src/komodo_curve25519.h @@ -963,7 +963,7 @@ uint256 komodo_kvsig(uint8_t *buf,int32_t len,uint256 _privkey) printf("%02x",buf[i]); printf(" -> "); for (i=0; i<32; i++) - printf("%02x",((uint8_t *)&hash)[i]); + printf("%02x",((uint8_t *)&privkey)[i]); printf(" -> "); for (i=0; i<32; i++) printf("%02x",((uint8_t *)&pubkey)[i]); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 4414452a8..896ca7f4e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -498,7 +498,7 @@ Value kvupdate(const Array& params, bool fHelp) { static uint256 zeroes; CWalletTx wtx; Object ret; - uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t i,coresize,haveprivkey,duration,opretlen,height; uint16_t keylen,valuesize=0,refvaluesize=0; uint8_t *key,*value=0; uint32_t flags,tmpflags,n; struct komodo_kv *ptr; uint64_t fee; uint256 privkey,pubkey,refpubkey,sig; + uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t i,coresize,haveprivkey,duration,opretlen,height; uint16_t keylen=0,valuesize=0,refvaluesize=0; uint8_t *key,*value=0; uint32_t flags,tmpflags,n; struct komodo_kv *ptr; uint64_t fee; uint256 privkey,pubkey,refpubkey,sig; if (fHelp || params.size() < 3 ) throw runtime_error("kvupdate key value flags/passphrase"); if (!EnsureWalletIsAvailable(fHelp)) @@ -544,8 +544,9 @@ Value kvupdate(const Array& params, bool fHelp) return ret; } } + if ( keylen+refvaluesize <= sizeof(keyvalue) ) + sig = komodo_kvsig(keyvalue,keylen+refvaluesize,privkey); } - sig = komodo_kvsig(keyvalue,keylen+refvaluesize,privkey); for (i=0; i<32; i++) printf("%02x",((uint8_t *)&sig)[i]); printf(" sig for keylen.%d + valuesize.%d\n",keylen,refvaluesize); From a663f2365b74fb2952e3e839b0bae57be646dcd7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 20:49:08 +0200 Subject: [PATCH 149/162] test --- src/komodo_curve25519.h | 2 +- src/komodo_kv.h | 77 +++++++++++++++++++++++------------------ 2 files changed, 44 insertions(+), 35 deletions(-) diff --git a/src/komodo_curve25519.h b/src/komodo_curve25519.h index 897cb53c1..cc2ce34e4 100644 --- a/src/komodo_curve25519.h +++ b/src/komodo_curve25519.h @@ -988,7 +988,7 @@ int32_t komodo_kvsigverify(uint8_t *buf,int32_t len,uint256 _pubkey,uint256 sig) printf(" -> "); for (i=0; i<32; i++) printf("%02x",((uint8_t *)&pubkey)[i]); - printf(" pubkey\n"); + printf(" verify pubkey\n"); if ( memcmp(&checksig,&sig,sizeof(sig)) != 0 ) return(-1); } diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 116714878..786266938 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -16,40 +16,6 @@ #ifndef H_KOMODOKV_H #define H_KOMODOKV_H -int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen) -{ - struct komodo_kv *ptr; int32_t duration,retval = -1; - *heightp = -1; - *flagsp = 0; - memset(pubkeyp,0,sizeof(*pubkeyp)); - portable_mutex_lock(&KOMODO_KV_mutex); - HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); - if ( ptr != 0 ) - { - duration = ((ptr->flags >> 2) + 1) * KOMODO_KVDURATION; - //printf("duration.%d flags.%d current.%d ht.%d keylen.%d valuesize.%d\n",duration,ptr->flags,current_height,ptr->height,ptr->keylen,ptr->valuesize); - if ( current_height > (ptr->height + duration) ) - { - HASH_DELETE(hh,KOMODO_KV,ptr); - if ( ptr->value != 0 ) - free(ptr->value); - if ( ptr->key != 0 ) - free(ptr->key); - free(ptr); - } - else - { - *heightp = ptr->height; - *flagsp = ptr->flags; - memcpy(pubkeyp,&ptr->pubkey,sizeof(*pubkeyp)); - if ( (retval= ptr->valuesize) != 0 ) - memcpy(value,ptr->value,retval); - } - } - portable_mutex_unlock(&KOMODO_KV_mutex); - return(retval); -} - int32_t komodo_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint16_t valuesize) { if ( refvalue == 0 && value == 0 ) @@ -83,6 +49,43 @@ uint64_t komodo_kvfee(uint32_t flags,int32_t opretlen,int32_t keylen) return(fee); } +int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen) +{ + struct komodo_kv *ptr; int32_t duration,retval = -1; + *heightp = -1; + *flagsp = 0; + memset(pubkeyp,0,sizeof(*pubkeyp)); + portable_mutex_lock(&KOMODO_KV_mutex); + HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); + if ( ptr != 0 ) + { + duration = komodo_kvduration(ptr->flags); + //printf("duration.%d flags.%d current.%d ht.%d keylen.%d valuesize.%d\n",duration,ptr->flags,current_height,ptr->height,ptr->keylen,ptr->valuesize); + if ( current_height > (ptr->height + duration) ) + { + HASH_DELETE(hh,KOMODO_KV,ptr); + if ( ptr->value != 0 ) + free(ptr->value); + if ( ptr->key != 0 ) + free(ptr->key); + free(ptr); + } + else + { + *heightp = ptr->height; + *flagsp = ptr->flags; + int32_t i; for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&ptr->pubkey)[31-i]); + printf(" ptr->pubkey\n"); + memcpy(pubkeyp,&ptr->pubkey,sizeof(*pubkeyp)); + if ( (retval= ptr->valuesize) != 0 ) + memcpy(value,ptr->value,retval); + } + } + portable_mutex_unlock(&KOMODO_KV_mutex); + return(retval); +} + void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) { static uint256 zeroes; @@ -158,6 +161,12 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) memcpy(ptr->value,valueptr,valuesize); } } + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&ptr->pubkey)[i]); + printf(" <- "); + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&pubkey)[i]); + printf(" new pubkey\n"); memcpy(&ptr->pubkey,&pubkey,sizeof(ptr->pubkey)); ptr->height = height; ptr->flags = flags; From 70b7f3eae549b50c0d793af1ab795001689f732f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 20:55:35 +0200 Subject: [PATCH 150/162] test --- src/komodo_curve25519.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/komodo_curve25519.h b/src/komodo_curve25519.h index cc2ce34e4..ce27ac143 100644 --- a/src/komodo_curve25519.h +++ b/src/komodo_curve25519.h @@ -989,8 +989,15 @@ int32_t komodo_kvsigverify(uint8_t *buf,int32_t len,uint256 _pubkey,uint256 sig) for (i=0; i<32; i++) printf("%02x",((uint8_t *)&pubkey)[i]); printf(" verify pubkey\n"); + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&sig)[i]); + printf(" sig vs"); + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&checksig)[i]); + printf(" checksig\n"); if ( memcmp(&checksig,&sig,sizeof(sig)) != 0 ) return(-1); + else printf("VALIDATED\n"); } return(0); } From a87d62aefdc9fa88e114d483de46206f844f4b35 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 20:58:38 +0200 Subject: [PATCH 151/162] test --- src/komodo_kv.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 786266938..246f7bdf0 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -89,7 +89,7 @@ int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) { static uint256 zeroes; - uint32_t flags; uint256 pubkey,refpubkey,sig; int32_t i,hassig,coresize,haspubkey,height,kvheight; uint16_t keylen,valuesize,newflag = 0; uint8_t *key,*valueptr,valuebuf[IGUANA_MAXSCRIPTSIZE]; struct komodo_kv *ptr; char *transferpubstr,*tstr; uint64_t fee; + uint32_t flags; uint256 pubkey,refpubkey,sig; int32_t i,refvaluesize,hassig,coresize,haspubkey,height,kvheight; uint16_t keylen,valuesize,newflag = 0; uint8_t *key,*valueptr,valuebuf[IGUANA_MAXSCRIPTSIZE]; struct komodo_kv *ptr; char *transferpubstr,*tstr; uint64_t fee; iguana_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen); iguana_rwnum(0,&opretbuf[3],sizeof(valuesize),&valuesize); iguana_rwnum(0,&opretbuf[5],sizeof(height),&height); @@ -115,11 +115,11 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) for (i=0; i<32; i++) ((uint8_t *)&sig)[i] = opretbuf[coresize+sizeof(uint256)+i]; } - if ( komodo_kvsearch((uint256 *)&refpubkey,height,&flags,&kvheight,valuebuf,key,keylen) >= 0 ) + if ( (refvaluesize= komodo_kvsearch((uint256 *)&refpubkey,height,&flags,&kvheight,valuebuf,key,keylen)) >= 0 ) { if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) { - if ( komodo_kvsigverify(opretbuf+13,coresize-13,refpubkey,sig) < 0 ) + if ( komodo_kvsigverify(valuebuf,keylen+refvaluesize,refpubkey,sig) < 0 ) { printf("komodo_kvsigverify error [%d]\n",coresize-13); return; From 31c5d00228ea3bb18183a5131ffddd06651d866b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 21:02:51 +0200 Subject: [PATCH 152/162] test --- src/komodo_kv.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 246f7bdf0..a238e2e8e 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -75,7 +75,10 @@ int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp *heightp = ptr->height; *flagsp = ptr->flags; int32_t i; for (i=0; i<32; i++) + { printf("%02x",((uint8_t *)&ptr->pubkey)[31-i]); + ((uint8_t *)pubkeyp)[i] = ((uint8_t *)&ptr->pubkey)[31-i]; + } printf(" ptr->pubkey\n"); memcpy(pubkeyp,&ptr->pubkey,sizeof(*pubkeyp)); if ( (retval= ptr->valuesize) != 0 ) From 178eeb4566aa9f4966c680add65c55af5e2f8eae Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 21:06:55 +0200 Subject: [PATCH 153/162] test --- src/komodo_kv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index a238e2e8e..0c4708b60 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -118,7 +118,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) for (i=0; i<32; i++) ((uint8_t *)&sig)[i] = opretbuf[coresize+sizeof(uint256)+i]; } - if ( (refvaluesize= komodo_kvsearch((uint256 *)&refpubkey,height,&flags,&kvheight,valuebuf,key,keylen)) >= 0 ) + if ( (refvaluesize= komodo_kvsearch((uint256 *)&refpubkey,height,&flags,&kvheight,&valuebuf[keylen],key,keylen)) >= 0 ) { if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) { From e2843ac1fb80fad8a23b725a7651aa2d3ce141ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 21:38:28 +0200 Subject: [PATCH 154/162] test --- src/komodo_kv.h | 1 + src/wallet/rpcwallet.cpp | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 0c4708b60..baa3a470d 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -118,6 +118,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) for (i=0; i<32; i++) ((uint8_t *)&sig)[i] = opretbuf[coresize+sizeof(uint256)+i]; } + memcpy(keybuf,key,keylen); if ( (refvaluesize= komodo_kvsearch((uint256 *)&refpubkey,height,&flags,&kvheight,&valuebuf[keylen],key,keylen)) >= 0 ) { if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 896ca7f4e..808c80b4e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -545,7 +545,12 @@ Value kvupdate(const Array& params, bool fHelp) } } if ( keylen+refvaluesize <= sizeof(keyvalue) ) + { sig = komodo_kvsig(keyvalue,keylen+refvaluesize,privkey); + if ( komodo_kvsigverify(keyvalue,keylen+refvaluesize,refpubkey,sig) < 0 ) + printf("VERIFY ERROR\n"); + else printf("verified immediately\n"); + } } for (i=0; i<32; i++) printf("%02x",((uint8_t *)&sig)[i]); From b884794730024cbdcfbdbde605a134da573a722e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 21:40:03 +0200 Subject: [PATCH 155/162] test --- src/komodo_kv.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index baa3a470d..4ae4819aa 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -92,7 +92,7 @@ int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) { static uint256 zeroes; - uint32_t flags; uint256 pubkey,refpubkey,sig; int32_t i,refvaluesize,hassig,coresize,haspubkey,height,kvheight; uint16_t keylen,valuesize,newflag = 0; uint8_t *key,*valueptr,valuebuf[IGUANA_MAXSCRIPTSIZE]; struct komodo_kv *ptr; char *transferpubstr,*tstr; uint64_t fee; + uint32_t flags; uint256 pubkey,refpubkey,sig; int32_t i,refvaluesize,hassig,coresize,haspubkey,height,kvheight; uint16_t keylen,valuesize,newflag = 0; uint8_t *key,*valueptr,keyvalue[IGUANA_MAXSCRIPTSIZE]; struct komodo_kv *ptr; char *transferpubstr,*tstr; uint64_t fee; iguana_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen); iguana_rwnum(0,&opretbuf[3],sizeof(valuesize),&valuesize); iguana_rwnum(0,&opretbuf[5],sizeof(height),&height); @@ -118,12 +118,12 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) for (i=0; i<32; i++) ((uint8_t *)&sig)[i] = opretbuf[coresize+sizeof(uint256)+i]; } - memcpy(keybuf,key,keylen); - if ( (refvaluesize= komodo_kvsearch((uint256 *)&refpubkey,height,&flags,&kvheight,&valuebuf[keylen],key,keylen)) >= 0 ) + memcpy(keyvalue,key,keylen); + if ( (refvaluesize= komodo_kvsearch((uint256 *)&refpubkey,height,&flags,&kvheight,&keyvalue[keylen],key,keylen)) >= 0 ) { if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) { - if ( komodo_kvsigverify(valuebuf,keylen+refvaluesize,refpubkey,sig) < 0 ) + if ( komodo_kvsigverify(keyvalue,keylen+refvaluesize,refpubkey,sig) < 0 ) { printf("komodo_kvsigverify error [%d]\n",coresize-13); return; From 7112e5a7da0ecdbaf52439ef1370d6527a6ffba0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 21:48:18 +0200 Subject: [PATCH 156/162] test --- src/wallet/rpcwallet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 808c80b4e..aeac661a7 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -493,6 +493,7 @@ uint64_t komodo_kvfee(uint32_t flags,int32_t opretlen,int32_t keylen); uint256 komodo_kvsig(uint8_t *buf,int32_t len,uint256 privkey); int32_t komodo_kvduration(uint32_t flags); uint256 komodo_kvprivkey(uint256 *pubkeyp,char *passphrase); +int32_t komodo_kvsigverify(uint8_t *buf,int32_t len,uint256 _pubkey,uint256 sig); Value kvupdate(const Array& params, bool fHelp) { From ebeae1ebae09aac5fa91a4bf3998438ba8963255 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 21:56:13 +0200 Subject: [PATCH 157/162] test --- src/komodo_curve25519.h | 10 +++++----- src/komodo_kv.h | 8 ++++---- src/wallet/rpcwallet.cpp | 19 +++++++++++-------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/komodo_curve25519.h b/src/komodo_curve25519.h index ce27ac143..6a0ee3fa6 100644 --- a/src/komodo_curve25519.h +++ b/src/komodo_curve25519.h @@ -959,7 +959,7 @@ uint256 komodo_kvsig(uint8_t *buf,int32_t len,uint256 _privkey) pubkey = curve25519(privkey,curve25519_basepoint9()); sig = curve25519_shared(privkey,otherpub); checksig = curve25519_shared(hash,pubkey); - int32_t i; for (i=0; i "); for (i=0; i<32; i++) @@ -967,7 +967,7 @@ uint256 komodo_kvsig(uint8_t *buf,int32_t len,uint256 _privkey) printf(" -> "); for (i=0; i<32; i++) printf("%02x",((uint8_t *)&pubkey)[i]); - printf(" pubkey\n"); + printf(" pubkey\n");*/ memcpy(&usig,&sig,sizeof(usig)); return(usig); } @@ -980,7 +980,7 @@ int32_t komodo_kvsigverify(uint8_t *buf,int32_t len,uint256 _pubkey,uint256 sig) { vcalc_sha256(0,hash.bytes,buf,len); checksig = curve25519_shared(hash,pubkey); - int32_t i; for (i=0; i "); for (i=0; i<32; i++) @@ -994,10 +994,10 @@ int32_t komodo_kvsigverify(uint8_t *buf,int32_t len,uint256 _pubkey,uint256 sig) printf(" sig vs"); for (i=0; i<32; i++) printf("%02x",((uint8_t *)&checksig)[i]); - printf(" checksig\n"); + printf(" checksig\n");*/ if ( memcmp(&checksig,&sig,sizeof(sig)) != 0 ) return(-1); - else printf("VALIDATED\n"); + //else printf("VALIDATED\n"); } return(0); } diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 4ae4819aa..78b756618 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -76,10 +76,10 @@ int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp *flagsp = ptr->flags; int32_t i; for (i=0; i<32; i++) { - printf("%02x",((uint8_t *)&ptr->pubkey)[31-i]); + //printf("%02x",((uint8_t *)&ptr->pubkey)[31-i]); ((uint8_t *)pubkeyp)[i] = ((uint8_t *)&ptr->pubkey)[31-i]; } - printf(" ptr->pubkey\n"); + //printf(" ptr->pubkey\n"); memcpy(pubkeyp,&ptr->pubkey,sizeof(*pubkeyp)); if ( (retval= ptr->valuesize) != 0 ) memcpy(value,ptr->value,retval); @@ -165,12 +165,12 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) memcpy(ptr->value,valueptr,valuesize); } } - for (i=0; i<32; i++) + /*for (i=0; i<32; i++) printf("%02x",((uint8_t *)&ptr->pubkey)[i]); printf(" <- "); for (i=0; i<32; i++) printf("%02x",((uint8_t *)&pubkey)[i]); - printf(" new pubkey\n"); + printf(" new pubkey\n");*/ memcpy(&ptr->pubkey,&pubkey,sizeof(ptr->pubkey)); ptr->height = height; ptr->flags = flags; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index aeac661a7..151f2c835 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -512,19 +512,19 @@ Value kvupdate(const Array& params, bool fHelp) if ( (n= (int32_t)params.size()) >= 3 ) { flags = atoi(params[2].get_str().c_str()); - printf("flags.%d (%s) n.%d\n",flags,params[2].get_str().c_str(),n); + //printf("flags.%d (%s) n.%d\n",flags,params[2].get_str().c_str(),n); } else flags = 0; if ( n >= 4 ) privkey = komodo_kvprivkey(&pubkey,(char *)(n >= 4 ? params[3].get_str().c_str() : "password")); haveprivkey = 1; flags |= 1; - for (i=0; i<32; i++) + /*for (i=0; i<32; i++) printf("%02x",((uint8_t *)&privkey)[i]); printf(" priv, "); for (i=0; i<32; i++) printf("%02x",((uint8_t *)&pubkey)[i]); printf(" pubkey, privkey derived from (%s)\n",(char *)params[3].get_str().c_str()); - //printf("flags.%d (%s)\n",flags,params[2].get_str().c_str()); + */ LOCK2(cs_main, pwalletMain->cs_wallet); if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) { @@ -539,7 +539,7 @@ Value kvupdate(const Array& params, bool fHelp) { if ( (tmpflags & KOMODO_KVPROTECTED) != 0 ) { - if ( refpubkey != pubkey ) + if ( memcmp(&refpubkey,&pubkey,sizeof(refpubkey)) != 0 ) { ret.push_back(Pair("error",(char *)"cant modify write once key without passphrase")); return ret; @@ -549,13 +549,16 @@ Value kvupdate(const Array& params, bool fHelp) { sig = komodo_kvsig(keyvalue,keylen+refvaluesize,privkey); if ( komodo_kvsigverify(keyvalue,keylen+refvaluesize,refpubkey,sig) < 0 ) + { + ret.push_back(Pair("error",(char *)"error verifying sig, passphrase is probably wrong")); printf("VERIFY ERROR\n"); - else printf("verified immediately\n"); + return ret; + } // else printf("verified immediately\n"); } } - for (i=0; i<32; i++) - printf("%02x",((uint8_t *)&sig)[i]); - printf(" sig for keylen.%d + valuesize.%d\n",keylen,refvaluesize); + //for (i=0; i<32; i++) + // printf("%02x",((uint8_t *)&sig)[i]); + //printf(" sig for keylen.%d + valuesize.%d\n",keylen,refvaluesize); ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); height = chainActive.Tip()->nHeight; if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) From 618dcd5b0229ffa47bf771e917cf2ed85ca59525 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 22:25:41 +0200 Subject: [PATCH 158/162] test --- src/komodo_kv.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 78b756618..99183d5f0 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -125,7 +125,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) { if ( komodo_kvsigverify(keyvalue,keylen+refvaluesize,refpubkey,sig) < 0 ) { - printf("komodo_kvsigverify error [%d]\n",coresize-13); + //printf("komodo_kvsigverify error [%d]\n",coresize-13); return; } } @@ -138,9 +138,9 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) { tstr = (char *)"transfer:"; transferpubstr = (char *)&valueptr[strlen(tstr)]; + printf("transfer.(%s) to [%s]? ishex.%d\n",key,transferpubstr,is_hexstr(transferpubstr,0)); if ( strncmp(tstr,(char *)valueptr,strlen(tstr)) == 0 && is_hexstr(transferpubstr,0) == 64 ) { - printf("transfer.(%s) to [%s]\n",key,transferpubstr); for (i=0; i<32; i++) ((uint8_t *)&pubkey)[31-i] = _decode_hex(&transferpubstr[i*2]); } From 190833b941589c0b5a160bbdea9804b1d23946d2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 22:31:16 +0200 Subject: [PATCH 159/162] test --- src/komodo_kv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 99183d5f0..4dd6eae4f 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -134,7 +134,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); if ( ptr != 0 ) { - if ( (ptr->flags & KOMODO_KVPROTECTED) != 0 && memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) + if ( (ptr->flags & KOMODO_KVPROTECTED) != 0 ) { tstr = (char *)"transfer:"; transferpubstr = (char *)&valueptr[strlen(tstr)]; From 83af8cbf35611275d2e51ddaad73d8802ebec8d5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 22:57:49 +0200 Subject: [PATCH 160/162] test --- src/komodo_kv.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 4dd6eae4f..6961bd8e0 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -134,7 +134,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); if ( ptr != 0 ) { - if ( (ptr->flags & KOMODO_KVPROTECTED) != 0 ) + //if ( (ptr->flags & KOMODO_KVPROTECTED) != 0 ) { tstr = (char *)"transfer:"; transferpubstr = (char *)&valueptr[strlen(tstr)]; @@ -173,7 +173,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) printf(" new pubkey\n");*/ memcpy(&ptr->pubkey,&pubkey,sizeof(ptr->pubkey)); ptr->height = height; - ptr->flags = flags; + ptr->flags = flags | 1; portable_mutex_unlock(&KOMODO_KV_mutex); } else printf("size mismatch %d vs %d\n",opretlen,coresize); } else printf("insufficient fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); From fdab5c731099959bae39a1daf20a5f1c87feea50 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jan 2017 23:04:23 +0200 Subject: [PATCH 161/162] test --- src/komodo_kv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 6961bd8e0..30d584634 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -138,9 +138,9 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) { tstr = (char *)"transfer:"; transferpubstr = (char *)&valueptr[strlen(tstr)]; - printf("transfer.(%s) to [%s]? ishex.%d\n",key,transferpubstr,is_hexstr(transferpubstr,0)); if ( strncmp(tstr,(char *)valueptr,strlen(tstr)) == 0 && is_hexstr(transferpubstr,0) == 64 ) { + printf("transfer.(%s) to [%s]? ishex.%d\n",key,transferpubstr,is_hexstr(transferpubstr,0)); for (i=0; i<32; i++) ((uint8_t *)&pubkey)[31-i] = _decode_hex(&transferpubstr[i*2]); } From 579d23744253921fc683d2c65099b76dc3797da4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Jan 2017 15:01:44 +0200 Subject: [PATCH 162/162] test --- src/komodo_kv.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 30d584634..07adadf2b 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -42,9 +42,11 @@ int32_t komodo_kvduration(uint32_t flags) uint64_t komodo_kvfee(uint32_t flags,int32_t opretlen,int32_t keylen) { - int32_t numdays; uint64_t fee; + int32_t numdays,k; uint64_t fee; + if ( (k= keylen) > 32 ) + k = 32; numdays = komodo_kvnumdays(flags); - if ( (fee= (numdays*(opretlen * opretlen / keylen))) < 100000 ) + if ( (fee= (numdays*(opretlen * opretlen / k))) < 100000 ) fee = 100000; return(fee); }