Beispiel #1
0
int32_t iguana_rwtx(int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgtx *msg,int32_t maxsize,bits256 *txidp,int32_t hastimestamp,int32_t isvpncoin)
{
    int32_t i,len = 0; uint8_t *txstart = serialized; char txidstr[65];
    len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->version),&msg->version);
    if ( hastimestamp != 0 )
        len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->timestamp),&msg->timestamp);
    len += iguana_rwvarint32(rwflag,&serialized[len],&msg->tx_in);
    //printf("version.%d ",msg->version);
    if ( msg->tx_in > 0 && msg->tx_out*100 < maxsize )
    {
        if ( rwflag == 0 )
            msg->vins = iguana_memalloc(mem,msg->tx_in * sizeof(*msg->vins),1);
        for (i=0; i<msg->tx_in; i++)
            len += iguana_rwvin(rwflag,mem,&serialized[len],&msg->vins[i]);
        //printf("numvins.%d\n",msg->tx_in);
    }
    else
    {
        printf("invalid tx_in.%d\n",msg->tx_in);
        return(-1);
    }
    len += iguana_rwvarint32(rwflag,&serialized[len],&msg->tx_out);
    if ( msg->tx_out > 0 && msg->tx_out*32 < maxsize )
    {
        //printf("numvouts.%d ",msg->tx_out);
        if ( rwflag == 0 )
            msg->vouts = iguana_memalloc(mem,msg->tx_out * sizeof(*msg->vouts),1);
        for (i=0; i<msg->tx_out; i++)
            len += iguana_rwvout(rwflag,mem,&serialized[len],&msg->vouts[i]);
    }
    else
    {
        printf("invalid tx_out.%d\n",msg->tx_out);
        return(-1);
    }
    len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->lock_time),&msg->lock_time);
    if ( isvpncoin != 0 )
    {
        uint16_t ddosflag=0;
        len += iguana_rwnum(rwflag,&serialized[len],sizeof(ddosflag),&ddosflag);
        for (; serialized[len]!=0&&len<maxsize; len++) // eat null terminated string
            ;
    }
    *txidp = bits256_doublesha256(txidstr,txstart,len);
    msg->allocsize = len;
    return(len);
}
Beispiel #2
0
int32_t iguana_rwtx(int32_t rwflag,uint8_t *serialized,struct iguana_msgtx *msg,int32_t maxsize,bits256 *txidp,int32_t height,int32_t hastimestamp)
{
    int32_t i,len = 0; uint8_t *txstart = serialized; char txidstr[65]; uint32_t timestamp;
    len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->version),&msg->version);
    if ( hastimestamp != 0 )
        len += iguana_rwnum(rwflag,&serialized[len],sizeof(timestamp),&timestamp);
    len += iguana_rwvarint32(rwflag,&serialized[len],&msg->tx_in);
    //printf("version.%d ",msg->version);
    if ( msg->tx_in > 0 && msg->tx_out*100 < maxsize )
    {
        if ( rwflag == 0 )
            msg->vins = mycalloc('v',msg->tx_in,sizeof(*msg->vins));
        for (i=0; i<msg->tx_in; i++)
            len += iguana_rwvin(rwflag,&serialized[len],&msg->vins[i]);
        //printf("numvins.%d\n",msg->tx_in);
    }
    else
    {
        printf("invalid tx_in.%d\n",msg->tx_in);
        return(-1);
    }
    len += iguana_rwvarint32(rwflag,&serialized[len],&msg->tx_out);
    if ( msg->tx_out > 0 && msg->tx_out*32 < maxsize )
    {
        //printf("numvouts.%d ",msg->tx_out);
        if ( rwflag == 0 )
            msg->vouts = mycalloc('v',msg->tx_out,sizeof(*msg->vouts));
        for (i=0; i<msg->tx_out; i++)
            len += iguana_rwvout(rwflag,&serialized[len],&msg->vouts[i]);
    }
    else
    {
        printf("invalid tx_out.%d\n",msg->tx_out);
        return(-1);
    }
    len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->lock_time),&msg->lock_time);
    *txidp = bits256_doublesha256(txidstr,txstart,len);
    //printf("txid.(%s) len.%d\n",bits256_str(*txidp),len);
    msg->allocsize = len;
    Tx_allocated++, Tx_allocsize += len;
    if ( ((Tx_allocated + Tx_freed) % 10000000) == 0 )
        printf("h.%u len.%d (%llu - %llu) %lld (%llu - %llu)\n",height,len,(long long)Tx_allocated,(long long)Tx_freed,(long long)(Tx_allocated - Tx_freed),(long long)Tx_allocsize,(long long)Tx_freesize);
    return(len);
}
Beispiel #3
0
int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t maxlen,bits256 *txidp,struct iguana_txid *tx,int32_t height,struct iguana_msgvin *vins,struct iguana_msgvout *vouts,int32_t validatesigs)
{
    int32_t i,rwflag=1,len = 0; char asmstr[512],txidstr[65];
    uint32_t numvins,numvouts,version,locktime,timestamp=0; struct iguana_msgvin vin; struct iguana_msgvout vout; uint8_t space[IGUANA_MAXSCRIPTSIZE];
    if ( rwflag != 0 )
    {
        version = tx->version;
        locktime = tx->locktime;
        timestamp = tx->timestamp;
        numvins = tx->numvins;
        numvouts = tx->numvouts;
    }
    len += iguana_rwnum(rwflag,&serialized[len],sizeof(version),&version);
    if ( coin->chain->isPoS != 0 )
        len += iguana_rwnum(rwflag,&serialized[len],sizeof(timestamp),&timestamp);
    len += iguana_rwvarint32(rwflag,&serialized[len],&numvins);
    memset(&vin,0,sizeof(vin));
    for (i=0; i<numvins; i++)
    {
        if ( vins == 0 )
        {
            if ( iguana_vinset(coin,space,height,&vin,tx,i) < 0 )
            {
                printf("iguana_ramtxbytes vinset error %d of %d\n",i,numvins);
                return(0);
            }
        } else vin = vins[i];
        len += iguana_rwvin(rwflag,coin,0,&serialized[len],&vin,i);
        if ( len > maxlen )
            break;
    }
    if ( len > maxlen )
    {
        printf("len.%d > maxlen.%d\n",len,maxlen);
        return(0);
    }
    len += iguana_rwvarint32(rwflag,&serialized[len],&numvouts);
    for (i=0; i<numvouts; i++)
    {
        if ( vouts == 0 )
        {
            if ( iguana_voutset(coin,space,asmstr,height,&vout,tx,i) < 0 )
            {
                static uint32_t counter;
                if ( counter++ < 10 )
                    printf("iguana_ramtxbytes voutset error %d of %d\n",i,numvouts);
                return(0);
            }
        } else vout = vouts[i];
        len += iguana_rwvout(rwflag,0,&serialized[len],&vout);
        if ( len > maxlen )
            break;
    }
    if ( len > maxlen )
    {
        printf("len.%d > maxlenB.%d\n",len,maxlen);
        return(0);
    }
    len += iguana_rwnum(rwflag,&serialized[len],sizeof(locktime),&locktime);
    if ( rwflag == 0 )
    {
        tx->version = version;
        tx->timestamp = timestamp;
        tx->numvins = numvins;
        tx->numvouts = numvouts;
        tx->locktime = locktime;
    }
    *txidp = bits256_doublesha256(txidstr,serialized,len);
    if ( memcmp(txidp,tx->txid.bytes,sizeof(*txidp)) != 0 )
    {
        for (i=0; i<len; i++)
            printf("%02x",serialized[i]);
        char str[65],str2[65]; printf("\nrw.%d numvins.%d numvouts.%d error generating txbytes txid %s vs %s\n",rwflag,numvins,numvouts,bits256_str(str,*txidp),bits256_str(str2,tx->txid));
        return(-1);
    }
    return(len);
}