From 5963c84f369e633f163b4860b249ace5ef4fdd33 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 21 Jul 2018 04:31:00 -1100 Subject: [PATCH] Bid --- src/cc/assets.cpp | 27 +++++++++++++-------------- src/wallet/rpcwallet.cpp | 23 +++++++++++++++++++---- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index ef4466e68..492363e96 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -61,7 +61,7 @@ extern uint8_t NOTARY_PUBKEY33[33]; vin.0: normal input vout.0: issuance assetoshis to CC vout.1: normal output for change (if any) - vout.n-1: opreturn [EVAL_ASSETS] ['c'] [{"":""}] + vout.n-1: opreturn [EVAL_ASSETS] ['c'] [origpubkey] "" "" transfer vin.0: normal input @@ -191,10 +191,10 @@ CPubKey GetUnspendable(uint8_t evalcode,uint8_t *unspendablepriv) return(pubkey2pk(ParseHex(Unspendablehex))); } -CScript EncodeCreateOpRet(uint8_t funcid,std::string name,std::string description) +CScript EncodeCreateOpRet(uint8_t funcid,std::vector origpubkey,std::string name,std::string description) { CScript opret; uint8_t evalcode = EVAL_ASSETS; - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << name << description); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << origpubkey << name << description); return(opret); } @@ -611,8 +611,7 @@ bool SetFillamounts(uint64_t &paid,uint64_t &remaining_price,uint64_t orig_nValu uint64_t AddCCinputs(CMutableTransaction &mtx,CPubKey mypk,uint256 assetid,uint64_t total) { uint64_t totalinputs = 0; - //for (i=0; i mypubkey,uint64_t txfee,uint64_t as if ( AddNormalinputs(mtx,mypk,assetsupply+txfee,64) > 0 ) { mtx.vout.push_back(MakeAssetsVout(assetsupply,mypk)); - return(FinalizeCCTx(EVAL_ASSETS,mtx,mypk,txfee,EncodeCreateOpRet('c',name,description))); + return(FinalizeCCTx(EVAL_ASSETS,mtx,mypk,txfee,EncodeCreateOpRet('c',mypubkey,name,description))); } return(0); } -std::string CreateAssetTransfer(std::vector mypubkey,uint64_t txfee,uint256 assetid,std::vectoroutputs,std::vectoramounts) +std::string CreateAssetTransfer(uint64_t txfee,uint256 assetid,std::vectoroutputs,std::vectoramounts) { CMutableTransaction mtx; CPubKey mypk; int32_t i,n; uint64_t CCchange=0,inputs=0,total=0; if ( txfee == 0 ) txfee = 10000; - mypk = pubkey2pk(mypubkey); + mypk = pubkey2pk(Mypubkey()); if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) { n = outputs.size(); @@ -688,12 +687,12 @@ std::string CreateAssetTransfer(std::vector mypubkey,uint64_t txfee,uin return(0); } -std::string CreateBuyOffer(std::vector mypubkey,uint64_t txfee,uint64_t bidamount,uint256 assetid,uint64_t pricetotal) +std::string CreateBuyOffer(uint64_t txfee,uint64_t bidamount,uint256 assetid,uint64_t pricetotal) { CMutableTransaction mtx; CPubKey mypk; if ( txfee == 0 ) txfee = 10000; - mypk = pubkey2pk(mypubkey); + mypk = pubkey2pk(Mypubkey()); if ( AddNormalinputs(mtx,mypk,bidamount+txfee,64) > 0 ) { mtx.vout.push_back(CTxOut(bidamount,CScript() << ParseHex(Unspendablehex) << OP_CHECKSIG)); @@ -702,12 +701,12 @@ std::string CreateBuyOffer(std::vector mypubkey,uint64_t txfee,uint64_t return(0); } -std::string CancelBuyOffer(std::vector mypubkey,uint64_t txfee,uint256 bidtxid) +std::string CancelBuyOffer(uint64_t txfee,uint256 bidtxid) { CMutableTransaction mtx; CTransaction vintx; uint256 hashBlock; uint64_t bidamount; CPubKey mypk; if ( txfee == 0 ) txfee = 10000; - mypk = pubkey2pk(mypubkey); + mypk = pubkey2pk(Mypubkey()); if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) { if ( GetTransaction(bidtxid,vintx,hashBlock,false) != 0 ) @@ -721,12 +720,12 @@ std::string CancelBuyOffer(std::vector mypubkey,uint64_t txfee,uint256 return(0); } -std::string FillBuyOffer(std::vector mypubkey,uint64_t txfee,uint256 assetid,uint256 bidtxid,uint256 filltxid,int32_t fillvout) +std::string FillBuyOffer(uint64_t txfee,uint256 assetid,uint256 bidtxid,uint256 filltxid,int32_t fillvout) { CTransaction vintx,filltx; uint256 hashBlock; CMutableTransaction mtx; CPubKey mypk; std::vector origpubkey,tmppubkey; int32_t bidvout=0; uint64_t tmpprice,origprice,bidamount,paid_amount,fillamount,remaining_required; if ( txfee == 0 ) txfee = 10000; - mypk = pubkey2pk(mypubkey); + mypk = pubkey2pk(Mypubkey()); if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) { if ( GetTransaction(bidtxid,vintx,hashBlock,false) != 0 && GetTransaction(filltxid,filltx,hashBlock,false) != 0 ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 93ccfa19a..6ed2bc180 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4830,8 +4830,11 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt return(siglen); } -std::string CreateAsset(std::vector mypubkey,uint64_t txfee,uint64_t assetsupply,std::string name,std::string description); -std::vector Mypubkey(); +std::string CreateAsset(uint64_t txfee,uint64_t assetsupply,std::string name,std::string description); +std::string CreateAssetTransfer(uint64_t txfee,uint256 assetid,std::vectoroutputs,std::vectoramounts); +std::string CreateBuyOffer(uint64_t txfee,uint64_t bidamount,uint256 assetid,uint64_t pricetotal); +std::string CancelBuyOffer(uint64_t txfee,uint256 bidtxid); +std::string FillBuyOffer(uint64_t txfee,uint256 assetid,uint256 bidtxid,uint256 filltxid,int32_t fillvout); UniValue tokencreate(const UniValue& params, bool fHelp) { @@ -4842,7 +4845,7 @@ UniValue tokencreate(const UniValue& params, bool fHelp) supply = atof(params[1].get_str().c_str()) * COIN; if ( params.size() == 3 ) description = params[2].get_str(); - hex = CreateAsset(Mypubkey(),0,supply,name,description); + hex = CreateAsset(0,supply,name,description); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); @@ -4859,7 +4862,19 @@ UniValue tokentransfer(const UniValue& params, bool fHelp) UniValue tokenbid(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); + uint64_t bidamount; double price; uint256 tokenid; + if ( fHelp || params.size() != 3 ) + throw runtime_error("tokenbid numtokens tokenid price\n"); + numtokens = atoi(params[0].get_str().c_str()); + tokenid = ParseHex(params[1].get_str()); + price = atof(params[2].get_str().c_str()); + bidamount = (price * numtokens) * COIN; + hex = CreateBuyOffer(0,bidamount,tokenid,numtokens); + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else result.push_back(Pair("error", "could create bid")); return(result); }