|
|
@ -124,6 +124,7 @@ 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; |
|
|
|
if ( 0 ) |
|
|
|
{ |
|
|
|
char coinaddr[64],str[65]; |
|
|
|
bitcoin_address(coinaddr,type_rmd160[0],&type_rmd160[1],20); |
|
|
@ -304,9 +305,9 @@ cJSON *kmd_transactionjson(int32_t height,struct kmd_transactionhh *ptr,char *ty |
|
|
|
return(obj); |
|
|
|
} |
|
|
|
|
|
|
|
cJSON *kmd_unspentjson(struct iguana_info *coin,int32_t height,struct kmd_transaction *tx,int32_t vout) |
|
|
|
cJSON *kmd_unspentjson(struct supernet_info *myinfo,struct iguana_info *coin,int32_t height,struct kmd_transaction *tx,int32_t vout,int32_t is_listunspent) |
|
|
|
{ |
|
|
|
cJSON *item = cJSON_CreateObject(); |
|
|
|
char *script; cJSON *sobj,*txout,*item = cJSON_CreateObject(); |
|
|
|
jaddstr(item,"type","received"); |
|
|
|
jaddnum(item,"height",tx->height); |
|
|
|
jaddnum(item,"timestamp",tx->timestamp); |
|
|
@ -315,6 +316,17 @@ cJSON *kmd_unspentjson(struct iguana_info *coin,int32_t height,struct kmd_transa |
|
|
|
jaddnum(item,"amount",dstr(tx->vouts[vout].amount)); |
|
|
|
if ( strcmp(coin->symbol,"KMD") == 0 ) |
|
|
|
jaddnum(item,"interest",dstr(_iguana_interest((uint32_t)time(NULL),coin->longestchain,tx->timestamp,tx->vouts[vout].amount))); |
|
|
|
if ( is_listunspent != 0 ) |
|
|
|
{ |
|
|
|
//char str[65]; printf("get spendscriptstr for %s/v%d\n",bits256_str(str,tx->txid),vout);
|
|
|
|
if ( (txout= dpow_gettxout(myinfo,coin,tx->txid,vout)) != 0 ) |
|
|
|
{ |
|
|
|
//printf("got.(%s)\n",jprint(txout,0));
|
|
|
|
if ( (sobj= jobj(txout,"scriptPubKey")) != 0 && (script= jstr(sobj,"hex")) != 0 ) |
|
|
|
jaddstr(item,"scriptPubKey",script); |
|
|
|
free_json(txout); |
|
|
|
} |
|
|
|
} |
|
|
|
return(item); |
|
|
|
} |
|
|
|
|
|
|
@ -378,7 +390,7 @@ 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 *array) |
|
|
|
cJSON *kmd_listaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,int32_t mode,cJSON *array) |
|
|
|
{ |
|
|
|
struct kmd_addresshh *addr; struct kmd_transactionhh *ptr=0,*spent,*prev=0; uint8_t type_rmd160[21]; int32_t i; |
|
|
|
if ( array == 0 ) |
|
|
@ -412,14 +424,14 @@ cJSON *kmd_listaddress(struct iguana_info *coin,char *coinaddr,int32_t mode,cJSO |
|
|
|
//if ( fulltx == 0 )
|
|
|
|
{ |
|
|
|
if ( mode == 0 ) |
|
|
|
jaddi(array,kmd_unspentjson(coin,coin->kmd_height,ptr->tx,i)); |
|
|
|
jaddi(array,kmd_unspentjson(myinfo,coin,coin->kmd_height,ptr->tx,i,1)); |
|
|
|
else if ( mode == 1 ) |
|
|
|
jaddi(array,kmd_spentjson(coin->kmd_height,ptr->tx,i,spent)); |
|
|
|
else if ( mode == 2 ) |
|
|
|
{ |
|
|
|
if ( spent != 0 ) |
|
|
|
jaddi(array,kmd_spentjson(coin->kmd_height,ptr->tx,i,spent)); |
|
|
|
else jaddi(array,kmd_unspentjson(coin,coin->kmd_height,ptr->tx,i)); |
|
|
|
else jaddi(array,kmd_unspentjson(myinfo,coin,coin->kmd_height,ptr->tx,i,0)); |
|
|
|
} |
|
|
|
} |
|
|
|
/*else if ( flag == 0 )
|
|
|
@ -455,34 +467,37 @@ cJSON *kmd_listaddress(struct iguana_info *coin,char *coinaddr,int32_t mode,cJSO |
|
|
|
return(array); |
|
|
|
} |
|
|
|
|
|
|
|
cJSON *kmd_listunspent(struct iguana_info *coin,char *coinaddr) |
|
|
|
cJSON *kmd_listunspent(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr) |
|
|
|
{ |
|
|
|
return(kmd_listaddress(coin,coinaddr,0,0)); |
|
|
|
cJSON *retjson; |
|
|
|
retjson = kmd_listaddress(myinfo,coin,coinaddr,0,0); |
|
|
|
//printf("KMD utxos.(%s)\n",jprint(retjson,0));
|
|
|
|
return(retjson); |
|
|
|
} |
|
|
|
|
|
|
|
cJSON *kmd_listspent(struct iguana_info *coin,char *coinaddr) |
|
|
|
cJSON *kmd_listspent(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr) |
|
|
|
{ |
|
|
|
return(kmd_listaddress(coin,coinaddr,1,0)); |
|
|
|
return(kmd_listaddress(myinfo,coin,coinaddr,1,0)); |
|
|
|
} |
|
|
|
|
|
|
|
cJSON *kmd_listtransactions(struct iguana_info *coin,char *coinaddr,int32_t count,int32_t skip) |
|
|
|
cJSON *kmd_listtransactions(struct supernet_info *myinfo,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); |
|
|
|
array = kmd_listaddress(coin,coinaddr,1,array); |
|
|
|
array = kmd_listaddress(myinfo,coin,coinaddr,0,0); |
|
|
|
array = kmd_listaddress(myinfo,coin,coinaddr,1,array); |
|
|
|
return(array); |
|
|
|
} |
|
|
|
|
|
|
|
int64_t _kmd_getbalance(struct iguana_info *coin,char *coinaddr,uint64_t *receivedp,uint64_t *sentp,uint64_t *interestp) |
|
|
|
int64_t _kmd_getbalance(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,uint64_t *receivedp,uint64_t *sentp,uint64_t *interestp) |
|
|
|
{ |
|
|
|
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)) != 0 ) |
|
|
|
if ( (array= kmd_listaddress(myinfo,coin,coinaddr,iter,0)) != 0 ) |
|
|
|
{ |
|
|
|
if ( (n= cJSON_GetArraySize(array)) > 0 ) |
|
|
|
{ |
|
|
@ -505,7 +520,7 @@ int64_t _kmd_getbalance(struct iguana_info *coin,char *coinaddr,uint64_t *receiv |
|
|
|
return(*receivedp - *sentp); |
|
|
|
} |
|
|
|
|
|
|
|
cJSON *kmd_getbalance(struct iguana_info *coin,char *coinaddr) |
|
|
|
cJSON *kmd_getbalance(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr) |
|
|
|
{ |
|
|
|
cJSON *retjson; double netbalance=0.,fbalance; uint64_t interest,i,s,r,sent=0,received=0; int64_t balance=0; struct kmd_addresshh *addr,*tmp; char address[64]; int32_t height = coin->kmd_height+1; |
|
|
|
retjson = cJSON_CreateObject(); |
|
|
@ -517,7 +532,7 @@ cJSON *kmd_getbalance(struct iguana_info *coin,char *coinaddr) |
|
|
|
{ |
|
|
|
bitcoin_address(address,addr->type_rmd160[0],&addr->type_rmd160[1],20); |
|
|
|
s = r = i = 0; |
|
|
|
balance += _kmd_getbalance(coin,address,&r,&s,&i); |
|
|
|
balance += _kmd_getbalance(myinfo,coin,address,&r,&s,&i); |
|
|
|
netbalance += dstr(r); |
|
|
|
netbalance -= dstr(s); |
|
|
|
if ( (r - s) > 100000*SATOSHIDEN ) |
|
|
@ -531,7 +546,7 @@ cJSON *kmd_getbalance(struct iguana_info *coin,char *coinaddr) |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
balance = _kmd_getbalance(coin,coinaddr,&received,&sent,&interest); |
|
|
|
balance = _kmd_getbalance(myinfo,coin,coinaddr,&received,&sent,&interest); |
|
|
|
netbalance = dstr(balance); |
|
|
|
} |
|
|
|
jaddstr(retjson,"result","success"); |
|
|
|