ERC-1155 的鷹架式 Go Token 專案

Blockchain App Builder 會從您的權杖規格檔案進行輸入,並產生功能完整的鷹架式鏈碼專案。

專案會自動產生記號週期類別和函數,包括 CRUD 和非 CRUD 方法。系統會自動支援引數驗證、封送處理 (Marshal) / 解除封送處理 (unmarshal) 以及透明保存功能。

如需鷹架專案的相關資訊,以及與記號無關的方法,請參閱 Scaffolded Go Chaincode Project

Model

OchainModel 類別中擷取「通透保存功能 (Transparent Persistence Capability)」或簡化的 ORM。下列模型顯示整個不可行記號。

package model

type ArtCollection struct {
	AssetType     string `json:"AssetType" final:"otoken"`
	TokenId       string `json:"TokenId" id:"true" mandatory:"true" validate:"regexp=^[A-Za-z0-9][A-Za-z0-9_-]*$,max=16"`
	TokenName     string `json:"TokenName" final:"artcollection"`
	TokenDesc     string `json:"TokenDesc" validate:"max=256"`
	TokenStandard string `json:"TokenStandard" final:"erc1155+"`
	TokenType     string `json:"TokenType" final:"nonfungible" validate:"regexp=^nonfungible$"`
	TokenUnit     string `json:"TokenUnit" final:"whole" validate:"regexp=^whole$"`

	Mintable map[string]interface{} `json:"Mintable" final:"{\"Max_mint_quantity\":20000}"`

	Behaviors []string `json:"Behaviors" final:"[\"indivisible\",\"singleton\",\"mintable\",\"transferable\",\"burnable\",\"roles\"]"`

	Roles map[string]interface{} `json:"Roles" final:"{\"minter_role_name\":\"minter\"}"`

	Owner           string `json:"Owner,omitempty" validate:"string"`
	CreatedBy       string `json:"CreatedBy,omitempty" validate:"string"`
	TransferredBy   string `json:"TransferredBy,omitempty" validate:"string"`
	CreationDate    string `json:"CreationDate,omitempty" validate:"string"`
	TransferredDate string `json:"TransferredDate,omitempty" validate:"string"`
	IsBurned        bool   `json:"IsBurned" validate:"bool"`
	BurnedBy        string `json:"BurnedBy,omitempty" validate:"string"`
	BurnedDate      string `json:"BurnedDate,omitempty" validate:"string"`
	TokenUri        string `json:"TokenUri" mandatory:"true" validate:"string,max=2000"`

	TokenMetadata ArtCollectionMetadata `json:"TokenMetadata"`

	Price        int  `json:"Price" validate:"int"`
	On_sale_flag bool `json:"On_sale_flag" validate:"bool"`
}

type ArtCollectionMetadata struct {
	Painting_name string `json:"Painting_name" validate:"string"`
	Description   string `json:"Description" validate:"string"`
	Image         string `json:"Image" validate:"string"`
	Painter_name  string `json:"Painter_name" validate:"string"`
}

type Loyalty struct {
	AssetType     string `json:"AssetType" final:"otoken"`
	TokenId       string `json:"TokenId" id:"true" mandatory:"true" validate:"regexp=^[A-Za-z0-9][A-Za-z0-9_-]*$,max=16"`
	TokenName     string `json:"TokenName" final:"loyalty"`
	TokenDesc     string `json:"TokenDesc" validate:"max=256"`
	TokenStandard string `json:"TokenStandard" final:"erc1155+"`
	TokenType     string `json:"TokenType" final:"fungible" validate:"regexp=^fungible$"`
	TokenUnit     string `json:"TokenUnit" final:"fractional" validate:"regexp=^fractional$"`

	Mintable map[string]interface{} `json:"Mintable" final:"{\"Max_mint_quantity\":10000}"`

	Divisible map[string]interface{} `json:"Divisible" final:"{\"Decimal\":2}"`

	Behaviors []string `json:"Behaviors" final:"[\"divisible\",\"mintable\",\"transferable\",\"burnable\",\"roles\"]"`

	Roles map[string]interface{} `json:"Roles" final:"{\"minter_role_name\":\"minter\"}"`

	Currency_name           string      `json:"Currency_name" validate:"string"`
	Token_to_currency_ratio int         `json:"Token_to_currency_ratio" validate:"int"`
	Metadata                interface{} `json:"Metadata,omitempty"`
}
下列模型顯示分數的不可行記號。
type RealEstateProperty struct {
      AssetType string `json:"AssetType" final:"otoken"`
      TokenId string `json:"TokenId" id:"true" mandatory:"true" validate:"regexp=^[A-Za-z0-9][A-Za-z0-9_-]*$,max=16"`
      TokenName string `json:"TokenName" final:"realestateproperty"`
      TokenDesc string `json:"TokenDesc" validate:"max=256"`
      TokenStandard string `json:"TokenStandard" final:"erc1155+"`
      TokenType string `json:"TokenType" final:"nonfungible" validate:"regexp=^nonfungible$"`
      TokenUnit string `json:"TokenUnit" final:"fractional" validate:"regexp=^fractional$"`

      Mintable map[string]interface{} `json:"Mintable" final:"{\"Max_mint_quantity\":0}"`
      Behaviors []string `json:"Behaviors" final:"[\"divisible\",\"mintable\",\"transferable\",\"roles\"]"`

      Divisible map[string]interface{} `json:"Divisible" final:"{\"Decimal\":0}"`

      Roles map[string]interface{} `json:"Roles" final:"{\"minter_role_name\":\"minter\"}"`

      CreatedBy string `json:"CreatedBy,omitempty" validate:"string"`
      CreationDate string `json:"CreationDate,omitempty" validate:"string"`
      IsBurned bool `json:"IsBurned" validate:"bool"`
      TokenUri string `json:"TokenUri" mandatory:"true" validate:"string,max=2000"`
      Quantity float64 `json:"Quantity,omitempty"`
      TokenMetadata RealEstatePropertyMetadata `json:"TokenMetadata"`

      PropertySellingPrice int `json:"PropertySellingPrice" validate:"int"`
      PropertyRentingPrice int `json:"PropertyRentingPrice" validate:"int"`
}

type RealEstatePropertyMetadata struct {
      PropertyType string `json:"PropertyType" validate:"string"`
      PropertyName string `json:"PropertyName" validate:"string"`
      PropertyAddress string `json:"PropertyAddress" validate:"string"`
      PropertyImage string `json:"PropertyImage" validate:"string"`
}

控制器

只有一個主控制器。

type Controller struct {
    Ctx trxcontext.TrxContext
}

您可以建立不限數目的類別、函數或檔案,但只能呼叫在主控制器類別中定義的方法。其他方法則為隱藏。

您可以使用記號 SDK 方法,為商業應用程式撰寫自訂方法。

自動產生的記號方法

Blockchain App Builder 會自動產生支援權杖和權杖生命週期的方法。您可以使用這些方法來初始化記號、管理角色和帳戶,以及完成其他記號生命週期工作,而無需進行任何其他編碼。控制器方法必須是公用才能呼叫。公用方法名稱開頭為大寫字元。開頭為小寫字元的方法名稱是私密的。

存取控制管理的方法

IsTokenAdmin
如果函數的呼叫程式是 Token Admin,此方法會傳回布林值 true,否則會傳回 false。此方法只能由鏈碼的 Token Admin 呼叫。
func (t *Controller) IsTokenAdmin(orgId string, userId string) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Admin.IsUserTokenAdmin", "TOKEN", map[string]string{"orgId": orgId, "userId": userId})
            if err != nil || !auth {
                  return false, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Auth.IsUserTokenAdmin(orgId, userId)
      }
參數:
  • orgId: string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId: string - 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 如果呼叫程式是 Token Admin,此方法會傳回 true,否則會傳回 false
傳回值範例:
{"result": true}
AddTokenAdmin
此方法會將使用者新增為鏈碼的 Token Admin。鏈碼的 Token Admin 只能呼叫此方法。
func (t *Controller) AddTokenAdmin(orgId string, userId string) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Admin.AddAdmin", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Admin.AddAdmin(orgId, userId)
      }
參數:
  • orgId: string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId: string - 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,包含新增為鏈碼 Token Admin 之使用者詳細資訊的訊息。
傳回值範例:
{"msg":"Successfully added Admin (orgId: appDev, userId: user1)"}
RemoveTokenAdmin
此方法會將使用者移除為鏈碼的 Token Admin。鏈碼的 Token Admin 只能呼叫此方法。您無法移除本身的 Token Admin
func (t *Controller) RemoveTokenAdmin(orgId string, userId string) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Admin.RemoveAdmin", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Admin.RemoveAdmin(orgId, userId)
      }
參數:
  • orgId: string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId: string - 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,包含以鏈碼 Token Admin 移除之使用者詳細資訊的訊息。
傳回值範例:
{
    "msg": "Successfully removed Admin (orgId appdev userId user1)"
}
GetAllTokenAdmins
此方法會傳回屬於鏈碼 Token Admin 的所有使用者清單。鏈碼的 Token Admin 只能呼叫此方法。
func (t *Controller) GetAllTokenAdmins() (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Admin.GetAllAdmins", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Admin.GetAllAdminUsers()
      }
參數:
傳回值:
  • 成功時,JSON 格式的 admins 陣列。
傳回值範例:
{
  "admins": [
    {
      "OrgId": "appdev",
      "UserId": "idcqa"
    },
    {
      "OrgId": "appdev",
      "UserId": "user1"
    }
  ]
}

記號組態管理的方法

Init
建立鏈碼時會呼叫此方法。每個 Token Admin 都是由 adminList 參數中的 userIdorgId 資訊所識別。userId 是執行處理擁有者或登入執行處理之使用者的使用者名稱或電子郵件 ID。orgId 是目前網路組織中使用者的成員服務提供者 (MSP) ID。第一次部署鏈碼時,adminList 參數是必要的。如果您要升級鏈碼,請傳送空白清單 ([])。如果您是初始部署鏈碼的使用者,您也可以在升級鏈碼時,在 adminList 參數中指定新的管理員。升級時會忽略 adminList 參數中的任何其他資訊。
func (t *Controller) Init(adminList []erc1155Admin.ERC1155TokenAdminAsset) (interface{}, error) {
      list, err := t.Ctx.ERC1155Admin.InitAdmin(adminList)
      if err != nil {
            return nil, fmt.Errorf("initialising admin list failed %s", err.Error())
      }
      <1st Token Name> := <1st TokenClassName>{}
      _, err = t.Ctx.ERC1155Token.SaveClassInfo(&<1st Token Name>)
      if err != nil {
            return nil, err
      }
         .
         .
      <nth Token Name> := <nth TokenClassName>{}
      _, err = t.Ctx.ERC1155Token.SaveClassInfo(&<nth Token Name>)
      if err != nil {
            return nil, err
      }
      _, err = t.Ctx.ERC1155Token.SaveDeleteTransactionInfo()
      if err != nil {
            fmt.Println("error: ", err)
      }
      return list, err
}
參數:
  • adminList array - 指定記號管理員清單的 {OrgId, UserId} 資訊陣列。adminList 陣列是必要參數。
Create<Token Name>Token
此方法會建立記號。每個定義的記號都有自己的建立方法。對於有趣的權杖,此方法只能由鏈碼的 Token Admin 呼叫。對於非功能變數替代字,如果在規格檔案中定義了 minter 角色,則具有 minter 角色的任何使用者都可以呼叫此方法來建立 NFT。如果未定義較小的角色,任何使用者都可以使用此方法來建立 (提示) NFT。呼叫此方法的使用者會成為 NFT 的擁有者。
有趣的代幣:
func (t *Controller) Create<Token Name>Token(tokenAsset <Token Class>) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.Save", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Token.Save(&tokenAsset)
    }
非真記號:
func (t *Controller) Create<Token Name>Token(tokenAsset <Token Class>, quantity float64) (interface{}, error) {
         quantityToPass := []float64{quantity}
          return t.Ctx.ERC1155Token.Save(&tokenAsset, quantityToPass...)
    }
參數:
  • tokenAsset: <Token Class> - 記號資產。資產的特性是在模型檔案中定義。
  • quantity: number - 僅適用於非功能變數替代字,用於提示的變數替代字數目。此參數唯一支援的值是 1
傳回值:
  • 成功時,視權杖類型而定,JSON 格式的權杖資產會包含下列資訊。
  • Behaviors - 記號行為清單。無法編輯此特性。
  • CreatedBy - 呼叫者的帳戶 ID,呼叫者的帳戶 ID 是正在修改記號的使用者。無法編輯此特性。
  • CreationDate - 採礦交易的時間戳記。無法編輯此特性。
  • IsBurned - 此特性指示記號是否被燒錄。無法編輯此特性。
  • Mintable - 與轉換相關的特性。max_mint_quantity 值定義可為記號類別建立的記號數目上限。
  • Owner - 目前擁有者的帳戶 ID,亦即方法的呼叫程式。
  • Symbol - 記號的符號。無法編輯此特性。
  • TokenDesc - 記號的描述。
  • TokenMetadata - 描述權杖的 JSON 資訊。
  • TokenName - 記號的名稱。無法編輯此特性。
  • TokenStandard - 記號的標準。無法編輯此特性。
  • TokenType - 記號的類型 (有趣或不可行)。無法編輯此特性。
  • TokenUnit - 記號的單位 (完整或分數)。無法編輯此特性。
  • TokenUri - 記號的 URI。
  • Quantity - 記號的數量。
傳回值範例 (整個 NFT):
{
    "AssetType": "otoken",
    "Behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "CreationDate": "2022-12-29T09:57:03+05:30",
    "IsBurned": false,
    "Mintable": {
        "Max_mint_quantity": 500
    },
    "OnSaleFlag": false,
    "Owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "Price": 100,
    "Quantity": 1,
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "token description",
    "TokenId": "monalisa",
    "TokenMetadata": {
        "Description": "Mona Lisa Painting",
        "Image": "monalisa.jpeg",
        "PainterName": "Leonardo_da_Vinci",
        "PaintingName": "Mona_Lisa"
    },
    "TokenName": "artcollection",
    "TokenStandard": "erc1155+",
    "TokenType": "nonfungible",
    "TokenUnit": "whole",
    "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg"
}
傳回值範例 (Fungible Token):
{
    "AssetType": "otoken",
    "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "Currency_name": "Dollar",
    "Divisible": {
        "Decimal": 2
    },
    "Mintable": {
        "Max_mint_quantity": 10000
    },
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "Token Description",
    "TokenId": "Loyalty",
    "TokenName": "loyalty",
    "TokenStandard": "erc1155+",
    "TokenType": "fungible",
    "TokenUnit": "fractional",
    "Token_to_currency_ratio": 0
}
傳回值範例 (小數 NFT):
{
    "AssetType": "otoken",
    "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "CreationDate": "2023-06-14T09:53:53+05:30",
    "Divisible": {
        "Decimal": 2
    },
    "IsBurned": false,
    "Mintable": {
        "Max_mint_quantity": 20000
    },
    "On_sale_flag": false,
    "Price": 1000,
    "Quantity": 100,
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "Token Description",
    "TokenId": "realEstate",
    "TokenMetadata": {
        "Description": "Painting Description",
        "Image": "",
        "Painter_name": "",
        "Painting_name": "Paint"
    },
    "TokenName": "realestate",
    "TokenStandard": "erc1155+",
    "TokenType": "nonfungible",
    "TokenUnit": "fractional",
    "TokenUri": "www.realestate.example.com"
}
Update<Token Name>Token
此方法會更新記號。每個定義的記號都有自己的更新方法。您無法更新記號中繼資料或不可行記號的記號 URI。對於有趣的權杖,此方法只能由鏈碼的 Token Admin 呼叫。對於不可行的記號,此方法只能由記號擁有者呼叫。
有趣的代幣:
func (t *Controller) Update<%=tokenModelName%>Token(tokenAsset <%=tokenModelName%>) (interface{}, error) {
        auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.Update", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Token.Update(&tokenAsset)
    }
非真記號:
func (t *Controller) Update<%=tokenModelName%>Token(tokenAsset <%=tokenModelName%>) (interface{}, error) {
            return t.Ctx.ERC1155Token.Update(&tokenAsset)
    }
參數:
  • tokenAsset: <Token Class> - 記號資產。資產的特性是在模型檔案中定義。
傳回值:
  • 更新的權杖資產若成功,則為 JSON 格式。
傳回值範例 (整個 NFT):
{
    "AssetType": "otoken",
    "Behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "CreationDate": "2022-12-29T09:57:03+05:30",
    "IsBurned": false,
    "Mintable": {
        "Max_mint_quantity": 500
    },
    "OnSaleFlag": false,
    "Owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "Price": 100,
    "Quantity": 1,
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "token description",
    "TokenId": "monalisa",
    "TokenMetadata": {
        "Description": "Mona Lisa Painting",
        "Image": "monalisa.jpeg",
        "PainterName": "Leonardo_da_Vinci",
        "PaintingName": "Mona_Lisa"
    },
    "TokenName": "artcollection",
    "TokenStandard": "erc1155+",
    "TokenType": "nonfungible",
    "TokenUnit": "whole",
    "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg"
}
GetTokenHistory
此方法會傳回指定記號 ID 的歷史記錄。任何人都可以呼叫此方法。
func (t *Controller) GetTokenHistory(tokenId string) (interface{}, error) {
            return t.Ctx.ERC1155Token.GetTokenHistory(tokenId)
      }
參數:
  • tokenId: string - 記號的 ID。
傳回值:
  • 成功時,包含權杖歷史記錄的 JSON 陣列。
