Browse Source

Handled OP_KEVA_* - treated them as NOP.

cn
Jianping Wu 6 years ago
parent
commit
148ff7fcbd
  1. 2
      src/consensus/tx_verify.cpp
  2. 48
      src/keva/main.cpp
  3. 10
      src/script/interpreter.cpp
  4. 4
      src/wallet/rpcwallet.cpp
  5. 15
      src/wallet/wallet.cpp

2
src/consensus/tx_verify.cpp

@ -209,7 +209,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fChe
bool Consensus::CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, unsigned flags, CAmount& txfee) bool Consensus::CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, unsigned flags, CAmount& txfee)
{ {
if (!CheckKevaTransaction (tx, nSpendHeight, inputs, state, flags)) { if (!CheckKevaTransaction (tx, nSpendHeight, inputs, state, flags)) {
return state.Invalid(false, 0, "", "Tx invalid for Namecoin"); return state.Invalid(false, 0, "", "Tx invalid for Kevacoin");
} }
// are the actual inputs available? // are the actual inputs available?

48
src/keva/main.cpp

@ -306,38 +306,39 @@ CheckKevaTransaction (const CTransaction& tx, unsigned nHeight,
#endif #endif
/* As a first step, try to locate inputs and outputs of the transaction /* As a first step, try to locate inputs and outputs of the transaction
that are name scripts. At most one input and output should be that are keva scripts. At most one input and output should be
a name operation. */ a keva operation. */
int nameIn = -1; int nameIn = -1;
CKevaScript nameOpIn; CKevaScript nameOpIn;
Coin coinIn; Coin coinIn;
for (unsigned i = 0; i < tx.vin.size (); ++i) for (unsigned i = 0; i < tx.vin.size (); ++i) {
{ const COutPoint& prevout = tx.vin[i].prevout;
const COutPoint& prevout = tx.vin[i].prevout; Coin coin;
Coin coin; if (!view.GetCoin (prevout, coin)) {
if (!view.GetCoin (prevout, coin)) return error ("%s: failed to fetch input coin for %s", __func__, txid);
return error ("%s: failed to fetch input coin for %s", __func__, txid); }
const CKevaScript op(coin.out.scriptPubKey); const CKevaScript op(coin.out.scriptPubKey);
if (op.isKevaOp()) { if (op.isKevaOp()) {
if (nameIn != -1) if (nameIn != -1) {
return state.Invalid (error ("%s: multiple name inputs into" return state.Invalid (error ("%s: multiple name inputs into transaction %s", __func__, txid));
" transaction %s", __func__, txid));
nameIn = i;
nameOpIn = op;
coinIn = coin;
} }
nameIn = i;
nameOpIn = op;
coinIn = coin;
} }
}
int nameOut = -1; int nameOut = -1;
CKevaScript nameOpOut; CKevaScript nameOpOut;
for (unsigned i = 0; i < tx.vout.size (); ++i) { for (unsigned i = 0; i < tx.vout.size (); ++i) {
const CKevaScript op(tx.vout[i].scriptPubKey); const CKevaScript op(tx.vout[i].scriptPubKey);
if (op.isKevaOp()) { if (op.isKevaOp()) {
if (nameOut != -1) if (nameOut != -1) {
return state.Invalid (error ("%s: multiple name outputs from" return state.Invalid (error ("%s: multiple name outputs from"
" transaction %s", __func__, txid)); " transaction %s", __func__, txid));
}
nameOut = i; nameOut = i;
nameOpOut = op; nameOpOut = op;
} }
@ -349,11 +350,11 @@ CheckKevaTransaction (const CTransaction& tx, unsigned nHeight,
if (!tx.IsKevacoin ()) { if (!tx.IsKevacoin ()) {
if (nameIn != -1) if (nameIn != -1)
return state.Invalid (error ("%s: non-Namecoin tx %s has name inputs", return state.Invalid (error ("%s: non-Kevacoin tx %s has keva inputs",
__func__, txid)); __func__, txid));
if (nameOut != -1) if (nameOut != -1)
return state.Invalid (error ("%s: non-Namecoin tx %s at height %u" return state.Invalid (error ("%s: non-Kevacoin tx %s at height %u"
" has name outputs", " has keva outputs",
__func__, txid, nHeight)); __func__, txid, nHeight));
return true; return true;
@ -361,7 +362,7 @@ CheckKevaTransaction (const CTransaction& tx, unsigned nHeight,
assert(tx.IsKevacoin ()); assert(tx.IsKevacoin ());
if (nameOut == -1) if (nameOut == -1)
return state.Invalid (error ("%s: Namecoin tx %s has no name outputs", return state.Invalid (error ("%s: Kevacoin tx %s has no keva outputs",
__func__, txid)); __func__, txid));
/* Reject "greedy names". */ /* Reject "greedy names". */
@ -406,8 +407,7 @@ CheckKevaTransaction (const CTransaction& tx, unsigned nHeight,
assert (nameOpOut.isAnyUpdate()); assert (nameOpOut.isAnyUpdate());
if (nameIn == -1) { if (nameIn == -1) {
return state.Invalid(error("CheckNameTransaction: update without" return state.Invalid(error("CheckNameTransaction: update without previous keva input"));
" previous name input"));
} }
const valtype& key = nameOpOut.getOpKey(); const valtype& key = nameOpOut.getOpKey();

10
src/script/interpreter.cpp

@ -354,6 +354,13 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
case OP_NOP: case OP_NOP:
break; break;
//
// KEVA
//
case OP_KEVA_NAMESPACE:
case OP_KEVA_PUT:
break;
case OP_CHECKLOCKTIMEVERIFY: case OP_CHECKLOCKTIMEVERIFY:
{ {
if (!(flags & SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY)) { if (!(flags & SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY)) {
@ -1437,9 +1444,10 @@ bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const C
return false; return false;
if (flags & SCRIPT_VERIFY_P2SH) if (flags & SCRIPT_VERIFY_P2SH)
stackCopy = stack; stackCopy = stack;
if (!EvalScript(stack, scriptPubKey, flags, checker, SIGVERSION_BASE, serror)) if (!EvalScript(stack, scriptPubKey, flags, checker, SIGVERSION_BASE, serror)) {
// serror is set // serror is set
return false; return false;
}
if (stack.empty()) if (stack.empty())
return set_error(serror, SCRIPT_ERR_EVAL_FALSE); return set_error(serror, SCRIPT_ERR_EVAL_FALSE);
if (CastToBool(stack.back()) == false) if (CastToBool(stack.back()) == false)

4
src/wallet/rpcwallet.cpp

@ -459,9 +459,9 @@ void SendMoneyToScript(CWallet* const pwallet, const CScript &scriptPubKey,
std::string strError; std::string strError;
if (withInput) { if (withInput) {
const CWalletTx* dummyWalletTx; const CWalletTx* dummyWalletTx;
if (!pwallet->FindValueInNameInput (*withInput, lockedValue, if (!pwallet->FindValueInNameInput (*withInput, lockedValue, dummyWalletTx, strError)) {
dummyWalletTx, strError))
throw JSONRPCError(RPC_WALLET_ERROR, strError); throw JSONRPCError(RPC_WALLET_ERROR, strError);
}
} }
if (nValue > curBalance + lockedValue) if (nValue > curBalance + lockedValue)

15
src/wallet/wallet.cpp

@ -2857,6 +2857,10 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend,
} }
} }
if (withInput) {
setCoins.insert(CInputCoin(withInputTx, withInput->prevout.n));
}
const CAmount nChange = nValueIn - nValueToSelect; const CAmount nChange = nValueIn - nValueToSelect;
if (nChange > 0) if (nChange > 0)
@ -3060,9 +3064,7 @@ CWallet::FindValueInNameInput (const CTxIn& nameInput,
CAmount& value, const CWalletTx*& walletTx, CAmount& value, const CWalletTx*& walletTx,
std::string& strFailReason) const std::string& strFailReason) const
{ {
#if 0 walletTx = GetWalletTx(nameInput.prevout.hash);
// JWU TODO: implement this!
walletTx = GetWalletTx (nameInput.prevout.hash);
if (!walletTx) { if (!walletTx) {
strFailReason = _("Input tx not found in wallet"); strFailReason = _("Input tx not found in wallet");
return false; return false;
@ -3074,16 +3076,13 @@ CWallet::FindValueInNameInput (const CTxIn& nameInput,
return false; return false;
} }
if (!CKevaScript::isKevaScript (output.scriptPubKey)) { if (!CKevaScript::isKevaScript(output.scriptPubKey)) {
strFailReason = _("Input tx is not a name operation"); strFailReason = _("Input tx is not a keva operation");
return false; return false;
} }
value = output.nValue; value = output.nValue;
return true; return true;
#else
return true;
#endif
} }
/** /**

Loading…
Cancel
Save