Merge pull request #1075 from jl777/dev

Dev
This commit is contained in:
jl777
2018-12-14 04:27:31 -11:00
committed by GitHub
8 changed files with 394 additions and 40 deletions

View File

@@ -14,8 +14,10 @@ testScripts=(
'ac_private.py' 'ac_private.py'
'verushash.py' 'verushash.py'
'cryptoconditions.py' 'cryptoconditions.py'
'cryptoconditions_channels.py'
'cryptoconditions_dice.py' 'cryptoconditions_dice.py'
'cryptoconditions_faucet.py' 'cryptoconditions_faucet.py'
'cryptoconditions_gateways.py'
'cryptoconditions_oracles.py' 'cryptoconditions_oracles.py'
'cryptoconditions_rewards.py' 'cryptoconditions_rewards.py'
'cryptoconditions_token.py' 'cryptoconditions_token.py'

View File

@@ -0,0 +1,174 @@
#!/usr/bin/env python2
# Copyright (c) 2018 SuperNET developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
from test_framework.util import assert_equal, assert_greater_than, \
initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \
stop_nodes, sync_blocks, sync_mempools, wait_bitcoinds, rpc_port, assert_raises
from cryptoconditions import assert_success, assert_error, generate_random_string
class CryptoconditionsChannelsTest(BitcoinTestFramework):
def setup_chain(self):
print("Initializing CC test directory "+self.options.tmpdir)
self.num_nodes = 2
initialize_chain_clean(self.options.tmpdir, self.num_nodes)
def setup_network(self, split = False):
print("Setting up network...")
self.addr = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D"
self.pubkey = "02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf"
self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9"
self.addr1 = "RXEXoa1nRmKhMbuZovpcYwQMsicwzccZBp"
self.pubkey1 = "024026d4ad4ecfc1f705a9b42ca64af6d2ad947509c085534a30b8861d756c6ff0"
self.privkey1 = "UtdydP56pGTFmawHzHr1wDrc4oUwCNW1ttX8Pc3KrvH3MA8P49Wi"
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir,
extra_args=[[
# always give -ac_name as first extra_arg and port as third
'-ac_name=REGTEST',
'-conf='+self.options.tmpdir+'/node0/REGTEST.conf',
'-port=64367',
'-rpcport=64368',
'-regtest',
'-addressindex=1',
'-spentindex=1',
'-ac_supply=5555555',
'-ac_reward=10000000000000',
'-pubkey=' + self.pubkey,
'-ac_cc=2',
'-whitelist=127.0.0.1',
'-debug',
'--daemon',
'-rpcuser=rt',
'-rpcpassword=rt'
],
['-ac_name=REGTEST',
'-conf='+self.options.tmpdir+'/node1/REGTEST.conf',
'-port=64365',
'-rpcport=64366',
'-regtest',
'-addressindex=1',
'-spentindex=1',
'-ac_supply=5555555',
'-ac_reward=10000000000000',
'-pubkey=' + self.pubkey1,
'-ac_cc=2',
'-whitelist=127.0.0.1',
'-debug',
'-addnode=127.0.0.1:64367',
'--daemon',
'-rpcuser=rt',
'-rpcpassword=rt']]
)
self.is_network_split = split
self.rpc = self.nodes[0]
self.rpc1 = self.nodes[1]
self.sync_all()
print("Done setting up network")
def send_and_mine(self, xtn, rpc_connection):
txid = rpc_connection.sendrawtransaction(xtn)
assert txid, 'got txid'
# we need the tx above to be confirmed in the next block
rpc_connection.generate(1)
return txid
def run_channels_tests(self):
"""!!! for testing needed test daemon which built with custom flag
export CONFIGURE_FLAGS='CPPFLAGS=-DTESTMODE'
since in usual mode 101 confirmations are needed for payment/refund
"""
rpc = self.nodes[0]
rpc1 = self.nodes[1]
# getting empty channels list
result = rpc.channelsinfo()
assert_equal(len(result), 2)
assert_equal(result["result"], "success")
assert_equal(result["name"], "Channels Info")
# 10 payments, 100000 sat denomination channel opening with second node pubkey
new_channel_hex = rpc.channelsopen(self.pubkey1, "10", "100000")
assert_success(new_channel_hex)
channel_txid = self.send_and_mine(new_channel_hex["hex"], rpc)
assert channel_txid, "got channel txid"
# checking if our new channel in common channels list
result = rpc.channelsinfo()
assert_equal(len(result), 3)
# checking info about channel directly
result = rpc.channelsinfo(channel_txid)
assert_success(result)
assert_equal(result["Open"], "10 payments of 100000 satoshi")
# open transaction should be confirmed
rpc.generate(1)
# trying to make wrong denomination channel payment
result = rpc.channelspayment(channel_txid, "199000")
assert_error(result)
# trying to make 0 channel payment
result = rpc.channelspayment(channel_txid, "0")
assert_error(result)
# trying to make negative channel payment
result = rpc.channelspayment(channel_txid, "-1")
assert_error(result)
# valid channel payment
result = rpc.channelspayment(channel_txid, "100000")
assert_success(result)
payment_tx_id = self.send_and_mine(result["hex"], rpc)
assert payment_tx_id, "got txid"
# now in channelinfo payment information should appear
result = rpc.channelsinfo(channel_txid)
assert_equal(result["Payment"], "100000 satoshi to {}, 9 payments left".format(self.addr1))
# executing channel close
result = rpc.channelsclose(channel_txid)
assert_success(result)
channel_close_txid = self.send_and_mine(result["hex"], rpc)
assert channel_close_txid, "got txid"
rpc.generate(2)
self.sync_all()
# now in channelinfo closed flag should appear
result = rpc.channelsinfo(channel_txid)
assert_equal(result["Close"], "channel")
# executing channel refund
result = rpc.channelsrefund(channel_txid, channel_close_txid)
assert_success(result)
refund_txid = self.send_and_mine(result["hex"], rpc)
assert refund_txid, "got txid"
def run_test(self):
print("Mining blocks...")
rpc = self.nodes[0]
rpc1 = self.nodes[1]
# utxos from block 1 become mature in block 101
rpc.generate(101)
self.sync_all()
rpc.getinfo()
rpc1.getinfo()
# this corresponds to -pubkey above
print("Importing privkeys")
rpc.importprivkey(self.privkey)
rpc1.importprivkey(self.privkey1)
self.run_channels_tests()
if __name__ == '__main__':
CryptoconditionsChannelsTest().main()

