TypeScript Metodi per il blocco NFT ERC-1155

Blockchain App Builder genera automaticamente metodi che è possibile utilizzare per bloccare i token non fungibili che utilizzano lo standard ERC-1155 esteso.

Un token bloccato non può essere masterizzato o trasferito ad altri utenti. Vengono conservate tutte le altre proprietà, ad esempio lo stato, il proprietario e la cronologia del token. È possibile utilizzare la funzionalità di blocco NFT quando si trasferisce un token su un'altra rete blockchain, come Ethereum o Polygon.

Prima di poter bloccare gli NFT, è necessario assegnare il ruolo di vault manager a un utente. Il gestore del vault è un tipo speciale di ruolo, un ruolo TokenSys. I ruoli TokenSys sono diversi dai ruoli basati sugli asset, ad esempio masterizzatore, minter e notaio, nonché dai ruoli amministrativi quali Token Admin e Org Admin. Attualmente Blockchain App Builder supporta il ruolo vault TokenSys. Il singolo utente che dispone del ruolo vault per un codice concatenato è il gestore vault del codice concatenato e può gestire NFT bloccati.

Il flusso tipico per l'utilizzo della funzionalità di blocco NFT segue questi passaggi.
  • Creare un token non fungibile con il funzionamento bloccabile.
  • Utilizzare il metodo addTokenSysRole per assegnare il ruolo vault a un utente, il gestore vault.
  • Chiamare il metodo lockNFT per bloccare un token non fungibile specificato dall'ID token.

TokenSys Metodi di gestione dei ruoli

addTokenSysRole
Questo metodo aggiunge un ruolo TokenSys a un utente specificato. Questo metodo può essere richiamato solo da un Token Admin del codice concatenato.
@Validator(yup.string(), yup.string(), yup.string())
public async addTokenSysRole(orgId: string, userId: string, role: string) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155TOKEN.addTokenSysRoleMember", "TOKEN");
  const userAccountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId);
  return await this.Ctx.ERC1155Token.addTokenSysRoleMember(role, userAccountId);
}
Parametri:
  • orgId: string: l'ID del provider di servizi di appartenenza (MSP) dell'utente nell'organizzazione corrente.
  • userId: string: il nome utente o l'ID e-mail dell'utente.
  • role: string: il nome del ruolo TokenSys da assegnare all'utente.
Restituisce:
  • In caso di operazione riuscita, un messaggio contenente i dettagli rilevanti dell'operazione.
Esempio di valore restituito:
{
    "msg": "Successfully added role 'vault' to Account Id: oaccount~bf07f584a94be44781e49d9101bfaf58c6fbbe77a4dfebdb83c874c2caf03eba (Org-Id: Org1MSP, User-Id: user1)"
}
isInTokenSysRole
Questo metodo restituisce un valore booleano per indicare se un utente dispone di un ruolo TokenSys specificato. Questo metodo può essere richiamato solo da un Token Admin del codice concatenato.
@Validator(yup.string(), yup.string(), yup.string())
public async isInTokenSysRole(orgId: string, userId: string, role: string) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155TOKEN.isInTokenSysRole", "TOKEN", {orgId: orgId, userId: userId });
  const userAccountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId);
  return await this.Ctx.ERC1155Token.isInTokenSysRole(role, userAccountId);
}
Parametri:
  • orgId: string: l'ID del provider di servizi di appartenenza (MSP) dell'utente nell'organizzazione corrente.
  • userId: string: il nome utente o l'ID e-mail dell'utente.
  • role: string: il nome del ruolo TokenSys da controllare.
Restituisce:
  • In caso di operazione riuscita, un messaggio contenente i dettagli rilevanti dell'operazione.
