Browse Source

Merge branch 'duke' of https://git.hush.is/hush/hush3 into duke

duke
Duke 4 months ago
parent
commit
283066fda4
  1. 1
      src/Makefile.am
  2. 22
      src/cc/pegs.cpp
  3. 30
      src/rpc/server.cpp
  4. 15
      src/rpc/server.h
  5. 316
      src/wallet/rpcwallet.cpp

1
src/Makefile.am

@ -287,7 +287,6 @@ libbitcoin_server_a_SOURCES = \
cc/fsm.cpp \
cc/heir.cpp \
cc/oracles.cpp \
cc/pegs.cpp \
cc/payments.cpp \
cc/gateways.cpp \
cc/channels.cpp \

22
src/cc/pegs.cpp

@ -1,22 +0,0 @@
// Copyright (c) 2016-2023 The Hush developers
// Distributed under the GPLv3 software license, see the accompanying
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* SuperNET software, including this file may be copied, modified, propagated *
* or distributed except according to the terms contained in the LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
#include "../importcoin.h"
#include "key_io.h"
#include <gmp.h>

30
src/rpc/server.cpp

@ -356,19 +356,6 @@ static const CRPCCommand vRPCCommands[] =
{ "crosschain", "migrate_createnotaryapprovaltransaction", &migrate_createnotaryapprovaltransaction, true },
{ "crosschain", "selfimport", &selfimport, true },
{ "crosschain", "importdual", &importdual, true },
//ImportGateway
{ "crosschain", "importgatewayddress", &importgatewayaddress, true },
{ "crosschain", "importgatewayinfo", &importgatewayinfo, true },
{ "crosschain", "importgatewaybind", &importgatewaybind, true },
{ "crosschain", "importgatewaydeposit", &importgatewaydeposit, true },
{ "crosschain", "importgatewaywithdraw", &importgatewaywithdraw, true },
{ "crosschain", "importgatewaypartialsign", &importgatewaypartialsign, true },
{ "crosschain", "importgatewaycompletesigning", &importgatewaycompletesigning, true },
{ "crosschain", "importgatewaymarkdone", &importgatewaymarkdone, true },
{ "crosschain", "importgatewaypendingwithdraws", &importgatewaypendingwithdraws, true },
{ "crosschain", "importgatewayprocessed", &importgatewayprocessed, true },
/* Mining */
{ "mining", "getblocktemplate", &getblocktemplate, true },
@ -489,23 +476,6 @@ static const CRPCCommand vRPCCommands[] =
{ "CClib", "cclibinfo", &cclibinfo, true },
{ "CClib", "cclib", &cclib, true },
// Gateways
{ "gateways", "gatewaysaddress", &gatewaysaddress, true },
{ "gateways", "gatewayslist", &gatewayslist, true },
{ "gateways", "gatewaysexternaladdress", &gatewaysexternaladdress, true },
{ "gateways", "gatewaysdumpprivkey", &gatewaysdumpprivkey, true },
{ "gateways", "gatewaysinfo", &gatewaysinfo, true },
{ "gateways", "gatewaysbind", &gatewaysbind, true },
{ "gateways", "gatewaysdeposit", &gatewaysdeposit, true },
{ "gateways", "gatewaysclaim", &gatewaysclaim, true },
{ "gateways", "gatewayswithdraw", &gatewayswithdraw, true },
{ "gateways", "gatewayspartialsign", &gatewayspartialsign, true },
{ "gateways", "gatewayscompletesigning", &gatewayscompletesigning, true },
{ "gateways", "gatewaysmarkdone", &gatewaysmarkdone, true },
{ "gateways", "gatewayspendingdeposits", &gatewayspendingdeposits, true },
{ "gateways", "gatewayspendingwithdraws", &gatewayspendingwithdraws, true },
{ "gateways", "gatewaysprocessed", &gatewaysprocessed, true },
// dice
{ "dice", "dicelist", &dicelist, true },
{ "dice", "diceinfo", &diceinfo, true },

15
src/rpc/server.h

