Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
giaki3003 committed Nov 20, 2020
2 parents 6a75676 + e249efe commit eddb52a
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 3 deletions.
98 changes: 97 additions & 1 deletion src/rpc/infinitynode.cpp
Expand Up @@ -655,6 +655,102 @@ static UniValue infinitynodeburnfund(const JSONRPCRequest& request)
return results;
}

/**
* @xtdevcoin co-authored by @giaki3003
* this function help user burn correctly their funds to run infinity node
* (giaki3003) from an array of inputs, without signing
*/
static UniValue infinitynodeburnfund_external(const JSONRPCRequest& request)
{

if (request.fHelp || request.params.size() != 4)
throw std::runtime_error(
"infinitynodeburnfund NodeOwnerAddress amount SINBackupAddress"
"\nSend an amount to BurnAddress.\n"
"\nArguments:\n"
"1. \"inputs\" (array, required) A json array of json objects\n"
" [\n"
" {\n"
" \"txid\":\"id\", (string, required) The transaction id\n"
" \"vout\":n, (numeric, required) The output number\n"
" \"sequence\":n (numeric, optional) The sequence number\n"
" } \n"
" ,...\n"
" ]\n"
"2. \"NodeOwnerAddress\" (string, required) Address of Collateral.\n"
"3. \"amount\" (numeric or string, required) The amount in " + CURRENCY_UNIT + " to send for making an InfinityNode. eg 1000000\n"
"4. \"SINBackupAddress\" (string, required) The SIN address to send to when you make a notification(new feature soon).\n"
"\nResult:\n"
"\"BURNtxid\" (string) The burn transaction id. Needed to run infinity node\n"
"\"CollateralAddress\" (string) Collateral. Please send 10000" + CURRENCY_UNIT + " to this address.\n"
"\nExamples:\n"
+ HelpExampleCli("infinitynodeburnfund", "NodeOwnerAddress 1000000 SINBackupAddress")
);

std::string strError;

RPCTypeCheck(request.params, {
UniValue::VARR,
UniValue::VSTR,
UniValue::VSTR,
UniValue::VSTR
}, true
);

UniValue results(UniValue::VARR);
UniValue entry(UniValue::VOBJ);
// Amount

CTxDestination NodeOwnerAddress = DecodeDestination(request.params[1].get_str());
if (!IsValidDestination(NodeOwnerAddress))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid SIN address as NodeOwnerAddress");

CAmount nAmount = AmountFromValue(request.params[2]);
if (nAmount != Params().GetConsensus().nMasternodeBurnSINNODE_1 * COIN &&
nAmount != Params().GetConsensus().nMasternodeBurnSINNODE_5 * COIN &&
nAmount != Params().GetConsensus().nMasternodeBurnSINNODE_10 * COIN)
{
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount to burn and run an InfinityNode");
}

CTxDestination BKaddress = DecodeDestination(request.params[3].get_str());
if (!IsValidDestination(BKaddress))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid SIN address as SINBackupAddress");

std::map<COutPoint, CInfinitynode> mapInfinitynodes = infnodeman.GetFullInfinitynodeMap();
int totalNode = 0, totalBIG = 0, totalMID = 0, totalLIL = 0, totalUnknown = 0;
for (auto& infpair : mapInfinitynodes) {
++totalNode;
CInfinitynode inf = infpair.second;
int sintype = inf.getSINType();
if (sintype == 10) ++totalBIG;
else if (sintype == 5) ++totalMID;
else if (sintype == 1) ++totalLIL;
else ++totalUnknown;
}

// BurnAddress
CTxDestination dest = DecodeDestination(Params().GetConsensus().cBurnAddress);
CScript scriptPubKeyBurnAddress = GetScriptForDestination(dest);
std::vector<std::vector<unsigned char> > vSolutions;
txnouttype whichType;
if (!Solver(scriptPubKeyBurnAddress, whichType, vSolutions))
return false;
CKeyID keyid = CKeyID(uint160(vSolutions[0]));
CScript script;
script = GetScriptForBurn(keyid, request.params[3].get_str());

CMutableTransaction rawMetaTx = ConstructTransactionWithScript(request.params[0], script);

entry.pushKV("rawMetaTx", EncodeHexTx(rawMetaTx));
entry.pushKV("BURNADDRESS", EncodeDestination(dest));
entry.pushKV("BURNPUBLICKEY", HexStr(keyid.begin(), keyid.end()));
entry.pushKV("BURNSCRIPT", HexStr(scriptPubKeyBurnAddress.begin(), scriptPubKeyBurnAddress.end()));
entry.pushKV("BACKUP_ADDRESS",EncodeDestination(BKaddress));
results.push_back(entry);
return results;
}


static UniValue infinitynodeupdatemeta(const JSONRPCRequest& request)
{
Expand Down Expand Up @@ -923,7 +1019,7 @@ static UniValue infinitynodeupdatemeta_external(const JSONRPCRequest& request)
CScript script;
script = GetScriptForBurn(keyid, streamInfo.str());

CMutableTransaction rawMetaTx = ConstructTransactionWithScript(request.params[0], script, INFAddress);
CMutableTransaction rawMetaTx = ConstructTransactionWithScript(request.params[0], script);

return EncodeHexTx(rawMetaTx);
}
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/rawtransaction.cpp
Expand Up @@ -450,7 +450,7 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal
return rawTx;
}

CMutableTransaction ConstructTransactionWithScript(const UniValue& inputs_in, const CScript& scriptMeta, const CTxDestination& INFAddress)
CMutableTransaction ConstructTransactionWithScript(const UniValue& inputs_in, const CScript& scriptMeta)
{
if (inputs_in.isNull())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, argument must be non-null");
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/rawtransaction.h
Expand Up @@ -15,6 +15,6 @@ UniValue SignTransaction(CMutableTransaction& mtx, const UniValue& prevTxs, CBas
/** Create a transaction from univalue parameters */
CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniValue& outputs_in, const UniValue& locktime, const UniValue& rbf);

CMutableTransaction ConstructTransactionWithScript(const UniValue& inputs_in, const CScript& scriptMeta, const CTxDestination& INFAddress);
CMutableTransaction ConstructTransactionWithScript(const UniValue& inputs_in, const CScript& scriptMeta);

#endif // BITCOIN_RPC_RAWTRANSACTION_H

0 comments on commit eddb52a

Please sign in to comment.