Browse Source

iguana.sources

release/v0.1
jl777 9 years ago
parent
commit
246753621e
  1. BIN
      arm/libcrypto.so
  2. BIN
      arm/libssl.so
  3. 4
      crypto777/OS_nonportable.c
  4. 5
      crypto777/OS_portable.c
  5. 4
      crypto777/OS_portable.h
  6. 16
      crypto777/cJSON.c
  7. 2
      iguana/Makefile
  8. 9
      iguana/iguana.sources
  9. 14
      iguana/iguana777.h
  10. 1
      iguana/iguana_html.c
  11. 132
      iguana/iguana_pubkeys.c
  12. 563
      iguana/iguana_rpc.c
  13. 56
      iguana/iguana_wallet.c
  14. 10
      iguana/mingw
  15. 4
      includes/cJSON.h

BIN
arm/libcrypto.so

Binary file not shown.

BIN
arm/libssl.so

Binary file not shown.

4
crypto777/OS_nonportable.c

@ -197,7 +197,7 @@ int _mprotect(void *addr, size_t len, int prot)
return -1; return -1;
} }
int msync(void *addr, size_t len, int flags) /*int msync(void *addr, size_t len, int flags)
{ {
if (FlushViewOfFile(addr, len)) if (FlushViewOfFile(addr, len))
return 0; return 0;
@ -205,7 +205,7 @@ int msync(void *addr, size_t len, int flags)
errno = __map_mman_error(GetLastError(), EPERM); errno = __map_mman_error(GetLastError(), EPERM);
return -1; return -1;
} }*/
int mlock(const void *addr, size_t len) int mlock(const void *addr, size_t len)
{ {

5
crypto777/OS_portable.c

@ -155,7 +155,7 @@ void *OS_portable_mapfile(char *fname,long *filesizep,int32_t enablewrite)
int32_t OS_portable_syncmap(struct OS_mappedptr *mp,long len) int32_t OS_portable_syncmap(struct OS_mappedptr *mp,long len)
{ {
#ifndef __PNACL /*#ifndef __PNACL
int32_t err = -1; int32_t err = -1;
if ( mp->actually_allocated != 0 ) if ( mp->actually_allocated != 0 )
return(0); return(0);
@ -172,7 +172,8 @@ int32_t OS_portable_syncmap(struct OS_mappedptr *mp,long len)
return(err); return(err);
#else #else
return(OS_nonportable_syncmap(mp,len)); return(OS_nonportable_syncmap(mp,len));
#endif #endif*/
return(-1);
} }
void *OS_portable_tmpalloc(char *dirname,char *name,struct OS_memspace *mem,long origsize) void *OS_portable_tmpalloc(char *dirname,char *name,struct OS_memspace *mem,long origsize)

4
crypto777/OS_portable.h

@ -121,7 +121,7 @@ struct tai taitime2tai(struct taitime ct);
char *tai_str(char *str,struct tai t); char *tai_str(char *str,struct tai t);
char *utc_str(char *str,struct tai t); char *utc_str(char *str,struct tai t);
int32_t msync(void *addr,size_t len,int32_t flags); //int32_t msync(void *addr,size_t len,int32_t flags);
#ifdef __PNACL #ifdef __PNACL
int32_t OS_nonportable_syncmap(struct OS_mappedptr *mp,long len); int32_t OS_nonportable_syncmap(struct OS_mappedptr *mp,long len);
@ -307,5 +307,7 @@ int32_t bits256_cmp(bits256 a,bits256 b);
bits256 bits256_lshift(bits256 x); bits256 bits256_lshift(bits256 x);
bits256 bits256_from_compact(uint32_t c); bits256 bits256_from_compact(uint32_t c);
int32_t btc_priv2pub(uint8_t pubkey[33],uint8_t privkey[32]);
#endif #endif

16
crypto777/cJSON.c

@ -811,6 +811,22 @@ char *jstr(cJSON *json,char *field) { if ( field == 0 ) return(cJSON_str(json));
char *jstri(cJSON *json,int32_t i) { return(cJSON_str(cJSON_GetArrayItem(json,i))); } char *jstri(cJSON *json,int32_t i) { return(cJSON_str(cJSON_GetArrayItem(json,i))); }
char *jprint(cJSON *json,int32_t freeflag) { char *str; if ( json == 0 ) return(clonestr("{}")); str = cJSON_Print(json), _stripwhite(str,' '); if ( freeflag != 0 ) free_json(json); return(str); } char *jprint(cJSON *json,int32_t freeflag) { char *str; if ( json == 0 ) return(clonestr("{}")); str = cJSON_Print(json), _stripwhite(str,' '); if ( freeflag != 0 ) free_json(json); return(str); }
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);
}
bits256 jbits256(cJSON *json,char *field) { if ( field == 0 ) return(get_API_bits256(json)); return(get_API_bits256(cJSON_GetObjectItem(json,field))); }
bits256 jbits256i(cJSON *json,int32_t i) { return(get_API_bits256(cJSON_GetArrayItem(json,i))); }
void jaddbits256(cJSON *json,char *field,bits256 hash) { char str[65]; bits256_str(str,hash), jaddstr(json,field,str); }
void jaddibits256(cJSON *json,bits256 hash) { char str[65]; bits256_str(str,hash), jaddistr(json,str); }
char *get_cJSON_fieldname(cJSON *obj) char *get_cJSON_fieldname(cJSON *obj)
{ {
if ( obj != 0 ) if ( obj != 0 )

2
iguana/Makefile

@ -26,7 +26,7 @@ LIBS = crypto777 curl ssl crypto z glibc-compat nacl_spawn ppapi nacl_io ppapi_
CFLAGS = -Wall -D__PNACL -fno-strict-aliasing $(EXTRA) CFLAGS = -Wall -D__PNACL -fno-strict-aliasing $(EXTRA)
LFLAGS = libs LFLAGS = libs
SOURCES = main.c iguana777.c iguana_init.c iguana_json.c iguana_recv.c iguana_chains.c iguana_ramchain.c iguana_bitmap.c iguana_rpc.c iguana_bundles.c iguana_pubkeys.c iguana_msg.c iguana_html.c iguana_blocks.c iguana_peers.c SOURCES = main.c iguana777.c iguana_wallet.c iguana_init.c iguana_json.c iguana_recv.c iguana_chains.c iguana_ramchain.c iguana_bitmap.c iguana_rpc.c iguana_bundles.c iguana_pubkeys.c iguana_msg.c iguana_html.c iguana_blocks.c iguana_peers.c
SOURCESI = InstantDEX/main.c InstantDEX/InstantDEX_main.c InstantDEX/prices777.c SOURCESI = InstantDEX/main.c InstantDEX/InstantDEX_main.c InstantDEX/prices777.c

9
iguana/iguana.sources

@ -0,0 +1,9 @@
SOURCES := iguana_wallet.c iguana_pubkeys.c iguana_recv.c iguana_bundles.c iguana_msg.c iguana_rpc.c iguana777.c iguana_chains.c iguana_peers.c iguana_accept.c iguana_html.c iguana_bitmap.c iguana_init.c iguana_ramchain.c iguana_blocks.c iguana_json.c ../crypto777/cJSON.c ../crypto777/iguana_utils.c ../crypto777/OS_nonportable.c ../crypto777/curve25519-donna.c ../crypto777/inet.c ../crypto777/OS_portable.c ../crypto777/curve25519.c ../crypto777/libgfshare.c ../crypto777/OS_time.c ../crypto777/hmac_sha512.c ../crypto777/ramcoder.c ../crypto777/SaM.c ../crypto777/iguana_OS.c ../crypto777/iguana_serdes.c ../crypto777/jpeg/jaricom.c ../crypto777/jpeg/jcapimin.c ../crypto777/jpeg/jcapistd.c ../crypto777/jpeg/jcarith.c ../crypto777/jpeg/jccoefct.c ../crypto777/jpeg/jccolor.c \
../crypto777/jpeg/jcdctmgr.c ../crypto777/jpeg/jchuff.c ../crypto777/jpeg/jcinit.c ../crypto777/jpeg/jcmainct.c ../crypto777/jpeg/jcmarker.c ../crypto777/jpeg/jcmaster.c \
../crypto777/jpeg/jcomapi.c ../crypto777/jpeg/jcparam.c ../crypto777/jpeg/jcprepct.c ../crypto777/jpeg/jcsample.c ../crypto777/jpeg/jctrans.c ../crypto777/jpeg/jdapimin.c \
../crypto777/jpeg/jdapistd.c ../crypto777/jpeg/jdarith.c ../crypto777/jpeg/jdatadst.c ../crypto777/jpeg/jdatasrc.c ../crypto777/jpeg/jdcoefct.c ../crypto777/jpeg/jdcolor.c \
../crypto777/jpeg/jddctmgr.c ../crypto777/jpeg/jdhuff.c ../crypto777/jpeg/jdinput.c ../crypto777/jpeg/jdmainct.c ../crypto777/jpeg/jdmarker.c ../crypto777/jpeg/jdmaster.c \
../crypto777/jpeg/jdmerge.c ../crypto777/jpeg/jdpostct.c ../crypto777/jpeg/jdsample.c ../crypto777/jpeg/jdtrans.c ../crypto777/jpeg/jerror.c ../crypto777/jpeg/jfdctflt.c \
../crypto777/jpeg/jfdctfst.c ../crypto777/jpeg/jfdctint.c ../crypto777/jpeg/jidctflt.c ../crypto777/jpeg/jidctfst.c ../crypto777/jpeg/jidctint.c ../crypto777/jpeg/jquant1.c \
../crypto777/jpeg/jquant2.c ../crypto777/jpeg/jutils.c ../crypto777/jpeg/jmemmgr.c ../crypto777/jpeg/jmemnobs.c main.c

14
iguana/iguana777.h

@ -406,6 +406,10 @@ struct iguana_bundlereq
struct iguana_bitmap { int32_t width,height,amplitude; char name[52]; uint8_t data[IGUANA_WIDTH*IGUANA_HEIGHT*3]; }; struct iguana_bitmap { int32_t width,height,amplitude; char name[52]; uint8_t data[IGUANA_WIDTH*IGUANA_HEIGHT*3]; };
struct iguana_waddress { UT_hash_handle hh; uint8_t rmd160[20],type,pubkey[33],wiptype; uint32_t symbolbits; bits256 privkey; char coinaddr[36],wipstr[50]; };
struct iguana_waccount { UT_hash_handle hh; char account[128]; struct iguana_waddress *waddrs; };
struct iguana_wallet { UT_hash_handle hh; struct iguana_waccount *waccts; };
struct iguana_info struct iguana_info
{ {
char name[64],symbol[8],statusstr[512]; char name[64],symbol[8],statusstr[512];
@ -438,6 +442,7 @@ struct iguana_info
void *launched,*started; void *launched,*started;
uint64_t bloomsearches,bloomhits,bloomfalse,collisions; uint8_t blockspace[IGUANA_MAXPACKETSIZE + 8192]; struct OS_memspace blockMEM; uint64_t bloomsearches,bloomhits,bloomfalse,collisions; uint8_t blockspace[IGUANA_MAXPACKETSIZE + 8192]; struct OS_memspace blockMEM;
struct iguana_blocks blocks; struct iguana_blocks blocks;
struct iguana_waccount *wallet;
}; };
// peers // peers
@ -663,4 +668,13 @@ struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana
int32_t iguana_sendblockreq(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,int32_t iamthreadsafe); int32_t iguana_sendblockreq(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,int32_t iamthreadsafe);
int32_t iguana_send_supernet(struct iguana_info *coin,struct iguana_peer *addr,char *jsonstr,int32_t delay); int32_t iguana_send_supernet(struct iguana_info *coin,struct iguana_peer *addr,char *jsonstr,int32_t delay);
struct iguana_waccount *iguana_waccountfind(struct iguana_info *coin,char *account);
struct iguana_waccount *iguana_waccountadd(struct iguana_info *coin,char *walletaccount,struct iguana_waddress *waddr);
int32_t iguana_waccountswitch(struct iguana_info *coin,struct iguana_waddress *waddr,char *coinaddr);
struct iguana_waddress *iguana_waddressfind(struct iguana_info *coin,char *coinaddr);
char *iguana_coinjson(struct iguana_info *coin,char *method,cJSON *json);
cJSON *iguana_peersjson(struct iguana_info *coin,int32_t addronly);
int32_t btc_priv2wip(char *wipstr,uint8_t privkey[32],uint8_t addrtype);
int32_t btc_pub2rmd(uint8_t rmd160[20],uint8_t pubkey[33]);
#endif #endif

1
iguana/iguana_html.c

@ -298,7 +298,6 @@ char *iguana_hashparse(char *path)
char *iguana_htmlget(char *space,int32_t max,int32_t *jsonflagp,char *path,char *remoteaddr,int32_t localaccess) char *iguana_htmlget(char *space,int32_t max,int32_t *jsonflagp,char *path,char *remoteaddr,int32_t localaccess)
{ {
char *iguana_coinjson(struct iguana_info *coin,char *method,cJSON *json);
struct iguana_info *coin = 0; cJSON *json; bits256 hash2; int32_t height,i; struct iguana_info *coin = 0; cJSON *json; bits256 hash2; int32_t height,i;
char buf[64],jsonstr[1024],coinstr[64],*retstr; char buf[64],jsonstr[1024],coinstr[64],*retstr;
for (i=0; path[i]!=0; i++) for (i=0; path[i]!=0; i++)

132
iguana/iguana_pubkeys.c

@ -666,9 +666,10 @@ int32_t btc_wip2priv(uint8_t privkey[32],char *wipstr)
return(len); return(len);
} }
int32_t btc_setprivkey(struct bp_key *key,char *privkeystr) int32_t btc_setprivkey(struct bp_key *key,char *wipstr)
{ {
uint8_t privkey[512]; int32_t len = btc_wip2priv(privkey,privkeystr); uint8_t privkey[512]; int32_t len;
len = btc_wip2priv(privkey,wipstr);
if ( len < 0 || bp_key_init(key) == 0 || bp_key_secret_set(key,privkey,len) == 0 ) if ( len < 0 || bp_key_init(key) == 0 || bp_key_secret_set(key,privkey,len) == 0 )
{ {
printf("error setting privkey\n"); printf("error setting privkey\n");
@ -685,21 +686,20 @@ void btc_freekey(void *key)
int32_t btc_priv2pub(uint8_t pubkey[33],uint8_t privkey[32]) int32_t btc_priv2pub(uint8_t pubkey[33],uint8_t privkey[32])
{ {
size_t len; void *pub = 0; int32_t retval = -1; size_t len; void *pub = 0;
struct bp_key *key = mycalloc('b',1,sizeof(*key)); struct bp_key key;
if ( key != 0 && bp_key_init(key) != 0 && bp_key_secret_set(key,privkey,32) != 0 ) if ( bp_key_init(&key) != 0 && bp_key_secret_set(&key,privkey,32) != 0 )
{ {
bp_pubkey_get(key,&pub,&len); bp_pubkey_get(&key,&pub,&len);
bp_key_free(key); bp_key_free(&key);
if ( len == 33 ) if ( len == 33 )
memcpy(pubkey,pub,33); memcpy(pubkey,pub,33);
if ( pub != 0 ) if ( pub != 0 )
myfree(pub,len); myfree(pub,len);
return(retval); return(0);
} }
if ( key != 0 ) bp_key_free(&key);
bp_key_free(key); return(-1);
return(retval);
} }
int32_t btc_pub2rmd(uint8_t rmd160[20],uint8_t pubkey[33]) int32_t btc_pub2rmd(uint8_t rmd160[20],uint8_t pubkey[33])
@ -997,3 +997,113 @@ int32_t iguana_scriptgen(struct iguana_info *coin,uint8_t *script,char *asmstr,s
} }
return(0); return(0);
} }
char *iguana_txcreate(struct iguana_info *coin,uint8_t *space,int32_t maxlen,char *jsonstr)
{
struct iguana_txid T; struct iguana_msgvin *vins,*vin; struct iguana_msgvout *vouts,*vout;
char *redeemstr;
cJSON *array,*json,*item,*retjson = 0; bits256 scriptPubKey; int32_t i,numvins,numvouts,len = 0;
if ( (json= cJSON_Parse(jsonstr)) != 0 )
{
memset(&T,0,sizeof(T));
if ( (T.version= juint(json,"version")) == 0 )
T.version = 1;
if ( (T.locktime= juint(json,"locktime")) == 0 )
T.locktime = 0xffffffff;
vins = (struct iguana_msgvin *)&space[len];
if ( (array= jarray(&numvins,json,"vins")) != 0 )
{
len += sizeof(*vins) * numvins;
memset(vins,0,sizeof(*vins) * numvins);
//struct iguana_msgvin { bits256 prev_hash; uint8_t *script; uint32_t prev_vout,scriptlen,sequence; };
for (i=0; i<numvins; i++)
{
vin = &vins[i];
item = jitem(array,i);
vin->prev_hash = jbits256(item,"txid");
vin->prev_vout = juint(item,"vout");
vin->sequence = juint(item,"sequence");
scriptPubKey = jbits256(item,"scriptPubKey");
if ( bits256_nonz(scriptPubKey) > 0 )
{
if ( (redeemstr= jstr(item,"redeemScript")) == 0 )
{
vin->scriptlen = (int32_t)strlen(redeemstr);
if ( (vin->scriptlen & 1) != 0 )
{
free_json(json);
return(clonestr("{\"error\":\"odd redeemScript length\"}"));
}
vin->scriptlen >>= 1;
vin->script = &space[len], len += vin->scriptlen;
}
}
}
}
vouts = (struct iguana_msgvout *)&space[len];
if ( (array= jarray(&numvouts,json,"vouts")) != 0 )
{
len += sizeof(*vouts) * numvouts;
memset(vouts,0,sizeof(*vouts) * numvouts);
//struct iguana_msgvout { uint64_t value; uint32_t pk_scriptlen; uint8_t *pk_script; };
for (i=0; i<numvouts; i++)
{
vout = &vouts[i];
item = jitem(array,i);
printf("create vout\n");
}
}
T.numvins = numvins, T.numvouts = numvouts;
T.timestamp = (uint32_t)time(NULL);
if ( (len= iguana_txbytes(coin,space,maxlen-len,&T.txid,&T,-1,vins,vouts)) > 0 )
{
}
free_json(json);
}
if ( retjson == 0 )
retjson = cJSON_Parse("{\"error\":\"couldnt create transaction\"}");
return(jprint(retjson,1));
}
/*
if ( bp_key_init(&key) != 0 && bp_key_secret_set(&key,privkey,32) != 0 )
{
if ( (T= calloc(1,sizeof(*T))) == 0 )
return(0);
*T = *refT; vin = &T->inputs[redeemi];
for (i=0; i<T->numinputs; i++)
strcpy(T->inputs[i].sigs,"00");
strcpy(vin->sigs,redeemscript);
vin->sequence = (uint32_t)-1;
T->nlocktime = 0;
//disp_cointx(&T);
emit_cointx(&hash2,data,sizeof(data),T,oldtx_format,SIGHASH_ALL);
//printf("HASH2.(%llx)\n",(long long)hash2.txid);
if ( bp_sign(&key,hash2.bytes,sizeof(hash2),&sig,&siglen) != 0 )
{
memcpy(sigbuf,sig,siglen);
sigbuf[siglen++] = SIGHASH_ALL;
init_hexbytes_noT(sigs[privkeyind],sigbuf,(int32_t)siglen);
strcpy(vin->sigs,"00");
for (i=0; i<n; i++)
{
if ( sigs[i][0] != 0 )
{
sprintf(vin->sigs + strlen(vin->sigs),"%02x%s",(int32_t)strlen(sigs[i])>>1,sigs[i]);
//printf("(%s).%ld ",sigs[i],strlen(sigs[i]));
}
}
len = (int32_t)(strlen(redeemscript)/2);
if ( len >= 0xfd )
sprintf(&vin->sigs[strlen(vin->sigs)],"4d%02x%02x",len & 0xff,(len >> 8) & 0xff);
else sprintf(&vin->sigs[strlen(vin->sigs)],"4c%02x",len);
sprintf(&vin->sigs[strlen(vin->sigs)],"%s",redeemscript);
//printf("after A.(%s) othersig.(%s) siglen.%02lx -> (%s)\n",hexstr,othersig != 0 ? othersig : "",siglen,vin->sigs);
//printf("vinsigs.(%s) %ld\n",vin->sigs,strlen(vin->sigs));
_emit_cointx(hexstr,sizeof(hexstr),T,oldtx_format);
//disp_cointx(&T);
free(T);
return(clonestr(hexstr));
}
*/

563
iguana/iguana_rpc.c

@ -408,6 +408,10 @@ char *ramchain_coinparser(struct iguana_info *coin,char *method,cJSON *json)
{ {
jaddstr(retitem,"totalsent","totalsent entry"); jaddstr(retitem,"totalsent","totalsent entry");
} }
else if ( strcmp(method,"validate") == 0 )
{
jaddstr(retitem,"validate",coinaddr);
}
if ( n == 0 ) if ( n == 0 )
return(jprint(retitem,1)); return(jprint(retitem,1));
else jaddi(retjson,retitem); else jaddi(retjson,retitem);
@ -501,3 +505,562 @@ char *ramchain_parser(struct iguana_agent *agent,struct iguana_info *coin,char *
} }
return(ramchain_coinparser(coin,method,json)); return(ramchain_coinparser(coin,method,json));
} }
/*
#define RPCARGS struct iguana_info *coin,struct iguana_wallet *wallet,cJSON *params[],int32_t n,char *origstr,char *remoteaddr
// MAP bitcoin RPC to SuperNET JSONstr
// MAP REST to SuperNET JSONstr
// misc
static char *help(RPCARGS)
{
return(clonestr("{\"result\":\"return help string here\n"));
}
static char *stop(RPCARGS)
{
return(iguana_coinjson(coin,"pausecoin",params[0]));
}
static char *sendalert(RPCARGS)
{
}
static char *SuperNET(RPCARGS)
{
return(iguana_JSON(coin,origstr,remoteaddr));
}
static char *getrawmempool(RPCARGS)
{
}
// peers
static char *getconnectioncount(RPCARGS)
{
int32_t i,num = 0; char buf[128];
for (i=0; i<sizeof(coin->peers.active)/sizeof(*coin->peers.active); i++)
if ( coin->peers.active[i].usock >= 0 )
num++;
sprintf(buf,"{\"result\":\"%d\"}",num);
return(clonestr(buf));
}
static char *getpeerinfo(RPCARGS)
{
cJSON *retjson; char buf[128];
if ( (retjson= iguana_peersjson(coin,0)) != 0 )
return(jprint(retjson,1));
sprintf(buf,"{\"result\":\"%d\"}",coin->blocks.hwmchain.height + 1);
return(clonestr("{\"error\":\"no peers\"}"));
}
static char *addnode(RPCARGS)
{
// addnode <node> <add/remove/onetry> version 0.8 Attempts add or remove <node> from the addnode list or try a connection to <node> once. N
}
// address and pubkeys
int32_t iguana_waddresscalc(struct iguana_info *coin,struct iguana_waddress *addr,bits256 privkey)
{
memset(addr,0,sizeof(*addr));
addr->privkey = privkey;
if ( btc_priv2pub(addr->pubkey,addr->privkey.bytes) == 0 && btc_priv2wip(addr->wipstr,addr->privkey.bytes,coin->chain->wipval) == 0 && btc_pub2rmd(addr->rmd160,addr->pubkey) == 0 && btc_convrmd160(addr->coinaddr,coin->chain->pubval,addr->rmd160) == 0 )
{
addr->wiptype = coin->chain->wipval;
addr->type = coin->chain->pubval;
return(0);
}
return(-1);
}
static char *validateretstr(struct iguana_info *coin,char *coinaddr)
{
char *retstr,buf[512]; cJSON *json;
if ( iguana_addressvalidate(coin,coinaddr) < 0 )
return(clonestr("{\"error\":\"invalid coin address\"}"));
sprintf(buf,"{\"agent\":\"ramchain\",\"coin\":\"%s\",\"method\":\"validate\",\"address\":\"%s\"}",coin->symbol,coinaddr);
if ( (json= cJSON_Parse(buf)) != 0 )
retstr = ramchain_coinparser(coin,"validate",json);
else return(clonestr("{\"error\":\"internal error, couldnt parse validate\"}"));
free_json(json);
return(retstr);
}
static char *validateaddress(RPCARGS)
{
char *coinaddr; cJSON *retjson;
retjson = cJSON_CreateObject();
if ( params[0] != 0 && (coinaddr= jstr(params[0],0)) != 0 )
return(validateretstr(coin,coinaddr));
return(clonestr("{\"error\":\"need coin address\"}"));
}
static char *validatepubkey(RPCARGS)
{
char *pubkeystr,coinaddr[128]; cJSON *retjson;
retjson = cJSON_CreateObject();
if ( params[0] != 0 && (pubkeystr= jstr(params[0],0)) != 0 )
{
if ( btc_coinaddr(coinaddr,coin->chain->pubval,pubkeystr) == 0 )
return(validateretstr(coin,coinaddr));
return(clonestr("{\"error\":\"cant convert pubkey\"}"));
}
return(clonestr("{\"error\":\"need pubkey\"}"));
}
static char *createmultisig(RPCARGS)
{
}
// blockchain
static char *getinfo(RPCARGS)
{
cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"result",coin->statusstr);
return(jprint(retjson,1));
}
static char *getbestblockhash(RPCARGS)
{
char buf[512],str[65];
sprintf(buf,"{\"result\":\"%s\"}",bits256_str(str,coin->blocks.hwmchain.RO.hash2));
return(clonestr(buf));
}
static char *getblockcount(RPCARGS)
{
char buf[512];
sprintf(buf,"{\"result\":\"%d\"}",coin->blocks.hwmchain.height + 1);
return(clonestr(buf));
}
static char *getblock(RPCARGS)
{
}
static char *getblockhash(RPCARGS)
{
}
static char *gettransaction(RPCARGS)
{
}
static char *listtransactions(RPCARGS)
{
}
static char *getreceivedbyaddress(RPCARGS)
{
}
static char *listreceivedbyaddress(RPCARGS)
{
}
static char *listsinceblock(RPCARGS)
{
}
// waccount and waddress funcs
static char *getreceivedbyaccount(RPCARGS)
{
}
static char *listreceivedbyaccount(RPCARGS)
{
}
static char *addmultisigaddress(RPCARGS)
{
}
static char *getnewaddress(RPCARGS)
{
struct iguana_waddress addr; char str[67],*account; cJSON *retjson = cJSON_CreateObject();
if ( iguana_waddresscalc(coin,&addr,rand256(1)) == 0 )
{
jaddstr(retjson,"result",addr.coinaddr);
init_hexbytes_noT(str,addr.pubkey,33);
jaddstr(retjson,"pubkey",str);
jaddstr(retjson,"privkey",bits256_str(str,addr.privkey));
jaddstr(retjson,"wip",addr.wipstr);
init_hexbytes_noT(str,addr.rmd160,20);
jaddstr(retjson,"rmd160",str);
if ( params[0] != 0 && (account= jstr(params[0],0)) != 0 )
{
if ( iguana_waccountadd(coin,account,&addr) < 0 )
jaddstr(retjson,"account","error adding to account");
else jaddstr(retjson,"account",account);
}
} else jaddstr(retjson,"error","cant create address");
return(jprint(retjson,1));
}
static char *makekeypair(RPCARGS)
{
struct iguana_waddress addr; char str[67]; cJSON *retjson = cJSON_CreateObject();
if ( iguana_waddresscalc(coin,&addr,rand256(1)) == 0 )
{
init_hexbytes_noT(str,addr.pubkey,33);
jaddstr(retjson,"result",str);
jaddstr(retjson,"privkey",bits256_str(str,addr.privkey));
} else jaddstr(retjson,"error","cant create address");
return(jprint(retjson,1));
}
static char *getaccountaddress(RPCARGS)
{
struct iguana_waddress *waddr,addr; char str[67]; char *account,*coinaddr; cJSON *retjson;
if ( params[0] != 0 && (coinaddr= jstr(params[0],0)) != 0 )
{
if ( (waddr= iguana_waccountfind(coin,account)) == 0 )
{
if ( (waddr= iguana_waddresscalc(coin,&addr,rand256(1))) == 0 )
return(clonestr("{\"error\":\"cant generate address\"}"));
}
retjson = cJSON_CreateObject();
jaddstr(retjson,"result",waddr->coinaddr);
init_hexbytes_noT(str,addr.pubkey,33);
jaddstr(retjson,"pubkey",str);
jaddstr(retjson,"privkey",bits256_str(str,waddr->privkey));
jaddstr(retjson,"wip",waddr->wipstr);
init_hexbytes_noT(str,waddr->rmd160,20);
jaddstr(retjson,"rmd160",str);
jaddstr(retjson,"account",account);
return(jprint(retjson,1));
}
return(clonestr("{\"error\":\"no account specified\"}"));
}
static char *setaccount(RPCARGS)
{
struct iguana_waddress *waddr,addr; char *account,*coinaddr;
if ( params[0] != 0 && (coinaddr= jstr(params[0],0)) != 0 && params[1] != 0 && (account= jstr(params[1],0)) != 0 )
{
if ( iguana_addressvalidate(coin,coinaddr) < 0 )
return(clonestr("{\"error\":\"invalid coin address\"}"));
if ( (waddr= iguana_waddressfind(coin,coinaddr)) == 0 )
{
if ( (waddr= iguana_waddresscalc(coin,&addr,rand256(1))) == 0 )
return(clonestr("{\"error\":\"cant generate address\"}"));
}
iguana_waccountswitch(coin,waddr,coinaddr);
return(clonestr("{\"result\":\"account set\"}"));
}
return(clonestr("{\"error\":\"need address and account\"}"));
}
static char *getaccount(RPCARGS)
{
struct iguana_waddress *waddr,addr; char *account,*coinaddr; cJSON *retjson;
if ( params[0] != 0 && (coinaddr= jstr(params[0],0)) != 0 )
{
if ( iguana_addressvalidate(coin,coinaddr) < 0 )
return(clonestr("{\"error\":\"invalid coin address\"}"));
if ( (waddr= iguana_waccountfind(coin,account)) == 0 )
return(clonestr("{\"result\":\"no account for address\"}"));
retjson = cJSON_CreateObject();
jaddstr(retjson,"result",waddr->account);
return(jprint(retjson,1));
}
return(clonestr("{\"error\":\"need address\"}"));
}
static char *getaddressesbyaccount(RPCARGS)
{
struct iguana_waccount *subset; char *account; cJSON *retjson,*array;
retjson = cJSON_CreateObject();
if ( params[0] != 0 && (account= jstr(params[0],0)) != 0 )
{
array = cJSON_CreateArray();
if ( (subset= iguana_waccountfind(coin,account)) != 0 )
{
HASH_ITER(hh,subset->waddrs,waddr,tmp)
{
jaddistr(array,waddr->coinaddr);
}
} else jaddstr(retjson,"result","cant find account");
} else jaddstr(retjson,"error","no account specified");
jadd(retjson,"addresses",array);
return(jprint(retjson,1));
}
static char *listaddressgroupings(RPCARGS)
{
}
static char *getbalance(RPCARGS)
{
}
// wallet
static char *listaccounts(RPCARGS)
{
}
static char *dumpprivkey(RPCARGS)
{
}
static char *importprivkey(RPCARGS)
{
}
static char *dumpwallet(RPCARGS)
{
}
static char *importwallet(RPCARGS)
{
}
static char *walletpassphrase(RPCARGS)
{
}
static char *walletpassphrasechange(RPCARGS)
{
}
static char *walletlock(RPCARGS)
{
}
static char *encryptwallet(RPCARGS)
{
}
static char *checkwallet(RPCARGS)
{
}
static char *repairwallet(RPCARGS)
{
}
// messages
static char *signmessage(RPCARGS)
{
}
static char *verifymessage(RPCARGS)
{
}
// unspents
static char *listunspent(RPCARGS)
{
}
static char *lockunspent(RPCARGS)
{
}
static char *listlockunspent(RPCARGS)
{
}
static char *gettxout(RPCARGS)
{
}
static char *gettxoutsetinfo(RPCARGS)
{
}
// payments
static char *sendtoaddress(RPCARGS)
{
struct iguana_waddress *waddr,addr; char *account,*coinaddr,*comment=0,*comment2=0; double amount = -1.;
//sendtoaddress <bitcoinaddress> <amount> [comment] [comment-to] <amount> is a real and is rounded to 8 decimal places. Returns the transaction ID <txid> if successful. Y
if ( params[0] != 0 && (coinaddr= jstr(params[0],0)) != 0 && params[1] != 0 && is_cJSON_Number(params[1]) != 0 )
{
if ( iguana_addressvalidate(coin,coinaddr) < 0 )
return(clonestr("{\"error\":\"invalid coin address\"}"));
amount = jdouble(params[1],0);
comment = jstr(params[2],0);
comment2 = jstr(params[3],0);
printf("need to generate send %.8f to %s [%s] [%s]\n",dstr(amount),coinaddr,comment!=0?comment:"",comment2!=0comment2:"");
}
return(clonestr("{\"error\":\"need address and amount\"}"));
}
static char *move(RPCARGS)
{
}
static char *sendfrom(RPCARGS)
{
}
static char *sendmany(RPCARGS)
{
}
static char *settxfee(RPCARGS)
{
}
// rawtransaction
static char *getrawtransaction(RPCARGS)
{
}
static char *createrawtransaction(RPCARGS)
{
}
static char *decoderawtransaction(RPCARGS)
{
}
static char *decodescript(RPCARGS)
{
}
static char *signrawtransaction(RPCARGS)
{
}
static char *sendrawtransaction(RPCARGS)
{
}
static char *resendtx(RPCARGS)
{
}
static char *getrawchangeaddress(RPCARGS)
{
}
struct RPC_info { char *name; char *(*rpcfunc)(RPCARGS); int32_t flag0,flag1; } RPCcalls[] =
{
{ "help", &help, true, true },
{ "stop", &stop, true, true },
{ "getbestblockhash", &getbestblockhash, true, false },
{ "getblockcount", &getblockcount, true, false },
{ "getconnectioncount", &getconnectioncount, true, false },
{ "getpeerinfo", &getpeerinfo, true, false },
{ "getinfo", &getinfo, true, false },
{ "getnewaddress", &getnewaddress, true, false },
{ "getnewpubkey", &makekeypair, true, false },
{ "getaccountaddress", &getaccountaddress, true, false },
{ "setaccount", &setaccount, true, false },
{ "getaccount", &getaccount, false, false },
{ "getaddressesbyaccount", &getaddressesbyaccount, true, false },
{ "sendtoaddress", &sendtoaddress, false, false },
{ "getreceivedbyaddress", &getreceivedbyaddress, false, false },
{ "getreceivedbyaccount", &getreceivedbyaccount, false, false },
{ "listreceivedbyaddress", &listreceivedbyaddress, false, false },
{ "listreceivedbyaccount", &listreceivedbyaccount, false, false },
{ "backupwallet", &backupwallet, true, false },
{ "walletpassphrase", &walletpassphrase, true, false },
{ "walletpassphrasechange", &walletpassphrasechange, false, false },
{ "walletlock", &walletlock, true, false },
{ "encryptwallet", &encryptwallet, false, false },
{ "validateaddress", &validateaddress, true, false },
{ "validatepubkey", &validatepubkey, true, false },
{ "getbalance", &getbalance, false, false },
{ "move", &movecmd, false, false },
{ "sendfrom", &sendfrom, false, false },
{ "sendmany", &sendmany, false, false },
{ "addmultisigaddress", &addmultisigaddress, false, false },
{ "getblock", &getblock, false, false },
{ "getblockhash", &getblockhash, false, false },
{ "gettransaction", &gettransaction, false, false },
{ "listtransactions", &listtransactions, false, false },
{ "listaddressgroupings", &listaddressgroupings, false, false },
{ "signmessage", &signmessage, false, false },
{ "verifymessage", &verifymessage, false, false },
{ "listaccounts", &listaccounts, false, false },
{ "settxfee", &settxfee, false, false },
{ "listsinceblock", &listsinceblock, false, false },
{ "dumpprivkey", &dumpprivkey, false, false },
{ "SuperNET", &SuperNET, false, false },
{ "dumpwallet", &dumpwallet, true, false },
{ "importwallet", &importwallet, false, false },
{ "importprivkey", &importprivkey, false, false },
{ "listunspent", &listunspent, false, false },
{ "getrawtransaction", &getrawtransaction, false, false },
{ "createrawtransaction", &createrawtransaction, false, false },
{ "decoderawtransaction", &decoderawtransaction, false, false },
{ "decodescript", &decodescript, false, false },
{ "signrawtransaction", &signrawtransaction, false, false },
{ "sendrawtransaction", &sendrawtransaction, false, false },
{ "checkwallet", &checkwallet, false, true},
{ "repairwallet", &repairwallet, false, true},
{ "resendtx", &resendtx, false, true},
{ "makekeypair", &makekeypair, false, true},
{ "sendalert", &sendalert, false, false},
//
{ "addnode", &addnode, false, false},
{ "getrawmempool", &getrawmempool, false, false},
{ "getrawchangeaddress", &getrawchangeaddress, false, false},
{ "listlockunspent", &listlockunspent, false, false},
{ "lockunspent", &lockunspent, false, false},
{ "gettxout", &gettxout, false, false},
{ "gettxoutsetinfo", &gettxoutsetinfo, false, false}]
#ifdef PEGGY
//{ "peggytx", &peggytx, true, false },
//{ "peggypayments", &peggypayments, true, false },
//{ "getpeggyblock", &getpeggyblock, true, false },
#endif
// { "addredeemscript", &addredeemscript, false, false },
// { "getrawmempool", &getrawmempool, true, false },
// { "getdifficulty", &getdifficulty, true, false },
// { "getsubsidy", &getsubsidy, true, false },
// { "getmininginfo", &getmininginfo, true, false },
// { "getstakinginfo", &getstakinginfo, true, false },
// { "getblockbynumber", &getblockbynumber, false, false },
//{ "getwork", &getwork, true, false },
//{ "getworkex", &getworkex, true, false },
// { "keypoolrefill", &keypoolrefill, true, false },
//{ "getblocktemplate", &getblocktemplate, true, false },
//{ "submitblock", &submitblock, false, false },
// { "getcheckpoint", &getcheckpoint, true, false },
// { "reservebalance", &reservebalance, false, true},
};
char *iguana_bitcoinrpc(struct iguana_info *coin,struct iguana_wallet *wallet,char *method,cJSON *params,int32_t n,char *origstr,char *remoteaddr)
{
int32_t i;
for (i=0; i<sizeof(RPCcalls)/sizeof(*RPCcalls); i++)
{
if ( strcmp(RPCcalls[i].name,method) == 0 )
return((*RPCcalls[i].rpcfunc)(coin,wallet,params,n,origstr,remoteaddr));
}
return(clonestr("{\"error\":\"invalid coin address\"}"));
}
char *iguana_bitcoinRPC(struct iguana_info *coin,struct supernet_info *myinfo,char *jsonstr,char *remoteaddr)
{
cJSON *json,*obj0,*params[16]; char *method; int32_t n; char *retstr = 0;
memset(params,0,sizeof(params));
if ( (json= cJSON_Parse(jsonstr)) != 0 )
{
if ( (method= jstr(json,"method")) != 0 )
{
if ( (params= jarray(&n,json,"params")) == 0 )
{
n = 1;
params[0] = jobj(json,"params");
}
else
{
params[0] = jitem(params,0);
if ( n > 1 )
for (i=1; i<n; i++)
params[i] = jitem(params,i);
}
retstr = iguana_bitcoin(coin,myinfo,method,params,n,jsonstr,remoteaddr);
}
free_json(json);
}
if ( retstr == 0 )
retstr = clonestr("{\"error\":\"cant parse jsonstr\"}");
return(retstr);
}
*/

56
iguana/iguana_wallet.c

@ -0,0 +1,56 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* SuperNET software, including this file may be copied, modified, propagated *
* or distributed except according to the terms contained in the LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
#include "iguana777.h"
struct iguana_waccount *iguana_waccountcreate(struct iguana_info *coin,char *account)
{
struct iguana_waccount *waddr; int32_t len = (int32_t)strlen(account)+1;
HASH_FIND(hh,coin->wallet,account,len,waddr);
if ( waddr != 0 )
return(waddr);
waddr = mycalloc('w',1,sizeof(*waddr) + len);
strcpy(waddr->account,account);
HASH_ADD(hh,coin->wallet,account,len,waddr);
return(waddr);
}
struct iguana_waccount *iguana_waccountfind(struct iguana_info *coin,char *account)
{
struct iguana_waccount *waddr;
HASH_FIND(hh,coin->wallet,account,strlen(account)+1,waddr);
return(waddr);
}
struct iguana_waccount *iguana_waccountadd(struct iguana_info *coin,char *walletaccount,struct iguana_waddress *waddr)
{
struct iguana_waccount *acct;
if ( (acct= iguana_waccountfind(coin,walletaccount)) == 0 )
acct = iguana_waccountcreate(coin,walletaccount);
return(acct);
}
int32_t iguana_waccountswitch(struct iguana_info *coin,struct iguana_waddress *waddr,char *coinaddr)
{
// what if coinaddr is already in an account?
//printf("change %s walletaccount.(%s) (%s) <- %s\n",coin->symbol,waddr->account,waddr->coinaddr,coinaddr);
return(0);
}
struct iguana_waddress *iguana_waddressfind(struct iguana_info *coin,char *coinaddr)
{
return(0);
}

10
iguana/mingw

@ -1,12 +1,4 @@
SOURCES := iguana_pubkeys.c iguana_recv.c iguana_bundles.c iguana_msg.c iguana_rpc.c iguana777.c iguana_chains.c iguana_peers.c iguana_accept.c iguana_html.c iguana_bitmap.c iguana_init.c iguana_ramchain.c iguana_blocks.c iguana_json.c ../crypto777/cJSON.c ../crypto777/iguana_utils.c ../crypto777/OS_nonportable.c ../crypto777/curve25519-donna.c ../crypto777/inet.c ../crypto777/OS_portable.c ../crypto777/curve25519.c ../crypto777/libgfshare.c ../crypto777/OS_time.c ../crypto777/hmac_sha512.c ../crypto777/ramcoder.c ../crypto777/SaM.c ../crypto777/iguana_OS.c ../crypto777/iguana_serdes.c ../crypto777/jpeg/jaricom.c ../crypto777/jpeg/jcapimin.c ../crypto777/jpeg/jcapistd.c ../crypto777/jpeg/jcarith.c ../crypto777/jpeg/jccoefct.c ../crypto777/jpeg/jccolor.c \ include iguana.sources
../crypto777/jpeg/jcdctmgr.c ../crypto777/jpeg/jchuff.c ../crypto777/jpeg/jcinit.c ../crypto777/jpeg/jcmainct.c ../crypto777/jpeg/jcmarker.c ../crypto777/jpeg/jcmaster.c \
../crypto777/jpeg/jcomapi.c ../crypto777/jpeg/jcparam.c ../crypto777/jpeg/jcprepct.c ../crypto777/jpeg/jcsample.c ../crypto777/jpeg/jctrans.c ../crypto777/jpeg/jdapimin.c \
../crypto777/jpeg/jdapistd.c ../crypto777/jpeg/jdarith.c ../crypto777/jpeg/jdatadst.c ../crypto777/jpeg/jdatasrc.c ../crypto777/jpeg/jdcoefct.c ../crypto777/jpeg/jdcolor.c \
../crypto777/jpeg/jddctmgr.c ../crypto777/jpeg/jdhuff.c ../crypto777/jpeg/jdinput.c ../crypto777/jpeg/jdmainct.c ../crypto777/jpeg/jdmarker.c ../crypto777/jpeg/jdmaster.c \
../crypto777/jpeg/jdmerge.c ../crypto777/jpeg/jdpostct.c ../crypto777/jpeg/jdsample.c ../crypto777/jpeg/jdtrans.c ../crypto777/jpeg/jerror.c ../crypto777/jpeg/jfdctflt.c \
../crypto777/jpeg/jfdctfst.c ../crypto777/jpeg/jfdctint.c ../crypto777/jpeg/jidctflt.c ../crypto777/jpeg/jidctfst.c ../crypto777/jpeg/jidctint.c ../crypto777/jpeg/jquant1.c \
../crypto777/jpeg/jquant2.c ../crypto777/jpeg/jutils.c ../crypto777/jpeg/jmemmgr.c ../crypto777/jpeg/jmemnobs.c main.c
all: all:
$(TOOL_DIR)/$(MINGW)-gcc -o ../agents/iguana.exe -D __MINGW $(SOURCES) $(LIBS) $(TOOL_DIR)/$(MINGW)-gcc -o ../agents/iguana.exe -D __MINGW $(SOURCES) $(LIBS)

4
includes/cJSON.h

@ -187,6 +187,10 @@ extern "C"
void jdelete(cJSON *object,char *string); void jdelete(cJSON *object,char *string);
cJSON *jduplicate(cJSON *json); cJSON *jduplicate(cJSON *json);
bits256 jbits256(cJSON *json,char *field);
bits256 jbits256i(cJSON *json,int32_t i);
void jaddbits256(cJSON *json,char *field,bits256 hash);
void jaddibits256(cJSON *json,bits256 hash);
void copy_cJSON(struct destbuf *dest,cJSON *obj); void copy_cJSON(struct destbuf *dest,cJSON *obj);
void copy_cJSON2(char *dest,int32_t maxlen,cJSON *obj); void copy_cJSON2(char *dest,int32_t maxlen,cJSON *obj);
cJSON *gen_list_json(char **list); cJSON *gen_list_json(char **list);

Loading…
Cancel
Save