Esempio n. 1
0
cJSON *gecko_paymentsobj(struct supernet_info *myinfo,cJSON *txjson,cJSON *valsobj,int32_t reusedaddrs)
{
    cJSON *item,*array; char *coinaddr; uint64_t satoshis; uint8_t addrtype,pubkey33[33],rmd160[20],outputscript[512]; int32_t i,n,scriptlen; uint32_t locktime,txversion; struct iguana_waddress *waddr; struct iguana_waccount *wacct;
    locktime = jint(valsobj,"locktime");
    if ( (txversion= juint(valsobj,"txversion")) == 0 )
        txversion = (locktime == 0) ? IGUANA_NORMAL_TXVERSION : IGUANA_LOCKTIME_TXVERSION;
    if ( txjson == 0 )
        txjson = bitcoin_txcreate(1,locktime,txversion);
    if ( (array= jarray(&n,valsobj,"payments")) != 0 && n > 0 )
    {
        for (i=0; i<n; i++)
        {
            item = jitem(array,i);
            if ( (coinaddr= jfieldname(item)) != 0 && (satoshis= j64bits(item,coinaddr)) > 0 )
            {
                printf("payment.%s <- %.8f\n",coinaddr,dstr(satoshis));
                bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr);
                scriptlen = 0;
                if ( reusedaddrs == 0 )
                {
                    if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 )
                    {
                        if ( bitcoin_pubkeylen(waddr->pubkey) > 0 )
                            scriptlen = bitcoin_pubkeyspend(outputscript,0,pubkey33);
                    }
                }
                if ( scriptlen == 0 )
                    scriptlen = bitcoin_standardspend(outputscript,0,rmd160);
                bitcoin_txoutput(txjson,outputscript,scriptlen,satoshis);
            }
        }
    }
    return(txjson);
}
Esempio n. 2
0
TWO_STRINGS(iguana,dpow,symbol,pubkey)
{
    char *retstr,srcaddr[64],destaddr[64]; struct iguana_info *src,*dest; cJSON *ismine; int32_t i,srcvalid,destvalid; struct dpow_info *dp = &myinfo->DPOWS[myinfo->numdpows];
    destvalid = srcvalid = 0;
    if ( myinfo->NOTARY.RELAYID < 0 )
    {
        if ( (retstr= basilisk_addrelay_info(myinfo,0,(uint32_t)calc_ipbits(myinfo->ipaddr),myinfo->myaddr.persistent)) != 0 )
        {
            printf("addrelay.(%s)\n",retstr);
            free(retstr);
        }
        if ( myinfo->NOTARY.RELAYID < 0 )
            return(clonestr("{\"error\":\"must be running as notary node\"}"));
    }
    if ( dp->symbol[0] != 0 )
        return(clonestr("{\"error\":\"cant dPoW more than one coin at a time\"}"));
    if ( pubkey == 0 || pubkey[0] == 0 || is_hexstr(pubkey,0) != 66 )
        return(clonestr("{\"error\":\"need 33 byte pubkey\"}"));
    if ( symbol == 0 || symbol[0] == 0 )
        symbol = "KMD";
    //if ( myinfo->numdpows == 1 )
    //    komodo_assetcoins(-1);
    if ( iguana_coinfind(symbol) == 0 )
        return(clonestr("{\"error\":\"cant dPoW an inactive coin\"}"));
    if ( strcmp(symbol,"KMD") == 0 && iguana_coinfind("BTC") == 0 )
        return(clonestr("{\"error\":\"cant dPoW KMD without BTC\"}"));
    else if ( myinfo->numdpows == 0 && strcmp(symbol,"KMD") != 0 && iguana_coinfind("KMD") == 0 )
        return(clonestr("{\"error\":\"cant dPoW without KMD\"}"));
    if ( myinfo->numdpows > 1 )
    {
        if ( strcmp(symbol,"KMD") == 0 || iguana_coinfind("BTC") == 0 )
        {
            dp->symbol[0] = 0;
            return(clonestr("{\"error\":\"cant dPoW KMD or BTC again\"}"));
        }
        for (i=1; i<myinfo->numdpows; i++)
            if ( strcmp(symbol,myinfo->DPOWS[i].symbol) == 0 )
            {
                dp->symbol[0] = 0;
                return(clonestr("{\"error\":\"cant dPoW same coin again\"}"));
            }
    }
    strcpy(dp->symbol,symbol);
    if ( strcmp(dp->symbol,"KMD") == 0 )
    {
        strcpy(dp->dest,"BTC");
        dp->srcconfirms = DPOW_KOMODOCONFIRMS;
    }
    else
    {
        strcpy(dp->dest,"KMD");
        dp->srcconfirms = DPOW_THIRDPARTY_CONFIRMS;
    }
    if ( dp->srcconfirms > DPOW_FIFOSIZE )
        dp->srcconfirms = DPOW_FIFOSIZE;
    src = iguana_coinfind(dp->symbol);
    dest = iguana_coinfind(dp->dest);
    if ( src == 0 || dest == 0 )
    {
        dp->symbol[0] = 0;
        return(clonestr("{\"error\":\"source coin or dest coin not there\"}"));
    }
    char tmp[67];
    safecopy(tmp,pubkey,sizeof(tmp));
    decode_hex(dp->minerkey33,33,tmp);
    bitcoin_address(srcaddr,src->chain->pubtype,dp->minerkey33,33);
    if ( (retstr= dpow_validateaddress(myinfo,src,srcaddr)) != 0 )
    {
        json = cJSON_Parse(retstr);
        if ( (ismine= jobj(json,"ismine")) != 0 && is_cJSON_True(ismine) != 0 )
            srcvalid = 1;
        else srcvalid = 0;
        free(retstr);
        retstr = 0;
    }
    bitcoin_address(destaddr,dest->chain->pubtype,dp->minerkey33,33);
    if ( (retstr= dpow_validateaddress(myinfo,dest,destaddr)) != 0 )
    {
        json = cJSON_Parse(retstr);
        if ( (ismine= jobj(json,"ismine")) != 0 && is_cJSON_True(ismine) != 0 )
            destvalid = 1;
        else destvalid = 0;
        free(retstr);
        retstr = 0;
    }
    for (i=0; i<33; i++)
        printf("%02x",dp->minerkey33[i]);
    printf(" DPOW with pubkey.(%s) %s.valid%d %s -> %s %s.valid%d\n",tmp,srcaddr,srcvalid,dp->symbol,dp->dest,destaddr,destvalid);
    if ( srcvalid <= 0 || destvalid <= 0 )
    {
        dp->symbol[0] = 0;
        return(clonestr("{\"error\":\"source address or dest address has no privkey, importprivkey\"}"));
    }
    if ( bitcoin_pubkeylen(dp->minerkey33) <= 0 )
    {
        dp->symbol[0] = 0;
        return(clonestr("{\"error\":\"illegal pubkey\"}"));
    }
    if ( dp->blocks == 0 )
    {
        dp->maxblocks = 1000000;
        dp->blocks = calloc(dp->maxblocks,sizeof(*dp->blocks));
    }
    portable_mutex_init(&dp->paxmutex);
    portable_mutex_init(&dp->dexmutex);
    PAX_init();
    //printf(">>>>>>>>>>>>>>> call paxpending\n");
    //uint8_t buf[32768];
    //dpow_paxpending(buf);
    myinfo->numdpows++;
    return(clonestr("{\"result\":\"success\"}"));
}