Esempio di valore restituito:
{
    "result": true,
    "msg": "Account Id oaccount~bf07f584a94be44781e49d9101bfaf58c6fbbe77a4dfebdb83c874c2caf03eba (Org-Id: Org1MSP, User-Id: user1) has vault role"
}
removeTokenSysRole
Questo metodo rimuove un ruolo TokenSys da un utente specificato. Questo metodo può essere richiamato solo da un Token Admin del codice concatenato.
@Validator(yup.string(), yup.string(), yup.string())
public async removeTokenSysRole(orgId: string, userId: string, role: string) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155TOKEN.removeTokenSysRoleMember", "TOKEN");
  const userAccountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId);
  return await this.Ctx.ERC1155Token.removeTokenSysRoleMember(role, userAccountId);
}
Parametri:
  • orgId: string: l'ID del provider di servizi di appartenenza (MSP) dell'utente nell'organizzazione corrente.
  • userId: string: il nome utente o l'ID e-mail dell'utente.
  • role: string: il nome del ruolo TokenSys da rimuovere.
Restituisce:
  • In caso di operazione riuscita, un messaggio contenente i dettagli rilevanti dell'operazione.
Esempio di valore restituito:
{
    "msg": "Successfully removed role 'vault' from Account Id: oaccount~bf07f584a94be44781e49d9101bfaf58c6fbbe77a4dfebdb83c874c2caf03eba (Org-Id: Org1MSP, User-Id: user1)"
}
transferTokenSysRole
Questo metodo trasferisce un ruolo TokenSys da un utente a un altro utente. Questo metodo può essere richiamato solo da un Token Admin del codice concatenato.
@Validator(yup.string(), yup.string(), yup.string(), yup.string(), yup.string())
public async transferTokenSysRole(fromOrgId: string, fromUserId: string, toOrgId: string, toUserId: string, role: string) {
    await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155TOKEN.transferTokenSysRole", "TOKEN");
    const fromUserAccountId = await this.Ctx.ERC1155Account.generateAccountId(fromOrgId, fromUserId);
    const toUserAccountId = await this.Ctx.ERC1155Account.generateAccountId(toOrgId, toUserId);
    return await this.Ctx.ERC1155Token.transferTokenSysRole(role, fromUserAccountId, toUserAccountId);
}
Parametri:
  • fromOrgId: string: l'ID del provider di servizi di appartenenza (MSP) dell'utente da cui trasferire il ruolo TokenSys.
  • fromUserId: string: il nome utente o l'ID e-mail dell'utente da cui trasferire il ruolo TokenSys.
  • toOrgId: string: l'ID del provider di servizi di appartenenza (MSP) dell'utente a cui trasferire il ruolo TokenSys.
  • toUserId: string: il nome utente o l'ID e-mail dell'utente a cui trasferire il ruolo TokenSys.
  • role: string: il nome del ruolo TokenSys da trasferire.
Restituisce:
  • In caso di operazione riuscita, un messaggio contenente i dettagli rilevanti dell'operazione.
Esempio di valore restituito:
{
    "msg": "Successfully transfered role 'vault' from Account Id: ouaccount~f4e311528f03fffa7810753d643f66289ff6c9080fcf839902f28a1d3aff1789 (Org-Id: Org1MSP, User-Id: user1) to Account Id: ouaccount~ae5be2ae8f98d6d32f5d02b43877d987114e7937c7bacbc30390dcce09996a19 (Org-Id: Org1MSP, User-Id: user2)"
}
getAccountsByTokenSysRole
Questo metodo restituisce un elenco di tutti gli ID account per un ruolo TokenSys specificato. Questo metodo può essere richiamato solo da un Token Admin del codice concatenato.
@Validator(yup.string())
public async getAccountsByTokenSysRole(role: string) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155TOKEN.getAccountsByTokenSysRole", "TOKEN");
  return await this.Ctx.ERC1155Token.getAccountsByTokenSysRole(role);
}
Parametri:
  • role: string: il nome del ruolo TokenSys.
Restituisce:
  • In caso di operazione riuscita, un messaggio contenente i dettagli rilevanti dell'operazione.
