mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Returned input hash and ledger info for input submissions. (#283)
- Introduced input hash which can later be used to query the ledger. - Returned input hash and ledger info at input submission. - Updated js client lib to support input hash. - Updated consensus proposal candidate expiration rules.
This commit is contained in:
@@ -224,13 +224,17 @@ namespace msg::usrmsg::json
|
||||
* "type": "contract_input_status",
|
||||
* "status": "<accepted|rejected>",
|
||||
* "reason": "<reson>",
|
||||
* "input_sig": "<hex sig of original input message>"
|
||||
* "input_hash": "<hex hash of original input signature>",
|
||||
* "ledger_seq_no": <sequence no of the ledger that the input got included in>,
|
||||
* "ledger_hash": "<hex hash no of the ledger that the input got included in>"
|
||||
* }
|
||||
* @param is_accepted Whether the original message was accepted or not.
|
||||
* @param reason Rejected reason. Empty if accepted.
|
||||
* @param input_sig Binary signature of the original input message which generated this result.
|
||||
* @param input_hash Binary Hash of the original input signature. This is used by user
|
||||
* to tie the response with the input submission.
|
||||
*/
|
||||
void create_contract_input_status(std::vector<uint8_t> &msg, std::string_view status, std::string_view reason, std::string_view input_sig)
|
||||
void create_contract_input_status(std::vector<uint8_t> &msg, std::string_view status, std::string_view reason,
|
||||
std::string_view input_hash, const uint64_t ledger_seq_no, const util::h32 &ledger_hash)
|
||||
{
|
||||
msg.reserve(256);
|
||||
msg += "{\"";
|
||||
@@ -242,13 +246,33 @@ namespace msg::usrmsg::json
|
||||
msg += SEP_COLON;
|
||||
msg += status;
|
||||
msg += SEP_COMMA;
|
||||
msg += msg::usrmsg::FLD_REASON;
|
||||
|
||||
// Reject reason is only included for rejected inputs.
|
||||
if (!reason.empty())
|
||||
{
|
||||
msg += msg::usrmsg::FLD_REASON;
|
||||
msg += SEP_COLON;
|
||||
msg += reason;
|
||||
msg += SEP_COMMA;
|
||||
}
|
||||
|
||||
msg += msg::usrmsg::FLD_INPUT_HASH;
|
||||
msg += SEP_COLON;
|
||||
msg += reason;
|
||||
msg += SEP_COMMA;
|
||||
msg += msg::usrmsg::FLD_INPUT_SIG;
|
||||
msg += SEP_COLON;
|
||||
msg += util::to_hex(input_sig);
|
||||
msg += util::to_hex(input_hash);
|
||||
|
||||
// Ledger information is only included in 'accepted' input statuses.
|
||||
if (ledger_seq_no > 0)
|
||||
{
|
||||
msg += SEP_COMMA;
|
||||
msg += msg::usrmsg::FLD_LEDGER_SEQ_NO;
|
||||
msg += SEP_COLON_NOQUOTE;
|
||||
msg += std::to_string(ledger_seq_no);
|
||||
msg += SEP_COMMA_NOQUOTE;
|
||||
msg += msg::usrmsg::FLD_LEDGER_HASH;
|
||||
msg += SEP_COLON;
|
||||
msg += util::to_hex(ledger_hash.to_string_view());
|
||||
}
|
||||
|
||||
msg += "\"}";
|
||||
}
|
||||
|
||||
@@ -676,16 +700,16 @@ namespace msg::usrmsg::json
|
||||
* Extract the individual components of a given input container json.
|
||||
* @param input The extracted input.
|
||||
* @param nonce The extracted nonce.
|
||||
* @param max_lcl_seq_no The extracted max ledger sequence no.
|
||||
* @param max_ledger_seq_no The extracted max ledger sequence no.
|
||||
* @param contentjson The json string containing the input container message.
|
||||
* {
|
||||
* "input": "<any string>",
|
||||
* "nonce": "<random string with optional sorted order>",
|
||||
* "max_lcl_seq_no": <integer>
|
||||
* "max_ledger_seq_no": <integer>
|
||||
* }
|
||||
* @return 0 on succesful extraction. -1 on failure.
|
||||
*/
|
||||
int extract_input_container(std::string &input, std::string &nonce, uint64_t &max_lcl_seq_no, std::string_view contentjson)
|
||||
int extract_input_container(std::string &input, std::string &nonce, uint64_t &max_ledger_seq_no, std::string_view contentjson)
|
||||
{
|
||||
jsoncons::json d;
|
||||
try
|
||||
@@ -698,13 +722,13 @@ namespace msg::usrmsg::json
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!d.contains(msg::usrmsg::FLD_INPUT) || !d.contains(msg::usrmsg::FLD_NONCE) || !d.contains(msg::usrmsg::FLD_MAX_LCL_SEQ))
|
||||
if (!d.contains(msg::usrmsg::FLD_INPUT) || !d.contains(msg::usrmsg::FLD_NONCE) || !d.contains(msg::usrmsg::FLD_MAX_LEDGER_SEQ_NO))
|
||||
{
|
||||
LOG_DEBUG << "User input container required fields missing.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!d[msg::usrmsg::FLD_INPUT].is<std::string>() || !d[msg::usrmsg::FLD_NONCE].is<std::string>() || !d[msg::usrmsg::FLD_MAX_LCL_SEQ].is<uint64_t>())
|
||||
if (!d[msg::usrmsg::FLD_INPUT].is<std::string>() || !d[msg::usrmsg::FLD_NONCE].is<std::string>() || !d[msg::usrmsg::FLD_MAX_LEDGER_SEQ_NO].is<uint64_t>())
|
||||
{
|
||||
LOG_DEBUG << "User input container invalid field values.";
|
||||
return -1;
|
||||
@@ -712,7 +736,7 @@ namespace msg::usrmsg::json
|
||||
|
||||
input = d[msg::usrmsg::FLD_INPUT].as<std::string>();
|
||||
nonce = d[msg::usrmsg::FLD_NONCE].as<std::string>();
|
||||
max_lcl_seq_no = d[msg::usrmsg::FLD_MAX_LCL_SEQ].as<uint64_t>();
|
||||
max_ledger_seq_no = d[msg::usrmsg::FLD_MAX_LEDGER_SEQ_NO].as<uint64_t>();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user