Browse Source

Merge pull request #1146 from jl777/jl777

Jl777
pull/4/head
jl777 6 years ago
committed by GitHub
parent
commit
3e5cfdc24b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/Makefile.am
  2. 4
      src/cc/CCMarmara.h
  3. 30
      src/cc/CCcustom.cpp
  4. 2
      src/cc/eval.h
  5. 66
      src/cc/marmara.cpp
  6. 4
      src/importcoin.cpp
  7. 15
      src/rpc/blockchain.cpp
  8. 9
      src/rpc/rawtransaction.cpp
  9. 4
      src/rpc/server.cpp
  10. 2
      src/rpc/server.h
  11. 103
      src/wallet/rpcwallet.cpp

2
src/Makefile.am

@ -300,7 +300,7 @@ libbitcoin_server_a_SOURCES = \
cc/oracles.cpp \
cc/prices.cpp \
cc/pegs.cpp \
cc/triggers.cpp \
cc/marmara.cpp \
cc/payments.cpp \
cc/gateways.cpp \
cc/channels.cpp \

4
src/cc/CCTriggers.h → src/cc/CCMarmara.h

@ -19,9 +19,9 @@
#include "CCinclude.h"
bool TriggersValidate(struct CCcontract_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 TriggersInfo();
UniValue MarmaraInfo();
#endif

30
src/cc/CCcustom.cpp

@ -27,7 +27,7 @@
#include "CCOracles.h"
#include "CCPrices.h"
#include "CCPegs.h"
#include "CCTriggers.h"
#include "CCMarmara.h"
#include "CCPayments.h"
#include "CCGateways.h"
@ -189,13 +189,13 @@ uint8_t PegsCCpriv[32] = { 0x52, 0x56, 0x4c, 0x78, 0x87, 0xf7, 0xa2, 0x39, 0xb0,
#undef FUNCNAME
#undef EVALCODE
// Triggers
#define FUNCNAME IsTriggersInput
#define EVALCODE EVAL_TRIGGERS
const char *TriggersCCaddr = "RGLSRDnUqTB43bYtRtNVgmwSSd1sun2te8";
const char *TriggersNormaladdr = "RMN25Tn8NNzcyQDiQNuMp8UmwLMFd9thYc";
char TriggersCChexstr[67] = { "03afc5be570d0ff419425cfcc580cc762ab82baad88c148f5b028d7db7bfeee61d" };
uint8_t TriggersCCpriv[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 };
// Marmara
#define FUNCNAME IsMarmaraInput
#define EVALCODE EVAL_MARMARA
const char *MarmaraCCaddr = "RGLSRDnUqTB43bYtRtNVgmwSSd1sun2te8";
const char *MarmaraNormaladdr = "RMN25Tn8NNzcyQDiQNuMp8UmwLMFd9thYc";
char MarmaraCChexstr[67] = { "03afc5be570d0ff419425cfcc580cc762ab82baad88c148f5b028d7db7bfeee61d" };
uint8_t MarmaraCCpriv[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
@ -323,13 +323,13 @@ struct CCcontract_info *CCinit(struct CCcontract_info *cp, uint8_t evalcode)
cp->validate = PegsValidate;
cp->ismyvin = IsPegsInput;
break;
case EVAL_TRIGGERS:
strcpy(cp->unspendableCCaddr,TriggersCCaddr);
strcpy(cp->normaladdr,TriggersNormaladdr);
strcpy(cp->CChexstr,TriggersCChexstr);
memcpy(cp->CCpriv,TriggersCCpriv,32);
cp->validate = TriggersValidate;
cp->ismyvin = IsTriggersInput;
case EVAL_MARMARA:
strcpy(cp->unspendableCCaddr,MarmaraCCaddr);
strcpy(cp->normaladdr,MarmaraNormaladdr);
strcpy(cp->CChexstr,MarmaraCChexstr);
memcpy(cp->CCpriv,MarmaraCCpriv,32);
cp->validate = MarmaraValidate;
cp->ismyvin = IsMarmaraInput;
break;
case EVAL_PAYMENTS:
strcpy(cp->unspendableCCaddr,PaymentsCCaddr);

2
src/cc/eval.h

@ -53,7 +53,7 @@
EVAL(EVAL_ORACLES, 0xec) \
EVAL(EVAL_PRICES, 0xed) \
EVAL(EVAL_PEGS, 0xee) \
EVAL(EVAL_TRIGGERS, 0xef) \
EVAL(EVAL_MARMARA, 0xef) \
EVAL(EVAL_PAYMENTS, 0xf0) \
EVAL(EVAL_GATEWAYS, 0xf1)

66
src/cc/triggers.cpp → src/cc/marmara.cpp

@ -13,16 +13,16 @@
* *
******************************************************************************/
#include "CCTriggers.h"
#include "CCMarmara.h"
/*
Triggers CC is a building block CC that allows creation of event -> action processing, where events are defined during trigger creation and actions to be mostly done via payments, but by making payments to other CC contracts, it can be used to invoke other CC contracts
Marmara CC is for the MARMARA project
*/
// start of consensus code
int64_t IsTriggersvout(struct CCcontract_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 )
@ -33,7 +33,7 @@ int64_t IsTriggersvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t
return(0);
}
bool TriggersExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee)
bool MarmaraExactAmounts(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;
@ -51,8 +51,8 @@ bool TriggersExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransacti
{
//fprintf(stderr,"vini.%d check hash and vout\n",i);
if ( hashBlock == zerohash )
return eval->Invalid("cant Triggers from mempool");
if ( (assetoshis= IsTriggersvout(cp,vinTx,tx.vin[i].prevout.n)) != 0 )
return eval->Invalid("cant Marmara from mempool");
if ( (assetoshis= IsMarmaravout(cp,vinTx,tx.vin[i].prevout.n)) != 0 )
inputs += assetoshis;
}
}
@ -60,7 +60,7 @@ bool TriggersExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransacti
for (i=0; i<numvouts; i++)
{
//fprintf(stderr,"i.%d of numvouts.%d\n",i,numvouts);
if ( (assetoshis= IsTriggersvout(cp,tx,i)) != 0 )
if ( (assetoshis= IsMarmaravout(cp,tx,i)) != 0 )
outputs += assetoshis;
}
if ( inputs != outputs+txfee )
@ -71,7 +71,7 @@ bool TriggersExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransacti
else return(true);
}
bool TriggersValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn)
bool MarmaraValidate(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(false);
@ -91,9 +91,9 @@ bool TriggersValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &
}
}
//fprintf(stderr,"check amounts\n");
if ( TriggersExactAmounts(cp,eval,tx,1,10000) == false )
if ( MarmaraExactAmounts(cp,eval,tx,1,10000) == false )
{
fprintf(stderr,"Triggersget invalid amount\n");
fprintf(stderr,"Marmaraget invalid amount\n");
return false;
}
else
@ -102,8 +102,8 @@ bool TriggersValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &
memcpy(hash,&txid,sizeof(hash));
retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts);
if ( retval != 0 )
fprintf(stderr,"Triggersget validated\n");
else fprintf(stderr,"Triggersget invalid\n");
fprintf(stderr,"Marmaraget validated\n");
else fprintf(stderr,"Marmaraget invalid\n");
return(retval);
}
}
@ -112,7 +112,7 @@ bool TriggersValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &
// helper functions for rpc calls in rpcwallet.cpp
int64_t AddTriggersInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs)
int64_t AddMarmaraInputs(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<uint8_t> origpubkey; CTransaction vintx; int32_t vout,n = 0;
@ -126,7 +126,7 @@ int64_t AddTriggersInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP
// no need to prevent dup
if ( GetTransaction(txid,vintx,hashBlock,false) != 0 )
{
if ( (nValue= IsTriggersvout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 )
if ( (nValue= IsMarmaravout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 )
{
if ( total != 0 && maxinputs != 0 )
mtx.vin.push_back(CTxIn(txid,vout,CScript()));
@ -141,28 +141,28 @@ int64_t AddTriggersInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP
return(totalinputs);
}
std::string TriggersGet(uint64_t txfee,int64_t nValue)
std::string MarmaraGet(uint64_t txfee,int64_t nValue)
{
CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
CPubKey mypk,Triggerspk; 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_TRIGGERS);
CPubKey mypk,Marmarapk; 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_MARMARA);
if ( txfee == 0 )
txfee = 10000;
Triggerspk = GetUnspendable(cp,0);
Marmarapk = GetUnspendable(cp,0);
mypk = pubkey2pk(Mypubkey());
if ( (inputs= AddTriggersInputs(cp,mtx,Triggerspk,nValue+txfee,60)) > 0 )
if ( (inputs= AddMarmaraInputs(cp,mtx,Marmarapk,nValue+txfee,60)) > 0 )
{
if ( inputs > nValue )
CCchange = (inputs - nValue - txfee);
if ( CCchange != 0 )
mtx.vout.push_back(MakeCC1vout(EVAL_TRIGGERS,CCchange,Triggerspk));
mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,CCchange,Marmarapk));
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_TRIGGERS << (uint8_t)'G' << j));
rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_MARMARA << (uint8_t)'G' << j));
if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 )
{
len >>= 1;
@ -178,37 +178,37 @@ std::string TriggersGet(uint64_t txfee,int64_t nValue)
}
fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL));
return("");
} else fprintf(stderr,"cant find Triggers inputs\n");
} else fprintf(stderr,"cant find Marmara inputs\n");
return("");
}
std::string TriggersFund(uint64_t txfee,int64_t funds)
std::string MarmaraFund(uint64_t txfee,int64_t funds)
{
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
CPubKey mypk,Triggerspk; CScript opret; struct CCcontract_info *cp,C;
cp = CCinit(&C,EVAL_TRIGGERS);
CPubKey mypk,Marmarapk; CScript opret; struct CCcontract_info *cp,C;
cp = CCinit(&C,EVAL_MARMARA);
if ( txfee == 0 )
txfee = 10000;
mypk = pubkey2pk(Mypubkey());
Triggerspk = GetUnspendable(cp,0);
Marmarapk = GetUnspendable(cp,0);
if ( AddNormalinputs(mtx,mypk,funds+txfee,64) > 0 )
{
mtx.vout.push_back(MakeCC1vout(EVAL_TRIGGERS,funds,Triggerspk));
mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,funds,Marmarapk));
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret));
}
return("");
}
UniValue TriggersInfo()
UniValue MarmaraInfo()
{
UniValue result(UniValue::VOBJ); char numstr[64];
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
CPubKey Triggerspk; struct CCcontract_info *cp,C; int64_t funding;
CPubKey Marmarapk; struct CCcontract_info *cp,C; int64_t funding;
result.push_back(Pair("result","success"));
result.push_back(Pair("name","Triggers"));
cp = CCinit(&C,EVAL_TRIGGERS);
Triggerspk = GetUnspendable(cp,0);
funding = AddTriggersInputs(cp,mtx,Triggerspk,0,0);
result.push_back(Pair("name","Marmara"));
cp = CCinit(&C,EVAL_MARMARA);
Marmarapk = GetUnspendable(cp,0);
funding = AddMarmaraInputs(cp,mtx,Marmarapk,0,0);
sprintf(numstr,"%.8f",(double)funding/COIN);
result.push_back(Pair("funding",numstr));
return(result);

4
src/importcoin.cpp

@ -68,13 +68,13 @@ bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint
if (burnTx.vout.size() == 0) return false;
GetOpReturnData(burnTx.vout.back().scriptPubKey, burnOpret);
E_UNMARSHAL(burnOpret, ss >> VARINT(ccid));
if ( ccid != 0xffffffff )
/*if ( ccid != 0xffffffff )
{
return E_UNMARSHAL(burnOpret, ss >> VARINT(*targetCCid);
ss >> targetSymbol;
ss >> payoutsHash);
}
else
else*/
{
return E_UNMARSHAL(burnOpret, ss >> VARINT(*targetCCid);
ss >> targetSymbol;

15
src/rpc/blockchain.cpp

@ -695,7 +695,8 @@ UniValue getblockheader(const UniValue& params, bool fHelp)
"\nResult (for verbose = true):\n"
"{\n"
" \"hash\" : \"hash\", (string) the block hash (same as provided)\n"
" \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n"
" \"confirmations\" : n, (numeric) The number of notarized DPoW confirmations, or -1 if the block is not on the main chain\n"
" \"rawconfirmations\" : n,(numeric) The number of raw confirmations, or -1 if the block is not on the main chain\n"
" \"height\" : n, (numeric) The block height or index\n"
" \"version\" : n, (numeric) The block version\n"
" \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
@ -755,7 +756,8 @@ UniValue getblock(const UniValue& params, bool fHelp)
"\nResult (for verbosity = 1):\n"
"{\n"
" \"hash\" : \"hash\", (string) the block hash (same as provided hash)\n"
" \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n"
" \"confirmations\" : n, (numeric) The number of notarized DPoW confirmations, or -1 if the block is not on the main chain\n"
" \"rawconfirmations\" : n,(numeric) The number of raw confirmations, or -1 if the block is not on the main chain\n"
" \"size\" : n, (numeric) The block size\n"
" \"height\" : n, (numeric) The block height or index (same as provided height)\n"
" \"version\" : n, (numeric) The block version\n"
@ -1198,7 +1200,8 @@ UniValue gettxout(const UniValue& params, bool fHelp)
"\nResult:\n"
"{\n"
" \"bestblock\" : \"hash\", (string) the block hash\n"
" \"confirmations\" : n, (numeric) The number of confirmations\n"
" \"confirmations\" : n, (numeric) The number of notarized DPoW confirmations\n"
" \"rawconfirmations\" : n, (numeric) The number of raw confirmations\n"
" \"value\" : x.xxx, (numeric) The transaction value in " + CURRENCY_UNIT + "\n"
" \"scriptPubKey\" : { (json object)\n"
" \"asm\" : \"code\", (string) \n"
@ -1251,10 +1254,10 @@ UniValue gettxout(const UniValue& params, bool fHelp)
BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
CBlockIndex *pindex = it->second;
ret.push_back(Pair("bestblock", pindex->GetBlockHash().GetHex()));
if ((unsigned int)coins.nHeight == MEMPOOL_HEIGHT)
if ((unsigned int)coins.nHeight == MEMPOOL_HEIGHT) {
ret.push_back(Pair("confirmations", 0));
else
{
ret.push_back(Pair("rawconfirmations", 0));
} else {
ret.push_back(Pair("confirmations", komodo_dpowconfs(coins.nHeight,pindex->GetHeight() - coins.nHeight + 1)));
ret.push_back(Pair("rawconfirmations", pindex->GetHeight() - coins.nHeight + 1));
}

9
src/rpc/rawtransaction.cpp

@ -297,6 +297,7 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue&
} else {
entry.push_back(Pair("height", -1));
entry.push_back(Pair("confirmations", 0));
entry.push_back(Pair("rawconfirmations", 0));
}
}
@ -379,9 +380,10 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
entry.push_back(Pair("confirmations", komodo_dpowconfs(pindex->GetHeight(),1 + chainActive.Height() - pindex->GetHeight())));
entry.push_back(Pair("time", pindex->GetBlockTime()));
entry.push_back(Pair("blocktime", pindex->GetBlockTime()));
}
else
} else {
entry.push_back(Pair("confirmations", 0));
entry.push_back(Pair("rawconfirmations", 0));
}
}
}
}
@ -469,7 +471,8 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp)
" ,...\n"
" ],\n"
" \"blockhash\" : \"hash\", (string) the block hash\n"
" \"confirmations\" : n, (numeric) The confirmations\n"
" \"confirmations\" : n, (numeric) The number of notarized DPoW confirmations\n"
" \"rawconfirmations\" : n, (numeric) The number of raw confirmations\n"
" \"time\" : ttt, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT)\n"
" \"blocktime\" : ttt (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
"}\n"

