bits256 get_API_bits256(cJSON *obj) { bits256 hash; char *str; memset(hash.bytes,0,sizeof(hash)); if ( obj != 0 ) { if ( is_cJSON_String(obj) != 0 && (str= obj->valuestring) != 0 && strlen(str) == 64 ) decode_hex(hash.bytes,sizeof(hash),str); } return(hash); }
uint32_t *conv_addrjson(int32_t *nump,struct coin777 *coin,cJSON *addrjson) { uint32_t firstblocknum,*addrinds = 0; int32_t i; if ( is_cJSON_String(addrjson) != 0 ) { *nump = 1; addrinds = malloc(sizeof(*addrinds)); addrinds[0] = coin777_addrind(&firstblocknum,coin,cJSON_str(addrjson)); } else if ( is_cJSON_Array(addrjson) != 0 && (*nump= cJSON_GetArraySize(addrjson)) > 0 ) { addrinds = calloc(*nump,sizeof(*addrinds)); for (i=0; i<*nump; i++) addrinds[i] = coin777_addrind(&firstblocknum,coin,cJSON_str(cJSON_GetArrayItem(addrjson,i))); } return(addrinds); }
int32_t jnum(cJSON *obj,char *field) { char *str; int32_t polarity = 1; if ( field != 0 ) obj = jobj(obj,field); if ( obj != 0 ) { if ( is_cJSON_Number(obj) != 0 ) return(obj->valuedouble); else if ( is_cJSON_String(obj) != 0 && (str= jstr(obj,0)) != 0 ) { if ( str[0] == '-' ) polarity = -1, str++; return(polarity * (int32_t)calc_nxt64bits(str)); } } return(0); }
char *cJSON_str(cJSON *json) { if ( json != 0 && is_cJSON_String(json) != 0 ) return(json->valuestring); return(0); }