This commit is contained in:
jl777
2016-10-26 10:42:29 -03:00
parent 9dea9602b6
commit 33935bd0f0
4 changed files with 18 additions and 11 deletions

View File

@@ -108,12 +108,14 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
}
else if ( func == 'O' )
{
uint16_t olen; uint8_t opret[10000];
uint16_t olen; uint64_t ovalue; uint8_t opret[10000];
if ( fread(&olen,1,sizeof(olen),fp) != sizeof(olen) )
errs++;
if ( fread(&ovalue,1,sizeof(ovalue),fp) != sizeof(ovalue) )
errs++;
if ( fread(opret,1,olen,fp) != olen )
errs++;
komodo_opreturn(ht,opret,olen);
komodo_opreturn(ht,ovalue,opret,olen);
}
else if ( func == 'D' )
{
@@ -159,9 +161,11 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
fputc('O',fp);
if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
errs++;
if ( fwrite(&value,1,sizeof(value),fp) != sizeof(value) )
errs++;
if ( fwrite(opretbuf,1,opretlen,fp) != opretlen )
errs++;
komodo_opreturn(height,opretbuf,opretlen);
komodo_opreturn(height,value,opretbuf,opretlen);
}
else if ( notarypubs != 0 && numnotaries > 0 )
{

View File

@@ -17,9 +17,9 @@
// paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse
// need to save most processed block in other chain(s)
const char *komodo_opreturn(int32_t height,uint8_t *opretbuf,int32_t opretlen)
const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen)
{
uint8_t rmd160[20],addrtype,shortflag; char base[4],coinaddr[64]; int64_t fiatoshis; const char *typestr = "unknown";
uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; char base[4],coinaddr[64],destaddr[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown";
if ( opretbuf[0] == 'D' )
{
if ( opretlen == 34 )
@@ -28,8 +28,12 @@ const char *komodo_opreturn(int32_t height,uint8_t *opretbuf,int32_t opretlen)
if ( fiatoshis < 0 )
fiatoshis = -fiatoshis;
bitcoin_address(coinaddr,addrtype,rmd160,20);
checktoshis = PAX_fiatdest(destaddr,pubkey33,coinaddr,height,base,fiatoshis);
printf("DEPOSIT %.8f %c%s -> %s\n",dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr);
// verify price value for fiatoshis of base
for (i=0; i<33; i++)
printf("%02x",pubkey33[i]);
printf(" checkpubkey check %.8f v %.8f dest.(%s)\n",dstr(checktoshis),dstr(value),destaddr);
typestr = "deposit";
}
}
@@ -54,7 +58,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t v
else
{
printf("offset.%d opretlen.%d\n",offset,opretlen);
typestr = komodo_opreturn(height,&script[offset],opretlen);
typestr = komodo_opreturn(height,value,&script[offset],opretlen);
komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,&script[offset],opretlen);
}
}

View File

@@ -307,7 +307,7 @@ void komodo_paxpricefeed(int32_t height,uint8_t *pricefeed,int32_t opretlen)
printf("komodo_paxpricefeed vout OP_RETURN.%d prices numpvals.%d opretlen.%d\n",height,numpvals,opretlen);
}
uint64_t PAX_fiatdest(char *fiatbuf,char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *origbase,int64_t fiatoshis)
uint64_t PAX_fiatdest(char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *origbase,int64_t fiatoshis)
{
uint8_t shortflag = 0; char base[4]; int32_t i; uint8_t addrtype,rmd160[20]; uint64_t komodoshis = 0;
fiatbuf[0] = 0;
@@ -321,7 +321,6 @@ uint64_t PAX_fiatdest(char *fiatbuf,char *destaddr,uint8_t pubkey33[33],char *co
komodoshis = komodo_paxprice(height,base,(char *)"KMD",(uint64_t)fiatoshis);
if ( bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr) == 20 )
{
// put JSON into fiatbuf enough to replicate/validate
PAX_pubkey(1,pubkey33,&addrtype,rmd160,base,&shortflag,&fiatoshis);
bitcoin_address(destaddr,KOMODO_PUBTYPE,pubkey33,33);
}

View File

@@ -466,7 +466,7 @@ Value sendtoaddress(const Array& params, bool fHelp)
return wtx.GetHash().GetHex();
}
uint64_t PAX_fiatdest(char *fiatbuf,char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *base,int64_t fiatoshis);
uint64_t PAX_fiatdest(char *destaddr,uint8_t pubkey33[33],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"
@@ -484,8 +484,8 @@ Value paxdeposit(const Array& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
int64_t fiatoshis = atof(params[1].get_str().c_str()) * COIN;
std::string base = params[2].get_str();
std::string dest; char fiatbuf[1024];
komodoshis = PAX_fiatdest(fiatbuf,destaddr,pubkey33,(char *)params[0].get_str().c_str(),chainActive.Tip()->nHeight,(char *)base.c_str(),fiatoshis);
std::string dest;
komodoshis = PAX_fiatdest(destaddr,pubkey33,(char *)params[0].get_str().c_str(),chainActive.Tip()->nHeight,(char *)base.c_str(),fiatoshis);
dest.append(destaddr);
CBitcoinAddress destaddress(CRYPTO777_KMDADDR);
if (!destaddress.IsValid())