@@ -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 &
|
||||
|
||||
@@ -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\"}"
|
||||
|
||||
@@ -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
|
||||
|
||||
2
src/fiat/kv
Executable file
2
src/fiat/kv
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
./komodo-cli -ac_name=KV $1 $2 $3 $4
|
||||
@@ -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);
|
||||
@@ -251,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);
|
||||
}
|
||||
|
||||
@@ -671,17 +671,60 @@ 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]; 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 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));
|
||||
@@ -689,7 +732,54 @@ 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' && 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 )
|
||||
{
|
||||
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);
|
||||
}
|
||||
else if ( opretbuf[0] == 'D' )
|
||||
{
|
||||
tokomodo = 0;
|
||||
if ( opretlen == 38 ) // any KMD tx
|
||||
|
||||
@@ -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;
|
||||
pthread_mutex_t KOMODO_KV_mutex;
|
||||
@@ -37,6 +37,12 @@
|
||||
#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]; };
|
||||
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[]; };
|
||||
|
||||
@@ -396,6 +396,10 @@ Value gettxoutsetinfo(const Array& params, bool fHelp)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#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);
|
||||
uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume);
|
||||
@@ -404,6 +408,40 @@ 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);
|
||||
|
||||
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;
|
||||
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("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(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);
|
||||
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));
|
||||
} 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)
|
||||
{
|
||||
|
||||
@@ -112,6 +112,8 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
||||
{ "paxpending", 0 },
|
||||
{ "notaries", 1 },
|
||||
{ "minerids", 1 },
|
||||
{ "kvsearch", 1 },
|
||||
{ "kvupdate", 3 },
|
||||
};
|
||||
|
||||
class CRPCConvertTable
|
||||
|
||||
@@ -305,6 +305,8 @@ static const CRPCCommand vRPCCommands[] =
|
||||
{ "blockchain", "paxprices", &paxprices, true },
|
||||
{ "blockchain", "notaries", ¬aries, true },
|
||||
{ "blockchain", "minerids", &minerids, true },
|
||||
{ "blockchain", "kvsearch", &kvsearch, true },
|
||||
{ "blockchain", "kvupdate", &kvupdate, true },
|
||||
|
||||
/* Mining */
|
||||
{ "mining", "getblocktemplate", &getblocktemplate, true },
|
||||
|
||||
@@ -247,6 +247,8 @@ 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 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);
|
||||
|
||||
@@ -404,9 +404,9 @@ static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtr
|
||||
for (i=0; i<opretlen; i++)
|
||||
{
|
||||
ptr[i] = opretbuf[i];
|
||||
printf("%02x",ptr[i]);
|
||||
//printf("%02x",ptr[i]);
|
||||
}
|
||||
printf(" opretbuf[%d]\n",opretlen);
|
||||
//printf(" opretbuf[%d]\n",opretlen);
|
||||
CRecipient opret = { opretpubkey, opretValue, false };
|
||||
vecSend.push_back(opret);
|
||||
}
|
||||
@@ -475,6 +475,10 @@ Value sendtoaddress(const Array& params, bool fHelp)
|
||||
return wtx.GetHash().GetHex();
|
||||
}
|
||||
|
||||
#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);
|
||||
#define CRYPTO777_KMDADDR "RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA"
|
||||
@@ -483,6 +487,8 @@ 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_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint16_t valuesize);
|
||||
|
||||
Value paxdeposit(const Array& params, bool fHelp)
|
||||
{
|
||||
@@ -557,6 +563,71 @@ Value paxwithdraw(const Array& params, bool fHelp)
|
||||
return wtx.GetHash().GetHex();
|
||||
}
|
||||
|
||||
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;
|
||||
if (fHelp || params.size() < 2 )
|
||||
throw runtime_error("kvupdate key value [flags]");
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return 0;
|
||||
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;
|
||||
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());
|
||||
}
|
||||
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;
|
||||
}
|
||||
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));
|
||||
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);
|
||||
if ( (opretlen= komodo_opreturnscript(opretbuf,'K',keyvalue,sizeof(flags)+sizeof(height)+sizeof(uint16_t)*2+keylen+valuesize)) == 40 )
|
||||
opretlen++;
|
||||
//for (i=0; i<opretlen; i++)
|
||||
// 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= ((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");
|
||||
SendMoney(destaddress.Get(),10000,false,wtx,opretbuf,opretlen,fee);
|
||||
ret.push_back(Pair("txid",wtx.GetHash().GetHex()));
|
||||
} else ret.push_back(Pair("error",(char *)"null key"));
|
||||
return ret;
|
||||
}
|
||||
|
||||
Value listaddressgroupings(const Array& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
|
||||
Reference in New Issue
Block a user