gagliardetto / solana-go

Go SDK library and RPC client for the Solana Blockchain
Apache License 2.0
942 stars 266 forks source link

Error in PublicKey's UnmarshalBSONValue #241

Closed newmanifold closed 1 month ago

newmanifold commented 3 months ago

It can be reproduced by simple snippet

package main

import (
    "fmt"

    "github.com/gagliardetto/solana-go"
    "go.mongodb.org/mongo-driver/bson"
)

func main() {
    key := solana.MustPublicKeyFromBase58("4wBqpZM9k69W87zdYXT2bRtLViWqTiJV3i2Kn9q7S6j")

    type S struct {
        Address solana.PublicKey `bson:"address"`
    }
    v, _ := bson.Marshal(S{Address: key})

    var s S
    err := bson.Unmarshal(v, &s)

    if err != nil {
        fmt.Println(err)
    }
}

reason for the error is that PublicKey's UnmarshalBSONValue method calls bson.Unmarshal instead of bson.UnmarshalValue