From 8811b8633f537623284f320722a1e416c8991be4 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 12 Dec 2019 20:21:06 -0500 Subject: [PATCH] Add src/cc upstream changes --- src/cc/CCGateways.h | 20 +- src/cc/CCOracles.h | 10 +- src/cc/CCPegs.h | 16 +- src/cc/CCPrices.h | 1 + src/cc/CCassetstx.cpp | 16 +- src/cc/CCchannels.h | 12 +- src/cc/CCfaucet.h | 4 +- src/cc/CCinclude.h | 894 +++++++++++++++++++++++++++++++++----- src/cc/CCrewards.h | 1 + src/cc/CCtokens.cpp | 3 +- src/cc/CCtx.cpp | 143 ++++-- src/cc/CCutilbits.cpp | 26 +- src/cc/CCutils.cpp | 13 +- src/cc/COptCCParams.cpp | 116 +++++ src/cc/cclib.cpp | 2 +- src/cc/channels.cpp | 239 +++------- src/cc/customcc.cpp | 2 +- src/cc/dapps/oraclefeed.c | 108 ++--- src/cc/eval.h | 2 +- src/cc/faucet.cpp | 34 +- src/cc/gateways.cpp | 487 +++++---------------- src/cc/heir.cpp | 312 ++++++------- src/cc/oracles.cpp | 215 +++++---- src/cc/payments.cpp | 7 + src/cc/pegs.cpp | 500 ++++++++------------- src/cc/rewards.cpp | 54 ++- 26 files changed, 1852 insertions(+), 1385 deletions(-) create mode 100644 src/cc/COptCCParams.cpp diff --git a/src/cc/CCGateways.h b/src/cc/CCGateways.h index 8dfed186f..8793c0dc4 100644 --- a/src/cc/CCGateways.h +++ b/src/cc/CCGateways.h @@ -20,16 +20,16 @@ #include "CCinclude.h" bool GatewaysValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); -std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector pubkeys,uint8_t p1,uint8_t p2,uint8_t p3,uint8_t p4); -std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std::string refcoin,uint256 cointxid,int32_t claimvout,std::string deposithex,std::vectorproof,CPubKey destpub,int64_t amount); -std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,uint256 deposittxid,CPubKey destpub,int64_t amount); -std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,CPubKey withdrawpub,int64_t amount); -std::string GatewaysPartialSign(uint64_t txfee,uint256 txidaddr,std::string refcoin,std::string hex); -std::string GatewaysCompleteSigning(uint64_t txfee,uint256 txidaddr,std::string refcoin,std::string hex); -std::string GatewaysMarkDone(uint64_t txfee,uint256 withdrawtxid,std::string refcoin); -UniValue GatewaysPendingDeposits(uint256 bindtxid,std::string refcoin); -UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin); -UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin); +UniValue GatewaysBind(const CPubKey& pk, uint64_t txfee,std::string coin,uint256 tokenid,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector pubkeys,uint8_t p1,uint8_t p2,uint8_t p3,uint8_t p4); +UniValue GatewaysDeposit(const CPubKey& pk, uint64_t txfee,uint256 bindtxid,int32_t height,std::string refcoin,uint256 cointxid,int32_t claimvout,std::string deposithex,std::vectorproof,CPubKey destpub,int64_t amount); +UniValue GatewaysClaim(const CPubKey& pk, uint64_t txfee,uint256 bindtxid,std::string refcoin,uint256 deposittxid,CPubKey destpub,int64_t amount); +UniValue GatewaysWithdraw(const CPubKey& pk, uint64_t txfee,uint256 bindtxid,std::string refcoin,CPubKey withdrawpub,int64_t amount); +UniValue GatewaysPartialSign(const CPubKey& pk, uint64_t txfee,uint256 txidaddr,std::string refcoin,std::string hex); +UniValue GatewaysCompleteSigning(const CPubKey& pk, uint64_t txfee,uint256 txidaddr,std::string refcoin,std::string hex); +UniValue GatewaysMarkDone(const CPubKey& pk, uint64_t txfee,uint256 withdrawtxid,std::string refcoin); +UniValue GatewaysPendingDeposits(const CPubKey& pk, uint256 bindtxid,std::string refcoin); +UniValue GatewaysPendingWithdraws(const CPubKey& pk, uint256 bindtxid,std::string refcoin); +UniValue GatewaysProcessedWithdraws(const CPubKey& pk, uint256 bindtxid,std::string refcoin); // CCcustom UniValue GatewaysInfo(uint256 bindtxid); diff --git a/src/cc/CCOracles.h b/src/cc/CCOracles.h index 2f2b702f4..10dbfae97 100644 --- a/src/cc/CCOracles.h +++ b/src/cc/CCOracles.h @@ -20,11 +20,11 @@ #include "CCinclude.h" bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); -std::string OracleCreate(int64_t txfee,std::string name,std::string description,std::string format); -std::string OracleFund(int64_t txfee,uint256 oracletxid); -std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee); -std::string OracleSubscribe(int64_t txfee,uint256 oracletxid,CPubKey publisher,int64_t amount); -std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector data); +UniValue OracleCreate(const CPubKey& pk, int64_t txfee,std::string name,std::string description,std::string format); +UniValue OracleFund(const CPubKey& pk, int64_t txfee,uint256 oracletxid); +UniValue OracleRegister(const CPubKey& pk, int64_t txfee,uint256 oracletxid,int64_t datafee); +UniValue OracleSubscribe(const CPubKey& pk, int64_t txfee,uint256 oracletxid,CPubKey publisher,int64_t amount); +UniValue OracleData(const CPubKey& pk, int64_t txfee,uint256 oracletxid,std::vector data); // CCcustom UniValue OracleDataSample(uint256 reforacletxid,uint256 txid); UniValue OracleDataSamples(uint256 reforacletxid,char* batonaddr,int32_t num); diff --git a/src/cc/CCPegs.h b/src/cc/CCPegs.h index e4d390d0e..78f1accac 100644 --- a/src/cc/CCPegs.h +++ b/src/cc/CCPegs.h @@ -22,14 +22,14 @@ bool PegsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom -std::string PegsCreate(uint64_t txfee,int64_t amount,std::vector bindtxids); -std::string PegsFund(uint64_t txfee,uint256 pegstxid, uint256 tokenid, int64_t amount); -std::string PegsGet(uint64_t txfee,uint256 pegstxid, uint256 tokenid, int64_t amount); -std::string PegsRedeem(uint64_t txfee,uint256 pegstxid, uint256 tokenid); -std::string PegsLiquidate(uint64_t txfee,uint256 pegstxid, uint256 tokenid, uint256 liquidatetxid); -std::string PegsExchange(uint64_t txfee,uint256 pegstxid, uint256 tokenid, int64_t amount); -UniValue PegsAccountHistory(uint256 pegstxid); -UniValue PegsAccountInfo(uint256 pegstxid); +UniValue PegsCreate(const CPubKey& pk,uint64_t txfee,int64_t amount,std::vector bindtxids); +UniValue PegsFund(const CPubKey& pk,uint64_t txfee,uint256 pegstxid, uint256 tokenid, int64_t amount); +UniValue PegsGet(const CPubKey& pk,uint64_t txfee,uint256 pegstxid, uint256 tokenid, int64_t amount); +UniValue PegsRedeem(const CPubKey& pk,uint64_t txfee,uint256 pegstxid, uint256 tokenid); +UniValue PegsLiquidate(const CPubKey& pk,uint64_t txfee,uint256 pegstxid, uint256 tokenid, uint256 liquidatetxid); +UniValue PegsExchange(const CPubKey& pk,uint64_t txfee,uint256 pegstxid, uint256 tokenid, int64_t amount); +UniValue PegsAccountHistory(const CPubKey& pk,uint256 pegstxid); +UniValue PegsAccountInfo(const CPubKey& pk,uint256 pegstxid); UniValue PegsWorstAccounts(uint256 pegstxid); UniValue PegsInfo(uint256 pegstxid); diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 3779111a6..554cf0eca 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -19,6 +19,7 @@ #include "komodo_defs.h" #include "CCinclude.h" + int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblocks); extern void GetKomodoEarlytxidScriptPub(); extern CScript KOMODO_EARLYTXID_SCRIPTPUB; diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 6788cbf1f..654f01a38 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -19,7 +19,6 @@ UniValue AssetOrders(uint256 refassetid, CPubKey pk, uint8_t additionalEvalCode) { - static uint256 zero; UniValue result(UniValue::VARR); struct CCcontract_info *cpAssets, assetsC; @@ -35,7 +34,7 @@ UniValue AssetOrders(uint256 refassetid, CPubKey pk, uint8_t additionalEvalCode) std::vector origpubkey; CTransaction ordertx; uint8_t funcid, evalCode; - char numstr[32], funcidstr[16], origaddr[64], origtokenaddr[64], assetidstr[65]; + char numstr[32], funcidstr[16], origaddr[64], origtokenaddr[64]; txid = it->first.txhash; LOGSTREAM("ccassets", CCLOG_DEBUG2, stream << "addOrders() checking txid=" << txid.GetHex() << std::endl); @@ -46,8 +45,8 @@ UniValue AssetOrders(uint256 refassetid, CPubKey pk, uint8_t additionalEvalCode) { LOGSTREAM("ccassets", CCLOG_DEBUG2, stream << "addOrders() checking ordertx.vout.size()=" << ordertx.vout.size() << " funcid=" << (char)(funcid ? funcid : ' ') << " assetid=" << assetid.GetHex() << std::endl); - if (refassetid != zero && assetid == refassetid || - pk != CPubKey() && pk == pubkey2pk(origpubkey) && (funcid == 'S' || funcid == 's')) + if (pk == CPubKey() && (refassetid == zeroid || assetid == refassetid) // tokenorders + || pk != CPubKey() && pk == pubkey2pk(origpubkey) && (funcid == 'S' || funcid == 's')) // mytokenorders, returns only asks (is this correct?) { LOGSTREAM("ccassets", CCLOG_DEBUG2, stream << "addOrders() it->first.index=" << it->first.index << " ordertx.vout[it->first.index].nValue=" << ordertx.vout[it->first.index].nValue << std::endl); @@ -61,7 +60,7 @@ UniValue AssetOrders(uint256 refassetid, CPubKey pk, uint8_t additionalEvalCode) funcidstr[0] = funcid; funcidstr[1] = 0; item.push_back(Pair("funcid", funcidstr)); - item.push_back(Pair("txid", uint256_str(assetidstr, txid))); + item.push_back(Pair("txid", txid.GetHex())); item.push_back(Pair("vout", (int64_t)it->first.index)); if (funcid == 'b' || funcid == 'B') { @@ -77,18 +76,17 @@ UniValue AssetOrders(uint256 refassetid, CPubKey pk, uint8_t additionalEvalCode) sprintf(numstr, "%llu", (long long)ordertx.vout[0].nValue); item.push_back(Pair("askamount", numstr)); } - if (origpubkey.size() == 33) + if (origpubkey.size() == CPubKey::COMPRESSED_PUBLIC_KEY_SIZE) { GetCCaddress(cp, origaddr, pubkey2pk(origpubkey)); item.push_back(Pair("origaddress", origaddr)); GetTokensCCaddress(cpTokens, origtokenaddr, pubkey2pk(origpubkey)); item.push_back(Pair("origtokenaddress", origtokenaddr)); - } if (assetid != zeroid) - item.push_back(Pair("tokenid", uint256_str(assetidstr, assetid))); + item.push_back(Pair("tokenid", assetid.GetHex())); if (assetid2 != zeroid) - item.push_back(Pair("otherid", uint256_str(assetidstr, assetid2))); + item.push_back(Pair("otherid", assetid2.GetHex())); if (price > 0) { if (funcid == 's' || funcid == 'S' || funcid == 'e' || funcid == 'e') diff --git a/src/cc/CCchannels.h b/src/cc/CCchannels.h index 10cb4d224..ecca145d3 100644 --- a/src/cc/CCchannels.h +++ b/src/cc/CCchannels.h @@ -21,12 +21,12 @@ #define CHANNELS_MAXPAYMENTS 1000 bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); -std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment,uint256 tokenid); -std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint256 secret); -std::string ChannelClose(uint64_t txfee,uint256 opentxid); -std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid); -UniValue ChannelsList(); +UniValue ChannelOpen(const CPubKey& pk,uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment,uint256 tokenid); +UniValue ChannelPayment(const CPubKey& pk,uint64_t txfee,uint256 opentxid,int64_t amount, uint256 secret); +UniValue ChannelClose(const CPubKey& pk,uint64_t txfee,uint256 opentxid); +UniValue ChannelRefund(const CPubKey& pk,uint64_t txfee,uint256 opentxid,uint256 closetxid); +UniValue ChannelsList(const CPubKey& pk); // CCcustom -UniValue ChannelsInfo(uint256 opentxid); +UniValue ChannelsInfo(const CPubKey& pk,uint256 opentxid); #endif diff --git a/src/cc/CCfaucet.h b/src/cc/CCfaucet.h index 3cb6c66e5..af3237ab1 100644 --- a/src/cc/CCfaucet.h +++ b/src/cc/CCfaucet.h @@ -25,8 +25,8 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom -std::string FaucetFund(uint64_t txfee,int64_t funds); -std::string FaucetGet(uint64_t txfee); +UniValue FaucetFund(const CPubKey& mypk,uint64_t txfee,int64_t funds); +UniValue FaucetGet(const CPubKey& mypk,uint64_t txfee); UniValue FaucetInfo(); #endif diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index a2bb65e48..1d28e2cc9 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -16,26 +16,43 @@ #ifndef CC_INCLUDE_H #define CC_INCLUDE_H -/* -there are only a very few types in bitcoin. pay to pubkey, pay to pubkey hash and pay to script hash -p2pk, p2pkh, p2sh -there are actually more that are possible, but those three are 99%+ of bitcoin transactions -so you can pay to a pubkey, or to its hash. or to a script's hash. the last is how most of the more complex scripts are invoked. to spend a p2sh vout, you need to provide the redeemscript, this script's hash is what the p2sh address was. -all of the above are the standard bitcoin vout types and there should be plenty of materials about it -Encrypted by a verified device -what I did with the CC contracts is created a fourth type of vout, the CC vout. this is using the cryptoconditions standard and it is even a different signature mechanism. ed25519 instead of secp256k1. it is basically a big extension to the bitcoin script. There is a special opcode that is added that says it is a CC script. +/*! \file CCinclude.h +\brief A Documented file. -but it gets more interesting -each CC script has an evalcode -this is just an arbitrary number. but what it does is allows to create a self-contained universe of CC utxo that all have the same evalcode and that is how a faucet CC differentiates itself from a dice CC, the eval code is different - -one effect from using a different eval code is that even if the rest of the CC script is the same, the bitcoin address that is calculated is different. what this means is that for each pubkey, there is a unique address for each different eval code! -and this allows efficient segregation of one CC contracts transactions from another -the final part that will make it all clear how the funds can be locked inside the contract. this is what makes a contract, a contract. I put both the privkey and pubkey for a randomly chosen address and associate it with each CC contract. That means anybody can sign outputs for that privkey. However, it is a CC output, so in addition to the signature, whatever constraints a CC contract implements must also be satistifed. This allows funds to be locked and yet anybody is able to spend it, assuming they satisfy the CC's rules - -one other technical note is that komodod has the insight-explorer extensions built in. so it can lookup directly all transactions to any address. this is a key performance boosting thing as if it wasnt there, trying to get all the utxo for an address not in the wallet is quite time consuming +Details. */ +/// \mainpage Brief introduction into cryptocondition contracts +/// There are only a very few types in bitcoin: pay to pubkey, pay to pubkey hash and pay to script hash (p2pk, p2pkh, p2sh). +/// There are actually more that are possible, but those three are 99%+ of bitcoin transactions. +/// So you can pay to a pubkey, or to its hash or to a script's hash. The last is how most of the more complex scripts are invoked. To spend a p2sh vout, you need to provide the redeemscript, +/// this script's hash is what the p2sh address was. +/// All of the above are the standard bitcoin vout types and there should be plenty of materials about it. +/// +/// What I did with the cryptoconditions (CC) contracts (now rebranded as Antara modules) is created a fourth type of vout, the CC vout. This is using the cryptoconditions standard and it is even a different signature mechanism, +/// ed25519 instead of secp256k1. It is basically a big extension to the bitcoin script. There is a special opcode that is added that says it is a CC script. +/// +/// But it gets more interesting. Each CC script has an evalcode. +/// This is just an arbitrary number but what it does is allows to create a self-contained universe of CC utxo that all have the same evalcode and that is +/// how a faucet CC contract differentiates itself from a dice CC contract, the eval code is different. +/// +/// One effect from using a different eval code is that even if the rest of the CC script is the same, the bitcoin address that is calculated is different. +/// What this means is that for each pubkey, there is a unique address for each different eval code! +/// And this allows efficient segregation of one CC contracts transactions from another. +/// The final part that will make it all clear how the funds can be locked inside the contract. +/// This is what makes a contract, a contract. +/// I put both the privkey and pubkey for a randomly chosen address and associate it with each CC contract. +/// That means anybody can sign outputs for that privkey. +/// However, it is a CC output, so in addition to the signature, whatever constraints a CC contract implements must also be satistifed. +/// This allows funds to be locked and yet anybody is able to spend it, assuming they satisfy the CC's rules. +/// +/// One other technical note is that komodod has the insight-explorer extensions built in +/// so it can lookup directly all transactions to any address. +/// This is a key performance boosting thing as if it wasnt there, trying to get all the utxo for an address not in the wallet is quite time consuming. +/// +/// More information about Antara framework: +/// https://developers.komodoplatform.com/basic-docs/start-here/about-komodo-platform/product-introductions.html#smart-chains-antara + #include #include