|
|
@ -124,7 +124,12 @@ int32_t kmd_transactionvin(struct iguana_info *coin,bits256 spendtxid,int32_t vi |
|
|
|
void kmd_transactionvout(struct iguana_info *coin,struct kmd_transactionhh *ptr,int32_t vout,uint64_t amount,uint8_t type_rmd160[21],bits256 spendtxid,int32_t spendvini) |
|
|
|
{ |
|
|
|
struct kmd_addresshh *addr; struct kmd_transaction *tx = 0; |
|
|
|
//printf("ht.%d VOUT %d %.8f\n",ptr->tx->height,vout,dstr(amount));
|
|
|
|
{ |
|
|
|
char coinaddr[64],str[65]; |
|
|
|
bitcoin_address(coinaddr,type_rmd160[0],&type_rmd160[1],20); |
|
|
|
if ( strcmp(coinaddr,"RCsKEQ3r5Xxw4ZtK4CH9VzvfGpTFMdPpsh") == 0 ) |
|
|
|
printf("%s ht.%d %s VOUT %d %.8f\n",coinaddr,ptr->tx->height,bits256_str(str,ptr->tx->txid),vout,dstr(amount)); |
|
|
|
} |
|
|
|
if ( vout < ptr->numvouts && (tx= ptr->tx) != 0 ) |
|
|
|
{ |
|
|
|
tx->vouts[vout].spendtxid = spendtxid; |
|
|
@ -308,6 +313,22 @@ cJSON *kmd_unspentjson(struct kmd_transaction *tx,int32_t vout) |
|
|
|
return(item); |
|
|
|
} |
|
|
|
|
|
|
|
cJSON *kmd_spentjson(struct kmd_transaction *tx,int32_t vout,struct kmd_transactionhh *spent) |
|
|
|
{ |
|
|
|
cJSON *item = cJSON_CreateObject(); |
|
|
|
jaddstr(item,"type","sent"); |
|
|
|
jaddbits256(item,"txid",tx->txid); |
|
|
|
jaddnum(item,"vout",vout); |
|
|
|
jaddnum(item,"amount",dstr(tx->vouts[vout].amount)); |
|
|
|
jaddbits256(item,"spentdtxid",tx->vouts[vout].spendtxid); |
|
|
|
jaddnum(item,"vin",tx->vouts[vout].spendvini); |
|
|
|
if ( spent != 0 ) |
|
|
|
{ |
|
|
|
jadd(item,"paid",kmd_transactionjson(spent,"paid")); |
|
|
|
} |
|
|
|
return(item); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t kmd_height(struct iguana_info *coin) |
|
|
|
{ |
|
|
|
char params[64],*curlstr; cJSON *curljson; int32_t height = 0; |
|
|
@ -325,40 +346,6 @@ int32_t kmd_height(struct iguana_info *coin) |
|
|
|
return(height); |
|
|
|
} |
|
|
|
|
|
|
|
cJSON *kmd_listtransactions(struct iguana_info *coin,char *coinaddr,int32_t count,int32_t skip) |
|
|
|
{ |
|
|
|
struct kmd_addresshh *addr; struct kmd_transactionhh *ptr,*spent,*prev=0; uint8_t type_rmd160[21]; int32_t i,counter=0; cJSON *array = cJSON_CreateArray(); |
|
|
|
//if ( (height= kmd_height(coin)) > coin->kmd_height+KMD_EXPLORER_LAG )
|
|
|
|
// return(cJSON_Parse("[]"));
|
|
|
|
bitcoin_addr2rmd160(&type_rmd160[0],&type_rmd160[1],coinaddr); |
|
|
|
if ( (addr= _kmd_address(coin,type_rmd160)) != 0 && (ptr= addr->prev) != 0 && ptr->tx != 0 ) |
|
|
|
{ |
|
|
|
while ( ptr != 0 ) |
|
|
|
{ |
|
|
|
if ( counter >= skip && counter < count+skip ) |
|
|
|
jaddi(array,kmd_transactionjson(ptr,"received")); |
|
|
|
if ( ++counter >= count+skip ) |
|
|
|
break; |
|
|
|
for (i=0; i<ptr->numvouts; i++) |
|
|
|
{ |
|
|
|
if ( memcmp(ptr->tx->vouts[i].type_rmd160,type_rmd160,21) == 0 && (spent= ptr->ptrs[(i<<1)+1]) != 0 ) |
|
|
|
{ |
|
|
|
if ( counter >= skip && counter < count+skip ) |
|
|
|
jaddi(array,kmd_transactionjson(spent,"sent")); |
|
|
|
if ( ++counter >= count+skip ) |
|
|
|
break; |
|
|
|
if ( ptr->ptrs[i << 1] != 0 ) |
|
|
|
prev = ptr->ptrs[i << 1]; |
|
|
|
} |
|
|
|
} |
|
|
|
if ( counter >= count+skip ) |
|
|
|
break; |
|
|
|
ptr = prev; |
|
|
|
} |
|
|
|
} |
|
|
|
return(array); |
|
|
|
} |
|
|
|
|
|
|
|
cJSON *kmd_gettxin(struct iguana_info *coin,bits256 txid,int32_t vout) |
|
|
|
{ |
|
|
|
struct kmd_transactionhh *ptr,*spendptr; struct kmd_transaction *tx; cJSON *retjson; |
|
|
@ -383,9 +370,11 @@ cJSON *kmd_gettxin(struct iguana_info *coin,bits256 txid,int32_t vout) |
|
|
|
return(cJSON_Parse("{\"error\":\"txid not found\"}")); |
|
|
|
} |
|
|
|
|
|
|
|
cJSON *kmd_listaddress(struct iguana_info *coin,char *coinaddr,int32_t mode) |
|
|
|
cJSON *kmd_listaddress(struct iguana_info *coin,char *coinaddr,int32_t mode,cJSON *array,int32_t fulltx) |
|
|
|
{ |
|
|
|
struct kmd_addresshh *addr; struct kmd_transactionhh *ptr,*spent,*prev=0; uint8_t type_rmd160[21]; int32_t i; cJSON *array = cJSON_CreateArray(); |
|
|
|
struct kmd_addresshh *addr; struct kmd_transactionhh *ptr,*spent,*prev=0; uint8_t type_rmd160[21]; int32_t i,flag = 0; |
|
|
|
if ( array == 0 ) |
|
|
|
array = cJSON_CreateArray(); |
|
|
|
/*if ( time(NULL) > coin->kmd_lasttime+30 )
|
|
|
|
{ |
|
|
|
coin->kmd_lasttime = (uint32_t)time(NULL); |
|
|
@ -411,7 +400,38 @@ cJSON *kmd_listaddress(struct iguana_info *coin,char *coinaddr,int32_t mode) |
|
|
|
//if ( strcmp("RFpYbieWuKm2ZsTaKeWkrrEdeSkVzhqX8x",coinaddr) == 0 )
|
|
|
|
// printf("mode.%d [%d] %s ht.%d amount %.8f spent.%p\n",mode,coin->kmd_height,coinaddr,ptr->tx->height,dstr(ptr->tx->vouts[i].amount),spent);
|
|
|
|
if ( (mode == 0 && spent == 0) || (mode == 1 && spent != 0) || mode == 2 ) |
|
|
|
jaddi(array,kmd_unspentjson(ptr->tx,i)); |
|
|
|
{ |
|
|
|
if ( fulltx == 0 ) |
|
|
|
{ |
|
|
|
if ( mode == 0 ) |
|
|
|
jaddi(array,kmd_unspentjson(ptr->tx,i)); |
|
|
|
else if ( mode == 1 ) |
|
|
|
jaddi(array,kmd_spentjson(ptr->tx,i,spent)); |
|
|
|
else if ( mode == 2 ) |
|
|
|
{ |
|
|
|
if ( spent != 0 ) |
|
|
|
jaddi(array,kmd_spentjson(ptr->tx,i,spent)); |
|
|
|
else jaddi(array,kmd_unspentjson(ptr->tx,i)); |
|
|
|
} |
|
|
|
} |
|
|
|
else if ( flag == 0 ) |
|
|
|
{ |
|
|
|
if ( mode == 0 ) |
|
|
|
jaddi(array,kmd_transactionjson(ptr,"received")); |
|
|
|
else if ( mode == 1 ) |
|
|
|
{ |
|
|
|
jaddi(array,kmd_transactionjson(ptr,"received")); |
|
|
|
jaddi(array,kmd_transactionjson(spent,"sent")); |
|
|
|
} |
|
|
|
else if ( mode == 2 ) |
|
|
|
{ |
|
|
|
if ( spent != 0 ) |
|
|
|
jaddi(array,kmd_transactionjson(ptr,"spent")); |
|
|
|
else jaddi(array,kmd_transactionjson(ptr,"received")); |
|
|
|
} |
|
|
|
flag = 1; |
|
|
|
} |
|
|
|
} |
|
|
|
if ( ptr->ptrs[i<<1] != 0 ) |
|
|
|
{ |
|
|
|
if ( prev == 0 ) |
|
|
@ -429,12 +449,24 @@ cJSON *kmd_listaddress(struct iguana_info *coin,char *coinaddr,int32_t mode) |
|
|
|
|
|
|
|
cJSON *kmd_listunspent(struct iguana_info *coin,char *coinaddr) |
|
|
|
{ |
|
|
|
return(kmd_listaddress(coin,coinaddr,0)); |
|
|
|
return(kmd_listaddress(coin,coinaddr,0,0,0)); |
|
|
|
} |
|
|
|
|
|
|
|
cJSON *kmd_listspent(struct iguana_info *coin,char *coinaddr) |
|
|
|
{ |
|
|
|
return(kmd_listaddress(coin,coinaddr,1)); |
|
|
|
return(kmd_listaddress(coin,coinaddr,1,0,0)); |
|
|
|
} |
|
|
|
|
|
|
|
cJSON *kmd_listtransactions(struct iguana_info *coin,char *coinaddr,int32_t count,int32_t skip) |
|
|
|
{ |
|
|
|
cJSON *array = cJSON_CreateArray(); |
|
|
|
//if ( (height= kmd_height(coin)) > coin->kmd_height+KMD_EXPLORER_LAG )
|
|
|
|
// return(cJSON_Parse("[]"));
|
|
|
|
if ( count == 0 ) |
|
|
|
count = 100; |
|
|
|
array = kmd_listaddress(coin,coinaddr,0,0,0); |
|
|
|
array = kmd_listaddress(coin,coinaddr,1,array,0); |
|
|
|
return(array); |
|
|
|
} |
|
|
|
|
|
|
|
int64_t _kmd_getbalance(struct iguana_info *coin,char *coinaddr,uint64_t *receivedp,uint64_t *sentp) |
|
|
@ -442,7 +474,7 @@ int64_t _kmd_getbalance(struct iguana_info *coin,char *coinaddr,uint64_t *receiv |
|
|
|
int32_t iter,i,n; cJSON *array,*item; uint64_t value; |
|
|
|
for (iter=1; iter<=2; iter++) |
|
|
|
{ |
|
|
|
if ( (array= kmd_listaddress(coin,coinaddr,iter)) != 0 ) |
|
|
|
if ( (array= kmd_listaddress(coin,coinaddr,iter,0,0)) != 0 ) |
|
|
|
{ |
|
|
|
if ( (n= cJSON_GetArraySize(array)) > 0 ) |
|
|
|
{ |
|
|
|