View File

@@ -0,0 +1,157 @@
#!/usr/bin/env python2
# Copyright (c) 2018 SuperNET developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
from test_framework.util import assert_equal, assert_greater_than, \
initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \
stop_nodes, sync_blocks, sync_mempools, wait_bitcoinds, rpc_port, assert_raises
from cryptoconditions import assert_success, assert_error, generate_random_string
class CryptoconditionsGatewaysTest(BitcoinTestFramework):
def setup_chain(self):
print("Initializing CC test directory "+self.options.tmpdir)
self.num_nodes = 2
initialize_chain_clean(self.options.tmpdir, self.num_nodes)
def setup_network(self, split = False):
print("Setting up network...")
self.addr = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D"
self.pubkey = "02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf"
self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9"
self.addr1 = "RXEXoa1nRmKhMbuZovpcYwQMsicwzccZBp"
self.pubkey1 = "024026d4ad4ecfc1f705a9b42ca64af6d2ad947509c085534a30b8861d756c6ff0"
self.privkey1 = "UtdydP56pGTFmawHzHr1wDrc4oUwCNW1ttX8Pc3KrvH3MA8P49Wi"
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir,
extra_args=[[
# always give -ac_name as first extra_arg and port as third
'-ac_name=REGTEST',
'-conf='+self.options.tmpdir+'/node0/REGTEST.conf',
'-port=64367',
'-rpcport=64368',
'-regtest',
'-addressindex=1',
'-spentindex=1',
'-ac_supply=5555555',
'-ac_reward=10000000000000',
'-pubkey=' + self.pubkey,
'-ac_cc=2',
'-whitelist=127.0.0.1',
'-debug',
'--daemon',
'-rpcuser=rt',
'-rpcpassword=rt'
],
['-ac_name=REGTEST',
'-conf='+self.options.tmpdir+'/node1/REGTEST.conf',
'-port=64365',
'-rpcport=64366',
'-regtest',
'-addressindex=1',
'-spentindex=1',
'-ac_supply=5555555',
'-ac_reward=10000000000000',
'-pubkey=' + self.pubkey1,
'-ac_cc=2',
'-whitelist=127.0.0.1',
'-debug',
'-addnode=127.0.0.1:64367',
'--daemon',
'-rpcuser=rt',
'-rpcpassword=rt']]
)
self.is_network_split = split
self.rpc = self.nodes[0]
self.rpc1 = self.nodes[1]
self.sync_all()
print("Done setting up network")
def send_and_mine(self, xtn, rpc_connection):
txid = rpc_connection.sendrawtransaction(xtn)
assert txid, 'got txid'
# we need the tx above to be confirmed in the next block
rpc_connection.generate(1)
return txid
def run_gateways_tests(self):
rpc = self.nodes[0]
rpc1 = self.nodes[1]
result = rpc.gatewaysaddress()
assert_success(result)
for x in ['GatewaysCCaddress', 'myCCaddress', 'Gatewaysmarker', 'myaddress']:
assert_equal(result[x][0], 'R')
assert_equal("03ea9c062b9652d8eff34879b504eda0717895d27597aaeb60347d65eed96ccb40", result["GatewaysPubkey"])
# getting an empty gateways list
result = rpc.gatewayslist()
assert_equal(result, [])
# Gateways binding preparation
# creating oracle
oracle_hex = rpc.oraclescreate("Test", "Testing", "Ihh")
assert_success(oracle_hex)
oracle_txid = self.send_and_mine(oracle_hex["hex"], rpc)
assert oracle_txid, "got txid"
# registering as an oracle publisher
reg_hex = rpc.oraclesregister(oracle_txid, "10000")
assert_success(reg_hex)
reg_txid = self.send_and_mine(reg_hex["hex"], rpc)
assert reg_txid, "got txid"
# subscribing on oracle
sub_hex = rpc.oraclessubscribe(oracle_txid, self.pubkey, "1")
assert_success(sub_hex)
sub_txid = self.send_and_mine(sub_hex["hex"], rpc)
assert sub_txid, "got txid"
# creating token
token_hex = rpc.tokencreate("Test", "1", "Testing")
assert_success(token_hex)
token_txid = self.send_and_mine(token_hex["hex"], rpc)
assert token_txid, "got txid"
# converting tokens
convertion_hex = rpc.tokenconvert("241",token_txid,"03ea9c062b9652d8eff34879b504eda0717895d27597aaeb60347d65eed96ccb40","100000000")
assert_success(convertion_hex)
convertion_txid = self.send_and_mine(convertion_hex["hex"], rpc)
assert convertion_txid, "got txid"
# binding gateway
bind_hex = rpc.gatewaysbind(token_txid, oracle_txid, "KMD", "100000000", "1", "1", self.pubkey)
assert_success(bind_hex)
bind_txid = self.send_and_mine(bind_hex["hex"], rpc)
assert bind_txid, "got txid"
# checking if created gateway in list
result = rpc.gatewayslist()
assert_equal(result[0], bind_txid)
def run_test(self):
print("Mining blocks...")
rpc = self.nodes[0]
rpc1 = self.nodes[1]
# utxos from block 1 become mature in block 101
rpc.generate(101)
self.sync_all()
rpc.getinfo()
rpc1.getinfo()
# this corresponds to -pubkey above
print("Importing privkeys")
rpc.importprivkey(self.privkey)
rpc1.importprivkey(self.privkey1)
self.run_gateways_tests()
if __name__ == '__main__':
CryptoconditionsGatewaysTest().main()

