Skip to content

feat: token preloaded lib - #1016

Open
charmful0x wants to merge 4 commits into
edgefrom
feat/exported-token-util
Open

feat: token preloaded lib#1016
charmful0x wants to merge 4 commits into
edgefrom
feat/exported-token-util

Conversation

@charmful0x

Copy link
Copy Markdown

No description provided.

Comment thread src/preloaded/token/lib_token.erl Outdated
Comment thread src/preloaded/token/lib_token.erl Outdated
<<"committers">>,
<<"index">>,
<<"info">>,
<<"set_path">>,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- will match _ just as well in AO-Core. We are never going to be able to keep this up-to-date -- is it necessary for the design?

Comment thread src/preloaded/token/lib_token.erl Outdated
%% mixed-case input cannot collide with AO/trie control keys after
%% canonicalization.
validate_address(Address, CustomList) ->
validate_address(Address, CustomList, #{}).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just not offer a no-Opts version? I think in general we should remove those across the codebase. Far more trouble than good!

Comment thread src/preloaded/token/lib_token.erl Outdated
validate_address(Address, CustomList, Opts) when is_binary(Address), is_list(CustomList) ->
ReservedKeys = ?AO_RESERVED_ADDRESS_KEYS ++ CustomList,
AccountKey = account_key(Address),
CanonicalReservedKeys = [account_key(Key) || Key <- ReservedKeys, is_binary(Key)],

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we expect this to be frequently executed can extract AO_RESERVED_ADDRESS_KEYS from the account_key-processed part? to_lower is surprisingly slow at the moment.


trie_reserved_keys(Opts) ->
{ok, Trie} = hb_device_load:reference(<<"trie@1.0">>, Opts),
maps:get(reserved, Trie:info(), []).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have -- if we don't already -- a way to programmatically generate the list of device keys. in hb_device. The message_to_fun flow must use it somewhere, so we should just be able to extract it. Perhaps simple: Just use message_to_fun with #{ <<"device">> => DEV_NAME }, ... [key:] Address, ...)? If you get back fun dev_message:get/4 then you know there were no hits. I think you can also specify the default, at least in the neo/edge-1.0 branch.

Comment thread src/preloaded/token/lib_token.erl Outdated

%% @doc Canonical token balance trie key for an external account ID.
account_key(Address) when is_binary(Address) ->
hb_util:to_lower(Address).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to do normalize_key here, too. I don't think this flow catches integer keys at the momen, for example. I think this will probably just crash?

@charmful0x

Copy link
Copy Markdown
Author

thanks for the feedbacks @speeddragon @samcamwilliams -- addressed, now:

  • removed hardcoded reserved keys list, device operations are now detected dynamically via hb_device:message_to_fun/3 -- however only <<"path">> is still hardcoded in the last commit because it control trie updates and a must have
  • no no-Opts -- removed validate_address/2 and now it's the exported validate_address/3
  • dynamically rejects callable keys from trie@1.0 and message@1.0
  • applied normalize_key in account_key

Comment thread src/preloaded/token/lib_token.erl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants