Merge pull request #1134 from jl777/jl777

Jl777
This commit is contained in:
jl777
2019-01-02 02:17:52 -11:00
committed by GitHub
7 changed files with 154 additions and 114 deletions

View File

@@ -18,7 +18,7 @@
#include "importcoin.h" #include "importcoin.h"
#include "crosschain.h" #include "crosschain.h"
#include "primitives/transaction.h" #include "primitives/transaction.h"
#include "cc/CCinclude.h"
/* /*
* CC Eval method for import coin. * CC Eval method for import coin.
@@ -31,86 +31,112 @@
extern std::string ASSETCHAINS_SELFIMPORT; extern std::string ASSETCHAINS_SELFIMPORT;
extern uint16_t ASSETCHAINS_CODAPORT,ASSETCHAINS_BEAMPORT; extern uint16_t ASSETCHAINS_CODAPORT,ASSETCHAINS_BEAMPORT;
extern uint8_t ASSETCHAINS_OVERRIDE_PUBKEY33[33];
int32_t GetSelfimportProof(TxProof &proof,CTransaction burnTx,uint256 hash) // find burnTx with hash from "other" daemon int32_t GetSelfimportProof(std::string source,CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector<uint8_t> rawtx,uint256 txid,std::vector<uint8_t> rawproof) // find burnTx with hash from "other" daemon
{ {
if ( ASSETCHAINS_SELFIMPORT == "BEAM" ) MerkleBranch newBranch; CMutableTransaction tmpmtx; CTransaction tx,vintx; uint256 blockHash; char destaddr[64],pkaddr[64];
tmpmtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),komodo_nextheight());
if ( source == "BEAM" )
{ {
if ( ASSETCHAINS_BEAMPORT == 0 )
return(-1);
// confirm via ASSETCHAINS_BEAMPORT that burnTx/hash is a valid BEAM burn // confirm via ASSETCHAINS_BEAMPORT that burnTx/hash is a valid BEAM burn
return(-1); // return(0);
} }
else if ( ASSETCHAINS_SELFIMPORT == "CODA" ) else if ( source == "CODA" )
{ {
if ( ASSETCHAINS_CODAPORT == 0 )
return(-1);
// confirm via ASSETCHAINS_CODAPORT that burnTx/hash is a valid CODA burn // confirm via ASSETCHAINS_CODAPORT that burnTx/hash is a valid CODA burn
return(-1); // return(0);
} }
else if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) else
{ {
// make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 if ( !E_UNMARSHAL(rawtx, ss >> tx) )
return(0);
}
else if ( ASSETCHAINS_SELFIMPORT == "GATEWAY" )
{
// external coin is the assetchains symbol in the burnTx OP_RETURN
return(-1); return(-1);
scriptPubKey = tx.vout[0].scriptPubKey;
mtx = tx;
mtx.fOverwintered = tmpmtx.fOverwintered;
mtx.nExpiryHeight = tmpmtx.nExpiryHeight;
mtx.nVersionGroupId = tmpmtx.nVersionGroupId;
mtx.nVersion = tmpmtx.nVersion;
mtx.vout.clear();
mtx.vout.resize(1);
mtx.vout[0].nValue = burnAmount;
mtx.vout[0].scriptPubKey = scriptPubKey;
if ( tx.GetHash() != txid )
return(-1);
if ( source == "PUBKEY" )
{
// make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33
if ( myGetTransaction(tx.vin[0].prevout.hash,vintx,blockHash) == 0 )
return(-1);
if ( tx.vin[0].prevout.n < vintx.vout.size() && Getscriptaddress(destaddr,vintx.vout[tx.vin[0].prevout.n].scriptPubKey) != 0 )
{
pubkey2addr(pkaddr,ASSETCHAINS_OVERRIDE_PUBKEY33);
if ( strcmp(pkaddr,destaddr) == 0 )
{
proof = std::make_pair(txid,newBranch);
return(0);
}
fprintf(stderr,"mismatched vin0[%d] -> %s vs %s\n",tx.vin[0].prevout.n,destaddr,pkaddr);
}
}
else if ( source == ASSETCHAINS_SELFIMPORT )
{
// source is external coin is the assetchains symbol in the burnTx OP_RETURN
// burnAmount, rawtx and rawproof should be enough for gatewaysdeposit equivalent
}
} }
else return(-1); return(-1);
return(0);
} }
// use proof from the above functions to validate the import // use proof from the above functions to validate the import
int32_t CheckBEAMimport(TxProof proof,CTransaction burnTx,std::vector<CTxOut> payouts) int32_t CheckBEAMimport(TxProof proof,std::vector<uint8_t> rawproof,CTransaction burnTx,std::vector<CTxOut> payouts)
{ {
// check with dual-BEAM daemon via ASSETCHAINS_BEAMPORT for validity of burnTx // check with dual-BEAM daemon via ASSETCHAINS_BEAMPORT for validity of burnTx
return(-1); return(-1);
} }
int32_t CheckCODAimport(TxProof proof,CTransaction burnTx,std::vector<CTxOut> payouts) int32_t CheckCODAimport(TxProof proof,std::vector<uint8_t> rawproof,CTransaction burnTx,std::vector<CTxOut> payouts)
{ {
// check with dual-CODA daemon via ASSETCHAINS_CODAPORT for validity of burnTx // check with dual-CODA daemon via ASSETCHAINS_CODAPORT for validity of burnTx
return(-1); return(-1);
} }
int32_t CheckGATEWAYimport(std::string coin,TxProof proof,CTransaction burnTx,std::vector<CTxOut> payouts) int32_t CheckGATEWAYimport(TxProof proof,std::vector<uint8_t> rawproof,CTransaction burnTx,std::vector<CTxOut> payouts)
{ {
// ASSETCHAINS_SELFIMPORT is coin
// check for valid burn from external coin blockchain and if valid return(0); // check for valid burn from external coin blockchain and if valid return(0);
return(-1); return(-1);
} }
int32_t CheckPUBKEYimport(TxProof proof,CTransaction burnTx,std::vector<CTxOut> payouts) int32_t CheckPUBKEYimport(TxProof proof,std::vector<uint8_t> rawproof,CTransaction burnTx,std::vector<CTxOut> payouts)
{ {
// if burnTx has ASSETCHAINS_PUBKEY vin, it is valid return(0); // if burnTx has ASSETCHAINS_PUBKEY vin, it is valid return(0);
fprintf(stderr,"proof txid.%s\n",proof.first.GetHex().c_str());
return(0); return(0);
return(-1); return(-1);
} }
bool Eval::ImportCoin(const std::vector<uint8_t> params, const CTransaction &importTx, unsigned int nIn) bool Eval::ImportCoin(const std::vector<uint8_t> params,const CTransaction &importTx,unsigned int nIn)
{ {
if (importTx.vout.size() < 2) TxProof proof; CTransaction burnTx; std::vector<CTxOut> payouts; uint64_t txfee = 10000;
uint32_t targetCcid; std::string targetSymbol; uint256 payoutsHash; std::vector<uint8_t> rawproof;
if ( importTx.vout.size() < 2 )
return Invalid("too-few-vouts"); return Invalid("too-few-vouts");
// params // params
TxProof proof;
CTransaction burnTx;
std::vector<CTxOut> payouts;
if (!UnmarshalImportTx(importTx, proof, burnTx, payouts)) if (!UnmarshalImportTx(importTx, proof, burnTx, payouts))
return Invalid("invalid-params"); return Invalid("invalid-params");
// Control all aspects of this transaction // Control all aspects of this transaction
// It should not be at all malleable // It should not be at all malleable
if (MakeImportCoinTransaction(proof, burnTx, payouts).GetHash() != importTx.GetHash()) if (MakeImportCoinTransaction(proof, burnTx, payouts).GetHash() != importTx.GetHash())
return Invalid("non-canonical"); return Invalid("non-canonical");
// burn params // burn params
uint32_t targetCcid; if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCcid, payoutsHash,rawproof))
std::string targetSymbol;
uint256 payoutsHash;
if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCcid, payoutsHash))
return Invalid("invalid-burn-tx"); return Invalid("invalid-burn-tx");
// check burn amount // check burn amount
{ {
uint64_t burnAmount = burnTx.vout.back().nValue; uint64_t burnAmount = burnTx.vout.back().nValue;
@@ -119,46 +145,51 @@ bool Eval::ImportCoin(const std::vector<uint8_t> params, const CTransaction &imp
uint64_t totalOut = 0; uint64_t totalOut = 0;
for (int i=0; i<importTx.vout.size(); i++) for (int i=0; i<importTx.vout.size(); i++)
totalOut += importTx.vout[i].nValue; totalOut += importTx.vout[i].nValue;
if (totalOut > burnAmount) if (totalOut > burnAmount || totalOut < burnAmount-txfee )
return Invalid("payout-too-high"); return Invalid("payout-too-high");
} }
// Check burntx shows correct outputs hash // Check burntx shows correct outputs hash
if (payoutsHash != SerializeHash(payouts)) if (payoutsHash != SerializeHash(payouts))
return Invalid("wrong-payouts"); return Invalid("wrong-payouts");
if (targetCcid < KOMODO_FIRSTFUNGIBLEID) if (targetCcid < KOMODO_FIRSTFUNGIBLEID)
return Invalid("chain-not-fungible"); return Invalid("chain-not-fungible");
// Check proof confirms existance of burnTx // Check proof confirms existance of burnTx
if ( targetCcid != 0xffffffff ) if ( targetCcid != 0xffffffff )
{ {
if (targetCcid != GetAssetchainsCC() || targetSymbol != GetAssetchainsSymbol()) if ( targetCcid != GetAssetchainsCC() || targetSymbol != GetAssetchainsSymbol() )
return Invalid("importcoin-wrong-chain"); return Invalid("importcoin-wrong-chain");
uint256 target = proof.second.Exec(burnTx.GetHash()); uint256 target = proof.second.Exec(burnTx.GetHash());
if (!CheckMoMoM(proof.first, target)) if (!CheckMoMoM(proof.first, target))
return Invalid("momom-check-fail"); return Invalid("momom-check-fail");
} }
else if ( ASSETCHAINS_SELFIMPORT == targetSymbol || ASSETCHAINS_SELFIMPORT == "GATEWAY" ) // various selfchain imports else
{ {
if ( ASSETCHAINS_SELFIMPORT == "BEAM" ) if ( targetSymbol == "BEAM" )
{ {
if ( CheckBEAMimport(proof,burnTx,payouts) < 0 ) if ( ASSETCHAINS_BEAMPORT == 0 )
return Invalid("BEAM-import-without-port");
else if ( CheckBEAMimport(proof,rawproof,burnTx,payouts) < 0 )
return Invalid("BEAM-import-failure"); return Invalid("BEAM-import-failure");
} }
else if ( ASSETCHAINS_SELFIMPORT == "CODA" ) else if ( targetSymbol == "CODA" )
{ {
if ( CheckCODAimport(proof,burnTx,payouts) < 0 ) if ( ASSETCHAINS_CODAPORT == 0 )
return Invalid("CODA-import-without-port");
else if ( CheckCODAimport(proof,rawproof,burnTx,payouts) < 0 )
return Invalid("CODA-import-failure"); return Invalid("CODA-import-failure");
} }
else if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) else if ( targetSymbol == "PUBKEY" )
{ {
if ( CheckPUBKEYimport(proof,burnTx,payouts) < 0 ) if ( ASSETCHAINS_SELFIMPORT != "PUBKEY" )
return Invalid("PUBKEY-import-when-notPUBKEY");
else if ( CheckPUBKEYimport(proof,rawproof,burnTx,payouts) < 0 )
return Invalid("PUBKEY-import-failure"); return Invalid("PUBKEY-import-failure");
} }
else else
{ {
if ( CheckGATEWAYimport(GetAssetchainsSymbol(),proof,burnTx,payouts) < 0 ) if ( targetSymbol != ASSETCHAINS_SELFIMPORT )
return Invalid("invalid-gateway-import-coin");
else if ( CheckGATEWAYimport(proof,rawproof,burnTx,payouts) < 0 )
return Invalid("GATEWAY-import-failure"); return Invalid("GATEWAY-import-failure");
} }
} }

View File

@@ -214,16 +214,14 @@ cont:
*/ */
void CompleteImportTransaction(CTransaction &importTx) void CompleteImportTransaction(CTransaction &importTx)
{ {
TxProof proof; TxProof proof; CTransaction burnTx; std::vector<CTxOut> payouts; std::vector<uint8_t> rawproof;
CTransaction burnTx;
std::vector<CTxOut> payouts;
if (!UnmarshalImportTx(importTx, proof, burnTx, payouts)) if (!UnmarshalImportTx(importTx, proof, burnTx, payouts))
throw std::runtime_error("Couldn't parse importTx"); throw std::runtime_error("Couldn't parse importTx");
std::string targetSymbol; std::string targetSymbol;
uint32_t targetCCid; uint32_t targetCCid;
uint256 payoutsHash; uint256 payoutsHash;
if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCCid, payoutsHash)) if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCCid, payoutsHash, rawproof))
throw std::runtime_error("Couldn't parse burnTx"); throw std::runtime_error("Couldn't parse burnTx");
proof = GetCrossChainProof(burnTx.GetHash(), targetSymbol.data(), targetCCid, proof); proof = GetCrossChainProof(burnTx.GetHash(), targetSymbol.data(), targetCCid, proof);

