-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pallet Assets Chain Extension #1124
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Few minor comments, the most impactful probably the one about weight charging placement.
assert_ok!(Assets::set_team( | ||
RuntimeOrigin::signed(ALICE), | ||
ASSET_ID, | ||
addr.clone(), | ||
ALICE, | ||
ALICE | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity - is this needed for the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is needed. Only EOA can create assets (because create is not part of CE) and set_team is used to transfer Admin roles. As in Chain extension the Origin can only be the contract, Issuer (minter role) should be transferred to it in order to mint assets.
I move the comment line on top of it for more clarity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, I missed the addr.clone()
, my bad!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing you could do in test is use force_create
, that way you can set the owner to whoever in a single call.
This is informational, no changes needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes true! I tend to be closer to real use case in my tests
amount: u128, | ||
) -> Result<ExecReturnValue, DispatchError> { | ||
let data = [ | ||
[0x84, 0xa1, 0x5d, 0xa1].to_vec(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you intend to reuse the consts here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
functions selector are the first 4bytes of the blake_2b hash of the function name. So it cannot be evaluated at compile time. For more clarity I added a macro that takes the &str of the function name to be more straight forward and not deal with bytes arrays
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, but I didn't mean for them to be evaluated at compile time necessarily, the question was more generic about reusing the constants. They could also be str constants, and macros could be used on them, I guess.
But I think you got my point 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah got your point but I responded there to you comment above Question - can these values be fetched automatically or calculated from a string/tuple? so I made things not so clear sorry
To respond to the str const:
The str const will be 4 bytes len str of an hash so not more informative/less error prone than explicit bytes array. I think with macro is the best approach here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
assert_ok!(Assets::set_team( | ||
RuntimeOrigin::signed(ALICE), | ||
ASSET_ID, | ||
addr.clone(), | ||
ALICE, | ||
ALICE | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing you could do in test is use force_create
, that way you can set the owner to whoever in a single call.
This is informational, no changes needed.
amount: u128, | ||
) -> Result<ExecReturnValue, DispatchError> { | ||
let data = [ | ||
selector_bytes!("transfer").to_vec(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick - these strings could have been left as &str consts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean like const TRASNFER &str = b"9bae9d5e";
?
I think this way is more readable (even tho it's not the most performant - but it's off chain tests)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost, I meant like `const TRANSFER: &str = "transfer";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah but I would have to hash that &str and get the first 4 bytes so it defeats the static part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just some nitpick comments
Minimum allowed line rate is |
Pull Request Summary
Added Pallet Assets Chain extension to Shibuya (and local).
It expose the same API as assets-er20 precompiles:
State modify functions
Getters
Error Handling
Chain extension return a RetVal that is being handled/decoded in contract to get proper Error handling.
Weight
The chain extension reads scale encoded bytes from buffer to get the type. Every call only use fixed bytes (no usage of read_as_unbunded() to read Vectors) so it can not be abused. It then charge the pallet call and perform the call. It then return an RetVal in case of a extrinsic call (no encoding) or write the encoded bytes in buffer in case of query.
Tests
Test contract: AstarNetwork/ink-test-contracts#4