Browse Source

Merge pull request #376 from jl777/spvdex

Spvdex
etomic
jl777 7 years ago
committed by GitHub
parent
commit
e3ba28acb1
  1. 10
      iguana/dpow/dpow_network.c
  2. 6
      iguana/exchanges/LP_nativeDEX.c
  3. 2
      iguana/iguana777.h
  4. 28
      iguana/iguana_mofn.c
  5. 14
      iguana/iguana_notary.c
  6. 8
      iguana/main.c

10
iguana/dpow/dpow_network.c

@ -170,7 +170,7 @@ int32_t signed_nn_recv(void **freeptrp,struct supernet_info *myinfo,uint8_t nota
vcalc_sha256(0,packethash.bytes,(void *)&sigpacket->nonce,(int32_t)(sigpacket->packetlen+sizeof(sigpacket->nonce)+sizeof(sigpacket->packetlen)));
if ( bits256_cmp(packethash,sigpacket->packethash) == 0 && sigpacket->packethash.bytes[0] == 0 )
{
if ( bitcoin_recoververify(myinfo->ctx,"nnrecv",sigpacket->sig64,sigpacket->packethash,pubkey33,33) == 0 )
if ( bitcoin_recoververify(myinfo->ctx[1],"nnrecv",sigpacket->sig64,sigpacket->packethash,pubkey33,33) == 0 )
{
char *notary0 = "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828";
// expand to official notaries
@ -2020,7 +2020,7 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo
pfd.events = NN_POLLOUT;
if ( nn_poll(&pfd,1,100) > 0 )
{
sentbytes = signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->dpowsock,np,size);
sentbytes = signed_nn_send(myinfo,myinfo->ctx[2],myinfo->persistent_priv,myinfo->dpowsock,np,size);
break;
}
usleep(1000);
@ -2168,13 +2168,13 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo)
//printf("REP got %d crc.%08x\n",size,calc_crc32(0,(void *)dexp,size));
if ( (retstr= dex_response(&broadcastflag,myinfo,dexp)) != 0 )
{
signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->repsock,retstr,(int32_t)strlen(retstr)+1);
signed_nn_send(myinfo,myinfo->ctx[1],myinfo->persistent_priv,myinfo->repsock,retstr,(int32_t)strlen(retstr)+1);
//printf("send back[%ld]\n",strlen(retstr)+1);
free(retstr);
if ( broadcastflag != 0 )
{
printf("BROADCAST dexp request.[%d]\n",size);
signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->dexsock,dexp,size);
signed_nn_send(myinfo,myinfo->ctx[1],myinfo->persistent_priv,myinfo->dexsock,dexp,size);
//signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->pubsock,dexp,size);
}
}
@ -2183,7 +2183,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo)
if ( (m= myinfo->numdpowipbits) > 0 )
{
r = myinfo->dpowipbits[rand() % m];
signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->repsock,&r,sizeof(r));
signed_nn_send(myinfo,myinfo->ctx[1],myinfo->persistent_priv,myinfo->repsock,&r,sizeof(r));
printf("REP.%08x <- rand ip m.%d %x\n",dexp->crc32,m,r);
} else printf("illegal state without dpowipbits?\n");
if ( dex_packetcheck(myinfo,dexp,size) == 0 )

6
iguana/exchanges/LP_nativeDEX.c

@ -19,14 +19,14 @@
// marketmaker
//
// dPoW security -> 4: KMD notarized, 5: BTC notarized
// dICO allocation script
// sign critical api calls (pubkey reg, listunspent, orders?)
//
// process stats.log local file
// verify portfolio, pricearray, interest to KMD withdraw
// handles <-> pubkeys
// deal with offline pubkeys, reputations, etc.
//
// alice only coins GAME UNO BTM ANC: GAME BTCD PPC RDD XZC POT EAC FTC BASH SPR WDC UNO XPM XCN BELA CHC DIME MEC NAUT MED AUR MAX DGC RIC EB3 DOT BTM GEO ANC CANN ICASH WBB SRC PTC ADZ TIPS EQT START EFL FST FJC NYC GCN
// verify portfolio, pricearray, interest to KMD withdraw
#include <stdio.h>

2
iguana/iguana777.h

@ -150,7 +150,7 @@ struct supernet_info
struct queueitem *DEX_quotes; cJSON *Cunspents,*Cspends;
struct basilisk_swap *swaps[256]; int32_t numswaps;
struct basilisk_message *messagetable; portable_mutex_t messagemutex; queue_t msgQ,p2pQ;
void *ctx;
void *ctx[4];
uint8_t *pingbuf;
struct basilisk_request DEXaccept;
FILE *dexfp;

