-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'judez/added-embed-pds' into loic/fix-pack-nft-entitlement
- Loading branch information
Showing
11 changed files
with
140 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package common | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"regexp" | ||
) | ||
|
||
var ( | ||
placeholderNonFungibleToken = regexp.MustCompile(`"[^"\s]?.*NonFungibleToken(\.cdc)?"`) | ||
placeholderExampleNFT = regexp.MustCompile(`"[^"\s].*ExampleNFT.cdc"`) | ||
placeholderMetadataViews = regexp.MustCompile(`"[^"\s].*MetadataViews.cdc"`) | ||
placeholderFungibleToken = regexp.MustCompile(`"[^"\s].*FungibleToken.cdc"`) | ||
) | ||
|
||
type Replacer map[AddressName]*regexp.Regexp | ||
|
||
type AddressName string | ||
|
||
const ( | ||
NonFungibleTokenAddr AddressName = "NonFungibleToken" | ||
) | ||
|
||
func NewReplacer() Replacer { | ||
xxx := map[AddressName]*regexp.Regexp{ | ||
NonFungibleTokenAddr: placeholderNonFungibleToken, | ||
} | ||
return xxx | ||
} | ||
|
||
func (r Replacer) ReplaceAddresses(code string, data interface{}) (string, error) { | ||
|
||
val := reflect.ValueOf(data) | ||
if val.Kind() != reflect.Struct { | ||
return "", fmt.Errorf("data must be a struct") | ||
} | ||
|
||
var code1 = code | ||
for i := 0; i < val.NumField(); i++ { | ||
field := val.Type().Field(i) | ||
fieldName := field.Name | ||
fieldValue := val.Field(i).String() | ||
|
||
placeholder := AddressName(fieldName) | ||
if r[placeholder] == nil { | ||
return "", fmt.Errorf("no placeholder found for %s", placeholder) | ||
} | ||
|
||
code1 = r[placeholder].ReplaceAllString(code1, "0x"+fieldValue) | ||
fmt.Printf(`"%s %s"\n`, fieldName, fieldValue) | ||
} | ||
return code1, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package common | ||
|
||
import ( | ||
"github.com/dapperlabs/studio-platform-smart-contracts/pds" | ||
"testing" | ||
) | ||
|
||
func TestGetUserOwnedEditionToMomentMap_Transaction(t *testing.T) { | ||
script, err := pds.Transaction.ReadFile("transactions/deploy/deploy-packNFT-with-auth.cdc") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
t.Log(string(script)) | ||
} | ||
|
||
func TestGetUserOwnedEditionToMomentMap_Script(t *testing.T) { | ||
script, err := pds.Scripts.ReadFile("scripts/packNFT/balance_packNFT.cdc") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
t.Log(string(script)) | ||
dddd := NewReplacer() | ||
aaa, err := dddd.ReplaceAddresses(string(script), struct { | ||
NonFungibleToken string | ||
}{ | ||
"0x1", | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
t.Log(aaa) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/dapperlabs/studio-platform-smart-contracts | ||
|
||
go 1.20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package pds | ||
|
||
import ( | ||
"embed" | ||
) | ||
|
||
//go:embed transactions/* | ||
var Transactions embed.FS | ||
|
||
//go:embed scripts/* | ||
var Scripts embed.FS | ||
|
||
//go:embed contracts/* | ||
var Contracts embed.FS |
12 changes: 7 additions & 5 deletions
12
pds/transactions/dapperSport/link_providerCap_dapperSport.cdc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
import NonFungibleToken from 0x{{.NonFungibleToken}} | ||
import {{.DapperSportContract}} from 0x{{.DapperSportAddress}} | ||
import NonFungibleToken from "NonFungibleToken" | ||
import DapperSport from "DapperSport" | ||
|
||
transaction(NFTProviderPath: PrivatePath) { | ||
|
||
prepare(signer: AuthAccount) { | ||
if signer.getCapability<&{NonFungibleToken.Provider}>(NFTProviderPath).check() { | ||
prepare(signer: auth(Capabilities) &Account) { | ||
if signer.capabilities.get<&{NonFungibleToken.Provider}>(at: NFTProviderPath).check() { | ||
return | ||
} | ||
let cap = signer.capabilities.storage.issue<&{NonFungibleToken.Provider}>(target: DapperSport.CollectionStoragePath) | ||
|
||
// This needs to be used to allow for PDS to withdraw | ||
signer.link<&{NonFungibleToken.Provider}>( NFTProviderPath, target: {{.DapperSportContract}}.CollectionStoragePath) | ||
signer.capabilities.publish(cap, at: NFTProviderPath) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import PDS from "PDS" | ||
import ExampleNFT from "ExampleNFT" | ||
|
||
transaction (distId: UInt64, nftIDs: [UInt64]) { | ||
transaction (NFTProviderPath: String, distId: UInt64, nftIDs: [UInt64]) { | ||
prepare(pds: auth(BorrowValue) &Account) { | ||
let cap = pds.storage.borrow<&PDS.DistributionManager>(from: PDS.DistManagerStoragePath) | ||
?? panic("pds does not have Dist manager") | ||
cap.withdraw( | ||
distId: distId, | ||
nftIDs: nftIDs, | ||
escrowCollectionPublic: PublicPath(identifier: "exampleNFTCollection")!, | ||
escrowCollectionPublic: PublicPath(identifier: NFTProviderPath)!, | ||
) | ||
} | ||
} |