kodadot / nft-gallery

Generative Art Marketplace
https://kodadot.xyz
MIT License
612 stars 351 forks source link

Migration UI - 3 - Signing #7562

Closed exezbcz closed 7 months ago

exezbcz commented 8 months ago

part of a bigger issue:

Signing 🚥

exezbcz commented 8 months ago

Some changes will be made, mainly to the structure of what you are signing, and maybe some flow as well.

don't take this issue please till we update that.

cc @vikiival

yangwao commented 8 months ago

@exezbcz where the user will see if everything was migrated successfully with on-chain checks? Like item list for example?

exezbcz commented 8 months ago

@exezbcz where the user will see if everything was migrated successfully with on-chain checks? Like item list for example?

After each transaction is complete, you can click on the link. Once everything is completed it also works like a list of transactions. It does proceed to the congratulations before you click the complete button

I will add more comprehensive list on the congratulations screen - list of items with status and link to tx. Thanks for feedback sir

vikiival commented 8 months ago

Context

So as I wrote the migration script I found out a unpleasant truth: If user wants to presign items, he/she need to sign MANUALY EVERY SINGLE ITEM. As this should be as easy as possible, I found a new way

The code

The create collectoion tx should be composed of

// Step 1
const nextId = weHaveACodeForThis()
const collection = getCollectionById('ksm', collectionId)

batch [
create(accountId, defaultSettings),
set_collection_metadata(nextId, collection.metadata),
set_team(nextId, KODA_BOT, accountId, accountId)
]

after transaction is successful the code should call an API

POST /relocations

body

{
  "from": {
    "chain": "ksm", // or rmrk depends which 
    "collection": "" // collection id from 
  },
   "to": {
    "chain": "ahk", // or ahp depends
    "collection": "" // collection id 
  },
  "issuer": "" // account id
}

Once API call was returned with status 200.

we need to compose another API call that sends all the required params to sign.

// Step 2
PUT /relocations/{chainFrom}/{collectionFrom}/iterations/{iteration}

The return of this api call is a list of Signatures where signature is composed at least from

{
  "result": {
    "ok": true,
    "id": "", //basically id of last one 
    "error": null
  },
  "data": [
    {
      "account": "", //current owner of nft
      "attributes": "", // attributes to be created
      "chain": "ksm", // chain 
      "collection": "", // rmrk_collection_id
      "data": "", // packed data, check step 3, sig.data
      "deadline": 12000000,
      "id": "", // internal id
      "metadata": "", // metadta to be minted along 
      "signature": "", // signature, check step 3, sig.signature
      "signer": "",// signer, check step 3, sig. signer
      "sn": "", // rmrk_sn_id
      "to_chain": "ahk",
      "to_collection": "", // collection_id
      "to_sn": "" // future_nft_sn
    }
  ]

Keep in mind that API returns just a list of owned nfts, other signatures are dedicated for other users

Once you get this list of signatures we need to build a payload for tx

// Step 3
function createItem(api: ApiPromise, sig: Signature) {
  const preSignInfo = api.createType("PalletNftsPreSignedMint", sig.data);
  const create = api.tx.nfts.mintPreSigned(preSignInfo, {
    Ed25519: sig.signature,
  }, sig.signer);
  return create;
}

const items = iterations.data.map((sig) => createItem(api, sig));

batch(
  items
)

Once this is successful we can burn the existing nfts

// Step 4

Last step is to iterate over signatures one more time and build proper system.remark for BURN

so iterate over nfts build proper extrinsic (do not remeber from head so can find along the way).

Once this is done. Call API to mark these nfts as migrated and continue to https://github.com/kodadot/nft-gallery/issues/7563

TBA

DELETE /relocations/{chainFrom}/{collectionFrom}

Body

[

]

From design perspective

I wrote the code first so I can guide better.

1. Create collection (✅)

2. Waiting API to sign NFTs

This will be possibly done in iterations. my bet is 1000 items per one iteration would be sufficient

3. Creating your own NFTs (✅)

Due to the limit of the AH blockchain my estimation is that 200 items can be minted in one iteration. Each iteration needs to wait for the in block state (then we can reflect it as done).

4. Burning migrated NFTs on Kusama

Same as step 3, but different naming, however we are not limited (13K items were tested).

Questions

  1. @exezbcz please let me know if anything is unclear.
  2. @kodadot/internal-dev is anything unclear here? Happy to hear your opinion.
exezbcz commented 8 months ago

Thank you sir; mostly clear, however, ad signing txs - some questions

For me, it's important how many tx the user will sign and after which step the user will wait.

from what i understand:

cc @vikiival

vikiival commented 8 months ago

For me, it's important how many tx the user will sign

  1. To create collection
  2. No need to sign anything from user
  3. NumberOfItems / BatchSize = iterations
  4. One to burn

So min 3

exezbcz commented 8 months ago

@vikiival, last question just to be sure

What will user sign if he is not the owner of the collection - migrating only items that were pre-signed by the owner

thanks!

vikiival commented 8 months ago

What will user sign if he is not the owner of the collection - migrating only items that were pre-signed by the owner

There should be a separated screen for /migrations where user can find list of waiting mogrations and can transact them in the batch

EDIT: @exezbcz already designed the screen

photo_2023-10-23 13 21 46

photo_2023-10-23 13 21 49

exezbcz commented 8 months ago

Changes/second iteration

image

Initiation stage

image


Migrating your items


Finalization

vikiival commented 8 months ago

I updated the API

preschian commented 8 months ago

hi @vikiival, is there something wrong with my args in here? https://assethub-kusama.subscan.io/block/0xf8cbf28ce3b0ce89b07ab484654c589efd443e6ed241902c437a59b52f920b73

I'm getting a 400 error on the /relocations endpoint. It returns Cannot read properties of null (reading 'currentOwner')

vikiival commented 8 months ago

For the logs purposes

hi @vikiival, is there something wrong with my args in here? https://assethub-kusama.subscan.io/block/0xf8cbf28ce3b0ce89b07ab484654c589efd443e6ed241902c437a59b52f920b73

Everything is good here

I'm getting a 400 error on the /relocations endpoint. It returns Cannot read properties of null (reading 'currentOwner')

There was a bug with usage of uniquery I was requesting image field on rmrk endpoint that does not exist. Fixed and deployed

preschian commented 8 months ago

Updates:

I will check again tomorrow

preschian commented 8 months ago

Updates:

image

preschian commented 8 months ago

Updates https://github.com/kodadot/nft-gallery/pull/7909:

On ahk:

On ahp:

cc @vikiival

Iterations and Burn not yet implemented. I will implement that once migration nfts look ok

preschian commented 8 months ago

Because of the API error, I will try to help on the backend side also on https://github.com/kodadot/private-workers

vikiival commented 8 months ago

❌ mock API on /relocations returns Target collection not found or you are not the owner

This was fixed

preschian commented 8 months ago

Because of the API error, I will try to help on the backend side also on kodadot/private-workers

I'm still not able to test this out. My dashboard has been blank since yesterday. There were some issues on the Cloudflare side. ref: https://github.com/kodadot/workers/issues/192#issuecomment-1791968274

https://www.cloudflarestatus.com/

image

vikiival commented 8 months ago

Still dead :/

Screenshot 2023-11-03 at 12 50 00