Merge pull request #1391 from jl777/FSM

sync with FSM
This commit is contained in:
jl777
2019-04-10 19:48:01 -11:00
committed by GitHub
104 changed files with 14597 additions and 4177 deletions

View File

@@ -5151,7 +5151,9 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
boost::optional<TransactionBuilder> builder;
if (isToSaplingZaddr || saplingNoteInputs.size() > 0) {
builder = TransactionBuilder(Params().GetConsensus(), nextBlockHeight, pwalletMain);
}
} else
contextualTx.nExpiryHeight = 0; // set non z-tx to have no expiry height.
// Create operation and add to global queue
std::shared_ptr<AsyncRPCQueue> q = getAsyncRPCQueue();
std::shared_ptr<AsyncRPCOperation> operation(
@@ -5323,6 +5325,7 @@ int32_t verus_staked(CBlock *pBlock, CMutableTransaction &txNew, uint32_t &nBits
#include "../cc/CCPrices.h"
#include "../cc/CCHeir.h"
#include "../cc/CCMarmara.h"
#include "../cc/CCPayments.h"
int32_t ensure_CCrequirements(uint8_t evalcode)
{
@@ -5573,6 +5576,84 @@ UniValue cclib(const UniValue& params, bool fHelp)
return(CClib(cp,method,jsonstr));
}
UniValue payments_release(const UniValue& params, bool fHelp)
{
struct CCcontract_info *cp,C;
if ( fHelp || params.size() != 1 )
throw runtime_error("paymentsrelease \"[%22createtxid%22,amount]\"\n");
if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
cp = CCinit(&C,EVAL_PAYMENTS);
return(PaymentsRelease(cp,(char *)params[0].get_str().c_str()));
}
UniValue payments_fund(const UniValue& params, bool fHelp)
{
struct CCcontract_info *cp,C;
if ( fHelp || params.size() != 1 )
throw runtime_error("paymentsfund \"[%22createtxid%22,amount(,useopret)]\"\n");
if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
cp = CCinit(&C,EVAL_PAYMENTS);
return(PaymentsFund(cp,(char *)params[0].get_str().c_str()));
}
UniValue payments_txidopret(const UniValue& params, bool fHelp)
{
struct CCcontract_info *cp,C;
if ( fHelp || params.size() != 1 )
throw runtime_error("paymentstxidopret \"[allocation,%22scriptPubKey%22(,%22destopret%22)]\"\n");
if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
cp = CCinit(&C,EVAL_PAYMENTS);
return(PaymentsTxidopret(cp,(char *)params[0].get_str().c_str()));
}
UniValue payments_create(const UniValue& params, bool fHelp)
{
struct CCcontract_info *cp,C;
if ( fHelp || params.size() != 1 )
throw runtime_error("paymentscreate \"[lockedblocks,minamount,%22paytxid0%22,...,%22paytxidN%22]\"\n");
if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
cp = CCinit(&C,EVAL_PAYMENTS);
return(PaymentsCreate(cp,(char *)params[0].get_str().c_str()));
}
UniValue payments_info(const UniValue& params, bool fHelp)
{
struct CCcontract_info *cp,C;
if ( fHelp || params.size() != 1 )
throw runtime_error("paymentsinfo \"[%22createtxid%22]\"\n");
if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
cp = CCinit(&C,EVAL_PAYMENTS);
return(PaymentsInfo(cp,(char *)params[0].get_str().c_str()));
}
UniValue payments_list(const UniValue& params, bool fHelp)
{
struct CCcontract_info *cp,C;
if ( fHelp || params.size() != 0 )
throw runtime_error("paymentslist\n");
if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
cp = CCinit(&C,EVAL_PAYMENTS);
return(PaymentsList(cp,(char *)""));
}
UniValue oraclesaddress(const UniValue& params, bool fHelp)
{
struct CCcontract_info *cp,C; std::vector<unsigned char> pubkey;
@@ -5779,6 +5860,19 @@ UniValue tokenaddress(const UniValue& params, bool fHelp)
return(CCaddress(cp,(char *)"Tokens", pubkey));
}
UniValue importgatewayaddress(const UniValue& params, bool fHelp)
{
struct CCcontract_info *cp,C; std::vector<unsigned char> pubkey;
cp = CCinit(&C,EVAL_IMPORTGATEWAY);
if ( fHelp || params.size() > 1 )
throw runtime_error("importgatewayddress [pubkey]\n");
if ( ensure_CCrequirements(0) < 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 *)"ImportGateway", pubkey));
}
UniValue marmara_poolpayout(const UniValue& params, bool fHelp)
{
int32_t firstheight; double perc; char *jsonstr;
@@ -6026,6 +6120,7 @@ UniValue channelsopen(const UniValue& params, bool fHelp)
tokenid=Parseuint256((char *)params[3].get_str().c_str());
}
hex = ChannelOpen(0,pubkey2pk(destpub),numpayments,payment,tokenid);
RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 )
{
result.push_back(Pair("result", "success"));
@@ -6056,6 +6151,7 @@ UniValue channelspayment(const UniValue& params, bool fHelp)
secret = Parseuint256((char *)params[2].get_str().c_str());
}
hex = ChannelPayment(0,opentxid,amount,secret);
RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 )
{
result.push_back(Pair("result", "success"));
@@ -6076,6 +6172,7 @@ UniValue channelsclose(const UniValue& params, bool fHelp)
LOCK2(cs_main, pwalletMain->cs_wallet);
opentxid = Parseuint256((char *)params[0].get_str().c_str());
hex = ChannelClose(0,opentxid);
RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 )
{
result.push_back(Pair("result", "success"));
@@ -6097,6 +6194,7 @@ UniValue channelsrefund(const UniValue& params, bool fHelp)
opentxid = Parseuint256((char *)params[0].get_str().c_str());
closetxid = Parseuint256((char *)params[1].get_str().c_str());
hex = ChannelRefund(0,opentxid,closetxid);
RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 )
{
result.push_back(Pair("result", "success"));
@@ -6830,143 +6928,14 @@ UniValue priceslist(const UniValue& params, bool fHelp)
UniValue pricesinfo(const UniValue& params, bool fHelp)
{
uint256 fundingtxid;
if ( fHelp || params.size() != 1 )
uint256 bettxid; int32_t height;
if ( fHelp || params.size() != 2 )
throw runtime_error("pricesinfo fundingtxid\n");
if ( ensure_CCrequirements(EVAL_PRICES) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
fundingtxid = Parseuint256((char *)params[0].get_str().c_str());
return(PricesInfo(fundingtxid));
}
UniValue pricescreate(const UniValue& params, bool fHelp)
{
UniValue result(UniValue::VOBJ); uint64_t mode; int64_t funding; int32_t i,n,margin,maxleverage; std::string hex; uint256 oracletxid,longtoken,shorttoken,bettoken; std::vector<CPubKey> pubkeys; std::vector<uint8_t>pubkey;
if ( fHelp || params.size() < 8 )
throw runtime_error("pricescreate bettoken oracletxid margin mode longtoken shorttoken maxleverage funding N [pubkeys]\n");
if ( ensure_CCrequirements(EVAL_PRICES) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
bettoken = Parseuint256((char *)params[0].get_str().c_str());
oracletxid = Parseuint256((char *)params[1].get_str().c_str());
margin = atof(params[2].get_str().c_str()) * 1000;
mode = atol(params[3].get_str().c_str());
longtoken = Parseuint256((char *)params[4].get_str().c_str());
shorttoken = Parseuint256((char *)params[5].get_str().c_str());
maxleverage = atol(params[6].get_str().c_str());
funding = atof(params[7].get_str().c_str()) * COIN + 0.00000000499999;
n = atoi(params[8].get_str().c_str());
if ( n > 0 )
{
for (i=0; i<n; i++)
{
if ( params.size() < 9+i+1 )
throw runtime_error("not enough parameters for N pubkeys\n");
pubkey = ParseHex(params[9+i].get_str().c_str());
pubkeys.push_back(pubkey2pk(pubkey));
}
}
hex = PricesCreateFunding(0,bettoken,oracletxid,margin,mode,longtoken,shorttoken,maxleverage,funding,pubkeys);
if ( hex.size() > 0 )
{
result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex));
}
else
{
ERR_RESULT("couldnt create prices funding transaction");
}
return(result);
}
UniValue pricesaddfunding(const UniValue& params, bool fHelp)
{
UniValue result(UniValue::VOBJ); std::string hex; uint256 fundingtxid,bettoken; int64_t amount;
if ( fHelp || params.size() != 3 )
throw runtime_error("pricesaddfunding fundingtxid bettoken amount\n");
if ( ensure_CCrequirements(EVAL_PRICES) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
fundingtxid = Parseuint256((char *)params[0].get_str().c_str());
bettoken = Parseuint256((char *)params[1].get_str().c_str());
amount = atof(params[2].get_str().c_str()) * COIN + 0.00000000499999;
hex = PricesAddFunding(0,bettoken,fundingtxid,amount);
if ( hex.size() > 0 )
{
result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex));
}
else
{
ERR_RESULT("couldnt create pricesaddfunding transaction");
}
return(result);
}
UniValue pricesbet(const UniValue& params, bool fHelp)
{
UniValue result(UniValue::VOBJ); std::string hex; uint256 fundingtxid,bettoken; int64_t amount; int32_t leverage;
if ( fHelp || params.size() != 4 )
throw runtime_error("pricesbet fundingtxid bettoken amount leverage\n");
if ( ensure_CCrequirements(EVAL_PRICES) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
fundingtxid = Parseuint256((char *)params[0].get_str().c_str());
bettoken = Parseuint256((char *)params[1].get_str().c_str());
amount = atof(params[2].get_str().c_str()) * COIN + 0.00000000499999;
leverage = atoi(params[3].get_str().c_str());
hex = PricesBet(0,bettoken,fundingtxid,amount,leverage);
if ( hex.size() > 0 )
{
result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex));
}
else
{
ERR_RESULT("couldnt create pricesbet transaction");
}
return(result);
}
UniValue pricesstatus(const UniValue& params, bool fHelp)
{
uint256 fundingtxid,bettxid,bettoken;
if ( fHelp || params.size() != 3 )
throw runtime_error("pricesstatus fundingtxid bettoken bettxid\n");
if ( ensure_CCrequirements(EVAL_PRICES) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
fundingtxid = Parseuint256((char *)params[0].get_str().c_str());
bettoken = Parseuint256((char *)params[1].get_str().c_str());
bettxid = Parseuint256((char *)params[2].get_str().c_str());
return(PricesStatus(0,bettoken,fundingtxid,bettxid));
}
UniValue pricesfinish(const UniValue& params, bool fHelp)
{
UniValue result(UniValue::VOBJ); uint256 fundingtxid,bettxid,bettoken; std::string hex;
if ( fHelp || params.size() != 3 )
throw runtime_error("pricesfinish fundingtxid bettoken bettxid\n");
if ( ensure_CCrequirements(EVAL_PRICES) < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
fundingtxid = Parseuint256((char *)params[0].get_str().c_str());
bettoken = Parseuint256((char *)params[1].get_str().c_str());
bettxid = Parseuint256((char *)params[2].get_str().c_str());
hex = PricesFinish(0,bettoken,fundingtxid,bettxid);
if ( hex.size() > 0 )
{
result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex));
}
else
{
ERR_RESULT("couldnt create pricesfinish transaction");
}
return(result);
bettxid = Parseuint256((char *)params[0].get_str().c_str());
height = atoi(params[1].get_str().c_str());
return(PricesInfo(bettxid,height));
}
UniValue dicefund(const UniValue& params, bool fHelp)
@@ -8040,7 +8009,6 @@ UniValue test_heirmarker(const UniValue& params, bool fHelp)
return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, opret));
}
UniValue test_burntx(const UniValue& params, bool fHelp)
{
// make fake token tx:

View File

@@ -38,6 +38,7 @@
#include "crypter.h"
#include "coins.h"
#include "zcash/zip32.h"
#include "cc/CCinclude.h"
#include <assert.h>
@@ -1747,10 +1748,6 @@ bool CWallet::UpdatedNoteData(const CWalletTx& wtxIn, CWalletTx& wtx)
* pblock is optional, but should be provided if the transaction is known to be in a block.
* If fUpdate is true, existing transactions will be updated.
*/
extern uint8_t NOTARY_PUBKEY33[33];
extern std::string NOTARY_ADDRESS,WHITELIST_ADDRESS;
extern int32_t IS_STAKED_NOTARY;
extern uint64_t MIN_RECV_SATS;
bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate)
{
@@ -1769,71 +1766,49 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl
return false;
}
}
static std::string NotaryAddress; static bool didinit;
if ( !didinit && NotaryAddress.empty() && NOTARY_PUBKEY33[0] != 0 )
{
didinit = true;
char Raddress[64];
pubkey2addr((char *)Raddress,(uint8_t *)NOTARY_PUBKEY33);
NotaryAddress.assign(Raddress);
vWhiteListAddress = mapMultiArgs["-whitelistaddress"];
if ( !vWhiteListAddress.empty() )
{
fprintf(stderr, "Activated Wallet Filter \n Notary Address: %s \n Adding whitelist address's:\n", NotaryAddress.c_str());
for ( auto wladdr : vWhiteListAddress )
fprintf(stderr, " %s\n", wladdr.c_str());
}
}
if (fExisted || IsMine(tx) || IsFromMe(tx) || sproutNoteData.size() > 0 || saplingNoteData.size() > 0)
{
// wallet filter for notary nodes. Disabled! Can be reenabled or customised for any specific use, pools could also use this to prevent wallet dwy attack.
if ( 0 && !tx.IsCoinBase() && !NOTARY_ADDRESS.empty() && IS_STAKED_NOTARY > -1 )
// wallet filter for notary nodes. Enables by setting -whitelistaddress= as startup param or in conf file (works same as -addnode byut with R-address's)
if ( !tx.IsCoinBase() && !vWhiteListAddress.empty() && !NotaryAddress.empty() )
{
int numvinIsOurs = 0, numvoutIsOurs = 0, numvinIsWhiteList = 0; int64_t totalvoutvalue = 0;
int numvinIsOurs = 0, numvinIsWhiteList = 0;
for (size_t i = 0; i < tx.vin.size(); i++)
{
uint256 hash; CTransaction txin; CTxDestination address;
if (GetTransaction(tx.vin[i].prevout.hash,txin,hash,false))
if ( GetTransaction(tx.vin[i].prevout.hash,txin,hash,false) && ExtractDestination(txin.vout[tx.vin[i].prevout.n].scriptPubKey, address) )
{
if (ExtractDestination(txin.vout[tx.vin[i].prevout.n].scriptPubKey, address))
if ( CBitcoinAddress(address).ToString() == NotaryAddress )
numvinIsOurs++;
for ( auto wladdr : vWhiteListAddress )
{
if ( CBitcoinAddress(address).ToString() == NOTARY_ADDRESS )
numvinIsOurs++;
if ( !WHITELIST_ADDRESS.empty() )
if ( CBitcoinAddress(address).ToString() == wladdr )
{
//fprintf(stderr, "white list address: %s recv address: %s\n", WHITELIST_ADDRESS.c_str(),CBitcoinAddress(address).ToString().c_str());
if ( CBitcoinAddress(address).ToString() == WHITELIST_ADDRESS ) {
//fprintf(stderr, "whitlisted is set to true here.\n");
numvinIsWhiteList++;
}
//fprintf(stderr, "We received from whitelisted address.%s\n", wladdr.c_str());
numvinIsWhiteList++;
}
}
}
}
// Now we know if it was a tx sent to us, that wasnt from ourself or the whitelist address if set..
// Now we know if it was a tx sent to us, by either a whitelisted address, or ourself.
if ( numvinIsOurs != 0 )
fprintf(stderr, "We sent from address: %s vins: %d\n",NOTARY_ADDRESS.c_str(),numvinIsOurs);
if ( numvinIsWhiteList != 0 )
fprintf(stderr, "We received from whitelisted address: %s\n",WHITELIST_ADDRESS.c_str());
// Count vouts, check if OUR notary address is the receiver.
fprintf(stderr, "We sent from address: %s vins: %d\n",NotaryAddress.c_str(),numvinIsOurs);
if ( numvinIsOurs == 0 && numvinIsWhiteList == 0 )
{
for (size_t i = 0; i < tx.vout.size() ; i++)
{
CTxDestination address2;
if ( ExtractDestination(tx.vout[i].scriptPubKey, address2))
{
if ( CBitcoinAddress(address2).ToString() == NOTARY_ADDRESS )
{
numvoutIsOurs++;
totalvoutvalue += tx.vout[i].nValue;
}
}
}
// if MIN_RECV_SATS is 0, we are on full lock down mode, accept NO transactions.
if ( MIN_RECV_SATS == 0 ) {
fprintf(stderr, "This node is on full lock down all txs are ignored! \n");
return false;
}
// If no vouts are to the notary address we will ignore them.
if ( numvoutIsOurs == 0 ) {
fprintf(stderr, "Received transaction to address other than notary address, ignored! \n");
return false;
}
fprintf(stderr, "address: %s received %ld sats from %d vouts.\n",NOTARY_ADDRESS.c_str(),totalvoutvalue,(int32_t)numvoutIsOurs);
// here we add calculation for number if vouts received, average size and determine if we accept them to wallet or not.
int64_t avgVoutSize = totalvoutvalue / numvoutIsOurs;
if ( avgVoutSize < MIN_RECV_SATS ) {
// average vout size is less than set minimum, default is 1 coin, we will ignore it
fprintf(stderr, "ignored: %d vouts average size of %ld sats.\n",numvoutIsOurs, (long)avgVoutSize);
return false;
}
}
return false;
}
CWalletTx wtx(this,tx);