Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
a1fdb702d6
  1. 2
      crypto777/iguana_utils.c
  2. 1
      iguana/SuperNET.h
  3. 4
      iguana/exchanges/bitcoin.c
  4. 10
      iguana/iguana777.h
  5. 29
      iguana/iguana_pubkeys.c
  6. 38
      iguana/iguana_ramchain.c
  7. 8
      iguana/iguana_rpc.c
  8. 12
      iguana/iguana_scripts.c
  9. 43
      iguana/iguana_tx.c
  10. 4
      iguana/iguana_unspents.c
  11. 30
      iguana/iguana_wallet.c
  12. 151
      iguana/ramchain_api.c
  13. 99
      includes/iguana_apideclares.h

2
crypto777/iguana_utils.c

@ -984,7 +984,7 @@ void calc_unhexstr(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len)
void calc_base64_encodestr(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len)
{
nn_base64_encode(msg,len,hexstr,64);
nn_base64_encode(msg,len,hexstr,len);
}
void calc_base64_decodestr(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len)

1
iguana/SuperNET.h

@ -203,6 +203,7 @@ struct supernet_info *SuperNET_accountfind(cJSON *argjson);
int32_t SuperNET_MYINFOS(struct supernet_info **myinfos,int32_t max);
FILE *myfopen(char *fname,char *mode);
int32_t myfclose(FILE *fp);
cJSON *SuperNET_rosettajson(bits256 privkey,int32_t showprivs);
#endif

4
iguana/exchanges/bitcoin.c