傳回值範例 (Fungible Token):
[
  {
    "IsDelete": "false",
    "Timestamp": "2022-12-08T09:54:11Z",
    "TxId": "823sa7c7a00941c62285c86f922bc4d3f5326a20f4bf2f82daa5bc661e4682e8",
    "Value": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "Rupees",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "Updated Token Description",
      "TokenId": "tokenOne",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  },
  {
    "IsDelete": "false",
    "Timestamp": "2022-12-08T09:54:11Z",
    "TxId": "711bb7c7a00941c62285c86f922bc3b3f5326a20f4bf2f82daa5bc661e4682e8",
    "Value": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "Dollar",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenOne",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  }
]
傳回值範例 (小數 NFT):
[
    {
        "Timestamp": "2023-06-20T01:06:33Z",
        "TrxId": "16e53db4f8107f9634b7c3a0a2a81a00f69b634f2a52902b809e544d07f272b1",
        "Value": {
            "AssetType": "otoken",
            "Behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "CreationDate": "2023-06-20T01:02:27Z",
            "Divisible": {
                "Decimal": 2
            },
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "On_sale_flag": true,
            "Owners": [
                {
                    "AccountId": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
                    "TokenShare": 10
                },
                {
                    "AccountId": "oaccount~3cddfdaa855900579d963aa6f755a4aed1f3a474a2462c1b45bd7f36df673224",
                    "TokenShare": 10
                }
            ],
            "Price": 2000,
            "Quantity": 20,
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "TokenDesc": "",
            "TokenId": "FNFT",
            "TokenMetadata": {
                "Description": "",
                "Image": "",
                "Painter_name": "",
                "Painting_name": ""
            },
            "TokenName": "realestate",
            "TokenStandard": "erc1155+",
            "TokenType": "nonfungible",
            "TokenUnit": "fractional",
            "TokenUri": "www.FNFT.example.com"
        }
    },
    {
        "Timestamp": "2023-06-20T01:02:27Z",
        "TrxId": "cec80910d087682554048f911d2cf98b66382bbcf1615483fa1c96c7ea08077c",
        "Value": {
            "AssetType": "otoken",
            "Behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "CreationDate": "2023-06-20T01:02:27Z",
            "Divisible": {
                "Decimal": 2
            },
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "On_sale_flag": true,
            "Owners": [
                {
                    "AccountId": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
                    "TokenShare": 20
                }
            ],
            "Price": 2000,
            "Quantity": 20,
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "TokenDesc": "",
            "TokenId": "FNFT",
            "TokenMetadata": {
                "Description": "",
                "Image": "",
                "Painter_name": "",
                "Painting_name": ""
            },
            "TokenName": "realestate",
            "TokenStandard": "erc1155+",
            "TokenType": "nonfungible",
            "TokenUnit": "fractional",
            "TokenUri": "www.FNFT.example.com"
        }
    }
]
傳回值範例 (整個 NFT):
[
    {
        "IsDelete": "false",
        "Timestamp": "2023-06-20T01:15:56Z",
        "TxId": "89a3df3ebbe6dca2bcfbd51fc7dca9aab818a2af746b79a92dc8155b729ab22d",
        "Value": {
            "AssetType": "otoken",
            "Behaviors": [
                "indivisible",
                "singleton",
                "mintable",
                "transferable",
                "roles"
            ],
            "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "CreationDate": "2023-06-20T01:15:56Z",
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "On_sale_flag": true,
            "Owner": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "Price": 2000,
            "Quantity": 1,
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "TokenDesc": "Updated Token Description",
            "TokenId": "NFT",
            "TokenMetadata": {
                "Description": "",
                "Image": "",
                "Painter_name": "",
                "Painting_name": ""
            },
            "TokenName": "artcollection",
            "TokenStandard": "erc1155+",
            "TokenType": "nonfungible",
            "TokenUnit": "whole",
            "TokenUri": "www.NFT.example.com"
        }
    },
    {
        "IsDelete": "false",
        "Timestamp": "2023-06-20T01:15:56Z",
        "TxId": "90d6af3ebbe6dca2bcfbd51fc7dca9aab818a2af746b79a92dc8155b729ab22d",
        "Value": {
            "AssetType": "otoken",
            "Behaviors": [
                "indivisible",
                "singleton",
                "mintable",
                "transferable",
                "roles"
            ],
            "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "CreationDate": "2023-06-20T01:15:56Z",
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "On_sale_flag": true,
            "Owner": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "Price": 2000,
            "Quantity": 1,
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "TokenDesc": "",
            "TokenId": "NFT",
            "TokenMetadata": {
                "Description": "",
                "Image": "",
                "Painter_name": "",
                "Painting_name": ""
            },
            "TokenName": "artcollection",
            "TokenStandard": "erc1155+",
            "TokenType": "nonfungible",
            "TokenUnit": "whole",
            "TokenUri": "www.NFT.example.com"
        }
    }
]
GetAllTokens
此方法會傳回儲存在狀態資料庫中的所有記號資產。鏈碼的 Token Admin 只能呼叫此方法。此方法使用 Berkeley DB SQL 豐富查詢,且只能在連線至遠端 Oracle Blockchain Platform 網路時呼叫。
func (t *Controller) GetAllTokens() (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.GetAllTokens", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Token.GetAllTokens()
      }
參數:
傳回值:
  • JSON 格式的所有權杖資產清單。
傳回值範例:
[
  {
    "key": "tokenOne",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenOne",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  },
  {
    "key": "tokenTwo",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenTwo",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  },
  {
    "key": "art",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
      ],
      "BurnedBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "BurnedDate": "2022-12-08T10:49:37Z",
      "CreatedBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "CreationDate": "2022-12-08T10:45:10Z",
      "IsBurned": true,
      "Mintable": {
        "Max_mint_quantity": 20000
      },
      "OnSaleFlag": false,
      "Owner": "",
      "Price": 0,
      "Roles": {
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "art",
      "TokenMetadata": {
        "Description": "",
        "Image": "",
        "PainterName": "",
        "PaintingName": ""
      },
      "TokenName": "artcollection",
      "TokenStandard": "erc1155+",
      "TokenType": "nonfungible",
      "TokenUnit": "whole",
      "TokenUri": "art.example.com",
      "TransferredBy": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc",
      "TransferredDate": "2022-12-08T10:47:04Z"
    }
  },
  {
    "key": "FNFT",
    "valueJson": {
        "AssetType": "otoken",
        "Behaviors": [
            "divisible",
            "mintable",
            "transferable",
            "burnable",
            "roles"
        ],
        "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
        "CreationDate": "2023-06-20T01:02:27Z",
        "Divisible": {
            "Decimal": 2
        },
        "IsBurned": false,
        "Mintable": {
            "Max_mint_quantity": 20000
        },
        "On_sale_flag": true,
        "Price": 2000,
        "Quantity": 20,
        "Roles": {
            "burner_role_name": "burner",
            "minter_role_name": "minter"
        },
        "TokenDesc": "",
        "TokenId": "FNFT",
        "TokenMetadata": {
            "Description": "",
            "Image": "",
            "Painter_name": "",
            "Painting_name": ""
        },
        "TokenName": "realestate",
        "TokenStandard": "erc1155+",
        "TokenType": "nonfungible",
        "TokenUnit": "fractional",
        "TokenUri": "www.FNFT.example.com"
    }
  },
  {
    "key": "FNFT",
    "valueJson": {
        "AssetType": "otoken",
        "Behaviors": [
            "divisible",
            "mintable",
            "transferable",
            "burnable",
            "roles"
        ],
        "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
        "CreationDate": "2023-06-20T01:02:27Z",
        "Divisible": {
            "Decimal": 2
        },
        "IsBurned": false,
        "Mintable": {
            "Max_mint_quantity": 20000
        },
        "On_sale_flag": true,
        "Price": 2000,
        "Quantity": 20,
        "Roles": {
            "burner_role_name": "burner",
            "minter_role_name": "minter"
        },
        "TokenDesc": "",
        "TokenId": "FNFT",
        "TokenMetadata": {
            "Description": "",
            "Image": "",
            "Painter_name": "",
            "Painting_name": ""
        },
        "TokenName": "realestate",
        "TokenStandard": "erc1155+",
        "TokenType": "nonfungible",
        "TokenUnit": "fractional",
        "TokenUri": "www.FNFT.example.com"
    }
  }
]
GetTokenById
如果記號存在於狀態資料庫中,這個方法就會傳回記號物件。對於小數的 NFT,也會傳回擁有者清單。此方法只能由鏈碼的 Token Admin 或記號擁有者呼叫。
func (t *Controller) GetTokenById(tokenId string) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.Get", "TOKEN", map[string]string{"tokenId": tokenId})
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Token.GetTokenById(tokenId)
      }
參數:
  • tokenId string - 要取得之記號的 ID。
傳回值範例 (整個 NFT):
{
  "AssetType": "otoken",
  "Behaviors": [
    "indivisible",
    "singleton",
    "mintable",
    "transferable",
    "burnable",
    "roles"
  ],
  "CreatedBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
  "CreationDate": "2022-12-08T10:55:29Z",
  "IsBurned": false,
  "Mintable": {
    "Max_mint_quantity": 20000
  },
  "OnSaleFlag": false,
  "Owner": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
  "Price": 0,
  "Quantity": 1,
  "Roles": {
    "minter_role_name": "minter"
  },
  "TokenDesc": "",
  "TokenId": "nftToken",
  "TokenMetadata": {
    "Description": "",
    "Image": "",
    "PainterName": "",
    "PaintingName": ""
  },
  "TokenName": "artcollection",
  "TokenStandard": "erc1155+",
  "TokenType": "nonfungible",
  "TokenUnit": "whole",
  "TokenUri": "nftToken.example.com"
}
傳回值範例 (Fungible Token):
{
    "AssetType": "otoken",
    "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "Currency_name": "Dollar",
    "Divisible": {
        "Decimal": 2
    },
    "Mintable": {
        "Max_mint_quantity": 10000
    },
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "Token Description",
    "TokenId": "Loyalty",
    "TokenName": "loyalty",
    "TokenStandard": "erc1155+",
    "TokenType": "fungible",
    "TokenUnit": "fractional",
    "Token_to_currency_ratio": 0
}
傳回值範例 (小數 NFT):
{
    "AssetType": "otoken",
    "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "CreationDate": "2023-06-14T09:53:53+05:30",
    "Divisible": {
        "Decimal": 2
    },
    "IsBurned": false,
    "Mintable": {
        "Max_mint_quantity": 20000
    },
    "On_sale_flag": false,
    "Owners": [
        {
            "AccountId": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "TokenShare": 100
        }
    ],
    "Price": 1000,
    "Quantity": 100,
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "Token Description",
    "TokenId": "realEstate",
    "TokenMetadata": {
        "Description": "Painting Description",
        "Image": "",
        "Painter_name": "",
        "Painting_name": "Paint"
    },
    "TokenName": "realestate",
    "TokenStandard": "erc1155+",
    "TokenType": "nonfungible",
    "TokenUnit": "fractional",
    "TokenUri": "www.realestate.example.com"
}
GetAllTokensByUser
此方法會傳回指定使用者擁有的所有權杖資產。此方法使用 Berkeley DB SQL 豐富查詢,且只能在連線至遠端 Oracle Blockchain Platform 網路時呼叫。此方法只能由鏈碼的 Token Admin 或帳戶擁有者呼叫。
func (t *Controller) GetAllTokensByUser(orgId string, userId string) (interface{}, error) {
            accountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in GetAllTokensByUser. Error: %s", err)
            }
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.GetAllTokensByUser", "TOKEN", map[string]string{"accountId": accountId})
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Token.GetAllTokensByUser(accountId)
      }
參數:
  • orgId string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId string - 使用者的使用者名稱或電子郵件 ID。
傳回值範例:
[
  {
    "key": "tokenOne",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenOne",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  },
  {
    "key": "nftToken",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
      ],
      "CreatedBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "CreationDate": "2022-12-08T10:55:29Z",
      "IsBurned": false,
      "Mintable": {
        "Max_mint_quantity": 20000
      },
      "OnSaleFlag": false,
      "Owner": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "Price": 0,
      "Quantity": 1,
      "Roles": {
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "nftToken",
      "TokenMetadata": {
        "Description": "",
        "Image": "",
        "PainterName": "",
        "PaintingName": ""
      },
      "TokenName": "artcollection",
      "TokenStandard": "erc1155+",
      "TokenType": "nonfungible",
      "TokenUnit": "whole",
      "TokenUri": "example.com"
    }
  }
]
OwnerOf
此方法會傳回指定記號 ID 之擁有者的帳戶 ID、組織 ID 和使用者 ID。任何人都可以呼叫此方法。
func (t *Controller) OwnerOf(tokenId string) (interface{}, error) {
            return t.Ctx.ERC1155Token.OwnerOf(tokenId)
      }
參數:
  • tokenId string - 記號的 ID。
傳回值範例 (整個 NFT):
{
  "AccountId": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
  "OrgId": "appdev",
  "UserId": "idcqa"
}
傳回值範例 (小數 NFT):
[
    {
        "AccountId": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
        "OrgId": "Org1MSP",
        "UserId": "admin"
    },
    {
        "AccountId": "oaccount~74108eca702bab6d8548e740254f2cc7955d886885251d52d065042172a59db0",
        "OrgId": "Org1MSP",
        "UserId": "user"
    }
]
URI
此方法會傳回指定記號的 URI。任何人都可以呼叫此方法。
func (t *Controller) URI(tokenId string) (interface{}, error) {
            return t.Ctx.ERC1155Token.TokenURI(tokenId)
      }
參數:
  • tokenId string - 記號的 ID。
傳回值範例:
{
    "TokenUri": "example.com"
}
Name
此方法會傳回記號類別的名稱。任何人都可以呼叫此方法。
func (t *Controller) Name(tokenId string) (interface{}, error) {
            return t.Ctx.ERC1155Token.Name(tokenId)
      }
參數:
  • tokenId string - 記號的 ID。
傳回值範例:
{"TokenName": "artcollection"}
TotalSupply
此方法會傳回已轉換記號的總數。變數替代字是由變數替代字 ID 指定。記號名稱指定了不可行的記號。鏈碼的 Token Admin 只能呼叫此方法。
func (t *Controller) TotalSupply(tokenDetail erc1155Role.TokenDetail) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.TotalSupply", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            token, err := t.Ctx.ERC1155Token.GetTokenByIdOrName(tokenDetail)
            if err != nil {
                  return nil, err
            }
            return t.Ctx.ERC1155Token.TotalSupply(token)
      }
參數:
  • tokenDetails erc1155Role.TokenDetail - 指定記號的詳細資訊。對於有趣的記號,請使用下列格式:
    {"TokenId":"token1"}
    對於不可行記號,請使用下列格式:
    {"TokenName":"artCollection"}
傳回值範例:
{
    "TotalSupply": 100
}
TotalNetSupply
這個方法會傳回經過 minted 記號減去燒錄記號數目的總數。變數替代字是由變數替代字 ID 指定。記號名稱指定了不可行的記號。鏈碼的 Token Admin 只能呼叫此方法。
func (t *Controller) TotalNetSupply(tokenDetail erc1155Role.TokenDetail) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.TotalNetSupply", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            token, err := t.Ctx.ERC1155Token.GetTokenByIdOrName(tokenDetail)
            if err != nil {
                  return nil, err
            }
            return t.Ctx.ERC1155Token.TotalNetSupply(token)
      }
參數:
  • tokenDetails erc1155Role.TokenDetail - 指定記號的詳細資訊。對於有趣的記號,請使用下列格式:
    {"TokenId":"token1"}
    對於不可行記號,請使用下列格式:
    {"TokenName":"artCollection"}
傳回值範例:
{
   "TotalNetSupply": 900
}
GetTokensByName
此方法會傳回指定記號名稱的所有記號資產。此方法使用 Berkeley DB SQL 豐富查詢,且只能在連線至遠端 Oracle Blockchain Platform 網路時呼叫。鏈碼的 Token Admin 只能呼叫此方法。
func (t *Controller) GetTokensByName(tokenName string) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.GetTokensByName", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Token.GetTokensByName(tokenName)
      }
參數:
  • tokenName: string - 記號的名稱。
傳回值範例:
[
  {
    "key": "tokenOne",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenOne",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  },
  {
    "key": "tokenTwo",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenTwo",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  }
]
GetTokenDecimal
此方法會傳回指定記號的小數位數。鏈碼的 Token Admin 只能呼叫此方法。
func (t *Controller) GetTokenDecimal(tokenId string) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.GetTokenDecimal", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            tokenDecimal, err := t.Ctx.ERC1155Token.GetDecimals(tokenId)
            if err != nil {
                  return nil, fmt.Errorf("error in GetTokenDecimal: %s", err.Error())
            }
            response := make(map[string]interface{})
            response["msg"] = fmt.Sprintf("Token Id: %s has %d decimal places.", tokenId, tokenDecimal)
            return response, nil
      }
參數:
  • tokenId string - 記號的 ID。
傳回值範例:
{
    "msg": "Token Id: tokenOne has 2 decimal places."
}

帳戶管理方法

CreateAccount
此方法會為指定的使用者和關聯的記號帳戶建立好玩或不可行記號的帳戶。必須為任何時候會有權杖的任何使用者建立帳戶。使用者帳戶會追蹤使用者擁有的 NFT 帳戶和有趣的權杖帳戶。使用者必須在網路中擁有帳戶,才能完成權杖相關作業。鏈碼的 Token Admin 只能呼叫此方法。

使用者帳戶具有唯一 ID,由 orgId 參數和 userId 參數的 SHA-256 雜湊組成。

使用者可以有多個具有唯一帳戶 ID 的有趣權杖帳戶。有趣的記號帳戶 ID 是由 orgId 參數的 SHA-256 雜湊、userId 參數、常數字串 ft (以波狀符號 (~) 分隔) 以及計數器編號所組成,代表要以波狀符號 (~) 分隔建立的有趣帳戶索引。

使用者只能有一個不可行的權杖帳戶。不可行的記號帳戶 ID 是唯一的,由 orgId 參數的 SHA-256 雜湊、userId 參數,以及以波狀符號 (~) 分隔的常數字串 nft 組成。使用者擁有的所有非功能變數替代字 (不論全部或小數) 都連結至此帳戶。

使用者帳戶 ID 的開頭為 ouaccount~。記號帳戶 ID 的開頭為 oaccount~

func (t *Controller) CreateAccount(orgId string, userId string, ftAccount bool, nftAccount bool) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.CreateAccount", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Account.CreateAccount(orgId, userId, ftAccount, nftAccount)
      }
