mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-09-11 13:52:08 +00:00
send transation of a new user created in wallet
This commit is contained in:
parent
ad712d5006
commit
927aad13a5
@ -243,6 +243,7 @@ static const CRPCCommand vRPCCommands[] =
|
|||||||
{ "decoderawtransaction", &decoderawtransaction, false, false },
|
{ "decoderawtransaction", &decoderawtransaction, false, false },
|
||||||
{ "signrawtransaction", &signrawtransaction, false, false },
|
{ "signrawtransaction", &signrawtransaction, false, false },
|
||||||
{ "sendrawtransaction", &sendrawtransaction, false, false },
|
{ "sendrawtransaction", &sendrawtransaction, false, false },
|
||||||
|
{ "sendnewusertransaction", &sendnewusertransaction, false, false },
|
||||||
{ "verifychain", &verifychain, true, false },
|
{ "verifychain", &verifychain, true, false },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -196,6 +196,7 @@ extern json_spirit::Value createrawtransaction(const json_spirit::Array& params,
|
|||||||
extern json_spirit::Value decoderawtransaction(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value decoderawtransaction(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value signrawtransaction(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value signrawtransaction(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value sendrawtransaction(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value sendrawtransaction(const json_spirit::Array& params, bool fHelp);
|
||||||
|
extern json_spirit::Value sendnewusertransaction(const json_spirit::Array& params, bool fHelp);
|
||||||
|
|
||||||
extern json_spirit::Value getblockcount(const json_spirit::Array& params, bool fHelp); // in rpcblockchain.cpp
|
extern json_spirit::Value getblockcount(const json_spirit::Array& params, bool fHelp); // in rpcblockchain.cpp
|
||||||
extern json_spirit::Value getbestblockhash(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value getbestblockhash(const json_spirit::Array& params, bool fHelp);
|
||||||
|
@ -145,9 +145,9 @@ Value getrawtransaction(const Array& params, bool fHelp)
|
|||||||
|
|
||||||
Value createrawtransaction(const Array& params, bool fHelp)
|
Value createrawtransaction(const Array& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (fHelp || params.size() < 1 || params.size() > 2)
|
if (fHelp || params.size() != 2)
|
||||||
throw runtime_error(
|
throw runtime_error(
|
||||||
"createrawtransaction <username> [pubKey=generate if omited]\n"
|
"createrawtransaction <username> <pubKey>\n"
|
||||||
"Create a transaction registering a new user\n"
|
"Create a transaction registering a new user\n"
|
||||||
"Returns hex-encoded raw transaction.\n"
|
"Returns hex-encoded raw transaction.\n"
|
||||||
"it is not stored in the wallet or transmitted to the network.");
|
"it is not stored in the wallet or transmitted to the network.");
|
||||||
@ -159,13 +159,12 @@ Value createrawtransaction(const Array& params, bool fHelp)
|
|||||||
string username = params[0].get_str();
|
string username = params[0].get_str();
|
||||||
rawTx.userName = CScript() << vector<unsigned char>((const unsigned char*)username.data(), (const unsigned char*)username.data() + username.size());
|
rawTx.userName = CScript() << vector<unsigned char>((const unsigned char*)username.data(), (const unsigned char*)username.data() + username.size());
|
||||||
|
|
||||||
if (params.size() > 1) {
|
vector<unsigned char> vch(ParseHexV(params[1], "pubkey"));
|
||||||
vector<unsigned char> txData(ParseHexV(params[1], "pubkey"));
|
CPubKey pubkey(vch);
|
||||||
rawTx.pubKey << txData;
|
if( !pubkey.IsValid() )
|
||||||
} else {
|
throw JSONRPCError(RPC_INTERNAL_ERROR, "pubkey is not valid");
|
||||||
pwalletMain->GenerateNewKey(username);
|
|
||||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "pubkey generation not implemented");
|
rawTx.pubKey << vch;
|
||||||
}
|
|
||||||
|
|
||||||
DoTxProofOfWork(rawTx);
|
DoTxProofOfWork(rawTx);
|
||||||
|
|
||||||
@ -425,3 +424,36 @@ Value sendrawtransaction(const Array& params, bool fHelp)
|
|||||||
|
|
||||||
return hashTx.GetHex();
|
return hashTx.GetHex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Value sendnewusertransaction(const Array& params, bool fHelp)
|
||||||
|
{
|
||||||
|
if (fHelp || params.size() != 1)
|
||||||
|
throw runtime_error(
|
||||||
|
"sendnewusertransaction <username>\n"
|
||||||
|
"Send a transaction registering a previously created new user\n"
|
||||||
|
"using createuserkey or imported to the wallet\n"
|
||||||
|
"Submits raw transaction (serialized, hex-encoded) to local node and network.");
|
||||||
|
|
||||||
|
if (params[0].type() != str_type)
|
||||||
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "username must be string");
|
||||||
|
string strUsername = params[0].get_str();
|
||||||
|
|
||||||
|
CKeyID keyID;
|
||||||
|
if( !pwalletMain->GetKeyIdFromUsername(strUsername, keyID) )
|
||||||
|
throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME, "Error: username must exist in wallet");
|
||||||
|
|
||||||
|
CPubKey pubkey;
|
||||||
|
if( !pwalletMain->GetPubKey(keyID, pubkey) )
|
||||||
|
throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME, "Error: no public key found");
|
||||||
|
|
||||||
|
Array createTxParams;
|
||||||
|
createTxParams.push_back(strUsername);
|
||||||
|
createTxParams.push_back(HexStr(pubkey));
|
||||||
|
Value txValue = createrawtransaction(createTxParams, false);
|
||||||
|
|
||||||
|
std::string strTxHex = txValue.get_str();
|
||||||
|
Array sendTxParams;
|
||||||
|
sendTxParams.push_back(strTxHex);
|
||||||
|
return sendrawtransaction(sendTxParams, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ Value createuserkey(const Array& params, bool fHelp)
|
|||||||
throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME, "Error: this username exists in wallet");
|
throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME, "Error: this username exists in wallet");
|
||||||
|
|
||||||
uint256 userhash = SerializeHash(strUsername);
|
uint256 userhash = SerializeHash(strUsername);
|
||||||
printf("usernamehash(%s) = %s\n", strUsername.c_str(), userhash.GetHex().c_str());
|
printf("createuserkey: usernamehash(%s) = %s\n", strUsername.c_str(), userhash.GetHex().c_str());
|
||||||
|
|
||||||
CTransaction txOut;
|
CTransaction txOut;
|
||||||
uint256 hashBlock;
|
uint256 hashBlock;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user