mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-18 17:45:48 +00:00
add slot_type API
This commit is contained in:
@@ -254,7 +254,8 @@ public:
|
||||
slot_subfield(uint32_t parent_slot, uint32_t field_id, uint32_t new_slot)
|
||||
const;
|
||||
|
||||
// slot_type
|
||||
Expected<std::variant<STBase, STAmount>, HookReturnCode>
|
||||
slot_type(uint32_t slot_no, uint32_t flags) const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
slot_float(uint32_t slot_no) const;
|
||||
|
||||
@@ -2353,7 +2353,38 @@ HookAPI::slot_subfield(
|
||||
}
|
||||
}
|
||||
|
||||
// slot_type
|
||||
Expected<std::variant<STBase, STAmount>, HookReturnCode>
|
||||
HookAPI::slot_type(uint32_t slot_no, uint32_t flags) const
|
||||
{
|
||||
if (hookCtx.slot.find(slot_no) == hookCtx.slot.end())
|
||||
return Unexpected(DOESNT_EXIST);
|
||||
|
||||
if (hookCtx.slot[slot_no].entry == 0)
|
||||
return Unexpected(INTERNAL_ERROR);
|
||||
try
|
||||
{
|
||||
ripple::STBase& obj = const_cast<ripple::STBase&>(
|
||||
*hookCtx.slot[slot_no].entry); //.downcast<ripple::STBase>();
|
||||
if (flags == 0)
|
||||
return obj;
|
||||
|
||||
// this flag is for use with an amount field to determine if the amount
|
||||
// is native (xrp)
|
||||
if (flags == 1)
|
||||
{
|
||||
if (obj.getSType() != STI_AMOUNT)
|
||||
return Unexpected(NOT_AN_AMOUNT);
|
||||
return const_cast<ripple::STBase&>(*hookCtx.slot[slot_no].entry)
|
||||
.downcast<ripple::STAmount>();
|
||||
}
|
||||
|
||||
return Unexpected(INVALID_ARGUMENT);
|
||||
}
|
||||
catch (const std::bad_cast& e)
|
||||
{
|
||||
return Unexpected(INTERNAL_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
HookAPI::slot_float(uint32_t slot_no) const
|
||||
|
||||
@@ -2131,34 +2131,20 @@ DEFINE_HOOK_FUNCTION(int64_t, slot_type, uint32_t slot_no, uint32_t flags)
|
||||
HOOK_SETUP(); // populates memory_ctx, memory, memory_length, applyCtx,
|
||||
// hookCtx on current stack
|
||||
|
||||
if (hookCtx.slot.find(slot_no) == hookCtx.slot.end())
|
||||
return DOESNT_EXIST;
|
||||
hook::HookAPI api(hookCtx);
|
||||
auto const result = api.slot_type(slot_no, flags);
|
||||
if (!result)
|
||||
return result.error();
|
||||
|
||||
if (hookCtx.slot[slot_no].entry == 0)
|
||||
return INTERNAL_ERROR;
|
||||
try
|
||||
if (flags == 0)
|
||||
{
|
||||
ripple::STBase& obj = const_cast<ripple::STBase&>(
|
||||
*hookCtx.slot[slot_no].entry); //.downcast<ripple::STBase>();
|
||||
if (flags == 0)
|
||||
return obj.getFName().fieldCode;
|
||||
|
||||
// this flag is for use with an amount field to determine if the amount
|
||||
// is native (xrp)
|
||||
if (flags == 1)
|
||||
{
|
||||
if (obj.getSType() != STI_AMOUNT)
|
||||
return NOT_AN_AMOUNT;
|
||||
return const_cast<ripple::STBase&>(*hookCtx.slot[slot_no].entry)
|
||||
.downcast<ripple::STAmount>()
|
||||
.native();
|
||||
}
|
||||
|
||||
return INVALID_ARGUMENT;
|
||||
auto const base = std::get<0>(*result);
|
||||
return base.getFName().fieldCode;
|
||||
}
|
||||
catch (const std::bad_cast& e)
|
||||
else
|
||||
{
|
||||
return INTERNAL_ERROR;
|
||||
auto const amount = std::get<1>(*result);
|
||||
return amount.native();
|
||||
}
|
||||
|
||||
HOOK_TEARDOWN();
|
||||
|
||||
Reference in New Issue
Block a user