Skip to content

Commit 4aa2772

Browse files
authoredMar 7, 2025··
Adds CrossVMMetadataViews to templates package (#477)
* add CrossVMMetadataViews to templates package * add getters for ExampleToken and ExampleNFT * add LinearCodeAddressGenerator to contracts * update NFT contracts version
1 parent 1102446 commit 4aa2772

File tree

7 files changed

+84
-49
lines changed

7 files changed

+84
-49
lines changed
 

‎lib/go/contracts/contracts.go

+30-16
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
_ "github.com/kevinburke/go-bindata"
1010
ftcontracts "github.com/onflow/flow-ft/lib/go/contracts"
11+
"github.com/onflow/flow-go-sdk"
1112
nftcontracts "github.com/onflow/flow-nft/lib/go/contracts"
1213

1314
"github.com/onflow/flow-core-contracts/lib/go/templates"
@@ -26,22 +27,23 @@ import (
2627
///
2728

2829
const (
29-
flowFeesFilename = "FlowFees.cdc"
30-
storageFeesFilename = "FlowStorageFees.cdc"
31-
executionParametersFilename = "FlowExecutionParameters.cdc"
32-
flowServiceAccountFilename = "FlowServiceAccount.cdc"
33-
flowTokenFilename = "FlowToken.cdc"
34-
flowIdentityTableFilename = "FlowIDTableStaking.cdc"
35-
flowQCFilename = "epochs/FlowClusterQC.cdc"
36-
flowDKGFilename = "epochs/FlowDKG.cdc"
37-
flowEpochFilename = "epochs/FlowEpoch.cdc"
38-
flowLockedTokensFilename = "LockedTokens.cdc"
39-
flowStakingProxyFilename = "StakingProxy.cdc"
40-
flowStakingCollectionFilename = "FlowStakingCollection.cdc"
41-
flowContractAuditsFilename = "FlowContractAudits.cdc"
42-
flowNodeVersionBeaconFilename = "NodeVersionBeacon.cdc"
43-
flowRandomBeaconHistoryFilename = "RandomBeaconHistory.cdc"
44-
cryptoFilename = "Crypto.cdc"
30+
flowFeesFilename = "FlowFees.cdc"
31+
storageFeesFilename = "FlowStorageFees.cdc"
32+
executionParametersFilename = "FlowExecutionParameters.cdc"
33+
flowServiceAccountFilename = "FlowServiceAccount.cdc"
34+
flowTokenFilename = "FlowToken.cdc"
35+
flowIdentityTableFilename = "FlowIDTableStaking.cdc"
36+
flowQCFilename = "epochs/FlowClusterQC.cdc"
37+
flowDKGFilename = "epochs/FlowDKG.cdc"
38+
flowEpochFilename = "epochs/FlowEpoch.cdc"
39+
flowLockedTokensFilename = "LockedTokens.cdc"
40+
flowStakingProxyFilename = "StakingProxy.cdc"
41+
flowStakingCollectionFilename = "FlowStakingCollection.cdc"
42+
flowContractAuditsFilename = "FlowContractAudits.cdc"
43+
flowNodeVersionBeaconFilename = "NodeVersionBeacon.cdc"
44+
flowRandomBeaconHistoryFilename = "RandomBeaconHistory.cdc"
45+
cryptoFilename = "Crypto.cdc"
46+
linearCodeAddressGeneratorFilename = "LinearCodeAddressGenerator.cdc"
4547

4648
// Test contracts
4749
// only used for testing
@@ -301,6 +303,10 @@ func Crypto() []byte {
301303
return assets.MustAsset(cryptoFilename)
302304
}
303305

306+
func LinearCodeAddressGenerator() []byte {
307+
return assets.MustAsset(linearCodeAddressGeneratorFilename)
308+
}
309+
304310
/******************** Test contracts *********************/
305311

306312
// TESTFlowIDTableStaking returns the TestFlowIDTableStaking contract
@@ -361,3 +367,11 @@ func TestFlowFees(fungibleTokenAddress, flowTokenAddress, storageFeesAddress str
361367

362368
return []byte(code)
363369
}
370+
371+
func ExampleToken(env templates.Environment) []byte {
372+
return ftcontracts.ExampleToken(env.FungibleTokenAddress, env.MetadataViewsAddress, env.FungibleTokenMetadataViewsAddress)
373+
}
374+
375+
func ExampleNFT(env templates.Environment) []byte {
376+
return nftcontracts.ExampleNFTWithCrossVMPointers(flow.HexToAddress(env.NonFungibleTokenAddress), flow.HexToAddress(env.MetadataViewsAddress), flow.HexToAddress(env.ViewResolverAddress), flow.HexToAddress(env.EVMAddress), flow.HexToAddress(env.CrossVMMetadataViewsAddress))
377+
}

‎lib/go/contracts/contracts_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ func TestCrypto(t *testing.T) {
174174
GetCadenceContractShouldSucceed(t, contract)
175175
}
176176

177+
func TestLinearCodeAddressGenerator(t *testing.T) {
178+
contract := string(contracts.LinearCodeAddressGenerator())
179+
GetCadenceContractShouldSucceed(t, contract)
180+
}
181+
177182
func TestFlowExecutionParameters(t *testing.T) {
178183
env := templates.Environment{}
179184
SetAllAddresses(&env)

‎lib/go/contracts/go.mod

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ toolchain go1.22.4
66

77
require (
88
github.com/kevinburke/go-bindata v3.24.0+incompatible
9-
github.com/onflow/flow-core-contracts/lib/go/templates v1.5.1-preview
9+
github.com/onflow/flow-core-contracts/lib/go/templates v1.6.1-0.20250226163127-3c9723416637
1010
github.com/onflow/flow-ft/lib/go/contracts v1.0.1
11-
github.com/onflow/flow-nft/lib/go/contracts v1.2.3
11+
github.com/onflow/flow-go-sdk v1.0.0-preview.54
12+
github.com/onflow/flow-nft/lib/go/contracts v1.2.4
1213
github.com/stretchr/testify v1.9.0
1314
)
1415

@@ -38,7 +39,6 @@ require (
3839
github.com/onflow/cadence v1.0.0-preview.51 // indirect
3940
github.com/onflow/crypto v0.25.1 // indirect
4041
github.com/onflow/flow-ft/lib/go/templates v1.0.1 // indirect
41-
github.com/onflow/flow-go-sdk v1.0.0-preview.54 // indirect
4242
github.com/onflow/flow-nft/lib/go/templates v1.2.1 // indirect
4343
github.com/onflow/flow/protobuf/go/flow v0.4.3 // indirect
4444
github.com/onflow/go-ethereum v1.13.4 // indirect

‎lib/go/contracts/go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,16 @@ github.com/onflow/cadence v1.0.0-preview.51 h1:L+toCS2Sw9bsExc2PxeNMmAK96fn2LdTO
221221
github.com/onflow/cadence v1.0.0-preview.51/go.mod h1:7wvvecnAZtYOspLOS3Lh+FuAmMeSrXhAWiycC3kQ1UU=
222222
github.com/onflow/crypto v0.25.1 h1:0txy2PKPMM873JbpxQNbJmuOJtD56bfs48RQfm0ts5A=
223223
github.com/onflow/crypto v0.25.1/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI=
224-
github.com/onflow/flow-core-contracts/lib/go/templates v1.5.1-preview h1:C0PraQFfwpav4nJAf/RPE9BJyYD6lUMvt+cJyiMDeis=
225-
github.com/onflow/flow-core-contracts/lib/go/templates v1.5.1-preview/go.mod h1:pN768Al/wLRlf3bwugv9TyxniqJxMu4sxnX9eQJam64=
224+
github.com/onflow/flow-core-contracts/lib/go/templates v1.6.1-0.20250226163127-3c9723416637 h1:EhhRQDEAc5K3NOtFF+Qd7eXKOToYxEOtSqOtt70ia/Y=
225+
github.com/onflow/flow-core-contracts/lib/go/templates v1.6.1-0.20250226163127-3c9723416637/go.mod h1:pN768Al/wLRlf3bwugv9TyxniqJxMu4sxnX9eQJam64=
226226
github.com/onflow/flow-ft/lib/go/contracts v1.0.1 h1:Ts5ob+CoCY2EjEd0W6vdLJ7hLL3SsEftzXG2JlmSe24=
227227
github.com/onflow/flow-ft/lib/go/contracts v1.0.1/go.mod h1:PwsL8fC81cjnUnTfmyL/HOIyHnyaw/JA474Wfj2tl6A=
228228
github.com/onflow/flow-ft/lib/go/templates v1.0.1 h1:FDYKAiGowABtoMNusLuRCILIZDtVqJ/5tYI4VkF5zfM=
229229
github.com/onflow/flow-ft/lib/go/templates v1.0.1/go.mod h1:uQ8XFqmMK2jxyBSVrmyuwdWjTEb+6zGjRYotfDJ5pAE=
230230
github.com/onflow/flow-go-sdk v1.0.0-preview.54 h1:5GjCkyIyvE9KolOUUPTkGdEiV/8qOe1MGnLHOLBmthA=
231231
github.com/onflow/flow-go-sdk v1.0.0-preview.54/go.mod h1:u9oFiS25TpnU1EW62PQlq22jzkwBAj4VEiiCBM6nhHo=
232-
github.com/onflow/flow-nft/lib/go/contracts v1.2.3 h1:4ju20g1xgDKWBT63rOj5f/Sa4Lc+naCSWT4p31x9yQk=
233-
github.com/onflow/flow-nft/lib/go/contracts v1.2.3/go.mod h1:eZ9VMMNfCq0ho6kV25xJn1kXeCfxnkhj3MwF3ed08gY=
232+
github.com/onflow/flow-nft/lib/go/contracts v1.2.4 h1:gWJgSSgIGo0qWOqr90+khQ69VoYF9vNlqzF+Yh6YYy4=
233+
github.com/onflow/flow-nft/lib/go/contracts v1.2.4/go.mod h1:eZ9VMMNfCq0ho6kV25xJn1kXeCfxnkhj3MwF3ed08gY=
234234
github.com/onflow/flow-nft/lib/go/templates v1.2.1 h1:SAALMZPDw9Eb9p5kSLnmnFxjyig1MLiT4JUlLp0/bSE=
235235
github.com/onflow/flow-nft/lib/go/templates v1.2.1/go.mod h1:W6hOWU0xltPqNpv9gQX8Pj8Jtf0OmRxc1XX2V0kzJaI=
236236
github.com/onflow/flow/protobuf/go/flow v0.4.3 h1:gdY7Ftto8dtU+0wI+6ZgW4oE+z0DSDUMIDwVx8mqae8=

‎lib/go/templates/templates.go

+38-22
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,30 @@ import (
1414
)
1515

1616
const (
17-
placeholderFungibleTokenAddress = "\"FungibleToken\""
18-
placeholderNonFungibleTokenAddress = "\"NonFungibleToken\""
19-
placeholderEVMAddress = "\"EVM\""
20-
placeholderViewResolverAddress = "\"ViewResolver\""
21-
placeholderFungibleTokenMVAddress = "\"FungibleTokenMetadataViews\""
22-
placeholderMetadataViewsAddress = "\"MetadataViews\""
23-
placeholderBurnerAddress = "\"Burner\""
24-
placeholderCryptoAddress = "\"Crypto\""
25-
placeholderFlowTokenAddress = "\"FlowToken\""
26-
placeholderIDTableAddress = "\"FlowIDTableStaking\""
27-
placeholderLockedTokensAddress = "\"LockedTokens\""
28-
placeholderStakingProxyAddress = "\"StakingProxy\""
29-
placeholderQuorumCertificateAddress = "\"FlowClusterQC\""
30-
placeholderFlowFeesAddress = "\"FlowFees\""
31-
placeholderStorageFeesAddress = "\"FlowStorageFees\""
32-
placeholderExecutionParametersAddress = "\"FlowExecutionParameters\""
33-
placeholderServiceAccountAddress = "\"FlowServiceAccount\""
34-
placeholderDKGAddress = "\"FlowDKG\""
35-
placeholderEpochAddress = "\"FlowEpoch\""
36-
placeholderStakingCollectionAddress = "\"FlowStakingCollection\""
37-
placeholderNodeVersionBeaconAddress = "\"NodeVersionBeacon\""
38-
placeholderRandomBeaconHistoryAddress = "\"RandomBeaconHistory\""
17+
placeholderFungibleTokenAddress = "\"FungibleToken\""
18+
placeholderNonFungibleTokenAddress = "\"NonFungibleToken\""
19+
placeholderEVMAddress = "\"EVM\""
20+
placeholderViewResolverAddress = "\"ViewResolver\""
21+
placeholderFungibleTokenMVAddress = "\"FungibleTokenMetadataViews\""
22+
placeholderMetadataViewsAddress = "\"MetadataViews\""
23+
placeholderCrossVMMetadataViewsAddress = "\"CrossVMMetadataViews\""
24+
placeholderBurnerAddress = "\"Burner\""
25+
placeholderCryptoAddress = "\"Crypto\""
26+
placeholderFlowTokenAddress = "\"FlowToken\""
27+
placeholderIDTableAddress = "\"FlowIDTableStaking\""
28+
placeholderLockedTokensAddress = "\"LockedTokens\""
29+
placeholderStakingProxyAddress = "\"StakingProxy\""
30+
placeholderQuorumCertificateAddress = "\"FlowClusterQC\""
31+
placeholderFlowFeesAddress = "\"FlowFees\""
32+
placeholderStorageFeesAddress = "\"FlowStorageFees\""
33+
placeholderExecutionParametersAddress = "\"FlowExecutionParameters\""
34+
placeholderServiceAccountAddress = "\"FlowServiceAccount\""
35+
placeholderDKGAddress = "\"FlowDKG\""
36+
placeholderEpochAddress = "\"FlowEpoch\""
37+
placeholderStakingCollectionAddress = "\"FlowStakingCollection\""
38+
placeholderNodeVersionBeaconAddress = "\"NodeVersionBeacon\""
39+
placeholderRandomBeaconHistoryAddress = "\"RandomBeaconHistory\""
40+
placeholderLinearCodeAddressGeneratorAddress = "\"LinearCodeAddressGenerator\""
3941
)
4042

4143
type Environment struct {
@@ -47,6 +49,7 @@ type Environment struct {
4749
NonFungibleTokenAddress string
4850
EVMAddress string
4951
MetadataViewsAddress string
52+
CrossVMMetadataViewsAddress string
5053
FungibleTokenMetadataViewsAddress string
5154
FungibleTokenSwitchboardAddress string
5255
FlowTokenAddress string
@@ -63,6 +66,7 @@ type Environment struct {
6366
ServiceAccountAddress string
6467
NodeVersionBeaconAddress string
6568
RandomBeaconHistoryAddress string
69+
LinearCodeAddressGeneratorAddress string
6670
}
6771

6872
func withHexPrefix(address string) string {
@@ -112,6 +116,12 @@ func ReplaceAddresses(code string, env Environment) string {
112116
env.MetadataViewsAddress,
113117
)
114118

119+
code = ReplaceAddress(
120+
code,
121+
placeholderCrossVMMetadataViewsAddress,
122+
env.CrossVMMetadataViewsAddress,
123+
)
124+
115125
code = ReplaceAddress(
116126
code,
117127
placeholderBurnerAddress,
@@ -232,5 +242,11 @@ func ReplaceAddresses(code string, env Environment) string {
232242
env.RandomBeaconHistoryAddress,
233243
)
234244

245+
code = ReplaceAddress(
246+
code,
247+
placeholderLinearCodeAddressGeneratorAddress,
248+
env.LinearCodeAddressGeneratorAddress,
249+
)
250+
235251
return code
236252
}

‎lib/go/test/go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ require (
129129
github.com/onflow/bridged-usdc/lib/go/contracts v1.0.0 // indirect
130130
github.com/onflow/flow-ft/lib/go/contracts v1.0.1 // indirect
131131
github.com/onflow/flow-ft/lib/go/templates v1.0.1 // indirect
132-
github.com/onflow/flow-nft/lib/go/contracts v1.2.3 // indirect
132+
github.com/onflow/flow-nft/lib/go/contracts v1.2.4 // indirect
133133
github.com/onflow/flow-nft/lib/go/templates v1.2.1 // indirect
134134
github.com/onflow/flow/protobuf/go/flow v0.4.7 // indirect
135135
github.com/onflow/go-ethereum v1.14.7 // indirect
@@ -213,7 +213,7 @@ require (
213213
// replaced by module version in this repo - disregard pinned version
214214
github.com/onflow/flow-core-contracts/lib/go/contracts v1.5.1-preview
215215
// replaced by module version in this repo - disregard pinned version
216-
github.com/onflow/flow-core-contracts/lib/go/templates v1.5.1-preview
216+
github.com/onflow/flow-core-contracts/lib/go/templates v1.6.1-0.20250226163127-3c9723416637
217217
)
218218

219219
replace github.com/onflow/flow-core-contracts/lib/go/contracts => ../contracts

‎lib/go/test/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,8 @@ github.com/onflow/flow-go v0.38.0-util.0.20250130182921-c8d283b60d12 h1:RUmzt0En
582582
github.com/onflow/flow-go v0.38.0-util.0.20250130182921-c8d283b60d12/go.mod h1:bXxLlDLhyMj05TGYWFJdKTZdySShJMT0eqgommYq48w=
583583
github.com/onflow/flow-go-sdk v1.3.1 h1:2YdTL/R1/DjMYYmyKgArTeQ93GKvLlfCeCpMVH7b8q4=
584584
github.com/onflow/flow-go-sdk v1.3.1/go.mod h1:0rMuCLShdX9F4pLBCPhlMGCFu8gu9SfiXT/Lc9qAi24=
585-
github.com/onflow/flow-nft/lib/go/contracts v1.2.3 h1:4ju20g1xgDKWBT63rOj5f/Sa4Lc+naCSWT4p31x9yQk=
586-
github.com/onflow/flow-nft/lib/go/contracts v1.2.3/go.mod h1:eZ9VMMNfCq0ho6kV25xJn1kXeCfxnkhj3MwF3ed08gY=
585+
github.com/onflow/flow-nft/lib/go/contracts v1.2.4 h1:gWJgSSgIGo0qWOqr90+khQ69VoYF9vNlqzF+Yh6YYy4=
586+
github.com/onflow/flow-nft/lib/go/contracts v1.2.4/go.mod h1:eZ9VMMNfCq0ho6kV25xJn1kXeCfxnkhj3MwF3ed08gY=
587587
github.com/onflow/flow-nft/lib/go/templates v1.2.1 h1:SAALMZPDw9Eb9p5kSLnmnFxjyig1MLiT4JUlLp0/bSE=
588588
github.com/onflow/flow-nft/lib/go/templates v1.2.1/go.mod h1:W6hOWU0xltPqNpv9gQX8Pj8Jtf0OmRxc1XX2V0kzJaI=
589589
github.com/onflow/flow/protobuf/go/flow v0.4.7 h1:iP6DFx4wZ3ETORsyeqzHu7neFT3d1CXF6wdK+AOOjmc=

0 commit comments

Comments
 (0)
Please sign in to comment.