Merge pull request #127 from jl777/beta

Beta
This commit is contained in:
jl777
2017-01-23 15:04:54 +02:00
committed by GitHub
68 changed files with 1772 additions and 107 deletions

View File

@@ -26,6 +26,9 @@ cd komodo
git checkout dev
./zcutil/build-mac.sh
```
To build a distributable version of komodo then run the makeDistrib.sh script after building.
When you are done building, you need to do a few things in the [Configuration](https://github.com/zcash/zcash/wiki/1.0-User-Guide#configuration) section of the Zcash User Guide differently because we are on the Mac. All instances of `~/.zcash` need to be replaced by `~/Library/Application\ Support/Zcash`
The fetch-params.sh script, however, has already been altered to fetch the proving keys into the correct directory to conform to Mac specific naming conventions.

35
makeDistrib.sh Executable file
View File

@@ -0,0 +1,35 @@
#!/bin/sh
TMP_DIR=~/tmp/komodo
# make a tmp directory
mkdir -p $TMP_DIR
echo "making $TMP_DIR"
binaries=("komodo-cli" "komodod")
for binary in "${binaries[@]}";
do
echo "copying $binary to $TMP_DIR"
cp src/$binary $TMP_DIR
# find the dylibs to copy for komodod
DYLIBS=`otool -L $TMP_DIR/$binary | grep "/usr/local" | awk -F' ' '{ print $1 }'`
echo "copying $DYLIBS to $TMP_DIR"
# copy the dylibs to the tmpdir
for dylib in $DYLIBS; do cp -rf $dylib $TMP_DIR/; done
# modify komodod to point to dylibs
echo "modifying $binary to use local libraries"
for dylib in $DYLIBS; do install_name_tool -change $dylib @executable_path/`basename $dylib` $TMP_DIR/$binary; done;
done

View File

@@ -5443,7 +5443,7 @@ fiat/revs sendtoaddress RURYZ8FhS5oJ1h1xuv78EXe8rA32SiM4Dy 304.32862968
fiat/revs sendtoaddress RGba6AJogyFQGuMAzD1czE67KR6eW5PV2k 304.98070893
fiat/revs sendtoaddress RXMtwrMXyimRU5CWSdtWzHwWmcCeAc62ua 306.73973391
fiat/revs sendtoaddress RYEmXCS9D2qR71XKzzWbsiAMZGg5E2UWt3 307.15599818
fiat/revs sendtoaddress RWM3UrsRP4WtH6DTetm5KmUyBASvFCV6wH 313.40690770
fiat/revs sendtoaddress RWM3UrsRP4WtH6DTetm5KmUyBASvFCV6wH 3005.5069077
fiat/revs sendtoaddress RL4hFVzdntZQ2DM59QXZc619boZV45YFdk 316.05434626
fiat/revs sendtoaddress RG3vbi2TJp9jeqn8qDSnL1W5eFUeTGQJmu 317.33569076
fiat/revs sendtoaddress RQYgriDwRUuUbfw3E1AecAHZXryGSx1BdN 337.23469627
@@ -5587,7 +5587,7 @@ fiat/revs sendtoaddress RWU752dM2s3sjpPZCaWpihUEYmbL6m7Pne 2537.07064054
fiat/revs sendtoaddress RTCq8NorFo4bNwUTNnyKg9YwYgxH49SbbY 2556.94031291
fiat/revs sendtoaddress RNiUNTzDtBgQyA64txPH3W7gMXAjJriM1T 2597.18712886
fiat/revs sendtoaddress RHuJvZphT6ZhKP3hxCRDDsCnNmCMtDy43r 2603.59182293
fiat/revs sendtoaddress RKxJ7a2J8faQ7VD5dAyFFjMU9DxMDFqv3D 2692.10000000
fiat/revs sendtoaddress RKxJ7a2J8faQ7VD5dAyFFjMU9DxMDFqv3D 1.10000000
fiat/revs sendtoaddress RGyC2cGKrTbv1zQq4f6fbMc2byCNdUAwBX 2700.00000000
fiat/revs sendtoaddress RWJPh9C4WQGuT8UDMXb4u278Teqzcq3zQt 2784.22122603
fiat/revs sendtoaddress RNjNREuiLJ3D5eWGqLcsMvjno5RBsBxqKN 2894.22787069

View File

@@ -15,37 +15,70 @@ echo $pubkey
./komodod -pubkey=$pubkey -ac_name=BOTS -ac_supply=999999 -addnode=78.47.196.146 $1 -gen &
./komodod -pubkey=$pubkey -ac_name=MGW -ac_supply=999999 -addnode=78.47.196.146 $1 -gen &
./komodod -pubkey=$pubkey -ac_name=MVP -ac_supply=1000000 -addnode=78.47.196.146 $1 -gen &
./komodod -pubkey=$pubkey -ac_name=WIRELESS -ac_supply=21000000 -addnode=78.47.196.146 $1 -gen &
./komodod -pubkey=$pubkey -ac_name=KV -ac_supply=1000000 -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=USD -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=EUR -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=JPY -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=GBP -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=AUD -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=CAD -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=CHF -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=NZD -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=CNY -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=RUB -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=MXN -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=BRL -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=INR -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=HKD -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=TRY -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=ZAR -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=PLN -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=NOK -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=SEK -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=DKK -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=CZK -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=HUF -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=ILS -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=KRW -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=MYR -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=PHP -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=RON -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=SGD -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=THB -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=BGN -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=IDR -addnode=78.47.196.146 $1 -gen &
sleep 10
./komodod -pubkey=$pubkey -ac_name=HRK -addnode=78.47.196.146 $1 -gen &

View File

@@ -17,6 +17,8 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BOTS\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MGW\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MVP\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"WIRELESS\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"KV\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"USD\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"EUR\",\"pubkey\":\"$pubkey\"}"

View File

@@ -44,3 +44,5 @@ echo shark; fiat/shark $1 $2 $3 $4
echo bots; fiat/bots $1 $2 $3 $4
echo mgw; fiat/mgw $1 $2 $3 $4
echo mvp; fiat/mvp $1 $2 $3 $4
echo wireless; fiat/wireless $1 $2 $3 $4
echo kv; fiat/kv $1 $2 $3 $4

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=AUD $1 $2 $3 $4
./komodo-cli -ac_name=AUD $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=BET $1 $2 $3 $4
./komodo-cli -ac_name=BET $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=BGN $1 $2 $3 $4
./komodo-cli -ac_name=BGN $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=BOTS $1 $2 $3 $4
./komodo-cli -ac_name=BOTS $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=BRL $1 $2 $3 $4
./komodo-cli -ac_name=BRL $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=CAD $1 $2 $3 $4
./komodo-cli -ac_name=CAD $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=CHF $1 $2 $3 $4
./komodo-cli -ac_name=CHF $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=CNY $1 $2 $3 $4
./komodo-cli -ac_name=CNY $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=CRYPTO $1 $2 $3 $4
./komodo-cli -ac_name=CRYPTO $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=CZK $1 $2 $3 $4
./komodo-cli -ac_name=CZK $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=DEX $1 $2 $3 $4
./komodo-cli -ac_name=DEX $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=DKK $1 $2 $3 $4
./komodo-cli -ac_name=DKK $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=EUR $1 $2 $3 $4
./komodo-cli -ac_name=EUR $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=GBP $1 $2 $3 $4
./komodo-cli -ac_name=GBP $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=HKD $1 $2 $3 $4
./komodo-cli -ac_name=HKD $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=HODL $1 $2 $3 $4
./komodo-cli -ac_name=HODL $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=HRK $1 $2 $3 $4
./komodo-cli -ac_name=HRK $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=HUF $1 $2 $3 $4
./komodo-cli -ac_name=HUF $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=IDR $1 $2 $3 $4
./komodo-cli -ac_name=IDR $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=ILS $1 $2 $3 $4
./komodo-cli -ac_name=ILS $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=INR $1 $2 $3 $4
./komodo-cli -ac_name=INR $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=JPY $1 $2 $3 $4
./komodo-cli -ac_name=JPY $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=JUMBLR $1 $2 $3 $4
./komodo-cli -ac_name=JUMBLR $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=KRW $1 $2 $3 $4
./komodo-cli -ac_name=KRW $1 $2 $3 $4 $5 $6

2
src/fiat/kv Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=KV $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=MGW $1 $2 $3 $4
./komodo-cli -ac_name=MGW $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=MVP $1 $2 $3 $4
./komodo-cli -ac_name=MVP $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=MXN $1 $2 $3 $4
./komodo-cli -ac_name=MXN $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=MYR $1 $2 $3 $4
./komodo-cli -ac_name=MYR $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=NOK $1 $2 $3 $4
./komodo-cli -ac_name=NOK $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=NZD $1 $2 $3 $4
./komodo-cli -ac_name=NZD $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=PANGEA $1 $2 $3 $4
./komodo-cli -ac_name=PANGEA $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=PHP $1 $2 $3 $4
./komodo-cli -ac_name=PHP $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=PLN $1 $2 $3 $4
./komodo-cli -ac_name=PLN $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=REVS $1 $2 $3 $4
./komodo-cli -ac_name=REVS $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=RON $1 $2 $3 $4
./komodo-cli -ac_name=RON $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=RUB $1 $2 $3 $4
./komodo-cli -ac_name=RUB $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=SEK $1 $2 $3 $4
./komodo-cli -ac_name=SEK $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=SGD $1 $2 $3 $4
./komodo-cli -ac_name=SGD $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=SHARK $1 $2 $3 $4
./komodo-cli -ac_name=SHARK $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=SUPERNET $1 $2 $3 $4
./komodo-cli -ac_name=SUPERNET $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=THB $1 $2 $3 $4
./komodo-cli -ac_name=THB $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=TRY $1 $2 $3 $4
./komodo-cli -ac_name=TRY $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=USD $1 $2 $3 $4
./komodo-cli -ac_name=USD $1 $2 $3 $4 $5 $6

2
src/fiat/wireless Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=WIRELESS $1 $2 $3 $4 $5 $6

View File

@@ -1,2 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=ZAR $1 $2 $3 $4
./komodo-cli -ac_name=ZAR $1 $2 $3 $4 $5 $6

View File

@@ -19,10 +19,6 @@
// Todo:
// verify: reorgs
// non komodod (non-hardfork) todo:
// a. automate notarization fee payouts
// b. automated distribution of test REVS snapshot
#define KOMODO_ASSETCHAINS_WAITNOTARIZE
#define KOMODO_PAXMAX (10000 * COIN)
@@ -40,6 +36,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block);
#include "komodo_structs.h"
#include "komodo_globals.h"
#include "komodo_utils.h"
#include "komodo_curve25519.h"
#include "cJSON.c"
#include "komodo_bitcoind.h"
@@ -48,6 +45,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block);
#include "komodo_notary.h"
int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char *dest);
#include "komodo_kv.h"
#include "komodo_gateway.h"
#include "komodo_events.h"
@@ -191,8 +189,13 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char
void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint32_t KMDtimestamp,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout)
{
static FILE *fp; static int32_t errs;
static FILE *fp; static int32_t errs,didinit;
struct komodo_state *sp; char fname[512],symbol[16],dest[16]; int32_t ht,func; uint8_t num,pubkeys[64][33];
if ( didinit == 0 )
{
portable_mutex_init(&KOMODO_KV_mutex);
didinit = 1;
}
if ( (sp= komodo_stateptr(symbol,dest)) == 0 )
{
KOMODO_INITDONE = (uint32_t)time(NULL);
@@ -255,7 +258,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
errs++;
if ( fwrite(opretbuf,1,olen,fp) != olen )
errs++;
//printf("ht.%d R opret[%d]\n",height,olen);
//printf("ht.%d R opret[%d] sp.%p\n",height,olen,sp);
//komodo_opreturn(height,opretvalue,opretbuf,olen,txhash,vout);
komodo_eventadd_opreturn(sp,symbol,height,txhash,opretvalue,vout,opretbuf,olen);
}
@@ -380,7 +383,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid);
len += iguana_rwnum(0,&scriptbuf[len],sizeof(*notarizedheightp),(uint8_t *)notarizedheightp);
len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid);
if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height )
if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && (height < sp->CURRENT_HEIGHT-1000 || komodo_verifynotarization(ASSETCHAINS_SYMBOL[0]==0?(char *)"KMD":ASSETCHAINS_SYMBOL,(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "BTC" : "KMD"),height,*notarizedheightp,kmdtxid,desttxid) == 0) )
{
sp->NOTARIZED_HEIGHT = *notarizedheightp;
sp->NOTARIZED_HASH = kmdtxid;
@@ -413,7 +416,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen-len+4+3+(scriptbuf[1] == 0x4d),j);
}
}
} else printf("notarized.%d %llx reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",notarized,(long long)signedmask,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]);
} else printf("notarized.%d %llx reject ht.%d NOTARIZED.%d prev.%d %s.%s DESTTXID.%s (%s)\n",notarized,(long long)signedmask,height,*notarizedheightp,sp->NOTARIZED_HEIGHT,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]);
}
else if ( i == 0 && j == 1 && opretlen == 149 )
{

View File

@@ -346,6 +346,82 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port)
return(retstr2);
}
int32_t komodo_verifynotarizedscript(int32_t height,uint8_t *script,int32_t len,uint256 NOTARIZED_HASH)
{
int32_t i; uint256 hash; char params[256];
for (i=0; i<32; i++)
((uint8_t *)&hash)[i] = script[2+i];
if ( hash == NOTARIZED_HASH )
return(0);
for (i=0; i<32; i++)
printf("%02x",((uint8_t *)&NOTARIZED_HASH)[i]);
printf(" notarized, ");
for (i=0; i<32; i++)
printf("%02x",((uint8_t *)&hash)[i]);
printf(" opreturn from [%s] ht.%d\n",ASSETCHAINS_SYMBOL,height);
return(-1);
}
int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t NOTARIZED_HEIGHT,uint256 NOTARIZED_HASH,uint256 NOTARIZED_DESTTXID)
{
char params[256],*jsonstr,*hexstr; uint8_t script[8192]; int32_t n,len,retval = -1; cJSON *json,*txjson,*vouts,*vout,*skey;
/*params[0] = '[';
params[1] = '"';
for (i=0; i<32; i++)
sprintf(&params[i*2 + 2],"%02x",((uint8_t *)&NOTARIZED_DESTTXID)[31-i]);
strcat(params,"\", 1]");*/
sprintf(params,"[\"%s\", 1]",NOTARIZED_DESTTXID.ToString().c_str());
if ( strcmp(symbol,ASSETCHAINS_SYMBOL[0]==0?(char *)"KMD":ASSETCHAINS_SYMBOL) != 0 )
return(0);
//printf("[%s] src.%s dest.%s params.[%s] ht.%d notarized.%d\n",ASSETCHAINS_SYMBOL,symbol,dest,params,height,NOTARIZED_HEIGHT);
if ( strcmp(dest,"KMD") == 0 )
{
if ( KMDUSERPASS[0] != 0 )
jsonstr = komodo_issuemethod(KMDUSERPASS,(char *)"getrawtransaction",params,7771);
//else jsonstr = _dex_getrawtransaction();
else return(0); // need universal way to issue DEX* API, since notaries mine most blocks, this ok
}
else if ( strcmp(dest,"BTC") == 0 )
{
if ( BTCUSERPASS[0] != 0 )
{
//printf("BTCUSERPASS.(%s)\n",BTCUSERPASS);
jsonstr = komodo_issuemethod(BTCUSERPASS,(char *)"getrawtransaction",params,8332);
}
//else jsonstr = _dex_getrawtransaction();
else return(0);
}
else
{
printf("[%s] verifynotarization error unexpected dest.(%s)\n",ASSETCHAINS_SYMBOL,dest);
return(-1);
}
if ( jsonstr != 0 )
{
if ( (json= cJSON_Parse(jsonstr)) != 0 )
{
if ( (txjson= jobj(json,(char *)"result")) != 0 && (vouts= jarray(&n,txjson,(char *)"vout")) > 0 )
{
vout = jitem(vouts,n-1);
//printf("vout.(%s)\n",jprint(vout,0));
if ( (skey= jobj(vout,(char *)"scriptPubKey")) != 0 )
{
if ( (hexstr= jstr(skey,(char *)"hex")) != 0 )
{
//printf("HEX.(%s)\n",hexstr);
len = strlen(hexstr) >> 1;
decode_hex(script,len,hexstr);
retval = komodo_verifynotarizedscript(height,script,len,NOTARIZED_HASH);
}
}
}
free_json(txjson);
}
free(jsonstr);
}
return(retval);
}
uint256 komodo_getblockhash(int32_t height)
{
uint256 hash; char params[128],*hexstr,*jsonstr; cJSON *result; int32_t i; uint8_t revbuf[32];

1005
src/komodo_curve25519.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -39,14 +39,19 @@ struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char
void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t height,char *dest,uint256 notarized_hash,uint256 notarized_desttxid,int32_t notarizedheight)
{
struct komodo_event_notarized N;
memset(&N,0,sizeof(N));
N.blockhash = notarized_hash;
N.desttxid = notarized_desttxid;
N.notarizedheight = notarizedheight;
strcpy(N.dest,dest);
komodo_eventadd(sp,height,symbol,KOMODO_EVENT_NOTARIZED,(uint8_t *)&N,sizeof(N));
if ( sp != 0 )
komodo_notarized_update(sp,height,notarizedheight,notarized_hash,notarized_desttxid);
if ( komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid) != 0 )
printf("[%s] error validating notarization ht.%d notarized_height.%d\n",ASSETCHAINS_SYMBOL,height,notarizedheight);
else
{
memset(&N,0,sizeof(N));
N.blockhash = notarized_hash;
N.desttxid = notarized_desttxid;
N.notarizedheight = notarizedheight;
strcpy(N.dest,dest);
komodo_eventadd(sp,height,symbol,KOMODO_EVENT_NOTARIZED,(uint8_t *)&N,sizeof(N));
if ( sp != 0 )
komodo_notarized_update(sp,height,notarizedheight,notarized_hash,notarized_desttxid);
}
}
void komodo_eventadd_pubkeys(struct komodo_state *sp,char *symbol,int32_t height,uint8_t num,uint8_t pubkeys[64][33])

View File

@@ -673,15 +673,15 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above
const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout,char *source)
{
uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff;
uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,kvheight,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fee,fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff;
const char *typestr = "unknown";
if ( KOMODO_PAX == 0 )
return("nopax");
if ( ASSETCHAINS_SYMBOL[0] != 0 && komodo_baseid(ASSETCHAINS_SYMBOL) < 0 )
if ( ASSETCHAINS_SYMBOL[0] != 0 && komodo_baseid(ASSETCHAINS_SYMBOL) < 0 && opretbuf[0] != 'K' )
{
//printf("komodo_opreturn skip %s\n",ASSETCHAINS_SYMBOL);
return("assetchain");
}
//else if ( KOMODO_PAX == 0 )
// return("nopax");
memset(baseids,0xff,sizeof(baseids));
memset(values,0,sizeof(values));
memset(srcvalues,0,sizeof(srcvalues));
@@ -689,7 +689,11 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
memset(kmdheights,0,sizeof(kmdheights));
memset(otherheights,0,sizeof(otherheights));
tokomodo = (komodo_is_issuer() == 0);
if ( opretbuf[0] == 'D' )
if ( opretbuf[0] == 'K' && opretlen != 40 )
{
komodo_kvupdate(opretbuf,opretlen,value);
}
else if ( opretbuf[0] == 'D' )
{
tokomodo = 0;
if ( opretlen == 38 ) // any KMD tx
@@ -763,7 +767,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
}
}
}
else if ( kmdheight > 91800 )
else if ( kmdheight > 91800 && strcmp(base,ASSETCHAINS_SYMBOL) == 0 )
printf("pax %s deposit %.8f rejected kmdheight.%d %.8f KMD\n",base,dstr(fiatoshis),kmdheight,dstr(value));
}
}
@@ -819,11 +823,11 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
}
else if ( opretbuf[0] == 'W' )//&& opretlen >= 38 )
{
if ( komodo_baseid((char *)&opretbuf[opretlen-4]) >= 0 )
if ( komodo_baseid((char *)&opretbuf[opretlen-4]) >= 0 && strcmp("KMD",(char *)&opretbuf[opretlen-4]) != 0 )
{
for (i=0; i<opretlen; i++)
printf("%02x",opretbuf[i]);
printf(" reject obsolete withdraw request\n");
printf(" [%s] reject obsolete withdraw request.%s\n",ASSETCHAINS_SYMBOL,(char *)&opretbuf[opretlen-4]);
return(typestr);
}
tokomodo = 1;
@@ -965,7 +969,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
{
basesp->redeemed += value;
pax->didstats = 1;
//if ( strcmp(CURRENCIES[baseids[i]],ASSETCHAINS_SYMBOL) == 0 )
if ( strcmp(CURRENCIES[baseids[i]],ASSETCHAINS_SYMBOL) == 0 )
printf("ht.%d %.8f ########### %p redeemed %s += %.8f %.8f kht.%d ht.%d\n",height,dstr(value),basesp,CURRENCIES[baseids[i]],dstr(value),dstr(srcvalues[i]),kmdheights[i],otherheights[i]);
}
}

View File

@@ -27,6 +27,7 @@ int32_t komodo_longestchain();
pthread_mutex_t komodo_mutex;
#define KOMODO_ELECTION_GAP 2000 //((ASSETCHAINS_SYMBOL[0] == 0) ? 2000 : 100)
#define IGUANA_MAXSCRIPTSIZE 10001
struct pax_transaction *PAX;
int32_t NUM_PRICES; uint32_t *PVALS;
@@ -47,5 +48,8 @@ uint32_t ASSETCHAINS_MAGIC = 2387029918;
uint64_t ASSETCHAINS_SUPPLY = 10;
uint32_t KOMODO_INITDONE;
char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771;
char KMDUSERPASS[4096],BTCUSERPASS[4096]; uint16_t BITCOIND_PORT = 7771;
uint64_t PENDING_KOMODO_TX;
struct komodo_kv *KOMODO_KV;
pthread_mutex_t KOMODO_KV_mutex;

184
src/komodo_kv.h Normal file
View File

@@ -0,0 +1,184 @@
/******************************************************************************
* Copyright © 2014-2017 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. *
* *
******************************************************************************/
#ifndef H_KOMODOKV_H
#define H_KOMODOKV_H
int32_t komodo_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint16_t valuesize)
{
if ( refvalue == 0 && value == 0 )
return(0);
else if ( refvalue == 0 || value == 0 )
return(-1);
else if ( refvaluesize != valuesize )
return(-1);
else return(memcmp(refvalue,value,valuesize));
}
int32_t komodo_kvnumdays(uint32_t flags)
{
int32_t numdays;
if ( (numdays= ((flags>>2)&0x3ff)+1) > 365 )
numdays = 365;
return(numdays);
}
int32_t komodo_kvduration(uint32_t flags)
{
return(komodo_kvnumdays(flags) * KOMODO_KVDURATION);
}
uint64_t komodo_kvfee(uint32_t flags,int32_t opretlen,int32_t keylen)
{
int32_t numdays,k; uint64_t fee;
if ( (k= keylen) > 32 )
k = 32;
numdays = komodo_kvnumdays(flags);
if ( (fee= (numdays*(opretlen * opretlen / k))) < 100000 )
fee = 100000;
return(fee);
}
int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen)
{
struct komodo_kv *ptr; int32_t duration,retval = -1;
*heightp = -1;
*flagsp = 0;
memset(pubkeyp,0,sizeof(*pubkeyp));
portable_mutex_lock(&KOMODO_KV_mutex);
HASH_FIND(hh,KOMODO_KV,key,keylen,ptr);
if ( ptr != 0 )
{
duration = komodo_kvduration(ptr->flags);
//printf("duration.%d flags.%d current.%d ht.%d keylen.%d valuesize.%d\n",duration,ptr->flags,current_height,ptr->height,ptr->keylen,ptr->valuesize);
if ( current_height > (ptr->height + duration) )
{
HASH_DELETE(hh,KOMODO_KV,ptr);
if ( ptr->value != 0 )
free(ptr->value);
if ( ptr->key != 0 )
free(ptr->key);
free(ptr);
}
else
{
*heightp = ptr->height;
*flagsp = ptr->flags;
int32_t i; for (i=0; i<32; i++)
{
//printf("%02x",((uint8_t *)&ptr->pubkey)[31-i]);
((uint8_t *)pubkeyp)[i] = ((uint8_t *)&ptr->pubkey)[31-i];
}
//printf(" ptr->pubkey\n");
memcpy(pubkeyp,&ptr->pubkey,sizeof(*pubkeyp));
if ( (retval= ptr->valuesize) != 0 )
memcpy(value,ptr->value,retval);
}
}
portable_mutex_unlock(&KOMODO_KV_mutex);
return(retval);
}
void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value)
{
static uint256 zeroes;
uint32_t flags; uint256 pubkey,refpubkey,sig; int32_t i,refvaluesize,hassig,coresize,haspubkey,height,kvheight; uint16_t keylen,valuesize,newflag = 0; uint8_t *key,*valueptr,keyvalue[IGUANA_MAXSCRIPTSIZE]; struct komodo_kv *ptr; char *transferpubstr,*tstr; uint64_t fee;
iguana_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen);
iguana_rwnum(0,&opretbuf[3],sizeof(valuesize),&valuesize);
iguana_rwnum(0,&opretbuf[5],sizeof(height),&height);
iguana_rwnum(0,&opretbuf[9],sizeof(flags),&flags);
key = &opretbuf[13];
valueptr = &key[keylen];
fee = komodo_kvfee(flags,opretlen,keylen);
//printf("fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]);
if ( value >= fee )
{
coresize = (int32_t)(sizeof(flags)+sizeof(height)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1);
if ( opretlen == coresize || opretlen == coresize+sizeof(uint256) || opretlen == coresize+2*sizeof(uint256) )
{
memset(&pubkey,0,sizeof(pubkey));
memset(&sig,0,sizeof(sig));
if ( (haspubkey= (opretlen >= coresize+sizeof(uint256))) != 0 )
{
for (i=0; i<32; i++)
((uint8_t *)&pubkey)[i] = opretbuf[coresize+i];
}
if ( (hassig= (opretlen == coresize+sizeof(uint256)*2)) != 0 )
{
for (i=0; i<32; i++)
((uint8_t *)&sig)[i] = opretbuf[coresize+sizeof(uint256)+i];
}
memcpy(keyvalue,key,keylen);
if ( (refvaluesize= komodo_kvsearch((uint256 *)&refpubkey,height,&flags,&kvheight,&keyvalue[keylen],key,keylen)) >= 0 )
{
if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 )
{
if ( komodo_kvsigverify(keyvalue,keylen+refvaluesize,refpubkey,sig) < 0 )
{
//printf("komodo_kvsigverify error [%d]\n",coresize-13);
return;
}
}
}
portable_mutex_lock(&KOMODO_KV_mutex);
HASH_FIND(hh,KOMODO_KV,key,keylen,ptr);
if ( ptr != 0 )
{
//if ( (ptr->flags & KOMODO_KVPROTECTED) != 0 )
{
tstr = (char *)"transfer:";
transferpubstr = (char *)&valueptr[strlen(tstr)];
if ( strncmp(tstr,(char *)valueptr,strlen(tstr)) == 0 && is_hexstr(transferpubstr,0) == 64 )
{
printf("transfer.(%s) to [%s]? ishex.%d\n",key,transferpubstr,is_hexstr(transferpubstr,0));
for (i=0; i<32; i++)
((uint8_t *)&pubkey)[31-i] = _decode_hex(&transferpubstr[i*2]);
}
}
}
else if ( ptr == 0 )
{
ptr = (struct komodo_kv *)calloc(1,sizeof(*ptr));
ptr->key = (uint8_t *)calloc(1,keylen);
ptr->keylen = keylen;
memcpy(ptr->key,key,keylen);
newflag = 1;
HASH_ADD_KEYPTR(hh,KOMODO_KV,ptr->key,ptr->keylen,ptr);
}
if ( newflag != 0 || (ptr->flags & KOMODO_KVPROTECTED) == 0 )
{
if ( ptr->value != 0 )
free(ptr->value), ptr->value = 0;
if ( (ptr->valuesize= valuesize) != 0 )
{
ptr->value = (uint8_t *)calloc(1,valuesize);
memcpy(ptr->value,valueptr,valuesize);
}
}
/*for (i=0; i<32; i++)
printf("%02x",((uint8_t *)&ptr->pubkey)[i]);
printf(" <- ");
for (i=0; i<32; i++)
printf("%02x",((uint8_t *)&pubkey)[i]);
printf(" new pubkey\n");*/
memcpy(&ptr->pubkey,&pubkey,sizeof(ptr->pubkey));
ptr->height = height;
ptr->flags = flags | 1;
portable_mutex_unlock(&KOMODO_KV_mutex);
} else printf("size mismatch %d vs %d\n",opretlen,coresize);
} else printf("insufficient fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]);
}
#endif

View File

@@ -13,6 +13,8 @@
* *
******************************************************************************/
#define KOMODO_MAINNET_START 178999
const char *Notaries_genesis[][2] =
{
{ "jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" },
@@ -52,6 +54,12 @@ const char *Notaries_genesis[][2] =
{ "titomane_SH", "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960" },
};
const char *Notaries_elected[][2] = // update with all elected notaries
{
{ "jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" },
{ "jl777_testB", "02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344" },
};
int32_t komodo_ratify_threshold(int32_t height,uint64_t signedmask)
{
int32_t htind,numnotaries,i,wt = 0;
@@ -226,6 +234,8 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n
void komodo_init(int32_t height)
{
static int didinit; uint256 zero; int32_t i,k,n; uint8_t pubkeys[64][33];
if ( 0 && height != 0 )
printf("komodo_init ht.%d didinit.%d\n",height,didinit);
if ( didinit == 0 )
{
pthread_mutex_init(&komodo_mutex,NULL);
@@ -246,6 +256,18 @@ void komodo_init(int32_t height)
// Minerids[i] = -2;
didinit = 1;
}
else if ( height == KOMODO_MAINNET_START )
{
n = (int32_t)(sizeof(Notaries_elected)/sizeof(*Notaries_elected));
for (k=0; k<n; k++)
{
if ( Notaries_elected[k][0] == 0 || Notaries_elected[k][1] == 0 || Notaries_elected[k][0][0] == 0 || Notaries_elected[k][1][0] == 0 )
break;
decode_hex(pubkeys[k],33,(char *)Notaries_elected[k][1]);
}
printf("set MAINNET notaries.%d\n",k);
komodo_notarysinit(KOMODO_MAINNET_START,pubkeys,k);
}
komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,0,0,0,0,0);
}

View File

@@ -429,7 +429,7 @@ uint64_t _komodo_paxprice(uint64_t *kmdbtcp,uint64_t *btcusdp,int32_t height,cha
height -= 10;
if ( (baseid= komodo_baseid(base)) >= 0 && (relid= komodo_baseid(rel)) >= 0 )
{
portable_mutex_lock(&komodo_mutex);
//portable_mutex_lock(&komodo_mutex);
for (i=NUM_PRICES-1; i>=0; i--)
{
ptr = &PVALS[36 * i];
@@ -440,18 +440,47 @@ uint64_t _komodo_paxprice(uint64_t *kmdbtcp,uint64_t *btcusdp,int32_t height,cha
*kmdbtcp = ptr[MAX_CURRENCIES + 1] / 539;
*btcusdp = ptr[MAX_CURRENCIES + 2] / 539;
}
portable_mutex_unlock(&komodo_mutex);
//portable_mutex_unlock(&komodo_mutex);
if ( kmdbtc != 0 && btcusd != 0 )
return(komodo_paxcalc(&ptr[1],baseid,relid,basevolume,kmdbtc,btcusd));
else return(0);
}
}
portable_mutex_unlock(&komodo_mutex);
//portable_mutex_unlock(&komodo_mutex);
} //else printf("paxprice invalid base.%s %d, rel.%s %d\n",base,baseid,rel,relid);
return(0);
}
uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume)
int32_t komodo_kmdbtcusd(int32_t rwflag,uint64_t *kmdbtcp,uint64_t *btcusdp,int32_t height)
{
static uint64_t *KMDBTCS,*BTCUSDS; static int32_t maxheight = 0; int32_t incr = 10000;
if ( height >= maxheight )
{
//printf("height.%d maxheight.%d incr.%d\n",height,maxheight,incr);
if ( height >= maxheight+incr )
incr = (height - (maxheight+incr) + 1000);
KMDBTCS = (uint64_t *)realloc(KMDBTCS,((incr + maxheight) * sizeof(*KMDBTCS)));
memset(&KMDBTCS[maxheight],0,(incr * sizeof(*KMDBTCS)));
BTCUSDS = (uint64_t *)realloc(BTCUSDS,((incr + maxheight) * sizeof(*BTCUSDS)));
memset(&BTCUSDS[maxheight],0,(incr * sizeof(*BTCUSDS)));
maxheight += incr;
}
if ( rwflag == 0 )
{
*kmdbtcp = KMDBTCS[height];
*btcusdp = BTCUSDS[height];
}
else
{
KMDBTCS[height] = *kmdbtcp;
BTCUSDS[height] = *btcusdp;
}
if ( *kmdbtcp != 0 && *btcusdp != 0 )
return(0);
else return(-1);
}
uint64_t komodo_paxpriceB(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume)
{
int32_t i,j,k,ind,zeroes,numvotes,wt,nonz; int64_t delta; uint64_t lastprice,tolerance,den,densum,sum=0,votes[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],btcusds[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],kmdbtcs[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],kmdbtc,btcusd;
*seedp = komodo_seed(height);
@@ -467,15 +496,19 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin
}
numvotes = (int32_t)(sizeof(Peggy_inds)/sizeof(*Peggy_inds));
memset(votes,0,sizeof(votes));
memset(btcusds,0,sizeof(btcusds));
memset(kmdbtcs,0,sizeof(kmdbtcs));
for (i=0; i<numvotes; i++)
//if ( komodo_kmdbtcusd(0,&kmdbtc,&btcusd,height) < 0 ) crashes when via passthru GUI use
{
_komodo_paxprice(&kmdbtcs[numvotes-1-i],&btcusds[numvotes-1-i],height-i,base,rel,100000,0,0);
//printf("(%llu %llu) ",(long long)kmdbtcs[numvotes-1-i],(long long)btcusds[numvotes-1-i]);
memset(btcusds,0,sizeof(btcusds));
memset(kmdbtcs,0,sizeof(kmdbtcs));
for (i=0; i<numvotes; i++)
{
_komodo_paxprice(&kmdbtcs[numvotes-1-i],&btcusds[numvotes-1-i],height-i,base,rel,100000,0,0);
//printf("(%llu %llu) ",(long long)kmdbtcs[numvotes-1-i],(long long)btcusds[numvotes-1-i]);
}
kmdbtc = komodo_paxcorrelation(kmdbtcs,numvotes,*seedp) * 539;
btcusd = komodo_paxcorrelation(btcusds,numvotes,*seedp) * 539;
//komodo_kmdbtcusd(1,&kmdbtc,&btcusd,height);
}
kmdbtc = komodo_paxcorrelation(kmdbtcs,numvotes,*seedp) * 539;
btcusd = komodo_paxcorrelation(btcusds,numvotes,*seedp) * 539;
for (i=nonz=0; i<numvotes; i++)
{
if ( (votes[numvotes-1-i]= _komodo_paxprice(0,0,height-i,base,rel,100000,kmdbtc,btcusd)) == 0 )
@@ -491,6 +524,49 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin
return(komodo_paxcorrelation(votes,numvotes,*seedp) * basevolume / 100000);
}
uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume)
{
int32_t i,nonz=0; int64_t diff; uint64_t price,seed,sum = 0;
if ( chainActive.Tip() != 0 && height > chainActive.Tip()->nHeight )
return(0);
portable_mutex_lock(&komodo_mutex);
for (i=0; i<17; i++)
{
if ( (price= komodo_paxpriceB(&seed,height-i,base,rel,basevolume)) != 0 )
{
sum += price;
nonz++;
if ( 0 && i == 1 && nonz == 2 )
{
diff = (((int64_t)price - (sum >> 1)) * 10000);
if ( diff < 0 )
diff = -diff;
diff /= price;
printf("(%llu %llu %lld).%lld ",(long long)price,(long long)(sum>>1),(long long)(((int64_t)price - (sum >> 1)) * 10000),(long long)diff);
if ( diff < 33 )
break;
}
else if ( 0 && i == 3 && nonz == 4 )
{
diff = (((int64_t)price - (sum >> 2)) * 10000);
if ( diff < 0 )
diff = -diff;
diff /= price;
printf("(%llu %llu %lld).%lld ",(long long)price,(long long)(sum>>2),(long long) (((int64_t)price - (sum >> 2)) * 10000),(long long)diff);
if ( diff < 20 )
break;
}
}
if ( height < 165000 )
break;
}
portable_mutex_unlock(&komodo_mutex);
if ( nonz != 0 )
sum /= nonz;
//printf("-> %lld %s/%s i.%d ht.%d\n",(long long)sum,base,rel,i,height);
return(sum);
}
int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *base,char *rel)
{
int32_t baseid=-1,relid=-1,i,num = 0; uint32_t *ptr;

View File

@@ -37,6 +37,18 @@
#define KOMODO_OPRETURN_WITHDRAW 'W' // assetchain
#define KOMODO_OPRETURN_REDEEMED 'X'
#define KOMODO_KVPROTECTED 1
#define KOMODO_KVBINARY 2
#define KOMODO_KVDURATION 1440
union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; };
typedef union _bits256 bits256;
union _bits320 { uint8_t bytes[40]; uint16_t ushorts[20]; uint32_t uints[10]; uint64_t ulongs[5]; uint64_t txid; };
typedef union _bits320 bits320;
struct komodo_kv { UT_hash_handle hh; bits256 pubkey; uint8_t *key,*value; int32_t height; uint32_t flags; uint16_t keylen,valuesize; };
struct komodo_event_notarized { uint256 blockhash,desttxid; int32_t notarizedheight; char dest[16]; };
struct komodo_event_pubkeys { uint8_t num; uint8_t pubkeys[64][33]; };
struct komodo_event_opreturn { uint256 txid; uint64_t value; uint16_t vout,oplen; uint8_t opret[]; };

View File

@@ -30,9 +30,6 @@ typedef struct queue
char name[64],initflag;
} queue_t;
union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; };
typedef union _bits256 bits256;
#include "mini-gmp.c"
#define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9"
@@ -1347,7 +1344,11 @@ void komodo_configfile(char *symbol,uint16_t port)
#else
while ( fname[strlen(fname)-1] != '/' )
fname[strlen(fname)-1] = 0;
#ifdef __APPLE__
strcat(fname,"Komodo.conf");
#else
strcat(fname,"komodo.conf");
#endif
#endif
if ( (fp= fopen(fname,"rb")) != 0 )
{
@@ -1363,7 +1364,13 @@ int32_t komodo_userpass(char *userpass,char *symbol)
FILE *fp; char fname[512],username[512],password[512],confname[16];
userpass[0] = 0;
if ( strcmp("KMD",symbol) == 0 )
{
#ifdef __APPLE__
sprintf(confname,"Komodo.conf");
#else
sprintf(confname,"komodo.conf");
#endif
}
else sprintf(confname,"%s.conf",symbol);
komodo_statefname(fname,symbol,confname);
if ( (fp= fopen(fname,"rb")) != 0 )
@@ -1492,25 +1499,40 @@ void komodo_args()
}
else
{
char fname[512],username[512],password[4096]; FILE *fp;
char fname[512],username[512],password[4096]; int32_t iter; FILE *fp;
ASSETCHAINS_PORT = 8777;
strcpy(fname,GetDataDir().string().c_str());
#ifdef WIN32
while ( fname[strlen(fname)-1] != '\\' )
fname[strlen(fname)-1] = 0;
strcat(fname,".komodo/komodo.conf");
#else
while ( fname[strlen(fname)-1] != '/' )
fname[strlen(fname)-1] = 0;
strcat(fname,".komodo/komodo.conf");
#endif
if ( (fp= fopen(fname,"rb")) != 0 )
for (iter=0; iter<2; iter++)
{
komodo_userpass(username,password,fp);
sprintf(KMDUSERPASS,"%s:%s",username,password);
fclose(fp);
//printf("KOMODO.(%s) -> userpass.(%s)\n",fname,KMDUSERPASS);
} else printf("couldnt open.(%s)\n",fname);
strcpy(fname,GetDataDir().string().c_str());
#ifdef WIN32
while ( fname[strlen(fname)-1] != '\\' )
fname[strlen(fname)-1] = 0;
if ( iter == 0 )
strcat(fname,".komodo\\komodo.conf");
else strcat(fname,".bitcoin\\bitcoin.conf");
#else
while ( fname[strlen(fname)-1] != '/' )
fname[strlen(fname)-1] = 0;
#ifdef __APPLE__
if ( iter == 0 )
strcat(fname,"Komodo/Komodo.conf");
else strcat(fname,"Bitcoin/Bitcoin.conf");
#else
if ( iter == 0 )
strcat(fname,".komodo/komodo.conf");
else strcat(fname,".bitcoin/bitcoin.conf");
#endif
#endif
if ( (fp= fopen(fname,"rb")) != 0 )
{
komodo_userpass(username,password,fp);
sprintf(iter == 0 ? KMDUSERPASS : BTCUSERPASS,"%s:%s",username,password);
fclose(fp);
//printf("KOMODO.(%s) -> userpass.(%s)\n",fname,KMDUSERPASS);
} else printf("couldnt open.(%s)\n",fname);
if ( IS_KOMODO_NOTARY == 0 )
break;
}
}
//fprintf(stderr,"%s chain params initialized\n",ASSETCHAINS_SYMBOL);
}

View File

@@ -396,6 +396,10 @@ Value gettxoutsetinfo(const Array& params, bool fHelp)
return ret;
}
#define IGUANA_MAXSCRIPTSIZE 10001
#define KOMODO_KVDURATION 1440
#define KOMODO_KVBINARY 2
extern char ASSETCHAINS_SYMBOL[16];
uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime);
uint32_t komodo_txtime(uint256 hash);
uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume);
@@ -404,6 +408,42 @@ 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);
uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n);
int32_t komodo_minerids(uint8_t *minerids,int32_t height);
int32_t komodo_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen);
Value kvsearch(const Array& params, bool fHelp)
{
Object ret; uint32_t flags; uint8_t value[IGUANA_MAXSCRIPTSIZE],key[IGUANA_MAXSCRIPTSIZE]; int32_t duration,j,height,valuesize,keylen; uint256 refpubkey; static uint256 zeroes;
if (fHelp || params.size() != 1 )
throw runtime_error("kvsearch key");
LOCK(cs_main);
if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 )
{
ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL)));
ret.push_back(Pair("currentheight", (int64_t)chainActive.Tip()->nHeight));
ret.push_back(Pair("key",params[0].get_str()));
ret.push_back(Pair("keylen",keylen));
if ( keylen < sizeof(key) )
{
memcpy(key,params[0].get_str().c_str(),keylen);
if ( (valuesize= komodo_kvsearch(&refpubkey,chainActive.Tip()->nHeight,&flags,&height,value,key,keylen)) >= 0 )
{
std::string val; char *valuestr;
val.resize(valuesize);
valuestr = (char *)val.data();
memcpy(valuestr,value,valuesize);
if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 )
ret.push_back(Pair("owner",refpubkey.GetHex()));
ret.push_back(Pair("height",height));
duration = ((flags >> 2) + 1) * KOMODO_KVDURATION;
ret.push_back(Pair("expiration", (int64_t)(height+duration)));
ret.push_back(Pair("flags",(int64_t)flags));
ret.push_back(Pair("value",val));
ret.push_back(Pair("valuesize",valuesize));
} else ret.push_back(Pair("error",(char *)"cant find key"));
} else ret.push_back(Pair("error",(char *)"key too big"));
} else ret.push_back(Pair("error",(char *)"null key"));
return ret;
}
Value minerids(const Array& params, bool fHelp)
{

View File

@@ -112,6 +112,8 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "paxpending", 0 },
{ "notaries", 1 },
{ "minerids", 1 },
{ "kvsearch", 1 },
{ "kvupdate", 4 },
};
class CRPCConvertTable

View File

@@ -305,6 +305,8 @@ static const CRPCCommand vRPCCommands[] =
{ "blockchain", "paxprices", &paxprices, true },
{ "blockchain", "notaries", &notaries, true },
{ "blockchain", "minerids", &minerids, true },
{ "blockchain", "kvsearch", &kvsearch, true },
{ "blockchain", "kvupdate", &kvupdate, true },
/* Mining */
{ "mining", "getblocktemplate", &getblocktemplate, true },

View File

@@ -247,6 +247,8 @@ extern json_spirit::Value gettxoutsetinfo(const json_spirit::Array& params, bool
extern json_spirit::Value gettxout(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value notaries(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value minerids(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value kvsearch(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value kvupdate(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value paxprice(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value paxpending(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value paxprices(const json_spirit::Array& params, bool fHelp);

View File

@@ -404,9 +404,9 @@ static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtr
for (i=0; i<opretlen; i++)
{
ptr[i] = opretbuf[i];
printf("%02x",ptr[i]);
//printf("%02x",ptr[i]);
}
printf(" opretbuf[%d]\n",opretlen);
//printf(" opretbuf[%d]\n",opretlen);
CRecipient opret = { opretpubkey, opretValue, false };
vecSend.push_back(opret);
}
@@ -475,6 +475,10 @@ Value sendtoaddress(const Array& params, bool fHelp)
return wtx.GetHash().GetHex();
}
#define KOMODO_KVPROTECTED 1
#define KOMODO_KVBINARY 2
#define KOMODO_KVDURATION 1440
#define IGUANA_MAXSCRIPTSIZE 10001
uint64_t PAX_fiatdest(uint64_t *seedp,int32_t tokomodo,char *destaddr,uint8_t pubkey37[37],char *coinaddr,int32_t height,char *base,int64_t fiatoshis);
int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_t opretlen);
#define CRYPTO777_KMDADDR "RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA"
@@ -483,6 +487,129 @@ int32_t komodo_is_issuer();
int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp);
int32_t komodo_isrealtime(int32_t *kmdheightp);
int32_t pax_fiatstatus(uint64_t *available,uint64_t *deposited,uint64_t *issued,uint64_t *withdrawn,uint64_t *approved,uint64_t *redeemed,char *base);
int32_t komodo_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen);
int32_t komodo_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint16_t valuesize);
uint64_t komodo_kvfee(uint32_t flags,int32_t opretlen,int32_t keylen);
uint256 komodo_kvsig(uint8_t *buf,int32_t len,uint256 privkey);
int32_t komodo_kvduration(uint32_t flags);
uint256 komodo_kvprivkey(uint256 *pubkeyp,char *passphrase);
int32_t komodo_kvsigverify(uint8_t *buf,int32_t len,uint256 _pubkey,uint256 sig);
Value kvupdate(const Array& params, bool fHelp)
{
static uint256 zeroes;
CWalletTx wtx; Object ret;
uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t i,coresize,haveprivkey,duration,opretlen,height; uint16_t keylen=0,valuesize=0,refvaluesize=0; uint8_t *key,*value=0; uint32_t flags,tmpflags,n; struct komodo_kv *ptr; uint64_t fee; uint256 privkey,pubkey,refpubkey,sig;
if (fHelp || params.size() < 3 )
throw runtime_error("kvupdate key value flags/passphrase");
if (!EnsureWalletIsAvailable(fHelp))
return 0;
haveprivkey = 0;
memset(&sig,0,sizeof(sig));
memset(&privkey,0,sizeof(privkey));
memset(&refpubkey,0,sizeof(refpubkey));
memset(&pubkey,0,sizeof(pubkey));
if ( (n= (int32_t)params.size()) >= 3 )
{
flags = atoi(params[2].get_str().c_str());
//printf("flags.%d (%s) n.%d\n",flags,params[2].get_str().c_str(),n);
} else flags = 0;
if ( n >= 4 )
privkey = komodo_kvprivkey(&pubkey,(char *)(n >= 4 ? params[3].get_str().c_str() : "password"));
haveprivkey = 1;
flags |= 1;
/*for (i=0; i<32; i++)
printf("%02x",((uint8_t *)&privkey)[i]);
printf(" priv, ");
for (i=0; i<32; i++)
printf("%02x",((uint8_t *)&pubkey)[i]);
printf(" pubkey, privkey derived from (%s)\n",(char *)params[3].get_str().c_str());
*/
LOCK2(cs_main, pwalletMain->cs_wallet);
if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 )
{
key = (uint8_t *)params[0].get_str().c_str();
if ( n >= 2 && params[1].get_str().c_str() != 0 )
{
value = (uint8_t *)params[1].get_str().c_str();
valuesize = (int32_t)strlen(params[1].get_str().c_str());
}
memcpy(keyvalue,key,keylen);
if ( (refvaluesize= komodo_kvsearch(&refpubkey,chainActive.Tip()->nHeight,&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 )
{
if ( (tmpflags & KOMODO_KVPROTECTED) != 0 )
{
if ( memcmp(&refpubkey,&pubkey,sizeof(refpubkey)) != 0 )
{
ret.push_back(Pair("error",(char *)"cant modify write once key without passphrase"));
return ret;
}
}
if ( keylen+refvaluesize <= sizeof(keyvalue) )
{
sig = komodo_kvsig(keyvalue,keylen+refvaluesize,privkey);
if ( komodo_kvsigverify(keyvalue,keylen+refvaluesize,refpubkey,sig) < 0 )
{
ret.push_back(Pair("error",(char *)"error verifying sig, passphrase is probably wrong"));
printf("VERIFY ERROR\n");
return ret;
} // else printf("verified immediately\n");
}
}
//for (i=0; i<32; i++)
// printf("%02x",((uint8_t *)&sig)[i]);
//printf(" sig for keylen.%d + valuesize.%d\n",keylen,refvaluesize);
ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL)));
height = chainActive.Tip()->nHeight;
if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 )
ret.push_back(Pair("owner",refpubkey.GetHex()));
ret.push_back(Pair("height", (int64_t)height));
duration = komodo_kvduration(flags); //((flags >> 2) + 1) * KOMODO_KVDURATION;
ret.push_back(Pair("expiration", (int64_t)(height+duration)));
ret.push_back(Pair("flags",(int64_t)flags));
ret.push_back(Pair("key",params[0].get_str()));
ret.push_back(Pair("keylen",(int64_t)keylen));
if ( n >= 2 && params[1].get_str().c_str() != 0 )
{
ret.push_back(Pair("value",params[1].get_str()));
ret.push_back(Pair("valuesize",valuesize));
}
iguana_rwnum(1,&keyvalue[0],sizeof(keylen),&keylen);
iguana_rwnum(1,&keyvalue[2],sizeof(valuesize),&valuesize);
iguana_rwnum(1,&keyvalue[4],sizeof(height),&height);
iguana_rwnum(1,&keyvalue[8],sizeof(flags),&flags);
memcpy(&keyvalue[12],key,keylen);
if ( value != 0 )
memcpy(&keyvalue[12 + keylen],value,valuesize);
coresize = (int32_t)(sizeof(flags)+sizeof(height)+sizeof(uint16_t)*2+keylen+valuesize);
if ( haveprivkey != 0 )
{
for (i=0; i<32; i++)
keyvalue[12 + keylen + valuesize + i] = ((uint8_t *)&pubkey)[i];
coresize += 32;
if ( refvaluesize >=0 )
{
for (i=0; i<32; i++)
keyvalue[12 + keylen + valuesize + 32 + i] = ((uint8_t *)&sig)[i];
coresize += 32;
}
}
if ( (opretlen= komodo_opreturnscript(opretbuf,'K',keyvalue,coresize)) == 40 )
opretlen++;
//for (i=0; i<opretlen; i++)
// printf("%02x",opretbuf[i]);
//printf(" opretbuf keylen.%d valuesize.%d height.%d (%02x %02x %02x)\n",*(uint16_t *)&keyvalue[0],*(uint16_t *)&keyvalue[2],*(uint32_t *)&keyvalue[4],keyvalue[8],keyvalue[9],keyvalue[10]);
EnsureWalletIsUnlocked();
fee = komodo_kvfee(flags,opretlen,keylen);
ret.push_back(Pair("fee",(double)fee/COIN));
CBitcoinAddress destaddress(CRYPTO777_KMDADDR);
if (!destaddress.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid dest Bitcoin address");
SendMoney(destaddress.Get(),10000,false,wtx,opretbuf,opretlen,fee);
ret.push_back(Pair("txid",wtx.GetHash().GetHex()));
} else ret.push_back(Pair("error",(char *)"null key"));
return ret;
}
Value paxdeposit(const Array& params, bool fHelp)
{
@@ -2510,7 +2637,7 @@ uint64_t komodo_interestsum()
BOOST_FOREACH(const COutput& out,vecOutputs)
{
CAmount nValue = out.tx->vout[out.i].nValue;
if ( out.tx->nLockTime != 0 )
if ( out.tx->nLockTime != 0 && out.fSpendable != 0 )
{
BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
CBlockIndex *tipindex,*pindex = it->second;