Skip to content

Commit

Permalink
Allow unkown standard and details
Browse files Browse the repository at this point in the history
  • Loading branch information
ajamaica committed Nov 28, 2022
1 parent 1af0fc0 commit d6e045a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.metaplex.lib.serialization.serializers.solana.PublicKeyAs32ByteSerial
import com.metaplex.lib.shared.OperationError
import com.metaplex.lib.shared.ResultWithCustomError
import com.solana.core.PublicKey
import com.solana.networking.serialization.serializers.solana.PublicKeyAsStringSerializer
import com.solana.vendor.borshj.*
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
Expand All @@ -22,11 +23,11 @@ import org.bitcoinj.core.Base58
// this will be replaced with beet kt generated code in the near future

enum class MetaplexTokenStandard {
NonFungible, FungibleAsset, Fungible, NonFungibleEdition
NonFungible, FungibleAsset, Fungible, NonFungibleEdition, Unkown
}

enum class MetaplexCollectionDetails {
V1
V1, Unkown
}

@Serializable
Expand All @@ -44,10 +45,10 @@ data class MetadataAccount(
val primarySaleHappened: Boolean,
val isMutable: Boolean,
val editionNonce: UByte?,
val tokenStandard: MetaplexTokenStandard?,
@Serializable(with = MetaplexTokenStandardSerializer::class) val tokenStandard: MetaplexTokenStandard? = null,
val collection: MetaplexCollection?,
val uses: Uses? = null,
val collectionDetails: MetaplexCollectionDetails? = null
@Serializable(with = CollectionDetailsSerializer::class) val collectionDetails: MetaplexCollectionDetails? = null
) : BorshCodable {
companion object {
fun pda(publicKey: PublicKey): ResultWithCustomError<PublicKey, OperationError> {
Expand Down Expand Up @@ -115,8 +116,26 @@ object CollectionDetailsSerializer : KSerializer<MetaplexCollectionDetails> {
}

override fun deserialize(decoder: Decoder): MetaplexCollectionDetails {
return MetaplexCollectionDetails.values().get(decoder.decodeByte().toInt()).also {
decoder.decodeLong()
return MetaplexCollectionDetails.values().getOrNull(decoder.decodeByte().toInt())?.let {
it
}.run {
MetaplexCollectionDetails.Unkown
}
}
}

object MetaplexTokenStandardSerializer : KSerializer<MetaplexTokenStandard> {
override val descriptor = Byte.serializer().descriptor
override fun serialize(encoder: Encoder, value: MetaplexTokenStandard) {
encoder.encodeByte(value.ordinal.toByte())
encoder.encodeLong(0)
}

override fun deserialize(decoder: Decoder): MetaplexTokenStandard {
return MetaplexTokenStandard.values().getOrNull(decoder.decodeByte().toInt())?.let {
it
}.run {
MetaplexTokenStandard.Unkown
}
}
}
4 changes: 3 additions & 1 deletion sample/src/main/java/com/metaplex/sample/FirstFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ import com.metaplex.lib.modules.nfts.models.NFT
import com.metaplex.lib.solana.SolanaConnectionDriver
import com.metaplex.sample.databinding.FragmentFirstBinding
import com.solana.core.PublicKey
import com.solana.networking.Network
import com.solana.networking.RPCEndpoint
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.net.URL


/**
Expand Down Expand Up @@ -64,7 +66,7 @@ class FirstFragment : Fragment() {
activity?.finish()
}

val solanaConnection = SolanaConnectionDriver(RPCEndpoint.mainnetBetaSolana)
val solanaConnection = SolanaConnectionDriver(RPCEndpoint.custom(URL("https://api.metaplex.solana.com"), URL("https://api.metaplex.solana.com"), Network.mainnetBeta))
val solanaIdentityDriver = ReadOnlyIdentityDriver(ownerPublicKey, solanaConnection)
val storageDriver = OkHttpSharedStorageDriver()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ import com.metaplex.lib.modules.nfts.models.Value
import com.metaplex.lib.programs.token_metadata.accounts.MetaplexCreator
import com.metaplex.lib.solana.SolanaConnectionDriver
import com.solana.core.PublicKey
import com.solana.networking.Network
import com.solana.networking.RPCEndpoint
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.net.URL


class NftDetailsActivity : AppCompatActivity() {
Expand Down Expand Up @@ -71,7 +73,9 @@ class NftDetailsActivity : AppCompatActivity() {
ownerPublicKey = PublicKey(nftOwner)
setTitle(nftName)

val solanaConnection = SolanaConnectionDriver(RPCEndpoint.mainnetBetaSolana)
val solanaConnection = SolanaConnectionDriver(
RPCEndpoint.custom(URL("https://api.metaplex.solana.com"), URL("https://api.metaplex.solana.com"), Network.mainnetBeta)
)
val solanaIdentityDriver = ReadOnlyIdentityDriver(ownerPublicKey, solanaConnection)
val storageDriver = OkHttpSharedStorageDriver()

Expand Down

0 comments on commit d6e045a

Please sign in to comment.