View File

@@ -38,11 +38,22 @@ CTransaction MakeImportCoinTransaction(const TxProof proof, const CTransaction b
} }
CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector<CTxOut> payouts) CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector<CTxOut> payouts,std::vector<uint8_t> rawproof)
{ {
std::vector<uint8_t> opret = E_MARSHAL(ss << VARINT(targetCCid); std::vector<uint8_t> opret;
ss << targetSymbol; if ( targetCCid != 0xffffffff )
ss << SerializeHash(payouts)); {
opret = E_MARSHAL(ss << VARINT(targetCCid);
ss << targetSymbol;
ss << SerializeHash(payouts));
}
else
{
opret = E_MARSHAL(ss << VARINT(targetCCid);
ss << targetSymbol;
ss << SerializeHash(payouts);
ss << rawproof);
}
return CTxOut(value, CScript() << OP_RETURN << opret); return CTxOut(value, CScript() << OP_RETURN << opret);
} }
@@ -60,14 +71,25 @@ bool UnmarshalImportTx(const CTransaction &importTx, TxProof &proof, CTransactio
} }
bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint32_t *targetCCid, uint256 &payoutsHash) bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint32_t *targetCCid, uint256 &payoutsHash,std::vector<uint8_t>&rawproof)
{ {
std::vector<uint8_t> burnOpret; std::vector<uint8_t> burnOpret; uint32_t ccid = 0;
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); E_UNMARSHAL(burnOpret, ss >> VARINT(ccid));
ss >> targetSymbol; if ( ccid != 0xffffffff )
ss >> payoutsHash); {
return E_UNMARSHAL(burnOpret, ss >> VARINT(*targetCCid);
ss >> targetSymbol;
ss >> payoutsHash);
}
else
{
return E_UNMARSHAL(burnOpret, ss >> VARINT(*targetCCid);
ss >> targetSymbol;
ss >> payoutsHash;
ss >> rawproof);
}
} }

