From 2d5537af0036596a91db7eb2313a25c6961ef7fc Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Dec 2018 00:59:35 -1100 Subject: [PATCH 01/12] Stubs for -ac_import --- src/cc/import.cpp | 119 ++++++++++++++++++++++++++++++++++++++--- src/crosschain.cpp | 13 ++++- src/komodo_globals.h | 4 +- src/komodo_utils.h | 38 +++++++++++-- src/rpc/crosschain.cpp | 19 ++++--- 5 files changed, 173 insertions(+), 20 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index b250bb7bf..c569ffaa8 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -25,7 +25,90 @@ * * This method should control every parameter of the ImportCoin transaction, since it has no signature * to protect it from malleability. + + ##### 0xffffffff is a special CCid for single chain/dual daemon imports */ + +extern std::string ASSETCHAINS_SELFIMPORT; +extern uint16_t ASSETCHAINS_CODAPORT,ASSETCHAINS_BEAMPORT; + +int32_t GetBEAMProof(TxProof &proof,CTransaction burnTx,uint256 hash) +{ + // confirm via ASSETCHAINS_BEAMPORT that burnTx/hash is a valid BEAM burn + return(-1); +} + +int32_t GetCODAProof(TxProof &proof,CTransaction burnTx,uint256 hash) +{ + // confirm via ASSETCHAINS_CODAPORT that burnTx/hash is a valid CODA burn + return(-1); +} + +int32_t GetPUBKEYProof(TxProof &proof,CTransaction burnTx,uint256 hash) +{ + // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 + return(-1); +} + +int32_t GetGATEWAYProof(TxProof &proof,CTransaction burnTx,uint256 hash) +{ + // external coin is the assetchains symbol in the burnTx OP_RETURN + return(-1); +} + +int32_t GetSelfimportProof(TxProof &proof,CTransaction burnTx,uint256 hash) // find burnTx with hash from "other" daemon +{ + if ( ASSETCHAINS_SELFIMPORT == "BEAM" ) + { + if ( GetBEAMproof(proof,burnTx,hash) < 0 ) + return(-1); + } + else if ( ASSETCHAINS_SELFIMPORT == "CODA" ) + { + if ( GetCODAproof(proof,burnTx,hash) < 0 ) + return(-1); + } + else if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) + { + if ( GetPUBKEYproof(proof,burnTx,hash) < 0 ) + return(-1); + } + else if ( ASSETCHAINS_SELFIMPORT == "GATEWAY" ) + { + if ( GetGATEWAYproof(proof,burnTx,hash) < 0 ) // extract source coin from burnTx opreturn + return(-1); + } + else return(-1); + return(0); +} + +// use proof from the above functions to validate the import + +int32_t CheckBEAMimport(TxProof proof,CTransaction burnTx,td::vector payouts) +{ + // check with dual-BEAM daemon via ASSETCHAINS_BEAMPORT for validity of burnTx + return(-1); +} + +int32_t CheckCODAimport(TxProof proof,CTransaction burnTx,td::vector payouts) +{ + // check with dual-CODA daemon via ASSETCHAINS_CODAPORT for validity of burnTx + return(-1); +} + +int32_t CheckGATEWAYimport(std::string coin,TxProof proof,CTransaction burnTx,td::vector payouts) +{ + // check for valid burn from external coin blockchain and if valid return(0); + return(-1); +} + +int32_t CheckPUBKEYimport(TxProof proof,CTransaction burnTx,td::vector payouts) +{ + // if burnTx has ASSETCHAINS_PUBKEY vin, it is valid return(0); + return(0); + return(-1); +} + bool Eval::ImportCoin(const std::vector params, const CTransaction &importTx, unsigned int nIn) { if (importTx.vout.size() < 2) @@ -52,12 +135,6 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCcid, payoutsHash)) return Invalid("invalid-burn-tx"); - if (targetCcid != GetAssetchainsCC() || targetSymbol != GetAssetchainsSymbol()) - return Invalid("importcoin-wrong-chain"); - - if (targetCcid < KOMODO_FIRSTFUNGIBLEID) - return Invalid("chain-not-fungible"); - // check burn amount { uint64_t burnAmount = burnTx.vout.back().nValue; @@ -74,13 +151,41 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp if (payoutsHash != SerializeHash(payouts)) return Invalid("wrong-payouts"); + if (targetCcid < KOMODO_FIRSTFUNGIBLEID) + return Invalid("chain-not-fungible"); + // Check proof confirms existance of burnTx + if ( targetCcid != 0xffffffff ) { + if (targetCcid != GetAssetchainsCC() || targetSymbol != GetAssetchainsSymbol()) + return Invalid("importcoin-wrong-chain"); uint256 target = proof.second.Exec(burnTx.GetHash()); if (!CheckMoMoM(proof.first, target)) return Invalid("momom-check-fail"); } - + else if ( ASSETCHAINS_SELFIMPORT == targetSymbol || ASSETCHAINS_SELFIMPORT == "GATEWAY" ) // various selfchain imports + { + if ( GetAssetchainsSymbol() == "BEAM" ) + { + if ( CheckBEAMimport(proof,burnTx,payouts) < 0 ) + return Invalid("BEAM-import-failure"); + } + else if ( GetAssetchainsSymbol() == "CODA" ) + { + if ( CheckCODAimport(proof,burnTx,payouts) < 0 ) + return Invalid("CODA-import-failure"); + } + else if ( GetAssetchainsSymbol() == "PUBKEY" ) + { + if ( CheckPUBKEYimport(proof,burnTx,payouts) < 0 ) + return Invalid("PUBKEY-import-failure"); + } + else + { + if ( CheckGATEWAYimport(GetAssetchainsSymbol(),proof,burnTx,payouts) < 0 ) + return Invalid("GATEWAY-import-failure"); + } + } return Valid(); } diff --git a/src/crosschain.cpp b/src/crosschain.cpp index e9444c607..806641f6a 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -26,6 +26,8 @@ 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 */ @@ -284,13 +286,20 @@ bool CheckMoMoM(uint256 kmdNotarisationHash, uint256 momom) * in: txid * out: pair */ -TxProof GetAssetchainProof(uint256 hash) + +TxProof GetAssetchainProof(uint256 hash,CTransaction burnTx) { int nIndex; 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_globals.h b/src/komodo_globals.h index 3e9b84db1..bd28d39f3 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -47,12 +47,12 @@ int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; -std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB; +std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB,ASSETCHAINS_SELFIMPORT; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW; bool VERUS_MINTBLOCKS; char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; -uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; +uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT,ASSETCHAINS_BEAMPORT,ASSETCHAINS_CODAPORT; uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC,KOMODO_STOPAT,KOMODO_DPOWCONFS = 1; uint32_t ASSETCHAINS_MAGIC = 2387029918; int64_t ASSETCHAINS_GENESISTXVAL = 5000000000; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 19941a172..2a3617748 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1773,6 +1773,30 @@ void komodo_args(char *argv0) ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0); ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey",""); ASSETCHAINS_SCRIPTPUB = GetArg("-ac_script",""); + ASSETCHAINS_BEAMPORT = GetArg("-ac_beam",0); + ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); + + ASSETCHAINS_SELFIMPORT = GetArg("-ac_import",""); // BEAM, CODA, PUBKEY, GATEWAY + if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" && strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) != 66 ) + { + fprintf(stderr,"invalid -ac_pubkey for -ac_import=PUBKEY\n"); + ASSETCHAINS_SELFIMPORT = ""; + } + else if ( ASSETCHAINS_SELFIMPORT == "BEAM" && ASSETCHAINS_BEAMPORT == 0 ) + { + fprintf(stderr,"missing -ac_beam for BEAM rpcport\n"); + ASSETCHAINS_SELFIMPORT = ""; + } + else if ( ASSETCHAINS_SELFIMPORT == "CODA" && ASSETCHAINS_CODAPORT == 0 ) + { + fprintf(stderr,"missing -ac_coda for CODA rpcport\n"); + ASSETCHAINS_SELFIMPORT = ""; + } + else if ( ASSETCHAINS_SELFIMPORT != "GATEWAY" ) + { + fprintf(stderr,"invalid -ac_import type\n"); + ASSETCHAINS_SELFIMPORT = ""; + } //ASSETCHAINS_FOUNDERS_PERIOD = GetArg("-ac_period",0); if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 ) @@ -1809,7 +1833,7 @@ void komodo_args(char *argv0) } else { - ASSETCHAINS_OVERRIDE_PUBKEY.clear(); + //ASSETCHAINS_OVERRIDE_PUBKEY.clear(); printf("-ac_perc must be set with -ac_pubkey\n"); } } @@ -1827,7 +1851,7 @@ void komodo_args(char *argv0) 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 ) + 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 ) { 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; @@ -1889,6 +1913,14 @@ void komodo_args(char *argv0) //extralen += iguana_rwnum(1,&extraptr[extralen],(int32_t)ASSETCHAINS_SCRIPTPUB.size(),(void *)ASSETCHAINS_SCRIPTPUB.c_str()); fprintf(stderr,"append ac_script %s\n",ASSETCHAINS_SCRIPTPUB.c_str()); } + if ( ASSETCHAINS_SELFIMPORT.size() > 0 ) + { + memcpy(&extraptr[extralen],(char *)ASSETCHAINS_SELFIMPORT.c_str(),ASSETCHAINS_SELFIMPORT.size()); + for (i=0; i 0 ) + { + if ( ASSETCHAINS_SELFIMPORT == targetSymbol || ASSETCHAINS_SELFIMPORT == "GATEWAY" ) + { + ccid = 0xffffffff; + } // else maybe clusters of self-import chains can be supported? + } + CTxOut burnOut = MakeBurnOutput(burnAmount, ccid, targetSymbol, tx.vout); UniValue ret(UniValue::VOBJ); ret.push_back(Pair("payouts", HexStr(E_MARSHAL(ss << tx.vout)))); tx.vout.clear(); @@ -229,7 +236,7 @@ UniValue migrate_createimporttransaction(const UniValue& params, bool fHelp) throw runtime_error("Couldn't parse payouts"); uint256 txid = burnTx.GetHash(); - TxProof proof = GetAssetchainProof(burnTx.GetHash()); + TxProof proof = GetAssetchainProof(burnTx.GetHash(),burnTx); CTransaction importTx = MakeImportCoinTransaction(proof, burnTx, payouts); return HexStr(E_MARSHAL(ss << importTx)); From ac96ea51783445f5c8a5db98bb90bea567d535b8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Dec 2018 01:09:24 -1100 Subject: [PATCH 02/12] std --- src/cc/import.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index c569ffaa8..e034d5fa5 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -84,25 +84,25 @@ int32_t GetSelfimportProof(TxProof &proof,CTransaction burnTx,uint256 hash) // f // use proof from the above functions to validate the import -int32_t CheckBEAMimport(TxProof proof,CTransaction burnTx,td::vector payouts) +int32_t CheckBEAMimport(TxProof proof,CTransaction burnTx,std::vector payouts) { // check with dual-BEAM daemon via ASSETCHAINS_BEAMPORT for validity of burnTx return(-1); } -int32_t CheckCODAimport(TxProof proof,CTransaction burnTx,td::vector payouts) +int32_t CheckCODAimport(TxProof proof,CTransaction burnTx,std::vector payouts) { // check with dual-CODA daemon via ASSETCHAINS_CODAPORT for validity of burnTx return(-1); } -int32_t CheckGATEWAYimport(std::string coin,TxProof proof,CTransaction burnTx,td::vector payouts) +int32_t CheckGATEWAYimport(std::string coin,TxProof proof,CTransaction burnTx,std::vector payouts) { // check for valid burn from external coin blockchain and if valid return(0); return(-1); } -int32_t CheckPUBKEYimport(TxProof proof,CTransaction burnTx,td::vector payouts) +int32_t CheckPUBKEYimport(TxProof proof,CTransaction burnTx,std::vector payouts) { // if burnTx has ASSETCHAINS_PUBKEY vin, it is valid return(0); return(0); From 75ecbdebb4cb1d46d5c0358692bd77fa5668cd77 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Dec 2018 01:11:03 -1100 Subject: [PATCH 03/12] selfimports --- src/cc/import.cpp | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index e034d5fa5..a5deea0cd 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -32,50 +32,26 @@ extern std::string ASSETCHAINS_SELFIMPORT; extern uint16_t ASSETCHAINS_CODAPORT,ASSETCHAINS_BEAMPORT; -int32_t GetBEAMProof(TxProof &proof,CTransaction burnTx,uint256 hash) -{ - // confirm via ASSETCHAINS_BEAMPORT that burnTx/hash is a valid BEAM burn - return(-1); -} - -int32_t GetCODAProof(TxProof &proof,CTransaction burnTx,uint256 hash) -{ - // confirm via ASSETCHAINS_CODAPORT that burnTx/hash is a valid CODA burn - return(-1); -} - -int32_t GetPUBKEYProof(TxProof &proof,CTransaction burnTx,uint256 hash) -{ - // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 - return(-1); -} - -int32_t GetGATEWAYProof(TxProof &proof,CTransaction burnTx,uint256 hash) -{ - // external coin is the assetchains symbol in the burnTx OP_RETURN - return(-1); -} - int32_t GetSelfimportProof(TxProof &proof,CTransaction burnTx,uint256 hash) // find burnTx with hash from "other" daemon { if ( ASSETCHAINS_SELFIMPORT == "BEAM" ) { - if ( GetBEAMproof(proof,burnTx,hash) < 0 ) + // confirm via ASSETCHAINS_BEAMPORT that burnTx/hash is a valid BEAM burn return(-1); } else if ( ASSETCHAINS_SELFIMPORT == "CODA" ) { - if ( GetCODAproof(proof,burnTx,hash) < 0 ) + // confirm via ASSETCHAINS_CODAPORT that burnTx/hash is a valid CODA burn return(-1); } else if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) { - if ( GetPUBKEYproof(proof,burnTx,hash) < 0 ) + // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 return(-1); } else if ( ASSETCHAINS_SELFIMPORT == "GATEWAY" ) { - if ( GetGATEWAYproof(proof,burnTx,hash) < 0 ) // extract source coin from burnTx opreturn + // external coin is the assetchains symbol in the burnTx OP_RETURN return(-1); } else return(-1); From 33f99eb34a7a7e99b572e0e79b1d04909c8ea565 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Dec 2018 01:12:37 -1100 Subject: [PATCH 04/12] Allow any ac_pubkey import for testing --- src/cc/import.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index a5deea0cd..4d61b4bf8 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -47,7 +47,7 @@ int32_t GetSelfimportProof(TxProof &proof,CTransaction burnTx,uint256 hash) // f else if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) { // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 - return(-1); + return(0); } else if ( ASSETCHAINS_SELFIMPORT == "GATEWAY" ) { From 141560e39adab62b3a4d185c093f17f8c0fadc63 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Dec 2018 01:14:33 -1100 Subject: [PATCH 05/12] Fix define --- src/crosschain.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crosschain.h b/src/crosschain.h index 1fbd7603a..57e4a79d0 100644 --- a/src/crosschain.h +++ b/src/crosschain.h @@ -5,7 +5,7 @@ /* On assetchain */ -TxProof GetAssetchainProof(uint256 hash); +TxProof GetAssetchainProof(uint256 hash,CTransaction burnTx); /* On KMD */ uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeight, From 722964362a4e1c2297fe8181dd417f6ce7606c6d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Dec 2018 08:28:37 -1100 Subject: [PATCH 06/12] Fix -ac_import --- src/komodo_utils.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 2a3617748..eeedf1949 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1777,10 +1777,13 @@ void komodo_args(char *argv0) ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); ASSETCHAINS_SELFIMPORT = GetArg("-ac_import",""); // BEAM, CODA, PUBKEY, GATEWAY - if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" && strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) != 66 ) + if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) { - fprintf(stderr,"invalid -ac_pubkey for -ac_import=PUBKEY\n"); - ASSETCHAINS_SELFIMPORT = ""; + if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) != 66 ) + { + fprintf(stderr,"invalid -ac_pubkey for -ac_import=PUBKEY\n"); + ASSETCHAINS_SELFIMPORT = ""; + } } else if ( ASSETCHAINS_SELFIMPORT == "BEAM" && ASSETCHAINS_BEAMPORT == 0 ) { @@ -1831,7 +1834,7 @@ void komodo_args(char *argv0) ASSETCHAINS_COMMISSION = 53846154; // maps to 35% printf("ASSETCHAINS_COMMISSION defaulted to 35%% when founders reward active\n"); } - else + else if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) { //ASSETCHAINS_OVERRIDE_PUBKEY.clear(); printf("-ac_perc must be set with -ac_pubkey\n"); From a3f0af586e63e81e62ae1f99792c71ff8f857849 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 28 Dec 2018 03:25:18 -1100 Subject: [PATCH 07/12] Check for -port --- src/crosschain.cpp | 9 --------- src/komodo_utils.h | 22 ++++++++++++++++++---- src/rpc/crosschain.cpp | 28 ++++++++++++++++++++++++++-- 3 files changed, 44 insertions(+), 15 deletions(-) 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) { From 6fdc83c22d716b29203af6b3d14a318a3a8c157b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 28 Dec 2018 03:27:13 -1100 Subject: [PATCH 08/12] Syntax --- src/komodo_utils.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index f0cecfe66..373b0d16a 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1955,11 +1955,10 @@ 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); - 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); + uint16_t tmpport = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); + if ( GetArg("-port",0) == 0 ) + ASSETCHAINS_P2PPORT = GetArg("-port",0); + else ASSETCHAINS_P2PPORT = tmpport; while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) { From df7b0fd17c841fbe68493831d46a0fa5c784c92f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 28 Dec 2018 03:30:25 -1100 Subject: [PATCH 09/12] KOMODO_FIRSTFUNGIBLEID --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 373b0d16a..b58fe3665 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1804,7 +1804,7 @@ void komodo_args(char *argv0) ASSETCHAINS_SELFIMPORT = ""; exit(0); } - if ( ASSETCHAINS_SELFIMPORT.size() > 0 && ASSETCHAINS_CC >= KOMODO_FIRST_FUNGIBLEID ) + if ( ASSETCHAINS_SELFIMPORT.size() > 0 && ASSETCHAINS_CC >= KOMODO_FIRSTFUNGIBLEID ) { fprintf(stderr,"selfimport chains cant be in a fungible cluster\n"); exit(0); From 0b2804b365c8d7a247a48191cabd3d5bc894ed0e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 28 Dec 2018 03:37:04 -1100 Subject: [PATCH 10/12] +print --- src/komodo_utils.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index b58fe3665..92e55fec5 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1957,8 +1957,10 @@ void komodo_args(char *argv0) //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); uint16_t tmpport = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); if ( GetArg("-port",0) == 0 ) + { ASSETCHAINS_P2PPORT = GetArg("-port",0); - else ASSETCHAINS_P2PPORT = tmpport; + fprintf(stderr,"set port.%u\n",ASSETCHAINS_P2PPORT); + } else ASSETCHAINS_P2PPORT = tmpport; while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) { From ca4d8cbceddd856e683dd88c417e0eb343ac928b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 28 Dec 2018 03:39:29 -1100 Subject: [PATCH 11/12] Set p2pport! --- src/komodo_utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 92e55fec5..5e25898b5 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1956,10 +1956,10 @@ void komodo_args(char *argv0) //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); uint16_t tmpport = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); - if ( GetArg("-port",0) == 0 ) + if ( GetArg("-port",0) != 0 ) { ASSETCHAINS_P2PPORT = GetArg("-port",0); - fprintf(stderr,"set port.%u\n",ASSETCHAINS_P2PPORT); + fprintf(stderr,"set p2pport.%u\n",ASSETCHAINS_P2PPORT); } else ASSETCHAINS_P2PPORT = tmpport; while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) From 6c23fd4159a98a7eee33dfb5350aa12e84bef27c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Dec 2018 00:59:36 -1100 Subject: [PATCH 12/12] Fix import tx CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); --- src/importcoin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/importcoin.cpp b/src/importcoin.cpp index d36943b5d..e6b5a166f 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -10,7 +10,7 @@ CTransaction MakeImportCoinTransaction(const TxProof proof, const CTransaction burnTx, const std::vector payouts) { std::vector payload = E_MARSHAL(ss << EVAL_IMPORTCOIN); - CMutableTransaction mtx; + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); mtx.vin.push_back(CTxIn(COutPoint(burnTx.GetHash(), 10e8), CScript() << payload)); mtx.vout = payouts; auto importData = E_MARSHAL(ss << proof; ss << burnTx);