Browse Source

test

release/v0.1
jl777 8 years ago
parent
commit
33b7a1d5b6
  1. 2
      basilisk/basilisk.c
  2. 5
      gecko/gecko.h
  3. 25
      gecko/gecko_mempool.c
  4. 7
      iguana/iguana_unspents.c

2
basilisk/basilisk.c

@ -210,7 +210,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
//printf("%s s.%d vs n.%d\n",addr->ipaddr,s,n);
if ( s == n && (addr->supernet != 0 || addr->basilisk != 0) && (destipaddr == 0 || strcmp(addr->ipaddr,destipaddr) == 0) )
{
printf("[%s].tag%d send %s.(%s) [%x] datalen.%d addr->supernet.%u basilisk.%u to (%s).%d destip.%s\n",cmd,*(uint32_t *)data,type,(char *)&data[4],*(int32_t *)&data[datalen-4],datalen,addr->supernet,addr->basilisk,addr->ipaddr,addr->A.port,destipaddr!=0?destipaddr:"broadcast");
//printf("[%s].tag%d send %s.(%s) [%x] datalen.%d addr->supernet.%u basilisk.%u to (%s).%d destip.%s\n",cmd,*(uint32_t *)data,type,(char *)&data[4],*(int32_t *)&data[datalen-4],datalen,addr->supernet,addr->basilisk,addr->ipaddr,addr->A.port,destipaddr!=0?destipaddr:"broadcast");
if ( encryptflag != 0 && bits256_nonz(addr->pubkey) != 0 )
{
void *ptr; uint8_t *cipher,space[8192]; int32_t cipherlen; bits256 privkey;

5
gecko/gecko.h

@ -41,9 +41,10 @@ struct gecko_memtx
{
double feeperkb;
bits256 txid;
int64_t txfee,inputsum,outputsum;
int32_t pending,numinputs,numoutputs,datalen;
uint32_t ipbits;
int64_t txfee,inputsum,outputsum; int32_t pending,numinputs,numoutputs,datalen;
uint8_t data[];
bits256 data256[];
};
struct gecko_mempool

25
gecko/gecko_mempool.c

@ -84,12 +84,12 @@ void gecko_mempool_sync(struct supernet_info *myinfo,struct iguana_info *virt,bi
uint8_t *gecko_txdata(struct gecko_memtx *memtx)
{
return(&memtx->data[memtx->numoutputs * sizeof(int64_t) + memtx->numinputs * sizeof(bits256)]);
return((void *)((long)memtx->data256 + memtx->numoutputs * sizeof(int64_t) + memtx->numinputs * sizeof(bits256)));
}
int64_t *gecko_valueptr(struct gecko_memtx *memtx,int32_t vout)
{
return((int64_t *)&memtx->data[memtx->numinputs * sizeof(bits256) + vout*sizeof(int64_t)]);
return((void *)((long)memtx->data256 + vout * sizeof(int64_t) + memtx->numinputs * sizeof(bits256)));
}
int32_t gecko_memtxcmp(struct gecko_memtx *memtxA,struct gecko_memtx *memtxB)
@ -99,13 +99,13 @@ int32_t gecko_memtxcmp(struct gecko_memtx *memtxA,struct gecko_memtx *memtxB)
{
for (i=0; i<memtxA->numinputs; i++)
{
if ( bits256_cmp(*(bits256 *)&memtxA->data[i * sizeof(bits256)],*(bits256 *)&memtxB->data[i * sizeof(bits256)]) != 0 )
if ( bits256_cmp(memtxA->data256[i],memtxB->data256[i]) != 0 )
return(-1 - 2*i);
}
for (i=numdiff=0; i<memtxA->numoutputs; i++)
{
valA = *gecko_valueptr(memtxA,i);
valB = *gecko_valueptr(memtxB,i);
memcpy(&valA,gecko_valueptr(memtxA,i),sizeof(valA));
memcpy(&valB,gecko_valueptr(memtxB,i),sizeof(valB));
if ( (diff= valA - valB) < 0 )
diff = -diff;
if ( diff > 100000 )
@ -139,7 +139,7 @@ struct gecko_memtx *gecko_unspentfind(struct gecko_memtx ***ptrpp,struct iguana_
struct gecko_memtx *gecko_mempool_txadd(struct supernet_info *myinfo,struct iguana_info *virt,char *rawtx,uint32_t senderbits)
{
struct gecko_memtx *spentmemtx,**ptrp,*memtx = 0; uint8_t *extraspace; char *str; struct iguana_msgtx msgtx; int32_t i,len,extralen = 65536; cJSON *retjson; int64_t *amountptr;
struct gecko_memtx *spentmemtx,**ptrp,*memtx = 0; uint8_t *extraspace; char *str; struct iguana_msgtx msgtx; int32_t i,len,extralen = 65536; cJSON *retjson; int64_t value;
extraspace = calloc(1,extralen);
if ( (str= iguana_validaterawtx(myinfo,virt,&msgtx,extraspace,extralen,rawtx,1)) != 0 )
{
@ -159,16 +159,16 @@ struct gecko_memtx *gecko_mempool_txadd(struct supernet_info *myinfo,struct igua
memtx->datalen = len;
memtx->feeperkb = dstr(memtx->txfee) / (memtx->datalen / 1024.);
for (i=0; i<msgtx.numoutputs; i++)
*gecko_valueptr(memtx,i) = msgtx.vouts[i].value;
memcpy(gecko_valueptr(memtx,i),&msgtx.vouts[i].value,sizeof(msgtx.vouts[i].value));
decode_hex(gecko_txdata(memtx),len,rawtx);
for (i=0; i<msgtx.numinputs; i++)
memcpy(&memtx->data[i * sizeof(bits256)],msgtx.vins[i].prev_hash.bytes,sizeof(bits256));
memtx->data256[i] = msgtx.vins[i].prev_hash;
for (i=0; i<msgtx.numinputs; i++)
{
if ( (spentmemtx= gecko_unspentfind(&ptrp,virt->mempool,msgtx.vins[i].prev_hash)) != 0 )
{
amountptr = gecko_valueptr(spentmemtx,msgtx.vins[i].prev_vout);
if ( *amountptr < 0 )
memcpy(&value,gecko_valueptr(spentmemtx,msgtx.vins[i].prev_vout),sizeof(value));
if ( value < 0 )
{
if ( gecko_memtxcmp(spentmemtx,memtx) != 0 || memtx->txfee <= spentmemtx->txfee )
{
@ -193,8 +193,9 @@ struct gecko_memtx *gecko_mempool_txadd(struct supernet_info *myinfo,struct igua
{
if ( (spentmemtx= gecko_unspentfind(0,virt->mempool,msgtx.vins[i].prev_hash)) != 0 )
{
amountptr = gecko_valueptr(spentmemtx,msgtx.vins[i].prev_vout);
*amountptr = -(*amountptr);
memcpy(&value,gecko_valueptr(spentmemtx,msgtx.vins[i].prev_vout),sizeof(value));
value = -value;
memcpy(gecko_valueptr(spentmemtx,msgtx.vins[i].prev_vout),&value,sizeof(value));
}
}
} else printf("gecko_mempool_txadd had error.(%s)\n",str);

7
iguana/iguana_unspents.c

@ -22,7 +22,7 @@
int32_t iguana_unspentindfind(struct iguana_info *coin,char *coinaddr,uint8_t *spendscript,int32_t *spendlenp,uint64_t *valuep,int32_t *heightp,bits256 txid,int32_t vout,int32_t lasthdrsi,int32_t mempool)
{
struct iguana_txid *tp,TX; struct gecko_memtx *memtx; struct iguana_pkhash *P; struct iguana_unspent *U; struct iguana_bundle *bp; struct iguana_ramchaindata *rdata; int64_t RTspend; int32_t pkind,hdrsi,firstvout,spentheight,flag=0,unspentind = -1;
struct iguana_txid *tp,TX; struct gecko_memtx *memtx; struct iguana_pkhash *P; struct iguana_unspent *U; struct iguana_bundle *bp; struct iguana_ramchaindata *rdata; int64_t RTspend; int64_t value; int32_t pkind,hdrsi,firstvout,spentheight,flag=0,unspentind = -1;
if ( valuep != 0 )
*valuep = 0;
if ( coinaddr != 0 )
@ -54,9 +54,10 @@ int32_t iguana_unspentindfind(struct iguana_info *coin,char *coinaddr,uint8_t *s
{
if ( (memtx= gecko_unspentfind(0,coin,txid)) != 0 && vout < memtx->numoutputs )
{
if ( *gecko_valueptr(memtx,vout) > 0 )
memcpy(&value,gecko_valueptr(memtx,vout),sizeof(value));
if ( value > 0 )
{
*valuep = *gecko_valueptr(memtx,vout);
*valuep = value;
if ( spendlenp != 0 )
{
*spendlenp = 1;

Loading…
Cancel
Save