參數:
  • orgId string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId string - 使用者的使用者名稱或電子郵件 ID。
  • ftAccount bool - 若為 true,則會建立有趣的權杖帳戶並與使用者帳戶關聯。
  • nftAccount bool - 若為 true,則會建立與使用者帳戶相關聯的不可行記號帳戶。
傳回值:
  • 成功時,所建立帳戶的 JSON 物件。
傳回值範例:
{
  "AssetType": "ouaccount",
  "AccountId": "ouaccount~cf20877546f52687f387e7c91d88b9722c97e1a456cc0484f40c747f7804feae",
  "UserId": "user1",
  "OrgId": "appdev",
  "TotalAccounts": 2,
  "TotalFtAccounts": 1,
  "AssociatedFtAccounts": [
    {
      "AccountId": "oaccount~60bb20c14a83f6e426e1437c479c5891e1c6477dfd7ad18b73acac5d80bc504b",
      "TokenId": ""
    }
  ],
  "AssociatedNftAccount": "oaccount~73c3e835dac6d0a56ca9d8def08269f83cefd59b9d297fe2cdc5a9083828fa58"
}
CreateUserAccount
此方法會為指定的使用者建立帳戶。必須為任何時候會有權杖的任何使用者建立帳戶。使用者帳戶會追蹤使用者擁有的 NFT 帳戶和有趣的權杖帳戶。使用者必須在網路中擁有帳戶,才能完成權杖相關作業。

帳戶 ID 是 orgId 參數和 userId 參數的 SHA-256 雜湊。鏈碼的 Token Admin 只能呼叫此方法。

func (t *Controller) CreateUserAccount(orgId string, userId string) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.CreateUserAccount", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Account.CreateUserAccount(orgId, userId)
      }
參數:
  • orgId string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId string - 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,所建立使用者帳戶的 JSON 物件。
傳回值範例:
{
  "AssetType": "ouaccount",
  "AccountId": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc",
  "UserId": "idcqa",
  "OrgId": "appdev",
  "TotalAccounts": 0,
  "TotalFtAccounts": 0,
  "AssociatedFtAccounts": [],
  "AssociatedNftAccount": ""
}
CreateTokenAccount
此方法會建立有趣或不可行的權杖帳戶,以便與使用者帳戶建立關聯。

使用者可以有多個具有唯一帳戶 ID 的有趣權杖帳戶。有趣的記號帳戶 ID 是由 orgId 參數的 SHA-256 雜湊、userId 參數、常數字串 ft (以波狀符號 (~) 分隔) 以及計數器編號所組成,代表要以波狀符號 (~) 分隔建立的有趣帳戶索引。

使用者只能有一個不可行的權杖帳戶。不可行的記號帳戶 ID 是唯一的,由 orgId 參數的 SHA-256 雜湊、userId 參數,以及以波狀符號 (~) 分隔的常數字串 nft 組成。使用者擁有的所有非功能變數替代字 (不論全部或小數) 都連結至此帳戶。

鏈碼的 Token Admin 只能呼叫此方法。

func (t *Controller) CreateTokenAccount(orgId string, userId string, tokenType erc1155Token.TokenType) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.CreateTokenAccount", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            typeOfToken, err := tokenType.GetTokenType()
          if err != nil {
                  return nil, err
            }
            return t.Ctx.ERC1155Account.CreateTokenAccount(orgId, userId, typeOfToken)
      }
參數:
  • orgId string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId string - 使用者的使用者名稱或電子郵件 ID。
  • tokenType erc1155Token.TokenType - 要建立的記號帳戶類型。唯一支援的權杖類型為 nonfungiblefungible
傳回值:
  • 成功時,所建立權杖帳戶的 JSON 物件。
傳回值範例:
{
    "AssetType": "ouaccount",
    "AccountId": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc",
    "UserId": "idcqa",
    "OrgId": "appdev",
    "TotalAccounts": 1,
    "TotalFtAccounts": 1,
    "AssociatedFtAccounts": [
        {
            "AccountId": "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
            "TokenId": ""
        }
    ],
    "AssociatedNftAccount": ""
}
AssociateFungibleTokenAccount
此方法會建立使用者有趣的權杖帳戶與特定有趣的權杖的關聯。

鏈碼的 Token Admin 只能呼叫此方法。

func (t *Controller) AssociateFungibleTokenToAccount(orgId string, userId string, tokenId string) (interface{}, error) {
            accountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in generating accountId. Error: %s", err)
            }
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.AssociateFungibleTokenToAccount", "TOKEN", map[string]string{"accountId": accountId})
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Account.AssociateTokenToToken(accountId, tokenId)
      }
參數:
  • orgId string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId string - 使用者的使用者名稱或電子郵件 ID。
  • tokenId string - 記號的 ID。
傳回值:
  • 成功時,使用者帳戶的 JSON 物件會顯示有趣的權杖與權杖帳戶關聯。例如,在下列範例中,associatedFtAccounts 陣列中的第一個物件會顯示有趣的記號帳戶 ID 和記號 ID 相關聯。
傳回值範例:
{
    "AssetType": "ouaccount",
    "AccountId": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc",
    "UserId": "idcqa",
    "OrgId": "appdev",
    "TotalAccounts": 1,
    "TotalFtAccounts": 1,
    "AssociatedFtAccounts": [
        {
            "AccountId": "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
            "TokenId": "tokenOne"
        }
    ],
    "AssociatedNftAccount": ""
}
GetAccountHistory
此方法會傳回指定記號帳戶的歷史記錄。這是非同步方法。此方法只能由鏈碼的 Token Admin 或帳戶擁有者呼叫。
func (t *Controller) GetAccountHistory(orgId string, userId string, tokenId ...string) (interface{}, error) {
            userAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in GetAccountHistory. Error: %s", err)
            }
            _, err = t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.History", "TOKEN", map[string]string{"accountId": userAccountId})
            if err != nil {
                  return nil, fmt.Errorf("error in GetAccountHistory. Error: %s", err)
            }
            tokenAccount, err := t.Ctx.ERC1155Account.Get(userAccountId, tokenId...)
            if err != nil {
                  return nil, fmt.Errorf("error in GetAccountHistory. Error: %s", err)
            }
            tokenAccountId, err := util.GetAccountProperty(tokenAccount, constants.AccountId)
            if err != nil {
                  return nil, fmt.Errorf("error in GetAccountHistory. Error: %s", err)
            }
            return t.Ctx.ERC1155Account.GetAccountHistory(tokenAccountId)
      }
參數:
  • orgId string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId string - 使用者的使用者名稱或電子郵件 ID。
  • tokenId ...string - 若為非工具權杖帳戶,則為空白字串。如果是有趣的權杖帳戶,則是權杖 ID。
傳回值:
  • 成功時,描述帳戶歷史記錄的 JSON 物件陣列。
傳回值範例:
[
    {
        "IsDelete": "false",
        "Timestamp": "2023-06-06T11:03:48Z",
        "TxId": "c5180f3be3d9130f25a4b4e866f38a4283117dcbfbffb4f55e2c5b03dba0dd29",
        "Value": {
            "AccountCategory": "",
            "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
            "AssetType": "oaccount",
            "Balance": 100,
            "BapAccountVersion": 1
            "OrgId": "appdev",
            "TokenId": "loy1",
            "TokenName": "loyalty",
            "TokenType": "fungible",
            "UserId": "idcqa"
        }
    },
    {
        "IsDelete": "false",
        "Timestamp": "2023-06-06T11:02:39Z",
        "TxId": "6f81b0c94b451d375a3892446aefbdf78d9fd1ac43699daa89f0dff10db5fd22",
        "Value": {
            "AccountCategory": "",
            "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
            "AssetType": "oaccount",
            "Balance": 0,
            "BapAccountVersion": 0
            "OrgId": "appdev",
            "TokenId": "loy1",
            "TokenName": "loyalty",
            "TokenType": "fungible",
            "UserId": "idcqa"
        }
    },
    {
        "IsDelete": "false",
        "Timestamp": "2023-06-05T16:28:46Z",
        "TxId": "8185af648546e909488e72149be497b210f74f95ada252c42da9c35cb9d98691",
        "Value": {
            "AccountCategory": "",
            "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
            "AssetType": "oaccount",
            "Balance": 0,
            "BapAccountVersion": 0
            "OrgId": "appdev",
            "TokenId": "",
            "TokenName": "",
            "TokenType": "fungible",
            "UserId": "idcqa"
        }
    }
]
GetAccount
此方法會傳回指定之使用者的權杖帳戶詳細資訊。此方法只能由鏈碼的 Token Admin 或帳戶的 Account Owner 呼叫。
func (t *Controller) GetAccount(orgId string, userId string, tokenId ...string) (interface{}, error) {
            accountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, err
            }
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.GetAccount", "TOKEN", map[string]string{"accountId": accountId})
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Account.GetAccountWithStatus(accountId, tokenId...)
      }
參數:
  • orgId string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId string - 使用者的使用者名稱或電子郵件 ID。
  • tokenId ...string - 若為非工具權杖帳戶,則為空白字串。如果是有趣的權杖帳戶,則是權杖 ID。
傳回值:
  • 成功時,包含權杖帳戶詳細資訊的 JSON 物件。BapAccountVersionAccountCategory 參數定義於帳戶物件中供內部使用。
傳回值範例 (不可行權杖帳戶):
{
  "AccountId": "oaccount~cc301bee057f14236a97d434909ec1084970921b008f6baab09c2a0f5f419a9a",
  "AssetType": "oaccount",
  "BapAccountVersion": 1,
  "NoOfNfts": 1,
  "OrgId": "appdev",
  "Status": "active",
  "TokenType": "nonfungible",
  "UserId": "idcqa"
}
傳回值範例 (Fungible Token 帳戶):
{
  "AccountCategory": "",
  "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
  "AssetType": "oaccount",
  "Balance": 0,
  "BapAccountVersion": 0,
  "OrgId": "appdev",
  "Status": "active",
  "TokenId": "t1",
  "TokenName": "loyalty",
  "TokenType": "fungible",
  "UserId": "idcqa"
}
GetAllAccounts
此方法會傳回所有使用者帳戶的詳細資訊。鏈碼的 Token Admin 只能呼叫此方法。
func (t *Controller) GetAllAccounts() (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.GetAllAccounts", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Account.GetAllAccounts()
      }
參數:
傳回值:
  • 成功時,所有帳戶的 JSON 陣列。
傳回值範例:
[
    {
        "AssetType": "ouaccount",
        "AccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
        "UserId": "idcqa",
        "OrgId": "appdev",
        "TotalAccounts": 3,
        "TotalFtAccounts": 2,
        "AssociatedFtAccounts": [
            {
                "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
                "TokenId": "loy1"
            },
            {
                "AccountId": "oaccount~58c5a6b09a41befca2a9ea2550439838c4dcf4d8a2a4f7c98e9319cf8479bfc4",
                "TokenId": ""
            }
        ],
        "AssociatedNftAccount": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371"
    },
    {
        "AssetType": "ouaccount",
        "AccountId": "ouaccount~9501bb774c156eb8354dfe489250ea91f757523d70f08ee494bda98bb352003b",
        "UserId": "user1_minter",
        "OrgId": "appdev",
        "TotalAccounts": 2,
        "TotalFtAccounts": 1,
        "AssociatedFtAccounts": [
            {
                "AccountId": "oaccount~1089ee5122f367ee0ca38c6660298f4b81f199627e4f67f3691c0f628237974c",
                "TokenId": "loy1"
            }
        ],
        "AssociatedNftAccount": "oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446"
    },
]
GetAccountDetailsByUser
此方法會傳回指定之使用者的帳戶摘要,以及與使用者關聯之有趣和不可漏洞記號的詳細資訊。此方法只能由鏈碼的 Token Admin 或帳戶的 Account Owner 呼叫。
func (t *Controller) GetAccountDetailsByUser(orgId string, userId string) (interface{}, error) {
            accountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, err
            }
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.GetAccountDetailsByUser", "TOKEN", map[string]string{"accountId": accountId})
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Account.GetAccountDetailsByUser(orgId, userId)
      }
參數:
  • orgId string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId string - 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,包含指定使用者的 JSON 帳戶物件和帳戶摘要,以及與使用者相關聯之有趣和不有趣記號的詳細資訊。對於小數的不可行記號,AssociatedNFTs 區段中的 TokenShare 特性會顯示使用者擁有的共用。
傳回值範例:
{
    "AssociatedFTAccounts": [
        {
            "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
            "Balance": 90,
          "TokenId": "FT"
        },
    ],
    "AssociatedNFTAccount": {
        "AccountId": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "AssociatedNFTs": [
            {
              "NFTTokenId": "FNFT",
                "TokenShare": 230
            },
            {
              "NFTTokenId": "NFT"
            },
            {
              "NFTTokenId": "NFT2"
            }
        ]
    },
    "UserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38"
}
GetUserByAccountId
此方法會傳回指定帳戶 ID 的使用者詳細資料。任何使用者都可以呼叫這個方法。
func (t *Controller) GetUserByAccountId(accountId string) (interface{}, error) {
            return t.Ctx.ERC1155Account.GetUserByAccountById(accountId)
      }
參數:
  • accountId string - 帳戶的 ID。
傳回值:
  • 成功時,使用者詳細資訊 (orgIduserId) 的 JSON 物件。
傳回值範例:
{
    "OrgId": "appdev",
    "UserId": "user2"
}

角色管理方法

AddRole
這個方法會將角色新增至指定的使用者和記號。鏈碼的 Token Admin 只能呼叫此方法。變數替代字是由變數替代字 ID 指定。記號名稱指定了不可行的記號。指定的使用者必須要有一個與有趣的權杖關聯的權杖帳戶,或 NFT 角色的不可行權杖帳戶。指定的角色必須存在於變數替代字的規格檔案中。
func (t *Controller) AddRole(orgId string, userId string, role string, tokenDetail erc1155Role.TokenDetail) (interface{}, error) {
            userAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, err
            }
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.AddRoleMember", "TOKEN", map[string]string{"accountId": userAccountId})
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            token, err := t.Ctx.ERC1155Token.GetTokenByIdOrName(tokenDetail)
            if err != nil {
                  return nil, err
            }
            return t.Ctx.ERC1155Token.AddRoleMember(role, userAccountId, token)
      }
參數:
  • orgId string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId string - 使用者的使用者名稱或電子郵件 ID。
  • role: string - 要新增至指定使用者的角色名稱。
  • tokenDetails erc1155Role.TokenDetail - 指定記號的詳細資訊。對於有趣的記號,請使用下列格式:
    {"TokenId":"token1"}
    對於不可行記號,請使用下列格式:
    {"TokenName":"artCollection"}
傳回值:
  • 成功時,會出現含有帳戶詳細資訊的訊息。
傳回值範例:
{
    "msg": "Successfully added role minter to oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a (orgId : appdev, userId : idcqa)"
}
IsInRole
此方法會傳回布林值,指示使用者是否具有指定的角色。變數替代字是由變數替代字 ID 指定。記號名稱指定了不可行的記號。此方法只能由鏈碼的 Token Admin 或帳戶的 Account Owner 呼叫。指定的使用者必須要有一個與有趣的權杖關聯的權杖帳戶,或 NFT 角色的不可行權杖帳戶。指定的角色必須存在於變數替代字的規格檔案中。
func (t *Controller) IsInRole(orgId string, userId string, role string, tokenDetail erc1155Role.TokenDetail) (interface{}, error) {
            userAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, err
            }
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.IsInRole", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            token, err := t.Ctx.ERC1155Token.GetTokenByIdOrName(tokenDetail)
            if err != nil {
                  return nil, err
            }
            var result bool
            result, err = t.Ctx.ERC1155Token.IsInRole(role, userAccountId, token)
            if err != nil {
                  return nil, fmt.Errorf("error in IsInRole %s", err.Error())
            }
            response := make(map[string]interface{})
            response["result"] = result
            return response, nil
      }
參數:
  • orgId string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId string - 使用者的使用者名稱或電子郵件 ID。
  • role: string - 要搜尋的角色名稱。
  • tokenDetails erc1155Role.TokenDetail - 指定記號的詳細資訊。對於有趣的記號,請使用下列格式:
    {"TokenId":"token1"}
    對於不可行記號,請使用下列格式:
    {"TokenName":"artCollection"}
傳回值範例:
{
    "result": true
}
RemoveRole
此方法會從指定的使用者和記號移除角色。變數替代字是由變數替代字 ID 指定。記號名稱指定了不可行的記號。鏈碼的 Token Admin 只能呼叫此方法。指定的使用者必須要有一個與有趣的權杖關聯的權杖帳戶,或 NFT 角色的不可行權杖帳戶。指定的角色必須存在於變數替代字的規格檔案中。
func (t *Controller) RemoveRole(orgId string, userId string, role string, tokenDetail erc1155Role.TokenDetail) (interface{}, error) {
            userAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, err
            }
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.RemoveRoleMember", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            token, err := t.Ctx.ERC1155Token.GetTokenByIdOrName(tokenDetail)
            if err != nil {
                  return nil, err
            }
            return t.Ctx.ERC1155Token.RemoveRoleMember(role, userAccountId, token)
      }
參數:
  • orgId string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId string - 使用者的使用者名稱或電子郵件 ID。
  • role: string - 要從指定使用者移除的角色名稱。
  • tokenDetails erc1155Role.TokenDetail - 指定記號的詳細資訊。對於有趣的記號,請使用下列格式:
    {"TokenId":"token1"}
    對於不可行記號,請使用下列格式:
    {"TokenName":"artCollection"}
