Skip to content

Commit

Permalink
Merge pull request #75 from blockfrost/fix/asset-metadata
Browse files Browse the repository at this point in the history
fix: allow arbitrary asset onchain metadata
  • Loading branch information
slowbackspace authored Dec 20, 2023
2 parents 3cdc7c6 + cc938da commit ae8e79f
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 18 deletions.
7 changes: 1 addition & 6 deletions api_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ const (
resourcePolicyAssets = "assets/policy"
)

type AssetOnchainMetadata struct {
Name string `json:"name"`
Image string `json:"image"`
}

// Contains metadata information about an asset.
type AssetMetadata struct {
Name string `json:"name"`
Expand Down Expand Up @@ -56,7 +51,7 @@ type Asset struct {
MintOrBurnCount int `json:"mint_or_burn_count"`

// On-chain metadata which SHOULD adhere to the valid standards, based on which we perform the look up and display the asset (best effort)
OnchainMetadata *AssetOnchainMetadata `json:"onchain_metadata"`
OnchainMetadata *interface{} `json:"onchain_metadata"`
// Enum: "CIP25v1" "CIP25v2" "CIP68v1"
// If on-chain metadata passes validation, we display the standard under which it is valid
OnchainMetadataStandard *string `json:"onchain_metadata_standard"`
Expand Down
24 changes: 20 additions & 4 deletions api_assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ import (
)

func TestAssetUnmarshal(t *testing.T) {

var onchainMetadata interface{} = map[string]interface{}{
"image": "ipfs://ipfs/QmfKyJ4tuvHowwKQCbCHj4L5T3fSj8cjs7Aau8V7BWv226",
"name": "My NFT token",
"description": "optional",
}

fp := filepath.Join(testdata, "json", "assets", "asset.json")
want := blockfrost.Asset{
Asset: "b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e",
Expand All @@ -21,10 +28,7 @@ func TestAssetUnmarshal(t *testing.T) {
InitialMintTxHash: "6804edf9712d2b619edb6ac86861fe93a730693183a262b165fcc1ba1bc99cad",
MintOrBurnCount: 1,
Quantity: "12000",
OnchainMetadata: &blockfrost.AssetOnchainMetadata{
Image: "ipfs://ipfs/QmfKyJ4tuvHowwKQCbCHj4L5T3fSj8cjs7Aau8V7BWv226",
Name: "My NFT token",
},
OnchainMetadata: &onchainMetadata,
Metadata: &blockfrost.AssetMetadata{
Name: "nutcoin",
Description: "The Nut Coin",
Expand Down Expand Up @@ -62,6 +66,18 @@ func TestResourceAssetIntegration(t *testing.T) {
want := blockfrost.Asset{}
testIntUtil(t, fp, &got, &want)
}
func TestResourceAssetMetadataIntegration(t *testing.T) {
asset := "14696a4676909f4e3cb1f2e60e2e08e5abed70caf5c02699be97113943554259"
api := blockfrost.NewAPIClient(blockfrost.APIClientOptions{})

got, err := api.Asset(context.TODO(), asset)
if err != nil {
t.Fatal(err)
}
fp := filepath.Join(testdata, strings.ToLower(strings.TrimLeft(t.Name(), "Test"))+".golden")
want := blockfrost.Asset{}
testIntUtil(t, fp, &got, &want)
}

func TestResourceAssetHistoryIntegration(t *testing.T) {
asset := "3a9241cd79895e3a8d65261b40077d4437ce71e9d7c8c6c00e3f658e4669727374636f696e"
Expand Down
17 changes: 9 additions & 8 deletions testdata/json/assets/asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
"initial_mint_tx_hash": "6804edf9712d2b619edb6ac86861fe93a730693183a262b165fcc1ba1bc99cad",
"mint_or_burn_count": 1,
"onchain_metadata": {
"name": "My NFT token",
"image": "ipfs://ipfs/QmfKyJ4tuvHowwKQCbCHj4L5T3fSj8cjs7Aau8V7BWv226"
"name": "My NFT token",
"image": "ipfs://ipfs/QmfKyJ4tuvHowwKQCbCHj4L5T3fSj8cjs7Aau8V7BWv226",
"description": "optional"
},
"metadata": {
"name": "nutcoin",
"description": "The Nut Coin",
"ticker": "nutc",
"url": "https://www.stakenuts.com/",
"logo": "42",
"decimals": 6
"name": "nutcoin",
"description": "The Nut Coin",
"ticker": "nutc",
"url": "https://www.stakenuts.com/",
"logo": "42",
"decimals": 6
}
}
Loading

0 comments on commit ae8e79f

Please sign in to comment.