Esempio di valore restituito:
{
    "accountIds": [
        "oaccount~bf07f584a94be44781e49d9101bfaf58c6fbbe77a4dfebdb83c874c2caf03eba"
    ]
}
getUsersByTokenSysRole
Questo metodo restituisce le informazioni utente per tutti gli utenti con un ruolo TokenSys specificato. Questo metodo può essere richiamato solo da un Token Admin del codice concatenato.
@Validator(yup.string())
public async getUsersByTokenSysRole(role: string) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155TOKEN.getUsersByTokenSysRole", "TOKEN");
  return await this.Ctx.ERC1155Token.getUsersByTokenSysRole(role);
}
Parametri:
  • role: string: il nome del ruolo TokenSys.
Restituisce:
  • In caso di operazione riuscita, un messaggio contenente i dettagli rilevanti dell'operazione.
Esempio di valore restituito:
{
   "users":[
      {
         "accountId":"oaccount~bf07f584a94be44781e49d9101bfaf58c6fbbe77a4dfebdb83c874c2caf03eba",
         "orgId":"Org1MSP",
         "userId":"user1"
      }
   ]
}

Metodi di blocco NFT

lockNFT
Questo metodo blocca un token non fungibile specificato. Per bloccare un token, deve esistere un utente con il ruolo TokenSys vault che funge da gestore del vault. Questo metodo può essere chiamato solo dal proprietario del token.
@Validator(yup.string())
public async lockNFT(orgId: string, userId: string, tokenId: string) {
  return await this.Ctx.ERC1155Token.lockNFT(orgId, userId, tokenId);
}
Parametri:
  • orgId: string: l'ID del provider di servizi di appartenenza (MSP) dell'utente nell'organizzazione corrente.
  • userId: string: il nome utente o l'ID e-mail dell'utente (facoltativo).
  • tokenID: string: l'ID del token da bloccare.
Restituisce:
  • In caso di operazione riuscita, una rappresentazione JSON dell'oggetto token.
