Browse Source

Change name to Stake Guard

pull/4/head
miketout 6 years ago
parent
commit
ca4a5f2692
  1. 4
      src/Makefile.am
  2. 6
      src/cc/CCcustom.cpp
  3. 20
      src/cc/StakeGuard.cpp
  4. 8
      src/cc/StakeGuard.h
  5. 2
      src/cc/eval.cpp
  6. 2
      src/cc/eval.h
  7. 4
      src/miner.cpp
  8. 17
      src/primitives/block.cpp
  9. 4
      src/primitives/block.h
  10. 2
      src/script/sign.cpp
  11. 2
      src/wallet/wallet.cpp

4
src/Makefile.am

@ -291,8 +291,8 @@ libbitcoin_server_a_SOURCES = \
cc/CCcustom.cpp \
cc/CCtx.cpp \
cc/CCutils.cpp \
cc/CoinbaseGuard.cpp \
cc/CoinbaseGuard.h \
cc/StakeGuard.cpp \
cc/StakeGuard.h \
cc/assets.cpp \
cc/faucet.cpp \
cc/rewards.cpp \

6
src/cc/CCcustom.cpp

@ -29,7 +29,7 @@
#include "CCTriggers.h"
#include "CCPayments.h"
#include "CCGateways.h"
#include "CoinbaseGuard.h"
#include "StakeGuard.h"
/*
CCcustom has most of the functions that need to be extended to create a new CC contract.
@ -227,12 +227,12 @@ struct CCcontract_info *CCinit(struct CCcontract_info *cp, uint8_t evalcode)
cp->evalcode = evalcode;
switch ( evalcode )
{
case EVAL_COINBASEGUARD:
case EVAL_STAKEGUARD:
strcpy(cp->unspendableCCaddr,AssetsCCaddr);
strcpy(cp->normaladdr,AssetsNormaladdr);
strcpy(cp->CChexstr,AssetsCChexstr);
memcpy(cp->CCpriv,AssetsCCpriv,32);
cp->validate = CoinbaseGuardValidate;
cp->validate = StakeGuardValidate;
cp->ismyvin = IsAssetsInput;
break;

20
src/cc/CoinbaseGuard.cpp → src/cc/StakeGuard.cpp

@ -9,7 +9,7 @@
*
*/
#include "CoinbaseGuard.h"
#include "StakeGuard.h"
#include "script/script.h"
#include "main.h"
#include "hash.h"
@ -184,13 +184,13 @@ bool ValidateStakeTransaction(const CTransaction &stakeTx, CStakeParams &stakePa
bool MakeGuardedOutput(CAmount value, CPubKey &dest, CTransaction &stakeTx, CTxOut &vout)
{
CCcontract_info *cp, C;
cp = CCinit(&C,EVAL_COINBASEGUARD);
cp = CCinit(&C,EVAL_STAKEGUARD);
CPubKey ccAddress = CPubKey(ParseHex(cp->CChexstr));
// return an output that is bound to the stake transaction and can be spent by presenting either a signed condition by the original
// destination address or a properly signed stake transaction of the same utxo on a fork
vout = MakeCC1of2vout(EVAL_COINBASEGUARD, value, dest, ccAddress);
vout = MakeCC1of2vout(EVAL_STAKEGUARD, value, dest, ccAddress);
std::vector<CPubKey> vPubKeys = std::vector<CPubKey>();
vPubKeys.push_back(dest);
@ -218,7 +218,7 @@ bool MakeGuardedOutput(CAmount value, CPubKey &dest, CTransaction &stakeTx, CTxO
}
vData.push_back(height);
COptCCParams ccp = COptCCParams(COptCCParams::VERSION, EVAL_COINBASEGUARD, 1, 2, vPubKeys, vData);
COptCCParams ccp = COptCCParams(COptCCParams::VERSION, EVAL_STAKEGUARD, 1, 2, vPubKeys, vData);
vout.scriptPubKey << ccp.AsVector() << OP_DROP;
return true;
@ -352,12 +352,12 @@ int IsCCFulfilled(CC *cc, ccFulfillmentCheck *ctx)
return ctx->vCount[0];
}
bool CoinbaseGuardValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn)
bool StakeGuardValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn)
{
// This also supports a variable blockstomaturity option for backward feature compatibility
// WARNING: this has not been tested combined with time locks
// validate this spend of a transaction with it being past any applicable time lock and one of the following statements being true:
// 1. the spend is signed by the original output destination's private key and normal payment requirements, spends as normal
// 2. the spend is signed by the private key of the CoinbaseGuard contract and pushes a signed stake transaction
// 2. the spend is signed by the private key of the StakeGuard contract and pushes a signed stake transaction
// with the same exact utxo source, a target block height of later than or equal to this tx, and a different prevBlock hash
// first, check to see if the spending contract is signed by the default destination address
@ -424,7 +424,7 @@ bool CoinbaseGuardValidate(struct CCcontract_info *cp, Eval* eval, const CTransa
else return true;
}
UniValue CoinbaseGuardInfo()
UniValue StakeGuardInfo()
{
UniValue result(UniValue::VOBJ); char numstr[64];
CMutableTransaction mtx;
@ -432,10 +432,10 @@ UniValue CoinbaseGuardInfo()
CCcontract_info *cp,C;
cp = CCinit(&C,EVAL_COINBASEGUARD);
cp = CCinit(&C,EVAL_STAKEGUARD);
result.push_back(Pair("result","success"));
result.push_back(Pair("name","CoinbaseGuard"));
result.push_back(Pair("name","StakeGuard"));
// all UTXOs to the contract address that are to any of the wallet addresses are to us
// each is spendable as a normal transaction, but the spend may fail if it gets spent out

8
src/cc/CoinbaseGuard.h → src/cc/StakeGuard.h

@ -9,8 +9,8 @@
*
*/
#ifndef CC_COINBASEGUARD_H
#define CC_COINBASEGUARD_H
#ifndef CC_STAKEGUARD_H
#define CC_STAKEGUARD_H
#include <vector>
@ -32,8 +32,8 @@ bool MakeGuardedOutput(CAmount value, CPubKey &dest, CTransaction &stakeTx, CTxO
bool MakeCheatEvidence(CMutableTransaction &mtx, const CTransaction &ccTx, uint32_t voutNum, const CTransaction &cheatTx);
bool CoinbaseGuardValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn);
bool StakeGuardValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn);
UniValue CoinbaseGuardInfo();
UniValue StakeGuardInfo();
#endif

2
src/cc/eval.cpp

@ -83,7 +83,7 @@ bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn)
default:
// only support coinbase guard for now
if (ecode == EVAL_COINBASEGUARD)
if (ecode == EVAL_STAKEGUARD)
return(ProcessCC(cp,this, vparams, txTo, nIn));
break;
}

