Token convert
This commit is contained in:
@@ -54,6 +54,8 @@ UniValue AssetInfo(uint256 tokenid);
|
|||||||
UniValue AssetList();
|
UniValue AssetList();
|
||||||
std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std::string description);
|
std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std::string description);
|
||||||
std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector<uint8_t> destpubkey,int64_t total);
|
std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector<uint8_t> destpubkey,int64_t total);
|
||||||
|
std::string AssetConvert(int64_t txfee,uint256 assetid,std::vector<uint8_t> destpubkey,int64_t total,int32_t evalcode);
|
||||||
|
|
||||||
std::string CreateBuyOffer(int64_t txfee,int64_t bidamount,uint256 assetid,int64_t pricetotal);
|
std::string CreateBuyOffer(int64_t txfee,int64_t bidamount,uint256 assetid,int64_t pricetotal);
|
||||||
std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid);
|
std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid);
|
||||||
std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t fillamount);
|
std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t fillamount);
|
||||||
|
|||||||
@@ -243,6 +243,33 @@ std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector<uint8_t> des
|
|||||||
return("");
|
return("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string AssetConvert(int64_t txfee,uint256 assetid,std::vector<uint8_t> destpubkey,int64_t total,int32_t evalcode)
|
||||||
|
{
|
||||||
|
CMutableTransaction mtx; CPubKey mypk; int64_t CCchange=0,inputs=0; struct CCcontract_info *cp,C;
|
||||||
|
if ( total < 0 )
|
||||||
|
{
|
||||||
|
fprintf(stderr,"negative total %lld\n",(long long)total);
|
||||||
|
return("");
|
||||||
|
}
|
||||||
|
cp = CCinit(&C,EVAL_ASSETS);
|
||||||
|
if ( txfee == 0 )
|
||||||
|
txfee = 10000;
|
||||||
|
mypk = pubkey2pk(Mypubkey());
|
||||||
|
if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 )
|
||||||
|
{
|
||||||
|
if ( (inputs= AddAssetInputs(cp,mtx,mypk,assetid,total,60)) > 0 )
|
||||||
|
{
|
||||||
|
if ( inputs > total )
|
||||||
|
CCchange = (inputs - total);
|
||||||
|
mtx.vout.push_back(MakeCC1vout(evalcode,total,pubkey2pk(destpubkey)));
|
||||||
|
if ( CCchange != 0 )
|
||||||
|
mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk));
|
||||||
|
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey())));
|
||||||
|
} else fprintf(stderr,"not enough CC asset inputs for %.8f\n",(double)total/COIN);
|
||||||
|
}
|
||||||
|
return("");
|
||||||
|
}
|
||||||
|
|
||||||
std::string CreateBuyOffer(int64_t txfee,int64_t bidamount,uint256 assetid,int64_t pricetotal)
|
std::string CreateBuyOffer(int64_t txfee,int64_t bidamount,uint256 assetid,int64_t pricetotal)
|
||||||
{
|
{
|
||||||
CMutableTransaction mtx; CPubKey mypk; struct CCcontract_info *cp,C; uint256 hashBlock; CTransaction vintx; std::vector<uint8_t> origpubkey; std::string name,description;
|
CMutableTransaction mtx; CPubKey mypk; struct CCcontract_info *cp,C; uint256 hashBlock; CTransaction vintx; std::vector<uint8_t> origpubkey; std::string name,description;
|
||||||
|
|||||||
@@ -474,7 +474,7 @@ std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t
|
|||||||
txfee = 10000;
|
txfee = 10000;
|
||||||
mypk = pubkey2pk(Mypubkey());
|
mypk = pubkey2pk(Mypubkey());
|
||||||
gatewayspk = GetUnspendable(cp,0);
|
gatewayspk = GetUnspendable(cp,0);
|
||||||
if ( _GetCCaddress(destaddr,EVAL_ASSETS,gatewayspk) == 0 )
|
if ( _GetCCaddress(destaddr,EVAL_GATEWAYS,gatewayspk) == 0 )
|
||||||
{
|
{
|
||||||
fprintf(stderr,"Gateway bind.%s (%s) cant create globaladdr\n",coin.c_str(),uint256_str(str,tokenid));
|
fprintf(stderr,"Gateway bind.%s (%s) cant create globaladdr\n",coin.c_str(),uint256_str(str,tokenid));
|
||||||
return("");
|
return("");
|
||||||
|
|||||||
@@ -454,6 +454,7 @@ static const CRPCCommand vRPCCommands[] =
|
|||||||
{ "tokens", "tokencancelask", &tokencancelask, true },
|
{ "tokens", "tokencancelask", &tokencancelask, true },
|
||||||
{ "tokens", "tokenfillask", &tokenfillask, true },
|
{ "tokens", "tokenfillask", &tokenfillask, true },
|
||||||
//{ "tokens", "tokenfillswap", &tokenfillswap, true },
|
//{ "tokens", "tokenfillswap", &tokenfillswap, true },
|
||||||
|
{ "tokens", "tokenconvert", &tokenconvert, true },
|
||||||
|
|
||||||
/* Address index */
|
/* Address index */
|
||||||
{ "addressindex", "getaddressmempool", &getaddressmempool, true },
|
{ "addressindex", "getaddressmempool", &getaddressmempool, true },
|
||||||
|
|||||||
@@ -221,6 +221,7 @@ extern UniValue tokenfillbid(const UniValue& params, bool fHelp);
|
|||||||
extern UniValue tokenask(const UniValue& params, bool fHelp);
|
extern UniValue tokenask(const UniValue& params, bool fHelp);
|
||||||
extern UniValue tokencancelask(const UniValue& params, bool fHelp);
|
extern UniValue tokencancelask(const UniValue& params, bool fHelp);
|
||||||
extern UniValue tokenfillask(const UniValue& params, bool fHelp);
|
extern UniValue tokenfillask(const UniValue& params, bool fHelp);
|
||||||
|
extern UniValue tokenconvert(const UniValue& params, bool fHelp);
|
||||||
extern UniValue mofnaddress(const UniValue& params, bool fHelp);
|
extern UniValue mofnaddress(const UniValue& params, bool fHelp);
|
||||||
extern UniValue channelsaddress(const UniValue& params, bool fHelp);
|
extern UniValue channelsaddress(const UniValue& params, bool fHelp);
|
||||||
extern UniValue oraclesaddress(const UniValue& params, bool fHelp);
|
extern UniValue oraclesaddress(const UniValue& params, bool fHelp);
|
||||||
|
|||||||
@@ -6279,6 +6279,42 @@ UniValue tokentransfer(const UniValue& params, bool fHelp)
|
|||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UniValue tokenconvert(const UniValue& params, bool fHelp)
|
||||||
|
{
|
||||||
|
UniValue result(UniValue::VOBJ); std::string hex; int32_t evalcode; int64_t amount; uint256 tokenid;
|
||||||
|
if ( fHelp || params.size() != 3 )
|
||||||
|
throw runtime_error("tokenconvert evalcode tokenid pubkey amount\n");
|
||||||
|
if ( ensure_CCrequirements() < 0 )
|
||||||
|
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||||
|
const CKeyStore& keystore = *pwalletMain;
|
||||||
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||||
|
evalcode = atoi(params[0].get_str().c_str());
|
||||||
|
tokenid = Parseuint256((char *)params[1].get_str().c_str());
|
||||||
|
std::vector<unsigned char> pubkey(ParseHex(params[2].get_str().c_str()));
|
||||||
|
amount = atol(params[3].get_str().c_str());
|
||||||
|
if ( tokenid == zeroid )
|
||||||
|
{
|
||||||
|
ERR_RESULT("invalid tokenid");
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
if ( amount <= 0 )
|
||||||
|
{
|
||||||
|
ERR_RESULT("amount must be positive");
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
hex = AssetConvert(0,tokenid,pubkey,amount,evalcode);
|
||||||
|
if (amount > 0) {
|
||||||
|
if ( hex.size() > 0 )
|
||||||
|
{
|
||||||
|
result.push_back(Pair("result", "success"));
|
||||||
|
result.push_back(Pair("hex", hex));
|
||||||
|
} else ERR_RESULT("couldnt convert tokens");
|
||||||
|
} else {
|
||||||
|
ERR_RESULT("amount must be positive");
|
||||||
|
}
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
UniValue tokenbid(const UniValue& params, bool fHelp)
|
UniValue tokenbid(const UniValue& params, bool fHelp)
|
||||||
{
|
{
|
||||||
UniValue result(UniValue::VOBJ); int64_t bidamount,numtokens; std::string hex; double price; uint256 tokenid;
|
UniValue result(UniValue::VOBJ); int64_t bidamount,numtokens; std::string hex; double price; uint256 tokenid;
|
||||||
|
|||||||
Reference in New Issue
Block a user