diff --git a/lib/go/templates/internal/assets/assets.go b/lib/go/templates/internal/assets/assets.go index af6179d..8934b50 100644 --- a/lib/go/templates/internal/assets/assets.go +++ b/lib/go/templates/internal/assets/assets.go @@ -53,7 +53,7 @@ // ../../../transactions/marketV3/change_price.cdc (799B) // ../../../transactions/marketV3/change_receiver.cdc (477B) // ../../../transactions/marketV3/create_sale.cdc (1.85kB) -// ../../../transactions/marketV3/create_start_sale.cdc (3.418kB) +// ../../../transactions/marketV3/create_start_sale.cdc (5.563kB) // ../../../transactions/marketV3/mint_and_purchase.cdc (1.396kB) // ../../../transactions/marketV3/purchase_both_markets.cdc (2.368kB) // ../../../transactions/marketV3/purchase_group_of_moments.cdc (4.519kB) @@ -1247,7 +1247,7 @@ func TransactionsMarketv3Create_saleCdc() (*asset, error) { return a, nil } -var _TransactionsMarketv3Create_start_saleCdc = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x57\xdf\x6f\xe2\x38\x10\x7e\xe7\xaf\x98\xdb\x87\x2a\x48\x6c\xb8\xaa\xa7\x7b\x88\x60\x57\x3d\x5a\xee\xaa\xbd\xfe\x50\xa1\xbd\x67\x63\x06\xb0\x1a\xec\xc8\x99\xd0\xa2\x55\xff\xf7\x53\x9c\x9f\xb6\x43\xdb\x55\xc9\x0b\x89\x35\xf6\xcc\x37\xf3\xcd\xf8\x43\x6c\x13\xa5\x09\xa6\x99\x5c\x8b\x45\x8c\x73\xf5\x84\x12\x56\x5a\x6d\xe1\xf7\x97\xe9\xc3\xcd\xdf\x57\x7f\xfd\x7b\x39\xbf\xfd\x71\x79\x73\x7e\x71\x71\x7f\x39\x9b\xf5\xca\x0d\x73\x95\xcc\x36\x8a\xae\x99\x7e\x42\x7a\x3c\xab\xb6\x5c\x9f\xdf\xff\xb8\x9c\x3f\x9e\x75\x5b\x57\x56\xf3\xdb\xbb\xd9\x3f\xb7\x73\xc7\xa8\x38\xcb\x3e\xc9\x31\xb9\x51\xb2\x33\xd2\x9b\x69\x6d\xd9\x23\xcd\x64\xca\x38\x09\x25\x03\xca\x8d\xee\x91\xa3\xd8\xa1\xbe\x63\xb4\x89\xe0\x2e\x5b\xc4\x82\xe7\xef\x03\x58\xa0\xc4\x95\xe0\x82\xe9\xfd\x39\xe7\x2a\x93\x14\xc1\xf9\x72\xa9\x31\x4d\x07\xc0\x33\xba\x43\xcd\x51\x12\x5b\x63\x04\x0f\x53\xf1\xf2\xe7\x1f\x03\xd8\xaa\x2d\x4a\xba\xba\x88\xe0\xe1\x4a\x52\xbe\x92\x68\xc1\x6b\x83\x3e\xfc\xec\xf5\x00\x00\x12\x8d\x09\xd3\x18\x30\xce\x29\x02\x96\xd1\x26\x98\x91\xd2\x6c\x8d\x03\x98\xb0\x84\x2d\x44\x2c\x48\x60\xda\x87\x93\xd2\x77\xbe\x15\xca\x67\x38\x04\xbe\x41\xfe\x04\xa4\x20\x45\x04\xb1\x02\x06\xbb\x33\x48\x59\x8c\xc0\x55\x1c\xa3\x01\x08\x2c\xd6\xc8\x96\x7b\xc0\x17\x91\x52\x5a\x6f\xcf\xcd\x39\xa7\x30\x2d\x3c\x86\x0b\xa5\xb5\x7a\x1e\x9d\x38\x55\x0b\x67\x2c\xc6\x49\x7d\xda\xb7\x20\x4f\x67\xe4\xd6\x36\xdc\x9a\x97\x32\xfa\x3c\x73\x7d\x18\x8f\x41\x8a\xb8\x15\x70\x19\xf4\x1a\x09\x68\x83\xb0\x2a\xab\x04\xa6\x02\xc0\x5b\x80\x61\xa5\xb4\xb1\x51\xcf\x12\x35\x30\xb9\x6c\xd7\xc1\x3a\x30\x46\x2a\xac\xea\x84\xed\x61\x5c\x20\x6b\x9f\x18\xae\x91\x46\x27\x3f\x2d\x66\x84\x55\xd5\x5f\xbf\xf9\x2c\xe8\xff\xe6\xb9\x69\x85\x60\x39\x5b\x23\x95\xe5\x09\x7c\xb6\xf4\x3f\x1d\x86\x15\xc7\x8e\xe9\x12\x6e\x53\xe0\xb1\x5d\x48\xae\x92\xfd\xa8\x09\x70\x64\x78\xe5\x76\x45\xf8\x9f\xa0\xcd\x52\xb3\xe7\x81\xd7\x30\xe1\x43\xb2\x64\x84\x7d\xa8\xa8\x10\xb6\xca\x5f\xd5\x7f\x58\x7a\x1b\x5e\x1b\xae\x37\x16\x13\x96\xf4\xad\x88\xc5\xca\x0f\xb8\x8b\x19\xf9\x73\x00\x99\x95\xc1\x0a\xa6\x48\xd3\x0c\x8f\x0b\x2e\x38\x88\xaa\xef\x85\x6a\xa5\x3c\x65\x3b\x0c\x9c\xe0\x07\x40\xea\x57\xf2\xf4\xda\xeb\x6a\x14\xd6\xf4\xc5\xbe\xee\x8a\xdd\x69\xab\xbf\x3d\x7a\xec\x4e\xed\x96\xfd\x10\x3f\x8a\x46\x0e\x27\x1a\x19\x61\x47\xda\x9a\x8c\x96\x96\x75\x1e\xcb\x6f\x67\x4c\x78\x3c\x21\x95\xa4\x1b\x45\xb6\x59\x17\x59\xfc\xf0\x0f\xb1\xe5\x10\xd0\xf7\xe8\x72\x6c\xac\xc1\xdb\x20\x3f\xc2\x1d\x17\x8a\x43\x9e\x8f\x25\xcf\x67\x10\x37\x10\x81\x81\xc4\x67\xf7\x5e\xf0\xc6\x5b\xa7\x13\x18\x7d\xf5\x66\x7d\x71\xaa\x6d\xe7\xb2\x3f\x72\x7b\x79\xe0\x65\xe1\x53\x8f\x33\xf2\x23\x77\xe1\xc8\xee\x3a\x47\x7f\xd4\xbd\x7c\x64\xd7\x8e\xc6\xb0\x3e\x8f\xec\xaa\xb8\xc4\x1f\x4f\xdb\x10\x5d\x66\xda\x94\x73\x09\x97\x93\x19\x04\x19\x49\x52\x70\xd7\xb2\xf0\x89\x3f\xfa\xda\x49\xbb\x82\xff\xef\x8b\x8c\xde\xa1\x40\x6a\xe6\x27\x46\xcb\x41\x2c\xa4\x11\x4a\xf9\xf8\x7c\xa3\x11\xfc\xf9\x61\xf6\xa7\x9b\xa0\xbb\x89\xdf\x18\x35\xef\x0a\xa9\xf7\xd1\xf9\xe5\x65\x74\x28\x2b\x8d\x66\xb5\x36\x35\x19\x6a\x4d\x87\xe1\x10\x0a\xb5\x07\x0c\x34\xae\x50\xa3\xe4\xd8\xce\x4e\x6d\x79\x78\x2e\x8c\x3b\xd5\xa3\x99\xaf\x6e\x80\xc5\xa0\x6d\xae\xdc\x4f\x4b\x4b\x0b\xe1\xf7\xef\x90\x30\x29\x78\xf0\x65\xa2\xb2\x78\x09\x52\x51\x85\xce\x28\x7f\x53\x6d\x21\x2b\x3e\x7e\xe9\xe0\xcc\x70\x08\x49\x56\x88\xd2\x42\xba\x43\x96\x98\xcb\xd6\xca\x45\x67\x1e\xc2\x58\xa4\x34\x55\x3a\x5f\x2d\xd4\x5b\x2e\xfb\xab\x3f\x00\xb5\xf0\x37\x3f\x8e\xe7\xd7\xde\xeb\xff\x01\x00\x00\xff\xff\xb6\xae\xd4\x20\x5a\x0d\x00\x00" +var _TransactionsMarketv3Create_start_saleCdc = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x58\x5f\x73\xdb\x36\x0c\x7f\xf7\xa7\x40\xfb\xd0\xca\x77\x8e\xbc\x5c\x76\x7b\xf0\x25\xed\x65\xf9\xd3\xe5\xba\x26\xb9\xda\x49\x5f\x43\x53\xb0\xc5\xab\x4c\xea\x48\xca\xae\xd7\xcb\x77\xdf\x91\xa2\x2c\x89\x94\xe2\x6c\xf3\xf2\xd0\xda\x32\x08\x80\x3f\x00\x3f\x00\x62\xab\x5c\x48\x0d\xd7\x05\x5f\xb2\x79\x86\x33\xf1\x1d\x39\x2c\xa4\x58\xc1\x2f\x3f\xae\x1f\x6e\x3f\xdd\xfc\xfe\xe7\xd5\xec\xee\xf3\xd5\xed\xf9\xe5\xe5\xd7\xab\xe9\x74\xe0\x0e\xcc\x44\x3e\x4d\x85\xfe\x42\xe4\x77\xd4\x8f\x27\xd5\x91\x2f\xe7\x5f\x3f\x5f\xcd\x1e\x4f\xba\xa5\x2b\xa9\xd9\xdd\xfd\xf4\x8f\xbb\x99\x27\x54\xea\x6a\x6b\xf2\x44\x6e\x05\xef\xf4\xf4\xf6\x7a\x27\x39\x18\x8f\xc7\x30\x4b\x99\x02\x2d\x09\x57\x84\x6a\x26\x38\x50\x89\x44\xa3\x02\x02\x8f\x27\x30\x25\x19\xc2\x85\xc8\x32\xb4\x3f\xda\x13\x8c\x03\x81\x42\xa1\x7c\xaf\x80\x50\x2a\x0a\xae\x81\xf0\x04\x32\xa6\xb4\x39\xf6\x45\xac\x90\x6b\x58\x08\x59\x1e\x67\x1c\x74\x4a\x34\xd0\xb6\x9a\x9b\x85\x53\x03\x24\x93\x48\x92\x2d\xa4\xe4\x05\xab\x3a\xc5\x96\x9b\x82\x67\x5b\x67\xd2\xfc\xb4\xaa\x8d\x2a\x92\xa1\x39\x62\x8f\x7d\x4b\xd1\x5d\x89\xf1\x65\xa7\xf6\x11\xb0\x85\x55\xd1\xe5\xcb\x71\x20\xdd\xe9\xcc\x86\x65\x99\x03\xce\x42\xa1\xb4\x90\x08\x04\x72\x29\xd6\x2c\x41\x09\x94\xe4\x64\xce\x32\xa6\xb7\xd6\x45\x8b\x47\xa8\xbc\xd4\x2d\x60\x6e\x9d\x49\x60\xc3\x74\x6a\x6d\x75\x60\x32\x68\xd8\x8f\xb4\x89\xf0\x57\xa4\xc8\xd6\x28\xef\x89\x4e\x27\x70\x5f\xcc\x33\x46\xcd\xe7\x11\xcc\x91\xe3\x82\x51\x46\xe4\xf6\xbc\x0c\xd8\x04\xce\x93\x44\xa2\x52\x23\xa0\x85\xbe\x47\x49\x91\x6b\xb2\xc4\x09\x3c\x5c\xb3\x1f\xbf\xfd\x3a\x72\x80\xde\x5c\x4e\xe0\xe1\x86\x6b\xf3\x24\x97\x8c\xee\x04\x86\xf0\x73\x30\x00\x00\xc8\x25\xe6\x44\x62\x44\x28\xd5\x13\x20\x85\x4e\xa3\xa9\x16\x92\x2c\x71\x04\x17\xd5\xad\x19\xaa\x21\xbc\x73\xb6\xcd\x51\x70\x7f\xe3\x31\xd0\x14\xe9\x77\x73\x6b\x85\x68\x42\x41\x60\x7d\x62\x63\xd8\x48\x98\x5d\x58\xf0\x87\x89\xf8\xee\xb8\x11\xa7\x54\xc7\xaa\xb4\x18\xcf\x85\x94\x62\x73\xfa\xce\x2b\xb9\xd8\x80\x57\x63\xf7\x21\x32\xb5\x30\xf1\x0b\x33\x5e\xd9\x0f\xce\x7b\x83\xdc\x10\xce\xce\x80\xb3\xac\xe1\xb0\x73\xfa\x66\xd1\x13\x17\x48\x04\x2a\xe0\x42\x97\xae\x8e\x40\xa1\x86\x22\x07\x02\x1c\x37\x20\x38\x0e\x7c\x55\x4b\xd4\x56\xd7\xc2\x55\x2b\xd8\x60\xd6\x19\xc3\x50\xb9\x9c\x41\x10\x1b\x6e\x72\x94\x27\xcd\x90\xb6\x14\x66\xa8\x4b\xa9\x8b\x3a\xe3\xce\x4a\x90\x9a\x1a\xe3\x25\xea\xd3\x77\x3f\x5b\x0c\x11\x57\x09\xf4\xfc\x21\x4c\xa8\x61\xcb\x0a\x5b\xc0\x1b\xcf\x4a\x6c\xe3\x18\x0d\x3d\xac\x6c\x8a\x10\xce\x68\xf4\xf6\x42\x14\x59\x62\xa1\xa9\xae\x6c\x55\xbc\x57\xd0\xed\x46\xab\x68\x0c\x79\xbd\x8d\xa9\xe0\x94\xe8\xd0\xbb\x58\x8b\xa9\x96\x8c\x2f\xa3\xe1\xb0\xed\xe9\x73\x80\x4e\x03\xb9\x16\x46\x4b\xd4\x2e\x41\xa3\xb0\x5e\x86\x87\x46\xaf\xd3\x8b\x7f\x83\x61\x43\xd1\xff\x8d\xa4\x9f\xb9\x9f\xbc\x30\x56\xad\xab\x51\x0d\xf7\x15\x01\x36\xa0\x36\xe4\xe7\xab\x22\x59\x26\x36\xaa\xaa\x29\xbf\xfa\xb5\xb0\x54\x98\x48\xb2\x81\x8d\x21\x74\x23\xa0\x80\x48\x84\x15\x49\xb0\xa5\x6c\x4d\xa4\x2b\x80\xfa\xfc\x59\x9b\x25\xa8\xc8\xb7\xa7\xb5\x43\xa7\x96\xb4\xfc\x7e\x19\x7f\x73\x16\x47\x41\x2b\x8d\x1f\xf2\x84\x68\x1c\x42\xc5\x33\x71\x83\x5b\x2a\x72\x19\x3b\x6b\xe3\xb2\x1d\xd6\x12\x17\x24\x0f\xd2\x21\x70\xb8\x8b\x76\xa0\x45\x3d\xae\xe1\x35\x50\xaa\x33\x54\x6f\x6b\x1a\x6a\x31\xe7\xa8\x53\xa1\x52\x05\xd6\x04\xd5\x68\x60\x4c\x97\xcd\x1b\x41\x69\xc2\x13\x22\x13\xd3\x04\xd6\xa6\xcb\xbd\x60\x7e\x0b\x39\xd1\x69\x60\xa9\x27\x28\xad\xba\xaa\x22\xc4\x8c\x4b\x87\x8d\x4b\xd4\x1b\x90\x61\xe0\x6a\x2b\x5b\x14\x59\x63\xe4\x39\x3f\x02\x2d\xfe\x49\x88\xc3\xda\x31\xe5\x4b\xc2\xb1\x00\x61\x7d\xdc\x1c\x94\xbc\x53\x77\x66\xe8\x71\x33\x97\x2a\xa7\x08\x1b\x57\x34\x0d\x61\x61\x42\xd6\xd3\x95\xa8\xe0\x5a\x12\xaa\x61\x43\x14\x24\x98\x67\x62\x8b\x89\xaf\xdd\x4e\x31\x29\x59\x1b\x2d\x4c\x05\x55\xb5\x3e\x6e\xb7\xd1\x57\x95\x55\xd9\x5c\xe3\x0b\x3b\x1b\x75\x84\xac\x8e\xa6\x93\xdc\xc5\xd0\x7d\xf7\x5a\x77\x50\x5e\x5a\xe4\x2a\x15\xba\x2d\xd6\x55\x63\xa1\xfb\xfb\x8b\xac\x1a\x6f\x4d\x35\xf1\xf7\xba\x04\xa7\x6b\x2c\x6c\x46\xd2\x55\x5c\x67\xad\x2d\x98\x54\xda\x8d\x3c\xe5\xd8\xb9\x05\x5c\x23\x7f\x41\x33\x31\x35\x9c\x05\xca\x7a\x46\x9f\x10\xf4\x5e\x28\x5f\x85\xe4\x10\xde\xf4\xc1\xd4\x82\x6a\xdb\x7f\x83\x11\x30\xc7\x30\x5e\xba\x33\xdd\xa7\xd3\xa7\x20\xe7\x62\xa7\x78\x5f\x5a\xee\x23\x96\x43\x67\x66\xb4\x07\xc8\x4e\xe7\x43\xa6\xf1\xaf\xe3\x51\xcd\xeb\xd2\x1d\x82\xc9\x27\x64\xa0\x6a\x5d\xb1\xbc\xef\x75\x5c\x5f\xf6\xd1\xc7\xd8\x52\x85\xd2\xe6\xdf\x39\xc2\x13\x67\xd9\x13\xa4\x28\xdd\x00\xdf\xb1\xd9\x78\x0a\x13\x96\xd4\x43\x72\xd5\x64\x4c\x58\x84\x64\x7f\x35\x37\x4b\xff\xe0\x37\x04\x4a\xb8\x49\x1f\x8a\x47\x05\xdf\x48\x92\xc3\x93\xc7\xce\x4f\x30\x47\x4a\x0a\x65\xb3\xc7\x10\x5e\xd5\x03\x97\x05\x91\x84\x6b\xc4\xc4\x6d\x59\x5c\xf0\xa3\xd2\x79\x32\x17\x6b\x0c\x66\x45\x87\xf6\xe3\x89\x77\xfd\xd3\xa3\x60\x79\x28\xe1\x6c\xcb\xf9\x6d\x63\xe2\x37\xc1\x37\x21\x49\xfc\xa7\x3f\x6f\x26\x9f\xf8\x0f\x0e\x6c\xae\x73\x88\x9d\x74\x3f\x3e\xb0\x69\x6f\x6b\x6d\x7d\x3d\xb0\xa9\x72\x2d\x7c\x3c\x6e\x5e\xd1\xaf\xd2\x76\xf9\xf9\x49\x6b\x0a\xdb\xe4\xa2\x59\x72\x3b\x98\x2c\x24\x81\xd3\xa3\x9e\xcc\x2b\xd9\x60\xff\xe2\x3a\xe8\x73\x65\x57\xf5\xb9\x7d\x3f\x00\x19\xe3\x76\xf9\xb6\x43\x5e\x3f\x09\x84\x8c\x6a\xcf\xab\x34\xea\x1e\x9e\x5e\x20\xdf\xbd\xcb\xf9\xfe\xdb\x85\x01\x26\xba\x0f\x95\xfa\x3d\x48\xeb\x50\x8d\x50\x83\x19\xc7\x63\x28\xdb\x28\x10\x90\xb8\x40\x89\x9c\x62\x13\x9d\x9d\x64\x83\x1c\x5e\x1e\x8a\x9a\x6d\xd9\x77\x70\xd7\x9f\x0f\xf5\xba\xa2\x75\xc3\x8f\x1f\xc3\xa5\xd1\xdd\xce\x5b\xda\xc0\x6e\x6d\x1d\x53\x63\xdd\x79\xbd\xb5\x71\xaf\x2b\xdd\x6b\x64\x13\xe8\xbc\xd0\xcd\x3d\xa6\xc8\xeb\x77\x77\x95\x54\x27\xc0\x71\xc6\x94\xbe\x16\xd2\x3c\x2d\xd7\xd7\x9b\xcb\xc9\xee\x6d\xd5\xee\x2d\x95\xfd\xaf\xb4\xfc\x3c\x78\xfe\x3b\x00\x00\xff\xff\xa6\xa7\x87\xd1\xbb\x15\x00\x00" func TransactionsMarketv3Create_start_saleCdcBytes() ([]byte, error) { return bindataRead( @@ -1263,7 +1263,7 @@ func TransactionsMarketv3Create_start_saleCdc() (*asset, error) { } info := bindataFileInfo{name: "../../../transactions/marketV3/create_start_sale.cdc", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xca, 0xb5, 0xd3, 0x63, 0xe8, 0x76, 0x1, 0x43, 0xb1, 0x0, 0x93, 0x16, 0x7e, 0x35, 0xfc, 0x74, 0xc6, 0x14, 0x9e, 0xd5, 0x28, 0x61, 0xb, 0x84, 0xb1, 0xc0, 0xa1, 0x44, 0xa8, 0x6a, 0x9a, 0xb3}} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x75, 0x6b, 0xf3, 0x72, 0xe0, 0x81, 0x77, 0xce, 0xe, 0x60, 0xdb, 0xda, 0x97, 0x1c, 0x1c, 0x4, 0xb9, 0x1, 0xa, 0xe4, 0x78, 0xb4, 0x35, 0x8a, 0xa2, 0xa9, 0x4e, 0x3f, 0xbc, 0x6a, 0x46, 0x19}} return a, nil } diff --git a/transactions/marketV3/create_start_sale.cdc b/transactions/marketV3/create_start_sale.cdc index e42fb0f..f273e9b 100644 --- a/transactions/marketV3/create_start_sale.cdc +++ b/transactions/marketV3/create_start_sale.cdc @@ -4,37 +4,69 @@ import TopShot from 0xTOPSHOTADDRESS import Market from 0xMARKETADDRESS import NonFungibleToken from 0xNFTADDRESS +/// This transaction creates a V3 Sale Collection +/// in a user's account and lists a Moment for Sale in that collection +/// If a user already has a V3 Sale Collection +/// the transaction only lists the moment for sale +/// +/// When creating a V3 Sale Collection, if the user already has a V1 Sale Collection, +/// the transaction will create and store a provider capability for that V1 Sale Collection +/// to be used with the V3 Sale Collection + transaction(tokenReceiverPath: PublicPath, beneficiaryAccount: Address, cutPercentage: UFix64, momentID: UInt64, price: UFix64) { prepare(acct: auth(Storage, Capabilities) &Account) { // check to see if a v3 sale collection already exists if acct.storage.borrow<&TopShotMarketV3.SaleCollection>(from: TopShotMarketV3.marketStoragePath) == nil { + // If the V3 Sale Collection does not exist, set up a new one + // get the fungible token capabilities for the owner and beneficiary - let ownerCapability = acct.capabilities.get<&{FungibleToken.Receiver}>(tokenReceiverPath)! - let beneficiaryCapability = getAccount(beneficiaryAccount).capabilities.get<&{FungibleToken.Receiver}>(tokenReceiverPath)! + let ownerCapability = acct.capabilities.get<&{FungibleToken.Receiver}>(tokenReceiverPath) + if !ownerCapability.check() { + panic("Could not get the owner's FungibleToken.Receiver capability from ".concat(tokenReceiverPath.toString())) + } + let beneficiaryCapability = getAccount(beneficiaryAccount).capabilities.get<&{FungibleToken.Receiver}>(tokenReceiverPath) + if !beneficiaryCapability.check() { + panic("Could not get the beneficiary's FungibleToken.Receiver capability from ".concat(tokenReceiverPath.toString())) + } + // Get the owner's TopShot Collection Provider Capability that + // allows the V3 sale collection to withdraw when sales are made var ownerCollection = acct.storage.copy>(from: /storage/MomentCollectionCap) if ownerCollection == nil { + // If the moment collection capabilitity does not already exist, + // Issue a new one and store it in the standard private moment collection capability path ownerCollection = acct.capabilities.storage.issue(/storage/MomentCollection) acct.storage.save(ownerCollection, to: /storage/MomentCollectionCap) } // get a capability for the v1 collection + // Only accounts that existed before the V3 Sale Collection contract was deployed + // will have this var v1SaleCollection = acct.storage.copy>(from: /storage/topshotSaleCollectionCap) if v1SaleCollection == nil { - v1SaleCollection = acct.capabilities.storage.issue(/storage/topshotSaleCollection) - acct.storage.save(v1SaleCollection, to: /storage/topshotSaleCollectionCap) + // If the account doesn't have a V1 Sale Collection capability already, + // first check if they even have a V1 Sale Collection at all + if acct.storage.borrow(from: /storage/topshotSaleCollection) != nil { + // If they have a V1 Sale Collection, issue a capability for it + // and store it in storage + v1SaleCollection = acct.capabilities.storage.issue(/storage/topshotSaleCollection) + acct.storage.save(v1SaleCollection, to: /storage/topshotSaleCollectionCap) + } } // create a new sale collection - let topshotSaleCollection <- TopShotMarketV3.createSaleCollection(ownerCollection: ownerCollection, + // V1SaleCollection will still be `nil` here if a V1 Sale Collection + // did not exist in the authorizer's account + // We can force-unwrap `ownerCollection` because it was already guaranteed to be non-`nil` above + let topshotV3SaleCollection <- TopShotMarketV3.createSaleCollection(ownerCollection: ownerCollection!, ownerCapability: ownerCapability, beneficiaryCapability: beneficiaryCapability, cutPercentage: cutPercentage, marketV1Capability: v1SaleCollection) // save it to storage - acct.storage.save(<-topshotSaleCollection, to: TopShotMarketV3.marketStoragePath) + acct.storage.save(<-topshotV3SaleCollection, to: TopShotMarketV3.marketStoragePath) // create a public link to the sale collection acct.capabilities.publish( @@ -45,10 +77,9 @@ transaction(tokenReceiverPath: PublicPath, beneficiaryAccount: Address, cutPerce // borrow a reference to the sale let topshotSaleCollection = acct.storage.borrow(from: TopShotMarketV3.marketStoragePath) - ?? panic("Could not borrow from sale in storage") + ?? panic("Could not borrow the owner's Top Shot V3 Sale Collection in storage from ".concat(TopShotMarketV3.marketStoragePath.toString())) // put the moment up for sale topshotSaleCollection.listForSale(tokenID: momentID, price: price) - } } \ No newline at end of file