2
src/cc/eval.h

@ -38,7 +38,7 @@
* after the code is interpreted as a bitcoin script.
*/
#define FOREACH_EVAL(EVAL) \
EVAL(EVAL_COINBASEGUARD, 0x1) \
EVAL(EVAL_STAKEGUARD, 0x1) \
EVAL(EVAL_IMPORTPAYOUT, 0xe1) \
EVAL(EVAL_IMPORTCOIN, 0xe2) \
EVAL(EVAL_ASSETS, 0xe3) \

4
src/miner.cpp

@ -10,7 +10,7 @@
#include "amount.h"
#include "chainparams.h"
#include "cc/CoinbaseGuard.h"
#include "cc/StakeGuard.h"
#include "importcoin.h"
#include "consensus/consensus.h"
#include "consensus/upgrades.h"
@ -488,7 +488,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount,
txNew.vout[0].scriptPubKey = scriptPubKeyIn;
txNew.vout[0].nValue = GetBlockSubsidy(nHeight,chainparams.GetConsensus()) + nFees;
// once we get to Sapling, enable CC CoinbaseGuard for stake transactions
// once we get to Sapling, enable CC StakeGuard for stake transactions
if (isStake && extendedStake)
{
// if there is a specific destination, use it

17
src/primitives/block.cpp

@ -49,13 +49,13 @@ void CBlockHeader::SetVerusHash()
// if it returns false, value is set to 0, but it can still be calculated from the full block
// in that case. the only difference between this and the POS hash for the contest is that it is not divided by the value out
// this is used as a source of entropy
bool CBlockHeader::GetRawVerusPOSHash(uint256 &value, int32_t nHeight) const
bool CBlockHeader::GetRawVerusPOSHash(uint256 &ret, int32_t nHeight) const
{
// if below the required height or no storage space in the solution, we can't get
// a cached txid value to calculate the POSHash from the header
if (!(CPOSNonce::NewNonceActive(nHeight) && IsVerusPOSBlock()))
{
value = uint256();
ret = uint256();
return false;
}
@ -74,10 +74,21 @@ bool CBlockHeader::GetRawVerusPOSHash(uint256 &value, int32_t nHeight) const
hashWriter << ASSETCHAINS_MAGIC;
hashWriter << nNonce;
hashWriter << nHeight;
value = hashWriter.GetHash();
ret = hashWriter.GetHash();
return true;
}
bool CBlockHeader::GetVerusPOSHash(arith_uint256 &ret, int32_t nHeight, CAmount value) const
{
uint256 raw;
if (GetRawVerusPOSHash(raw, nHeight))
{
ret = UintToArith256(raw) / value;
return true;
}
return false;
}
// depending on the height of the block and its type, this returns the POS hash or the POW hash
uint256 CBlockHeader::GetVerusEntropyHash(int32_t height) const
{

4
src/primitives/block.h

@ -84,8 +84,8 @@ public:
uint256 GetVerusHash() const;
static void SetVerusHash();
bool GetRawVerusPOSHash(uint256 &value, int32_t nHeight) const;
bool GetRawVerusPOSHash(uint256 &ret, int32_t nHeight) const;
bool GetVerusPOSHash(arith_uint256 &ret, int32_t nHeight, CAmount value) const; // value is amount of stake tx
uint256 GetVerusEntropyHash(int32_t nHeight) const;
uint256 GetVerusV2Hash() const;

2
src/script/sign.cpp

@ -104,7 +104,7 @@ std::vector<CCcontract_info> &GetCryptoConditions()
if (!initialized)
{
C.evalcode = EVAL_COINBASEGUARD;
C.evalcode = EVAL_STAKEGUARD;
uint8_t privKey[32] = { 0x9b, 0x17, 0x66, 0xe5, 0x82, 0x66, 0xac, 0xb6, 0xba, 0x43, 0x83, 0x74, 0xf7, 0x63, 0x11, 0x3b, 0xf0, 0xf3, 0x50, 0x6f, 0xd9, 0x6b, 0x67, 0x85, 0xf9, 0x7a, 0xf0, 0x54, 0x4d, 0xb1, 0x30, 0x77 };
strcpy(C.unspendableCCaddr,"RGKRjeTBw4LYFotSDLT6RWzMHbhXri6BG6");
strcpy(C.normaladdr,"RFYE2yL3KknWdHK6uNhvWacYsCUtwzjY3u");

2
src/wallet/wallet.cpp

@ -23,7 +23,7 @@
#include "crypter.h"
#include "coins.h"
#include "zcash/zip32.h"
#include "cc/CoinbaseGuard.h"
#include "cc/StakeGuard.h"
#include <assert.h>

Loading…
Cancel
Save