View File

@@ -167,7 +167,7 @@ try_again:
curl_handle = curl_easy_init(); curl_handle = curl_easy_init();
init_string(&s); init_string(&s);
headers = curl_slist_append(0,"Expect:"); headers = curl_slist_append(0,"Expect:");
curl_easy_setopt(curl_handle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); curl_easy_setopt(curl_handle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )");
curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl_handle,CURLOPT_URL, url); curl_easy_setopt(curl_handle,CURLOPT_URL, url);
@@ -196,7 +196,7 @@ try_again:
bracket0 = (char *)"["; bracket0 = (char *)"[";
bracket1 = (char *)"]"; bracket1 = (char *)"]";
} }
databuf = (char *)malloc(256 + strlen(command) + strlen(params)); databuf = (char *)malloc(256 + strlen(command) + strlen(params));
sprintf(databuf,"{\"id\":\"jl777\",\"method\":\"%s\",\"params\":%s%s%s}",command,bracket0,params,bracket1); sprintf(databuf,"{\"id\":\"jl777\",\"method\":\"%s\",\"params\":%s%s%s}",command,bracket0,params,bracket1);
//printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf); //printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf);
@@ -236,7 +236,7 @@ try_again:
free(s.ptr); free(s.ptr);
sleep((1<<numretries)); sleep((1<<numretries));
goto try_again; goto try_again;
} }
else else
{ {
@@ -522,7 +522,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t
} }
return(hash); return(hash);
} }
uint256 _komodo_getblockhash(int32_t height);*/ uint256 _komodo_getblockhash(int32_t height);*/
uint64_t komodo_seed(int32_t height) uint64_t komodo_seed(int32_t height)
@@ -889,9 +889,9 @@ int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,uint32_t blo
int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width) int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width)
{ {
int32_t i,j,n,nonz,numnotaries; CBlock block; CBlockIndex *pindex; uint8_t notarypubs33[64][33],pubkey33[33]; int32_t i,j,nonz,numnotaries; CBlock block; CBlockIndex *pindex; uint8_t notarypubs33[64][33],pubkey33[33];
numnotaries = komodo_notaries(notarypubs33,height,0); numnotaries = komodo_notaries(notarypubs33,height,0);
for (i=nonz=0; i<width; i++,n++) for (i=nonz=0; i<width; i++)
{ {
if ( height-i <= 0 ) if ( height-i <= 0 )
continue; continue;
@@ -1106,9 +1106,9 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_
/* /*
komodo_checkPOW (fast) is called early in the process and should only refer to data immediately available. it is a filter to prevent bad blocks from going into the local DB. The more blocks we can filter out at this stage, the less junk in the local DB that will just get purged later on. komodo_checkPOW (fast) is called early in the process and should only refer to data immediately available. it is a filter to prevent bad blocks from going into the local DB. The more blocks we can filter out at this stage, the less junk in the local DB that will just get purged later on.
komodo_checkPOW (slow) is called right before connecting blocks so all prior blocks can be assumed to be there and all checks must pass komodo_checkPOW (slow) is called right before connecting blocks so all prior blocks can be assumed to be there and all checks must pass
commission must be in coinbase.vout[1] and must be >= 10000 sats commission must be in coinbase.vout[1] and must be >= 10000 sats
PoS stake must be without txfee and in the last tx in the block at vout[0] PoS stake must be without txfee and in the last tx in the block at vout[0]
*/ */
@@ -1123,11 +1123,13 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height)
{ {
nSubsidy = GetBlockSubsidy(height,Params().GetConsensus()); nSubsidy = GetBlockSubsidy(height,Params().GetConsensus());
//fprintf(stderr,"ht.%d nSubsidy %.8f prod %llu\n",height,(double)nSubsidy/COIN,(long long)(nSubsidy * ASSETCHAINS_COMMISSION)); //fprintf(stderr,"ht.%d nSubsidy %.8f prod %llu\n",height,(double)nSubsidy/COIN,(long long)(nSubsidy * ASSETCHAINS_COMMISSION));
return((nSubsidy * ASSETCHAINS_COMMISSION) / COIN); commission = ((nSubsidy * ASSETCHAINS_COMMISSION) / COIN);
n = pblock->vtx[0].vout.size(); if ( ASSETCHAINS_FOUNDERS > 1 )
for (j=0; j<n; j++) {
if ( j != 1 ) if ( (height % ASSETCHAINS_FOUNDERS) == 0 )
total += pblock->vtx[0].vout[j].nValue; commission = commission * ASSETCHAINS_FOUNDERS;
else commission = 0;
}
} }
else else
{ {
@@ -1141,9 +1143,8 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height)
total += pblock->vtx[i].vout[j].nValue; total += pblock->vtx[i].vout[j].nValue;
} }
} }
commission = ((total * ASSETCHAINS_COMMISSION) / COIN);
} }
//fprintf(stderr,"txn.%d n.%d commission total %.8f -> %.8f\n",txn_count,n,dstr(total),dstr((total * ASSETCHAINS_COMMISSION) / COIN));
commission = ((total * ASSETCHAINS_COMMISSION) / COIN);
if ( commission < 10000 ) if ( commission < 10000 )
commission = 0; commission = 0;
return(commission); return(commission);
@@ -1545,7 +1546,7 @@ bool verusCheckPOSBlock(int32_t slowflag, CBlock *pblock, int32_t height)
{ {
fprintf(stderr,"ERROR: chain not fully loaded or invalid PoS block %s - no past block found\n",blkHash.ToString().c_str()); fprintf(stderr,"ERROR: chain not fully loaded or invalid PoS block %s - no past block found\n",blkHash.ToString().c_str());
} }
else else
#ifndef KOMODO_ZCASH #ifndef KOMODO_ZCASH
if (!GetTransaction(txid, tx, Params().GetConsensus(), blkHash, true)) if (!GetTransaction(txid, tx, Params().GetConsensus(), blkHash, true))
#else #else
@@ -1578,7 +1579,7 @@ bool verusCheckPOSBlock(int32_t slowflag, CBlock *pblock, int32_t height)
{ {
BlockMap::const_iterator it = mapBlockIndex.find(blkHash); BlockMap::const_iterator it = mapBlockIndex.find(blkHash);
if ((it == mapBlockIndex.end()) || if ((it == mapBlockIndex.end()) ||
!(pastBlockIndex = it->second) || !(pastBlockIndex = it->second) ||
(height - pastBlockIndex->GetHeight()) < VERUS_MIN_STAKEAGE) (height - pastBlockIndex->GetHeight()) < VERUS_MIN_STAKEAGE)
{ {
fprintf(stderr,"ERROR: invalid PoS block %s - stake source too new or not found\n",blkHash.ToString().c_str()); fprintf(stderr,"ERROR: invalid PoS block %s - stake source too new or not found\n",blkHash.ToString().c_str());
@@ -1695,7 +1696,7 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height)
// fprintf(stderr,"%02x",script[i]); // fprintf(stderr,"%02x",script[i]);
//fprintf(stderr," payment to wrong pubkey scriptlen.%d, scriptpub[%d]\n",scriptlen,(int32_t)ASSETCHAINS_SCRIPTPUB.size()/2); //fprintf(stderr," payment to wrong pubkey scriptlen.%d, scriptpub[%d]\n",scriptlen,(int32_t)ASSETCHAINS_SCRIPTPUB.size()/2);
return(-1); return(-1);
} }
if ( pblock->vtx[0].vout[1].nValue != checktoshis ) if ( pblock->vtx[0].vout[1].nValue != checktoshis )
{ {
@@ -1806,7 +1807,9 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) if ( ASSETCHAINS_SCRIPTPUB.size() > 1 )
{ {
int32_t scriptlen; uint8_t scripthex[10000]; int32_t scriptlen; uint8_t scripthex[10000];
if ( ASSETCHAINS_SCRIPTPUB.size()/2 == pblock->vtx[0].vout[0].scriptPubKey.size() && scriptlen < sizeof(scripthex) ) script = (uint8_t *)&pblock->vtx[0].vout[0].scriptPubKey[0];
scriptlen = (int32_t)pblock->vtx[0].vout[0].scriptPubKey.size();
if ( ASSETCHAINS_SCRIPTPUB.size()/2 == scriptlen && scriptlen < sizeof(scripthex) )
{ {
decode_hex(scripthex,scriptlen,(char *)ASSETCHAINS_SCRIPTPUB.c_str()); decode_hex(scripthex,scriptlen,(char *)ASSETCHAINS_SCRIPTPUB.c_str());
if ( memcmp(scripthex,script,scriptlen) != 0 ) if ( memcmp(scripthex,script,scriptlen) != 0 )

View File

@@ -45,10 +45,10 @@ struct komodo_state KOMODO_STATES[34];
#define _COINBASE_MATURITY 100 #define _COINBASE_MATURITY 100
int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int COINBASE_MATURITY = _COINBASE_MATURITY;//100;
int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI; int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS;
int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1;
std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB;
uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_FOUNDERS; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW;
bool VERUS_MINTBLOCKS; bool VERUS_MINTBLOCKS;
char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096];
@@ -131,7 +131,7 @@ int64_t komodo_current_supply(uint32_t nHeight)
if ( (baseid = komodo_baseid(ASSETCHAINS_SYMBOL)) >= 0 && baseid < 32 ) if ( (baseid = komodo_baseid(ASSETCHAINS_SYMBOL)) >= 0 && baseid < 32 )
cur_money = ASSETCHAINS_GENESISTXVAL + ASSETCHAINS_SUPPLY + nHeight * ASSETCHAINS_REWARD[0] / SATOSHIDEN; cur_money = ASSETCHAINS_GENESISTXVAL + ASSETCHAINS_SUPPLY + nHeight * ASSETCHAINS_REWARD[0] / SATOSHIDEN;
else else
{ {
// figure out max_money by adding up supply to a maximum of 10,000,000 blocks // figure out max_money by adding up supply to a maximum of 10,000,000 blocks
cur_money = (ASSETCHAINS_SUPPLY+1) * SATOSHIDEN + (ASSETCHAINS_MAGIC & 0xffffff) + ASSETCHAINS_GENESISTXVAL; cur_money = (ASSETCHAINS_SUPPLY+1) * SATOSHIDEN + (ASSETCHAINS_MAGIC & 0xffffff) + ASSETCHAINS_GENESISTXVAL;
@@ -144,7 +144,7 @@ int64_t komodo_current_supply(uint32_t nHeight)
for ( int j = 0; j <= ASSETCHAINS_LASTERA; j++ ) for ( int j = 0; j <= ASSETCHAINS_LASTERA; j++ )
{ {
// if any condition means we have no more rewards, break // if any condition means we have no more rewards, break
if (j != 0 && (nHeight <= ASSETCHAINS_ENDSUBSIDY[j - 1] || (ASSETCHAINS_ENDSUBSIDY[j - 1] == 0 && if (j != 0 && (nHeight <= ASSETCHAINS_ENDSUBSIDY[j - 1] || (ASSETCHAINS_ENDSUBSIDY[j - 1] == 0 &&
(ASSETCHAINS_REWARD[j] == 0 && (j == ASSETCHAINS_LASTERA || ASSETCHAINS_DECAY[j] != SATOSHIDEN))))) (ASSETCHAINS_REWARD[j] == 0 && (j == ASSETCHAINS_LASTERA || ASSETCHAINS_DECAY[j] != SATOSHIDEN)))))
break; break;
@@ -180,7 +180,7 @@ int64_t komodo_current_supply(uint32_t nHeight)
lowestSubsidy = 0; lowestSubsidy = 0;
} }
else else
{ {
// Ex: -ac_eras=3 -ac_reward=0,384,24 -ac_end=1440,260640,0 -ac_halving=1,1440,2103840 -ac_decay 100000000,97750000,0 // Ex: -ac_eras=3 -ac_reward=0,384,24 -ac_end=1440,260640,0 -ac_halving=1,1440,2103840 -ac_decay 100000000,97750000,0
subsidyDifference = reward - ASSETCHAINS_REWARD[j + 1]; subsidyDifference = reward - ASSETCHAINS_REWARD[j + 1];
if (subsidyDifference < 0) if (subsidyDifference < 0)
@@ -234,7 +234,7 @@ int64_t komodo_current_supply(uint32_t nHeight)
// if negative slope, the minor triangle is the full number of steps, as the highest // if negative slope, the minor triangle is the full number of steps, as the highest
// level step is full. lowest subsidy is just the lowest so far // level step is full. lowest subsidy is just the lowest so far
lowestSubsidy = reward - (stepDifference * nSteps); lowestSubsidy = reward - (stepDifference * nSteps);
// add the step triangles, one per step // add the step triangles, one per step
cur_money += stepTriangle * nSteps; cur_money += stepTriangle * nSteps;
@@ -261,4 +261,3 @@ int64_t komodo_current_supply(uint32_t nHeight)
} }
return((int64_t)(cur_money + (cur_money * ASSETCHAINS_COMMISSION))); return((int64_t)(cur_money + (cur_money * ASSETCHAINS_COMMISSION)));
} }

View File

@@ -1068,7 +1068,7 @@ uint64_t komodo_block_prg(uint32_t nHeight)
// given a block height, this returns the unlock time for that block height, derived from // given a block height, this returns the unlock time for that block height, derived from
// the ASSETCHAINS_MAGIC number as well as the block height, providing different random numbers // the ASSETCHAINS_MAGIC number as well as the block height, providing different random numbers
// for corresponding blocks across chains, but the same sequence in each chain // for corresponding blocks across chains, but the same sequence in each chain
int64_t komodo_block_unlocktime(uint32_t nHeight) int64_t komodo_block_unlocktime(uint32_t nHeight)
{ {
uint64_t fromTime, toTime, unlocktime; uint64_t fromTime, toTime, unlocktime;
@@ -1500,6 +1500,9 @@ uint32_t komodo_assetmagic(char *symbol,uint64_t supply,uint8_t *extraptr,int32_
{ {
vcalc_sha256(0,hash.bytes,extraptr,extralen); vcalc_sha256(0,hash.bytes,extraptr,extralen);
crc0 = hash.uints[0]; crc0 = hash.uints[0];
int32_t i; for (i=0; i<extralen; i++)
fprintf(stderr,"%02x",extraptr[i]);
fprintf(stderr," extralen.%d crc0.%x\n",extralen,crc0);
} }
return(calc_crc32(crc0,buf,len)); return(calc_crc32(crc0,buf,len));
} }
@@ -1604,7 +1607,7 @@ uint64_t komodo_ac_block_subsidy(int nHeight)
subsidyDifference = subsidy; subsidyDifference = subsidy;
} }
else else
{ {
// Ex: -ac_eras=3 -ac_reward=0,384,24 -ac_end=1440,260640,0 -ac_halving=1,1440,2103840 -ac_decay 100000000,97750000,0 // Ex: -ac_eras=3 -ac_reward=0,384,24 -ac_end=1440,260640,0 -ac_halving=1,1440,2103840 -ac_decay 100000000,97750000,0
subsidyDifference = subsidy - ASSETCHAINS_REWARD[curEra + 1]; subsidyDifference = subsidy - ASSETCHAINS_REWARD[curEra + 1];
if (subsidyDifference < 0) if (subsidyDifference < 0)
@@ -1765,11 +1768,13 @@ void komodo_args(char *argv0)
MAX_BLOCK_SIGOPS = 60000; MAX_BLOCK_SIGOPS = 60000;
ASSETCHAINS_TXPOW = GetArg("-ac_txpow",0) & 3; ASSETCHAINS_TXPOW = GetArg("-ac_txpow",0) & 3;
ASSETCHAINS_FOUNDERS = GetArg("-ac_founders",0) & 1; ASSETCHAINS_FOUNDERS = GetArg("-ac_founders",0);// & 1;
ASSETCHAINS_SUPPLY = GetArg("-ac_supply",10); ASSETCHAINS_SUPPLY = GetArg("-ac_supply",10);
ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0); ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0);
ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey",""); ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey","");
ASSETCHAINS_SCRIPTPUB = GetArg("-ac_script",""); ASSETCHAINS_SCRIPTPUB = GetArg("-ac_script","");
//ASSETCHAINS_FOUNDERS_PERIOD = GetArg("-ac_period",0);
if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 ) if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 )
ASSETCHAINS_STAKED = 100; ASSETCHAINS_STAKED = 100;
@@ -1777,7 +1782,7 @@ void komodo_args(char *argv0)
// other values // other values
if ( (ASSETCHAINS_LWMAPOS = GetArg("-ac_veruspos",0)) != 0 ) if ( (ASSETCHAINS_LWMAPOS = GetArg("-ac_veruspos",0)) != 0 )
ASSETCHAINS_LWMAPOS = 50; ASSETCHAINS_LWMAPOS = 50;
ASSETCHAINS_SAPLING = GetArg("-ac_sapling", -1); ASSETCHAINS_SAPLING = GetArg("-ac_sapling", -1);
if (ASSETCHAINS_SAPLING == -1) if (ASSETCHAINS_SAPLING == -1)
{ {
@@ -1823,7 +1828,7 @@ void komodo_args(char *argv0)
} }
if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 ) if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 )
{ {
fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...]\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2]); fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size());
extraptr = extrabuf; extraptr = extrabuf;
memcpy(extraptr,ASSETCHAINS_OVERRIDE_PUBKEY33,33), extralen = 33; memcpy(extraptr,ASSETCHAINS_OVERRIDE_PUBKEY33,33), extralen = 33;
@@ -1870,9 +1875,19 @@ void komodo_args(char *argv0)
val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6) | ASSETCHAINS_TXPOW; val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6) | ASSETCHAINS_TXPOW;
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(val),(void *)&val); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(val),(void *)&val);
if ( ASSETCHAINS_FOUNDERS != 0 ) if ( ASSETCHAINS_FOUNDERS != 0 )
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS),(void *)&ASSETCHAINS_FOUNDERS); {
uint8_t tmp = 1;
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(tmp),(void *)&tmp);
if ( ASSETCHAINS_FOUNDERS > 1 )
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS),(void *)&ASSETCHAINS_FOUNDERS);
}
if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) if ( ASSETCHAINS_SCRIPTPUB.size() > 1 )
extralen += iguana_rwnum(1,&extraptr[extralen],(int32_t)ASSETCHAINS_SCRIPTPUB.size(),(void *)ASSETCHAINS_SCRIPTPUB.c_str()); {
decode_hex(&extraptr[extralen],ASSETCHAINS_SCRIPTPUB.size()/2,(char *)ASSETCHAINS_SCRIPTPUB.c_str());
extralen += ASSETCHAINS_SCRIPTPUB.size()/2;
//extralen += iguana_rwnum(1,&extraptr[extralen],(int32_t)ASSETCHAINS_SCRIPTPUB.size(),(void *)ASSETCHAINS_SCRIPTPUB.c_str());
fprintf(stderr,"append ac_script %s\n",ASSETCHAINS_SCRIPTPUB.c_str());
}
} }
addn = GetArg("-seednode",""); addn = GetArg("-seednode","");
@@ -1899,11 +1914,11 @@ void komodo_args(char *argv0)
while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 )
{ {
fprintf(stderr,"waiting for datadir\n"); fprintf(stderr,"waiting for datadir\n");
#ifndef _WIN32 #ifndef _WIN32
sleep(3); sleep(3);
#else #else
boost::this_thread::sleep(boost::posix_time::milliseconds(3000)); boost::this_thread::sleep(boost::posix_time::milliseconds(3000));
#endif #endif
} }
//fprintf(stderr,"Got datadir.(%s)\n",dirname); //fprintf(stderr,"Got datadir.(%s)\n",dirname);
if ( ASSETCHAINS_SYMBOL[0] != 0 ) if ( ASSETCHAINS_SYMBOL[0] != 0 )
@@ -2051,4 +2066,3 @@ void komodo_prefetch(FILE *fp)
} }
fseek(fp,fpos,SEEK_SET); fseek(fp,fpos,SEEK_SET);
} }

