From 4ee2db4aab760d320e29ac54d6d253322881ae13 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 8 Jul 2016 11:11:19 -0300 Subject: [PATCH] test --- iguana/iguana_unspents.c | 62 ++++++++++++++++++++++++++++++++++++---- iguana/tests/firstheight | 1 + includes/iguana_funcs.h | 1 + 3 files changed, 59 insertions(+), 5 deletions(-) create mode 100755 iguana/tests/firstheight diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index 93bdfef47..33f6b587c 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -113,12 +113,62 @@ cJSON *ramchain_unspentjson(struct iguana_unspent *up,uint32_t unspentind) return(item); } -cJSON *ramchain_spentjson(struct iguana_info *coin,int32_t spentheight,int32_t hdrsi,int32_t unspentind) +cJSON *ramchain_spentjson(struct iguana_info *coin,int32_t spentheight,int32_t hdrsi,int32_t unspentind,bits256 txid,int32_t vout,int64_t uvalue) { - char coinaddr[64]; int64_t total = 0; cJSON *item = cJSON_CreateObject(); - coinaddr[0] = 0; - jaddstr(item,"destaddr",coinaddr); - jaddnum(item,"total",dstr(total)); + char coinaddr[64]; bits256 hash2,*X; struct iguana_txid T,*tx,*spentT,*spent_tx; struct iguana_bundle *bp; int32_t j,i; struct iguana_block *block; int64_t total = 0; struct iguana_unspent *U,*u; struct iguana_pkhash *P; struct iguana_spend *S,*s; struct iguana_ramchaindata *rdata; cJSON *addrs,*item,*voutobj; + item = cJSON_CreateObject(); + hash2 = iguana_blockhash(coin,spentheight); + if ( (block= iguana_blockfind("spent",coin,hash2)) != 0 && (bp= coin->bundles[spentheight/coin->chain->bundlesize]) != 0 && (rdata= bp->ramchain.H.data) != 0 ) + { + X = RAMCHAIN_PTR(rdata,Xoffset); + S = RAMCHAIN_PTR(rdata,Soffset); + U = RAMCHAIN_PTR(rdata,Uoffset); + P = RAMCHAIN_PTR(rdata,Poffset); + spentT = RAMCHAIN_PTR(rdata,Toffset); + for (i=0; iRO.txn_count; i++) + { + if ( (tx= iguana_blocktx(coin,&T,block,i)) != 0 ) + { + // struct iguana_txid { bits256 txid; uint32_t txidind:29,firstvout:28,firstvin:28,bundlei:11,locktime,version,timestamp,extraoffset; uint16_t numvouts,numvins; } __attribute__((packed)); + // struct iguana_spend { uint64_t scriptpos:48,scriptlen:16; uint32_t spendtxidind,sequenceid; int16_t prevout; uint16_t fileid:15,external:1; } __attribute__((packed)); // numsigs:4,numpubkeys:4,p2sh:1,sighash:4 + s = &S[tx->firstvin]; + for (j=0; jnumvins; j++,s++) + { + if ( s->prevout == vout ) + { + if ( s->external != 0 ) + { + if ( bits256_cmp(X[s->spendtxidind],txid) != 0 ) + continue; + } + else + { + spent_tx = &spentT[s->spendtxidind]; + if ( bits256_cmp(spent_tx->txid,txid) != 0 ) + continue; + } + jaddbits256(item,"spentfrom",tx->txid); + jaddnum(item,"vin",j); + u = &U[tx->firstvout]; + addrs = cJSON_CreateArray(); + for (j=0; jnumvouts; j++,u++) + { + voutobj = cJSON_CreateObject(); + bitcoin_address(coinaddr,iguana_addrtype(coin,u->type),P[u->pkind].rmd160,sizeof(P[u->pkind].rmd160)); + jaddnum(voutobj,coinaddr,dstr(u->value)); + jaddi(addrs,voutobj); + total += u->value; + } + jadd(item,"vouts",addrs); + jaddnum(item,"total",dstr(total)); + jaddnum(item,"ratio",dstr(uvalue) / dstr(total)); + return(item); + } + } + } + } + } + jaddstr(item,"error","couldnt find spent info"); return(item); } @@ -162,6 +212,8 @@ cJSON *iguana_unspentjson(struct supernet_info *myinfo,struct iguana_info *coin, { jadd(item,"spent",ramchain_unspentjson(up,unspentind)); jaddnum(item,"spentheight",spentheight); + jadd(item,"dest",ramchain_spentjson(coin,spentheight,hdrsi,unspentind,T[up->txidind].txid,up->vout,up->value)); + } else jadd(item,"unspent",ramchain_unspentjson(up,unspentind)); return(item); } diff --git a/iguana/tests/firstheight b/iguana/tests/firstheight new file mode 100755 index 000000000..d5b181d7c --- /dev/null +++ b/iguana/tests/firstheight @@ -0,0 +1 @@ +curl --url "http://127.0.0.1:7778" --data "{\"timeout\":20000,\"agent\":\"basilisk\",\"method\":\"balances\",\"vals\":{\"minconf\":1,\"history\":3,\"firstheight\":1181452}}" diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index 77cd23786..629374d00 100755 --- a/includes/iguana_funcs.h +++ b/includes/iguana_funcs.h @@ -417,6 +417,7 @@ int64_t iguana_addressreceived(struct supernet_info *myinfo,struct iguana_info * cJSON *iguana_walletjson(struct supernet_info *myinfo); int32_t iguana_payloadupdate(struct supernet_info *myinfo,struct iguana_info *coin,char *retstr,struct iguana_waddress *waddr,char *account); int32_t bitcoin_MofNspendscript(uint8_t p2sh_rmd160[20],uint8_t *script,int32_t n,const struct vin_info *vp); +struct iguana_txid *iguana_blocktx(struct iguana_info *coin,struct iguana_txid *tx,struct iguana_block *block,int32_t i); cJSON *iguana_p2shjson(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *retjson,struct iguana_waddress *waddr); char *setaccount(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_waddress **waddrp,char *account,char *coinaddr,char *redeemScript); char *iguana_APIrequest(struct iguana_info *coin,bits256 blockhash,bits256 txid,int32_t seconds);