Xahau / xahaud

Codebase for Xahaud - The consensus, RPC & blockchain app for the Xahau network.
https://xahau.network
ISC License
22 stars 11 forks source link

`accept` and `rollback` error message should be the same as c hooks #325

Open dangell7 opened 1 month ago

dangell7 commented 1 month ago

When doing accept or rollback in jshooks you cannot send in data and have it return the hex value. If you send in a hex, it will hex that again.

Current Behavior:

accept('DEADBEEF', 18)
// "HookReturnString": "4445414442454546"
accept(SBUF("DEADBEEF"), 18)
// "HookReturnString": "4445414442454546"
let acc = hook_account()
accept(acc, 18)
// "HookReturnString": ""
uint8_t hook_acc[20];
hook_account(SBUF(hook_acc));
accept(SBUF(hook_acc), 18)
// "HookReturnString": "6DF90ECA2B5C0B45AA2E1D6E993BF7D9DCB226B3"
let acc = hook_account()
accept(toHex(acc), 18)
// "HookReturnString": "36444639304543413242354330423435414132453144364539393342463744394443423232364233"

Conclusion:

I think we should allow the ability to send in the buffer/byte array and have it return the hex of that. To match the behavior of the c hooks.

If I update the macro with the following then I can send the byte array into the accept, with as_hex=true and then get the account id as the HookReturnString.

if (JS_IsBool(as_hex) && !!JS_ToBool(ctx, as_hex))\
    {\
        auto in = FromJSIntArrayOrHexString(ctx, error_msg, 64*1024);\
        if (in.has_value())\
        {\
            if (in->size() > 1024)\
                in->resize(1024);\
            hookCtx.result.exitReason = std::string((const char*)in->data(), in->size());\
        }\
    }\

There is also a function is_UTF16LE in the c path and I think we should decide if we want to incorporate this as well.

RichardAH commented 4 days ago

This seems reasonable, feel free to make the change