mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-25 14:04:27 +00:00
RPC newpostcustom allows buiding post with custom defined fields
This commit is contained in:
parent
4d59ebe2ab
commit
cb020faba8
@ -252,6 +252,7 @@ static const CRPCCommand vRPCCommands[] =
|
|||||||
{ "dhtputraw", &dhtputraw, false, true, true },
|
{ "dhtputraw", &dhtputraw, false, true, true },
|
||||||
{ "dhtget", &dhtget, false, true, true },
|
{ "dhtget", &dhtget, false, true, true },
|
||||||
{ "newpostmsg", &newpostmsg, false, true, false },
|
{ "newpostmsg", &newpostmsg, false, true, false },
|
||||||
|
{ "newpostcustom", &newpostcustom, false, true, false },
|
||||||
{ "newpostraw", &newpostraw, false, true, true },
|
{ "newpostraw", &newpostraw, false, true, true },
|
||||||
{ "newdirectmsg", &newdirectmsg, false, true, false },
|
{ "newdirectmsg", &newdirectmsg, false, true, false },
|
||||||
{ "newrtmsg", &newrtmsg, false, true, false },
|
{ "newrtmsg", &newrtmsg, false, true, false },
|
||||||
@ -1330,6 +1331,8 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
|
|||||||
if (strMethod == "dhtget" && n > 5) ConvertTo<boost::int64_t>(params[5]);
|
if (strMethod == "dhtget" && n > 5) ConvertTo<boost::int64_t>(params[5]);
|
||||||
if (strMethod == "newpostmsg" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
if (strMethod == "newpostmsg" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
||||||
if (strMethod == "newpostmsg" && n > 4) ConvertTo<boost::int64_t>(params[4]);
|
if (strMethod == "newpostmsg" && n > 4) ConvertTo<boost::int64_t>(params[4]);
|
||||||
|
if (strMethod == "newpostcustom" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
||||||
|
if (strMethod == "newpostcustom" && n > 2) ConvertTo<Object>(params[2]);
|
||||||
if (strMethod == "newpostraw" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
if (strMethod == "newpostraw" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
||||||
if (strMethod == "newdirectmsg" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
if (strMethod == "newdirectmsg" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
||||||
if (strMethod == "newdirectmsg" && n > 4) ConvertTo<bool>(params[4]);
|
if (strMethod == "newdirectmsg" && n > 4) ConvertTo<bool>(params[4]);
|
||||||
|
@ -204,6 +204,7 @@ extern json_spirit::Value dhtput(const json_spirit::Array& params, bool fHelp);
|
|||||||
extern json_spirit::Value dhtputraw(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value dhtputraw(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value dhtget(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value dhtget(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value newpostmsg(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value newpostmsg(const json_spirit::Array& params, bool fHelp);
|
||||||
|
extern json_spirit::Value newpostcustom(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value newpostraw(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value newpostraw(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value newdirectmsg(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value newdirectmsg(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value newrtmsg(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value newrtmsg(const json_spirit::Array& params, bool fHelp);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
// These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it
|
// These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it
|
||||||
#define CLIENT_VERSION_MAJOR 0
|
#define CLIENT_VERSION_MAJOR 0
|
||||||
#define CLIENT_VERSION_MINOR 9
|
#define CLIENT_VERSION_MINOR 9
|
||||||
#define CLIENT_VERSION_REVISION 34
|
#define CLIENT_VERSION_REVISION 35
|
||||||
#define CLIENT_VERSION_BUILD 0
|
#define CLIENT_VERSION_BUILD 0
|
||||||
|
|
||||||
// Set to true for release, false for prerelease or test build
|
// Set to true for release, false for prerelease or test build
|
||||||
|
@ -1697,10 +1697,7 @@ bool createSignedUserpost(entry &v, std::string const &username, int k,
|
|||||||
userpost["pfav"] = *ent;
|
userpost["pfav"] = *ent;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if ( !msg.size() ) {
|
break;
|
||||||
printf("createSignedUserpost: unknown type\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( reply_n.size() ) {
|
if( reply_n.size() ) {
|
||||||
@ -2261,6 +2258,72 @@ Value newpostmsg(const Array& params, bool fHelp)
|
|||||||
return entryToJson(v);
|
return entryToJson(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Value newpostcustom(const Array& params, bool fHelp)
|
||||||
|
{
|
||||||
|
if (fHelp || params.size() != 3)
|
||||||
|
throw runtime_error(
|
||||||
|
"newpostcustom <username> <k> '{\"field1\":value,\"field2\":value,...}'\n"
|
||||||
|
"Create a post with custom fields and add it to swarm");
|
||||||
|
|
||||||
|
EnsureWalletIsUnlocked();
|
||||||
|
|
||||||
|
string strUsername = params[0].get_str();
|
||||||
|
int k = params[1].get_int();
|
||||||
|
string strK = boost::lexical_cast<std::string>(k);
|
||||||
|
Object fields = params[2].get_obj();
|
||||||
|
|
||||||
|
entry v;
|
||||||
|
entry &userpost = v["userpost"];
|
||||||
|
// [MF] Warning: findLastPublicPostLocalUser requires that we follow ourselves
|
||||||
|
int lastk = findLastPublicPostLocalUser(strUsername);
|
||||||
|
if( lastk >= 0 )
|
||||||
|
userpost["lastk"] = lastk;
|
||||||
|
|
||||||
|
for (Object::const_iterator i = fields.begin(); i != fields.end(); ++i) {
|
||||||
|
if( i->value_.type() == str_type ) {
|
||||||
|
userpost[i->name_] = i->value_.get_str();
|
||||||
|
} else if ( i->value_.type() == int_type ) {
|
||||||
|
userpost[i->name_] = i->value_.get_int();
|
||||||
|
} else {
|
||||||
|
JSONRPCError(RPC_INVALID_PARAMS,string("unknown type for parameter: ") + i->name_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !createSignedUserpost(v, strUsername, k, 0,
|
||||||
|
"", NULL, NULL) )
|
||||||
|
throw JSONRPCError(RPC_INTERNAL_ERROR,"error signing post with private key of user");
|
||||||
|
|
||||||
|
vector<char> buf;
|
||||||
|
bencode(std::back_inserter(buf), v);
|
||||||
|
|
||||||
|
std::string errmsg;
|
||||||
|
if( !acceptSignedPost(buf.data(),buf.size(),strUsername,k,errmsg,NULL) )
|
||||||
|
throw JSONRPCError(RPC_INVALID_PARAMS,errmsg);
|
||||||
|
|
||||||
|
torrent_handle h = startTorrentUser(strUsername, true);
|
||||||
|
if( h.is_valid() ) {
|
||||||
|
// if member of torrent post it directly
|
||||||
|
h.add_piece(k,buf.data(),buf.size());
|
||||||
|
} else {
|
||||||
|
// TODO: swarm resource forwarding not implemented
|
||||||
|
dhtPutData(strUsername, "swarm", false,
|
||||||
|
v, strUsername, GetAdjustedTime(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// post to dht as well
|
||||||
|
dhtPutData(strUsername, string("post")+strK, false,
|
||||||
|
v, strUsername, GetAdjustedTime(), 1);
|
||||||
|
if( userpost.find_key("msg") ) {
|
||||||
|
dhtPutData(strUsername, string("status"), false,
|
||||||
|
v, strUsername, GetAdjustedTime(), k);
|
||||||
|
//look for mentions and hashtags in msg
|
||||||
|
dispatchHM(userpost["msg"].string(), strUsername, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
hexcapePost(v);
|
||||||
|
return entryToJson(v);
|
||||||
|
}
|
||||||
|
|
||||||
Value newpostraw(const Array& params, bool fHelp)
|
Value newpostraw(const Array& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (fHelp || params.size() != 3)
|
if (fHelp || params.size() != 3)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user