Channels adaptation to TokensCC (#3)

* Initial changes

* ChannelsCC adaptation

* Fix

* Fix

* Fix

* Fix

* Fix

* Fix

* Fix

* Fix

* Fix

* Fix
This commit is contained in:
Mihailo Milenkovic
2019-01-16 14:05:54 +01:00
committed by dimxy
parent dae431eaa5
commit e23073fff5
5 changed files with 217 additions and 164 deletions

View File

@@ -5840,8 +5840,10 @@ UniValue channelsinfo(const UniValue& params, bool fHelp)
UniValue channelsopen(const UniValue& params, bool fHelp)
{
UniValue result(UniValue::VOBJ); int32_t numpayments; int64_t payment; std::vector<unsigned char> destpub; struct CCcontract_info *cp,C; std::string hex;
uint256 tokenid=zeroid;
cp = CCinit(&C,EVAL_CHANNELS);
if ( fHelp || params.size() != 3 )
if ( fHelp || params.size() < 3 || params.size() > 4)
throw runtime_error("channelsopen destpubkey numpayments payment\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");
@@ -5865,7 +5867,11 @@ UniValue channelsopen(const UniValue& params, bool fHelp)
ERR_RESULT("invalid payment amount, must be greater than 0");
return result;
}
hex = ChannelOpen(0,pubkey2pk(destpub),numpayments,payment);
if (params.size()==4)
{
tokenid=Parseuint256((char *)params[3].get_str().c_str());
}
hex = ChannelOpen(0,pubkey2pk(destpub),numpayments,payment,tokenid);
if ( hex.size() > 0 )
{
result.push_back(Pair("result", "success"));
@@ -5878,7 +5884,7 @@ UniValue channelspayment(const UniValue& params, bool fHelp)
{
UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid,secret=zeroid; int32_t n; int64_t amount;
cp = CCinit(&C,EVAL_CHANNELS);
if ( fHelp || params.size() != 2 )
if ( fHelp || params.size() < 2 || params.size() >3 )
throw runtime_error("channelspayment opentxid amount [secret]\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");
@@ -6979,7 +6985,6 @@ UniValue tokenbalance(const UniValue& params, bool fHelp)
UniValue result(UniValue::VOBJ); uint256 tokenid; uint64_t balance; std::vector<unsigned char> pubkey; struct CCcontract_info *cp,C;
CCerror.clear();
cp = CCinit(&C,EVAL_ASSETS);
if ( fHelp || params.size() > 2 )
throw runtime_error("tokenbalance tokenid [pubkey]\n");
if ( ensure_CCrequirements() < 0 )
@@ -6999,7 +7004,7 @@ UniValue tokenbalance(const UniValue& params, bool fHelp)
char destaddr[64];
result.push_back(Pair("result", "success"));
cp = CCinit(&C,EVAL_TOKENS);
if (GetCCaddress(cp, destaddr, pubkey2pk(pubkey)) != 0)
result.push_back(Pair("CCaddress", destaddr));