mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
add auto_sign parameter and bring into live
if set to true, transaction will be directly signed and if get enough signes, sended afterwards (but asynchron)
This commit is contained in:
parent
65471ddc35
commit
d5e60af3a1
@ -29,6 +29,10 @@ Poco::JSON::Object* JsonCreateTransaction::handle(Poco::Dynamic::Var params)
|
||||
paramJsonObject->get("transaction_type").convert(transaction_type);
|
||||
paramJsonObject->get("blockchain_type").convert(blockchain_type);
|
||||
paramJsonObject->get("memo").convert(mMemo);
|
||||
auto auto_sign = paramJsonObject->get("auto_sign");
|
||||
if (!auto_sign.isEmpty()) {
|
||||
auto_sign.convert(mAutoSign);
|
||||
}
|
||||
}
|
||||
catch (Poco::Exception& ex) {
|
||||
return stateError("json exception", ex.displayText());
|
||||
@ -118,7 +122,22 @@ Poco::JSON::Object* JsonCreateTransaction::transfer(Poco::Dynamic::Var params)
|
||||
}
|
||||
}
|
||||
if (!result) {
|
||||
model::gradido::Transaction::createTransfer(mSession->getNewUser(), target_pubkey, mTargetGroup, amount, mMemo, mBlockchainType);
|
||||
auto transactions = model::gradido::Transaction::createTransfer(mSession->getNewUser(), target_pubkey, mTargetGroup, amount, mMemo, mBlockchainType);
|
||||
|
||||
if (mAutoSign) {
|
||||
Poco::JSON::Array errors;
|
||||
for (auto it = transactions.begin(); it != transactions.end(); it++) {
|
||||
(*it)->sign(user);
|
||||
if ((*it)->errorCount() > 0) {
|
||||
errors.add((*it)->getErrorsArray());
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.size() > 0) {
|
||||
return stateError("error by signing transaction", errors);
|
||||
}
|
||||
}
|
||||
|
||||
result = stateSuccess();
|
||||
}
|
||||
mm->releaseMemory(target_pubkey);
|
||||
@ -184,7 +203,13 @@ Poco::JSON::Object* JsonCreateTransaction::creation(Poco::Dynamic::Var params)
|
||||
}
|
||||
|
||||
if(!result) {
|
||||
model::gradido::Transaction::createCreation(mReceiverUser, amount, target_date, mMemo, mBlockchainType);
|
||||
auto transaction = model::gradido::Transaction::createCreation(mReceiverUser, amount, target_date, mMemo, mBlockchainType);
|
||||
if (mAutoSign) {
|
||||
if (!transaction->sign(mSession->getNewUser())) {
|
||||
return stateError("error by signing transaction", transaction);
|
||||
}
|
||||
}
|
||||
|
||||
result = stateSuccess();
|
||||
}
|
||||
mm->releaseMemory(target_pubkey);
|
||||
@ -200,7 +225,12 @@ Poco::JSON::Object* JsonCreateTransaction::groupMemberUpdate(Poco::Dynamic::Var
|
||||
if (mTargetGroup.isNull()) {
|
||||
return stateError("target_group not found");
|
||||
}
|
||||
model::gradido::Transaction::createGroupMemberUpdate(mSession->getNewUser(), mTargetGroup);
|
||||
auto transaction = model::gradido::Transaction::createGroupMemberUpdate(mSession->getNewUser(), mTargetGroup);
|
||||
if (mAutoSign) {
|
||||
if (!transaction->sign(mSession->getNewUser())) {
|
||||
return stateError("error by signing transaction", transaction);
|
||||
}
|
||||
}
|
||||
return stateSuccess();
|
||||
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
class JsonCreateTransaction : public JsonRequestHandler
|
||||
{
|
||||
public:
|
||||
JsonCreateTransaction() : mSession(nullptr) {}
|
||||
JsonCreateTransaction() : mSession(nullptr), mAutoSign(false) {}
|
||||
Poco::JSON::Object* handle(Poco::Dynamic::Var params);
|
||||
|
||||
protected:
|
||||
@ -24,6 +24,8 @@ protected:
|
||||
Poco::AutoPtr<controller::Group> mTargetGroup;
|
||||
Poco::AutoPtr<controller::User> mReceiverUser;
|
||||
model::gradido::BlockchainType mBlockchainType;
|
||||
//! if set to true, transaction will be direct signed by user which belong to session
|
||||
bool mAutoSign;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -133,6 +133,26 @@ Poco::JSON::Object* JsonRequestHandler::stateError(const char* msg, std::string
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Poco::JSON::Object* JsonRequestHandler::stateError(const char* msg, const Poco::JSON::Array& details)
|
||||
{
|
||||
Poco::JSON::Object* result = new Poco::JSON::Object;
|
||||
result->set("state", "error");
|
||||
result->set("msg", msg);
|
||||
result->set("details", details);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Poco::JSON::Object* JsonRequestHandler::stateError(const char* msg, NotificationList* errorReciver)
|
||||
{
|
||||
assert(errorReciver);
|
||||
Poco::JSON::Object* result = new Poco::JSON::Object;
|
||||
result->set("state", "error");
|
||||
result->set("msg", msg);
|
||||
result->set("details", errorReciver->getErrorsArray());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Poco::JSON::Object* JsonRequestHandler::stateSuccess()
|
||||
{
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
#include "Poco/Net/HTTPRequestHandler.h"
|
||||
#include "Poco/JSON/Object.h"
|
||||
#include "Poco/JSON/Array.h"
|
||||
#include "../model/Session.h"
|
||||
#include "../lib/NotificationList.h"
|
||||
|
||||
@ -30,6 +31,8 @@ protected:
|
||||
Poco::JSON::Object* checkAndLoadSession(Poco::Dynamic::Var params, bool checkIp = false);
|
||||
|
||||
static Poco::JSON::Object* stateError(const char* msg, std::string details = "");
|
||||
static Poco::JSON::Object* stateError(const char* msg, NotificationList* errorReciver);
|
||||
static Poco::JSON::Object* stateError(const char* msg, const Poco::JSON::Array& details);
|
||||
static Poco::JSON::Object* customStateError(const char* state, const char* msg, std::string details = "");
|
||||
static Poco::JSON::Object* stateSuccess();
|
||||
static Poco::JSON::Object* stateWarning(const char* msg, std::string details = "");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user