Exemplo n.º 1
0
uint64_t calc_nxt64bits(const char *NXTaddr)
{
    int32_t c;
    int64_t n,i,polarity = 1;
    uint64_t lastval,mult,nxt64bits = 0;
    if ( NXTaddr == 0 )
    {
        printf("calling calc_nxt64bits with null ptr!\n");
        return(0);
    }
    n = strlen(NXTaddr);
    if ( n >= 22 )
    {
        printf("calc_nxt64bits: illegal NXTaddr.(%s) too long\n",NXTaddr);
        return(0);
    }
    else if ( strcmp(NXTaddr,"0") == 0 || strcmp(NXTaddr,"false") == 0 )
    {
        // printf("zero address?\n"); getchar();
        return(0);
    }
    if ( NXTaddr[0] == '-' )
        polarity = -1, NXTaddr++, n--;
    mult = 1;
    lastval = 0;
    for (i=n-1; i>=0; i--,mult*=10)
    {
        c = NXTaddr[i];
        if ( c < '0' || c > '9' )
        {
            printf("calc_nxt64bits: illegal char.(%c %d) in (%s).%d\n",c,c,NXTaddr,(int32_t)i);
#ifdef __APPLE__
            //while ( 1 )
            {
                //sleep(60);
                printf("calc_nxt64bits: illegal char.(%c %d) in (%s).%d\n",c,c,NXTaddr,(int32_t)i);
            }
#endif
            return(0);
        }
        nxt64bits += mult * (c - '0');
        if ( nxt64bits < lastval )
            printf("calc_nxt64bits: warning: 64bit overflow %llx < %llx\n",(long long)nxt64bits,(long long)lastval);
        lastval = nxt64bits;
    }
    while ( *NXTaddr == '0' && *NXTaddr != 0 )
        NXTaddr++;
    if ( cmp_nxt64bits(NXTaddr,nxt64bits) != 0 )
        printf("error calculating nxt64bits: %s -> %llx -> %s\n",NXTaddr,(long long)nxt64bits,nxt64str(nxt64bits));
    if ( polarity < 0 )
        return(-(int64_t)nxt64bits);
    return(nxt64bits);
}
Exemplo n.º 2
0
int32_t process_NXT_event(struct NXThandler_info *mp,int32_t histmode,char *txid,int64_t type,int64_t subtype,struct NXT_AMhdr *AMhdr,char *sender,char *receiver,char *assetid,int64_t assetoshis,char *comment,cJSON *json)
{
    int32_t i,count,highest_priority;
    NXT_handler NXT_handler = 0;
    void *handlerdata = 0;
    struct NXT_protocol *p;
    struct NXT_protocol_parms PARMS;
    count = 0;
    highest_priority = -1;
    memset(&PARMS,0,sizeof(PARMS));
    if ( Num_NXThandlers == 0 )
        printf("WARNING: process_NXT_event Num_NXThandlers.%d\n",Num_NXThandlers);
    for (i=0; i<Num_NXThandlers; i++)
    {
        if ( (p= NXThandlers[i]) != 0 )
        {
            if ( AMhdr != 0 || ((p->type < 0 || p->type == type) && (p->subtype < 0 || p->subtype == subtype)) )
            {
                if ( AMhdr != 0 )
                {
                    if ( p->AMsigfilter != 0 && p->AMsigfilter != AMhdr->sig )
                        continue;
                }
                else if ( p->assetlist != 0 && assetid != 0 && listcmp(p->assetlist,assetid) != 0 )
                    continue;
                if ( strcmp(sender,GENESISACCT) == 0 || strcmp(receiver,GENESISACCT) == 0 || //is_gateway_addr(sender) != 0 ||
                     (AMhdr == 0 || p->whitelist == 0 || listcmp(p->whitelist,sender) == 0) ||
                     (AMhdr != 0 && cmp_nxt64bits(sender,AMhdr->nxt64bits) == 0) )
                {
                    if ( p->priority > highest_priority )
                    {
                        count = 1;
                        highest_priority = p->priority;
                        NXT_handler = p->NXT_handler;
                        handlerdata = p->handlerdata;
                        PARMS.argjson = json; PARMS.txid = txid; PARMS.sender = sender; PARMS.receiver = receiver;
                        PARMS.type = (int32_t)type; PARMS.subtype = (int32_t)subtype; PARMS.priority = highest_priority; PARMS.histflag = histmode;
                        if ( AMhdr != 0 )
                        {
                            PARMS.mode = NXTPROTOCOL_AMTXID;
                            PARMS.AMptr = AMhdr;
                        }
                        else
                        {
                            PARMS.mode = NXTPROTOCOL_TYPEMATCH;
                            PARMS.assetid = assetid;
                            PARMS.assetoshis = assetoshis;
                            PARMS.comment = comment;
                        }
                        //printf("call NXT_handler\n");
                        (*NXT_handler)(mp,&PARMS,handlerdata);
                   }
                    else if ( p->priority == highest_priority )
                        count++;
                }
                //printf("end iter\n");
            }
        }
    }
    if ( count > 1 )
        printf("WARNING: (%s) claimed %d times, priority.%d\n",cJSON_Print(json),count,highest_priority);  // this is bad, also leaks mem!
    if ( 0 && highest_priority >= 0 && NXT_handler != 0 )
    {
        //printf("count.%d handler.%p NXThandler_info_handler.%p AMhdr.%p\n",count,NXT_handler,multigateway_handler,AMhdr);
        PARMS.argjson = json; PARMS.txid = txid; PARMS.sender = sender; PARMS.receiver = receiver;
        PARMS.type = (int32_t)type; PARMS.subtype = (int32_t)subtype; PARMS.priority = highest_priority; PARMS.histflag = histmode;
        if ( AMhdr != 0 )
        {
            PARMS.mode = NXTPROTOCOL_AMTXID;
            PARMS.AMptr = AMhdr;
        }
        else
        {
            PARMS.mode = NXTPROTOCOL_TYPEMATCH;
            PARMS.assetid = assetid;
            PARMS.assetoshis = assetoshis;
            PARMS.comment = comment;
        }
        (*NXT_handler)(mp,&PARMS,handlerdata);///histmode,txid,AMhdr,sender,receiver,assetid,assetoshis,comment,json);
    }
    return(count != 0);
}