傳回值範例:
{
    "msg": "Successfully removed role 'minter' from Account Id: oaccount~ec7e4de2f81e3ea071710e07b6ff7d9346e84ef665ca4650885dbe8c3e2bd4c0 (Org-Id: appdev, User-Id: idcqa)"
}
GetAccountsByRole
此方法會傳回指定角色和權杖的所有帳戶 ID 清單。變數替代字是由變數替代字 ID 指定。記號名稱指定了不可行的記號。鏈碼的 Token Admin 只能呼叫此方法。
func (t *Controller) GetAccountsByRole(role string, tokenDetail erc1155Role.TokenDetail) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Role.GetAccountsByRole", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            token, err := t.Ctx.ERC1155Token.GetTokenByIdOrName(tokenDetail)
            if err != nil {
                  return nil, err
            }
            return t.Ctx.ERC1155Role.GetAccountsByRole(role, token)
      }
參數:
  • role: string - 要搜尋的角色名稱。
  • tokenDetails erc1155Role.TokenDetail - 指定記號的詳細資訊。對於有趣的記號,請使用下列格式:
    {"TokenId":"token1"}
    對於不可行記號,請使用下列格式:
    {"TokenName":"artCollection"}
傳回值範例:
{
    "accounts": [
        "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
        "oaccount~60bb20c14a83f6e426e1437c479c5891e1c6477dfd7ad18b73acac5d80bc504b"
    ]
}
GetUsersByRole
此方法會針對指定的角色和記號,傳回所有使用者的清單。變數替代字是由變數替代字 ID 指定。記號名稱指定了不可行的記號。鏈碼的 Token Admin 只能呼叫此方法。
func (t *Controller) GetUsersByRole(role string, tokenDetail erc1155Role.TokenDetail) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Role.GetUsersByRole", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            token, err := t.Ctx.ERC1155Token.GetTokenByIdOrName(tokenDetail)
            if err != nil {
                  return nil, err
            }
            return t.Ctx.ERC1155Role.GetUsersByRole(role, token)
      }
參數:
  • role: string - 要搜尋的角色名稱。
  • tokenDetails erc1155Role.TokenDetail - 指定記號的詳細資訊。對於有趣的記號,請使用下列格式:
    {"TokenId":"token1"}
    對於不可行記號,請使用下列格式:
    {"TokenName":"artCollection"}
傳回值範例:
{
    "Users": [
        {
            "AccountId": "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
            "OrgId": "appdev",
            "UserId": "idcqa"
        },
        {
            "AccountId": "oaccount~60bb20c14a83f6e426e1437c479c5891e1c6477dfd7ad18b73acac5d80bc504b",
            "OrgId": "appdev",
            "UserId": "user1"
        }
    ]
}

交易歷史記錄管理的方法

GetAccountTransactionHistory
此方式會傳回科目交易歷史記錄。此方法只能由鏈碼的 Token Admin 或帳戶擁有者呼叫。對於非功能權杖,只有在連線至遠端 Oracle Blockchain Platform 網路時才能呼叫此方法。
func (t *Controller) GetAccountTransactionHistory(orgId string, userId string, tokenId ...string) (interface{}, error) {
            userAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in GetAccountTransactionHistory. Error: %s", err)
            }
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.GetAccountTransactionHistory", "TOKEN", map[string]string{"accountId": userAccountId})
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            tokenAccount, err := t.Ctx.ERC1155Account.Get(userAccountId, tokenId...)
            if err != nil {
                  return nil, fmt.Errorf("error in GetAccountTransactionHistory. Error: %s", err)
            }
            tokenAccountId, err := util.GetAccountProperty(tokenAccount, constants.AccountId)
            if err != nil {
                  return nil, fmt.Errorf("error in GetAccountTransactionHistory. Error: %s", err)
            }
            return t.Ctx.ERC1155Account.GetAccountTransactionHistory(tokenAccountId)
      }
參數:
  • orgId string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId string - 使用者的使用者名稱或電子郵件 ID。
  • tokenId ...string - 若為非工具權杖帳戶,則為空白字串。如果是有趣的權杖帳戶,則是權杖 ID。
傳回值範例:
[
    {
        "Balance": 90,
        "Timestamp": "2023-06-06T11:11:09Z",
        "TokenId": "FNFT",
        "TransactedAccount": "oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446",
        "TransactedAmount": 10,
        "TransactionId": "otransaction~0f4d96fbf8fed88ea8a3133428977721091467c701848d595ebc3fffa88b3657~7c88c736df38d5622512f1e8dcdd50710eb47c953f1ecb24ac44790a9e2f475b",
        "TransactionType": "DEBIT",
        "TriggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38"
    },
    {
        "Timestamp": "2023-06-06T11:11:09Z",
        "TokenId": "NFT",
        "TransactedAccount": "oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446",
        "TransactionId": "otransaction~0f4d96fbf8fed88ea8a3133428977721091467c701848d595ebc3fffa88b3657~178e3730bc5bee50d02f1464a4eebf733a051905f651e5789039adb4a3edc114",
        "TransactionType": "DEBIT",
        "TriggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38"
    },
    {
        "Timestamp": "2023-06-06T11:06:54Z",
        "TokenId": "NFT",
        "TransactedAccount": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "TransactionId": "otransaction~6a13667ea3f6edc4c854e85b127526eccb58783f653c348b42a3869f0f29a4fb~a7cefb22ff39ee7e36967be71de27da6798548c872061a62dabc56d88d50b930",
        "TransactionType": "MINT",
        "TriggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38"
    },
    {
        "Balance": 100,
        "Timestamp": "2023-06-05T16:34:33Z",
        "TokenId": "FNFT",
        "TransactedAccount": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "TransactedAmount": 100,
        "TransactionId": "otransaction~2bc15de1766d582d821bd8d61756bca02837dc683c0aa61f69657ccd1d95e335~e4eb15d9354f694230df8835ade012100d82aa43672896a2c7125a86e3048f9f",
        "TransactionType": "MINT",
        "TriggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38"
    }
]
GetTransactionById
此方法會傳回指定交易 ID 的交易詳細資料。任何人都可以呼叫此方法。
func (t *Controller) GetTransactionById(transactionId string) (interface{}, error) {
            return t.Ctx.ERC1155Transaction.GetTransactionById(transactionId)
      }
參數:
  • transactionId: string - 交易的 ID。
傳回值範例:
{
    "history": [
        {
            "IsDelete": "false",
            "Timestamp": "2022-12-08T10:45:56Z",
            "TxId": "2da02a53aa1032602df6c68c5628a4ab8b22ba107c0201520ce495948901aa98",
            "Value": {
                "Amount": 5,
                "AssetType": "otransaction",
                "FromAccountId": "oaccount~60bb20c14a83f6e426e1437c479c5891e1c6477dfd7ad18b73acac5d80bc504b",
                "Timestamp": "2022-12-08T10:45:56Z",
                "ToAccountId": "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
                "TokenId": "tokenOne",
                "TransactionId": "otransaction~2da02a53aa1032602df6c68c5628a4ab8b22ba107c0201520ce495948901aa98~9c3ce5f21abd98ca018c196086d73a812f2f49dba323f1de4f6867eecfeec8ff",
                "TransactionType": "TRANSFER",
                "TriggeredByUserAccountId": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc"
            }
        }
    ],
    "transactionId": "otransaction~2da02a53aa1032602df6c68c5628a4ab8b22ba107c0201520ce495948901aa98~9c3ce5f21abd98ca018c196086d73a812f2f49dba323f1de4f6867eecfeec8ff"
}
DeleteHistoricalTransactions
此方法會從狀態資料庫刪除指定時戳之前的交易。鏈碼的 Token Admin 只能呼叫此方法。
func (t *Controller) DeleteHistoricalTransactions(timestamp string) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Transaction.DeleteHistoricalTransactions", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Transaction.DeleteHistoricalTransactions(timestamp)
      }
參數:
  • timestamp: string - 將會刪除此時戳之前的所有交易。
傳回值範例:
{
    "Transactions": [
        "otransaction~750f68538451847f57948f7d5261dcb81570cd9e429f928a4cb7bfa76392ecf7"
    ],
    "msg": "Successfuly deleted transaction older than date:2022-04-06T08:17:53Z"
}

記號行為管理方法 - 可調整行為

MintBatch
此方法會在批次作業中建立 (提示) 多重記號。此方法只會建立有趣的記號或小數的不可行記號。

對於有趣的記號,如果在規格檔案中定義了較小的角色,則具有較小角色的任何使用者都可以呼叫此方法。如果不是,任何使用者都可以使用此方法來提示記號。如果在建立或更新記號時指定了該特性,您就不能超過記號的 max_mint_quantity 特性。

對於非功能變數替代字,如果在規格檔案中定義了 minter 角色,則具有 minter 角色的任何使用者都可以呼叫此方法。如果不是,任何使用者都可以使用此方法來提示記號。此外,呼叫者也必須是記號的建立者。沒有可被調解之小數不可行記號的數量上限。

您無法使用此方法來輸入整個不可行記號。

func (t *Controller) MintBatch(orgId string, userId string, tokenIds []string, quantity []float64) (interface{}, error) {
            accountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in generating the accountId. Error: %s", err)
            }
            var tokens []interface{}
            for _, tokenId := range tokenIds {
                  tokenAssetValue, err := t.getTokenObject(tokenId)
                  if err != nil {
                        return nil, err
                  }
                  tokens = append(tokens, tokenAssetValue.Interface())
            }
            return t.Ctx.ERC1155Token.MintBatch(accountId, tokens, quantity)
      }
參數:
  • orgId string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId string - 使用者的使用者名稱或電子郵件 ID。
  • tokenIds []string - 用於提示記號的記號 ID 清單。
  • quantity []float64 - 對應至權杖 ID 陣列的權杖數量清單。
傳回值:
  • 成功時,包含所提示記號詳細資訊的 JSON 物件。
傳回值範例:
{
    "details": [
        {
            "msg": "Successfully minted 100 tokens of fractional tokenId: plot55 to Org-Id: appdev, User-Id: idcqa"
        },
        {
            "msg": "Successfully minted 100 tokens of tokenId: 'loyalty' to Token-Account-Id 'oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e'"
        }
    ],
    "msg": "Successfully minted batch of tokens for User-Account-Id 'ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38' (Org-Id: 'appdev', User-Id: 'idcqa')"
}

記號行為管理方法 - 可傳輸行為

BatchTransferFrom
此方法會完成批次作業,將記號 ID 清單中指定的記號從某個使用者傳輸給另一個使用者。

對於 NFT,因為方法會傳輸 NFT 的所有權,NFT 的寄件者必須擁有該記號。

對於分數 NFT,如果使用者 (包括記號的建立者) 傳輸他們擁有的所有共用,則會失去記號的所有權。如果將記號的任何共用轉移給使用者,則該使用者會自動成為分數 NFT 的其中一個擁有者。

這個方法不會驗證方法的呼叫程式是指定的寄件者。任何使用者都可以呼叫這個方法。

func (t *Controller) BatchTransferFrom(fromOrgId string, fromUserId string, toOrgId string, toUserId string, tokenIds []string, quantity []float64) (interface{}, error) {
            fromAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(fromOrgId, fromUserId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in BatachTransferFrom. Error: %s", err)
            }
            toAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(toOrgId, toUserId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in BatachTransferFrom. Error: %s", err)
            }
            var tokens []interface{}
            for _, tokenId := range tokenIds {
                  tokenAssetValue, err := t.getTokenObject(tokenId)
                  if err != nil {
                        return nil, err
                  }
                  tokens = append(tokens, tokenAssetValue.Interface())
            }
            return t.Ctx.ERC1155Token.BatchTransferFrom(fromAccountId, toAccountId, tokens, quantity)
      }
參數:
  • fromOrgId string - 目前組織中寄件者與記號擁有者的成員服務提供者 (MSP) ID。
  • fromUserId string - 寄件者與記號擁有者的使用者名稱或電子郵件 ID。
  • toOrgId string - 目前組織中接收者的成員服務提供者 (MSP) ID。
  • toUserId string - 接收者的使用者名稱或電子郵件 ID。
  • tokenIds string[] - 要傳輸之記號的記號 ID 清單。
  • quantity float64[] - 與記號 ID 陣列對應的記號數量清單。
傳回值:
  • 成功時,每個權杖傳輸都有詳細資訊的訊息。
傳回值範例:
[
    {
        "msg": "Successfully transferred NFT token: 'FNFT' of '10' quantity from Account-Id: oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371 (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446 (Org-Id: appdev, User-Id: user1_minter)"
    },
    {
        "msg": "Successfully transferred 10 FT token: 'FT' from Account-Id: oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~1089ee5122f367ee0ca38c6660298f4b81f199627e4f67f3691c0f628237974c (Org-Id: appdev, User-Id: user1_minter)"
    },
    {
        "msg": "Successfully transferred NFT token: 'NFT' from Account-Id: oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371 (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446 (Org-Id: appdev, User-Id: user1_minter)"
    }
]
SafeBatchTransferFrom
此方法會完成批次作業,將記號 ID 清單中指定的記號從某個使用者傳輸給另一個使用者。

對於 NFT,因為方法會傳輸 NFT 的所有權,NFT 的寄件者必須擁有該記號。

對於分數 NFT,如果使用者 (包括記號的建立者) 傳輸他們擁有的所有共用,則會失去記號的所有權。如果將記號的任何共用轉移給使用者,則該使用者會自動成為分數 NFT 的其中一個擁有者。

方法的呼叫程式必須是指定的寄件者。任何使用者都可以呼叫這個方法。

func (t *Controller) SafeBatchTransferFrom(fromOrgId string, fromUserId string, toOrgId string, toUserId string, tokenIds []string, quantity []float64) (interface{}, error) {
            fromAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(fromOrgId, fromUserId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in BatachTransferFrom. Error: %s", err)
            }
            toAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(toOrgId, toUserId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in BatachTransferFrom. Error: %s", err)
            }
            var tokens []interface{}
            for _, tokenId := range tokenIds {
                  tokenAssetValue, err := t.getTokenObject(tokenId)
                  if err != nil {
                        return nil, err
                  }
                  tokens = append(tokens, tokenAssetValue.Interface())
            }
            return t.Ctx.ERC1155Token.SafeBatchTransferFrom(fromAccountId, toAccountId, tokens, quantity)
      }
參數:
  • fromOrgId string - 目前組織中寄件者與記號擁有者的成員服務提供者 (MSP) ID。
  • fromUserId string - 寄件者與記號擁有者的使用者名稱或電子郵件 ID。
  • toOrgId string - 目前組織中接收者的成員服務提供者 (MSP) ID。
  • toUserId string - 接收者的使用者名稱或電子郵件 ID。
  • tokenIds string[] - 要傳輸之記號的記號 ID 清單。
  • quantity float64[] - 與記號 ID 陣列對應的記號數量清單。
傳回值:
  • 成功時,每個權杖傳輸都有詳細資訊的訊息。
傳回值範例:
[
    {
        "msg": "Successfully transferred NFT token: 'FNFT' of '10' quantity from Account-Id: oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371 (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446 (Org-Id: appdev, User-Id: user1_minter)"
    },
    {
        "msg": "Successfully transferred 10 FT token: 'FT' from Account-Id: oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~1089ee5122f367ee0ca38c6660298f4b81f199627e4f67f3691c0f628237974c (Org-Id: appdev, User-Id: user1_minter)"
    },
    {
        "msg": "Successfully transferred NFT token: 'NFT' from Account-Id: oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371 (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446 (Org-Id: appdev, User-Id: user1_minter)"
    }
]
BalanceOfBatch
此方法會完成取得變數替代字帳戶餘額的批次作業。帳戶詳細資料是以三個不同的組織 ID、使用者 ID 和憑證 ID 清單來指定。此方法只能由鏈碼的 Token Admin 或帳戶擁有者呼叫。帳戶擁有者只能查看他們擁有之帳戶的餘額明細。
func (t *Controller) BalanceOfBatch(orgIds []string, userIds []string, tokenIds []string) (interface{}, error) {
            callerAccountCheck := false
            _, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.BalanceOfBatch", "TOKEN")
            if err != nil {
                  callerAccountCheck = true
            }
            accountIds, err := t.Ctx.ERC1155Account.GenerateAccountIds(orgIds, userIds, callerAccountCheck)
            if err != nil {
                  return nil, fmt.Errorf("error in BalanceOfBatch. Error: %s", err)
            }
            var tokens []interface{}
            for _, tokenId := range tokenIds {
                  tokenAssetValue, err := t.getTokenObject(tokenId)
                  if err != nil {
                        tokens = append(tokens, map[string]interface{}{"TokenId": tokenId})
                  } else {
                        tokens = append(tokens, tokenAssetValue.Interface())
                  }
            }
            return t.Ctx.ERC1155Account.BalanceOfBatch(accountIds, tokens)
      }
參數:
  • orgIds []string - 目前組織中的成員服務提供者 (MSP) ID 清單。
  • userIds []string - 使用者名稱或電子郵件 ID 的清單。
  • tokenIds []string - 記號 ID 的清單。
傳回值範例:

在下列範例中,記號 ID FNFT 代表分數非函數記號,而記號 ID FT 代表一個有趣的記號。