28
iguana/iguana_mofn.c

@ -238,19 +238,35 @@ int32_t gfshare_test(struct supernet_info *myinfo,int32_t M,int32_t N,int32_t da
return ok!=1;
}
void *bitcoin_ctx()
{
void *ptr;
ptr = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
secp256k1_pedersen_context_initialize(ptr);
secp256k1_rangeproof_context_initialize(ptr);
return(ptr);
}
void iguana_fixsecp(struct supernet_info *myinfo)
{
myinfo->ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
secp256k1_pedersen_context_initialize(myinfo->ctx);
secp256k1_rangeproof_context_initialize(myinfo->ctx);
int32_t i;
for (i=0; i<sizeof(myinfo->ctx)/sizeof(*myinfo->ctx); i++)
{
myinfo->ctx[i] = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
secp256k1_pedersen_context_initialize(myinfo->ctx[i]);
secp256k1_rangeproof_context_initialize(myinfo->ctx[i]);
}
}
void libgfshare_init(struct supernet_info *myinfo,uint8_t _logs[256],uint8_t _exps[510])
{
uint32_t i,x = 1;
myinfo->ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
secp256k1_pedersen_context_initialize(myinfo->ctx);
secp256k1_rangeproof_context_initialize(myinfo->ctx);
for (i=0; i<sizeof(myinfo->ctx)/sizeof(*myinfo->ctx); i++)
{
myinfo->ctx[i] = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
secp256k1_pedersen_context_initialize(myinfo->ctx[i]);
secp256k1_rangeproof_context_initialize(myinfo->ctx[i]);
}
for (i=0; i<255; i++)
{
_exps[i] = x;

14
iguana/iguana_notary.c

@ -60,14 +60,14 @@ void dpow_checkpointset(struct supernet_info *myinfo,struct dpow_checkpoint *che
int32_t dpow_txhasnotarization(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid)
{
cJSON *txobj,*vins,*vin,*vouts,*vout,*spentobj,*sobj; char *hexstr; uint8_t script[35]; bits256 spenttxid; int32_t i,j,numnotaries,len,spentvout,numvins,numvouts,hasnotarization = 0;
cJSON *txobj,*vins,*vin,*vouts,*vout,*spentobj,*sobj; char *hexstr; uint8_t script[35]; bits256 spenttxid; uint64_t notarymask; int32_t i,j,numnotaries,len,spentvout,numvins,numvouts,hasnotarization = 0;
if ( (txobj= dpow_gettransaction(myinfo,coin,txid)) != 0 )
{
if ( (vins= jarray(&numvins,txobj,"vin")) != 0 )
{
if ( numvins >= DPOW_MIN_ASSETCHAIN_SIGS )
{
numnotaries = 0;
notarymask = numnotaries = 0;
for (i=0; i<numvins; i++)
{
vin = jitem(vins,i);
@ -90,9 +90,13 @@ int32_t dpow_txhasnotarization(struct supernet_info *myinfo,struct iguana_info *
{
if ( strncmp(Notaries_elected[j][1],hexstr+2,66) == 0 )
{
printf("n%d ",j);
numnotaries++;
break;
if ( ((1LL << j) & notarymask) == 0 )
{
printf("n%d ",j);
numnotaries++;
notarymask |= (1LL << j);
break;
}
}
}
}

8
iguana/main.c

@ -71,13 +71,17 @@ int32_t SuperNET_str2hex(uint8_t *hex,char *str)
void SuperNET_hex2str(char *str,uint8_t *hex,int32_t len)
{
init_hexbytes_noT(str,hex,len);
init_hexbytes_noT(str,hex,len);
}
void *bitcoin_ctx();
struct supernet_info *SuperNET_MYINFO(char *passphrase)
{
if ( MYINFO.ctx == 0 )
int32_t i;
if ( MYINFO.ctx[0] == 0 )
{
for (i=0; i<sizeof(MYINFO.ctx)/sizeof(*MYINFO.ctx); i++)
MYINFO.ctx[i] = bitcoin_ctx();
OS_randombytes(MYINFO.privkey.bytes,sizeof(MYINFO.privkey));
MYINFO.myaddr.pubkey = curve25519(MYINFO.privkey,curve25519_basepoint9());
printf("SuperNET_MYINFO: generate session keypair\n");

Loading…
Cancel
Save