From e3b2202ee7a7c7734c82a6f18ced39700655a2a2 Mon Sep 17 00:00:00 2001 From: Josh Hannan Date: Fri, 9 Feb 2024 11:51:13 -0600 Subject: [PATCH] add generic setup and transfer transactions --- lib/go/templates/internal/assets/assets.go | 46 +++++++++++++++++++ lib/go/templates/templates.go | 27 +++++++++--- lib/go/templates/transaction_templates.go | 44 +++++++++++++++++- tests/test_example_nft.cdc | 49 +++++++++++++++++++-- transactions/generic_transfer.cdc | 38 ++++++++++++++++ transactions/setup_account_from_address.cdc | 33 ++++++++++++++ 6 files changed, 225 insertions(+), 12 deletions(-) create mode 100644 transactions/generic_transfer.cdc create mode 100644 transactions/setup_account_from_address.cdc diff --git a/lib/go/templates/internal/assets/assets.go b/lib/go/templates/internal/assets/assets.go index 2e1bb0b1..654f2080 100644 --- a/lib/go/templates/internal/assets/assets.go +++ b/lib/go/templates/internal/assets/assets.go @@ -9,12 +9,14 @@ // scripts/get_nft_metadata.cdc (5.622kB) // scripts/get_nft_view.cdc (4.367kB) // transactions/destroy_nft.cdc (1.277kB) +// transactions/generic_transfer.cdc (1.555kB) // transactions/mint_nft.cdc (2.885kB) // transactions/nft-forwarding/change_forwarder_recipient.cdc (1.298kB) // transactions/nft-forwarding/create_forwarder.cdc (1.594kB) // transactions/nft-forwarding/transfer_nft_to_receiver.cdc (2.091kB) // transactions/nft-forwarding/unlink_forwarder_link_collection.cdc (1.104kB) // transactions/setup_account.cdc (1.326kB) +// transactions/setup_account_from_address.cdc (1.632kB) // transactions/setup_account_from_nft_reference.cdc (1.415kB) // transactions/setup_account_to_receive_royalty.cdc (1.477kB) // transactions/test/upgrade_nft_contract.cdc (172B) @@ -269,6 +271,26 @@ func transactionsDestroy_nftCdc() (*asset, error) { return a, nil } +var _transactionsGeneric_transferCdc = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x84\x54\x41\x4f\xf3\x38\x10\xbd\xf7\x57\x3c\xf5\x00\x89\x54\xc2\x65\xb5\x87\xa8\xc0\xb2\x45\x95\xb8\x54\x88\xed\xee\x9e\x5d\x7b\xd2\x18\x52\x3b\xb2\x27\xf4\xab\x50\xff\xfb\xa7\xd8\x49\x9a\x52\x3e\x7d\x9c\x8c\x3b\xf3\xde\x9b\xf7\xc6\xd1\xbb\xda\x3a\xc6\xca\x9a\x65\x63\xb6\x7a\x53\xd1\xda\xbe\x93\x41\xe1\xec\x0e\xd3\xaf\xd7\xd3\xc9\xe4\xf6\xf6\x16\x0b\x61\x50\x0b\xef\xa1\x0d\x84\x39\xc0\xb3\x75\x62\x4b\xa8\x05\x97\x10\x46\xc1\x91\x24\xfd\x41\x2e\xde\x68\xe3\x99\x84\x82\x2d\xf0\xd6\x78\x06\x97\x04\x45\x85\x68\x2a\xce\x02\xde\xba\xd4\x1e\x15\xb1\xc7\xc1\x36\x90\xa5\xb5\x9e\x42\x15\x07\x2d\xed\xe5\x5e\x18\x06\x5b\x78\x32\x0a\xc2\x63\x4f\x55\x15\x4a\xa4\xa8\xc5\x46\x57\x9a\x0f\x97\x75\xba\x3d\x06\x8a\x40\xf3\x68\x0e\x1d\x62\x90\x25\x85\xc1\x86\xc2\x20\x14\x30\x85\x81\x70\xdb\x66\x47\x86\x51\x92\xa3\x19\xbc\xc5\x5e\x54\x41\x99\x2f\x6d\x53\xa9\x80\x13\x8f\x90\x25\xc9\xf7\x53\xc7\x87\xa8\x1a\xf2\x2d\xf7\x4e\xbc\x13\x7c\xe3\xe2\x0c\xda\x30\x19\x45\x6a\x4c\xad\x7d\x4f\xab\x4d\x90\xc7\x4e\x18\x2f\x24\x6b\x6b\x12\xad\x72\xfc\xfb\x6c\xf8\xcf\x3f\x66\x60\x9b\xe3\x51\x29\x47\xde\xcf\xc2\x4c\xe4\x5e\x04\x97\x39\xfe\x89\x96\xb7\xff\xcc\x06\xbb\xe3\x4f\x2f\xcd\xa6\xd2\xb2\x3d\xa7\xf8\x9c\x4c\x00\x20\x78\x4c\x58\x2d\xd7\x70\xe4\x6d\xe3\x64\xeb\x6d\x3b\x7d\x20\x2e\xc8\x39\x52\xa1\xb2\x22\x06\xd3\xae\x5e\x2d\xd7\x39\xfe\xfa\xfc\xba\x00\xd9\x6a\xb9\x3e\x46\xcc\xda\x51\x2d\x1c\x25\x5e\x6f\x0d\xb9\x1c\xa2\xe1\x32\xf9\xdb\x3a\x67\xf7\xff\xb5\x56\xa4\xb8\x7a\x94\xd2\x36\x86\x07\x19\x9d\x94\x4d\x28\x82\x80\xa3\x82\x1c\x99\x28\xa6\xf5\x2a\x62\x5d\xfb\xa0\x54\xda\xaa\xa2\x60\xc9\xd0\xdc\xaa\xdb\x6b\x2e\x95\x13\xfb\x57\x2a\x70\xd7\x75\x64\xdd\x06\x66\x11\x7a\x1e\xb4\x5c\x68\xff\xbf\xeb\x4c\x71\x75\x39\xd8\x62\x60\x3b\xde\x27\x03\x61\xff\xd7\x3e\x87\x7c\x14\xc0\x59\x41\x8a\x87\x07\xd4\xc2\x68\x99\x4c\xbb\x91\xa1\x2c\x79\x18\xcb\xe1\x6d\x10\xc4\x68\x1a\xd8\xcd\x1b\x49\x86\x88\x2f\xc1\xd7\x24\x75\xa1\x49\x85\xd5\x98\xa6\x27\xab\x3c\x55\x45\xd6\x85\x81\xf9\xcd\x78\xf2\xac\x3f\x27\xfd\xe1\xf9\x29\x87\x56\x69\x68\xee\x12\xa2\x1f\x24\x1b\x26\x7c\x8e\xcd\xdf\x52\xa4\x75\x24\x75\xad\xc9\xb0\x47\x1d\x16\x06\xa2\x93\x1e\xe5\x9d\x79\x3e\x14\xe3\xae\x05\xe8\x86\x4c\xd8\xa6\xdf\x07\xdb\x21\x5e\xe4\xdb\x2f\xaa\xff\x55\xb8\x7d\xc1\x42\xd4\xb8\x3b\xd1\x66\xc3\x2b\xd7\xe4\xb3\x2d\xf1\xfc\x9b\x04\x5f\xbb\xde\xe3\x7d\x32\x7e\x10\xe9\x59\x56\xa7\xa4\x16\xe1\x11\xb7\x11\x5d\x58\x72\xed\xd1\x83\x61\x31\x7c\x5f\xc6\xd1\x8c\xb5\xc6\x45\x1c\x29\xef\xb6\x30\xf9\x3d\x73\x67\xd8\x77\x3e\x0d\x4a\x7a\xe0\xe9\xb9\xd7\x4f\x54\x5b\xaf\xa3\xf0\x76\x3f\xbe\x38\x3c\x94\x8e\x54\x66\x2a\xf6\x24\xe1\x4b\x94\x63\x7e\x33\xde\xb0\x7e\x75\x8e\x3f\x03\x00\x00\xff\xff\x72\xc3\xbf\x75\x13\x06\x00\x00" + +func transactionsGeneric_transferCdcBytes() ([]byte, error) { + return bindataRead( + _transactionsGeneric_transferCdc, + "transactions/generic_transfer.cdc", + ) +} + +func transactionsGeneric_transferCdc() (*asset, error) { + bytes, err := transactionsGeneric_transferCdcBytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "transactions/generic_transfer.cdc", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x6a, 0x21, 0xd8, 0x94, 0xf7, 0x92, 0x8a, 0xc6, 0xc4, 0x58, 0xa0, 0x2a, 0x4a, 0xbb, 0x49, 0xa6, 0xbe, 0xcd, 0x84, 0xd8, 0x79, 0xed, 0x5, 0xb2, 0xd3, 0xc9, 0x79, 0xb8, 0x3f, 0x9d, 0x2f, 0xf}} + return a, nil +} + var _transactionsMint_nftCdc = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x84\x56\x41\x6f\xe3\x36\x13\xbd\xeb\x57\xcc\xe7\x83\x57\xc6\x97\xb5\x5a\xa0\xe8\x41\x88\xb3\x48\xbc\x0d\xd0\xc3\x06\x8b\xac\xbb\x97\xc0\x87\xb1\x34\x96\xd8\xd2\xa4\x4a\x8e\xec\x18\x41\xfe\x7b\x41\x51\xa2\x25\x47\x4e\x0c\xc3\x96\xc8\x99\xc7\x99\x37\x6f\x46\x4a\x92\x04\x56\xa5\xb0\x60\x33\x23\x2a\x86\xda\x92\x05\x2e\x09\x1e\xee\x57\xdf\x84\x62\x32\x60\xc8\xea\xda\x64\x04\xac\x61\x27\x14\x03\x82\xa2\x83\x33\x88\x9c\xf7\x9f\x0c\xbb\xda\x32\x6c\x08\x4c\xad\xe0\x20\xb8\x6c\x00\x30\xcb\x74\xad\x18\xb8\x44\x86\x12\x3d\xea\x6e\x08\xd9\x00\x58\xd6\x86\x72\x10\x0a\x12\x77\x89\x05\x25\xe1\xf0\x28\x12\xbb\x4a\x1b\x86\xc9\x83\x56\xf7\xb5\x2a\xc4\x46\xd2\x4a\xff\x43\x6a\x12\x76\xfe\x78\xc6\x5d\x25\xe9\xe1\x7e\x75\x5a\xfb\x46\x8c\x39\x32\xfe\x14\x74\xb0\xa7\xe5\x33\x84\x88\x0d\x2a\x8b\x19\x0b\xad\xe2\x08\x00\xc0\x50\x26\x2a\x41\x8a\x53\xb8\xcd\x73\x43\xd6\x5e\x35\xeb\x0a\x77\x94\xc2\x0f\x36\x42\x15\x7e\x25\x27\xcf\x98\xd0\x6a\xb8\xc1\x65\xbd\xdb\x28\x14\x72\xb8\x9c\xd5\x6c\x53\x78\xfa\xeb\x5e\x3c\xff\xfe\xdb\xda\xaf\x19\x7d\x44\xc9\xc7\xaf\x27\x28\x67\xe2\xbd\x86\x26\x77\xa4\x68\x2b\x32\x81\x46\x90\xb3\x69\x83\x5b\x47\x33\x78\x89\x1a\x43\xc7\xa4\xd4\x19\x4a\xd8\xa3\x11\xb8\x91\x04\x5b\x6d\x1a\x72\x85\x2a\x86\xe4\x6f\xc9\x90\xca\xa8\xf1\x93\xc4\xed\x46\x0a\xd3\x13\x95\xf3\x5e\x09\x3a\xf8\xc7\xce\xd1\x29\xc1\x01\x1a\xca\x48\xec\xc9\x7c\xb2\x90\x69\x29\xa9\x21\x32\xa0\x06\x2e\x97\x61\xef\x91\xb6\x29\x4c\x5f\xce\x6b\x39\x7f\x6c\x81\x5e\xfd\x61\x95\xa1\x0a\x0d\xc5\x56\x14\xca\xc5\x85\x35\x97\xf1\x9d\x36\x46\x1f\x7e\xa2\xac\x69\x06\xd3\x5b\xaf\xae\x90\x7e\x77\xe8\x29\x8e\xaf\xc8\x08\x0b\xe8\xa5\xe4\x54\x27\xf7\xb4\xd4\x8a\x0d\x66\xec\xb4\x11\x77\x4a\x5c\x1d\x2b\x4a\x41\x09\x79\x05\x7b\x41\x07\x7f\xeb\x7e\xaf\x07\x52\x72\xb4\x2c\x07\x47\xdc\xc4\xb3\x19\xa0\xfd\x1f\x7c\x60\xf7\x25\x84\xe9\x3e\x5f\xbe\x40\x85\x4a\x64\xf1\xc4\x99\x3f\xfa\xc0\x0c\xe4\x9a\x2c\x28\xcd\xd0\x86\x0a\x6f\x60\x9a\xe8\x26\xb3\x00\x16\x2e\x92\x04\x36\x0d\x43\x80\xa7\x0a\x77\x85\x1a\x69\x66\xa1\xa0\xed\xb6\x00\x61\x49\x6e\xe7\xad\x48\x16\xe0\xc9\x9f\xb7\x46\x73\x0f\x7e\x3d\x2a\x91\x9b\x78\x6b\xf4\x2e\xed\x73\xed\x37\x7e\x78\xe7\xef\xc8\xe5\xec\x42\xfe\x6d\x21\x4f\xa9\x37\xe3\x00\x50\x81\xde\xfc\x4d\x19\x03\x72\x93\x82\xad\x28\x13\x5b\x41\x39\x54\xc8\xe5\x64\x16\xf5\x33\xf7\xda\xe8\x34\xe9\x55\xf7\xc9\x42\x55\x6f\xa4\xc8\x5c\xf6\x3d\x5d\x9c\xe9\x3f\x24\x3e\x2e\x57\x58\x40\x41\xdc\x06\x19\x07\x9b\xd9\x3c\xc3\x0a\x37\x42\x0a\x16\x64\x03\x39\xef\x28\xfb\x26\x1e\x10\xd0\x8c\x84\x41\x65\xe7\x3e\x5a\xc7\xd5\xc0\x72\xd6\x23\x6b\xa9\x6b\x99\x37\x2c\x15\xbe\xc1\x1a\xec\xd1\x7a\xc3\x29\x8d\x56\x2e\xa7\xe6\x82\x97\x70\x82\x1b\x4b\x73\x49\xaa\xe0\x12\x16\x8b\xb1\x89\xd4\xed\x4e\xa7\x17\x8c\x07\xb3\xa9\xdd\x4e\x61\x72\x6b\x0c\x1e\xa1\xb5\xb6\x65\x13\xf9\x86\x80\xfe\xad\x51\x36\xa3\xa9\x75\x07\x43\x12\x99\x72\xc8\x89\x51\x48\x3b\xe9\x07\x4b\xcf\x94\xd5\x4c\xfd\x2e\x4f\x12\xf7\x5d\x1a\x42\x26\x5f\xf1\x16\xa7\xf5\xef\x1b\xee\xd1\x80\x97\xd7\x02\x7e\x39\xdf\xf0\x7e\x7e\x9e\x0e\x9b\xf7\xd1\x23\xae\x61\x01\x4f\xeb\xbe\xdb\xa1\x14\x92\xde\xcb\x1b\x6e\xda\xf3\x5e\xfa\x6e\xdd\x70\xda\x04\x8f\x23\x8c\xd3\xf7\xd4\x78\xaf\x3f\x70\x5e\x76\xda\x3b\x0e\xe5\xd9\x33\x39\x13\x68\x41\x7c\x3d\x7d\xf9\x58\x9a\xed\x79\xdd\x67\x48\x4b\x41\xdc\x32\xd3\xb9\x7e\x0f\x92\x8d\x67\x63\x18\x7d\xed\xde\xf5\x92\x0f\xcd\x5e\xe2\x9e\xa0\x43\x83\x4c\xab\xad\x28\x6a\xf7\x36\x80\x0c\x17\xcf\x3a\x6b\x7e\x08\x8f\x49\x97\x29\x56\x15\xa9\x7c\x34\xa3\xd1\x22\x5f\xcc\xbd\xeb\xae\x74\x9c\xf9\xab\x4b\x7e\x59\xcd\x69\xd3\x29\x6d\x2d\x2f\x1a\x0e\xde\x20\x46\x1a\xef\x82\x16\x1a\x5e\xcf\x17\xdf\x2c\x74\xaa\xf7\xff\xff\x87\x5f\xfb\x06\xaf\xd1\x80\x40\x37\xab\xc3\xd8\x40\xe5\x3a\xb1\xd2\x56\x30\x08\xee\x3d\xe9\xc3\x54\x3d\x7b\xd4\x43\xff\x25\x22\x77\x10\xd7\x9f\xfb\x8f\x92\xe6\xef\xe1\x7e\x35\x9c\x7f\xfe\x85\xca\xfd\x5e\x45\x17\x49\xe9\xdd\x0c\xad\x7a\xef\x58\xe1\x72\x68\xd1\x6f\xee\x35\x24\x49\xb8\x8f\xde\x72\xf8\xce\xf8\x9f\xb7\x54\xc4\xec\x5a\x26\x85\xeb\xcf\x21\xcd\x30\x54\x5f\xa3\xff\x02\x00\x00\xff\xff\x0d\x17\x53\xe3\x45\x0b\x00\x00" func transactionsMint_nftCdcBytes() ([]byte, error) { @@ -389,6 +411,26 @@ func transactionsSetup_accountCdc() (*asset, error) { return a, nil } +var _transactionsSetup_account_from_addressCdc = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x94\x54\x4d\x6f\xdb\x30\x0c\xbd\xfb\x57\x70\x39\x14\x36\x90\x3a\xf7\x20\x6d\xd1\x79\x2b\xb0\xc3\x82\x62\xcd\x7a\x67\x64\x3a\x16\xea\x48\x86\x44\xdb\x08\x8a\xfe\xf7\x41\xf2\x47\x22\x77\x5d\x31\x1d\x02\x47\x24\x1f\x1f\x1f\x49\xad\x56\x2b\xd8\x95\xd2\x02\x1b\x54\x16\x05\x4b\xad\x40\x5a\xe8\x4a\x64\x40\x05\x28\x84\x6e\x14\x43\xa7\x9b\x2a\x07\xd3\xa8\xc8\x45\xb0\x06\x4b\x0c\x92\x2d\x55\x05\x34\xb5\xbb\x30\x24\x48\xb6\x04\xdb\x87\x9d\x4d\x7b\xcc\xa2\x51\x1e\xd0\xc7\x34\x96\x2c\xb4\x92\x3a\xeb\xbc\x5f\x94\xee\xa0\x2b\xc9\xd0\x08\xe6\x50\x4a\x02\xa1\xab\x8a\xce\x51\x52\x81\x65\x6d\xf0\x40\x80\x2a\x77\xbe\xc2\x10\x32\x79\x5f\x3a\xd6\x7c\xba\x88\x48\xa3\x48\x1e\x6b\x6d\x18\xb6\x5a\x3d\x34\xea\x20\xf7\x15\xed\xf4\x0b\x29\x28\x8c\x3e\xc2\x62\x7e\xbd\x18\xfd\x7f\x12\x63\x8e\x8c\xcf\x9e\x5f\xef\x1c\xdc\x2d\xa2\xe8\x42\xa1\x58\x68\xc5\x06\x05\xdf\xe7\xb9\x21\x6b\xd7\x30\x7c\x2c\x61\xb4\x6c\xf1\x48\x6b\x78\x62\x23\xd5\x21\x81\xd7\x28\x02\x00\xa8\x0d\xd5\x68\x28\xb6\xf2\xa0\xc8\xac\x01\x1b\x2e\xe3\x1f\xd6\x36\xf4\xd4\x17\x99\x61\x8d\x7b\x59\x49\x3e\x65\x0e\xc7\x55\x66\x96\xf0\xd8\xec\x2b\x69\xcb\xb3\x71\x09\x4f\xd8\xd2\x33\x56\x0d\x25\x70\x75\xdf\xf7\xc8\x65\x81\xe1\xac\x56\xf0\x55\x1b\xa3\x3b\x40\x30\x54\x90\x21\x25\xbc\xd2\x4e\x36\x55\xf0\x44\x13\x72\xaa\x2b\x7d\xa2\x7c\x34\xd6\x68\x2d\xe5\x63\xdf\x27\xc0\x8a\x18\x0c\x59\x5d\xb5\x64\x7e\x51\x01\x37\x70\x20\x1e\x12\xcf\xd5\x48\xa6\x28\x77\xd2\xd1\x6a\xd3\xbd\xa7\xb4\xb9\x9a\xb7\xe1\x36\x56\x5e\xad\x4b\xed\x42\x90\xbb\x3b\xa8\x51\x49\x11\x2f\x32\x3f\x88\x4a\x33\xec\x3f\x2e\x50\xab\xeb\x62\x48\x00\xec\xfb\x3f\x42\x2f\x92\xe8\x52\xa4\xdf\xd6\x4d\x12\x72\x88\x61\x88\x8d\xa4\xb6\x1f\xb2\xed\xc3\x2e\x9b\x26\xec\x1b\x32\xfa\x21\x86\x40\x19\x11\x3a\xdc\x5c\x4a\x95\x0e\xdf\xd9\xc0\xc0\x8d\x53\xec\xee\x1a\x23\x68\x77\xaa\x69\x0d\x4a\x56\x4b\x8f\xda\xff\x75\xbf\x9b\x60\xfa\xd2\x77\x24\x6e\xe3\x24\x01\xb4\x5f\xe0\x13\xbf\xbb\x4f\x65\x1c\xe8\xfd\xab\xd6\x42\x1b\x6f\x3e\xc8\x96\xd4\x7f\xa8\x9b\xf5\xab\x8a\xa0\xa8\x7b\xb7\xac\x36\x50\xd0\x5b\xcf\xb9\x61\x73\x3d\x13\x35\xed\xf7\xfe\x7b\xe8\x17\x87\x09\x2d\xb6\x04\x92\xc7\x39\x98\x0f\x71\xbf\x76\xe9\xf0\xa0\xa4\xce\x3b\xde\x5c\xcf\x52\x2f\x81\xf5\x7a\x9e\x7c\x08\x79\x44\x2e\xc3\x8c\x62\x2c\xb1\x76\x3b\x2a\x40\x4c\x3b\x3a\xa9\x76\xf1\xa2\xfd\x7d\x66\x32\xac\xe1\x66\x24\x37\x01\x48\xb2\x13\x53\xe9\x9e\x88\xcd\xd5\xeb\x7c\x71\xd2\x33\xed\xb7\xdb\x38\x68\xb5\x3b\x1f\x17\x11\xb8\x26\x73\x81\x02\x0e\x75\xff\xf8\xc4\x01\xdf\x25\x20\xbf\x13\xa9\x97\xa0\xd7\xc8\xa1\xbd\x45\x6f\xd1\x9f\x00\x00\x00\xff\xff\xcc\x48\xc9\x43\x60\x06\x00\x00" + +func transactionsSetup_account_from_addressCdcBytes() ([]byte, error) { + return bindataRead( + _transactionsSetup_account_from_addressCdc, + "transactions/setup_account_from_address.cdc", + ) +} + +func transactionsSetup_account_from_addressCdc() (*asset, error) { + bytes, err := transactionsSetup_account_from_addressCdcBytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "transactions/setup_account_from_address.cdc", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x60, 0x6e, 0x5b, 0x1c, 0x5f, 0x86, 0x2f, 0x31, 0x93, 0x33, 0x23, 0x5a, 0x8a, 0x1f, 0x43, 0x2, 0xa8, 0x86, 0xc3, 0xb4, 0xb0, 0xe2, 0x90, 0x61, 0xaf, 0x85, 0xc3, 0x9, 0xe9, 0x64, 0x51, 0x8a}} + return a, nil +} + var _transactionsSetup_account_from_nft_referenceCdc = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xa4\x54\x41\x6f\x9b\x4c\x10\xbd\xf3\x2b\x5e\x7c\x88\x40\x72\xf0\xe5\xd3\x77\xb0\xec\x44\x11\xad\xa5\x1c\x6a\x45\x8d\x9b\xfb\x18\x06\xb3\x0a\xd9\x45\xbb\x83\x91\x15\xf9\xbf\x57\xb0\xc6\x36\xb4\x51\x0e\xdd\x13\xda\x7d\xf3\xe6\xcd\xcc\x1b\x66\xb3\x19\x36\x85\x72\x10\x4b\xda\x51\x2a\xca\x68\x28\x87\xa6\x20\x01\x69\x50\x9a\x9a\x5a\x0b\x1a\x53\x97\x19\x6c\xad\x83\x36\x42\x0c\x1c\x0b\x94\x38\x2e\x73\xd4\x55\x7b\x61\x39\x65\xb5\x67\xac\x57\x1b\x17\x7b\xce\xbc\xd6\x1d\x61\x17\x53\x3b\x76\xd8\x2b\x6e\x5c\x8b\x7e\xd3\xa6\x41\x53\xb0\xe5\x9e\xac\x65\x29\x18\xa9\x29\x4b\xbe\x44\x29\x0d\x27\xc6\xd2\x8e\x41\x3a\x6b\xb1\xa9\x65\x12\xee\xb0\xfc\x5e\xc9\xe1\x2a\x22\x0e\x02\xf5\x5e\x19\x2b\x58\x1b\xbd\xaa\xf5\x4e\x6d\x4b\xde\x98\x37\xd6\xc8\xad\x79\xc7\x64\x7c\x3d\xe9\xf1\x3f\x58\x28\x23\xa1\xd7\x4e\x9f\x07\x0f\xee\x26\x41\x70\xd5\xa1\x90\xb2\xcc\xb2\x73\x73\x3c\xfa\x8f\x29\xaa\x7a\x5b\xaa\xf4\x99\xa4\x98\xe3\xf9\xfc\x3d\x85\xca\xe6\xf8\xf5\xa4\xe5\xff\xff\x22\x7c\x04\x01\x00\x54\x96\x2b\xb2\x1c\x3a\xb5\xd3\x6c\xe7\xa0\x5a\x8a\xf0\xc9\xb9\x9a\x5f\x7c\xa9\x09\x55\xb4\x55\xa5\x92\x43\x62\xb4\xd8\xb6\x3e\x3b\xf5\xac\xae\xb8\x3c\x4e\xf1\x42\x7b\x7e\xa5\xb2\xe6\x08\xb7\x8f\x7e\x52\x6d\x16\x9c\x4e\xc9\x72\xd5\x1d\x2c\xb1\x63\x39\xc1\xfa\x0a\xa2\x38\xed\xf9\x14\xbb\x78\x6b\xac\x35\xcd\xe2\xf6\x63\xdc\xa9\x38\x39\xf3\x1c\xef\xc3\x4b\xb1\xd1\x39\x59\x7b\x1e\x1e\x50\x91\x56\x69\x38\x49\x3a\xbf\x68\x23\xf0\x94\x20\x58\xce\xd9\xb2\x4e\xbb\x89\x0f\x47\x3d\x89\x82\x81\x68\x9d\xcb\x4f\xce\xb1\xbc\x9e\xad\xe7\x59\xaf\x36\xa1\xca\xfe\x25\x6b\xc6\x4e\x59\xce\x5a\x9f\x4e\x2e\x3c\x9f\xf4\xec\x1b\x09\x61\x79\xd2\x13\x5b\x76\xa6\xdc\x73\x6b\x88\x70\x73\xa8\x78\x31\xb0\x48\xbc\x5e\x6d\x92\x41\xe4\x7d\x18\x45\x37\x20\x77\x83\x2f\x80\x97\xea\x67\x33\x24\xde\xe0\x04\xcd\xcd\x1f\x16\x77\x03\xa1\xdd\xeb\x85\x0a\x8b\xbb\x91\xf6\xd8\x6f\xcb\xf7\x21\x2e\x8c\x06\x09\x1d\xed\x19\x4a\xfa\x06\x9d\x56\xfe\x8c\xf0\x36\x8d\x4f\x6b\x18\xb7\xe8\x70\x71\x37\x4a\x3d\x85\x98\xf9\x38\xf9\x29\xc4\xfb\xe4\x3a\x63\xda\x97\xe8\x8d\x84\xb3\x07\x0f\xc8\x8d\x1d\xff\x07\xfe\x3e\x9a\x84\x2a\x2c\x7b\x71\x03\x13\xf7\x4a\x55\xbb\x52\x5f\x7a\x79\x60\xa5\xf6\x7c\x5e\xc4\x00\x1a\x8d\x1b\x34\xd0\x50\xf9\x65\x0d\x07\x7a\xa7\x20\x99\x63\xbc\x3c\xc7\xe0\x18\xfc\x0e\x00\x00\xff\xff\x9d\xf2\x7d\x21\x87\x05\x00\x00" func transactionsSetup_account_from_nft_referenceCdcBytes() ([]byte, error) { @@ -589,12 +631,14 @@ var _bindata = map[string]func() (*asset, error){ "scripts/get_nft_metadata.cdc": scriptsGet_nft_metadataCdc, "scripts/get_nft_view.cdc": scriptsGet_nft_viewCdc, "transactions/destroy_nft.cdc": transactionsDestroy_nftCdc, + "transactions/generic_transfer.cdc": transactionsGeneric_transferCdc, "transactions/mint_nft.cdc": transactionsMint_nftCdc, "transactions/nft-forwarding/change_forwarder_recipient.cdc": transactionsNftForwardingChange_forwarder_recipientCdc, "transactions/nft-forwarding/create_forwarder.cdc": transactionsNftForwardingCreate_forwarderCdc, "transactions/nft-forwarding/transfer_nft_to_receiver.cdc": transactionsNftForwardingTransfer_nft_to_receiverCdc, "transactions/nft-forwarding/unlink_forwarder_link_collection.cdc": transactionsNftForwardingUnlink_forwarder_link_collectionCdc, "transactions/setup_account.cdc": transactionsSetup_accountCdc, + "transactions/setup_account_from_address.cdc": transactionsSetup_account_from_addressCdc, "transactions/setup_account_from_nft_reference.cdc": transactionsSetup_account_from_nft_referenceCdc, "transactions/setup_account_to_receive_royalty.cdc": transactionsSetup_account_to_receive_royaltyCdc, "transactions/test/upgrade_nft_contract.cdc": transactionsTestUpgrade_nft_contractCdc, @@ -658,6 +702,7 @@ var _bintree = &bintree{nil, map[string]*bintree{ }}, "transactions": {nil, map[string]*bintree{ "destroy_nft.cdc": {transactionsDestroy_nftCdc, map[string]*bintree{}}, + "generic_transfer.cdc": {transactionsGeneric_transferCdc, map[string]*bintree{}}, "mint_nft.cdc": {transactionsMint_nftCdc, map[string]*bintree{}}, "nft-forwarding": {nil, map[string]*bintree{ "change_forwarder_recipient.cdc": {transactionsNftForwardingChange_forwarder_recipientCdc, map[string]*bintree{}}, @@ -666,6 +711,7 @@ var _bintree = &bintree{nil, map[string]*bintree{ "unlink_forwarder_link_collection.cdc": {transactionsNftForwardingUnlink_forwarder_link_collectionCdc, map[string]*bintree{}}, }}, "setup_account.cdc": {transactionsSetup_accountCdc, map[string]*bintree{}}, + "setup_account_from_address.cdc": {transactionsSetup_account_from_addressCdc, map[string]*bintree{}}, "setup_account_from_nft_reference.cdc": {transactionsSetup_account_from_nft_referenceCdc, map[string]*bintree{}}, "setup_account_to_receive_royalty.cdc": {transactionsSetup_account_to_receive_royaltyCdc, map[string]*bintree{}}, "test": {nil, map[string]*bintree{ diff --git a/lib/go/templates/templates.go b/lib/go/templates/templates.go index db53b692..bfba0457 100644 --- a/lib/go/templates/templates.go +++ b/lib/go/templates/templates.go @@ -1,6 +1,7 @@ package templates import ( + "fmt" "regexp" "github.com/onflow/flow-go-sdk" @@ -9,12 +10,14 @@ import ( //go:generate go run github.com/kevinburke/go-bindata/go-bindata -prefix ../../../ -o internal/assets/assets.go -pkg assets -nometadata -nomemcopy ../../../scripts/... ../../../transactions/... var ( - placeholderNonFungibleToken = regexp.MustCompile(`"NonFungibleToken"`) - placeholderExampleNFT = regexp.MustCompile(`"ExampleNFT"`) - placeholderMetadataViews = regexp.MustCompile(`"MetadataViews"`) - placeholderFungibleToken = regexp.MustCompile(`"FungibleToken"`) - placeholderViewResolver = regexp.MustCompile(`"ViewResolver"`) - placeholderFlowToken = regexp.MustCompile(`"FlowToken"`) + placeholderNonFungibleTokenString = "\"NonFungibleToken\"" + placeholderNonFungibleToken = regexp.MustCompile(`"NonFungibleToken"`) + placeholderExampleNFT = regexp.MustCompile(`"ExampleNFT"`) + placeholderMetadataViews = regexp.MustCompile(`"MetadataViews"`) + placeholderMetadataViewsString = "\"MetadataViews\"" + placeholderFungibleToken = regexp.MustCompile(`"FungibleToken"`) + placeholderViewResolver = regexp.MustCompile(`"ViewResolver"`) + placeholderFlowToken = regexp.MustCompile(`"FlowToken"`) ) func replaceAddresses(code string, nftAddress, exampleNFTAddress, metadataAddress, ftAddress, viewResolverAddress flow.Address) []byte { @@ -25,3 +28,15 @@ func replaceAddresses(code string, nftAddress, exampleNFTAddress, metadataAddres code = placeholderViewResolver.ReplaceAllString(code, "0x"+viewResolverAddress.String()) return []byte(code) } + +func withHexPrefix(address string) string { + if address == "" { + return "" + } + + if address[0:2] == "0x" { + return address + } + + return fmt.Sprintf("0x%s", address) +} diff --git a/lib/go/templates/transaction_templates.go b/lib/go/templates/transaction_templates.go index 0acc6028..2fe17702 100644 --- a/lib/go/templates/transaction_templates.go +++ b/lib/go/templates/transaction_templates.go @@ -1,6 +1,8 @@ package templates import ( + "strings" + "github.com/onflow/flow-go-sdk" _ "github.com/kevinburke/go-bindata" @@ -11,8 +13,10 @@ import ( const ( filenameUpgradeNFT = "transactions/test/upgrade_nft_contract.cdc" filenameSetupAccount = "transactions/setup_account.cdc" + filenameSetupFromAddress = "transactions/setup_account_from_address.cdc" filenameMintNFT = "transactions/mint_nft.cdc" filenameTransferNFT = "transactions/transfer_nft.cdc" + filenameTransferGenericNFT = "transactions/transfer_nft.cdc" filenameDestroyNFT = "transactions/destroy_nft.cdc" filenameSetupRoyalty = "transactions/setup_account_to_receive_royalty.cdc" filenameSetupAccountFromNftReference = "transactions/setup_account_from_nft_reference.cdc" @@ -31,6 +35,27 @@ func GenerateSetupAccountScript(nftAddress, exampleNFTAddress, metadataViewsAddr return replaceAddresses(code, nftAddress, exampleNFTAddress, metadataViewsAddress, flow.EmptyAddress, flow.EmptyAddress) } +// GenerateSetupAccountFromAddressScript returns a script that instantiates a new +// NFT collection instance for any NFT type, assuming that the sender knows the address +// and name of the NFT contract +func GenerateSetupAccountFromAddressScript(nftAddress, metadataViewsAddress string) []byte { + code := assets.MustAssetString(filenameSetupFromAddress) + + code = strings.ReplaceAll( + code, + placeholderNonFungibleTokenString, + withHexPrefix(nftAddress), + ) + + code = strings.ReplaceAll( + code, + placeholderMetadataViewsString, + withHexPrefix(metadataViewsAddress), + ) + + return []byte(code) +} + // GenerateMintNFTScript returns script that uses the admin resource // to mint a new NFT and deposit it into a user's collection. func GenerateMintNFTScript(nftAddress, exampleNFTAddress, metadataViewsAddress, ftAddress flow.Address) []byte { @@ -40,9 +65,24 @@ func GenerateMintNFTScript(nftAddress, exampleNFTAddress, metadataViewsAddress, // GenerateTransferNFTScript returns a script that withdraws an NFT token // from a collection and deposits it into another collection. -func GenerateTransferNFTScript(nftAddress, exampleNFTAddress, metadataAddress, viewResolverAddress flow.Address) []byte { +func GenerateTransferNFTScript(nftAddress, exampleNFTAddress, metadataViewsAddress, viewResolverAddress flow.Address) []byte { + code := assets.MustAssetString(filenameTransferGenericNFT) + return replaceAddresses(code, nftAddress, exampleNFTAddress, metadataViewsAddress, flow.EmptyAddress, viewResolverAddress) +} + +// GenerateTransferGenericNFTScript returns a script that withdraws a generic NFT token +// from a collection and deposits it into another collection. +// The sender needs to send the paths to use to withdraw from and deposit to +func GenerateTransferGenericNFTScript(nftAddress string) []byte { code := assets.MustAssetString(filenameTransferNFT) - return replaceAddresses(code, nftAddress, exampleNFTAddress, metadataAddress, flow.EmptyAddress, viewResolverAddress) + + code = strings.ReplaceAll( + code, + placeholderNonFungibleTokenString, + withHexPrefix(nftAddress), + ) + + return []byte(code) } // GenerateDestroyNFTScript creates a script that withdraws an NFT token diff --git a/tests/test_example_nft.cdc b/tests/test_example_nft.cdc index 3260479f..506738cf 100644 --- a/tests/test_example_nft.cdc +++ b/tests/test_example_nft.cdc @@ -20,20 +20,37 @@ fun setup() { access(all) fun testSetupAccount() { - let txResult = executeTransaction( + var txResult = executeTransaction( "../transactions/setup_account.cdc", [], recipient ) Test.expect(txResult, Test.beSucceeded()) - let scriptResult = executeScript( + var scriptResult = executeScript( "../scripts/get_collection_length.cdc", [admin.address] ) Test.expect(scriptResult, Test.beSucceeded()) - let collectionLength = scriptResult.returnValue! as! Int + var collectionLength = scriptResult.returnValue! as! Int + Test.assertEqual(0, collectionLength) + + let newAccount = Test.createAccount() + txResult = executeTransaction( + "../transactions/setup_account_from_address.cdc", + [admin.address, "ExampleNFT"], + newAccount + ) + Test.expect(txResult, Test.beSucceeded()) + + scriptResult = executeScript( + "../scripts/get_collection_length.cdc", + [newAccount.address] + ) + Test.expect(scriptResult, Test.beSucceeded()) + + collectionLength = scriptResult.returnValue! as! Int Test.assertEqual(0, collectionLength) } @@ -96,7 +113,7 @@ fun testTransferNFT() { Test.assertEqual(1, collectionIDs.length) let nftID: UInt64 = collectionIDs[0] - let txResult = executeTransaction( + var txResult = executeTransaction( "../transactions/transfer_nft.cdc", [ admin.address, @@ -135,6 +152,30 @@ fun testTransferNFT() { collectionIDs = scriptResult.returnValue! as! [UInt64] Test.assertEqual([nftID] as [UInt64], collectionIDs) + + txResult = executeTransaction( + "../transactions/generic_transfer.cdc", + [ + nftID, + recipient.address, + /storage/cadenceExampleNFTCollection, + /public/cadenceExampleNFTCollection + ], + admin + ) + Test.expect(txResult, Test.beSucceeded()) + + txResult = executeTransaction( + "../transactions/transfer_nft.cdc", + [ + admin.address, + "ExampleNFT", + admin.address, + nftID + ], + recipient + ) + Test.expect(txResult, Test.beSucceeded()) } access(all) diff --git a/transactions/generic_transfer.cdc b/transactions/generic_transfer.cdc new file mode 100644 index 00000000..f24e9c67 --- /dev/null +++ b/transactions/generic_transfer.cdc @@ -0,0 +1,38 @@ +import NonFungibleToken from "NonFungibleToken" + +/// Can pass in any storage path and receiver path instead of just the default. +/// This lets you choose the token you want to send as well the capability you want to send it to. +/// +/// Any token path can be passed as an argument here, so wallets should +/// should check argument values to make sure the intended token path is passed in +/// +transaction(id: UInt64, to: Address, senderPath: StoragePath, receiverPath: PublicPath) { + + // The NFT resource to be transferred + let tempNFT: @{NonFungibleToken.NFT} + + prepare(signer: auth(BorrowValue) &Account) { + + // borrow a reference to the signer's NFT collection + let withdrawRef = signer.storage.borrow( + from: senderPath + ) ?? panic("Account does not store a collection object at the specified path") + + self.tempNFT <- withdrawRef.withdraw(withdrawID: id) + } + + execute { + // get the recipients public account object + let recipient = getAccount(to) + + // borrow a public reference to the receivers collection + let receiverCap = recipient.capabilities.get<&{NonFungibleToken.Receiver}>(receiverPath) + ?? panic("Could not get the recipient's Receiver Capability") + + let receiverRef = receiverCap.borrow() + ?? panic("Could not borrow reference to the recipient's receiver") + + // Deposit the NFT to the receiver + receiverRef.deposit(token: <-self.tempNFT) + } +} \ No newline at end of file diff --git a/transactions/setup_account_from_address.cdc b/transactions/setup_account_from_address.cdc new file mode 100644 index 00000000..cb34a885 --- /dev/null +++ b/transactions/setup_account_from_address.cdc @@ -0,0 +1,33 @@ +/// This transaction is what an account would run +/// to set itself up to receive NFTs. This function +/// uses views to know where to set up the collection +/// in storage and to create the empty collection. + +import NonFungibleToken from "NonFungibleToken" +import MetadataViews from "MetadataViews" + +transaction(contractAddress: Address, contractName: String) { + + prepare(signer: auth(IssueStorageCapabilityController, PublishCapability, SaveValue) &Account) { + // Borrow a reference to the nft contract deployed to the passed account + let resolverRef = getAccount(contractAddress) + .contracts.borrow<&NonFungibleToken>(name: contractName) + ?? panic("Could not borrow a reference to the non-fungible token contract") + + // Use that reference to retrieve the NFTCollectionData view + let collectionData = resolverRef.resolveContractView(resourceType: nil, viewType: Type()) as! MetadataViews.NFTCollectionData? + ?? panic("Could not resolve the NFTCollectionData view for the given non-fungible token contract") + + // Create a new empty collections + let emptyCollection <- collectionData.createEmptyCollection() + + // save it to the account + signer.storage.save(<-emptyCollection, to: collectionData.storagePath) + + // create a public capability for the collection + let collectionCap = signer.capabilities.storage.issue<&{NonFungibleToken.Collection}>( + collectionData.storagePath + ) + signer.capabilities.publish(collectionCap, at: collectionData.publicPath) + } +}