[
    {
        "OrgId": "appdev",
        "UserId": "idcqa",
        "UserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
        "TokenAccountId": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "TokenId": "FNFT",
        "Balance": 100
    },
    {
        "OrgId": "appdev",
        "UserId": "idcqa",
        "UserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
        "TokenAccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
        "TokenId": "FT",
        "Balance": 50
    },
    {
        "OrgId": "appdev",
        "UserId": "user1_minter",
        "UserAccountId": "ouaccount~9501bb774c156eb8354dfe489250ea91f757523d70f08ee494bda98bb352003b",
        "TokenAccountId": "oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446",
        "TokenId": "FNFT",
        "Balance": 10
    }
]
ExchangeToken
此方法會在指定的帳戶之間交換記號。此方法僅支援在 NFT 與有趣的記號或有趣的記號與 NFT 之間交換。只有帳戶擁有者才能呼叫此方法。
func (t *Controller) ExchangeToken(fromTokenId string, fromOrgId string, fromUserId string, fromTokenQuantity float64, toTokenId string, toOrgId string, toUserId string, toTokenQuantity float64) (interface{}, error) {
            fromUserAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(fromOrgId, fromUserId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in BatachTransferFrom. Error: %s", err)
            }
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.ExchangeToken", "TOKEN", map[string]string{"accountId": fromUserAccountId})
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            toUserAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(toOrgId, toUserId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in BatachTransferFrom. Error: %s", err)
            }
            return t.Ctx.ERC1155Token.ExchangeToken(fromTokenId, fromUserAccountId, fromTokenQuantity, toTokenId, toUserAccountId, toTokenQuantity)
      }
參數:
  • fromTokenId string - 寄件者擁有之記號的 ID。
  • fromOrgId string - 目前組織中寄件者的成員身分服務提供者 (MSP) ID。
  • fromUserId string - 寄件者的使用者名稱或電子郵件 ID。
  • fromTokenQuantity float64 - 寄件者與收件者交換的記號數量。
  • toTokenId string - 接收者擁有之記號的 ID。
  • toOrgId string - 目前組織中接收者的成員服務提供者 (MSP) ID。
  • toUserId string - 接收者的使用者名稱或電子郵件 ID。
  • toTokenQuantity float64 - 接收者要與寄件者交換的記號數量。
傳回值:
  • 成功時,含有權杖交換詳細資訊的訊息。
傳回值範例:
{
    "msg": "Succesfully exchanged 10 tokens of type 'nonfungible' with tokenId: [r1] from Account 'oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371' (OrgId: appdev, UserId: idcqa) to 10 tokens of type 'fungible' with tokenId: [loy1] from Account 'oaccount~1089ee5122f367ee0ca38c6660298f4b81f199627e4f67f3691c0f628237974c' (OrgId: 'appdev', UserId: 'user1_minter')"
}

記號行為管理方法 - 可燒錄行為

BurnBatch
此方法會停用或燒錄指定的有趣和不可行記號。任何使用者都可以呼叫此方法。
func (t *Controller) BurnBatch(orgId string, userId string, tokenIds []string, quantity []float64) (interface{}, error) {
            accountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in BatachTransferFrom. Error: %s", err)
            }
            var tokens []interface{}
            for _, tokenId := range tokenIds {
                  tokenAssetValue, err := t.getTokenObject(tokenId)
                  if err != nil {
                        return nil, err
                  }
                  tokens = append(tokens, tokenAssetValue.Interface())
            }
            return t.Ctx.ERC1155Token.Burn(accountId, tokens, quantity)
      }
參數:
  • orgId string - 目前組織中的成員服務提供者 (MSP) ID。
  • userId string - 使用者名稱或電子郵件 ID。
  • tokenIds []string - 要燒錄的記號 ID 清單
  • quantity []float64 - 要燒錄的記號數量清單,對應於記號 ID 陣列。
傳回值:
  • 成功時,會出現一則訊息,內含有關耗盡作業的詳細資料。
傳回值範例:
[
    {
        "msg": "Successfully burned NFT token: 'art' from Account-Id: oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6 (Org-Id: appdev, User-Id: idcqa)"
    },
    {
        "msg": "Successfully burned 2 tokens of tokenId: FT from Account-ID oaccount~9a940587fd322ccc8400233244cd3b13f3aa2a52e418e4c71fb819a2217bc49e (Org-Id: AutoF1377358917, User-Id: idcqa)"
    },
    {
        "msg": "Successfully burned 2 token share of tokenId: FNFT from Account-ID oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a (Org-Id: AutoF1377358917, User-Id: idcqa)"
    }
]
BurnNFT
這個方法會停用或燒錄指定的不可行記號,並傳回記號物件和記號歷史記錄。任何具備 burner 角色的使用者都可以呼叫這個方法。
func (t *Controller) BurnNFT(orgId string, userId string, tokenId string) (interface{}, error) {
            tokenAsset, err := t.Ctx.ERC1155Token.Get(tokenId)
            if err != nil {
                  return nil, err
            }
            token := tokenAsset.(map[string]interface{})
            if token[constants.TokenType] != constants.NonFungible {
                  return nil, fmt.Errorf("only nonfungible tokens are allowed")
            }
            if token[constants.IsBurned] == true {
                  return nil, fmt.Errorf("token with tokenId %s is already burned", tokenId)
            }
            tokenQuantity := float64(1)
            tokenUnit := token[constants.TokenUnit]
            tokenHistory, err := t.Ctx.ERC1155Token.History(tokenId)
            if err != nil {
                  return nil, err
            }
            if tokenUnit == constants.Fractional {
                  owners, err := t.Ctx.ERC1155Token.OwnerOf(tokenId)
                  if err != nil {
                        return nil, err
                  }
                  ownersList := owners.([]map[string]interface{})
                  if len(ownersList) != 1 {
                        return nil, fmt.Errorf("NFT has multiple owners, to completely burn this NFT it should have only one owner")
                  }
                  tokenQuantity = token[constants.Quantity].(float64)
            }
            token[constants.TokenId], err = strconv.Atoi(token[constants.TokenId].(string))
            if err != nil {
                  return nil, fmt.Errorf("tokenId is expected to be integer but found %s", tokenId)
            }
            tokenHistoryBytes, err := json.Marshal(tokenHistory)
            if err != nil {
                  return nil, err
            }
            var tokenHistoryAsRawJson json.RawMessage
            err = json.Unmarshal(tokenHistoryBytes, &tokenHistoryAsRawJson)
            if err != nil {
                  return nil, err
            }
            token[constants.TokenHistory] = string(tokenHistoryAsRawJson)
            tokenIds := []string{tokenId}
            tokenQuantities := []float64{tokenQuantity}
            token[constants.IsBurned] = true
            _, err = t.BurnBatch(orgId, userId, tokenIds, tokenQuantities)
            if err != nil {
                  return nil, err
            }
            return token, nil
      }
參數:
  • orgId: string - 目前組織中的成員服務提供者 (MSP) ID。
  • userId: string - 使用者名稱或電子郵件 ID。
  • tokenId: string - 要燒錄的不可行記號 ID
傳回值:
  • 成功時,JSON 格式的記號物件會包含記號歷史記錄資訊。
傳回值範例:
{
    "AssetType": "otoken",
    "Behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "CreationDate": "2023-08-22T13:14:46+05:30",
    "IsBurned": true,
    "Mintable": {
        "Max_mint_quantity": 20000
    },
    "On_sale_flag": false,
    "Owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "Price": 120,
    "Quantity": 1,
    "Roles": {
        "minter_role_name": "minter"
    },
    "TokenDesc": "",
    "TokenHistory": "[{\"IsDelete\":\"false\",\"Timestamp\":\"2023-08-22T13:14:46+05:30\",\"TxId\":\"c0ea212f19197c5b86323bfca11c6ca545aa0af5d40cd04f9e955b5371fd40ae\",\"Value\":{\"AssetType\":\"otoken\",\"Behaviors\":[\"indivisible\",\"singleton\",\"mintable\",\"transferable\",\"burnable\",\"roles\"],\"CreatedBy\":\"oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d\",\"CreationDate\":\"2023-08-22T13:14:46+05:30\",\"IsBurned\":false,\"Mintable\":{\"Max_mint_quantity\":20000},\"On_sale_flag\":false,\"Owner\":\"oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d\",\"Price\":120,\"Quantity\":1,\"Roles\":{\"minter_role_name\":\"minter\"},\"TokenDesc\":\"\",\"TokenId\":\"1\",\"TokenMetadata\":{\"Description\":\"\",\"Image\":\"\",\"Painter_name\":\"\",\"Painting_name\":\"\"},\"TokenName\":\"artcollection\",\"TokenStandard\":\"erc1155+\",\"TokenType\":\"nonfungible\",\"TokenUnit\":\"whole\",\"TokenUri\":\"example.com\"}}]",
    "TokenId": 1,
    "TokenMetadata": {
        "Description": "",
        "Image": "",
        "Painter_name": "",
        "Painting_name": ""
    },
    "TokenName": "artcollection",
    "TokenStandard": "erc1155+",
    "TokenType": "nonfungible",
    "TokenUnit": "whole",
    "TokenUri": "example.com"
}

SDK 方法

存取控制管理的方法

CheckAuthorization
您可以使用此方法將存取控制檢查新增至作業。這是非同步函數。大多數自動產生的方法都包含存取控制。某些記號方法只能由記號的 ERC721AdminAccount Owner 執行,或由 MultipleAccountOwner 為具有多個帳戶的使用者執行。CheckAuthorization 方法是 erc721Auth 類別的一部分,您可以透過 Ctx 物件存取此類別。存取控制對應會在 oChainUtil.go 檔案中描述,如下列文字所示。您可以編輯 oChainUtil.go 檔案來修改存取控制。
  var t TokenAccess
      var r RoleAccess
      var a AccountAccess
      var as AccountStatusAccess
      var h HoldAccess
      var ad AdminAccess
      var trx TransactionAccess
      var tc TokenConversionAccess
      var auth AuthAccess
      var erc721ad ERC721AdminAccess
      var erc721t ERC721TokenAccess
      var erc721r ERC721RoleAccess
      var erc721a ERC721AccountAccess
      var erc721as ERC721AccountStatusAccess
      var erc721trx ERC721TransactionAccess

      var erc1155ad ERC1155AdminAccess
      var erc1155t ERC1155TokenAccess
      var erc1155a ERC1155AccountAccess
      var erc1155as ERC1155AccountStatusAccess
      var erc1155trx ERC1155TransactionAccess
      var erc1155role ERC1155RoleAccess
      trx.DeleteHistoricalTransactions = []string{"Admin"}
      ad.AddAdmin = []string{"Admin"}
      ad.RemoveAdmin = []string{"Admin"}
      ad.GetAllAdmins = []string{"Admin", "OrgAdmin"}
      ad.AddOrgAdmin = []string{"Admin", "OrgAdminOrgIdCheck"}
      ad.RemoveOrgAdmin = []string{"Admin", "OrgAdminOrgIdCheck"}
      ad.GetOrgAdmins = []string{"Admin", "OrgAdmin"}
      ad.IsTokenAdmin = []string{"Admin", "MultipleAccountOwner", "OrgAdmin"}
      t.Save = []string{"Admin"}
      t.GetAllTokens = []string{"Admin", "OrgAdmin"}
      t.Update = []string{"Admin"}
      t.GetTokenDecimals = []string{"Admin", "OrgAdmin"}
      t.GetTokensByName = []string{"Admin", "OrgAdmin"}
      t.AddRoleMember = []string{"Admin", "OrgAdminRoleCheck"}
      t.RemoveRoleMember = []string{"Admin", "OrgAdminRoleCheck"}
      t.IsInRole = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      t.GetTotalMintedTokens = []string{"Admin", "OrgAdmin"}
      t.GetNetTokens = []string{"Admin", "OrgAdmin"}
      t.Get = []string{"Admin", "OrgAdmin"}
      t.GetTokenHistory = []string{"Admin", "OrgAdmin"}
      a.CreateAccount = []string{"Admin", "OrgAdminOrgIdCheck"}
      a.AssociateToken = []string{"Admin", "OrgAdminAccountIdCheck"}
      a.GetAllAccounts = []string{"Admin"}
      a.GetAllOrgAccounts = []string{"Admin", "OrgAdminOrgIdCheck"}
      a.GetAccount = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      a.History = []string{"Admin", "AccountOwner"}
      a.GetAccountTransactionHistory = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      a.GetAccountTransactionHistoryWithFilters = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      a.GetSubTransactionsById = []string{"Admin", "TransactionInvoker"}
      a.GetSubTransactionsByIdWithFilters = []string{"Admin", "TransactionInvoker"}
      a.GetAccountBalance = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      a.GetAccountOnHoldBalance = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      a.GetOnHoldIds = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      a.GetAccountsByUser = []string{"Admin", "OrgAdminOrgIdCheck", "MultipleAccountOwner"}

      as.Get = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      as.ActivateAccount = []string{"Admin", "OrgAdminOrgIdCheck"}
      as.SuspendAccount = []string{"Admin", "OrgAdminOrgIdCheck"}
      as.DeleteAccount = []string{"Admin", "OrgAdminOrgIdCheck"}

      r.GetAccountsByRole = []string{"Admin"}
      r.GetUsersByRole = []string{"Admin"}
      r.GetOrgAccountsByRole = []string{"Admin", "OrgAdminOrgIdCheck"}
      r.GetOrgUsersByRole = []string{"Admin", "OrgAdminOrgIdCheck"}
      tc.InitializeExchangePoolUser = []string{"Admin"}
      tc.AddConversionRate = []string{"Admin"}
      tc.UpdateConversionRate = []string{"Admin"}
      tc.GetConversionRate = []string{"Admin", "OrgAdmin", "AnyAccountOwner"}
      tc.GetConversionRateHistory = []string{"Admin", "OrgAdmin", "AnyAccountOwner"}
      tc.TokenConversion = []string{"Admin", "AnyAccountOwner"}
      tc.GetExchangePoolUser = []string{"Admin"}

      erc721ad.AddAdmin = []string{"Admin"}
      erc721ad.GetAllAdmins = []string{"Admin"}
      erc721ad.IsTokenAdmin = []string{"Admin"}
      erc721ad.RemoveAdmin = []string{"Admin"}
      erc721trx.DeleteHistoricalTransactions = []string{"Admin"}
      erc721t.Save = []string{"Admin"}
      erc721t.GetAllTokens = []string{"Admin"}
      erc721t.Update = []string{"Admin"}
      erc721t.GetTokensByName = []string{"Admin"}
      erc721t.AddRoleMember = []string{"Admin"}
      erc721t.RemoveRoleMember = []string{"Admin"}
      erc721t.IsInRole = []string{"Admin", "AccountOwner"}
      erc721t.Get = []string{"Admin", "TokenOwner"}
      erc721t.GetAllTokensByUser = []string{"Admin", "AccountOwner"}
      erc721t.TotalSupply = []string{"Admin"}
      erc721t.TotalNetSupply = []string{"Admin"}
      erc721t.History = []string{"Admin"}
      erc721a.CreateAccount = []string{"Admin"}
      erc721a.CreateUserAccount = []string{"Admin"}
      erc721a.CreateTokenAccount = []string{"Admin"}
      erc721a.AssociateFungibleTokenToAccount = []string{"Admin", "AccountOwner"}
      erc721a.GetAllAccounts = []string{"Admin"}
      erc721a.History = []string{"Admin", "AccountOwner"}
      erc721a.GetAccountTransactionHistory = []string{"Admin", "AccountOwner"}
      erc721a.GetAccountTransactionHistoryWithFilters = []string{"Admin", "AccountOwner"}
      erc721a.GetAccountByUser = []string{"Admin", "MultipleAccountOwner"}
      erc721a.BalanceOf = []string{"Admin", "MultipleAccountOwner"}

      erc721as.Get = []string{"Admin", "AccountOwner"}
      erc721as.ActivateAccount = []string{"Admin"}
      erc721as.SuspendAccount = []string{"Admin"}
      erc721as.DeleteAccount = []string{"Admin"}

      erc721r.GetAccountsByRole = []string{"Admin"}
      erc721r.GetUsersByRole = []string{"Admin"}

      erc1155ad.AddAdmin = []string{"Admin"}
      erc1155ad.GetAllAdmins = []string{"Admin"}
      erc1155ad.IsUserTokenAdmin = []string{"Admin"}
      erc1155ad.RemoveAdmin = []string{"Admin"}
      erc1155t.AddRoleMember = []string{"Admin"}
      erc1155t.IsInRole = []string{"Admin"}
      erc1155t.GetAllTokens = []string{"Admin"}
      erc1155t.GetAllTokensByUser = []string{"Admin", "AccountOwner"}
      erc1155t.Get = []string{"Admin", "TokenOwner"}
      erc1155t.RemoveRoleMember = []string{"Admin"}
      erc1155t.TotalNetSupply = []string{"Admin"}
      erc1155t.TotalSupply = []string{"Admin"}
      erc1155t.GetTokenDecimal = []string{"Admin"}
      erc1155t.GetTokensByName = []string{"Admin"}
      erc1155t.GetTotalMintedTokens = []string{"Admin"}
      erc1155t.GetNetTokens = []string{"Admin"}
      erc1155t.Save = []string{"Admin"}
      erc1155t.Update = []string{"Admin"}

      erc1155trx.DeleteHistoricalTransactions = []string{"Admin"}

      erc1155role.GetAccountsByRole = []string{"Admin"}
      erc1155role.GetUsersByRole = []string{"Admin"}
      erc1155a.AssociateFungibleTokenToAccount = []string{"Admin", "AccountOwner"}
      erc1155a.BalanceOfBatch = []string{"Admin"}
      erc1155a.CreateAccount = []string{"Admin"}
      erc1155a.CreateTokenAccount = []string{"Admin"}
      erc1155a.CreateUserAccount = []string{"Admin"}
      erc1155a.GetAccountTransactionHistory = []string{"Admin", "AccountOwner"}
      erc1155a.GetAccountTransactionHistoryWithFilters = []string{"Admin", "AccountOwner"}
      erc1155a.GetAccountsByUser = []string{"Admin", "AccountOwner"}
      erc1155a.GetAccount = []string{"Admin", "AccountOwner"}
      erc1155a.History = []string{"Admin", "AccountOwner"}
      erc1155a.GetAllAccounts = []string{"Admin"}
      erc1155a.ExchangeToken = []string{"AccountOwner"}
      erc1155a.GetAccountDetailsByUser = []string{"Admin", "AccountOwner"}

      erc1155as.Get = []string{"Admin", "AccountOwner"}
      erc1155as.ActivateAccount = []string{"Admin"}
      erc1155as.SuspendAccount = []string{"Admin"}
      erc1155as.DeleteAccount = []string{"Admin"}
      var accessMap TokenAccessControl
      accessMap.Token = t
      accessMap.Account = a
      accessMap.AccountStatus = as
      accessMap.Hold = h
      accessMap.Role = r
      accessMap.Admin = ad
      accessMap.Auth = auth
      accessMap.TokenConversion = tc
      accessMap.ERC721ADMIN = erc721ad
      accessMap.ERC721TOKEN = erc721t
      accessMap.ERC721ACCOUNT = erc721a
      accessMap.ERC721AccountStatus = erc721as
      accessMap.ERC721ROLE = erc721r
      accessMap.ERC721TRANSACTION = erc721trx
      accessMap.ERC1155Account = erc1155a
      accessMap.ERC1155AccountStatus = erc1155as
      accessMap.ERC1155Admin = erc1155ad
      accessMap.ERC1155Token = erc1155t
      accessMap.ERC1155Transaction = erc1155trx
      accessMap.ERC1155Role = erc1155role