View File

@@ -28,9 +28,9 @@ CAmount GetCoinImportValue(const CTransaction &tx);
CTransaction MakeImportCoinTransaction(const TxProof proof, CTransaction MakeImportCoinTransaction(const TxProof proof,
const CTransaction burnTx, const std::vector<CTxOut> payouts); const CTransaction burnTx, const std::vector<CTxOut> payouts);
CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector<CTxOut> payouts); CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector<CTxOut> payouts,std::vector<uint8_t> rawproof);
bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint32_t *targetCCid, uint256 &payoutsHash); bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint32_t *targetCCid, uint256 &payoutsHash,std::vector<uint8_t> &rawproof);
bool UnmarshalImportTx(const CTransaction &importTx, TxProof &proof, CTransaction &burnTx, bool UnmarshalImportTx(const CTransaction &importTx, TxProof &proof, CTransaction &burnTx,
std::vector<CTxOut> &payouts); std::vector<CTxOut> &payouts);

View File

@@ -1775,41 +1775,32 @@ void komodo_args(char *argv0)
ASSETCHAINS_SCRIPTPUB = GetArg("-ac_script",""); ASSETCHAINS_SCRIPTPUB = GetArg("-ac_script","");
ASSETCHAINS_BEAMPORT = GetArg("-ac_beam",0); ASSETCHAINS_BEAMPORT = GetArg("-ac_beam",0);
ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0);
if ( ASSETCHAINS_BEAMPORT != 0 && ASSETCHAINS_CODAPORT != 0 )
{
fprintf(stderr,"can only have one of -ac_beam or -ac_coda\n");
exit(0);
}
ASSETCHAINS_SELFIMPORT = GetArg("-ac_import",""); // BEAM, CODA, PUBKEY, GATEWAY ASSETCHAINS_SELFIMPORT = GetArg("-ac_import",""); // BEAM, CODA, PUBKEY, GATEWAY
if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" )
{ {
if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) != 66 ) if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) != 66 )
{ {
fprintf(stderr,"invalid -ac_pubkey for -ac_import=PUBKEY\n"); fprintf(stderr,"invalid -ac_pubkey for -ac_import=PUBKEY\n");
ASSETCHAINS_SELFIMPORT = "";
exit(0); exit(0);
} }
} }
else if ( ASSETCHAINS_SELFIMPORT == "BEAM" && ASSETCHAINS_BEAMPORT == 0 ) else if ( ASSETCHAINS_SELFIMPORT == "BEAM" && ASSETCHAINS_BEAMPORT == 0 )
{ {
fprintf(stderr,"missing -ac_beam for BEAM rpcport\n"); fprintf(stderr,"missing -ac_beam for BEAM rpcport\n");
ASSETCHAINS_SELFIMPORT = "";
exit(0); exit(0);
} }
else if ( ASSETCHAINS_SELFIMPORT == "CODA" && ASSETCHAINS_CODAPORT == 0 ) else if ( ASSETCHAINS_SELFIMPORT == "CODA" && ASSETCHAINS_CODAPORT == 0 )
{ {
fprintf(stderr,"missing -ac_coda for CODA rpcport\n"); fprintf(stderr,"missing -ac_coda for CODA rpcport\n");
ASSETCHAINS_SELFIMPORT = "";
exit(0); exit(0);
} }
else if ( ASSETCHAINS_SELFIMPORT.size() > 0 && ASSETCHAINS_SELFIMPORT != "GATEWAY" ) // else it can be gateway coin
{
fprintf(stderr,"invalid -ac_import type\n");
ASSETCHAINS_SELFIMPORT = "";
exit(0);
}
if ( ASSETCHAINS_SELFIMPORT.size() > 0 && ASSETCHAINS_CC >= KOMODO_FIRSTFUNGIBLEID )
{
fprintf(stderr,"selfimport chains cant be in a fungible cluster\n");
exit(0);
}
//ASSETCHAINS_FOUNDERS_PERIOD = GetArg("-ac_period",0);
if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 ) if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 )
ASSETCHAINS_STAKED = 100; ASSETCHAINS_STAKED = 100;
@@ -1863,7 +1854,7 @@ void komodo_args(char *argv0)
printf("ASSETCHAINS_FOUNDERS needs an ASETCHAINS_OVERRIDE_PUBKEY\n"); printf("ASSETCHAINS_FOUNDERS needs an ASETCHAINS_OVERRIDE_PUBKEY\n");
} }
} }
if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 ) if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 )
{ {
fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size()); fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size());
extraptr = extrabuf; extraptr = extrabuf;
@@ -1933,6 +1924,10 @@ void komodo_args(char *argv0)
fprintf(stderr," selfimport\n"); fprintf(stderr," selfimport\n");
extralen += ASSETCHAINS_SELFIMPORT.size(); extralen += ASSETCHAINS_SELFIMPORT.size();
} }
if ( ASSETCHAINS_BEAMPORT != 0 )
extraptr[extralen++] = 'b';
if ( ASSETCHAINS_CODAPORT != 0 )
extraptr[extralen++] = 'c';
} }
addn = GetArg("-seednode",""); addn = GetArg("-seednode","");

