From 57abdbaf6c41760ee8c9d53b79e3a142e4e390d8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 09:38:47 -0300 Subject: [PATCH] test --- src/komodo.h | 2 -- src/komodo_gateway.h | 16 ++++++++++++++-- src/komodo_pax.h | 29 +++++++++++++++++++++-------- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 9ea4fb301..47a143286 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -37,9 +37,7 @@ char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771; #include "cJSON.c" #include "komodo_bitcoind.h" #include "komodo_interest.h" -#ifdef KOMODO_PAX #include "komodo_pax.h" -#endif #include "komodo_notary.h" #include "komodo_gateway.h" diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 91e66da66..6b3288867 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -19,7 +19,8 @@ void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t vout,int32_t numvouts,uint64_t value,uint8_t *script,int32_t len) { - const char *typestr = "unknown"; + uint8_t rmd160[20],addrtype,shortflag; char base[4],coinaddr[64]; int64_t fiatoshis; const char *typestr; + typestr = "unknown"; if ( script[0] == 0x6a ) { if ( len >= 32*2+4 && strcmp((char *)&script[2+32*2+4],"KMD") == 0 ) @@ -27,7 +28,18 @@ void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t v if ( script[2] == 'P' ) typestr = "pricefeed"; else if ( script[2] == 'D' ) - typestr = "deposit"; + { + if ( len == 36 ) + { + PAX_pubkey(0,&script[3],&addrtype,rmd160,base,&shortflag,&fiatoshis); + if ( fiatoshis < 0 ) + fiatoshis = -fiatoshis; + bitcoin_address(coinaddr,addrtype,rmd160,20); + printf("DEPOSIT %.8f %s -> %s\n",dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); + // verify price value for fiatoshis of base + typestr = "deposit"; + } + } } else if ( numvouts > 13 ) typestr = "ratify"; diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 5c8cdf88d..d73fad325 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -153,14 +153,27 @@ int32_t komodo_pax_opreturn(uint8_t *opret,int32_t maxsize) return(val32); }*/ -int32_t PAX_pubkey(uint8_t *pubkey33,uint8_t addrtype,uint8_t rmd160[20],char fiat[4],uint8_t shortflag,int32_t fiatoshis) +int32_t PAX_pubkey(int32_t rwflag,uint8_t *pubkey33,uint8_t *addrtypep,uint8_t rmd160[20],char fiat[4],uint8_t *shortflagp,int64_t *fiatoshisp) { - memset(pubkey33,0,33); - pubkey33[0] = 0x02 | (shortflag != 0); - memcpy(&pubkey33[1],fiat,3); - iguana_rwnum(1,&pubkey33[4],sizeof(fiatoshis),(void *)&fiatoshis); - pubkey33[12] = addrtype; - memcpy(&pubkey33[13],rmd160,20); + if ( rwflag != 0 ) + { + memset(pubkey33,0,33); + pubkey33[0] = 0x02 | (*shortflagp != 0); + memcpy(&pubkey33[1],fiat,3); + iguana_rwnum(rwflag,&pubkey33[4],sizeof(*fiatoshisp),(void *)fiatoshisp); + pubkey33[12] = *addrtypep; + memcpy(&pubkey33[13],rmd160,20); + } + else + { + *shortflagp = (pubkey33[0] == 0x03); + memcpy(fiat,&pubkey33[1],4); + iguana_rwnum(rwflag,&pubkey33[4],sizeof(*fiatoshisp),(void *)fiatoshisp); + if ( *shortflagp != 0 ) + *fiatoshisp = -(*fiatoshisp); + *addrtypep = pubkey33[12]; + memcpy(rmd160,&pubkey33[13],20); + } } double PAX_val(uint32_t pval,int32_t baseid) @@ -298,7 +311,7 @@ uint64_t PAX_fiatdest(char *fiatbuf,char *destaddr,uint8_t pubkey33[33],char *co if ( bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr) == 20 ) { // put JSON into fiatbuf enough to replicate/validate - PAX_pubkey(pubkey33,addrtype,rmd160,base,shortflag,fiatoshis); + PAX_pubkey(1,pubkey33,&addrtype,rmd160,base,&shortflag,&fiatoshis); bitcoin_address(destaddr,KOMODO_PUBTYPE,pubkey33,33); } return(komodoshis);