Browse Source

test

pull/4/head
jl777 8 years ago
parent
commit
1e9d15c61c
  1. 63
      src/komodo_notary.h
  2. 44
      src/rpcblockchain.cpp

63
src/komodo_notary.h

@ -13,7 +13,7 @@
* *
******************************************************************************/
const char *Notaries[][2] =
const char *Notaries_genesis[][2] =
{
{ "jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" },
{ "jl777_testB", "02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344" },
@ -60,18 +60,6 @@ struct knotary_entry { UT_hash_handle hh; uint8_t pubkey[33],notaryid; };
struct knotaries_entry { int32_t height,numnotaries; struct knotary_entry *Notaries; } Pubkeys[10000];
struct notarized_checkpoint { uint256 notarized_hash,notarized_desttxid; int32_t nHeight,notarized_height; } *NPOINTS; int32_t NUM_NPOINTS;
int32_t komodo_ratify_threshold(int32_t height,uint64_t signedmask)
{
int32_t numnotaries,i,wt = 0;
numnotaries = Pubkeys[height / KOMODO_ELECTION_GAP].numnotaries;
for (i=0; i<numnotaries; i++)
if ( ((1LL << i) & signedmask) != 0 )
wt++;
if ( wt > (numnotaries >> 1) || (wt > 7 && (signedmask & 3) != 0) )
return(1); // N/2+1 || N/3 + devsig
else return(0);
}
void komodo_nutxoadd(int32_t height,int32_t notaryid,uint256 txhash,uint64_t voutmask,int32_t numvouts)
{
struct nutxo_entry *np;
@ -84,7 +72,7 @@ void komodo_nutxoadd(int32_t height,int32_t notaryid,uint256 txhash,uint64_t vou
np->voutmask = voutmask;
np->notaryid = notaryid;
HASH_ADD_KEYPTR(hh,NUTXOS,&np->txhash,sizeof(np->txhash),np);
printf("Add NUTXO[%d] <- %s notaryid.%d t%u %s %llx\n",Num_nutxos,Notaries[notaryid][0],notaryid,komodo_txtime(txhash),txhash.ToString().c_str(),(long long)voutmask);
//printf("Add NUTXO[%d] <- %s notaryid.%d t%u %s %llx\n",Num_nutxos,Notaries[notaryid][0],notaryid,komodo_txtime(txhash),txhash.ToString().c_str(),(long long)voutmask);
Num_nutxos++;
pthread_mutex_unlock(&komodo_mutex);
}
@ -101,6 +89,42 @@ int32_t komodo_nutxofind(int32_t height,uint256 txhash,int32_t vout)
return(-1);
}
int32_t komodo_ratify_threshold(int32_t height,uint64_t signedmask)
{
int32_t htind,numnotaries,i,wt = 0;
if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 1 )
htind = 0;
numnotaries = Pubkeys[htind].numnotaries;
for (i=0; i<numnotaries; i++)
if ( ((1LL << i) & signedmask) != 0 )
wt++;
if ( wt > (numnotaries >> 1) || (wt > 7 && (signedmask & 3) != 0) )
return(1);
else return(0);
}
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height)
{
int32_t i,htind,n; uint64_t mask = 0; struct knotary_entry *kp,*tmp;
if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 1 )
htind = 0;
pthread_mutex_lock(&komodo_mutex);
n = Pubkeys[htind].num;
HASH_ITER(hh,Pubkeys[htind].Notaries,kp,tmp)
{
if ( kp->notaryid < n )
{
mask |= (1LL << kp->notaryid);
memcpy(pubkeys[kp->notaryid],kp->pubkey,33);
}
}
pthread_mutex_unlock(&komodo_mutex);
if ( mask == ((1LL << n)-1) )
return(n);
printf("error retrieving notaries ht.%d got mask.%llx for n.%d\n",height,(long long)mask,n);
return(-1);
}
void komodo_notarysinit(int32_t height,uint8_t pubkeys[64][33],int32_t num)
{
int32_t k,i,htind; struct knotary_entry *kp; struct knotaries_entry N;
@ -120,8 +144,7 @@ void komodo_notarysinit(int32_t height,uint8_t pubkeys[64][33],int32_t num)
}
}
N.numnotaries = num;
htind = KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP;
if ( htind == 1 )
if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 1 )
htind = 0;
for (i=htind; i<sizeof(Pubkeys)/sizeof(*Pubkeys); i++)
{
@ -134,16 +157,18 @@ void komodo_notarysinit(int32_t height,uint8_t pubkeys[64][33],int32_t num)
int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33)
{
// -1 if not notary, 0 if notary, 1 if special notary
struct knotary_entry *kp; int32_t numnotaries,modval = -1;
struct knotary_entry *kp; int32_t numnotaries,htind,modval = -1;
*notaryidp = -1;
if ( height < 0 || height/KOMODO_ELECTION_GAP >= sizeof(Pubkeys)/sizeof(*Pubkeys) )
return(-1);
if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 1 )
htind = 0;
pthread_mutex_lock(&komodo_mutex);
HASH_FIND(hh,Pubkeys[height/KOMODO_ELECTION_GAP].Notaries,pubkey33,33,kp);
HASH_FIND(hh,Pubkeys[htind].Notaries,pubkey33,33,kp);
pthread_mutex_unlock(&komodo_mutex);
if ( kp != 0 )
{
if ( (numnotaries= Pubkeys[height/KOMODO_ELECTION_GAP].numnotaries) > 0 )
if ( (numnotaries= Pubkeys[htind].numnotaries) > 0 )
{
*notaryidp = kp->notaryid;
modval = ((height % numnotaries) == kp->notaryid);

44
src/rpcblockchain.cpp

@ -384,6 +384,50 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin
uint32_t komodo_txtime(uint256 hash);
uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume);
int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *base,char *rel);
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height);
char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len);
Value notaries(const Array& params, bool fHelp)
{
if ( fHelp || params.size() != 1 )
throw runtime_error("notaries height\n");
LOCK(cs_main);
int32_t n,height = atoi(params[0].get_str().c_str());
if ( height < 0 || height > chainActive.Height() )
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
else
{
Array a; Object item; int32_t i,j,n,m; char *hexstr; std::string hex,addr; uint8_t pubkeys[64][33]; char btcaddr[64],kmdaddr[64],*ptr;
hex.resize(67);
if ( (n= komodo_notaries(pubkeys,height)) > 0 )
{
for (i=0; i<n; i++)
{
std::string btcaddress,kmdaddress;
bitcoin_address(btcaddr,0,pubkeys[i],33);
m = (int32_t)strlen(btcaddr);
btcaddress.resize(m+1);
ptr = (char *)btcaddress.data();
strcpy(ptr,btcaddr);
bitcoin_address(kmdaddr,60,pubkeys[i],33);
m = (int32_t)strlen(kmdaddr);
kmdaddress.resize(m+1);
ptr = (char *)kmdaddress.data();
strcpy(ptr,kmdaddr);
hexstr = (char *)hex.data();
for (j=0; j<33; j++)
sprintf(&hexstr[j*2],"%02x",pubkeys[i][j]);
hexstr[j*2] = 0;
item.push_back(Pair("pubkey", hex));
item.push_back(Pair("BTCaddress", btcaddress));
item.push_back(Pair("KMDaddress", kmdaddress));
a.push_back(item);
}
}
ret.push_back(Pair("notaries", a));
}
return ret;
}
Value paxprice(const Array& params, bool fHelp)
{

Loading…
Cancel
Save