View File

@@ -46,9 +46,8 @@ int32_t komodo_MoMoMdata(char *hexstr,int32_t hexsize,struct komodo_ccdataMoMoM
struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t kmdstarti,int32_t kmdendi); struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t kmdstarti,int32_t kmdendi);
uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth); uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth);
extern std::string ASSETCHAINS_SELFIMPORT; extern std::string ASSETCHAINS_SELFIMPORT;
int komodo_nextheight();
uint256 Parseuint256(char *hexstr); uint256 Parseuint256(char *hexstr);
int32_t GetSelfimportProof(TxProof &proof,CTransaction burnTx,uint256 hash); int32_t GetSelfimportProof(std::string source,CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector<uint8_t> rawtx,uint256 txid,std::vector<uint8_t> rawproof);
UniValue assetchainproof(const UniValue& params, bool fHelp) UniValue assetchainproof(const UniValue& params, bool fHelp)
@@ -164,7 +163,7 @@ UniValue calc_MoM(const UniValue& params, bool fHelp)
UniValue migrate_converttoexport(const UniValue& params, bool fHelp) UniValue migrate_converttoexport(const UniValue& params, bool fHelp)
{ {
uint32_t ccid = ASSETCHAINS_CC; std::vector<uint8_t> rawproof; uint8_t *ptr; int32_t i; uint32_t ccid = ASSETCHAINS_CC;
if (fHelp || params.size() != 3) if (fHelp || params.size() != 3)
throw runtime_error( throw runtime_error(
"migrate_converttoexport rawTx dest_symbol export_amount\n" "migrate_converttoexport rawTx dest_symbol export_amount\n"
@@ -200,15 +199,13 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp)
if (burnAmount < needed) if (burnAmount < needed)
throw runtime_error("export_amount too small"); throw runtime_error("export_amount too small");
} }
if ( ASSETCHAINS_SELFIMPORT.size() > 0 ) //if ( ASSETCHAINS_SELFIMPORT.size() > 0 )
{ // throw runtime_error("self-import chains cant be fungible");
throw runtime_error("self-import chains cant be fungible"); rawproof.resize(strlen(ASSETCHAINS_SYMBOL));
/*if ( ASSETCHAINS_SELFIMPORT == targetSymbol || ASSETCHAINS_SELFIMPORT == "GATEWAY" ) ptr = rawproof.data();
{ for (i=0; i<rawproof.size(); i++)
ccid = 0xffffffff; ptr[i] = ASSETCHAINS_SYMBOL[i];
} // else maybe clusters of self-import chains can be supported?*/ CTxOut burnOut = MakeBurnOutput(burnAmount, ccid, targetSymbol, tx.vout,rawproof);
}
CTxOut burnOut = MakeBurnOutput(burnAmount, ccid, targetSymbol, tx.vout);
UniValue ret(UniValue::VOBJ); UniValue ret(UniValue::VOBJ);
ret.push_back(Pair("payouts", HexStr(E_MARSHAL(ss << tx.vout)))); ret.push_back(Pair("payouts", HexStr(E_MARSHAL(ss << tx.vout))));
tx.vout.clear(); tx.vout.clear();
@@ -284,33 +281,30 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp)
UniValue selfimport(const UniValue& params, bool fHelp) UniValue selfimport(const UniValue& params, bool fHelp)
{ {
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CMutableTransaction mtx;
TxProof proof; CTransaction burnTx,tx; CTxOut burnOut,savevout; uint64_t burnAmount; uint256 txid,blockHash; std::vector<CTxOut> vouts; std::string source; TxProof proof; CTransaction burnTx,tx; CTxOut burnOut; uint64_t burnAmount; uint256 txid,blockHash; std::vector<CTxOut> vouts; std::vector<uint8_t> rawtx,rawproof; CScript scriptPubKey;
if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) if ( ASSETCHAINS_SELFIMPORT.size() == 0 )
throw runtime_error("selfimport only works on -ac_import chains"); throw runtime_error("selfimport only works on -ac_import chains");
if (fHelp || params.size() != 2) if (fHelp || params.size() < 3 || params.size() > 5 )
throw runtime_error("selfimport txid burnamount\n\n" throw runtime_error("selfimport rawtx txid burnamount [rawproof source]\n\n"
"creates signed selfimport transaction from txid"); "creates signed selfimport transaction");
txid = Parseuint256((char *)params[0].get_str().c_str()); rawtx = ParseHex(params[0].get_str().c_str());
burnAmount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; txid = Parseuint256((char *)params[1].get_str().c_str()); // allow for txid != hash(rawtx)
// txid is just used to specify the import recv address burnAmount = atof(params[2].get_str().c_str()) * COIN + 0.00000000499999;
// in reality it would be rawtx from the other chain and maybe better to specify address source = ASSETCHAINS_SELFIMPORT;
if ( GetTransaction(txid,tx,blockHash,false) == 0 ) if ( params.size() >= 4 )
throw runtime_error("selfimport couldnt find txid"); {
savevout = tx.vout[0]; rawproof = ParseHex(params[3].get_str().c_str());
mtx = tx; if ( params.size() == 5 )
mtx.vout.clear(); source = params[4].get_str();
mtx.vout.resize(1); }
mtx.vout[0] = savevout; if ( GetSelfimportProof(source,mtx,scriptPubKey,proof,burnAmount,rawtx,txid,rawproof) < 0 )
mtx.vout[0].nValue = burnAmount; throw std::runtime_error("Failed validating selfimport");
vouts = mtx.vout; vouts = mtx.vout;
burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,vouts); burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,vouts,rawproof);
mtx = tx;
mtx.vout.clear(); mtx.vout.clear();
mtx.vout.push_back(burnOut); mtx.vout.push_back(burnOut);
burnTx = mtx; burnTx = mtx;
if ( GetSelfimportProof(proof,tx,txid) < 0 )
throw std::runtime_error("Failed validating selfimport");
return HexStr(E_MARSHAL(ss << MakeImportCoinTransaction(proof,burnTx,vouts))); return HexStr(E_MARSHAL(ss << MakeImportCoinTransaction(proof,burnTx,vouts)));
} }

View File

@@ -26,7 +26,7 @@ static uint8_t testNum = 0;
class TestCoinImport : public ::testing::Test, public Eval { class TestCoinImport : public ::testing::Test, public Eval {
public: public:
CMutableTransaction burnTx; CMutableTransaction burnTx; std::vector<uint8_t> rawproof;
std::vector<CTxOut> payouts; std::vector<CTxOut> payouts;
TxProof proof; TxProof proof;
uint256 MoMoM; uint256 MoMoM;
@@ -37,7 +37,7 @@ public:
void SetImportTx() { void SetImportTx() {
burnTx.vout.resize(0); burnTx.vout.resize(0);
burnTx.vout.push_back(MakeBurnOutput(amount, testCcid, testSymbol, payouts)); burnTx.vout.push_back(MakeBurnOutput(amount, testCcid, testSymbol, payouts,rawproof));
importTx = CMutableTransaction(MakeImportCoinTransaction(proof, CTransaction(burnTx), payouts)); importTx = CMutableTransaction(MakeImportCoinTransaction(proof, CTransaction(burnTx), payouts));
MoMoM = burnTx.GetHash(); // TODO: an actual branch MoMoM = burnTx.GetHash(); // TODO: an actual branch
} }