Esempio di valore restituito:
{
   "assetType":"otoken",
   "tokenId":"token1",
   "tokenName":"artcollection",
   "tokenStandard":"erc1155+",
   "tokenType":"nonfungible",
   "tokenUnit":"whole",
   "behaviors":[
      "indivisible",
      "mintable",
      "transferable",
      "burnable",
      "lockable",
      "roles"
   ],
   "roles":{
      "minter_role_name":"minter"
   },
   "mintable":{
      "max_mint_quantity":20000
   },
   "quantity":1,
   "createdBy":"oaccount~208e3345ac84b4849f0d2648b2f2f018019886a1230f99304ebff1b6a7733463",
   "creationDate":"2023-10-20T09:16:29.000Z",
   "owner":"oaccount~208e3345ac84b4849f0d2648b2f2f018019886a1230f99304ebff1b6a7733463",
   "isBurned":false,
   "isLocked":true,
   "tokenUri":"token1.example.com",
   "price":120,
   "on_sale_flag":false
}
isNFTLocked
Questo metodo restituisce un valore booleano per indicare se un token specificato è bloccato. Questo metodo può essere richiamato solo dal proprietario del token, dal gestore del vault (l'utente con il ruolo TokenSys vault) o da un Token Admin del codice concatenato.
@GetMethod()
@Validator(yup.string())
public async isNFTLocked(tokenId: string) {
  try {
    await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155TOKEN.isNFTLocked", "TOKEN", { tokenId });
  } catch(err) {
    const isCallerTokenSysRoleHolder = await this.Ctx.ERC1155Token.isCallerTokenSysRoleHolder(TOKEN_SYS_ROLE_TYPE.VAULT);
    if(!isCallerTokenSysRoleHolder)
      throw err;
  }
  const isNFTLocked = await this.Ctx.ERC1155Token.isNFTLocked(tokenId);
  return {isNFTLocked};
}
Parametri:
  • tokenID: string: l'ID del token.
Restituisce:
  • In caso di operazione riuscita, un messaggio contenente i dettagli rilevanti dell'operazione.
Esempio di valore restituito:
{
   "isNFTLocked":true
}
getAllLockedNFTs
Questo metodo restituisce un elenco di tutti i token non fungibili bloccati. Questo metodo può essere chiamato solo dal gestore del vault (l'utente con il ruolo TokenSys vault) o da un Token Admin del codice concatenato.
@GetMethod()
@Validator()
public async getAllLockedNFTs() {
  try {
    await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155TOKEN.getAllLockedNFTs", "TOKEN");
  } catch(err) {
    const isCallerTokenSysRoleHolder = await this.Ctx.ERC1155Token.isCallerTokenSysRoleHolder(TOKEN_SYS_ROLE_TYPE.VAULT);
    if(!isCallerTokenSysRoleHolder)
      throw err;
  }
  return this.Ctx.ERC1155Token.getAllLockedNFTs();
}
Parametri:
  • Nessuno.
Restituisce:
  • In caso di operazione riuscita, un array di oggetti token non fungibili bloccati.
Esempio di valore restituito:
[
   {
      "key":"token1",
      "valueJson":{
         "assetType":"otoken",
         "tokenId":"token1",
         "tokenName":"artcollection",
         "tokenStandard":"erc1155+",
         "tokenType":"nonfungible",
         "tokenUnit":"whole",
         "behaviors":[
            "indivisible",
            "mintable",
            "transferable",
            "burnable",
            "lockable",
            "roles"
         ],
         "roles":{
            "minter_role_name":"minter"
         },
         "mintable":{
            "max_mint_quantity":20000
         },
         "quantity":1,
         "createdBy":"oaccount~208e3345ac84b4849f0d2648b2f2f018019886a1230f99304ebff1b6a7733463",
         "creationDate":"2023-10-20T09:16:29.000Z",
         "owner":"oaccount~208e3345ac84b4849f0d2648b2f2f018019886a1230f99304ebff1b6a7733463",
         "isBurned":false,
         "isLocked":true,
         "tokenUri":"token1.example.com",
         "price":120,
         "on_sale_flag":false
      }
   }
]
getAllLockedNFTsByOrg
Questo metodo restituisce un elenco di tutti i token non fungibili bloccati per un'organizzazione specificata e, facoltativamente, per un utente specificato. Questo metodo può essere chiamato solo dal gestore del vault (l'utente con il ruolo TokenSys vault) o da un Token Admin del codice concatenato.
@GetMethod()
@Validator(yup.string(), yup.string())
public async getLockedNFTsByOrg(orgId: string, userId?: string) {
  try {
    await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155TOKEN.getLockedNFTsByOrg", "TOKEN");
  } catch(err) {
    const isCallerTokenSysRoleHolder = await this.Ctx.ERC1155Token.isCallerTokenSysRoleHolder(TOKEN_SYS_ROLE_TYPE.VAULT);
    if(!isCallerTokenSysRoleHolder)
      throw err;
  }
  return await this.Ctx.ERC1155Token.getLockedNFTsByOrg(orgId, userId);
}
Parametri:
  • orgId: string: l'ID del provider di servizi di appartenenza (MSP) dell'utente nell'organizzazione corrente.
  • userId: string: il nome utente o l'ID e-mail dell'utente (facoltativo).
Restituisce:
  • In caso di operazione riuscita, un array di oggetti token non fungibili bloccati.
Esempio di valore restituito:
[
   {
      "key":"token1",
      "valueJson":{
         "assetType":"otoken",
         "tokenId":"token1",
         "tokenName":"artcollection",
         "tokenStandard":"erc1155+",
         "tokenType":"nonfungible",
         "tokenUnit":"whole",
         "behaviors":[
            "indivisible",
            "mintable",
            "transferable",
            "burnable",
            "lockable",
            "roles"
         ],
         "roles":{
            "minter_role_name":"minter"
         },
         "mintable":{
            "max_mint_quantity":20000
         },
         "quantity":1,
         "createdBy":"oaccount~208e3345ac84b4849f0d2648b2f2f018019886a1230f99304ebff1b6a7733463",
         "creationDate":"2023-10-20T09:16:29.000Z",
         "owner":"oaccount~208e3345ac84b4849f0d2648b2f2f018019886a1230f99304ebff1b6a7733463",
         "isBurned":false,
         "isLocked":true,
         "tokenUri":"token1.example.com",
         "price":120,
         "on_sale_flag":false
      }
   }
]