2

I'm pretty sure std::collections::BinaryHeap supports Borsh, so I thought I could use it with an account.

Here is the account:

#[account]
pub struct Voter {
    pub claim_queue: BinaryHeap<DisputeRecord>,
    pub bump: u8,
}

The contract actually builds and I deployed, however when I try to run a test using typescript, I get an IdlError that the type BinaryHeap is not found. Is this a limitation of Anchor or would I not be able to do this with raw solana either?

1 Answer 1

3

You're correct that BinaryHeap is implemented in Borsh: https://github.com/near/borsh-rs/blob/9e6831628442036fe3183f8244da3973bd99e8f7/borsh/src/ser/mod.rs#L305

This means that you can safely use it in a Solana program, with both Anchor and non-Anchor, provided that the account has enough space.

On the Borsh JS side, however, there is no way to declare and deserialize it, so you're out of luck unfortunately. This is why you're seeing an error on the IDL side.

You can see the supported type mappings at https://github.com/near/borsh-js#type-mappings. It probably wouldn't be too much work to support, so feel free to send them a PR!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.