-
Notifications
You must be signed in to change notification settings - Fork 50
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
chore: add sdk::PublicKey
to workspaces::PublicKey
conversion
#267
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.
Just took a look at sdk::PublicKey
's borsh-serialization format, and it's really weird tbh, I think in general it's not ideal to assume byte slices deserialize the same way for two types in differing crates with the same name. We should be able to retain the current behavior, and instead just provide two-way conversion at the API-level.
So, if you have a byte slice that successfully deserializes into sdk::PublicKey
, you can just call into()
on that instead of attempting to deserialize the same byte slice into a workspaces::PublicKey
. And vice-versa.
So I was trying to eliminate a friction point with this, but historically for serialized types in workspaces, it's just been passing them into contract.call("function")
.args_json(json!({
"account_id": AccountId("user.test"),
})
.transact().await?; Adding the conversion would feel pretty inconsistent: contract.call("function")
.args_json(json!({
"account_id": AccountId("user.test"),
"public_key": sdk::PublicKey::from(PublicKey::try_from_bytes(&bytes)?)
})
.transact().await?; since we'd now need to know what types are serializable via workspaces or sdk. I'd like not to go down that route, since the experience wouldn't be nice I'd say.
Like creating |
That's a fair point, although just noting that serde-serialization looks to be consistent between sdk/workspaces' |
@frol this should be good to go whenever you want to fully take a look at it |
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 am not exactly sure about having interop_sdk
to be enabled by default, but I think in the bright future where PublicKey is extracted into a separate crate and shared across nearcore, near-sdk-rs, and workspace-rs, we can drop this code altogether and the feature will become no-op
@frol by enabling it by default, it offers the least friction to testing contracts which
So, the |
Resolves #262
This adds a
TryFrom<sdk::PublicKey>
impl to convertsdk::PublicKey
intoworkspaces::PublicKey
s, along with a test to check serialization. This also has a new feature flaginterop_sdk
just in a case they don't want to add a big dependency to their testing pipeline. It's enabled by default anywaysBorsh serialization had to change from the previous PR #265 to make it compatible to be sent to a contract through borsh serialization. The new format is now
[buffer_len, key_type, key_data..]