diff --git a/src/crosschain.cpp b/src/crosschain.cpp index 806641f6a..8dc5657b8 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -26,8 +26,6 @@ int NOTARISATION_SCAN_LIMIT_BLOCKS = 1440; CBlockIndex *komodo_getblockindex(uint256 hash); -extern std::string ASSETCHAINS_SELFIMPORT; -int32_t GetSelfimportProof(TxProof &proof,CTransaction burnTx,uint256 hash); /* On KMD */ @@ -293,13 +291,6 @@ TxProof GetAssetchainProof(uint256 hash,CTransaction burnTx) CBlockIndex* blockIndex; Notarisation nota; std::vector branch; - if ( ASSETCHAINS_SELFIMPORT.size() > 0 ) - { - TxProof proof; - if ( GetSelfimportProof(proof,burnTx,hash) < 0 ) - throw std::runtime_error("Failed validating selfimport"); - return(proof); - } { uint256 blockHash; CTransaction tx; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index eeedf1949..f0cecfe66 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1783,22 +1783,31 @@ void komodo_args(char *argv0) { fprintf(stderr,"invalid -ac_pubkey for -ac_import=PUBKEY\n"); ASSETCHAINS_SELFIMPORT = ""; + exit(0); } } else if ( ASSETCHAINS_SELFIMPORT == "BEAM" && ASSETCHAINS_BEAMPORT == 0 ) { fprintf(stderr,"missing -ac_beam for BEAM rpcport\n"); ASSETCHAINS_SELFIMPORT = ""; + exit(0); } else if ( ASSETCHAINS_SELFIMPORT == "CODA" && ASSETCHAINS_CODAPORT == 0 ) { fprintf(stderr,"missing -ac_coda for CODA rpcport\n"); ASSETCHAINS_SELFIMPORT = ""; + exit(0); } - else if ( ASSETCHAINS_SELFIMPORT != "GATEWAY" ) + else if ( ASSETCHAINS_SELFIMPORT.size() > 0 && ASSETCHAINS_SELFIMPORT != "GATEWAY" ) { fprintf(stderr,"invalid -ac_import type\n"); ASSETCHAINS_SELFIMPORT = ""; + exit(0); + } + if ( ASSETCHAINS_SELFIMPORT.size() > 0 && ASSETCHAINS_CC >= KOMODO_FIRST_FUNGIBLEID ) + { + fprintf(stderr,"selfimport chains cant be in a fungible cluster\n"); + exit(0); } //ASSETCHAINS_FOUNDERS_PERIOD = GetArg("-ac_period",0); @@ -1834,11 +1843,11 @@ void komodo_args(char *argv0) ASSETCHAINS_COMMISSION = 53846154; // maps to 35% printf("ASSETCHAINS_COMMISSION defaulted to 35%% when founders reward active\n"); } - else if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) + /*else if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) { //ASSETCHAINS_OVERRIDE_PUBKEY.clear(); printf("-ac_perc must be set with -ac_pubkey\n"); - } + }*/ } } else @@ -1946,7 +1955,12 @@ void komodo_args(char *argv0) MAX_MONEY = 10000100000LL*SATOSHIDEN; //fprintf(stderr,"MAX_MONEY %llu %.8f\n",(long long)MAX_MONEY,(double)MAX_MONEY/SATOSHIDEN); //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); - ASSETCHAINS_P2PPORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); + port = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); + if ( GetArgs("-port",0) == 0 ) + ASSETCHAINS_P2PPORT = GetArgs("-port",0); + else ASSETCHAINS_P2PPORT = port; + mainParams.SetDefaultPort(ASSETCHAINS_P2PPORT); + while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) { fprintf(stderr,"waiting for datadir\n"); diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 617af120b..4495ab0f3 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -183,10 +183,11 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) } if ( ASSETCHAINS_SELFIMPORT.size() > 0 ) { - if ( ASSETCHAINS_SELFIMPORT == targetSymbol || ASSETCHAINS_SELFIMPORT == "GATEWAY" ) + throw runtime_error("self-import chains cant be fungible"); + /*if ( ASSETCHAINS_SELFIMPORT == targetSymbol || ASSETCHAINS_SELFIMPORT == "GATEWAY" ) { ccid = 0xffffffff; - } // else maybe clusters of self-import chains can be supported? + } // else maybe clusters of self-import chains can be supported?*/ } CTxOut burnOut = MakeBurnOutput(burnAmount, ccid, targetSymbol, tx.vout); UniValue ret(UniValue::VOBJ); @@ -262,6 +263,29 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp) return HexStr(E_MARSHAL(ss << importTx)); } +#ifdef selfimport +UniValue selfimport(const UniValue& params, bool fHelp) +{ + TxProof proof; CTransaction importTx,burnTx; CTxOut burnOut; uint64_t burnAmount; uint256 blockHash; + if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) + throw runtime_error("selfimport only works on -ac_import chains"); + if (fHelp || params.size() != 2) + throw runtime_error("selfimport txid burnamount\n\n" + "creates signed selfimport transaction from txid"); + //txid = + //burnAmount = + + if ( GetTransaction(txid,burnTx,hashBlock,false) == 0 ) + throw runtime_error("selfimport couldnt find txid"); + if ( GetSelfimportProof(proof,burnTx,txid) < 0 ) + throw std::runtime_error("Failed validating selfimport"); + + burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,burnTx.vout); + importTx = MakeImportCoinTransaction(proof,burnTx,payouts); + importTx.vout.clear(); + importTx.vout.push_back(burnOut); +} +#endif UniValue getNotarisationsForBlock(const UniValue& params, bool fHelp) {