@ -407,7 +407,7 @@ int32_t iguana_parsevinobj(struct iguana_info *coin,uint8_t *serialized,int32_t
cJSON *iguana_voutjson(struct iguana_info *coin,struct iguana_msgvout *vout,int32_t txi,bits256 txid)
{
// 035f1321ed17d387e4433b2fa229c53616057964af065f98bfcae2233c5108055e OP_CHECKSIG
char scriptstr[8192+1],asmstr[16384]; int32_t i,m,n,scriptlen,asmtype; struct vin_info *vp;
char scriptstr[IGUANA_MAXSCRIPTSIZE+1],asmstr[2*IGUANA_MAXSCRIPTSIZE+1]; int32_t i,m,n,scriptlen,asmtype; struct vin_info *vp;
uint8_t space[8192]; cJSON *addrs,*skey,*json = cJSON_CreateObject();
vp = calloc(1,sizeof(*vp));
jaddnum(json,"value",dstr(vout->value));
@ -416,7 +416,7 @@ cJSON *iguana_voutjson(struct iguana_info *coin,struct iguana_msgvout *vout,int3
if ( vout->pk_script != 0 && vout->pk_scriptlen*2+1 < sizeof(scriptstr) )
{
memset(vp,0,sizeof(*vp));
if ( (asmtype= iguana_calcrmd160(coin,vp,vout->pk_script,vout->pk_scriptlen,txid,txi,0xffffffff)) >= 0 )
if ( (asmtype= iguana_calcrmd160(coin,asmstr,vp,vout->pk_script,vout->pk_scriptlen,txid,txi,0xffffffff)) >= 0 )
{
skey = cJSON_CreateObject();
scriptlen = iguana_scriptgen(coin,&m,&n,vp->coinaddr,space,asmstr,vp->rmd160,asmtype,vp,txi);

10
iguana/iguana777.h

@ -51,7 +51,7 @@ typedef int32_t (*blockhashfunc)(uint8_t *blockhashp,uint8_t *serialized,int32_t
#define IGUANA_MINPENDBUNDLES 4
#define IGUANA_MAXPENDBUNDLES 64
#ifdef __APPLE__
#define IGUANA_RPCPORT 7778
#define IGUANA_RPCPORT 7779
#else
#define IGUANA_RPCPORT 7778
#endif
@ -577,7 +577,7 @@ int64_t iguana_verifyaccount(struct iguana_info *coin,struct iguana_account *acc
int32_t iguana_initramchain(struct iguana_info *coin,int32_t initialheight,int32_t mapflags,int32_t fullverify);
void iguana_syncramchain(struct iguana_info *coin);
//int32_t iguana_validateramchain(struct iguana_info *coin,int64_t *netp,uint64_t *creditsp,uint64_t *debitsp,int32_t height,struct iguana_block *block,int32_t hwmheight,struct iguana_prevdep *lp);
int32_t iguana_calcrmd160(struct iguana_info *coin,struct vin_info *vp,uint8_t *pk_script,int32_t pk_scriptlen,bits256 debugtxid,int32_t vout,uint32_t sequence);
int32_t iguana_calcrmd160(struct iguana_info *coin,char *asmstr,struct vin_info *vp,uint8_t *pk_script,int32_t pk_scriptlen,bits256 debugtxid,int32_t vout,uint32_t sequence);
uint32_t iguana_updatescript(struct iguana_info *coin,uint32_t blocknum,uint32_t txidind,uint32_t spendind,uint32_t unspentind,uint64_t value,uint8_t *script,int32_t scriptlen,uint32_t sequence);
void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *txdata,struct iguana_msgtx *txarray,struct iguana_msghdr *H,uint8_t *data,int32_t datalen);
int32_t iguana_parseblock(struct iguana_info *coin,struct iguana_block *block,struct iguana_msgtx *tx,int32_t numtx);
@ -902,6 +902,12 @@ int32_t iguana_send_ping(struct iguana_info *coin,struct iguana_peer *addr);
int32_t iguana_process_msgrequestQ(struct iguana_info *coin);
uint32_t iguana_fastfindinit(struct iguana_info *coin);
int32_t iguana_unspentindfind(struct iguana_info *coin,int32_t *heightp,bits256 txid,int32_t vout,int32_t lasthdrsi);
int32_t iguana_addressvalidate(struct iguana_info *coin,uint8_t *addrtypep,uint8_t rmd160[20],char *address);
int32_t bitcoin_sign(uint8_t *sig,int32_t maxlen,uint8_t *data,int32_t datalen,bits256 privkey);
bits256 iguana_str2priv(struct iguana_info *coin,char *str);
int32_t iguana_spentflag(struct iguana_info *coin,int64_t *RTspendp,int32_t *spentheightp,struct iguana_ramchain *ramchain,int16_t spent_hdrsi,uint32_t spent_unspentind,int32_t height,uint64_t amount);
int32_t iguana_voutscript(struct iguana_info *coin,struct iguana_bundle *bp,uint8_t *scriptspace,char *asmstr,struct iguana_unspent *u,struct iguana_pkhash *p,int32_t txi);
cJSON *iguana_unspentjson(struct iguana_info *coin,int32_t hdrsi,uint32_t unspentind,struct iguana_txid *T,struct iguana_unspent *up,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33);
extern int32_t HDRnet,netBLOCKS;

29
iguana/iguana_pubkeys.c

@ -670,14 +670,19 @@ int32_t btc_wif2priv(uint8_t *addrtypep,uint8_t privkey[32],char *wifstr)
cstring *cstr; int32_t len = -1;
if ( (cstr= base58_decode_check(addrtypep,(const char *)wifstr)) != 0 )
{
init_hexbytes_noT((void *)privkey,(void *)cstr->str,cstr->len);
if ( cstr->str[cstr->len-1] == 0x01 )
cstr->len--;
memcpy(privkey,cstr->str,cstr->len);
len = (int32_t)cstr->len;
char tmp[138];
btc_priv2wif(tmp,privkey,*addrtypep);
//printf("addrtype.%02x wifstr.(%llx) privlen.%d\n",*addrtypep,*(long long *)privkey,len);
if ( cstr->len == sizeof(bits256) )
{
memcpy(privkey,cstr->str,cstr->len);
len = (int32_t)cstr->len;
if ( 1 )
{
char tmp[138];
btc_priv2wif(tmp,privkey,*addrtypep);
printf("addrtype.%02x wifstr.(%llx) privlen.%d\n",*addrtypep,*(long long *)privkey,len);
}
}
cstr_free(cstr,true);
}
return(len);
@ -906,18 +911,6 @@ int32_t iguana_sig(uint8_t *sig,int32_t maxsize,uint8_t *data,int32_t datalen,bi
return(0);
}*/
char *makekeypair(struct iguana_info *coin)
{
struct iguana_waddress addr; char str[67]; cJSON *retjson = cJSON_CreateObject();
if ( iguana_waddresscalc(coin->chain->pubtype,coin->chain->wiftype,&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));
}
cJSON *iguana_pubkeyjson(struct iguana_info *coin,char *pubkeystr)
{
cJSON *json = cJSON_CreateObject();

38
iguana/iguana_ramchain.c

@ -273,13 +273,16 @@ uint32_t iguana_ramchain_addunspent20(struct iguana_info *coin,struct iguana_pee
memset(&V,0,sizeof(V));
if ( type < 0 )
{
type = iguana_calcrmd160(coin,&V,script,scriptlen,txid,vout,0xffffffff);
type = iguana_calcrmd160(coin,asmstr,&V,script,scriptlen,txid,vout,0xffffffff);
if ( (type == 12 && scriptlen == 0) || (type == 1 && bitcoin_pubkeylen(script+1) <= 0) )
{
int32_t i; for (i=0; i<scriptlen; i++)
printf("%02x",script[i]);
printf(" script type.%d\n",type);
}
int32_t i; for (i=0; i<scriptlen; i++)
printf("%02x",script[i]);
char str[65]; printf(" type.%d %s\n",type,bits256_str(str,txid));
memcpy(rmd160,V.rmd160,sizeof(V.rmd160));
} //else printf("iguana_ramchain_addunspent20: unexpected non-neg type.%d\n",type);
}
@ -333,13 +336,27 @@ uint32_t iguana_ramchain_addunspent20(struct iguana_info *coin,struct iguana_pee
}
}
u->txidind = ramchain->H.txidind;
int32_t i; for (i=0; i<20; i++)
printf("%02x",rmd160[i]);
printf(" rmd160 ");
for (i=0; i<20; i++)
printf("%02x",u->rmd160[i]);
printf(" u->rmd160\n");
}
return(unspentind);
}
uint32_t iguana_ramchain_addunspent(struct iguana_info *coin,RAMCHAIN_FUNC,uint64_t value,uint16_t hdrsi,uint8_t *rmd160,uint16_t vout,uint8_t type,uint16_t fileid,uint32_t fpos,int32_t scriptlen)
{
uint32_t unspentind; struct iguana_unspent *u; struct iguana_kvitem *ptr; int32_t pkind;//,checklen,metalen; uint8_t _script[IGUANA_MAXSCRIPTSIZE],*checkscript;
uint32_t unspentind; struct iguana_unspent *u; struct iguana_kvitem *ptr; int32_t i,pkind;
for (i=0; i<20; i++)
if ( rmd160[i] != 0 )
break;
if ( i == 20 )
{
printf("iguana_ramchain_addunspent: null rmd160 error\n");
return(0);
}
unspentind = ramchain->H.unspentind++;
u = &Ux[unspentind];
if ( (ptr= iguana_hashfind(ramchain,'P',rmd160)) == 0 )
@ -350,8 +367,10 @@ uint32_t iguana_ramchain_addunspent(struct iguana_info *coin,RAMCHAIN_FUNC,uint6
printf("addunspent error getting pkind\n");
return(0);
}
if ( 0 )
printf("ROflag.%d pkind.%d unspentind.%d script[%d] uoffset.%d %d:%d type.%d A.%p\n",ramchain->H.ROflag,pkind,unspentind,scriptlen,u->scriptpos,ramchain->H.scriptoffset,ramchain->H.data->scriptspace,type,A);
if ( 1 )
{
printf(" ROflag.%d pkind.%d unspentind.%d vout.%d %.8f script[%d] uoffset.%d %d:%d type.%d A.%p\n",ramchain->H.ROflag,pkind,unspentind,vout,dstr(value),scriptlen,u->scriptpos,ramchain->H.scriptoffset,ramchain->H.data->scriptspace,type,A);
}
if ( ramchain->H.ROflag != 0 )
{
/*if ( Kspace != 0 && ((u->scriptoffset != 0 && scriptlen > 0) || type == IGUANA_SCRIPT_76AC) )
@ -754,7 +773,7 @@ int32_t iguana_ramchain_prefetch(struct iguana_info *coin,struct iguana_ramchain
nonz++;
}
}
printf("PREFETCH.[%d] flag.%d -> nonz.%d\n",ramchain->H.data->height,flag,nonz);
//printf("PREFETCH.[%d] flag.%d -> nonz.%d\n",ramchain->H.data->height,flag,nonz);
return(nonz);
}
@ -1684,6 +1703,9 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
//fprintf(stderr,"iter add %p[%d] type.%d\n",scriptdata,scriptlen,type);
if ( iguana_ramchain_addunspent(coin,RAMCHAIN_ARG,value,hdrsi,rmd160,j,type,fileid,(uint32_t)scriptpos,scriptlen) == 0 )
return(-3);
int32_t i; for (i=0; i<20; i++)
printf("%02x",rmd160[i]);
char str[65]; printf(" raw rmd160.A txid.(%s)\n",bits256_str(str,tx->txid));
}
}
else
@ -1706,11 +1728,11 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
printf("%02x",scriptdata[i]);
fprintf(stderr," raw unspent script type.%d U%d offset.%d\n",type,ramchain->H.unspentind,U[ramchain->H.unspentind].scriptoffset);
} //else printf("no script\n");*/
//for (i=0; i<20; i++)
// printf("%02x",rmd160[i]);
//printf(" raw rmd160\n");
if ( iguana_ramchain_addunspent20(coin,0,RAMCHAIN_ARG,value,0,scriptlen,tx->txid,j,type,bp,rmd160) == 0 )
return(-4);
int32_t i; for (i=0; i<20; i++)
printf("%02x",rmd160[i]);
char str[65]; printf(" raw rmd160 txid.(%s)\n",bits256_str(str,tx->txid));
}
if ( dest != 0 )
{

8
iguana/iguana_rpc.c

@ -216,7 +216,7 @@ static char *addmultisigaddress(RPCARGS)
// blockchain
static char *getinfo(RPCARGS)
{
return(sglue(0,CALLGLUE,"bitcoinrpc","status"));
return(sglue(0,CALLGLUE,"bitcoinrpc","getinfo"));
}
static char *getbestblockhash(RPCARGS)
@ -512,6 +512,8 @@ static char *getrawchangeaddress(RPCARGS)
#define false 0
struct RPC_info { char *name; char *(*rpcfunc)(RPCARGS); int32_t flag0,remoteflag; } RPCcalls[] =
{
{ "validatepubkey", &validatepubkey, true, true },
{ "makekeypair", &makekeypair, false, false },
{ "listunspent", &listunspent, false, false },
{ "getblockhash", &getblockhash, false, true },
{ "walletpassphrase", &walletpassphrase, true, false },
@ -540,7 +542,6 @@ struct RPC_info { char *name; char *(*rpcfunc)(RPCARGS); int32_t flag0,remotefla
{ "walletlock", &walletlock, true, false },
{ "encryptwallet", &encryptwallet, false, false },
{ "validateaddress", &validateaddress, true, true },
{ "validatepubkey", &validatepubkey, true, true },
{ "getbalance", &getbalance, false, false },
{ "move", &movecmd, false, false },
{ "sendfrom", &sendfrom, false, false },
@ -567,7 +568,6 @@ struct RPC_info { char *name; char *(*rpcfunc)(RPCARGS); int32_t flag0,remotefla
{ "sendrawtransaction", &sendrawtransaction, false, true },
{ "checkwallet", &checkwallet, false, false },
{ "repairwallet", &repairwallet, false, false },
{ "makekeypair", &makekeypair, false, false },
{ "sendalert", &sendalert, false, false },
//
{ "createmultisig", &createmultisig, false, false },
@ -654,6 +654,8 @@ char *iguana_bitcoinRPC(struct supernet_info *myinfo,char *method,cJSON *json,ch
if ( i == IGUANA_MAXCOINS )
coin = 0;
}
if ( coin == 0 && symbol != 0 && symbol[0] != 0 )
coin = iguana_coinfind(symbol);
//printf("method.(%s) (%s) remote.(%s) symbol.(%s)\n",method,jprint(json,0),remoteaddr,symbol);
if ( method != 0 && symbol != 0 && (coin != 0 || (coin= iguana_coinfind(symbol)) != 0) )
{

12
iguana/iguana_scripts.c

@ -682,9 +682,9 @@ int32_t _iguana_calcrmd160(struct iguana_info *coin,struct vin_info *vp)
return(type);
}
int32_t iguana_calcrmd160(struct iguana_info *coin,struct vin_info *vp,uint8_t *pk_script,int32_t pk_scriptlen,bits256 debugtxid,int32_t vout,uint32_t sequence)
int32_t iguana_calcrmd160(struct iguana_info *coin,char *asmstr,struct vin_info *vp,uint8_t *pk_script,int32_t pk_scriptlen,bits256 debugtxid,int32_t vout,uint32_t sequence)
{
int32_t scriptlen; uint8_t script[IGUANA_MAXSCRIPTSIZE]; char asmstr[IGUANA_MAXSCRIPTSIZE*3];
int32_t scriptlen; uint8_t script[IGUANA_MAXSCRIPTSIZE];
memset(vp,0,sizeof(*vp));
vp->vin.prev_hash = debugtxid, vp->vin.prev_vout = vout;
vp->spendlen = pk_scriptlen;
@ -693,6 +693,12 @@ int32_t iguana_calcrmd160(struct iguana_info *coin,struct vin_info *vp,uint8_t *
if ( (vp->type= _iguana_calcrmd160(coin,vp)) >= 0 )
{
scriptlen = iguana_scriptgen(coin,&vp->M,&vp->N,vp->coinaddr,script,asmstr,vp->rmd160,vp->type,(const struct vin_info *)vp,vout);
if ( vp->M == 0 && vp->N == 0 )
{
vp->M = vp->N = 1;
strcpy(vp->signers[0].coinaddr,vp->coinaddr);
memcpy(vp->signers[0].rmd160,vp->rmd160,20);
}
if ( scriptlen != pk_scriptlen || (scriptlen != 0 && memcmp(script,pk_script,scriptlen) != 0) )
{
if ( vp->type != IGUANA_SCRIPT_OPRETURN && vp->type != IGUANA_SCRIPT_DATA && vp->type != IGUANA_SCRIPT_STRANGE )
@ -1114,7 +1120,7 @@ int32_t iguana_scriptspaceraw(struct iguana_info *coin,int32_t *scriptspacep,int
for (j=0; j<tx->tx_out; j++)
{
memset(&V,0,sizeof(V));
type = iguana_calcrmd160(coin,&V,tx->vouts[j].pk_script,tx->vouts[j].pk_scriptlen,tx->txid,j,0xffffffff);
type = iguana_calcrmd160(coin,asmstr,&V,tx->vouts[j].pk_script,tx->vouts[j].pk_scriptlen,tx->txid,j,0xffffffff);
if ( type != 0 ) // IGUANA_SCRIPT_NULL
{
memcpy(rmd160,V.rmd160,sizeof(rmd160));

43
iguana/iguana_tx.c

@ -91,34 +91,39 @@ int32_t iguana_vinset(struct iguana_info *coin,uint8_t *scriptspace,int32_t heig
else return(vin->scriptlen);
}
int32_t iguana_voutset(struct iguana_info *coin,uint8_t *scriptspace,char *asmstr,int32_t height,struct iguana_msgvout *vout,struct iguana_txid *tx,int32_t i)
int32_t iguana_voutscript(struct iguana_info *coin,struct iguana_bundle *bp,uint8_t *scriptspace,char *asmstr,struct iguana_unspent *u,struct iguana_pkhash *p,int32_t txi)
{
struct vin_info V; char fname[1024],coinaddr[65]; int32_t scriptlen = -1;
if ( u->scriptpos > 0 && u->scriptlen > 0 )
{
iguana_voutsfname(coin,bp->ramchain.from_ro,fname,u->fileid);
if ( (scriptlen= iguana_scriptdata(coin,scriptspace,coin->peers.voutptrs[u->fileid],fname,u->scriptpos,u->scriptlen)) != u->scriptlen )
printf("%d bytes from fileid.%d[%d] %s for type.%d\n",u->scriptlen,u->fileid,u->scriptpos,fname,u->type);
}
else
{
memset(&V,0,sizeof(V));
scriptlen = iguana_scriptgen(coin,&V.M,&V.N,coinaddr,scriptspace,asmstr,p->rmd160,u->type,(const struct vin_info *)&V,txi);
}
return(scriptlen);
}
int32_t iguana_voutset(struct iguana_info *coin,uint8_t *scriptspace,char *asmstr,int32_t height,struct iguana_msgvout *vout,struct iguana_txid *tx,int32_t txi)
{
struct iguana_ramchaindata *rdata; uint32_t unspentind,scriptlen = 0; struct iguana_bundle *bp;
struct iguana_unspent *u,*U; char coinaddr[65]; struct iguana_pkhash *P,*p; struct vin_info V;
char fname[1024]; int32_t err = 0;
struct iguana_unspent *u,*U; struct iguana_pkhash *P; int32_t err = 0;
memset(vout,0,sizeof(*vout));
if ( height >= 0 && height < coin->chain->bundlesize*coin->bundlescount && (bp= coin->bundles[height / coin->chain->bundlesize]) != 0 && (rdata= bp->ramchain.H.data) != 0 && i < tx->numvouts )
if ( height >= 0 && height < coin->chain->bundlesize*coin->bundlescount && (bp= coin->bundles[height / coin->chain->bundlesize]) != 0 && (rdata= bp->ramchain.H.data) != 0 && txi < tx->numvouts )
{
U = (void *)(long)((long)rdata + rdata->Uoffset);
P = (void *)(long)((long)rdata + rdata->Poffset);
unspentind = (tx->firstvout + i);
unspentind = (tx->firstvout + txi);
u = &U[unspentind];
if ( u->txidind != tx->txidind || u->vout != i || u->hdrsi != height / coin->chain->bundlesize )
printf("iguana_voutset: txidind mismatch %d vs %d || %d vs %d || (%d vs %d)\n",u->txidind,u->txidind,u->vout,i,u->hdrsi,height / coin->chain->bundlesize);
p = &P[u->pkind];
if ( u->txidind != tx->txidind || u->vout != txi || u->hdrsi != height / coin->chain->bundlesize )
printf("iguana_voutset: txidind mismatch %d vs %d || %d vs %d || (%d vs %d)\n",u->txidind,u->txidind,u->vout,txi,u->hdrsi,height / coin->chain->bundlesize);
vout->value = u->value;
vout->pk_script = scriptspace;
if ( u->scriptpos > 0 && u->scriptlen > 0 )
{
iguana_voutsfname(coin,bp->ramchain.from_ro,fname,u->fileid);
if ( (scriptlen= iguana_scriptdata(coin,scriptspace,coin->peers.voutptrs[u->fileid],fname,u->scriptpos,u->scriptlen)) != u->scriptlen )
printf("error.%d %d bytes from fileid.%d[%d] %s for u%d type.%d\n",err,u->scriptlen,u->fileid,u->scriptpos,fname,unspentind,u->type);
}
else
{
memset(&V,0,sizeof(V));
scriptlen = iguana_scriptgen(coin,&V.M,&V.N,coinaddr,scriptspace,asmstr,p->rmd160,u->type,(const struct vin_info *)&V,i);
}
scriptlen = iguana_voutscript(coin,bp,scriptspace,asmstr,u,&P[u->pkind],txi);
} else printf("iguana_voutset unexpected path\n");
vout->pk_scriptlen = scriptlen;
if ( err != 0 )

4
iguana/iguana_unspents.c

@ -861,6 +861,8 @@ static int _bignum_cmp(const void *a,const void *b)
uint32_t iguana_fastfindinit(struct iguana_info *coin)
{
int32_t i,j,iter,num,tablesize,*hashtable; uint8_t *sorted; char fname[1024];
if ( strcmp("BTC",coin->symbol) != 0 )
return(0);
for (iter=0; iter<2; iter++)
{
for (i=0; i<0x100; i++)
@ -1098,7 +1100,7 @@ cJSON *iguana_unspentjson(struct iguana_info *coin,int32_t hdrsi,uint32_t unspen
jaddnum(item,"amount",dstr(up->value));
if ( (checkind= iguana_unspentindfind(coin,&height,T[up->txidind].txid,up->vout,coin->bundlescount-1)) != 0 )
{
jaddnum(item,"confirmations",coin->longestchain - height);
jaddnum(item,"confirmations",coin->blocks.hwmchain.height - height);
jaddnum(item,"checkind",checkind);
}
if ( (wacct= iguana_waddressfind(coin,&ind,coinaddr)) != 0 )

30
iguana/iguana_wallet.c

@ -264,6 +264,21 @@ char *jsuccess()
return(jprint(retjson,1));
}
bits256 iguana_str2priv(struct iguana_info *coin,char *str)
{
bits256 privkey; int32_t ind,n; uint8_t addrtype; struct iguana_waccount *wacct;
n = (int32_t)strlen(str) >> 1;
memset(&privkey,0,sizeof(privkey));
if ( n == sizeof(bits256) && is_hexstr(str,sizeof(bits256)) > 0 )
decode_hex(privkey.bytes,sizeof(privkey),str);
else if ( btc_wif2priv(&addrtype,privkey.bytes,str) != sizeof(bits256) )
{
if ( (wacct= iguana_waddressfind(coin,&ind,str)) != 0 )
privkey = wacct->waddrs[ind].privkey;
}
return(privkey);
}
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
@ -322,7 +337,18 @@ ZERO_ARGS(bitcoinrpc,getinfo)
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
retjson = cJSON_CreateObject();
jaddstr(retjson,"result",coin->statusstr);
if ( coin != 0 )
{
jaddstr(retjson,"result","success");
jaddnum(retjson,"protocolversion",PROTOCOL_VERSION);
jaddnum(retjson,"blocks",coin->blocks.hwmchain.height);
jaddnum(retjson,"longestchain",coin->longestchain);
jaddnum(retjson,"port",coin->chain->portp2p);
jaddnum(retjson,"connections",coin->peers.numranked);
jaddnum(retjson,"difficulty",coin->blocks.hwmchain.PoW);
jaddstr(retjson,"status",coin->statusstr);
jaddstr(retjson,"coin",coin->symbol);
}
return(jprint(retjson,1));
}
@ -488,6 +514,7 @@ SS_D_I_SS(bitcoinrpc,sendfrom,fromaccount,toaddress,amount,minconf,comment,comme
return(clonestr("{\"error\":\"no remote\"}"));
return(jsuccess());
}
DOUBLE_ARG(bitcoinrpc,settxfee,amount)
{
cJSON *retjson = cJSON_CreateObject();
@ -506,7 +533,6 @@ S_A_I_S(bitcoinrpc,sendmany,fromaccount,array,minconf,comment)
return(jprint(retjson,1));
}
// entire wallet funcs
TWO_INTS(bitcoinrpc,listaccounts,minconf,includewatchonly)
{

151
iguana/ramchain_api.c

@ -221,14 +221,35 @@ ZERO_ARGS(bitcoinrpc,getblockcount)
ZERO_ARGS(bitcoinrpc,makekeypair)
{
cJSON *retjson = cJSON_CreateObject();
bits256 privkey; char str[67]; cJSON *retjson = cJSON_CreateObject();
privkey = rand256(1);
jaddstr(retjson,"result","success");
jaddstr(retjson,"privkey",bits256_str(str,privkey));
jadd(retjson,"rosetta",SuperNET_rosettajson(privkey,1));
return(jprint(retjson,1));
}
STRING_ARG(bitcoinrpc,validatepubkey,pubkey)
STRING_ARG(bitcoinrpc,validatepubkey,pubkeystr)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
uint8_t rmd160[20],pubkey[65],addrtype = 0; int32_t plen; char coinaddr[128],*str; cJSON *retjson;
plen = (int32_t)strlen(pubkeystr) >> 1;
if ( plen <= 65 && coin != 0 && coin->chain != 0 )
{
addrtype = coin->chain->pubtype;
decode_hex(pubkey,plen,pubkeystr);
if ( (str= bitcoin_address(coinaddr,addrtype,pubkey,plen)) != 0 )
{
if ( iguana_addressvalidate(coin,&addrtype,rmd160,coinaddr) < 0 )
return(clonestr("{\"error\":\"invalid coin address\"}"));
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddstr(retjson,"pubkey",pubkeystr);
jaddstr(retjson,"address",coinaddr);
jaddstr(retjson,"coin",coin->symbol);
return(jprint(retjson,1));
}
}
return(clonestr("{\"error\":\"invalid pubkey\"}"));
}
HASH_AND_TWOINTS(bitcoinrpc,listsinceblock,blockhash,target,flag)
@ -237,21 +258,124 @@ HASH_AND_TWOINTS(bitcoinrpc,listsinceblock,blockhash,target,flag)
return(jprint(retjson,1));
}
STRING_ARG(bitcoinrpc,decodescript,script)
cJSON *iguana_scriptobj(struct iguana_info *coin,uint8_t rmd160[20],char *coinaddr,char *asmstr,uint8_t *script,int32_t scriptlen)
{
cJSON *retjson = cJSON_CreateObject();
struct vin_info V; int32_t i,plen,asmtype; char pubkeystr[130],rmdstr[41]; cJSON *addrobj,*scriptobj=0;
if ( (asmtype= iguana_calcrmd160(coin,asmstr,&V,script,scriptlen,rand256(1),1,0xffffffff)) >= 0 )
{
if ( asmstr != 0 && asmstr[0] != 0 )
jaddstr(scriptobj,"asm",asmstr);
jaddnum(scriptobj,"iguanatype",asmtype);
jaddnum(scriptobj,"scriptlen",scriptlen);
jaddnum(scriptobj,"reqSigs",V.M);
if ( (plen= bitcoin_pubkeylen(V.signers[0].pubkey)) > 0 )
{
init_hexbytes_noT(pubkeystr,V.signers[0].pubkey,plen);
jaddstr(scriptobj,"pubkey",pubkeystr);
init_hexbytes_noT(rmdstr,V.signers[0].rmd160,20);
jaddstr(scriptobj,"rmd160",rmdstr);
}
addrobj = cJSON_CreateArray();
for (i=0; i<V.N; i++)
jaddistr(addrobj,V.signers[i].coinaddr);
jadd(scriptobj,"addresses",addrobj);
if ( V.p2shlen != 0 )
jaddstr(scriptobj,"p2sh",V.coinaddr);
strcpy(coinaddr,V.coinaddr);
memcpy(rmd160,V.rmd160,20);
}
return(scriptobj);
}
STRING_ARG(bitcoinrpc,decodescript,scriptstr)
{
int32_t scriptlen; uint8_t script[IGUANA_MAXSCRIPTSIZE],rmd160[20]; char coinaddr[128],asmstr[IGUANA_MAXSCRIPTSIZE*2+1]; cJSON *scriptobj,*retjson = cJSON_CreateObject();
if ( coin != 0 && (scriptlen= (int32_t)strlen(scriptstr)>>1) < sizeof(script) )
{
decode_hex(script,scriptlen,scriptstr);
if ( (scriptobj= iguana_scriptobj(coin,rmd160,coinaddr,asmstr,script,scriptlen)) != 0 )
jadd(retjson,"result",scriptobj);
}
return(jprint(retjson,1));
}
STRING_ARG(bitcoinrpc,vanitygen,vanity)
HASH_AND_TWOINTS(bitcoinrpc,gettxout,txid,vout,mempool)
{
cJSON *retjson = cJSON_CreateObject();
uint8_t script[IGUANA_MAXSCRIPTSIZE],rmd160[20],pubkey33[33]; char coinaddr[128],asmstr[IGUANA_MAXSCRIPTSIZE*2+1]; struct iguana_bundle *bp; int32_t scriptlen,unspentind,height,spentheight; int64_t RTspend; struct iguana_ramchaindata *rdata; struct iguana_pkhash *P; struct iguana_txid *T; struct iguana_unspent *U; struct iguana_ramchain *ramchain; cJSON *scriptobj,*retjson = cJSON_CreateObject();
if ( coin != 0 )
{
if ( (unspentind= iguana_unspentindfind(coin,&height,txid,vout,coin->bundlescount-1)) != 0 )
{
if ( height >= 0 && height < coin->longestchain && (bp= coin->bundles[height / coin->chain->bundlesize]) != 0 )
{
ramchain = (bp == coin->current) ? &coin->RTramchain : &bp->ramchain;
if ( (rdata= ramchain->H.data) != 0 )
{
U = (void *)(long)((long)rdata + rdata->Uoffset);
P = (void *)(long)((long)rdata + rdata->Poffset);
T = (void *)(long)((long)rdata + rdata->Toffset);
RTspend = 0;
if ( iguana_spentflag(coin,&RTspend,&spentheight,ramchain,bp->hdrsi,unspentind,height,U[unspentind].value) == 0 )
{
jaddbits256(retjson,"bestblock",coin->blocks.hwmchain.RO.hash2);
jaddnum(retjson,"bestheight",coin->blocks.hwmchain.height);
jaddnum(retjson,"height",height);
jaddnum(retjson,"confirmations",coin->blocks.hwmchain.height - height);
jaddnum(retjson,"value",dstr(U[unspentind].value));
memset(rmd160,0,sizeof(rmd160));
memset(pubkey33,0,sizeof(pubkey33));
memset(coinaddr,0,sizeof(coinaddr));
if ( (scriptlen= iguana_voutscript(coin,bp,script,0,&U[unspentind],&P[U[unspentind].pkind],vout)) > 0 )
{
if ( (scriptobj= iguana_scriptobj(coin,rmd160,coinaddr,asmstr,script,scriptlen)) != 0 )
jadd(retjson,"scriptPubKey",scriptobj);
}
jadd(retjson,"iguana",iguana_unspentjson(coin,bp->hdrsi,unspentind,T,&U[unspentind],rmd160,coinaddr,pubkey33));
if ( (height % coin->chain->bundlesize) == 0 && vout == 0 )
jadd(retjson,"coinbase",jtrue());
else jadd(retjson,"coinbase",jfalse());
}
else
{
jaddstr(retjson,"error","already spent");
jaddnum(retjson,"spentheight",spentheight);
jaddnum(retjson,"unspentind",unspentind);
}
}
}
}
}
return(jprint(retjson,1));
}
TWO_STRINGS(bitcoinrpc,signmessage,address,message)
TWO_STRINGS(bitcoinrpc,signmessage,address,messagestr)
{
cJSON *retjson = cJSON_CreateObject();
bits256 privkey; int32_t n,len,siglen; char sigstr[256],sig64str[256]; uint8_t sig[128],*message=0; cJSON *retjson = cJSON_CreateObject();
if ( coin != 0 )
{
privkey = iguana_str2priv(coin,address);
if ( bits256_nonz(privkey) != 0 )
{
n = (int32_t)strlen(messagestr) >> 1;
if ( messagestr[0] == '0' && messagestr[1] == 'x' && is_hexstr(messagestr+2,n-2) > 0 )
{
message = malloc(n-2);
decode_hex(message,n-2,messagestr+2);
n -= 2;
} else message = (uint8_t *)messagestr, n <<= 1;
if ( (siglen= bitcoin_sign(sig,sizeof(sig),message,n,privkey)) > 0 )
{
sigstr[0] = sig64str[0] = 0;
//init_hexbytes_noT(sigstr,sig,siglen);
len = nn_base64_encode(sig,siglen,sig64str,sizeof(sig64str));
sig64str[len++] = '=';
sig64str[len++] = 0;
jaddstr(retjson,"result",sig64str);
}
if ( message != (void *)messagestr )
free(message);
} else jaddstr(retjson,"error","invalid address (can be wif, wallet address or privkey hex)");
}
return(jprint(retjson,1));
}
@ -299,12 +423,6 @@ ZERO_ARGS(bitcoinrpc,listlockunspent)
return(jprint(retjson,1));
}
HASH_AND_TWOINTS(bitcoinrpc,gettxout,txid,vout,mempool)
{
cJSON *retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
TWOINTS_AND_ARRAY(bitcoinrpc,listunspent,minconf,maxconf,array)
{
int32_t numrmds; uint8_t *rmdarray; cJSON *retjson = cJSON_CreateArray();
@ -325,7 +443,6 @@ STRING_AND_INT(bitcoinrpc,getreceivedbyaddress,address,minconf)
return(jprint(retjson,1));
}
// single address/account funcs
ZERO_ARGS(bitcoinrpc,getrawchangeaddress)
{

99
includes/iguana_apideclares.h

@ -13,79 +13,74 @@
* *
******************************************************************************/
TWOINTS_AND_ARRAY(bitcoinrpc,listunspent,minconf,maxconf,array);
HASH_AND_STRING(bitcoinrpc,verifytx,txid,txbytes);
ZERO_ARGS(bitcoinrpc,getinfo);
ZERO_ARGS(bitcoinrpc,getblockcount);
ZERO_ARGS(bitcoinrpc,getbestblockhash);
INT_ARG(bitcoinrpc,getblockhash,height);
HASH_AND_TWOINTS(bitcoinrpc,getblock,blockhash,verbose,remoteonly);
HASH_AND_INT(bitcoinrpc,getrawtransaction,txid,verbose);
HASH_ARG(bitcoinrpc,gettransaction,txid);
STRING_ARG(bitcoinrpc,decodescript,script);
STRING_ARG(bitcoinrpc,decoderawtransaction,rawtx);
TWO_ARRAYS(bitcoinrpc,createrawtransaction,vins,vouts); //
STRING_AND_TWOARRAYS(bitcoinrpc,signrawtransaction,rawtx,vins,privkeys); //
STRING_AND_INT(bitcoinrpc,sendrawtransaction,rawtx,allowhighfees); //
ZERO_ARGS(bitcoinrpc,getinfo);
ZERO_ARGS(bitcoinrpc,getbestblockhash);
ZERO_ARGS(bitcoinrpc,getblockcount);
ZERO_ARGS(bitcoinrpc,listaddressgroupings);
ZERO_ARGS(bitcoinrpc,makekeypair);
ZERO_ARGS(bitcoinrpc,gettxoutsetinfo);
ZERO_ARGS(bitcoinrpc,listlockunspent);
ZERO_ARGS(bitcoinrpc,getrawchangeaddress);
HASH_AND_TWOINTS(bitcoinrpc,gettxout,txid,vout,mempool); //
TWOINTS_AND_ARRAY(bitcoinrpc,listunspent,minconf,maxconf,array);
HASH_AND_TWOINTS(bitcoinrpc,listsinceblock,blockhash,target,flag); //
TWO_INTS(bitcoinrpc,listaccounts,minconf,includewatchonly);
THREE_INTS(bitcoinrpc,listreceivedbyaddress,minconf,includeempty,flag);
SS_D_I_S(bitcoinrpc,move,fromaccount,toaccount,amount,minconf,comment); //
SS_D_I_SS(bitcoinrpc,sendfrom,fromaccount,toaddress,amount,minconf,comment,comment2); //
S_A_I_S(bitcoinrpc,sendmany,fromaccount,array,minconf,comment); //
S_D_SS(bitcoinrpc,sendtoaddress,address,amount,comment,comment2); //
ZERO_ARGS(bitcoinrpc,makekeypair);
STRING_ARG(bitcoinrpc,validatepubkey,pubkey);
STRING_ARG(bitcoinrpc,validateaddress,address);
ZERO_ARGS(bitcoinrpc,walletlock);
ZERO_ARGS(bitcoinrpc,checkwallet);
ZERO_ARGS(bitcoinrpc,repairwallet);
STRING_ARG(bitcoinrpc,dumpwallet,filename);
STRING_ARG(bitcoinrpc,backupwallet,filename);
TWOSTRINGS_AND_INT(bitcoinrpc,walletpassphrase,password,permanentfile,timeout);
THREE_STRINGS(bitcoinrpc,encryptwallet,passphrase,password,permanentfile);
FOUR_STRINGS(bitcoinrpc,walletpassphrasechange,oldpassword,newpassword,oldpermanentfile,permanentfile);
STRING_ARG(bitcoinrpc,importwallet,filename);
TWOSTRINGS_AND_INT(bitcoinrpc,walletpassphrase,password,permanentfile,timeout);
STRING_ARG(bitcoinrpc,validateaddress,address);
STRING_ARG(bitcoinrpc,validatepubkey,pubkey);
STRING_ARG(bitcoinrpc,getnewaddress,account);
STRING_ARG(bitcoinrpc,vanitygen,vanity);
// accounts
STRING_ARG(bitcoinrpc,getnewaddress,account); //
TWOSTRINGS_AND_INT(bitcoinrpc,importprivkey,wif,account,rescan); //
STRING_ARG(bitcoinrpc,dumpprivkey,address); //
INT_ARRAY_STRING(bitcoinrpc,createmultisig,M,array,account); //
STRING_AND_THREEINTS(bitcoinrpc,listtransactions,account,count,skip,includewatchonly);
THREE_INTS(bitcoinrpc,listreceivedbyaddress,minconf,includeempty,flag);
THREE_INTS(bitcoinrpc,listreceivedbyaccount,confirmations,includeempty,watchonly);
TWO_INTS(bitcoinrpc,listaccounts,minconf,includewatchonly);
ZERO_ARGS(bitcoinrpc,listaddressgroupings);
STRING_AND_INT(bitcoinrpc,getreceivedbyaddress,address,minconf);
STRING_AND_INT(bitcoinrpc,getreceivedbyaccount,account,includeempty);
THREE_INTS(bitcoinrpc,getbalance,confirmations,includeempty,watchonly);
STRING_ARG(bitcoinrpc,getaddressesbyaccount,account);
STRING_ARG(bitcoinrpc,getaccount,address);
STRING_ARG(bitcoinrpc,getaccountaddress,account);
STRING_ARG(bitcoinrpc,dumpprivkey,address);
STRING_ARG(bitcoinrpc,decodescript,script);
TWO_STRINGS(bitcoinrpc,setaccount,address,account);
TWO_STRINGS(bitcoinrpc,signmessage,address,message);
THREE_STRINGS(bitcoinrpc,verifymessage,address,sig,message);
THREE_INTS(bitcoinrpc,listreceivedbyaccount,confirmations,includeempty,watchonly);
THREE_INTS(bitcoinrpc,getbalance,confirmations,includeempty,watchonly);
TWOSTRINGS_AND_INT(bitcoinrpc,importprivkey,wif,account,rescan);
STRING_AND_INT(bitcoinrpc,getreceivedbyaccount,account,includeempty);
STRING_AND_INT(bitcoinrpc,getreceivedbyaddress,address,minconf);
STRING_AND_INT(bitcoinrpc,sendrawtransaction,rawtx,allowhighfees);
HASH_AND_TWOINTS(bitcoinrpc,listsinceblock,blockhash,target,flag);
STRING_AND_THREEINTS(bitcoinrpc,listtransactions,account,count,skip,includewatchonly);
HASH_AND_TWOINTS(bitcoinrpc,gettxout,txid,vout,mempool);
DOUBLE_ARG(bitcoinrpc,settxfee,amount);
// maybe later
TWO_STRINGS(bitcoinrpc,signmessage,address,message); //
THREE_STRINGS(bitcoinrpc,verifymessage,address,sig,message); //
ZERO_ARGS(bitcoinrpc,gettxoutsetinfo);
INT_AND_ARRAY(bitcoinrpc,lockunspent,flag,array);
INT_ARRAY_STRING(bitcoinrpc,createmultisig,M,array,account);
TWO_ARRAYS(bitcoinrpc,createrawtransaction,vins,vouts);
STRING_AND_TWOARRAYS(bitcoinrpc,signrawtransaction,rawtx,vins,privkeys);
SS_D_I_S(bitcoinrpc,move,fromaccount,toaccount,amount,minconf,comment);
SS_D_I_SS(bitcoinrpc,sendfrom,fromaccount,toaddress,amount,minconf,comment,comment2);
S_A_I_S(bitcoinrpc,sendmany,fromaccount,array,minconf,comment);
S_D_SS(bitcoinrpc,sendtoaddress,address,amount,comment,comment2);
ZERO_ARGS(bitcoinrpc,listlockunspent);
ZERO_ARGS(bitcoinrpc,getrawchangeaddress);
ZERO_ARGS(bitcoinrpc,checkwallet);
ZERO_ARGS(bitcoinrpc,repairwallet);
STRING_ARG(bitcoinrpc,dumpwallet,filename);
STRING_ARG(bitcoinrpc,backupwallet,filename);
STRING_ARG(bitcoinrpc,importwallet,filename);
DOUBLE_ARG(bitcoinrpc,settxfee,amount);
STRING_ARG(iguana,initfastfind,activecoin);
STRING_ARG(iguana,peers,activecoin);

Loading…
Cancel
Save