4
src/rpc/server.cpp

@ -441,8 +441,8 @@ static const CRPCCommand vRPCCommands[] =
// Pegs
{ "pegs", "pegsaddress", &pegsaddress, true },
// Triggers
{ "triggers", "triggersaddress", &triggersaddress, true },
// Marmara
{ "marmara", "Marmaraaddress", &marmaraaddress, true },
// Payments
{ "payments", "paymentsaddress", &paymentsaddress, true },

2
src/rpc/server.h

@ -271,7 +271,7 @@ extern UniValue pricesbet(const UniValue& params, bool fHelp);
extern UniValue pricesstatus(const UniValue& params, bool fHelp);
extern UniValue pricesfinish(const UniValue& params, bool fHelp);
extern UniValue pegsaddress(const UniValue& params, bool fHelp);
extern UniValue triggersaddress(const UniValue& params, bool fHelp);
extern UniValue marmaraaddress(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);

103
src/wallet/rpcwallet.cpp

@ -1435,11 +1435,13 @@ struct tallyitem
int nConf;
vector<uint256> txids;
bool fIsWatchonly;
int nHeight;
tallyitem()
{
nAmount = 0;
nConf = std::numeric_limits<int>::max();
fIsWatchonly = false;
nHeight = 0;
}
};
@ -1485,6 +1487,7 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
tallyitem& item = mapTally[address];
item.nAmount += txout.nValue; // komodo_interest?
item.nConf = min(item.nConf, nDepth);
item.nHeight = mapBlockIndex[wtx.hashBlock]->GetHeight();
item.txids.push_back(wtx.GetHash());
if (mine & ISMINE_WATCH_ONLY)
item.fIsWatchonly = true;
@ -1504,11 +1507,13 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
CAmount nAmount = 0;
int nConf = std::numeric_limits<int>::max();
bool fIsWatchonly = false;
int nHeight=0;
if (it != mapTally.end())
{
nAmount = (*it).second.nAmount;
nConf = (*it).second.nConf;
fIsWatchonly = (*it).second.fIsWatchonly;
nHeight = (*it).second.nHeight;
}
if (fByAccounts)
@ -1521,12 +1526,14 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
else
{
UniValue obj(UniValue::VOBJ);
if(fIsWatchonly)
obj.push_back(Pair("involvesWatchonly", true));
obj.push_back(Pair("address", EncodeDestination(dest)));
obj.push_back(Pair("account", strAccount));
obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
obj.push_back(Pair("rawconfirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : komodo_dpowconfs(nHeight, nConf))));
UniValue transactions(UniValue::VARR);
if (it != mapTally.end())
{
@ -1546,12 +1553,14 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
{
CAmount nAmount = (*it).second.nAmount;
int nConf = (*it).second.nConf;
int nHeight = (*it).second.nHeight;
UniValue obj(UniValue::VOBJ);
if((*it).second.fIsWatchonly)
obj.push_back(Pair("involvesWatchonly", true));
obj.push_back(Pair("account", (*it).first));
obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
obj.push_back(Pair("rawconfirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : komodo_dpowconfs(nHeight, nConf))));
ret.push_back(obj);
}
}
@ -2954,10 +2963,29 @@ UniValue z_listunspent(const UniValue& params, bool fHelp)
for (auto & entry : sproutEntries) {
UniValue obj(UniValue::VOBJ);
int nHeight = 0;
CTransaction tx;
uint256 hashBlock;
obj.push_back(Pair("txid", entry.jsop.hash.ToString()));
obj.push_back(Pair("jsindex", (int)entry.jsop.js ));
obj.push_back(Pair("jsoutindex", (int)entry.jsop.n));
obj.push_back(Pair("confirmations", entry.confirmations));
if (!GetTransaction(entry.jsop.hash, tx, hashBlock, true)) {
// TODO: should we throw JSONRPCError ?
fprintf(stderr,"tx hash %s does not exist!\n", entry.jsop.hash.ToString().c_str() );
}
BlockMap::const_iterator it = mapBlockIndex.find(hashBlock);
if (it != mapBlockIndex.end()) {
nHeight = it->second->GetHeight();
fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight);
} else {
// TODO: should we throw JSONRPCError ?
fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() );
}
obj.push_back(Pair("confirmations", komodo_dpowconfs(nHeight, entry.confirmations)));
obj.push_back(Pair("rawconfirmations", entry.confirmations));
bool hasSproutSpendingKey = pwalletMain->HaveSproutSpendingKey(boost::get<libzcash::SproutPaymentAddress>(entry.address));
obj.push_back(Pair("spendable", hasSproutSpendingKey));
obj.push_back(Pair("address", EncodePaymentAddress(entry.address)));
@ -2974,7 +3002,24 @@ UniValue z_listunspent(const UniValue& params, bool fHelp)
UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("txid", entry.op.hash.ToString()));
obj.push_back(Pair("outindex", (int)entry.op.n));
obj.push_back(Pair("confirmations", entry.confirmations));
int nHeight = 0;
CTransaction tx;
uint256 hashBlock;
if (!GetTransaction(entry.op.hash, tx, hashBlock, true)) {
// TODO: should we throw JSONRPCError ?
fprintf(stderr,"tx hash %s does not exist!\n", entry.op.hash.ToString().c_str() );
}
BlockMap::const_iterator it = mapBlockIndex.find(hashBlock);
if (it != mapBlockIndex.end()) {
nHeight = it->second->GetHeight();
fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight);
} else {
// TODO: should we throw JSONRPCError ?
fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() );
}
obj.push_back(Pair("confirmations", komodo_dpowconfs(nHeight, entry.confirmations)));
obj.push_back(Pair("rawconfirmations", entry.confirmations));
libzcash::SaplingIncomingViewingKey ivk;
libzcash::SaplingFullViewingKey fvk;
pwalletMain->GetSaplingIncomingViewingKey(boost::get<libzcash::SaplingPaymentAddress>(entry.address), ivk);
@ -3702,7 +3747,11 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
"{\n"
" \"txid\": xxxxx, (string) the transaction id\n"
" \"amount\": xxxxx, (numeric) the amount of value in the note\n"
" \"memo\": xxxxx, (string) hexademical string representation of memo field\n"
" \"memo\": xxxxx, (string) hexadecimal string representation of memo field\n"
" \"confirmations\" : n, (numeric) the number of confirmations\n"
" \"jsindex\" (sprout) : n, (numeric) the joinsplit index\n"
" \"jsoutindex\" (sprout) : n, (numeric) the output index of the joinsplit\n"
" \"outindex\" (sapling) : n, (numeric) the output index\n"
" \"change\": true|false, (boolean) true if the address that received the note is also one of the sending addresses\n"
"}\n"
"\nExamples:\n"
@ -3747,12 +3796,30 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
if (boost::get<libzcash::SproutPaymentAddress>(&zaddr) != nullptr) {
for (CSproutNotePlaintextEntry & entry : sproutEntries) {
UniValue obj(UniValue::VOBJ);
int nHeight = 0;
CTransaction tx;
uint256 hashBlock;
if (GetTransaction(entry.jsop.hash, tx, hashBlock, true)) {
BlockMap::const_iterator it = mapBlockIndex.find(hashBlock);
if (it != mapBlockIndex.end()) {
nHeight = it->second->GetHeight();
fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight);
} else {
fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() );
}
} else {
fprintf(stderr,"tx hash %s does not exist!\n", entry.jsop.hash.ToString().c_str() );
}
obj.push_back(Pair("txid", entry.jsop.hash.ToString()));
obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.plaintext.value()))));
std::string data(entry.plaintext.memo().begin(), entry.plaintext.memo().end());
obj.push_back(Pair("memo", HexStr(data)));
obj.push_back(Pair("jsindex", entry.jsop.js));
obj.push_back(Pair("jsoutindex", entry.jsop.n));
obj.push_back(Pair("rawconfirmations", entry.confirmations));
obj.push_back(Pair("confirmations", komodo_dpowconfs(nHeight, entry.confirmations)));
if (hasSpendingKey) {
obj.push_back(Pair("change", pwalletMain->IsNoteSproutChange(nullifierSet, entry.address, entry.jsop)));
}
@ -3761,10 +3828,27 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
} else if (boost::get<libzcash::SaplingPaymentAddress>(&zaddr) != nullptr) {
for (SaplingNoteEntry & entry : saplingEntries) {
UniValue obj(UniValue::VOBJ);
int nHeight = 0;
CTransaction tx;
uint256 hashBlock;
if (GetTransaction(entry.op.hash, tx, hashBlock, true)) {
BlockMap::const_iterator it = mapBlockIndex.find(hashBlock);
if (it != mapBlockIndex.end()) {
nHeight = it->second->GetHeight();
fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight);
} else {
fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() );
}
} else {
fprintf(stderr,"tx hash %s does not exist!\n", entry.op.hash.ToString().c_str() );
}
obj.push_back(Pair("txid", entry.op.hash.ToString()));
obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.note.value()))));
obj.push_back(Pair("memo", HexStr(entry.memo)));
obj.push_back(Pair("outindex", (int)entry.op.n));
obj.push_back(Pair("rawconfirmations", entry.confirmations));
obj.push_back(Pair("confirmations", komodo_dpowconfs(nHeight, entry.confirmations)));
if (hasSpendingKey) {
obj.push_back(Pair("change", pwalletMain->IsNoteSaplingChange(nullifierSet, entry.address, entry.op)));
}
@ -5111,6 +5195,7 @@ int32_t ensure_CCrequirements()
#include "../cc/CCGateways.h"
#include "../cc/CCPrices.h"
#include "../cc/CCHeir.h"
#include "../cc/CCMarmara.h"
UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vector<unsigned char> &pubkey)
{
@ -5291,17 +5376,17 @@ UniValue pegsaddress(const UniValue& params, bool fHelp)
return(CCaddress(cp,(char *)"Pegs",pubkey));
}
UniValue triggersaddress(const UniValue& params, bool fHelp)
UniValue marmaraaddress(const UniValue& params, bool fHelp)
{
struct CCcontract_info *cp,C; std::vector<unsigned char> pubkey;
cp = CCinit(&C,EVAL_TRIGGERS);
cp = CCinit(&C,EVAL_MARMARA);
if ( fHelp || params.size() > 1 )
throw runtime_error("triggersaddress [pubkey]\n");
throw runtime_error("Marmaraaddress [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 *)"Triggers",pubkey));
return(CCaddress(cp,(char *)"Marmara",pubkey));
}
UniValue paymentsaddress(const UniValue& params, bool fHelp)

Loading…
Cancel
Save