Ctx.ERC1155Auth.CheckAuthorization(funcName string, args []string) (bool, error)
參數:
  • funcName string - 接收者與方法之間的對應值,如 oChainUtil.go 檔案中所述。
  • args - 一個變數引數,其中 args[0] 會採用 'TOKEN' 常數,而 args[1] 會採用 accountId 參數來新增 AccountOwner 的存取控制檢查。若要新增 MultipleAccountOwner 的存取控制檢查,args[1] 會採用 orgId 參數,而 args[2] 則會採用 userId 參數。若要新增 TokenOwner 的存取控制檢查,args[1] 會採用記號 ID 參數。
傳回值:
  • 視需要回應 bool 錯誤。
IsUserTokenAdmin
如果指定的使用者是 Token Admin,則此方法會傳回布林值 true,否則會傳回 false。此方法只能由記號鏈碼的 Token Admin 呼叫。
Ctx.ERC1155Auth.IsUserTokenAdmin(orgId string, userId string) (interface{}, error)
參數:
  • orgId: string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId: string - 使用者的使用者名稱或電子郵件 ID。
傳回值範例:
{
  "result": true
}
AddAdmin
此方法會將使用者新增為記號鏈碼的 Token Admin。此方法只能由記號鏈碼的 Token Admin 呼叫。
Ctx.ERC1155Admin.AddAdmin(orgId string, userId string) (interface{}, error)
參數:
  • orgId: string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId: string - 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會列出新增為記號鏈碼之 Token Admin 的使用者詳細資訊的訊息。
傳回值範例:
{
  "msg": "Successfully added Admin (orgId: appdev, userId: user1)"
}
RemoveAdmin
此方法會將使用者移除為記號鏈碼的 Token Admin。此方法只能由記號鏈碼的 Token Admin 呼叫。您無法移除本身的 Token Admin
Ctx.ERC1155Admin.RemoveAdmin(orgId string, userId string) (interface{}, error)
參數:
  • orgId: string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId: string - 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會出現一則訊息,其中列出使用者的詳細資訊,已移除為記號鏈碼的 Token Admin
傳回值範例:
{
    "msg": "Successfully removed Admin (orgId appdev userId user1)"
}
GetAllAdminUsers
此方法會傳回所有 Token Admin 使用者的清單。
Ctx.ERC1155Admin.GetAllAdminUsers() (interface{}, error)
參數:
傳回值:
  • 成功時,依組織 ID 與使用者 ID 識別的所有 Token Admin 使用者清單。
傳回值範例:
{
  "admins": [
    {
      "OrgId": "appdev",
      "UserId": "idcqa"
    },
    {
      "OrgId": "appdev",
      "UserId": "user1"
    }
  ]
}

記號組態管理的方法

Save
此方法會建立記號。每個定義的記號都有自己的建立方法。對於非功能權杖,如果是在規格檔案中定義較小的角色,則具有較小角色的任何使用者都可以呼叫此方法來建立 NFT。否則,任何使用者都可以使用此方法來建立 (提示) NFT。呼叫此方法的使用者會成為 NFT 的擁有者 (完整或分數)。
Ctx.ERC1155Token.Save(token interface{}, quantity ...float64) (interface{}, error)
參數:
  • tokenAsset: interface{} - 記號資產。資產的特性是在模型檔案中定義。
  • quantity: number - 僅適用於非功能變數替代字,用於提示的變數替代字數目。此參數唯一支援的值是 1
傳回值:
  • 順利完成時,JSON 格式的權杖資產包括下列資訊。
  • BehaviorBehaviors - 記號行為清單。無法編輯此特性。
  • CreatedBy - 呼叫者的帳戶 ID,呼叫者的帳戶 ID 是正在修改記號的使用者。無法編輯此特性。
  • CreationDate - 採礦交易的時間戳記。無法編輯此特性。
  • IsBurned - 此特性指示記號是否被燒錄。無法編輯此特性。
  • Mintable - 與轉換相關的特性。max_mint_quantity 值定義可為記號類別建立的記號數目上限。
  • Owner - 目前擁有者的帳戶 ID,亦即方法的呼叫程式。
  • Symbol - 記號的符號。無法編輯此特性。
  • TokenDesc - 記號的描述。
  • TokenMetadata - 描述權杖的 JSON 資訊。
  • TokenName - 記號的名稱。無法編輯此特性。
  • TokenStandard - 記號的標準。無法編輯此特性。
  • TokenType - 記號的類型 (有趣或不可行)。無法編輯此特性。
  • TokenUnit - 記號的單位 (完整或分數)。無法編輯此特性。
  • TokenUri - 記號的 URI。
  • Quantity - 記號的數量。
傳回值範例 (整個 NFT):
{
    "AssetType": "otoken",
    "Behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "CreationDate": "2022-12-29T09:57:03+05:30",
    "IsBurned": false,
    "Mintable": {
        "Max_mint_quantity": 500
    },
    "OnSaleFlag": false,
    "Owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "Price": 100,
    "Quantity": 1,
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "token description",
    "TokenId": "monalisa",
    "TokenMetadata": {
        "Description": "Mona Lisa Painting",
        "Image": "monalisa.jpeg",
        "PainterName": "Leonardo_da_Vinci",
        "PaintingName": "Mona_Lisa"
    },
    "TokenName": "artcollection",
    "TokenStandard": "erc1155+",
    "TokenType": "nonfungible",
    "TokenUnit": "whole",
    "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg"
}
傳回值範例 (Fungible Token):
{
    "AssetType": "otoken",
    "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "Currency_name": "Dollar",
    "Divisible": {
        "Decimal": 2
    },
    "Mintable": {
        "Max_mint_quantity": 10000
    },
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "Token Description",
    "TokenId": "Loyalty",
    "TokenName": "loyalty",
    "TokenStandard": "erc1155+",
    "TokenType": "fungible",
    "TokenUnit": "fractional",
    "Token_to_currency_ratio": 0
}
傳回值範例 (小數 NFT):
{
    "AssetType": "otoken",
    "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "CreationDate": "2023-06-14T09:53:53+05:30",
    "Divisible": {
        "Decimal": 2
    },
    "IsBurned": false,
    "Mintable": {
        "Max_mint_quantity": 20000
    },
    "On_sale_flag": false,
    "Price": 1000,
    "Quantity": 100,
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "Token Description",
    "TokenId": "realEstate",
    "TokenMetadata": {
        "Description": "Painting Description",
        "Image": "",
        "Painter_name": "",
        "Painting_name": "Paint"
    },
    "TokenName": "realestate",
    "TokenStandard": "erc1155+",
    "TokenType": "nonfungible",
    "TokenUnit": "fractional",
    "TokenUri": "www.realestate.example.com"
}
Update
此方法會更新記號。您無法更新記號中繼資料或不可行記號的記號 URI。
Ctx.ERC1155Token.Update(tokenAsset interface{}) (interface{}, error)
參數:
  • tokenAsset: interface{} - 記號資產。資產的特性是在模型檔案中定義。
傳回值:
  • 更新的權杖資產若成功,則為 JSON 格式。
傳回值範例 (整個 NFT):
{
    "AssetType": "otoken",
    "Behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "CreationDate": "2022-12-29T09:57:03+05:30",
    "IsBurned": false,
    "Mintable": {
        "Max_mint_quantity": 500
    },
    "OnSaleFlag": false,
    "Owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "Price": 100,
    "Quantity": 1,
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "token description",
    "TokenId": "monalisa",
    "TokenMetadata": {
        "Description": "Mona Lisa Painting",
        "Image": "monalisa.jpeg",
        "PainterName": "Leonardo_da_Vinci",
        "PaintingName": "Mona_Lisa"
    },
    "TokenName": "artcollection",
    "TokenStandard": "erc1155+",
    "TokenType": "nonfungible",
    "TokenUnit": "whole",
    "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg"
}
History (Token)
此方法會傳回指定記號 ID 的歷史記錄。
Ctx.ERC1155Token.History(tokenId string) (interface{}, error)
參數:
  • tokenId string - 記號的 ID。
傳回值:
  • 成功時,包含權杖歷史記錄的 JSON 陣列。
