From 7faabcef68d62f204b543ec0689d14dd9d0a6962 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 04:44:29 -1100 Subject: [PATCH 001/144] Mine to 1of2 CC addr --- src/cc/marmara.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 4eea7395d..39d8d01a7 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -175,9 +175,10 @@ int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid, CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) { - CTxOut ccvout; + CTxOut ccvout; struct CCcontract_info *cp,C; CPubKey Marmarapk; + cp = CCinit(&C,EVAL_MARMARA); if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) - ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); + ccvout = MakeCC1of2vout(EVAL_MARMARA,0,Marmarapk,pk); return(ccvout.scriptPubKey); } @@ -298,9 +299,10 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx,int32_t firstheight,CPubKey poolpk,int32_t maxinputs) { - char coinaddr[64]; CPubKey pk; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; + char coinaddr[64]; CPubKey Marmarapk,pk; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; std::vector > unspentOutputs; - GetCCaddress(cp,coinaddr,poolpk); + Marmarapk = GetUnspendable(cp,0); + MakeCC1of2vout(cp,coinaddr,Marmarapk,poolpk); SetCCunspents(unspentOutputs,coinaddr); unlocks = MarmaraUnlockht(firstheight); //fprintf(stderr,"check coinaddr.(%s)\n",coinaddr); From 6206090faaef1f8e2e7c4a1e0c94e296ad44580b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 04:47:12 -1100 Subject: [PATCH 002/144] EVAL_MARMARA --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 39d8d01a7..587354ff2 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -302,7 +302,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, char coinaddr[64]; CPubKey Marmarapk,pk; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; std::vector > unspentOutputs; Marmarapk = GetUnspendable(cp,0); - MakeCC1of2vout(cp,coinaddr,Marmarapk,poolpk); + MakeCC1of2vout(EVAL_MARMARA,coinaddr,Marmarapk,poolpk); SetCCunspents(unspentOutputs,coinaddr); unlocks = MarmaraUnlockht(firstheight); //fprintf(stderr,"check coinaddr.(%s)\n",coinaddr); From 6dc61c6bcf4f22ed3b2a74b8cb8135a27ee5609f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 04:49:21 -1100 Subject: [PATCH 003/144] GetCCaddress1of2 --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 587354ff2..8c2b5df0b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -302,7 +302,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, char coinaddr[64]; CPubKey Marmarapk,pk; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; std::vector > unspentOutputs; Marmarapk = GetUnspendable(cp,0); - MakeCC1of2vout(EVAL_MARMARA,coinaddr,Marmarapk,poolpk); + GetCCaddress1of2(cp,coinaddr,Marmarapk,poolpk); SetCCunspents(unspentOutputs,coinaddr); unlocks = MarmaraUnlockht(firstheight); //fprintf(stderr,"check coinaddr.(%s)\n",coinaddr); From 3e2991000f29126325c05a7a48bcb1487b81a89f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 04:52:18 -1100 Subject: [PATCH 004/144] Fix --- src/cc/marmara.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8c2b5df0b..01ecaba83 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -195,6 +195,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); + Marmarapk = GetUnspendable(cp,0); if ( 0 ) { int32_t d,histo[365*2+30]; @@ -222,7 +223,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) if ( ht == height && MarmaraUnlockht(height) == unlockht ) { //fprintf(stderr,"ht.%d -> unlock.%d\n",ht,unlockht); - ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); + ccvout = MakeCC1of2vout(EVAL_MARMARA,0,Marmarapk,pk); if ( ccvout.scriptPubKey == tx.vout[0].scriptPubKey ) return(0); fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey\n",height); From f1046be9dcf72b532785977eba7f3c820271a437 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 04:53:16 -1100 Subject: [PATCH 005/144] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 01ecaba83..3eab9e364 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -193,7 +193,7 @@ CScript MarmaraCoinbaseOpret(uint8_t funcid,int32_t height,CPubKey pk) int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { - struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; + struct CCcontract_info *cp,C; CPubKey Marmarapk,pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); if ( 0 ) From 6e8e24cbc869cc62f099ea3e91b11e7b2a9cdcea Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 04:57:38 -1100 Subject: [PATCH 006/144] Init marmarapk --- src/cc/marmara.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 3eab9e364..39efecf2f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -177,6 +177,7 @@ CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) { CTxOut ccvout; struct CCcontract_info *cp,C; CPubKey Marmarapk; cp = CCinit(&C,EVAL_MARMARA); + Marmarapk = GetUnspendable(cp,0); if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) ccvout = MakeCC1of2vout(EVAL_MARMARA,0,Marmarapk,pk); return(ccvout.scriptPubKey); From 5e8d1a2d8734333b1ee732328f043d7c00fbb03f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 05:01:45 -1100 Subject: [PATCH 007/144] Test --- src/cc/marmara.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 39efecf2f..c0697a1ba 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -227,7 +227,10 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) ccvout = MakeCC1of2vout(EVAL_MARMARA,0,Marmarapk,pk); if ( ccvout.scriptPubKey == tx.vout[0].scriptPubKey ) return(0); - fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey\n",height); + char addr0[64],addr1[64]; + Getscriptaddress(addr0,ccvout.scriptPubKey); + Getscriptaddress(addr1,tx.vout[0].scriptPubKey); + fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey %s vs %s\n",height,addr0,addr1); } else fprintf(stderr,"ht.%d %d vs %d unlock.%d\n",height,MarmaraUnlockht(height),ht,unlockht); } else fprintf(stderr,"ht.%d error decoding coinbase opret\n",height); } From 32a6eb7ccecdbab87deb405563bce3f1c964fbe3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 05:04:43 -1100 Subject: [PATCH 008/144] Test --- src/cc/marmara.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index c0697a1ba..aa96ea20c 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -179,7 +179,12 @@ CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) + { ccvout = MakeCC1of2vout(EVAL_MARMARA,0,Marmarapk,pk); + char coinaddr[64]; + Getscriptaddress(coinaddr,ccvout.scriptPubKey); + fprintf(stderr,"Marmara_scriptPubKey %s ht.%d -> %s\n",HexStr(pk),height,coinaddr); + } return(ccvout.scriptPubKey); } @@ -230,7 +235,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) char addr0[64],addr1[64]; Getscriptaddress(addr0,ccvout.scriptPubKey); Getscriptaddress(addr1,tx.vout[0].scriptPubKey); - fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey %s vs %s\n",height,addr0,addr1); + fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey %s vs %s pk %s\n",height,addr0,addr1,HexStr(pk)); } else fprintf(stderr,"ht.%d %d vs %d unlock.%d\n",height,MarmaraUnlockht(height),ht,unlockht); } else fprintf(stderr,"ht.%d error decoding coinbase opret\n",height); } From 503f753e7be090976bb993f09f02a68329634433 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 05:11:01 -1100 Subject: [PATCH 009/144] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index aa96ea20c..6c6f824e7 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -235,7 +235,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) char addr0[64],addr1[64]; Getscriptaddress(addr0,ccvout.scriptPubKey); Getscriptaddress(addr1,tx.vout[0].scriptPubKey); - fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey %s vs %s pk %s\n",height,addr0,addr1,HexStr(pk)); + fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey %s vs %s pk.%d %s\n",height,addr0,addr1,(int32_t)pk.size(),HexStr(pk)); } else fprintf(stderr,"ht.%d %d vs %d unlock.%d\n",height,MarmaraUnlockht(height),ht,unlockht); } else fprintf(stderr,"ht.%d error decoding coinbase opret\n",height); } From 6617435e16d1dc4fdd02622375ae4768c0bb5134 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 05:12:15 -1100 Subject: [PATCH 010/144] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 6c6f824e7..908f80b39 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -235,7 +235,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) char addr0[64],addr1[64]; Getscriptaddress(addr0,ccvout.scriptPubKey); Getscriptaddress(addr1,tx.vout[0].scriptPubKey); - fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey %s vs %s pk.%d %s\n",height,addr0,addr1,(int32_t)pk.size(),HexStr(pk)); + fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey %s vs %s pk.%d %s\n",height,addr0,addr1,(int32_t)pk.size(),HexStr(pk).c_str()); } else fprintf(stderr,"ht.%d %d vs %d unlock.%d\n",height,MarmaraUnlockht(height),ht,unlockht); } else fprintf(stderr,"ht.%d error decoding coinbase opret\n",height); } From 3231c57262d45402f6c1f7fd3f773b92deebdb43 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 05:13:57 -1100 Subject: [PATCH 011/144] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 908f80b39..1afd97dc1 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -183,7 +183,7 @@ CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) ccvout = MakeCC1of2vout(EVAL_MARMARA,0,Marmarapk,pk); char coinaddr[64]; Getscriptaddress(coinaddr,ccvout.scriptPubKey); - fprintf(stderr,"Marmara_scriptPubKey %s ht.%d -> %s\n",HexStr(pk),height,coinaddr); + fprintf(stderr,"Marmara_scriptPubKey %s ht.%d -> %s\n",HexStr(pk).c_str(),height,coinaddr); } return(ccvout.scriptPubKey); } From 72e7bc73b82cdcb5dda6c6dc8b6f082129cc5079 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 05:20:20 -1100 Subject: [PATCH 012/144] Test --- src/miner.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index a44eb380c..ba2ceefb8 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -545,6 +545,9 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 // to transaction if so, cast for GTE operator if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) { + char checkaddr[64]; + Getscriptaddress(checkaddr,txNew.vout[0].scriptPubKey); + fprintf(stderr,"set mining coinbase -> %s\n",checkaddr); txNew.vout.resize(2); txNew.vout[1].nValue = 0; txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret('C',nHeight,pk); From 97f40221f9334c930fda4882743042140de8b391 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 05:21:09 -1100 Subject: [PATCH 013/144] Test --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index ba2ceefb8..c6309d35e 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -158,6 +158,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33); int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); CScript Marmara_scriptPubKey(int32_t height,CPubKey pk); CScript MarmaraCoinbaseOpret(uint8_t funcid,int32_t height,CPubKey pk); +bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) { From 1d946f881205172886ad209abc8317fdcc6c6c33 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 05:30:48 -1100 Subject: [PATCH 014/144] Test --- src/cc/marmara.cpp | 6 +++--- src/miner.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 1afd97dc1..ce17c0bcb 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -181,9 +181,9 @@ CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) { ccvout = MakeCC1of2vout(EVAL_MARMARA,0,Marmarapk,pk); - char coinaddr[64]; - Getscriptaddress(coinaddr,ccvout.scriptPubKey); - fprintf(stderr,"Marmara_scriptPubKey %s ht.%d -> %s\n",HexStr(pk).c_str(),height,coinaddr); + //char coinaddr[64]; + //Getscriptaddress(coinaddr,ccvout.scriptPubKey); + //fprintf(stderr,"Marmara_scriptPubKey %s ht.%d -> %s\n",HexStr(pk).c_str(),height,coinaddr); } return(ccvout.scriptPubKey); } diff --git a/src/miner.cpp b/src/miner.cpp index c6309d35e..782716fcf 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -548,7 +548,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 { char checkaddr[64]; Getscriptaddress(checkaddr,txNew.vout[0].scriptPubKey); - fprintf(stderr,"set mining coinbase -> %s\n",checkaddr); + //`fprintf(stderr,"set mining coinbase -> %s\n",checkaddr); txNew.vout.resize(2); txNew.vout[1].nValue = 0; txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret('C',nHeight,pk); From 2dc911558b0a9aa31b0e00356b799330f85261e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 05:40:47 -1100 Subject: [PATCH 015/144] -print --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ebc50fa62..fc302c545 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2176,7 +2176,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } else { - fprintf(stderr,"ht.%d error validating winning blocktime %u -> %.8f eligible.%u test prior\n",nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); + //fprintf(stderr,"ht.%d error validating winning blocktime %u -> %.8f eligible.%u test prior\n",nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); continue; } eligible = besttime; From c8af7b80f79b230f0ccaa9a6ac44effe87834ab5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 06:03:51 -1100 Subject: [PATCH 016/144] -print --- src/cc/marmara.cpp | 1 + src/miner.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index ce17c0bcb..5c61ebeef 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -521,6 +521,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,pk,amount,matures,currency)) != 0 ) { GetCCaddress1of2(cp,coinaddr,Marmarapk,pk); + make tx here fprintf(stderr,"get locked funds of %s %.8f\n",coinaddr,(double)CCaddress_balance(coinaddr)/COIN); } else fprintf(stderr,"null funcid for creditloop[%d]\n",i); } else fprintf(stderr,"couldnt get creditloop[%d]\n",i); diff --git a/src/miner.cpp b/src/miner.cpp index 782716fcf..cbc033d47 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1609,7 +1609,7 @@ void static BitcoinMiner() int32_t percPoS,z; bool fNegative,fOverflow; HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); HASHTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - if ( ASSETCHAINS_STAKED < 100 ) + if ( ASSETCHAINS_STAKED < 100 && KOMODO_MININGTHREADS == 0 ) { for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); From 3d8083fb4d4a5de9b116fa9e37d0e7e0dabe853e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 06:05:05 -1100 Subject: [PATCH 017/144] -print --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5c61ebeef..6a9c78472 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -521,7 +521,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,pk,amount,matures,currency)) != 0 ) { GetCCaddress1of2(cp,coinaddr,Marmarapk,pk); - make tx here + //make tx here fprintf(stderr,"get locked funds of %s %.8f\n",coinaddr,(double)CCaddress_balance(coinaddr)/COIN); } else fprintf(stderr,"null funcid for creditloop[%d]\n",i); } else fprintf(stderr,"couldnt get creditloop[%d]\n",i); From 3dcde0ccf1d8d9cab1b0ecfcc26d18f070bcffe1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 06:07:36 -1100 Subject: [PATCH 018/144] +ht --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index cbc033d47..3a163c637 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1613,7 +1613,7 @@ void static BitcoinMiner() { for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); - fprintf(stderr," PoW for staked coin PoS %d%% vs target %d%%\n",percPoS,(int32_t)ASSETCHAINS_STAKED); + fprintf(stderr," PoW for staked coin PoS %d%% vs target %d%% ht.%d\n",percPoS,(int32_t)ASSETCHAINS_STAKED,Mining_height); } } while (true) From 060986987449d2beca241a4fc14d7978a26251db Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 20:26:02 -1100 Subject: [PATCH 019/144] Ise fixes --- src/cc/CCtx.cpp | 2 +- src/komodo.h | 5 +++++ src/komodo_gateway.h | 2 +- src/komodo_jumblr.h | 10 +++++----- src/main.cpp | 2 ++ src/wallet/rpcwallet.cpp | 2 +- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index a80b3b3cf..546c4cb6b 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -384,8 +384,8 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 { int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=64; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; #ifdef ENABLE_WALLET - const CKeyStore& keystore = *pwalletMain; assert(pwalletMain != NULL); + const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); utxos = (struct CC_utxo *)calloc(maxutxos,sizeof(*utxos)); diff --git a/src/komodo.h b/src/komodo.h index 4c97a8171..7d2b17963 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -799,6 +799,11 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) uint64_t signedmask,voutmask; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; uint8_t scriptbuf[10001],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 zero,btctxid,txhash; int32_t i,j,k,numnotaries,notarized,scriptlen,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; + if ( pindex == 0 ) + { + fprintf(stderr,"komodo_connectblock null pindex\n"); + return; + } memset(&zero,0,sizeof(zero)); komodo_init(pindex->GetHeight()); KOMODO_INITDONE = (uint32_t)time(NULL); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e19d94915..02ab67407 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1388,7 +1388,7 @@ void komodo_passport_iteration() { static long lastpos[34]; static char userpass[33][1024]; static uint32_t lasttime,callcounter,lastinterest; int32_t maxseconds = 10; - FILE *fp; uint8_t *filedata; long fpos,datalen,lastfpos; int32_t baseid,limit,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; uint32_t buf[3],starttime; cJSON *infoobj,*result; uint64_t RTmask = 0; //CBlockIndex *pindex; + FILE *fp; uint8_t *filedata; long fpos,datalen,lastfpos; int32_t baseid,limit,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; uint32_t buf[3],starttime; uint64_t RTmask = 0; //CBlockIndex *pindex; expired = 0; while ( KOMODO_INITDONE == 0 ) { diff --git a/src/komodo_jumblr.h b/src/komodo_jumblr.h index 5a5ad0885..fca7395e5 100755 --- a/src/komodo_jumblr.h +++ b/src/komodo_jumblr.h @@ -629,7 +629,7 @@ uint64_t jumblr_increment(uint8_t r,int32_t height,uint64_t total,uint64_t bigge void jumblr_iteration() { static int32_t lastheight; static uint32_t lasttime; - char *zaddr,*addr,*retstr,secretaddr[64]; cJSON *array; int32_t i,iter,height,acpublic,counter,chosen_one,n; uint64_t smallest,medium,biggest,amount=0,total=0; double fee; struct jumblr_item *ptr,*tmp; uint16_t r,s; + char *zaddr,*addr,*retstr=0,secretaddr[64]; cJSON *array; int32_t i,iter,height,acpublic,counter,chosen_one,n; uint64_t smallest,medium,biggest,amount=0,total=0; double fee; struct jumblr_item *ptr,*tmp; uint16_t r,s; acpublic = ASSETCHAINS_PUBLIC; if ( ASSETCHAINS_SYMBOL[0] == 0 && GetTime() >= KOMODO_SAPLING_DEADLINE ) acpublic = 1; @@ -648,7 +648,7 @@ void jumblr_iteration() } free_json(array); } - free(retstr); + free(retstr), retstr = 0; } } height = (int32_t)chainActive.LastTip()->GetHeight(); @@ -691,7 +691,7 @@ void jumblr_iteration() if ( amount > 0 && (retstr= jumblr_sendt_to_z(Jumblr_deposit,addr,dstr(amount))) != 0 ) { printf("sendt_to_z.(%s)\n",retstr); - free(retstr); + free(retstr), retstr = 0; } free(zaddr); } else printf("no zaddr from jumblr_zgetnewaddress\n"); @@ -723,7 +723,7 @@ void jumblr_iteration() if ( (retstr= jumblr_sendz_to_z(ptr->dest,addr,dstr(total))) != 0 ) { printf("n.%d counter.%d chosen_one.%d send z_to_z.(%s)\n",n,counter,chosen_one,retstr); - free(retstr); + free(retstr), retstr = 0; } ptr->spent = (uint32_t)time(NULL); free(zaddr); @@ -768,7 +768,7 @@ void jumblr_iteration() if ( (retstr= jumblr_sendz_to_t(ptr->dest,secretaddr,dstr(total))) != 0 ) { printf("%s send z_to_t.(%s)\n",secretaddr,retstr); - free(retstr); + free(retstr), retstr = 0; } else printf("null return from jumblr_sendz_to_t\n"); ptr->spent = (uint32_t)time(NULL); break; diff --git a/src/main.cpp b/src/main.cpp index 929ec9d5e..21b6b4eb0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3497,6 +3497,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin CDiskBlockPos pos; if (!FindUndoPos(state, pindex->nFile, pos, ::GetSerializeSize(blockundo, SER_DISK, CLIENT_VERSION) + 40)) return error("ConnectBlock(): FindUndoPos failed"); + if ( pindex->pprev == 0 ) + fprintf(stderr,"ConnectBlock: unexpected null pprev\n"); if (!UndoWriteToDisk(blockundo, pos, pindex->pprev->GetBlockHash(), chainparams.MessageStart())) return AbortNode(state, "Failed to write undo data"); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 0dcaaa848..5d15381c6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5094,8 +5094,8 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) if (!EnsureWalletIsAvailable(0)) return 0; - const CKeyStore& keystore = *pwalletMain; assert(pwalletMain != NULL); + const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); utxovalue = 0; memset(&utxotxid,0,sizeof(utxotxid)); From 88e77b78515358e297f58be35567b801d250c527 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 20:56:41 -1100 Subject: [PATCH 020/144] Allow null batontxid for issue --- src/cc/marmara.cpp | 2 -- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 6a9c78472..94608e1a4 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -443,8 +443,6 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a mypk = pubkey2pk(Mypubkey()); if ( MarmaraGetcreatetxid(createtxid,approvaltxid) < 0 ) errorstr = (char *)"cant get createtxid from approvaltxid"; - else if ( batontxid == zeroid ) - errorstr = (char *)"null batontxid"; else if ( currency != "MARMARA" ) errorstr = (char *)"for now, only MARMARA loops are supported"; else if ( amount < txfee ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5d15381c6..2ce2435a7 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5581,7 +5581,7 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); uint256 approvaltxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || params.size() != 5 ) { - // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 3903 010ff7f9256cefe3b5dee3d72c0eeae9fc6f34884e6f32ffe5b60916df54a9be + // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1168 32da4cb3e886ee42de90b4a15042d71169077306badf909099c5c5c692df3f27 throw runtime_error("marmaraissue receiverpk amount currency matures approvaltxid\n"); } if ( ensure_CCrequirements() < 0 ) From 8ef46649e55ecf00b4d04c5a828dfcc3498be0a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 21:02:23 -1100 Subject: [PATCH 021/144] Fix --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 94608e1a4..d37314e9e 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -669,6 +669,8 @@ UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_ { UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i,n,matches; int64_t totalamount=0; std::vector issuances; char coinaddr[64]; CPubKey Marmarapk; struct CCcontract_info *cp,C; + cp = CCinit(&C,EVAL_MARMARA); + Marmarapk = GetUnspendable(cp,0); result.push_back(Pair("result","success")); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(Mypubkey())) << OP_CHECKSIG); result.push_back(Pair("myaddress",coinaddr)); @@ -687,8 +689,6 @@ UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_ result.push_back(Pair("minamount",ValueFromAmount(minamount))); result.push_back(Pair("maxamount",ValueFromAmount(maxamount))); result.push_back(Pair("currency",currency)); - cp = CCinit(&C,EVAL_MARMARA); - Marmarapk = GetUnspendable(cp,0); if ( (n= MarmaraGetCreditloops(totalamount,issuances,cp,firstheight,lastheight,minamount,maxamount,refpk,currency)) > 0 ) { result.push_back(Pair("n",n)); From e1037c704cef7aa5b8958ad38dbe851013dc80ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 23:22:00 -1100 Subject: [PATCH 022/144] Prepare to create settlement tx --- src/cc/CCMarmara.h | 1 + src/cc/marmara.cpp | 176 +++++++++++++++++++++++++-------------- src/komodo_bitcoind.h | 65 ++++++++++----- src/wallet/rpcwallet.cpp | 6 +- 4 files changed, 158 insertions(+), 90 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 753f8edb6..d008095f7 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -24,6 +24,7 @@ #define MARMARA_MINLOCK (1440 * 3 * 30) #define MARMARA_MAXLOCK (1440 * 24 * 30) +extern uint8_t ASSETCHAINS_MARMARA; uint64_t komodo_block_prg(uint32_t nHeight); int32_t MarmaraGetcreatetxid(uint256 &createtxid,uint256 txid); int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid,uint256 txid); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index d37314e9e..c82a28f4c 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -245,6 +245,8 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { std::vector vopret; CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid,vfuncid,*script; CPubKey pk,vpk; + if ( ASSETCHAINS_MARMARA == 0 ) + return eval->Invalid("-ac_marmara must be set for marmara CC"); numvins = tx.vin.size(); numvouts = tx.vout.size(); if ( numvouts < 1 ) @@ -344,6 +346,116 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, return(totalinputs); } +UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount,remaining,change,avail; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; + if ( txfee == 0 ) + txfee = 10000; + cp = CCinit(&C,EVAL_MARMARA); + mypk = pubkey2pk(Mypubkey()); + Marmarapk = GetUnspendable(cp,0); + remaining = change = 0; + if ( (n= MarmaraGetbatontxid(creditloop,batontxid,refbatontxid)) > 0 ) + { + if ( GetTransaction(batontxid,batontx,hashBlock,false) != 0 && (numvouts= batontx.vout.size()) > 1 ) + { + if ( (funcid= MarmaraDecodeLoopOpret(batontx.vout[numvouts-1].scriptPubKey,refcreatetxid,pk,refamount,refmatures,refcurrency)) != 0 ) + { + if ( refcreatetxid != creditloop[0] ) + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"invalid refcreatetxid, setting to creditloop[0]")); + return(result); + } + if ( chainActive.LastTip()->GetHeight() < refmatures ) + { + fprintf(stderr,"doesnt mature for another %d blocks\n",refmatures - chainActive.LastTip()->GetHeight())' + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"cant settle immature creditloop")); + return(result); + } + remaining = refamount; + GetCCaddress(cp,myCCaddr,Mypubkey()); + Getscriptaddress(batonCCaddr,batontx.vout[0].scriptPubKey); + if ( strcmp(myCCaddr,batonCCaddr) == 0 ) + { + mtx.vin.push_back(CTxIn(batontxid,0,CScript())); + for (i=0; i 1 ) + { + if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,pk,amount,matures,currency)) != 0 ) + { + GetCCaddress1of2(cp,coinaddr,Marmarapk,pk); + avail = CCaddress_balance(coinaddr); + if ( avail > remaining ) + { + // add remaining + change = (avail - remaining); + mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + if ( change > txfee ) + mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,change,Marmarapk,pk)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount,matures,currency)); + result.push_back(Pair("result",(char *)"success")); + result.push_back(Pair("rawtx",rawtx)); + return(result); + } + else if ( avail > txfee ) + { + // add all utxos + remaining -= avail; + } + fprintf(stderr,"get locked funds of %s %.8f\n",coinaddr,(double)avail/COIN); + } else fprintf(stderr,"null funcid for creditloop[%d]\n",i); + } else fprintf(stderr,"couldnt get creditloop[%d]\n",i); + } + if ( amount - remaining > 2*txfee ) + { + mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,createtxid))) << OP_CHECKSIG)); // failure marker + if ( amount-remaining > 3*txfee ) + mtx.vout.push_back(CTxOut(amount-remaining-2*txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount-remaining,-remaining,currency)); + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"insufficient funds")); + result.push_back(Pair("rawtx",rawtx)); + result.push_back(Pair("remaining",ValueFromAmount(remaining))); + } + else + { + // jl777: maybe fund a txfee to report no funds avail + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"no funds available at all")); + } + } + else + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"this node does not have the baton")); + result.push_back(Pair("myCCaddr",myCCaddr)); + result.push_back(Pair("batonCCaddr",batonCCaddr)); + } + } + else + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"couldnt get batontxid opret")); + } + } + else + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"couldnt find batontxid")); + } + } + else + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"couldnt get creditloop")); + } + return(result); +} + int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuances,struct CCcontract_info *cp,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,CPubKey refpk,std::string refcurrency) { char coinaddr[64]; CPubKey Marmarapk,senderpk; int64_t amount; uint256 createtxid,txid,hashBlock; CTransaction tx; int32_t numvouts,vout,matures,n=0; std::string currency; @@ -489,70 +601,6 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a return(result); } -UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) -{ - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey Marmarapk,pk; std::string currency,refcurrency; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; - if ( txfee == 0 ) - txfee = 10000; - cp = CCinit(&C,EVAL_MARMARA); - Marmarapk = GetUnspendable(cp,0); - if ( (n= MarmaraGetbatontxid(creditloop,batontxid,refbatontxid)) > 0 ) - { - if ( GetTransaction(batontxid,batontx,hashBlock,false) != 0 && (numvouts= batontx.vout.size()) > 1 ) - { - if ( (funcid= MarmaraDecodeLoopOpret(batontx.vout[numvouts-1].scriptPubKey,refcreatetxid,pk,refamount,refmatures,refcurrency)) != 0 ) - { - if ( refcreatetxid != creditloop[0] ) - { - fprintf(stderr,"invalid refcreatetxid, setting to creditloop[0]\n"); - refcreatetxid = creditloop[0]; - numerrs++; - } - GetCCaddress(cp,myCCaddr,Mypubkey()); - Getscriptaddress(batonCCaddr,batontx.vout[0].scriptPubKey); - if ( strcmp(myCCaddr,batonCCaddr) == 0 ) - { - for (i=0; i 1 ) - { - if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,pk,amount,matures,currency)) != 0 ) - { - GetCCaddress1of2(cp,coinaddr,Marmarapk,pk); - //make tx here - fprintf(stderr,"get locked funds of %s %.8f\n",coinaddr,(double)CCaddress_balance(coinaddr)/COIN); - } else fprintf(stderr,"null funcid for creditloop[%d]\n",i); - } else fprintf(stderr,"couldnt get creditloop[%d]\n",i); - } - } - else - { - result.push_back(Pair("result",(char *)"error")); - result.push_back(Pair("error",(char *)"this node does not have the baton")); - result.push_back(Pair("myCCaddr",myCCaddr)); - result.push_back(Pair("batonCCaddr",batonCCaddr)); - } - } - else - { - result.push_back(Pair("result",(char *)"error")); - result.push_back(Pair("error",(char *)"couldnt get batontxid opret")); - } - } - else - { - result.push_back(Pair("result",(char *)"error")); - result.push_back(Pair("error",(char *)"couldnt find batontxid")); - } - } - else - { - result.push_back(Pair("result",(char *)"error")); - result.push_back(Pair("error",(char *)"couldnt get creditloop")); - } - return(result); -} - UniValue MarmaraCreditloop(uint256 txid) { UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey pk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index fc302c545..19a5f8103 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -643,6 +643,10 @@ int32_t komodo_isPoS(CBlock *pblock) { txid = pblock->vtx[n-1].vin[0].prevout.hash; vout = pblock->vtx[n-1].vin[0].prevout.n; + if ( ASSETCHAINS_MARMARA != 0 ) + { + // need to verify it was signed by the non-Marmarapk of the 1of2 + } txtime = komodo_txtime(&value,txid,vout,destaddr); if ( ExtractDestination(pblock->vtx[n-1].vout[0].scriptPubKey,voutaddress) ) { @@ -2112,34 +2116,42 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt maxkp = numkp = 0; lasttime = 0; } - BOOST_FOREACH(const COutput& out, vecOutputs) + if ( ASSETCHAINS_MARMARA == 0 || 1 ) { - if ( (tipindex= chainActive.Tip()) == 0 || tipindex->GetHeight()+1 > nHeight ) + BOOST_FOREACH(const COutput& out, vecOutputs) { - fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter); - return(0); - } - counter++; - if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) - { - fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); - continue; - } - CAmount nValue = out.tx->vout[out.i].nValue; - if ( nValue < COIN || !out.fSpendable ) - continue; - const CScript& pk = out.tx->vout[out.i].scriptPubKey; - if ( ExtractDestination(pk,address) != 0 ) - { - if ( IsMine(*pwalletMain,address) == 0 ) - continue; - if ( GetTransaction(out.tx->GetHash(),tx,hashBlock,true) != 0 && (pindex= komodo_getblockindex(hashBlock)) != 0 ) + if ( (tipindex= chainActive.Tip()) == 0 || tipindex->GetHeight()+1 > nHeight ) { - array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,out.tx->GetHash(),out.i,(char *)CBitcoinAddress(address).ToString().c_str(),hashbuf,(CScript)pk); - //fprintf(stderr,"addutxo numkp.%d vs max.%d\n",numkp,maxkp); + fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter); + return(0); + } + counter++; + if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) + { + fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); + continue; + } + CAmount nValue = out.tx->vout[out.i].nValue; + if ( nValue < COIN || !out.fSpendable ) + continue; + const CScript& pk = out.tx->vout[out.i].scriptPubKey; + if ( ExtractDestination(pk,address) != 0 ) + { + if ( IsMine(*pwalletMain,address) == 0 ) + continue; + if ( GetTransaction(out.tx->GetHash(),tx,hashBlock,true) != 0 && (pindex= komodo_getblockindex(hashBlock)) != 0 ) + { + array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,out.tx->GetHash(),out.i,(char *)CBitcoinAddress(address).ToString().c_str(),hashbuf,(CScript)pk); + //fprintf(stderr,"addutxo numkp.%d vs max.%d\n",numkp,maxkp); + } } } } + else + { + // calc 1of2 address + // iterate all unspents not spent in mempool and komodo_addutxo + } lasttime = (uint32_t)time(NULL); //fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp); } @@ -2218,7 +2230,14 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt txNew.vout[0].nValue = *utxovaluep - txfee; txNew.nLockTime = earliest; CTransaction txNewConst(txNew); - signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, *utxovaluep, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId); + if ( ASSETCHAINS_MARMARA == 0 || 1 ) + { + signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, *utxovaluep, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId); + } + else + { + // signSuccess = CCFinalizetx(...) + } if (!signSuccess) fprintf(stderr,"failed to create signature\n"); else diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 2ce2435a7..877342306 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5554,7 +5554,7 @@ UniValue marmara_receive(const UniValue& params, bool fHelp) if ( fHelp || (params.size() != 5 && params.size() != 4) ) { // 1st marmarareceive 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 1440 - // after marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 3903 bf6b4d42aa3ce974c853d73b06c78597dd3b5fb493d5d0d944f72c2017f561ad + // after marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1168 d72d87aa0d50436de695c93e2bf3d7273c63c92ef6307913aa01a6ee6a16548b throw runtime_error("marmarareceive senderpk amount currency matures batontxid\n"); } if ( ensure_CCrequirements() < 0 ) @@ -5604,7 +5604,7 @@ UniValue marmara_transfer(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); uint256 approvaltxid,batontxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; std::vector creditloop; if ( fHelp || params.size() != 5 ) { - // marmaratransfer 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 3903 748a4c80e6f6b725340fb0f52738f38a11c422d59b3034c8366b3d7b33c99a1e + // marmaratransfer 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 1168 1506c774e4b2804a6e25260920840f4cfca8d1fb400e69fe6b74b8e593dbedc5 throw runtime_error("marmaratransfer receiverpk amount currency matures approvaltxid\n"); } if ( ensure_CCrequirements() < 0 ) @@ -5674,7 +5674,7 @@ UniValue marmara_settlement(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) { // marmarasettlement 010ff7f9256cefe3b5dee3d72c0eeae9fc6f34884e6f32ffe5b60916df54a9be - // marmarasettlement cc23bf81733556dc06db2fd9c9f4178cad44bdc237d6e62101cf0cdafb5195f7 + // marmarasettlement ff3e259869196f3da9b5ea3f9e088a76c4fc063cf36ab586b652e121d441a603 throw runtime_error("marmarasettlement batontxid\n"); } if ( ensure_CCrequirements() < 0 ) From af6dae789e93c63272afd56f9bf8417dfeac504f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Jan 2019 23:23:10 -1100 Subject: [PATCH 023/144] syntax --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index c82a28f4c..9e921df6b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -349,7 +349,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount,remaining,change,avail; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount,remaining,change,avail; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; struct CCcontract_info *cp,C; if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); @@ -370,7 +370,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) } if ( chainActive.LastTip()->GetHeight() < refmatures ) { - fprintf(stderr,"doesnt mature for another %d blocks\n",refmatures - chainActive.LastTip()->GetHeight())' + fprintf(stderr,"doesnt mature for another %d blocks\n",refmatures - chainActive.LastTip()->GetHeight()); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"cant settle immature creditloop")); return(result); From 024a9fd81e589daa708850afd12f99709fbb83d4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:23:26 -1100 Subject: [PATCH 024/144] implemented marmarasettlement --- src/cc/CCMarmara.h | 1 + src/cc/marmara.cpp | 55 ++++++++++++++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index d008095f7..6c81ed689 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -23,6 +23,7 @@ #define MARMARA_GROUPSIZE 60 #define MARMARA_MINLOCK (1440 * 3 * 30) #define MARMARA_MAXLOCK (1440 * 24 * 30) +#define MARMARA_VINS 16 extern uint8_t ASSETCHAINS_MARMARA; uint64_t komodo_block_prg(uint32_t nHeight); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 9e921df6b..ca11f276e 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -82,13 +82,13 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript scriptPubKey,CPubKey &pk,int32 } if ( vopret.size() > 2 && script[0] == EVAL_MARMARA ) { - if ( script[1] == 'C' || script[1] == 'P' ) + if ( script[1] == 'C' || script[1] == 'P' || script[1] == 'L' ) { if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk; ss >> height; ss >> unlockht) != 0 ) { return(script[1]); } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for %c\n",script[1]); - } else fprintf(stderr,"script[1] is %d != 'C' %d or 'P' %d\n",script[1],'C','P'); + } else fprintf(stderr,"script[1] is %d != 'C' %d or 'P' %d or 'L' %d\n",script[1],'C','P','L'); } else fprintf(stderr,"vopret.size() is %d\n",(int32_t)vopret.size()); return(0); } @@ -346,10 +346,39 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, return(totalinputs); } +int64_t AddMarmarainputs(CMutableTransaction &mtx,char *coinaddr,int64_t total,int32_t maxinputs) +{ + uint64_t threshold,nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction tx; int32_t numvouts,vout,n = 0; uint8_t funcid; + std::vector > unspentOutputs; + SetCCunspents(unspentOutputs,coinaddr); + threshold = total/(maxinputs+1); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + if ( it->second.satoshis < threshold ) + continue; + if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 && vout < numvouts && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + { + if ( (funcid= DecodeMaramaraCoinbaseOpRet(tx.vout[numvouts-1].scriptPubKey,pk,ht,unlockht) == 'C' || funcid == 'P' || funcid == 'L' ) + { + char str[64]; fprintf(stderr,"(%s) %s/v%d %.8f ht.%d unlockht.%d\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN,ht,unlockht); + if ( total != 0 && maxinputs != 0 ) + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + totalinputs += it->second.satoshis; + n++; + if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) + break; + } else fprintf(stderr,"null funcid\n"); + } + } + return(totalinputs); +} + UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount,remaining,change,avail; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount,remaining,inputsum,change; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; struct CCcontract_info *cp,C; if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); @@ -388,25 +417,19 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,pk,amount,matures,currency)) != 0 ) { GetCCaddress1of2(cp,coinaddr,Marmarapk,pk); - avail = CCaddress_balance(coinaddr); - if ( avail > remaining ) + if ( (inputsum= AddMarmarainputs(mtx,coinaddr,remaining,MARMARA_VINS)) >= remaining ) { - // add remaining - change = (avail - remaining); + change = (inputsum - remaining); mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); if ( change > txfee ) mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,change,Marmarapk,pk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount,matures,currency)); + rawtx = FinalizeCCTx(0,cp,mtx,Marmarapk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount,matures,currency)); result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); return(result); - } - else if ( avail > txfee ) - { - // add all utxos - remaining -= avail; - } - fprintf(stderr,"get locked funds of %s %.8f\n",coinaddr,(double)avail/COIN); + } else remaining -= inputsum; + if ( mtx.vin.size() >= CC_MAXVINS - MARMARA_VINS ) + break; } else fprintf(stderr,"null funcid for creditloop[%d]\n",i); } else fprintf(stderr,"couldnt get creditloop[%d]\n",i); } @@ -415,7 +438,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,createtxid))) << OP_CHECKSIG)); // failure marker if ( amount-remaining > 3*txfee ) mtx.vout.push_back(CTxOut(amount-remaining-2*txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount-remaining,-remaining,currency)); + rawtx = FinalizeCCTx(0,cp,mtx,Marmarapk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount-remaining,-remaining,currency)); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"insufficient funds")); result.push_back(Pair("rawtx",rawtx)); From 62d50529edbba03c7af0234927d73fd6c2baef99 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:24:53 -1100 Subject: [PATCH 025/144] Fix --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index ca11f276e..81ae9cb29 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -348,7 +348,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, int64_t AddMarmarainputs(CMutableTransaction &mtx,char *coinaddr,int64_t total,int32_t maxinputs) { - uint64_t threshold,nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction tx; int32_t numvouts,vout,n = 0; uint8_t funcid; + uint64_t threshold,nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction tx; int32_t numvouts,ht,vout,n = 0; uint8_t funcid; CPubKey pk; std::vector > unspentOutputs; SetCCunspents(unspentOutputs,coinaddr); threshold = total/(maxinputs+1); @@ -360,7 +360,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,char *coinaddr,int64_t total,i continue; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 && vout < numvouts && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { - if ( (funcid= DecodeMaramaraCoinbaseOpRet(tx.vout[numvouts-1].scriptPubKey,pk,ht,unlockht) == 'C' || funcid == 'P' || funcid == 'L' ) + if ( (funcid= DecodeMaramaraCoinbaseOpRet(tx.vout[numvouts-1].scriptPubKey,pk,ht,unlockht)) == 'C' || funcid == 'P' || funcid == 'L' ) { char str[64]; fprintf(stderr,"(%s) %s/v%d %.8f ht.%d unlockht.%d\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN,ht,unlockht); if ( total != 0 && maxinputs != 0 ) From c9b9d1f26f4beaa63477f176e873b1972581674b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:25:42 -1100 Subject: [PATCH 026/144] Unlockht --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 81ae9cb29..883e8f08c 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -348,7 +348,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, int64_t AddMarmarainputs(CMutableTransaction &mtx,char *coinaddr,int64_t total,int32_t maxinputs) { - uint64_t threshold,nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction tx; int32_t numvouts,ht,vout,n = 0; uint8_t funcid; CPubKey pk; + uint64_t threshold,nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction tx; int32_t numvouts,ht,unlockht,vout,n = 0; uint8_t funcid; CPubKey pk; std::vector > unspentOutputs; SetCCunspents(unspentOutputs,coinaddr); threshold = total/(maxinputs+1); From a47537398fc07d60391790ac3989ab4f039a27b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:29:43 -1100 Subject: [PATCH 027/144] Sign with mypk --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 883e8f08c..290600ddd 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -423,7 +423,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); if ( change > txfee ) mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,change,Marmarapk,pk)); - rawtx = FinalizeCCTx(0,cp,mtx,Marmarapk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount,matures,currency)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount,matures,currency)); result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); return(result); @@ -438,7 +438,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,createtxid))) << OP_CHECKSIG)); // failure marker if ( amount-remaining > 3*txfee ) mtx.vout.push_back(CTxOut(amount-remaining-2*txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - rawtx = FinalizeCCTx(0,cp,mtx,Marmarapk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount-remaining,-remaining,currency)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,amount-remaining,-remaining,currency)); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"insufficient funds")); result.push_back(Pair("rawtx",rawtx)); From 1f3dd2947c8030d7bf5d36f396050a6a08838b51 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:42:08 -1100 Subject: [PATCH 028/144] Pubkeys vector --- src/cc/CCinclude.h | 2 +- src/cc/CCtx.cpp | 32 ++++++++++++++++++++++++++------ src/cc/marmara.cpp | 10 +++++++--- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 40028ee5c..871285ae8 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -179,7 +179,7 @@ int64_t CCduration(int32_t &numblocks,uint256 txid); bool komodo_txnotarizedconfirmed(uint256 txid); // CCtx bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey); -std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret); +std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys=0); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr); void SetCCtxids(std::vector > &addressIndex,char *coinaddr); int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 546c4cb6b..317b9549b 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -38,13 +38,14 @@ bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScrip return(false); } -std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret) +std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys) { auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); - CTransaction vintx; std::string hex; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0; + CTransaction vintx; std::string hex; CPubKey globalpk; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0; int64_t utxovalues[CC_MAXVINS],change,normalinputs=0,totaloutputs=0,normaloutputs=0,totalinputs=0,normalvins=0,ccvins=0; - int32_t i,utxovout,n,err = 0; char myaddr[64],destaddr[64],unspendable[64]; - uint8_t *privkey,myprivkey[32],unspendablepriv[32],*msg32 = 0; CC *mycond=0,*othercond=0,*othercond2=0,*othercond3=0,*cond; CPubKey unspendablepk; + int32_t i,flag,utxovout,n,err = 0; char myaddr[64],destaddr[64],unspendable[64]; + uint8_t *privkey,myprivkey[32],unspendablepriv[32],*msg32 = 0; CC *mycond=0,*othercond=0,*othercond2=0,*othercond3=0,*othercond4=0,*cond; CPubKey unspendablepk; + globalpk = GetUnspendable(cp,0); n = mtx.vout.size(); for (i=0; iunspendablepriv; + if ( othercond4 != 0 ) + cc_free(othercond4); + othercond4 = MakeCCcond1of2(cp->evalcode,globalpk,pubkeys[i]); + cond = othercond4; + flag = 1; + } + } + if ( flag == 0 ) + { + fprintf(stderr,"CC signing error: vini.%d has unknown CC address.(%s)\n",i,destaddr); + continue; + } } uint256 sighash = SignatureHash(CCPubKey(cond), mtx, i, SIGHASH_ALL, utxovalues[i],consensusBranchId, &txdata); if ( cc_signTreeSecp256k1Msg32(cond,privkey,sighash.begin()) != 0 ) @@ -190,6 +208,8 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran cc_free(othercond2); if ( othercond3 != 0 ) cc_free(othercond3); + if ( othercond4 != 0 ) + cc_free(othercond4); std::string strHex = EncodeHexTx(mtx); if ( strHex.size() > 0 ) return(strHex); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 290600ddd..59ec3d73c 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -346,7 +346,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, return(totalinputs); } -int64_t AddMarmarainputs(CMutableTransaction &mtx,char *coinaddr,int64_t total,int32_t maxinputs) +int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys,char *coinaddr,int64_t total,int32_t maxinputs) { uint64_t threshold,nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction tx; int32_t numvouts,ht,unlockht,vout,n = 0; uint8_t funcid; CPubKey pk; std::vector > unspentOutputs; @@ -364,7 +364,10 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,char *coinaddr,int64_t total,i { char str[64]; fprintf(stderr,"(%s) %s/v%d %.8f ht.%d unlockht.%d\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN,ht,unlockht); if ( total != 0 && maxinputs != 0 ) + { mtx.vin.push_back(CTxIn(txid,vout,CScript())); + pubkeys.push_back(pk); + } totalinputs += it->second.satoshis; n++; if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) @@ -378,7 +381,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,char *coinaddr,int64_t total,i UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount,remaining,inputsum,change; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount,remaining,inputsum,change; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; std::vector pubkeys; struct CCcontract_info *cp,C; if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); @@ -410,6 +413,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) if ( strcmp(myCCaddr,batonCCaddr) == 0 ) { mtx.vin.push_back(CTxIn(batontxid,0,CScript())); + pubkeys.push_back(mypk); for (i=0; i 1 ) @@ -417,7 +421,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,pk,amount,matures,currency)) != 0 ) { GetCCaddress1of2(cp,coinaddr,Marmarapk,pk); - if ( (inputsum= AddMarmarainputs(mtx,coinaddr,remaining,MARMARA_VINS)) >= remaining ) + if ( (inputsum= AddMarmarainputs(mtx,pubkeys,coinaddr,remaining,MARMARA_VINS)) >= remaining ) { change = (inputsum - remaining); mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); From dc737540cf6d67beb53e5fa636d8e09062d05009 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:43:20 -1100 Subject: [PATCH 029/144] NULL --- src/cc/CCinclude.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 871285ae8..197929277 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -179,7 +179,7 @@ int64_t CCduration(int32_t &numblocks,uint256 txid); bool komodo_txnotarizedconfirmed(uint256 txid); // CCtx bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey); -std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys=0); +std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys=NULL); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr); void SetCCtxids(std::vector > &addressIndex,char *coinaddr); int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs); From 8ef1410d28e531d33fd3a76c461a08b5504d5a37 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:46:39 -1100 Subject: [PATCH 030/144] Cast --- src/cc/CCinclude.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 197929277..43b851cc6 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -179,7 +179,7 @@ int64_t CCduration(int32_t &numblocks,uint256 txid); bool komodo_txnotarizedconfirmed(uint256 txid); // CCtx bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey); -std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys=NULL); +std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys = (std::vector)NULL); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr); void SetCCtxids(std::vector > &addressIndex,char *coinaddr); int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs); From d42000a83894c91f93964cd134112b58a7a99379 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:48:21 -1100 Subject: [PATCH 031/144] extern std::vector NULL_pubkeys; --- src/cc/CCinclude.h | 3 ++- src/cc/CCtx.cpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 43b851cc6..2dc3f0a51 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -179,7 +179,8 @@ int64_t CCduration(int32_t &numblocks,uint256 txid); bool komodo_txnotarizedconfirmed(uint256 txid); // CCtx bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey); -std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys = (std::vector)NULL); +extern std::vector NULL_pubkeys; +std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys = NULL_pubkeys); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr); void SetCCtxids(std::vector > &addressIndex,char *coinaddr); int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 317b9549b..9b3e9627c 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -16,6 +16,8 @@ #include "CCinclude.h" #include "key_io.h" +std::vector NULL_pubkeys; + /* FinalizeCCTx is a very useful function that will properly sign both CC and normal inputs, adds normal change and the opreturn. From 39a1f86d6887edaad2169ff4cfd1511282092177 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:49:31 -1100 Subject: [PATCH 032/144] CCpriv --- src/cc/CCtx.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 9b3e9627c..4f5af7ac7 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -164,12 +164,12 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran else { flag = 0; - if ( pubkeys != 0 ) + if ( pubkeys != NULL_pubkeys ) { GetCCaddress1of2(cp,coinaddr,globalpk,pubkeys[i]); if ( strcmp(destaddr,coinaddr) == 0 ) { - privkey = cp->unspendablepriv; + privkey = cp->CCpriv; if ( othercond4 != 0 ) cc_free(othercond4); othercond4 = MakeCCcond1of2(cp->evalcode,globalpk,pubkeys[i]); From 770873156380ea5768c3626ccb44ef46a0040088 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:50:39 -1100 Subject: [PATCH 033/144] Coinaddr --- src/cc/CCtx.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 4f5af7ac7..1a97b4dc1 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -166,6 +166,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran flag = 0; if ( pubkeys != NULL_pubkeys ) { + char coinaddr[64]; GetCCaddress1of2(cp,coinaddr,globalpk,pubkeys[i]); if ( strcmp(destaddr,coinaddr) == 0 ) { From 9bbfa5e89ced283c807feff0f5d6e2cb676b89d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:56:08 -1100 Subject: [PATCH 034/144] Test --- src/cc/CCtx.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 1a97b4dc1..fe6af3f80 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -168,6 +168,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { char coinaddr[64]; GetCCaddress1of2(cp,coinaddr,globalpk,pubkeys[i]); + fprintf(stderr,"%s + %s -> %s vs %s\n",HexStr(globalpk).c_str(),HexStr(pubkeys[i]).c_str(),coinstr,destaddr); if ( strcmp(destaddr,coinaddr) == 0 ) { privkey = cp->CCpriv; From 0480189b29cc7249ae9284118a6a1d03aea24990 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:56:47 -1100 Subject: [PATCH 035/144] Coinaddr --- src/cc/CCtx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index fe6af3f80..c32a79d78 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -168,7 +168,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { char coinaddr[64]; GetCCaddress1of2(cp,coinaddr,globalpk,pubkeys[i]); - fprintf(stderr,"%s + %s -> %s vs %s\n",HexStr(globalpk).c_str(),HexStr(pubkeys[i]).c_str(),coinstr,destaddr); + fprintf(stderr,"%s + %s -> %s vs %s\n",HexStr(globalpk).c_str(),HexStr(pubkeys[i]).c_str(),coinaddr,destaddr); if ( strcmp(destaddr,coinaddr) == 0 ) { privkey = cp->CCpriv; From d4bdc4d79f7f003849598d5fdc5c40b844fbbd51 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 21:58:39 -1100 Subject: [PATCH 036/144] Dont forget to pass in pubkeys --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 59ec3d73c..654cdd600 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -427,7 +427,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); if ( change > txfee ) mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,change,Marmarapk,pk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount,matures,currency)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount,matures,currency),pubkeys); result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); return(result); @@ -442,7 +442,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,createtxid))) << OP_CHECKSIG)); // failure marker if ( amount-remaining > 3*txfee ) mtx.vout.push_back(CTxOut(amount-remaining-2*txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,amount-remaining,-remaining,currency)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,amount-remaining,-remaining,currency),pubkeys); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"insufficient funds")); result.push_back(Pair("rawtx",rawtx)); From 41b29fcc3969313750db2b05983a92bf8cf90356 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 22:07:30 -1100 Subject: [PATCH 037/144] Automatic flag -> lsb of matures --- src/cc/CCMarmara.h | 2 +- src/cc/CCtx.cpp | 2 +- src/cc/marmara.cpp | 11 +++++++++-- src/wallet/rpcwallet.cpp | 3 ++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 6c81ed689..fe9f7f30b 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -33,7 +33,7 @@ UniValue MarmaraCreditloop(uint256 txid); UniValue MarmaraSettlement(uint64_t txfee,uint256 batontxid); UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] -UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid); +UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid,bool automaticflag); UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 approvaltxid,uint256 batontxid); UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index c32a79d78..bb9e02fce 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -168,7 +168,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { char coinaddr[64]; GetCCaddress1of2(cp,coinaddr,globalpk,pubkeys[i]); - fprintf(stderr,"%s + %s -> %s vs %s\n",HexStr(globalpk).c_str(),HexStr(pubkeys[i]).c_str(),coinaddr,destaddr); + //fprintf(stderr,"%s + %s -> %s vs %s\n",HexStr(globalpk).c_str(),HexStr(pubkeys[i]).c_str(),coinaddr,destaddr); if ( strcmp(destaddr,coinaddr) == 0 ) { privkey = cp->CCpriv; diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 654cdd600..fad9921c2 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -301,6 +301,10 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t { return(true); // iterate from issuer all remainder after maturity } + else if ( funcid == 'D' ) // collect -> automatically spend issuers locked funds, given 'I' + { + return(true); // iterate from issuer all remainder after maturity + } // staking only for locked utxo } return eval->Invalid("fall through error"); @@ -515,14 +519,17 @@ int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuanc return(n); } -UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid) +UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid,bool automaticflag) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; uint256 createtxid; int64_t batonamount; int32_t needbaton = 0; cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; - // check for batonownership by senderpk and parameters match createtxid + if ( automaticflag != 0 && (matures & 1) == 0 ) + matures++; + else if ( automaticflag == 0 && (matures & 1) != 0 ) + matures++; mypk = pubkey2pk(Mypubkey()); memset(&createtxid,0,sizeof(createtxid)); if ( batontxid != zeroid && MarmaraGetcreatetxid(createtxid,batontxid) < 0 ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 877342306..899fe3099 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5553,6 +5553,7 @@ UniValue marmara_receive(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); uint256 batontxid; std::vector senderpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || (params.size() != 5 && params.size() != 4) ) { + // automatic flag -> lsb of matures // 1st marmarareceive 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 1440 // after marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1168 d72d87aa0d50436de695c93e2bf3d7273c63c92ef6307913aa01a6ee6a16548b throw runtime_error("marmarareceive senderpk amount currency matures batontxid\n"); @@ -5573,7 +5574,7 @@ UniValue marmara_receive(const UniValue& params, bool fHelp) matures = atol(params[3].get_str().c_str()); batontxid = Parseuint256((char *)params[4].get_str().c_str()); } else matures = atol(params[3].get_str().c_str()) + chainActive.LastTip()->GetHeight() + 1; - return(MarmaraReceive(0,pubkey2pk(senderpub),amount,currency,matures,batontxid)); + return(MarmaraReceive(0,pubkey2pk(senderpub),amount,currency,matures,batontxid,true)); } UniValue marmara_issue(const UniValue& params, bool fHelp) From 5415bbed425cd389b7defb96512b85b25b12ab00 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 22:23:06 -1100 Subject: [PATCH 038/144] Print --- src/cc/marmara.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index fad9921c2..5496590c8 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -404,13 +404,20 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) result.push_back(Pair("error",(char *)"invalid refcreatetxid, setting to creditloop[0]")); return(result); } - if ( chainActive.LastTip()->GetHeight() < refmatures ) + else if ( chainActive.LastTip()->GetHeight() < refmatures ) { fprintf(stderr,"doesnt mature for another %d blocks\n",refmatures - chainActive.LastTip()->GetHeight()); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"cant settle immature creditloop")); return(result); } + else if ( (refmatures & 1) == 0 ) + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"cant automatic settle even maturity heights")); + return(result); + } + fprintf(stderr,"refmatures.%d\n",refmatures); remaining = refamount; GetCCaddress(cp,myCCaddr,Mypubkey()); Getscriptaddress(batonCCaddr,batontx.vout[0].scriptPubKey); From 8099e3af55182e16b46b5e472a5c99a4423c868e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 22:46:45 -1100 Subject: [PATCH 039/144] Test --- src/cc/marmara.cpp | 23 +++++++++++++++++------ src/wallet/rpcwallet.cpp | 2 ++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5496590c8..a945474f7 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -155,18 +155,23 @@ int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid, if ( MarmaraGetcreatetxid(createtxid,txid) == 0 ) { txid = createtxid; - fprintf(stderr,"txid.%s -> createtxid %s\n",txid.GetHex().c_str(),createtxid.GetHex().c_str()); + //fprintf(stderr,"txid.%s -> createtxid %s\n",txid.GetHex().c_str(),createtxid.GetHex().c_str()); while ( CCgetspenttxid(spenttxid,vini,height,txid,vout) == 0 ) { creditloop.push_back(txid); - fprintf(stderr,"%d: %s\n",n,txid.GetHex().c_str()); + //fprintf(stderr,"%d: %s\n",n,txid.GetHex().c_str()); n++; - if ( (value= CCgettxout(spenttxid,vout,1)) > 0 ) + if ( (value= CCgettxout(spenttxid,vout,1)) == 10000 ) { batontxid = spenttxid; - fprintf(stderr,"got baton %s %.8f\n",batontxid.GetHex().c_str(),(double)value/COIN); + //fprintf(stderr,"got baton %s %.8f\n",batontxid.GetHex().c_str(),(double)value/COIN); return(n); } + else if ( value > 0 ) + { + fprintf(stderr,"got false baton %s %.8f\n",batontxid.GetHex().c_str(),(double)value/COIN); + break; + } txid = spenttxid; } } @@ -417,15 +422,21 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) result.push_back(Pair("error",(char *)"cant automatic settle even maturity heights")); return(result); } - fprintf(stderr,"refmatures.%d\n",refmatures); + else if ( n < 2 ) + { + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",(char *)"creditloop too short")); + return(result); + } remaining = refamount; GetCCaddress(cp,myCCaddr,Mypubkey()); Getscriptaddress(batonCCaddr,batontx.vout[0].scriptPubKey); if ( strcmp(myCCaddr,batonCCaddr) == 0 ) { mtx.vin.push_back(CTxIn(batontxid,0,CScript())); + mtx.vin.push_back(CTxIn(creditloop[1],1,CScript())); // issuance marker pubkeys.push_back(mypk); - for (i=0; i 1 ) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 899fe3099..577c5fcb6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5583,6 +5583,8 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 5 ) { // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1168 32da4cb3e886ee42de90b4a15042d71169077306badf909099c5c5c692df3f27 + // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 700 MARMARA 2629 11fe8bf1de80c2ef69124d08907f259aef7f41e3a632ca2d48ad072a8c8f3078 -> 335df3a5dd6b92a3d020c9465d4d76e0d8242126106b83756dcecbad9813fdf3 + throw runtime_error("marmaraissue receiverpk amount currency matures approvaltxid\n"); } if ( ensure_CCrequirements() < 0 ) From 4ec27d22e8b1c0621ae419f54ddba3443f885e8d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 23:13:21 -1100 Subject: [PATCH 040/144] +print --- src/cc/marmara.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index a945474f7..771b36610 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -35,6 +35,8 @@ vout0 baton to next receiverpk (following the unspent baton back to original is the credit loop) 'S' + vin0 'I' marker + vin1 baton vins CC utxos from credit loop */ @@ -169,9 +171,10 @@ int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid, } else if ( value > 0 ) { - fprintf(stderr,"got false baton %s %.8f\n",batontxid.GetHex().c_str(),(double)value/COIN); - break; + fprintf(stderr,"got false baton %s/v%d %.8f\n",batontxid.GetHex().c_str(),vout,(double)value/COIN); + return(n); } + // get funcid txid = spenttxid; } } @@ -302,13 +305,13 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t { return(true); } - else if ( funcid == 'S' ) // collect -> automatically spend issuers locked funds, given 'I' + else if ( funcid == 'S' ) // settlement -> automatically spend issuers locked funds, given 'I' { - return(true); // iterate from issuer all remainder after maturity + return(true); } - else if ( funcid == 'D' ) // collect -> automatically spend issuers locked funds, given 'I' + else if ( funcid == 'D' ) // insufficient settlement { - return(true); // iterate from issuer all remainder after maturity + return(true); } // staking only for locked utxo } @@ -433,8 +436,9 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) Getscriptaddress(batonCCaddr,batontx.vout[0].scriptPubKey); if ( strcmp(myCCaddr,batonCCaddr) == 0 ) { - mtx.vin.push_back(CTxIn(batontxid,0,CScript())); mtx.vin.push_back(CTxIn(creditloop[1],1,CScript())); // issuance marker + pubkeys.push_back(Marmarapk); + mtx.vin.push_back(CTxIn(batontxid,0,CScript())); pubkeys.push_back(mypk); for (i=1; iGetHeight() ) errorstr = (char *)"it must mature in the future"; @@ -601,7 +605,6 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; - // make sure receiverpk is unique to creditloop // make sure less than maxlength Marmarapk = GetUnspendable(cp,0); mypk = pubkey2pk(Mypubkey()); @@ -609,7 +612,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a errorstr = (char *)"cant get createtxid from approvaltxid"; else if ( currency != "MARMARA" ) errorstr = (char *)"for now, only MARMARA loops are supported"; - else if ( amount < txfee ) + else if ( amount <= txfee ) errorstr = (char *)"amount must be for more than txfee"; else if ( matures <= chainActive.LastTip()->GetHeight() ) errorstr = (char *)"it must mature in the future"; @@ -888,3 +891,6 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * return(result); } +// MarmaraLock(uint64_t txfee,int64_t amount,int32_t refunlockht) +// scan all unlocked +// total capped at amount, change -> unlocked, if no change then scan all locked 'C' and 'P' for unlockht < refunlockht From ec2c6122061c2cdf69ea5abcf8fbe0ff65a9577c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 23:15:16 -1100 Subject: [PATCH 041/144] N --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 771b36610..66a36cab0 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -171,7 +171,7 @@ int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid, } else if ( value > 0 ) { - fprintf(stderr,"got false baton %s/v%d %.8f\n",batontxid.GetHex().c_str(),vout,(double)value/COIN); + fprintf(stderr,"n.%d got false baton %s/v%d %.8f\n",n,batontxid.GetHex().c_str(),vout,(double)value/COIN); return(n); } // get funcid From 8d87e118df09455489d7bbd47ec953df2bbdf51e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 23:17:12 -1100 Subject: [PATCH 042/144] batontxid = spenttxid; --- src/cc/marmara.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 66a36cab0..ac8f4d8ce 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -171,6 +171,7 @@ int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid, } else if ( value > 0 ) { + batontxid = spenttxid; fprintf(stderr,"n.%d got false baton %s/v%d %.8f\n",n,batontxid.GetHex().c_str(),vout,(double)value/COIN); return(n); } From 3d93fa24d9a91a8ebecf7fa86e43ff42ab830375 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 23:22:10 -1100 Subject: [PATCH 043/144] 'S' mode --- src/cc/marmara.cpp | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index ac8f4d8ce..7ab5a55d4 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -673,32 +673,41 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("batontxid",batontxid.GetHex())); if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,refcreatetxid,pk,refamount,refmatures,refcurrency)) != 0 ) { - str[0] = funcid, str[1] = 0; - result.push_back(Pair("funcid",str)); if ( refcreatetxid != creditloop[0] ) { fprintf(stderr,"invalid refcreatetxid, setting to creditloop[0]\n"); refcreatetxid = creditloop[0]; numerrs++; } + str[0] = funcid, str[1] = 0; + result.push_back(Pair("funcid",str)); result.push_back(Pair("createtxid",refcreatetxid.GetHex())); result.push_back(Pair("amount",ValueFromAmount(refamount))); result.push_back(Pair("matures",refmatures)); result.push_back(Pair("currency",refcurrency)); - result.push_back(Pair("batonpk",HexStr(pk))); - Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); - result.push_back(Pair("batonaddr",coinaddr)); - GetCCaddress(cp,batonCCaddr,pk); - result.push_back(Pair("batonCCaddr",batonCCaddr)); - Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); - if ( strcmp(coinaddr,batonCCaddr) != 0 ) + if ( funcid == 'S' ) { - result.push_back(Pair("vout0address",coinaddr)); - numerrs++; + result.push_back(Pair("settled",HexStr(pk))); + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); + result.push_back(Pair("coinaddr",coinaddr)); + } + else + { + result.push_back(Pair("batonpk",HexStr(pk))); + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); + result.push_back(Pair("batonaddr",coinaddr)); + GetCCaddress(cp,batonCCaddr,pk); + result.push_back(Pair("batonCCaddr",batonCCaddr)); + Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); + if ( strcmp(coinaddr,batonCCaddr) != 0 ) + { + result.push_back(Pair("vout0address",coinaddr)); + numerrs++; + } + if ( strcmp(myCCaddr,coinaddr) == 0 ) + result.push_back(Pair("ismine",1)); + else result.push_back(Pair("ismine",0)); } - if ( strcmp(myCCaddr,coinaddr) == 0 ) - result.push_back(Pair("ismine",1)); - else result.push_back(Pair("ismine",0)); for (i=0; i 1 ) From 5de16764e777ba2abaa35bd5df3c881314d5a660 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 23:26:24 -1100 Subject: [PATCH 044/144] Test --- src/cc/marmara.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 7ab5a55d4..146bbeb4f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -673,12 +673,6 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("batontxid",batontxid.GetHex())); if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,refcreatetxid,pk,refamount,refmatures,refcurrency)) != 0 ) { - if ( refcreatetxid != creditloop[0] ) - { - fprintf(stderr,"invalid refcreatetxid, setting to creditloop[0]\n"); - refcreatetxid = creditloop[0]; - numerrs++; - } str[0] = funcid, str[1] = 0; result.push_back(Pair("funcid",str)); result.push_back(Pair("createtxid",refcreatetxid.GetHex())); @@ -690,9 +684,22 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("settled",HexStr(pk))); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); result.push_back(Pair("coinaddr",coinaddr)); + obj.push_back(Pair("collected",ValueFromAmount(tx.vout[0].nValue))); + Getscriptaddress(destaddr,tx.vout[0].scriptPubKey); + if ( strcmp(coinaddr,destaddr) != 0 ) + { + result.push_back(Pair("destaddr",destaddr)); + numerrs++; + } } else { + if ( refcreatetxid != creditloop[0] ) + { + fprintf(stderr,"invalid refcreatetxid, setting to creditloop[0]\n"); + refcreatetxid = creditloop[0]; + numerrs++; + } result.push_back(Pair("batonpk",HexStr(pk))); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); result.push_back(Pair("batonaddr",coinaddr)); From 80d27512be47b37af25f09258f1271e6d57fefb1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 23:27:08 -1100 Subject: [PATCH 045/144] Result --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 146bbeb4f..6821b48a0 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -684,7 +684,7 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("settled",HexStr(pk))); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); result.push_back(Pair("coinaddr",coinaddr)); - obj.push_back(Pair("collected",ValueFromAmount(tx.vout[0].nValue))); + result.push_back(Pair("collected",ValueFromAmount(tx.vout[0].nValue))); Getscriptaddress(destaddr,tx.vout[0].scriptPubKey); if ( strcmp(coinaddr,destaddr) != 0 ) { From fe514fd5b6ce42fe76412ff279638bdaf69c72a1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 23:31:08 -1100 Subject: [PATCH 046/144] Tweak --- src/cc/marmara.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 6821b48a0..803c66e77 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -394,13 +394,14 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount,remaining,inputsum,change; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; std::vector pubkeys; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures,height; int64_t amount,refamount,remaining,inputsum,change; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; std::vector pubkeys; struct CCcontract_info *cp,C; if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); remaining = change = 0; + height = chainActive.LastTip()->GetHeight(); if ( (n= MarmaraGetbatontxid(creditloop,batontxid,refbatontxid)) > 0 ) { if ( GetTransaction(batontxid,batontx,hashBlock,false) != 0 && (numvouts= batontx.vout.size()) > 1 ) @@ -454,7 +455,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); if ( change > txfee ) mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,change,Marmarapk,pk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount,matures,currency),pubkeys); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount,height,currency),pubkeys); result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); return(result); @@ -469,7 +470,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,createtxid))) << OP_CHECKSIG)); // failure marker if ( amount-remaining > 3*txfee ) mtx.vout.push_back(CTxOut(amount-remaining-2*txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,amount-remaining,-remaining,currency),pubkeys); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,-remaining,height,currency),pubkeys); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"insufficient funds")); result.push_back(Pair("rawtx",rawtx)); @@ -691,6 +692,7 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("destaddr",destaddr)); numerrs++; } + refcreatetxid = creditloop[0]; } else { From d320e88b53dbd350fae36c6c37baee37a6ca4cf7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 23:35:14 -1100 Subject: [PATCH 047/144] Test --- src/cc/marmara.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 803c66e77..b59772f35 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -455,7 +455,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); if ( change > txfee ) mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,change,Marmarapk,pk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,amount,height,currency),pubkeys); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,0,height,currency),pubkeys); result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); return(result); @@ -676,12 +676,13 @@ UniValue MarmaraCreditloop(uint256 txid) { str[0] = funcid, str[1] = 0; result.push_back(Pair("funcid",str)); - result.push_back(Pair("createtxid",refcreatetxid.GetHex())); - result.push_back(Pair("amount",ValueFromAmount(refamount))); - result.push_back(Pair("matures",refmatures)); result.push_back(Pair("currency",refcurrency)); if ( funcid == 'S' ) { + refcreatetxid = creditloop[0]; + result.push_back(Pair("createtxid",refcreatetxid.GetHex())); + result.push_back(Pair("remainder",ValueFromAmount(refamount))); + result.push_back(Pair("height",refmatures)); result.push_back(Pair("settled",HexStr(pk))); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); result.push_back(Pair("coinaddr",coinaddr)); @@ -692,10 +693,13 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("destaddr",destaddr)); numerrs++; } - refcreatetxid = creditloop[0]; + refamount = -1; } else { + result.push_back(Pair("createtxid",refcreatetxid.GetHex())); + result.push_back(Pair("amount",ValueFromAmount(refamount))); + result.push_back(Pair("matures",refmatures)); if ( refcreatetxid != creditloop[0] ) { fprintf(stderr,"invalid refcreatetxid, setting to creditloop[0]\n"); @@ -750,6 +754,11 @@ UniValue MarmaraCreditloop(uint256 txid) obj.push_back(Pair("vout0address",destaddr)); numerrs++; } + if ( i == 0 && refamount < 0 ) + { + refamount = amount; + refmatures = matures; + } if ( createtxid != refcreatetxid || amount != refamount || matures != refmatures || currency != refcurrency ) { numerrs++; From f2a11ac0afb63db644d5479f19bc6bc7f3cce8d1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 23:37:38 -1100 Subject: [PATCH 048/144] Settletxid --- src/cc/marmara.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index b59772f35..133a8c187 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -671,7 +671,6 @@ UniValue MarmaraCreditloop(uint256 txid) result.push_back(Pair("myaddress",coinaddr)); GetCCaddress(cp,myCCaddr,Mypubkey()); result.push_back(Pair("myCCaddress",myCCaddr)); - result.push_back(Pair("batontxid",batontxid.GetHex())); if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,refcreatetxid,pk,refamount,refmatures,refcurrency)) != 0 ) { str[0] = funcid, str[1] = 0; @@ -680,10 +679,11 @@ UniValue MarmaraCreditloop(uint256 txid) if ( funcid == 'S' ) { refcreatetxid = creditloop[0]; + result.push_back(Pair("settletxid",batontxid.GetHex())); result.push_back(Pair("createtxid",refcreatetxid.GetHex())); result.push_back(Pair("remainder",ValueFromAmount(refamount))); - result.push_back(Pair("height",refmatures)); - result.push_back(Pair("settled",HexStr(pk))); + result.push_back(Pair("settled",refmatures)); + result.push_back(Pair("pubkey",HexStr(pk))); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); result.push_back(Pair("coinaddr",coinaddr)); result.push_back(Pair("collected",ValueFromAmount(tx.vout[0].nValue))); @@ -697,6 +697,7 @@ UniValue MarmaraCreditloop(uint256 txid) } else { + result.push_back(Pair("batontxid",batontxid.GetHex())); result.push_back(Pair("createtxid",refcreatetxid.GetHex())); result.push_back(Pair("amount",ValueFromAmount(refamount))); result.push_back(Pair("matures",refmatures)); From 4f0a54f26fdfc7d14ddcc335531c06f71df3987e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Jan 2019 23:44:01 -1100 Subject: [PATCH 049/144] 'D' --- src/cc/marmara.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 133a8c187..215a55297 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -679,7 +679,7 @@ UniValue MarmaraCreditloop(uint256 txid) if ( funcid == 'S' ) { refcreatetxid = creditloop[0]; - result.push_back(Pair("settletxid",batontxid.GetHex())); + result.push_back(Pair("settlement",batontxid.GetHex())); result.push_back(Pair("createtxid",refcreatetxid.GetHex())); result.push_back(Pair("remainder",ValueFromAmount(refamount))); result.push_back(Pair("settled",refmatures)); @@ -695,6 +695,18 @@ UniValue MarmaraCreditloop(uint256 txid) } refamount = -1; } + else if ( funcid == 'D' ) + { + refcreatetxid = creditloop[0]; + result.push_back(Pair("settlement",batontxid.GetHex())); + result.push_back(Pair("createtxid",refcreatetxid.GetHex())); + result.push_back(Pair("remainder",ValueFromAmount(refamount))); + result.push_back(Pair("settled",refmatures)); + Getscriptaddress(destaddr,tx.vout[0].scriptPubKey); + result.push_back(Pair("txidaddr",destaddr)); + if ( tx.vout.size() > 1 ) + result.push_back(Pair("collected",ValueFromAmount(tx.vout[1].nValue))); + } else { result.push_back(Pair("batontxid",batontxid.GetHex())); @@ -759,6 +771,8 @@ UniValue MarmaraCreditloop(uint256 txid) { refamount = amount; refmatures = matures; + result.push_back(Pair("amount",ValueFromAmount(refamount))); + result.push_back(Pair("matures",refmatures)); } if ( createtxid != refcreatetxid || amount != refamount || matures != refmatures || currency != refcurrency ) { From a9369c2811ac35f02f6670e991838b328ddb9535 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Jan 2019 04:49:20 -1100 Subject: [PATCH 050/144] Handle short credit loop --- src/cc/marmara.cpp | 93 ++++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 40 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 215a55297..1d115f557 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -39,6 +39,10 @@ vin1 baton vins CC utxos from credit loop + 'D' default/partial payment + + 'L' lockfunds + */ // start of consensus code @@ -427,7 +431,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) result.push_back(Pair("error",(char *)"cant automatic settle even maturity heights")); return(result); } - else if ( n < 2 ) + else if ( n < 1 ) { result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"creditloop too short")); @@ -438,7 +442,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) Getscriptaddress(batonCCaddr,batontx.vout[0].scriptPubKey); if ( strcmp(myCCaddr,batonCCaddr) == 0 ) { - mtx.vin.push_back(CTxIn(creditloop[1],1,CScript())); // issuance marker + mtx.vin.push_back(CTxIn(n == 1 ? batontxid : creditloop[1],1,CScript())); // issuance marker pubkeys.push_back(Marmarapk); mtx.vin.push_back(CTxIn(batontxid,0,CScript())); pubkeys.push_back(mypk); @@ -511,13 +515,14 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) return(result); } -int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuances,struct CCcontract_info *cp,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,CPubKey refpk,std::string refcurrency) +int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuances,int64_t &totalclosed,std::vector &closed,struct CCcontract_info *cp,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,CPubKey refpk,std::string refcurrency) { char coinaddr[64]; CPubKey Marmarapk,senderpk; int64_t amount; uint256 createtxid,txid,hashBlock; CTransaction tx; int32_t numvouts,vout,matures,n=0; std::string currency; std::vector > unspentOutputs; Marmarapk = GetUnspendable(cp,0); GetCCaddress(cp,coinaddr,Marmarapk); SetCCunspents(unspentOutputs,coinaddr); + // do all txid, conditional on spent/unspent //fprintf(stderr,"check coinaddr.(%s)\n",coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { @@ -810,43 +815,6 @@ UniValue MarmaraCreditloop(uint256 txid) } return(result); } - -UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency) -{ - UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i,n,matches; int64_t totalamount=0; std::vector issuances; char coinaddr[64]; - CPubKey Marmarapk; struct CCcontract_info *cp,C; - cp = CCinit(&C,EVAL_MARMARA); - Marmarapk = GetUnspendable(cp,0); - result.push_back(Pair("result","success")); - Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(Mypubkey())) << OP_CHECKSIG); - result.push_back(Pair("myaddress",coinaddr)); - GetCCaddress(cp,coinaddr,Mypubkey()); - result.push_back(Pair("myCCaddress",coinaddr)); - if ( refpk.size() == 33 ) - result.push_back(Pair("issuer",HexStr(refpk))); - if ( currency.size() == 0 ) - currency = (char *)"MARMARA"; - if ( firstheight <= lastheight ) - firstheight = 0, lastheight = (1 << 30); - if ( minamount <= maxamount ) - minamount = 0, maxamount = (1LL << 60); - result.push_back(Pair("firstheight",firstheight)); - result.push_back(Pair("lastheight",lastheight)); - result.push_back(Pair("minamount",ValueFromAmount(minamount))); - result.push_back(Pair("maxamount",ValueFromAmount(maxamount))); - result.push_back(Pair("currency",currency)); - if ( (n= MarmaraGetCreditloops(totalamount,issuances,cp,firstheight,lastheight,minamount,maxamount,refpk,currency)) > 0 ) - { - result.push_back(Pair("n",n)); - matches = (int32_t)issuances.size(); - result.push_back(Pair("matches",matches)); - for (i=0; i unlocked, if no change then scan all locked 'C' and 'P' for unlockht < refunlockht + +// get all tx, constrain by vout, issuances[] and closed[] + +UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency) +{ + UniValue result(UniValue::VOBJ),a(UniValue::VARR),b(UniValue::VARR); int32_t i,n,matches; int64_t totalclosed=0,totalamount=0; std::vector issuances,closed; char coinaddr[64]; + CPubKey Marmarapk; struct CCcontract_info *cp,C; + cp = CCinit(&C,EVAL_MARMARA); + Marmarapk = GetUnspendable(cp,0); + result.push_back(Pair("result","success")); + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(Mypubkey())) << OP_CHECKSIG); + result.push_back(Pair("myaddress",coinaddr)); + GetCCaddress(cp,coinaddr,Mypubkey()); + result.push_back(Pair("myCCaddress",coinaddr)); + if ( refpk.size() == 33 ) + result.push_back(Pair("issuer",HexStr(refpk))); + if ( currency.size() == 0 ) + currency = (char *)"MARMARA"; + if ( firstheight <= lastheight ) + firstheight = 0, lastheight = (1 << 30); + if ( minamount <= maxamount ) + minamount = 0, maxamount = (1LL << 60); + result.push_back(Pair("firstheight",firstheight)); + result.push_back(Pair("lastheight",lastheight)); + result.push_back(Pair("minamount",ValueFromAmount(minamount))); + result.push_back(Pair("maxamount",ValueFromAmount(maxamount))); + result.push_back(Pair("currency",currency)); + if ( (n= MarmaraGetCreditloops(totalamount,issuances,totalclosed,closed,cp,firstheight,lastheight,minamount,maxamount,refpk,currency)) > 0 ) + { + result.push_back(Pair("n",n)); + matches = (int32_t)issuances.size(); + result.push_back(Pair("pending",matches)); + for (i=0; i Date: Thu, 17 Jan 2019 05:02:34 -1100 Subject: [PATCH 051/144] Ref amount --- src/cc/marmara.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 1d115f557..4cf1a2a42 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -469,11 +469,11 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) } else fprintf(stderr,"null funcid for creditloop[%d]\n",i); } else fprintf(stderr,"couldnt get creditloop[%d]\n",i); } - if ( amount - remaining > 2*txfee ) + if ( refamount - remaining > 2*txfee ) { mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,createtxid))) << OP_CHECKSIG)); // failure marker - if ( amount-remaining > 3*txfee ) - mtx.vout.push_back(CTxOut(amount-remaining-2*txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + if ( refamount-remaining > 3*txfee ) + mtx.vout.push_back(CTxOut(refamount-remaining-2*txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,-remaining,height,currency),pubkeys); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"insufficient funds")); From 0b257f6dfac182abcf7b06490fbc2d19c1378867 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Jan 2019 21:49:55 -1100 Subject: [PATCH 052/144] Add 1of2 add and coin balances --- src/cc/marmara.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 4cf1a2a42..cf2382277 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -917,8 +917,16 @@ UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_ result.push_back(Pair("result","success")); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(Mypubkey())) << OP_CHECKSIG); result.push_back(Pair("myaddress",coinaddr)); + result.push_back(Pair("normal",ValueFromAmount(CCaddress_balance(coinaddr)))); + + GetCCaddress1of2(cp,coinaddr,Marmarapk,Mypubkey()); + result.push_back(Pair("myCCactivated",coinaddr)); + result.push_back(Pair("activated",ValueFromAmount(CCaddress_balance(coinaddr)))); + GetCCaddress(cp,coinaddr,Mypubkey()); result.push_back(Pair("myCCaddress",coinaddr)); + result.push_back(Pair("CCutxos",ValueFromAmount(CCaddress_balance(coinaddr)))); + if ( refpk.size() == 33 ) result.push_back(Pair("issuer",HexStr(refpk))); if ( currency.size() == 0 ) From e555995f194aa978e77ea65bd87427f3faf477af Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Jan 2019 22:46:56 -1100 Subject: [PATCH 053/144] Marmaralock --- src/cc/CCMarmara.h | 1 + src/cc/marmara.cpp | 43 ++++++++++++++++++++++++++++++++++------ src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 14 +++++++++++++ 5 files changed, 54 insertions(+), 6 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index fe9f7f30b..65269df77 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -31,6 +31,7 @@ int32_t MarmaraGetcreatetxid(uint256 &createtxid,uint256 txid); int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid,uint256 txid); UniValue MarmaraCreditloop(uint256 txid); UniValue MarmaraSettlement(uint64_t txfee,uint256 batontxid); +UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height); UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid,bool automaticflag); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index cf2382277..b57b156e1 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -395,6 +395,41 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, return(totalinputs); } +UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk; int64_t inputsum,change = 0; std::string rawtx,errorstr; + // scan all unlocked + // total capped at amount, change -> unlocked, if no change then scan all locked 'C' and 'P' for unlockht < refunlockht + if ( txfee == 0 ) + txfee = 10000; + cp = CCinit(&C,EVAL_MARMARA); + mypk = pubkey2pk(Mypubkey()); + Marmarapk = GetUnspendable(cp,0); + if ( (inputsum= AddNormalinputs(mtx,mypk,amount + txfee,1)) > 0 ) + { + if ( inputsum > amount+txfee ) + { + change = (inputsum - amount); + mtx.vout.push_back(CTxOut(change,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + } + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraCoinbaseOpret('L',height,mypk)); + if ( rawtx.size() == 0 ) + errorstr = (char *)"couldnt finalize CCtx"; + else + { + result.push_back(Pair("result",(char *)"success")); + result.push_back(Pair("rawtx",rawtx)); + return(result); + } + } + result.push_back(Pair("result",(char *)"error")); + result.push_back(Pair("error",errorstr)); + return(result); +} + +// decide on what unlockht settlement change should have + UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); @@ -459,7 +494,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); if ( change > txfee ) mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,change,Marmarapk,pk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,0,height,currency),pubkeys); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,0,unlockht,currency),pubkeys); result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); return(result); @@ -474,7 +509,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,createtxid))) << OP_CHECKSIG)); // failure marker if ( refamount-remaining > 3*txfee ) mtx.vout.push_back(CTxOut(refamount-remaining-2*txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,-remaining,height,currency),pubkeys); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,-remaining,unlockht,currency),pubkeys); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"insufficient funds")); result.push_back(Pair("rawtx",rawtx)); @@ -902,10 +937,6 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * return(result); } -// MarmaraLock(uint64_t txfee,int64_t amount,int32_t refunlockht) -// scan all unlocked -// total capped at amount, change -> unlocked, if no change then scan all locked 'C' and 'P' for unlockht < refunlockht - // get all tx, constrain by vout, issuances[] and closed[] UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 5761b5bf7..90f8fd6db 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -458,6 +458,7 @@ static const CRPCCommand vRPCCommands[] = { "marmara", "marmarainfo", &marmara_info, true }, { "marmara", "marmaracreditloop", &marmara_creditloop, true }, { "marmara", "marmarasettlement", &marmara_settlement, true }, + { "marmara", "marmaralock", &marmara_lock, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 99b7e8678..d5ebb56ab 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -285,6 +285,7 @@ extern UniValue marmara_transfer(const UniValue& params, bool fHelp); extern UniValue marmara_info(const UniValue& params, bool fHelp); extern UniValue marmara_creditloop(const UniValue& params, bool fHelp); extern UniValue marmara_settlement(const UniValue& params, bool fHelp); +extern UniValue marmara_lock(const UniValue& params, bool fHelp); extern UniValue paymentsaddress(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); extern UniValue gatewayslist(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a92cf4bf8..02cf85ee6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5692,6 +5692,20 @@ UniValue marmara_settlement(const UniValue& params, bool fHelp) return(result); } +UniValue marmara_lock(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); int64_t amount; int32_t height; + if ( fHelp || params.size() > 2 || params.size() == 0 ) + { + throw runtime_error("marmaralock amount unlockht\n"); + } + amount = atof(params[0].get_str().c_str()) * COIN + 0.00000000499999; + if ( params.size() == 2 ) + height = atol(params[1].get_str().c_str()); + else height = chainActive.LastTip()->GetHeight() + 1; + return(MarmaraLock(0,amount,height)); +} + UniValue channelslist(const UniValue& params, bool fHelp) { if ( fHelp || params.size() > 0 ) From 6e4d54fb7b83bdd5c91332e7da9d1c08d8df243d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Jan 2019 22:48:50 -1100 Subject: [PATCH 054/144] Refunlockht --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index b57b156e1..8f5701553 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -494,7 +494,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); if ( change > txfee ) mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,change,Marmarapk,pk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,0,unlockht,currency),pubkeys); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,0,refunlockht,currency),pubkeys); result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); return(result); @@ -509,7 +509,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,createtxid))) << OP_CHECKSIG)); // failure marker if ( refamount-remaining > 3*txfee ) mtx.vout.push_back(CTxOut(refamount-remaining-2*txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,-remaining,unlockht,currency),pubkeys); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,-remaining,refunlockht,currency),pubkeys); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"insufficient funds")); result.push_back(Pair("rawtx",rawtx)); From bc04276465a8ae9f57843a11903a87e7d2b57a45 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Jan 2019 22:49:41 -1100 Subject: [PATCH 055/144] refmatures --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8f5701553..b43754cb3 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -494,7 +494,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); if ( change > txfee ) mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,change,Marmarapk,pk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,0,refunlockht,currency),pubkeys); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,0,refmatures,currency),pubkeys); result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); return(result); @@ -509,7 +509,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,createtxid))) << OP_CHECKSIG)); // failure marker if ( refamount-remaining > 3*txfee ) mtx.vout.push_back(CTxOut(refamount-remaining-2*txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,-remaining,refunlockht,currency),pubkeys); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,-remaining,refmatures,currency),pubkeys); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"insufficient funds")); result.push_back(Pair("rawtx",rawtx)); From 68597fa670091864e017f0c07a118251822a60f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Jan 2019 22:56:06 -1100 Subject: [PATCH 056/144] Add CC out --- src/cc/marmara.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index b43754cb3..f095c5da3 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -408,6 +408,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) Marmarapk = GetUnspendable(cp,0); if ( (inputsum= AddNormalinputs(mtx,mypk,amount + txfee,1)) > 0 ) { + mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum > amount+txfee ) { change = (inputsum - amount); From 901c7952044aaf1a45f0d75f031bf9853024341d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Jan 2019 23:22:46 -1100 Subject: [PATCH 057/144] Test --- src/cc/marmara.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index f095c5da3..5260df2ae 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -398,15 +398,18 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk; int64_t inputsum,change = 0; std::string rawtx,errorstr; - // scan all unlocked - // total capped at amount, change -> unlocked, if no change then scan all locked 'C' and 'P' for unlockht < refunlockht + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk; int32_t unlockht; int64_t inputsum,change = 0; std::string rawtx,errorstr; if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); - if ( (inputsum= AddNormalinputs(mtx,mypk,amount + txfee,1)) > 0 ) + inputsum = AddNormalinputs(mtx,mypk,amount + txfee,1); + if ( inputsum < amount+txfee ) + { + unlockht = MarmaraUnlockht(height); + } + if ( inputsum > 0 ) { mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum > amount+txfee ) From 619958c2a40844cda9807f6c41a0528ba4bef6cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 00:59:14 -1100 Subject: [PATCH 058/144] Merge earlier to expire locked funds --- src/cc/marmara.cpp | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5260df2ae..ec41cc3e8 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -398,20 +398,51 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk; int32_t unlockht; int64_t inputsum,change = 0; std::string rawtx,errorstr; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,ht,numvouts; int64_t nValue,inputsum,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); inputsum = AddNormalinputs(mtx,mypk,amount + txfee,1); + mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) { - unlockht = MarmaraUnlockht(height); + remains = (amount + txfee) - inputsum; + std::vector > unspentOutputs; + GetCCaddress1of2(cp,coinaddr,Marmarapk,mypk); + SetCCunspents(unspentOutputs,coinaddr); + threshold = remains / 16; + refunlockht = MarmaraUnlockht(height); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + if ( (nValue= it->second.satoshis) < threshold ) + continue; + if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 && vout < numvouts && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + { + if ( (funcid= DecodeMaramaraCoinbaseOpRet(tx.vout[numvouts-1].scriptPubKey,pk,ht,unlockht)) == 'C' || funcid == 'P' || funcid == 'L' ) + { + if ( unlockht < refunlockht ) + { + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + fprintf(stderr,"merge CC vout %s/v%d %.8f unlockht.%d < ref.%d\n",txid.GetHex().c_str(),vout,(double)nValue/COIN,unlockht,refunlockht); + inputsum += nValue; + remains -= nValue; + if ( inputsum >= amount + txfee ) + { + fprintf(stderr,"inputsum %.8f >= amount %.8f, update amount\n",(double)inputsum/COIN,(double)amount/COIN); + amount = inputsum; + break; + } + } + } + } + } } - if ( inputsum > 0 ) + if ( inputsum >= amount+txfee ) { - mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum > amount+txfee ) { change = (inputsum - amount); @@ -426,13 +457,13 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) result.push_back(Pair("rawtx",rawtx)); return(result); } - } + } else errorstr = (char *)"insufficient funds"; result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",errorstr)); return(result); } -// decide on what unlockht settlement change should have +// jl777: decide on what unlockht settlement change should have UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { From 9419e1034f922cd92af4940e82f13a83a5fb25f4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:02:06 -1100 Subject: [PATCH 059/144] top16 --- src/cc/marmara.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index ec41cc3e8..b943c1519 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -398,7 +398,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,ht,numvouts; int64_t nValue,inputsum,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,inputsum,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); @@ -976,6 +976,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency) { + CMutableTransaction mtx; std::vector pubkeys; UniValue result(UniValue::VOBJ),a(UniValue::VARR),b(UniValue::VARR); int32_t i,n,matches; int64_t totalclosed=0,totalamount=0; std::vector issuances,closed; char coinaddr[64]; CPubKey Marmarapk; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); @@ -988,6 +989,7 @@ UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_ GetCCaddress1of2(cp,coinaddr,Marmarapk,Mypubkey()); result.push_back(Pair("myCCactivated",coinaddr)); result.push_back(Pair("activated",ValueFromAmount(CCaddress_balance(coinaddr)))); + result.push_back(Pair("activated16",ValueFromAmount(AddMarmarainputs(mtx,pubkeys,coinaddr,1LL << 60,16)))); GetCCaddress(cp,coinaddr,Mypubkey()); result.push_back(Pair("myCCaddress",coinaddr)); From 64726e1e217c56bfd208458a3fbfdcbce247089a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:04:09 -1100 Subject: [PATCH 060/144] activated16 --- src/cc/marmara.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index b943c1519..af1d0e496 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -977,7 +977,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency) { CMutableTransaction mtx; std::vector pubkeys; - UniValue result(UniValue::VOBJ),a(UniValue::VARR),b(UniValue::VARR); int32_t i,n,matches; int64_t totalclosed=0,totalamount=0; std::vector issuances,closed; char coinaddr[64]; + UniValue result(UniValue::VOBJ),a(UniValue::VARR),b(UniValue::VARR); int32_t i,n,matches; int64_t totalclosed=0,totalamount=0,val; std::vector issuances,closed; char coinaddr[64]; CPubKey Marmarapk; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); @@ -988,8 +988,9 @@ UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_ GetCCaddress1of2(cp,coinaddr,Marmarapk,Mypubkey()); result.push_back(Pair("myCCactivated",coinaddr)); - result.push_back(Pair("activated",ValueFromAmount(CCaddress_balance(coinaddr)))); - result.push_back(Pair("activated16",ValueFromAmount(AddMarmarainputs(mtx,pubkeys,coinaddr,1LL << 60,16)))); + val = CCaddress_balance(coinaddr); + result.push_back(Pair("activated",ValueFromAmount(val))); + result.push_back(Pair("activated16",ValueFromAmount(AddMarmarainputs(mtx,pubkeys,coinaddr,val,16)))); GetCCaddress(cp,coinaddr,Mypubkey()); result.push_back(Pair("myCCaddress",coinaddr)); From bb41418f23425e0478016bcffd110f625272dfba Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:06:25 -1100 Subject: [PATCH 061/144] Get total --- src/cc/marmara.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index af1d0e496..88f47be0b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -977,7 +977,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency) { CMutableTransaction mtx; std::vector pubkeys; - UniValue result(UniValue::VOBJ),a(UniValue::VARR),b(UniValue::VARR); int32_t i,n,matches; int64_t totalclosed=0,totalamount=0,val; std::vector issuances,closed; char coinaddr[64]; + UniValue result(UniValue::VOBJ),a(UniValue::VARR),b(UniValue::VARR); int32_t i,n,matches; int64_t totalclosed=0,totalamount=0; std::vector issuances,closed; char coinaddr[64]; CPubKey Marmarapk; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); @@ -988,9 +988,8 @@ UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_ GetCCaddress1of2(cp,coinaddr,Marmarapk,Mypubkey()); result.push_back(Pair("myCCactivated",coinaddr)); - val = CCaddress_balance(coinaddr); - result.push_back(Pair("activated",ValueFromAmount(val))); - result.push_back(Pair("activated16",ValueFromAmount(AddMarmarainputs(mtx,pubkeys,coinaddr,val,16)))); + result.push_back(Pair("activated",ValueFromAmount(CCaddress_balance(coinaddr)))); + result.push_back(Pair("activated16",ValueFromAmount(AddMarmarainputs(mtx,pubkeys,coinaddr,0,16)))); GetCCaddress(cp,coinaddr,Mypubkey()); result.push_back(Pair("myCCaddress",coinaddr)); From 951c9af6ffd6b99e4dd4aeb4fbe6e4b21d5b5d17 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:11:44 -1100 Subject: [PATCH 062/144] Test --- src/cc/marmara.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 88f47be0b..5c8bca482 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -373,6 +373,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, { txid = it->first.txhash; vout = (int32_t)it->first.index; + char str[64]; fprintf(stderr,"(%s) %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); if ( it->second.satoshis < threshold ) continue; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 && vout < numvouts && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) From 81df6aeabdca4f7cbcfbe77cbe054524ab38399e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:16:41 -1100 Subject: [PATCH 063/144] Sort utxo gals --- src/cc/marmara.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5c8bca482..17d1aa6c8 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -365,7 +365,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys,char *coinaddr,int64_t total,int32_t maxinputs) { - uint64_t threshold,nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction tx; int32_t numvouts,ht,unlockht,vout,n = 0; uint8_t funcid; CPubKey pk; + uint64_t threshold,nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction tx; int32_t numvouts,ht,unlockht,vout,i,n = 0; uint8_t funcid; CPubKey pk; std::vector vals; std::vector > unspentOutputs; SetCCunspents(unspentOutputs,coinaddr); threshold = total/(maxinputs+1); @@ -373,7 +373,6 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, { txid = it->first.txhash; vout = (int32_t)it->first.index; - char str[64]; fprintf(stderr,"(%s) %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); if ( it->second.satoshis < threshold ) continue; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 && vout < numvouts && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) @@ -387,12 +386,20 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, pubkeys.push_back(pk); } totalinputs += it->second.satoshis; + vals.push_back(it->second.satoshis); n++; if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) break; } else fprintf(stderr,"null funcid\n"); } } + if ( maxinputs != 0 && total == 0 ) + { + std::sort(vals.begin(), vals.end()); + totalinputs = 0; + for (i=0; i Date: Fri, 18 Jan 2019 01:19:19 -1100 Subject: [PATCH 064/144] Continue in special case --- src/cc/marmara.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 17d1aa6c8..bf18c82aa 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -379,7 +379,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, { if ( (funcid= DecodeMaramaraCoinbaseOpRet(tx.vout[numvouts-1].scriptPubKey,pk,ht,unlockht)) == 'C' || funcid == 'P' || funcid == 'L' ) { - char str[64]; fprintf(stderr,"(%s) %s/v%d %.8f ht.%d unlockht.%d\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN,ht,unlockht); + //char str[64]; fprintf(stderr,"(%s) %s/v%d %.8f ht.%d unlockht.%d\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN,ht,unlockht); if ( total != 0 && maxinputs != 0 ) { mtx.vin.push_back(CTxIn(txid,vout,CScript())); @@ -388,6 +388,8 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, totalinputs += it->second.satoshis; vals.push_back(it->second.satoshis); n++; + if ( maxinputs != 0 && total == 0 ) + continue; if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) break; } else fprintf(stderr,"null funcid\n"); @@ -395,7 +397,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, } if ( maxinputs != 0 && total == 0 ) { - std::sort(vals.begin(), vals.end()); + std::sort(vals.begin(),vals.end()); totalinputs = 0; for (i=0; i Date: Fri, 18 Jan 2019 01:30:17 -1100 Subject: [PATCH 065/144] Test --- src/cc/marmara.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index bf18c82aa..d4e6fedd9 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -411,6 +411,8 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,inputsum,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; if ( txfee == 0 ) txfee = 10000; + if ( (height & 1) != 0 ) + height++; cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); @@ -418,12 +420,14 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) { + refunlockht = MarmaraUnlockht(height); + result.push_back(Pair("height",height)); + result.push_back(Pair("unlockht",refunlockht)); remains = (amount + txfee) - inputsum; std::vector > unspentOutputs; GetCCaddress1of2(cp,coinaddr,Marmarapk,mypk); SetCCunspents(unspentOutputs,coinaddr); - threshold = remains / 16; - refunlockht = MarmaraUnlockht(height); + threshold = remains / (MARMARA_VINS+1); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; @@ -443,7 +447,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) if ( inputsum >= amount + txfee ) { fprintf(stderr,"inputsum %.8f >= amount %.8f, update amount\n",(double)inputsum/COIN,(double)amount/COIN); - amount = inputsum; + amount = inputsum - txfee; break; } } From 22441d1ed66338a23085a8f4970700ca998b4485 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:31:10 -1100 Subject: [PATCH 066/144] Test --- src/cc/marmara.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index d4e6fedd9..8ac73189c 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -421,6 +421,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) if ( inputsum < amount+txfee ) { refunlockht = MarmaraUnlockht(height); + result.push_back(Pair("normalfunds",ValueFromAmount(inputsum))); result.push_back(Pair("height",height)); result.push_back(Pair("unlockht",refunlockht)); remains = (amount + txfee) - inputsum; From 810ae9fd08511d6e4e4b532b3b59ce2952707170 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:36:36 -1100 Subject: [PATCH 067/144] Add normal inputs --- src/cc/marmara.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8ac73189c..298241039 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -408,7 +408,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,inputsum,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,val,inputsum,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; if ( txfee == 0 ) txfee = 10000; if ( (height & 1) != 0 ) @@ -416,7 +416,8 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); - inputsum = AddNormalinputs(mtx,mypk,amount + txfee,1); + val = AddNormalinputs(mtx,mypk,0,0); + inputsum = AddNormalinputs(mtx,mypk,val,MARMARA_VINS); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) { From b5bfaaed0fb91e9de39e381a52d688987fdcee6d Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:39:59 -1100 Subject: [PATCH 068/144] Test --- src/cc/marmara.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 298241039..d139f2090 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -407,7 +407,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) { - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,val,inputsum,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; if ( txfee == 0 ) txfee = 10000; @@ -416,8 +416,9 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); - val = AddNormalinputs(mtx,mypk,0,0); - inputsum = AddNormalinputs(mtx,mypk,val,MARMARA_VINS); + val = AddNormalinputs(tmpmtx,mypk,0,0); + fprintf(stderr,"normal inputs %.8f numvins.%d\n",(double)val/COIN,(int32_t)tmpmtx.vin.size()); + inputsum = AddNormalinputs(mtx,mypk,val,tmpmtx.vin.size() < MARMARA_VINS ? tmpmtx.vin.size() : MARMARA_VINS); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) { From d3a0c0e897ed35d288810dcfb5e36caed2ac452a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:43:10 -1100 Subject: [PATCH 069/144] Normalinputs2 --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index d139f2090..e99221a04 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -416,9 +416,9 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); - val = AddNormalinputs(tmpmtx,mypk,0,0); + val = AddNormalinputs2(tmpmtx,mypk,0,0); fprintf(stderr,"normal inputs %.8f numvins.%d\n",(double)val/COIN,(int32_t)tmpmtx.vin.size()); - inputsum = AddNormalinputs(mtx,mypk,val,tmpmtx.vin.size() < MARMARA_VINS ? tmpmtx.vin.size() : MARMARA_VINS); + inputsum = AddNormalinputs2(mtx,mypk,val,tmpmtx.vin.size() < MARMARA_VINS ? tmpmtx.vin.size() : MARMARA_VINS); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) { From 5be35df3dfb452352ac6bb1b40ba1db33cbf6758 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:44:16 -1100 Subject: [PATCH 070/144] Test --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index e99221a04..2d99ae31f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -416,9 +416,9 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); - val = AddNormalinputs2(tmpmtx,mypk,0,0); + val = AddNormalinputs2(tmpmtx,0,0); fprintf(stderr,"normal inputs %.8f numvins.%d\n",(double)val/COIN,(int32_t)tmpmtx.vin.size()); - inputsum = AddNormalinputs2(mtx,mypk,val,tmpmtx.vin.size() < MARMARA_VINS ? tmpmtx.vin.size() : MARMARA_VINS); + inputsum = AddNormalinputs2(mtx,val,tmpmtx.vin.size() < MARMARA_VINS ? tmpmtx.vin.size() : MARMARA_VINS); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) { From baefcb30c165eb76cfb7021e93cf6e6e5ec82740 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:51:13 -1100 Subject: [PATCH 071/144] mypk --- src/cc/marmara.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 2d99ae31f..6085981e1 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -416,7 +416,8 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); - val = AddNormalinputs2(tmpmtx,0,0); + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); + val = AddNormalinputs2(tmpmtx,CCaddressbalance(coinaddr),MARMARA_VINS); fprintf(stderr,"normal inputs %.8f numvins.%d\n",(double)val/COIN,(int32_t)tmpmtx.vin.size()); inputsum = AddNormalinputs2(mtx,val,tmpmtx.vin.size() < MARMARA_VINS ? tmpmtx.vin.size() : MARMARA_VINS); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); From dce284a1d18da00a07c4455a30309b91b75d2d9c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:52:05 -1100 Subject: [PATCH 072/144] _ --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 6085981e1..3109b5ee0 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -417,7 +417,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); - val = AddNormalinputs2(tmpmtx,CCaddressbalance(coinaddr),MARMARA_VINS); + val = AddNormalinputs2(tmpmtx,CCaddress_balance(coinaddr),MARMARA_VINS); fprintf(stderr,"normal inputs %.8f numvins.%d\n",(double)val/COIN,(int32_t)tmpmtx.vin.size()); inputsum = AddNormalinputs2(mtx,val,tmpmtx.vin.size() < MARMARA_VINS ? tmpmtx.vin.size() : MARMARA_VINS); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); From 5f1790817271d975a7e2ac86c0a88498b5d7e6dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 01:55:30 -1100 Subject: [PATCH 073/144] Revert --- src/cc/marmara.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 3109b5ee0..75fa385b4 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -417,9 +417,8 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); - val = AddNormalinputs2(tmpmtx,CCaddress_balance(coinaddr),MARMARA_VINS); - fprintf(stderr,"normal inputs %.8f numvins.%d\n",(double)val/COIN,(int32_t)tmpmtx.vin.size()); - inputsum = AddNormalinputs2(mtx,val,tmpmtx.vin.size() < MARMARA_VINS ? tmpmtx.vin.size() : MARMARA_VINS); + inputsum = AddNormalinputs2(mtx,amount,MARMARA_VINS); + fprintf(stderr,"normal inputs %.8f\n",(double)inputsum/COIN); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) { From 04b11f66d4ed94af7cee7b16a465ebd971cffca4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:07:01 -1100 Subject: [PATCH 074/144] Test --- src/cc/marmara.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 75fa385b4..0a2a5e13b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -408,7 +408,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,val,inputsum,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,val,inputsum=0,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; if ( txfee == 0 ) txfee = 10000; if ( (height & 1) != 0 ) @@ -417,8 +417,11 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); - inputsum = AddNormalinputs2(mtx,amount,MARMARA_VINS); - fprintf(stderr,"normal inputs %.8f\n",(double)inputsum/COIN); + if ( (val= CCaddress_balance(coinaddr)) < amount ) + val -= txfee; + if ( val > txfee ) + inputsum = AddNormalinputs2(mtx,val,MARMARA_VINS); + //fprintf(stderr,"normal inputs %.8f\n",(double)inputsum/COIN); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) { From d099a1b607aad1f6d460f9bc279bc4cb53787138 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:08:29 -1100 Subject: [PATCH 075/144] Vals --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 0a2a5e13b..da6b7d9c2 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -421,7 +421,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) val -= txfee; if ( val > txfee ) inputsum = AddNormalinputs2(mtx,val,MARMARA_VINS); - //fprintf(stderr,"normal inputs %.8f\n",(double)inputsum/COIN); + fprintf(stderr,"normal inputs %.8f val %.8f\n",(double)inputsum/COIN,(double)val/COIN); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) { From 0a669e79b2498ae0a0976f4943e5235d5fa715d1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:10:47 -1100 Subject: [PATCH 076/144] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index da6b7d9c2..8c848e3f0 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -418,7 +418,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) Marmarapk = GetUnspendable(cp,0); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); if ( (val= CCaddress_balance(coinaddr)) < amount ) - val -= txfee; + val = (amount - txfee) / 2; if ( val > txfee ) inputsum = AddNormalinputs2(mtx,val,MARMARA_VINS); fprintf(stderr,"normal inputs %.8f val %.8f\n",(double)inputsum/COIN,(double)val/COIN); From 220b23b70d09bec953ef09533642cd56bd784b93 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:13:19 -1100 Subject: [PATCH 077/144] Fix > case --- src/cc/marmara.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8c848e3f0..eb313c587 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -419,9 +419,10 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); if ( (val= CCaddress_balance(coinaddr)) < amount ) val = (amount - txfee) / 2; + else val = amount; if ( val > txfee ) inputsum = AddNormalinputs2(mtx,val,MARMARA_VINS); - fprintf(stderr,"normal inputs %.8f val %.8f\n",(double)inputsum/COIN,(double)val/COIN); + //fprintf(stderr,"normal inputs %.8f val %.8f\n",(double)inputsum/COIN,(double)val/COIN); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) { From d9b5673a14bc2e93b3527cf0bc2dcfe89e9df8a8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:18:30 -1100 Subject: [PATCH 078/144] CCaddr2 --- src/cc/marmara.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index eb313c587..4a6d799cc 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -435,6 +435,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) GetCCaddress1of2(cp,coinaddr,Marmarapk,mypk); SetCCunspents(unspentOutputs,coinaddr); threshold = remains / (MARMARA_VINS+1); + CCaddr2set(cp,EVAL_MARMARA,gatewayspk,cp->CCpriv,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; @@ -448,12 +449,12 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) if ( unlockht < refunlockht ) { mtx.vin.push_back(CTxIn(txid,vout,CScript())); - fprintf(stderr,"merge CC vout %s/v%d %.8f unlockht.%d < ref.%d\n",txid.GetHex().c_str(),vout,(double)nValue/COIN,unlockht,refunlockht); + //fprintf(stderr,"merge CC vout %s/v%d %.8f unlockht.%d < ref.%d\n",txid.GetHex().c_str(),vout,(double)nValue/COIN,unlockht,refunlockht); inputsum += nValue; remains -= nValue; if ( inputsum >= amount + txfee ) { - fprintf(stderr,"inputsum %.8f >= amount %.8f, update amount\n",(double)inputsum/COIN,(double)amount/COIN); + //fprintf(stderr,"inputsum %.8f >= amount %.8f, update amount\n",(double)inputsum/COIN,(double)amount/COIN); amount = inputsum - txfee; break; } From 28154f6212398ccaf412c8f7ffd883068261147d Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:19:17 -1100 Subject: [PATCH 079/144] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 4a6d799cc..7eb1675d5 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -435,7 +435,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) GetCCaddress1of2(cp,coinaddr,Marmarapk,mypk); SetCCunspents(unspentOutputs,coinaddr); threshold = remains / (MARMARA_VINS+1); - CCaddr2set(cp,EVAL_MARMARA,gatewayspk,cp->CCpriv,coinaddr); + CCaddr2set(cp,EVAL_MARMARA,Marmarapk,cp->CCpriv,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; From 4227647cc2ebdcbc14af01a0304a830c49655b04 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:22:03 -1100 Subject: [PATCH 080/144] CCaddrTokens1of2set --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 7eb1675d5..da0a5b5e3 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -435,7 +435,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) GetCCaddress1of2(cp,coinaddr,Marmarapk,mypk); SetCCunspents(unspentOutputs,coinaddr); threshold = remains / (MARMARA_VINS+1); - CCaddr2set(cp,EVAL_MARMARA,Marmarapk,cp->CCpriv,coinaddr); + CCaddrTokens1of2set(cp,Marmarapk,mypk,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; From 96cd77ae65bf68ec24aec12d03f8b29a574035f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:24:33 -1100 Subject: [PATCH 081/144] CCaddr1of2set --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index da0a5b5e3..8ac9b3094 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -435,7 +435,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) GetCCaddress1of2(cp,coinaddr,Marmarapk,mypk); SetCCunspents(unspentOutputs,coinaddr); threshold = remains / (MARMARA_VINS+1); - CCaddrTokens1of2set(cp,Marmarapk,mypk,coinaddr); + CCaddr1of2set(cp,Marmarapk,mypk,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; From 71f6a35db9e3999f12037dc64e334724b5f76dda Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:27:08 -1100 Subject: [PATCH 082/144] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8ac9b3094..208036cab 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -418,7 +418,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) Marmarapk = GetUnspendable(cp,0); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); if ( (val= CCaddress_balance(coinaddr)) < amount ) - val = (amount - txfee) / 2; + val = 9*(amount - txfee) / 10; else val = amount; if ( val > txfee ) inputsum = AddNormalinputs2(mtx,val,MARMARA_VINS); From 1bc00bf8223f11e9a97eff16adca900276a8956f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:28:55 -1100 Subject: [PATCH 083/144] 2/3 --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 208036cab..a46b67e29 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -418,7 +418,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) Marmarapk = GetUnspendable(cp,0); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); if ( (val= CCaddress_balance(coinaddr)) < amount ) - val = 9*(amount - txfee) / 10; + val = 2*(amount - txfee) / 3; else val = amount; if ( val > txfee ) inputsum = AddNormalinputs2(mtx,val,MARMARA_VINS); From 681177257d0a8868f2cac4cb2a9c4fc5ebb3a29e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:30:26 -1100 Subject: [PATCH 084/144] Test --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index a46b67e29..185e67d66 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -418,10 +418,10 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) Marmarapk = GetUnspendable(cp,0); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); if ( (val= CCaddress_balance(coinaddr)) < amount ) - val = 2*(amount - txfee) / 3; + val = 9*(amount - txfee) / 10; else val = amount; if ( val > txfee ) - inputsum = AddNormalinputs2(mtx,val,MARMARA_VINS); + inputsum = AddNormalinputs2(mtx,val,CC_MAXVINS/2); //fprintf(stderr,"normal inputs %.8f val %.8f\n",(double)inputsum/COIN,(double)val/COIN); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) From 7d4824b53458e3b40394d75965a78ce2d01f1c50 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:32:06 -1100 Subject: [PATCH 085/144] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 185e67d66..d9efa583b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -418,7 +418,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) Marmarapk = GetUnspendable(cp,0); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); if ( (val= CCaddress_balance(coinaddr)) < amount ) - val = 9*(amount - txfee) / 10; + val = 3*(amount - txfee) / 4; else val = amount; if ( val > txfee ) inputsum = AddNormalinputs2(mtx,val,CC_MAXVINS/2); From 3b0a779f0d44782e29dca0466abffd1b70f380b2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:35:10 -1100 Subject: [PATCH 086/144] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index d9efa583b..22962c94e 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -418,7 +418,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) Marmarapk = GetUnspendable(cp,0); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); if ( (val= CCaddress_balance(coinaddr)) < amount ) - val = 3*(amount - txfee) / 4; + val = 2*(amount - txfee) / 3; else val = amount; if ( val > txfee ) inputsum = AddNormalinputs2(mtx,val,CC_MAXVINS/2); From 21bd1c08e861d2dd690c9431f9d8f5c96c4007fb Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Jan 2019 02:36:53 -1100 Subject: [PATCH 087/144] Val -= txfee --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 22962c94e..795b95186 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -418,7 +418,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) Marmarapk = GetUnspendable(cp,0); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); if ( (val= CCaddress_balance(coinaddr)) < amount ) - val = 2*(amount - txfee) / 3; + val -= txfee; else val = amount; if ( val > txfee ) inputsum = AddNormalinputs2(mtx,val,CC_MAXVINS/2); From 2a7ecf6e03a5c788eea625a60ae607a7dcc7513e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 00:06:17 -1100 Subject: [PATCH 088/144] Comments --- src/komodo_bitcoind.h | 1 + src/miner.cpp | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 19a5f8103..d24492317 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2236,6 +2236,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } else { + // add opreturn // signSuccess = CCFinalizetx(...) } if (!signSuccess) diff --git a/src/miner.cpp b/src/miner.cpp index 3a163c637..c71bc2461 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -541,9 +541,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txNew.vout[0].nValue += 5000; pblock->vtx[0] = txNew; - //fprintf(stderr,"ht.%d cmp.%d [%d %d %d %d %d]\n",nHeight,nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0,nHeight > 1,ASSETCHAINS_SYMBOL[0] != 0, (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1), ASSETCHAINS_COMMISSION != 0,(commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0); - // check if coinbase transactions must be time locked at current subsidy and prepend the time lock - // to transaction if so, cast for GTE operator if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) { char checkaddr[64]; From 539b6dd1a9228d8174dc8cb0de29aabfeb437afe Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 00:38:55 -1100 Subject: [PATCH 089/144] -ac_ccenable[] --- src/cc/CCinclude.h | 1 + src/cc/eval.cpp | 5 +++++ src/komodo_globals.h | 1 + src/komodo_utils.h | 19 ++++++++++++++++++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index d103f408d..d3acbd5e6 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -55,6 +55,7 @@ extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE; extern uint32_t ASSETCHAINS_CC; extern char ASSETCHAINS_SYMBOL[]; extern std::string CCerror; +extern ASSETCHAINS_CCDISABLES[256]; #define CC_MAXVINS 1024 diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index 9161f2007..b98982ecd 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -65,6 +65,11 @@ bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn) return Invalid("empty-eval"); uint8_t ecode = cond->code[0]; + if ( ASSETCHAINS_CCDISABLES[ecode] != 0 ) + { + fprintf(stderr,"%s evalcode.%d %02x\n",txTo.GetHash().GetHex().c_str(),ecode,ecode); + return Invalid("disabled-code, -ac_ccenables didnt include this ecode"); + } cp = &CCinfos[(int32_t)ecode]; if ( cp->didinit == 0 ) { diff --git a/src/komodo_globals.h b/src/komodo_globals.h index f434674b7..4e1d0ef8d 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -71,6 +71,7 @@ uint64_t ASSETCHAINS_TIMEUNLOCKFROM = 0, ASSETCHAINS_TIMEUNLOCKTO = 0; uint32_t ASSETCHAINS_LASTERA = 1; uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_DECAY[ASSETCHAINS_MAX_ERAS]; +uint8_t ASSETCHAINS_CCENABLE[256],ASSETCHAINS_CCDISABLES[256]; #define _ASSETCHAINS_EQUIHASH 0 uint32_t ASSETCHAINS_NUMALGOS = 2; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 017a17eff..163b1c43a 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1654,7 +1654,7 @@ extern int64_t MAX_MONEY; void komodo_args(char *argv0) { extern const char *Notaries_elected1[][2]; - std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[8192],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,baseid,len,n,extralen = 0; + std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[8192],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz,baseid,len,n,extralen = 0; IS_KOMODO_NOTARY = GetBoolArg("-notary", false); if ( GetBoolArg("-gen", false) != 0 ) @@ -1779,6 +1779,23 @@ void komodo_args(char *argv0) ASSETCHAINS_BEAMPORT = GetArg("-ac_beam",0); ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); ASSETCHAINS_MARMARA = GetArg("-ac_marmara",0); + Split(GetArg("-ac_ccenable",""), ASSETCHAINS_CCENABLE, 0); + for (i=nonz=0; i<0x100; i++) + { + if ( ASSETCHAINS_CCENABLE[i] != 0 ) + { + nonz++; + fprintf(stderr,"%d ",ASSETCHAINS_CCENABLE[i]); + } + } + fprintf(stderr,"nonz.%d CCENABLES[]\n"); + if ( nonz > 0 ) + { + for (i=0; i<256; i++) + ASSETCHAINS_CCDISABLES[i] = 1; + for (i=0; i<256; i++) + ASSETCHAINS_CCDISABLES[ASSETCHAINS_CCENABLE[i]] = 0; + } if ( ASSETCHAINS_BEAMPORT != 0 && ASSETCHAINS_CODAPORT != 0 ) { fprintf(stderr,"can only have one of -ac_beam or -ac_coda\n"); From 6e40c81b942c63ad43684ee6765accb92e5a41de Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 00:39:53 -1100 Subject: [PATCH 090/144] uint8_t --- src/cc/CCinclude.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index d3acbd5e6..7541dc3a4 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -55,7 +55,7 @@ extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE; extern uint32_t ASSETCHAINS_CC; extern char ASSETCHAINS_SYMBOL[]; extern std::string CCerror; -extern ASSETCHAINS_CCDISABLES[256]; +extern uint8_t ASSETCHAINS_CCDISABLES[256]; #define CC_MAXVINS 1024 From 6e71c40201d247de410c7a12cb7f4e2ac87aa8c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 00:48:53 -1100 Subject: [PATCH 091/144] Ccenables --- src/komodo_globals.h | 2 +- src/komodo_utils.h | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 4e1d0ef8d..ba5e84135 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -71,7 +71,7 @@ uint64_t ASSETCHAINS_TIMEUNLOCKFROM = 0, ASSETCHAINS_TIMEUNLOCKTO = 0; uint32_t ASSETCHAINS_LASTERA = 1; uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_DECAY[ASSETCHAINS_MAX_ERAS]; -uint8_t ASSETCHAINS_CCENABLE[256],ASSETCHAINS_CCDISABLES[256]; +uint8_t ASSETCHAINS_CCDISABLES[256]; #define _ASSETCHAINS_EQUIHASH 0 uint32_t ASSETCHAINS_NUMALGOS = 2; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 163b1c43a..e074bd4c0 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1654,9 +1654,10 @@ extern int64_t MAX_MONEY; void komodo_args(char *argv0) { extern const char *Notaries_elected1[][2]; - std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[8192],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz,baseid,len,n,extralen = 0; + std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[8192],disablebits[32],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz,baseid,len,n,extralen = 0; uint64_t ccenables[256]; IS_KOMODO_NOTARY = GetBoolArg("-notary", false); - + memset(ccenables,0,sizeof(ccenables)); + memset(disablebits,0,sizeof(disablebits)); if ( GetBoolArg("-gen", false) != 0 ) { KOMODO_MININGTHREADS = GetArg("-genproclimit",-1); @@ -1779,22 +1780,25 @@ void komodo_args(char *argv0) ASSETCHAINS_BEAMPORT = GetArg("-ac_beam",0); ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); ASSETCHAINS_MARMARA = GetArg("-ac_marmara",0); - Split(GetArg("-ac_ccenable",""), ASSETCHAINS_CCENABLE, 0); + Split(GetArg("-ac_ccenable",""), ccenables, 0); for (i=nonz=0; i<0x100; i++) { - if ( ASSETCHAINS_CCENABLE[i] != 0 ) + if ( ccenables[i] != 0 ) { nonz++; - fprintf(stderr,"%d ",ASSETCHAINS_CCENABLE[i]); + fprintf(stderr,"%d ",ccenables[i]); } } - fprintf(stderr,"nonz.%d CCENABLES[]\n"); + fprintf(stderr,"nonz.%d ccenables[]\n",nonz); if ( nonz > 0 ) { for (i=0; i<256; i++) ASSETCHAINS_CCDISABLES[i] = 1; for (i=0; i<256; i++) - ASSETCHAINS_CCDISABLES[ASSETCHAINS_CCENABLE[i]] = 0; + { + SETBIT(disablebits,i); + ASSETCHAINS_CCDISABLES[ccenables[i] & 0xff] = 0; + } } if ( ASSETCHAINS_BEAMPORT != 0 && ASSETCHAINS_CODAPORT != 0 ) { @@ -1880,7 +1884,7 @@ void komodo_args(char *argv0) fprintf(stderr,"-ac_script and -ac_marmara are mutually exclusive\n"); exit(0); } - 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 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 ) + 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 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 ) { 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; @@ -1956,6 +1960,11 @@ void komodo_args(char *argv0) extraptr[extralen++] = 'c'; if ( ASSETCHAINS_MARMARA != 0 ) extraptr[extralen++] = ASSETCHAINS_MARMARA; + if ( nonz > 0 ) + { + memcpy(&extraptr[extralen],disablebits,sizeof(disablebits)); + extralen += sizeof(disablebits); + } } addn = GetArg("-seednode",""); From 70fba21c4681a0d2a23166694ac4fc89f4f2db21 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 00:50:51 -1100 Subject: [PATCH 092/144] SETBIT --- src/komodo_defs.h | 4 ++++ src/komodo_utils.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index bd516be61..91fcadddb 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -30,6 +30,10 @@ #define KOMODO_SAPLING_DEADLINE 1550188800 // Feb 15th, 2019 #define _COINBASE_MATURITY 100 +#define SETBIT(bits,bitoffset) (((uint8_t *)bits)[(bitoffset) >> 3] |= (1 << ((bitoffset) & 7))) +#define GETBIT(bits,bitoffset) (((uint8_t *)bits)[(bitoffset) >> 3] & (1 << ((bitoffset) & 7))) +#define CLEARBIT(bits,bitoffset) (((uint8_t *)bits)[(bitoffset) >> 3] &= ~(1 << ((bitoffset) & 7))) + extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC; int32_t MAX_BLOCK_SIZE(int32_t height); diff --git a/src/komodo_utils.h b/src/komodo_utils.h index e074bd4c0..cb2ea7a1e 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1786,7 +1786,7 @@ void komodo_args(char *argv0) if ( ccenables[i] != 0 ) { nonz++; - fprintf(stderr,"%d ",ccenables[i]); + fprintf(stderr,"%d ",(uint8_t)(ccenables[i] & 0xff)); } } fprintf(stderr,"nonz.%d ccenables[]\n",nonz); From ac9bd541b4c32e8971d1a740813bda0ad08409d5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 00:57:55 -1100 Subject: [PATCH 093/144] Require cc for ccenable --- src/komodo_utils.h | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index cb2ea7a1e..1352c5bf7 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1780,24 +1780,27 @@ void komodo_args(char *argv0) ASSETCHAINS_BEAMPORT = GetArg("-ac_beam",0); ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); ASSETCHAINS_MARMARA = GetArg("-ac_marmara",0); - Split(GetArg("-ac_ccenable",""), ccenables, 0); - for (i=nonz=0; i<0x100; i++) + if ( ASSETCHAINS_CC != 0 ) { - if ( ccenables[i] != 0 ) + Split(GetArg("-ac_ccenable",""), ccenables, 0); + for (i=nonz=0; i<0x100; i++) { - nonz++; - fprintf(stderr,"%d ",(uint8_t)(ccenables[i] & 0xff)); + if ( ccenables[i] != 0 ) + { + nonz++; + fprintf(stderr,"%d ",(uint8_t)(ccenables[i] & 0xff)); + } } - } - fprintf(stderr,"nonz.%d ccenables[]\n",nonz); - if ( nonz > 0 ) - { - for (i=0; i<256; i++) - ASSETCHAINS_CCDISABLES[i] = 1; - for (i=0; i<256; i++) + fprintf(stderr,"nonz.%d ccenables[]\n",nonz); + if ( nonz > 0 ) { - SETBIT(disablebits,i); - ASSETCHAINS_CCDISABLES[ccenables[i] & 0xff] = 0; + for (i=0; i<256; i++) + ASSETCHAINS_CCDISABLES[i] = 1; + for (i=0; i<256; i++) + { + SETBIT(disablebits,i); + ASSETCHAINS_CCDISABLES[ccenables[i] & 0xff] = 0; + } } } if ( ASSETCHAINS_BEAMPORT != 0 && ASSETCHAINS_CODAPORT != 0 ) From 3ab60f65c75e8d3ef3681920e8a21b3ba20cf54f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 01:00:51 -1100 Subject: [PATCH 094/144] Fix disable bits --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 1352c5bf7..ea1741d5a 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1798,7 +1798,7 @@ void komodo_args(char *argv0) ASSETCHAINS_CCDISABLES[i] = 1; for (i=0; i<256; i++) { - SETBIT(disablebits,i); + SETBIT(disablebits,(ccenables[i] & 0xff)); ASSETCHAINS_CCDISABLES[ccenables[i] & 0xff] = 0; } } From 37019a6438e46c6f247a2ff0990725381a93d1eb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 01:02:53 -1100 Subject: [PATCH 095/144] Fix bits --- src/komodo_utils.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index ea1741d5a..eb6134ffe 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1795,10 +1795,13 @@ void komodo_args(char *argv0) if ( nonz > 0 ) { for (i=0; i<256; i++) + { ASSETCHAINS_CCDISABLES[i] = 1; + SETBIT(disablebits,i); + } for (i=0; i<256; i++) { - SETBIT(disablebits,(ccenables[i] & 0xff)); + CLEARBIT(disablebits,(ccenables[i] & 0xff)); ASSETCHAINS_CCDISABLES[ccenables[i] & 0xff] = 0; } } From c5dcd3f8282288b2af851712b7d047f32b2761b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 01:20:27 -1100 Subject: [PATCH 096/144] cclib.so --- src/Makefile.am | 3 ++- src/cc/eval.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 5e665cc3c..96ab3f1fa 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -571,7 +571,8 @@ komodod_LDADD += \ $(LIBBITCOIN_CRYPTO) \ $(LIBVERUS_CRYPTO) \ $(LIBVERUS_PORTABLE_CRYPTO) \ - $(LIBZCASH_LIBS) + $(LIBZCASH_LIBS) \ + cclib.so if ENABLE_PROTON komodod_LDADD += $(LIBBITCOIN_PROTON) $(PROTON_LIBS) diff --git a/src/cc/eval.h b/src/cc/eval.h index de1636ab8..be86629a0 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -59,6 +59,8 @@ EVAL(EVAL_TOKENS, 0xf2) +// evalcodes 0x10 to 0x7f are reserved for cclib dynamic CC + typedef uint8_t EvalCode; From 614c8a61d5c280dc6e76bef72cb6f475f7f46101 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 01:21:43 -1100 Subject: [PATCH 097/144] Win dll spot --- src/Makefile.am | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Makefile.am b/src/Makefile.am index 96ab3f1fa..327d32e3f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -572,7 +572,12 @@ komodod_LDADD += \ $(LIBVERUS_CRYPTO) \ $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBZCASH_LIBS) \ +if TARGET_WINDOWS + +# add .dll somehow +else cclib.so +endif if ENABLE_PROTON komodod_LDADD += $(LIBBITCOIN_PROTON) $(PROTON_LIBS) From f93a96af0741da186fb9bf7933289a16f0abdc8a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 01:22:54 -1100 Subject: [PATCH 098/144] -if --- src/Makefile.am | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 327d32e3f..b1e67cf2e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -572,12 +572,8 @@ komodod_LDADD += \ $(LIBVERUS_CRYPTO) \ $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBZCASH_LIBS) \ -if TARGET_WINDOWS - -# add .dll somehow -else cclib.so -endif + if ENABLE_PROTON komodod_LDADD += $(LIBBITCOIN_PROTON) $(PROTON_LIBS) From b22c190e3c8b87f6551b62b5a1eb97bfaa165ca6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 01:33:06 -1100 Subject: [PATCH 099/144] cclib.cpp --- src/Makefile.am | 3 +++ src/cc/cclib.cpp | 2 ++ src/cc/eval.h | 2 ++ 3 files changed, 7 insertions(+) create mode 100644 src/cc/cclib.cpp diff --git a/src/Makefile.am b/src/Makefile.am index b1e67cf2e..46e03dc83 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -559,6 +559,9 @@ if ENABLE_WALLET komodod_LDADD += $(LIBBITCOIN_WALLET) endif +cclib.so: cclib.cpp + gcc -o cclib.so -c cclib.cpp + komodod_LDADD += \ $(BOOST_LIBS) \ $(BDB_LIBS) \ diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp new file mode 100644 index 000000000..5cd56f9eb --- /dev/null +++ b/src/cc/cclib.cpp @@ -0,0 +1,2 @@ + +char *CClib_name() { return("stub"); } diff --git a/src/cc/eval.h b/src/cc/eval.h index be86629a0..a42bbdb2f 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -60,6 +60,8 @@ // evalcodes 0x10 to 0x7f are reserved for cclib dynamic CC +#define EVAL_FIRSTUSER 0x10 +#define EVAL_LASTUSER 0x7f typedef uint8_t EvalCode; From b693dfd93c8659596d4c19091a7535562f0400e8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 01:35:21 -1100 Subject: [PATCH 100/144] Test --- src/Makefile.am | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 46e03dc83..7de831f3b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -560,7 +560,6 @@ komodod_LDADD += $(LIBBITCOIN_WALLET) endif cclib.so: cclib.cpp - gcc -o cclib.so -c cclib.cpp komodod_LDADD += \ $(BOOST_LIBS) \ From 32d407e84e1729e829aae95d392265a55457c570 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 01:37:20 -1100 Subject: [PATCH 101/144] Char * --- src/Makefile.am | 2 -- src/cc/cclib.cpp | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 7de831f3b..b1e67cf2e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -559,8 +559,6 @@ if ENABLE_WALLET komodod_LDADD += $(LIBBITCOIN_WALLET) endif -cclib.so: cclib.cpp - komodod_LDADD += \ $(BOOST_LIBS) \ $(BDB_LIBS) \ diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 5cd56f9eb..29ea4b787 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -1,2 +1,2 @@ -char *CClib_name() { return("stub"); } +char *CClib_name() { return((char *)"stub"); } From a22cc60e1a7c896d866f867cbc854076973310f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 01:42:22 -1100 Subject: [PATCH 102/144] Make --- src/Makefile.am | 1 - src/cc/makecclib | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100755 src/cc/makecclib diff --git a/src/Makefile.am b/src/Makefile.am index b1e67cf2e..96ab3f1fa 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -574,7 +574,6 @@ komodod_LDADD += \ $(LIBZCASH_LIBS) \ cclib.so - if ENABLE_PROTON komodod_LDADD += $(LIBBITCOIN_PROTON) $(PROTON_LIBS) endif diff --git a/src/cc/makecclib b/src/cc/makecclib new file mode 100755 index 000000000..e90f0877b --- /dev/null +++ b/src/cc/makecclib @@ -0,0 +1 @@ +gcc -fPIC -shared -c -o ../cclib.so cclib.cpp From c310c7fa47e7048c98cb16b9e93beb93fd9e6975 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 02:05:51 -1100 Subject: [PATCH 103/144] CClib_Dispatch --- src/cc/cclib.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/cc/eval.cpp | 7 ++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 29ea4b787..f89301b34 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -1,2 +1,40 @@ +/****************************************************************************** + * Copyright © 2014-2019 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. * + * * + ******************************************************************************/ + +#include +#include + +#include "../primitives/block.h" +#include "../primitives/transaction.h" +#include "../script/cc.h" +#include "eval.h" +#include "utils.h" +#include "CCinclude.h" +#include "../main.h" +#include "../chain.h" +#include "../core_io.h" +#include "../crosschain.h" char *CClib_name() { return((char *)"stub"); } + +bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) +{ + uint8_t evalcode = cond->code[0]; + if ( evalcode >= EVAL_FIRSTUSER && evalcode <= EVAL_LASTUSER ) + { + + } + return eval->Invalid("cclib CC must have evalcode between 16 and 127"); +} diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index b98982ecd..e30ec263c 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -27,6 +27,7 @@ #include "core_io.h" #include "crosschain.h" +bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn); Eval* EVAL_TEST = 0; struct CCcontract_info CCinfos[0x100]; @@ -70,13 +71,17 @@ bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn) fprintf(stderr,"%s evalcode.%d %02x\n",txTo.GetHash().GetHex().c_str(),ecode,ecode); return Invalid("disabled-code, -ac_ccenables didnt include this ecode"); } + std::vector vparams(cond->code+1, cond->code+cond->codeLength); + if ( ecode >= EVAL_FIRSTUSER && ecode <= EVAL_LASTUSER ) + { + return CClib_Dispatch(cond,this,vparams,txTo,nIn); + } cp = &CCinfos[(int32_t)ecode]; if ( cp->didinit == 0 ) { CCinit(cp,ecode); cp->didinit = 1; } - std::vector vparams(cond->code+1, cond->code+cond->codeLength); switch ( ecode ) { case EVAL_IMPORTPAYOUT: From 5a4c3ce5b3004bf27da6a1bb20d99baf9fd0b7f0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 02:08:22 -1100 Subject: [PATCH 104/144] cryptoconditions.h --- src/cc/eval.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index e30ec263c..7c578c8c3 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -14,8 +14,8 @@ ******************************************************************************/ #include -#include +#include "../cryptoconditions/include/cryptoconditions.h" #include "primitives/block.h" #include "primitives/transaction.h" #include "script/cc.h" From 8420bb5e96288bda4e29f868f9dd67b6ec920d42 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 02:09:06 -1100 Subject: [PATCH 105/144] Fix --- src/cc/cclib.cpp | 4 ++-- src/cc/eval.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index f89301b34..cca7a812a 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -14,8 +14,8 @@ ******************************************************************************/ #include -#include - +//#include +#include "../cryptoconditions/include/cryptoconditions.h" #include "../primitives/block.h" #include "../primitives/transaction.h" #include "../script/cc.h" diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index 7c578c8c3..e30ec263c 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -14,8 +14,8 @@ ******************************************************************************/ #include +#include -#include "../cryptoconditions/include/cryptoconditions.h" #include "primitives/block.h" #include "primitives/transaction.h" #include "script/cc.h" From 05ffb90ab69cc52a65770af14644bccec2596251 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 02:10:35 -1100 Subject: [PATCH 106/144] Test --- src/cc/cclib.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index cca7a812a..d6e7a95fc 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -15,17 +15,17 @@ #include //#include -#include "../cryptoconditions/include/cryptoconditions.h" -#include "../primitives/block.h" -#include "../primitives/transaction.h" -#include "../script/cc.h" -#include "eval.h" -#include "utils.h" -#include "CCinclude.h" -#include "../main.h" -#include "../chain.h" -#include "../core_io.h" -#include "../crosschain.h" +#include "cryptoconditions/include/cryptoconditions.h" +#include "primitives/block.h" +#include "primitives/transaction.h" +#include "script/cc.h" +#include "cc/eval.h" +#include "cc/utils.h" +#include "cc/CCinclude.h" +#include "main.h" +#include "chain.h" +#include "core_io.h" +#include "crosschain.h" char *CClib_name() { return((char *)"stub"); } From afc693198f048820a3ec7af0200c8b1775f77632 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 02:14:25 -1100 Subject: [PATCH 107/144] Test --- src/cc/cclib.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index d6e7a95fc..bd66f5bda 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -15,7 +15,7 @@ #include //#include -#include "cryptoconditions/include/cryptoconditions.h" +#include "../cryptoconditions/include/cryptoconditions.h" #include "primitives/block.h" #include "primitives/transaction.h" #include "script/cc.h" From a761d97300566eff6f68bad80843c1e924a28629 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 02:24:31 -1100 Subject: [PATCH 108/144] Makecclib --- src/cc/cclib.cpp | 4 ++-- src/cc/makecclib | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index bd66f5bda..036971666 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -14,8 +14,8 @@ ******************************************************************************/ #include -//#include -#include "../cryptoconditions/include/cryptoconditions.h" +#include + #include "primitives/block.h" #include "primitives/transaction.h" #include "script/cc.h" diff --git a/src/cc/makecclib b/src/cc/makecclib index e90f0877b..47aec377d 100755 --- a/src/cc/makecclib +++ b/src/cc/makecclib @@ -1 +1 @@ -gcc -fPIC -shared -c -o ../cclib.so cclib.cpp +gcc -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o ../cclib.so cclib.cpp From 33a2ac6e3bbeddabd72ea4da79facaa999d08eb7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 02:33:23 -1100 Subject: [PATCH 109/144] -ac_cclib --- src/cc/cclib.cpp | 15 ++++++++++++--- src/cc/eval.cpp | 4 +++- src/komodo_globals.h | 2 +- src/komodo_utils.h | 14 ++++++++++++-- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 036971666..24c6380bd 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -27,14 +27,23 @@ #include "core_io.h" #include "crosschain.h" -char *CClib_name() { return((char *)"stub"); } +#define MYCCLIBNAME ((char *)"stub") +extern std::string ASSETCHAINS_CCLIB; + +char *CClib_name() { return(MYCCLIBNAME); } bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) { - uint8_t evalcode = cond->code[0]; + uint8_t evalcode; + if ( ASSETCHAINS_CCLIB != MYCCLIBNAME ) + { + fprintf(stderr,"-ac_cclib=%s vs myname %s\n",ASSETCHAINS_CCLIB,MYCCLIBNAME); + return eval->Invalid("-ac_cclib name mismatches myname"); + } + evalcode = cond->code[0]; if ( evalcode >= EVAL_FIRSTUSER && evalcode <= EVAL_LASTUSER ) { - + return(true); } return eval->Invalid("cclib CC must have evalcode between 16 and 127"); } diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index e30ec263c..bd8c69a55 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -74,7 +74,9 @@ bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn) std::vector vparams(cond->code+1, cond->code+cond->codeLength); if ( ecode >= EVAL_FIRSTUSER && ecode <= EVAL_LASTUSER ) { - return CClib_Dispatch(cond,this,vparams,txTo,nIn); + if ( ASSETCHAINS_CCLIB.size() > 0 && ASSETCHAINS_CCLIB == CClib_name() ) + return CClib_Dispatch(cond,this,vparams,txTo,nIn); + else return Invalid("mismatched -ac_cclib vs CClib_name"); } cp = &CCinfos[(int32_t)ecode]; if ( cp->didinit == 0 ) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index ba5e84135..79b56cbbb 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -48,7 +48,7 @@ unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; 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; -std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB,ASSETCHAINS_SELFIMPORT; +std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB,ASSETCHAINS_SELFIMPORT,ASSETCHAINS_CCLIB; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_MARMARA; bool VERUS_MINTBLOCKS; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index eb6134ffe..289a84d7c 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1782,6 +1782,7 @@ void komodo_args(char *argv0) ASSETCHAINS_MARMARA = GetArg("-ac_marmara",0); if ( ASSETCHAINS_CC != 0 ) { + ASSETCHAINS_CCLIB = GetArg("-ac_cclib",""); Split(GetArg("-ac_ccenable",""), ccenables, 0); for (i=nonz=0; i<0x100; i++) { @@ -1890,7 +1891,7 @@ void komodo_args(char *argv0) fprintf(stderr,"-ac_script and -ac_marmara are mutually exclusive\n"); exit(0); } - 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 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 ) + 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 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 ) { 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; @@ -1971,8 +1972,17 @@ void komodo_args(char *argv0) memcpy(&extraptr[extralen],disablebits,sizeof(disablebits)); extralen += sizeof(disablebits); } + if ( ASSETCHAINS_CCLIB.size() > 1 ) + { + for (i=0; i 0 ) ASSETCHAINS_SEED = 1; From cc1d11914488a18b78cedd4a22f33b9d313f775a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 02:34:33 -1100 Subject: [PATCH 110/144] Test --- src/cc/CCinclude.h | 2 +- src/cc/cclib.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 7541dc3a4..680e4ca5c 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -54,7 +54,7 @@ one other technical note is that komodod has the insight-explorer extensions bui extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE; extern uint32_t ASSETCHAINS_CC; extern char ASSETCHAINS_SYMBOL[]; -extern std::string CCerror; +extern std::string CCerror,ASSETCHAINS_CCLIB; extern uint8_t ASSETCHAINS_CCDISABLES[256]; #define CC_MAXVINS 1024 diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 24c6380bd..9dc74e424 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -28,7 +28,6 @@ #include "crosschain.h" #define MYCCLIBNAME ((char *)"stub") -extern std::string ASSETCHAINS_CCLIB; char *CClib_name() { return(MYCCLIBNAME); } From 385c79357ff8204ead60d0d7b12887b18b85ecd2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 02:35:27 -1100 Subject: [PATCH 111/144] char *CClib_name() --- src/cc/eval.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index bd8c69a55..ca2703bff 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -28,6 +28,7 @@ #include "crosschain.h" bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn); +char *CClib_name(); Eval* EVAL_TEST = 0; struct CCcontract_info CCinfos[0x100]; From f31416834ae86490fbfe855ee2435d8d9348f936 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 02:40:24 -1100 Subject: [PATCH 112/144] Char * --- src/cc/cclib.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 9dc74e424..10a289459 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -36,7 +36,7 @@ bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,co uint8_t evalcode; if ( ASSETCHAINS_CCLIB != MYCCLIBNAME ) { - fprintf(stderr,"-ac_cclib=%s vs myname %s\n",ASSETCHAINS_CCLIB,MYCCLIBNAME); + fprintf(stderr,"-ac_cclib=%s vs myname %s\n",ASSETCHAINS_CCLIB.c_str(),MYCCLIBNAME); return eval->Invalid("-ac_cclib name mismatches myname"); } evalcode = cond->code[0]; From c7002513e383907de706e1e6459370d6ac448afe Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 03:37:28 -1100 Subject: [PATCH 113/144] Height and from_mempool in club --- src/cc/cclib.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 10a289459..889c40d8c 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -33,12 +33,22 @@ char *CClib_name() { return(MYCCLIBNAME); } bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) { - uint8_t evalcode; + uint8_t evalcode; int32_t height,from_mempool; if ( ASSETCHAINS_CCLIB != MYCCLIBNAME ) { fprintf(stderr,"-ac_cclib=%s vs myname %s\n",ASSETCHAINS_CCLIB.c_str(),MYCCLIBNAME); return eval->Invalid("-ac_cclib name mismatches myname"); } + height = KOMODO_CONNECTING; + if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation + return(true); + if ( ASSETCHAINS_CC == 0 || (height & ~(1<<30)) < KOMODO_CCACTIVATE ) + return eval->Invalid("CC are disabled or not active yet"); + if ( (KOMODO_CONNECTING & (1<<30)) != 0 ) + { + from_mempool = 1; + height &= ((1<<30) - 1); + } evalcode = cond->code[0]; if ( evalcode >= EVAL_FIRSTUSER && evalcode <= EVAL_LASTUSER ) { From 6692b4b0c6a2fe677aced9a40e821a67df6ac2cf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 04:06:59 -1100 Subject: [PATCH 114/144] Locked staking --- src/komodo_bitcoind.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d24492317..4ac20713b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2149,8 +2149,26 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } else { - // calc 1of2 address - // iterate all unspents not spent in mempool and komodo_addutxo + struct CCcontract_info *cp,C; uint256 txid; int32_t vout; CAmount nValue; char coinaddr[64]; CPubKey mypk,Marmarapk; + std::vector > unspentOutputs; + cp = CCinit(&C,EVAL_MARMARA); + mypk = pubkey2pk(Mypubkey()); + Marmarapk = GetUnspendable(cp,0); + GetCCaddress1of2(cp,coinaddr,Marmarapk,pk); + SetCCunspents(unspentOutputs,coinaddr); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + if ( (nValue= it->second.satoshis) < COIN ) + continue; + if ( GetTransaction(txid,tx,hashBlock,true) != 0 && (pindex= komodo_getblockindex(hashBlock)) != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + { + const CScript &scriptPubKey = tx.vout[vout].scriptPubKey; + array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,txid,vout,coinaddr,hashbuf,(CScript)scriptPubKey); + fprintf(stderr,"addutxo %.8f numkp.%d vs max.%d\n",(double)nValue/COIN,numkp,maxkp); + } + } } lasttime = (uint32_t)time(NULL); //fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp); From 66198b83f0407e5487dd893d361a9279186f8d82 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 04:07:41 -1100 Subject: [PATCH 115/144] Mypk --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4ac20713b..fbd73f59f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2154,7 +2154,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); Marmarapk = GetUnspendable(cp,0); - GetCCaddress1of2(cp,coinaddr,Marmarapk,pk); + GetCCaddress1of2(cp,coinaddr,Marmarapk,mypk); SetCCunspents(unspentOutputs,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { From 240fdaa384fb247b2e352fb211916a51b24fead9 Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 20 Jan 2019 03:11:54 +0100 Subject: [PATCH 116/144] add cclib to makefile --- zcutil/build.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/zcutil/build.sh b/zcutil/build.sh index 08517475c..68239e16e 100755 --- a/zcutil/build.sh +++ b/zcutil/build.sh @@ -101,6 +101,21 @@ eval "$MAKE" --version as --version ld -v +#BUILD CCLIB + +WD=$PWD +cd src/cc +echo $PWD + +if make "$@"; then + echo CCLIB BUILD SUCCESSFUL +else + echo CCLIB BUILD FAILED + exit 1 +fi + +cd $WD + HOST="$HOST" BUILD="$BUILD" NO_PROTON="$PROTON_ARG" "$MAKE" "$@" -C ./depends/ V=1 ./autogen.sh From 5fe3792aef1b662640e37d5c076e7793b3ac5445 Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 20 Jan 2019 03:13:21 +0100 Subject: [PATCH 117/144] create cclib Makefile --- src/cc/Makefile | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/cc/Makefile diff --git a/src/cc/Makefile b/src/cc/Makefile new file mode 100644 index 000000000..5848d46dd --- /dev/null +++ b/src/cc/Makefile @@ -0,0 +1,19 @@ +SHELL = /bin/sh +CC = gcc +#CXXFLAGS = -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c +CFLAGS = -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c +DEBUGFLAGS = -O0 -D _DEBUG +RELEASEFLAGS = -O2 -D NDEBUG -combine -fwhole-program + +TARGET = ../cclib.so +SOURCES = cclib.cpp +#HEADERS = $(shell echo ../cryptoconditions/include/*.h) +all: $(TARGET) + +$(TARGET): $(SOURCES) + $(info Building cclib.so to src/) + $(CC) $(CFLAGS) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) + +clean: + rm -rf $(TARGET) + From 4357791ede3f46e63fab14dfd3b12a321ebff2c9 Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 20 Jan 2019 05:04:14 +0100 Subject: [PATCH 118/144] [update] cclib multiOS Makefile --- src/cc/Makefile | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/cc/Makefile b/src/cc/Makefile index 5848d46dd..24d13690c 100644 --- a/src/cc/Makefile +++ b/src/cc/Makefile @@ -1,19 +1,32 @@ -SHELL = /bin/sh -CC = gcc -#CXXFLAGS = -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -CFLAGS = -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -DEBUGFLAGS = -O0 -D _DEBUG -RELEASEFLAGS = -O2 -D NDEBUG -combine -fwhole-program - +SHELL = /bin/sh +CC = gcc +CC_WIN = x86_64-w64-mingw32-gcc-posix +CFLAGS_DARWIN = -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c +CFLAGS = -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c +CFLAGS_WIN = -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c +DEBUGFLAGS = -O0 -D _DEBUG +RELEASEFLAGS = -O2 -D NDEBUG -combine -fwhole-program +$(info $(OS)) +OS := $(shell uname -s) +$(info $(OS)) TARGET = ../cclib.so +TARGET_WIN = ../cclib.dll SOURCES = cclib.cpp #HEADERS = $(shell echo ../cryptoconditions/include/*.h) + all: $(TARGET) $(TARGET): $(SOURCES) $(info Building cclib.so to src/) +ifeq ($(OS),Darwin) + $(CC) $(CFLAGS_DARWIN) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) +else ifeq ($(OS),Linux) $(CC) $(CFLAGS) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) +#else ifeq ($(WIN_HOST),True) - todo: pass ENV var from build.sh if WIN host +else + $(info else) + #$(CC)_WIN $(CFLAGS_WIN) $(DEBUGFLAGS) -o $(TARGET_WIN) $(SOURCES) +endif clean: rm -rf $(TARGET) - From 1dbed5f02024e62783f3b8cf74652a0e9179fc45 Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 20 Jan 2019 05:06:51 +0100 Subject: [PATCH 119/144] [update] cclib multiOS Makefile --- src/cc/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/Makefile b/src/cc/Makefile index 24d13690c..3522a0c08 100644 --- a/src/cc/Makefile +++ b/src/cc/Makefile @@ -17,7 +17,7 @@ SOURCES = cclib.cpp all: $(TARGET) $(TARGET): $(SOURCES) - $(info Building cclib.so to src/) + $(info Building cclib to src/) ifeq ($(OS),Darwin) $(CC) $(CFLAGS_DARWIN) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) else ifeq ($(OS),Linux) @@ -25,7 +25,7 @@ else ifeq ($(OS),Linux) #else ifeq ($(WIN_HOST),True) - todo: pass ENV var from build.sh if WIN host else $(info else) - #$(CC)_WIN $(CFLAGS_WIN) $(DEBUGFLAGS) -o $(TARGET_WIN) $(SOURCES) + #$(CC_WIN) $(CFLAGS_WIN) $(DEBUGFLAGS) -o $(TARGET_WIN) $(SOURCES) endif clean: From 12ebbabfd6b21b77400bddd933cb9f5b04db4481 Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 20 Jan 2019 05:11:14 +0100 Subject: [PATCH 120/144] [update] OSX Makefile --- zcutil/build-mac.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/zcutil/build-mac.sh b/zcutil/build-mac.sh index 138508cb5..a3619111f 100755 --- a/zcutil/build-mac.sh +++ b/zcutil/build-mac.sh @@ -42,6 +42,21 @@ PREFIX="$(pwd)/depends/$TRIPLET" make "$@" -C ./depends/ V=1 NO_QT=1 NO_PROTON=1 +#BUILD CCLIB + +WD=$PWD +cd src/cc +echo $PWD + +if make "$@"; then + echo CCLIB BUILD SUCCESSFUL +else + echo CCLIB BUILD FAILED + exit 1 +fi + +cd $WD + ./autogen.sh CPPFLAGS="-I$PREFIX/include -arch x86_64" LDFLAGS="-L$PREFIX/lib -arch x86_64 -Wl,-no_pie" \ CXXFLAGS='-arch x86_64 -I/usr/local/Cellar/gcc\@6/6.4.0_2/include/c++/6.4.0/ -I$PREFIX/include -fwrapv -fno-strict-aliasing -Werror -g -Wl,-undefined -Wl,dynamic_lookup' \ From 9307591c1435a0881e74a9f25073b3ff39f87cd7 Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 20 Jan 2019 06:45:59 +0100 Subject: [PATCH 121/144] [update] OSX cclib Makefile --- src/cc/Makefile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cc/Makefile b/src/cc/Makefile index 3522a0c08..a3c54d81d 100644 --- a/src/cc/Makefile +++ b/src/cc/Makefile @@ -1,7 +1,8 @@ SHELL = /bin/sh CC = gcc +CC_DARWIN = g++-6 CC_WIN = x86_64-w64-mingw32-gcc-posix -CFLAGS_DARWIN = -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c +CFLAGS_DARWIN = -std=c++11 -arch x86_64 -I/usr/local/Cellar/gcc\@6/6.4.0_2/include/c++/6.4.0/ -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -c -Wl,-undefined -Wl,dynamic_lookup CFLAGS = -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c CFLAGS_WIN = -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c DEBUGFLAGS = -O0 -D _DEBUG @@ -19,13 +20,13 @@ all: $(TARGET) $(TARGET): $(SOURCES) $(info Building cclib to src/) ifeq ($(OS),Darwin) - $(CC) $(CFLAGS_DARWIN) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) + $(CC_DARWIN) $(CFLAGS_DARWIN) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) else ifeq ($(OS),Linux) $(CC) $(CFLAGS) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) #else ifeq ($(WIN_HOST),True) - todo: pass ENV var from build.sh if WIN host else - $(info else) - #$(CC_WIN) $(CFLAGS_WIN) $(DEBUGFLAGS) -o $(TARGET_WIN) $(SOURCES) + $(info WINDOWS) + $(CC_WIN) $(CFLAGS_WIN) $(DEBUGFLAGS) -o $(TARGET_WIN) $(SOURCES) endif clean: From 0139e3eedf9cf8b3515213017642c0d499d2996d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 20:18:36 -1100 Subject: [PATCH 122/144] test --- src/komodo.h | 13 ++++++++----- src/komodo_bitcoind.h | 6 ++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 7d2b17963..4a8bd7d96 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -947,12 +947,15 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } } } - if ( ((signedmask & 1) != 0 && numvalid >= KOMODO_MINRATIFY) || bitweight(signedmask) > (numnotaries/3) ) + if ( ASSETCHAINS_SYMBOL[0] != 0 || height < 100000 ) { - memset(&txhash,0,sizeof(txhash)); - komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0,0,zero,0); - printf("RATIFIED! >>>>>>>>>> new notaries.%d newheight.%d from height.%d\n",numvalid,(((height+KOMODO_ELECTION_GAP/2)/KOMODO_ELECTION_GAP)+1)*KOMODO_ELECTION_GAP,height); - } else printf("signedmask.%llx numvalid.%d wt.%d numnotaries.%d\n",(long long)signedmask,numvalid,bitweight(signedmask),numnotaries); + if ( ((signedmask & 1) != 0 && numvalid >= KOMODO_MINRATIFY) || bitweight(signedmask) > (numnotaries/3) ) + { + memset(&txhash,0,sizeof(txhash)); + komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0,0,zero,0); + printf("RATIFIED! >>>>>>>>>> new notaries.%d newheight.%d from height.%d\n",numvalid,(((height+KOMODO_ELECTION_GAP/2)/KOMODO_ELECTION_GAP)+1)*KOMODO_ELECTION_GAP,height); + } else printf("signedmask.%llx numvalid.%d wt.%d numnotaries.%d\n",(long long)signedmask,numvalid,bitweight(signedmask),numnotaries); + } } } } diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index fbd73f59f..10c6ee4b8 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -645,6 +645,7 @@ int32_t komodo_isPoS(CBlock *pblock) vout = pblock->vtx[n-1].vin[0].prevout.n; if ( ASSETCHAINS_MARMARA != 0 ) { + fprintf(stderr,"validate proper signature and unlockht preservation\n"); // need to verify it was signed by the non-Marmarapk of the 1of2 } txtime = komodo_txtime(&value,txid,vout,destaddr); @@ -2116,7 +2117,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt maxkp = numkp = 0; lasttime = 0; } - if ( ASSETCHAINS_MARMARA == 0 || 1 ) + if ( ASSETCHAINS_MARMARA == 0 ) { BOOST_FOREACH(const COutput& out, vecOutputs) { @@ -2248,12 +2249,13 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt txNew.vout[0].nValue = *utxovaluep - txfee; txNew.nLockTime = earliest; CTransaction txNewConst(txNew); - if ( ASSETCHAINS_MARMARA == 0 || 1 ) + if ( ASSETCHAINS_MARMARA == 0 ) { signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, *utxovaluep, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId); } else { + fprintf(stderr,"add opreturn and CCFinalizetx\n"); // add opreturn // signSuccess = CCFinalizetx(...) } From 6a696bdecf60fe51ee6c41824c1f0980c19caf75 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 21:32:52 -1100 Subject: [PATCH 123/144] +print --- src/cc/CCutils.cpp | 2 +- src/cc/cclib.cpp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index e9c30acc1..73f62825c 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -471,7 +471,7 @@ bool Myprivkey(uint8_t myprivkey[]) if ( pwalletMain->GetKey(keyID,vchSecret) != 0 ) { memcpy(myprivkey,vchSecret.begin(),32); - if ( 0 ) + if ( 1 ) { for (i=0; i<32; i++) fprintf(stderr,"0x%02x, ",myprivkey[i]); diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 889c40d8c..ed57b2194 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -27,6 +27,28 @@ #include "core_io.h" #include "crosschain.h" +#define FUNCNAME IsCClibInput +#define EVALCODE EVAL_FIRSTUSER +const char *CClibCCaddr = "RGLSRDnUqTB43bYtRtNVgmwSSd1sun2te8"; +const char *CClibNormaladdr = "RVVeUg43rNcq3mZFnvZ8yqagyzqFgUnq4u"; +char CClibCChexstr[67] = { "032447d97655da079729dc024c61088ea415b22f4c15d4810ddaf2069ac6468d2f" }; +uint8_t CClibCCpriv[32] = { 0x7c, 0x0b, 0x54, 0x9b, 0x65, 0xd4, 0x89, 0x57, 0xdf, 0x05, 0xfe, 0xa2, 0x62, 0x41, 0xa9, 0x09, 0x0f, 0x2a, 0x6b, 0x11, 0x2c, 0xbe, 0xbd, 0x06, 0x31, 0x8d, 0xc0, 0xb9, 0x96, 0x76, 0x3f, 0x24 }; +#include "CCcustom.inc" +#undef FUNCNAME +#undef EVALCODE + + +struct CClib_rpcinfo +{ + char *method,*help; + int32_t numrequiredargs,maxargs; // frontloaded with required + uint8_t evalcode; +} +CClib_rpcs[] = +{ + { "info", "", 0, 0, 0x10 }, +}; + #define MYCCLIBNAME ((char *)"stub") char *CClib_name() { return(MYCCLIBNAME); } From 10528424f92b912f35816b10ea30a743d0bb8648 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 22:48:46 -1100 Subject: [PATCH 124/144] CC_info * --- src/cc/CC made easy.md | 8 +-- src/cc/CCGateways.h | 2 +- src/cc/CCHeir.h | 4 +- src/cc/CCMarmara.h | 2 +- src/cc/CCOracles.h | 2 +- src/cc/CCPayments.h | 2 +- src/cc/CCPegs.h | 2 +- src/cc/CCPrices.h | 2 +- src/cc/CCassets.h | 12 ++-- src/cc/CCassetsCore.cpp | 18 +++--- src/cc/CCassetstx.cpp | 34 +++++------ src/cc/CCauction.h | 2 +- src/cc/CCchannels.h | 2 +- src/cc/CCcustom.cpp | 34 ++++++++++- src/cc/CCdice.h | 4 +- src/cc/CCfaucet.h | 2 +- src/cc/CCfsm.h | 2 +- src/cc/CCinclude.h | 34 ++++++----- src/cc/CClotto.h | 2 +- src/cc/CCrewards.h | 2 +- src/cc/CCtokens.cpp | 24 ++++---- src/cc/CCtokens.h | 8 +-- src/cc/CCtx.cpp | 4 +- src/cc/CCutils.cpp | 123 ++++++++++++++++++++++++++------------- src/cc/assets.cpp | 4 +- src/cc/auction.cpp | 14 ++--- src/cc/cclib.cpp | 91 ++++++++++++++++++----------- src/cc/channels.cpp | 22 +++---- src/cc/dice.cpp | 34 +++++------ src/cc/eval.cpp | 4 +- src/cc/eval.h | 4 +- src/cc/faucet.cpp | 14 ++--- src/cc/fsm.cpp | 12 ++-- src/cc/gateways.cpp | 36 ++++++------ src/cc/heir.cpp | 26 ++++----- src/cc/heir_validate.h | 12 ++-- src/cc/lotto.cpp | 20 +++---- src/cc/marmara.cpp | 26 ++++----- src/cc/oracles.cpp | 30 +++++----- src/cc/payments.cpp | 14 ++--- src/cc/pegs.cpp | 14 ++--- src/cc/prices.cpp | 14 ++--- src/cc/rewards.cpp | 24 ++++---- src/komodo_bitcoind.h | 2 +- src/rpc/server.cpp | 4 ++ src/rpc/server.h | 4 +- src/wallet/rpcwallet.cpp | 81 +++++++++++++++++++------- 47 files changed, 489 insertions(+), 348 deletions(-) diff --git a/src/cc/CC made easy.md b/src/cc/CC made easy.md index 453aa5467..f409efb2d 100644 --- a/src/cc/CC made easy.md +++ b/src/cc/CC made easy.md @@ -206,13 +206,13 @@ The idea is that people send funds to the faucet by locking it in faucet's globa There are only 7 functions in faucet.cpp, a bit over 200 lines including comments. The first three are for validation, the last four for the rpc calls to use. -int64_t IsFaucetvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsFaucetvout(struct CC_info *cp,const CTransaction& tx,int32_t v) -bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool FaucetExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) -bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) +bool FaucetValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx) -int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddFaucetInputs(struct CC_infoCC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) std::string FaucetGet(uint64_t txfee) diff --git a/src/cc/CCGateways.h b/src/cc/CCGateways.h index b629ade1f..0ffeced6e 100644 --- a/src/cc/CCGateways.h +++ b/src/cc/CCGateways.h @@ -20,7 +20,7 @@ #include "CCinclude.h" #include "../merkleblock.h" -bool GatewaysValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool GatewaysValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector pubkeys); std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std::string refcoin,uint256 cointxid,int32_t claimvout,std::string deposithex,std::vectorproof,CPubKey destpub,int64_t amount); std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,uint256 deposittxid,CPubKey destpub,int64_t amount); diff --git a/src/cc/CCHeir.h b/src/cc/CCHeir.h index ecaff9cdb..1e831e772 100644 --- a/src/cc/CCHeir.h +++ b/src/cc/CCHeir.h @@ -22,7 +22,7 @@ //#define EVAL_HEIR 0xea -bool HeirValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool HeirValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); class CoinHelper; class TokenHelper; @@ -36,6 +36,6 @@ UniValue HeirInfo(uint256 fundingtxid); UniValue HeirList(); //std::string Heir_MakeBadTx(uint256 fundingtxid, uint8_t funcId, int64_t amount, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTime, uint32_t errMask); -//bool HeirExactTokenAmounts(bool compareTotals, struct CCcontract_info *cpHeir, Eval* eval, uint256 assetid, const CTransaction &tx); +//bool HeirExactTokenAmounts(bool compareTotals, struct CC_info *cpHeir, Eval* eval, uint256 assetid, const CTransaction &tx); #endif diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 65269df77..567f43aa3 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -38,7 +38,7 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 approvaltxid,uint256 batontxid); UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency); -bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool MarmaraValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom UniValue MarmaraInfo(); diff --git a/src/cc/CCOracles.h b/src/cc/CCOracles.h index 7f952e5f5..a46d0c311 100644 --- a/src/cc/CCOracles.h +++ b/src/cc/CCOracles.h @@ -19,7 +19,7 @@ #include "CCinclude.h" -bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool OraclesValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string OracleCreate(int64_t txfee,std::string name,std::string description,std::string format); std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee); std::string OracleSubscribe(int64_t txfee,uint256 oracletxid,CPubKey publisher,int64_t amount); diff --git a/src/cc/CCPayments.h b/src/cc/CCPayments.h index 187d9c9ad..f229212fb 100644 --- a/src/cc/CCPayments.h +++ b/src/cc/CCPayments.h @@ -19,7 +19,7 @@ #include "CCinclude.h" -bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool PaymentsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom UniValue PaymentsInfo(); diff --git a/src/cc/CCPegs.h b/src/cc/CCPegs.h index 8d2a268f1..a7863a3ec 100644 --- a/src/cc/CCPegs.h +++ b/src/cc/CCPegs.h @@ -19,7 +19,7 @@ #include "CCinclude.h" -bool PegsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool PegsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom UniValue PegsInfo(); diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 1a68be7dd..fe625e31b 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -19,7 +19,7 @@ #include "CCinclude.h" -bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool PricesValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom UniValue PricesList(); diff --git a/src/cc/CCassets.h b/src/cc/CCassets.h index 69fcfacbb..061e0f899 100644 --- a/src/cc/CCassets.h +++ b/src/cc/CCassets.h @@ -26,7 +26,7 @@ #include "CCinclude.h" // CCcustom -bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool AssetsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCassetsCore //CTxOut MakeAssetsVout(CAmount nValue,CPubKey pk); @@ -35,20 +35,20 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx //bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); //uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCode, uint256 &assetid, uint256 &assetid2, int64_t &price, std::vector &origpubkey); bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CTransaction &tx); -int64_t IsAssetvout(struct CCcontract_info *cp, int64_t &price, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 refassetid); +int64_t IsAssetvout(struct CC_info *cp, int64_t &price, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 refassetid); bool ValidateBidRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); bool ValidateAskRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); bool ValidateSwapRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); bool SetBidFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); bool SetAskFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); bool SetSwapFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); -int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid); -int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid); -bool AssetCalcAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 assetid); +int64_t AssetValidateBuyvin(struct CC_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid); +int64_t AssetValidateSellvin(struct CC_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid); +bool AssetCalcAmounts(struct CC_info *cpAssets, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 assetid); // CCassetstx //int64_t GetAssetBalance(CPubKey pk,uint256 tokenid); // --> GetTokenBalance() -int64_t AddAssetInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 assetid, int64_t total, int32_t maxinputs); +int64_t AddAssetInputs(struct CC_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 assetid, int64_t total, int32_t maxinputs); UniValue AssetOrders(uint256 tokenid); //UniValue AssetInfo(uint256 tokenid); diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 1b8e46189..45d3421be 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -365,7 +365,7 @@ bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CT } // Calculate sell/buy owner's source token/asset address from ask/bid tx -bool GetAssetorigaddrs(struct CCcontract_info *cp, char *userCCaddr, char *destaddr, const CTransaction& tx) +bool GetAssetorigaddrs(struct CC_info *cp, char *userCCaddr, char *destaddr, const CTransaction& tx) { uint256 assetid,assetid2; int64_t price,nValue=0; int32_t n; uint8_t funcid; std::vector origpubkey; @@ -378,13 +378,13 @@ bool GetAssetorigaddrs(struct CCcontract_info *cp, char *userCCaddr, char *desta bool bGetCCaddr = false; if (funcid == 's' || funcid == 'S') { - struct CCcontract_info *cpTokens, tokensC; + struct CC_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); bGetCCaddr = GetCCaddress(cpTokens, userCCaddr, pubkey2pk(origpubkey)); //bGetCCaddr = GetTokensCCaddress(cp, CCaddr, pubkey2pk(origpubkey)); } else if (funcid == 'b' || funcid == 'B') { - struct CCcontract_info *cpTokens, tokensC; + struct CC_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); bGetCCaddr = GetCCaddress(cpTokens, userCCaddr, pubkey2pk(origpubkey)); } @@ -400,7 +400,7 @@ bool GetAssetorigaddrs(struct CCcontract_info *cp, char *userCCaddr, char *desta } -int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,char *origaddr,const CTransaction &tx,int32_t vini,CTransaction &vinTx) +int64_t AssetValidateCCvin(struct CC_info *cp,Eval* eval,char *CCaddr,char *origaddr,const CTransaction &tx,int32_t vini,CTransaction &vinTx) { uint256 hashBlock; uint256 assetid, assetid2; @@ -463,7 +463,7 @@ int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,ch return(vinTx.vout[0].nValue); } -int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid) +int64_t AssetValidateBuyvin(struct CC_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid) { CTransaction vinTx; int64_t nValue; uint256 assetid,assetid2; uint8_t funcid, evalCode; CCaddr[0] = origaddr[0] = 0; @@ -490,7 +490,7 @@ int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmppr return(nValue); } -int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid) +int64_t AssetValidateSellvin(struct CC_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid) { CTransaction vinTx; int64_t nValue,assetoshis; //fprintf(stderr,"AssetValidateSellvin\n"); @@ -558,7 +558,7 @@ bool ValidateAssetOpret(CTransaction tx, int32_t v, uint256 assetid, int64_t &pr // Checks if the vout is a really Asset CC vout // compareTotals == true, the func also validates the passed transaction itself: // it should be either sum(cc vins) == sum(cc vouts) or the transaction is the 'tokenbase' ('c') tx -int64_t IsAssetvout(struct CCcontract_info *cp, int64_t &price, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 refassetid) +int64_t IsAssetvout(struct CC_info *cp, int64_t &price, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 refassetid) { //std::cerr << "IsAssetvout() entered for txid=" << tx.GetHash().GetHex() << " v=" << v << " for assetid=" << refassetid.GetHex() << std::endl; @@ -587,14 +587,14 @@ int64_t IsAssetvout(struct CCcontract_info *cp, int64_t &price, std::vector tmporigpubkey; int64_t tmpprice; int32_t numvins = tx.vin.size(); int32_t numvouts = tx.vout.size(); inputs = outputs = 0; - struct CCcontract_info *cpTokens, C; + struct CC_info *cpTokens, C; cpTokens = CCinit(&C, EVAL_TOKENS); diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 968775d38..dff279acd 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -17,7 +17,7 @@ //#include "CCtokens.h" -int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs) +int64_t AddAssetInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs) { char coinaddr[64],destaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t j,vout,n = 0; std::vector > unspentOutputs; @@ -72,13 +72,13 @@ UniValue AssetOrders(uint256 refassetid) UniValue result(UniValue::VARR); std::vector > unspentOutputsTokens, unspentOutputsAssets; - struct CCcontract_info *cpTokens, tokensC; - struct CCcontract_info *cpAssets, assetsC; + struct CC_info *cpTokens, tokensC; + struct CC_info *cpAssets, assetsC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); cpAssets = CCinit(&assetsC, EVAL_ASSETS); - auto addOrders = [&](struct CCcontract_info *cp, std::vector >::const_iterator it) + auto addOrders = [&](struct CC_info *cp, std::vector >::const_iterator it) { uint256 txid, hashBlock, assetid, assetid2; int64_t price; @@ -189,7 +189,7 @@ UniValue AssetOrders(uint256 refassetid) /* std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std::string description) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; struct CCcontract_info *cp,C; + CPubKey mypk; struct CC_info *cp,C; if ( assetsupply < 0 ) { fprintf(stderr,"negative assetsupply %lld\n",(long long)assetsupply); @@ -217,7 +217,7 @@ UniValue AssetOrders(uint256 refassetid) /* std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; uint64_t mask; int64_t CCchange=0,inputs=0; struct CCcontract_info *cp,C; + CPubKey mypk; uint64_t mask; int64_t CCchange=0,inputs=0; struct CC_info *cp,C; if ( total < 0 ) { fprintf(stderr,"negative total %lld\n",(long long)total); @@ -259,7 +259,7 @@ UniValue AssetOrders(uint256 refassetid) /* std::string AssetConvert(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total,int32_t evalcode) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; int64_t CCchange=0,inputs=0; struct CCcontract_info *cp,C; + CPubKey mypk; int64_t CCchange=0,inputs=0; struct CC_info *cp,C; if ( total < 0 ) { fprintf(stderr,"negative total %lld\n",(long long)total); @@ -288,7 +288,7 @@ std::string CreateBuyOffer(int64_t txfee, int64_t bidamount, uint256 assetid, in { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CPubKey mypk; - struct CCcontract_info *cpAssets, C; + struct CC_info *cpAssets, C; uint256 hashBlock; CTransaction vintx; std::vector origpubkey; @@ -349,8 +349,8 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p uint64_t mask; int64_t inputs, CCchange; CScript opret; - struct CCcontract_info *cpAssets, assetsC; - struct CCcontract_info *cpTokens, tokensC; + struct CC_info *cpAssets, assetsC; + struct CC_info *cpTokens, tokensC; //std::cerr << "CreateSell() askamount=" << askamount << " pricetotal=" << pricetotal << std::endl; @@ -408,7 +408,7 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 assetid2,int64_t pricetotal) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; uint64_t mask; int64_t inputs,CCchange; CScript opret; struct CCcontract_info *cp,C; + CPubKey mypk; uint64_t mask; int64_t inputs,CCchange; CScript opret; struct CC_info *cp,C; ////////////////////////// NOT IMPLEMENTED YET///////////////////////////////// fprintf(stderr,"asset swaps disabled\n"); @@ -482,7 +482,7 @@ std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) uint256 hashBlock; int64_t bidamount; CPubKey mypk; - struct CCcontract_info *cpAssets, C; + struct CC_info *cpAssets, C; uint8_t dummyEvalCode; uint256 dummyAssetid, dummyAssetid2; int64_t dummyPrice; std::vector dummyOrigpubkey; @@ -526,7 +526,7 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) uint256 hashBlock; int64_t askamount; CPubKey mypk; - struct CCcontract_info *cpTokens, *cpAssets, tokensC, assetsC; + struct CC_info *cpTokens, *cpAssets, tokensC, assetsC; uint8_t dummyEvalCode; uint256 dummyAssetid, dummyAssetid2; int64_t dummyPrice; std::vector dummyOrigpubkey; @@ -592,8 +592,8 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f int32_t bidvout=0; uint64_t mask; int64_t origprice, bidamount, paid_amount, remaining_required, inputs, CCchange=0; - struct CCcontract_info *cpTokens, tokensC; - struct CCcontract_info *cpAssets, assetsC; + struct CC_info *cpTokens, tokensC; + struct CC_info *cpAssets, assetsC; if (fillamount < 0) { @@ -676,8 +676,8 @@ std::string FillSell(int64_t txfee, uint256 assetid, uint256 assetid2, uint256 a uint64_t mask = 0; int32_t askvout = 0; int64_t received_assetoshis, total_nValue, orig_assetoshis, paid_nValue, remaining_nValue, inputs, CCchange=0; - //struct CCcontract_info *cpTokens, tokensC; - struct CCcontract_info *cpAssets, assetsC; + //struct CC_info *cpTokens, tokensC; + struct CC_info *cpAssets, assetsC; if (fillunits < 0) { diff --git a/src/cc/CCauction.h b/src/cc/CCauction.h index cfcd615cc..13393d510 100644 --- a/src/cc/CCauction.h +++ b/src/cc/CCauction.h @@ -21,7 +21,7 @@ #define EVAL_AUCTION 0xe8 -bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool AuctionValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string AuctionPost(uint64_t txfee,uint256 itemhash,int64_t minbid,char *title,char *description); std::string AuctionBid(uint64_t txfee,uint256 itemhash,int64_t amount); diff --git a/src/cc/CCchannels.h b/src/cc/CCchannels.h index 10cb4d224..76e0ab8cf 100644 --- a/src/cc/CCchannels.h +++ b/src/cc/CCchannels.h @@ -20,7 +20,7 @@ #include "CCinclude.h" #define CHANNELS_MAXPAYMENTS 1000 -bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool ChannelsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment,uint256 tokenid); std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint256 secret); std::string ChannelClose(uint64_t txfee,uint256 opentxid); diff --git a/src/cc/CCcustom.cpp b/src/cc/CCcustom.cpp index 918ceb24a..c05210542 100644 --- a/src/cc/CCcustom.cpp +++ b/src/cc/CCcustom.cpp @@ -234,8 +234,36 @@ uint8_t TokensCCpriv[32] = { 0x1d, 0x0d, 0x0d, 0xce, 0x2d, 0xd2, 0xe1, 0x9d, 0xf #undef FUNCNAME #undef EVALCODE +#define FUNCNAME IsCClibInput +#define EVALCODE EVAL_FIRSTUSER +const char *CClibNormaladdr = "RVVeUg43rNcq3mZFnvZ8yqagyzqFgUnq4u"; +char CClibCChexstr[67] = { "032447d97655da079729dc024c61088ea415b22f4c15d4810ddaf2069ac6468d2f" }; +uint8_t CClibCCpriv[32] = { 0x57, 0xcf, 0x49, 0x71, 0x7d, 0xb4, 0x15, 0x1b, 0x4f, 0x98, 0xc5, 0x45, 0x8d, 0x26, 0x52, 0x4b, 0x7b, 0xe9, 0xbd, 0x55, 0xd8, 0x20, 0xd6, 0xc4, 0x82, 0x0f, 0xf5, 0xec, 0x6c, 0x1c, 0xa0, 0xc0 }; +#include "CCcustom.inc" +#undef FUNCNAME +#undef EVALCODE -struct CCcontract_info *CCinit(struct CCcontract_info *cp, uint8_t evalcode) +int32_t CClib_initcp(struct CC_info *cp,uint8_t evalcode) +{ + CPubKey pk; uint8_t pub33[33]; char CCaddr[64]; + if ( evalcode == EVAL_FIRSTUSER ) // eventually make a hashchain for each evalcode + { + cp->evalcode = evalcode; + cp->ismyvin = IsCClibInput; + strcpy(cp->CChexstr,CClibCChexstr); + memcpy(cp->CCpriv,CClibCCpriv,32); + decode_hex(pub33,33,cp->CChexstr); + pk = buf2pk(pub33); + Getscriptaddress(cp->normaladdr,CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG); + if ( strcmp(cp->normaladdr,CClibNormaladdr) != 0 ) + fprintf(stderr,"CClib_initcp addr mismatch %s vs %s\n",cp->normaladdr,CClibNormaladdr); + GetCCaddress(cp,cp->unspendableCCaddr,pk); + return(0); + } + return(-1); +} + +struct CC_info *CCinit(struct CC_info *cp, uint8_t evalcode) { cp->evalcode = evalcode; switch ( evalcode ) @@ -369,6 +397,10 @@ struct CCcontract_info *CCinit(struct CCcontract_info *cp, uint8_t evalcode) cp->validate = TokensValidate; cp->ismyvin = IsTokensInput; break; + default: + if ( CClib_initcp(cp,evalcode) < 0 ) + return(0); + break; } return(cp); } diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index 363aad735..0de222c50 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -21,7 +21,7 @@ #define EVAL_DICE 0xe6 -bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool DiceValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds); std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyvout,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout,uint256 vin0txid,int32_t vin0vout); @@ -30,6 +30,6 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); UniValue DiceInfo(uint256 diceid); UniValue DiceList(); -int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random); +int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CC_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random); #endif diff --git a/src/cc/CCfaucet.h b/src/cc/CCfaucet.h index 3cb6c66e5..4bb2ae0d7 100644 --- a/src/cc/CCfaucet.h +++ b/src/cc/CCfaucet.h @@ -22,7 +22,7 @@ #define EVAL_FAUCET 0xe4 #define FAUCETSIZE (COIN / 10) -bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool FaucetValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom std::string FaucetFund(uint64_t txfee,int64_t funds); diff --git a/src/cc/CCfsm.h b/src/cc/CCfsm.h index 2bce35597..0690e4dd2 100644 --- a/src/cc/CCfsm.h +++ b/src/cc/CCfsm.h @@ -21,7 +21,7 @@ #define EVAL_FSM 0xe7 -bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool FSMValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string FSMList(); std::string FSMInfo(uint256 fsmtxid); diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 680e4ca5c..0b537f3d3 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -88,7 +88,7 @@ struct CC_meta // followed by address destinations }; -struct CCcontract_info +struct CC_info { // this is for spending from 'unspendable' CC address uint8_t evalcode; @@ -111,12 +111,12 @@ struct CCcontract_info uint8_t unspendablepriv2[32], unspendablepriv3[32]; CPubKey unspendablepk2, unspendablepk3; - bool (*validate)(struct CCcontract_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn); // cc contract tx validation callback + bool (*validate)(struct CC_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn); // cc contract tx validation callback bool (*ismyvin)(CScript const& scriptSig); // checks if evalcode is present in the scriptSig param uint8_t didinit; }; -struct CCcontract_info *CCinit(struct CCcontract_info *cp,uint8_t evalcode); +struct CC_info *CCinit(struct CC_info *cp,uint8_t evalcode); struct oracleprice_info { @@ -134,6 +134,7 @@ CBlockIndex *komodo_getblockindex(uint256 hash); int32_t komodo_nextheight(); int32_t CCgetspenttxid(uint256 &spenttxid,int32_t &vini,int32_t &height,uint256 txid,int32_t vout); +void CCclearvars(struct CC_info *cp); static const uint256 zeroid; bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock); @@ -157,9 +158,9 @@ uint8_t DecodeOraclesCreateOpRet(const CScript &scriptPubKey,std::string &name,s uint256 OracleMerkle(int32_t height,uint256 reforacletxid,char *format,std::vectorpublishers); uint256 OraclesBatontxid(uint256 oracletxid,CPubKey pk); -//int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs); -int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); -int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, const CTransaction& tx, int32_t v, uint256 reftokenid); +//int64_t AddAssetInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs); +int64_t AddTokenCCInputs(struct CC_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); +int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CC_info *cp, Eval* eval, const CTransaction& tx, int32_t v, uint256 reftokenid); bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx); CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 assetid2, int64_t price, std::vector origpubkey); @@ -177,7 +178,7 @@ int32_t oracle_format(uint256 *hashp,int64_t *valp,char *str,uint8_t fmt,uint8_t // CCcustom -CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv); +CPubKey GetUnspendable(struct CC_info *cp,uint8_t *unspendablepriv); // CCutils CPubKey buf2pk(uint8_t *buf33); @@ -188,18 +189,19 @@ CTxOut MakeCC1of2vout(uint8_t evalcode,CAmount nValue,CPubKey pk,CPubKey pk2); CC *MakeCCcond1(uint8_t evalcode,CPubKey pk); CC *MakeCCcond1of2(uint8_t evalcode,CPubKey pk1,CPubKey pk2); CC* GetCryptoCondition(CScript const& scriptSig); -void CCaddr2set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); -void CCaddr3set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); -void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); +void CCaddr2set(struct CC_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); +void CCaddr3set(struct CC_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); +void CCaddr1of2set(struct CC_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); CTxOut MakeTokensCC1of2vout(uint8_t evalcode, CAmount nValue, CPubKey pk1, CPubKey pk2); CTxOut MakeTokensCC1vout(uint8_t evalcode, CAmount nValue, CPubKey pk); CC *MakeTokensCCcond1of2(uint8_t evalcode, CPubKey pk1, CPubKey pk2); CC *MakeTokensCCcond1(uint8_t evalcode, CPubKey pk); -bool GetTokensCCaddress(struct CCcontract_info *cp, char *destaddr, CPubKey pk); -bool GetTokensCCaddress1of2(struct CCcontract_info *cp, char *destaddr, CPubKey pk, CPubKey pk2); -void CCaddrTokens1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); +bool GetTokensCCaddress(struct CC_info *cp, char *destaddr, CPubKey pk); +bool GetTokensCCaddress1of2(struct CC_info *cp, char *destaddr, CPubKey pk, CPubKey pk2); +void CCaddrTokens1of2set(struct CC_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); +int32_t CClib_initcp(struct CC_info *cp,uint8_t evalcode); bool IsCCInput(CScript const& scriptSig); int32_t unstringbits(char *buf,uint64_t bits); @@ -214,8 +216,8 @@ int64_t CCfullsupply(uint256 tokenid); int64_t CCtoken_balance(char *destaddr,uint256 tokenid); int64_t CCtoken_balance2(char *destaddr,uint256 tokenid); bool _GetCCaddress(char *destaddr,uint8_t evalcode,CPubKey pk); -bool GetCCaddress(struct CCcontract_info *cp,char *destaddr,CPubKey pk); -bool GetCCaddress1of2(struct CCcontract_info *cp,char *destaddr,CPubKey pk,CPubKey pk2); +bool GetCCaddress(struct CC_info *cp,char *destaddr,CPubKey pk); +bool GetCCaddress1of2(struct CC_info *cp,char *destaddr,CPubKey pk,CPubKey pk2); bool ConstrainVout(CTxOut vout,int32_t CCflag,char *cmpaddr,int64_t nValue); bool PreventCC(Eval* eval,const CTransaction &tx,int32_t preventCCvins,int32_t numvins,int32_t preventCCvouts,int32_t numvouts); bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); @@ -227,7 +229,7 @@ CPubKey check_signing_pubkey(CScript scriptSig); // CCtx bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey); extern std::vector NULL_pubkeys; -std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys = NULL_pubkeys); +std::string FinalizeCCTx(uint64_t skipmask,struct CC_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys = NULL_pubkeys); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr); void SetCCtxids(std::vector > &addressIndex,char *coinaddr); int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs); diff --git a/src/cc/CClotto.h b/src/cc/CClotto.h index 2f0595371..4ef147cef 100644 --- a/src/cc/CClotto.h +++ b/src/cc/CClotto.h @@ -21,7 +21,7 @@ #define EVAL_LOTTO 0xe9 -bool LottoValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool LottoValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); UniValue LottoInfo(uint256 lottoid); UniValue LottoList(); diff --git a/src/cc/CCrewards.h b/src/cc/CCrewards.h index 4d6cc80f9..41977f915 100644 --- a/src/cc/CCrewards.h +++ b/src/cc/CCrewards.h @@ -22,7 +22,7 @@ #define EVAL_REWARDS 0xe5 #define REWARDSCC_MAXAPR (COIN * 25) -bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool RewardsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); UniValue RewardsInfo(uint256 rewardid); UniValue RewardsList(); diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 2961f6597..6620a9cd8 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -177,7 +177,7 @@ uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCode, uint256 // tx validation -bool TokensValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn) +bool TokensValidate(struct CC_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn) { static uint256 zero; CTxDestination address; CTransaction vinTx, createTx; uint256 hashBlock, tokenid, tokenid2; @@ -251,7 +251,7 @@ bool TokensValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction & // forward validation if evalcode in opret is not EVAL_TOKENS // init for forwarding validation call //if (evalCodeInOpret != EVAL_TOKENS) { // TODO: should we check also only allowed for tokens evalcodes, like EVAL_ASSETS, EVAL_GATEWAYS? - // struct CCcontract_info *cpOther = NULL, C; + // struct CC_info *cpOther = NULL, C; // cpOther = CCinit(&C, evalCodeInOpret); // if (cpOther) @@ -271,7 +271,7 @@ bool ExtractTokensVinPubkeys(CTransaction tx, std::vector &vinPubkeys) bool found = false; CPubKey pubkey; - struct CCcontract_info *cpTokens, tokensC; + struct CC_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); @@ -353,7 +353,7 @@ uint8_t ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, std::vec // goDeeper is true: the func also validates amounts of the passed transaction: // it should be either sum(cc vins) == sum(cc vouts) or the transaction is the 'tokenbase' ('c') tx // checkPubkeys is true: validates if the vout is token vout1 or token vout1of2. Should always be true! -int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, const CTransaction& tx, int32_t v, uint256 reftokenid) +int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CC_info *cp, Eval* eval, const CTransaction& tx, int32_t v, uint256 reftokenid) { // this is just for log messages indentation fur debugging recursive calls: @@ -488,13 +488,13 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c } // compares cc inputs vs cc outputs (to prevent feeding vouts from normal inputs) -bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cp, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid) +bool TokensExactAmounts(bool goDeeper, struct CC_info *cp, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid) { CTransaction vinTx; uint256 hashBlock; int64_t tokenoshis; - struct CCcontract_info *cpTokens, tokensC; + struct CC_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); int32_t numvins = tx.vin.size(); @@ -559,7 +559,7 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cp, int64_t &inpu } // add inputs from token cc addr -int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs) +int64_t AddTokenCCInputs(struct CC_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs) { char tokenaddr[64], destaddr[64]; int64_t threshold, nValue, price, totalinputs = 0; @@ -617,7 +617,7 @@ int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, C std::string CreateToken(int64_t txfee, int64_t assetsupply, std::string name, std::string description) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; struct CCcontract_info *cp, C; + CPubKey mypk; struct CC_info *cp, C; if (assetsupply < 0) { fprintf(stderr, "negative assetsupply %lld\n", (long long)assetsupply); @@ -647,7 +647,7 @@ std::string CreateToken(int64_t txfee, int64_t assetsupply, std::string name, st std::string TokenTransfer(int64_t txfee, uint256 assetid, std::vector destpubkey, int64_t total) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; uint64_t mask; int64_t CCchange = 0, inputs = 0; struct CCcontract_info *cp, C; + CPubKey mypk; uint64_t mask; int64_t CCchange = 0, inputs = 0; struct CC_info *cp, C; std::vector emptyExtraOpret; if (total < 0) @@ -714,7 +714,7 @@ int64_t GetTokenBalance(CPubKey pk, uint256 tokenid) return 0; } - struct CCcontract_info *cp, C; + struct CC_info *cp, C; cp = CCinit(&C, EVAL_TOKENS); return(AddTokenCCInputs(cp, mtx, pk, tokenid, 0, 0)); } @@ -748,7 +748,7 @@ UniValue TokenList() { UniValue result(UniValue::VARR); std::vector > addressIndex; - struct CCcontract_info *cp, C; uint256 txid, hashBlock; + struct CC_info *cp, C; uint256 txid, hashBlock; CTransaction vintx; std::vector origpubkey; std::string name, description; char str[65]; @@ -766,4 +766,4 @@ UniValue TokenList() } } return(result); -} \ No newline at end of file +} diff --git a/src/cc/CCtokens.h b/src/cc/CCtokens.h index e7bb62101..2eaffe31f 100644 --- a/src/cc/CCtokens.h +++ b/src/cc/CCtokens.h @@ -26,9 +26,9 @@ #include "CCinclude.h" // CCcustom -bool TokensValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); -bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid); -//int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys); +bool TokensValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool TokensExactAmounts(bool goDeeper, struct CC_info *cpTokens, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid); +//int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CC_info *cp, Eval* eval, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys); std::string CreateToken(int64_t txfee, int64_t assetsupply, std::string name, std::string description); std::string TokenTransfer(int64_t txfee, uint256 assetid, std::vector destpubkey, int64_t total); @@ -36,7 +36,7 @@ int64_t GetTokenBalance(CPubKey pk, uint256 tokenid); UniValue TokenInfo(uint256 tokenid); UniValue TokenList(); -//this is in CCinclude.h int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); +//this is in CCinclude.h int64_t AddTokenCCInputs(struct CC_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); //this is in CCinclude.h uint8_t DecodeTokenCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index ae7483f4d..307ac214f 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -40,7 +40,7 @@ bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScrip return(false); } -std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys) +std::string FinalizeCCTx(uint64_t CCmask,struct CC_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys) { auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); CTransaction vintx; std::string hex; CPubKey globalpk; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0; @@ -50,7 +50,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran uint8_t *privkey, myprivkey[32], unspendablepriv[32], tokensunspendablepriv[32], *msg32 = 0; CC *mycond=0, *othercond=0, *othercond2=0,*othercond4=0, *othercond3=0, *othercond1of2=NULL, *othercond1of2tokens = NULL, *cond, *mytokenscond = NULL, *mysingletokenscond = NULL, *othertokenscond = NULL; CPubKey unspendablepk /*, tokensunspendablepk*/; - struct CCcontract_info *cpTokens, tokensC; + struct CC_info *cpTokens, tokensC; globalpk = GetUnspendable(cp,0); n = mtx.vout.size(); for (i=0; i pubkey) return(pk); } -void CCaddr2set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr) +void CCaddr2set(struct CC_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr) { cp->evalcode2 = evalcode; cp->unspendablepk2 = pk; @@ -235,7 +235,7 @@ void CCaddr2set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t * strcpy(cp->unspendableaddr2,coinaddr); } -void CCaddr3set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr) +void CCaddr3set(struct CC_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr) { cp->evalcode3 = evalcode; cp->unspendablepk3 = pk; @@ -244,7 +244,7 @@ void CCaddr3set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t * } // set pubkeys, myprivkey and 1of2 cc addr for spending from 1of2 cryptocondition vout: -void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) +void CCaddr1of2set(struct CC_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) { cp->coins1of2pk[0] = pk1; cp->coins1of2pk[1] = pk2; @@ -252,7 +252,7 @@ void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *c } // set pubkeys, myprivkey and 1of2 cc addr for spending from 1of2 tokens cryptocondition vout: -void CCaddrTokens1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) +void CCaddrTokens1of2set(struct CC_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) { cp->tokens1of2pk[0] = pk1; cp->tokens1of2pk[1] = pk2; @@ -343,7 +343,7 @@ bool _GetCCaddress(char *destaddr,uint8_t evalcode,CPubKey pk) return(destaddr[0] != 0); } -bool GetCCaddress(struct CCcontract_info *cp,char *destaddr,CPubKey pk) +bool GetCCaddress(struct CC_info *cp,char *destaddr,CPubKey pk) { destaddr[0] = 0; if ( pk.size() == 0 ) @@ -363,7 +363,7 @@ bool _GetTokensCCaddress(char *destaddr, uint8_t evalcode, CPubKey pk) return(destaddr[0] != 0); } -bool GetTokensCCaddress(struct CCcontract_info *cp, char *destaddr, CPubKey pk) +bool GetTokensCCaddress(struct CC_info *cp, char *destaddr, CPubKey pk) { destaddr[0] = 0; if (pk.size() == 0) @@ -372,7 +372,7 @@ bool GetTokensCCaddress(struct CCcontract_info *cp, char *destaddr, CPubKey pk) } -bool GetCCaddress1of2(struct CCcontract_info *cp,char *destaddr,CPubKey pk,CPubKey pk2) +bool GetCCaddress1of2(struct CC_info *cp,char *destaddr,CPubKey pk,CPubKey pk2) { CC *payoutCond; destaddr[0] = 0; @@ -384,7 +384,7 @@ bool GetCCaddress1of2(struct CCcontract_info *cp,char *destaddr,CPubKey pk,CPubK return(destaddr[0] != 0); } -bool GetTokensCCaddress1of2(struct CCcontract_info *cp, char *destaddr, CPubKey pk, CPubKey pk2) +bool GetTokensCCaddress1of2(struct CC_info *cp, char *destaddr, CPubKey pk, CPubKey pk2) { CC *payoutCond; destaddr[0] = 0; @@ -471,7 +471,7 @@ bool Myprivkey(uint8_t myprivkey[]) if ( pwalletMain->GetKey(keyID,vchSecret) != 0 ) { memcpy(myprivkey,vchSecret.begin(),32); - if ( 1 ) + if ( 0 ) { for (i=0; i<32; i++) fprintf(stderr,"0x%02x, ",myprivkey[i]); @@ -486,46 +486,17 @@ bool Myprivkey(uint8_t myprivkey[]) return(false); } -CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv) +CPubKey GetUnspendable(struct CC_info *cp,uint8_t *unspendablepriv) { if ( unspendablepriv != 0 ) memcpy(unspendablepriv,cp->CCpriv,32); return(pubkey2pk(ParseHex(cp->CChexstr))); } -bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector paramsNull,const CTransaction &ctx, unsigned int nIn) +void CCclearvars(struct CC_info *cp) { - CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t height,i,n,from_mempool = 0; int64_t amount; std::vector origpubkey; - height = KOMODO_CONNECTING; - if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation - return(true); - if ( ASSETCHAINS_CC == 0 || (height & ~(1<<30)) < KOMODO_CCACTIVATE ) - return eval->Invalid("CC are disabled or not active yet"); - if ( (KOMODO_CONNECTING & (1<<30)) != 0 ) - { - from_mempool = 1; - height &= ((1<<30) - 1); - } - //fprintf(stderr,"KOMODO_CONNECTING.%d mempool.%d vs CCactive.%d\n",height,from_mempool,KOMODO_CCACTIVATE); - // there is a chance CC tx is valid in mempool, but invalid when in block, so we cant filter duplicate requests. if any of the vins are spent, for example - //txid = ctx.GetHash(); - //if ( txid == cp->prevtxid ) - // return(true); - //fprintf(stderr,"process CC %02x\n",cp->evalcode); cp->evalcode2 = cp->evalcode3 = 0; cp->unspendableaddr2[0] = cp->unspendableaddr3[0] = 0; - if ( paramsNull.size() != 0 ) // Don't expect params - return eval->Invalid("Cannot have params"); - //else if ( ctx.vout.size() == 0 ) // spend can go to z-addresses - // return eval->Invalid("no-vouts"); - else if ( (*cp->validate)(cp,eval,ctx,nIn) != 0 ) - { - //fprintf(stderr,"done CC %02x\n",cp->evalcode); - //cp->prevtxid = txid; - return(true); - } - //fprintf(stderr,"invalid CC %02x\n",cp->evalcode); - return(false); } int64_t CCduration(int32_t &numblocks,uint256 txid) @@ -630,3 +601,75 @@ CPubKey check_signing_pubkey(CScript scriptSig) } return CPubKey(); } + +bool ProcessCC(struct CC_info *cp,Eval* eval, std::vector paramsNull,const CTransaction &ctx, unsigned int nIn) +{ + CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t height,i,n,from_mempool = 0; int64_t amount; std::vector origpubkey; + height = KOMODO_CONNECTING; + if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation + return(true); + if ( ASSETCHAINS_CC == 0 || (height & ~(1<<30)) < KOMODO_CCACTIVATE ) + return eval->Invalid("CC are disabled or not active yet"); + if ( (KOMODO_CONNECTING & (1<<30)) != 0 ) + { + from_mempool = 1; + height &= ((1<<30) - 1); + } + //fprintf(stderr,"KOMODO_CONNECTING.%d mempool.%d vs CCactive.%d\n",height,from_mempool,KOMODO_CCACTIVATE); + // there is a chance CC tx is valid in mempool, but invalid when in block, so we cant filter duplicate requests. if any of the vins are spent, for example + //txid = ctx.GetHash(); + //if ( txid == cp->prevtxid ) + // return(true); + //fprintf(stderr,"process CC %02x\n",cp->evalcode); + CCclearvars(cp); + if ( paramsNull.size() != 0 ) // Don't expect params + return eval->Invalid("Cannot have params"); + //else if ( ctx.vout.size() == 0 ) // spend can go to z-addresses + // return eval->Invalid("no-vouts"); + else if ( (*cp->validate)(cp,eval,ctx,nIn) != 0 ) + { + //fprintf(stderr,"done CC %02x\n",cp->evalcode); + //cp->prevtxid = txid; + return(true); + } + //fprintf(stderr,"invalid CC %02x\n",cp->evalcode); + return(false); +} + +bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) +{ + uint8_t evalcode; int32_t height,from_mempool; struct CCinfo *cp; + if ( ASSETCHAINS_CCLIB != MYCCLIBNAME ) + { + fprintf(stderr,"-ac_cclib=%s vs myname %s\n",ASSETCHAINS_CCLIB.c_str(),MYCCLIBNAME); + return eval->Invalid("-ac_cclib name mismatches myname"); + } + height = KOMODO_CONNECTING; + if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation + return(true); + if ( ASSETCHAINS_CC == 0 || (height & ~(1<<30)) < KOMODO_CCACTIVATE ) + return eval->Invalid("CC are disabled or not active yet"); + if ( (KOMODO_CONNECTING & (1<<30)) != 0 ) + { + from_mempool = 1; + height &= ((1<<30) - 1); + } + evalcode = cond->code[0]; + if ( evalcode >= EVAL_FIRSTUSER && evalcode <= EVAL_LASTUSER ) + { + cp = &CCinfos[(int32_t)ecode]; + if ( cp->didinit == 0 ) + { + if ( CClib_initcp(cp,ecode) == 0 ) + cp->didinit = 1; + else return eval->Invalid("unsupported CClib evalcode"); + } + CCclearvars(cp); + if ( paramsNull.size() != 0 ) // Don't expect params + return eval->Invalid("Cannot have params"); + else if ( CClib_validate(cp,eval,ctx,nIn) != 0 ) + return(true); + return eval->Invalid("error in CClib_validate"); + } + return eval->Invalid("cclib CC must have evalcode between 16 and 127"); +} diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index 3ccafa34f..7747fb61c 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -126,7 +126,7 @@ // tx validation -bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool AssetsValidate(struct CC_info *cpAssets,Eval* eval,const CTransaction &tx, uint32_t nIn) { static uint256 zero; CTxDestination address; CTransaction vinTx,createTx; uint256 hashBlock,assetid,assetid2; @@ -157,7 +157,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti GetTokensCCaddress(cpAssets, tokensUnspendableAddr, GetUnspendable(cpAssets, NULL)); // we need this for validating single-eval tokens' vins/vous: - struct CCcontract_info *cpTokens, tokensC; + struct CC_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); // find single-eval token user cc addr: diff --git a/src/cc/auction.cpp b/src/cc/auction.cpp index 0858facfa..b3fe4aa86 100644 --- a/src/cc/auction.cpp +++ b/src/cc/auction.cpp @@ -21,7 +21,7 @@ // start of consensus code -int64_t IsAuctionvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsAuctionvout(struct CC_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -32,7 +32,7 @@ int64_t IsAuctionvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t return(0); } -bool AuctionExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool AuctionExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -70,7 +70,7 @@ bool AuctionExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransactio else return(true); } -bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool AuctionValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; return eval->Invalid("no validation yet"); @@ -118,7 +118,7 @@ bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t // helper functions for rpc calls in rpcwallet.cpp -int64_t AddAuctionInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddAuctionInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; @@ -151,7 +151,7 @@ int64_t AddAuctionInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPu std::string AuctionBid(uint64_t txfee,uint256 itemhash,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Auctionpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + CPubKey mypk,Auctionpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CC_info *cp,C; cp = CCinit(&C,EVAL_AUCTION); if ( txfee == 0 ) txfee = 10000; @@ -172,7 +172,7 @@ std::string AuctionBid(uint64_t txfee,uint256 itemhash,int64_t amount) std::string AuctionDeliver(uint64_t txfee,uint256 itemhash,uint256 bidtxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Auctionpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + CPubKey mypk,Auctionpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CC_info *cp,C; cp = CCinit(&C,EVAL_AUCTION); if ( txfee == 0 ) txfee = 10000; @@ -193,7 +193,7 @@ std::string AuctionDeliver(uint64_t txfee,uint256 itemhash,uint256 bidtxid) std::string AuctionPost(uint64_t txfee,uint256 itemhash,int64_t minbid,char *title,char *description) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Auctionpk; int64_t funds = 0; CScript opret; struct CCcontract_info *cp,C; + CPubKey mypk,Auctionpk; int64_t funds = 0; CScript opret; struct CC_info *cp,C; cp = CCinit(&C,EVAL_AUCTION); if ( txfee == 0 ) txfee = 10000; diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index ed57b2194..c93d204df 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -27,54 +27,75 @@ #include "core_io.h" #include "crosschain.h" -#define FUNCNAME IsCClibInput -#define EVALCODE EVAL_FIRSTUSER -const char *CClibCCaddr = "RGLSRDnUqTB43bYtRtNVgmwSSd1sun2te8"; -const char *CClibNormaladdr = "RVVeUg43rNcq3mZFnvZ8yqagyzqFgUnq4u"; -char CClibCChexstr[67] = { "032447d97655da079729dc024c61088ea415b22f4c15d4810ddaf2069ac6468d2f" }; -uint8_t CClibCCpriv[32] = { 0x7c, 0x0b, 0x54, 0x9b, 0x65, 0xd4, 0x89, 0x57, 0xdf, 0x05, 0xfe, 0xa2, 0x62, 0x41, 0xa9, 0x09, 0x0f, 0x2a, 0x6b, 0x11, 0x2c, 0xbe, 0xbd, 0x06, 0x31, 0x8d, 0xc0, 0xb9, 0x96, 0x76, 0x3f, 0x24 }; -#include "CCcustom.inc" -#undef FUNCNAME -#undef EVALCODE - - struct CClib_rpcinfo { char *method,*help; int32_t numrequiredargs,maxargs; // frontloaded with required - uint8_t evalcode; + uint8_t funcid; } -CClib_rpcs[] = +CClib_methods[] = { - { "info", "", 0, 0, 0x10 }, + { "faucet2_get", "", 0, 0, 'G' }, }; #define MYCCLIBNAME ((char *)"stub") char *CClib_name() { return(MYCCLIBNAME); } -bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) +std::string CClib_rawtxgen(struct CC_info *cp,uint8_t funcid,cJSON *params); + +UniValue CClib_info(struct CC_info *cp) { - uint8_t evalcode; int32_t height,from_mempool; - if ( ASSETCHAINS_CCLIB != MYCCLIBNAME ) + UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i; char str[2]; + result.push_back(Pair("result","success")); + result.push_back(Pair("CClib",CClib_name())); + for (i=0; iInvalid("-ac_cclib name mismatches myname"); + UniValue obj(UniValue::VOBJ); + if ( CClib_methods[i].funcid < ' ' || CClib_methods[i].funcid >= 128 ) + obj.push_back(Pair("funcid",CClib_methods[i].funcid)); + else + { + str[0] = CClib_methods[i].funcid; + str[1] = 0; + obj.push_back(Pair("funcid",str)); + } + obj.push_back(Pair("name",CClib_methods[i].method)); + obj.push_back(Pair("help",CClib_methods[i].help)); + obj.push_back(Pair("params_required",CClib_methods[i].numrequiredargs)); + obj.push_back(Pair("params_max",CClib_methods[i].maxargs)); + a.push_back(obj)); } - height = KOMODO_CONNECTING; - if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation - return(true); - if ( ASSETCHAINS_CC == 0 || (height & ~(1<<30)) < KOMODO_CCACTIVATE ) - return eval->Invalid("CC are disabled or not active yet"); - if ( (KOMODO_CONNECTING & (1<<30)) != 0 ) - { - from_mempool = 1; - height &= ((1<<30) - 1); - } - evalcode = cond->code[0]; - if ( evalcode >= EVAL_FIRSTUSER && evalcode <= EVAL_LASTUSER ) - { - return(true); - } - return eval->Invalid("cclib CC must have evalcode between 16 and 127"); + result.push_back(Pair("methods",a)); + return(result); +} + +UniValue CClib(struct CC_info *cp,char *method,cJSON *params) +{ + UniValue result(UniValue::VOBJ); int32_t i; std::string rawtx; + for (i=0; i > unspentOutputs; @@ -465,7 +465,7 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); uint8_t hash[32],hashdest[32]; uint64_t amount,tokens=0,funds; int32_t i; uint256 hashchain,entropy,hentropy; - CPubKey mypk; struct CCcontract_info *cp,*cpTokens,C,CTokens; + CPubKey mypk; struct CC_info *cp,*cpTokens,C,CTokens; if ( numpayments <= 0 || payment <= 0 || numpayments > CHANNELS_MAXPAYMENTS ) { @@ -509,7 +509,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CPubKey mypk,srcpub,destpub; uint256 txid,hashchain,gensecret,hashblock,entropy,hentropy,prevtxid,param3,tokenid; - struct CCcontract_info *cp,C; int32_t i,funcid,prevdepth,numvouts,numpayments,totalnumpayments; + struct CC_info *cp,C; int32_t i,funcid,prevdepth,numvouts,numpayments,totalnumpayments; int64_t payment,change,funds,param2; uint8_t hash[32],hashdest[32]; CTransaction channelOpenTx,prevTx; @@ -616,7 +616,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 std::string ChannelClose(uint64_t txfee,uint256 opentxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,srcpub,destpub; struct CCcontract_info *cp,C; + CPubKey mypk,srcpub,destpub; struct CC_info *cp,C; CTransaction channelOpenTx; uint256 hashblock,tmp_txid,prevtxid,hashchain,tokenid; int32_t numvouts,numpayments; @@ -665,7 +665,7 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; struct CCcontract_info *cp,C; int64_t funds,payment,param2; + CPubKey mypk; struct CC_info *cp,C; int64_t funds,payment,param2; int32_t i,numpayments,numvouts,param1; uint256 hashchain,hashblock,txid,prevtxid,param3,tokenid; CTransaction channelOpenTx,channelCloseTx,prevTx; @@ -735,7 +735,7 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) } UniValue ChannelsList() { - UniValue result(UniValue::VOBJ); std::vector > txids; struct CCcontract_info *cp,C; uint256 txid,hashBlock,tmp_txid,param3,tokenid; + UniValue result(UniValue::VOBJ); std::vector > txids; struct CC_info *cp,C; uint256 txid,hashBlock,tmp_txid,param3,tokenid; CTransaction tx; char myCCaddr[65],addr[65],str[256]; CPubKey mypk,srcpub,destpub; int32_t vout,numvouts,param1; int64_t nValue,param2; @@ -766,7 +766,7 @@ UniValue ChannelsList() UniValue ChannelsInfo(uint256 channeltxid) { UniValue result(UniValue::VOBJ),array(UniValue::VARR); CTransaction tx,opentx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain,prevtxid,tokenid; - struct CCcontract_info *cp,C; char CCaddr[65],addr[65],str[512]; int32_t vout,numvouts,param1,numpayments; + struct CC_info *cp,C; char CCaddr[65],addr[65],str[512]; int32_t vout,numvouts,param1,numpayments; int64_t param2,payment; CPubKey srcpub,destpub,mypk; std::vector > addressIndex; std::vector txids; diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 05dad9bf6..7a10913e7 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -322,7 +322,7 @@ void dicefinish_delete(struct dicefinish_info *ptr) void *dicefinish(void *_ptr) { - std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,entropyvout,numblocks,lastheight=0,vin0_needed,i,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; uint32_t now; struct dicefinish_utxo *utxos; uint256 hashBlock,entropyused; CPubKey dicepk; CTransaction betTx,finishTx,tx; + std::vector mypk; struct CC_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,entropyvout,numblocks,lastheight=0,vin0_needed,i,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; uint32_t now; struct dicefinish_utxo *utxos; uint256 hashBlock,entropyused; CPubKey dicepk; CTransaction betTx,finishTx,tx; mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); @@ -735,7 +735,7 @@ uint256 DiceGetEntropy(CTransaction tx,uint8_t reffuncid) else return(zeroid); } -uint64_t IsDicevout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) +uint64_t IsDicevout(struct CC_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) { char destaddr[64]; uint8_t funcid; int32_t numvouts; uint64_t sbits; uint256 fundingtxid,hash,proof; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -749,7 +749,7 @@ uint64_t IsDicevout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v, return(0); } -int64_t DiceAmounts(uint64_t &inputs,uint64_t &outputs,struct CCcontract_info *cp,Eval *eval,const CTransaction &tx,uint64_t refsbits,uint256 reffundingtxid) +int64_t DiceAmounts(uint64_t &inputs,uint64_t &outputs,struct CC_info *cp,Eval *eval,const CTransaction &tx,uint64_t refsbits,uint256 reffundingtxid) { CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; uint64_t assetoshis; numvins = tx.vin.size(); @@ -834,7 +834,7 @@ bool DiceVerifyTimeout(CTransaction &betTx,int32_t timeoutblocks) return(numblocks >= timeoutblocks); } -bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx, uint32_t nIn) +bool DiceValidate(struct CC_info *cp,Eval *eval,const CTransaction &tx, uint32_t nIn) { uint256 txid,fundingtxid,vinfundingtxid,vinhentropy,vinproof,hashBlock,hash,proof,entropy; int64_t minbet,maxbet,maxodds,timeoutblocks,odds,winnings; uint64_t vinsbits,refsbits=0,sbits,amount,inputs,outputs,txfee=10000; int32_t numvins,entropyvout,numvouts,preventCCvins,preventCCvouts,i,iswin; uint8_t funcid; CScript fundingPubKey; CTransaction fundingTx,vinTx,vinofvinTx; char CCaddr[64]; numvins = tx.vin.size(); @@ -1046,7 +1046,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx, return(true); } -uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) +uint64_t AddDiceInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) { char coinaddr[64],str[65]; uint64_t threshold,sbits,nValue,totalinputs = 0; uint256 txid,hash,proof,hashBlock,fundingtxid; CTransaction tx; int32_t j,vout,n = 0; uint8_t funcid; std::vector > unspentOutputs; @@ -1095,7 +1095,7 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK return(totalinputs); } -int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random) +int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CC_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random) { char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,sum,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0,i=0,pendingbets=0; uint8_t funcid; std::vector > unspentOutputs; @@ -1215,7 +1215,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } } -bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontract_info *cp,uint64_t refsbits,CPubKey dicepk,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) +bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CC_info *cp,uint64_t refsbits,CPubKey dicepk,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) { char CCaddr[64]; uint64_t sbits=0; uint256 txid,hashBlock; CTransaction tx; std::vector > txids; @@ -1256,9 +1256,9 @@ bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontrac return(false); } -struct CCcontract_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid,struct CCcontract_info *C,char *planstr,uint64_t &txfee,CPubKey &mypk,CPubKey &dicepk,uint64_t &sbits,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) +struct CC_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid,struct CC_info *C,char *planstr,uint64_t &txfee,CPubKey &mypk,CPubKey &dicepk,uint64_t &sbits,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) { - struct CCcontract_info *cp; int32_t cmpflag; + struct CC_info *cp; int32_t cmpflag; cp = CCinit(C,EVAL_DICE); if ( txfee == 0 ) txfee = 10000; @@ -1278,7 +1278,7 @@ struct CCcontract_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid,s UniValue DiceInfo(uint256 diceid) { - UniValue result(UniValue::VOBJ); CPubKey dicepk; uint256 hashBlock,entropytxid; CTransaction vintx; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits,funding,entropyval; char str[67],numstr[65]; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ); CPubKey dicepk; uint256 hashBlock,entropytxid; CTransaction vintx; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits,funding,entropyval; char str[67],numstr[65]; struct CC_info *cp,C; if ( myGetTransaction(diceid,vintx,hashBlock) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); @@ -1314,7 +1314,7 @@ UniValue DiceInfo(uint256 diceid) UniValue DiceList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock; CTransaction vintx; uint64_t sbits; int64_t minbet,maxbet,maxodds,timeoutblocks; char str[65]; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint256 txid,hashBlock; CTransaction vintx; uint64_t sbits; int64_t minbet,maxbet,maxodds,timeoutblocks; char str[65]; cp = CCinit(&C,EVAL_DICE); SetCCtxids(addressIndex,cp->normaladdr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) @@ -1334,7 +1334,7 @@ UniValue DiceList() std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - uint256 zero; CScript fundingPubKey; CPubKey mypk,dicepk; int64_t a,b,c,d; uint64_t sbits; struct CCcontract_info *cp,C; + uint256 zero; CScript fundingPubKey; CPubKey mypk,dicepk; int64_t a,b,c,d; uint64_t sbits; struct CC_info *cp,C; if ( funds < 0 || minbet < 0 || maxbet < 0 || maxodds < 1 || maxodds > 9999 || timeoutblocks < 0 || timeoutblocks > 1440 ) { CCerror = "invalid parameter error"; @@ -1369,7 +1369,7 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CScript fundingPubKey,scriptPubKey; uint256 entropy,hentropy; CPubKey mypk,dicepk; uint64_t sbits; struct CCcontract_info *cp,C; int64_t minbet,maxbet,maxodds,timeoutblocks; + CScript fundingPubKey,scriptPubKey; uint256 entropy,hentropy; CPubKey mypk,dicepk; uint64_t sbits; struct CC_info *cp,C; int64_t minbet,maxbet,maxodds,timeoutblocks; if ( amount < 0 ) { CCerror = "amount must be positive"; @@ -1413,7 +1413,7 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval,entropyval2; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropytxid2,entropy,hentropy; struct CCcontract_info *cp,C; + CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval,entropyval2; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropytxid2,entropy,hentropy; struct CC_info *cp,C; if ( bet < 0 ) { CCerror = "bet must be positive"; @@ -1472,7 +1472,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyvout,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout,uint256 vin0txid,int32_t vin0vout) { CMutableTransaction savemtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbettxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t oldentropyvout,retval=0,iswin=0; uint64_t entropyval,sbits; + CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbettxid; CPubKey mypk,dicepk,fundingpk; struct CC_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t oldentropyvout,retval=0,iswin=0; uint64_t entropyval,sbits; entropyused = zeroid; *resultp = 0; funcid = 0; @@ -1653,7 +1653,7 @@ static uint256 dealer0_fundingtxid; void *dealer0_loop(void *_arg) { char *planstr = (char *)_arg; - CTransaction tx,*entropytxs,entropytx; CPubKey mypk,dicepk; uint64_t entropyval; uint256 hashBlock,entropytxid,txid; int32_t height,lastht,numentropytxs,i,n,m,num; CScript fundingPubKey; struct CCcontract_info *cp,C; char coinaddr[64]; std::string res; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t refsbits,txfee = 10000; + CTransaction tx,*entropytxs,entropytx; CPubKey mypk,dicepk; uint64_t entropyval; uint256 hashBlock,entropytxid,txid; int32_t height,lastht,numentropytxs,i,n,m,num; CScript fundingPubKey; struct CC_info *cp,C; char coinaddr[64]; std::string res; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t refsbits,txfee = 10000; if ( (cp= Diceinit(fundingPubKey,dealer0_fundingtxid,&C,planstr,txfee,mypk,dicepk,refsbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { fprintf(stderr,"error initializing dealer0_loop\n"); @@ -1749,7 +1749,7 @@ void *dealer0_loop(void *_arg) double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid) { static int32_t didinit; static char _planstr[64]; - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,entropyvout,flag,win,num,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits,refsbits; char coinaddr[64]; std::string res; uint8_t funcid; + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CC_info *cp,C; int32_t i,entropyvout,flag,win,num,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits,refsbits; char coinaddr[64]; std::string res; uint8_t funcid; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,refsbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { CCerror = "Diceinit error in status, is your transaction confirmed?"; diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index ca2703bff..5239b0d5b 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -31,7 +31,7 @@ bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,co char *CClib_name(); Eval* EVAL_TEST = 0; -struct CCcontract_info CCinfos[0x100]; +struct CC_info CCinfos[0x100]; extern pthread_mutex_t KOMODO_CC_mutex; bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn) @@ -62,7 +62,7 @@ bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn) */ bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn) { - struct CCcontract_info *cp; + struct CC_info *cp; if (cond->codeLength == 0) return Invalid("empty-eval"); diff --git a/src/cc/eval.h b/src/cc/eval.h index a42bbdb2f..61fdb892d 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -286,8 +286,8 @@ typedef std::pair TxProof; uint256 GetMerkleRoot(const std::vector& vLeaves); -struct CCcontract_info *CCinit(struct CCcontract_info *cp,uint8_t evalcode); -bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector paramsNull, const CTransaction &tx, unsigned int nIn); +struct CC_info *CCinit(struct CC_info *cp,uint8_t evalcode); +bool ProcessCC(struct CC_info *cp,Eval* eval, std::vector paramsNull, const CTransaction &tx, unsigned int nIn); #endif /* CC_EVAL_H */ diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 6e59b6c1a..be3ff8a2c 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -28,7 +28,7 @@ // start of consensus code -int64_t IsFaucetvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsFaucetvout(struct CC_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -39,7 +39,7 @@ int64_t IsFaucetvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v return(0); } -bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool FaucetExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -77,7 +77,7 @@ bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction else return(true); } -bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool FaucetValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; std::vector > txids; @@ -140,7 +140,7 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx // helper functions for rpc calls in rpcwallet.cpp -int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddFaucetInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { char coinaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; @@ -175,7 +175,7 @@ int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub std::string FaucetGet(uint64_t txfee) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,faucetpk; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; + CPubKey mypk,faucetpk; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CC_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; cp = CCinit(&C,EVAL_FAUCET); if ( txfee == 0 ) txfee = 10000; @@ -216,7 +216,7 @@ std::string FaucetGet(uint64_t txfee) std::string FaucetFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,faucetpk; CScript opret; struct CCcontract_info *cp,C; + CPubKey mypk,faucetpk; CScript opret; struct CC_info *cp,C; cp = CCinit(&C,EVAL_FAUCET); if ( txfee == 0 ) txfee = 10000; @@ -234,7 +234,7 @@ UniValue FaucetInfo() { UniValue result(UniValue::VOBJ); char numstr[64]; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey faucetpk; struct CCcontract_info *cp,C; int64_t funding; + CPubKey faucetpk; struct CC_info *cp,C; int64_t funding; result.push_back(Pair("result","success")); result.push_back(Pair("name","Faucet")); cp = CCinit(&C,EVAL_FAUCET); diff --git a/src/cc/fsm.cpp b/src/cc/fsm.cpp index 0bcc61a1b..573299665 100644 --- a/src/cc/fsm.cpp +++ b/src/cc/fsm.cpp @@ -23,7 +23,7 @@ // start of consensus code -int64_t IsFSMvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsFSMvout(struct CC_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -34,7 +34,7 @@ int64_t IsFSMvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool FSMExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool FSMExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -72,7 +72,7 @@ bool FSMExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &t else return(true); } -bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool FSMValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; return eval->Invalid("no validation yet"); @@ -120,7 +120,7 @@ bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, u // helper functions for rpc calls in rpcwallet.cpp -int64_t AddFSMInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddFSMInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; @@ -158,7 +158,7 @@ std::string FSMList() std::string FSMCreate(uint64_t txfee,std::string name,std::string states) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,fsmpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + CPubKey mypk,fsmpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CC_info *cp,C; cp = CCinit(&C,EVAL_FSM); if ( txfee == 0 ) txfee = 10000; @@ -179,7 +179,7 @@ std::string FSMCreate(uint64_t txfee,std::string name,std::string states) std::string FSMInfo(uint256 fsmtxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,fsmpk; int64_t funds = 0; CScript opret; struct CCcontract_info *cp,C; + CPubKey mypk,fsmpk; int64_t funds = 0; CScript opret; struct CC_info *cp,C; cp = CCinit(&C,EVAL_FSM); mypk = pubkey2pk(Mypubkey()); fsmpk = GetUnspendable(cp,0); diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index c64d56b80..f00b1abfd 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -320,7 +320,7 @@ uint8_t DecodeGatewaysOpRet(const CScript &scriptPubKey) return(0); } -int64_t IsGatewaysvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsGatewaysvout(struct CC_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -331,7 +331,7 @@ int64_t IsGatewaysvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t return(0); } -bool GatewaysExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool GatewaysExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -429,7 +429,7 @@ uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,u return(zeroid); } -int32_t GatewaysCointxidExists(struct CCcontract_info *cp,uint256 cointxid) // dont forget to check mempool! +int32_t GatewaysCointxidExists(struct CC_info *cp,uint256 cointxid) // dont forget to check mempool! { char txidaddr[64]; std::string coin; int32_t numvouts; uint256 hashBlock; std::vector > addressIndex; @@ -515,7 +515,7 @@ int64_t GatewaysDepositval(CTransaction tx,CPubKey mypk) return(0); } -bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx, uint32_t nIn) +bool GatewaysValidate(struct CC_info *cp,Eval *eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks,height,claimvout; bool retval; uint8_t funcid,hash[32],M,N,taddr,prefix,prefix2; char str[65],destaddr[64],depositaddr[65],validationError[512]; @@ -683,7 +683,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & // helper functions for rpc calls in rpcwallet.cpp -int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 reftokenid,int64_t total,int32_t maxinputs) +int64_t AddGatewaysInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 reftokenid,int64_t total,int32_t maxinputs) { char coinaddr[64],destaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 tokenid,txid,hashBlock; std::vector origpubkey; std::vector vopret; CTransaction vintx; int32_t j,vout,n = 0; uint8_t evalcode,funcid; std::vector > unspentOutputs; @@ -730,7 +730,7 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP return(totalinputs); } -int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256 reftokenid) // dont forget to check mempool! +int32_t GatewaysBindExists(struct CC_info *cp,CPubKey gatewayspk,uint256 reftokenid) // dont forget to check mempool! { char markeraddr[64],depositaddr[64]; std::string coin; int32_t numvouts; int64_t totalsupply; uint256 tokenid,oracletxid,hashBlock; uint8_t M,N,taddr,prefix,prefix2; std::vector pubkeys; CTransaction tx; std::vector > addressIndex; @@ -757,7 +757,7 @@ int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256 std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector pubkeys) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction oracletx; uint8_t taddr,prefix,prefix2; CPubKey mypk,gatewayspk; CScript opret; uint256 hashBlock; struct CCcontract_info *cp,C; std::string name,description,format; int32_t i,numvouts; int64_t fullsupply; char destaddr[64],coinaddr[64],str[65],*fstr; + CTransaction oracletx; uint8_t taddr,prefix,prefix2; CPubKey mypk,gatewayspk; CScript opret; uint256 hashBlock; struct CC_info *cp,C; std::string name,description,format; int32_t i,numvouts; int64_t fullsupply; char destaddr[64],coinaddr[64],str[65],*fstr; cp = CCinit(&C,EVAL_GATEWAYS); if ( strcmp((char *)"KMD",coin.c_str()) == 0 ) { @@ -844,7 +844,7 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std:: { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CTransaction bindtx; CPubKey mypk,gatewayspk; uint256 oracletxid,merkleroot,mhash,hashBlock,tokenid,txid; - int64_t totalsupply; int32_t i,m,n,numvouts; uint8_t M,N,taddr,prefix,prefix2; std::string coin; struct CCcontract_info *cp,C; + int64_t totalsupply; int32_t i,m,n,numvouts; uint8_t M,N,taddr,prefix,prefix2; std::string coin; struct CC_info *cp,C; std::vector pubkeys,publishers; std::vectortxids; char str[67],depositaddr[64],txidaddr[64]; cp = CCinit(&C,EVAL_GATEWAYS); @@ -910,7 +910,7 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std:: std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,uint256 deposittxid,CPubKey destpub,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction tx; CPubKey mypk,gatewayspk,tmpdestpub; struct CCcontract_info *cp,C; uint8_t M,N,taddr,prefix,prefix2; + CTransaction tx; CPubKey mypk,gatewayspk,tmpdestpub; struct CC_info *cp,C; uint8_t M,N,taddr,prefix,prefix2; std::string coin, deposithex; std::vector msigpubkeys,publishers; int64_t totalsupply,depositamount,tmpamount,inputs,CCchange=0; int32_t numvouts,claimvout,height; std::vector proof; uint256 hashBlock,tokenid,oracletxid,tmptxid,cointxid; char str[65],depositaddr[64],coinaddr[64],destaddr[64]; std::vector txids; @@ -985,8 +985,8 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin CPubKey mypk, gatewayspk; uint256 tokenid,hashBlock,oracletxid; int32_t numvouts; int64_t totalsupply,inputs,CCchange=0; uint8_t M,N,taddr,prefix,prefix2; std::string coin; std::vector msigpubkeys; char depositaddr[64],str[65],coinaddr[64]; - struct CCcontract_info *cpGateways, gatewaysC; - struct CCcontract_info *cpTokens, tokensC; + struct CC_info *cpGateways, gatewaysC; + struct CC_info *cpTokens, tokensC; cpGateways = CCinit(&gatewaysC, EVAL_GATEWAYS); cpTokens = CCinit(&tokensC, EVAL_TOKENS); @@ -1049,7 +1049,7 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin std::string GatewaysPartialSign(uint64_t txfee,uint256 txid,std::string refcoin, std::string hex) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,txidaddrpk,signerpk; struct CCcontract_info *cp,C; CTransaction tx; + CPubKey mypk,txidaddrpk,signerpk; struct CC_info *cp,C; CTransaction tx; std::vector > unspentOutputs; char txidaddr[65]; int32_t maxK,K=0; uint256 tmptxid,parttxid,hashBlock; cp = CCinit(&C,EVAL_GATEWAYS); @@ -1089,7 +1089,7 @@ std::string GatewaysPartialSign(uint64_t txfee,uint256 txid,std::string refcoin, std::string GatewaysCompleteSigning(uint64_t txfee,uint256 withdrawtxid,std::string refcoin,std::string hex) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C; char txidaddr[65]; + CPubKey mypk,gatewayspk; struct CC_info *cp,C; char txidaddr[65]; cp = CCinit(&C,EVAL_GATEWAYS); mypk = pubkey2pk(Mypubkey()); gatewayspk = GetUnspendable(cp,0); @@ -1104,7 +1104,7 @@ std::string GatewaysCompleteSigning(uint64_t txfee,uint256 withdrawtxid,std::str std::string GatewaysMarkDone(uint64_t txfee,uint256 completetxid,std::string refcoin) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C; char txidaddr[65]; + CPubKey mypk,gatewayspk; struct CC_info *cp,C; char txidaddr[65]; cp = CCinit(&C,EVAL_GATEWAYS); mypk = pubkey2pk(Mypubkey()); if ( txfee == 0 ) @@ -1118,7 +1118,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) UniValue result(UniValue::VOBJ),pending(UniValue::VARR); CTransaction tx; std::string tmprefcoin; CPubKey mypk,gatewayspk,withdrawpub; std::vector msigpubkeys; uint256 hashBlock,tokenid,txid,oracletxid; uint8_t M,N,taddr,prefix,prefix2; char depositaddr[64],coinaddr[64],destaddr[64],str[65],withaddr[64],numstr[32],txidaddr[64],cctxidaddr[64],signeraddr[64]; - int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,amount,nValue; struct CCcontract_info *cp,C; + int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,amount,nValue; struct CC_info *cp,C; std::vector > unspentOutputs; cp = CCinit(&C,EVAL_GATEWAYS); @@ -1186,7 +1186,7 @@ UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin) UniValue result(UniValue::VOBJ),processed(UniValue::VARR); CTransaction tx; std::string tmprefcoin,hex; CPubKey mypk,gatewayspk,withdrawpub; std::vector msigpubkeys; uint256 withdrawtxid,hashBlock,txid,tokenid,oracletxid; uint8_t M,N,taddr,prefix,prefix2; char depositaddr[64],coinaddr[64],str[65],numstr[32],txidaddr[64],cctxidaddr[64],withaddr[64]; - int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,nValue,amount; struct CCcontract_info *cp,C; + int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,nValue,amount; struct CC_info *cp,C; std::vector > unspentOutputs; cp = CCinit(&C,EVAL_GATEWAYS); @@ -1278,7 +1278,7 @@ UniValue GatewaysMultisig(char *cctxidaddr) UniValue GatewaysList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock,oracletxid,tokenid; CTransaction vintx; std::string coin; int64_t totalsupply; char str[65],depositaddr[64]; uint8_t M,N,taddr,prefix,prefix2; std::vector pubkeys; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint256 txid,hashBlock,oracletxid,tokenid; CTransaction vintx; std::string coin; int64_t totalsupply; char str[65],depositaddr[64]; uint8_t M,N,taddr,prefix,prefix2; std::vector pubkeys; cp = CCinit(&C,EVAL_GATEWAYS); SetCCtxids(addressIndex,cp->unspendableCCaddr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) @@ -1298,7 +1298,7 @@ UniValue GatewaysList() UniValue GatewaysInfo(uint256 bindtxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::string coin; char str[67],numstr[65],depositaddr[64],gatewaysassets[64]; uint8_t M,N; std::vector pubkeys; uint8_t taddr,prefix,prefix2; uint256 tokenid,oracletxid,hashBlock; CTransaction tx; CPubKey Gatewayspk; struct CCcontract_info *cp,C; int32_t i; int64_t totalsupply,remaining; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::string coin; char str[67],numstr[65],depositaddr[64],gatewaysassets[64]; uint8_t M,N; std::vector pubkeys; uint8_t taddr,prefix,prefix2; uint256 tokenid,oracletxid,hashBlock; CTransaction tx; CPubKey Gatewayspk; struct CC_info *cp,C; int32_t i; int64_t totalsupply,remaining; result.push_back(Pair("result","success")); result.push_back(Pair("name","Gateways")); cp = CCinit(&C,EVAL_GATEWAYS); diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 4a78c69ac..499fb598d 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -34,7 +34,7 @@ class TokenHelper; // Plan validation runner, it may be called twice - for coins and tokens // (sadly we cannot have yet 'templatized' lambdas, if we could we could capture all these params inside HeirValidation()...) -template bool RunValidationPlans(uint8_t funcId, struct CCcontract_info* cp, Eval* eval, const CTransaction& tx, uint256 latestTxid, CScript fundingOpretScript, uint8_t hasHeirSpendingBegun) +template bool RunValidationPlans(uint8_t funcId, struct CC_info* cp, Eval* eval, const CTransaction& tx, uint256 latestTxid, CScript fundingOpretScript, uint8_t hasHeirSpendingBegun) { int32_t numvins = tx.vin.size(); int32_t numvouts = tx.vout.size(); @@ -104,14 +104,14 @@ template bool RunValidationPlans(uint8_t funcId, struct CCcont /** * Tx validation entry function */ -bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction& tx, uint32_t nIn) +bool HeirValidate(struct CC_info* cpHeir, Eval* eval, const CTransaction& tx, uint32_t nIn) { int32_t numvins = tx.vin.size(); int32_t numvouts = tx.vout.size(); //int32_t preventCCvins = -1; //int32_t preventCCvouts = -1; - struct CCcontract_info *cpTokens, tokensC; + struct CC_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); if (numvouts < 1) @@ -237,7 +237,7 @@ bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction * Checks if vout is to cryptocondition address * @return vout value in satoshis */ -template int64_t IsHeirFundingVout(struct CCcontract_info* cp, const CTransaction& tx, int32_t voutIndex, CPubKey ownerPubkey, CPubKey heirPubkey) +template int64_t IsHeirFundingVout(struct CC_info* cp, const CTransaction& tx, int32_t voutIndex, CPubKey ownerPubkey, CPubKey heirPubkey) { char destaddr[65], heirFundingAddr[65]; @@ -437,7 +437,7 @@ uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &toke // TODO: correct cc addr: std::vector> unspentOutputs; - struct CCcontract_info *cp, C; + struct CC_info *cp, C; cp = CCinit(&C, EVAL_HEIR); char coinaddr[64]; GetCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); // get the address of cryptocondition '1 of 2 pubkeys' @@ -507,7 +507,7 @@ uint256 FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &token } // add inputs of 1 of 2 cc address -template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, uint256 fundingtxid, CMutableTransaction& mtx, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t total, int32_t maxinputs) +template int64_t Add1of2AddressInputs(struct CC_info* cp, uint256 fundingtxid, CMutableTransaction& mtx, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t total, int32_t maxinputs) { // TODO: add threshold check int64_t nValue, voutValue, totalinputs = 0; @@ -566,7 +566,7 @@ template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, /** * enumerate all tx's sending to CCHeir 1of2address and calc total lifetime funds */ -template int64_t LifetimeHeirContractFunds(struct CCcontract_info* cp, uint256 fundingtxid, CPubKey ownerPubkey, CPubKey heirPubkey) +template int64_t LifetimeHeirContractFunds(struct CC_info* cp, uint256 fundingtxid, CPubKey ownerPubkey, CPubKey heirPubkey) { char coinaddr[64]; Helper::GetCoinsOrTokensCCaddress1of2(coinaddr, ownerPubkey, heirPubkey); // get the address of cryptocondition '1 of 2 pubkeys' @@ -619,7 +619,7 @@ template UniValue HeirFund(uint64_t txfee, int64_t amount, std { UniValue result(UniValue::VOBJ); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - struct CCcontract_info *cp, C; + struct CC_info *cp, C; cp = CCinit(&C, Helper::getMyEval()); if (txfee == 0) @@ -707,7 +707,7 @@ template UniValue _HeirAdd(uint256 fundingtxid, uint64_t txfee, i UniValue result(UniValue::VOBJ); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); int64_t inputs, CCchange = 0; - struct CCcontract_info *cp, C; + struct CC_info *cp, C; std::string rawhex; cp = CCinit(&C, Helper::getMyEval()); // for tokens shoud be EVAL_TOKENS to sign it correctly! @@ -825,7 +825,7 @@ template UniValue _HeirClaim(uint256 fundingtxid, uint64_t txfe CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CPubKey myPubkey; int64_t inputs, change = 0; - struct CCcontract_info *cp, C; + struct CC_info *cp, C; cp = CCinit(&C, EVAL_HEIR); if (txfee == 0) @@ -1006,7 +1006,7 @@ UniValue HeirInfo(uint256 fundingtxid) return result; }*/ - struct CCcontract_info *cp, C; + struct CC_info *cp, C; cp = CCinit(&C, EVAL_HEIR); uint8_t hasHeirSpendingBegun = 0; @@ -1123,7 +1123,7 @@ UniValue HeirInfo(uint256 fundingtxid) * @return list of heir plan handles (fundingtxid) */ -template void _HeirList(struct CCcontract_info *cp, UniValue &result) +template void _HeirList(struct CC_info *cp, UniValue &result) { std::vector> unspentOutputs; char coinaddr[64]; @@ -1174,7 +1174,7 @@ UniValue HeirList() UniValue result(UniValue::VOBJ); result.push_back(Pair("result", "success")); - struct CCcontract_info *cpHeir, *cpTokens, heirC, tokenC; // NOTE we must use a separate 'C' structure for each CCinit! + struct CC_info *cpHeir, *cpTokens, heirC, tokenC; // NOTE we must use a separate 'C' structure for each CCinit! cpHeir = CCinit(&heirC, EVAL_HEIR); cpTokens = CCinit(&tokenC, EVAL_TOKENS); diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index d66777933..39f6855ac 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -47,11 +47,11 @@ public: return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); } */ static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - struct CCcontract_info *cpHeir, heirC; + struct CC_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_HEIR); return GetCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); } - static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { CCaddr1of2set(cp, ownerPubkey, heirPubkey, coinaddr); } }; @@ -61,7 +61,7 @@ class TokenHelper { public: static uint8_t getMyEval() { return EVAL_TOKENS; } static int64_t addOwnerInputs(uint256 tokenid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { - struct CCcontract_info *cpHeir, heirC; + struct CC_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_TOKENS); return AddTokenCCInputs(cpHeir, mtx, ownerPubkey, tokenid, total, maxinputs); } @@ -89,12 +89,12 @@ public: return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS } */ static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - struct CCcontract_info *cpHeir, heirC; + struct CC_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_HEIR); return GetTokensCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); } - static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { CCaddrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); } @@ -628,4 +628,4 @@ public: }; -#endif \ No newline at end of file +#endif diff --git a/src/cc/lotto.cpp b/src/cc/lotto.cpp index e9c263ff1..c52c9a072 100644 --- a/src/cc/lotto.cpp +++ b/src/cc/lotto.cpp @@ -63,7 +63,7 @@ It is possible to have a jackpot but miss out on it due to not claiming it. To m // start of consensus code -int64_t IsLottovout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsLottovout(struct CC_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -74,7 +74,7 @@ int64_t IsLottovout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool LottoExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool LottoExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -112,7 +112,7 @@ bool LottoExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction else return(true); } -bool LottoValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool LottoValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; return eval->Invalid("no validation yet"); @@ -160,7 +160,7 @@ bool LottoValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, // helper functions for rpc calls in rpcwallet.cpp -int64_t AddLottoInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddLottoInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; @@ -203,7 +203,7 @@ uint8_t DecodeLottoFundingOpRet(const CScript &scriptPubKey,uint64_t &sbits,int3 return(0); } -int64_t LottoPlanFunds(uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk,uint256 reffundingtxid) +int64_t LottoPlanFunds(uint64_t refsbits,struct CC_info *cp,CPubKey pk,uint256 reffundingtxid) { char coinaddr[64]; uint64_t sbits; int64_t nValue,lockedfunds; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t vout; uint8_t funcid; std::vector > unspentOutputs; @@ -232,7 +232,7 @@ int64_t LottoPlanFunds(uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk,u UniValue LottoInfo(uint256 lottoid) { - UniValue result(UniValue::VOBJ); uint256 hashBlock,hentropy; CTransaction vintx; uint64_t lockedfunds,sbits; int32_t ticketsize,odds,firstheight,period; CPubKey lottopk; struct CCcontract_info *cp,C; char str[67],numstr[65]; + UniValue result(UniValue::VOBJ); uint256 hashBlock,hentropy; CTransaction vintx; uint64_t lockedfunds,sbits; int32_t ticketsize,odds,firstheight,period; CPubKey lottopk; struct CC_info *cp,C; char str[67],numstr[65]; if ( GetTransaction(lottoid,vintx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find lottoid\n"); @@ -264,7 +264,7 @@ UniValue LottoInfo(uint256 lottoid) UniValue LottoList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock,hentropy; CTransaction vintx; uint64_t sbits; int32_t ticketsize,odds,firstheight,period; char str[65]; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint256 txid,hashBlock,hentropy; CTransaction vintx; uint64_t sbits; int32_t ticketsize,odds,firstheight,period; char str[65]; cp = CCinit(&C,EVAL_LOTTO); SetCCtxids(addressIndex,cp->normaladdr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) @@ -284,7 +284,7 @@ UniValue LottoList() std::string LottoCreate(uint64_t txfee,char *planstr,int64_t funding,int32_t ticketsize,int32_t odds,int32_t firstheight,int32_t period) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - uint256 entropy,hentropy; CPubKey mypk,lottopk; uint64_t sbits; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + uint256 entropy,hentropy; CPubKey mypk,lottopk; uint64_t sbits; int64_t inputs,CCchange=0,nValue=COIN; struct CC_info *cp,C; cp = CCinit(&C,EVAL_LOTTO); if ( txfee == 0 ) txfee = 10000; @@ -303,7 +303,7 @@ std::string LottoCreate(uint64_t txfee,char *planstr,int64_t funding,int32_t tic std::string LottoTicket(uint64_t txfee,uint256 lottoid,int64_t numtickets) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,lottopk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + CPubKey mypk,lottopk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CC_info *cp,C; cp = CCinit(&C,EVAL_LOTTO); if ( txfee == 0 ) txfee = 10000; @@ -324,7 +324,7 @@ std::string LottoTicket(uint64_t txfee,uint256 lottoid,int64_t numtickets) std::string LottoWinner(uint64_t txfee) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,lottopk; int64_t winnings = 0; CScript opret; struct CCcontract_info *cp,C; + CPubKey mypk,lottopk; int64_t winnings = 0; CScript opret; struct CC_info *cp,C; cp = CCinit(&C,EVAL_LOTTO); if ( txfee == 0 ) txfee = 10000; diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 795b95186..692c496b3 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -47,7 +47,7 @@ // start of consensus code -int64_t IsMarmaravout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsMarmaravout(struct CC_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -188,7 +188,7 @@ int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid, CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) { - CTxOut ccvout; struct CCcontract_info *cp,C; CPubKey Marmarapk; + CTxOut ccvout; struct CC_info *cp,C; CPubKey Marmarapk; cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) @@ -212,7 +212,7 @@ CScript MarmaraCoinbaseOpret(uint8_t funcid,int32_t height,CPubKey pk) int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { - struct CCcontract_info *cp,C; CPubKey Marmarapk,pk; int32_t ht,unlockht; CTxOut ccvout; + struct CC_info *cp,C; CPubKey Marmarapk,pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); if ( 0 ) @@ -255,7 +255,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) return(-1); } -bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool MarmaraValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { std::vector vopret; CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid,vfuncid,*script; CPubKey pk,vpk; if ( ASSETCHAINS_MARMARA == 0 ) @@ -326,7 +326,7 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t // helper functions for rpc calls in rpcwallet.cpp -int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx,int32_t firstheight,CPubKey poolpk,int32_t maxinputs) +int64_t AddMarmaraCoinbases(struct CC_info *cp,CMutableTransaction &mtx,int32_t firstheight,CPubKey poolpk,int32_t maxinputs) { char coinaddr[64]; CPubKey Marmarapk,pk; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; std::vector > unspentOutputs; @@ -408,7 +408,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,val,inputsum=0,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; + UniValue result(UniValue::VOBJ); struct CC_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,val,inputsum=0,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; if ( txfee == 0 ) txfee = 10000; if ( (height & 1) != 0 ) @@ -490,7 +490,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures,height; int64_t amount,refamount,remaining,inputsum,change; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; std::vector pubkeys; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures,height; int64_t amount,refamount,remaining,inputsum,change; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; std::vector pubkeys; struct CC_info *cp,C; if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); @@ -607,7 +607,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) return(result); } -int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuances,int64_t &totalclosed,std::vector &closed,struct CCcontract_info *cp,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,CPubKey refpk,std::string refcurrency) +int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuances,int64_t &totalclosed,std::vector &closed,struct CC_info *cp,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,CPubKey refpk,std::string refcurrency) { char coinaddr[64]; CPubKey Marmarapk,senderpk; int64_t amount; uint256 createtxid,txid,hashBlock; CTransaction tx; int32_t numvouts,vout,matures,n=0; std::string currency; std::vector > unspentOutputs; @@ -643,7 +643,7 @@ int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuanc UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid,bool automaticflag) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; uint256 createtxid; int64_t batonamount; int32_t needbaton = 0; + UniValue result(UniValue::VOBJ); CPubKey mypk; struct CC_info *cp,C; std::string rawtx; char *errorstr=0; uint256 createtxid; int64_t batonamount; int32_t needbaton = 0; cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; @@ -700,7 +700,7 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 approvaltxid,uint256 batontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); CPubKey mypk,Marmarapk; struct CCcontract_info *cp,C; std::string rawtx; uint256 createtxid; char *errorstr=0; + UniValue result(UniValue::VOBJ); CPubKey mypk,Marmarapk; struct CC_info *cp,C; std::string rawtx; uint256 createtxid; char *errorstr=0; cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; @@ -757,7 +757,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a UniValue MarmaraCreditloop(uint256 txid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey pk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey pk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CC_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) { @@ -911,7 +911,7 @@ UniValue MarmaraCreditloop(uint256 txid) UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,poolfee=0,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,poolfee=0,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CC_info *cp,C; poolpk = pubkey2pk(Mypubkey()); if ( txfee == 0 ) txfee = 10000; @@ -1000,7 +1000,7 @@ UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_ { CMutableTransaction mtx; std::vector pubkeys; UniValue result(UniValue::VOBJ),a(UniValue::VARR),b(UniValue::VARR); int32_t i,n,matches; int64_t totalclosed=0,totalamount=0; std::vector issuances,closed; char coinaddr[64]; - CPubKey Marmarapk; struct CCcontract_info *cp,C; + CPubKey Marmarapk; struct CC_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); result.push_back(Pair("result","success")); diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 66c0e1b9a..a64f65a18 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -163,7 +163,7 @@ uint8_t DecodeOraclesData(const CScript &scriptPubKey,uint256 &oracletxid,uint25 return(0); } -CPubKey OracleBatonPk(char *batonaddr,struct CCcontract_info *cp) +CPubKey OracleBatonPk(char *batonaddr,struct CC_info *cp) { static secp256k1_context *ctx; size_t clen = CPubKey::PUBLIC_KEY_SIZE; @@ -256,7 +256,7 @@ static uint256 myIs_baton_spentinmempool(uint256 batontxid,int32_t batonvout) return(batontxid); } -uint256 OracleBatonUtxo(uint64_t txfee,struct CCcontract_info *cp,uint256 reforacletxid,char *batonaddr,CPubKey publisher,std::vector &dataarg) +uint256 OracleBatonUtxo(uint64_t txfee,struct CC_info *cp,uint256 reforacletxid,char *batonaddr,CPubKey publisher,std::vector &dataarg) { uint256 txid,oracletxid,hashBlock,btxid,batontxid = zeroid; int64_t dfee; int32_t dheight=0,vout,height,numvouts; CTransaction tx; CPubKey pk; uint8_t *ptr; std::vector vopret,data; std::vector > unspentOutputs; @@ -302,7 +302,7 @@ uint256 OracleBatonUtxo(uint64_t txfee,struct CCcontract_info *cp,uint256 refora uint256 OraclesBatontxid(uint256 reforacletxid,CPubKey refpk) { std::vector > unspentOutputs; - CTransaction regtx; uint256 hash,txid,batontxid,oracletxid; CPubKey pk; int32_t numvouts,height,maxheight=0; int64_t datafee; char markeraddr[64],batonaddr[64]; std::vector data; struct CCcontract_info *cp,C; + CTransaction regtx; uint256 hash,txid,batontxid,oracletxid; CPubKey pk; int32_t numvouts,height,maxheight=0; int64_t datafee; char markeraddr[64],batonaddr[64]; std::vector data; struct CC_info *cp,C; batontxid = zeroid; cp = CCinit(&C,EVAL_ORACLES); CCtxidaddr(markeraddr,reforacletxid); @@ -528,7 +528,7 @@ int32_t oracleprice_add(std::vector &publishers,CPubKey int64_t OraclePrice(int32_t height,uint256 reforacletxid,char *markeraddr,char *format) { std::vector > unspentOutputs; - CTransaction regtx; uint256 hash,txid,oracletxid,batontxid; CPubKey pk; int32_t i,ht,maxheight=0; int64_t datafee,price; char batonaddr[64]; std::vector data; struct CCcontract_info *cp,C; std::vector publishers; std::vector prices; + CTransaction regtx; uint256 hash,txid,oracletxid,batontxid; CPubKey pk; int32_t i,ht,maxheight=0; int64_t datafee,price; char batonaddr[64]; std::vector data; struct CC_info *cp,C; std::vector publishers; std::vector prices; if ( format[0] != 'L' ) return(0); cp = CCinit(&C,EVAL_ORACLES); @@ -564,7 +564,7 @@ int64_t OraclePrice(int32_t height,uint256 reforacletxid,char *markeraddr,char * return(0); } -int64_t IsOraclesvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsOraclesvout(struct CC_info *cp,const CTransaction& tx,int32_t v) { //char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -575,7 +575,7 @@ int64_t IsOraclesvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t return(0); } -bool OraclesDataValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,uint256 oracletxid,CPubKey publisher,int64_t datafee) +bool OraclesDataValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx,uint256 oracletxid,CPubKey publisher,int64_t datafee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; CScript scriptPubKey; @@ -633,7 +633,7 @@ bool OraclesDataValidate(struct CCcontract_info *cp,Eval* eval,const CTransactio else return(true); } -bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool OraclesValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { uint256 txid,oracletxid,batontxid; uint64_t txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts; uint8_t *script; std::vector vopret,data; CScript scriptPubKey; CPubKey publisher; numvins = tx.vin.size(); @@ -703,7 +703,7 @@ bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t // helper functions for rpc calls in rpcwallet.cpp -int64_t AddOracleInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,uint256 oracletxid,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddOracleInputs(struct CC_info *cp,CMutableTransaction &mtx,uint256 oracletxid,CPubKey pk,int64_t total,int32_t maxinputs) { char coinaddr[64],funcid; int64_t nValue,price,totalinputs = 0; uint256 tmporacletxid,tmpbatontxid,txid,hashBlock; std::vector origpubkey,data; CTransaction vintx; int32_t numvouts,vout,n = 0; std::vector > unspentOutputs; CPubKey tmppk; int64_t tmpnum; @@ -741,7 +741,7 @@ int64_t AddOracleInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,uint return(totalinputs); } -int64_t LifetimeOraclesFunds(struct CCcontract_info *cp,uint256 oracletxid,CPubKey publisher) +int64_t LifetimeOraclesFunds(struct CC_info *cp,uint256 oracletxid,CPubKey publisher) { char coinaddr[64]; CPubKey pk; int64_t total=0,num; uint256 txid,hashBlock,subtxid; CTransaction subtx; std::vector > addressIndex; @@ -765,7 +765,7 @@ int64_t LifetimeOraclesFunds(struct CCcontract_info *cp,uint256 oracletxid,CPubK std::string OracleCreate(int64_t txfee,std::string name,std::string description,std::string format) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Oraclespk; struct CCcontract_info *cp,C; char fmt; + CPubKey mypk,Oraclespk; struct CC_info *cp,C; char fmt; cp = CCinit(&C,EVAL_ORACLES); if ( name.size() > 32 || description.size() > 4096 || format.size() > 4096 ) @@ -805,7 +805,7 @@ std::string OracleCreate(int64_t txfee,std::string name,std::string description, std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,markerpubkey,batonpk; struct CCcontract_info *cp,C; char markeraddr[64],batonaddr[64]; + CPubKey mypk,markerpubkey,batonpk; struct CC_info *cp,C; char markeraddr[64],batonaddr[64]; cp = CCinit(&C,EVAL_ORACLES); if ( txfee == 0 ) txfee = 10000; @@ -832,7 +832,7 @@ std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee) std::string OracleSubscribe(int64_t txfee,uint256 oracletxid,CPubKey publisher,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,markerpubkey; struct CCcontract_info *cp,C; char markeraddr[64]; + CPubKey mypk,markerpubkey; struct CC_info *cp,C; char markeraddr[64]; cp = CCinit(&C,EVAL_ORACLES); if ( txfee == 0 ) txfee = 10000; @@ -852,7 +852,7 @@ std::string OracleSubscribe(int64_t txfee,uint256 oracletxid,CPubKey publisher,i std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector data) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CScript pubKey; CPubKey mypk,batonpk; int64_t offset,datafee,inputs,CCchange = 0; struct CCcontract_info *cp,C; uint256 batontxid,hashBlock; + CScript pubKey; CPubKey mypk,batonpk; int64_t offset,datafee,inputs,CCchange = 0; struct CC_info *cp,C; uint256 batontxid,hashBlock; char coinaddr[64],batonaddr[64]; std::vector prevdata; CTransaction tx; std::string name,description,format; int32_t len,numvouts; cp = CCinit(&C,EVAL_ORACLES); @@ -971,7 +971,7 @@ UniValue OracleInfo(uint256 origtxid) UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector > unspentOutputs; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction regtx,tx; std::string name,description,format; uint256 hashBlock,txid,oracletxid,batontxid; CPubKey pk; struct CCcontract_info *cp,C; int64_t datafee,funding; char str[67],markeraddr[64],numstr[64],batonaddr[64]; std::vector data; + CTransaction regtx,tx; std::string name,description,format; uint256 hashBlock,txid,oracletxid,batontxid; CPubKey pk; struct CC_info *cp,C; int64_t datafee,funding; char str[67],markeraddr[64],numstr[64],batonaddr[64]; std::vector data; cp = CCinit(&C,EVAL_ORACLES); CCtxidaddr(markeraddr,origtxid); if ( GetTransaction(origtxid,tx,hashBlock,false) == 0 ) @@ -1025,7 +1025,7 @@ UniValue OracleInfo(uint256 origtxid) UniValue OraclesList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock; CTransaction createtx; std::string name,description,format; char str[65]; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint256 txid,hashBlock; CTransaction createtx; std::string name,description,format; char str[65]; cp = CCinit(&C,EVAL_ORACLES); SetCCtxids(addressIndex,cp->normaladdr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 859a5ba3f..c25842ea3 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -23,7 +23,7 @@ // start of consensus code -int64_t IsPaymentsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsPaymentsvout(struct CC_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -34,7 +34,7 @@ int64_t IsPaymentsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t return(0); } -bool PaymentsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool PaymentsExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -72,7 +72,7 @@ bool PaymentsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransacti else return(true); } -bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool PaymentsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; return eval->Invalid("no validation yet"); @@ -113,7 +113,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & // helper functions for rpc calls in rpcwallet.cpp -int64_t AddPaymentsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddPaymentsInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; @@ -145,7 +145,7 @@ int64_t AddPaymentsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP std::string PaymentsGet(uint64_t txfee,int64_t nValue) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Paymentspk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; + CPubKey mypk,Paymentspk; int64_t inputs,CCchange=0; struct CC_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; cp = CCinit(&C,EVAL_PAYMENTS); if ( txfee == 0 ) txfee = 10000; @@ -186,7 +186,7 @@ std::string PaymentsGet(uint64_t txfee,int64_t nValue) std::string PaymentsFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Paymentspk; CScript opret; struct CCcontract_info *cp,C; + CPubKey mypk,Paymentspk; CScript opret; struct CC_info *cp,C; cp = CCinit(&C,EVAL_PAYMENTS); if ( txfee == 0 ) txfee = 10000; @@ -204,7 +204,7 @@ UniValue PaymentsInfo() { UniValue result(UniValue::VOBJ); char numstr[64]; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey Paymentspk; struct CCcontract_info *cp,C; int64_t funding; + CPubKey Paymentspk; struct CC_info *cp,C; int64_t funding; result.push_back(Pair("result","success")); result.push_back(Pair("name","Payments")); cp = CCinit(&C,EVAL_PAYMENTS); diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index e2893bec8..d137778a6 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -30,7 +30,7 @@ // start of consensus code -int64_t IsPegsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsPegsvout(struct CC_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -41,7 +41,7 @@ int64_t IsPegsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool PegsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool PegsExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -79,7 +79,7 @@ bool PegsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction & else return(true); } -bool PegsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool PegsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; return eval->Invalid("no validation yet"); @@ -120,7 +120,7 @@ bool PegsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, // helper functions for rpc calls in rpcwallet.cpp -int64_t AddPegsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddPegsInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; @@ -152,7 +152,7 @@ int64_t AddPegsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKe std::string PegsGet(uint64_t txfee,int64_t nValue) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Pegspk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; + CPubKey mypk,Pegspk; int64_t inputs,CCchange=0; struct CC_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; cp = CCinit(&C,EVAL_PEGS); if ( txfee == 0 ) txfee = 10000; @@ -193,7 +193,7 @@ std::string PegsGet(uint64_t txfee,int64_t nValue) std::string PegsFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Pegspk; CScript opret; struct CCcontract_info *cp,C; + CPubKey mypk,Pegspk; CScript opret; struct CC_info *cp,C; cp = CCinit(&C,EVAL_PEGS); if ( txfee == 0 ) txfee = 10000; @@ -211,7 +211,7 @@ UniValue PegsInfo() { UniValue result(UniValue::VOBJ); char numstr[64]; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey Pegspk; struct CCcontract_info *cp,C; int64_t funding; + CPubKey Pegspk; struct CC_info *cp,C; int64_t funding; result.push_back(Pair("result","success")); result.push_back(Pair("name","Pegs")); cp = CCinit(&C,EVAL_PEGS); diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 369495b1a..6171e73a8 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -86,7 +86,7 @@ uint8_t DecodePricesFundingOpRet(CScript scriptPubKey,CPubKey &planpk,uint256 &o return(0); } -bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool PricesValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; return eval->Invalid("no validation yet"); @@ -127,7 +127,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx // helper functions for rpc calls in rpcwallet.cpp -int64_t AddTokensInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char *destaddr,uint256 tolenid,int64_t total,int32_t maxinputs) +int64_t AddTokensInputs(struct CC_info *cp,CMutableTransaction &mtx,char *destaddr,uint256 tolenid,int64_t total,int32_t maxinputs) { // add threshold check int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; @@ -158,7 +158,7 @@ int64_t AddTokensInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char UniValue PricesList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint64_t mode; int32_t margin,maxleverage; std::vectorpubkeys; uint256 txid,hashBlock,oracletxid,longtoken,shorttoken,bettoken; CPubKey planpk,pricespk; char str[65]; CTransaction vintx; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint64_t mode; int32_t margin,maxleverage; std::vectorpubkeys; uint256 txid,hashBlock,oracletxid,longtoken,shorttoken,bettoken; CPubKey planpk,pricespk; char str[65]; CTransaction vintx; cp = CCinit(&C,EVAL_PRICES); pricespk = GetUnspendable(cp,0); SetCCtxids(addressIndex,cp->normaladdr); @@ -183,7 +183,7 @@ UniValue PricesList() std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletxid,uint64_t margin,uint64_t mode,uint256 longtoken,uint256 shorttoken,int32_t maxleverage,int64_t funding,std::vector pubkeys) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction oracletx; int64_t fullsupply,inputs,CCchange=0; uint256 hashBlock; char str[65],coinaddr[64],houseaddr[64]; CPubKey mypk,pricespk; int32_t i,N,numvouts; struct CCcontract_info *cp,C; + CTransaction oracletx; int64_t fullsupply,inputs,CCchange=0; uint256 hashBlock; char str[65],coinaddr[64],houseaddr[64]; CPubKey mypk,pricespk; int32_t i,N,numvouts; struct CC_info *cp,C; if ( funding < 100*COIN || maxleverage <= 0 || maxleverage > 10000 ) { CCerror = "invalid parameter error"; @@ -246,7 +246,7 @@ std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletx UniValue PricesInfo(uint256 fundingtxid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); CPubKey pricespk,planpk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction vintx; int64_t balance,supply,exposure; uint64_t funding,mode; int32_t i,margin,maxleverage; char numstr[65],houseaddr[64],exposureaddr[64],str[65]; std::vectorpubkeys; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); CPubKey pricespk,planpk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction vintx; int64_t balance,supply,exposure; uint64_t funding,mode; int32_t i,margin,maxleverage; char numstr[65],houseaddr[64],exposureaddr[64],str[65]; std::vectorpubkeys; struct CC_info *cp,C; cp = CCinit(&C,EVAL_PRICES); pricespk = GetUnspendable(cp,0); if ( GetTransaction(fundingtxid,vintx,hashBlock,false) == 0 ) @@ -295,7 +295,7 @@ UniValue PricesInfo(uint256 fundingtxid) std::string PricesAddFunding(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - struct CCcontract_info *cp,C; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,CCchange = 0; uint64_t funding,mode; int32_t margin,maxleverage; char houseaddr[64],myaddr[64]; std::vectorpubkeys; + struct CC_info *cp,C; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,CCchange = 0; uint64_t funding,mode; int32_t margin,maxleverage; char houseaddr[64],myaddr[64]; std::vectorpubkeys; if ( amount < 10000 ) { CCerror = "amount must be positive"; @@ -350,7 +350,7 @@ std::string PricesAddFunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount,int32_t leverage) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - struct CCcontract_info *cp,C; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; std::vectorpubkeys; + struct CC_info *cp,C; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; std::vectorpubkeys; if ( amount < 0 ) { amount = -amount; diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index bd5a6d919..c47fcf1c2 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -141,7 +141,7 @@ uint8_t DecodeRewardsOpRet(uint256 txid,const CScript &scriptPubKey,uint64_t &sb return(0); } -int64_t IsRewardsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) +int64_t IsRewardsvout(struct CC_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) { char destaddr[64]; uint64_t sbits; uint256 fundingtxid,txid; uint8_t funcid; int32_t numvouts; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 && (numvouts= (int32_t)tx.vout.size()) > 0 ) @@ -157,7 +157,7 @@ int64_t IsRewardsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t return(0); } -bool RewardsExactAmounts(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx,uint64_t txfee,uint64_t refsbits,uint256 reffundingtxid) +bool RewardsExactAmounts(struct CC_info *cp,Eval *eval,const CTransaction &tx,uint64_t txfee,uint64_t refsbits,uint256 reffundingtxid) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -192,7 +192,7 @@ bool RewardsExactAmounts(struct CCcontract_info *cp,Eval *eval,const CTransactio else return(true); } -bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool RewardsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { uint256 txid,fundingtxid,hashBlock,vinfundingtxid; uint64_t vinsbits,sbits,APR,minseconds,maxseconds,mindeposit,amount,reward,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; uint8_t funcid; CScript scriptPubKey; CTransaction fundingTx,vinTx; numvins = tx.vin.size(); @@ -327,7 +327,7 @@ static uint64_t myIs_unlockedtx_inmempool(uint256 &txid,int32_t &vout,uint64_t r } // 'L' vs 'F' and 'A' -int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) +int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) { char coinaddr[64],str[65]; uint64_t threshold,sbits,nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t numblocks,j,vout,n = 0; uint8_t funcid; std::vector > unspentOutputs; @@ -387,7 +387,7 @@ int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CCcont return(totalinputs); } -int64_t RewardsPlanFunds(uint64_t &lockedfunds,uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk,uint256 reffundingtxid) +int64_t RewardsPlanFunds(uint64_t &lockedfunds,uint64_t refsbits,struct CC_info *cp,CPubKey pk,uint256 reffundingtxid) { char coinaddr[64]; uint64_t sbits; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t vout; uint8_t funcid; std::vector > unspentOutputs; @@ -418,7 +418,7 @@ int64_t RewardsPlanFunds(uint64_t &lockedfunds,uint64_t refsbits,struct CCcontra return(totalinputs); } -bool RewardsPlanExists(struct CCcontract_info *cp,uint64_t refsbits,CPubKey rewardspk,uint64_t &APR,uint64_t &minseconds,uint64_t &maxseconds,uint64_t &mindeposit) +bool RewardsPlanExists(struct CC_info *cp,uint64_t refsbits,CPubKey rewardspk,uint64_t &APR,uint64_t &minseconds,uint64_t &maxseconds,uint64_t &mindeposit) { char CCaddr[64]; uint64_t sbits; uint256 txid,hashBlock; CTransaction tx; std::vector > txids; @@ -443,7 +443,7 @@ bool RewardsPlanExists(struct CCcontract_info *cp,uint64_t refsbits,CPubKey rewa UniValue RewardsInfo(uint256 rewardsid) { - UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction vintx; uint64_t lockedfunds,APR,minseconds,maxseconds,mindeposit,sbits,funding; CPubKey rewardspk; struct CCcontract_info *cp,C; char str[67],numstr[65]; + UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction vintx; uint64_t lockedfunds,APR,minseconds,maxseconds,mindeposit,sbits,funding; CPubKey rewardspk; struct CC_info *cp,C; char str[67],numstr[65]; if ( GetTransaction(rewardsid,vintx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); @@ -481,7 +481,7 @@ UniValue RewardsInfo(uint256 rewardsid) UniValue RewardsList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock; CTransaction vintx; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; char str[65]; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint256 txid,hashBlock; CTransaction vintx; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; char str[65]; cp = CCinit(&C,EVAL_REWARDS); SetCCtxids(addressIndex,cp->normaladdr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) @@ -501,7 +501,7 @@ UniValue RewardsList() std::string RewardsCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t APR,int64_t minseconds,int64_t maxseconds,int64_t mindeposit) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,a,b,c,d; struct CCcontract_info *cp,C; + CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,a,b,c,d; struct CC_info *cp,C; if ( funds < COIN || mindeposit < 0 || minseconds < 0 || maxseconds < 0 ) { fprintf(stderr,"negative parameter error\n"); @@ -536,7 +536,7 @@ std::string RewardsCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int6 std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,a,b,c,d; struct CCcontract_info *cp,C; + CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,a,b,c,d; struct CC_info *cp,C; if ( amount < 0 ) { fprintf(stderr,"negative parameter error\n"); @@ -571,7 +571,7 @@ std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,i std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t deposit) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,rewardspk; CScript opret; uint64_t lockedfunds,sbits,funding,APR,minseconds,maxseconds,mindeposit; struct CCcontract_info *cp,C; + CPubKey mypk,rewardspk; CScript opret; uint64_t lockedfunds,sbits,funding,APR,minseconds,maxseconds,mindeposit; struct CC_info *cp,C; if ( deposit < txfee ) { CCerror = "deposit amount less than txfee"; @@ -615,7 +615,7 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 locktxid) { CMutableTransaction firstmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction tx; char coinaddr[64]; CPubKey mypk,rewardspk; CScript scriptPubKey,ignore; uint256 hashBlock; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; int64_t funding,reward=0,amount=0,inputs,CCchange=0; struct CCcontract_info *cp,C; + CTransaction tx; char coinaddr[64]; CPubKey mypk,rewardspk; CScript scriptPubKey,ignore; uint256 hashBlock; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; int64_t funding,reward=0,amount=0,inputs,CCchange=0; struct CC_info *cp,C; cp = CCinit(&C,EVAL_REWARDS); if ( txfee == 0 ) txfee = 10000; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 10c6ee4b8..51b31c5c7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2150,7 +2150,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } else { - struct CCcontract_info *cp,C; uint256 txid; int32_t vout; CAmount nValue; char coinaddr[64]; CPubKey mypk,Marmarapk; + struct CC_info *cp,C; uint256 txid; int32_t vout; CAmount nValue; char coinaddr[64]; CPubKey mypk,Marmarapk; std::vector > unspentOutputs; cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 90f8fd6db..24f0c5f98 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -463,6 +463,10 @@ static const CRPCCommand vRPCCommands[] = // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, + { "CClib", "cclibaddress", &cclibaddress, true }, + { "CClib", "cclibinfo", &cclibinfo, true }, + { "CClib", "cclib", &cclib, true }, + // Gateways { "gateways", "gatewaysaddress", &gatewaysaddress, true }, { "gateways", "gatewayslist", &gatewayslist, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index d5ebb56ab..92cbb5105 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -286,7 +286,9 @@ extern UniValue marmara_info(const UniValue& params, bool fHelp); extern UniValue marmara_creditloop(const UniValue& params, bool fHelp); extern UniValue marmara_settlement(const UniValue& params, bool fHelp); extern UniValue marmara_lock(const UniValue& params, bool fHelp); -extern UniValue paymentsaddress(const UniValue& params, bool fHelp); +extern UniValue cclibaddress(const UniValue& params, bool fHelp); +extern UniValue cclibinfo(const UniValue& params, bool fHelp); +extern UniValue cclib(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); extern UniValue gatewayslist(const UniValue& params, bool fHelp); extern UniValue gatewaysinfo(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 02cf85ee6..588706a41 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5197,7 +5197,7 @@ int32_t ensure_CCrequirements() #include "../cc/CCHeir.h" #include "../cc/CCMarmara.h" -UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vector &pubkey) +UniValue CCaddress(struct CC_info *cp,char *name,std::vector &pubkey) { UniValue result(UniValue::VOBJ); char destaddr[64],str[64]; CPubKey pk; pk = GetUnspendable(cp,0); @@ -5302,7 +5302,7 @@ UniValue setpubkey(const UniValue& params, bool fHelp) UniValue channelsaddress(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::vector destpubkey; CPubKey pk,pk2; char destaddr[64]; + UniValue result(UniValue::VOBJ); struct CC_info *cp,C; std::vector destpubkey; CPubKey pk,pk2; char destaddr[64]; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() != 1 ) throw runtime_error("channelsaddress destpubkey\n"); @@ -5327,9 +5327,46 @@ UniValue channelsaddress(const UniValue& params, bool fHelp) return(result); } +UniValue cclibaddress(const UniValue& params, bool fHelp) +{ + struct CC_info *cp,C; std::vector pubkey; + cp = CCinit(&C,EVAL_FIRSTUSER); + if ( fHelp || params.size() > 1 ) + throw runtime_error("cclibaddress [pubkey]\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + if ( params.size() == 1 ) + pubkey = ParseHex(params[0].get_str().c_str()); + return(CCaddress(cp,(char *)"CClib",pubkey)); +} + +UniValue cclibinfo(const UniValue& params, bool fHelp) +{ + struct CC_info *cp,C; + cp = CCinit(&C,EVAL_FIRSTUSER); + if ( fHelp || params.size() > 0 ) + throw runtime_error("cclibinfo\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + return(CClib_info(cp)); +} + +UniValue cclib(const UniValue& params, bool fHelp) +{ + struct CC_info *cp,C; char *method; cJSON *params; + cp = CCinit(&C,EVAL_FIRSTUSER); + if ( fHelp || params.size() > 2 ) + throw runtime_error("cclib method [JSON params]\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + method = params[0].get_str().c_str(); + params = cJSON_Parse(params[1].get_str().c_str()); + return(CClib(cp,method,params)); +} + UniValue oraclesaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_ORACLES); if ( fHelp || params.size() > 1 ) throw runtime_error("oraclesaddress [pubkey]\n"); @@ -5342,7 +5379,7 @@ UniValue oraclesaddress(const UniValue& params, bool fHelp) UniValue pricesaddress(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C,*assetscp,C2; std::vector pubkey; CPubKey mypk,planpk,pricespk; char myaddr[64],houseaddr[64],exposureaddr[64]; + UniValue result(UniValue::VOBJ); struct CC_info *cp,C,*assetscp,C2; std::vector pubkey; CPubKey mypk,planpk,pricespk; char myaddr[64],houseaddr[64],exposureaddr[64]; cp = CCinit(&C,EVAL_PRICES); assetscp = CCinit(&C2,EVAL_PRICES); if ( fHelp || params.size() > 1 ) @@ -5365,7 +5402,7 @@ UniValue pricesaddress(const UniValue& params, bool fHelp) UniValue pegsaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_PEGS); if ( fHelp || params.size() > 1 ) throw runtime_error("pegssaddress [pubkey]\n"); @@ -5378,7 +5415,7 @@ UniValue pegsaddress(const UniValue& params, bool fHelp) UniValue marmaraaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_MARMARA); if ( fHelp || params.size() > 1 ) throw runtime_error("Marmaraaddress [pubkey]\n"); @@ -5391,7 +5428,7 @@ UniValue marmaraaddress(const UniValue& params, bool fHelp) UniValue paymentsaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_PAYMENTS); if ( fHelp || params.size() > 1 ) throw runtime_error("paymentsaddress [pubkey]\n"); @@ -5404,7 +5441,7 @@ UniValue paymentsaddress(const UniValue& params, bool fHelp) UniValue gatewaysaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_GATEWAYS); if ( fHelp || params.size() > 1 ) throw runtime_error("gatewaysaddress [pubkey]\n"); @@ -5417,7 +5454,7 @@ UniValue gatewaysaddress(const UniValue& params, bool fHelp) UniValue heiraddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_HEIR); if ( fHelp || params.size() > 1 ) throw runtime_error("heiraddress [pubkey]\n"); @@ -5432,7 +5469,7 @@ UniValue heiraddress(const UniValue& params, bool fHelp) UniValue lottoaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_LOTTO); if ( fHelp || params.size() > 1 ) throw runtime_error("lottoaddress [pubkey]\n"); @@ -5445,7 +5482,7 @@ UniValue lottoaddress(const UniValue& params, bool fHelp) UniValue FSMaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_FSM); if ( fHelp || params.size() > 1 ) throw runtime_error("FSMaddress [pubkey]\n"); @@ -5458,7 +5495,7 @@ UniValue FSMaddress(const UniValue& params, bool fHelp) UniValue auctionaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_AUCTION); if ( fHelp || params.size() > 1 ) throw runtime_error("auctionaddress [pubkey]\n"); @@ -5471,7 +5508,7 @@ UniValue auctionaddress(const UniValue& params, bool fHelp) UniValue diceaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_DICE); if ( fHelp || params.size() > 1 ) throw runtime_error("diceaddress [pubkey]\n"); @@ -5484,7 +5521,7 @@ UniValue diceaddress(const UniValue& params, bool fHelp) UniValue faucetaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; int errno; cp = CCinit(&C,EVAL_FAUCET); if ( fHelp || params.size() > 1 ) @@ -5499,7 +5536,7 @@ UniValue faucetaddress(const UniValue& params, bool fHelp) UniValue rewardsaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_REWARDS); if ( fHelp || params.size() > 1 ) throw runtime_error("rewardsaddress [pubkey]\n"); @@ -5512,7 +5549,7 @@ UniValue rewardsaddress(const UniValue& params, bool fHelp) UniValue assetsaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp, C; std::vector pubkey; + struct CC_info *cp, C; std::vector pubkey; cp = CCinit(&C, EVAL_ASSETS); if (fHelp || params.size() > 1) throw runtime_error("assetsaddress [pubkey]\n"); @@ -5525,7 +5562,7 @@ UniValue assetsaddress(const UniValue& params, bool fHelp) UniValue tokenaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + struct CC_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_TOKENS); if ( fHelp || params.size() > 1 ) throw runtime_error("tokenaddress [pubkey]\n"); @@ -5730,7 +5767,7 @@ UniValue channelsinfo(const UniValue& params, bool fHelp) UniValue channelsopen(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); int32_t numpayments; int64_t payment; std::vector destpub; struct CCcontract_info *cp,C; std::string hex; + UniValue result(UniValue::VOBJ); int32_t numpayments; int64_t payment; std::vector destpub; struct CC_info *cp,C; std::string hex; uint256 tokenid=zeroid; cp = CCinit(&C,EVAL_CHANNELS); @@ -5773,7 +5810,7 @@ UniValue channelsopen(const UniValue& params, bool fHelp) UniValue channelspayment(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid,secret=zeroid; int32_t n; int64_t amount; + UniValue result(UniValue::VOBJ); struct CC_info *cp,C; std::string hex; uint256 opentxid,secret=zeroid; int32_t n; int64_t amount; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() < 2 || params.size() >3 ) throw runtime_error("channelspayment opentxid amount [secret]\n"); @@ -5803,7 +5840,7 @@ UniValue channelspayment(const UniValue& params, bool fHelp) UniValue channelsclose(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid; + UniValue result(UniValue::VOBJ); struct CC_info *cp,C; std::string hex; uint256 opentxid; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() != 1 ) throw runtime_error("channelsclose opentxid\n"); @@ -5823,7 +5860,7 @@ UniValue channelsclose(const UniValue& params, bool fHelp) UniValue channelsrefund(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid,closetxid; + UniValue result(UniValue::VOBJ); struct CC_info *cp,C; std::string hex; uint256 opentxid,closetxid; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() != 2 ) throw runtime_error("channelsrefund opentxid closetxid\n"); @@ -6877,7 +6914,7 @@ UniValue tokenorders(const UniValue& params, bool fHelp) UniValue tokenbalance(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint256 tokenid; uint64_t balance; std::vector pubkey; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ); uint256 tokenid; uint64_t balance; std::vector pubkey; struct CC_info *cp,C; CCerror.clear(); if ( fHelp || params.size() > 2 ) From df2c10a6d7e0ca0add54826b9e6b97d63b2b175c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 22:50:26 -1100 Subject: [PATCH 125/144] CC_info --- src/cc/CCutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index b61fef840..9d4567322 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -638,7 +638,7 @@ bool ProcessCC(struct CC_info *cp,Eval* eval, std::vector paramsNull,co bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) { - uint8_t evalcode; int32_t height,from_mempool; struct CCinfo *cp; + uint8_t evalcode; int32_t height,from_mempool; struct CC_info *cp; if ( ASSETCHAINS_CCLIB != MYCCLIBNAME ) { fprintf(stderr,"-ac_cclib=%s vs myname %s\n",ASSETCHAINS_CCLIB.c_str(),MYCCLIBNAME); From 0b911c18ac9efdebbc96c97c631889b4a24a61ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 22:52:13 -1100 Subject: [PATCH 126/144] Fix --- src/cc/CCutils.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 9d4567322..5a7ee53f0 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -636,6 +636,8 @@ bool ProcessCC(struct CC_info *cp,Eval* eval, std::vector paramsNull,co return(false); } +extern struct CC_info CCinfos[0x100]; + bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) { uint8_t evalcode; int32_t height,from_mempool; struct CC_info *cp; @@ -657,17 +659,17 @@ bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,co evalcode = cond->code[0]; if ( evalcode >= EVAL_FIRSTUSER && evalcode <= EVAL_LASTUSER ) { - cp = &CCinfos[(int32_t)ecode]; + cp = &CCinfos[(int32_t)evalcode]; if ( cp->didinit == 0 ) { - if ( CClib_initcp(cp,ecode) == 0 ) + if ( CClib_initcp(cp,evalcode) == 0 ) cp->didinit = 1; else return eval->Invalid("unsupported CClib evalcode"); } CCclearvars(cp); if ( paramsNull.size() != 0 ) // Don't expect params return eval->Invalid("Cannot have params"); - else if ( CClib_validate(cp,eval,ctx,nIn) != 0 ) + else if ( CClib_validate(cp,eval,txTo,nIn) != 0 ) return(true); return eval->Invalid("error in CClib_validate"); } From df02d14c651159937d65716b33fe22237e87fa08 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 22:53:15 -1100 Subject: [PATCH 127/144] Test --- src/cc/CCutils.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 5a7ee53f0..d4f7b32bc 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -637,6 +637,8 @@ bool ProcessCC(struct CC_info *cp,Eval* eval, std::vector paramsNull,co } extern struct CC_info CCinfos[0x100]; +extern std::string MYCCLIBNAME; +bool CClib_validate(struct CC_info *cp,Eval *eval,const CTransaction &txTo,unsigned int nIn); bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) { From b1ec7e5afa0887fbe117f02f014f6d9ac16d347a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 22:55:19 -1100 Subject: [PATCH 128/144] Test --- src/cc/CCutils.cpp | 2 +- src/cc/cclib.cpp | 2 +- src/cc/heir_validate.h | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index d4f7b32bc..aecca0dd7 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -645,7 +645,7 @@ bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,co uint8_t evalcode; int32_t height,from_mempool; struct CC_info *cp; if ( ASSETCHAINS_CCLIB != MYCCLIBNAME ) { - fprintf(stderr,"-ac_cclib=%s vs myname %s\n",ASSETCHAINS_CCLIB.c_str(),MYCCLIBNAME); + fprintf(stderr,"-ac_cclib=%s vs myname %s\n",ASSETCHAINS_CCLIB.c_str(),MYCCLIBNAME.c_str()); return eval->Invalid("-ac_cclib name mismatches myname"); } height = KOMODO_CONNECTING; diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index c93d204df..837a36024 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -38,7 +38,7 @@ CClib_methods[] = { "faucet2_get", "", 0, 0, 'G' }, }; -#define MYCCLIBNAME ((char *)"stub") +std::string MYCCLIBNAME = (char *)"stub"; char *CClib_name() { return(MYCCLIBNAME); } diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 39f6855ac..481947fe2 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -47,11 +47,11 @@ public: return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); } */ static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - struct CC_info *cpHeir, heirC; + struct CCcontract_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_HEIR); return GetCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); } - static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { CCaddr1of2set(cp, ownerPubkey, heirPubkey, coinaddr); } }; @@ -61,7 +61,7 @@ class TokenHelper { public: static uint8_t getMyEval() { return EVAL_TOKENS; } static int64_t addOwnerInputs(uint256 tokenid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { - struct CC_info *cpHeir, heirC; + struct CCcontract_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_TOKENS); return AddTokenCCInputs(cpHeir, mtx, ownerPubkey, tokenid, total, maxinputs); } @@ -89,12 +89,12 @@ public: return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS } */ static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - struct CC_info *cpHeir, heirC; + struct CCcontract_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_HEIR); return GetTokensCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); } - static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { CCaddrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); } From e1e740c18c988da13c6c1cf2d1339ba361d67a87 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 22:56:33 -1100 Subject: [PATCH 129/144] CC_info --- src/cc/heir_validate.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 481947fe2..85f5b5c11 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -47,11 +47,11 @@ public: return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); } */ static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - struct CCcontract_info *cpHeir, heirC; + struct CC_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_HEIR); return GetCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); } - static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { CCaddr1of2set(cp, ownerPubkey, heirPubkey, coinaddr); } }; @@ -61,7 +61,7 @@ class TokenHelper { public: static uint8_t getMyEval() { return EVAL_TOKENS; } static int64_t addOwnerInputs(uint256 tokenid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { - struct CCcontract_info *cpHeir, heirC; + struct CC_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_TOKENS); return AddTokenCCInputs(cpHeir, mtx, ownerPubkey, tokenid, total, maxinputs); } @@ -89,12 +89,12 @@ public: return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS } */ static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - struct CCcontract_info *cpHeir, heirC; + struct CC_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_HEIR); return GetTokensCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); } - static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { CCaddrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); } @@ -123,13 +123,13 @@ public: class CValidatorBase { public: - CValidatorBase(CCcontract_info* cp) : m_cp(cp) {} + CValidatorBase(CC_info* cp) : m_cp(cp) {} virtual bool isVinValidator() const = 0; virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const = 0; virtual bool validateVout(CTxOut vout, std::string& message) const = 0; protected: - CCcontract_info * m_cp; + CC_info * m_cp; }; /** @@ -138,11 +138,11 @@ protected: class CInputIdentifierBase { public: - CInputIdentifierBase(CCcontract_info* cp) : m_cp(cp) {} + CInputIdentifierBase(CC_info* cp) : m_cp(cp) {} virtual std::string inputName() const = 0; virtual bool identifyInput(CTxIn vin) const = 0; protected: - CCcontract_info * m_cp; + CC_info * m_cp; }; /** @@ -375,7 +375,7 @@ private: class CNormalInputIdentifier : CInputIdentifierBase { public: - CNormalInputIdentifier(CCcontract_info* cp) : CInputIdentifierBase(cp) {} + CNormalInputIdentifier(CC_info* cp) : CInputIdentifierBase(cp) {} virtual std::string inputName() const { return std::string("normal input"); } virtual bool identifyInput(CTxIn vin) const { return !IsCCInput(vin.scriptSig); @@ -384,7 +384,7 @@ public: class CCCInputIdentifier : CInputIdentifierBase { public: - CCCInputIdentifier(CCcontract_info* cp) : CInputIdentifierBase(cp) {} + CCCInputIdentifier(CC_info* cp) : CInputIdentifierBase(cp) {} virtual std::string inputName() const { return std::string("CC input"); } virtual bool identifyInput(CTxIn vin) const { return IsCCInput(vin.scriptSig); @@ -398,7 +398,7 @@ public: template class CCC1of2AddressValidator : CValidatorBase { public: - CCC1of2AddressValidator(CCcontract_info* cp, CScript opRetScript, std::string customMessage = "") : + CCC1of2AddressValidator(CC_info* cp, CScript opRetScript, std::string customMessage = "") : m_fundingOpretScript(opRetScript), m_customMessage(customMessage), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } @@ -452,7 +452,7 @@ private: template class CMyPubkeyVoutValidator : CValidatorBase { public: - CMyPubkeyVoutValidator(CCcontract_info* cp, CScript opRetScript, bool checkNormals) + CMyPubkeyVoutValidator(CC_info* cp, CScript opRetScript, bool checkNormals) : m_fundingOpretScript(opRetScript), m_checkNormals(checkNormals), CValidatorBase(cp) { } virtual bool isVinValidator() const { return false; } @@ -512,7 +512,7 @@ private: template class CHeirSpendValidator : CValidatorBase { public: - CHeirSpendValidator(CCcontract_info* cp, CScript opRetScript, uint256 latesttxid, uint8_t isHeirSpendingBegan) + CHeirSpendValidator(CC_info* cp, CScript opRetScript, uint256 latesttxid, uint8_t isHeirSpendingBegan) : m_fundingOpretScript(opRetScript), m_latesttxid(latesttxid), m_isHeirSpendingBegan(isHeirSpendingBegan), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } @@ -568,7 +568,7 @@ private: template class COpRetValidator : CValidatorBase { public: - COpRetValidator(CCcontract_info* cp, CScript opret) + COpRetValidator(CC_info* cp, CScript opret) : m_fundingOpretScript(opret), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } @@ -619,7 +619,7 @@ private: template class CNullValidator : CValidatorBase { public: - CNullValidator(CCcontract_info* cp) + CNullValidator(CC_info* cp) : CValidatorBase(cp) { } virtual bool isVinValidator() const { return false; } From 016548281c628b73107d3ebbe5d0f71885b2552c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:00:53 -1100 Subject: [PATCH 130/144] Payments address define --- src/rpc/server.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpc/server.h b/src/rpc/server.h index 92cbb5105..0166bca41 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -286,6 +286,7 @@ extern UniValue marmara_info(const UniValue& params, bool fHelp); extern UniValue marmara_creditloop(const UniValue& params, bool fHelp); extern UniValue marmara_settlement(const UniValue& params, bool fHelp); extern UniValue marmara_lock(const UniValue& params, bool fHelp); +extern UniValue paymentsaddress(const UniValue& params, bool fHelp); extern UniValue cclibaddress(const UniValue& params, bool fHelp); extern UniValue cclibinfo(const UniValue& params, bool fHelp); extern UniValue cclib(const UniValue& params, bool fHelp); From 3962a18c334c8062ab437abf9c1becb65ed8ff3e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:04:59 -1100 Subject: [PATCH 131/144] CC --- src/script/sign.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index b90ceafb5..cf44786b7 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -136,7 +136,7 @@ std::vector &GetCryptoConditions() return vCC; } -bool GetCCByUnspendableAddress(struct CCcontract_info *cp, char *addrstr) +bool GetCCByUnspendableAddress(struct CC_info *cp, char *addrstr) { std::vector &vCC = GetCryptoConditions(); bool found = false; From 607f47588b79c404bdde9b06fda4886595388552 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:06:02 -1100 Subject: [PATCH 132/144] x --- src/script/sign.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index cf44786b7..641d0a4d2 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -153,7 +153,7 @@ bool GetCCByUnspendableAddress(struct CC_info *cp, char *addrstr) return found; } -bool CCinitLite(struct CCcontract_info *cp, uint8_t evalcode) +bool CCinitLite(struct CC_info *cp, uint8_t evalcode) { std::vector &vCC = GetCryptoConditions(); bool found = false; From 4223d927ad5f46cba54f64355e25cd006e9442ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:12:28 -1100 Subject: [PATCH 133/144] struct CC_info --- src/cc/heir_validate.h | 1028 ++++++++++++++++++++-------------------- src/script/sign.cpp | 327 ++++++------- 2 files changed, 678 insertions(+), 677 deletions(-) diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 85f5b5c11..f8e66e3d5 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -22,100 +22,100 @@ inline static bool isSpendingTx(uint8_t funcid) { return (funcid == 'C'); } // helper class to allow polymorphic behaviour for HeirXXX() functions in case of coins class CoinHelper { public: - - static uint8_t getMyEval() { return EVAL_HEIR; } - static int64_t addOwnerInputs(uint256 dummyid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { - return AddNormalinputs(mtx, ownerPubkey, total, maxinputs); - } - - static CScript makeCreateOpRet(uint256 dummyid, std::vector dummyPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { - return EncodeHeirCreateOpRet((uint8_t)'F', ownerPubkey, heirPubkey, inactivityTimeSec, heirName); - } - static CScript makeAddOpRet(uint256 dummyid, std::vector dummyPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { - return EncodeHeirOpRet((uint8_t)'A', fundingtxid, isHeirSpendingBegan); - } - static CScript makeClaimOpRet(uint256 dummyid, std::vector dummyPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { - return EncodeHeirOpRet((uint8_t)'C', fundingtxid, isHeirSpendingBegan); - } - static CTxOut make1of2Vout(int64_t amount, CPubKey ownerPubkey, CPubKey heirPubkey) { - return MakeCC1of2vout(EVAL_HEIR, amount, ownerPubkey, heirPubkey); - } - static CTxOut makeUserVout(int64_t amount, CPubKey myPubkey) { - return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); - } -/* static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) { - return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); - } */ - static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - struct CC_info *cpHeir, heirC; - cpHeir = CCinit(&heirC, EVAL_HEIR); - return GetCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); - } - static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { - CCaddr1of2set(cp, ownerPubkey, heirPubkey, coinaddr); - } + + static uint8_t getMyEval() { return EVAL_HEIR; } + static int64_t addOwnerInputs(uint256 dummyid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { + return AddNormalinputs(mtx, ownerPubkey, total, maxinputs); + } + + static CScript makeCreateOpRet(uint256 dummyid, std::vector dummyPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { + return EncodeHeirCreateOpRet((uint8_t)'F', ownerPubkey, heirPubkey, inactivityTimeSec, heirName); + } + static CScript makeAddOpRet(uint256 dummyid, std::vector dummyPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { + return EncodeHeirOpRet((uint8_t)'A', fundingtxid, isHeirSpendingBegan); + } + static CScript makeClaimOpRet(uint256 dummyid, std::vector dummyPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { + return EncodeHeirOpRet((uint8_t)'C', fundingtxid, isHeirSpendingBegan); + } + static CTxOut make1of2Vout(int64_t amount, CPubKey ownerPubkey, CPubKey heirPubkey) { + return MakeCC1of2vout(EVAL_HEIR, amount, ownerPubkey, heirPubkey); + } + static CTxOut makeUserVout(int64_t amount, CPubKey myPubkey) { + return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); + } + /* static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) { + return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); + } */ + static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { + struct CC_info *cpHeir, heirC; + cpHeir = CCinit(&heirC, EVAL_HEIR); + return GetCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); + } + static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + CCaddr1of2set(cp, ownerPubkey, heirPubkey, coinaddr); + } }; // helper class to allow polymorphic behaviour for HeirXXX() functions in case of tokens class TokenHelper { public: - static uint8_t getMyEval() { return EVAL_TOKENS; } - static int64_t addOwnerInputs(uint256 tokenid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { - struct CC_info *cpHeir, heirC; - cpHeir = CCinit(&heirC, EVAL_TOKENS); - return AddTokenCCInputs(cpHeir, mtx, ownerPubkey, tokenid, total, maxinputs); - } - - static CScript makeCreateOpRet(uint256 tokenid, std::vector voutTokenPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { - return EncodeTokenOpRet(tokenid, voutTokenPubkeys, - EncodeHeirCreateOpRet((uint8_t)'F', ownerPubkey, heirPubkey, inactivityTimeSec, heirName)); - } - static CScript makeAddOpRet(uint256 tokenid, std::vector voutTokenPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { - return EncodeTokenOpRet(tokenid, voutTokenPubkeys, - EncodeHeirOpRet((uint8_t)'A', fundingtxid, isHeirSpendingBegan)); - } - static CScript makeClaimOpRet(uint256 tokenid, std::vector voutTokenPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { - return EncodeTokenOpRet(tokenid, voutTokenPubkeys, - EncodeHeirOpRet((uint8_t)'C', fundingtxid, isHeirSpendingBegan)); - } - - static CTxOut make1of2Vout(int64_t amount, CPubKey ownerPubkey, CPubKey heirPubkey) { - return MakeTokensCC1of2vout(EVAL_HEIR, amount, ownerPubkey, heirPubkey); - } - static CTxOut makeUserVout(int64_t amount, CPubKey myPubkey) { - return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS - } -/* static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) { - return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS - } */ - static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - struct CC_info *cpHeir, heirC; - cpHeir = CCinit(&heirC, EVAL_HEIR); - return GetTokensCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); - } - - static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { - - CCaddrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); - } + static uint8_t getMyEval() { return EVAL_TOKENS; } + static int64_t addOwnerInputs(uint256 tokenid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { + struct CC_info *cpHeir, heirC; + cpHeir = CCinit(&heirC, EVAL_TOKENS); + return AddTokenCCInputs(cpHeir, mtx, ownerPubkey, tokenid, total, maxinputs); + } + + static CScript makeCreateOpRet(uint256 tokenid, std::vector voutTokenPubkeys, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { + return EncodeTokenOpRet(tokenid, voutTokenPubkeys, + EncodeHeirCreateOpRet((uint8_t)'F', ownerPubkey, heirPubkey, inactivityTimeSec, heirName)); + } + static CScript makeAddOpRet(uint256 tokenid, std::vector voutTokenPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { + return EncodeTokenOpRet(tokenid, voutTokenPubkeys, + EncodeHeirOpRet((uint8_t)'A', fundingtxid, isHeirSpendingBegan)); + } + static CScript makeClaimOpRet(uint256 tokenid, std::vector voutTokenPubkeys, uint256 fundingtxid, uint8_t isHeirSpendingBegan) { + return EncodeTokenOpRet(tokenid, voutTokenPubkeys, + EncodeHeirOpRet((uint8_t)'C', fundingtxid, isHeirSpendingBegan)); + } + + static CTxOut make1of2Vout(int64_t amount, CPubKey ownerPubkey, CPubKey heirPubkey) { + return MakeTokensCC1of2vout(EVAL_HEIR, amount, ownerPubkey, heirPubkey); + } + static CTxOut makeUserVout(int64_t amount, CPubKey myPubkey) { + return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS + } + /* static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) { + return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS + } */ + static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { + struct CC_info *cpHeir, heirC; + cpHeir = CCinit(&heirC, EVAL_HEIR); + return GetTokensCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); + } + + static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + + CCaddrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); + } }; /** -* Small framework for vins and vouts validation implementing a variation of 'chain of responsibility' pattern: -* It consists of two classes CInputValidationPlan and COutputValidationPlan which both are configured with an array of vectors of validators -* (These validators are derived from the class CValidatorBase). -* -* A example of a validator may verify for a vout if its public key corresponds to the public key which is stored in opreturn. -* Or, vin validator may check if this vin depicts correctly to the CC contract's address. -* -* For validating vins CInputValidator additionally is provided with an instance of a class derived from the CInputIdentifierBase class. -* this identifier class allows to select identical vins (for example, normal vins or cc input vins) and apply validators from the corresponding vector to it. -* Note: CInputValidator treats that at least one identified vin should be present, otherwise it returns eval->invalid() and false. -* -* For validating vouts COutputValidator is configured for each vector of validators with the vout index to which these validators are applied -* (see constructors of both CInputValidator and COutputValidator) -*/ + * Small framework for vins and vouts validation implementing a variation of 'chain of responsibility' pattern: + * It consists of two classes CInputValidationPlan and COutputValidationPlan which both are configured with an array of vectors of validators + * (These validators are derived from the class CValidatorBase). + * + * A example of a validator may verify for a vout if its public key corresponds to the public key which is stored in opreturn. + * Or, vin validator may check if this vin depicts correctly to the CC contract's address. + * + * For validating vins CInputValidator additionally is provided with an instance of a class derived from the CInputIdentifierBase class. + * this identifier class allows to select identical vins (for example, normal vins or cc input vins) and apply validators from the corresponding vector to it. + * Note: CInputValidator treats that at least one identified vin should be present, otherwise it returns eval->invalid() and false. + * + * For validating vouts COutputValidator is configured for each vector of validators with the vout index to which these validators are applied + * (see constructors of both CInputValidator and COutputValidator) + */ /** * base class for all validators @@ -123,13 +123,13 @@ public: class CValidatorBase { public: - CValidatorBase(CC_info* cp) : m_cp(cp) {} - virtual bool isVinValidator() const = 0; - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const = 0; - virtual bool validateVout(CTxOut vout, std::string& message) const = 0; - + CValidatorBase(CCcontract_info* cp) : m_cp(cp) {} + virtual bool isVinValidator() const = 0; + virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const = 0; + virtual bool validateVout(CTxOut vout, std::string& message) const = 0; + protected: - CC_info * m_cp; + CCcontract_info * m_cp; }; /** @@ -138,493 +138,493 @@ protected: class CInputIdentifierBase { public: - CInputIdentifierBase(CC_info* cp) : m_cp(cp) {} - virtual std::string inputName() const = 0; - virtual bool identifyInput(CTxIn vin) const = 0; + CInputIdentifierBase(CCcontract_info* cp) : m_cp(cp) {} + virtual std::string inputName() const = 0; + virtual bool identifyInput(CTxIn vin) const = 0; protected: - CC_info * m_cp; + CCcontract_info * m_cp; }; /** -* Encapsulates an array containing rows of validators -* Each row is a vector of validators (zero is possible) for validating vins or prev tx's vouts -* this validation plan is used for validating tx inputs -*/ + * Encapsulates an array containing rows of validators + * Each row is a vector of validators (zero is possible) for validating vins or prev tx's vouts + * this validation plan is used for validating tx inputs + */ template class CInputValidationPlan { - using ValidatorsRow = std::vector; - + using ValidatorsRow = std::vector; + public: - - // Pushes a row of validators for validating a vin or vout - // @param CInputIdentifierBase* pointer to class-identifier which determines several identical adjacent vins (like in schema "vin.0+: normal inputs") - // @param pargs parameter pack of zero or more pointer to validator objects - // Why pointers? because we store the base class in validators' row and then call its virtual functions - template - void pushValidators(CInputIdentifierBase *identifier, ARGS*... pargs) // validators row passed as variadic arguments CValidatorX *val1, CValidatorY *val2 ... - { - ValidatorsRow vValidators({ (TValidatorBase*)pargs... }); - m_arrayValidators.push_back(std::make_pair(identifier, vValidators)); - } - - // validate tx inputs and corresponding prev tx vouts - bool validate(const CTransaction& tx, Eval* eval) - { - std::string message = ""; - //std::cerr << "CInputValidationPlan::validate() starting vins validation..." << std::endl; - - int32_t ival = 0; - int32_t iv = 0; - int32_t numv = tx.vin.size(); - int32_t numValidators = m_arrayValidators.size(); - - // run over vins: - while (iv < numv && ival < numValidators) { - - int32_t identifiedCount = 0; - CInputIdentifierBase *identifier = m_arrayValidators[ival].first; - // check if this is 'our' input: - while (iv < numv && identifier->identifyInput(tx.vin[iv])) { - - // get prev tx: - CTransaction prevTx, *pPrevTxOrNull = NULL; - uint256 hashBlock; - - if (!eval->GetTxUnconfirmed(tx.vin[iv].prevout.hash, prevTx, hashBlock)) { - std::ostringstream stream; - stream << "can't find vinTx for vin=" << iv << "."; - return eval->Invalid(stream.str().c_str()); - } - pPrevTxOrNull = &prevTx; // TODO: get prev tx only if it required (i.e. if vout validators are present) - - // exec 'validators' from validator row of ival index, for tx.vin[iv] - if (!execValidatorsInRow(&tx, pPrevTxOrNull, iv, ival, message)) { - std::ostringstream stream; - stream << "invalid tx vin[" << iv << "]:" << message; - return eval->Invalid(stream.str().c_str()); // ... if not, return 'invalid' - } - - identifiedCount++; // how many vins we identified - iv++; // advance to the next vin - } - - // CInputValidationPlan treats that there must be at least one identified vin for configured validators' row - // like in 'vin.0: normal input' - if (identifiedCount == 0) { - std::ostringstream stream; - stream << "can't find required vins for " << identifier->inputName() << "."; - return eval->Invalid(stream.str().c_str()); - } - - ival++; // advance to the next validator row - // and it will try the same vin with the new CInputIdentifierBase and validators row - } - - // validation is successful if all validators have been used (i.e. ival = numValidators) - if (ival < numValidators) { - std::cerr << "CInputValidationPlan::validate() incorrect tx" << " ival=" << ival << " numValidators=" << numValidators << std::endl; - return eval->Invalid("incorrect tx structure: not all required vins are present."); - } - - //std::cerr << "CInputValidationPlan::validate() returns with true" << std::endl; - return true; - } - + + // Pushes a row of validators for validating a vin or vout + // @param CInputIdentifierBase* pointer to class-identifier which determines several identical adjacent vins (like in schema "vin.0+: normal inputs") + // @param pargs parameter pack of zero or more pointer to validator objects + // Why pointers? because we store the base class in validators' row and then call its virtual functions + template + void pushValidators(CInputIdentifierBase *identifier, ARGS*... pargs) // validators row passed as variadic arguments CValidatorX *val1, CValidatorY *val2 ... + { + ValidatorsRow vValidators({ (TValidatorBase*)pargs... }); + m_arrayValidators.push_back(std::make_pair(identifier, vValidators)); + } + + // validate tx inputs and corresponding prev tx vouts + bool validate(const CTransaction& tx, Eval* eval) + { + std::string message = ""; + //std::cerr << "CInputValidationPlan::validate() starting vins validation..." << std::endl; + + int32_t ival = 0; + int32_t iv = 0; + int32_t numv = tx.vin.size(); + int32_t numValidators = m_arrayValidators.size(); + + // run over vins: + while (iv < numv && ival < numValidators) { + + int32_t identifiedCount = 0; + CInputIdentifierBase *identifier = m_arrayValidators[ival].first; + // check if this is 'our' input: + while (iv < numv && identifier->identifyInput(tx.vin[iv])) { + + // get prev tx: + CTransaction prevTx, *pPrevTxOrNull = NULL; + uint256 hashBlock; + + if (!eval->GetTxUnconfirmed(tx.vin[iv].prevout.hash, prevTx, hashBlock)) { + std::ostringstream stream; + stream << "can't find vinTx for vin=" << iv << "."; + return eval->Invalid(stream.str().c_str()); + } + pPrevTxOrNull = &prevTx; // TODO: get prev tx only if it required (i.e. if vout validators are present) + + // exec 'validators' from validator row of ival index, for tx.vin[iv] + if (!execValidatorsInRow(&tx, pPrevTxOrNull, iv, ival, message)) { + std::ostringstream stream; + stream << "invalid tx vin[" << iv << "]:" << message; + return eval->Invalid(stream.str().c_str()); // ... if not, return 'invalid' + } + + identifiedCount++; // how many vins we identified + iv++; // advance to the next vin + } + + // CInputValidationPlan treats that there must be at least one identified vin for configured validators' row + // like in 'vin.0: normal input' + if (identifiedCount == 0) { + std::ostringstream stream; + stream << "can't find required vins for " << identifier->inputName() << "."; + return eval->Invalid(stream.str().c_str()); + } + + ival++; // advance to the next validator row + // and it will try the same vin with the new CInputIdentifierBase and validators row + } + + // validation is successful if all validators have been used (i.e. ival = numValidators) + if (ival < numValidators) { + std::cerr << "CInputValidationPlan::validate() incorrect tx" << " ival=" << ival << " numValidators=" << numValidators << std::endl; + return eval->Invalid("incorrect tx structure: not all required vins are present."); + } + + //std::cerr << "CInputValidationPlan::validate() returns with true" << std::endl; + return true; + } + private: - // Executes validators from the requested row of validators (selected by iValidators) for selected vin or vout (selected by iv) - bool execValidatorsInRow(const CTransaction* pTx, const CTransaction* pPrevTx, int32_t iv, int32_t ival, std::string& refMessage) const - { - // check boundaries: - if (ival < 0 || ival >= m_arrayValidators.size()) { - std::cerr << "CInputValidationPlan::execValidatorsInRow() internal error: incorrect param ival=" << ival << " size=" << m_arrayValidators.size(); - refMessage = "internal error: incorrect param ival index"; - return false; - } - - if (iv < 0 || iv >= pTx->vin.size()) { - std::cerr << "CInputValidationPlan::execValidatorsInRow() internal error: incorrect param iv=" << iv << " size=" << m_arrayValidators.size(); - refMessage = "internal error: incorrect param iv index"; - return false; - } - - // get requested row of validators: - ValidatorsRow vValidators = m_arrayValidators[ival].second; - - //std::cerr << "CInputValidationPlan::execValidatorsInRow() calling validators" << " for vin iv=" << iv << " ival=" << ival << std::endl; - - for (auto v : vValidators) { - bool result; - - if (v->isVinValidator()) - // validate this vin and previous vout: - result = v->validateVin(pTx->vin[iv], pPrevTx->vout[pTx->vin[iv].prevout.n], refMessage); - else - // if it is vout validator pass the previous tx vout: - result = v->validateVout( pPrevTx->vout[pTx->vin[iv].prevout.n], refMessage); - if (!result) { - return result; - } - } - return true; // validation OK - } - - + // Executes validators from the requested row of validators (selected by iValidators) for selected vin or vout (selected by iv) + bool execValidatorsInRow(const CTransaction* pTx, const CTransaction* pPrevTx, int32_t iv, int32_t ival, std::string& refMessage) const + { + // check boundaries: + if (ival < 0 || ival >= m_arrayValidators.size()) { + std::cerr << "CInputValidationPlan::execValidatorsInRow() internal error: incorrect param ival=" << ival << " size=" << m_arrayValidators.size(); + refMessage = "internal error: incorrect param ival index"; + return false; + } + + if (iv < 0 || iv >= pTx->vin.size()) { + std::cerr << "CInputValidationPlan::execValidatorsInRow() internal error: incorrect param iv=" << iv << " size=" << m_arrayValidators.size(); + refMessage = "internal error: incorrect param iv index"; + return false; + } + + // get requested row of validators: + ValidatorsRow vValidators = m_arrayValidators[ival].second; + + //std::cerr << "CInputValidationPlan::execValidatorsInRow() calling validators" << " for vin iv=" << iv << " ival=" << ival << std::endl; + + for (auto v : vValidators) { + bool result; + + if (v->isVinValidator()) + // validate this vin and previous vout: + result = v->validateVin(pTx->vin[iv], pPrevTx->vout[pTx->vin[iv].prevout.n], refMessage); + else + // if it is vout validator pass the previous tx vout: + result = v->validateVout( pPrevTx->vout[pTx->vin[iv].prevout.n], refMessage); + if (!result) { + return result; + } + } + return true; // validation OK + } + + private: - //std::map m_arrayValidators; - std::vector< std::pair > m_arrayValidators; - + //std::map m_arrayValidators; + std::vector< std::pair > m_arrayValidators; + }; /** -* Encapsulates an array containing rows of validators -* Each row is a vector of validators (zero is possible) for validating vouts -* this validation plan is used for validating tx outputs -*/ + * Encapsulates an array containing rows of validators + * Each row is a vector of validators (zero is possible) for validating vouts + * this validation plan is used for validating tx outputs + */ template class COutputValidationPlan { - using ValidatorsRow = std::vector; - + using ValidatorsRow = std::vector; + public: - // Pushes a row of validators for validating a vout - // @param ivout index to vout to validate - // @param pargs parameter pack of zero or more pointer to validator objects - // Why pointers? because we store base class and call its virtual functions - - template - void pushValidators(int32_t ivout, ARGS*... pargs) // validators row passed as variadic arguments CValidatorX *val1, CValidatorY *val2 ... - { - ValidatorsRow vValidators({ (TValidatorBase*)pargs... }); - m_arrayValidators.push_back(std::make_pair(ivout, vValidators)); - } - - // validate tx outputs - bool validate(const CTransaction& tx, Eval* eval) - { - std::string message = ""; - //std::cerr << "COutputValidationPlan::validateOutputs() starting vouts validation..." << std::endl; - - int32_t ival = 0; - int32_t numVouts = tx.vout.size(); - int32_t numValidators = m_arrayValidators.size(); - - // run over vouts: - while (ival < numValidators) { - - int32_t ivout = m_arrayValidators[ival].first; - if (ivout >= numVouts) { - std::cerr << "COutputValidationPlan::validate() incorrect tx" << "for ival=" << ival << " in tx.vout no such ivout=" << ivout << std::endl; - return eval->Invalid("incorrect tx structure: not all required vouts are present."); - } - else - { - // exec 'validators' from validator row of ival index, for tx.vout[ivout] - if (!execValidatorsInRow(&tx, ivout, ival, message)) { - std::ostringstream stream; - stream << "invalid tx vout[" << ivout << "]:" << message; - return eval->Invalid(stream.str().c_str()); // ... if not, return 'invalid' - } - } - ival++; // advance to the next vout - } - //std::cerr << "COutputValidationPlan::validate() returns with true" << std::endl; - return true; - } - + // Pushes a row of validators for validating a vout + // @param ivout index to vout to validate + // @param pargs parameter pack of zero or more pointer to validator objects + // Why pointers? because we store base class and call its virtual functions + + template + void pushValidators(int32_t ivout, ARGS*... pargs) // validators row passed as variadic arguments CValidatorX *val1, CValidatorY *val2 ... + { + ValidatorsRow vValidators({ (TValidatorBase*)pargs... }); + m_arrayValidators.push_back(std::make_pair(ivout, vValidators)); + } + + // validate tx outputs + bool validate(const CTransaction& tx, Eval* eval) + { + std::string message = ""; + //std::cerr << "COutputValidationPlan::validateOutputs() starting vouts validation..." << std::endl; + + int32_t ival = 0; + int32_t numVouts = tx.vout.size(); + int32_t numValidators = m_arrayValidators.size(); + + // run over vouts: + while (ival < numValidators) { + + int32_t ivout = m_arrayValidators[ival].first; + if (ivout >= numVouts) { + std::cerr << "COutputValidationPlan::validate() incorrect tx" << "for ival=" << ival << " in tx.vout no such ivout=" << ivout << std::endl; + return eval->Invalid("incorrect tx structure: not all required vouts are present."); + } + else + { + // exec 'validators' from validator row of ival index, for tx.vout[ivout] + if (!execValidatorsInRow(&tx, ivout, ival, message)) { + std::ostringstream stream; + stream << "invalid tx vout[" << ivout << "]:" << message; + return eval->Invalid(stream.str().c_str()); // ... if not, return 'invalid' + } + } + ival++; // advance to the next vout + } + //std::cerr << "COutputValidationPlan::validate() returns with true" << std::endl; + return true; + } + private: - // Executes validators from the requested row of validators (selected by iValidators) for selected vin or vout (selected by iv) - bool execValidatorsInRow(const CTransaction* pTx, int32_t iv, int32_t ival, std::string& refMessage) const - { - // check boundaries: - if (ival < 0 || ival >= m_arrayValidators.size()) { - std::cerr << "COutputValidationPlan::execValidatorsInRow() internal error: incorrect param ival=" << ival << " size=" << m_arrayValidators.size(); - refMessage = "internal error: incorrect param ival index"; - return false; - } - - if (iv < 0 || iv >= pTx->vout.size()) { - std::cerr << "COutputValidationPlan::execValidatorsInRow() internal error: incorrect param iv=" << iv << " size=" << m_arrayValidators.size(); - refMessage = "internal error: incorrect param iv index"; - return false; - } - - // get requested row of validators: - ValidatorsRow vValidators = m_arrayValidators[ival].second; - - //std::cerr << "COutputValidationPlan::execRow() calling validators" << " for vout iv=" << iv << " ival=" << ival << std::endl; - - for (auto v : vValidators) { - - if (!v->isVinValidator()) { - // if this is a 'in' validation plan then pass the previous tx vout: - bool result = v->validateVout(pTx->vout[iv], refMessage); - if (!result) - return result; - } - } - return true; // validation OK - } - + // Executes validators from the requested row of validators (selected by iValidators) for selected vin or vout (selected by iv) + bool execValidatorsInRow(const CTransaction* pTx, int32_t iv, int32_t ival, std::string& refMessage) const + { + // check boundaries: + if (ival < 0 || ival >= m_arrayValidators.size()) { + std::cerr << "COutputValidationPlan::execValidatorsInRow() internal error: incorrect param ival=" << ival << " size=" << m_arrayValidators.size(); + refMessage = "internal error: incorrect param ival index"; + return false; + } + + if (iv < 0 || iv >= pTx->vout.size()) { + std::cerr << "COutputValidationPlan::execValidatorsInRow() internal error: incorrect param iv=" << iv << " size=" << m_arrayValidators.size(); + refMessage = "internal error: incorrect param iv index"; + return false; + } + + // get requested row of validators: + ValidatorsRow vValidators = m_arrayValidators[ival].second; + + //std::cerr << "COutputValidationPlan::execRow() calling validators" << " for vout iv=" << iv << " ival=" << ival << std::endl; + + for (auto v : vValidators) { + + if (!v->isVinValidator()) { + // if this is a 'in' validation plan then pass the previous tx vout: + bool result = v->validateVout(pTx->vout[iv], refMessage); + if (!result) + return result; + } + } + return true; // validation OK + } + private: - //std::map m_mapValidators; - std::vector< std::pair > m_arrayValidators; - + //std::map m_mapValidators; + std::vector< std::pair > m_arrayValidators; + }; class CNormalInputIdentifier : CInputIdentifierBase { public: - CNormalInputIdentifier(CC_info* cp) : CInputIdentifierBase(cp) {} - virtual std::string inputName() const { return std::string("normal input"); } - virtual bool identifyInput(CTxIn vin) const { - return !IsCCInput(vin.scriptSig); - } + CNormalInputIdentifier(CCcontract_info* cp) : CInputIdentifierBase(cp) {} + virtual std::string inputName() const { return std::string("normal input"); } + virtual bool identifyInput(CTxIn vin) const { + return !IsCCInput(vin.scriptSig); + } }; class CCCInputIdentifier : CInputIdentifierBase { public: - CCCInputIdentifier(CC_info* cp) : CInputIdentifierBase(cp) {} - virtual std::string inputName() const { return std::string("CC input"); } - virtual bool identifyInput(CTxIn vin) const { - return IsCCInput(vin.scriptSig); - } + CCCInputIdentifier(CCcontract_info* cp) : CInputIdentifierBase(cp) {} + virtual std::string inputName() const { return std::string("CC input"); } + virtual bool identifyInput(CTxIn vin) const { + return IsCCInput(vin.scriptSig); + } }; /** -* Validates 1of2address for vout (may be used for either this or prev tx) -*/ + * Validates 1of2address for vout (may be used for either this or prev tx) + */ template class CCC1of2AddressValidator : CValidatorBase { public: - CCC1of2AddressValidator(CC_info* cp, CScript opRetScript, std::string customMessage = "") : - m_fundingOpretScript(opRetScript), m_customMessage(customMessage), CValidatorBase(cp) {} - - virtual bool isVinValidator() const { return false; } - virtual bool validateVout(CTxOut vout, std::string& message) const - { - //std::cerr << "CCC1of2AddressValidator::validateVout() entered" << std::endl; - CPubKey ownerPubkey, heirPubkey; - int64_t inactivityTime; - std::string heirName; - uint256 tokenid; - - uint8_t funcId = DecodeHeirEitherOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true); - if (funcId == 0) { - message = m_customMessage + std::string(" invalid opreturn format"); - std::cerr << "CCC1of2AddressValidator::validateVout() exits with false: " << message << std::endl; - return false; - } - - char shouldBeAddr[65], ccAddr[65]; - - //GetCCaddress1of2(m_cp, shouldBeAddr, ownerPubkey, heirPubkey); - Helper::GetCoinsOrTokensCCaddress1of2(shouldBeAddr, ownerPubkey, heirPubkey); - - if (vout.scriptPubKey.IsPayToCryptoCondition()) { - if (Getscriptaddress(ccAddr, vout.scriptPubKey) && strcmp(shouldBeAddr, ccAddr) == 0) { - //std::cerr << "CCC1of2AddressValidator::validateVout() exits with true" << std::endl; - return true; - } - else { - message = m_customMessage + std::string(" incorrect heir funding address: incorrect pubkey(s)"); - } - } - else { - message = m_customMessage + std::string(" incorrect heir funding address: not a 1of2addr"); - } - - std::cerr << "CCC1of2AddressValidator::validateVout() exits with false: " << message << std::endl; - return false; - } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return false; } - + CCC1of2AddressValidator(CCcontract_info* cp, CScript opRetScript, std::string customMessage = "") : + m_fundingOpretScript(opRetScript), m_customMessage(customMessage), CValidatorBase(cp) {} + + virtual bool isVinValidator() const { return false; } + virtual bool validateVout(CTxOut vout, std::string& message) const + { + //std::cerr << "CCC1of2AddressValidator::validateVout() entered" << std::endl; + CPubKey ownerPubkey, heirPubkey; + int64_t inactivityTime; + std::string heirName; + uint256 tokenid; + + uint8_t funcId = DecodeHeirEitherOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true); + if (funcId == 0) { + message = m_customMessage + std::string(" invalid opreturn format"); + std::cerr << "CCC1of2AddressValidator::validateVout() exits with false: " << message << std::endl; + return false; + } + + char shouldBeAddr[65], ccAddr[65]; + + //GetCCaddress1of2(m_cp, shouldBeAddr, ownerPubkey, heirPubkey); + Helper::GetCoinsOrTokensCCaddress1of2(shouldBeAddr, ownerPubkey, heirPubkey); + + if (vout.scriptPubKey.IsPayToCryptoCondition()) { + if (Getscriptaddress(ccAddr, vout.scriptPubKey) && strcmp(shouldBeAddr, ccAddr) == 0) { + //std::cerr << "CCC1of2AddressValidator::validateVout() exits with true" << std::endl; + return true; + } + else { + message = m_customMessage + std::string(" incorrect heir funding address: incorrect pubkey(s)"); + } + } + else { + message = m_customMessage + std::string(" incorrect heir funding address: not a 1of2addr"); + } + + std::cerr << "CCC1of2AddressValidator::validateVout() exits with false: " << message << std::endl; + return false; + } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return false; } + private: - CScript m_fundingOpretScript; - std::string m_customMessage; + CScript m_fundingOpretScript; + std::string m_customMessage; }; /** -* Validates if this is vout to owner or heir from opret (funding or change) -*/ + * Validates if this is vout to owner or heir from opret (funding or change) + */ template class CMyPubkeyVoutValidator : CValidatorBase { public: - CMyPubkeyVoutValidator(CC_info* cp, CScript opRetScript, bool checkNormals) - : m_fundingOpretScript(opRetScript), m_checkNormals(checkNormals), CValidatorBase(cp) { } - - virtual bool isVinValidator() const { return false; } - virtual bool validateVout(CTxOut vout, std::string& message) const - { - //std::cerr << "CMyPubkeyVoutValidator::validateVout() entered" << std::endl; - - CPubKey ownerPubkey, heirPubkey; - int64_t inactivityTime; - std::string heirName; - uint256 tokenid; - - ///std::cerr << "CMyPubkeyVoutValidator::validateVout() m_opRetScript=" << m_opRetScript.ToString() << std::endl; - - // get both pubkeys: - uint8_t funcId = DecodeHeirEitherOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true); - if (funcId == 0) { - message = std::string("invalid opreturn format"); - return false; - } - - CScript ownerScript; - CScript heirScript; - if (m_checkNormals) { //not used, incorrect check, too strict - ownerScript = CoinHelper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey; - heirScript = CoinHelper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey; - std::cerr << "CMyPubkeyVoutValidator::validateVout() vout.scriptPubKey=" << vout.scriptPubKey.ToString() << " makeUserVout(coin,owner)=" << CoinHelper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey.ToString() << " makeUserVout(coin,heir)=" << CoinHelper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey.ToString() << std::endl; - } - else { - ownerScript = Helper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey; - heirScript = Helper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey; - std::cerr << "CMyPubkeyVoutValidator::validateVout() vout.scriptPubKey=" << vout.scriptPubKey.ToString() << " makeUserVout(owner)=" << Helper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey.ToString() << " makeUserVout(heir)=" << Helper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey.ToString() << std::endl; - } - - // recreate scriptPubKey for owner and heir and compare it with that of the vout to check: - if (vout.scriptPubKey == ownerScript || vout.scriptPubKey == heirScript) { - // this is vout to owner or heir addr: - //std::cerr << "CMyPubkeyVoutValidator::validateVout() exits with true" << std::endl; - return true; - } - - std::cerr << "CMyPubkeyVoutValidator::validateVout() exits with false (not the owner's or heir's addresses)" << std::endl; - message = std::string("invalid pubkey"); - return false; - } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } - + CMyPubkeyVoutValidator(CCcontract_info* cp, CScript opRetScript, bool checkNormals) + : m_fundingOpretScript(opRetScript), m_checkNormals(checkNormals), CValidatorBase(cp) { } + + virtual bool isVinValidator() const { return false; } + virtual bool validateVout(CTxOut vout, std::string& message) const + { + //std::cerr << "CMyPubkeyVoutValidator::validateVout() entered" << std::endl; + + CPubKey ownerPubkey, heirPubkey; + int64_t inactivityTime; + std::string heirName; + uint256 tokenid; + + ///std::cerr << "CMyPubkeyVoutValidator::validateVout() m_opRetScript=" << m_opRetScript.ToString() << std::endl; + + // get both pubkeys: + uint8_t funcId = DecodeHeirEitherOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true); + if (funcId == 0) { + message = std::string("invalid opreturn format"); + return false; + } + + CScript ownerScript; + CScript heirScript; + if (m_checkNormals) { //not used, incorrect check, too strict + ownerScript = CoinHelper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey; + heirScript = CoinHelper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey; + std::cerr << "CMyPubkeyVoutValidator::validateVout() vout.scriptPubKey=" << vout.scriptPubKey.ToString() << " makeUserVout(coin,owner)=" << CoinHelper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey.ToString() << " makeUserVout(coin,heir)=" << CoinHelper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey.ToString() << std::endl; + } + else { + ownerScript = Helper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey; + heirScript = Helper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey; + std::cerr << "CMyPubkeyVoutValidator::validateVout() vout.scriptPubKey=" << vout.scriptPubKey.ToString() << " makeUserVout(owner)=" << Helper::makeUserVout(vout.nValue, ownerPubkey).scriptPubKey.ToString() << " makeUserVout(heir)=" << Helper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey.ToString() << std::endl; + } + + // recreate scriptPubKey for owner and heir and compare it with that of the vout to check: + if (vout.scriptPubKey == ownerScript || vout.scriptPubKey == heirScript) { + // this is vout to owner or heir addr: + //std::cerr << "CMyPubkeyVoutValidator::validateVout() exits with true" << std::endl; + return true; + } + + std::cerr << "CMyPubkeyVoutValidator::validateVout() exits with false (not the owner's or heir's addresses)" << std::endl; + message = std::string("invalid pubkey"); + return false; + } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } + private: - CScript m_fundingOpretScript; - //uint256 m_lasttxid; - bool m_checkNormals; + CScript m_fundingOpretScript; + //uint256 m_lasttxid; + bool m_checkNormals; }; /** -* Check if the user is the heir and the heir is allowed to spend (duration > inactivityTime) -*/ + * Check if the user is the heir and the heir is allowed to spend (duration > inactivityTime) + */ template class CHeirSpendValidator : CValidatorBase { public: - CHeirSpendValidator(CC_info* cp, CScript opRetScript, uint256 latesttxid, uint8_t isHeirSpendingBegan) - : m_fundingOpretScript(opRetScript), m_latesttxid(latesttxid), m_isHeirSpendingBegan(isHeirSpendingBegan), CValidatorBase(cp) {} - - virtual bool isVinValidator() const { return false; } - virtual bool validateVout(CTxOut vout, std::string& message) const - { - //std::cerr << "CHeirSpendValidator::validateVout() entered" << std::endl; - - CPubKey ownerPubkey, heirPubkey; - int64_t inactivityTime; - std::string heirName; - uint256 tokenid; - - // get heir pubkey: - uint8_t funcId = DecodeHeirEitherOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true); - if (funcId == 0) { - message = std::string("invalid opreturn format"); - return false; - } - - int32_t numblocks; - int64_t durationSec = CCduration(numblocks, m_latesttxid); - - // recreate scriptPubKey for heir and compare it with that of the vout: - if (vout.scriptPubKey == Helper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey) { - // this is the heir is trying to spend - if (!m_isHeirSpendingBegan && durationSec <= inactivityTime) { - message = "heir is not allowed yet to spend funds"; - std::cerr << "CHeirSpendValidator::validateVout() heir is not allowed yet to spend funds" << std::endl; - return false; - } - else { - // heir is allowed to spend - return true; - } - } - - //std::cerr << "CHeirSpendValidator::validateVout() exits with true" << std::endl; - - // this is not heir: - return true; - } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } - + CHeirSpendValidator(CCcontract_info* cp, CScript opRetScript, uint256 latesttxid, uint8_t isHeirSpendingBegan) + : m_fundingOpretScript(opRetScript), m_latesttxid(latesttxid), m_isHeirSpendingBegan(isHeirSpendingBegan), CValidatorBase(cp) {} + + virtual bool isVinValidator() const { return false; } + virtual bool validateVout(CTxOut vout, std::string& message) const + { + //std::cerr << "CHeirSpendValidator::validateVout() entered" << std::endl; + + CPubKey ownerPubkey, heirPubkey; + int64_t inactivityTime; + std::string heirName; + uint256 tokenid; + + // get heir pubkey: + uint8_t funcId = DecodeHeirEitherOpRet(m_fundingOpretScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true); + if (funcId == 0) { + message = std::string("invalid opreturn format"); + return false; + } + + int32_t numblocks; + int64_t durationSec = CCduration(numblocks, m_latesttxid); + + // recreate scriptPubKey for heir and compare it with that of the vout: + if (vout.scriptPubKey == Helper::makeUserVout(vout.nValue, heirPubkey).scriptPubKey) { + // this is the heir is trying to spend + if (!m_isHeirSpendingBegan && durationSec <= inactivityTime) { + message = "heir is not allowed yet to spend funds"; + std::cerr << "CHeirSpendValidator::validateVout() heir is not allowed yet to spend funds" << std::endl; + return false; + } + else { + // heir is allowed to spend + return true; + } + } + + //std::cerr << "CHeirSpendValidator::validateVout() exits with true" << std::endl; + + // this is not heir: + return true; + } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } + private: - CScript m_fundingOpretScript; - uint256 m_latesttxid; - uint8_t m_isHeirSpendingBegan; + CScript m_fundingOpretScript; + uint256 m_latesttxid; + uint8_t m_isHeirSpendingBegan; }; /** -* Validates this opreturn and compares it with the opreturn from the previous tx -*/ + * Validates this opreturn and compares it with the opreturn from the previous tx + */ template class COpRetValidator : CValidatorBase { public: - COpRetValidator(CC_info* cp, CScript opret) - : m_fundingOpretScript(opret), CValidatorBase(cp) {} - - virtual bool isVinValidator() const { return false; } - virtual bool validateVout(CTxOut vout, std::string& message) const - { - //std::cerr << "COpRetValidator::validateVout() entered" << std::endl; - - uint256 fundingTxidInOpret = zeroid, dummyTxid, tokenid = zeroid, initialTokenid = zeroid; - uint8_t dummyIsHeirSpendingBegan; - - uint8_t funcId = DecodeHeirEitherOpRet(vout.scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); - if (funcId == 0) { - message = std::string("invalid opreturn format"); - return false; - } - - uint8_t initialFuncId = DecodeHeirEitherOpRet(m_fundingOpretScript, initialTokenid, dummyTxid, dummyIsHeirSpendingBegan, true); - if (initialFuncId == 0) { - message = std::string("invalid initial tx opreturn format"); - return false; - } - - // validation rules: - if (!isMyFuncId(funcId)) { - message = std::string("invalid funcid in opret"); - return false; - } - - if (typeid(Helper) == typeid(TokenHelper)) { - if (tokenid != initialTokenid) { - message = std::string("invalid tokenid in opret"); - return false; - } - } - - //std::cerr << "COpRetValidator::validateVout() exits with true" << std::endl; - return true; - } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } - + COpRetValidator(CCcontract_info* cp, CScript opret) + : m_fundingOpretScript(opret), CValidatorBase(cp) {} + + virtual bool isVinValidator() const { return false; } + virtual bool validateVout(CTxOut vout, std::string& message) const + { + //std::cerr << "COpRetValidator::validateVout() entered" << std::endl; + + uint256 fundingTxidInOpret = zeroid, dummyTxid, tokenid = zeroid, initialTokenid = zeroid; + uint8_t dummyIsHeirSpendingBegan; + + uint8_t funcId = DecodeHeirEitherOpRet(vout.scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); + if (funcId == 0) { + message = std::string("invalid opreturn format"); + return false; + } + + uint8_t initialFuncId = DecodeHeirEitherOpRet(m_fundingOpretScript, initialTokenid, dummyTxid, dummyIsHeirSpendingBegan, true); + if (initialFuncId == 0) { + message = std::string("invalid initial tx opreturn format"); + return false; + } + + // validation rules: + if (!isMyFuncId(funcId)) { + message = std::string("invalid funcid in opret"); + return false; + } + + if (typeid(Helper) == typeid(TokenHelper)) { + if (tokenid != initialTokenid) { + message = std::string("invalid tokenid in opret"); + return false; + } + } + + //std::cerr << "COpRetValidator::validateVout() exits with true" << std::endl; + return true; + } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } + private: - CScript m_fundingOpretScript; + CScript m_fundingOpretScript; }; /** -* empty validator always returns true -*/ + * empty validator always returns true + */ template class CNullValidator : CValidatorBase { public: - CNullValidator(CC_info* cp) - : CValidatorBase(cp) { } - - virtual bool isVinValidator() const { return false; } - virtual bool validateVout(CTxOut vout, std::string& message) const { return true; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } + CNullValidator(CCcontract_info* cp) + : CValidatorBase(cp) { } + + virtual bool isVinValidator() const { return false; } + virtual bool validateVout(CTxOut vout, std::string& message) const { return true; } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } }; diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 641d0a4d2..f7f663db2 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -45,14 +45,14 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, key = *pprivKey; else if (!keystore || !keystore->GetKey(address, key)) return false; - + uint256 hash; try { hash = SignatureHash(scriptCode, *txTo, nIn, nHashType, amount, consensusBranchId); } catch (logic_error ex) { return false; } - + if (scriptCode.IsPayToCryptoCondition()) { CC *cc = (CC *)extraData; @@ -75,9 +75,9 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, return false; } } - + vchSig.push_back((unsigned char)nHashType); - + return true; } @@ -128,7 +128,7 @@ std::vector &GetCryptoConditions() static bool initialized = false; static std::vector vCC = std::vector(); CCcontract_info C; - + if (!initialized) { // this should initialize any desired auto-signed crypto-conditions @@ -140,7 +140,7 @@ bool GetCCByUnspendableAddress(struct CC_info *cp, char *addrstr) { std::vector &vCC = GetCryptoConditions(); bool found = false; - + for (int i = 0; i < vCC.size(); i++) { if (strcmp(addrstr, vCC[i].unspendableCCaddr) == 0) @@ -157,7 +157,7 @@ bool CCinitLite(struct CC_info *cp, uint8_t evalcode) { std::vector &vCC = GetCryptoConditions(); bool found = false; - + for (int i = 0; i < vCC.size(); i++) { if (vCC[i].evalcode == evalcode) @@ -172,7 +172,7 @@ bool CCinitLite(struct CC_info *cp, uint8_t evalcode) bool _Getscriptaddress(char *destaddr, const CScript &scriptPubKey) { - CTxDestination address; + CTxDestination address; txnouttype whichType; std::vector> vvch = std::vector>(); if (Solver(scriptPubKey, whichType, vvch) && vvch[0].size() == 20) @@ -199,10 +199,10 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip vector vPK; vector vParams = vector(); COptCCParams p; - + // get information to sign with CCcontract_info C; - + scriptPubKey.IsPayToCryptoCondition(&subScript, vParams); if (vParams.empty()) { @@ -219,12 +219,12 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip { p = COptCCParams(vParams[0]); } - + if (p.IsValid() && p.vKeys.size() >= p.n) { bool is1of2 = (p.m == 1 && p.n == 2); CKey privKey; - + // must be a valid cc eval code if (CCinitLite(&C, p.evalCode)) { @@ -232,7 +232,7 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip if (!is1of2) { bool havePriv = creator.KeyStore().GetKey(p.vKeys[0].GetID(), privKey); - + // if we don't have the private key, it must be the unspendable address if (!havePriv && (p.vKeys[0] == CPubKey(ParseHex(C.CChexstr)))) { @@ -240,9 +240,9 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip std::vector vch(&(C.CCpriv[0]), C.CCpriv + sizeof(C.CCpriv)); privKey.Set(vch.begin(), vch.end(), false); } - + CC *cc = CCcond1(p.evalCode, p.vKeys[0]); - + if (cc) { vector vch; @@ -254,7 +254,7 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip { fprintf(stderr,"vin has 1of1 CC signing error with address.(%s)\n", p.vKeys[0].GetID().ToString().c_str()); } - + cc_free(cc); return ret.size() != 0; } @@ -266,7 +266,7 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip { if (creator.IsKeystoreValid() && creator.KeyStore().GetKey(pk.GetID(), privKey) && privKey.IsValid()) break; - + if (pk == CPubKey(ParseHex(C.CChexstr))) { privKey = CKey(); @@ -275,12 +275,12 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip break; } } - + if (!privKey.IsValid()) return false; - + CC *cc = CCcond1of2(p.evalCode, p.vKeys[0], p.vKeys[1]); - + if (cc) { vector vch; @@ -292,7 +292,7 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip { fprintf(stderr,"vin has 1of2 CC signing error with addresses.(%s)\n(%s)\n", p.vKeys[0].GetID().ToString().c_str(), p.vKeys[1].GetID().ToString().c_str()); } - + cc_free(cc); return ret.size() != 0; } @@ -314,9 +314,9 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP CScript scriptRet; uint160 h160; ret.clear(); - + vector vSolutions; - + if (!Solver(scriptPubKey, whichTypeRet, vSolutions)) { // if this is a CLTV script, solve for the destination after CLTV @@ -324,10 +324,10 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP { uint8_t pushOp = scriptPubKey[0]; uint32_t scriptStart = pushOp + 3; - + // check post CLTV script CScript postfix = CScript(scriptPubKey.size() > scriptStart ? scriptPubKey.begin() + scriptStart : scriptPubKey.end(), scriptPubKey.end()); - + // check again with only postfix subscript if (!Solver(postfix, whichTypeRet, vSolutions)) return false; @@ -335,44 +335,44 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP else return false; } - + CKeyID keyID; - + switch (whichTypeRet) { - case TX_NONSTANDARD: - case TX_NULL_DATA: - return false; - case TX_PUBKEY: - keyID = CPubKey(vSolutions[0]).GetID(); - return Sign1(keyID, creator, scriptPubKey, ret, consensusBranchId); - case TX_PUBKEYHASH: - keyID = CKeyID(uint160(vSolutions[0])); - if (!Sign1(keyID, creator, scriptPubKey, ret, consensusBranchId)) + case TX_NONSTANDARD: + case TX_NULL_DATA: return false; - else - { - CPubKey vch; - creator.KeyStore().GetPubKey(keyID, vch); - ret.push_back(ToByteVector(vch)); - } - return true; - case TX_SCRIPTHASH: - if (creator.KeyStore().GetCScript(uint160(vSolutions[0]), scriptRet)) { - ret.push_back(std::vector(scriptRet.begin(), scriptRet.end())); + case TX_PUBKEY: + keyID = CPubKey(vSolutions[0]).GetID(); + return Sign1(keyID, creator, scriptPubKey, ret, consensusBranchId); + case TX_PUBKEYHASH: + keyID = CKeyID(uint160(vSolutions[0])); + if (!Sign1(keyID, creator, scriptPubKey, ret, consensusBranchId)) + return false; + else + { + CPubKey vch; + creator.KeyStore().GetPubKey(keyID, vch); + ret.push_back(ToByteVector(vch)); + } return true; - } - return false; - - case TX_CRYPTOCONDITION: - return SignStepCC(creator, scriptPubKey, vSolutions, ret, consensusBranchId); - - case TX_MULTISIG: - ret.push_back(valtype()); // workaround CHECKMULTISIG bug - return (SignN(vSolutions, creator, scriptPubKey, ret, consensusBranchId)); - - default: - return false; + case TX_SCRIPTHASH: + if (creator.KeyStore().GetCScript(uint160(vSolutions[0]), scriptRet)) { + ret.push_back(std::vector(scriptRet.begin(), scriptRet.end())); + return true; + } + return false; + + case TX_CRYPTOCONDITION: + return SignStepCC(creator, scriptPubKey, vSolutions, ret, consensusBranchId); + + case TX_MULTISIG: + ret.push_back(valtype()); // workaround CHECKMULTISIG bug + return (SignN(vSolutions, creator, scriptPubKey, ret, consensusBranchId)); + + default: + return false; } } @@ -399,7 +399,7 @@ bool ProduceSignature(const BaseSignatureCreator& creator, const CScript& fromPu txnouttype whichType; solved = SignStep(creator, script, result, whichType, consensusBranchId); CScript subscript; - + if (solved && whichType == TX_SCRIPTHASH) { // Solver returns the subscript that needs to be evaluated; @@ -409,9 +409,9 @@ bool ProduceSignature(const BaseSignatureCreator& creator, const CScript& fromPu solved = solved && SignStep(creator, script, result, whichType, consensusBranchId) && whichType != TX_SCRIPTHASH; result.push_back(std::vector(subscript.begin(), subscript.end())); } - + sigdata.scriptSig = PushAll(result); - + // Test solution return solved && VerifyScript(sigdata.scriptSig, fromPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, creator.Checker(), consensusBranchId); } @@ -431,19 +431,19 @@ void UpdateTransaction(CMutableTransaction& tx, unsigned int nIn, const Signatur } bool SignSignature( - const CKeyStore &keystore, - const CScript& fromPubKey, - CMutableTransaction& txTo, - unsigned int nIn, - const CAmount& amount, - int nHashType, - uint32_t consensusBranchId) + const CKeyStore &keystore, + const CScript& fromPubKey, + CMutableTransaction& txTo, + unsigned int nIn, + const CAmount& amount, + int nHashType, + uint32_t consensusBranchId) { assert(nIn < txTo.vin.size()); - + CTransaction txToConst(txTo); TransactionSignatureCreator creator(&keystore, &txToConst, nIn, amount, nHashType); - + SignatureData sigdata; bool ret = ProduceSignature(creator, fromPubKey, sigdata, consensusBranchId); UpdateTransaction(txTo, nIn, sigdata); @@ -451,24 +451,24 @@ bool SignSignature( } bool SignSignature( - const CKeyStore &keystore, - const CTransaction& txFrom, - CMutableTransaction& txTo, - unsigned int nIn, - int nHashType, - uint32_t consensusBranchId) + const CKeyStore &keystore, + const CTransaction& txFrom, + CMutableTransaction& txTo, + unsigned int nIn, + int nHashType, + uint32_t consensusBranchId) { assert(nIn < txTo.vin.size()); CTxIn& txin = txTo.vin[nIn]; assert(txin.prevout.n < txFrom.vout.size()); const CTxOut& txout = txFrom.vout[txin.prevout.n]; - + return SignSignature(keystore, txout.scriptPubKey, txTo, nIn, txout.nValue, nHashType, consensusBranchId); } static vector CombineMultisig(const CScript& scriptPubKey, const BaseSignatureChecker& checker, - const vector& vSolutions, - const vector& sigs1, const vector& sigs2, uint32_t consensusBranchId) + const vector& vSolutions, + const vector& sigs1, const vector& sigs2, uint32_t consensusBranchId) { // Combine all the signatures we've got: set allsigs; @@ -482,7 +482,7 @@ static vector CombineMultisig(const CScript& scriptPubKey, const BaseSi if (!v.empty()) allsigs.insert(v); } - + // Build a map of pubkey -> signature by matching sigs to pubkeys: assert(vSolutions.size() > 1); unsigned int nSigsRequired = vSolutions.front()[0]; @@ -495,7 +495,7 @@ static vector CombineMultisig(const CScript& scriptPubKey, const BaseSi const valtype& pubkey = vSolutions[i+1]; if (sigs.count(pubkey)) continue; // Already got a sig for this pubkey - + if (checker.CheckSig(sig, pubkey, scriptPubKey, consensusBranchId)) { sigs[pubkey] = sig; @@ -517,108 +517,108 @@ static vector CombineMultisig(const CScript& scriptPubKey, const BaseSi // Fill any missing with OP_0: for (unsigned int i = nSigsHave; i < nSigsRequired; i++) result.push_back(valtype()); - + return result; } namespace { -struct Stacks -{ - std::vector script; - - Stacks() {} - explicit Stacks(const std::vector& scriptSigStack_) : script(scriptSigStack_) {} - explicit Stacks(const SignatureData& data, uint32_t consensusBranchId) { - EvalScript(script, data.scriptSig, SCRIPT_VERIFY_STRICTENC, BaseSignatureChecker(), consensusBranchId); - } - - SignatureData Output() const { - SignatureData result; - result.scriptSig = PushAll(script); - return result; - } -}; + struct Stacks + { + std::vector script; + + Stacks() {} + explicit Stacks(const std::vector& scriptSigStack_) : script(scriptSigStack_) {} + explicit Stacks(const SignatureData& data, uint32_t consensusBranchId) { + EvalScript(script, data.scriptSig, SCRIPT_VERIFY_STRICTENC, BaseSignatureChecker(), consensusBranchId); + } + + SignatureData Output() const { + SignatureData result; + result.scriptSig = PushAll(script); + return result; + } + }; } static Stacks CombineSignatures(const CScript& scriptPubKey, const BaseSignatureChecker& checker, - const txnouttype txType, const vector& vSolutions, - Stacks sigs1, Stacks sigs2, uint32_t consensusBranchId) + const txnouttype txType, const vector& vSolutions, + Stacks sigs1, Stacks sigs2, uint32_t consensusBranchId) { switch (txType) { - case TX_NONSTANDARD: - case TX_NULL_DATA: - // Don't know anything about this, assume bigger one is correct: - if (sigs1.script.size() >= sigs2.script.size()) - return sigs1; - return sigs2; - case TX_PUBKEY: - case TX_PUBKEYHASH: - case TX_CRYPTOCONDITION: - // Signatures are bigger than placeholders or empty scripts: - if (sigs1.script.empty() || sigs1.script[0].empty()) + case TX_NONSTANDARD: + case TX_NULL_DATA: + // Don't know anything about this, assume bigger one is correct: + if (sigs1.script.size() >= sigs2.script.size()) + return sigs1; return sigs2; - return sigs1; - case TX_SCRIPTHASH: - if (sigs1.script.empty() || sigs1.script.back().empty()) - return sigs2; - else if (sigs2.script.empty() || sigs2.script.back().empty()) + case TX_PUBKEY: + case TX_PUBKEYHASH: + case TX_CRYPTOCONDITION: + // Signatures are bigger than placeholders or empty scripts: + if (sigs1.script.empty() || sigs1.script[0].empty()) + return sigs2; return sigs1; - else - { - // Recur to combine: - valtype spk = sigs1.script.back(); - CScript pubKey2(spk.begin(), spk.end()); - - txnouttype txType2; - vector > vSolutions2; - Solver(pubKey2, txType2, vSolutions2); - sigs1.script.pop_back(); - sigs2.script.pop_back(); - Stacks result = CombineSignatures(pubKey2, checker, txType2, vSolutions2, sigs1, sigs2, consensusBranchId); - result.script.push_back(spk); - return result; - } - case TX_MULTISIG: - return Stacks(CombineMultisig(scriptPubKey, checker, vSolutions, sigs1.script, sigs2.script, consensusBranchId)); - default: - return Stacks(); + case TX_SCRIPTHASH: + if (sigs1.script.empty() || sigs1.script.back().empty()) + return sigs2; + else if (sigs2.script.empty() || sigs2.script.back().empty()) + return sigs1; + else + { + // Recur to combine: + valtype spk = sigs1.script.back(); + CScript pubKey2(spk.begin(), spk.end()); + + txnouttype txType2; + vector > vSolutions2; + Solver(pubKey2, txType2, vSolutions2); + sigs1.script.pop_back(); + sigs2.script.pop_back(); + Stacks result = CombineSignatures(pubKey2, checker, txType2, vSolutions2, sigs1, sigs2, consensusBranchId); + result.script.push_back(spk); + return result; + } + case TX_MULTISIG: + return Stacks(CombineMultisig(scriptPubKey, checker, vSolutions, sigs1.script, sigs2.script, consensusBranchId)); + default: + return Stacks(); } } SignatureData CombineSignatures(const CScript& scriptPubKey, const BaseSignatureChecker& checker, - const SignatureData& scriptSig1, const SignatureData& scriptSig2, - uint32_t consensusBranchId) + const SignatureData& scriptSig1, const SignatureData& scriptSig2, + uint32_t consensusBranchId) { txnouttype txType; vector > vSolutions; Solver(scriptPubKey, txType, vSolutions); - + return CombineSignatures( - scriptPubKey, checker, txType, vSolutions, - Stacks(scriptSig1, consensusBranchId), - Stacks(scriptSig2, consensusBranchId), - consensusBranchId).Output(); + scriptPubKey, checker, txType, vSolutions, + Stacks(scriptSig1, consensusBranchId), + Stacks(scriptSig2, consensusBranchId), + consensusBranchId).Output(); } namespace { -/** Dummy signature checker which accepts all signatures. */ -class DummySignatureChecker : public BaseSignatureChecker -{ -public: - DummySignatureChecker() {} - - bool CheckSig( - const std::vector& scriptSig, - const std::vector& vchPubKey, - const CScript& scriptCode, - uint32_t consensusBranchId) const + /** Dummy signature checker which accepts all signatures. */ + class DummySignatureChecker : public BaseSignatureChecker { - return true; - } -}; -const DummySignatureChecker dummyChecker; + public: + DummySignatureChecker() {} + + bool CheckSig( + const std::vector& scriptSig, + const std::vector& vchPubKey, + const CScript& scriptCode, + uint32_t consensusBranchId) const + { + return true; + } + }; + const DummySignatureChecker dummyChecker; } const BaseSignatureChecker& DummySignatureCreator::Checker() const @@ -627,12 +627,12 @@ const BaseSignatureChecker& DummySignatureCreator::Checker() const } bool DummySignatureCreator::CreateSig( - std::vector& vchSig, - const CKeyID& keyid, - const CScript& scriptCode, - uint32_t consensusBranchId, - CKey *key, - void *extraData) const + std::vector& vchSig, + const CKeyID& keyid, + const CScript& scriptCode, + uint32_t consensusBranchId, + CKey *key, + void *extraData) const { // Create a dummy signature that is a valid DER-encoding vchSig.assign(72, '\000'); @@ -647,3 +647,4 @@ bool DummySignatureCreator::CreateSig( vchSig[6 + 33 + 32] = SIGHASH_ALL; return true; } + From 4ad5879f56900e1fe9de6b26c60a11e2892d8da2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:13:59 -1100 Subject: [PATCH 134/144] struct CC_info --- src/cc/heir.cpp | 1611 ++++++++++++++++++++++++----------------------- 1 file changed, 806 insertions(+), 805 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 499fb598d..7867032b6 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -21,14 +21,14 @@ class TokenHelper; /* The idea of Heir CC is to allow crypto inheritance. - A special 1of2 CC address is created that is freely spendable by the creator (funds owner). + A special 1of2 CC address is created that is freely spendable by the creator (funds owner). The owner may add additional funds to this 1of2 address. - The heir is only allowed to spend after "the specified amount of idle blocks" (changed to "the owner inactivityTime"). - The idea is that if the address doesnt spend any funds for a year (or whatever amount set), then it is time to allow the heir to spend. + The heir is only allowed to spend after "the specified amount of idle blocks" (changed to "the owner inactivityTime"). + The idea is that if the address doesnt spend any funds for a year (or whatever amount set), then it is time to allow the heir to spend. "The design requires the heir to spend all the funds at once" (this requirement was changed to "after the inactivity time both the heir and owner may freely spend available funds") After the first heir spending a flag is set that spending is allowed for the heir whether the owner adds more funds or spends them. This Heir contract supports both coins and tokens. -*/ + */ // tx validation code @@ -36,69 +36,69 @@ class TokenHelper; // (sadly we cannot have yet 'templatized' lambdas, if we could we could capture all these params inside HeirValidation()...) template bool RunValidationPlans(uint8_t funcId, struct CC_info* cp, Eval* eval, const CTransaction& tx, uint256 latestTxid, CScript fundingOpretScript, uint8_t hasHeirSpendingBegun) { - int32_t numvins = tx.vin.size(); - int32_t numvouts = tx.vout.size(); - - // setup validation framework (please see its description in heir_validate.h): - // validation 'plans': - CInputValidationPlan vinPlan; - COutputValidationPlan voutPlan; - - // vin 'identifiers' - CNormalInputIdentifier normalInputIdentifier(cp); - CCCInputIdentifier ccInputIdentifier(cp); - - // vin and vout 'validators' - // not used, too strict for 2 pubkeys: CMyPubkeyVoutValidator normalInputValidator(cp, fundingOpretScript, true); // check normal input for this opret cause this is first tx - CCC1of2AddressValidator cc1of2ValidatorThis(cp, fundingOpretScript, "checking this tx opreturn:"); // 1of2add validator with pubkeys from this tx opreturn - CHeirSpendValidator heirSpendValidator(cp, fundingOpretScript, latestTxid, hasHeirSpendingBegun); // check if heir allowed to spend - - // only for tokens: - CMyPubkeyVoutValidator ownerCCaddrValidator(cp, fundingOpretScript, false); // check if this correct owner's cc user addr corresponding to opret - COpRetValidator opRetValidator(cp, fundingOpretScript); // compare opRets in this and last tx - CNullValidator nullValidator(cp); - - switch (funcId) { - case 'F': // fund tokens - // vin validation plan: - vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin - vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &ownerCCaddrValidator); // check cc owner addr - - // vout validation plan: - voutPlan.pushValidators(0, &cc1of2ValidatorThis); // check 1of2 addr funding - // do not check change at this time - // no checking for opret yet - break; - - case 'A': // add tokens - // vin validation plan: - vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin - vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &ownerCCaddrValidator); // check cc owner addr - - // vout validation plan: - voutPlan.pushValidators(0, &cc1of2ValidatorThis); // check 1of2 addr funding - // do not check change at this time - voutPlan.pushValidators(numvouts - 1, &opRetValidator); // opreturn check, NOTE: only for C or A: - break; - - case 'C': - // vin validation plan: - vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin - vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &cc1of2ValidatorThis); // cc1of2 funding addr - - // vout validation plan: - voutPlan.pushValidators(0, &heirSpendValidator); // check if heir is allowed to spend - voutPlan.pushValidators(numvouts - 1, &opRetValidator); // opreturn check, NOTE: only for C or A - break; - } - - // call vin/vout validation - if (!vinPlan.validate(tx, eval)) - return false; - if (!voutPlan.validate(tx, eval)) - return false; - - return true; + int32_t numvins = tx.vin.size(); + int32_t numvouts = tx.vout.size(); + + // setup validation framework (please see its description in heir_validate.h): + // validation 'plans': + CInputValidationPlan vinPlan; + COutputValidationPlan voutPlan; + + // vin 'identifiers' + CNormalInputIdentifier normalInputIdentifier(cp); + CCCInputIdentifier ccInputIdentifier(cp); + + // vin and vout 'validators' + // not used, too strict for 2 pubkeys: CMyPubkeyVoutValidator normalInputValidator(cp, fundingOpretScript, true); // check normal input for this opret cause this is first tx + CCC1of2AddressValidator cc1of2ValidatorThis(cp, fundingOpretScript, "checking this tx opreturn:"); // 1of2add validator with pubkeys from this tx opreturn + CHeirSpendValidator heirSpendValidator(cp, fundingOpretScript, latestTxid, hasHeirSpendingBegun); // check if heir allowed to spend + + // only for tokens: + CMyPubkeyVoutValidator ownerCCaddrValidator(cp, fundingOpretScript, false); // check if this correct owner's cc user addr corresponding to opret + COpRetValidator opRetValidator(cp, fundingOpretScript); // compare opRets in this and last tx + CNullValidator nullValidator(cp); + + switch (funcId) { + case 'F': // fund tokens + // vin validation plan: + vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &ownerCCaddrValidator); // check cc owner addr + + // vout validation plan: + voutPlan.pushValidators(0, &cc1of2ValidatorThis); // check 1of2 addr funding + // do not check change at this time + // no checking for opret yet + break; + + case 'A': // add tokens + // vin validation plan: + vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &ownerCCaddrValidator); // check cc owner addr + + // vout validation plan: + voutPlan.pushValidators(0, &cc1of2ValidatorThis); // check 1of2 addr funding + // do not check change at this time + voutPlan.pushValidators(numvouts - 1, &opRetValidator); // opreturn check, NOTE: only for C or A: + break; + + case 'C': + // vin validation plan: + vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &cc1of2ValidatorThis); // cc1of2 funding addr + + // vout validation plan: + voutPlan.pushValidators(0, &heirSpendValidator); // check if heir is allowed to spend + voutPlan.pushValidators(numvouts - 1, &opRetValidator); // opreturn check, NOTE: only for C or A + break; + } + + // call vin/vout validation + if (!vinPlan.validate(tx, eval)) + return false; + if (!voutPlan.validate(tx, eval)) + return false; + + return true; } /** @@ -110,121 +110,121 @@ bool HeirValidate(struct CC_info* cpHeir, Eval* eval, const CTransaction& tx, ui int32_t numvouts = tx.vout.size(); //int32_t preventCCvins = -1; //int32_t preventCCvouts = -1; - - struct CC_info *cpTokens, tokensC; - cpTokens = CCinit(&tokensC, EVAL_TOKENS); - + + struct CC_info *cpTokens, tokensC; + cpTokens = CCinit(&tokensC, EVAL_TOKENS); + if (numvouts < 1) return eval->Invalid("no vouts"); - - //if (chainActive.Height() < 741) - // return true; - + + //if (chainActive.Height() < 741) + // return true; + uint256 fundingTxidInOpret = zeroid, latestTxid = zeroid, dummyTokenid, tokenidThis, tokenid = zeroid; - CScript fundingTxOpRetScript; - uint8_t hasHeirSpendingBegun = 0, hasHeirSpendingBegunDummy; - - CScript opret = (tx.vout.size() > 0) ? tx.vout[tx.vout.size() - 1].scriptPubKey : CScript(); // check boundary - uint8_t funcId = DecodeHeirEitherOpRet(opret, tokenidThis, fundingTxidInOpret, hasHeirSpendingBegunDummy, true); - if (funcId == 0) + CScript fundingTxOpRetScript; + uint8_t hasHeirSpendingBegun = 0, hasHeirSpendingBegunDummy; + + CScript opret = (tx.vout.size() > 0) ? tx.vout[tx.vout.size() - 1].scriptPubKey : CScript(); // check boundary + uint8_t funcId = DecodeHeirEitherOpRet(opret, tokenidThis, fundingTxidInOpret, hasHeirSpendingBegunDummy, true); + if (funcId == 0) return eval->Invalid("invalid opreturn format"); - + if (funcId != 'F') { if (fundingTxidInOpret == zeroid) { return eval->Invalid("incorrect tx opreturn: no fundingtxid present"); } - latestTxid = FindLatestFundingTx(fundingTxidInOpret, tokenid, fundingTxOpRetScript, hasHeirSpendingBegun); - - if( tokenid != zeroid && tokenid != tokenidThis ) - return eval->Invalid("incorrect tx tokenid"); - - if (latestTxid == zeroid) { + latestTxid = FindLatestFundingTx(fundingTxidInOpret, tokenid, fundingTxOpRetScript, hasHeirSpendingBegun); + + if( tokenid != zeroid && tokenid != tokenidThis ) + return eval->Invalid("incorrect tx tokenid"); + + if (latestTxid == zeroid) { return eval->Invalid("no fundingtx found"); } - } - else { - fundingTxOpRetScript = opret; - } - - std::cerr << "HeirValidate funcid=" << (char)funcId << " evalcode=" << (int)cpHeir->evalcode << std::endl; - - //////////////// temp //////////////////////// - ///return true; - + } + else { + fundingTxOpRetScript = opret; + } + + std::cerr << "HeirValidate funcid=" << (char)funcId << " evalcode=" << (int)cpHeir->evalcode << std::endl; + + //////////////// temp //////////////////////// + ///return true; + switch (funcId) { - case 'F': - // fund coins: - // vins.*: normal inputs - // ----------------------------- - // vout.0: funding CC 1of2 addr for the owner and heir - // vout.1: txfee for CC addr used as a marker - // vout.2: normal change - // vout.n-1: opreturn 'F' ownerpk heirpk inactivitytime heirname - - // fund tokens: - // vin.0: normal inputs txfee - // vins.1+: user's CC addr inputs - // ----------------------- - // vout.0: funding heir CC 1of2 addr for the owner and heir - // vout.1: txfee for CC addr used as a marker - // vout.2: normal change - // vout.n-1: opreturn 't' tokenid 'F' ownerpk heirpk inactivitytime heirname tokenid - if (tokenid != zeroid) - return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); - else - return eval->Invalid("unexpected HeirValidate for heirfund"); - // break; - - case 'A': - // add funding coins: - // vins.*: normal inputs - // ------------------------ - // vout.0: funding CC 1of2 addr for the owner and heir - // vout.1: normal change - // vout.n-1: opreturn 'A' ownerpk heirpk inactivitytime fundingtx - - // add funding tokens: - // vins.0: normal inputs txfee - // vins.1+: user's CC addr inputs - // ------------------------ - // vout.0: funding CC 1of2 addr for the owner and heir - // vout.1: normal change - // vout.n-1: opreturn 't' tokenid 'A' ownerpk heirpk inactivitytime fundingtx - if (tokenid != zeroid) - return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); - else - return eval->Invalid("unexpected HeirValidate for heiradd"); - //break; - - case 'C': - // claim coins: - // vin.0: normal input txfee - // vin.1+: input from CC 1of2 addr - // ------------------------------------- - // vout.0: normal output to owner or heir address - // vout.1: change to CC 1of2 addr - // vout.2: change to user's addr from txfee input if any - // vout.n-1: opreturn 'C' ownerpk heirpk inactivitytime fundingtx - - // claim tokens: - // vin.0: normal input txfee - // vin.1+: input from CC 1of2 addr - // -------------------------------------------- - // vout.0: output to user's cc address - // vout.1: change to CC 1of2 addr - // vout.2: change to normal from txfee input if any - // vout.n-1: opreturn 't' tokenid 'C' ownerpk heirpk inactivitytime fundingtx - if (tokenid != zeroid) - return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); - else - return RunValidationPlans(funcId, cpHeir, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); - // break; - - default: - std::cerr << "HeirValidate() illegal heir funcid=" << (char)funcId << std::endl; - return eval->Invalid("unexpected HeirValidate funcid"); - // break; + case 'F': + // fund coins: + // vins.*: normal inputs + // ----------------------------- + // vout.0: funding CC 1of2 addr for the owner and heir + // vout.1: txfee for CC addr used as a marker + // vout.2: normal change + // vout.n-1: opreturn 'F' ownerpk heirpk inactivitytime heirname + + // fund tokens: + // vin.0: normal inputs txfee + // vins.1+: user's CC addr inputs + // ----------------------- + // vout.0: funding heir CC 1of2 addr for the owner and heir + // vout.1: txfee for CC addr used as a marker + // vout.2: normal change + // vout.n-1: opreturn 't' tokenid 'F' ownerpk heirpk inactivitytime heirname tokenid + if (tokenid != zeroid) + return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); + else + return eval->Invalid("unexpected HeirValidate for heirfund"); + // break; + + case 'A': + // add funding coins: + // vins.*: normal inputs + // ------------------------ + // vout.0: funding CC 1of2 addr for the owner and heir + // vout.1: normal change + // vout.n-1: opreturn 'A' ownerpk heirpk inactivitytime fundingtx + + // add funding tokens: + // vins.0: normal inputs txfee + // vins.1+: user's CC addr inputs + // ------------------------ + // vout.0: funding CC 1of2 addr for the owner and heir + // vout.1: normal change + // vout.n-1: opreturn 't' tokenid 'A' ownerpk heirpk inactivitytime fundingtx + if (tokenid != zeroid) + return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); + else + return eval->Invalid("unexpected HeirValidate for heiradd"); + //break; + + case 'C': + // claim coins: + // vin.0: normal input txfee + // vin.1+: input from CC 1of2 addr + // ------------------------------------- + // vout.0: normal output to owner or heir address + // vout.1: change to CC 1of2 addr + // vout.2: change to user's addr from txfee input if any + // vout.n-1: opreturn 'C' ownerpk heirpk inactivitytime fundingtx + + // claim tokens: + // vin.0: normal input txfee + // vin.1+: input from CC 1of2 addr + // -------------------------------------------- + // vout.0: output to user's cc address + // vout.1: change to CC 1of2 addr + // vout.2: change to normal from txfee input if any + // vout.n-1: opreturn 't' tokenid 'C' ownerpk heirpk inactivitytime fundingtx + if (tokenid != zeroid) + return RunValidationPlans(funcId, cpTokens, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); + else + return RunValidationPlans(funcId, cpHeir, eval, tx, latestTxid, fundingTxOpRetScript, hasHeirSpendingBegun); + // break; + + default: + std::cerr << "HeirValidate() illegal heir funcid=" << (char)funcId << std::endl; + return eval->Invalid("unexpected HeirValidate funcid"); + // break; } return eval->Invalid("unexpected"); // (PreventCC(eval, tx, preventCCvins, numvins, preventCCvouts, numvouts)); } @@ -234,194 +234,194 @@ bool HeirValidate(struct CC_info* cpHeir, Eval* eval, const CTransaction& tx, ui // helper functions used in implementations of rpc calls (in rpcwallet.cpp) or validation code /** -* Checks if vout is to cryptocondition address -* @return vout value in satoshis -*/ + * Checks if vout is to cryptocondition address + * @return vout value in satoshis + */ template int64_t IsHeirFundingVout(struct CC_info* cp, const CTransaction& tx, int32_t voutIndex, CPubKey ownerPubkey, CPubKey heirPubkey) { - char destaddr[65], heirFundingAddr[65]; - - Helper::GetCoinsOrTokensCCaddress1of2(cp, heirFundingAddr, ownerPubkey, heirPubkey); - if (tx.vout[voutIndex].scriptPubKey.IsPayToCryptoCondition() != 0) { - // NOTE: dimxy it was unsafe 'Getscriptaddress(destaddr,tx.vout[voutIndex].scriptPubKey) > 0' here: - if (Getscriptaddress(destaddr, tx.vout[voutIndex].scriptPubKey) && strcmp(destaddr, heirFundingAddr) == 0) - return (tx.vout[voutIndex].nValue); - else - std::cerr << "IsHeirFundingVout() heirFundingAddr=" << heirFundingAddr << " not equal to destaddr=" << destaddr << std::endl; - } - return (0); + char destaddr[65], heirFundingAddr[65]; + + Helper::GetCoinsOrTokensCCaddress1of2(cp, heirFundingAddr, ownerPubkey, heirPubkey); + if (tx.vout[voutIndex].scriptPubKey.IsPayToCryptoCondition() != 0) { + // NOTE: dimxy it was unsafe 'Getscriptaddress(destaddr,tx.vout[voutIndex].scriptPubKey) > 0' here: + if (Getscriptaddress(destaddr, tx.vout[voutIndex].scriptPubKey) && strcmp(destaddr, heirFundingAddr) == 0) + return (tx.vout[voutIndex].nValue); + else + std::cerr << "IsHeirFundingVout() heirFundingAddr=" << heirFundingAddr << " not equal to destaddr=" << destaddr << std::endl; + } + return (0); } // makes coin initial tx opret CScript EncodeHeirCreateOpRet(uint8_t funcid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName) { - uint8_t evalcode = EVAL_HEIR; - - return CScript() << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << ownerPubkey << heirPubkey << inactivityTimeSec << heirName); + uint8_t evalcode = EVAL_HEIR; + + return CScript() << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << ownerPubkey << heirPubkey << inactivityTimeSec << heirName); } // makes coin additional tx opret CScript EncodeHeirOpRet(uint8_t funcid, uint256 fundingtxid, uint8_t hasHeirSpendingBegun) { - uint8_t evalcode = EVAL_HEIR; - - fundingtxid = revuint256(fundingtxid); - return CScript() << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << fundingtxid << hasHeirSpendingBegun); + uint8_t evalcode = EVAL_HEIR; + + fundingtxid = revuint256(fundingtxid); + return CScript() << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << fundingtxid << hasHeirSpendingBegun); } // decode opret vout for Heir contract uint8_t _DecodeHeirOpRet(std::vector vopret, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) { - uint8_t evalCodeInOpret = 0; - uint8_t heirFuncId = 0; - - fundingTxidInOpret = zeroid; //to init - - evalCodeInOpret = vopret.begin()[0]; - - if (vopret.size() > 1 && evalCodeInOpret == EVAL_HEIR) { - // NOTE: it unmarshals for all F, A and C - uint8_t heirFuncId = 0; - hasHeirSpendingBegun = 0; - - bool result = E_UNMARSHAL(vopret, { ss >> evalCodeInOpret; ss >> heirFuncId; \ - if (heirFuncId == 'F') { \ - ss >> ownerPubkey; ss >> heirPubkey; ss >> inactivityTime; ss >> heirName; \ - } \ - else { \ - ss >> fundingTxidInOpret >> hasHeirSpendingBegun; \ - } \ - }); - - if (!result) { - if (!noLogging) std::cerr << "_DecodeHeirOpRet() could not unmarshal opret, evalCode=" << (int)evalCodeInOpret << std::endl; - return (uint8_t)0; - } - - /* std::cerr << "DecodeHeirOpRet()" - << " heirFuncId=" << (char)(heirFuncId ? heirFuncId : ' ') - << " ownerPubkey=" << HexStr(ownerPubkey) - << " heirPubkey=" << HexStr(heirPubkey) - << " heirName=" << heirName << " inactivityTime=" << inactivityTime - << " hasHeirSpendingBegun=" << (int)hasHeirSpendingBegun << std::endl; */ - - if (isMyFuncId(heirFuncId)) { - fundingTxidInOpret = revuint256(fundingTxidInOpret); - return heirFuncId; - } - else { - if(!noLogging) std::cerr << "_DecodeHeirOpRet() unexpected opret type, heirFuncId=" << (char)(heirFuncId ? heirFuncId : ' ') << std::endl; - } - } - else { - if (!noLogging) std::cerr << "_DecodeHeirOpRet() not a heir opret, vopretExtra.size() == 0 or not EVAL_HEIR evalcode=" << (int)evalCodeInOpret << std::endl; - } - return (uint8_t)0; + uint8_t evalCodeInOpret = 0; + uint8_t heirFuncId = 0; + + fundingTxidInOpret = zeroid; //to init + + evalCodeInOpret = vopret.begin()[0]; + + if (vopret.size() > 1 && evalCodeInOpret == EVAL_HEIR) { + // NOTE: it unmarshals for all F, A and C + uint8_t heirFuncId = 0; + hasHeirSpendingBegun = 0; + + bool result = E_UNMARSHAL(vopret, { ss >> evalCodeInOpret; ss >> heirFuncId; \ + if (heirFuncId == 'F') { \ + ss >> ownerPubkey; ss >> heirPubkey; ss >> inactivityTime; ss >> heirName; \ + } \ + else { \ + ss >> fundingTxidInOpret >> hasHeirSpendingBegun; \ + } \ + }); + + if (!result) { + if (!noLogging) std::cerr << "_DecodeHeirOpRet() could not unmarshal opret, evalCode=" << (int)evalCodeInOpret << std::endl; + return (uint8_t)0; + } + + /* std::cerr << "DecodeHeirOpRet()" + << " heirFuncId=" << (char)(heirFuncId ? heirFuncId : ' ') + << " ownerPubkey=" << HexStr(ownerPubkey) + << " heirPubkey=" << HexStr(heirPubkey) + << " heirName=" << heirName << " inactivityTime=" << inactivityTime + << " hasHeirSpendingBegun=" << (int)hasHeirSpendingBegun << std::endl; */ + + if (isMyFuncId(heirFuncId)) { + fundingTxidInOpret = revuint256(fundingTxidInOpret); + return heirFuncId; + } + else { + if(!noLogging) std::cerr << "_DecodeHeirOpRet() unexpected opret type, heirFuncId=" << (char)(heirFuncId ? heirFuncId : ' ') << std::endl; + } + } + else { + if (!noLogging) std::cerr << "_DecodeHeirOpRet() not a heir opret, vopretExtra.size() == 0 or not EVAL_HEIR evalcode=" << (int)evalCodeInOpret << std::endl; + } + return (uint8_t)0; } /* not used, see DecodeHeirOpRet(vopret,...) -// overload for 'F' opret -uint8_t DecodeHeirOpRet(CScript scriptPubKey, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging) -{ + // overload for 'F' opret + uint8_t DecodeHeirOpRet(CScript scriptPubKey, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging) + { uint256 dummytxid; uint8_t dummyHasHeirSpendingBegun; std::vector vopret; - + GetOpReturnData(scriptPubKey, vopret); if (vopret.size() == 0) { - if (!noLogging) std::cerr << "DecodeHeirOpRet() warning: empty opret" << std::endl; - return (uint8_t)0; + if (!noLogging) std::cerr << "DecodeHeirOpRet() warning: empty opret" << std::endl; + return (uint8_t)0; } return _DecodeHeirOpRet(vopret, ownerPubkey, heirPubkey, inactivityTime, heirName, dummytxid, dummyHasHeirSpendingBegun, noLogging); -}*/ + }*/ /* not used, see DecodeHeirOpRet(vopret,...) -// overload for A, C oprets and AddHeirContractInputs -uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256& fundingtxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) -{ + // overload for A, C oprets and AddHeirContractInputs + uint8_t DecodeHeirOpRet(CScript scriptPubKey, uint256& fundingtxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) + { CPubKey dummyOwnerPubkey, dummyHeirPubkey; int64_t dummyInactivityTime; std::string dummyHeirName; std::vector vopret; - + GetOpReturnData(scriptPubKey, vopret); if (vopret.size() == 0) { - if (!noLogging) std::cerr << "DecodeHeirOpRet() warning: empty opret" << std::endl; - return (uint8_t)0; + if (!noLogging) std::cerr << "DecodeHeirOpRet() warning: empty opret" << std::endl; + return (uint8_t)0; } - + return _DecodeHeirOpRet(vopret, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingtxidInOpret, hasHeirSpendingBegun, noLogging); -} */ + } */ // decode combined opret: uint8_t _DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint256& fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) { - uint8_t evalCodeTokens = 0; - std::vector voutPubkeysDummy; - std::vector vopretExtra, vopretStripped; - - if (DecodeTokenOpRet(scriptPubKey, evalCodeTokens, tokenid, voutPubkeysDummy, vopretExtra) != 0) { - if (vopretExtra.size() > 1) { - // restore the second opret: - - if (!E_UNMARSHAL(vopretExtra, { ss >> vopretStripped; })) { //strip string size - if (!noLogging) std::cerr << "_DecodeHeirEitherOpret() could not unmarshal vopretStripped" << std::endl; - return (uint8_t)0; - } - } - else { - if (!noLogging) std::cerr << "_DecodeHeirEitherOpret() empty vopretExtra" << std::endl; - return (uint8_t)0; - } - } - else - GetOpReturnData(scriptPubKey, vopretStripped); - - return _DecodeHeirOpRet(vopretStripped, ownerPubkey, heirPubkey, inactivityTime, heirName, fundingTxidInOpret, hasHeirSpendingBegun, noLogging); - + uint8_t evalCodeTokens = 0; + std::vector voutPubkeysDummy; + std::vector vopretExtra, vopretStripped; + + if (DecodeTokenOpRet(scriptPubKey, evalCodeTokens, tokenid, voutPubkeysDummy, vopretExtra) != 0) { + if (vopretExtra.size() > 1) { + // restore the second opret: + + if (!E_UNMARSHAL(vopretExtra, { ss >> vopretStripped; })) { //strip string size + if (!noLogging) std::cerr << "_DecodeHeirEitherOpret() could not unmarshal vopretStripped" << std::endl; + return (uint8_t)0; + } + } + else { + if (!noLogging) std::cerr << "_DecodeHeirEitherOpret() empty vopretExtra" << std::endl; + return (uint8_t)0; + } + } + else + GetOpReturnData(scriptPubKey, vopretStripped); + + return _DecodeHeirOpRet(vopretStripped, ownerPubkey, heirPubkey, inactivityTime, heirName, fundingTxidInOpret, hasHeirSpendingBegun, noLogging); + } // overload to decode opret in fundingtxid: uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, bool noLogging) { - uint256 dummyFundingTxidInOpret; - uint8_t dummyHasHeirSpendingBegun; - - return _DecodeHeirEitherOpRet(scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, dummyFundingTxidInOpret, dummyHasHeirSpendingBegun, noLogging); + uint256 dummyFundingTxidInOpret; + uint8_t dummyHasHeirSpendingBegun; + + return _DecodeHeirEitherOpRet(scriptPubKey, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, dummyFundingTxidInOpret, dummyHasHeirSpendingBegun, noLogging); } // overload to decode opret in A and C heir tx: uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, uint256 &fundingTxidInOpret, uint8_t &hasHeirSpendingBegun, bool noLogging) { - CPubKey dummyOwnerPubkey, dummyHeirPubkey; - int64_t dummyInactivityTime; - std::string dummyHeirName; - - return _DecodeHeirEitherOpRet(scriptPubKey, tokenid, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingTxidInOpret, hasHeirSpendingBegun, noLogging); + CPubKey dummyOwnerPubkey, dummyHeirPubkey; + int64_t dummyInactivityTime; + std::string dummyHeirName; + + return _DecodeHeirEitherOpRet(scriptPubKey, tokenid, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingTxidInOpret, hasHeirSpendingBegun, noLogging); } /** - * find the latest funding tx: it may be the first F tx or one of A or C tx's - * Note: this function is also called from validation code (use non-locking calls) + * find the latest funding tx: it may be the first F tx or one of A or C tx's + * Note: this function is also called from validation code (use non-locking calls) */ uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, CScript& fundingOpretScript, uint8_t &hasHeirSpendingBegun) { - CTransaction fundingtx; - uint256 hashBlock; + CTransaction fundingtx; + uint256 hashBlock; const bool allowSlow = false; - + //char markeraddr[64]; //CCtxidaddr(markeraddr, fundingtxid); //SetCCunspents(unspentOutputs, markeraddr); - - hasHeirSpendingBegun = 0; - funcId = 0; - + + hasHeirSpendingBegun = 0; + funcId = 0; + // get initial funding tx and set it as initial lasttx: if (myGetTransaction(fundingtxid, fundingtx, hashBlock) && fundingtx.vout.size()) { - - CScript heirScript = (fundingtx.vout.size() > 0) ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript(); - uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true); + + CScript heirScript = (fundingtx.vout.size() > 0) ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript(); + uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, true); if (funcId != 0) { // found at least funding tx! //std::cerr << "FindLatestFundingTx() lasttx currently is fundingtx, txid=" << fundingtxid.GetHex() << " opreturn type=" << (char)funcId << '\n'; @@ -434,55 +434,55 @@ uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &toke std::cerr << "FindLatestFundingTx() could not find funding tx for fundingtxid=" << fundingtxid.GetHex() << '\n'; return zeroid; } - - // TODO: correct cc addr: + + // TODO: correct cc addr: std::vector> unspentOutputs; struct CC_info *cp, C; cp = CCinit(&C, EVAL_HEIR); char coinaddr[64]; GetCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); // get the address of cryptocondition '1 of 2 pubkeys' - + SetCCunspents(unspentOutputs, coinaddr); // get vector with tx's with unspent vouts of 1of2pubkey address: //std::cerr << "FindLatestFundingTx() using 1of2address=" << coinaddr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; - + int32_t maxBlockHeight = 0; // max block height uint256 latesttxid = fundingtxid; - + // try to find the last funding or spending tx by checking fundingtxid in 'opreturn': for (std::vector>::const_iterator it = unspentOutputs.begin(); it != unspentOutputs.end(); it++) { CTransaction regtx; uint256 hash; - + uint256 txid = it->first.txhash; //std::cerr << "FindLatestFundingTx() checking unspents for txid=" << txid.GetHex() << '\n'; - + int32_t blockHeight = (int32_t)it->second.blockHeight; - - //NOTE: maybe called from validation code: - if (myGetTransaction(txid, regtx, hash)) { - //std::cerr << "FindLatestFundingTx() found tx for txid=" << txid.GetHex() << " blockHeight=" << blockHeight << " maxBlockHeight=" << maxBlockHeight << '\n'; - uint256 fundingTxidInOpret; - uint256 tokenidInOpret; // not to contaminate the tokenid from the params! - uint8_t tmpFuncId; - uint8_t hasHeirSpendingBegunInOpret; - - CScript heirScript = (regtx.vout.size() > 0) ? regtx.vout[regtx.vout.size() - 1].scriptPubKey : CScript(); - tmpFuncId = DecodeHeirEitherOpRet(heirScript, tokenidInOpret, fundingTxidInOpret, hasHeirSpendingBegunInOpret, true); + + //NOTE: maybe called from validation code: + if (myGetTransaction(txid, regtx, hash)) { + //std::cerr << "FindLatestFundingTx() found tx for txid=" << txid.GetHex() << " blockHeight=" << blockHeight << " maxBlockHeight=" << maxBlockHeight << '\n'; + uint256 fundingTxidInOpret; + uint256 tokenidInOpret; // not to contaminate the tokenid from the params! + uint8_t tmpFuncId; + uint8_t hasHeirSpendingBegunInOpret; + + CScript heirScript = (regtx.vout.size() > 0) ? regtx.vout[regtx.vout.size() - 1].scriptPubKey : CScript(); + tmpFuncId = DecodeHeirEitherOpRet(heirScript, tokenidInOpret, fundingTxidInOpret, hasHeirSpendingBegunInOpret, true); if (tmpFuncId != 0 && fundingtxid == fundingTxidInOpret && (tokenid == zeroid || tokenid == tokenidInOpret)) { // check tokenid also - + if (blockHeight > maxBlockHeight) { maxBlockHeight = blockHeight; latesttxid = txid; - funcId = tmpFuncId; - hasHeirSpendingBegun = hasHeirSpendingBegunInOpret; - - //std::cerr << "FindLatestFundingTx() txid=" << latesttxid.GetHex() << " at blockHeight=" << maxBlockHeight - // << " opreturn type=" << (char)(funcId ? funcId : ' ') << " hasHeirSpendingBegun=" << (int)hasHeirSpendingBegun << " - set as current lasttxid" << '\n'; + funcId = tmpFuncId; + hasHeirSpendingBegun = hasHeirSpendingBegunInOpret; + + //std::cerr << "FindLatestFundingTx() txid=" << latesttxid.GetHex() << " at blockHeight=" << maxBlockHeight + // << " opreturn type=" << (char)(funcId ? funcId : ' ') << " hasHeirSpendingBegun=" << (int)hasHeirSpendingBegun << " - set as current lasttxid" << '\n'; } } } } - + return latesttxid; } @@ -494,7 +494,7 @@ uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRe CPubKey heirPubkey; int64_t inactivityTime; std::string heirName; - + return _FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, opRetScript, hasHeirSpendingBegun); } @@ -502,7 +502,7 @@ uint256 FindLatestFundingTx(uint256 fundingtxid, uint256 &tokenid, CScript& opRe uint256 FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &tokenid, CPubKey& ownerPubkey, CPubKey& heirPubkey, int64_t& inactivityTime, std::string& heirName, uint8_t &hasHeirSpendingBegun) { CScript opRetScript; - + return _FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTime, heirName, opRetScript, hasHeirSpendingBegun); } @@ -514,41 +514,41 @@ template int64_t Add1of2AddressInputs(struct CC_info* cp, uint256 CTransaction heirtx; int32_t n = 0; std::vector> unspentOutputs; - + char coinaddr[64]; - Helper::GetCoinsOrTokensCCaddress1of2(coinaddr, ownerPubkey, heirPubkey); // get address of cryptocondition '1 of 2 pubkeys' + Helper::GetCoinsOrTokensCCaddress1of2(coinaddr, ownerPubkey, heirPubkey); // get address of cryptocondition '1 of 2 pubkeys' SetCCunspents(unspentOutputs, coinaddr); - + // char markeraddr[64]; // CCtxidaddr(markeraddr, fundingtxid); // SetCCunspents(unspentOutputs, markeraddr); - + std::cerr << "Add1of2AddressInputs() using 1of2addr=" << coinaddr << " unspentOutputs.size()=" << unspentOutputs.size() << std::endl; - + for (std::vector>::const_iterator it = unspentOutputs.begin(); it != unspentOutputs.end(); it++) { uint256 txid = it->first.txhash; uint256 hashBlock; int32_t voutIndex = (int32_t)it->first.index; // no need to prevent dup // dimxy: maybe it is good to put tx's in cache? - - std::cerr << "Add1of2AddressInputs() txid=" << txid.GetHex() << std::endl; - + + std::cerr << "Add1of2AddressInputs() txid=" << txid.GetHex() << std::endl; + if (GetTransaction(txid, heirtx, hashBlock, false) != 0) { - uint256 tokenid; + uint256 tokenid; uint256 fundingTxidInOpret; - uint8_t hasHeirSpendingBegunDummy; - - CScript heirScript = (heirtx.vout.size() > 0) ? heirtx.vout[heirtx.vout.size() - 1].scriptPubKey : CScript(); // check boundary - uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, fundingTxidInOpret, hasHeirSpendingBegunDummy, false); - - if ((txid == fundingtxid || fundingTxidInOpret == fundingtxid) && - funcId != 0 && - isMyFuncId(funcId) && - (typeid(Helper) != typeid(TokenHelper) || IsTokensvout(true, true, cp, nullptr, heirtx, voutIndex, tokenid) > 0) && // token validation logic + uint8_t hasHeirSpendingBegunDummy; + + CScript heirScript = (heirtx.vout.size() > 0) ? heirtx.vout[heirtx.vout.size() - 1].scriptPubKey : CScript(); // check boundary + uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, fundingTxidInOpret, hasHeirSpendingBegunDummy, false); + + if ((txid == fundingtxid || fundingTxidInOpret == fundingtxid) && + funcId != 0 && + isMyFuncId(funcId) && + (typeid(Helper) != typeid(TokenHelper) || IsTokensvout(true, true, cp, nullptr, heirtx, voutIndex, tokenid) > 0) && // token validation logic //(voutValue = IsHeirFundingVout(cp, heirtx, voutIndex, ownerPubkey, heirPubkey)) > 0 && // heir contract vout validation logic - not used since we moved to 2-eval vouts - !myIsutxo_spentinmempool(txid, voutIndex)) - { + !myIsutxo_spentinmempool(txid, voutIndex)) + { std::cerr << "Add1of2AddressInputs() satoshis=" << it->second.satoshis << std::endl; if (total != 0 && maxinputs != 0) mtx.vin.push_back(CTxIn(txid, voutIndex, CScript())); @@ -564,42 +564,42 @@ template int64_t Add1of2AddressInputs(struct CC_info* cp, uint256 } /** - * enumerate all tx's sending to CCHeir 1of2address and calc total lifetime funds + * enumerate all tx's sending to CCHeir 1of2address and calc total lifetime funds */ template int64_t LifetimeHeirContractFunds(struct CC_info* cp, uint256 fundingtxid, CPubKey ownerPubkey, CPubKey heirPubkey) { char coinaddr[64]; Helper::GetCoinsOrTokensCCaddress1of2(coinaddr, ownerPubkey, heirPubkey); // get the address of cryptocondition '1 of 2 pubkeys' - + std::vector> addressIndexes; SetCCtxids(addressIndexes, coinaddr); - + //fprintf(stderr,"LifetimeHeirContractFunds() scan lifetime of %s\n",coinaddr); int64_t total = 0; for (std::vector>::const_iterator it = addressIndexes.begin(); it != addressIndexes.end(); it++) { uint256 hashBlock; uint256 txid = it->first.txhash; CTransaction heirtx; - - // TODO: check all funding tx should contain unspendable markers + + // TODO: check all funding tx should contain unspendable markers if (GetTransaction(txid, heirtx, hashBlock, false) && heirtx.vout.size() > 0) { - uint256 tokenid; + uint256 tokenid; uint256 fundingTxidInOpret; - uint8_t hasHeirSpendingBegunDummy; + uint8_t hasHeirSpendingBegunDummy; const int32_t ivout = 0; - - CScript heirScript = (heirtx.vout.size() > 0) ? heirtx.vout[heirtx.vout.size() - 1].scriptPubKey : CScript(); // check boundary - uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, fundingTxidInOpret, hasHeirSpendingBegunDummy, false); - + + CScript heirScript = (heirtx.vout.size() > 0) ? heirtx.vout[heirtx.vout.size() - 1].scriptPubKey : CScript(); // check boundary + uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, fundingTxidInOpret, hasHeirSpendingBegunDummy, false); + //std::cerr << "LifetimeHeirContractFunds() found tx=" << txid.GetHex() << " vout[0].nValue=" << subtx.vout[ccVoutIdx].nValue << " opreturn=" << (char)funcId << '\n'; - - if (funcId != 0 && - (txid == fundingtxid || fundingTxidInOpret == fundingtxid) && - isMyFuncId(funcId) && !isSpendingTx(funcId) && - (typeid(Helper) != typeid(TokenHelper) || IsTokensvout(true, true, cp, nullptr, heirtx, ivout, tokenid) > 0) && - !myIsutxo_spentinmempool(txid, ivout)) // exclude tx in mempool + + if (funcId != 0 && + (txid == fundingtxid || fundingTxidInOpret == fundingtxid) && + isMyFuncId(funcId) && !isSpendingTx(funcId) && + (typeid(Helper) != typeid(TokenHelper) || IsTokensvout(true, true, cp, nullptr, heirtx, ivout, tokenid) > 0) && + !myIsutxo_spentinmempool(txid, ivout)) // exclude tx in mempool { - total += it->second; // dont do this: tx.vout[ivout].nValue; // in vin[0] always is the pay to 1of2 addr (funding or change) + total += it->second; // dont do this: tx.vout[ivout].nValue; // in vin[0] always is the pay to 1of2 addr (funding or change) //std::cerr << "LifetimeHeirContractFunds() added tx=" << txid.GetHex() << " it->second=" << it->second << " vout[0].nValue=" << tx.vout[ivout].nValue << " opreturn=" << (char)funcId << '\n'; } } @@ -611,90 +611,90 @@ template int64_t LifetimeHeirContractFunds(struct CC_info* cp, ui /** * heirfund rpc call implementation - * creates tx for initial funds deposit on cryptocondition address which locks funds for spending by either of address. + * creates tx for initial funds deposit on cryptocondition address which locks funds for spending by either of address. * and also for setting spending plan for the funds' owner and heir * @return fundingtxid handle for subsequent references to this heir funding plan */ template UniValue HeirFund(uint64_t txfee, int64_t amount, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) { - UniValue result(UniValue::VOBJ); - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - struct CC_info *cp, C; - + UniValue result(UniValue::VOBJ); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + struct CC_info *cp, C; + cp = CCinit(&C, Helper::getMyEval()); if (txfee == 0) txfee = 10000; - + //std::cerr << "HeirFund() amount=" << amount << " txfee=" << txfee << " heirPubkey IsValid()=" << heirPubkey.IsValid() << " inactivityTime(sec)=" << inactivityTimeSec << " tokenid=" << tokenid.GetHex() << std::endl; - - if (!heirPubkey.IsValid()) { - std::cerr << "HeirFund() heirPubkey is not valid!" << std::endl; - return std::string(""); - } - + + if (!heirPubkey.IsValid()) { + std::cerr << "HeirFund() heirPubkey is not valid!" << std::endl; + return std::string(""); + } + CPubKey myPubkey = pubkey2pk(Mypubkey()); - - if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { // txfee for miners - int64_t inputs, change; - - if ((inputs=Helper::addOwnerInputs(tokenid, mtx, myPubkey, amount, (int32_t)64)) > 0) { // 2 x txfee: 1st for marker vout, 2nd to miners - //mtx.vout.push_back(MakeTokensCC1of2vout(/*Helper::getMyEval()*/EVAL_HEIR, amount, myPubkey, heirPubkey)); // add cryptocondition to spend amount for either pk - mtx.vout.push_back(Helper::make1of2Vout(amount, myPubkey, heirPubkey)); - - // add a marker for finding all plans in HeirList() - // TODO: change marker either to cc or normal txidaddr unspendable - CPubKey heirUnspendablePubKey = GetUnspendable(cp, 0); - mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(heirUnspendablePubKey)) << OP_CHECKSIG)); // TODO: do we need this marker? - - // calc and add change vout: - if (inputs > amount) - change = (inputs - amount); // -txfee <-- txfee pays user - - //std::cerr << "HeirFund() inputs=" << inputs << " amount=" << amount << " txfee=" << txfee << " change=" << change << '\n'; - - if (change != 0) { // vout[1] - mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); - } - - // add 1of2 vout validation pubkeys: - std::vector voutTokenPubkeys; - voutTokenPubkeys.push_back(myPubkey); - voutTokenPubkeys.push_back(heirPubkey); - - // add change for txfee and opreturn vouts and sign tx: - std::string rawhextx = FinalizeCCTx(0, cp, mtx, myPubkey, txfee, - Helper::makeCreateOpRet(tokenid, voutTokenPubkeys, myPubkey, heirPubkey, inactivityTimeSec, heirName)); - if (!rawhextx.empty()) { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hextx", rawhextx)); - } - else { - std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl; - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "sign error")); - } - } - else { // TODO: need result return unification with heiradd and claim - std::cerr << "HeirFund() could not find owner cc inputs" << std::endl; - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "could not find owner cc inputs")); - } - } - else { - std::cerr << "HeirFund() could not find normal inputs" << std::endl; - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "could not find normal inputs")); - } + + if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { // txfee for miners + int64_t inputs, change; + + if ((inputs=Helper::addOwnerInputs(tokenid, mtx, myPubkey, amount, (int32_t)64)) > 0) { // 2 x txfee: 1st for marker vout, 2nd to miners + //mtx.vout.push_back(MakeTokensCC1of2vout(/*Helper::getMyEval()*/EVAL_HEIR, amount, myPubkey, heirPubkey)); // add cryptocondition to spend amount for either pk + mtx.vout.push_back(Helper::make1of2Vout(amount, myPubkey, heirPubkey)); + + // add a marker for finding all plans in HeirList() + // TODO: change marker either to cc or normal txidaddr unspendable + CPubKey heirUnspendablePubKey = GetUnspendable(cp, 0); + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(heirUnspendablePubKey)) << OP_CHECKSIG)); // TODO: do we need this marker? + + // calc and add change vout: + if (inputs > amount) + change = (inputs - amount); // -txfee <-- txfee pays user + + //std::cerr << "HeirFund() inputs=" << inputs << " amount=" << amount << " txfee=" << txfee << " change=" << change << '\n'; + + if (change != 0) { // vout[1] + mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); + } + + // add 1of2 vout validation pubkeys: + std::vector voutTokenPubkeys; + voutTokenPubkeys.push_back(myPubkey); + voutTokenPubkeys.push_back(heirPubkey); + + // add change for txfee and opreturn vouts and sign tx: + std::string rawhextx = FinalizeCCTx(0, cp, mtx, myPubkey, txfee, + Helper::makeCreateOpRet(tokenid, voutTokenPubkeys, myPubkey, heirPubkey, inactivityTimeSec, heirName)); + if (!rawhextx.empty()) { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hextx", rawhextx)); + } + else { + std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "sign error")); + } + } + else { // TODO: need result return unification with heiradd and claim + std::cerr << "HeirFund() could not find owner cc inputs" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "could not find owner cc inputs")); + } + } + else { + std::cerr << "HeirFund() could not find normal inputs" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "could not find normal inputs")); + } return result; } -// if no these callers - it could not link +// if no these callers - it could not link UniValue HeirFundCoinCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid){ - return HeirFund(txfee, funds, heirName, heirPubkey, inactivityTimeSec, tokenid); + return HeirFund(txfee, funds, heirName, heirPubkey, inactivityTimeSec, tokenid); } UniValue HeirFundTokenCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) { - return HeirFund(txfee, funds, heirName, heirPubkey, inactivityTimeSec, tokenid); + return HeirFund(txfee, funds, heirName, heirPubkey, inactivityTimeSec, tokenid); } /** @@ -704,113 +704,113 @@ UniValue HeirFundTokenCaller(uint64_t txfee, int64_t funds, std::string heirName */ template UniValue _HeirAdd(uint256 fundingtxid, uint64_t txfee, int64_t amount, uint256 latesttxid, uint8_t funcId, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName, uint8_t hasHeirSpendingBegun) { - UniValue result(UniValue::VOBJ); - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); int64_t inputs, CCchange = 0; struct CC_info *cp, C; std::string rawhex; - - cp = CCinit(&C, Helper::getMyEval()); // for tokens shoud be EVAL_TOKENS to sign it correctly! - + + cp = CCinit(&C, Helper::getMyEval()); // for tokens shoud be EVAL_TOKENS to sign it correctly! + if (txfee == 0) txfee = 10000; - + CPubKey myPubkey = pubkey2pk(Mypubkey()); - + // check if it is the owner if (myPubkey != ownerPubkey) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "adding funds is only allowed for the owner of this contract")); return result; } - - if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { // txfee for miners - - int64_t inputs, change; - - if ((inputs = Helper::addOwnerInputs(tokenid, mtx, myPubkey, amount, 64)) > 0) { // TODO: why 64 max inputs? - - // we do not use markers anymore - storing data in opreturn is better - // add marker vout: - /* char markeraddr[64]; - CPubKey markerpubkey = CCtxidaddr(markeraddr, fundingtxid); - mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG)); // txfee 1, txfee 2 - for miners - std::cerr << "HeirAdd() adding markeraddr=" << markeraddr << '\n'; */ - - // add cryptocondition to spend this funded amount for either pk - mtx.vout.push_back(Helper::make1of2Vout(amount, ownerPubkey, heirPubkey)); - - if (inputs > amount) - change = (inputs - amount); // -txfee <-- txfee pays user - - //std::cerr << "HeirAdd() inputs=" << inputs << " amount=" << amount << " txfee=" << txfee << " change=" << change << '\n'; - - if (change != 0) { // vout[1] - mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); - } - - // add 1of2 vout validation pubkeys - needed only for tokens: - std::vector voutTokenPubkeys; - voutTokenPubkeys.push_back(ownerPubkey); - voutTokenPubkeys.push_back(heirPubkey); - - // add opreturn 'A' and sign tx: // this txfee ignored - std::string rawhextx = (FinalizeCCTx(0, cp, mtx, myPubkey, txfee, - Helper::makeAddOpRet(tokenid, voutTokenPubkeys, fundingtxid, hasHeirSpendingBegun))); - - if (!rawhextx.empty()) { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hextx", rawhextx)); - } - else { - std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl; - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "sign error")); - } - - } - else { - std::cerr << "HeirAdd cannot find owner cc inputs" << std::endl; - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "can't find owner cc inputs")); - } - } - else { - std::cerr << "HeirAdd cannot find normal inputs for tx fee" << std::endl; - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "can't find normal inputs for tx fee")); - } - - - + + if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { // txfee for miners + + int64_t inputs, change; + + if ((inputs = Helper::addOwnerInputs(tokenid, mtx, myPubkey, amount, 64)) > 0) { // TODO: why 64 max inputs? + + // we do not use markers anymore - storing data in opreturn is better + // add marker vout: + /* char markeraddr[64]; + CPubKey markerpubkey = CCtxidaddr(markeraddr, fundingtxid); + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG)); // txfee 1, txfee 2 - for miners + std::cerr << "HeirAdd() adding markeraddr=" << markeraddr << '\n'; */ + + // add cryptocondition to spend this funded amount for either pk + mtx.vout.push_back(Helper::make1of2Vout(amount, ownerPubkey, heirPubkey)); + + if (inputs > amount) + change = (inputs - amount); // -txfee <-- txfee pays user + + //std::cerr << "HeirAdd() inputs=" << inputs << " amount=" << amount << " txfee=" << txfee << " change=" << change << '\n'; + + if (change != 0) { // vout[1] + mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); + } + + // add 1of2 vout validation pubkeys - needed only for tokens: + std::vector voutTokenPubkeys; + voutTokenPubkeys.push_back(ownerPubkey); + voutTokenPubkeys.push_back(heirPubkey); + + // add opreturn 'A' and sign tx: // this txfee ignored + std::string rawhextx = (FinalizeCCTx(0, cp, mtx, myPubkey, txfee, + Helper::makeAddOpRet(tokenid, voutTokenPubkeys, fundingtxid, hasHeirSpendingBegun))); + + if (!rawhextx.empty()) { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hextx", rawhextx)); + } + else { + std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "sign error")); + } + + } + else { + std::cerr << "HeirAdd cannot find owner cc inputs" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "can't find owner cc inputs")); + } + } + else { + std::cerr << "HeirAdd cannot find normal inputs for tx fee" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "can't find normal inputs for tx fee")); + } + + + return result; } UniValue HeirAddCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { - - CPubKey ownerPubkey, heirPubkey; - int64_t inactivityTimeSec; - - uint256 latesttxid, tokenid = zeroid; - uint8_t funcId; - std::string heirName; - uint8_t hasHeirSpendingBegun = 0; - - if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun)) != zeroid) { - if (tokenid == zeroid) - return _HeirAdd(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); - else - return _HeirAdd(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); - } - else { - UniValue result(UniValue::VOBJ); - - fprintf(stderr, "HeirAdd() can't find any heir CC funding tx's\n"); - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "can't find any heir CC funding transactions")); - return result; - } + + CPubKey ownerPubkey, heirPubkey; + int64_t inactivityTimeSec; + + uint256 latesttxid, tokenid = zeroid; + uint8_t funcId; + std::string heirName; + uint8_t hasHeirSpendingBegun = 0; + + if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun)) != zeroid) { + if (tokenid == zeroid) + return _HeirAdd(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + else + return _HeirAdd(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + } + else { + UniValue result(UniValue::VOBJ); + + fprintf(stderr, "HeirAdd() can't find any heir CC funding tx's\n"); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "can't find any heir CC funding transactions")); + return result; + } } @@ -821,110 +821,110 @@ UniValue HeirAddCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { */ template UniValue _HeirClaim(uint256 fundingtxid, uint64_t txfee, int64_t amount, uint256 latesttxid, uint8_t funcId, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName, uint8_t hasHeirSpendingBegun) { - UniValue result(UniValue::VOBJ); - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey myPubkey; + UniValue result(UniValue::VOBJ); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + CPubKey myPubkey; int64_t inputs, change = 0; struct CC_info *cp, C; - - cp = CCinit(&C, EVAL_HEIR); - if (txfee == 0) + + cp = CCinit(&C, EVAL_HEIR); + if (txfee == 0) txfee = 10000; - + int32_t numblocks; uint64_t durationSec = 0; - - // we do not need to find duration if spending already has begun - if (!hasHeirSpendingBegun) { + + // we do not need to find duration if spending already has begun + if (!hasHeirSpendingBegun) { durationSec = CCduration(numblocks, latesttxid); std::cerr << "HeirClaim() duration=" << durationSec << " inactivityTime=" << inactivityTimeSec << " numblocks=" << numblocks << std::endl; } - + // spending is allowed if there is already spending tx or inactivity time //bool isAllowedToHeir = (funcId == 'C' || durationSec > inactivityTimeSec) ? true : false; - bool isAllowedToHeir = (hasHeirSpendingBegun || durationSec > inactivityTimeSec) ? true : false; + bool isAllowedToHeir = (hasHeirSpendingBegun || durationSec > inactivityTimeSec) ? true : false; myPubkey = pubkey2pk(Mypubkey()); - + // if it is the heir, check if spending not allowed to heir yet if (myPubkey == heirPubkey && !isAllowedToHeir) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "spending is not allowed yet for the heir")); return result; } - - // we do not use markers any more: - // we allow owner to spend funds at any time: - // if it is the owner, check if spending already allowed to heir - /* if (myPubkey == ownerPubkey && isAllowedToHeir) { - result.push_back(Pair("result", "spending is not already allowed for the owner")); - return result; - } */ - - // add spending txfee from the calling user + + // we do not use markers any more: + // we allow owner to spend funds at any time: + // if it is the owner, check if spending already allowed to heir + /* if (myPubkey == ownerPubkey && isAllowedToHeir) { + result.push_back(Pair("result", "spending is not already allowed for the owner")); + return result; + } */ + + // add spending txfee from the calling user if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { - - // add spending from cc 1of2 address - if ((inputs = Add1of2AddressInputs(cp, fundingtxid, mtx, ownerPubkey, heirPubkey, amount, 60)) >= amount) // TODO: why only 60 inputs? + + // add spending from cc 1of2 address + if ((inputs = Add1of2AddressInputs(cp, fundingtxid, mtx, ownerPubkey, heirPubkey, amount, 60)) >= amount) // TODO: why only 60 inputs? { - /*if (inputs < amount) { - std::cerr << "HeirClaim() cant find enough HeirCC 1of2 inputs, found=" << inputs << " required=" << amount << std::endl; - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "can't find heir CC funding")); - - return result; - }*/ - - // add vout with amount to claiming address - mtx.vout.push_back(Helper::makeUserVout(amount, myPubkey)); // vout[0] - + /*if (inputs < amount) { + std::cerr << "HeirClaim() cant find enough HeirCC 1of2 inputs, found=" << inputs << " required=" << amount << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "can't find heir CC funding")); + + return result; + }*/ + + // add vout with amount to claiming address + mtx.vout.push_back(Helper::makeUserVout(amount, myPubkey)); // vout[0] + // calc and add change vout: if (inputs > amount) - change = (inputs - amount); // -txfee <-- txfee pays user - + change = (inputs - amount); // -txfee <-- txfee pays user + //std::cerr << "HeirClaim() inputs=" << inputs << " amount=" << amount << " txfee=" << txfee << " change=" << change << '\n'; - - // change to 1of2 funding addr: + + // change to 1of2 funding addr: if (change != 0) { // vout[1] mtx.vout.push_back(Helper::make1of2Vout(change, ownerPubkey, heirPubkey)); // using always pubkeys from OP_RETURN in order to not mixing them up! } - + // add marker vout: /*char markeraddr[64]; - CPubKey markerpubkey = CCtxidaddr(markeraddr, fundingtxid); - // NOTE: amount = 0 is not working: causes error code: -26, error message : 64 : dust - mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG)); // txfee 1, txfee 2 - for miners - std::cerr << "HeirClaim() adding markeraddr=" << markeraddr << '\n'; */ - - // get address of 1of2 cond + CPubKey markerpubkey = CCtxidaddr(markeraddr, fundingtxid); + // NOTE: amount = 0 is not working: causes error code: -26, error message : 64 : dust + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG)); // txfee 1, txfee 2 - for miners + std::cerr << "HeirClaim() adding markeraddr=" << markeraddr << '\n'; */ + + // get address of 1of2 cond char coinaddr[64]; Helper::GetCoinsOrTokensCCaddress1of2(coinaddr, ownerPubkey, heirPubkey); - - // retrieve priv key addresses for FinalizeCCtx: - uint8_t myprivkey[32]; + + // retrieve priv key addresses for FinalizeCCtx: + uint8_t myprivkey[32]; Myprivkey(myprivkey); - - // set pubkeys for finding 1of2 cc in FinalizeCCtx to sign it: - Helper::CCaddrCoinsOrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); - - // add 1of2 vout validation pubkeys (this is for tokens): - std::vector voutTokenPubkeys; - voutTokenPubkeys.push_back(ownerPubkey); - voutTokenPubkeys.push_back(heirPubkey); - + + // set pubkeys for finding 1of2 cc in FinalizeCCtx to sign it: + Helper::CCaddrCoinsOrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); + + // add 1of2 vout validation pubkeys (this is for tokens): + std::vector voutTokenPubkeys; + voutTokenPubkeys.push_back(ownerPubkey); + voutTokenPubkeys.push_back(heirPubkey); + // add opreturn 'C' and sign tx: // this txfee will be ignored - std::string rawhextx = FinalizeCCTx(0, cp, mtx, myPubkey, txfee, - Helper::makeClaimOpRet(tokenid, voutTokenPubkeys, fundingtxid, (myPubkey == heirPubkey) ? 1 : hasHeirSpendingBegun)); // forward isHeirSpending to the next latest tx - - if (!rawhextx.empty()) { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hextx", rawhextx)); - } - else { - std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl; - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "sign error")); - } - + std::string rawhextx = FinalizeCCTx(0, cp, mtx, myPubkey, txfee, + Helper::makeClaimOpRet(tokenid, voutTokenPubkeys, fundingtxid, (myPubkey == heirPubkey) ? 1 : hasHeirSpendingBegun)); // forward isHeirSpending to the next latest tx + + if (!rawhextx.empty()) { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hextx", rawhextx)); + } + else { + std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "sign error")); + } + } else { fprintf(stderr, "HeirClaim() cant find Heir CC inputs\n"); result.push_back(Pair("result", "error")); @@ -935,187 +935,187 @@ template UniValue _HeirClaim(uint256 fundingtxid, uint64_t txfe result.push_back(Pair("result", "error")); result.push_back(Pair("error", "can't find sufficient user inputs to pay transaction fee")); } - - + + return result; } UniValue HeirClaimCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { - - CPubKey ownerPubkey, heirPubkey; - int64_t inactivityTimeSec; - - uint256 latesttxid, tokenid = zeroid; - uint8_t funcId; - std::string heirName; - uint8_t hasHeirSpendingBegun = 0; - - if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun)) != zeroid) { - if( tokenid == zeroid ) - return _HeirClaim(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); - else - return _HeirClaim(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); - - } - else { - UniValue result(UniValue::VOBJ); - - fprintf(stderr, "HeirClaim() can't find any heir CC funding tx's\n"); - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "can't find any heir CC funding transactions")); - return result; - } + + CPubKey ownerPubkey, heirPubkey; + int64_t inactivityTimeSec; + + uint256 latesttxid, tokenid = zeroid; + uint8_t funcId; + std::string heirName; + uint8_t hasHeirSpendingBegun = 0; + + if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun)) != zeroid) { + if( tokenid == zeroid ) + return _HeirClaim(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + else + return _HeirClaim(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + + } + else { + UniValue result(UniValue::VOBJ); + + fprintf(stderr, "HeirClaim() can't find any heir CC funding tx's\n"); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "can't find any heir CC funding transactions")); + return result; + } } /** * heirinfo rpc call implementation - * returns some information about heir CC contract plan by a handle of initial fundingtxid: + * returns some information about heir CC contract plan by a handle of initial fundingtxid: * plan name, owner and heir pubkeys, funds deposited and available, flag if spending is enabled for the heir * @return heir info data */ UniValue HeirInfo(uint256 fundingtxid) { UniValue result(UniValue::VOBJ); - - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction fundingtx; - uint256 hashBlock; - const bool allowSlow = false; - - //char markeraddr[64]; - //CCtxidaddr(markeraddr, fundingtxid); - //SetCCunspents(unspentOutputs, markeraddr); - - // get initial funding tx and set it as initial lasttx: - if (myGetTransaction(fundingtxid, fundingtx, hashBlock) && fundingtx.vout.size()) { - - CPubKey ownerPubkey, heirPubkey; - uint256 dummyTokenid, tokenid = zeroid; // important to clear tokenid - std::string heirName; - int64_t inactivityTimeSec; - const bool noLogging = false; - uint8_t funcId; - - /*CScript opret = fundingtx.vout.size() > 0 ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript(); - uint8_t funcId = DecodeHeirEitherOpRet(opret, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, true); - if (funcId == 0) { - std::cerr << "HeirInfo() this fundingtx is incorrect" << std::endl; - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "initial tx F not found")); - return result; - }*/ - - struct CC_info *cp, C; - cp = CCinit(&C, EVAL_HEIR); - - uint8_t hasHeirSpendingBegun = 0; - - uint256 latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); - - if (latestFundingTxid != zeroid) { - int32_t numblocks; - uint64_t durationSec = 0; - - //std::cerr << "HeirInfo() latesttxid=" << latestFundingTxid.GetHex() << '\n'; - - std::ostringstream stream; - std::string msg; - - result.push_back(Pair("fundingtxid", fundingtxid.GetHex())); - result.push_back(Pair("name", heirName.c_str())); - - if (tokenid != zeroid) { // tokens - stream << tokenid.GetHex(); - msg = "tokenid"; - result.push_back(Pair(msg, stream.str().c_str())); - stream.str(""); - stream.clear(); - } - - char hexbuf[67]; - stream << pubkey33_str(hexbuf, (uint8_t*)ownerPubkey.begin()); - result.push_back(Pair("owner", stream.str().c_str())); - stream.str(""); - stream.clear(); - - stream << pubkey33_str(hexbuf, (uint8_t*)heirPubkey.begin()); - result.push_back(Pair("heir", stream.str().c_str())); - stream.str(""); - stream.clear(); - - int64_t total; - if (tokenid == zeroid) - total = LifetimeHeirContractFunds(cp, fundingtxid, ownerPubkey, heirPubkey); - else - total = LifetimeHeirContractFunds(cp, fundingtxid, ownerPubkey, heirPubkey); - - if (tokenid == zeroid) { - msg = "funding total in coins"; - stream << (double)total / COIN; - } - else { - msg = "funding total in tokens"; - stream << total; - } - result.push_back(Pair(msg, stream.str().c_str())); - stream.str(""); - stream.clear(); - - int64_t inputs; - if (tokenid == zeroid) - inputs = Add1of2AddressInputs(cp, fundingtxid, mtx, ownerPubkey, heirPubkey, 0, 60); //NOTE: amount = 0 means all unspent inputs - else - inputs = Add1of2AddressInputs(cp, fundingtxid, mtx, ownerPubkey, heirPubkey, 0, 60); - - if (tokenid == zeroid) { - msg = "funding available in coins"; - stream << (double)inputs / COIN; - } - else { - msg = "funding available in tokens"; - stream << inputs; - } - result.push_back(Pair(msg, stream.str().c_str())); - stream.str(""); - stream.clear(); - - if (tokenid != zeroid) { - int64_t ownerInputs = TokenHelper::addOwnerInputs(tokenid, mtx, ownerPubkey, 0, (int32_t)64); - stream << ownerInputs; - msg = "owner funding available in tokens"; - result.push_back(Pair(msg, stream.str().c_str())); - stream.str(""); - stream.clear(); - } - - stream << inactivityTimeSec; - result.push_back(Pair("inactivity time setting", stream.str().c_str())); - stream.str(""); - stream.clear(); - - if (!hasHeirSpendingBegun) { // we do not need find duration if the spending already has begun - durationSec = CCduration(numblocks, latestFundingTxid); - std::cerr << "HeirInfo() duration=" << durationSec << " inactivityTime=" << inactivityTimeSec << " numblocks=" << numblocks << '\n'; - } - - stream << std::boolalpha << (hasHeirSpendingBegun || durationSec > inactivityTimeSec); - result.push_back(Pair("spending allowed for the heir", stream.str().c_str())); - stream.str(""); - stream.clear(); - - result.push_back(Pair("result", "success")); - } - else { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "could not find heir cc plan for this txid")); - } - } - else { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "could not find heir cc plan for this txid (no initial tx)")); - } - return (result); + + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + CTransaction fundingtx; + uint256 hashBlock; + const bool allowSlow = false; + + //char markeraddr[64]; + //CCtxidaddr(markeraddr, fundingtxid); + //SetCCunspents(unspentOutputs, markeraddr); + + // get initial funding tx and set it as initial lasttx: + if (myGetTransaction(fundingtxid, fundingtx, hashBlock) && fundingtx.vout.size()) { + + CPubKey ownerPubkey, heirPubkey; + uint256 dummyTokenid, tokenid = zeroid; // important to clear tokenid + std::string heirName; + int64_t inactivityTimeSec; + const bool noLogging = false; + uint8_t funcId; + + /*CScript opret = fundingtx.vout.size() > 0 ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript(); + uint8_t funcId = DecodeHeirEitherOpRet(opret, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, true); + if (funcId == 0) { + std::cerr << "HeirInfo() this fundingtx is incorrect" << std::endl; + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "initial tx F not found")); + return result; + }*/ + + struct CC_info *cp, C; + cp = CCinit(&C, EVAL_HEIR); + + uint8_t hasHeirSpendingBegun = 0; + + uint256 latestFundingTxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + + if (latestFundingTxid != zeroid) { + int32_t numblocks; + uint64_t durationSec = 0; + + //std::cerr << "HeirInfo() latesttxid=" << latestFundingTxid.GetHex() << '\n'; + + std::ostringstream stream; + std::string msg; + + result.push_back(Pair("fundingtxid", fundingtxid.GetHex())); + result.push_back(Pair("name", heirName.c_str())); + + if (tokenid != zeroid) { // tokens + stream << tokenid.GetHex(); + msg = "tokenid"; + result.push_back(Pair(msg, stream.str().c_str())); + stream.str(""); + stream.clear(); + } + + char hexbuf[67]; + stream << pubkey33_str(hexbuf, (uint8_t*)ownerPubkey.begin()); + result.push_back(Pair("owner", stream.str().c_str())); + stream.str(""); + stream.clear(); + + stream << pubkey33_str(hexbuf, (uint8_t*)heirPubkey.begin()); + result.push_back(Pair("heir", stream.str().c_str())); + stream.str(""); + stream.clear(); + + int64_t total; + if (tokenid == zeroid) + total = LifetimeHeirContractFunds(cp, fundingtxid, ownerPubkey, heirPubkey); + else + total = LifetimeHeirContractFunds(cp, fundingtxid, ownerPubkey, heirPubkey); + + if (tokenid == zeroid) { + msg = "funding total in coins"; + stream << (double)total / COIN; + } + else { + msg = "funding total in tokens"; + stream << total; + } + result.push_back(Pair(msg, stream.str().c_str())); + stream.str(""); + stream.clear(); + + int64_t inputs; + if (tokenid == zeroid) + inputs = Add1of2AddressInputs(cp, fundingtxid, mtx, ownerPubkey, heirPubkey, 0, 60); //NOTE: amount = 0 means all unspent inputs + else + inputs = Add1of2AddressInputs(cp, fundingtxid, mtx, ownerPubkey, heirPubkey, 0, 60); + + if (tokenid == zeroid) { + msg = "funding available in coins"; + stream << (double)inputs / COIN; + } + else { + msg = "funding available in tokens"; + stream << inputs; + } + result.push_back(Pair(msg, stream.str().c_str())); + stream.str(""); + stream.clear(); + + if (tokenid != zeroid) { + int64_t ownerInputs = TokenHelper::addOwnerInputs(tokenid, mtx, ownerPubkey, 0, (int32_t)64); + stream << ownerInputs; + msg = "owner funding available in tokens"; + result.push_back(Pair(msg, stream.str().c_str())); + stream.str(""); + stream.clear(); + } + + stream << inactivityTimeSec; + result.push_back(Pair("inactivity time setting", stream.str().c_str())); + stream.str(""); + stream.clear(); + + if (!hasHeirSpendingBegun) { // we do not need find duration if the spending already has begun + durationSec = CCduration(numblocks, latestFundingTxid); + std::cerr << "HeirInfo() duration=" << durationSec << " inactivityTime=" << inactivityTimeSec << " numblocks=" << numblocks << '\n'; + } + + stream << std::boolalpha << (hasHeirSpendingBegun || durationSec > inactivityTimeSec); + result.push_back(Pair("spending allowed for the heir", stream.str().c_str())); + stream.str(""); + stream.clear(); + + result.push_back(Pair("result", "success")); + } + else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "could not find heir cc plan for this txid")); + } + } + else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "could not find heir cc plan for this txid (no initial tx)")); + } + return (result); } /** @@ -1125,47 +1125,47 @@ UniValue HeirInfo(uint256 fundingtxid) template void _HeirList(struct CC_info *cp, UniValue &result) { - std::vector> unspentOutputs; - char coinaddr[64]; - CPubKey ccPubKeyEmpty; - GetCCaddress(cp, coinaddr, ccPubKeyEmpty); - SetCCunspents(unspentOutputs, cp->normaladdr); - - //std::cerr << "HeirList() finding heir marker from Heir contract addr=" << cp->normaladdr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; - - // TODO: move marker to special cc addr to prevent checking all tokens - for (std::vector>::const_iterator it = unspentOutputs.begin(); it != unspentOutputs.end(); it++) { - uint256 hashBlock; - uint256 txid = it->first.txhash; - uint256 tokenid; - int32_t vout = (int32_t)it->first.index; - - //std::cerr << "HeirList() checking txid=" << txid.GetHex() << " vout=" << vout << '\n'; - - CTransaction fundingtx; - if (GetTransaction(txid, fundingtx, hashBlock, false)) { - CPubKey ownerPubkey, heirPubkey; - std::string heirName; - int64_t inactivityTimeSec; - const bool noLogging = true; - uint256 tokenid; - - CScript opret = (fundingtx.vout.size() > 0) ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript(); - uint8_t funcId = DecodeHeirEitherOpRet(opret, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, true); - - // note: if it is not Heir token funcId would be equal to 0 - if (funcId == 'F') { - //result.push_back(Pair("fundingtxid kind name", txid.GetHex() + std::string(" ") + (typeid(Helper) == typeid(TokenHelper) ? std::string("token") : std::string("coin")) + std::string(" ") + heirName)); - result.push_back( Pair("fundingtxid", txid.GetHex()) ); - } - else { - std::cerr << "HeirList() this is not the initial F transaction=" << txid.GetHex() << std::endl; - } - } - else { - std::cerr << "HeirList() could not load transaction=" << txid.GetHex() << std::endl; - } - } + std::vector> unspentOutputs; + char coinaddr[64]; + CPubKey ccPubKeyEmpty; + GetCCaddress(cp, coinaddr, ccPubKeyEmpty); + SetCCunspents(unspentOutputs, cp->normaladdr); + + //std::cerr << "HeirList() finding heir marker from Heir contract addr=" << cp->normaladdr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; + + // TODO: move marker to special cc addr to prevent checking all tokens + for (std::vector>::const_iterator it = unspentOutputs.begin(); it != unspentOutputs.end(); it++) { + uint256 hashBlock; + uint256 txid = it->first.txhash; + uint256 tokenid; + int32_t vout = (int32_t)it->first.index; + + //std::cerr << "HeirList() checking txid=" << txid.GetHex() << " vout=" << vout << '\n'; + + CTransaction fundingtx; + if (GetTransaction(txid, fundingtx, hashBlock, false)) { + CPubKey ownerPubkey, heirPubkey; + std::string heirName; + int64_t inactivityTimeSec; + const bool noLogging = true; + uint256 tokenid; + + CScript opret = (fundingtx.vout.size() > 0) ? fundingtx.vout[fundingtx.vout.size() - 1].scriptPubKey : CScript(); + uint8_t funcId = DecodeHeirEitherOpRet(opret, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, true); + + // note: if it is not Heir token funcId would be equal to 0 + if (funcId == 'F') { + //result.push_back(Pair("fundingtxid kind name", txid.GetHex() + std::string(" ") + (typeid(Helper) == typeid(TokenHelper) ? std::string("token") : std::string("coin")) + std::string(" ") + heirName)); + result.push_back( Pair("fundingtxid", txid.GetHex()) ); + } + else { + std::cerr << "HeirList() this is not the initial F transaction=" << txid.GetHex() << std::endl; + } + } + else { + std::cerr << "HeirList() could not load transaction=" << txid.GetHex() << std::endl; + } + } } @@ -1173,15 +1173,16 @@ UniValue HeirList() { UniValue result(UniValue::VOBJ); result.push_back(Pair("result", "success")); - + struct CC_info *cpHeir, *cpTokens, heirC, tokenC; // NOTE we must use a separate 'C' structure for each CCinit! - cpHeir = CCinit(&heirC, EVAL_HEIR); - cpTokens = CCinit(&tokenC, EVAL_TOKENS); - - _HeirList(cpHeir, result); - _HeirList(cpTokens, result); - - return result; + cpHeir = CCinit(&heirC, EVAL_HEIR); + cpTokens = CCinit(&tokenC, EVAL_TOKENS); + + _HeirList(cpHeir, result); + _HeirList(cpTokens, result); + + return result; } + From 557886b5914d6b39a1b5f3a34f0a1c3ae1f048c6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:16:38 -1100 Subject: [PATCH 135/144] CC_info --- src/cc/heir_validate.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index f8e66e3d5..c41c38c09 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -123,13 +123,13 @@ public: class CValidatorBase { public: - CValidatorBase(CCcontract_info* cp) : m_cp(cp) {} + CValidatorBase(CC_info* cp) : m_cp(cp) {} virtual bool isVinValidator() const = 0; virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const = 0; virtual bool validateVout(CTxOut vout, std::string& message) const = 0; protected: - CCcontract_info * m_cp; + CC_info * m_cp; }; /** @@ -138,11 +138,11 @@ protected: class CInputIdentifierBase { public: - CInputIdentifierBase(CCcontract_info* cp) : m_cp(cp) {} + CInputIdentifierBase(CC_info* cp) : m_cp(cp) {} virtual std::string inputName() const = 0; virtual bool identifyInput(CTxIn vin) const = 0; protected: - CCcontract_info * m_cp; + CC_info * m_cp; }; /** @@ -375,7 +375,7 @@ private: class CNormalInputIdentifier : CInputIdentifierBase { public: - CNormalInputIdentifier(CCcontract_info* cp) : CInputIdentifierBase(cp) {} + CNormalInputIdentifier(CC_info* cp) : CInputIdentifierBase(cp) {} virtual std::string inputName() const { return std::string("normal input"); } virtual bool identifyInput(CTxIn vin) const { return !IsCCInput(vin.scriptSig); @@ -384,7 +384,7 @@ public: class CCCInputIdentifier : CInputIdentifierBase { public: - CCCInputIdentifier(CCcontract_info* cp) : CInputIdentifierBase(cp) {} + CCCInputIdentifier(CC_info* cp) : CInputIdentifierBase(cp) {} virtual std::string inputName() const { return std::string("CC input"); } virtual bool identifyInput(CTxIn vin) const { return IsCCInput(vin.scriptSig); @@ -398,7 +398,7 @@ public: template class CCC1of2AddressValidator : CValidatorBase { public: - CCC1of2AddressValidator(CCcontract_info* cp, CScript opRetScript, std::string customMessage = "") : + CCC1of2AddressValidator(CC_info* cp, CScript opRetScript, std::string customMessage = "") : m_fundingOpretScript(opRetScript), m_customMessage(customMessage), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } @@ -452,7 +452,7 @@ private: template class CMyPubkeyVoutValidator : CValidatorBase { public: - CMyPubkeyVoutValidator(CCcontract_info* cp, CScript opRetScript, bool checkNormals) + CMyPubkeyVoutValidator(CC_info* cp, CScript opRetScript, bool checkNormals) : m_fundingOpretScript(opRetScript), m_checkNormals(checkNormals), CValidatorBase(cp) { } virtual bool isVinValidator() const { return false; } @@ -512,7 +512,7 @@ private: template class CHeirSpendValidator : CValidatorBase { public: - CHeirSpendValidator(CCcontract_info* cp, CScript opRetScript, uint256 latesttxid, uint8_t isHeirSpendingBegan) + CHeirSpendValidator(CC_info* cp, CScript opRetScript, uint256 latesttxid, uint8_t isHeirSpendingBegan) : m_fundingOpretScript(opRetScript), m_latesttxid(latesttxid), m_isHeirSpendingBegan(isHeirSpendingBegan), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } @@ -568,7 +568,7 @@ private: template class COpRetValidator : CValidatorBase { public: - COpRetValidator(CCcontract_info* cp, CScript opret) + COpRetValidator(CC_info* cp, CScript opret) : m_fundingOpretScript(opret), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } @@ -619,7 +619,7 @@ private: template class CNullValidator : CValidatorBase { public: - CNullValidator(CCcontract_info* cp) + CNullValidator(CC_info* cp) : CValidatorBase(cp) { } virtual bool isVinValidator() const { return false; } From c4d932a318885e2163474e5f0850ef2a80021011 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:23:08 -1100 Subject: [PATCH 136/144] Partial revert --- src/cc/CCinclude.h | 1 + src/cc/heir.cpp | 27 +++++++++++++-------------- src/cc/heir_validate.h | 32 ++++++++++++++++---------------- src/script/sign.cpp | 4 ++-- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 0b537f3d3..eda543a66 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -116,6 +116,7 @@ struct CC_info uint8_t didinit; }; +typedef struct CC_info CCcontract_info; struct CC_info *CCinit(struct CC_info *cp,uint8_t evalcode); struct oracleprice_info diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 7867032b6..ccf9da1bf 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -34,7 +34,7 @@ class TokenHelper; // Plan validation runner, it may be called twice - for coins and tokens // (sadly we cannot have yet 'templatized' lambdas, if we could we could capture all these params inside HeirValidation()...) -template bool RunValidationPlans(uint8_t funcId, struct CC_info* cp, Eval* eval, const CTransaction& tx, uint256 latestTxid, CScript fundingOpretScript, uint8_t hasHeirSpendingBegun) +template bool RunValidationPlans(uint8_t funcId, struct CCcontract_info* cp, Eval* eval, const CTransaction& tx, uint256 latestTxid, CScript fundingOpretScript, uint8_t hasHeirSpendingBegun) { int32_t numvins = tx.vin.size(); int32_t numvouts = tx.vout.size(); @@ -104,14 +104,14 @@ template bool RunValidationPlans(uint8_t funcId, struct CC_inf /** * Tx validation entry function */ -bool HeirValidate(struct CC_info* cpHeir, Eval* eval, const CTransaction& tx, uint32_t nIn) +bool HeirValidate(struct CCcontract_info* cpHeir, Eval* eval, const CTransaction& tx, uint32_t nIn) { int32_t numvins = tx.vin.size(); int32_t numvouts = tx.vout.size(); //int32_t preventCCvins = -1; //int32_t preventCCvouts = -1; - struct CC_info *cpTokens, tokensC; + struct CCcontract_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); if (numvouts < 1) @@ -237,7 +237,7 @@ bool HeirValidate(struct CC_info* cpHeir, Eval* eval, const CTransaction& tx, ui * Checks if vout is to cryptocondition address * @return vout value in satoshis */ -template int64_t IsHeirFundingVout(struct CC_info* cp, const CTransaction& tx, int32_t voutIndex, CPubKey ownerPubkey, CPubKey heirPubkey) +template int64_t IsHeirFundingVout(struct CCcontract_info* cp, const CTransaction& tx, int32_t voutIndex, CPubKey ownerPubkey, CPubKey heirPubkey) { char destaddr[65], heirFundingAddr[65]; @@ -437,7 +437,7 @@ uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &toke // TODO: correct cc addr: std::vector> unspentOutputs; - struct CC_info *cp, C; + struct CCcontract_info *cp, C; cp = CCinit(&C, EVAL_HEIR); char coinaddr[64]; GetCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); // get the address of cryptocondition '1 of 2 pubkeys' @@ -507,7 +507,7 @@ uint256 FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &token } // add inputs of 1 of 2 cc address -template int64_t Add1of2AddressInputs(struct CC_info* cp, uint256 fundingtxid, CMutableTransaction& mtx, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t total, int32_t maxinputs) +template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, uint256 fundingtxid, CMutableTransaction& mtx, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t total, int32_t maxinputs) { // TODO: add threshold check int64_t nValue, voutValue, totalinputs = 0; @@ -566,7 +566,7 @@ template int64_t Add1of2AddressInputs(struct CC_info* cp, uint256 /** * enumerate all tx's sending to CCHeir 1of2address and calc total lifetime funds */ -template int64_t LifetimeHeirContractFunds(struct CC_info* cp, uint256 fundingtxid, CPubKey ownerPubkey, CPubKey heirPubkey) +template int64_t LifetimeHeirContractFunds(struct CCcontract_info* cp, uint256 fundingtxid, CPubKey ownerPubkey, CPubKey heirPubkey) { char coinaddr[64]; Helper::GetCoinsOrTokensCCaddress1of2(coinaddr, ownerPubkey, heirPubkey); // get the address of cryptocondition '1 of 2 pubkeys' @@ -619,7 +619,7 @@ template UniValue HeirFund(uint64_t txfee, int64_t amount, std { UniValue result(UniValue::VOBJ); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - struct CC_info *cp, C; + struct CCcontract_info *cp, C; cp = CCinit(&C, Helper::getMyEval()); if (txfee == 0) @@ -707,7 +707,7 @@ template UniValue _HeirAdd(uint256 fundingtxid, uint64_t txfee, i UniValue result(UniValue::VOBJ); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); int64_t inputs, CCchange = 0; - struct CC_info *cp, C; + struct CCcontract_info *cp, C; std::string rawhex; cp = CCinit(&C, Helper::getMyEval()); // for tokens shoud be EVAL_TOKENS to sign it correctly! @@ -825,7 +825,7 @@ template UniValue _HeirClaim(uint256 fundingtxid, uint64_t txfe CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CPubKey myPubkey; int64_t inputs, change = 0; - struct CC_info *cp, C; + struct CCcontract_info *cp, C; cp = CCinit(&C, EVAL_HEIR); if (txfee == 0) @@ -1006,7 +1006,7 @@ UniValue HeirInfo(uint256 fundingtxid) return result; }*/ - struct CC_info *cp, C; + struct CCcontract_info *cp, C; cp = CCinit(&C, EVAL_HEIR); uint8_t hasHeirSpendingBegun = 0; @@ -1123,7 +1123,7 @@ UniValue HeirInfo(uint256 fundingtxid) * @return list of heir plan handles (fundingtxid) */ -template void _HeirList(struct CC_info *cp, UniValue &result) +template void _HeirList(struct CCcontract_info *cp, UniValue &result) { std::vector> unspentOutputs; char coinaddr[64]; @@ -1174,7 +1174,7 @@ UniValue HeirList() UniValue result(UniValue::VOBJ); result.push_back(Pair("result", "success")); - struct CC_info *cpHeir, *cpTokens, heirC, tokenC; // NOTE we must use a separate 'C' structure for each CCinit! + struct CCcontract_info *cpHeir, *cpTokens, heirC, tokenC; // NOTE we must use a separate 'C' structure for each CCinit! cpHeir = CCinit(&heirC, EVAL_HEIR); cpTokens = CCinit(&tokenC, EVAL_TOKENS); @@ -1185,4 +1185,3 @@ UniValue HeirList() return result; } - diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index c41c38c09..c4bb7ea60 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -47,11 +47,11 @@ public: return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); } */ static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - struct CC_info *cpHeir, heirC; + struct CCcontract_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_HEIR); return GetCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); } - static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { CCaddr1of2set(cp, ownerPubkey, heirPubkey, coinaddr); } }; @@ -61,7 +61,7 @@ class TokenHelper { public: static uint8_t getMyEval() { return EVAL_TOKENS; } static int64_t addOwnerInputs(uint256 tokenid, CMutableTransaction& mtx, CPubKey ownerPubkey, int64_t total, int32_t maxinputs) { - struct CC_info *cpHeir, heirC; + struct CCcontract_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_TOKENS); return AddTokenCCInputs(cpHeir, mtx, ownerPubkey, tokenid, total, maxinputs); } @@ -89,12 +89,12 @@ public: return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS } */ static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { - struct CC_info *cpHeir, heirC; + struct CCcontract_info *cpHeir, heirC; cpHeir = CCinit(&heirC, EVAL_HEIR); return GetTokensCCaddress1of2(cpHeir, coinaddr, ownerPubkey, heirPubkey); } - static void CCaddrCoinsOrTokens1of2set(struct CC_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { + static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { CCaddrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); } @@ -123,13 +123,13 @@ public: class CValidatorBase { public: - CValidatorBase(CC_info* cp) : m_cp(cp) {} + CValidatorBase(CCcontract_info* cp) : m_cp(cp) {} virtual bool isVinValidator() const = 0; virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const = 0; virtual bool validateVout(CTxOut vout, std::string& message) const = 0; protected: - CC_info * m_cp; + CCcontract_info * m_cp; }; /** @@ -138,11 +138,11 @@ protected: class CInputIdentifierBase { public: - CInputIdentifierBase(CC_info* cp) : m_cp(cp) {} + CInputIdentifierBase(CCcontract_info* cp) : m_cp(cp) {} virtual std::string inputName() const = 0; virtual bool identifyInput(CTxIn vin) const = 0; protected: - CC_info * m_cp; + CCcontract_info * m_cp; }; /** @@ -375,7 +375,7 @@ private: class CNormalInputIdentifier : CInputIdentifierBase { public: - CNormalInputIdentifier(CC_info* cp) : CInputIdentifierBase(cp) {} + CNormalInputIdentifier(CCcontract_info* cp) : CInputIdentifierBase(cp) {} virtual std::string inputName() const { return std::string("normal input"); } virtual bool identifyInput(CTxIn vin) const { return !IsCCInput(vin.scriptSig); @@ -384,7 +384,7 @@ public: class CCCInputIdentifier : CInputIdentifierBase { public: - CCCInputIdentifier(CC_info* cp) : CInputIdentifierBase(cp) {} + CCCInputIdentifier(CCcontract_info* cp) : CInputIdentifierBase(cp) {} virtual std::string inputName() const { return std::string("CC input"); } virtual bool identifyInput(CTxIn vin) const { return IsCCInput(vin.scriptSig); @@ -398,7 +398,7 @@ public: template class CCC1of2AddressValidator : CValidatorBase { public: - CCC1of2AddressValidator(CC_info* cp, CScript opRetScript, std::string customMessage = "") : + CCC1of2AddressValidator(CCcontract_info* cp, CScript opRetScript, std::string customMessage = "") : m_fundingOpretScript(opRetScript), m_customMessage(customMessage), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } @@ -452,7 +452,7 @@ private: template class CMyPubkeyVoutValidator : CValidatorBase { public: - CMyPubkeyVoutValidator(CC_info* cp, CScript opRetScript, bool checkNormals) + CMyPubkeyVoutValidator(CCcontract_info* cp, CScript opRetScript, bool checkNormals) : m_fundingOpretScript(opRetScript), m_checkNormals(checkNormals), CValidatorBase(cp) { } virtual bool isVinValidator() const { return false; } @@ -512,7 +512,7 @@ private: template class CHeirSpendValidator : CValidatorBase { public: - CHeirSpendValidator(CC_info* cp, CScript opRetScript, uint256 latesttxid, uint8_t isHeirSpendingBegan) + CHeirSpendValidator(CCcontract_info* cp, CScript opRetScript, uint256 latesttxid, uint8_t isHeirSpendingBegan) : m_fundingOpretScript(opRetScript), m_latesttxid(latesttxid), m_isHeirSpendingBegan(isHeirSpendingBegan), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } @@ -568,7 +568,7 @@ private: template class COpRetValidator : CValidatorBase { public: - COpRetValidator(CC_info* cp, CScript opret) + COpRetValidator(CCcontract_info* cp, CScript opret) : m_fundingOpretScript(opret), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } @@ -619,7 +619,7 @@ private: template class CNullValidator : CValidatorBase { public: - CNullValidator(CC_info* cp) + CNullValidator(CCcontract_info* cp) : CValidatorBase(cp) { } virtual bool isVinValidator() const { return false; } diff --git a/src/script/sign.cpp b/src/script/sign.cpp index f7f663db2..685018828 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -136,7 +136,7 @@ std::vector &GetCryptoConditions() return vCC; } -bool GetCCByUnspendableAddress(struct CC_info *cp, char *addrstr) +bool GetCCByUnspendableAddress(struct CCcontract_info *cp, char *addrstr) { std::vector &vCC = GetCryptoConditions(); bool found = false; @@ -153,7 +153,7 @@ bool GetCCByUnspendableAddress(struct CC_info *cp, char *addrstr) return found; } -bool CCinitLite(struct CC_info *cp, uint8_t evalcode) +bool CCinitLite(struct CCcontract_info *cp, uint8_t evalcode) { std::vector &vCC = GetCryptoConditions(); bool found = false; From 62322eb58954690d645b1006849f282384691af4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:31:12 -1100 Subject: [PATCH 137/144] struct CCcontract_info --- src/cc/CC made easy.md | 8 +++---- src/cc/CCGateways.h | 2 +- src/cc/CCHeir.h | 4 ++-- src/cc/CCMarmara.h | 2 +- src/cc/CCOracles.h | 2 +- src/cc/CCPayments.h | 2 +- src/cc/CCPegs.h | 2 +- src/cc/CCPrices.h | 2 +- src/cc/CCassets.h | 12 +++++----- src/cc/CCassetsCore.cpp | 18 +++++++-------- src/cc/CCassetstx.cpp | 34 +++++++++++++-------------- src/cc/CCauction.h | 2 +- src/cc/CCchannels.h | 2 +- src/cc/CCcustom.cpp | 4 ++-- src/cc/CCdice.h | 4 ++-- src/cc/CCfaucet.h | 2 +- src/cc/CCfsm.h | 2 +- src/cc/CCinclude.h | 37 +++++++++++++++-------------- src/cc/CClotto.h | 2 +- src/cc/CCrewards.h | 2 +- src/cc/CCtokens.cpp | 22 +++++++++--------- src/cc/CCtokens.h | 8 +++---- src/cc/CCtx.cpp | 4 ++-- src/cc/CCutils.cpp | 28 +++++++++++----------- src/cc/assets.cpp | 4 ++-- src/cc/auction.cpp | 14 +++++------ src/cc/cclib.cpp | 10 ++++---- src/cc/channels.cpp | 22 +++++++++--------- src/cc/dice.cpp | 34 +++++++++++++-------------- src/cc/eval.cpp | 4 ++-- src/cc/eval.h | 4 ++-- src/cc/faucet.cpp | 14 +++++------ src/cc/fsm.cpp | 12 +++++----- src/cc/gateways.cpp | 36 ++++++++++++++--------------- src/cc/lotto.cpp | 20 ++++++++-------- src/cc/marmara.cpp | 26 ++++++++++----------- src/cc/oracles.cpp | 30 ++++++++++++------------ src/cc/payments.cpp | 14 +++++------ src/cc/pegs.cpp | 14 +++++------ src/cc/prices.cpp | 14 +++++------ src/cc/rewards.cpp | 24 +++++++++---------- src/komodo_bitcoind.h | 2 +- src/wallet/rpcwallet.cpp | 50 ++++++++++++++++++++-------------------- 43 files changed, 277 insertions(+), 278 deletions(-) diff --git a/src/cc/CC made easy.md b/src/cc/CC made easy.md index f409efb2d..2d1081003 100644 --- a/src/cc/CC made easy.md +++ b/src/cc/CC made easy.md @@ -206,13 +206,13 @@ The idea is that people send funds to the faucet by locking it in faucet's globa There are only 7 functions in faucet.cpp, a bit over 200 lines including comments. The first three are for validation, the last four for the rpc calls to use. -int64_t IsFaucetvout(struct CC_info *cp,const CTransaction& tx,int32_t v) +int64_t IsFaucetvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) -bool FaucetExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) -bool FaucetValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx) +bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) -int64_t AddFaucetInputs(struct CC_infoCC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddFaucetInputs(struct CCcontract_infoCC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) std::string FaucetGet(uint64_t txfee) diff --git a/src/cc/CCGateways.h b/src/cc/CCGateways.h index 0ffeced6e..b629ade1f 100644 --- a/src/cc/CCGateways.h +++ b/src/cc/CCGateways.h @@ -20,7 +20,7 @@ #include "CCinclude.h" #include "../merkleblock.h" -bool GatewaysValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool GatewaysValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector pubkeys); std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std::string refcoin,uint256 cointxid,int32_t claimvout,std::string deposithex,std::vectorproof,CPubKey destpub,int64_t amount); std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,uint256 deposittxid,CPubKey destpub,int64_t amount); diff --git a/src/cc/CCHeir.h b/src/cc/CCHeir.h index 1e831e772..ecaff9cdb 100644 --- a/src/cc/CCHeir.h +++ b/src/cc/CCHeir.h @@ -22,7 +22,7 @@ //#define EVAL_HEIR 0xea -bool HeirValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool HeirValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); class CoinHelper; class TokenHelper; @@ -36,6 +36,6 @@ UniValue HeirInfo(uint256 fundingtxid); UniValue HeirList(); //std::string Heir_MakeBadTx(uint256 fundingtxid, uint8_t funcId, int64_t amount, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTime, uint32_t errMask); -//bool HeirExactTokenAmounts(bool compareTotals, struct CC_info *cpHeir, Eval* eval, uint256 assetid, const CTransaction &tx); +//bool HeirExactTokenAmounts(bool compareTotals, struct CCcontract_info *cpHeir, Eval* eval, uint256 assetid, const CTransaction &tx); #endif diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 567f43aa3..65269df77 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -38,7 +38,7 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 approvaltxid,uint256 batontxid); UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,std::string currency); -bool MarmaraValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom UniValue MarmaraInfo(); diff --git a/src/cc/CCOracles.h b/src/cc/CCOracles.h index a46d0c311..7f952e5f5 100644 --- a/src/cc/CCOracles.h +++ b/src/cc/CCOracles.h @@ -19,7 +19,7 @@ #include "CCinclude.h" -bool OraclesValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string OracleCreate(int64_t txfee,std::string name,std::string description,std::string format); std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee); std::string OracleSubscribe(int64_t txfee,uint256 oracletxid,CPubKey publisher,int64_t amount); diff --git a/src/cc/CCPayments.h b/src/cc/CCPayments.h index f229212fb..187d9c9ad 100644 --- a/src/cc/CCPayments.h +++ b/src/cc/CCPayments.h @@ -19,7 +19,7 @@ #include "CCinclude.h" -bool PaymentsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom UniValue PaymentsInfo(); diff --git a/src/cc/CCPegs.h b/src/cc/CCPegs.h index a7863a3ec..8d2a268f1 100644 --- a/src/cc/CCPegs.h +++ b/src/cc/CCPegs.h @@ -19,7 +19,7 @@ #include "CCinclude.h" -bool PegsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool PegsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom UniValue PegsInfo(); diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index fe625e31b..1a68be7dd 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -19,7 +19,7 @@ #include "CCinclude.h" -bool PricesValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom UniValue PricesList(); diff --git a/src/cc/CCassets.h b/src/cc/CCassets.h index 061e0f899..69fcfacbb 100644 --- a/src/cc/CCassets.h +++ b/src/cc/CCassets.h @@ -26,7 +26,7 @@ #include "CCinclude.h" // CCcustom -bool AssetsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCassetsCore //CTxOut MakeAssetsVout(CAmount nValue,CPubKey pk); @@ -35,20 +35,20 @@ bool AssetsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32 //bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); //uint8_t DecodeAssetOpRet(const CScript &scriptPubKey, uint8_t &evalCode, uint256 &assetid, uint256 &assetid2, int64_t &price, std::vector &origpubkey); bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CTransaction &tx); -int64_t IsAssetvout(struct CC_info *cp, int64_t &price, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 refassetid); +int64_t IsAssetvout(struct CCcontract_info *cp, int64_t &price, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 refassetid); bool ValidateBidRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); bool ValidateAskRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); bool ValidateSwapRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); bool SetBidFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); bool SetAskFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); bool SetSwapFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); -int64_t AssetValidateBuyvin(struct CC_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid); -int64_t AssetValidateSellvin(struct CC_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid); -bool AssetCalcAmounts(struct CC_info *cpAssets, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 assetid); +int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid); +int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid); +bool AssetCalcAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 assetid); // CCassetstx //int64_t GetAssetBalance(CPubKey pk,uint256 tokenid); // --> GetTokenBalance() -int64_t AddAssetInputs(struct CC_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 assetid, int64_t total, int32_t maxinputs); +int64_t AddAssetInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 assetid, int64_t total, int32_t maxinputs); UniValue AssetOrders(uint256 tokenid); //UniValue AssetInfo(uint256 tokenid); diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 45d3421be..1b8e46189 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -365,7 +365,7 @@ bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CT } // Calculate sell/buy owner's source token/asset address from ask/bid tx -bool GetAssetorigaddrs(struct CC_info *cp, char *userCCaddr, char *destaddr, const CTransaction& tx) +bool GetAssetorigaddrs(struct CCcontract_info *cp, char *userCCaddr, char *destaddr, const CTransaction& tx) { uint256 assetid,assetid2; int64_t price,nValue=0; int32_t n; uint8_t funcid; std::vector origpubkey; @@ -378,13 +378,13 @@ bool GetAssetorigaddrs(struct CC_info *cp, char *userCCaddr, char *destaddr, con bool bGetCCaddr = false; if (funcid == 's' || funcid == 'S') { - struct CC_info *cpTokens, tokensC; + struct CCcontract_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); bGetCCaddr = GetCCaddress(cpTokens, userCCaddr, pubkey2pk(origpubkey)); //bGetCCaddr = GetTokensCCaddress(cp, CCaddr, pubkey2pk(origpubkey)); } else if (funcid == 'b' || funcid == 'B') { - struct CC_info *cpTokens, tokensC; + struct CCcontract_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); bGetCCaddr = GetCCaddress(cpTokens, userCCaddr, pubkey2pk(origpubkey)); } @@ -400,7 +400,7 @@ bool GetAssetorigaddrs(struct CC_info *cp, char *userCCaddr, char *destaddr, con } -int64_t AssetValidateCCvin(struct CC_info *cp,Eval* eval,char *CCaddr,char *origaddr,const CTransaction &tx,int32_t vini,CTransaction &vinTx) +int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,char *origaddr,const CTransaction &tx,int32_t vini,CTransaction &vinTx) { uint256 hashBlock; uint256 assetid, assetid2; @@ -463,7 +463,7 @@ int64_t AssetValidateCCvin(struct CC_info *cp,Eval* eval,char *CCaddr,char *orig return(vinTx.vout[0].nValue); } -int64_t AssetValidateBuyvin(struct CC_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid) +int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid) { CTransaction vinTx; int64_t nValue; uint256 assetid,assetid2; uint8_t funcid, evalCode; CCaddr[0] = origaddr[0] = 0; @@ -490,7 +490,7 @@ int64_t AssetValidateBuyvin(struct CC_info *cp,Eval* eval,int64_t &tmpprice,std: return(nValue); } -int64_t AssetValidateSellvin(struct CC_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid) +int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid) { CTransaction vinTx; int64_t nValue,assetoshis; //fprintf(stderr,"AssetValidateSellvin\n"); @@ -558,7 +558,7 @@ bool ValidateAssetOpret(CTransaction tx, int32_t v, uint256 assetid, int64_t &pr // Checks if the vout is a really Asset CC vout // compareTotals == true, the func also validates the passed transaction itself: // it should be either sum(cc vins) == sum(cc vouts) or the transaction is the 'tokenbase' ('c') tx -int64_t IsAssetvout(struct CC_info *cp, int64_t &price, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 refassetid) +int64_t IsAssetvout(struct CCcontract_info *cp, int64_t &price, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 refassetid) { //std::cerr << "IsAssetvout() entered for txid=" << tx.GetHash().GetHex() << " v=" << v << " for assetid=" << refassetid.GetHex() << std::endl; @@ -587,14 +587,14 @@ int64_t IsAssetvout(struct CC_info *cp, int64_t &price, std::vector &or } // sets cc inputs vs cc outputs and ensures they are equal: -bool AssetCalcAmounts(struct CC_info *cpAssets, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 assetid) +bool AssetCalcAmounts(struct CCcontract_info *cpAssets, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 assetid) { CTransaction vinTx; uint256 hashBlock, id, id2; int32_t flag; int64_t assetoshis; std::vector tmporigpubkey; int64_t tmpprice; int32_t numvins = tx.vin.size(); int32_t numvouts = tx.vout.size(); inputs = outputs = 0; - struct CC_info *cpTokens, C; + struct CCcontract_info *cpTokens, C; cpTokens = CCinit(&C, EVAL_TOKENS); diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index dff279acd..968775d38 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -17,7 +17,7 @@ //#include "CCtokens.h" -int64_t AddAssetInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs) +int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs) { char coinaddr[64],destaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t j,vout,n = 0; std::vector > unspentOutputs; @@ -72,13 +72,13 @@ UniValue AssetOrders(uint256 refassetid) UniValue result(UniValue::VARR); std::vector > unspentOutputsTokens, unspentOutputsAssets; - struct CC_info *cpTokens, tokensC; - struct CC_info *cpAssets, assetsC; + struct CCcontract_info *cpTokens, tokensC; + struct CCcontract_info *cpAssets, assetsC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); cpAssets = CCinit(&assetsC, EVAL_ASSETS); - auto addOrders = [&](struct CC_info *cp, std::vector >::const_iterator it) + auto addOrders = [&](struct CCcontract_info *cp, std::vector >::const_iterator it) { uint256 txid, hashBlock, assetid, assetid2; int64_t price; @@ -189,7 +189,7 @@ UniValue AssetOrders(uint256 refassetid) /* std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std::string description) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; struct CC_info *cp,C; + CPubKey mypk; struct CCcontract_info *cp,C; if ( assetsupply < 0 ) { fprintf(stderr,"negative assetsupply %lld\n",(long long)assetsupply); @@ -217,7 +217,7 @@ UniValue AssetOrders(uint256 refassetid) /* std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; uint64_t mask; int64_t CCchange=0,inputs=0; struct CC_info *cp,C; + CPubKey mypk; uint64_t mask; int64_t CCchange=0,inputs=0; struct CCcontract_info *cp,C; if ( total < 0 ) { fprintf(stderr,"negative total %lld\n",(long long)total); @@ -259,7 +259,7 @@ UniValue AssetOrders(uint256 refassetid) /* std::string AssetConvert(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total,int32_t evalcode) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; int64_t CCchange=0,inputs=0; struct CC_info *cp,C; + CPubKey mypk; int64_t CCchange=0,inputs=0; struct CCcontract_info *cp,C; if ( total < 0 ) { fprintf(stderr,"negative total %lld\n",(long long)total); @@ -288,7 +288,7 @@ std::string CreateBuyOffer(int64_t txfee, int64_t bidamount, uint256 assetid, in { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CPubKey mypk; - struct CC_info *cpAssets, C; + struct CCcontract_info *cpAssets, C; uint256 hashBlock; CTransaction vintx; std::vector origpubkey; @@ -349,8 +349,8 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p uint64_t mask; int64_t inputs, CCchange; CScript opret; - struct CC_info *cpAssets, assetsC; - struct CC_info *cpTokens, tokensC; + struct CCcontract_info *cpAssets, assetsC; + struct CCcontract_info *cpTokens, tokensC; //std::cerr << "CreateSell() askamount=" << askamount << " pricetotal=" << pricetotal << std::endl; @@ -408,7 +408,7 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 assetid2,int64_t pricetotal) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; uint64_t mask; int64_t inputs,CCchange; CScript opret; struct CC_info *cp,C; + CPubKey mypk; uint64_t mask; int64_t inputs,CCchange; CScript opret; struct CCcontract_info *cp,C; ////////////////////////// NOT IMPLEMENTED YET///////////////////////////////// fprintf(stderr,"asset swaps disabled\n"); @@ -482,7 +482,7 @@ std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) uint256 hashBlock; int64_t bidamount; CPubKey mypk; - struct CC_info *cpAssets, C; + struct CCcontract_info *cpAssets, C; uint8_t dummyEvalCode; uint256 dummyAssetid, dummyAssetid2; int64_t dummyPrice; std::vector dummyOrigpubkey; @@ -526,7 +526,7 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) uint256 hashBlock; int64_t askamount; CPubKey mypk; - struct CC_info *cpTokens, *cpAssets, tokensC, assetsC; + struct CCcontract_info *cpTokens, *cpAssets, tokensC, assetsC; uint8_t dummyEvalCode; uint256 dummyAssetid, dummyAssetid2; int64_t dummyPrice; std::vector dummyOrigpubkey; @@ -592,8 +592,8 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f int32_t bidvout=0; uint64_t mask; int64_t origprice, bidamount, paid_amount, remaining_required, inputs, CCchange=0; - struct CC_info *cpTokens, tokensC; - struct CC_info *cpAssets, assetsC; + struct CCcontract_info *cpTokens, tokensC; + struct CCcontract_info *cpAssets, assetsC; if (fillamount < 0) { @@ -676,8 +676,8 @@ std::string FillSell(int64_t txfee, uint256 assetid, uint256 assetid2, uint256 a uint64_t mask = 0; int32_t askvout = 0; int64_t received_assetoshis, total_nValue, orig_assetoshis, paid_nValue, remaining_nValue, inputs, CCchange=0; - //struct CC_info *cpTokens, tokensC; - struct CC_info *cpAssets, assetsC; + //struct CCcontract_info *cpTokens, tokensC; + struct CCcontract_info *cpAssets, assetsC; if (fillunits < 0) { diff --git a/src/cc/CCauction.h b/src/cc/CCauction.h index 13393d510..cfcd615cc 100644 --- a/src/cc/CCauction.h +++ b/src/cc/CCauction.h @@ -21,7 +21,7 @@ #define EVAL_AUCTION 0xe8 -bool AuctionValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string AuctionPost(uint64_t txfee,uint256 itemhash,int64_t minbid,char *title,char *description); std::string AuctionBid(uint64_t txfee,uint256 itemhash,int64_t amount); diff --git a/src/cc/CCchannels.h b/src/cc/CCchannels.h index 76e0ab8cf..10cb4d224 100644 --- a/src/cc/CCchannels.h +++ b/src/cc/CCchannels.h @@ -20,7 +20,7 @@ #include "CCinclude.h" #define CHANNELS_MAXPAYMENTS 1000 -bool ChannelsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment,uint256 tokenid); std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint256 secret); std::string ChannelClose(uint64_t txfee,uint256 opentxid); diff --git a/src/cc/CCcustom.cpp b/src/cc/CCcustom.cpp index c05210542..577332b63 100644 --- a/src/cc/CCcustom.cpp +++ b/src/cc/CCcustom.cpp @@ -243,7 +243,7 @@ uint8_t CClibCCpriv[32] = { 0x57, 0xcf, 0x49, 0x71, 0x7d, 0xb4, 0x15, 0x1b, 0x4f #undef FUNCNAME #undef EVALCODE -int32_t CClib_initcp(struct CC_info *cp,uint8_t evalcode) +int32_t CClib_initcp(struct CCcontract_info *cp,uint8_t evalcode) { CPubKey pk; uint8_t pub33[33]; char CCaddr[64]; if ( evalcode == EVAL_FIRSTUSER ) // eventually make a hashchain for each evalcode @@ -263,7 +263,7 @@ int32_t CClib_initcp(struct CC_info *cp,uint8_t evalcode) return(-1); } -struct CC_info *CCinit(struct CC_info *cp, uint8_t evalcode) +struct CCcontract_info *CCinit(struct CCcontract_info *cp, uint8_t evalcode) { cp->evalcode = evalcode; switch ( evalcode ) diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index 0de222c50..363aad735 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -21,7 +21,7 @@ #define EVAL_DICE 0xe6 -bool DiceValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds); std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyvout,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout,uint256 vin0txid,int32_t vin0vout); @@ -30,6 +30,6 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); UniValue DiceInfo(uint256 diceid); UniValue DiceList(); -int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CC_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random); +int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random); #endif diff --git a/src/cc/CCfaucet.h b/src/cc/CCfaucet.h index 4bb2ae0d7..3cb6c66e5 100644 --- a/src/cc/CCfaucet.h +++ b/src/cc/CCfaucet.h @@ -22,7 +22,7 @@ #define EVAL_FAUCET 0xe4 #define FAUCETSIZE (COIN / 10) -bool FaucetValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom std::string FaucetFund(uint64_t txfee,int64_t funds); diff --git a/src/cc/CCfsm.h b/src/cc/CCfsm.h index 0690e4dd2..2bce35597 100644 --- a/src/cc/CCfsm.h +++ b/src/cc/CCfsm.h @@ -21,7 +21,7 @@ #define EVAL_FSM 0xe7 -bool FSMValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string FSMList(); std::string FSMInfo(uint256 fsmtxid); diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index eda543a66..82c9484d5 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -88,7 +88,7 @@ struct CC_meta // followed by address destinations }; -struct CC_info +struct CCcontract_info { // this is for spending from 'unspendable' CC address uint8_t evalcode; @@ -111,13 +111,12 @@ struct CC_info uint8_t unspendablepriv2[32], unspendablepriv3[32]; CPubKey unspendablepk2, unspendablepk3; - bool (*validate)(struct CC_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn); // cc contract tx validation callback + bool (*validate)(struct CCcontract_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn); // cc contract tx validation callback bool (*ismyvin)(CScript const& scriptSig); // checks if evalcode is present in the scriptSig param uint8_t didinit; }; -typedef struct CC_info CCcontract_info; -struct CC_info *CCinit(struct CC_info *cp,uint8_t evalcode); +struct CCcontract_info *CCinit(struct CCcontract_info *cp,uint8_t evalcode); struct oracleprice_info { @@ -135,7 +134,7 @@ CBlockIndex *komodo_getblockindex(uint256 hash); int32_t komodo_nextheight(); int32_t CCgetspenttxid(uint256 &spenttxid,int32_t &vini,int32_t &height,uint256 txid,int32_t vout); -void CCclearvars(struct CC_info *cp); +void CCclearvars(struct CCcontract_info *cp); static const uint256 zeroid; bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock); @@ -159,9 +158,9 @@ uint8_t DecodeOraclesCreateOpRet(const CScript &scriptPubKey,std::string &name,s uint256 OracleMerkle(int32_t height,uint256 reforacletxid,char *format,std::vectorpublishers); uint256 OraclesBatontxid(uint256 oracletxid,CPubKey pk); -//int64_t AddAssetInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs); -int64_t AddTokenCCInputs(struct CC_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); -int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CC_info *cp, Eval* eval, const CTransaction& tx, int32_t v, uint256 reftokenid); +//int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs); +int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); +int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, const CTransaction& tx, int32_t v, uint256 reftokenid); bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx); CScript EncodeAssetOpRet(uint8_t assetFuncId, uint256 assetid2, int64_t price, std::vector origpubkey); @@ -179,7 +178,7 @@ int32_t oracle_format(uint256 *hashp,int64_t *valp,char *str,uint8_t fmt,uint8_t // CCcustom -CPubKey GetUnspendable(struct CC_info *cp,uint8_t *unspendablepriv); +CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv); // CCutils CPubKey buf2pk(uint8_t *buf33); @@ -190,19 +189,19 @@ CTxOut MakeCC1of2vout(uint8_t evalcode,CAmount nValue,CPubKey pk,CPubKey pk2); CC *MakeCCcond1(uint8_t evalcode,CPubKey pk); CC *MakeCCcond1of2(uint8_t evalcode,CPubKey pk1,CPubKey pk2); CC* GetCryptoCondition(CScript const& scriptSig); -void CCaddr2set(struct CC_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); -void CCaddr3set(struct CC_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); -void CCaddr1of2set(struct CC_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); +void CCaddr2set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); +void CCaddr3set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); +void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); CTxOut MakeTokensCC1of2vout(uint8_t evalcode, CAmount nValue, CPubKey pk1, CPubKey pk2); CTxOut MakeTokensCC1vout(uint8_t evalcode, CAmount nValue, CPubKey pk); CC *MakeTokensCCcond1of2(uint8_t evalcode, CPubKey pk1, CPubKey pk2); CC *MakeTokensCCcond1(uint8_t evalcode, CPubKey pk); -bool GetTokensCCaddress(struct CC_info *cp, char *destaddr, CPubKey pk); -bool GetTokensCCaddress1of2(struct CC_info *cp, char *destaddr, CPubKey pk, CPubKey pk2); -void CCaddrTokens1of2set(struct CC_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); -int32_t CClib_initcp(struct CC_info *cp,uint8_t evalcode); +bool GetTokensCCaddress(struct CCcontract_info *cp, char *destaddr, CPubKey pk); +bool GetTokensCCaddress1of2(struct CCcontract_info *cp, char *destaddr, CPubKey pk, CPubKey pk2); +void CCaddrTokens1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); +int32_t CClib_initcp(struct CCcontract_info *cp,uint8_t evalcode); bool IsCCInput(CScript const& scriptSig); int32_t unstringbits(char *buf,uint64_t bits); @@ -217,8 +216,8 @@ int64_t CCfullsupply(uint256 tokenid); int64_t CCtoken_balance(char *destaddr,uint256 tokenid); int64_t CCtoken_balance2(char *destaddr,uint256 tokenid); bool _GetCCaddress(char *destaddr,uint8_t evalcode,CPubKey pk); -bool GetCCaddress(struct CC_info *cp,char *destaddr,CPubKey pk); -bool GetCCaddress1of2(struct CC_info *cp,char *destaddr,CPubKey pk,CPubKey pk2); +bool GetCCaddress(struct CCcontract_info *cp,char *destaddr,CPubKey pk); +bool GetCCaddress1of2(struct CCcontract_info *cp,char *destaddr,CPubKey pk,CPubKey pk2); bool ConstrainVout(CTxOut vout,int32_t CCflag,char *cmpaddr,int64_t nValue); bool PreventCC(Eval* eval,const CTransaction &tx,int32_t preventCCvins,int32_t numvins,int32_t preventCCvouts,int32_t numvouts); bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); @@ -230,7 +229,7 @@ CPubKey check_signing_pubkey(CScript scriptSig); // CCtx bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey); extern std::vector NULL_pubkeys; -std::string FinalizeCCTx(uint64_t skipmask,struct CC_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys = NULL_pubkeys); +std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys = NULL_pubkeys); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr); void SetCCtxids(std::vector > &addressIndex,char *coinaddr); int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs); diff --git a/src/cc/CClotto.h b/src/cc/CClotto.h index 4ef147cef..2f0595371 100644 --- a/src/cc/CClotto.h +++ b/src/cc/CClotto.h @@ -21,7 +21,7 @@ #define EVAL_LOTTO 0xe9 -bool LottoValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool LottoValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); UniValue LottoInfo(uint256 lottoid); UniValue LottoList(); diff --git a/src/cc/CCrewards.h b/src/cc/CCrewards.h index 41977f915..4d6cc80f9 100644 --- a/src/cc/CCrewards.h +++ b/src/cc/CCrewards.h @@ -22,7 +22,7 @@ #define EVAL_REWARDS 0xe5 #define REWARDSCC_MAXAPR (COIN * 25) -bool RewardsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); UniValue RewardsInfo(uint256 rewardid); UniValue RewardsList(); diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 6620a9cd8..bdb710afb 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -177,7 +177,7 @@ uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCode, uint256 // tx validation -bool TokensValidate(struct CC_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn) +bool TokensValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn) { static uint256 zero; CTxDestination address; CTransaction vinTx, createTx; uint256 hashBlock, tokenid, tokenid2; @@ -251,7 +251,7 @@ bool TokensValidate(struct CC_info *cp, Eval* eval, const CTransaction &tx, uint // forward validation if evalcode in opret is not EVAL_TOKENS // init for forwarding validation call //if (evalCodeInOpret != EVAL_TOKENS) { // TODO: should we check also only allowed for tokens evalcodes, like EVAL_ASSETS, EVAL_GATEWAYS? - // struct CC_info *cpOther = NULL, C; + // struct CCcontract_info *cpOther = NULL, C; // cpOther = CCinit(&C, evalCodeInOpret); // if (cpOther) @@ -271,7 +271,7 @@ bool ExtractTokensVinPubkeys(CTransaction tx, std::vector &vinPubkeys) bool found = false; CPubKey pubkey; - struct CC_info *cpTokens, tokensC; + struct CCcontract_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); @@ -353,7 +353,7 @@ uint8_t ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, std::vec // goDeeper is true: the func also validates amounts of the passed transaction: // it should be either sum(cc vins) == sum(cc vouts) or the transaction is the 'tokenbase' ('c') tx // checkPubkeys is true: validates if the vout is token vout1 or token vout1of2. Should always be true! -int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CC_info *cp, Eval* eval, const CTransaction& tx, int32_t v, uint256 reftokenid) +int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, const CTransaction& tx, int32_t v, uint256 reftokenid) { // this is just for log messages indentation fur debugging recursive calls: @@ -488,13 +488,13 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CC_info *cp, Eval* } // compares cc inputs vs cc outputs (to prevent feeding vouts from normal inputs) -bool TokensExactAmounts(bool goDeeper, struct CC_info *cp, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid) +bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cp, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid) { CTransaction vinTx; uint256 hashBlock; int64_t tokenoshis; - struct CC_info *cpTokens, tokensC; + struct CCcontract_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); int32_t numvins = tx.vin.size(); @@ -559,7 +559,7 @@ bool TokensExactAmounts(bool goDeeper, struct CC_info *cp, int64_t &inputs, int6 } // add inputs from token cc addr -int64_t AddTokenCCInputs(struct CC_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs) +int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs) { char tokenaddr[64], destaddr[64]; int64_t threshold, nValue, price, totalinputs = 0; @@ -617,7 +617,7 @@ int64_t AddTokenCCInputs(struct CC_info *cp, CMutableTransaction &mtx, CPubKey p std::string CreateToken(int64_t txfee, int64_t assetsupply, std::string name, std::string description) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; struct CC_info *cp, C; + CPubKey mypk; struct CCcontract_info *cp, C; if (assetsupply < 0) { fprintf(stderr, "negative assetsupply %lld\n", (long long)assetsupply); @@ -647,7 +647,7 @@ std::string CreateToken(int64_t txfee, int64_t assetsupply, std::string name, st std::string TokenTransfer(int64_t txfee, uint256 assetid, std::vector destpubkey, int64_t total) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; uint64_t mask; int64_t CCchange = 0, inputs = 0; struct CC_info *cp, C; + CPubKey mypk; uint64_t mask; int64_t CCchange = 0, inputs = 0; struct CCcontract_info *cp, C; std::vector emptyExtraOpret; if (total < 0) @@ -714,7 +714,7 @@ int64_t GetTokenBalance(CPubKey pk, uint256 tokenid) return 0; } - struct CC_info *cp, C; + struct CCcontract_info *cp, C; cp = CCinit(&C, EVAL_TOKENS); return(AddTokenCCInputs(cp, mtx, pk, tokenid, 0, 0)); } @@ -748,7 +748,7 @@ UniValue TokenList() { UniValue result(UniValue::VARR); std::vector > addressIndex; - struct CC_info *cp, C; uint256 txid, hashBlock; + struct CCcontract_info *cp, C; uint256 txid, hashBlock; CTransaction vintx; std::vector origpubkey; std::string name, description; char str[65]; diff --git a/src/cc/CCtokens.h b/src/cc/CCtokens.h index 2eaffe31f..e7bb62101 100644 --- a/src/cc/CCtokens.h +++ b/src/cc/CCtokens.h @@ -26,9 +26,9 @@ #include "CCinclude.h" // CCcustom -bool TokensValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); -bool TokensExactAmounts(bool goDeeper, struct CC_info *cpTokens, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid); -//int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CC_info *cp, Eval* eval, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys); +bool TokensValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid); +//int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, std::vector &origpubkey, const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys); std::string CreateToken(int64_t txfee, int64_t assetsupply, std::string name, std::string description); std::string TokenTransfer(int64_t txfee, uint256 assetid, std::vector destpubkey, int64_t total); @@ -36,7 +36,7 @@ int64_t GetTokenBalance(CPubKey pk, uint256 tokenid); UniValue TokenInfo(uint256 tokenid); UniValue TokenList(); -//this is in CCinclude.h int64_t AddTokenCCInputs(struct CC_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); +//this is in CCinclude.h int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, CPubKey pk, uint256 tokenid, int64_t total, int32_t maxinputs); //this is in CCinclude.h uint8_t DecodeTokenCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 307ac214f..ae7483f4d 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -40,7 +40,7 @@ bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScrip return(false); } -std::string FinalizeCCTx(uint64_t CCmask,struct CC_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys) +std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys) { auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); CTransaction vintx; std::string hex; CPubKey globalpk; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0; @@ -50,7 +50,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CC_info *cp,CMutableTransaction uint8_t *privkey, myprivkey[32], unspendablepriv[32], tokensunspendablepriv[32], *msg32 = 0; CC *mycond=0, *othercond=0, *othercond2=0,*othercond4=0, *othercond3=0, *othercond1of2=NULL, *othercond1of2tokens = NULL, *cond, *mytokenscond = NULL, *mysingletokenscond = NULL, *othertokenscond = NULL; CPubKey unspendablepk /*, tokensunspendablepk*/; - struct CC_info *cpTokens, tokensC; + struct CCcontract_info *cpTokens, tokensC; globalpk = GetUnspendable(cp,0); n = mtx.vout.size(); for (i=0; i pubkey) return(pk); } -void CCaddr2set(struct CC_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr) +void CCaddr2set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr) { cp->evalcode2 = evalcode; cp->unspendablepk2 = pk; @@ -235,7 +235,7 @@ void CCaddr2set(struct CC_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,cha strcpy(cp->unspendableaddr2,coinaddr); } -void CCaddr3set(struct CC_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr) +void CCaddr3set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr) { cp->evalcode3 = evalcode; cp->unspendablepk3 = pk; @@ -244,7 +244,7 @@ void CCaddr3set(struct CC_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,cha } // set pubkeys, myprivkey and 1of2 cc addr for spending from 1of2 cryptocondition vout: -void CCaddr1of2set(struct CC_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) +void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) { cp->coins1of2pk[0] = pk1; cp->coins1of2pk[1] = pk2; @@ -252,7 +252,7 @@ void CCaddr1of2set(struct CC_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) } // set pubkeys, myprivkey and 1of2 cc addr for spending from 1of2 tokens cryptocondition vout: -void CCaddrTokens1of2set(struct CC_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) +void CCaddrTokens1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) { cp->tokens1of2pk[0] = pk1; cp->tokens1of2pk[1] = pk2; @@ -343,7 +343,7 @@ bool _GetCCaddress(char *destaddr,uint8_t evalcode,CPubKey pk) return(destaddr[0] != 0); } -bool GetCCaddress(struct CC_info *cp,char *destaddr,CPubKey pk) +bool GetCCaddress(struct CCcontract_info *cp,char *destaddr,CPubKey pk) { destaddr[0] = 0; if ( pk.size() == 0 ) @@ -363,7 +363,7 @@ bool _GetTokensCCaddress(char *destaddr, uint8_t evalcode, CPubKey pk) return(destaddr[0] != 0); } -bool GetTokensCCaddress(struct CC_info *cp, char *destaddr, CPubKey pk) +bool GetTokensCCaddress(struct CCcontract_info *cp, char *destaddr, CPubKey pk) { destaddr[0] = 0; if (pk.size() == 0) @@ -372,7 +372,7 @@ bool GetTokensCCaddress(struct CC_info *cp, char *destaddr, CPubKey pk) } -bool GetCCaddress1of2(struct CC_info *cp,char *destaddr,CPubKey pk,CPubKey pk2) +bool GetCCaddress1of2(struct CCcontract_info *cp,char *destaddr,CPubKey pk,CPubKey pk2) { CC *payoutCond; destaddr[0] = 0; @@ -384,7 +384,7 @@ bool GetCCaddress1of2(struct CC_info *cp,char *destaddr,CPubKey pk,CPubKey pk2) return(destaddr[0] != 0); } -bool GetTokensCCaddress1of2(struct CC_info *cp, char *destaddr, CPubKey pk, CPubKey pk2) +bool GetTokensCCaddress1of2(struct CCcontract_info *cp, char *destaddr, CPubKey pk, CPubKey pk2) { CC *payoutCond; destaddr[0] = 0; @@ -486,14 +486,14 @@ bool Myprivkey(uint8_t myprivkey[]) return(false); } -CPubKey GetUnspendable(struct CC_info *cp,uint8_t *unspendablepriv) +CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv) { if ( unspendablepriv != 0 ) memcpy(unspendablepriv,cp->CCpriv,32); return(pubkey2pk(ParseHex(cp->CChexstr))); } -void CCclearvars(struct CC_info *cp) +void CCclearvars(struct CCcontract_info *cp) { cp->evalcode2 = cp->evalcode3 = 0; cp->unspendableaddr2[0] = cp->unspendableaddr3[0] = 0; @@ -602,7 +602,7 @@ CPubKey check_signing_pubkey(CScript scriptSig) return CPubKey(); } -bool ProcessCC(struct CC_info *cp,Eval* eval, std::vector paramsNull,const CTransaction &ctx, unsigned int nIn) +bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector paramsNull,const CTransaction &ctx, unsigned int nIn) { CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t height,i,n,from_mempool = 0; int64_t amount; std::vector origpubkey; height = KOMODO_CONNECTING; @@ -636,13 +636,13 @@ bool ProcessCC(struct CC_info *cp,Eval* eval, std::vector paramsNull,co return(false); } -extern struct CC_info CCinfos[0x100]; +extern struct CCcontract_info CCinfos[0x100]; extern std::string MYCCLIBNAME; -bool CClib_validate(struct CC_info *cp,Eval *eval,const CTransaction &txTo,unsigned int nIn); +bool CClib_validate(struct CCcontract_info *cp,Eval *eval,const CTransaction &txTo,unsigned int nIn); bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) { - uint8_t evalcode; int32_t height,from_mempool; struct CC_info *cp; + uint8_t evalcode; int32_t height,from_mempool; struct CCcontract_info *cp; if ( ASSETCHAINS_CCLIB != MYCCLIBNAME ) { fprintf(stderr,"-ac_cclib=%s vs myname %s\n",ASSETCHAINS_CCLIB.c_str(),MYCCLIBNAME.c_str()); diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index 7747fb61c..3ccafa34f 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -126,7 +126,7 @@ // tx validation -bool AssetsValidate(struct CC_info *cpAssets,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransaction &tx, uint32_t nIn) { static uint256 zero; CTxDestination address; CTransaction vinTx,createTx; uint256 hashBlock,assetid,assetid2; @@ -157,7 +157,7 @@ bool AssetsValidate(struct CC_info *cpAssets,Eval* eval,const CTransaction &tx, GetTokensCCaddress(cpAssets, tokensUnspendableAddr, GetUnspendable(cpAssets, NULL)); // we need this for validating single-eval tokens' vins/vous: - struct CC_info *cpTokens, tokensC; + struct CCcontract_info *cpTokens, tokensC; cpTokens = CCinit(&tokensC, EVAL_TOKENS); // find single-eval token user cc addr: diff --git a/src/cc/auction.cpp b/src/cc/auction.cpp index b3fe4aa86..0858facfa 100644 --- a/src/cc/auction.cpp +++ b/src/cc/auction.cpp @@ -21,7 +21,7 @@ // start of consensus code -int64_t IsAuctionvout(struct CC_info *cp,const CTransaction& tx,int32_t v) +int64_t IsAuctionvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -32,7 +32,7 @@ int64_t IsAuctionvout(struct CC_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool AuctionExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool AuctionExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -70,7 +70,7 @@ bool AuctionExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,in else return(true); } -bool AuctionValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; return eval->Invalid("no validation yet"); @@ -118,7 +118,7 @@ bool AuctionValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint3 // helper functions for rpc calls in rpcwallet.cpp -int64_t AddAuctionInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddAuctionInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; @@ -151,7 +151,7 @@ int64_t AddAuctionInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk, std::string AuctionBid(uint64_t txfee,uint256 itemhash,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Auctionpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CC_info *cp,C; + CPubKey mypk,Auctionpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_AUCTION); if ( txfee == 0 ) txfee = 10000; @@ -172,7 +172,7 @@ std::string AuctionBid(uint64_t txfee,uint256 itemhash,int64_t amount) std::string AuctionDeliver(uint64_t txfee,uint256 itemhash,uint256 bidtxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Auctionpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CC_info *cp,C; + CPubKey mypk,Auctionpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_AUCTION); if ( txfee == 0 ) txfee = 10000; @@ -193,7 +193,7 @@ std::string AuctionDeliver(uint64_t txfee,uint256 itemhash,uint256 bidtxid) std::string AuctionPost(uint64_t txfee,uint256 itemhash,int64_t minbid,char *title,char *description) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Auctionpk; int64_t funds = 0; CScript opret; struct CC_info *cp,C; + CPubKey mypk,Auctionpk; int64_t funds = 0; CScript opret; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_AUCTION); if ( txfee == 0 ) txfee = 10000; diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 837a36024..0f201acc4 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -42,9 +42,9 @@ std::string MYCCLIBNAME = (char *)"stub"; char *CClib_name() { return(MYCCLIBNAME); } -std::string CClib_rawtxgen(struct CC_info *cp,uint8_t funcid,cJSON *params); +std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *params); -UniValue CClib_info(struct CC_info *cp) +UniValue CClib_info(struct CCcontract_info *cp) { UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i; char str[2]; result.push_back(Pair("result","success")); @@ -70,7 +70,7 @@ UniValue CClib_info(struct CC_info *cp) return(result); } -UniValue CClib(struct CC_info *cp,char *method,cJSON *params) +UniValue CClib(struct CCcontract_info *cp,char *method,cJSON *params) { UniValue result(UniValue::VOBJ); int32_t i; std::string rawtx; for (i=0; i > unspentOutputs; @@ -465,7 +465,7 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); uint8_t hash[32],hashdest[32]; uint64_t amount,tokens=0,funds; int32_t i; uint256 hashchain,entropy,hentropy; - CPubKey mypk; struct CC_info *cp,*cpTokens,C,CTokens; + CPubKey mypk; struct CCcontract_info *cp,*cpTokens,C,CTokens; if ( numpayments <= 0 || payment <= 0 || numpayments > CHANNELS_MAXPAYMENTS ) { @@ -509,7 +509,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CPubKey mypk,srcpub,destpub; uint256 txid,hashchain,gensecret,hashblock,entropy,hentropy,prevtxid,param3,tokenid; - struct CC_info *cp,C; int32_t i,funcid,prevdepth,numvouts,numpayments,totalnumpayments; + struct CCcontract_info *cp,C; int32_t i,funcid,prevdepth,numvouts,numpayments,totalnumpayments; int64_t payment,change,funds,param2; uint8_t hash[32],hashdest[32]; CTransaction channelOpenTx,prevTx; @@ -616,7 +616,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 std::string ChannelClose(uint64_t txfee,uint256 opentxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,srcpub,destpub; struct CC_info *cp,C; + CPubKey mypk,srcpub,destpub; struct CCcontract_info *cp,C; CTransaction channelOpenTx; uint256 hashblock,tmp_txid,prevtxid,hashchain,tokenid; int32_t numvouts,numpayments; @@ -665,7 +665,7 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk; struct CC_info *cp,C; int64_t funds,payment,param2; + CPubKey mypk; struct CCcontract_info *cp,C; int64_t funds,payment,param2; int32_t i,numpayments,numvouts,param1; uint256 hashchain,hashblock,txid,prevtxid,param3,tokenid; CTransaction channelOpenTx,channelCloseTx,prevTx; @@ -735,7 +735,7 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) } UniValue ChannelsList() { - UniValue result(UniValue::VOBJ); std::vector > txids; struct CC_info *cp,C; uint256 txid,hashBlock,tmp_txid,param3,tokenid; + UniValue result(UniValue::VOBJ); std::vector > txids; struct CCcontract_info *cp,C; uint256 txid,hashBlock,tmp_txid,param3,tokenid; CTransaction tx; char myCCaddr[65],addr[65],str[256]; CPubKey mypk,srcpub,destpub; int32_t vout,numvouts,param1; int64_t nValue,param2; @@ -766,7 +766,7 @@ UniValue ChannelsList() UniValue ChannelsInfo(uint256 channeltxid) { UniValue result(UniValue::VOBJ),array(UniValue::VARR); CTransaction tx,opentx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain,prevtxid,tokenid; - struct CC_info *cp,C; char CCaddr[65],addr[65],str[512]; int32_t vout,numvouts,param1,numpayments; + struct CCcontract_info *cp,C; char CCaddr[65],addr[65],str[512]; int32_t vout,numvouts,param1,numpayments; int64_t param2,payment; CPubKey srcpub,destpub,mypk; std::vector > addressIndex; std::vector txids; diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7a10913e7..05dad9bf6 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -322,7 +322,7 @@ void dicefinish_delete(struct dicefinish_info *ptr) void *dicefinish(void *_ptr) { - std::vector mypk; struct CC_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,entropyvout,numblocks,lastheight=0,vin0_needed,i,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; uint32_t now; struct dicefinish_utxo *utxos; uint256 hashBlock,entropyused; CPubKey dicepk; CTransaction betTx,finishTx,tx; + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,entropyvout,numblocks,lastheight=0,vin0_needed,i,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; uint32_t now; struct dicefinish_utxo *utxos; uint256 hashBlock,entropyused; CPubKey dicepk; CTransaction betTx,finishTx,tx; mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); @@ -735,7 +735,7 @@ uint256 DiceGetEntropy(CTransaction tx,uint8_t reffuncid) else return(zeroid); } -uint64_t IsDicevout(struct CC_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) +uint64_t IsDicevout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) { char destaddr[64]; uint8_t funcid; int32_t numvouts; uint64_t sbits; uint256 fundingtxid,hash,proof; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -749,7 +749,7 @@ uint64_t IsDicevout(struct CC_info *cp,const CTransaction& tx,int32_t v,uint64_t return(0); } -int64_t DiceAmounts(uint64_t &inputs,uint64_t &outputs,struct CC_info *cp,Eval *eval,const CTransaction &tx,uint64_t refsbits,uint256 reffundingtxid) +int64_t DiceAmounts(uint64_t &inputs,uint64_t &outputs,struct CCcontract_info *cp,Eval *eval,const CTransaction &tx,uint64_t refsbits,uint256 reffundingtxid) { CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; uint64_t assetoshis; numvins = tx.vin.size(); @@ -834,7 +834,7 @@ bool DiceVerifyTimeout(CTransaction &betTx,int32_t timeoutblocks) return(numblocks >= timeoutblocks); } -bool DiceValidate(struct CC_info *cp,Eval *eval,const CTransaction &tx, uint32_t nIn) +bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx, uint32_t nIn) { uint256 txid,fundingtxid,vinfundingtxid,vinhentropy,vinproof,hashBlock,hash,proof,entropy; int64_t minbet,maxbet,maxodds,timeoutblocks,odds,winnings; uint64_t vinsbits,refsbits=0,sbits,amount,inputs,outputs,txfee=10000; int32_t numvins,entropyvout,numvouts,preventCCvins,preventCCvouts,i,iswin; uint8_t funcid; CScript fundingPubKey; CTransaction fundingTx,vinTx,vinofvinTx; char CCaddr[64]; numvins = tx.vin.size(); @@ -1046,7 +1046,7 @@ bool DiceValidate(struct CC_info *cp,Eval *eval,const CTransaction &tx, uint32_t return(true); } -uint64_t AddDiceInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) +uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) { char coinaddr[64],str[65]; uint64_t threshold,sbits,nValue,totalinputs = 0; uint256 txid,hash,proof,hashBlock,fundingtxid; CTransaction tx; int32_t j,vout,n = 0; uint8_t funcid; std::vector > unspentOutputs; @@ -1095,7 +1095,7 @@ uint64_t AddDiceInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,ui return(totalinputs); } -int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CC_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random) +int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random) { char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,sum,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0,i=0,pendingbets=0; uint8_t funcid; std::vector > unspentOutputs; @@ -1215,7 +1215,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } } -bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CC_info *cp,uint64_t refsbits,CPubKey dicepk,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) +bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontract_info *cp,uint64_t refsbits,CPubKey dicepk,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) { char CCaddr[64]; uint64_t sbits=0; uint256 txid,hashBlock; CTransaction tx; std::vector > txids; @@ -1256,9 +1256,9 @@ bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CC_info * return(false); } -struct CC_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid,struct CC_info *C,char *planstr,uint64_t &txfee,CPubKey &mypk,CPubKey &dicepk,uint64_t &sbits,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) +struct CCcontract_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid,struct CCcontract_info *C,char *planstr,uint64_t &txfee,CPubKey &mypk,CPubKey &dicepk,uint64_t &sbits,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) { - struct CC_info *cp; int32_t cmpflag; + struct CCcontract_info *cp; int32_t cmpflag; cp = CCinit(C,EVAL_DICE); if ( txfee == 0 ) txfee = 10000; @@ -1278,7 +1278,7 @@ struct CC_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid,struct CC UniValue DiceInfo(uint256 diceid) { - UniValue result(UniValue::VOBJ); CPubKey dicepk; uint256 hashBlock,entropytxid; CTransaction vintx; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits,funding,entropyval; char str[67],numstr[65]; struct CC_info *cp,C; + UniValue result(UniValue::VOBJ); CPubKey dicepk; uint256 hashBlock,entropytxid; CTransaction vintx; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits,funding,entropyval; char str[67],numstr[65]; struct CCcontract_info *cp,C; if ( myGetTransaction(diceid,vintx,hashBlock) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); @@ -1314,7 +1314,7 @@ UniValue DiceInfo(uint256 diceid) UniValue DiceList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint256 txid,hashBlock; CTransaction vintx; uint64_t sbits; int64_t minbet,maxbet,maxodds,timeoutblocks; char str[65]; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock; CTransaction vintx; uint64_t sbits; int64_t minbet,maxbet,maxodds,timeoutblocks; char str[65]; cp = CCinit(&C,EVAL_DICE); SetCCtxids(addressIndex,cp->normaladdr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) @@ -1334,7 +1334,7 @@ UniValue DiceList() std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - uint256 zero; CScript fundingPubKey; CPubKey mypk,dicepk; int64_t a,b,c,d; uint64_t sbits; struct CC_info *cp,C; + uint256 zero; CScript fundingPubKey; CPubKey mypk,dicepk; int64_t a,b,c,d; uint64_t sbits; struct CCcontract_info *cp,C; if ( funds < 0 || minbet < 0 || maxbet < 0 || maxodds < 1 || maxodds > 9999 || timeoutblocks < 0 || timeoutblocks > 1440 ) { CCerror = "invalid parameter error"; @@ -1369,7 +1369,7 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CScript fundingPubKey,scriptPubKey; uint256 entropy,hentropy; CPubKey mypk,dicepk; uint64_t sbits; struct CC_info *cp,C; int64_t minbet,maxbet,maxodds,timeoutblocks; + CScript fundingPubKey,scriptPubKey; uint256 entropy,hentropy; CPubKey mypk,dicepk; uint64_t sbits; struct CCcontract_info *cp,C; int64_t minbet,maxbet,maxodds,timeoutblocks; if ( amount < 0 ) { CCerror = "amount must be positive"; @@ -1413,7 +1413,7 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval,entropyval2; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropytxid2,entropy,hentropy; struct CC_info *cp,C; + CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval,entropyval2; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropytxid2,entropy,hentropy; struct CCcontract_info *cp,C; if ( bet < 0 ) { CCerror = "bet must be positive"; @@ -1472,7 +1472,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyvout,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout,uint256 vin0txid,int32_t vin0vout) { CMutableTransaction savemtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbettxid; CPubKey mypk,dicepk,fundingpk; struct CC_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t oldentropyvout,retval=0,iswin=0; uint64_t entropyval,sbits; + CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbettxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t oldentropyvout,retval=0,iswin=0; uint64_t entropyval,sbits; entropyused = zeroid; *resultp = 0; funcid = 0; @@ -1653,7 +1653,7 @@ static uint256 dealer0_fundingtxid; void *dealer0_loop(void *_arg) { char *planstr = (char *)_arg; - CTransaction tx,*entropytxs,entropytx; CPubKey mypk,dicepk; uint64_t entropyval; uint256 hashBlock,entropytxid,txid; int32_t height,lastht,numentropytxs,i,n,m,num; CScript fundingPubKey; struct CC_info *cp,C; char coinaddr[64]; std::string res; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t refsbits,txfee = 10000; + CTransaction tx,*entropytxs,entropytx; CPubKey mypk,dicepk; uint64_t entropyval; uint256 hashBlock,entropytxid,txid; int32_t height,lastht,numentropytxs,i,n,m,num; CScript fundingPubKey; struct CCcontract_info *cp,C; char coinaddr[64]; std::string res; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t refsbits,txfee = 10000; if ( (cp= Diceinit(fundingPubKey,dealer0_fundingtxid,&C,planstr,txfee,mypk,dicepk,refsbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { fprintf(stderr,"error initializing dealer0_loop\n"); @@ -1749,7 +1749,7 @@ void *dealer0_loop(void *_arg) double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid) { static int32_t didinit; static char _planstr[64]; - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CC_info *cp,C; int32_t i,entropyvout,flag,win,num,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits,refsbits; char coinaddr[64]; std::string res; uint8_t funcid; + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,entropyvout,flag,win,num,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits,refsbits; char coinaddr[64]; std::string res; uint8_t funcid; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,refsbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { CCerror = "Diceinit error in status, is your transaction confirmed?"; diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index 5239b0d5b..ca2703bff 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -31,7 +31,7 @@ bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,co char *CClib_name(); Eval* EVAL_TEST = 0; -struct CC_info CCinfos[0x100]; +struct CCcontract_info CCinfos[0x100]; extern pthread_mutex_t KOMODO_CC_mutex; bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn) @@ -62,7 +62,7 @@ bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn) */ bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn) { - struct CC_info *cp; + struct CCcontract_info *cp; if (cond->codeLength == 0) return Invalid("empty-eval"); diff --git a/src/cc/eval.h b/src/cc/eval.h index 61fdb892d..a42bbdb2f 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -286,8 +286,8 @@ typedef std::pair TxProof; uint256 GetMerkleRoot(const std::vector& vLeaves); -struct CC_info *CCinit(struct CC_info *cp,uint8_t evalcode); -bool ProcessCC(struct CC_info *cp,Eval* eval, std::vector paramsNull, const CTransaction &tx, unsigned int nIn); +struct CCcontract_info *CCinit(struct CCcontract_info *cp,uint8_t evalcode); +bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector paramsNull, const CTransaction &tx, unsigned int nIn); #endif /* CC_EVAL_H */ diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index be3ff8a2c..6e59b6c1a 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -28,7 +28,7 @@ // start of consensus code -int64_t IsFaucetvout(struct CC_info *cp,const CTransaction& tx,int32_t v) +int64_t IsFaucetvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -39,7 +39,7 @@ int64_t IsFaucetvout(struct CC_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool FaucetExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -77,7 +77,7 @@ bool FaucetExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int else return(true); } -bool FaucetValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; std::vector > txids; @@ -140,7 +140,7 @@ bool FaucetValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32 // helper functions for rpc calls in rpcwallet.cpp -int64_t AddFaucetInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { char coinaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; @@ -175,7 +175,7 @@ int64_t AddFaucetInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,i std::string FaucetGet(uint64_t txfee) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,faucetpk; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CC_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; + CPubKey mypk,faucetpk; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; cp = CCinit(&C,EVAL_FAUCET); if ( txfee == 0 ) txfee = 10000; @@ -216,7 +216,7 @@ std::string FaucetGet(uint64_t txfee) std::string FaucetFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,faucetpk; CScript opret; struct CC_info *cp,C; + CPubKey mypk,faucetpk; CScript opret; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_FAUCET); if ( txfee == 0 ) txfee = 10000; @@ -234,7 +234,7 @@ UniValue FaucetInfo() { UniValue result(UniValue::VOBJ); char numstr[64]; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey faucetpk; struct CC_info *cp,C; int64_t funding; + CPubKey faucetpk; struct CCcontract_info *cp,C; int64_t funding; result.push_back(Pair("result","success")); result.push_back(Pair("name","Faucet")); cp = CCinit(&C,EVAL_FAUCET); diff --git a/src/cc/fsm.cpp b/src/cc/fsm.cpp index 573299665..0bcc61a1b 100644 --- a/src/cc/fsm.cpp +++ b/src/cc/fsm.cpp @@ -23,7 +23,7 @@ // start of consensus code -int64_t IsFSMvout(struct CC_info *cp,const CTransaction& tx,int32_t v) +int64_t IsFSMvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -34,7 +34,7 @@ int64_t IsFSMvout(struct CC_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool FSMExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool FSMExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -72,7 +72,7 @@ bool FSMExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_ else return(true); } -bool FSMValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; return eval->Invalid("no validation yet"); @@ -120,7 +120,7 @@ bool FSMValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t // helper functions for rpc calls in rpcwallet.cpp -int64_t AddFSMInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddFSMInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; @@ -158,7 +158,7 @@ std::string FSMList() std::string FSMCreate(uint64_t txfee,std::string name,std::string states) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,fsmpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CC_info *cp,C; + CPubKey mypk,fsmpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_FSM); if ( txfee == 0 ) txfee = 10000; @@ -179,7 +179,7 @@ std::string FSMCreate(uint64_t txfee,std::string name,std::string states) std::string FSMInfo(uint256 fsmtxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,fsmpk; int64_t funds = 0; CScript opret; struct CC_info *cp,C; + CPubKey mypk,fsmpk; int64_t funds = 0; CScript opret; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_FSM); mypk = pubkey2pk(Mypubkey()); fsmpk = GetUnspendable(cp,0); diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index f00b1abfd..c64d56b80 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -320,7 +320,7 @@ uint8_t DecodeGatewaysOpRet(const CScript &scriptPubKey) return(0); } -int64_t IsGatewaysvout(struct CC_info *cp,const CTransaction& tx,int32_t v) +int64_t IsGatewaysvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -331,7 +331,7 @@ int64_t IsGatewaysvout(struct CC_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool GatewaysExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool GatewaysExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -429,7 +429,7 @@ uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,u return(zeroid); } -int32_t GatewaysCointxidExists(struct CC_info *cp,uint256 cointxid) // dont forget to check mempool! +int32_t GatewaysCointxidExists(struct CCcontract_info *cp,uint256 cointxid) // dont forget to check mempool! { char txidaddr[64]; std::string coin; int32_t numvouts; uint256 hashBlock; std::vector > addressIndex; @@ -515,7 +515,7 @@ int64_t GatewaysDepositval(CTransaction tx,CPubKey mypk) return(0); } -bool GatewaysValidate(struct CC_info *cp,Eval *eval,const CTransaction &tx, uint32_t nIn) +bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks,height,claimvout; bool retval; uint8_t funcid,hash[32],M,N,taddr,prefix,prefix2; char str[65],destaddr[64],depositaddr[65],validationError[512]; @@ -683,7 +683,7 @@ bool GatewaysValidate(struct CC_info *cp,Eval *eval,const CTransaction &tx, uint // helper functions for rpc calls in rpcwallet.cpp -int64_t AddGatewaysInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 reftokenid,int64_t total,int32_t maxinputs) +int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 reftokenid,int64_t total,int32_t maxinputs) { char coinaddr[64],destaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 tokenid,txid,hashBlock; std::vector origpubkey; std::vector vopret; CTransaction vintx; int32_t j,vout,n = 0; uint8_t evalcode,funcid; std::vector > unspentOutputs; @@ -730,7 +730,7 @@ int64_t AddGatewaysInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk return(totalinputs); } -int32_t GatewaysBindExists(struct CC_info *cp,CPubKey gatewayspk,uint256 reftokenid) // dont forget to check mempool! +int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256 reftokenid) // dont forget to check mempool! { char markeraddr[64],depositaddr[64]; std::string coin; int32_t numvouts; int64_t totalsupply; uint256 tokenid,oracletxid,hashBlock; uint8_t M,N,taddr,prefix,prefix2; std::vector pubkeys; CTransaction tx; std::vector > addressIndex; @@ -757,7 +757,7 @@ int32_t GatewaysBindExists(struct CC_info *cp,CPubKey gatewayspk,uint256 reftoke std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector pubkeys) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction oracletx; uint8_t taddr,prefix,prefix2; CPubKey mypk,gatewayspk; CScript opret; uint256 hashBlock; struct CC_info *cp,C; std::string name,description,format; int32_t i,numvouts; int64_t fullsupply; char destaddr[64],coinaddr[64],str[65],*fstr; + CTransaction oracletx; uint8_t taddr,prefix,prefix2; CPubKey mypk,gatewayspk; CScript opret; uint256 hashBlock; struct CCcontract_info *cp,C; std::string name,description,format; int32_t i,numvouts; int64_t fullsupply; char destaddr[64],coinaddr[64],str[65],*fstr; cp = CCinit(&C,EVAL_GATEWAYS); if ( strcmp((char *)"KMD",coin.c_str()) == 0 ) { @@ -844,7 +844,7 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std:: { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CTransaction bindtx; CPubKey mypk,gatewayspk; uint256 oracletxid,merkleroot,mhash,hashBlock,tokenid,txid; - int64_t totalsupply; int32_t i,m,n,numvouts; uint8_t M,N,taddr,prefix,prefix2; std::string coin; struct CC_info *cp,C; + int64_t totalsupply; int32_t i,m,n,numvouts; uint8_t M,N,taddr,prefix,prefix2; std::string coin; struct CCcontract_info *cp,C; std::vector pubkeys,publishers; std::vectortxids; char str[67],depositaddr[64],txidaddr[64]; cp = CCinit(&C,EVAL_GATEWAYS); @@ -910,7 +910,7 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std:: std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,uint256 deposittxid,CPubKey destpub,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction tx; CPubKey mypk,gatewayspk,tmpdestpub; struct CC_info *cp,C; uint8_t M,N,taddr,prefix,prefix2; + CTransaction tx; CPubKey mypk,gatewayspk,tmpdestpub; struct CCcontract_info *cp,C; uint8_t M,N,taddr,prefix,prefix2; std::string coin, deposithex; std::vector msigpubkeys,publishers; int64_t totalsupply,depositamount,tmpamount,inputs,CCchange=0; int32_t numvouts,claimvout,height; std::vector proof; uint256 hashBlock,tokenid,oracletxid,tmptxid,cointxid; char str[65],depositaddr[64],coinaddr[64],destaddr[64]; std::vector txids; @@ -985,8 +985,8 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin CPubKey mypk, gatewayspk; uint256 tokenid,hashBlock,oracletxid; int32_t numvouts; int64_t totalsupply,inputs,CCchange=0; uint8_t M,N,taddr,prefix,prefix2; std::string coin; std::vector msigpubkeys; char depositaddr[64],str[65],coinaddr[64]; - struct CC_info *cpGateways, gatewaysC; - struct CC_info *cpTokens, tokensC; + struct CCcontract_info *cpGateways, gatewaysC; + struct CCcontract_info *cpTokens, tokensC; cpGateways = CCinit(&gatewaysC, EVAL_GATEWAYS); cpTokens = CCinit(&tokensC, EVAL_TOKENS); @@ -1049,7 +1049,7 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin std::string GatewaysPartialSign(uint64_t txfee,uint256 txid,std::string refcoin, std::string hex) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,txidaddrpk,signerpk; struct CC_info *cp,C; CTransaction tx; + CPubKey mypk,txidaddrpk,signerpk; struct CCcontract_info *cp,C; CTransaction tx; std::vector > unspentOutputs; char txidaddr[65]; int32_t maxK,K=0; uint256 tmptxid,parttxid,hashBlock; cp = CCinit(&C,EVAL_GATEWAYS); @@ -1089,7 +1089,7 @@ std::string GatewaysPartialSign(uint64_t txfee,uint256 txid,std::string refcoin, std::string GatewaysCompleteSigning(uint64_t txfee,uint256 withdrawtxid,std::string refcoin,std::string hex) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,gatewayspk; struct CC_info *cp,C; char txidaddr[65]; + CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C; char txidaddr[65]; cp = CCinit(&C,EVAL_GATEWAYS); mypk = pubkey2pk(Mypubkey()); gatewayspk = GetUnspendable(cp,0); @@ -1104,7 +1104,7 @@ std::string GatewaysCompleteSigning(uint64_t txfee,uint256 withdrawtxid,std::str std::string GatewaysMarkDone(uint64_t txfee,uint256 completetxid,std::string refcoin) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,gatewayspk; struct CC_info *cp,C; char txidaddr[65]; + CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C; char txidaddr[65]; cp = CCinit(&C,EVAL_GATEWAYS); mypk = pubkey2pk(Mypubkey()); if ( txfee == 0 ) @@ -1118,7 +1118,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) UniValue result(UniValue::VOBJ),pending(UniValue::VARR); CTransaction tx; std::string tmprefcoin; CPubKey mypk,gatewayspk,withdrawpub; std::vector msigpubkeys; uint256 hashBlock,tokenid,txid,oracletxid; uint8_t M,N,taddr,prefix,prefix2; char depositaddr[64],coinaddr[64],destaddr[64],str[65],withaddr[64],numstr[32],txidaddr[64],cctxidaddr[64],signeraddr[64]; - int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,amount,nValue; struct CC_info *cp,C; + int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,amount,nValue; struct CCcontract_info *cp,C; std::vector > unspentOutputs; cp = CCinit(&C,EVAL_GATEWAYS); @@ -1186,7 +1186,7 @@ UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin) UniValue result(UniValue::VOBJ),processed(UniValue::VARR); CTransaction tx; std::string tmprefcoin,hex; CPubKey mypk,gatewayspk,withdrawpub; std::vector msigpubkeys; uint256 withdrawtxid,hashBlock,txid,tokenid,oracletxid; uint8_t M,N,taddr,prefix,prefix2; char depositaddr[64],coinaddr[64],str[65],numstr[32],txidaddr[64],cctxidaddr[64],withaddr[64]; - int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,nValue,amount; struct CC_info *cp,C; + int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,nValue,amount; struct CCcontract_info *cp,C; std::vector > unspentOutputs; cp = CCinit(&C,EVAL_GATEWAYS); @@ -1278,7 +1278,7 @@ UniValue GatewaysMultisig(char *cctxidaddr) UniValue GatewaysList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint256 txid,hashBlock,oracletxid,tokenid; CTransaction vintx; std::string coin; int64_t totalsupply; char str[65],depositaddr[64]; uint8_t M,N,taddr,prefix,prefix2; std::vector pubkeys; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock,oracletxid,tokenid; CTransaction vintx; std::string coin; int64_t totalsupply; char str[65],depositaddr[64]; uint8_t M,N,taddr,prefix,prefix2; std::vector pubkeys; cp = CCinit(&C,EVAL_GATEWAYS); SetCCtxids(addressIndex,cp->unspendableCCaddr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) @@ -1298,7 +1298,7 @@ UniValue GatewaysList() UniValue GatewaysInfo(uint256 bindtxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::string coin; char str[67],numstr[65],depositaddr[64],gatewaysassets[64]; uint8_t M,N; std::vector pubkeys; uint8_t taddr,prefix,prefix2; uint256 tokenid,oracletxid,hashBlock; CTransaction tx; CPubKey Gatewayspk; struct CC_info *cp,C; int32_t i; int64_t totalsupply,remaining; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::string coin; char str[67],numstr[65],depositaddr[64],gatewaysassets[64]; uint8_t M,N; std::vector pubkeys; uint8_t taddr,prefix,prefix2; uint256 tokenid,oracletxid,hashBlock; CTransaction tx; CPubKey Gatewayspk; struct CCcontract_info *cp,C; int32_t i; int64_t totalsupply,remaining; result.push_back(Pair("result","success")); result.push_back(Pair("name","Gateways")); cp = CCinit(&C,EVAL_GATEWAYS); diff --git a/src/cc/lotto.cpp b/src/cc/lotto.cpp index c52c9a072..e9c263ff1 100644 --- a/src/cc/lotto.cpp +++ b/src/cc/lotto.cpp @@ -63,7 +63,7 @@ It is possible to have a jackpot but miss out on it due to not claiming it. To m // start of consensus code -int64_t IsLottovout(struct CC_info *cp,const CTransaction& tx,int32_t v) +int64_t IsLottovout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -74,7 +74,7 @@ int64_t IsLottovout(struct CC_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool LottoExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool LottoExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -112,7 +112,7 @@ bool LottoExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int3 else return(true); } -bool LottoValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool LottoValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; return eval->Invalid("no validation yet"); @@ -160,7 +160,7 @@ bool LottoValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_ // helper functions for rpc calls in rpcwallet.cpp -int64_t AddLottoInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddLottoInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; @@ -203,7 +203,7 @@ uint8_t DecodeLottoFundingOpRet(const CScript &scriptPubKey,uint64_t &sbits,int3 return(0); } -int64_t LottoPlanFunds(uint64_t refsbits,struct CC_info *cp,CPubKey pk,uint256 reffundingtxid) +int64_t LottoPlanFunds(uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk,uint256 reffundingtxid) { char coinaddr[64]; uint64_t sbits; int64_t nValue,lockedfunds; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t vout; uint8_t funcid; std::vector > unspentOutputs; @@ -232,7 +232,7 @@ int64_t LottoPlanFunds(uint64_t refsbits,struct CC_info *cp,CPubKey pk,uint256 r UniValue LottoInfo(uint256 lottoid) { - UniValue result(UniValue::VOBJ); uint256 hashBlock,hentropy; CTransaction vintx; uint64_t lockedfunds,sbits; int32_t ticketsize,odds,firstheight,period; CPubKey lottopk; struct CC_info *cp,C; char str[67],numstr[65]; + UniValue result(UniValue::VOBJ); uint256 hashBlock,hentropy; CTransaction vintx; uint64_t lockedfunds,sbits; int32_t ticketsize,odds,firstheight,period; CPubKey lottopk; struct CCcontract_info *cp,C; char str[67],numstr[65]; if ( GetTransaction(lottoid,vintx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find lottoid\n"); @@ -264,7 +264,7 @@ UniValue LottoInfo(uint256 lottoid) UniValue LottoList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint256 txid,hashBlock,hentropy; CTransaction vintx; uint64_t sbits; int32_t ticketsize,odds,firstheight,period; char str[65]; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock,hentropy; CTransaction vintx; uint64_t sbits; int32_t ticketsize,odds,firstheight,period; char str[65]; cp = CCinit(&C,EVAL_LOTTO); SetCCtxids(addressIndex,cp->normaladdr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) @@ -284,7 +284,7 @@ UniValue LottoList() std::string LottoCreate(uint64_t txfee,char *planstr,int64_t funding,int32_t ticketsize,int32_t odds,int32_t firstheight,int32_t period) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - uint256 entropy,hentropy; CPubKey mypk,lottopk; uint64_t sbits; int64_t inputs,CCchange=0,nValue=COIN; struct CC_info *cp,C; + uint256 entropy,hentropy; CPubKey mypk,lottopk; uint64_t sbits; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_LOTTO); if ( txfee == 0 ) txfee = 10000; @@ -303,7 +303,7 @@ std::string LottoCreate(uint64_t txfee,char *planstr,int64_t funding,int32_t tic std::string LottoTicket(uint64_t txfee,uint256 lottoid,int64_t numtickets) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,lottopk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CC_info *cp,C; + CPubKey mypk,lottopk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_LOTTO); if ( txfee == 0 ) txfee = 10000; @@ -324,7 +324,7 @@ std::string LottoTicket(uint64_t txfee,uint256 lottoid,int64_t numtickets) std::string LottoWinner(uint64_t txfee) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,lottopk; int64_t winnings = 0; CScript opret; struct CC_info *cp,C; + CPubKey mypk,lottopk; int64_t winnings = 0; CScript opret; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_LOTTO); if ( txfee == 0 ) txfee = 10000; diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 692c496b3..795b95186 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -47,7 +47,7 @@ // start of consensus code -int64_t IsMarmaravout(struct CC_info *cp,const CTransaction& tx,int32_t v) +int64_t IsMarmaravout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -188,7 +188,7 @@ int32_t MarmaraGetbatontxid(std::vector &creditloop,uint256 &batontxid, CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) { - CTxOut ccvout; struct CC_info *cp,C; CPubKey Marmarapk; + CTxOut ccvout; struct CCcontract_info *cp,C; CPubKey Marmarapk; cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) @@ -212,7 +212,7 @@ CScript MarmaraCoinbaseOpret(uint8_t funcid,int32_t height,CPubKey pk) int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { - struct CC_info *cp,C; CPubKey Marmarapk,pk; int32_t ht,unlockht; CTxOut ccvout; + struct CCcontract_info *cp,C; CPubKey Marmarapk,pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); if ( 0 ) @@ -255,7 +255,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) return(-1); } -bool MarmaraValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { std::vector vopret; CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid,vfuncid,*script; CPubKey pk,vpk; if ( ASSETCHAINS_MARMARA == 0 ) @@ -326,7 +326,7 @@ bool MarmaraValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint3 // helper functions for rpc calls in rpcwallet.cpp -int64_t AddMarmaraCoinbases(struct CC_info *cp,CMutableTransaction &mtx,int32_t firstheight,CPubKey poolpk,int32_t maxinputs) +int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx,int32_t firstheight,CPubKey poolpk,int32_t maxinputs) { char coinaddr[64]; CPubKey Marmarapk,pk; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; std::vector > unspentOutputs; @@ -408,7 +408,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); struct CC_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,val,inputsum=0,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; CPubKey Marmarapk,mypk,pk; int32_t unlockht,refunlockht,vout,ht,numvouts; int64_t nValue,val,inputsum=0,threshold,remains,change = 0; std::string rawtx,errorstr; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; uint8_t funcid; if ( txfee == 0 ) txfee = 10000; if ( (height & 1) != 0 ) @@ -490,7 +490,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures,height; int64_t amount,refamount,remaining,inputsum,change; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; std::vector pubkeys; struct CC_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures,height; int64_t amount,refamount,remaining,inputsum,change; CPubKey Marmarapk,mypk,pk; std::string currency,refcurrency,rawtx; CTransaction tx,batontx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2],txidaddr[64]; std::vector pubkeys; struct CCcontract_info *cp,C; if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); @@ -607,7 +607,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) return(result); } -int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuances,int64_t &totalclosed,std::vector &closed,struct CC_info *cp,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,CPubKey refpk,std::string refcurrency) +int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuances,int64_t &totalclosed,std::vector &closed,struct CCcontract_info *cp,int32_t firstheight,int32_t lastheight,int64_t minamount,int64_t maxamount,CPubKey refpk,std::string refcurrency) { char coinaddr[64]; CPubKey Marmarapk,senderpk; int64_t amount; uint256 createtxid,txid,hashBlock; CTransaction tx; int32_t numvouts,vout,matures,n=0; std::string currency; std::vector > unspentOutputs; @@ -643,7 +643,7 @@ int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuanc UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid,bool automaticflag) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); CPubKey mypk; struct CC_info *cp,C; std::string rawtx; char *errorstr=0; uint256 createtxid; int64_t batonamount; int32_t needbaton = 0; + UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; uint256 createtxid; int64_t batonamount; int32_t needbaton = 0; cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; @@ -700,7 +700,7 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 approvaltxid,uint256 batontxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); CPubKey mypk,Marmarapk; struct CC_info *cp,C; std::string rawtx; uint256 createtxid; char *errorstr=0; + UniValue result(UniValue::VOBJ); CPubKey mypk,Marmarapk; struct CCcontract_info *cp,C; std::string rawtx; uint256 createtxid; char *errorstr=0; cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; @@ -757,7 +757,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a UniValue MarmaraCreditloop(uint256 txid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey pk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CC_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector creditloop; uint256 batontxid,createtxid,refcreatetxid,hashBlock; uint8_t funcid; int32_t numerrs=0,i,n,numvouts,matures,refmatures; int64_t amount,refamount; CPubKey pk; std::string currency,refcurrency; CTransaction tx; char coinaddr[64],myCCaddr[64],destaddr[64],batonCCaddr[64],str[2]; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) { @@ -911,7 +911,7 @@ UniValue MarmaraCreditloop(uint256 txid) UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,poolfee=0,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CC_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,poolfee=0,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; poolpk = pubkey2pk(Mypubkey()); if ( txfee == 0 ) txfee = 10000; @@ -1000,7 +1000,7 @@ UniValue MarmaraInfo(CPubKey refpk,int32_t firstheight,int32_t lastheight,int64_ { CMutableTransaction mtx; std::vector pubkeys; UniValue result(UniValue::VOBJ),a(UniValue::VARR),b(UniValue::VARR); int32_t i,n,matches; int64_t totalclosed=0,totalamount=0; std::vector issuances,closed; char coinaddr[64]; - CPubKey Marmarapk; struct CC_info *cp,C; + CPubKey Marmarapk; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); result.push_back(Pair("result","success")); diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index a64f65a18..66c0e1b9a 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -163,7 +163,7 @@ uint8_t DecodeOraclesData(const CScript &scriptPubKey,uint256 &oracletxid,uint25 return(0); } -CPubKey OracleBatonPk(char *batonaddr,struct CC_info *cp) +CPubKey OracleBatonPk(char *batonaddr,struct CCcontract_info *cp) { static secp256k1_context *ctx; size_t clen = CPubKey::PUBLIC_KEY_SIZE; @@ -256,7 +256,7 @@ static uint256 myIs_baton_spentinmempool(uint256 batontxid,int32_t batonvout) return(batontxid); } -uint256 OracleBatonUtxo(uint64_t txfee,struct CC_info *cp,uint256 reforacletxid,char *batonaddr,CPubKey publisher,std::vector &dataarg) +uint256 OracleBatonUtxo(uint64_t txfee,struct CCcontract_info *cp,uint256 reforacletxid,char *batonaddr,CPubKey publisher,std::vector &dataarg) { uint256 txid,oracletxid,hashBlock,btxid,batontxid = zeroid; int64_t dfee; int32_t dheight=0,vout,height,numvouts; CTransaction tx; CPubKey pk; uint8_t *ptr; std::vector vopret,data; std::vector > unspentOutputs; @@ -302,7 +302,7 @@ uint256 OracleBatonUtxo(uint64_t txfee,struct CC_info *cp,uint256 reforacletxid, uint256 OraclesBatontxid(uint256 reforacletxid,CPubKey refpk) { std::vector > unspentOutputs; - CTransaction regtx; uint256 hash,txid,batontxid,oracletxid; CPubKey pk; int32_t numvouts,height,maxheight=0; int64_t datafee; char markeraddr[64],batonaddr[64]; std::vector data; struct CC_info *cp,C; + CTransaction regtx; uint256 hash,txid,batontxid,oracletxid; CPubKey pk; int32_t numvouts,height,maxheight=0; int64_t datafee; char markeraddr[64],batonaddr[64]; std::vector data; struct CCcontract_info *cp,C; batontxid = zeroid; cp = CCinit(&C,EVAL_ORACLES); CCtxidaddr(markeraddr,reforacletxid); @@ -528,7 +528,7 @@ int32_t oracleprice_add(std::vector &publishers,CPubKey int64_t OraclePrice(int32_t height,uint256 reforacletxid,char *markeraddr,char *format) { std::vector > unspentOutputs; - CTransaction regtx; uint256 hash,txid,oracletxid,batontxid; CPubKey pk; int32_t i,ht,maxheight=0; int64_t datafee,price; char batonaddr[64]; std::vector data; struct CC_info *cp,C; std::vector publishers; std::vector prices; + CTransaction regtx; uint256 hash,txid,oracletxid,batontxid; CPubKey pk; int32_t i,ht,maxheight=0; int64_t datafee,price; char batonaddr[64]; std::vector data; struct CCcontract_info *cp,C; std::vector publishers; std::vector prices; if ( format[0] != 'L' ) return(0); cp = CCinit(&C,EVAL_ORACLES); @@ -564,7 +564,7 @@ int64_t OraclePrice(int32_t height,uint256 reforacletxid,char *markeraddr,char * return(0); } -int64_t IsOraclesvout(struct CC_info *cp,const CTransaction& tx,int32_t v) +int64_t IsOraclesvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { //char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -575,7 +575,7 @@ int64_t IsOraclesvout(struct CC_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool OraclesDataValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx,uint256 oracletxid,CPubKey publisher,int64_t datafee) +bool OraclesDataValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,uint256 oracletxid,CPubKey publisher,int64_t datafee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; CScript scriptPubKey; @@ -633,7 +633,7 @@ bool OraclesDataValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx,ui else return(true); } -bool OraclesValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { uint256 txid,oracletxid,batontxid; uint64_t txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts; uint8_t *script; std::vector vopret,data; CScript scriptPubKey; CPubKey publisher; numvins = tx.vin.size(); @@ -703,7 +703,7 @@ bool OraclesValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint3 // helper functions for rpc calls in rpcwallet.cpp -int64_t AddOracleInputs(struct CC_info *cp,CMutableTransaction &mtx,uint256 oracletxid,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddOracleInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,uint256 oracletxid,CPubKey pk,int64_t total,int32_t maxinputs) { char coinaddr[64],funcid; int64_t nValue,price,totalinputs = 0; uint256 tmporacletxid,tmpbatontxid,txid,hashBlock; std::vector origpubkey,data; CTransaction vintx; int32_t numvouts,vout,n = 0; std::vector > unspentOutputs; CPubKey tmppk; int64_t tmpnum; @@ -741,7 +741,7 @@ int64_t AddOracleInputs(struct CC_info *cp,CMutableTransaction &mtx,uint256 orac return(totalinputs); } -int64_t LifetimeOraclesFunds(struct CC_info *cp,uint256 oracletxid,CPubKey publisher) +int64_t LifetimeOraclesFunds(struct CCcontract_info *cp,uint256 oracletxid,CPubKey publisher) { char coinaddr[64]; CPubKey pk; int64_t total=0,num; uint256 txid,hashBlock,subtxid; CTransaction subtx; std::vector > addressIndex; @@ -765,7 +765,7 @@ int64_t LifetimeOraclesFunds(struct CC_info *cp,uint256 oracletxid,CPubKey publi std::string OracleCreate(int64_t txfee,std::string name,std::string description,std::string format) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Oraclespk; struct CC_info *cp,C; char fmt; + CPubKey mypk,Oraclespk; struct CCcontract_info *cp,C; char fmt; cp = CCinit(&C,EVAL_ORACLES); if ( name.size() > 32 || description.size() > 4096 || format.size() > 4096 ) @@ -805,7 +805,7 @@ std::string OracleCreate(int64_t txfee,std::string name,std::string description, std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,markerpubkey,batonpk; struct CC_info *cp,C; char markeraddr[64],batonaddr[64]; + CPubKey mypk,markerpubkey,batonpk; struct CCcontract_info *cp,C; char markeraddr[64],batonaddr[64]; cp = CCinit(&C,EVAL_ORACLES); if ( txfee == 0 ) txfee = 10000; @@ -832,7 +832,7 @@ std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee) std::string OracleSubscribe(int64_t txfee,uint256 oracletxid,CPubKey publisher,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,markerpubkey; struct CC_info *cp,C; char markeraddr[64]; + CPubKey mypk,markerpubkey; struct CCcontract_info *cp,C; char markeraddr[64]; cp = CCinit(&C,EVAL_ORACLES); if ( txfee == 0 ) txfee = 10000; @@ -852,7 +852,7 @@ std::string OracleSubscribe(int64_t txfee,uint256 oracletxid,CPubKey publisher,i std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector data) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CScript pubKey; CPubKey mypk,batonpk; int64_t offset,datafee,inputs,CCchange = 0; struct CC_info *cp,C; uint256 batontxid,hashBlock; + CScript pubKey; CPubKey mypk,batonpk; int64_t offset,datafee,inputs,CCchange = 0; struct CCcontract_info *cp,C; uint256 batontxid,hashBlock; char coinaddr[64],batonaddr[64]; std::vector prevdata; CTransaction tx; std::string name,description,format; int32_t len,numvouts; cp = CCinit(&C,EVAL_ORACLES); @@ -971,7 +971,7 @@ UniValue OracleInfo(uint256 origtxid) UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector > unspentOutputs; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction regtx,tx; std::string name,description,format; uint256 hashBlock,txid,oracletxid,batontxid; CPubKey pk; struct CC_info *cp,C; int64_t datafee,funding; char str[67],markeraddr[64],numstr[64],batonaddr[64]; std::vector data; + CTransaction regtx,tx; std::string name,description,format; uint256 hashBlock,txid,oracletxid,batontxid; CPubKey pk; struct CCcontract_info *cp,C; int64_t datafee,funding; char str[67],markeraddr[64],numstr[64],batonaddr[64]; std::vector data; cp = CCinit(&C,EVAL_ORACLES); CCtxidaddr(markeraddr,origtxid); if ( GetTransaction(origtxid,tx,hashBlock,false) == 0 ) @@ -1025,7 +1025,7 @@ UniValue OracleInfo(uint256 origtxid) UniValue OraclesList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint256 txid,hashBlock; CTransaction createtx; std::string name,description,format; char str[65]; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock; CTransaction createtx; std::string name,description,format; char str[65]; cp = CCinit(&C,EVAL_ORACLES); SetCCtxids(addressIndex,cp->normaladdr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index c25842ea3..859a5ba3f 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -23,7 +23,7 @@ // start of consensus code -int64_t IsPaymentsvout(struct CC_info *cp,const CTransaction& tx,int32_t v) +int64_t IsPaymentsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -34,7 +34,7 @@ int64_t IsPaymentsvout(struct CC_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool PaymentsExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool PaymentsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -72,7 +72,7 @@ bool PaymentsExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,i else return(true); } -bool PaymentsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; return eval->Invalid("no validation yet"); @@ -113,7 +113,7 @@ bool PaymentsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint // helper functions for rpc calls in rpcwallet.cpp -int64_t AddPaymentsInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddPaymentsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; @@ -145,7 +145,7 @@ int64_t AddPaymentsInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk std::string PaymentsGet(uint64_t txfee,int64_t nValue) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Paymentspk; int64_t inputs,CCchange=0; struct CC_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; + CPubKey mypk,Paymentspk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; cp = CCinit(&C,EVAL_PAYMENTS); if ( txfee == 0 ) txfee = 10000; @@ -186,7 +186,7 @@ std::string PaymentsGet(uint64_t txfee,int64_t nValue) std::string PaymentsFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Paymentspk; CScript opret; struct CC_info *cp,C; + CPubKey mypk,Paymentspk; CScript opret; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_PAYMENTS); if ( txfee == 0 ) txfee = 10000; @@ -204,7 +204,7 @@ UniValue PaymentsInfo() { UniValue result(UniValue::VOBJ); char numstr[64]; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey Paymentspk; struct CC_info *cp,C; int64_t funding; + CPubKey Paymentspk; struct CCcontract_info *cp,C; int64_t funding; result.push_back(Pair("result","success")); result.push_back(Pair("name","Payments")); cp = CCinit(&C,EVAL_PAYMENTS); diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index d137778a6..e2893bec8 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -30,7 +30,7 @@ // start of consensus code -int64_t IsPegsvout(struct CC_info *cp,const CTransaction& tx,int32_t v) +int64_t IsPegsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -41,7 +41,7 @@ int64_t IsPegsvout(struct CC_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool PegsExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool PegsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -79,7 +79,7 @@ bool PegsExactAmounts(struct CC_info *cp,Eval* eval,const CTransaction &tx,int32 else return(true); } -bool PegsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool PegsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; return eval->Invalid("no validation yet"); @@ -120,7 +120,7 @@ bool PegsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t // helper functions for rpc calls in rpcwallet.cpp -int64_t AddPegsInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddPegsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; @@ -152,7 +152,7 @@ int64_t AddPegsInputs(struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int std::string PegsGet(uint64_t txfee,int64_t nValue) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Pegspk; int64_t inputs,CCchange=0; struct CC_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; + CPubKey mypk,Pegspk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; cp = CCinit(&C,EVAL_PEGS); if ( txfee == 0 ) txfee = 10000; @@ -193,7 +193,7 @@ std::string PegsGet(uint64_t txfee,int64_t nValue) std::string PegsFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Pegspk; CScript opret; struct CC_info *cp,C; + CPubKey mypk,Pegspk; CScript opret; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_PEGS); if ( txfee == 0 ) txfee = 10000; @@ -211,7 +211,7 @@ UniValue PegsInfo() { UniValue result(UniValue::VOBJ); char numstr[64]; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey Pegspk; struct CC_info *cp,C; int64_t funding; + CPubKey Pegspk; struct CCcontract_info *cp,C; int64_t funding; result.push_back(Pair("result","success")); result.push_back(Pair("name","Pegs")); cp = CCinit(&C,EVAL_PEGS); diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 6171e73a8..369495b1a 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -86,7 +86,7 @@ uint8_t DecodePricesFundingOpRet(CScript scriptPubKey,CPubKey &planpk,uint256 &o return(0); } -bool PricesValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; return eval->Invalid("no validation yet"); @@ -127,7 +127,7 @@ bool PricesValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32 // helper functions for rpc calls in rpcwallet.cpp -int64_t AddTokensInputs(struct CC_info *cp,CMutableTransaction &mtx,char *destaddr,uint256 tolenid,int64_t total,int32_t maxinputs) +int64_t AddTokensInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char *destaddr,uint256 tolenid,int64_t total,int32_t maxinputs) { // add threshold check int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; @@ -158,7 +158,7 @@ int64_t AddTokensInputs(struct CC_info *cp,CMutableTransaction &mtx,char *destad UniValue PricesList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint64_t mode; int32_t margin,maxleverage; std::vectorpubkeys; uint256 txid,hashBlock,oracletxid,longtoken,shorttoken,bettoken; CPubKey planpk,pricespk; char str[65]; CTransaction vintx; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint64_t mode; int32_t margin,maxleverage; std::vectorpubkeys; uint256 txid,hashBlock,oracletxid,longtoken,shorttoken,bettoken; CPubKey planpk,pricespk; char str[65]; CTransaction vintx; cp = CCinit(&C,EVAL_PRICES); pricespk = GetUnspendable(cp,0); SetCCtxids(addressIndex,cp->normaladdr); @@ -183,7 +183,7 @@ UniValue PricesList() std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletxid,uint64_t margin,uint64_t mode,uint256 longtoken,uint256 shorttoken,int32_t maxleverage,int64_t funding,std::vector pubkeys) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction oracletx; int64_t fullsupply,inputs,CCchange=0; uint256 hashBlock; char str[65],coinaddr[64],houseaddr[64]; CPubKey mypk,pricespk; int32_t i,N,numvouts; struct CC_info *cp,C; + CTransaction oracletx; int64_t fullsupply,inputs,CCchange=0; uint256 hashBlock; char str[65],coinaddr[64],houseaddr[64]; CPubKey mypk,pricespk; int32_t i,N,numvouts; struct CCcontract_info *cp,C; if ( funding < 100*COIN || maxleverage <= 0 || maxleverage > 10000 ) { CCerror = "invalid parameter error"; @@ -246,7 +246,7 @@ std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletx UniValue PricesInfo(uint256 fundingtxid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); CPubKey pricespk,planpk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction vintx; int64_t balance,supply,exposure; uint64_t funding,mode; int32_t i,margin,maxleverage; char numstr[65],houseaddr[64],exposureaddr[64],str[65]; std::vectorpubkeys; struct CC_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); CPubKey pricespk,planpk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction vintx; int64_t balance,supply,exposure; uint64_t funding,mode; int32_t i,margin,maxleverage; char numstr[65],houseaddr[64],exposureaddr[64],str[65]; std::vectorpubkeys; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_PRICES); pricespk = GetUnspendable(cp,0); if ( GetTransaction(fundingtxid,vintx,hashBlock,false) == 0 ) @@ -295,7 +295,7 @@ UniValue PricesInfo(uint256 fundingtxid) std::string PricesAddFunding(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - struct CC_info *cp,C; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,CCchange = 0; uint64_t funding,mode; int32_t margin,maxleverage; char houseaddr[64],myaddr[64]; std::vectorpubkeys; + struct CCcontract_info *cp,C; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,CCchange = 0; uint64_t funding,mode; int32_t margin,maxleverage; char houseaddr[64],myaddr[64]; std::vectorpubkeys; if ( amount < 10000 ) { CCerror = "amount must be positive"; @@ -350,7 +350,7 @@ std::string PricesAddFunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount,int32_t leverage) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - struct CC_info *cp,C; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; std::vectorpubkeys; + struct CCcontract_info *cp,C; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; std::vectorpubkeys; if ( amount < 0 ) { amount = -amount; diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index c47fcf1c2..bd5a6d919 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -141,7 +141,7 @@ uint8_t DecodeRewardsOpRet(uint256 txid,const CScript &scriptPubKey,uint64_t &sb return(0); } -int64_t IsRewardsvout(struct CC_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) +int64_t IsRewardsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) { char destaddr[64]; uint64_t sbits; uint256 fundingtxid,txid; uint8_t funcid; int32_t numvouts; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 && (numvouts= (int32_t)tx.vout.size()) > 0 ) @@ -157,7 +157,7 @@ int64_t IsRewardsvout(struct CC_info *cp,const CTransaction& tx,int32_t v,uint64 return(0); } -bool RewardsExactAmounts(struct CC_info *cp,Eval *eval,const CTransaction &tx,uint64_t txfee,uint64_t refsbits,uint256 reffundingtxid) +bool RewardsExactAmounts(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx,uint64_t txfee,uint64_t refsbits,uint256 reffundingtxid) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -192,7 +192,7 @@ bool RewardsExactAmounts(struct CC_info *cp,Eval *eval,const CTransaction &tx,ui else return(true); } -bool RewardsValidate(struct CC_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) +bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { uint256 txid,fundingtxid,hashBlock,vinfundingtxid; uint64_t vinsbits,sbits,APR,minseconds,maxseconds,mindeposit,amount,reward,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; uint8_t funcid; CScript scriptPubKey; CTransaction fundingTx,vinTx; numvins = tx.vin.size(); @@ -327,7 +327,7 @@ static uint64_t myIs_unlockedtx_inmempool(uint256 &txid,int32_t &vout,uint64_t r } // 'L' vs 'F' and 'A' -int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CC_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) +int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) { char coinaddr[64],str[65]; uint64_t threshold,sbits,nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t numblocks,j,vout,n = 0; uint8_t funcid; std::vector > unspentOutputs; @@ -387,7 +387,7 @@ int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CC_inf return(totalinputs); } -int64_t RewardsPlanFunds(uint64_t &lockedfunds,uint64_t refsbits,struct CC_info *cp,CPubKey pk,uint256 reffundingtxid) +int64_t RewardsPlanFunds(uint64_t &lockedfunds,uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk,uint256 reffundingtxid) { char coinaddr[64]; uint64_t sbits; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t vout; uint8_t funcid; std::vector > unspentOutputs; @@ -418,7 +418,7 @@ int64_t RewardsPlanFunds(uint64_t &lockedfunds,uint64_t refsbits,struct CC_info return(totalinputs); } -bool RewardsPlanExists(struct CC_info *cp,uint64_t refsbits,CPubKey rewardspk,uint64_t &APR,uint64_t &minseconds,uint64_t &maxseconds,uint64_t &mindeposit) +bool RewardsPlanExists(struct CCcontract_info *cp,uint64_t refsbits,CPubKey rewardspk,uint64_t &APR,uint64_t &minseconds,uint64_t &maxseconds,uint64_t &mindeposit) { char CCaddr[64]; uint64_t sbits; uint256 txid,hashBlock; CTransaction tx; std::vector > txids; @@ -443,7 +443,7 @@ bool RewardsPlanExists(struct CC_info *cp,uint64_t refsbits,CPubKey rewardspk,ui UniValue RewardsInfo(uint256 rewardsid) { - UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction vintx; uint64_t lockedfunds,APR,minseconds,maxseconds,mindeposit,sbits,funding; CPubKey rewardspk; struct CC_info *cp,C; char str[67],numstr[65]; + UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction vintx; uint64_t lockedfunds,APR,minseconds,maxseconds,mindeposit,sbits,funding; CPubKey rewardspk; struct CCcontract_info *cp,C; char str[67],numstr[65]; if ( GetTransaction(rewardsid,vintx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); @@ -481,7 +481,7 @@ UniValue RewardsInfo(uint256 rewardsid) UniValue RewardsList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CC_info *cp,C; uint256 txid,hashBlock; CTransaction vintx; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; char str[65]; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock; CTransaction vintx; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; char str[65]; cp = CCinit(&C,EVAL_REWARDS); SetCCtxids(addressIndex,cp->normaladdr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) @@ -501,7 +501,7 @@ UniValue RewardsList() std::string RewardsCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t APR,int64_t minseconds,int64_t maxseconds,int64_t mindeposit) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,a,b,c,d; struct CC_info *cp,C; + CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,a,b,c,d; struct CCcontract_info *cp,C; if ( funds < COIN || mindeposit < 0 || minseconds < 0 || maxseconds < 0 ) { fprintf(stderr,"negative parameter error\n"); @@ -536,7 +536,7 @@ std::string RewardsCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int6 std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,a,b,c,d; struct CC_info *cp,C; + CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,a,b,c,d; struct CCcontract_info *cp,C; if ( amount < 0 ) { fprintf(stderr,"negative parameter error\n"); @@ -571,7 +571,7 @@ std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,i std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t deposit) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,rewardspk; CScript opret; uint64_t lockedfunds,sbits,funding,APR,minseconds,maxseconds,mindeposit; struct CC_info *cp,C; + CPubKey mypk,rewardspk; CScript opret; uint64_t lockedfunds,sbits,funding,APR,minseconds,maxseconds,mindeposit; struct CCcontract_info *cp,C; if ( deposit < txfee ) { CCerror = "deposit amount less than txfee"; @@ -615,7 +615,7 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 locktxid) { CMutableTransaction firstmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction tx; char coinaddr[64]; CPubKey mypk,rewardspk; CScript scriptPubKey,ignore; uint256 hashBlock; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; int64_t funding,reward=0,amount=0,inputs,CCchange=0; struct CC_info *cp,C; + CTransaction tx; char coinaddr[64]; CPubKey mypk,rewardspk; CScript scriptPubKey,ignore; uint256 hashBlock; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; int64_t funding,reward=0,amount=0,inputs,CCchange=0; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_REWARDS); if ( txfee == 0 ) txfee = 10000; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 51b31c5c7..10c6ee4b8 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2150,7 +2150,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } else { - struct CC_info *cp,C; uint256 txid; int32_t vout; CAmount nValue; char coinaddr[64]; CPubKey mypk,Marmarapk; + struct CCcontract_info *cp,C; uint256 txid; int32_t vout; CAmount nValue; char coinaddr[64]; CPubKey mypk,Marmarapk; std::vector > unspentOutputs; cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 588706a41..2db63d83a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5197,7 +5197,7 @@ int32_t ensure_CCrequirements() #include "../cc/CCHeir.h" #include "../cc/CCMarmara.h" -UniValue CCaddress(struct CC_info *cp,char *name,std::vector &pubkey) +UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vector &pubkey) { UniValue result(UniValue::VOBJ); char destaddr[64],str[64]; CPubKey pk; pk = GetUnspendable(cp,0); @@ -5302,7 +5302,7 @@ UniValue setpubkey(const UniValue& params, bool fHelp) UniValue channelsaddress(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CC_info *cp,C; std::vector destpubkey; CPubKey pk,pk2; char destaddr[64]; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::vector destpubkey; CPubKey pk,pk2; char destaddr[64]; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() != 1 ) throw runtime_error("channelsaddress destpubkey\n"); @@ -5329,7 +5329,7 @@ UniValue channelsaddress(const UniValue& params, bool fHelp) UniValue cclibaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_FIRSTUSER); if ( fHelp || params.size() > 1 ) throw runtime_error("cclibaddress [pubkey]\n"); @@ -5342,7 +5342,7 @@ UniValue cclibaddress(const UniValue& params, bool fHelp) UniValue cclibinfo(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; + struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_FIRSTUSER); if ( fHelp || params.size() > 0 ) throw runtime_error("cclibinfo\n"); @@ -5353,7 +5353,7 @@ UniValue cclibinfo(const UniValue& params, bool fHelp) UniValue cclib(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; char *method; cJSON *params; + struct CCcontract_info *cp,C; char *method; cJSON *params; cp = CCinit(&C,EVAL_FIRSTUSER); if ( fHelp || params.size() > 2 ) throw runtime_error("cclib method [JSON params]\n"); @@ -5366,7 +5366,7 @@ UniValue cclib(const UniValue& params, bool fHelp) UniValue oraclesaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_ORACLES); if ( fHelp || params.size() > 1 ) throw runtime_error("oraclesaddress [pubkey]\n"); @@ -5379,7 +5379,7 @@ UniValue oraclesaddress(const UniValue& params, bool fHelp) UniValue pricesaddress(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CC_info *cp,C,*assetscp,C2; std::vector pubkey; CPubKey mypk,planpk,pricespk; char myaddr[64],houseaddr[64],exposureaddr[64]; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C,*assetscp,C2; std::vector pubkey; CPubKey mypk,planpk,pricespk; char myaddr[64],houseaddr[64],exposureaddr[64]; cp = CCinit(&C,EVAL_PRICES); assetscp = CCinit(&C2,EVAL_PRICES); if ( fHelp || params.size() > 1 ) @@ -5402,7 +5402,7 @@ UniValue pricesaddress(const UniValue& params, bool fHelp) UniValue pegsaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_PEGS); if ( fHelp || params.size() > 1 ) throw runtime_error("pegssaddress [pubkey]\n"); @@ -5415,7 +5415,7 @@ UniValue pegsaddress(const UniValue& params, bool fHelp) UniValue marmaraaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_MARMARA); if ( fHelp || params.size() > 1 ) throw runtime_error("Marmaraaddress [pubkey]\n"); @@ -5428,7 +5428,7 @@ UniValue marmaraaddress(const UniValue& params, bool fHelp) UniValue paymentsaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_PAYMENTS); if ( fHelp || params.size() > 1 ) throw runtime_error("paymentsaddress [pubkey]\n"); @@ -5441,7 +5441,7 @@ UniValue paymentsaddress(const UniValue& params, bool fHelp) UniValue gatewaysaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_GATEWAYS); if ( fHelp || params.size() > 1 ) throw runtime_error("gatewaysaddress [pubkey]\n"); @@ -5454,7 +5454,7 @@ UniValue gatewaysaddress(const UniValue& params, bool fHelp) UniValue heiraddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_HEIR); if ( fHelp || params.size() > 1 ) throw runtime_error("heiraddress [pubkey]\n"); @@ -5469,7 +5469,7 @@ UniValue heiraddress(const UniValue& params, bool fHelp) UniValue lottoaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_LOTTO); if ( fHelp || params.size() > 1 ) throw runtime_error("lottoaddress [pubkey]\n"); @@ -5482,7 +5482,7 @@ UniValue lottoaddress(const UniValue& params, bool fHelp) UniValue FSMaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_FSM); if ( fHelp || params.size() > 1 ) throw runtime_error("FSMaddress [pubkey]\n"); @@ -5495,7 +5495,7 @@ UniValue FSMaddress(const UniValue& params, bool fHelp) UniValue auctionaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_AUCTION); if ( fHelp || params.size() > 1 ) throw runtime_error("auctionaddress [pubkey]\n"); @@ -5508,7 +5508,7 @@ UniValue auctionaddress(const UniValue& params, bool fHelp) UniValue diceaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_DICE); if ( fHelp || params.size() > 1 ) throw runtime_error("diceaddress [pubkey]\n"); @@ -5521,7 +5521,7 @@ UniValue diceaddress(const UniValue& params, bool fHelp) UniValue faucetaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; int errno; cp = CCinit(&C,EVAL_FAUCET); if ( fHelp || params.size() > 1 ) @@ -5536,7 +5536,7 @@ UniValue faucetaddress(const UniValue& params, bool fHelp) UniValue rewardsaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_REWARDS); if ( fHelp || params.size() > 1 ) throw runtime_error("rewardsaddress [pubkey]\n"); @@ -5549,7 +5549,7 @@ UniValue rewardsaddress(const UniValue& params, bool fHelp) UniValue assetsaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp, C; std::vector pubkey; + struct CCcontract_info *cp, C; std::vector pubkey; cp = CCinit(&C, EVAL_ASSETS); if (fHelp || params.size() > 1) throw runtime_error("assetsaddress [pubkey]\n"); @@ -5562,7 +5562,7 @@ UniValue assetsaddress(const UniValue& params, bool fHelp) UniValue tokenaddress(const UniValue& params, bool fHelp) { - struct CC_info *cp,C; std::vector pubkey; + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_TOKENS); if ( fHelp || params.size() > 1 ) throw runtime_error("tokenaddress [pubkey]\n"); @@ -5767,7 +5767,7 @@ UniValue channelsinfo(const UniValue& params, bool fHelp) UniValue channelsopen(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); int32_t numpayments; int64_t payment; std::vector destpub; struct CC_info *cp,C; std::string hex; + UniValue result(UniValue::VOBJ); int32_t numpayments; int64_t payment; std::vector destpub; struct CCcontract_info *cp,C; std::string hex; uint256 tokenid=zeroid; cp = CCinit(&C,EVAL_CHANNELS); @@ -5810,7 +5810,7 @@ UniValue channelsopen(const UniValue& params, bool fHelp) UniValue channelspayment(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CC_info *cp,C; std::string hex; uint256 opentxid,secret=zeroid; int32_t n; int64_t amount; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid,secret=zeroid; int32_t n; int64_t amount; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() < 2 || params.size() >3 ) throw runtime_error("channelspayment opentxid amount [secret]\n"); @@ -5840,7 +5840,7 @@ UniValue channelspayment(const UniValue& params, bool fHelp) UniValue channelsclose(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CC_info *cp,C; std::string hex; uint256 opentxid; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() != 1 ) throw runtime_error("channelsclose opentxid\n"); @@ -5860,7 +5860,7 @@ UniValue channelsclose(const UniValue& params, bool fHelp) UniValue channelsrefund(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CC_info *cp,C; std::string hex; uint256 opentxid,closetxid; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid,closetxid; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() != 2 ) throw runtime_error("channelsrefund opentxid closetxid\n"); @@ -6914,7 +6914,7 @@ UniValue tokenorders(const UniValue& params, bool fHelp) UniValue tokenbalance(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint256 tokenid; uint64_t balance; std::vector pubkey; struct CC_info *cp,C; + UniValue result(UniValue::VOBJ); uint256 tokenid; uint64_t balance; std::vector pubkey; struct CCcontract_info *cp,C; CCerror.clear(); if ( fHelp || params.size() > 2 ) From 5f0b70615fa80550e6304988706e4be360e0e6d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:37:48 -1100 Subject: [PATCH 138/144] Jsonparams --- src/wallet/rpcwallet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 2db63d83a..5231dae27 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5353,15 +5353,15 @@ UniValue cclibinfo(const UniValue& params, bool fHelp) UniValue cclib(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; char *method; cJSON *params; + struct CCcontract_info *cp,C; char *method; cJSON *jsonparams; cp = CCinit(&C,EVAL_FIRSTUSER); if ( fHelp || params.size() > 2 ) throw runtime_error("cclib method [JSON params]\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); method = params[0].get_str().c_str(); - params = cJSON_Parse(params[1].get_str().c_str()); - return(CClib(cp,method,params)); + jsonparams = cJSON_Parse(params[1].get_str().c_str()); + return(CClib(cp,method,jsonparams)); } UniValue oraclesaddress(const UniValue& params, bool fHelp) From 01d2fa36a2997d57f30089bc4b46854b36cd023d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:38:48 -1100 Subject: [PATCH 139/144] UniValue CClib_info(struct CCcontract_info *cp) --- src/cc/CCinclude.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 82c9484d5..258d8b95b 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -135,6 +135,8 @@ int32_t komodo_nextheight(); int32_t CCgetspenttxid(uint256 &spenttxid,int32_t &vini,int32_t &height,uint256 txid,int32_t vout); void CCclearvars(struct CCcontract_info *cp); +UniValue CClib(struct CCcontract_info *cp,char *method,cJSON *params); +UniValue CClib_info(struct CCcontract_info *cp); static const uint256 zeroid; bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock); From b4e0b6bca4676407145b640f48101846ade1ee57 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:54:51 -1100 Subject: [PATCH 140/144] Faucet2 --- src/cc/cclib.cpp | 220 ++++++++++++++++++++++++++++++++++++++- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 219 insertions(+), 3 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 0f201acc4..23f3d81c9 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -27,6 +27,8 @@ #include "core_io.h" #include "crosschain.h" +#define FAUCET2SIZE COIN + struct CClib_rpcinfo { char *method,*help; @@ -35,6 +37,7 @@ struct CClib_rpcinfo } CClib_methods[] = { + { "faucet2_fund", "amount", 1, 1, 'F' }, { "faucet2_get", "", 0, 0, 'G' }, }; @@ -90,12 +93,225 @@ UniValue CClib(struct CCcontract_info *cp,char *method,cJSON *params) return(result); } +int64_t IsCClibvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +{ + char destaddr[64]; + if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) + { + if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,cp->unspendableCCaddr) == 0 ) + return(tx.vout[v].nValue); + } + return(0); +} + +bool CClibExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +{ + static uint256 zerohash; + CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; + numvins = tx.vin.size(); + numvouts = tx.vout.size(); + for (i=0; iismyvin)(tx.vin[i].scriptSig) != 0 ) + { + //fprintf(stderr,"vini.%d check mempool\n",i); + if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 ) + return eval->Invalid("cant find vinTx"); + else + { + //fprintf(stderr,"vini.%d check hash and vout\n",i); + if ( hashBlock == zerohash ) + return eval->Invalid("cant faucet2 from mempool"); + if ( (assetoshis= IsCClibvout(cp,vinTx,tx.vin[i].prevout.n)) != 0 ) + inputs += assetoshis; + } + } + } + for (i=0; iInvalid("mismatched inputs != outputs + FAUCET2SIZE + txfee"); + } + else return(true); +} + bool CClib_validate(struct CCcontract_info *cp,Eval *eval,const CTransaction &txTo,unsigned int nIn) { - return(true); // for now + int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; + std::vector > txids; + numvins = tx.vin.size(); + numvouts = tx.vout.size(); + preventCCvins = preventCCvouts = -1; + if ( numvouts < 1 ) + return eval->Invalid("no vouts"); + else + { + for (i=0; iInvalid("illegal normal vini"); + } + } + //fprintf(stderr,"check amounts\n"); + if ( CClibExactAmounts(cp,eval,tx,1,10000) == false ) + { + fprintf(stderr,"faucetget invalid amount\n"); + return false; + } + else + { + preventCCvouts = 1; + if ( IsFaucetvout(cp,tx,0) != 0 ) + { + preventCCvouts++; + i = 1; + } else i = 0; + txid = tx.GetHash(); + memcpy(hash,&txid,sizeof(hash)); + fprintf(stderr,"check faucetget txid %s %02x/%02x\n",uint256_str(str,txid),hash[0],hash[31]); + if ( tx.vout[i].nValue != FAUCET2SIZE ) + return eval->Invalid("invalid faucet output"); + else if ( (hash[0] & 0xff) != 0 || (hash[31] & 0xff) != 0 ) + return eval->Invalid("invalid faucetget txid"); + Getscriptaddress(destaddr,tx.vout[i].scriptPubKey); + SetCCtxids(txids,destaddr); + for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) + { + //int height = it->first.blockHeight; + if ( CCduration(numblocks,it->first.txhash) > 0 && numblocks > 3 ) + { + //fprintf(stderr,"would return error %s numblocks.%d ago\n",uint256_str(str,it->first.txhash),numblocks); + return eval->Invalid("faucet2 is only for brand new addresses"); + } + } + retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); + if ( retval != 0 ) + fprintf(stderr,"faucet2get validated\n"); + else fprintf(stderr,"faucet2get invalid\n"); + return(retval); + } + } +} + +int64_t AddCClibInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +{ + char coinaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; + std::vector > unspentOutputs; + GetCCaddress(cp,coinaddr,pk); + SetCCunspents(unspentOutputs,coinaddr); + threshold = total/(maxinputs+1); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + if ( it->second.satoshis < threshold ) + continue; + //char str[65]; fprintf(stderr,"check %s/v%d %.8f`\n",uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); + // no need to prevent dup + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + { + if ( (nValue= IsCClibvout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 ) + { + if ( total != 0 && maxinputs != 0 ) + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + nValue = it->second.satoshis; + totalinputs += nValue; + n++; + if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) + break; + } else fprintf(stderr,"nValue too small or already spent in mempool\n"); + } else fprintf(stderr,"couldnt get tx\n"); + } + return(totalinputs); +} + + +std::string Faucet2Fund(struct CCcontract_info *cp,uint64_t txfee,int64_t funds) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + CPubKey mypk,cclibpk; CScript opret; + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + cclibpk = GetUnspendable(cp,0); + if ( AddNormalinputs(mtx,mypk,funds+txfee,64) > 0 ) + { + mtx.vout.push_back(MakeCC1vout(cp->evalcode,funds,cclibpk)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); + } + return(""); +} + +UniValue FaucetInfo() +{ + UniValue result(UniValue::VOBJ); char numstr[64]; + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + CPubKey faucetpk; struct CCcontract_info *cp,C; int64_t funding; + result.push_back(Pair("result","success")); + result.push_back(Pair("name","Faucet")); + cp = CCinit(&C,EVAL_FAUCET); + faucetpk = GetUnspendable(cp,0); + funding = AddFaucetInputs(cp,mtx,faucetpk,0,0); + sprintf(numstr,"%.8f",(double)funding/COIN); + result.push_back(Pair("funding",numstr)); + return(result); } std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *params) { - return((char *)"deadbeef"); + CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + CPubKey mypk,cclibpk; int64_t funds,txfee=0,inputs,CCchange=0,nValue=FAUCET2SIZE; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; + if ( txfee == 0 ) + txfee = 10000; + if ( funcid == 'F' ) + { + if ( cJSON_GetArraySize(params) > 0 ) + { + funds = (int64_t)jdouble(jarrayi(params,0))*COIN + 0.0000000049; + return(Faucet2Fund(cp,0,funds)); + } else return(""); + } + else if ( funcid != 'G' ) + return(""); + cclibpk = GetUnspendable(cp,0); + mypk = pubkey2pk(Mypubkey()); + if ( (inputs= AddCClibInputs(cp,mtx,cclibpk,nValue+txfee,60)) > 0 ) + { + if ( inputs > nValue ) + CCchange = (inputs - nValue - txfee); + if ( CCchange != 0 ) + mtx.vout.push_back(MakeCC1vout(EVAL_FIRSTUSER,CCchange,cclibpk)); + mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + fprintf(stderr,"start at %u\n",(uint32_t)time(NULL)); + j = rand() & 0xfffffff; + for (i=0; i<1000000; i++,j++) + { + tmpmtx = mtx; + rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_FIRSTUSER << (uint8_t)'G' << j)); + if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) + { + len >>= 1; + decode_hex(buf,len,(char *)rawhex.c_str()); + hash = bits256_doublesha256(0,buf,len); + if ( (hash.bytes[0] & 0xff) == 0 && (hash.bytes[31] & 0xff) == 0 ) + { + fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); + return(rawhex); + } + //fprintf(stderr,"%02x%02x ",hash.bytes[0],hash.bytes[31]); + } + } + fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL)); + return(""); + } else fprintf(stderr,"cant find faucet inputs\n"); + return(""); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5231dae27..174f447f0 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5359,7 +5359,7 @@ UniValue cclib(const UniValue& params, bool fHelp) throw runtime_error("cclib method [JSON params]\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - method = params[0].get_str().c_str(); + method = (char *)params[0].get_str().c_str(); jsonparams = cJSON_Parse(params[1].get_str().c_str()); return(CClib(cp,method,jsonparams)); } From 1cf8cec01899d993380d9c9631db3b63102d43a4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Jan 2019 23:58:36 -1100 Subject: [PATCH 141/144] Item --- src/cc/CCutils.cpp | 2 +- src/cc/cclib.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 3670859cc..67ee7d5db 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -638,7 +638,7 @@ bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector param extern struct CCcontract_info CCinfos[0x100]; extern std::string MYCCLIBNAME; -bool CClib_validate(struct CCcontract_info *cp,Eval *eval,const CTransaction &txTo,unsigned int nIn); +bool CClib_validate(struct CCcontract_info *cp,Eval *eval,const CTransaction tx,unsigned int nIn); bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) { diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 23f3d81c9..d727dd8cd 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -37,13 +37,13 @@ struct CClib_rpcinfo } CClib_methods[] = { - { "faucet2_fund", "amount", 1, 1, 'F' }, - { "faucet2_get", "", 0, 0, 'G' }, + { (char *)"faucet2_fund", (char *)"amount", 1, 1, 'F' }, + { (char *)"faucet2_get", (char *)"", 0, 0, 'G' }, }; -std::string MYCCLIBNAME = (char *)"stub"; +std::string MYCCLIBNAME = (char *)"faucet2"; -char *CClib_name() { return(MYCCLIBNAME); } +char *CClib_name() { return(MYCCLIBNAME.c_str()); } std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *params); @@ -67,7 +67,7 @@ UniValue CClib_info(struct CCcontract_info *cp) obj.push_back(Pair("help",CClib_methods[i].help)); obj.push_back(Pair("params_required",CClib_methods[i].numrequiredargs)); obj.push_back(Pair("params_max",CClib_methods[i].maxargs)); - a.push_back(obj)); + a.push_back(obj); } result.push_back(Pair("methods",a)); return(result); @@ -134,7 +134,7 @@ bool CClibExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction if ( (assetoshis= IsCClibvout(cp,tx,i)) != 0 ) outputs += assetoshis; } - if ( inputs != outputs+FAUCETSIZE+txfee ) + if ( inputs != outputs+FAUCET2SIZE+txfee ) { fprintf(stderr,"inputs %llu vs outputs %llu\n",(long long)inputs,(long long)outputs); return eval->Invalid("mismatched inputs != outputs + FAUCET2SIZE + txfee"); @@ -142,7 +142,7 @@ bool CClibExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction else return(true); } -bool CClib_validate(struct CCcontract_info *cp,Eval *eval,const CTransaction &txTo,unsigned int nIn) +bool CClib_validate(struct CCcontract_info *cp,Eval *eval,const CTransaction tx,unsigned int nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; std::vector > txids; @@ -276,7 +276,7 @@ std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *para { if ( cJSON_GetArraySize(params) > 0 ) { - funds = (int64_t)jdouble(jarrayi(params,0))*COIN + 0.0000000049; + funds = (int64_t)jdouble(jitem(params,0))*COIN + 0.0000000049; return(Faucet2Fund(cp,0,funds)); } else return(""); } From 887f6cb2ab2ab3b3f9d76bb47136241c9b906908 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 20 Jan 2019 00:00:51 -1100 Subject: [PATCH 142/144] Test --- src/cc/CCinclude.h | 1 + src/cc/cclib.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 258d8b95b..451b87dd9 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -50,6 +50,7 @@ one other technical note is that komodod has the insight-explorer extensions bui #include "../komodo_defs.h" #include "../utlist.h" #include "../uthash.h" +#include "../cJSON.h" extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE; extern uint32_t ASSETCHAINS_CC; diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index d727dd8cd..7202dd7c6 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -43,7 +43,7 @@ CClib_methods[] = std::string MYCCLIBNAME = (char *)"faucet2"; -char *CClib_name() { return(MYCCLIBNAME.c_str()); } +char *CClib_name() { return((char *)MYCCLIBNAME.c_str()); } std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *params); @@ -170,7 +170,7 @@ bool CClib_validate(struct CCcontract_info *cp,Eval *eval,const CTransaction tx, else { preventCCvouts = 1; - if ( IsFaucetvout(cp,tx,0) != 0 ) + if ( IsCClibvout(cp,tx,0) != 0 ) { preventCCvouts++; i = 1; @@ -251,7 +251,7 @@ std::string Faucet2Fund(struct CCcontract_info *cp,uint64_t txfee,int64_t funds) return(""); } -UniValue FaucetInfo() +/*UniValue FaucetInfo() { UniValue result(UniValue::VOBJ); char numstr[64]; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); @@ -264,12 +264,12 @@ UniValue FaucetInfo() sprintf(numstr,"%.8f",(double)funding/COIN); result.push_back(Pair("funding",numstr)); return(result); -} +}*/ std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *params) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,cclibpk; int64_t funds,txfee=0,inputs,CCchange=0,nValue=FAUCET2SIZE; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; + CPubKey mypk,cclibpk; int64_t funds,txfee=0,inputs,CCchange=0,nValue=FAUCET2SIZE; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; if ( txfee == 0 ) txfee = 10000; if ( funcid == 'F' ) From 0ceca4c74546eea83ee528dec75542f8b7f1afc2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 20 Jan 2019 00:01:18 -1100 Subject: [PATCH 143/144] komodo_cJSON.h --- src/cc/CCinclude.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 451b87dd9..4cb658681 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -50,7 +50,7 @@ one other technical note is that komodod has the insight-explorer extensions bui #include "../komodo_defs.h" #include "../utlist.h" #include "../uthash.h" -#include "../cJSON.h" +#include "../komodo_cJSON.h" extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE; extern uint32_t ASSETCHAINS_CC; From 53b2d35da7d084ee3c28a8aa144183bd91a6f2af Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 20 Jan 2019 00:03:36 -1100 Subject: [PATCH 144/144] Bit256 --- src/cc/CCinclude.h | 2 +- src/cc/cclib.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 4cb658681..1953fad34 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -50,7 +50,6 @@ one other technical note is that komodod has the insight-explorer extensions bui #include "../komodo_defs.h" #include "../utlist.h" #include "../uthash.h" -#include "../komodo_cJSON.h" extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE; extern uint32_t ASSETCHAINS_CC; @@ -70,6 +69,7 @@ extern uint8_t ASSETCHAINS_CCDISABLES[256]; typedef union _bits256 bits256; #endif +#include "../komodo_cJSON.h" struct CC_utxo { diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 7202dd7c6..5a9c3b4af 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -276,7 +276,7 @@ std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *para { if ( cJSON_GetArraySize(params) > 0 ) { - funds = (int64_t)jdouble(jitem(params,0))*COIN + 0.0000000049; + funds = (int64_t)jdouble(jitem(params,0),0)*COIN + 0.0000000049; return(Faucet2Fund(cp,0,funds)); } else return(""); }