View File

@@ -148,7 +148,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount,
CPubKey pk = CPubKey(); CPubKey pk = CPubKey();
std::vector<std::vector<unsigned char>> vAddrs; std::vector<std::vector<unsigned char>> vAddrs;
txnouttype txT; txnouttype txT;
if (Solver(scriptPubKeyIn, txT, vAddrs)) if ( scriptPubKeyIn.size() > 0 && Solver(scriptPubKeyIn, txT, vAddrs))
{ {
if (txT == TX_PUBKEY) if (txT == TX_PUBKEY)
pk = CPubKey(vAddrs[0]); pk = CPubKey(vAddrs[0]);

View File

@@ -1492,13 +1492,18 @@ void ThreadOpenAddedConnections()
LOCK(cs_vNodes); LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes) BOOST_FOREACH(CNode* pnode, vNodes)
for (list<vector<CService> >::iterator it = lservAddressesToAdd.begin(); it != lservAddressesToAdd.end(); it++) for (list<vector<CService> >::iterator it = lservAddressesToAdd.begin(); it != lservAddressesToAdd.end(); it++)
{
BOOST_FOREACH(const CService& addrNode, *(it)) BOOST_FOREACH(const CService& addrNode, *(it))
if (pnode->addr == addrNode) if (pnode->addr == addrNode)
{ {
it = lservAddressesToAdd.erase(it); it = lservAddressesToAdd.erase(it);
it--; if ( it != lservAddressesToAdd.begin() )
it--;
break; break;
} }
if (it == lservAddressesToAdd.end())
break;
}
} }
BOOST_FOREACH(vector<CService>& vserv, lservAddressesToAdd) BOOST_FOREACH(vector<CService>& vserv, lservAddressesToAdd)
{ {