blocto / solana-go-sdk

Solana Golang SDK
https://blocto.github.io/solana-go-sdk/
MIT License
373 stars 96 forks source link

Add support for Metaplex Token Metadata Standard v1.2.0 fields. #50

Closed omarkilani closed 2 years ago

omarkilani commented 2 years ago

Reflect the updates in the Metaplex Token Metadata Standard.

yihau commented 2 years ago

Thank you for your contribution. I will merge it later because I found something strange with old version NFT. For those NFT I think TokenStandard, Collection and Uses should be nil. (like Degen Ape 9MwGzSyuQRqmBHqmYwE6wbP3vzRBj4WWiYxWns3rkR7A) Current version will give default value to those fields instead of nil

omarkilani commented 2 years ago

I'll take a look at that issue soon.

I think borsh just isn't designed for this kind of "versioned" data encoding, and since the original encoding doesn't have a version field, any encoded data where some bytes exist past the end of the previous data format will show up as data in the new data format.

omarkilani commented 2 years ago

@yihau the token you used as an example has been updated to contain a verified collection, e.g.:

2022/04/11 23:18:18.680761 get_token.go:125: metadataAcct As6s2eFUofRakmUnenYfaPkY5tYtZMVM4TUwKM8YgJNK
2022/04/11 23:18:18.680765 solana.go:1004: GetAccountInfo(https://young-sparkling-sun.solana-mainnet.quiknode.pro/[xxx]/): address As6s2eFUofRakmUnenYfaPkY5tYtZMVM4TUwKM8YgJNK
2022/04/11 23:18:18.825462 get_token.go:128: accInfo {Lamports:5616720 Owner:metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s Executable:false RentEpoch:298 Data:[4 181 31 162 155 29 219 194 100 31 16 249 211 201 33 57 90 137 179 68 4 180 152 165 233 137 208 199 164 231 177 248 194 124 58 123 55 195 218 245 184 61 127 137 46 29 204 26 104 204 235 71 74 52 43 21 86 68 104 19 236 170 12 164 205 32 0 0 0 68 101 103 101 110 32 65 112 101 32 35 55 50 50 53 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 0 68 65 80 69 0 0 0 0 0 0 200 0 0 0 104 116 116 112 115 58 47 47 97 114 119 101 97 118 101 46 110 101 116 47 75 122 88 55 106 107 76 54 116 77 69 99 76 73 120 84 80 113 70 69 86 83 76 77 105 84 117 118 110 100 84 113 77 74 49 103 101 118 106 99 117 56 89 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 164 1 1 5 0 0 0 121 130 60 219 108 229 8 115 219 63 137 94 36 63 148 216 34 11 152 56 112 46 249 123 186 235 105 112 221 35 148 255 0 39 122 151 168 221 137 146 85 123 177 119 86 8 24 13 5 199 243 65 134 90 221 144 222 240 138 25 105 243 64 1 108 214 0 25 243 45 182 57 78 247 72 151 107 20 236 251 194 118 218 196 47 8 23 97 98 24 75 75 218 152 3 6 32 109 213 74 0 25 92 253 74 143 238 198 30 66 40 240 40 108 93 43 0 81 13 38 21 38 58 32 237 88 63 25 218 17 39 68 237 16 0 10 181 31 162 155 29 219 194 100 31 16 249 211 201 33 57 90 137 179 68 4 180 152 165 233 137 208 199 164 231 177 248 194 1 1 1 0 1 246 0 1 1 184 241 145 254 161 208 24 110 195 21 252 87 60 41 77 27 204 211 232 31 28 78 205 173 7 225 63 57 133 45 245 58 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]}
2022/04/11 23:18:18.825583 get_token.go:130: err <nil>, metadata {Key:4 UpdateAuthority:DC2mkgwhy56w3viNtHDjJQmc7SGu2QX785bS4aexojwX Mint:9MwGzSyuQRqmBHqmYwE6wbP3vzRBj4WWiYxWns3rkR7A Data:{Name:Degen Ape #7225 Symbol:DAPE Uri:https://arweave.net/KzX7jkL6tMEcLIxTPqFEVSLMiTuvndTqMJ1gevjcu8Y SellerFeeBasisPoints:420 Creators:0xc00042c1f8} PrimarySaleHappened:true IsMutable:false EditionNonce:0xc00050ad91 TokenStandard:0xc00050ada9 Collection:0xc000394420 Uses:0xc0003ee060}
2022/04/11 23:18:18.825590 get_token.go:131: metadata.TokenStandard 0
2022/04/11 23:18:18.825596 get_token.go:132: metadata.Collection &{Verified:true Key:DSwfRF1jhhu6HpSuzaig1G19kzP73PfLZBPLofkw6fLD}
2022/04/11 23:18:18.825602 get_token.go:133: metadata.Uses &{UseMethod:0 Remaining:0 Total:0}

You can check it here:

https://explorer.solana.com/address/9MwGzSyuQRqmBHqmYwE6wbP3vzRBj4WWiYxWns3rkR7A

omarkilani commented 2 years ago

This token (8YzEAA3S6xDUyMxhSvf2NbMXatK819PpLgySC81kcboQ) doesn't have the token_standard/collection/uses data and the fields are set to zeroes instead of nil. I'm not sure why borsh-go is doing that.

2022/04/11 23:22:56.718145 get_token.go:125: metadataAcct CCU4cMhKZkwujDaff8ZymvTfosa3TMRmNRc4pLUiMSvv
2022/04/11 23:22:56.718150 solana.go:1004: GetAccountInfo(https://young-sparkling-sun.solana-mainnet.quiknode.pro/[xxx]/): address CCU4cMhKZkwujDaff8ZymvTfosa3TMRmNRc4pLUiMSvv
2022/04/11 23:22:56.847017 get_token.go:128: accInfo {Lamports:5616720 Owner:metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s Executable:false RentEpoch:298 Data:[4 92 224 174 129 219 163 18 255 7 39 134 215 169 151 252 230 58 171 225 219 206 204 127 135 54 26 41 189 210 18 230 122 112 51 133 42 170 199 60 59 242 48 118 4 220 89 99 191 199 197 63 38 10 178 181 114 42 145 7 129 92 192 122 179 32 0 0 0 79 71 32 65 116 97 100 105 97 110 115 32 35 49 55 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 0 65 84 68 0 0 0 0 0 0 0 200 0 0 0 104 116 116 112 115 58 47 47 97 114 119 101 97 118 101 46 110 101 116 47 110 102 86 89 88 120 99 122 97 55 50 113 88 109 82 87 90 106 45 118 85 99 99 99 73 122 69 87 67 99 76 122 88 102 74 86 56 98 110 99 82 98 119 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 88 2 1 4 0 0 0 56 203 190 119 128 180 226 208 30 171 124 58 189 45 114 52 142 151 22 211 181 86 138 130 206 187 92 249 69 21 114 181 1 0 12 173 162 218 116 180 0 195 137 142 198 199 58 183 142 24 217 23 106 233 104 191 241 151 84 212 249 156 157 26 210 40 0 90 114 204 63 53 69 11 132 254 93 214 70 20 35 27 162 213 10 249 245 87 131 37 225 135 242 240 157 188 71 242 79 147 0 5 249 214 220 125 128 72 167 116 243 75 46 16 87 28 91 181 161 221 93 115 1 29 109 14 165 154 34 245 103 65 101 88 1 5 1 1 1 255 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]}
2022/04/11 23:22:56.847095 get_token.go:130: err <nil>, metadata {Key:4 UpdateAuthority:7FZDdgbyUv1gWQ89uV4NpnfpRBgr4S7zhKLC1BKdttZP Mint:8YzEAA3S6xDUyMxhSvf2NbMXatK819PpLgySC81kcboQ Data:{Name:OG Atadians #17 Symbol:ATD Uri:https://arweave.net/nfVYXxcza72qXmRWZj-vUcccIzEWCcLzXfJV8bncRbw SellerFeeBasisPoints:600 Creators:0xc000127998} PrimarySaleHappened:true IsMutable:true EditionNonce:0xc000122e59 TokenStandard:0xc000122e71 Collection:0xc00002f3b0 Uses:0xc000625ab8}
2022/04/11 23:22:56.847101 get_token.go:131: metadata.TokenStandard 0
2022/04/11 23:22:56.847105 get_token.go:132: metadata.Collection &{Verified:false Key:11111111111111111111111111111111}
2022/04/11 23:22:56.847110 get_token.go:133: metadata.Uses &{UseMethod:0 Remaining:0 Total:0}
omarkilani commented 2 years ago

@yihau this turned out to be a "bug" in borsh-go.

This line returns a zeroed struct on optional types when an optional field isn't set in the serialized borsh data:

https://github.com/near/borsh-go/blob/master/borsh.go#L224

I don't think there's anything that can be done in solana-go-sdk.

There's probably a good reason it's like this in borsh-go, but I'll try to figure it out.

I've opened an issue:

https://github.com/near/borsh-go/issues/13

yihau commented 2 years ago

yeah. I think it is a feature from borsh-go. Thank you for all you have done.

omarkilani commented 2 years ago

@yihau thank you for a great library! It powers all of MoonRank. :)

omarkilani commented 2 years ago

@yihau btw, borsh-go have implemented nil for optional values, so if you bump the dep it should just work.

yihau commented 2 years ago

oh! Thank you for the information. I will do it later 🔥