diff --git a/lib/go/templates/internal/assets/assets.go b/lib/go/templates/internal/assets/assets.go index eb5d2d9..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.02kB) +// ../../../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\x56\x5b\x4f\xe3\x38\x14\x7e\xef\xaf\x38\x33\x0f\x28\x91\x32\xc9\x22\x56\xfb\x10\x95\x41\x2c\xd0\x5d\x34\xcb\x45\xb4\xb0\xcf\xae\x7b\xda\x58\xa4\x76\xe4\x9c\x14\xaa\x11\xff\x7d\x15\xe7\x6a\x27\x5d\x46\x82\xbe\x34\x71\x8e\xcf\xed\xfb\xce\x45\x6c\x33\xa5\x09\x66\x85\xdc\x88\x65\x8a\x0b\xf5\x8c\x12\xd6\x5a\x6d\xe1\xb7\xd7\xd9\xe3\xed\x5f\xd7\x7f\xfe\x73\xb5\xb8\xfb\x71\x75\x7b\x7e\x79\xf9\x70\x35\x9f\x4f\xea\x0b\x0b\x95\xcd\x13\x45\x37\x4c\x3f\x23\x3d\x9d\x34\x57\x6e\xce\x1f\x7e\x5c\x2d\x9e\x4e\xc6\xa5\x1b\xa9\xc5\xdd\xfd\xfc\xef\xbb\x85\x23\x54\xe9\xb2\x35\x39\x22\xb7\x4a\x8e\x7a\x7a\x3b\x6b\x25\x27\xa4\x99\xcc\x19\x27\xa1\xa4\x47\xa5\xd0\x03\x72\x14\x3b\xd4\xf7\x8c\x92\x18\xee\x8b\x65\x2a\x78\xf9\x1c\xc0\x12\x25\xae\x05\x17\x4c\xef\xcf\x39\x57\x85\xa4\x18\xce\x57\x2b\x8d\x79\x1e\x00\x2f\xe8\x1e\x35\x47\x49\x6c\x83\x31\x3c\xce\xc4\xeb\x1f\xbf\x07\xb0\x55\x5b\x94\x74\x7d\x19\xc3\xe3\xb5\xa4\xf2\x24\xd3\x82\xb7\x02\x3e\xfc\x9c\x4c\x00\x00\x32\x8d\x19\xd3\xe8\x31\xce\x29\x06\x56\x50\xe2\xcd\x49\x69\xb6\xc1\x00\x2e\x58\xc6\x96\x22\x15\x24\x30\xf7\xe1\xa8\xb6\x5d\x5e\x85\xfa\x17\x45\xc0\x13\xe4\xcf\x40\x0a\x72\x44\x10\x6b\x60\xb0\x3b\x81\x9c\xa5\x08\x5c\xa5\x29\x9a\x00\x81\xa5\x1a\xd9\x6a\x0f\xf8\x2a\x72\xca\xdb\xeb\xa5\x38\xe7\x14\xe6\x95\xc5\x70\xa9\xb4\x56\x2f\xd3\x23\x07\xb5\x70\xce\x52\xbc\x68\xb5\x7d\xf7\xca\x74\xc6\x2e\xb6\xe1\xd6\x3c\xd4\xde\x97\x99\xf3\xe1\xf4\x14\xa4\x48\x7b\x0e\xd7\x4e\x6f\x90\x80\x12\x84\x75\x8d\x12\x18\x04\x80\xf7\x02\x86\xb5\xd2\x46\x46\xbd\x48\xd4\xc0\xe4\xaa\x8f\x83\xa5\x30\x45\xaa\xa4\xda\x84\xed\xe1\xb4\x8a\xac\xaf\x31\xdc\x20\x4d\x8f\x7e\x5a\xcc\x08\x1b\xd4\xdf\xbe\x0f\x59\xe0\x7f\x19\x98\xe9\xb9\x60\x19\xdb\x20\xd5\xf0\x78\x43\xb6\xf8\x1f\x76\xe3\x40\xb8\x1d\xc0\x63\xe1\x36\xa8\x8a\x3c\x2f\x70\x6a\xa8\xe5\x16\x46\xf8\xaf\xa0\x64\xa5\xd9\x4b\x30\xf8\xf2\x98\xad\x18\xa1\x0f\x0d\x19\xc2\x3e\x01\xa2\x5a\x77\x74\x63\x68\xde\x7d\xf2\x27\x63\x50\xb3\x0e\xd9\x7d\x8b\xeb\xee\xb8\xc7\x50\xeb\xd6\x8e\x69\xd8\x1d\xdb\xa4\x8b\xbb\x6a\xd8\x57\xb1\x54\xbc\x0b\x2f\x34\x32\xc2\x60\x50\xf3\x5d\x68\x75\xc7\xe8\x22\xaa\xdf\x1d\x56\x9f\x81\x21\xab\xe5\xc9\xa1\x02\x19\xd7\x50\xd7\x45\x9b\x1c\x52\x59\x9e\x28\xb2\xa5\x7c\xf8\x32\x56\x14\x26\x6e\x27\xe6\x5f\x45\xf5\xb3\x33\xe1\xbd\x13\x81\xe5\xf8\xdb\x00\x71\x6e\xfc\x00\x06\x12\x5f\xdc\x4e\x34\x20\xf2\xa8\x05\x98\x7e\x1b\x74\x97\x4a\xab\x2d\xe7\x39\x65\x10\xbb\x75\x11\x0c\x72\xfc\xa1\x9f\xd3\x64\x62\xf7\xe0\x93\xcd\x8d\x36\x9b\x78\xfc\xf8\x93\x4d\x3b\x53\xcd\x7a\xfd\x64\x53\xd5\xd8\x78\x3a\xee\x87\xe8\x56\x82\x4d\x39\x97\x70\x39\xdb\x21\x08\x32\x43\xb0\x22\xae\x25\x61\x55\x70\x29\xeb\x4d\xbf\x8d\xd2\x2e\x00\x52\xbf\x32\xd6\x26\x87\x1c\x69\x99\x9f\x99\xed\x01\x52\x21\xcd\x68\x2e\xdb\xdd\xff\x14\xc2\xb0\xc8\xcd\xfd\x3c\xf1\x06\x99\x7e\xaf\x1f\xbc\x3b\xba\xdf\x8f\x6e\x08\x2f\xa3\x43\x59\xe9\xb6\x24\xeb\x52\x97\xa1\x5e\x77\x88\x22\xa8\xda\x27\x30\xd0\xb8\x46\x8d\x92\x63\x3f\x3b\xad\xe4\xe1\xbe\x70\x3a\xda\x8e\x4d\x13\x74\x1d\xac\xba\x61\x37\xbf\x3e\xbc\xcc\x58\x11\x9e\x9d\x41\xc6\xa4\xe0\xde\xd7\x0b\x55\xa4\x2b\x90\x8a\x9a\xe8\xcc\xae\x69\xd0\x16\xb2\xe1\xe3\xd7\x11\xce\x44\x11\x64\x45\xb5\x06\x55\xcb\x22\x14\x99\x19\x8e\x56\x2e\x46\xf3\x10\xa6\x22\xa7\x99\xd2\xe5\x69\xb5\x2f\x94\x8b\x66\xb3\x72\xb6\xab\xa6\xf9\x73\x2c\xbf\x4d\xde\xfe\x0b\x00\x00\xff\xff\xb9\x11\x7d\xc0\xcc\x0b\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{0xa7, 0xe4, 0x35, 0x5e, 0xb6, 0xa3, 0x88, 0x97, 0x4a, 0x75, 0xaf, 0x67, 0xfd, 0xeb, 0x7a, 0xa3, 0x42, 0x0, 0x33, 0xda, 0x9, 0x5a, 0xad, 0xd9, 0x88, 0xf8, 0xce, 0x28, 0x22, 0xee, 0xd4, 0xf4}} + 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 5aeb333..f273e9b 100644 --- a/transactions/marketV3/create_start_sale.cdc +++ b/transactions/marketV3/create_start_sale.cdc @@ -4,32 +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())) + } - let ownerCollection = acct.capabilities.storage.issue(/storage/MomentCollection) + // 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 - var v1SaleCollection: Capability? = nil - if acct.storage.borrow<&Market.SaleCollection>(from: /storage/topshotSaleCollection) != nil { - v1SaleCollection = acct.capabilities.storage.issue(/storage/topshotSaleCollection) + // 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 { + // 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( @@ -40,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