Skip to content

Commit 17bd2f4

Browse files
authored
Merge pull request #93 from dapperlabs/seanp/add-delisting-txs
Add delisting txs for NftStorefront and NftStorefrontV2
2 parents ab16cc1 + e71cde4 commit 17bd2f4

3 files changed

Lines changed: 96 additions & 0 deletions

File tree

atlas/embed.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ var (
1414

1515
//go:embed transactions/user/fulfill_pack_buyback_offer.cdc
1616
AdminFulfillPackBuybackOffer []byte
17+
18+
//go:embed transactions/user/delist_NftStorefront.cdc
19+
DelistNFTStorefront []byte
20+
21+
//go:embed transactions/user/delist_NftStorefrontV2.cdc
22+
DelistNFTStorefrontV2 []byte
1723
)
1824

1925
type UserBuyPacksPrimarySaleParams struct {
@@ -89,3 +95,57 @@ func AdminFulfillPackBuybackOfferTxScript(params AdminFulfillPackBuybackOfferPar
8995
}
9096
return string(bytes), nil
9197
}
98+
99+
type DelistNFTStorefrontTxScriptParams struct {
100+
NFTStorefrontAddress string
101+
listingResourceIDs []uint64
102+
}
103+
104+
func (p DelistNFTStorefrontTxScriptParams) Validate() error {
105+
if p.NFTStorefrontAddress == "" {
106+
return fmt.Errorf("NFTStorefrontAddress must be non-empty")
107+
}
108+
109+
if len(p.listingResourceIDs) == 0 {
110+
return fmt.Errorf("listingResourceIDs must contain at least one ID")
111+
}
112+
return nil
113+
}
114+
115+
func DelistNFTStorefrontTxScript(params DelistNFTStorefrontTxScriptParams) (string, error) {
116+
if err := params.Validate(); err != nil {
117+
return "", err
118+
}
119+
bytes, err := utils.ParseCadenceTemplate(DelistNFTStorefront, params)
120+
if err != nil {
121+
return "", err
122+
}
123+
return string(bytes), nil
124+
}
125+
126+
type DelistNFTStorefrontV2TxScriptParams struct {
127+
NFTStorefrontAddressV2 string
128+
listingResourceIDs []uint64
129+
}
130+
131+
func (p DelistNFTStorefrontV2TxScriptParams) Validate() error {
132+
if p.NFTStorefrontAddressV2 == "" {
133+
return fmt.Errorf("NFTStorefrontAddress must be non-empty")
134+
}
135+
136+
if len(p.listingResourceIDs) == 0 {
137+
return fmt.Errorf("listingResourceIDs must contain at least one ID")
138+
}
139+
return nil
140+
}
141+
142+
func DelistNFTStorefrontV2TxScript(params DelistNFTStorefrontV2TxScriptParams) (string, error) {
143+
if err := params.Validate(); err != nil {
144+
return "", err
145+
}
146+
bytes, err := utils.ParseCadenceTemplate(DelistNFTStorefrontV2, params)
147+
if err != nil {
148+
return "", err
149+
}
150+
return string(bytes), nil
151+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import NFTStorefront from 0x{{.NFTStorefrontAddress}}
2+
3+
// removes an NFT listing from NFTStorefront
4+
transaction() {
5+
let storefront: auth(NFTStorefront.RemoveListing) &NFTStorefront.Storefront
6+
7+
prepare(acct: auth(Storage) &Account) {
8+
self.storefront = acct.storage.borrow<auth(NFTStorefront.RemoveListing) &NFTStorefront.Storefront>(from: NFTStorefront.StorefrontStoragePath)
9+
?? panic("Missing or mis-typed NFTStorefront.Storefront")
10+
}
11+
12+
execute {
13+
let listingResourceIDs: [Uint64] = [{{.listingResourceIDs}}]
14+
for resourceID in listingResourceIDs {
15+
self.storefront.removeListing(listingResourceID: resourceID)
16+
}
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import NFTStorefrontV2 from 0x{{.NFTStorefrontV2Address}}
2+
3+
// removes an NFT listing from NFTStorefrontV2
4+
transaction() {
5+
let storefront: auth(NFTStorefrontV2.RemoveListing) &NFTStorefrontV2.Storefront
6+
7+
prepare(acct: auth(Storage) &Account) {
8+
self.storefront = acct.storage.borrow<auth(NFTStorefrontV2.RemoveListing) &NFTStorefrontV2.Storefront>(from: NFTStorefrontV2.StorefrontStoragePath)
9+
?? panic("Missing or mis-typed NFTStorefrontV2.Storefront resource")
10+
}
11+
12+
execute {
13+
let listingResourceIDs: [Uint64] = [{{.listingResourceIDs}}]
14+
for resourceID in listingResourceIDs {
15+
self.storefront.removeListing(listingResourceID: resourceID)
16+
}
17+
}
18+
}z

0 commit comments

Comments
 (0)