傳回值範例 (Fungible Token):
[
  {
    "IsDelete": "false",
    "Timestamp": "2022-12-08T09:54:11Z",
    "TxId": "823sa7c7a00941c62285c86f922bc4d3f5326a20f4bf2f82daa5bc661e4682e8",
    "Value": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "Rupees",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "Updated Token Description",
      "TokenId": "tokenOne",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  },
  {
    "IsDelete": "false",
    "Timestamp": "2022-12-08T09:54:11Z",
    "TxId": "711bb7c7a00941c62285c86f922bc3b3f5326a20f4bf2f82daa5bc661e4682e8",
    "Value": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "Dollar",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenOne",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  }
]
傳回值範例 (小數 NFT):
[
    {
        "Timestamp": "2023-06-20T01:06:33Z",
        "TrxId": "16e53db4f8107f9634b7c3a0a2a81a00f69b634f2a52902b809e544d07f272b1",
        "Value": {
            "AssetType": "otoken",
            "Behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "CreationDate": "2023-06-20T01:02:27Z",
            "Divisible": {
                "Decimal": 2
            },
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "On_sale_flag": true,
            "Owners": [
                {
                    "AccountId": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
                    "TokenShare": 10
                },
                {
                    "AccountId": "oaccount~3cddfdaa855900579d963aa6f755a4aed1f3a474a2462c1b45bd7f36df673224",
                    "TokenShare": 10
                }
            ],
            "Price": 2000,
            "Quantity": 20,
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "TokenDesc": "",
            "TokenId": "FNFT",
            "TokenMetadata": {
                "Description": "",
                "Image": "",
                "Painter_name": "",
                "Painting_name": ""
            },
            "TokenName": "realestate",
            "TokenStandard": "erc1155+",
            "TokenType": "nonfungible",
            "TokenUnit": "fractional",
            "TokenUri": "www.FNFT.example.com"
        }
    },
    {
        "Timestamp": "2023-06-20T01:02:27Z",
        "TrxId": "cec80910d087682554048f911d2cf98b66382bbcf1615483fa1c96c7ea08077c",
        "Value": {
            "AssetType": "otoken",
            "Behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "CreationDate": "2023-06-20T01:02:27Z",
            "Divisible": {
                "Decimal": 2
            },
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "On_sale_flag": true,
            "Owners": [
                {
                    "AccountId": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
                    "TokenShare": 20
                }
            ],
            "Price": 2000,
            "Quantity": 20,
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "TokenDesc": "",
            "TokenId": "FNFT",
            "TokenMetadata": {
                "Description": "",
                "Image": "",
                "Painter_name": "",
                "Painting_name": ""
            },
            "TokenName": "realestate",
            "TokenStandard": "erc1155+",
            "TokenType": "nonfungible",
            "TokenUnit": "fractional",
            "TokenUri": "www.FNFT.example.com"
        }
    }
]
傳回值範例 (整個 NFT):
[
    {
        "IsDelete": "false",
        "Timestamp": "2023-06-20T01:15:56Z",
        "TxId": "89a3df3ebbe6dca2bcfbd51fc7dca9aab818a2af746b79a92dc8155b729ab22d",
        "Value": {
            "AssetType": "otoken",
            "Behaviors": [
                "indivisible",
                "singleton",
                "mintable",
                "transferable",
                "roles"
            ],
            "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "CreationDate": "2023-06-20T01:15:56Z",
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "On_sale_flag": true,
            "Owner": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "Price": 2000,
            "Quantity": 1,
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "TokenDesc": "Updated Token Description",
            "TokenId": "NFT",
            "TokenMetadata": {
                "Description": "",
                "Image": "",
                "Painter_name": "",
                "Painting_name": ""
            },
            "TokenName": "artcollection",
            "TokenStandard": "erc1155+",
            "TokenType": "nonfungible",
            "TokenUnit": "whole",
            "TokenUri": "www.NFT.example.com"
        }
    },
    {
        "IsDelete": "false",
        "Timestamp": "2023-06-20T01:15:56Z",
        "TxId": "90d6af3ebbe6dca2bcfbd51fc7dca9aab818a2af746b79a92dc8155b729ab22d",
        "Value": {
            "AssetType": "otoken",
            "Behaviors": [
                "indivisible",
                "singleton",
                "mintable",
                "transferable",
                "roles"
            ],
            "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "CreationDate": "2023-06-20T01:15:56Z",
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "On_sale_flag": true,
            "Owner": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "Price": 2000,
            "Quantity": 1,
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "TokenDesc": "",
            "TokenId": "NFT",
            "TokenMetadata": {
                "Description": "",
                "Image": "",
                "Painter_name": "",
                "Painting_name": ""
            },
            "TokenName": "artcollection",
            "TokenStandard": "erc1155+",
            "TokenType": "nonfungible",
            "TokenUnit": "whole",
            "TokenUri": "www.NFT.example.com"
        }
    }
]
GetAllTokens
此方法會傳回儲存在狀態資料庫中的所有記號資產。鏈碼的 Token Admin 只能呼叫此方法。此方法使用 Berkeley DB SQL 豐富查詢,且只能在連線至遠端 Oracle Blockchain Platform 網路時呼叫。
Ctx.ERC1155Token.GetAllTokens()() (interface{}, error)
參數:
傳回值範例:
[
  {
    "key": "tokenOne",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenOne",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  },
  {
    "key": "tokenTwo",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenTwo",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  },
  {
    "key": "art",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
      ],
      "BurnedBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "BurnedDate": "2022-12-08T10:49:37Z",
      "CreatedBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "CreationDate": "2022-12-08T10:45:10Z",
      "IsBurned": true,
      "Mintable": {
        "Max_mint_quantity": 20000
      },
      "OnSaleFlag": false,
      "Owner": "",
      "Price": 0,
      "Roles": {
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "art",
      "TokenMetadata": {
        "Description": "",
        "Image": "",
        "PainterName": "",
        "PaintingName": ""
      },
      "TokenName": "artcollection",
      "TokenStandard": "erc1155+",
      "TokenType": "nonfungible",
      "TokenUnit": "whole",
      "TokenUri": "art.example.com",
      "TransferredBy": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc",
      "TransferredDate": "2022-12-08T10:47:04Z"
    }
  },
  {
    "key": "FNFT",
    "valueJson": {
        "AssetType": "otoken",
        "Behaviors": [
            "divisible",
            "mintable",
            "transferable",
            "burnable",
            "roles"
        ],
        "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
        "CreationDate": "2023-06-20T01:02:27Z",
        "Divisible": {
            "Decimal": 2
        },
        "IsBurned": false,
        "Mintable": {
            "Max_mint_quantity": 20000
        },
        "On_sale_flag": true,
        "Price": 2000,
        "Quantity": 20,
        "Roles": {
            "burner_role_name": "burner",
            "minter_role_name": "minter"
        },
        "TokenDesc": "",
        "TokenId": "FNFT",
        "TokenMetadata": {
            "Description": "",
            "Image": "",
            "Painter_name": "",
            "Painting_name": ""
        },
        "TokenName": "realestate",
        "TokenStandard": "erc1155+",
        "TokenType": "nonfungible",
        "TokenUnit": "fractional",
        "TokenUri": "www.FNFT.example.com"
    }
  },
  {
    "key": "FNFT",
    "valueJson": {
        "AssetType": "otoken",
        "Behaviors": [
            "divisible",
            "mintable",
            "transferable",
            "burnable",
            "roles"
        ],
        "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
        "CreationDate": "2023-06-20T01:02:27Z",
        "Divisible": {
            "Decimal": 2
        },
        "IsBurned": false,
        "Mintable": {
            "Max_mint_quantity": 20000
        },
        "On_sale_flag": true,
        "Price": 2000,
        "Quantity": 20,
        "Roles": {
            "burner_role_name": "burner",
            "minter_role_name": "minter"
        },
        "TokenDesc": "",
        "TokenId": "FNFT",
        "TokenMetadata": {
            "Description": "",
            "Image": "",
            "Painter_name": "",
            "Painting_name": ""
        },
        "TokenName": "realestate",
        "TokenStandard": "erc1155+",
        "TokenType": "nonfungible",
        "TokenUnit": "fractional",
        "TokenUri": "www.FNFT.example.com"
    }
  }
]
Get (Token)
如果記號存在於狀態資料庫中,這個方法就會傳回記號物件。此方法只能由鏈碼的 Token Admin 或記號擁有者呼叫。對於小數的 NFT,也會傳回擁有者清單。
Ctx.ERC1155Token.Get(id string, result ...interface{}) (interface{}, error)
參數:
  • id string - 要取得之記號的 ID。
傳回值範例 (整個 NFT):
{
  "AssetType": "otoken",
  "Behaviors": [
    "indivisible",
    "singleton",
    "mintable",
    "transferable",
    "burnable",
    "roles"
  ],
  "CreatedBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
  "CreationDate": "2022-12-08T10:55:29Z",
  "IsBurned": false,
  "Mintable": {
    "Max_mint_quantity": 20000
  },
  "OnSaleFlag": false,
  "Owner": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
  "Price": 0,
  "Quantity": 1,
  "Roles": {
    "minter_role_name": "minter"
  },
  "TokenDesc": "",
  "TokenId": "nftToken",
  "TokenMetadata": {
    "Description": "",
    "Image": "",
    "PainterName": "",
    "PaintingName": ""
  },
  "TokenName": "artcollection",
  "TokenStandard": "erc1155+",
  "TokenType": "nonfungible",
  "TokenUnit": "whole",
  "TokenUri": "example.com"
}
傳回值範例 (Fungible Token):
{
    "AssetType": "otoken",
    "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "Currency_name": "Dollar",
    "Divisible": {
        "Decimal": 2
    },
    "Mintable": {
        "Max_mint_quantity": 10000
    },
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "Token Description",
    "TokenId": "Loyalty",
    "TokenName": "loyalty",
    "TokenStandard": "erc1155+",
    "TokenType": "fungible",
    "TokenUnit": "fractional",
    "Token_to_currency_ratio": 0
}
傳回值範例 (小數 NFT):
{
    "AssetType": "otoken",
    "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "CreationDate": "2023-06-14T09:53:53+05:30",
    "Divisible": {
        "Decimal": 2
    },
    "IsBurned": false,
    "Mintable": {
        "Max_mint_quantity": 20000
    },
    "On_sale_flag": false,
    "Owners": [
        {
            "AccountId": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "TokenShare": 100
        }
    ],
    "Price": 1000,
    "Quantity": 100,
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "Token Description",
    "TokenId": "realEstate",
    "TokenMetadata": {
        "Description": "Painting Description",
        "Image": "",
        "Painter_name": "",
        "Painting_name": "Paint"
    },
    "TokenName": "realestate",
    "TokenStandard": "erc1155+",
    "TokenType": "nonfungible",
    "TokenUnit": "fractional",
    "TokenUri": "www.realestate.example.com"
}
GetAllTokensByUser
此方法會傳回指定使用者擁有的所有權杖資產。此方法使用 Berkeley DB SQL 豐富查詢,且只能在連線至遠端 Oracle Blockchain Platform 網路時呼叫。
Ctx.ERC1155Token.GetAllTokensByUser(accountId string) (interface{}, error)
參數:
  • accountId string - 使用者的帳戶 ID。
傳回值範例:
[
  {
    "key": "tokenOne",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenOne",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  },
  {
    "key": "nftToken",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
      ],
      "CreatedBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "CreationDate": "2022-12-08T10:55:29Z",
      "IsBurned": false,
      "Mintable": {
        "Max_mint_quantity": 20000
      },
      "OnSaleFlag": false,
      "Owner": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "Price": 0,
      "Quantity": 1,
      "Roles": {
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "nftToken",
      "TokenMetadata": {
        "Description": "",
        "Image": "",
        "PainterName": "",
        "PaintingName": ""
      },
      "TokenName": "artcollection",
      "TokenStandard": "erc1155+",
      "TokenType": "nonfungible",
      "TokenUnit": "whole",
      "TokenUri": "example.com"
    }
  }
]
OwnerOf
此方法會傳回指定記號 ID 之擁有者的帳戶 ID、組織 ID 和使用者 ID。
Ctx.ERC1155Token.OwnerOf(tokenId string) (interface{}, error)
參數:
  • tokenId string - 記號的 ID。
傳回值範例:
{
  "AccountId": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
  "OrgId": "appdev",
  "UserId": "idcqa"
}
TokenURI
此方法會傳回指定記號的 URI。任何人都可以呼叫此方法。
Ctx.ERC1155Token.TokenURI(tokenId string) (interface{}, error)
參數:
  • tokenId string - 記號的 ID。
傳回值範例:
{
    "TokenUri": "example.com"
}
Name
此方法會傳回記號類別的名稱。任何人都可以呼叫此方法。
Ctx.ERC1155Token.Name(tokenId string) (interface{}, error)
參數:
  • tokenId string - 記號的 ID。
傳回值範例:
{"TokenName": "artcollection"}
TotalSupply
此方法會傳回已轉換記號的總數。變數替代字是由變數替代字 ID 指定。記號名稱指定了不可行的記號。
Ctx.ERC1155Token.TotalSupply(tokenAsset interface{}) (map[string]interface{}, error)
參數:
  • tokenAsset interface{} - 記號資產。
傳回值範例:
{"TotalSupply": 100}
TotalNetSupply
這個方法會傳回經過 minted 記號減去燒錄記號數目的總數。變數替代字是由變數替代字 ID 指定。記號名稱指定了不可行的記號。
Ctx.ERC1155Token.TotalNetSupply(token interface{}) (interface{}, error)
參數:
  • token interface{} - 記號資產。
傳回值範例:
{"TotalNetSupply": 100}
GetTokensByName
此方法會傳回指定記號名稱的所有記號資產。此方法使用 Berkeley DB SQL 豐富查詢,且只能在連線至遠端 Oracle Blockchain Platform 網路時呼叫。
Ctx.ERC1155Token.GetTokensByName(tokenName string) (interface{}, error)
參數:
  • tokenName: string - 記號的名稱。
傳回值範例:
[
  {
    "key": "tokenOne",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenOne",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  },
  {
    "key": "tokenTwo",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenTwo",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  }
]
GetDecimals
此方法會傳回指定記號的小數位數。如果記號未指定可分割行為,則會傳回零小數位數的預設值。
Ctx.ERC1155Token.GetDecimals(tokenId string) (int, error)
參數:
  • tokenId: string - 記號的 ID。
傳回值範例:
2

帳戶管理方法

CreateAccount
此方法會為指定的使用者和關聯的記號帳戶建立好玩或不可行記號的帳戶。必須為任何時候會有權杖的任何使用者建立帳戶。使用者帳戶會追蹤使用者擁有的 NFT 帳戶和有趣的權杖帳戶。使用者必須在網路中擁有帳戶,才能完成權杖相關作業。鏈碼的 Token Admin 只能呼叫此方法。

使用者帳戶具有唯一 ID,由 orgId 參數和 userId 參數的 SHA-256 雜湊組成。

使用者可以有多個具有唯一帳戶 ID 的有趣權杖帳戶。有趣的記號帳戶 ID 是由 orgId 參數的 SHA-256 雜湊、userId 參數、常數字串 ft (以波狀符號 (~) 分隔) 以及計數器編號所組成,代表要以波狀符號 (~) 分隔建立的有趣帳戶索引。

使用者只能有一個不可行的權杖帳戶。不可行的記號帳戶 ID 是唯一的,由 orgId 參數的 SHA-256 雜湊、userId 參數,以及以波狀符號 (~) 分隔的常數字串 nft 組成。使用者擁有的所有不可行記號 (不論全部或小數) 都連結至此單一不可行記號帳戶。

Ctx.ERC1155Account.CreateAccount(orgId string, userId string, ftAccount bool, nftAccount bool) (ERC1155UserAccount, error)
參數:
  • orgId string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId string - 使用者的使用者名稱或電子郵件 ID。
  • ftAccount bool - 若為 true,則會建立有趣的權杖帳戶並與使用者帳戶關聯。
  • nftAccount bool - 若為 true,則會建立與使用者帳戶相關聯的不可行記號帳戶。
傳回值:
  • 成功時,所建立帳戶的 JSON 物件。
傳回值範例:
{
  "AssetType": "ouaccount",
  "AccountId": "ouaccount~cf20877546f52687f387e7c91d88b9722c97e1a456cc0484f40c747f7804feae",
  "UserId": "user1",
  "OrgId": "appdev",
  "TotalAccounts": 2,
  "TotalFtAccounts": 1,
  "AssociatedFtAccounts": [
    {
      "AccountId": "oaccount~60bb20c14a83f6e426e1437c479c5891e1c6477dfd7ad18b73acac5d80bc504b",
      "TokenId": ""
    }
  ],
  "AssociatedNftAccount": "oaccount~73c3e835dac6d0a56ca9d8def08269f83cefd59b9d297fe2cdc5a9083828fa58"
}
CreateUserAccount
此方法會為指定的使用者建立帳戶。必須為任何時候會有權杖的任何使用者建立帳戶。使用者帳戶會追蹤使用者擁有的 NFT 帳戶和有趣的權杖帳戶。使用者必須在網路中擁有帳戶,才能完成權杖相關作業。

帳戶 ID 是 orgId 參數和 userId 參數的 SHA-256 雜湊。鏈碼的 Token Admin 只能呼叫此方法。

Ctx.ERC1155Account.CreateUserAccount(orgId string, userId string) (interface{}, error)
參數:
  • orgId string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId string - 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,所建立使用者帳戶的 JSON 物件。
傳回值範例:
{
  "AssetType": "ouaccount",
  "AccountId": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc",
  "UserId": "idcqa",
  "OrgId": "appdev",
  "TotalAccounts": 0,
  "TotalFtAccounts": 0,
  "AssociatedFtAccounts": [],
  "AssociatedNftAccount": ""
}
CreateTokenAccount
此方法會建立有趣或不可行的權杖帳戶,以便與使用者帳戶建立關聯。

使用者可以有多個具有唯一帳戶 ID 的有趣權杖帳戶。有趣的記號帳戶 ID 是由 orgId 參數的 SHA-256 雜湊、userId 參數、常數字串 ft (以波狀符號 (~) 分隔) 以及計數器編號所組成,代表要以波狀符號 (~) 分隔建立的有趣帳戶索引。

使用者只能有一個不可行的權杖帳戶。不可行的記號帳戶 ID 是唯一的,由 orgId 參數的 SHA-256 雜湊、userId 參數,以及以波狀符號 (~) 分隔的常數字串 nft 組成。使用者擁有的所有不可行記號 (不論全部或小數) 都連結至此單一不可行記號帳戶。

鏈碼的 Token Admin 只能呼叫此方法。

Ctx.ERC1155Account.CreateTokenAccount(orgId string, userId string, tokenType string) (ERC1155UserAccount, error)
參數:
  • orgId string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId string - 使用者的使用者名稱或電子郵件 ID。
  • tokenType erc1155Token.TokenType - 要建立的記號帳戶類型。唯一支援的權杖類型為 nonfungiblefungible
傳回值:
  • 成功時,所建立權杖帳戶的 JSON 物件。
傳回值範例:
{
    "AssetType": "ouaccount",
    "AccountId": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc",
    "UserId": "idcqa",
    "OrgId": "appdev",
    "TotalAccounts": 1,
    "TotalFtAccounts": 1,
    "AssociatedFtAccounts": [
        {
            "AccountId": "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
            "TokenId": ""
        }
    ],
    "AssociatedNftAccount": ""
}
AssociateTokenToToken
此方法會建立使用者有趣的權杖帳戶與特定有趣的權杖的關聯。
Ctx.ERC1155Account.AssociateTokenToToken(accountId string, tokenId string) (interface{}, error)
參數:
  • accountId string - 使用者帳戶 ID。
  • tokenId string - 記號的 ID。
傳回值:
  • 成功時,使用者帳戶的 JSON 物件會顯示有趣的權杖與權杖帳戶關聯。例如,在下列範例中,AssociatedFtAccounts 陣列中的第一個物件會顯示有趣的記號帳戶 ID 和記號 ID 相關聯。
傳回值範例:
{
    "AssetType": "ouaccount",
    "AccountId": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc",
    "UserId": "idcqa",
    "OrgId": "appdev",
    "TotalAccounts": 1,
    "TotalFtAccounts": 1,
    "AssociatedFtAccounts": [
        {
            "AccountId": "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
            "TokenId": "tokenOne"
        }
    ],
    "AssociatedNftAccount": ""
}
GetAccountHistory
此方法會傳回指定記號帳戶的歷史記錄。
Ctx.ERC1155Account.GetAccountHistory(accountId string)
參數:
  • accountId string - 權杖帳戶 ID。
傳回值:
  • 成功時,描述帳戶歷史記錄的 JSON 物件陣列。
傳回值範例:
[
    {
        "IsDelete": "false",
        "Timestamp": "2023-06-06T11:03:48Z",
        "TxId": "c5180f3be3d9130f25a4b4e866f38a4283117dcbfbffb4f55e2c5b03dba0dd29",
        "Value": {
            "AccountCategory": "",
            "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
            "AssetType": "oaccount",
            "Balance": 100,
            "BapAccountVersion": 1
            "OrgId": "appdev",
            "TokenId": "loy1",
            "TokenName": "loyalty",
            "TokenType": "fungible",
            "UserId": "idcqa"
        }
    },
    {
        "IsDelete": "false",
        "Timestamp": "2023-06-06T11:02:39Z",
        "TxId": "6f81b0c94b451d375a3892446aefbdf78d9fd1ac43699daa89f0dff10db5fd22",
        "Value": {
            "AccountCategory": "",
            "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
            "AssetType": "oaccount",
            "Balance": 0,
            "BapAccountVersion": 0
            "OrgId": "appdev",
            "TokenId": "loy1",
            "TokenName": "loyalty",
            "TokenType": "fungible",
            "UserId": "idcqa"
        }
    },
    {
        "IsDelete": "false",
        "Timestamp": "2023-06-05T16:28:46Z",
        "TxId": "8185af648546e909488e72149be497b210f74f95ada252c42da9c35cb9d98691",
        "Value": {
            "AccountCategory": "",
            "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
            "AssetType": "oaccount",
            "Balance": 0,
            "BapAccountVersion": 0
            "OrgId": "appdev",
            "TokenId": "",
            "TokenName": "",
            "TokenType": "fungible",
            "UserId": "idcqa"
        }
    }
]
GetAccountWithStatus
此方法會傳回指定之使用者的權杖帳戶詳細資訊,包括帳戶狀態。此方法只能由鏈碼的 Token Admin 或帳戶的 Account Owner 呼叫。
Ctx.ERC1155Account.GetAccountWithStatus(userAccountId string, tokenId ...string) (interface{}, error)
參數:
  • userAccountId string - 使用者的帳戶 ID。
  • tokenId ...string - 若為非工具權杖帳戶,則為空白字串。如果是有趣的權杖帳戶,則是權杖 ID。
傳回值:
  • 成功時,包含權杖帳戶詳細資訊 (包括帳戶狀態) 的 JSON 物件。
傳回值範例 (不可行權杖帳戶):
{
    "AccountId": "oaccount~cc301bee057f14236a97d434909ec1084970921b008f6baab09c2a0f5f419a9a",
    "AssetType": "oaccount",
    "BapAccountVersion": 1,
    "NoOfNfts": 1,
    "OrgId": "appdev",
    "Status": "active",
    "TokenType": "nonfungible",
    "UserId": "idcqa"
}
傳回值範例 (Fungible Token 帳戶):
{
    "AccountCategory": "",
    "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
    "AssetType": "oaccount",
    "Balance": 0,
    "BapAccountVersion": 0,
    "OrgId": "appdev",
    "Status": "active",
    "TokenId": "t1",
    "TokenName": "loyalty",
    "TokenType": "fungible",
    "UserId": "idcqa"
}
GetAccount
此方法會傳回指定之使用者的權杖帳戶詳細資訊。此方法只能由鏈碼的 Token Admin 或帳戶的 Account Owner 呼叫。
Ctx.ERC1155Account.Get(accountId string, tokenId ...string) (interface{}, error) 
參數:
  • userAccountId string - 使用者的帳戶 ID。
  • tokenId ...string - 若為非工具權杖帳戶,則為空白字串。如果是有趣的權杖帳戶,則是權杖 ID。
傳回值:
  • 成功時,包含權杖帳戶詳細資訊的 JSON 物件。
傳回值範例 (不可行權杖帳戶):
{
    "AccountId": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
    "BapAccountVersion": 0,
    "AssetType": "oaccount",
    "NoOfNfts": 4,
    "OrgId": "appdev",
    "TokenType": "nonfungible",
    "UserId": "idcqa"
}
傳回值範例 (Fungible Token 帳戶):
{
    "AssetType": "oaccount",
    "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
    "UserId": "idcqa",
    "OrgId": "appdev",
    "BapAccountVersion": 0,
    "TokenType": "fungible",
    "TokenId": "loy1",
    "TokenName": "loyalty",
    "Balance": 90,
    "AccountCategory": ""
}
GetAllAccounts
此方法會傳回所有使用者帳戶的詳細資訊。
Ctx.ERC1155Account.GetAllAccounts() (interface{}, error)
參數:
傳回值範例:
[
    {
        "AssetType": "ouaccount",
        "AccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
        "UserId": "idcqa",
        "OrgId": "appdev",
        "TotalAccounts": 3,
        "TotalFtAccounts": 2,
        "AssociatedFtAccounts": [
            {
                "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
                "TokenId": "loy1"
            },
            {
                "AccountId": "oaccount~58c5a6b09a41befca2a9ea2550439838c4dcf4d8a2a4f7c98e9319cf8479bfc4",
                "TokenId": ""
            }
        ],
        "AssociatedNftAccount": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371"
    },
    {
        "AssetType": "ouaccount",
        "AccountId": "ouaccount~9501bb774c156eb8354dfe489250ea91f757523d70f08ee494bda98bb352003b",
        "UserId": "user1_minter",
        "OrgId": "appdev",
        "TotalAccounts": 2,
        "TotalFtAccounts": 1,
        "AssociatedFtAccounts": [
            {
                "AccountId": "oaccount~1089ee5122f367ee0ca38c6660298f4b81f199627e4f67f3691c0f628237974c",
                "TokenId": "loy1"
            }
        ],
        "AssociatedNftAccount": "oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446"
    },
]
GetAccountDetailsByUser
此方法會傳回指定之使用者的帳戶摘要,以及與使用者關聯之有趣和不可漏洞記號的詳細資訊。
Ctx.ERC1155Account.GetAccountDetailsByUser(orgId string, userId string) (interface{}, error)
參數:
  • orgId string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId string - 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,包含指定使用者的 JSON 帳戶物件和帳戶摘要,以及與使用者相關聯之有趣和不有趣記號的詳細資訊。對於小數的不可行記號,associatedNFTs 區段中的 tokenShare 特性會顯示使用者擁有的共用。
傳回值範例:
{
    "AssociatedFTAccounts": [
        {
            "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
            "Balance": 90,
            "TokenId": "FT"
        },
    ],
    "AssociatedNFTAccount": {
        "AccountId": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "AssociatedNFTs": [
            {
                "NFTTokenId": "FNFT",
                "TokenShare": 230
            },
            {
                "NFTTokenId": "NFT"
            },
            {
                "NFTTokenId": "NFT2"
            }
        ]
    },
    "UserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38"
}
GetUserByAccountId
此方法會傳回指定帳戶 ID 的使用者詳細資料。
Ctx.ERC1155Account.GetUserByAccountById(accountId string) (map[string]interface{}, error)
參數:
  • accountId string - 帳戶的 ID。
傳回值:
  • 成功時,使用者詳細資訊 (orgIduserId) 的 JSON 物件。
傳回值範例:
{
    "OrgId": "appdev",
    "UserId": "idcqa"
}

角色管理方法

AddRoleMember
這個方法會將角色新增至指定的使用者和記號。變數替代字是由變數替代字 ID 指定。記號名稱指定了不可行的記號。
Ctx.ERC1155Token.AddRoleMember(userRole string, userAccountId string, asset interface{}) (interface{}, error)
參數:
  • userRole: string - 要新增至指定使用者的角色名稱。
  • userAccountId: string - 使用者的帳戶 ID。
  • asset: interface{} - 記號資產。
傳回值:
  • 成功時,會出現含有帳戶詳細資訊的訊息。
傳回值範例:
{
    "msg": "Successfully added role minter to oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a (orgId : appdev, userId : idcqa)"
}
IsInRole
此方法會傳回布林值,指示使用者是否具有指定的角色。變數替代字是由變數替代字 ID 指定。記號名稱指定了不可行的記號。
Ctx.ERC1155Token.IsInRole(userRole string, userAccountId string, asset interface{}) (bool, error)
參數:
  • userRole: string - 要搜尋的角色名稱。
  • userAccountId: string - 使用者的帳戶 ID。
  • asset: interface{} - 記號資產。
傳回值範例:
{
    "result": true
}
RemoveRoleMember
此方法會從指定的使用者和記號移除角色。變數替代字是由變數替代字 ID 指定。記號名稱指定了不可行的記號。
Ctx.ERC1155Token.RemoveRoleMember(userRole string, userAccountId string, asset interface{}) (interface{}, error) 
參數:
  • userRole: string - 要移除的角色名稱。
  • userAccountId: string - 使用者的帳戶 ID。
  • asset: interface{} - 記號資產。
傳回值範例:
{
    "msg": "Successfully removed role 'minter' from Account Id: oaccount~ec7e4de2f81e3ea071710e07b6ff7d9346e84ef665ca4650885dbe8c3e2bd4c0 (Org-Id: appdev, User-Id: idcqa)"
}
GetAccountsByRole
此方法會傳回指定角色和權杖的所有帳戶 ID 清單。變數替代字是由變數替代字 ID 指定。記號名稱指定了不可行的記號。
Ctx.ERC1155Role.GetAccountsByRole(roleName string, token interface{}) (interface{}, error)
參數:
  • roleName: string - 要搜尋的角色名稱。
  • token: interface{} - 記號資產。
傳回值範例:
{
    "accounts": [
        "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
        "oaccount~60bb20c14a83f6e426e1437c479c5891e1c6477dfd7ad18b73acac5d80bc504b"
    ]
}
GetUsersByRole
此方法會針對指定的角色和記號,傳回所有使用者的清單。變數替代字是由變數替代字 ID 指定。記號名稱指定了不可行的記號。
Ctx.ERC1155Role.GetUsersByRole(roleName string, token interface{}) (interface{}, error)
參數:
  • roleName: string - 要搜尋的角色名稱。
  • token: interface{} - 記號資產。
傳回值範例:
{
    "Users": [
        {
            "AccountId": "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
            "OrgId": "appdev",
            "UserId": "idcqa"
        },
        {
            "AccountId": "oaccount~60bb20c14a83f6e426e1437c479c5891e1c6477dfd7ad18b73acac5d80bc504b",
            "OrgId": "appdev",
            "UserId": "user1"
        }
    ]
}

交易歷史記錄管理的方法

GetAccountTransactionHistory
此方式會傳回科目交易歷史記錄。此方法只能由鏈碼的 Token Admin 或帳戶擁有者呼叫。對於非功能權杖,只有在連線至遠端 Oracle Blockchain Platform 網路時才能呼叫此方法。
Ctx.ERC1155Account.GetAccountTransactionHistory(tokenAccountId string) (interface{}, error)
參數:
  • accountId string - 使用者帳戶 ID。
傳回值範例:
[
    {
        "Balance": 90,
        "Timestamp": "2023-06-06T11:11:09Z",
        "TokenId": "FNFT",
        "TransactedAccount": "oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446",
        "TransactedAmount": 10,
        "TransactionId": "otransaction~0f4d96fbf8fed88ea8a3133428977721091467c701848d595ebc3fffa88b3657~7c88c736df38d5622512f1e8dcdd50710eb47c953f1ecb24ac44790a9e2f475b",
        "TransactionType": "DEBIT",
        "TriggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38"
    },
    {
        "Timestamp": "2023-06-06T11:11:09Z",
        "TokenId": "NFT",
        "TransactedAccount": "oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446",
        "TransactionId": "otransaction~0f4d96fbf8fed88ea8a3133428977721091467c701848d595ebc3fffa88b3657~178e3730bc5bee50d02f1464a4eebf733a051905f651e5789039adb4a3edc114",
        "TransactionType": "DEBIT",
        "TriggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38"
    },
    {
        "Timestamp": "2023-06-06T11:06:54Z",
        "TokenId": "NFT",
        "TransactedAccount": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "TransactionId": "otransaction~6a13667ea3f6edc4c854e85b127526eccb58783f653c348b42a3869f0f29a4fb~a7cefb22ff39ee7e36967be71de27da6798548c872061a62dabc56d88d50b930",
        "TransactionType": "MINT",
        "TriggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38"
    },
    {
        "Balance": 100,
        "Timestamp": "2023-06-05T16:34:33Z",
        "TokenId": "FNFT",
        "TransactedAccount": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "TransactedAmount": 100,
        "TransactionId": "otransaction~2bc15de1766d582d821bd8d61756bca02837dc683c0aa61f69657ccd1d95e335~e4eb15d9354f694230df8835ade012100d82aa43672896a2c7125a86e3048f9f",
        "TransactionType": "MINT",
        "TriggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38"
    }
]
GetTransactionById
此方法會傳回指定交易 ID 的交易詳細資料。
Ctx.ERC1155Transaction.GetTransactionById(trxId string) (interface{}, error)
參數:
  • trxId string - 交易的 ID。
傳回值範例:
{
    "history": [
        {
            "IsDelete": "false",
            "Timestamp": "2022-12-08T10:45:56Z",
            "TxId": "2da02a53aa1032602df6c68c5628a4ab8b22ba107c0201520ce495948901aa98",
            "Value": {
                "Amount": 5,
                "AssetType": "otransaction",
                "FromAccountId": "oaccount~60bb20c14a83f6e426e1437c479c5891e1c6477dfd7ad18b73acac5d80bc504b",
                "Timestamp": "2022-12-08T10:45:56Z",
                "ToAccountId": "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
                "TokenId": "tokenOne",
                "TransactionId": "otransaction~2da02a53aa1032602df6c68c5628a4ab8b22ba107c0201520ce495948901aa98~9c3ce5f21abd98ca018c196086d73a812f2f49dba323f1de4f6867eecfeec8ff",
                "TransactionType": "TRANSFER",
                "TriggeredByUserAccountId": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc"
            }
        }
    ],
    "transactionId": "otransaction~2da02a53aa1032602df6c68c5628a4ab8b22ba107c0201520ce495948901aa98~9c3ce5f21abd98ca018c196086d73a812f2f49dba323f1de4f6867eecfeec8ff"
}
DeleteHistoricalTransactions
此方法會從狀態資料庫刪除指定時戳之前的交易。
Ctx.ERC1155Transaction.DeleteHistoricalTransactions(referenceTime string) (interface{}, error)
參數:
  • referenceTime string - 將會刪除此時戳之前的所有交易。
傳回值範例:
{
    "Transactions": [
        "otransaction~750f68538451847f57948f7d5261dcb81570cd9e429f928a4cb7bfa76392ecf7"
    ],
    "msg": "Successfuly deleted transaction older than date:2022-04-06T08:17:53Z"
}

記號行為管理方法 - 可調整行為

MintBatch
此方法會在批次作業中建立 (提示) 多重記號。此方法只會建立有趣的記號或小數的不可行記號。

對於有趣的記號,如果在規格檔案中定義了較小的角色,則具有較小角色的任何使用者都可以呼叫此方法。如果不是,任何使用者都可以使用此方法來提示記號。如果在建立或更新記號時指定了該特性,您就不能超過記號的 max_mint_quantity 特性。

對於非功能變數替代字,如果在規格檔案中定義了 minter 角色,則具有 minter 角色的任何使用者都可以呼叫此方法。如果不是,任何使用者都可以使用此方法來提示記號。此外,呼叫者也必須是記號的建立者。沒有可被調解之小數不可行記號的數量上限。

您無法使用此方法來輸入整個不可行記號。

Ctx.ERC1155Token.MintBatch(accountId string, tokens []interface{}, quantities []float64) (interface{}, error)
參數:
  • accountId string - 使用者的帳戶 ID。
  • tokenIds []string - 用於提示記號的記號 ID 清單。
  • quantity []float64 - 對應至權杖 ID 陣列的權杖數量清單。
傳回值:
  • 成功時,包含所提示記號詳細資訊的 JSON 物件。
傳回值範例:
{
    "details": [
        {
            "msg": "Successfully minted 100 tokens of fractional tokenId: plot55 to Org-Id: appdev, User-Id: idcqa"
        },
        {
            "msg": "Successfully minted 100 tokens of tokenId: 'loyalty' to Token-Account-Id 'oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e'"
        }
    ],
    "msg": "Successfully minted batch of tokens for User-Account-Id 'ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38' (Org-Id: 'appdev', User-Id: 'idcqa')"
}

記號行為管理方法 - 可傳輸行為

BatchTransferFrom
此方法會完成批次作業,將記號 ID 清單中指定的記號從某個使用者傳輸給另一個使用者。

對於 NFT,因為方法會傳輸 NFT 的所有權,NFT 的寄件者必須擁有該記號。

對於分數 NFT,如果使用者 (包括記號的建立者) 傳輸他們擁有的所有共用,則會失去記號的所有權。如果將記號的任何共用轉移給使用者,則該使用者會自動成為分數 NFT 的其中一個擁有者。

這個方法不會驗證方法的呼叫程式是指定的寄件者。

Ctx.ERC1155Token.BatchTransferFrom(fromAccountId string, toAccountId string, tokens []interface{}, quantities []float64) (interface{}, error) 
參數:
  • fromUserAccountId string - 目前組織中寄件者與記號擁有者的帳戶 ID。
  • toUserAccountId string - 接收者的帳戶 ID。
  • tokenIds string[] - 要傳輸之記號的記號 ID 清單。
  • quantity float64[] - 與記號 ID 陣列對應的記號數量清單。
傳回值:
  • 成功時,每個權杖傳輸都有詳細資訊的訊息。
傳回值範例:
[
    {
        "msg": "Successfully transferred NFT token: 'FNFT' of '10' quantity from Account-Id: oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371 (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446 (Org-Id: appdev, User-Id: user1_minter)"
    },
    {
        "msg": "Successfully transferred 10 FT token: 'FT' from Account-Id: oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~1089ee5122f367ee0ca38c6660298f4b81f199627e4f67f3691c0f628237974c (Org-Id: appdev, User-Id: user1_minter)"
    },
    {
        "msg": "Successfully transferred NFT token: 'NFT' from Account-Id: oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371 (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446 (Org-Id: appdev, User-Id: user1_minter)"
    }
]
SafeBatchTransferFrom
此方法會完成批次作業,將記號 ID 清單中指定的記號從某個使用者傳輸給另一個使用者。

對於 NFT,因為方法會傳輸 NFT 的所有權,NFT 的寄件者必須擁有該記號。

對於分數 NFT,如果使用者 (包括記號的建立者) 傳輸他們擁有的所有共用,則會失去記號的所有權。如果將記號的任何共用轉移給使用者,則該使用者會自動成為分數 NFT 的其中一個擁有者。

方法的呼叫程式必須是指定的寄件者。

Ctx.ERC1155Token.SafeBatchTransferFrom(fromAccountId string, toAccountId string, tokens []interface{}, quantities []float64) (interface{}, error)
參數:
  • fromUserAccountId string - 目前組織中寄件者與記號擁有者的帳戶 ID。
  • toUserAccountId string - 接收者的帳戶 ID。
  • tokenIds string[] - 要傳輸之記號的記號 ID 清單。
  • quantity float64[] - 與記號 ID 陣列對應的記號數量清單。
傳回值:
  • 成功時,每個權杖傳輸都有詳細資訊的訊息。
傳回值範例:
[
    {
        "msg": "Successfully transferred NFT token: 'FNFT' of '10' quantity from Account-Id: oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371 (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446 (Org-Id: appdev, User-Id: user1_minter)"
    },
    {
        "msg": "Successfully transferred 10 FT token: 'FT' from Account-Id: oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~1089ee5122f367ee0ca38c6660298f4b81f199627e4f67f3691c0f628237974c (Org-Id: appdev, User-Id: user1_minter)"
    },
    {
        "msg": "Successfully transferred NFT token: 'NFT' from Account-Id: oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371 (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446 (Org-Id: appdev, User-Id: user1_minter)"
    }
]
BalanceOfBatch
此方法會完成取得變數替代字帳戶餘額的批次作業。帳戶詳細資料是以三個不同的組織 ID、使用者 ID 和憑證 ID 清單來指定。此方法只能由鏈碼的 Token Admin 或帳戶擁有者呼叫。帳戶擁有者只能查看他們擁有之帳戶的餘額明細。
Ctx.ERC1155Account.BalanceOfBatch(accountIds []string, tokens []interface{}) (interface{}, error)
參數:
  • accountIds []string - 使用者帳戶 ID 的清單。
  • tokenIds []string - 記號 ID 的清單。
傳回值範例:
[
    {
        "OrgId": "appdev",
        "UserId": "idcqa",
        "UserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
        "TokenAccountId": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "TokenId": "FNFT",
        "Balance": 100
    },
    {
        "OrgId": "appdev",
        "UserId": "idcqa",
        "UserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
        "TokenAccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
        "TokenId": "FT",
        "Balance": 50
    },
    {
        "OrgId": "appdev",
        "UserId": "user1_minter",
        "UserAccountId": "ouaccount~9501bb774c156eb8354dfe489250ea91f757523d70f08ee494bda98bb352003b",
        "TokenAccountId": "oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446",
        "TokenId": "FNFT",
        "Balance": 10
    }
]
ExchangeToken
此方法會在指定的帳戶之間交換記號。此方法僅支援在 NFT (整數或分數) 與有趣的記號或有趣的記號與 NFT (整數或分數) 之間交換。只有帳戶擁有者才能呼叫此方法。
Ctx.ERC1155Token.ExchangeToken(fromTokenId string, fromUserAccountId string, fromTokenQuantity float64, toTokenId string, toUserAccountId string, toTokenQuantity float64) (interface{}, error) 
參數:
  • fromTokenId string - 寄件者擁有之記號的 ID。
  • fromUserAccountId string - 寄件者的帳戶 ID。
  • fromTokenQuantity float64 - 寄件者與收件者交換的記號數量。
  • toTokenId string - 接收者擁有之記號的 ID。
  • toUserAccountId string - 接收者的帳戶 ID。
  • toTokenQuantity float64 - 接收者要與寄件者交換的記號數量。
傳回值:
  • 成功時,含有權杖交換詳細資訊的訊息。
傳回值範例:
{
    "msg": "Succesfully exchanged 10 tokens of type 'nonfungible' with tokenId: [r1] from Account 'oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371' (OrgId: appdev, UserId: idcqa) to 10 tokens of type 'fungible' with tokenId: [loy1] from Account 'oaccount~1089ee5122f367ee0ca38c6660298f4b81f199627e4f67f3691c0f628237974c' (OrgId: 'appdev', UserId: 'user1_minter')"
}

記號行為管理方法 - 可燒錄行為

Burn
此方法會停用或燒錄指定的有趣和不可行記號。
Ctx.ERC1155Token.Burn(accountId string, tokens []interface{}, quantities []float64) (interface{}, error)
參數:
  • accountId string - 使用者的帳戶 ID。
  • tokenIds []string - 要燒錄的記號 ID 清單。
  • quantity []float64 - 要燒錄的記號數量清單,對應於記號 ID 陣列。
傳回值:
  • 成功時,會出現一則訊息,內含有關耗盡作業的詳細資料。
傳回值範例:
[
    {
        "msg": "Successfully burned NFT token: 'art' from Account-Id: oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6 (Org-Id: appdev, User-Id: idcqa)"
    },
    {
        "msg": "Successfully burned 2 tokens of tokenId: FT from Account-ID oaccount~9a940587fd322ccc8400233244cd3b13f3aa2a52e418e4c71fb819a2217bc49e (Org-Id: AutoF1377358917, User-Id: idcqa)"
    },
    {
        "msg": "Successfully burned 2 token share of tokenId: FNFT from Account-ID oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a (Org-Id: AutoF1377358917, User-Id: idcqa)"
    }
]