rebased onto latest FSM with gateways import

This commit is contained in:
dimxy
2019-04-19 15:17:47 +05:00
parent f9eaf192b4
commit 53a7f69501
3 changed files with 26 additions and 20 deletions

View File

@@ -519,7 +519,7 @@ int32_t CheckPUBKEYimport(TxProof proof,std::vector<uint8_t> rawproof,CTransacti
return(0); return(0);
} }
bool CheckFungible(Eval *eval, const CTransaction &importTx, const CTransaction &burnTx, std::vector<CTxOut> & payouts, const ImportProof &proof, const std::vector<uint8_t> &rawproof) bool CheckMigration(Eval *eval, const CTransaction &importTx, const CTransaction &burnTx, std::vector<CTxOut> & payouts, const ImportProof &proof, const std::vector<uint8_t> &rawproof)
{ {
if (strcmp(ASSETCHAINS_SYMBOL, "CFEKDIMXY6") == 0 && chainActive.Height() <= 10699) if (strcmp(ASSETCHAINS_SYMBOL, "CFEKDIMXY6") == 0 && chainActive.Height() <= 10699)
return true; return true;
@@ -649,12 +649,12 @@ bool Eval::ImportCoin(const std::vector<uint8_t> params, const CTransaction &imp
ImportProof proof; ImportProof proof;
CTransaction burnTx; CTransaction burnTx;
std::vector<CTxOut> payouts; std::vector<CTxOut> payouts;
CAmount txfee = 10000; CAmount txfee = 10000, amount;
int32_t height, burnvout; int32_t height, burnvout;
std::vector<CPubKey> publishers; std::vector<CPubKey> publishers;
uint32_t targetCcid; uint32_t targetCcid;
std::string targetSymbol, srcaddr, destaddr, receipt, rawburntx; std::string targetSymbol, srcaddr, destaddr, receipt, rawburntx;
uint256 payoutsHash, bindtxid; uint256 payoutsHash, bindtxid, burntxid;
std::vector<uint8_t> rawproof; std::vector<uint8_t> rawproof;
std::vector<uint256> txids; std::vector<uint256> txids;
CPubKey destpub; CPubKey destpub;
@@ -700,8 +700,8 @@ bool Eval::ImportCoin(const std::vector<uint8_t> params, const CTransaction &imp
if (targetCcid != GetAssetchainsCC() || targetSymbol != GetAssetchainsSymbol()) if (targetCcid != GetAssetchainsCC() || targetSymbol != GetAssetchainsSymbol())
return Invalid("importcoin-wrong-chain"); return Invalid("importcoin-wrong-chain");
if (!CheckFungible(this, importTx, burnTx, payouts, proof, rawproof)) if (!CheckMigration(this, importTx, burnTx, payouts, proof, rawproof))
return false; return false; // eval->Invalid() is called in the func
} }
else else
{ {

View File

@@ -29,7 +29,7 @@
int32_t komodo_nextheight(); int32_t komodo_nextheight();
// makes import tx for either coins or tokens // makes import tx for either coins or tokens
CTransaction MakeImportCoinTransaction(const ImportProof &proof, const CTransaction &burnTx, const std::vector<CTxOut> &payouts, uint32_t nExpiryHeightOverride) CTransaction MakeImportCoinTransaction(const ImportProof proof, const CTransaction burnTx, const std::vector<CTxOut> payouts, uint32_t nExpiryHeightOverride)
{ {
//std::vector<uint8_t> payload = E_MARSHAL(ss << EVAL_IMPORTCOIN); //std::vector<uint8_t> payload = E_MARSHAL(ss << EVAL_IMPORTCOIN);
CScript scriptSig; CScript scriptSig;
@@ -76,7 +76,7 @@ CTransaction MakeImportCoinTransaction(const ImportProof &proof, const CTransact
} }
CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, const std::string &targetSymbol, const std::vector<CTxOut> &payouts, const std::vector<uint8_t> &rawproof) CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, const std::string targetSymbol, const std::vector<CTxOut> payouts, const std::vector<uint8_t> rawproof)
{ {
std::vector<uint8_t> opret; std::vector<uint8_t> opret;
opret = E_MARSHAL(ss << (uint8_t)EVAL_IMPORTCOIN; // should mark burn opret to differentiate it from token opret opret = E_MARSHAL(ss << (uint8_t)EVAL_IMPORTCOIN; // should mark burn opret to differentiate it from token opret
@@ -91,7 +91,8 @@ CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymb
uint256 bindtxid,std::vector<CPubKey> publishers,std::vector<uint256> txids,uint256 burntxid,int32_t height,int32_t burnvout,std::string rawburntx,CPubKey destpub, int64_t amount) uint256 bindtxid,std::vector<CPubKey> publishers,std::vector<uint256> txids,uint256 burntxid,int32_t height,int32_t burnvout,std::string rawburntx,CPubKey destpub, int64_t amount)
{ {
std::vector<uint8_t> opret; std::vector<uint8_t> opret;
opret = E_MARSHAL(ss << VARINT(targetCCid); opret = E_MARSHAL(ss << (uint8_t)EVAL_IMPORTCOIN;
ss << VARINT(targetCCid);
ss << targetSymbol; ss << targetSymbol;
ss << SerializeHash(payouts); ss << SerializeHash(payouts);
ss << rawproof; ss << rawproof;
@@ -112,7 +113,8 @@ CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymb
std::string receipt) std::string receipt)
{ {
std::vector<uint8_t> opret; std::vector<uint8_t> opret;
opret = E_MARSHAL(ss << VARINT(targetCCid); opret = E_MARSHAL(ss << (uint8_t)EVAL_IMPORTCOIN;
ss << VARINT(targetCCid);
ss << targetSymbol; ss << targetSymbol;
ss << SerializeHash(payouts); ss << SerializeHash(payouts);
ss << rawproof; ss << rawproof;
@@ -122,7 +124,7 @@ CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymb
} }
bool UnmarshalImportTx(const CTransaction &importTx, ImportProof &proof, CTransaction &burnTx, std::vector<CTxOut> &payouts) bool UnmarshalImportTx(const CTransaction importTx, ImportProof &proof, CTransaction &burnTx, std::vector<CTxOut> &payouts)
{ {
if (importTx.vout.size() < 1) if (importTx.vout.size() < 1)
return false; return false;
@@ -173,7 +175,7 @@ bool UnmarshalImportTx(const CTransaction &importTx, ImportProof &proof, CTransa
} }
bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint32_t *targetCCid, uint256 &payoutsHash,std::vector<uint8_t>&rawproof) bool UnmarshalBurnTx(const CTransaction burnTx, std::string &targetSymbol, uint32_t *targetCCid, uint256 &payoutsHash,std::vector<uint8_t>&rawproof)
{ {
std::vector<uint8_t> vburnOpret; uint32_t ccid = 0; std::vector<uint8_t> vburnOpret; uint32_t ccid = 0;
uint8_t evalCode; uint8_t evalCode;
@@ -211,8 +213,8 @@ bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint
ss >> VARINT(*targetCCid); ss >> VARINT(*targetCCid);
ss >> targetSymbol; ss >> targetSymbol;
ss >> payoutsHash; ss >> payoutsHash;
ss >> rawproof; isEof = ss.eof();) || !isEof; // if isEof == false it means we successfully read add the data ss >> rawproof; isEof = ss.eof();) || !isEof; // if isEof == false it means we have successfully read the vars upto 'rawproof'
// and it might be additional data further that we do not need here // and it might be additional data further that we do not need here so we allow !isEof
} }
else { else {
LOGSTREAM("importcoin", CCLOG_INFO, stream << "UnmarshalBurnTx() invalid eval code in opret" << std::endl); LOGSTREAM("importcoin", CCLOG_INFO, stream << "UnmarshalBurnTx() invalid eval code in opret" << std::endl);
@@ -220,14 +222,16 @@ bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint
} }
} }
bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &srcaddr, std::string &receipt) bool UnmarshalBurnTx(const CTransaction burnTx, std::string &srcaddr, std::string &receipt)
{ {
std::vector<uint8_t> burnOpret,rawproof; bool isEof=true; std::vector<uint8_t> burnOpret,rawproof; bool isEof=true;
std::string targetSymbol; uint32_t targetCCid; uint256 payoutsHash; std::string targetSymbol; uint32_t targetCCid; uint256 payoutsHash;
uint8_t evalCode;
if (burnTx.vout.size() == 0) return false; if (burnTx.vout.size() == 0) return false;
GetOpReturnData(burnTx.vout.back().scriptPubKey, burnOpret); GetOpReturnData(burnTx.vout.back().scriptPubKey, burnOpret);
return (E_UNMARSHAL(burnOpret, ss >> VARINT(targetCCid); return (E_UNMARSHAL(burnOpret, ss >> evalCode;
ss >> VARINT(targetCCid);
ss >> targetSymbol; ss >> targetSymbol;
ss >> payoutsHash; ss >> payoutsHash;
ss >> rawproof; ss >> rawproof;
@@ -239,10 +243,12 @@ bool UnmarshalBurnTx(const CTransaction burnTx,uint256 &bindtxid,std::vector<CPu
{ {
std::vector<uint8_t> burnOpret,rawproof; bool isEof=true; std::vector<uint8_t> burnOpret,rawproof; bool isEof=true;
uint32_t targetCCid; uint256 payoutsHash; std::string targetSymbol; uint32_t targetCCid; uint256 payoutsHash; std::string targetSymbol;
uint8_t evalCode;
if (burnTx.vout.size() == 0) return false; if (burnTx.vout.size() == 0) return false;
GetOpReturnData(burnTx.vout.back().scriptPubKey, burnOpret); GetOpReturnData(burnTx.vout.back().scriptPubKey, burnOpret);
return (E_UNMARSHAL(burnOpret, ss >> VARINT(targetCCid); return (E_UNMARSHAL(burnOpret, ss >> evalCode;
ss >> VARINT(targetCCid);
ss >> targetSymbol; ss >> targetSymbol;
ss >> payoutsHash; ss >> payoutsHash;
ss >> rawproof; ss >> rawproof;

View File

@@ -94,9 +94,9 @@ public:
CAmount GetCoinImportValue(const CTransaction &tx); CAmount GetCoinImportValue(const CTransaction &tx);
CTransaction MakeImportCoinTransaction(const ImportProof &proof, const CTransaction &burnTx, const std::vector<CTxOut> &payouts, uint32_t nExpiryHeightOverride = 0); CTransaction MakeImportCoinTransaction(const ImportProof proof, const CTransaction burnTx, const std::vector<CTxOut> payouts, uint32_t nExpiryHeightOverride = 0);
CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, const std::string &targetSymbol, const std::vector<CTxOut> &payouts, const std::vector<uint8_t> &rawproof); CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, const std::string targetSymbol, const std::vector<CTxOut> payouts, const std::vector<uint8_t> rawproof);
CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector<CTxOut> payouts,std::vector<uint8_t> rawproof, CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector<CTxOut> payouts,std::vector<uint8_t> rawproof,
uint256 bindtxid,std::vector<CPubKey> publishers,std::vector<uint256>txids,uint256 burntxid,int32_t height,int32_t burnvout,std::string rawburntx,CPubKey destpub, int64_t amount); uint256 bindtxid,std::vector<CPubKey> publishers,std::vector<uint256>txids,uint256 burntxid,int32_t height,int32_t burnvout,std::string rawburntx,CPubKey destpub, int64_t amount);
CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector<CTxOut> payouts,std::vector<uint8_t> rawproof,std::string srcaddr, CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector<CTxOut> payouts,std::vector<uint8_t> rawproof,std::string srcaddr,
@@ -105,7 +105,7 @@ CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymb
bool UnmarshalBurnTx(const CTransaction burnTx, std::string &targetSymbol, uint32_t *targetCCid, uint256 &payoutsHash,std::vector<uint8_t> &rawproof); bool UnmarshalBurnTx(const CTransaction burnTx, std::string &targetSymbol, uint32_t *targetCCid, uint256 &payoutsHash,std::vector<uint8_t> &rawproof);
bool UnmarshalBurnTx(const CTransaction burnTx, std::string &srcaddr, std::string &receipt); bool UnmarshalBurnTx(const CTransaction burnTx, std::string &srcaddr, std::string &receipt);
bool UnmarshalBurnTx(const CTransaction burnTx,uint256 &bindtxid,std::vector<CPubKey> &publishers,std::vector<uint256> &txids,uint256& burntxid,int32_t &height,int32_t &burnvout,std::string &rawburntx,CPubKey &destpub, int64_t &amount); bool UnmarshalBurnTx(const CTransaction burnTx,uint256 &bindtxid,std::vector<CPubKey> &publishers,std::vector<uint256> &txids,uint256& burntxid,int32_t &height,int32_t &burnvout,std::string &rawburntx,CPubKey &destpub, int64_t &amount);
bool UnmarshalImportTx(const CTransaction &importTx, ImportProof &proof, CTransaction &burnTx,std::vector<CTxOut> &payouts); bool UnmarshalImportTx(const CTransaction importTx, ImportProof &proof, CTransaction &burnTx,std::vector<CTxOut> &payouts);
bool VerifyCoinImport(const CScript& scriptSig, TransactionSignatureChecker& checker, CValidationState &state); bool VerifyCoinImport(const CScript& scriptSig, TransactionSignatureChecker& checker, CValidationState &state);
@@ -116,6 +116,6 @@ int ExistsImportTombstone(const CTransaction &importTx, const CCoinsViewCache &i
bool CheckVinPubKey(const CTransaction &sourcetx, int32_t i, uint8_t pubkey33[33]); bool CheckVinPubKey(const CTransaction &sourcetx, int32_t i, uint8_t pubkey33[33]);
CMutableTransaction MakeSelfImportSourceTx(CTxDestination &dest, int64_t amount); CMutableTransaction MakeSelfImportSourceTx(CTxDestination &dest, int64_t amount);
int32_t GetSelfimportProof(const CMutableTransaction &sourceMtx, CMutableTransaction &templateMtx, ImportProof &proofNull); int32_t GetSelfimportProof(const CMutableTransaction sourceMtx, CMutableTransaction &templateMtx, ImportProof &proofNull);
#endif /* IMPORTCOIN_H */ #endif /* IMPORTCOIN_H */