@ -284,21 +284,6 @@ extern UniValue payments_list(const UniValue& params, bool fHelp, const CPubKey&
extern UniValue cclibaddress(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue cclibinfo(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue cclib(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue gatewaysaddress(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue gatewayslist(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue gatewaysinfo(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue gatewaysdumpprivkey(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue gatewaysexternaladdress(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue gatewaysbind(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue gatewaysdeposit(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue gatewaysclaim(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue gatewayswithdraw(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue gatewayspartialsign(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue gatewayscompletesigning(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue gatewaysmarkdone(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue gatewayspendingdeposits(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue gatewayspendingwithdraws(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue gatewaysprocessed(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue channelslist(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue channelsinfo(const UniValue& params, bool fHelp, const CPubKey& mypk);
extern UniValue channelsopen(const UniValue& params, bool fHelp, const CPubKey& mypk);

316
src/wallet/rpcwallet.cpp

@ -6486,19 +6486,6 @@ UniValue paymentsaddress(const UniValue& params, bool fHelp, const CPubKey& mypk
return(CCaddress(cp,(char *)"Payments",pubkey));
}
UniValue gatewaysaddress(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
struct CCcontract_info *cp,C; std::vector<unsigned char> pubkey;
cp = CCinit(&C,EVAL_GATEWAYS);
if ( fHelp || params.size() > 1 )
throw runtime_error("gatewaysaddress [pubkey]\n");
if ( ensure_CCrequirements(cp->evalcode) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
if ( params.size() == 1 )
pubkey = ParseHex(params[0].get_str().c_str());
return(CCaddress(cp,(char *)"Gateways",pubkey));
}
UniValue heiraddress(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
struct CCcontract_info *cp,C; std::vector<unsigned char> pubkey;
@ -6617,19 +6604,6 @@ UniValue tokenaddress(const UniValue& params, bool fHelp, const CPubKey& mypk)
return(CCaddress(cp,(char *)"Tokens", pubkey));
}
UniValue importgatewayaddress(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
struct CCcontract_info *cp,C; std::vector<unsigned char> pubkey;
cp = CCinit(&C,EVAL_IMPORTGATEWAY);
if ( fHelp || params.size() > 1 )
throw runtime_error("importgatewayddress [pubkey]\n");
if ( ensure_CCrequirements(cp->evalcode) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
if ( params.size() == 1 )
pubkey = ParseHex(params[0].get_str().c_str());
return(CCaddress(cp,(char *)"ImportGateway", pubkey));
}
UniValue channelslist(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
if ( fHelp || params.size() > 0 )
@ -6929,297 +6903,7 @@ UniValue rewardsinfo(const UniValue& params, bool fHelp, const CPubKey& mypk)
return(RewardsInfo(fundingtxid));
}
UniValue gatewayslist(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
if ( fHelp || params.size() > 0 )
throw runtime_error("gatewayslist\n");
if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
const CKeyStore& keystore = *pwalletMain;
return(GatewaysList());
}
UniValue gatewaysexternaladdress(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
uint256 bindtxid; CPubKey pubkey;
if ( fHelp || params.size() != 2)
throw runtime_error("gatewaysexternaladdress bindtxid pubkey\n");
if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
bindtxid = Parseuint256((char *)params[0].get_str().c_str());
pubkey = ParseHex(params[1].get_str().c_str());
return(GatewaysExternalAddress(bindtxid,pubkey));
}
UniValue gatewaysdumpprivkey(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
uint256 bindtxid;
if ( fHelp || params.size() != 2)
throw runtime_error("gatewaysdumpprivkey bindtxid address\n");
if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
bindtxid = Parseuint256((char *)params[0].get_str().c_str());
std::string strAddress = params[1].get_str();
CTxDestination dest = DecodeDestination(strAddress);
if (!IsValidDestination(dest)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid transparent address");
}
const CKeyID *keyID = boost::get<CKeyID>(&dest);
if (!keyID) {
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key");
}
CKey vchSecret;
if (!pwalletMain->GetKey(*keyID, vchSecret)) {
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known");
}
return(GatewaysDumpPrivKey(bindtxid,vchSecret));
}
UniValue gatewaysinfo(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
uint256 txid;
if ( fHelp || params.size() != 1 )
throw runtime_error("gatewaysinfo bindtxid\n");
if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
txid = Parseuint256((char *)params[0].get_str().c_str());
return(GatewaysInfo(txid));
}
UniValue gatewaysbind(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
UniValue result(UniValue::VOBJ); uint256 tokenid,oracletxid; int32_t i; int64_t totalsupply; std::vector<CPubKey> pubkeys;
uint8_t M,N,p1,p2,p3,p4=0; std::string coin; std::vector<unsigned char> pubkey;
if ( fHelp || params.size() < 10 )
throw runtime_error("gatewaysbind tokenid oracletxid coin tokensupply M N pubkey(s) pubtype p2shtype wiftype [taddr]\n");
if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
Lock2NSPV(mypk);
tokenid = Parseuint256((char *)params[0].get_str().c_str());
oracletxid = Parseuint256((char *)params[1].get_str().c_str());
coin = params[2].get_str();
totalsupply = atol((char *)params[3].get_str().c_str());
M = atoi((char *)params[4].get_str().c_str());
N = atoi((char *)params[5].get_str().c_str());
if ( M > N || N == 0 || N > 15 || totalsupply < COIN/100 || tokenid == zeroid )
{
Unlock2NSPV(mypk);
throw runtime_error("illegal M or N > 15 or tokensupply or invalid tokenid\n");
}
if ( params.size() < 6+N+3 )
{
Unlock2NSPV(mypk);
throw runtime_error("not enough parameters for N pubkeys\n");
}
for (i=0; i<N; i++)
{
pubkey = ParseHex(params[6+i].get_str().c_str());
if (pubkey.size()!= 33)
{
Unlock2NSPV(mypk);
throw runtime_error("invalid destination pubkey");
}
pubkeys.push_back(pubkey2pk(pubkey));
}
p1 = atoi((char *)params[6+N].get_str().c_str());
p2 = atoi((char *)params[6+N+1].get_str().c_str());
p3 = atoi((char *)params[6+N+2].get_str().c_str());
if (params.size() == 9+N+1) p4 = atoi((char *)params[9+N].get_str().c_str());
result = GatewaysBind(mypk,0,coin,tokenid,totalsupply,oracletxid,M,N,pubkeys,p1,p2,p3,p4);
if ( result[JSON_HEXTX].getValStr().size() > 0 )
{
result.push_back(Pair("result", "success"));
}
Unlock2NSPV(mypk);
return(result);
}
UniValue gatewaysdeposit(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
UniValue result(UniValue::VOBJ); int32_t i,claimvout,height; int64_t amount; std::string coin,deposithex; uint256 bindtxid,cointxid; std::vector<uint8_t>proof,destpub,pubkey;
if ( fHelp || params.size() != 9 )
throw runtime_error("gatewaysdeposit bindtxid height coin cointxid claimvout deposithex proof destpub amount\n");
if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
Lock2NSPV(mypk);
bindtxid = Parseuint256((char *)params[0].get_str().c_str());
height = atoi((char *)params[1].get_str().c_str());
coin = params[2].get_str();
cointxid = Parseuint256((char *)params[3].get_str().c_str());
claimvout = atoi((char *)params[4].get_str().c_str());
deposithex = params[5].get_str();
proof = ParseHex(params[6].get_str());
destpub = ParseHex(params[7].get_str());
amount = atof((char *)params[8].get_str().c_str()) * COIN + 0.00000000499999;
if ( amount <= 0 || claimvout < 0 )
{
Unlock2NSPV(mypk);
throw runtime_error("invalid param: amount, numpks or claimvout\n");
}
if (destpub.size()!= 33)
{
Unlock2NSPV(mypk);
throw runtime_error("invalid destination pubkey");
}
result = GatewaysDeposit(mypk,0,bindtxid,height,coin,cointxid,claimvout,deposithex,proof,pubkey2pk(destpub),amount);
if ( result[JSON_HEXTX].getValStr().size() > 0 )
{
result.push_back(Pair("result", "success"));
}
Unlock2NSPV(mypk);
return(result);
}
UniValue gatewaysclaim(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
UniValue result(UniValue::VOBJ); std::string coin; uint256 bindtxid,deposittxid; std::vector<uint8_t>destpub; int64_t amount;
if ( fHelp || params.size() != 5 )
throw runtime_error("gatewaysclaim bindtxid coin deposittxid destpub amount\n");
if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
Lock2NSPV(mypk);
bindtxid = Parseuint256((char *)params[0].get_str().c_str());
coin = params[1].get_str();
deposittxid = Parseuint256((char *)params[2].get_str().c_str());
destpub = ParseHex(params[3].get_str());
amount = atof((char *)params[4].get_str().c_str()) * COIN + 0.00000000499999;
if (destpub.size()!= 33)
{
Unlock2NSPV(mypk);
throw runtime_error("invalid destination pubkey");
}
result = GatewaysClaim(mypk,0,bindtxid,coin,deposittxid,pubkey2pk(destpub),amount);
if ( result[JSON_HEXTX].getValStr().size() > 0 )
{
result.push_back(Pair("result", "success"));
}
Unlock2NSPV(mypk);
return(result);
}
UniValue gatewayswithdraw(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
UniValue result(UniValue::VOBJ); uint256 bindtxid; int64_t amount; std::string coin; std::vector<uint8_t> withdrawpub;
if ( fHelp || params.size() != 4 )
throw runtime_error("gatewayswithdraw bindtxid coin withdrawpub amount\n");
if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
Lock2NSPV(mypk);
bindtxid = Parseuint256((char *)params[0].get_str().c_str());
coin = params[1].get_str();
withdrawpub = ParseHex(params[2].get_str());
amount = atof((char *)params[3].get_str().c_str()) * COIN + 0.00000000499999;
if (withdrawpub.size()!= 33)
{
Unlock2NSPV(mypk);
throw runtime_error("invalid destination pubkey");
}
result = GatewaysWithdraw(mypk,0,bindtxid,coin,pubkey2pk(withdrawpub),amount);
if ( result[JSON_HEXTX].getValStr().size() > 0 )
{
result.push_back(Pair("result", "success"));
}
Lock2NSPV(mypk);
return(result);
}
UniValue gatewayspartialsign(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
UniValue result(UniValue::VOBJ); std::string coin,parthex; uint256 txid;
if ( fHelp || params.size() != 3 )
throw runtime_error("gatewayspartialsign txidaddr refcoin hex\n");
if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
Lock2NSPV(mypk);
txid = Parseuint256((char *)params[0].get_str().c_str());
coin = params[1].get_str();
parthex = params[2].get_str();
result = GatewaysPartialSign(mypk,0,txid,coin,parthex);
if ( result[JSON_HEXTX].getValStr().size() > 0 )
{
result.push_back(Pair("result", "success"));
}
Unlock2NSPV(mypk);
return(result);
}
UniValue gatewayscompletesigning(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
UniValue result(UniValue::VOBJ); uint256 withdrawtxid; std::string txhex,coin;
if ( fHelp || params.size() != 3 )
throw runtime_error("gatewayscompletesigning withdrawtxid coin hex\n");
if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
Lock2NSPV(mypk);
withdrawtxid = Parseuint256((char *)params[0].get_str().c_str());
coin = params[1].get_str();
txhex = params[2].get_str();
result = GatewaysCompleteSigning(mypk,0,withdrawtxid,coin,txhex);
if ( result[JSON_HEXTX].getValStr().size() > 0 )
{
result.push_back(Pair("result", "success"));
}
Unlock2NSPV(mypk);
return(result);
}
UniValue gatewaysmarkdone(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
UniValue result(UniValue::VOBJ); uint256 completetxid; std::string coin;
if ( fHelp || params.size() != 2 )
throw runtime_error("gatewaysmarkdone completesigningtx coin\n");
if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
Lock2NSPV(mypk);
completetxid = Parseuint256((char *)params[0].get_str().c_str());
coin = params[1].get_str();
result = GatewaysMarkDone(mypk,0,completetxid,coin);
if ( result[JSON_HEXTX].getValStr().size() > 0 )
{
result.push_back(Pair("result", "success"));
}
Unlock2NSPV(mypk);
return(result);
}
UniValue gatewayspendingdeposits(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
uint256 bindtxid; std::string coin;
if ( fHelp || params.size() != 2 )
throw runtime_error("gatewayspendingdeposits bindtxid coin\n");
if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
bindtxid = Parseuint256((char *)params[0].get_str().c_str());
coin = params[1].get_str();
return(GatewaysPendingDeposits(mypk,bindtxid,coin));
}
UniValue gatewayspendingwithdraws(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
uint256 bindtxid; std::string coin;
if ( fHelp || params.size() != 2 )
throw runtime_error("gatewayspendingwithdraws bindtxid coin\n");
if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
bindtxid = Parseuint256((char *)params[0].get_str().c_str());
coin = params[1].get_str();
return(GatewaysPendingWithdraws(mypk,bindtxid,coin));
}
UniValue gatewaysprocessed(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
uint256 bindtxid; std::string coin;
if ( fHelp || params.size() != 2 )
throw runtime_error("gatewaysprocessed bindtxid coin\n");
if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
bindtxid = Parseuint256((char *)params[0].get_str().c_str());
coin = params[1].get_str();
return(GatewaysProcessedWithdraws(mypk,bindtxid,coin));
}
UniValue oracleslist(const UniValue& params, bool fHelp, const CPubKey& mypk)
{

Loading…
Cancel
Save