Fix NonFungibleTokenApprovalReceiver::nft_on_approve
return type
#1053
Labels
NonFungibleTokenApprovalReceiver::nft_on_approve
return type
#1053
Problem
The
NonFungibleTokenApprovalReceiver::nft_on_approve
trait method currently has anear_sdk::PromiseOrValue<String>
return type, but the standard mandates a void return type as reported in #693.Possible Solutions
The void return type in the standard is probably an oversight, since in the documentation of the
nft_approve
interface it says that it "returns promise call tonft_on_approve
, which can resolve with whatever it wants." This suggests that the intended return typenft_on_approve
in the standard wasany
. We could submit an errata to fix this.Question is how to represent the
any
return type ofNonFungibleTokenApprovalReceiver::nft_on_approve
in Rust? I see the following options:Box<dyn std::any::Any>
, but this won't work, because the traitSerialize
is not implemented fordyn Any
.NonFungibleTokenApprovalReceiver::nft_on_approve
returnnear_sdk::PromiseOrValue<serde_json::Value>
. This would be a good solution, but we need to supportborsh
as well. I'm not too familiar withborsh
, but as far as I can tell,borsh::schema::BorshSchema
achieves the same result, so we could haveNonFungibleTokenApprovalReceiver::nft_on_approve
return an enum value that wraps eitherserde_json::Value
orBorshSchema
, but this might be getting too complex.near_sdk::PromiseOrValue<String>
since anything can be serialized into a string and it hasn't caused any problems so far except for some confusion around the documentation.Edit: added associate type solution from Austin originally written in #918.
The text was updated successfully, but these errors were encountered: