記號分類架構的鷹架式 TypeScript 專案

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

專案會自動產生權杖生命週期類別和函數,包括 CRUD 和非 CRUD 方法。系統會自動支援引數驗證、封送處理 (Marshall) / 取消封送處理 (unmarshal) 以及通透保存功能。

如需結構化專案與與變數替代字無關的方法的相關資訊,請參閱鷹架式 TypeScript 鏈碼專案

Model

每個記號化模型類別都會擴充 Token 類別,然後再擴充 OchainModel 類別。Token 類別是從 ../lib/token 匯入的。「通透持續性功能 (Transparent Persistence Capability)」或簡化的 ORM 會擷取到 OchainModel 類別中。

import * as yup from 'yup';
import { Id, Mandatory, Validate, ReadOnly } from '../lib/decorators';
import { Token } from '../lib/token';
 
@Id('token_id')
export class Digicur extends Token<Digicur> {
 
    public readonly assetType = 'otoken';
 
    @Mandatory()
    @Validate(yup.string().required().matches(/^[A-Za-z0-9][A-Za-z0-9_-]*$/).max(16))
    public token_id: string;
 
    @ReadOnly('digicur')
    public token_name: string;
 
    @Validate(yup.string().trim().max(256))
    public token_desc: string;
 
    @ReadOnly('fungible')
    public token_type: string;
 
    @ReadOnly(["divisible","mintable","transferable","burnable","holdable","roles"])
    public behaviors: string[];
 
    @ReadOnly({minter_role_name: "minter", burner_role_name: "burner", notary_role_name: "notary"})
    public roles: object;
 
    @ReadOnly({max_mint_quantity: 20000})
    public mintable: object;
 
    @ReadOnly({decimal: 1})
    public divisible: object;
 
    @Validate(yup.number())
    public token_to_currency_ratio: number;
 
    @Validate(yup.string())
    public currency_representation: string;
 
}

控制器

main 控制器類別會擴充 OchainController 類別。只有一個主要控制器。

export class DigiCurrCCController extends OchainController{

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

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

自動產生的權杖方法

Blockchain App Builder 會自動產生支援權杖和權杖生命週期的方法。您可以使用這些方法來初始化記號、管理角色和帳戶,以及完成其他記號生命週期工作,而無需進行任何其他編碼。控制器方法必須要有 @Validator(...params) 修飾器才能呼叫。

存取控制管理方法

addTokenAdmin
此方法會將使用者新增為鏈碼的 Token Admin。只有鏈碼的 Token Admin 才能呼叫此方法。
@Validator(yup.string(), yup.string())
public async addTokenAdmin(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization('ADMIN.addAdmin', 'TOKEN');
    return await this.Ctx.Admin.addAdmin(org_id, user_id);
}
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會出現一則訊息,其中包含新增為鏈碼 Token Admin 的使用者詳細資料。
傳回值範例:
{"msg":"Successfully added Admin (Org_Id: Org1MSP, User_Id: User1)"}
removeTokenAdmin
此方法會移除使用者作為鏈碼的 Token Admin。只有鏈碼的 Token Admin 才能呼叫此方法。
@Validator(yup.string(), yup.string())
public async removeTokenAdmin(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization('ADMIN.removeAdmin', 'TOKEN');
    return await this.Ctx.Admin.removeAdmin(org_id, user_id);
}
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會顯示一則訊息,其中包含被移除為鏈碼 Token Admin 的使用者詳細資料。
傳回值範例:
{"msg": "Successfully removed Admin (Org_Id: Org1MSP, User_Id: User1)"}
isTokenAdmin
如果函數的呼叫程式是 Token Admin,則此方法會傳回布林值 true,否則會傳回 falseToken AdminOrg Admin 可以對區塊鏈網路中的任何其他使用者呼叫此功能。其他使用者只能在自己的帳戶上呼叫此方法。
@Validator(yup.string(), yup.string())
  public async isTokenAdmin(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization("ADMIN.isUserTokenAdmin", "TOKEN");
    return await this.Ctx.Auth.isUserTokenAdmin(org_id, user_id);
  }
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 如果呼叫程式是 Token Admin,則方法會傳回 true,否則會傳回 false
getAllTokenAdmins
此方法會傳回鏈碼為 Token Admin 的所有使用者清單。只有鏈碼的 Token Admin 或任何 Org Admin 才能呼叫此方法。
@Validator()
public async getAllTokenAdmins() {
    await this.Ctx.Auth.checkAuthorization('ADMIN.getAllAdmins', 'TOKEN');
    return await this.Ctx.Admin.getAllAdmins();
}
參數:
傳回值:
  • 成功時,JSON 格式的 admins 陣列包含 orgIduserId 物件。
傳回值範例:
{"admins":[{"org_id":"Org1MSP","user_id":"admin"}]}
addOrgAdmin
此方法會將使用者新增為組織的 Org Admin。只有鏈碼的 Token Admin 或指定組織的 Org Admin 才能呼叫此方法。
@Validator(yup.string(), yup.string())
  public async addOrgAdmin(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization("ADMIN.addOrgAdmin", "TOKEN", { org_id });
    return await this.Ctx.Admin.addOrgAdmin(org_id, user_id);
  }
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會出現一則訊息,其中包含新增為組織 Org Admin 的使用者詳細資訊。
傳回值範例:
{
    "msg": "Successfully added Org Admin (Org_Id: Org1MSP, User_Id: orgAdmin)"
}
removeOrgAdmin
此方法會移除使用者作為組織的 Org Admin。只有鏈碼的 Token Admin 或指定的組織 Org Admin 才能呼叫此方法。
@Validator(yup.string(), yup.string())
  public async removeOrgAdmin(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization("ADMIN.removeOrgAdmin", "TOKEN", { org_id });
    return await this.Ctx.Admin.removeOrgAdmin(org_id, user_id);
  }
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會顯示一則訊息,其中包含作為組織 Org Admin 移除之使用者的詳細資料。
傳回值範例:
{
  "msg": "Successfully removed Org Admin (Org_Id Org1MSP User_Id orgAdmin)"
}
getOrgAdmins
此方法會傳回屬於組織 Org Admin 的所有使用者清單。只有鏈碼的 Token Admin 或任何組織的 Org Admin 才能呼叫此方法。
  @Validator()
  public async getOrgAdmins() {
    await this.Ctx.Auth.checkAuthorization("ADMIN.getOrgAdmins", "TOKEN");
    return await this.Ctx.Admin.getAllOrgAdmins();
  }
參數:
傳回值:
  • 成功時,JSON 格式的陣列包含 orgIduserId 物件。
傳回值範例:
{
    "admins": [
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin"
        },
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin1"
        },
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin2"
        }
    ]
}
addTokenAdmin
此方法會將使用者新增為鏈碼的 Token Admin。只有鏈碼的 Token Admin 才能呼叫此方法。
@Validator(yup.string(), yup.string())
public async addTokenAdmin(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization('ADMIN.addAdmin', 'TOKEN');
    return await this.Ctx.Admin.addAdmin(org_id, user_id);
}
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會出現一則訊息,其中包含新增為鏈碼 Token Admin 的使用者詳細資料。
傳回值範例:
{"msg":"Successfully added Admin (Org_Id: Org1MSP, User_Id: User1)"}
removeTokenAdmin
此方法會移除使用者作為鏈碼的 Token Admin。只有鏈碼的 Token Admin 才能呼叫此方法。
@Validator(yup.string(), yup.string())
public async removeTokenAdmin(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization('ADMIN.removeAdmin', 'TOKEN');
    return await this.Ctx.Admin.removeAdmin(org_id, user_id);
}
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會顯示一則訊息,其中包含被移除為鏈碼 Token Admin 的使用者詳細資料。
傳回值範例:
{"msg": "Successfully removed Admin (Org_Id: Org1MSP, User_Id: User1)"}
isTokenAdmin
如果函數的呼叫程式是 Token Admin,則此方法會傳回布林值 true,否則會傳回 falseToken AdminToken Auditor、任何 Org Admin 或任何 Org Auditor 都可以對區塊鏈網路中的任何其他使用者呼叫此功能。其他使用者只能在自己的帳戶上呼叫此方法。
@Validator(yup.string(), yup.string())
  public async isTokenAdmin(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization("ADMIN.isUserTokenAdmin", "TOKEN");
    return await this.Ctx.Auth.isUserTokenAdmin(org_id, user_id);
  }
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 如果呼叫程式是 Token Admin,則方法會傳回 true,否則會傳回 false
getAllTokenAdmins
此方法會傳回鏈碼為 Token Admin 的所有使用者清單。只有鏈碼的 Token AdminToken Auditor 才能呼叫此方法。
@Validator()
public async getAllTokenAdmins() {
    await this.Ctx.Auth.checkAuthorization('ADMIN.getAllAdmins', 'TOKEN');
    return await this.Ctx.Admin.getAllAdmins();
}
參數:
傳回值:
  • 成功時,JSON 格式的 admins 陣列包含 orgIduserId 物件。
傳回值範例:
{"admins":[{"org_id":"Org1MSP","user_id":"admin"}]}
addOrgAdmin
此方法會將使用者新增為組織的 Org Admin。只有鏈碼的 Token Admin 或指定組織的 Org Admin 才能呼叫此方法。
@Validator(yup.string(), yup.string())
  public async addOrgAdmin(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization("ADMIN.addOrgAdmin", "TOKEN", { org_id });
    return await this.Ctx.Admin.addOrgAdmin(org_id, user_id);
  }
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會出現一則訊息,其中包含新增為組織 Org Admin 的使用者詳細資訊。
傳回值範例:
{
    "msg": "Successfully added Org Admin (Org_Id: Org1MSP, User_Id: orgAdmin)"
}
removeOrgAdmin
此方法會移除使用者作為組織的 Org Admin。只有鏈碼的 Token Admin 或指定的組織 Org Admin 才能呼叫此方法。
@Validator(yup.string(), yup.string())
  public async removeOrgAdmin(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization("ADMIN.removeOrgAdmin", "TOKEN", { org_id });
    return await this.Ctx.Admin.removeOrgAdmin(org_id, user_id);
  }
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會顯示一則訊息,其中包含作為組織 Org Admin 移除之使用者的詳細資料。
傳回值範例:
{
  "msg": "Successfully removed Org Admin (Org_Id Org1MSP User_Id orgAdmin)"
}
getOrgAdmins
此方法會傳回屬於組織 Org Admin 的所有使用者清單。只有 Token AdminToken Auditor、任何 Org Admin 或任何 Org Auditor 才能呼叫此方法。
  @Validator()
  public async getOrgAdmins() {
    await this.Ctx.Auth.checkAuthorization("ADMIN.getOrgAdmins", "TOKEN");
    return await this.Ctx.Admin.getAllOrgAdmins();
  }
參數:
傳回值:
  • 成功時,JSON 格式的陣列包含 orgIduserId 物件。
傳回值範例:
{
    "admins": [
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin"
        },
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin1"
        },
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin2"
        }
    ]
}
addTokenAuditor
此方法會將使用者新增為鏈碼的 Token Auditor。只有鏈碼的 Token Admin 才能呼叫此方法。
public async addTokenAuditor(org_id: string, user_id: string)
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會出現一則訊息,其中包含新增為鏈碼 Token Auditor 的使用者詳細資料。
傳回值範例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "txid": "cd81f6c4c9e7c18ece357dbf5c139ef66ef2d6566be3b14de5f6d0a3fd4bb2f0",
        "payload": {
            "msg": "Successfully added Token Auditor (Org_Id: CB, User_Id: cb)"
        },
        "encode": "JSON",
        "sourceURL": "cb-oabcs1-bom.blockchain.ocp.example.com:20009",
        "blockNumber": 196
    }
}
removeTokenAuditor
此方法會移除使用者作為鏈碼的 Token Auditor。只有鏈碼的 Token Admin 才能呼叫此方法。
public async removeTokenAuditor(org_id: string, user_id: string)
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會顯示一則訊息,其中包含被移除為鏈碼 Token Auditor 的使用者詳細資料。
傳回值範例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "txid": "a886a6040fbc76374a3c78c89ab0ffc9f7b8391cc5239b169bf3b878cf40c67b",
        "payload": {
            "msg": "Successfully removed Token Auditor (Org_Id: CB, User_Id: cb)"
        },
        "encode": "JSON",
        "sourceURL": "cb-oabcs1-bom.blockchain.ocp.example.com:20010",
        "blockNumber": 219
    }
}
getTokenAuditors
此方法會傳回鏈碼的所有 Token Auditors。只有鏈碼的 Token AdminToken Auditor 才能呼叫此方法。
public async getTokenAuditors()
傳回值範例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "payload": {
            "auditors": [
                {
                    "org_id": "CB",
                    "user_id": "auditor_user_cb"
                }
            ]
        },
        "encode": "JSON"
    }
}
addOrgAuditor
此方法會將使用者新增為鏈碼的 Org Auditor。只有鏈碼的 Token AdminOrg Admin 才能呼叫此方法。
public async addOrgAuditor(org_id: string, user_id: string)
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會出現一則訊息,其中包含新增為鏈碼 Org Auditor 的使用者詳細資料。
傳回值範例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "txid": "44bbad35a1478cb714e32f7cfd551897868a203520aab9cea5771d3aadc1cf03",
        "payload": {
            "msg": "Successfully added Org Auditor (Org_Id: CB, User_Id: cb)"
        },
        "encode": "JSON",
        "sourceURL": "cb-oabcs1-bom.blockchain.ocp.example.com:20009",
        "blockNumber": 198
    }
}
removeOrgAuditor
此方法會移除使用者作為鏈碼的 Org Auditor。只有鏈碼的 Token AdminOrg Admin 才能呼叫此方法。
public async removeOrgAuditor(org_id: string, user_id: string)
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會顯示一則訊息,其中包含被移除為鏈碼 Org Auditor 的使用者詳細資料。
傳回值範例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "txid": "c3bc720461004a53b37c68d4bb264858b88d980bc093a0a3ebb62a32974fb306",
        "payload": {
            "msg": "Successfully removed Org Auditor (Org_Id: CB, User_Id: cb)"
        },
        "encode": "JSON",
        "sourceURL": "cb-oabcs1-bom.blockchain.ocp.example.com:20010",
        "blockNumber": 221
    }
}
getOrgAuditors
此方法會傳回鏈碼的所有 Org Auditors。只有 Token AdminToken AuditorOrg AdminOrg Auditor 才能呼叫此方法。
public async getOrgAuditors()
傳回值範例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "payload": {
            "auditors": [
                {
                    "org_id": "FI1",
                    "user_id": "auditor_user_fi1"
                },
                {
                    "org_id": "FI2",
                    "user_id": "auditor_user_fi2"
                }
            ]
        },
        "encode": "JSON"
    }
}

權杖組態管理方法

init
部署或升級鏈碼時,就會呼叫此方法。每個 Token Admin 都是由必要 adminList 參數中的 user_idorg_id 資訊所識別。user_id 是執行處理擁有者或登入執行處理之使用者的使用者名稱或電子郵件 ID。org_id 是目前網路組織中使用者的成員服務提供者 (MSP) ID。
任何 Token Admin 使用者都可以透過呼叫 addAdminremoveAdmin 方法來新增和移除其他 Token Admin 使用者。
public async init(adminList: TokenAdminAsset[]) {
    await this.Ctx.Admin.initAdmin(adminList);
    return;
}
參數:
  • adminList array – 指定權杖管理員清單的 {user_id, org_id} 資訊陣列。adminList 陣列是必要參數。
參數範例:macOS 與 Linux CLI:
'[{"user_id":"userid", "org_id":"OrgMSPId"}]'
參數範例:Microsoft Windows CLI:
"[{\"user_id\":\"userid\", \"org_id\":\"OrgMSPId\"}]"
Oracle Blockchain Platform 主控台參數範例:
["[{\"user_id\":\"userid\", \"org_id\":\"OrgMSPId\"}]"]
initialize<Token Name>Token
此方法會建立記號並初始化記號特性。資產及其特性會儲存在狀態資料庫中。只有鏈碼的 Token Admin 才能呼叫此方法。
@Validator(Digicur)
    public async initializeDigicurToken(token_asset: Digicur) {
        await this.Ctx.Auth.checkAuthorization('TOKEN.save', 'TOKEN');
        return await this.Ctx.Token.save(token_asset)
    }
參數:
  • asset <Token Class> – 將記號資產當作參數傳遞給此方法。記號資產的特性會有所不同,並在記號規格檔案中說明。請勿在規格檔案中包含標示為唯讀的參數。

    如果您使用 Visual Studio Code 與 CLI 或 Postman 集合,請以不同的格式指定 asset 參數。

    Visual Studio 程式碼:使用 GUI 傳送對應至權杖類別欄位的個別參數。

    CLI / Postman:傳送包含記號規格欄位的序列化 JSON 字串,如下列範例所示。

    "{\"token_id\":\"USD\",\"token_desc\":\"token_desc value\",\"Currency_Name\":\"Currency_Name value\"}"

傳回值:
  • 成功時,所建立權杖資產的 JSON 表示法。
傳回值範例:
{
    "assetType": "otoken",
    "token_id": "digiCurr101",
    "token_name": "digicur",
    "token_type": "fungible",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter"
    },
    "mintable": {
        "max_mint_quantity": 1000
    },
    "divisible": {
        "decimal": 2
    },
    "currency_name": "DOLLAR",
    "token_to_currency_ratio": 1
}
update<Token Name>Token
此方法會更新記號特性。記號資產建立後,只能更新 token_desc 特性和自訂特性。只有鏈碼的 Token Admin 才能呼叫此方法。
@Validator(Digicur)
public async updateDigicurToken(token_asset: Digicur) {
    await this.Ctx.Auth.checkAuthorization('TOKEN.update', 'TOKEN');
    return await this.Ctx.Token.update(token_asset);
}
參數:
  • asset <Token Class> – 將記號資產當作參數傳遞給此方法。記號資產的特性會有所不同,並在記號規格檔案中說明。請勿在規格檔案中包含標示為唯讀的參數。

    如果您使用 Visual Studio Code 與 CLI 或 Postman 集合,請以不同的格式指定 asset 參數。

    Visual Studio 程式碼:使用 GUI 傳送對應至權杖類別欄位的個別參數。

    CLI / Postman:傳送包含記號規格欄位的序列化 JSON 字串,如下列範例所示。

    "{\"token_id\":\"USD\",\"token_desc\":\"token_desc value\",\"Currency_Name\":\"Currency_Name value\"}"

傳回值:
  • 成功時,更新的權杖資產 JSON 表示法。
傳回值範例:
{
    "assetType": "otoken",
    "token_id": "digiCurr101",
    "token_name": "digicur",
    "token_desc": "Digital Currency equiv of dollar",
    "token_type": "fungible",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter"
    },
    "mintable": {
        "max_mint_quantity": 1000
    },
    "divisible": {
        "decimal": 2
    },
    "currency_name": "DOLLAR",
    "token_to_currency_ratio": 1
}
getTokenDecimals
此方法會傳回針對分數記號設定的小數位數。如果未指定記號的 divisible 行為,則預設值為 0。只有鏈碼的 Token AdminOrg Admin 才能呼叫此方法。
@Validator(yup.string())
public async getTokenDecimals(token_id: string) {
    const token_asset = await this.getTokenObject(token_id);
    await this.Ctx.Auth.checkAuthorization('TOKEN.getDecimals', 'TOKEN');
    return {
        msg: `Token Id: ${token_id} has ${this.Ctx.Token.getDecimals(token_asset)} decimal places.`
    };
}
參數:
  • token_id: string – 記號的 ID。
傳回值:
  • 成功時,會顯示記號小數位數的 JSON 字串。
傳回值範例:
{"msg":"Token Id: digiCurr101 has 1 decimal places."}
getTokenById
如果某個記號物件存在於狀態資料庫中,這個方法會傳回該物件。只有鏈碼的 Token AdminOrg Admin 才能呼叫此方法。
@Validator(yup.string())
public async getTokenById(token_id: string) {
    await this.Ctx.Auth.checkAuthorization('TOKEN.get', 'TOKEN');
    const token = await this.getTokenObject(token_id);
    return token;
}
參數:
  • token_id: string – 記號的 ID。
傳回值:
  • 成功時,代表權杖資產的 JSON 物件。
傳回值範例:
{
    "assetType": "otoken",
    "token_id": "digiCurr101",
    "token_name": "digicur",
    "token_desc": "Digital Currency equiv of dollar",
    "token_type": "fungible",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter"
        "burner_role_name": "burner",
        "notary_role_name": "notary"
    },
    "mintable": {
        "max_mint_quantity": 2000
    },
    "divisible": {
        "decimal": 1
    },
    "currency_name": "DOLLAR",
    "token_to_currency_ratio": 1
}
getTokenHistory
此方法會傳回所指定記號 ID 的記號歷史記錄。所有使用者都可以呼叫此方法。
  @Validator(yup.string())
  public async getTokenHistory(tokenId: string) {
    await this.Ctx.Auth.checkAuthorization("TOKEN.getTokenHistory", "TOKEN");
    return await this.Ctx.Token.history(tokenId);
  }
參數:
  • tokenId: string – 記號的 ID。
傳回值:
  • 成功時,代表權杖歷史記錄的 JSON 物件。
傳回值範例:

[
    {
        "trxId": "0d75f09446a60088afb948c6aca046e261fddcd43df416076201cdc5565f1a35",
        "timeStamp": "2023-09-01T16:48:41.000Z",
        "value": {
            "assetType": "otoken",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "token_desc": "updatedDesc",
            "token_standard": "ttf+",
            "token_type": "fungible",
            "token_unit": "fractional",
            "behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter"
            },
            "mintable": {
                "max_mint_quantity": 1000
            },
            "divisible": {
                "decimal": 2
            }
        }
    },
    {
        "trxId": "3666344878b043b65d5b821cc79c042ba52aec467618800df5cf14eac69f72fa",
        "timeStamp": "2023-08-31T20:24:55.000Z",
        "value": {
            "assetType": "otoken",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "token_standard": "ttf+",
            "token_type": "fungible",
            "token_unit": "fractional",
            "behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter"
            },
            "mintable": {
                "max_mint_quantity": 1000
            },
            "divisible": {
                "decimal": 2
            }
        }
    }
]
getAllTokens
這個方法會傳回狀態資料庫中儲存的所有記號。只有鏈碼的 Token AdminOrg Admin 才能呼叫此方法。此方法使用 Berkeley DB SQL RTF 查詢,而且只能在連線至遠端 Oracle Blockchain Platform 網路時呼叫。
@Validator()
public async getAllTokens() {
    await this.Ctx.Auth.checkAuthorization('TOKEN.getAllTokens', 'TOKEN');
    return await this.Ctx.Token.getAllTokens();
}
參數:
傳回值:
  • 成功時,代表所有權杖資產的 JSON 物件。
getTokensByName
此方法會傳回具有指定名稱的所有記號物件。只有鏈碼的 Token AdminOrg Admin 才能呼叫此方法。此方法使用 Berkeley DB SQL RTF 查詢,而且只能在連線至遠端 Oracle Blockchain Platform 網路時呼叫。
@Validator(yup.string())
public async getTokensByName(token_name: string) {
    await this.Ctx.Auth.checkAuthorization('TOKEN.getTokensByName', 'TOKEN');
    return await this.Ctx.Token.getTokensByName(token_name);
}
參數:
  • token_name: string – 要擷取之記號的名稱。名稱對應至規格檔案中的 token_name 特性。此值為記號的類別名稱。
傳回值:
  • 成功時,所有與名稱相符之記號資產的 JSON 物件。
init
部署或升級鏈碼時,就會呼叫此方法。每個 Token Admin 都是由必要 adminList 參數中的 user_idorg_id 資訊所識別。user_id 是執行處理擁有者或登入執行處理之使用者的使用者名稱或電子郵件 ID。org_id 是目前網路組織中使用者的成員服務提供者 (MSP) ID。
任何 Token Admin 使用者都可以透過呼叫 addAdminremoveAdmin 方法來新增和移除其他 Token Admin 使用者。
public async init(adminList: TokenAdminAsset[]) {
    await this.Ctx.Admin.initAdmin(adminList);
    return;
}
參數:
  • adminList array – 指定權杖管理員清單的 {user_id, org_id} 資訊陣列。adminList 陣列是必要參數。
參數範例:macOS 與 Linux CLI:
'[{"user_id":"userid", "org_id":"OrgMSPId"}]'
參數範例:Microsoft Windows CLI:
"[{\"user_id\":\"userid\", \"org_id\":\"OrgMSPId\"}]"
Oracle Blockchain Platform 主控台參數範例:
["[{\"user_id\":\"userid\", \"org_id\":\"OrgMSPId\"}]"]
initialize<Token Name>Token
此方法會建立記號並初始化記號特性。資產及其特性會儲存在狀態資料庫中。只有鏈碼的 Token Admin 才能呼叫此方法。
@Validator(Digicur)
    public async initializeDigicurToken(token_asset: Digicur) {
        await this.Ctx.Auth.checkAuthorization('TOKEN.save', 'TOKEN');
        return await this.Ctx.Token.save(token_asset)
    }
參數:
  • asset <Token Class> – 將記號資產當作參數傳遞給此方法。記號資產的特性會有所不同,並在記號規格檔案中說明。請勿在規格檔案中包含標示為唯讀的參數。

    如果您使用 Visual Studio Code 與 CLI 或 Postman 集合,請以不同的格式指定 asset 參數。

    Visual Studio 程式碼:使用 GUI 傳送對應至權杖類別欄位的個別參數。

    CLI / Postman:傳送包含記號規格欄位的序列化 JSON 字串,如下列範例所示。

    "{\"token_id\":\"USD\",\"token_desc\":\"token_desc value\",\"Currency_Name\":\"Currency_Name value\"}"

傳回值:
  • 成功時,所建立權杖資產的 JSON 表示法。
傳回值範例:
{
    "assetType": "otoken",
    "token_id": "digiCurr101",
    "token_name": "digicur",
    "token_type": "fungible",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter"
    },
    "mintable": {
        "max_mint_quantity": 1000
    },
    "divisible": {
        "decimal": 2
    },
    "currency_name": "DOLLAR",
    "token_to_currency_ratio": 1
}
update<Token Name>Token
此方法會更新記號特性。記號資產建立後,只能更新 token_desc 特性和自訂特性。只有鏈碼的 Token Admin 才能呼叫此方法。
@Validator(Digicur)
public async updateDigicurToken(token_asset: Digicur) {
    await this.Ctx.Auth.checkAuthorization('TOKEN.update', 'TOKEN');
    return await this.Ctx.Token.update(token_asset);
}
參數:
  • asset <Token Class> – 將記號資產當作參數傳遞給此方法。記號資產的特性會有所不同,並在記號規格檔案中說明。請勿在規格檔案中包含標示為唯讀的參數。

    如果您使用 Visual Studio Code 與 CLI 或 Postman 集合,請以不同的格式指定 asset 參數。

    Visual Studio 程式碼:使用 GUI 傳送對應至權杖類別欄位的個別參數。

    CLI / Postman:傳送包含記號規格欄位的序列化 JSON 字串,如下列範例所示。

    "{\"token_id\":\"USD\",\"token_desc\":\"token_desc value\",\"Currency_Name\":\"Currency_Name value\"}"

傳回值:
  • 成功時,更新的權杖資產 JSON 表示法。
傳回值範例:
{
    "assetType": "otoken",
    "token_id": "digiCurr101",
    "token_name": "digicur",
    "token_desc": "Digital Currency equiv of dollar",
    "token_type": "fungible",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter"
    },
    "mintable": {
        "max_mint_quantity": 1000
    },
    "divisible": {
        "decimal": 2
    },
    "currency_name": "DOLLAR",
    "token_to_currency_ratio": 1
}
getTokenDecimals
此方法會傳回針對分數記號設定的小數位數。如果未指定記號的 divisible 行為,則預設值為 0。只有 Token AdminToken AuditorOrg AdminOrg Auditor 才能呼叫此方法。
@Validator(yup.string())
public async getTokenDecimals(token_id: string) {
    const token_asset = await this.getTokenObject(token_id);
    await this.Ctx.Auth.checkAuthorization('TOKEN.getDecimals', 'TOKEN');
    return {
        msg: `Token Id: ${token_id} has ${this.Ctx.Token.getDecimals(token_asset)} decimal places.`
    };
}
參數:
  • token_id: string – 記號的 ID。
傳回值:
  • 成功時,會顯示記號小數位數的 JSON 字串。
傳回值範例:
{"msg":"Token Id: digiCurr101 has 1 decimal places."}
getTokenById
如果某個記號物件存在於狀態資料庫中,這個方法會傳回該物件。只有 Token AdminToken AuditorOrg AdminOrg Auditor 才能呼叫此方法。
@Validator(yup.string())
public async getTokenById(token_id: string) {
    await this.Ctx.Auth.checkAuthorization('TOKEN.get', 'TOKEN');
    const token = await this.getTokenObject(token_id);
    return token;
}
參數:
  • token_id: string – 記號的 ID。
傳回值:
  • 成功時,代表權杖資產的 JSON 物件。
傳回值範例:
{
    "assetType": "otoken",
    "token_id": "digiCurr101",
    "token_name": "digicur",
    "token_desc": "Digital Currency equiv of dollar",
    "token_type": "fungible",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter"
        "burner_role_name": "burner",
        "notary_role_name": "notary"
    },
    "mintable": {
        "max_mint_quantity": 2000
    },
    "divisible": {
        "decimal": 1
    },
    "currency_name": "DOLLAR",
    "token_to_currency_ratio": 1
}
getTokenHistory
此方法會傳回所指定記號 ID 的記號歷史記錄。只有 Token AdminToken AuditorOrg AdminOrg Auditor 才能呼叫此方法。
  @Validator(yup.string())
  public async getTokenHistory(tokenId: string) {
    await this.Ctx.Auth.checkAuthorization("TOKEN.getTokenHistory", "TOKEN");
    return await this.Ctx.Token.history(tokenId);
  }
參數:
  • tokenId: string – 記號的 ID。
傳回值:
  • 成功時,代表權杖歷史記錄的 JSON 物件。
傳回值範例:

[
    {
        "trxId": "0d75f09446a60088afb948c6aca046e261fddcd43df416076201cdc5565f1a35",
        "timeStamp": "2023-09-01T16:48:41.000Z",
        "value": {
            "assetType": "otoken",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "token_desc": "updatedDesc",
            "token_standard": "ttf+",
            "token_type": "fungible",
            "token_unit": "fractional",
            "behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter"
            },
            "mintable": {
                "max_mint_quantity": 1000
            },
            "divisible": {
                "decimal": 2
            }
        }
    },
    {
        "trxId": "3666344878b043b65d5b821cc79c042ba52aec467618800df5cf14eac69f72fa",
        "timeStamp": "2023-08-31T20:24:55.000Z",
        "value": {
            "assetType": "otoken",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "token_standard": "ttf+",
            "token_type": "fungible",
            "token_unit": "fractional",
            "behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter"
            },
            "mintable": {
                "max_mint_quantity": 1000
            },
            "divisible": {
                "decimal": 2
            }
        }
    }
]
getAllTokens
這個方法會傳回狀態資料庫中儲存的所有記號。只有 Token AdminToken AuditorOrg AdminOrg Auditor 才能呼叫此方法。此方法使用 Berkeley DB SQL RTF 查詢,而且只能在連線至遠端 Oracle Blockchain Platform 網路時呼叫。
@Validator()
public async getAllTokens() {
    await this.Ctx.Auth.checkAuthorization('TOKEN.getAllTokens', 'TOKEN');
    return await this.Ctx.Token.getAllTokens();
}
參數:
傳回值:
  • 成功時,代表所有權杖資產的 JSON 物件。
getTokensByName
此方法會傳回具有指定名稱的所有記號物件。只有 Token AdminToken AuditorOrg AdminOrg Auditor 才能呼叫此方法。此方法使用 Berkeley DB SQL RTF 查詢,而且只能在連線至遠端 Oracle Blockchain Platform 網路時呼叫。
@Validator(yup.string())
public async getTokensByName(token_name: string) {
    await this.Ctx.Auth.checkAuthorization('TOKEN.getTokensByName', 'TOKEN');
    return await this.Ctx.Token.getTokensByName(token_name);
}
參數:
  • token_name: string – 要擷取之記號的名稱。名稱對應至規格檔案中的 token_name 特性。此值為記號的類別名稱。
傳回值:
  • 成功時,所有與名稱相符之記號資產的 JSON 物件。

帳戶管理方法

createAccount
這個方法會為指定的使用者與記號建立帳號。必須為任何需要記號的使用者建立帳戶。科目可追蹤餘額、保留餘額及交易歷史記錄。帳戶 ID 是一組英數字元,前面加上 oaccount~<token asset name>~,後面接著執行處理擁有者的使用者名稱或電子郵件 ID (user_id) 雜湊,或登入執行處理的使用者 (目前網路組織中使用者的成員服務提供者 ID (org_id)。只有鏈碼的 Token Admin 或指定的組織 Org Admin 才能呼叫此方法。
  @Validator(yup.string(), yup.string(), yup.string())
  public async createAccount(org_id: string, user_id: string, token_type: string) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.createAccount", "TOKEN", { org_id });
    return await this.Ctx.Account.createAccount(org_id, user_id, token_type);
  }
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
  • token_type: string – 記號的類型,必須是 fungible
傳回值:
  • 成功時,所建立帳戶的 JSON 物件。bapAccountVersion 參數是在科目物件中定義供內部使用。
傳回值範例:
{
  "assetType": "oaccount",
  "account_id": "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
  "bapAccountVersion": 0,
  "user_id": "admin",
  "org_id": "Org1MSP",
  "token_type": "fungible",
  "token_id": "",
  "token_name": "",
  "balance": 0,
  "onhold_balance": 0
}
associateTokenToAccount
此方法會將有趣的記號與帳戶建立關聯。只有鏈碼的 Token Admin 或相關組織的 Org Admin 才能呼叫此方法。
  @Validator(yup.string(), yup.string())
  public async associateTokenToAccount(account_id: string, token_id: string) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.associateToken", "TOKEN", { account_id });
    return await this.Ctx.Account.associateToken(account_id, token_id);
  }
參數:
  • account_id: string – 帳戶的 ID。
  • token_id: string – 記號的 ID。
傳回值:
  • 成功時,已更新帳戶的 JSON 物件。bapAccountVersion 參數是在科目物件中定義供內部使用。
傳回值範例:
{
    "assetType": "oaccount",
    "account_id": "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
    "bapAccountVersion": 0,
    "user_id": "admin",
    "org_id": "Org1MSP",
    "token_type": "fungible",
    "token_id": "fungible",
    "token_name": "fiatmoneytok",
    "balance": 0,
    "onhold_balance": 0
}
getAccount
此方法會傳回指定使用者和記號的帳戶詳細資訊。只有鏈碼的 Token Admin、指定組織的 Org Admin 或帳戶的 AccountOwner 才能呼叫此方法。
@Validator(yup.string(), yup.string(), yup.string())
public async getAccount(token_id: string, org_id: string, user_id: string) {
  const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
  await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAccount", "TOKEN", { account_id });
  return await this.Ctx.Account.getAccountWithStatus(account_id);
}
參數:
  • token_id: string – 記號的 ID。
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,包含下列特性的 JSON 帳戶物件:
  • account_id – 使用者帳戶的 ID。
  • user_id – 使用者的使用者名稱或電子郵件 ID。
  • org_id – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • token_id – 記號的 ID。
  • token_name – 權杖的名稱。
  • balance – 帳戶的目前餘額。
  • onhold_balance – 帳戶的目前保留結餘。
  • bapAccountVersion – 內部使用的帳戶物件參數。
  • status – 使用者帳戶的目前狀態。
傳回值範例:
{
  "bapAccountVersion": 0,
  "assetType": "oaccount",
  "status": "active",
  "account_id": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
  "user_id": "idcqa",
  "org_id": "appdev",
  "token_type": "fungible",
  "token_id": "t1",
  "token_name": "obptok",
  "balance": 0,
  "onhold_balance": 0
}
getAccountHistory
此方法會傳回指定使用者和權杖的帳戶歷史記錄詳細資訊。只有鏈碼的 Token Admin 或帳戶的 AccountOwner 才能呼叫此方法。
  @Validator(yup.string(), yup.string(), yup.string())
  public async getAccountHistory(token_id: string, org_id: string, user_id: string) {
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.history", "TOKEN", { account_id });
    return await this.Ctx.Account.history(account_id);
  }
參數:
  • token_id: string – 記號的 ID。
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,包含下列特性的 JSON 帳戶物件陣列:
  • trxId - 分類帳所傳回之交易的交易 ID。
  • timeStamp – 交易的時間。
  • value – 帳戶物件的 JSON 字串。
傳回值範例:
[
    {
      "trxId":"2gsdh17fff222467e5667be042e33ce18e804b3e065cca15de306f837e416d7c3e",
      "timeStamp":1629718288,
      "value":{
         "assetType":"oaccount",
         "account_id":"oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
         "user_id":"user1",
         "org_id":"Org1MSP",
         "token_id":"digiCurr101",
         "token_name":"digicur",
         "balance":100,
         "onhold_balance":0,
         "bapAccountVersion": 1
   },
   {
      "trxId":"9fd07fff222467e5667be042e33ce18e804b3e065cca15de306f837e416d7c3e",
      "timeStamp":1629718288,
      "value":{
         "assetType":"oaccount",
         "account_id":"oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
         "user_id":"user1",
         "org_id":"Org1MSP",
         "token_id":"digiCurr101",
         "token_name":"digicur",
         "balance":0,
         "onhold_balance":0,
         "bapAccountVersion": 0
      }
   }
]
getAccountOnHoldBalance
此方法會傳回指定帳戶與變數替代字的目前保留餘額。只有鏈碼的 Token Admin、指定組織的 Org Admin 或帳戶的 AccountOwner 才能呼叫此方法。
  @Validator(yup.string(), yup.string(), yup.string())
  public async getAccountOnHoldBalance(token_id: string, org_id: string, user_id: string) {
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAccountOnHoldBalance", "TOKEN", { account_id });
    return await this.Ctx.Account.getAccountOnHoldBalance(account_id);
  }
參數:
  • token_id: string – 記號的 ID。
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,代表目前保留餘額的 JSON。
傳回值範例:
{"msg":"Total Holding Balance is: 0","holding_balance":0}
getAllAccounts
這個方法會傳回所有帳號的清單。只有鏈碼的 Token Admin 才能呼叫此方法。此方法使用 Berkeley DB SQL RTF 查詢,而且只能在連線至遠端 Oracle Blockchain Platform 網路時呼叫。
@Validator()
public async getAllAccounts() {
    await this.Ctx.Auth.checkAuthorization('ACCOUNT.getAllAccounts', 'TOKEN');
    return await this.Ctx.Account.getAllAccounts();
}
參數:
傳回值:
  • 成功時,所有帳戶的 JSON 陣列。
getUserByAccountId
此方法會傳回指定帳戶的使用者詳細資訊 (org_iduser_id)。鏈碼的任何使用者都可以呼叫這個方法。
@Validator(yup.string())
public async getUserByAccountId(account_id: string) {
    return await this.Ctx.Account.getUserByAccountId(account_id);
}
參數:
  • account_id: string – 帳戶的 ID。
傳回值:
  • 成功時,使用者詳細資訊 (org_idtoken_iduser_id) 的 JSON 物件。
傳回值範例:
{
    "token_id": "digiCurr101",
    "user_id": "user1",
    "org_id": "Org1MSP"
}
getAccountBalance
此方法會傳回指定帳戶與變數替代字的目前餘額。只有鏈碼的 Token Admin、指定組織的 Org Admin 或帳戶的 AccountOwner 才能呼叫此方法。
  @Validator(yup.string(), yup.string(), yup.string())
  public async getAccountBalance(token_id: string, org_id: string, user_id: string) {
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAccountBalance", "TOKEN", { account_id });
    return await this.Ctx.Account.getAccountBalance(account_id);
  }
參數:
  • token_id: string – 記號的 ID。
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,代表目前帳戶餘額的 JSON。
傳回值範例:
{"msg":"Current Balance is: 0","user_balance":0}
getAllOrgAccounts
此方法會傳回屬於指定組織的所有記號帳戶清單。只有鏈碼的 Token Admin 或指定的組織 Org Admin 才能呼叫此方法。
  @Validator(yup.string())
  public async getAllOrgAccounts(org_id: string) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAllOrgAccounts", "TOKEN", { org_id });
    return await this.Ctx.Account.getAllOrgAccounts(org_id);
  }
參數:
  • org_id: string – 組織的成員服務提供者 (MSP) ID。
傳回值:
  • 成功時,指定組織的所有客戶清單。
傳回值範例:
[
    {
        "key": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
        "valueJson": {
            "bapAccountVersion": 0,
            "assetType": "oaccount",
            "account_id": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
            "user_id": "idcqa",
            "org_id": "appdev",
            "token_type": "fungible",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "balance": 0,
            "onhold_balance": 0
        }
    },
    {
        "key": "oaccount~620fcf5deb5fd5a65c0b5b10fda129de0f629ccd232c5891c130e24a574df50a",
        "valueJson": {
            "bapAccountVersion": 0,
            "assetType": "oaccount",
            "account_id": "oaccount~620fcf5deb5fd5a65c0b5b10fda129de0f629ccd232c5891c130e24a574df50a",
            "user_id": "example_minter",
            "org_id": "appdev",
            "token_type": "fungible",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "balance": 0,
            "onhold_balance": 0
        }
    }
]
createAccount
這個方法會為指定的使用者與記號建立帳號。必須為任何需要記號的使用者建立帳戶。科目可追蹤餘額、保留餘額及交易歷史記錄。帳戶 ID 是一組英數字元,前面加上 oaccount~<token asset name>~,後面接著執行處理擁有者的使用者名稱或電子郵件 ID (user_id) 雜湊,或登入執行處理的使用者 (目前網路組織中使用者的成員服務提供者 ID (org_id)。只有鏈碼的 Token Admin 或指定的組織 Org Admin 才能呼叫此方法。
@Validator(yup.string(), yup.string(), yup.string(), yup.object().nullable())

public async createAccount(org_id: string, user_id: string, token_type: string, daily_limits: DailyLimits) {
await this.Ctx.Auth.checkAuthorization("ACCOUNT.createAccount", "TOKEN", { org_id });
return await this.Ctx.Account.createAccount(org_id, user_id, token_type, daily_limits);
}
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
  • token_type: string – 記號的類型,必須是 fungible
  • daily_limits: JSON – 指定每日交易 (max_daily_amount) 中可使用的記號數目上限,以及每日可完成的交易數目上限 (max_daily_transactions) 的物件。

    如果您使用 Visual Studio Code 與 CLI 或 Postman 集合,請以不同的格式指定 daily_limits 參數。

    Visual Studio 程式碼:{ "max_daily_amount": 1000, "max_daily_transactions": 100 }

    CLI / Postman: "{\"max_daily_amount\":1000,\"max_daily_transactions\":100}"

傳回值:
  • 成功時,所建立帳戶的 JSON 物件。bapAccountVersion 參數是在科目物件中定義供內部使用。
傳回值範例:
{
  "assetType": "oaccount",
  "account_id": "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
  "bapAccountVersion": 0,
  "user_id": "admin",
  "org_id": "Org1MSP",
  "token_type": "fungible",
  "token_id": "",
  "token_name": "",
  "balance": 0,
  "onhold_balance": 0,
  "onhold_burn_balance": 0,
  "max_daily_amount": 1000,
  "max_daily_transactions": 100
}
associateTokenToAccount
此方法會將有趣的記號與帳戶建立關聯。只有鏈碼的 Token Admin 或相關組織的 Org Admin 才能呼叫此方法。
  @Validator(yup.string(), yup.string())
  public async associateTokenToAccount(account_id: string, token_id: string) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.associateToken", "TOKEN", { account_id });
    return await this.Ctx.Account.associateToken(account_id, token_id);
  }
參數:
  • account_id: string – 帳戶的 ID。
  • token_id: string – 記號的 ID。
傳回值:
  • 成功時,已更新帳戶的 JSON 物件。bapAccountVersion 參數是在科目物件中定義供內部使用。
傳回值範例:
{
    "assetType": "oaccount",
    "account_id": "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
    "bapAccountVersion": 0,
    "user_id": "admin",
    "org_id": "Org1MSP",
    "token_type": "fungible",
    "token_id": "fungible",
    "token_name": "fiatmoneytok",
    "balance": 0,
    "onhold_balance": 0
}
getAccount
此方法會傳回指定使用者和記號的帳戶詳細資訊。只有 Token AdminToken Auditor、指定組織的 Org AdminOrg Auditor 或帳戶的 AccountOwner 才能呼叫此方法。
@Validator(yup.string(), yup.string(), yup.string())
public async getAccount(token_id: string, org_id: string, user_id: string) {
  const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
  await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAccount", "TOKEN", { account_id });
  return await this.Ctx.Account.getAccountWithStatus(account_id);
}
參數:
  • token_id: string – 記號的 ID。
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,包含下列特性的 JSON 帳戶物件:
  • account_id – 使用者帳戶的 ID。
  • user_id – 使用者的使用者名稱或電子郵件 ID。
  • org_id – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • token_id – 記號的 ID。
  • token_name – 權杖的名稱。
  • balance – 帳戶的目前餘額。
  • onhold_balance – 帳戶的目前保留結餘。
  • bapAccountVersion – 內部使用的帳戶物件參數。
  • status – 使用者帳戶的目前狀態。
傳回值範例:
{
  "bapAccountVersion": 0,
  "assetType": "oaccount",
  "status": "active",
  "account_id": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
  "user_id": "idcqa",
  "org_id": "appdev",
  "token_type": "fungible",
  "token_id": "t1",
  "token_name": "obptok",
  "balance": 0,
  "onhold_balance": 0
}
getAccountHistory
此方法會傳回指定使用者和權杖的帳戶歷史記錄詳細資訊。只有鏈碼的 Token Admin 或帳戶的 AccountOwner 才能呼叫此方法。
  @Validator(yup.string(), yup.string(), yup.string())
  public async getAccountHistory(token_id: string, org_id: string, user_id: string) {
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.history", "TOKEN", { account_id });
    return await this.Ctx.Account.history(account_id);
  }
參數:
  • token_id: string – 記號的 ID。
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,包含下列特性的 JSON 帳戶物件陣列:
  • trxId - 分類帳所傳回之交易的交易 ID。
  • timeStamp – 交易的時間。
  • value – 帳戶物件的 JSON 字串。
傳回值範例:
[
    {
      "trxId":"2gsdh17fff222467e5667be042e33ce18e804b3e065cca15de306f837e416d7c3e",
      "timeStamp":1629718288,
      "value":{
         "assetType":"oaccount",
         "account_id":"oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
         "user_id":"user1",
         "org_id":"Org1MSP",
         "token_id":"digiCurr101",
         "token_name":"digicur",
         "balance":100,
         "onhold_balance":0,
         "bapAccountVersion": 1
   },
   {
      "trxId":"9fd07fff222467e5667be042e33ce18e804b3e065cca15de306f837e416d7c3e",
      "timeStamp":1629718288,
      "value":{
         "assetType":"oaccount",
         "account_id":"oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
         "user_id":"user1",
         "org_id":"Org1MSP",
         "token_id":"digiCurr101",
         "token_name":"digicur",
         "balance":0,
         "onhold_balance":0,
         "bapAccountVersion": 0
      }
   }
]
getAccountOnHoldBalance
此方法會傳回指定帳戶與變數替代字的目前保留餘額。只有 Token AdminToken Auditor、指定組織的 Org AdminOrg Auditor 或帳戶的 AccountOwner 才能呼叫此方法。
  @Validator(yup.string(), yup.string(), yup.string())
  public async getAccountOnHoldBalance(token_id: string, org_id: string, user_id: string) {
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAccountOnHoldBalance", "TOKEN", { account_id });
    return await this.Ctx.Account.getAccountOnHoldBalance(account_id);
  }
參數:
  • token_id: string – 記號的 ID。
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,代表目前保留餘額的 JSON。
傳回值範例:
{"msg":"Total Holding Balance is: 0","holding_balance":0}
getAllAccounts
這個方法會傳回所有帳號的清單。只有 Token AdminToken Auditor 才能呼叫此方法。此方法使用 Berkeley DB SQL RTF 查詢,而且只能在連線至遠端 Oracle Blockchain Platform 網路時呼叫。
@Validator()
public async getAllAccounts() {
    await this.Ctx.Auth.checkAuthorization('ACCOUNT.getAllAccounts', 'TOKEN');
    return await this.Ctx.Account.getAllAccounts();
}
參數:
傳回值:
  • 成功時,所有帳戶的 JSON 陣列。
getUserByAccountId
此方法會傳回指定帳戶的使用者詳細資訊 (org_iduser_id)。此方法可由 Token AdminToken Auditor 呼叫,或由指定組織的 Org AdminOrg Auditor 呼叫。
@Validator(yup.string())
public async getUserByAccountId(account_id: string) {
    return await this.Ctx.Account.getUserByAccountId(account_id);
}
參數:
  • account_id: string – 帳戶的 ID。
傳回值:
  • 成功時,使用者詳細資訊 (org_idtoken_iduser_id) 的 JSON 物件。
傳回值範例:
{
    "token_id": "digiCurr101",
    "user_id": "user1",
    "org_id": "Org1MSP"
}
getAccountBalance
此方法會傳回指定帳戶與變數替代字的目前餘額。只有 Token AdminToken Auditor、指定組織的 Org AdminOrg Auditor 或帳戶的 AccountOwner 才能呼叫此方法。
  @Validator(yup.string(), yup.string(), yup.string())
  public async getAccountBalance(token_id: string, org_id: string, user_id: string) {
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAccountBalance", "TOKEN", { account_id });
    return await this.Ctx.Account.getAccountBalance(account_id);
  }
參數:
  • token_id: string – 記號的 ID。
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,代表目前帳戶餘額的 JSON。
傳回值範例:
{"msg":"Current Balance is: 0","user_balance":0}
getAllOrgAccounts
此方法會傳回屬於指定組織的所有記號帳戶清單。此方法只能由 Token AdminToken Auditor 呼叫,或由指定組織的 Org AdminOrg Auditor 呼叫。
  @Validator(yup.string())
  public async getAllOrgAccounts(org_id: string) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAllOrgAccounts", "TOKEN", { org_id });
    return await this.Ctx.Account.getAllOrgAccounts(org_id);
  }
參數:
  • org_id: string – 組織的成員服務提供者 (MSP) ID。
傳回值:
  • 成功時,指定組織的所有客戶清單。
傳回值範例:
[
    {
        "key": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
        "valueJson": {
            "bapAccountVersion": 0,
            "assetType": "oaccount",
            "account_id": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
            "user_id": "idcqa",
            "org_id": "appdev",
            "token_type": "fungible",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "balance": 0,
            "onhold_balance": 0
        }
    },
    {
        "key": "oaccount~620fcf5deb5fd5a65c0b5b10fda129de0f629ccd232c5891c130e24a574df50a",
        "valueJson": {
            "bapAccountVersion": 0,
            "assetType": "oaccount",
            "account_id": "oaccount~620fcf5deb5fd5a65c0b5b10fda129de0f629ccd232c5891c130e24a574df50a",
            "user_id": "example_minter",
            "org_id": "appdev",
            "token_type": "fungible",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "balance": 0,
            "onhold_balance": 0
        }
    }
]

角色管理方法

addRole
此方法會新增角色至指定的使用者和記號。只有鏈碼的 Token Admin 或同時擁有指定角色的指定組織 Org Admin 才能呼叫此方法。
  @Validator(yup.string(), yup.string(), yup.string(), yup.string())
  public async addRole(token_id: string, role: string, org_id: string, user_id: string) {
    const token_asset = await this.getTokenObject(token_id);
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("TOKEN.addRoleMember", "TOKEN", { token_id, org_id, role });
    return await this.Ctx.Token.addRoleMember(role, account_id, token_asset);
  }
參數:
  • token_id: string – 記號的 ID。
  • role: string – 要新增至指定使用者的角色名稱。mintableburnable 行為對應至規格檔案的 minter_role_nameburner_role_name 特性。同樣地,notary 角色對應至規格檔案的 notary_role_name 特性。
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,包含帳戶詳細資訊的訊息。
傳回值範例:
{"msg":"Successfully added role 'minter' to Account Id: oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (Org-Id: Org1MSP, User-Id: user1)"}
removeRole
這個方法會從指定的使用者和記號中移除角色。只有鏈碼的 Token Admin 或同時擁有指定角色的指定組織 Org Admin 才能呼叫此方法。
  @Validator(yup.string(), yup.string(), yup.string(), yup.string())
  public async removeRole(token_id: string, role: string, org_id: string, user_id: string) {
    const token_asset = await this.getTokenObject(token_id);
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("TOKEN.removeRoleMember", "TOKEN", { token_id, org_id, role });
    return await this.Ctx.Token.removeRoleMember(role, account_id, token_asset);
  }
參數:
  • token_id: string – 記號的 ID。
  • role: string – 要從指定使用者移除的角色名稱。mintableburnable 行為對應至規格檔案的 minter_role_nameburner_role_name 特性。同樣地,notary 角色對應至規格檔案的 notary_role_name 特性。
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,包含帳戶詳細資訊的訊息。
傳回值範例:
{"msg":"Successfully removed role 'minter' from Account Id: oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (Org-Id: Org1MSP, User-Id: user1)"}
getAccountsByRole
此方法會傳回指定角色和記號的所有帳戶 ID 清單。只有鏈碼的 Token Admin 才能呼叫此方法。
@Validator(yup.string(), yup.string())
public async getAccountsByRole(token_id: string, role: string) {
   await this.Ctx.Auth.checkAuthorization('ROLE.getAccountsByRole', 'TOKEN');
   return await this.Ctx.Role.getAccountsByRole(token_id, role);
}
參數:
  • token_id: string – 記號的 ID。
  • role: string – 要搜尋的角色名稱。
傳回值:
  • 成功時,JSON 帳戶 ID 陣列。
傳回值範例:
{"accounts":["oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f"]}
getAccountsByUser
此方法會傳回指定組織 ID 與使用者 ID 之所有帳戶 ID 的清單。只有鏈碼的 Token Admin、指定組織的 Org Admin 或參數中指定的 Account Owner 才能呼叫此方法。
  @Validator(yup.string(), yup.string())
  public async getAccountsByUser(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAccountsByUser", "TOKEN", { org_id, user_id });
    return await this.Ctx.Account.getAccountsByUser(org_id, user_id);
  }
參數:
  • org_id string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,JSON 帳戶 ID 陣列。
傳回值範例:
{"accounts":["oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f"]}
getUsersByRole
此方法會傳回指定角色和記號之所有使用者的清單。只有鏈碼的 Token Admin 才能呼叫此方法。
@Validator(yup.string(), yup.string())
public async getUsersByRole(token_id: string, role: string) {
    await this.Ctx.Auth.checkAuthorization('ROLE.getUsersByRole', 'TOKEN');
    return await this.Ctx.Role.getUsersByRole(token_id, role);
}
參數:
  • token_id: string – 記號的 ID。
  • role: string – 要搜尋的角色名稱。
傳回值:
  • 成功時,使用者物件的 JSON 陣列 (org_idtoken_iduser_id)。
傳回值範例:
{"users":[{"token_id":"digiCurr101","user_id":"user1","org_id":"Org1MSP"}]}
isInRole
此方法會傳回布林值,指示使用者和記號是否具有指定的角色。只有鏈碼的 Token Admin、帳戶的 AccountOwner 或指定組織的 Org Admin 才能呼叫此方法。
  @Validator(yup.string(), yup.string(), yup.string(), yup.string())
  public async isInRole(token_id: string, org_id: string, user_id: string, role: string) {
    const token_asset = await this.getTokenObject(token_id);
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("TOKEN.isInRole", "TOKEN", { account_id });
    return { result: await this.Ctx.Token.isInRole(role, account_id, token_asset) };
  }
參數:
  • token_id: string – 記號的 ID。
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
  • role: string – 要搜尋的角色名稱。
傳回值:
  • 成功時,布林結果的 JSON 字串。
傳回值範例:
{"result":"false"}
getOrgAccountsByRole
此方法會傳回指定組織中具有指定角色之所有帳戶的相關資訊。只有鏈碼的 Token Admin 或指定的組織 Org Admin 才能呼叫此方法。
   @Validator(yup.string(), yup.string(), yup.string())
  public async getOrgAccountsByRole(token_id: string, role: string, org_id: string) {
    await this.Ctx.Auth.checkAuthorization("ROLE.getOrgAccountsByRole", "TOKEN", { org_id });
    return await this.Ctx.Role.getOrgAccountsByRole(token_id, role, org_id);
  }
參數:
  • token_id: string – 記號的 ID。
  • role: string – 要檢查的角色名稱。
  • org_id: string – 組織的成員服務提供者 (MSP) ID。
傳回值:
  • 成功時,指定組織中具有指定角色的所有客戶清單。
傳回值範例:
{
    "accounts": [
        "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
        "oaccount~9c650574af9025a6106c8d12a801b079eda9ae2e3399fc2fbd5bd683d738a850"
    ]
}
getOrgUsersByRole
此方法會傳回指定組織中具有指定角色之所有使用者的相關資訊。只有鏈碼的 Token Admin 或指定的組織 Org Admin 才能呼叫此方法。
  @Validator(yup.string(), yup.string(), yup.string())
  public async getOrgUsersByRole(token_id: string, role: string, org_id: string) {
    await this.Ctx.Auth.checkAuthorization("ROLE.getOrgUsersByRole", "TOKEN", { org_id });
    return await this.Ctx.Role.getOrgUsersByRole(token_id, role, org_id);
  }
參數:
  • token_id: string – 記號的 ID。
  • role: string – 要檢查的角色名稱。
  • org_id: string – 組織的成員服務提供者 (MSP) ID。
傳回值:
  • 成功時,指定組織中具有指定角色的所有使用者清單。
傳回值範例:
{
    "users": [
        {
            "token_id": "token",
            "user_id": "admin",
            "org_id": "Org1MSP"
        },
        {
            "token_id": "token",
            "user_id": "orgAdmin",
            "org_id": "Org1MSP"
        }
    ]
}
addRole
此方法會新增角色至指定的使用者和記號。只有鏈碼的 Token Admin 或同時擁有指定角色的指定組織 Org Admin 才能呼叫此方法。
  @Validator(yup.string(), yup.string(), yup.string(), yup.string())
  public async addRole(token_id: string, role: string, org_id: string, user_id: string) {
    const token_asset = await this.getTokenObject(token_id);
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("TOKEN.addRoleMember", "TOKEN", { token_id, org_id, role });
    return await this.Ctx.Token.addRoleMember(role, account_id, token_asset);
  }
參數:
  • token_id: string – 記號的 ID。
  • role: string – 要新增至指定使用者的角色名稱。mintableburnable 行為對應至規格檔案的 minter_role_nameburner_role_name 特性。同樣地,notary 角色對應至規格檔案的 notary_role_name 特性。
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,包含帳戶詳細資訊的訊息。
傳回值範例:
{"msg":"Successfully added role 'minter' to Account Id: oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (Org-Id: Org1MSP, User-Id: user1)"}
removeRole
這個方法會從指定的使用者和記號中移除角色。只有鏈碼的 Token Admin 或同時擁有指定角色的指定組織 Org Admin 才能呼叫此方法。
  @Validator(yup.string(), yup.string(), yup.string(), yup.string())
  public async removeRole(token_id: string, role: string, org_id: string, user_id: string) {
    const token_asset = await this.getTokenObject(token_id);
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("TOKEN.removeRoleMember", "TOKEN", { token_id, org_id, role });
    return await this.Ctx.Token.removeRoleMember(role, account_id, token_asset);
  }
參數:
  • token_id: string – 記號的 ID。
  • role: string – 要從指定使用者移除的角色名稱。mintableburnable 行為對應至規格檔案的 minter_role_nameburner_role_name 特性。同樣地,notary 角色對應至規格檔案的 notary_role_name 特性。
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,包含帳戶詳細資訊的訊息。
傳回值範例:
{"msg":"Successfully removed role 'minter' from Account Id: oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (Org-Id: Org1MSP, User-Id: user1)"}
getAccountsByRole
此方法會傳回指定角色和記號的所有帳戶 ID 清單。只有 Token AdminToken Auditor 才能呼叫此方法。
@Validator(yup.string(), yup.string())
public async getAccountsByRole(token_id: string, role: string) {
   await this.Ctx.Auth.checkAuthorization('ROLE.getAccountsByRole', 'TOKEN');
   return await this.Ctx.Role.getAccountsByRole(token_id, role);
}
參數:
  • token_id: string – 記號的 ID。
  • role: string – 要搜尋的角色名稱。
傳回值:
  • 成功時,JSON 帳戶 ID 陣列。
傳回值範例:
{"accounts":["oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f"]}
getAccountsByUser
此方法會傳回指定組織 ID 與使用者 ID 之所有帳戶 ID 的清單。只有 Token AdminToken Auditor、指定組織的 Org AdminOrg Auditor,或參數中指定的 Account Owner 才能呼叫此方法。
  @Validator(yup.string(), yup.string())
  public async getAccountsByUser(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAccountsByUser", "TOKEN", { org_id, user_id });
    return await this.Ctx.Account.getAccountsByUser(org_id, user_id);
  }
參數:
  • org_id string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,JSON 帳戶 ID 陣列。
傳回值範例:
{"accounts":["oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f"]}
getUsersByRole
此方法會傳回指定角色和記號之所有使用者的清單。只有 Token AdminToken Auditor 才能呼叫此方法。
@Validator(yup.string(), yup.string())
public async getUsersByRole(token_id: string, role: string) {
    await this.Ctx.Auth.checkAuthorization('ROLE.getUsersByRole', 'TOKEN');
    return await this.Ctx.Role.getUsersByRole(token_id, role);
}
參數:
  • token_id: string – 記號的 ID。
  • role: string – 要搜尋的角色名稱。
傳回值:
  • 成功時,使用者物件的 JSON 陣列 (org_idtoken_iduser_id)。
傳回值範例:
{"users":[{"token_id":"digiCurr101","user_id":"user1","org_id":"Org1MSP"}]}
isInRole
此方法會傳回布林值,指示使用者和記號是否具有指定的角色。只有 Token AdminToken Auditor、帳戶的 AccountOwner 或指定組織的 Org AdminOrg Auditor 才能呼叫此方法。
  @Validator(yup.string(), yup.string(), yup.string(), yup.string())
  public async isInRole(token_id: string, org_id: string, user_id: string, role: string) {
    const token_asset = await this.getTokenObject(token_id);
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("TOKEN.isInRole", "TOKEN", { account_id });
    return { result: await this.Ctx.Token.isInRole(role, account_id, token_asset) };
  }
參數:
  • token_id: string – 記號的 ID。
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
  • role: string – 要搜尋的角色名稱。
傳回值:
  • 成功時,布林結果的 JSON 字串。
傳回值範例:
{"result":"false"}
getOrgAccountsByRole
此方法會傳回指定組織中具有指定角色之所有帳戶的相關資訊。只有 Token AdminToken AuditorOrg AdminOrg Auditor 才能呼叫此方法。
   @Validator(yup.string(), yup.string(), yup.string())
  public async getOrgAccountsByRole(token_id: string, role: string, org_id: string) {
    await this.Ctx.Auth.checkAuthorization("ROLE.getOrgAccountsByRole", "TOKEN", { org_id });
    return await this.Ctx.Role.getOrgAccountsByRole(token_id, role, org_id);
  }
參數:
  • token_id: string – 記號的 ID。
  • role: string – 要檢查的角色名稱。
  • org_id: string – 組織的成員服務提供者 (MSP) ID。
傳回值:
  • 成功時,指定組織中具有指定角色的所有客戶清單。
傳回值範例:
{
    "accounts": [
        "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
        "oaccount~9c650574af9025a6106c8d12a801b079eda9ae2e3399fc2fbd5bd683d738a850"
    ]
}
getOrgUsersByRole
此方法會傳回指定組織中具有指定角色之所有使用者的相關資訊。只有指定組織的 Org AdminOrg Auditor 才能透過 Token AdminToken Auditor 呼叫此方法。
  @Validator(yup.string(), yup.string(), yup.string())
  public async getOrgUsersByRole(token_id: string, role: string, org_id: string) {
    await this.Ctx.Auth.checkAuthorization("ROLE.getOrgUsersByRole", "TOKEN", { org_id });
    return await this.Ctx.Role.getOrgUsersByRole(token_id, role, org_id);
  }
參數:
  • token_id: string – 記號的 ID。
  • role: string – 要檢查的角色名稱。
  • org_id: string – 組織的成員服務提供者 (MSP) ID。
傳回值:
  • 成功時,指定組織中具有指定角色的所有使用者清單。
傳回值範例:
{
    "users": [
        {
            "token_id": "token",
            "user_id": "admin",
            "org_id": "Org1MSP"
        },
        {
            "token_id": "token",
            "user_id": "orgAdmin",
            "org_id": "Org1MSP"
        }
    ]
}

交易歷史記錄管理的方式

getAccountTransactionHistory
此方法會傳回指定使用者與變數替代字的帳戶交易歷史記錄明細陣列。只有鏈碼的 Token Admin、指定組織的 Org Admin 或帳戶的 AccountOwner 才能呼叫此方法。
 @Validator(yup.string(), yup.string(), yup.string())
  public async getAccountTransactionHistory(token_id: string, org_id: string, user_id: string) {
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAccountTransactionHistory", "TOKEN", { account_id });
    return await this.Ctx.Account.getAccountTransactionHistory(account_id, org_id, user_id.toLowerCase());
  }
參數:
  • token_id: string – 記號的 ID。
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,包含下列特性的 JSON 帳戶交易物件陣列:
  • transaction_id – 交易的 ID。
  • transacted_account – 進行交易的帳戶。
  • transaction_type – 交易類型。
  • transacted_amount - 交易金額。
  • timestamp – 交易的時間。
  • balance – 交易時的帳戶餘額。
  • onhold_balance – 交易時的保留結餘。
  • token_id – 記號的 ID。
  • holding_idholdTokens 方法傳回的唯一識別碼。
傳回值範例:
[
    {
        "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
        "transacted_amount": 20,
        "timestamp": "2021-08-17T06:04:24.000Z",
        "balance": 930,
        "onhold_balance": 0,
        "token_id": "digiCurr101",
        "transaction_type": "BULKTRANSFER",
        "sub_transactions": [
            {
                "transacted_account": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
                "transaction_type": "DEBIT",
                "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c4ca4238a0b923820dcc509a6f75849b",
                "transacted_amount": 10
            },
            {
                "transacted_account": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
                "transaction_type": "DEBIT",
                "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c81e728d9d4c2f636f067f89cc14862c",
                "transacted_amount": 10
            }
        ]
    },
    {
        "transaction_id": "otransaction~757864d5369bd0539d044caeb3bb4898db310fd7aa740f45a9938771903d43da",
        "transacted_amount": 50,
        "timestamp": "2021-08-17T06:02:44.000Z",
        "balance": 950,
        "onhold_balance": 0,
        "token_id": "digiCurr101",
        "transacted_account": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
        "transaction_type": "DEBIT"
    }
]
getAccountTransactionHistoryWithFilters
此方法會傳回指定使用者與變數替代字的帳戶交易歷史記錄明細陣列。只有鏈碼的 Token Admin、指定組織的 Org Admin 或帳戶的 AccountOwner 才能呼叫此方法。只有在連線至遠端 Oracle Blockchain Platform 網路時才能呼叫此方法。
  @Validator(yup.string(), yup.string(), yup.string(), yup.object().nullable())
  public async getAccountTransactionHistoryWithFilters(token_id: string, org_id: string, user_id: string, filters?: Filters) {
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAccountTransactionHistoryWithFilters", "TOKEN", { account_id });
    return await this.Ctx.Account.getAccountTransactionHistoryWithFilters(account_id, org_id, user_id.toLowerCase(), filters);
  }
參數:
  • token_id: string – 記號的 ID。
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
  • filters: string – 選擇性參數。如果空白,則會傳回所有記錄。PageSize 特性決定要傳回的記錄數目。如果 PageSize 為 0,則預設頁面大小為 20。Bookmark 特性決定要傳回之記錄的開始索引。如需詳細資訊,請參閱 Hyperledger Fabric 文件。必須以 RFC-3339 格式指定 StartTimeEndTime 特性。
範例:

ochain invoke GetAccountTransactionHistoryWithFilters 'token1' 'appbuilder12' 'user_minter' '{"PageSize":10,"Bookmark":"1","StartTime":"2022-01-25T17:41:42Z","EndTime":"2022-01-25T17:59:10Z"}'

[
  {
    "transaction_id": "otransaction~672897b5a4fa78b421c000e4d6d4f71f3d46529bfbb5b4be10bf5471dc35ce89",
    "transacted_amount": 5,
    "timestamp": "2022-04-20T15:46:04.000Z",
    "token_id": "tokenId",
    "transacted_account": "oaccount~16c38d804413ebabf416360d374f76c973d4e71c74adfde73cc40c7c274883b8",
    "transaction_type": "DEBIT",
    "balance": 90,
    "onhold_balance": 0
  },
  {
    "transaction_id": "otransaction~467bb67a33aaffca4487f33dcd46c9844efdb5421a2e7b6aa2d53152eb2c6d85",
    "transacted_amount": 5,
    "timestamp": "2022-04-20T15:45:47.000Z",
    "token_id": "tokenId",
    "transacted_account": "oaccount~fbf95683b21bbc91a22205819ac1e2e9c90355d536821ed3fe22b7d23915c248",
    "transaction_type": "DEBIT",
    "balance": 95,
    "onhold_balance": 0
  },
  {
    "transaction_id": "otransaction~c6d56ce54a9bbe24597d1d10448e39316dc6f16328bf3c5b0c8ef10e1dfeb397",
    "transacted_amount": 100,
    "timestamp": "2022-04-20T15:44:26.000Z",
    "token_id": "tokenId",
    "transacted_account": "oaccount~deb5fb0906c40506f6c2d00c573b774e01a53dd91499e651d92ac4778b6add6a",
    "transaction_type": "MINT",
    "balance": 100,
    "onhold_balance": 0
  }
]
getSubTransactionsById
此方法會傳回指定使用者與變數替代字的帳戶交易歷史記錄明細陣列。只有鏈碼的 Token Admin 或帳戶的 AccountOwner 才能呼叫此方法。
  @Validator(yup.string())
  public async getSubTransactionsById(transaction_id: string) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getSubTransactionsById", "TOKEN", { transaction_id });
    return await this.Ctx.Account.getSubTransactionsById(transaction_id);
  }
參數:
  • transaction_id: string – 大量傳輸交易的 ID。
傳回值:
  • JSON 格式的科目子交易物件陣列,用於指定的大量移轉交易 ID。
範例:

ochain invoke GetAccountSubTransactionHistory 'otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b'

[
    {
        "transacted_account": "oaccount~16c38d804413ebabf416360d374f76c973d4e71c74adfde73cc40c7c274883b8",
        "transaction_type": "DEBIT",
        "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c81e728d9d4c2f636f067f89cc14862c",
        "transacted_amount": 5,
        "timestamp": "2022-04-20T15:52:21.000Z",
        "token_id": "token1",
        "balance": 80,
        "onhold_balance": 0
    },
    {
        "transacted_account": "oaccount~fbf95683b21bbc91a22205819ac1e2e9c90355d536821ed3fe22b7d23915c248",
        "transaction_type": "DEBIT",
        "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c4ca4238a0b923820dcc509a6f75849b",
        "transacted_amount": 5,
        "timestamp": "2022-04-20T15:52:21.000Z",
        "token_id": "token1",
        "balance": 85,
        "onhold_balance": 0
    }
]
getSubTransactionsByIdWithFilters
此方法會傳回指定交易的帳戶子交易歷史記錄明細陣列。
  @Validator(yup.string(), yup.object().nullable())
  public async getSubTransactionsByIdWithFilters(transaction_id: string, filters?: SubTransactionFilters) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getSubTransactionsByIdWithFilters", "TOKEN", { transaction_id });
    return await this.Ctx.Account.getSubTransactionsByIdWithFilters(transaction_id, filters);
  } 
參數:
  • transaction_id: string – 交易的 ID。
  • filters: string – 選擇性參數。如果空白,則會傳回所有記錄。PageSize 特性決定要傳回的記錄數目。如果 PageSize 為 0,則預設頁面大小為 20。Bookmark 特性決定要傳回之記錄的開始索引。如需詳細資訊,請參閱 Hyperledger Fabric 文件。必須以 RFC-3339 格式指定 StartTimeEndTime 特性。
傳回值:
  • JSON 格式的科目子交易物件陣列,用於指定的大量移轉交易 ID。
範例:

ochain invoke GetAccountSubTransactionHistoryWithFilters 'otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b' '{"PageSize":10,"Bookmark":"1"}'

[
  {
    "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c81e728d9d4c2f636f067f89cc14862c",
    "transacted_amount": 5,
    "timestamp": "2022-04-20T15:52:21.000Z",
    "token_id": "tokenId",
    "transacted_account": "oaccount~16c38d804413ebabf416360d374f76c973d4e71c74adfde73cc40c7c274883b8",
    "transaction_type": "DEBIT",
    "balance": 80,
    "onhold_balance": 0
  },
  {
    "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c4ca4238a0b923820dcc509a6f75849b",
    "transacted_amount": 5,
    "timestamp": "2022-04-20T15:52:21.000Z",
    "token_id": "tokenId",
    "transacted_account": "oaccount~fbf95683b21bbc91a22205819ac1e2e9c90355d536821ed3fe22b7d23915c248",
    "transaction_type": "DEBIT",
    "balance": 85,
    "onhold_balance": 0
  }
]
getTransactionById
此方法會傳回 Transaction 資產的歷史記錄。
@Validator(yup.string())
    public async getTransactionById(transaction_id: string) {
        return await this.Ctx.Transaction.getTransactionById(transaction_id);
    }
參數:
  • transaction_id string – 交易資產的 ID。
傳回值:
  • 成功時,交易歷史記錄的 JSON 陣列。
傳回值範例:
{
    "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
    "history": [
        {
            "trxId": "68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
            "timeStamp": 1629180264,
            "value": {
                "assetType": "otransaction",
                "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
                "token_id": "digiCurr101",
                "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
                "to_account_id": "",
                "transaction_type": "BULKTRANSFER",
                "amount": 20,
                "timestamp": "2021-08-17T06:04:24.000Z",
                "number_of_sub_transactions": 2,
                "holding_id": ""
            }
        }
    ],
    "sub_transactions": [
        {
            "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c4ca4238a0b923820dcc509a6f75849b",
            "history": [
                {
                    "trxId": "68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
                    "timeStamp": 1629180264,
                    "value": {
                        "assetType": "otransaction",
                        "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c4ca4238a0b923820dcc509a6f75849b",
                        "token_id": "digiCurr101",
                        "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
                        "to_account_id": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
                        "transaction_type": "TRANSFER",
                        "amount": 10,
                        "timestamp": "2021-08-17T06:04:24.000Z",
                        "number_of_sub_transactions": 0,
                        "holding_id": ""
                    }
                }
            ]
        },
        {
            "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c81e728d9d4c2f636f067f89cc14862c",
            "history": [
                {
                    "trxId": "68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
                    "timeStamp": 1629180264,
                    "value": {
                        "assetType": "otransaction",
                        "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c81e728d9d4c2f636f067f89cc14862c",
                        "token_id": "digiCurr101",
                        "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
                        "to_account_id": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
                        "transaction_type": "TRANSFER",
                        "amount": 10,
                        "timestamp": "2021-08-17T06:04:24.000Z",
                        "number_of_sub_transactions": 0,
                        "holding_id": ""
                    }
                }
            ]
        }
    ]
}
deleteHistoricalTransactions
此方法會從狀態資料庫刪除較舊的交易。
@Validator(yup.date())
    public async deleteHistoricalTransactions(time_to_expiration: Date) {
        await this.Ctx.Auth.checkAuthorization('TRANSACTION.deleteTransactions', 'TOKEN');
        return await this.Ctx.Transaction.deleteTransactions(time_to_expiration);
    }
參數:
  • time_to_expiration Date – 表示何時刪除交易的時戳。將刪除早於指定時間的交易資產。
傳回值範例:
"payload": {
    "msg": "Successfuly deleted transaction older than date: Thu Aug 19 2021 11:19:36 GMT+0000 (Coordinated Universal Time).",
    "transactions": [
        "otransaction~ec3366dd48b4ce2838f820f2f138648e6e55a07226713e59b411ff31b0d21058"
    ]
}
getAccountTransactionHistoryWithFiltersFromRichHistDB
您可以將資料同步至 RTF 歷史記錄資料庫,然後使用鏈碼 API 呼叫來擷取資料。此方法會從 Rich history 資料庫擷取交易歷史記錄。您必須先依照 Oracle Blockchain Platform Digital Assets Edition 中的 Oracle Database View Definitions for Wholesale CBDC 所述,執行 Oracle Autonomous Database 並啟用 Oracle REST Data Services (ORDS) 和 OAuth,才能使用此方法。
@GetMethod()
@Validator(yup.string(), yup.string(), yup.string(), yup.string(), yup.string(), yup.object().nullable())
public async getAccountTransactionHistoryWithFiltersFromRichHistDB(token_id: string, org_id: string, user_id: string, custom_endpoint: string, bearer_token: string, filters?: Filters) {
const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAccountTransactionHistoryWithFilters", "TOKEN", { account_id });
return await this.Ctx.Account.getAccountTrxHistoryWithFiltersFromRichHistDB(account_id, org_id, user_id.toLowerCase(), custom_endpoint, bearer_token, filters);
}
參數:
  • token_id: string – 要提示的記號 ID。
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
  • custom_endpoint – Rich History 資料庫的 RESTful 服務端點。
  • bearer_token – RESTful 服務端點的存取授權記號。
  • filters: string – 選擇性參數。如果空白,則會傳回所有記錄。PageSize 特性決定要傳回的記錄數目。如果 PageSize 為 0,則預設頁面大小為 20。Bookmark 特性決定要傳回之記錄的開始索引。如需詳細資訊,請參閱 Hyperledger Fabric 文件。必須以 RFC-3339 格式指定 StartTimeEndTime 特性。
getAccountTransactionHistory
此方法會傳回指定使用者與變數替代字的帳戶交易歷史記錄明細陣列。只有 Token AdminToken Auditor、指定組織的 Org AdminOrg Auditor 或帳戶的 AccountOwner 才能呼叫此方法。
@GetMethod()
@Validator(yup.string(), yup.string(), yup.string())
public async getAccountTransactionHistory(token_id: string, org_id: string, user_id: string) {
const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAccountTransactionHistory", "TOKEN", { account_id });
return await this.Ctx.Account.getAccountTransactionHistory(account_id, org_id, user_id.toLowerCase());
}
參數:
  • token_id: string – 記號的 ID。
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值範例:
[
            {
                "transaction_id": "otransaction~64c5a4830949eae1424600f3d4a438c6f603a7c3ea31a68e374b899803999e22",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:37:28.000Z",
                "balance": 550,
                "onhold_balance": 10,
                "token_id": "USD",
                "category": "category value",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "REJECT_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            },
            {
                "transaction_id": "otransaction~a4537ef34a955b023b7c205b9abf06a6c79e4fdd761fb24f41b8eb34126b66c0",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:36:32.000Z",
                "balance": 550,
                "onhold_balance": 10,
                "token_id": "USD",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "APPROVE_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            },
            {
                "transaction_id": "otransaction~6237a759422bd9fb112742e8cd7e6450df5a74a32236d9b1005571afed8904a4",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:36:18.000Z",
                "balance": 540,
                "onhold_balance": 10,
                "token_id": "USD",
                "category": "category value",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "REQUEST_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            },
            {
                "transaction_id": "otransaction~06b35071415d74aa1a7c18449149c937d886cae76a832c44cf8d98e84586e76e",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:35:46.000Z",
                "balance": 540,
                "onhold_balance": 10,
                "token_id": "USD",
                "category": "category value",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "REQUEST_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            }
 ]
getAccountTransactionHistoryWithFilters
此方法會傳回指定使用者與變數替代字之科目交易歷史記錄明細的篩選陣列。只有 Token AdminToken Auditor、指定組織的 Org AdminOrg Auditor 或帳戶的 AccountOwner 才能呼叫此方法。
@GetMethod()
@Validator(yup.string(), yup.string(), yup.string(), yup.object().nullable())
public async getAccountTransactionHistoryWithFilters(token_id: string, org_id: string, user_id: string, filters?: Filters) {
const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAccountTransactionHistoryWithFilters", "TOKEN", { account_id });
return await this.Ctx.Account.getAccountTransactionHistoryWithFilters(account_id, org_id, user_id.toLowerCase(), filters);
}
參數:
  • token_id: string – 記號的 ID。
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
  • filters: string – 選擇性參數。如果空白,則會傳回所有記錄。PageSize 特性決定要傳回的記錄數目。如果 PageSize 為 0,則預設頁面大小為 20。Bookmark 特性決定要傳回之記錄的開始索引。如需詳細資訊,請參閱 Hyperledger Fabric 文件。必須以 RFC-3339 格式指定 StartTimeEndTime 特性。
傳回值範例:
[
            {
                "transaction_id": "otransaction~64c5a4830949eae1424600f3d4a438c6f603a7c3ea31a68e374b899803999e22",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:37:28.000Z",
                "balance": 550,
                "onhold_balance": 10,
                "token_id": "USD",
                "category": "category value",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "REJECT_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            },
            {
                "transaction_id": "otransaction~a4537ef34a955b023b7c205b9abf06a6c79e4fdd761fb24f41b8eb34126b66c0",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:36:32.000Z",
                "balance": 550,
                "onhold_balance": 10,
                "token_id": "USD",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "APPROVE_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            },
            {
                "transaction_id": "otransaction~6237a759422bd9fb112742e8cd7e6450df5a74a32236d9b1005571afed8904a4",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:36:18.000Z",
                "balance": 540,
                "onhold_balance": 10,
                "token_id": "USD",
                "category": "category value",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "REQUEST_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            },
            {
                "transaction_id": "otransaction~06b35071415d74aa1a7c18449149c937d886cae76a832c44cf8d98e84586e76e",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:35:46.000Z",
                "balance": 540,
                "onhold_balance": 10,
                "token_id": "USD",
                "category": "category value",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "REQUEST_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            }
 ]
getSubTransactionsById
此方法會傳回指定使用者與變數替代字的帳戶交易歷史記錄明細陣列。只有呼叫交易的 Token AdminToken AuditorAccountOwner 才能呼叫此方法。
  @Validator(yup.string())
  public async getSubTransactionsById(transaction_id: string) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getSubTransactionsById", "TOKEN", { transaction_id });
    return await this.Ctx.Account.getSubTransactionsById(transaction_id);
  }
參數:
  • transaction_id: string – 大量傳輸交易的 ID。
傳回值:
  • JSON 格式的科目子交易物件陣列,用於指定的大量移轉交易 ID。
範例:

ochain invoke GetAccountSubTransactionHistory 'otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b'

[
    {
        "transacted_account": "oaccount~16c38d804413ebabf416360d374f76c973d4e71c74adfde73cc40c7c274883b8",
        "transaction_type": "DEBIT",
        "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c81e728d9d4c2f636f067f89cc14862c",
        "transacted_amount": 5,
        "timestamp": "2022-04-20T15:52:21.000Z",
        "token_id": "token1",
        "balance": 80,
        "onhold_balance": 0
    },
    {
        "transacted_account": "oaccount~fbf95683b21bbc91a22205819ac1e2e9c90355d536821ed3fe22b7d23915c248",
        "transaction_type": "DEBIT",
        "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c4ca4238a0b923820dcc509a6f75849b",
        "transacted_amount": 5,
        "timestamp": "2022-04-20T15:52:21.000Z",
        "token_id": "token1",
        "balance": 85,
        "onhold_balance": 0
    }
]
getSubTransactionsByIdWithFilters
此方法會傳回指定交易的帳戶子交易歷史記錄明細陣列。
  @Validator(yup.string(), yup.object().nullable())
  public async getSubTransactionsByIdWithFilters(transaction_id: string, filters?: SubTransactionFilters) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getSubTransactionsByIdWithFilters", "TOKEN", { transaction_id });
    return await this.Ctx.Account.getSubTransactionsByIdWithFilters(transaction_id, filters);
  } 
參數:
  • transaction_id: string – 交易的 ID。
  • filters: string – 選擇性參數。如果空白,則會傳回所有記錄。PageSize 特性決定要傳回的記錄數目。如果 PageSize 為 0,則預設頁面大小為 20。Bookmark 特性決定要傳回之記錄的開始索引。如需詳細資訊,請參閱 Hyperledger Fabric 文件。必須以 RFC-3339 格式指定 StartTimeEndTime 特性。
傳回值:
  • JSON 格式的科目子交易物件陣列,用於指定的大量移轉交易 ID。
範例:

ochain invoke GetAccountSubTransactionHistoryWithFilters 'otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b' '{"PageSize":10,"Bookmark":"1"}'

[
  {
    "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c81e728d9d4c2f636f067f89cc14862c",
    "transacted_amount": 5,
    "timestamp": "2022-04-20T15:52:21.000Z",
    "token_id": "tokenId",
    "transacted_account": "oaccount~16c38d804413ebabf416360d374f76c973d4e71c74adfde73cc40c7c274883b8",
    "transaction_type": "DEBIT",
    "balance": 80,
    "onhold_balance": 0
  },
  {
    "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c4ca4238a0b923820dcc509a6f75849b",
    "transacted_amount": 5,
    "timestamp": "2022-04-20T15:52:21.000Z",
    "token_id": "tokenId",
    "transacted_account": "oaccount~fbf95683b21bbc91a22205819ac1e2e9c90355d536821ed3fe22b7d23915c248",
    "transaction_type": "DEBIT",
    "balance": 85,
    "onhold_balance": 0
  }
]
getTransactionById
此方法會傳回 Transaction 資產的歷史記錄。只有 Token AdminToken Auditor、指定組織的 Org AdminOrg Auditor,或交易參與者 (寄件者、收件者或公證人) 才能呼叫此方法。
@Validator(yup.string())
    public async getTransactionById(transaction_id: string) {
        return await this.Ctx.Transaction.getTransactionById(transaction_id);
    }
參數:
  • transaction_id string – 交易資產的 ID。
傳回值:
  • 成功時,交易歷史記錄的 JSON 陣列。
傳回值範例:
{
    "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
    "history": [
        {
            "trxId": "68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
            "timeStamp": 1629180264,
            "value": {
                "assetType": "otransaction",
                "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
                "token_id": "digiCurr101",
                "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
                "to_account_id": "",
                "transaction_type": "BULKTRANSFER",
                "amount": 20,
                "timestamp": "2021-08-17T06:04:24.000Z",
                "number_of_sub_transactions": 2,
                "holding_id": ""
            }
        }
    ],
    "sub_transactions": [
        {
            "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c4ca4238a0b923820dcc509a6f75849b",
            "history": [
                {
                    "trxId": "68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
                    "timeStamp": 1629180264,
                    "value": {
                        "assetType": "otransaction",
                        "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c4ca4238a0b923820dcc509a6f75849b",
                        "token_id": "digiCurr101",
                        "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
                        "to_account_id": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
                        "transaction_type": "TRANSFER",
                        "amount": 10,
                        "timestamp": "2021-08-17T06:04:24.000Z",
                        "number_of_sub_transactions": 0,
                        "holding_id": ""
                    }
                }
            ]
        },
        {
            "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c81e728d9d4c2f636f067f89cc14862c",
            "history": [
                {
                    "trxId": "68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
                    "timeStamp": 1629180264,
                    "value": {
                        "assetType": "otransaction",
                        "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c81e728d9d4c2f636f067f89cc14862c",
                        "token_id": "digiCurr101",
                        "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
                        "to_account_id": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
                        "transaction_type": "TRANSFER",
                        "amount": 10,
                        "timestamp": "2021-08-17T06:04:24.000Z",
                        "number_of_sub_transactions": 0,
                        "holding_id": ""
                    }
                }
            ]
        }
    ]
}
deleteHistoricalTransactions
此方法會從狀態資料庫刪除較舊的交易。
@Validator(yup.date())
    public async deleteHistoricalTransactions(time_to_expiration: Date) {
        await this.Ctx.Auth.checkAuthorization('TRANSACTION.deleteTransactions', 'TOKEN');
        return await this.Ctx.Transaction.deleteTransactions(time_to_expiration);
    }
參數:
  • time_to_expiration Date – 表示何時刪除交易的時戳。將刪除早於指定時間的交易資產。
傳回值範例:
"payload": {
    "msg": "Successfuly deleted transaction older than date: Thu Aug 19 2021 11:19:36 GMT+0000 (Coordinated Universal Time).",
    "transactions": [
        "otransaction~ec3366dd48b4ce2838f820f2f138648e6e55a07226713e59b411ff31b0d21058"
    ]
}

權杖行為管理方法 - 可變行為

issueTokens
這個方法會提示該方法的呼叫程式所擁有的記號。來電者必須具有帳戶與次要角色。可提示的記號數目受規格檔案中 mintable 行為的 max_mint_quantity 特性所限制。如果未指定 max_mint_quantity 特性,則可以提示不限數目的記號。數量必須在規格檔案中 divisible 行為的 decimal 參數所指定的小數值內。只有具備 minter 角色之帳戶的 AccountOwner 才能呼叫此方法。
@Validator(yup.string(), yup.number().positive())
public async issueTokens(token_id: string, quantity: number) {
    const token_asset = await this.getTokenObject(token_id);
    return await this.Ctx.Token.mint(quantity, token_asset);
}
參數:
  • token_id: string – 記號的 ID。
  • quantity – 記號數目為 mint。
傳回值:
  • 成功時,包含帳戶詳細資訊的訊息。
傳回值範例:
{
    "msg": "Successfully minted 1000 tokens to Account Id: \
oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: user1)  ",
}
getTotalMintedTokens
此方法會傳回指定記號的預期記號總數。只有鏈碼的 Token Admin 或任何 Org Admin 才能呼叫此方法。
@Validator(yup.string())
 public async getTotalMintedTokens(token_id: string) {
     const token_asset = await this.getTokenObject(token_id);
     await this.Ctx.Auth.checkAuthorization('TOKEN.getTotalMintedTokens', 'TOKEN');
     const totalMintedTokens = await this.Ctx.Token.getTotalMintedTokens(token_asset);
     return {
         msg: `Total minted token for Token Id: ${token_id} is ${totalMintedTokens} tokens.`,
         quantity: totalMintedTokens
     };
 }
參數:
  • token_id: string – 記號的 ID。
傳回值:
  • 成功時,代表權杖總數的 JSON 字串。
傳回值範例:
{"msg":"Total minted token for Token Id: digiCurr101 is 100 tokens.","quantity":100}
getNetTokens
此方法會傳回系統中指定記號可用的記號總數。網路記號總計是記號燒錄後剩餘的記號數量。方程式形式:淨記號 = 總鑄幣記號 - 總燃燒記號。如果沒有燒錄記號,則網路記號的數目會等於總鑄幣的記號。只有鏈碼的 Token Admin 或任何 Org Admin 才能呼叫此方法。
@Validator(yup.string())
public async getNetTokens(token_id: string) {
	const token_asset = await this.getTokenObject(token_id);
	await this.Ctx.Auth.checkAuthorization('TOKEN.getNetTokens', 'TOKEN');
	const netTokens = await this.Ctx.Token.getNetTokens(token_asset);
	return {
		msg: `Net supply of token for Token Id: ${token_id} is ${netTokens} tokens.`,
		quantity: netTokens
	};
}
參數:
  • token_id: string – 記號的 ID。
傳回值:
  • 成功時,表示記號淨數的 JSON 字串。
傳回值範例:
{"msg":"Net supply of token for Token Id: digiCurr101 is 0 tokens.","quantity":0}
requestMint
礦工可以呼叫此方法,以傳送要求給礦工公證人以建立指定數量的權杖。
@Validator(yup.string(), yup.string(), yup.string(), yup.string(), yup.number().positive(), yup.date(), yup.object().nullable())
public async requestMint( token_id: string, operation_id: string, notary_org_id: string, notary_user_id: string, quantity: number, time_to_expiration: Date, info_details?: InfoDetails) {

const token_asset = await this.getTokenObject(token_id);
const notary_account_id = await this.Ctx.Account.generateAccountId(token_id, notary_org_id, notary_user_id);
return await this.Ctx.Token.hold(operation_id, null, notary_account_id, quantity, time_to_expiration, token_asset, HoldOperationType.MINT, info_details);

}
參數:
  • token_id: string – 要提示的記號 ID。
  • operation_id: string – 代表提示要求的唯一作業 ID。
  • notary_org_id: string – 將處理要求之礦產公證人的會員服務提供者 (MSP) ID。
  • notary_user_id: string – 將處理要求之礦產公證人的使用者名稱或電子郵件 ID。
  • quantity: number – 要提示的記號數量。
  • time_to_expiration – 採礦要求到期且不再有效的時間。
  • info_details: JSON – 指定要求之類別 (category) 和描述 (description) 的物件。

    如果您使用 Visual Studio Code 與 CLI 或 Postman 集合,請以不同的格式指定 info_details 參數。

    Visual Studio 程式碼:{ "category": "category value", "description": "description value" }

    CLI / Postman: "{\"category\":\"category value\",\"description\":\"description value\"}"

傳回值範例:
{
msg:
"AccountId oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin) has successfully submitted request to mint 100 tokens",
}
approveMint
礦工公證人可呼叫此方法,以核准採礦請求。
@Validator(yup.string(), yup.string())
public async approveMint(token_id: string, operation_id: string) {
const token_asset = await this.getTokenObject(token_id);
return await this.Ctx.Token.executeHold(operation_id, token_asset);
}
參數:
  • token_id: string – 要提示的記號 ID。
  • operation_id: string – 代表提示要求的唯一作業 ID。
傳回值範例:
{
msg:
"Successfully minted 100 tokens to Account Id: oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin)"
}
rejectMint
礦物公證人可以呼叫此方法,以拒絕採礦要求。
@Validator(yup.string(), yup.string())
public async rejectMint(token_id: string, operation_id: string) {
const token_asset = await this.getTokenObject(token_id);
return await this.Ctx.Token.releaseHold(operation_id, token_asset);
}
參數:
  • token_id: string – 要提示的記號 ID。
  • operation_id: string – 代表提示要求的唯一作業 ID。
傳回值範例:
{
 msg: "Successfully rejected mint request with Operation Id 'operation1' to mint 100 tokens of token id token"
}
issueTokens
這個方法會提示該方法的呼叫程式所擁有的記號。
@Validator(yup.string(), yup.number().positive(), yup.object().nullable())
public async issueTokens(token_id: string, quantity: number, info_details?: InfoDetails) {
const token_asset = await this.getTokenObject(token_id);
return await this.Ctx.Token.mint(quantity, token_asset, info_details);
}
參數:
  • token_id: string – 記號的 ID。
  • quantity – 記號數目為 mint。
  • info_details: JSON – 指定要求之類別 (category) 和描述 (description) 的物件。

    如果您使用 Visual Studio Code 與 CLI 或 Postman 集合,請以不同的格式指定 info_details 參數。

    Visual Studio 程式碼:{ "category": "category value", "description": "description value" }

    CLI / Postman: "{\"category\":\"category value\",\"description\":\"description value\"}"

傳回值範例:
{
msg:
"Successfully minted 100 tokens to Account Id: oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin)"
}
getTotalMintedTokens
此方法會傳回指定記號的預期記號總數。只有 Token AdminToken AuditorOrg AdminOrg Auditor 才能呼叫此方法。
@Validator(yup.string())
 public async getTotalMintedTokens(token_id: string) {
     const token_asset = await this.getTokenObject(token_id);
     await this.Ctx.Auth.checkAuthorization('TOKEN.getTotalMintedTokens', 'TOKEN');
     const totalMintedTokens = await this.Ctx.Token.getTotalMintedTokens(token_asset);
     return {
         msg: `Total minted token for Token Id: ${token_id} is ${totalMintedTokens} tokens.`,
         quantity: totalMintedTokens
     };
 }
參數:
  • token_id: string – 記號的 ID。
傳回值:
  • 成功時,代表權杖總數的 JSON 字串。
傳回值範例:
{"msg":"Total minted token for Token Id: digiCurr101 is 100 tokens.","quantity":100}
getNetTokens
此方法會傳回系統中指定記號可用的記號總數。網路記號總計是記號燒錄後剩餘的記號數量。方程式形式:淨記號 = 總鑄幣記號 - 總燃燒記號。如果沒有燒錄記號,則網路記號的數目會等於總鑄幣的記號。只有 Token AdminToken AuditorOrg AdminOrg Auditor 才能呼叫此方法。
@Validator(yup.string())
public async getNetTokens(token_id: string) {
	const token_asset = await this.getTokenObject(token_id);
	await this.Ctx.Auth.checkAuthorization('TOKEN.getNetTokens', 'TOKEN');
	const netTokens = await this.Ctx.Token.getNetTokens(token_asset);
	return {
		msg: `Net supply of token for Token Id: ${token_id} is ${netTokens} tokens.`,
		quantity: netTokens
	};
}
參數:
  • token_id: string – 記號的 ID。
傳回值:
  • 成功時,表示記號淨數的 JSON 字串。
傳回值範例:
{"msg":"Net supply of token for Token Id: digiCurr101 is 0 tokens.","quantity":0}

權杖行為管理方法 - 可轉移行為

transferTokens
此方法會將記號從呼叫程式轉移至指定的帳戶。方法的呼叫程式必須要有帳戶。數量必須在規格檔案中 divisible 行為的 decimal 參數所指定的小數值內。只有帳戶的 AccountOwner 才能呼叫此方法。
@Validator(yup.string(), yup.string(), yup.string(), yup.number().positive())
public async transferTokens(token_id: string, to_org_id: string, to_user_id: string, quantity: number) {
   const token_asset = await this.getTokenObject(token_id);
   const to_account_id = await this.Ctx.Account.generateAccountId(token_id, to_org_id, to_user_id);
   return await this.Ctx.Token.transfer(to_account_id, quantity, token_asset);
}
參數:
  • token_id: string – 記號的 ID。
  • to_org_id: string – 目前組織中接收者 (受款人) 的成員服務提供者 (MSP) ID。
  • to_user_id: string – 接收者的使用者名稱或電子郵件 ID。
  • quantity: number – 要傳輸的記號數目。
傳回值:
  • 成功時,包含付款人與受款人帳戶明細的訊息。
傳回值範例:
{
    "msg": "Successfully transferred 400 tokens from account id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: user1) to account id: oaccount~digicur~682bb71de419602af74e3f226345ef308445ca51010737900c112435f676152df (Org-Id: Org1MSP, User-Id: user2) ",
}
bulkTransferTokens
此方法會將變數替代字從呼叫者帳戶大量傳輸至 flow 物件中指定的帳戶。數量必須位於此方法之規格 file.The 呼叫程式中 divisible 行為的 decimal 參數所指定的小數值內,必須已建立帳戶。只有帳戶的 AccountOwner 才能呼叫此方法。
@Validator(yup.string(), yup.array().of(yup.object()))
public async bulkTransferTokens(token_id: string, flow: object[]) {
     const token_asset = await this.getTokenObject(token_id);
     return await this.Ctx.Token.bulkTransfer(flow, token_asset);
}
參數:
  • token_id: string – 記號的 ID。
  • flow : object[] – 指定接收者與數量的 JSON 物件陣列。
    • to_orgId: string – 目前組織中接收者的成員服務提供者 (MSP) ID。
    • userId: string – 接收者的使用者名稱或電子郵件 ID。
    • quantity: number – 要傳輸的記號數目。
    如果您使用 Visual Studio Code 與 CLI 或 Postman 集合,請以不同的格式指定 flow 參數。
    Visual Studio 程式碼:
    [
      { "to_org_id": "Org1MSP", "to_user_id": "user1", "quantity": 10 },
      { "to_org_id": "Org1MSP", "to_user_id": "user2", "quantity": 10 }
    ]
    
    CLI / Postman:
    "[{ \"to_org_id\": \"Org1MSP\", \"to_user_id\": \"user1\", \"quantity\": 10 }, { \"to_org_id\": \"Org1MSP\", \"to_user_id\": \"user2\", \"quantity\": 10 }]"
傳回值:
  • 表示成功的訊息。
傳回值範例:
{
    "msg": "Successfully transferred 20 tokens from Account Id           'oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df' (Org-Id: Org1MSP, User-Id: admin).",
    "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
    "sub_transactions": [
        {
            "to_account_id": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
            "amount": 10
        },
        {
            "to_account_id": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
            "amount": 10
        }
    ]
}
transferTokens
此方法會將記號從呼叫程式轉移至指定的帳戶。
@Validator(yup.string(), yup.string(), yup.string(), yup.number().positive(), yup.object().nullable())
public async transferTokens(token_id: string, to_org_id: string, to_user_id: string, quantity: number, info_details?: InfoDetails) {
const token_asset = await this.getTokenObject(token_id);
const to_account_id = await this.Ctx.Account.generateAccountId(token_id, to_org_id, to_user_id);
return await this.Ctx.Token.transfer(to_account_id, quantity, token_asset, info_details);
}
參數:
  • token_id: string – 記號的 ID。
  • to_org_id: string – 目前組織中接收者 (受款人) 的成員服務提供者 (MSP) ID。
  • to_user_id: string – 接收者的使用者名稱或電子郵件 ID。
  • quantity: number – 要傳輸的記號數目。
  • info_details: JSON – 指定要求之類別 (category) 和描述 (description) 的物件。

    如果您使用 Visual Studio Code 與 CLI 或 Postman 集合,請以不同的格式指定 info_details 參數。

    Visual Studio 程式碼:{ "category": "category value", "description": "description value" }

    CLI / Postman: "{\"category\":\"category value\",\"description\":\"description value\"}"

傳回值範例:
{
 msg: "Successfully transferred 100 tokens from account id: oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin) to account id: oaccount~7yuijg39b4e1e4136dd86a806020c97a930909325340481b8fdhjklliugbv699 (Org-Id: Org1MSP, User-Id: user)",
}
bulkTransferTokens
此方法會將變數替代字從呼叫者帳戶大量傳輸至 flow 物件中指定的帳戶。數量必須位於此方法之規格 file.The 呼叫程式中 divisible 行為的 decimal 參數所指定的小數值內,必須已建立帳戶。只有帳戶的 AccountOwner 才能呼叫此方法。
@Validator(yup.string(), yup.array().of(yup.object()))
public async bulkTransferTokens(token_id: string, flow: object[]) {
     const token_asset = await this.getTokenObject(token_id);
     return await this.Ctx.Token.bulkTransfer(flow, token_asset);
}
參數:
  • token_id: string – 記號的 ID。
  • flow : object[] – 指定接收者與數量的 JSON 物件陣列。
    • to_orgId: string – 目前組織中接收者的成員服務提供者 (MSP) ID。
    • userId: string – 接收者的使用者名稱或電子郵件 ID。
    • quantity: number – 要傳輸的記號數目。
    如果您使用 Visual Studio Code 與 CLI 或 Postman 集合,請以不同的格式指定 flow 參數。
    Visual Studio 程式碼:
    [
      { "to_org_id": "Org1MSP", "to_user_id": "user1", "quantity": 10 },
      { "to_org_id": "Org1MSP", "to_user_id": "user2", "quantity": 10 }
    ]
    
    CLI / Postman:
    "[{ \"to_org_id\": \"Org1MSP\", \"to_user_id\": \"user1\", \"quantity\": 10 }, { \"to_org_id\": \"Org1MSP\", \"to_user_id\": \"user2\", \"quantity\": 10 }]"
傳回值:
  • 表示成功的訊息。
傳回值範例:
{
    "msg": "Successfully transferred 20 tokens from Account Id           'oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df' (Org-Id: Org1MSP, User-Id: admin).",
    "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
    "sub_transactions": [
        {
            "to_account_id": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
            "amount": 10
        },
        {
            "to_account_id": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
            "amount": 10
        }
    ]
}

權杖行為管理方法 - 可保留行為

holdTokens
此方法使用 to_account_id 帳戶代表權杖的擁有者建立保留。已指定公證人帳戶,該帳戶負責完成或解除保留。建立保留時,系統會保留付款人的指定變數替代字餘額。保留完成或解除之前,無法移轉保留餘額。此方法的來電者必須已建立帳戶。只有帳戶的 AccountOwner 才能呼叫此方法。
@Validator(yup.string(), yup.string(), yup.string(), yup.string(), yup.string(), yup.string(), yup.number().positive(), yup.date())
public async holdTokens(
    token_id: string,
    operation_id: string,
    to_org_id: string,
    to_user_id: string,
    notary_org_id: string,
    notary_user_id: string,
    quantity: number,
    time_to_expiration: Date
) {
    const token_asset = await this.getTokenObject(token_id);
    const to_account_id = await this.Ctx.Account.generateAccountId(token_id, to_org_id, to_user_id);
    const notary_account_id = await this.Ctx.Account.generateAccountId(token_id, notary_org_id, notary_user_id);
    return await this.Ctx.Token.hold(operation_id, to_account_id, notary_account_id, quantity, time_to_expiration, token_asset);
}
參數:
  • token_id: string – 記號的 ID。
  • operation_id: string – 識別保留作業的唯一 ID。通常此 ID 會由用戶端應用程式傳送。
  • to_org_id: string – 目前組織中接收者的成員服務提供者 (MSP) ID。
  • to_user_id: string – 接收者的使用者名稱或電子郵件 ID。
  • notary_org_id: string – 目前組織中公證人的會員服務提供者 (MSP) ID。
  • notary_user_id: string – 公證人的使用者名稱或電子郵件 ID。
  • quantity: number – 保留的記號數目。
  • time_to_expiration – 保留到期的時間。為永久保留指定 0 。否則,請使用 RFC-3339 格式。例如,2021-06-02T12:46:06Z
傳回值:
  • 成功時,與來電者帳戶的訊息並保留詳細資料。
傳回值範例:
{
  "msg":"AccountId oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP , User-Id: admin) is   successfully holding 10 tokens"
}
executeHoldTokens
這個方法會完成記號的保留。權杖擁有者先前持有的權杖數量會移轉給接收者。如果 quantity 值小於實際保留值,則剩餘金額會再次提供給權杖的原始擁有者。只有具有指定作業 ID 之 notary 角色的 AccountOwner ID 才能呼叫此方法。只有公證人才能完成保留。
@Validator(yup.string(), yup.string(), yup.number().positive())
public async executeHoldTokens(token_id: string, operation_id: string, quantity: number) {
    const token_asset = await this.getTokenObject(token_id);
    return await this.Ctx.Token.executeHold(operation_id, quantity, token_asset);
}
參數:
  • token_id: string – 記號的 ID。
  • operation_id: string – 識別保留作業的唯一 ID。通常此 ID 會由用戶端應用程式傳送。
  • quantity: number – 要轉移的保留記號數目。
傳回值:
  • 成功時,訊息會包含來電者帳戶 ID 與交易數量。
傳回值範例:
{
 "msg":"Account Id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: admin) is successfully executed '10' tokens from Operation Id 'opr_121'."
}
releaseHoldTokens
此方法會解除保留記號。轉帳未完成,所有保留的權杖都會再次提供給原始擁有者使用。具有 notary 角色的 AccountOwner ID 可在指定的時間限制內呼叫此方法,或由付款人、受款人或公證人在指定的時間限制之後呼叫。
@Validator(yup.string(), yup.string())
public async releaseHoldTokens(token_id: string, operation_id: string) {
    const token_asset = await this.getTokenObject(token_id);
    return await this.Ctx.Token.releaseHold(operation_id, token_asset);
}
參數:
  • token_id: string – 記號的 ID。
  • operation_id: string – 識別保留作業的唯一 ID。通常此 ID 會由用戶端應用程式傳送。
傳回值:
  • 成功時,會出現一則訊息,指出已解除保留。
傳回值範例:
{
 "msg":"Successfully released '10' tokens from Operation Id 'opr_121' to Account Id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: user1)."
}
getOnHoldIds
此方法會傳回指定帳戶之所有持有 ID 的清單。此方法可由鏈碼的 Token Admin、指定組織的 Org Admin 或帳戶的 AccountOwner 呼叫。
  @Validator(yup.string(), yup.string(), yup.string())
  public async getOnHoldIds(token_id: string, org_id: string, user_id: string) {
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getOnHoldIds", "TOKEN", { account_id });
    return await this.Ctx.Account.getOnHoldIds(account_id);
  }
參數:
  • token_id: string – 記號的 ID。
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,JSON 保留 ID 清單。
傳回值範例:
{"msg":"Holding Ids are: ohold~digicur~digiCurr101~opr_121","holding_ids":["ohold~digicur~digiCurr101~opr_121"]}
getOnHoldDetailsWithOperationId
此方法會傳回指定作業 ID 與變數替代字的保留異動明細。任何人都可以呼叫這個方法。
@Validator(yup.string(), yup.string())
public async getOnHoldDetailsWithOperationId(token_id: string, operation_id: string) {
    return await this.Ctx.Hold.getOnHoldDetailsWithOperationId(token_id, operation_id);
}
參數:
  • token_id: string – 記號的 ID。
  • operation_id: string – 識別保留作業的唯一 ID。通常此 ID 會由用戶端應用程式傳送。
傳回值:
  • 成功時,包含下列特性的 JSON 保留物件:
  • holding_id – 交易的持有 ID。
  • operation_id: string – 識別保留作業的唯一 ID。通常此 ID 會由用戶端應用程式傳送。
  • from_account_id - 保留權杖目前擁有者的帳戶 ID。
  • to_account_id – 接收者的帳戶 ID。
  • notary_account_id – 公證人的帳戶 ID。
  • token_id: string – 已儲存記號的 ID。
  • quantity – 保留 ID 的記號數量。
  • time_to_expiration – 保留到期前的持續時間。
傳回值範例:
{
    "assetType": "ohold",
    "holding_id": "ohold~digicur~digiCurr101~opr_121",
    "operation_id": "opr_121",
    "token_name": "digicur",
    "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
    "to_account_id": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
    "notary_account_id": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
    "token_id": "digiCurr101",
    "quantity": 10,
    "time_to_expiration": "2022-08-01T18:30:00.000Z"
}
getOnHoldBalanceWithOperationId
此方法會傳回指定作業 ID 與變數替代字的保留餘額。任何人都可以呼叫這個方法。
@Validator(yup.string(), yup.string())
public async getOnHoldBalanceWithOperationId(token_id: string, operation_id: string) {
    return await this.Ctx.Hold.getOnHoldBalanceWithOperationId(token_id, operation_id);
}
參數:
  • token_id: string – 記號的 ID。
  • operation_id: string – 識別保留作業的唯一 ID。通常此 ID 會由用戶端應用程式傳送。
傳回值:
  • 成功時,一個 JSON 字串表示持有餘額。
傳回值範例:
{
	"msg": "Current Holding Balance of Operation 'opr_121' for token 'digiCurr101' is: 10",
	"holding_balance": 10
}
holdTokens
此方法使用 to_account_id 帳戶代表權杖的擁有者建立保留。
@Validator(yup.string(), yup.string(), yup.string(), yup.string(), yup.string(), yup.string(), yup.number().positive(), yup.date(), yup.object().nullable())
  public async holdTokens( token_id: string, operation_id: string, to_org_id: string, to_user_id: string, notary_org_id: string, notary_user_id: string, quantity: number, time_to_expiration: Date, info_details?: InfoDetails) {
    const token_asset = await this.getTokenObject(token_id);
    const to_account_id = await this.Ctx.Account.generateAccountId(token_id, to_org_id, to_user_id);
    const notary_account_id = await this.Ctx.Account.generateAccountId(token_id, notary_org_id, notary_user_id);
    return await this.Ctx.Token.hold(operation_id, to_account_id, notary_account_id, quantity, time_to_expiration, token_asset, HoldOperationType.TRANSFER, info_details);
  }
參數:
  • token_id: string – 記號的 ID。
  • operation_id: string – 識別保留作業的唯一 ID。通常此 ID 會由用戶端應用程式傳送。
  • to_org_id: string – 目前組織中接收者的成員服務提供者 (MSP) ID。
  • to_user_id: string – 接收者的使用者名稱或電子郵件 ID。
  • notary_org_id: string – 目前組織中公證人的會員服務提供者 (MSP) ID。
  • notary_user_id: string – 公證人的使用者名稱或電子郵件 ID。
  • quantity: number – 保留的記號數目。
  • time_to_expiration – 保留到期的時間。為永久保留指定 0 。否則,請使用 RFC-3339 格式。例如,2021-06-02T12:46:06Z
  • info_details: JSON – 指定要求之類別 (category) 和描述 (description) 的物件。

    如果您使用 Visual Studio Code 與 CLI 或 Postman 集合,請以不同的格式指定 info_details 參數。

    Visual Studio 程式碼:{ "category": "category value", "description": "description value" }

    CLI / Postman: "{\"category\":\"category value\",\"description\":\"description value\"}"

傳回值範例:
{
msg:
"AccountId oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin) is successfully holding 100 tokens",
}
executeHoldTokens
這個方法會完成記號的保留。權杖擁有者先前持有的權杖數量會移轉給接收者。如果 quantity 值小於實際保留值,則剩餘金額會再次提供給權杖的原始擁有者。只有具有指定作業 ID 之 notary 角色的 AccountOwner ID 才能呼叫此方法。只有公證人才能完成保留。
@Validator(yup.string(), yup.string(), yup.number().positive())
public async executeHoldTokens(token_id: string, operation_id: string, quantity: number) {
    const token_asset = await this.getTokenObject(token_id);
    return await this.Ctx.Token.executeHold(operation_id, quantity, token_asset);
}
參數:
  • token_id: string – 記號的 ID。
  • operation_id: string – 識別保留作業的唯一 ID。通常此 ID 會由用戶端應用程式傳送。
  • quantity: number – 要轉移的保留記號數目。
傳回值:
  • 成功時,訊息會包含來電者帳戶 ID 與交易數量。
傳回值範例:
{
 "msg":"Account Id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: admin) is successfully executed '10' tokens from Operation Id 'opr_121'."
}
releaseHoldTokens
此方法會解除保留記號。轉帳未完成,所有保留的權杖都會再次提供給原始擁有者使用。具有 notary 角色的 AccountOwner ID 可在指定的時間限制內呼叫此方法,或由付款人、受款人或公證人在指定的時間限制之後呼叫。
@Validator(yup.string(), yup.string())
public async releaseHoldTokens(token_id: string, operation_id: string) {
    const token_asset = await this.getTokenObject(token_id);
    return await this.Ctx.Token.releaseHold(operation_id, token_asset);
}
參數:
  • token_id: string – 記號的 ID。
  • operation_id: string – 識別保留作業的唯一 ID。通常此 ID 會由用戶端應用程式傳送。
傳回值:
  • 成功時,會出現一則訊息,指出已解除保留。
傳回值範例:
{
 "msg":"Successfully released '10' tokens from Operation Id 'opr_121' to Account Id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: user1)."
}
getOnHoldIds
此方法會傳回指定帳戶之所有持有 ID 的清單。此方法可由鏈碼的 Token AdminToken Auditor、指定組織的 Org AdminOrg Auditor 或帳戶的 AccountOwner 呼叫。
  @Validator(yup.string(), yup.string(), yup.string())
  public async getOnHoldIds(token_id: string, org_id: string, user_id: string) {
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getOnHoldIds", "TOKEN", { account_id });
    return await this.Ctx.Account.getOnHoldIds(account_id);
  }
參數:
  • token_id: string – 記號的 ID。
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,JSON 保留 ID 清單。
傳回值範例:
{"msg":"Holding Ids are: ohold~digicur~digiCurr101~opr_121","holding_ids":["ohold~digicur~digiCurr101~opr_121"]}
getOnHoldDetailsWithOperationId
此方法會傳回指定作業 ID 與變數替代字的保留異動明細。此方法可由鏈碼的 Token AdminToken Auditor 呼叫,或由交易參與者 (寄件者、收件者、公證人) 呼叫。
@Validator(yup.string(), yup.string())
public async getOnHoldDetailsWithOperationId(token_id: string, operation_id: string) {
    return await this.Ctx.Hold.getOnHoldDetailsWithOperationId(token_id, operation_id);
}
參數:
  • token_id: string – 記號的 ID。
  • operation_id: string – 識別保留作業的唯一 ID。通常此 ID 會由用戶端應用程式傳送。
傳回值:
  • 成功時,包含下列特性的 JSON 保留物件:
  • holding_id – 交易的持有 ID。
  • operation_id: string – 識別保留作業的唯一 ID。通常此 ID 會由用戶端應用程式傳送。
  • from_account_id - 保留權杖目前擁有者的帳戶 ID。
  • to_account_id – 接收者的帳戶 ID。
  • notary_account_id – 公證人的帳戶 ID。
  • token_id: string – 已儲存記號的 ID。
  • quantity – 保留 ID 的記號數量。
  • time_to_expiration – 保留到期前的持續時間。
傳回值範例:
{
    "assetType": "ohold",
    "holding_id": "ohold~digicur~digiCurr101~opr_121",
    "operation_id": "opr_121",
    "token_name": "digicur",
    "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
    "to_account_id": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
    "notary_account_id": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
    "token_id": "digiCurr101",
    "quantity": 10,
    "time_to_expiration": "2022-08-01T18:30:00.000Z"
}
getOnHoldBalanceWithOperationId
此方法會傳回指定作業 ID 與變數替代字的保留餘額。此方法可由鏈碼的 Token AdminToken Auditor 呼叫,或由交易參與者 (寄件者、收件者、公證人) 呼叫。
@Validator(yup.string(), yup.string())
public async getOnHoldBalanceWithOperationId(token_id: string, operation_id: string) {
    return await this.Ctx.Hold.getOnHoldBalanceWithOperationId(token_id, operation_id);
}
參數:
  • token_id: string – 記號的 ID。
  • operation_id: string – 識別保留作業的唯一 ID。通常此 ID 會由用戶端應用程式傳送。
傳回值:
  • 成功時,一個 JSON 字串表示持有餘額。
傳回值範例:
{
	"msg": "Current Holding Balance of Operation 'opr_121' for token 'digiCurr101' is: 10",
	"holding_balance": 10
}

記號行為管理方法 - 可燃行為

burnTokens
此方法會停用或燒錄交易呼叫者帳戶中的記號。此方法的來電者必須具有帳戶與燒錄者角色。數量必須在規格檔案中 divisible 行為的 decimal 參數所指定的小數值內。具有燒錄機角色之帳戶的 AccountOwner 可以呼叫此方法。
@Validator(yup.string(), yup.number().positive())
public async burnTokens(token_id: string, quantity: number) {
    const token_asset = await this.getTokenObject(token_id);
    return await this.Ctx.Token.burn(quantity, token_asset);
}
參數:
  • token_id: string – 記號的 ID。
  • quantity – 要燒錄的記號數目。
傳回值:
  • 成功時,會顯示已燒錄記號數量和帳戶 ID 的成功訊息。
傳回值範例:
{
    "msg": "Successfully burned 10 tokens from account id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: admin)"
}
requestBurn
燃燒器可以呼叫此方法,以傳送要求給燃燒器公證,以銷毀指定數量的記號,此記號必須小於或等於其可用餘額。當燒錄要求開始時,指定的金額會立即從可用餘額中扣除,並新增至 onhold_burn_balance 欄位。如果請求獲得核准,則系統會燒錄權杖。如果要求被拒絕,則記號會從 onhold_burn_balance 欄位傳回至可用餘額。
@Validator(yup.string(), yup.string(), yup.string(), yup.string(), yup.number().positive(), yup.date(), yup.object().nullable())

public async requestBurn( token_id: string, operation_id: string, notary_org_id: string, notary_user_id: string, quantity: number, time_to_expiration: Date, info_details?: InfoDetails ) {

const token_asset = await this.getTokenObject(token_id);
const notary_account_id = await this.Ctx.Account.generateAccountId(token_id, notary_org_id, notary_user_id);
return await this.Ctx.Token.hold(operation_id, null, notary_account_id, quantity, time_to_expiration, token_asset, HoldOperationType.BURN, null, description);
}
參數:
  • token_id: string – 要燒錄的記號 ID。
  • operation_id: string – 代表燒錄要求的唯一作業 ID。
  • notary_org_id: string – 將處理要求的燒錄公證人會員服務提供者 (MSP) ID。
  • notary_user_id: string – 將處理要求之燒錄者公證人的使用者名稱或電子郵件 ID。
  • quantity: number – 要燒錄的記號數量。
  • time_to_expiration – 燒錄要求到期且不再有效的時間。
  • info_details: JSON – 指定要求之類別 (category) 和描述 (description) 的物件。

    如果您使用 Visual Studio Code 與 CLI 或 Postman 集合,請以不同的格式指定 info_details 參數。

    Visual Studio 程式碼:{ "category": "category value", "description": "description value" }

    CLI / Postman: "{\"category\":\"category value\",\"description\":\"description value\"}"

傳回值範例:
{
msg:
"AccountId oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin) has successfully submitted request to mint 100 tokens",
}
approveBurn
燒錄機公證人可以呼叫此方法來核准燒錄要求。
@Validator(yup.string(), yup.string())
public async approveBurn(token_id: string, operation_id: string) {
const token_asset = await this.getTokenObject(token_id);
return await this.Ctx.Token.executeHold(operation_id, token_asset);
}
參數:
  • token_id: string – 要燒錄的記號 ID。
  • operation_id: string – 代表燒錄要求的唯一作業 ID。
傳回值範例:
{
msg:
"Successfully burned 100 tokens from account id: oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin)"
}
rejectBurn
燃燒器公證可以呼叫此方法,以拒絕燒錄請求。
@Validator(yup.string(), yup.string())
public async rejectBurn(token_id: string, operation_id: string) {
const token_asset = await this.getTokenObject(token_id);
return await this.Ctx.Token.releaseHold(operation_id, token_asset);
}
參數:
  • token_id: string – 要燒錄的記號 ID。
  • operation_id: string – 代表燒錄要求的唯一作業 ID。
傳回值範例:
{
 msg: "Successfully rejected burn request with Operation Id 'operation1' to burn 100 tokens of token id token",
}
getAccountOnHoldBurnBalance
此方法會傳回指定使用者的暫停燒錄餘額。只有 Token AdminToken AuditorOrg AdminOrg Auditor 或帳戶擁有者才能呼叫此方法。
@GetMethod()
@Validator(yup.string(), yup.string(), yup.string())
public async getAccountOnHoldBurnBalance(token_id: string, org_id: string, user_id: string) {
  const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
  await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAccountOnHoldBurnBalance", "TOKEN", { account_id });
  return await this.Ctx.Account.getAccountOnHoldBurnBalance(account_id);
}
參數:
  • token_id: string – 要燒錄的記號 ID。
  • org_id string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id string – 使用者的使用者名稱或電子郵件 ID。
傳回值範例:
{
  "msg": "Total On Hold Burning Balance is: 10",
  "onhold_burn_balance": 10
}
burnTokens
此方法會停用或燒錄交易呼叫者帳戶中的記號。
@Validator(yup.string(), yup.number().positive(), yup.object().nullable())

public async burnTokens(token_id: string, quantity: number, info_details?: InfoDetails) {
const token_asset = await this.getTokenObject(token_id);
return await this.Ctx.Token.burn(quantity, token_asset, info_details);
}
參數:
  • token_id: string – 記號的 ID。
  • quantity – 要燒錄的記號數目。
  • info_details: JSON – 指定要求之類別 (category) 和描述 (description) 的物件。

    如果您使用 Visual Studio Code 與 CLI 或 Postman 集合,請以不同的格式指定 info_details 參數。

    Visual Studio 程式碼:{ "category": "category value", "description": "description value" }

    CLI / Postman: "{\"category\":\"category value\",\"description\":\"description value\"}"

傳回值範例:
{
msg:
"Successfully burned 100 tokens from account id: oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin)"
}

自訂方式

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

為了避免重複花費,請勿合併在狀態資料庫中相同的索引鍵 - 值組上運作的多個非同步函數。請改用 bulkTransferTokens 方法,以一個方法來進行多個傳輸。

下列範例顯示如何在自訂方法中使用記號 SDK 方法。呼叫 buyTicket 方法時,會將 20 個權杖從來電者的帳戶轉移至賣方的帳戶,並傳回轉接的交易訊息。

@Validator(yup.string(), yup.string(), yup.string(), yup.string(), yup.string())
public async buyTicket(token_id: string, seller_org_id: string, seller_user_id: string) {
	const token = await this.getTokenObject(token_id);

	/**
	* The following method this.Ctx.Account.generateAccountId(token_id, seller_org_id, seller_user_id) generates account id of the seller.
	*/
	const seller_account_id = await this.Ctx.Account.generateAccountId(token_id, seller_org_id, seller_user_id);

	/**
	* The following method this.Ctx.Token.transfer(seller_account_id, 20, token) transfers the quantity 20 from caller's
	* account & to seller's account.
	*/
	const transaction = await this.Ctx.Token.transfer(seller_account_id, 20, token);

	return transaction;
}

如果您在自訂方法中使用多個記號 SDK 方法,請不要使用會影響狀態資料庫中相同索引鍵 - 值組的方法。下列範例顯示進行多重調動的正確方法:

@Validator(yup.string(), yup.string(), yup.string(), yup.string(), yup.string())
public async sendTokens(token_id: string, user1_org_id: string, user1_user_id: string, user2_org_id: string, user2_user_id: string) {
    const token = await this.getTokenObject(token_id);
    const user1_account_id = await Account.generateAccountId(token_id, user1_org_id, user1_user_id);
    const user2_account_id = await Account.generateAccountId(token_id, user2_org_id, user2_user_id);
    await token.transfer(user1_account_id, 20);
    await token.transfer(user2_account_id, 30);
}

請改用 bulkTransferTokens 方法,從呼叫者的帳戶轉移到多個帳戶,如以下程式碼片段所示。

bulkTransferTokens(token_id: string, flow: object[])

附註:

如果您在可能影響狀態資料庫中相同索引鍵 - 值組的自訂方法中使用多個記號 SDK 方法,請對記號鏈碼啟用 MVCC 最佳化。如需詳細資訊,請參閱 MVCC Optimization

權杖 SDK 方法

存取控制管理方法

權杖 SDK 提供存取控制功能。某些方法只能由記號的 Token AdminOrg AdminAccountOwner 呼叫。您可以使用此功能來確保只由預期的使用者執行作業。任何未授權的存取都會導致錯誤。若要使用存取控制功能,請從 ../lib/auth 模組匯入 Authorization 類別。
import { Authorization } from '../lib/auth';
addAdmin
此方法會將使用者新增為權杖鏈碼的 Token Admin
Ctx.Admin.addAdmin(org_id: string, user_id: string)
參數:
  • user_id – 使用者的使用者名稱或電子郵件 ID。
  • org_id – 目前網路組織中使用者的成員服務提供者 (MSP) ID。
傳回值:
  • 成功時,含有 JSON 物件的承諾訊息會列出新增為權杖鏈碼 Token Admin 的使用者明細。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
    "msg": "Successfully added Admin (Org_Id: Org1MSP, User_Id: user1)"
}
removeAdmin
此方法會移除使用者作為記號鏈碼的 Token Admin
Ctx.Admin.removeAdmin(org_id: string, user_id: string)
參數:
  • user_id – 使用者的使用者名稱或電子郵件 ID。
  • org_id – 目前網路組織中使用者的成員服務提供者 (MSP) ID。
傳回值:
  • 成功時,包含 JSON 物件的承諾訊息會列出不再是權杖鏈碼 Token Admin 之使用者的詳細資訊。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
    "msg": "Successfully removed Admin (Org_Id: Org1MSP, User_Id: user1)"
}
isUserTokenAdmin
如果函數的呼叫程式是 Token Admin,此方法會傳回布林值 true。否則,方法會傳回 false
Ctx.Auth.isUserTokenAdmin()
參數:
  • user_id – 使用者的使用者名稱或電子郵件 ID。
  • org_id – 目前網路組織中使用者的成員服務提供者 (MSP) ID。
傳回值:
  • 布林回應與錯誤訊息 (如果發生錯誤)。
getAllAdmins
此方法會傳回記號鏈碼 Token Admin 的所有使用者清單。
Ctx.Admin.getAllAdmins()
參數:
傳回值:
  • 成功時,具有 JSON 物件的承諾會列出權杖鏈碼 Token Admin 的所有使用者明細。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
    "admins": [
        {
            "orgId": "Org1MSP",
            "userId": "admin"
        }
    ]
}
checkAuthorization
使用此方法將存取控制檢查新增至作業。某些記號方法只能由記號的 Token AdminAccountOwner 執行,或由 MultipleAccountOwner 針對具有多個帳戶的使用者執行。存取控制對應詳述於 ../lib/constant.ts 檔案中。您可以編輯 ../lib/constant.ts 檔案來修改存取控制。若要使用自己的存取控制或停用存取控制,請從自動產生的控制器方法和自訂方法中移除存取控制碼。
export const TOKENACCESS = {
  ADMIN: {
    isUserTokenAdmin: ["Admin", "OrgAdmin"],
    addTokenAdmin: ["Admin"],
    removeTokenAdmin: ["Admin"],
    getAllAdmins: ["Admin", "OrgAdmin"],
    addOrgAdmin: ["Admin", "OrgAdminForOrgId"],
    removeOrgAdmin: ["Admin", "OrgAdminForOrgId"],
    getOrgAdmins: ["Admin", "OrgAdmin"],
  },
  TOKEN: {
    save: ["Admin"],
    getAllTokens: ["Admin", "OrgAdmin"],
    get: ["Admin", "OrgAdmin"],
    update: ["Admin"],
    getDecimals: ["Admin", "OrgAdmin"],
    getTokensByName: ["Admin", "OrgAdmin"],
    addRoleMember: ["Admin", "OrgAdminRoleCheck"],
    removeRoleMember: ["Admin", "OrgAdminRoleCheck"],
    isInRole: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getTotalMintedTokens: ["Admin", "OrgAdmin"],
    getNetTokens: ["Admin", "OrgAdmin"],
    getTokenHistory: ["Admin", "OrgAdmin"],
  },
  ROLE: {
    getAccountsByRole: ["Admin"],
    getOrgAccountsByRole: ["Admin", "OrgAdminForOrgId"],
    getUsersByRole: ["Admin"],
    getOrgUsersByRole: ["Admin", "OrgAdminForOrgId"],
  },
  TRANSACTION: {
    deleteTransactions: ["Admin"],
  },ACCOUNT: {
    createAccount: ["Admin", "OrgAdminForOrgId"],
    associateToken: ["Admin", "OrgAdminForAccountId"],
    getAllAccounts: ["Admin"],
    getAllOrgAccounts: ["Admin", "OrgAdminForOrgId"],
    getAccountsByUser: ["Admin", "OrgAdminForOrgId", "MultipleAccountOwner"],
    getAccount: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    history: ["Admin", "AccountOwner"],
    getAccountTransactionHistory: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getAccountTransactionHistoryWithFilters: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getSubTransactionsById: ["Admin", "TransactionInvoker"],
    getSubTransactionsByIdWithFilters: ["Admin", "TransactionInvoker"],
    getAccountBalance: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getAccountOnHoldBalance: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getOnHoldIds: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getConversionHistory: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
  },
  ACCOUNT_STATUS: {
    get: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    history: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    activateAccount: ["Admin", "OrgAdminForOrgId"],
    suspendAccount: ["Admin", "OrgAdminForOrgId"],
    deleteAccount: ["Admin", "OrgAdminForOrgId"],
  },
  TOKEN_CONVERSION: {
    initializeExchangePoolUser: ["Admin"],
    addConversionRate: ["Admin"],
    updateConversionRate: ["Admin"],
    getConversionRate: ["Admin", "OrgAdmin", "AnyAccountOwner"],
    getConversionRateHistory: ["Admin", "OrgAdmin", "AnyAccountOwner"],
    tokenConversion: ["Admin", "AnyAccountOwner"],
    getExchangePoolUser: ["Admin"],
  },
}
await this.Ctx.Auth.checkAuthorization(<parameters>);
參數:
  • classFuncName: string – 類別與方法之間的對應值,如 ../lib/constant.ts 檔案中所述。
  • ...args – 變數引數,其中 args[0] 會採用常數 'TOKEN' ,而 args[1] 會採用 account_id 來新增 AccountOwner 的存取控制檢查。若要新增 MultipleAccountOwner 的存取控制檢查,args[1] 會採用 org_id,而 args[2] 則採用 user_id
傳回值:
  • 成功實現承諾。發生錯誤時,拒絕並顯示錯誤訊息。
addOrgAdmin
此方法會將使用者新增為組織的 Org Admin
Ctx.Admin.addOrgAdmin(org_id, user_id)
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會出現一則訊息,其中包含新增為組織 Org Admin 的使用者詳細資訊。
傳回值範例:
{
    "msg": "Successfully added Org Admin (Org_Id: Org1MSP, User_Id: orgAdmin)"
}
removeOrgAdmin
此方法會移除使用者作為組織的 Org Admin
Ctx.Admin.removeOrgAdmin(org_id, user_id)
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會顯示一則訊息,其中包含作為組織 Org Admin 移除之使用者的詳細資料。
傳回值範例:
{
  "msg": "Successfully removed Org Admin (Org_Id Org1MSP User_Id orgAdmin)"
}
getOrgAdmins
此方法會傳回屬於組織 Org Admin 的所有使用者清單。
Ctx.Admin.getAllOrgAdmins()
參數:
傳回值:
  • 成功時,JSON 格式的陣列包含 orgIduserId 物件。
傳回值範例:
{
    "admins": [
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin"
        },
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin1"
        },
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin2"
        }
    ]
}
addAdmin
此方法會將使用者新增為權杖鏈碼的 Token Admin
Ctx.Admin.addAdmin(org_id: string, user_id: string)
參數:
  • user_id – 使用者的使用者名稱或電子郵件 ID。
  • org_id – 目前網路組織中使用者的成員服務提供者 (MSP) ID。
傳回值:
  • 成功時,含有 JSON 物件的承諾訊息會列出新增為權杖鏈碼 Token Admin 的使用者明細。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
    "msg": "Successfully added Admin (Org_Id: Org1MSP, User_Id: user1)"
}
removeAdmin
此方法會移除使用者作為記號鏈碼的 Token Admin
Ctx.Admin.removeAdmin(org_id: string, user_id: string)
參數:
  • user_id – 使用者的使用者名稱或電子郵件 ID。
  • org_id – 目前網路組織中使用者的成員服務提供者 (MSP) ID。
傳回值:
  • 成功時,包含 JSON 物件的承諾訊息會列出不再是權杖鏈碼 Token Admin 之使用者的詳細資訊。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
    "msg": "Successfully removed Admin (Org_Id: Org1MSP, User_Id: user1)"
}
isUserTokenAdmin
如果函數的呼叫程式是 Token Admin,此方法會傳回布林值 true。否則,方法會傳回 false
Ctx.Auth.isUserTokenAdmin()
參數:
  • user_id – 使用者的使用者名稱或電子郵件 ID。
  • org_id – 目前網路組織中使用者的成員服務提供者 (MSP) ID。
傳回值:
  • 布林回應與錯誤訊息 (如果發生錯誤)。
getAllAdmins
此方法會傳回記號鏈碼 Token Admin 的所有使用者清單。
Ctx.Admin.getAllAdmins()
參數:
傳回值:
  • 成功時,具有 JSON 物件的承諾會列出權杖鏈碼 Token Admin 的所有使用者明細。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
    "admins": [
        {
            "orgId": "Org1MSP",
            "userId": "admin"
        }
    ]
}
checkAuthorization
使用此方法將存取控制檢查新增至作業。某些記號方法只能由記號的 Token AdminAccountOwner 執行,或由 MultipleAccountOwner 針對具有多個帳戶的使用者執行。存取控制對應詳述於 ../lib/constant.ts 檔案中。您可以編輯 ../lib/constant.ts 檔案來修改存取控制。若要使用自己的存取控制或停用存取控制,請從自動產生的控制器方法和自訂方法中移除存取控制碼。
export const TOKENACCESS = {
  ADMIN: {
    isUserTokenAdmin: ["Admin", "OrgAdmin"],
    addTokenAdmin: ["Admin"],
    removeTokenAdmin: ["Admin"],
    getAllAdmins: ["Admin", "OrgAdmin"],
    addOrgAdmin: ["Admin", "OrgAdminForOrgId"],
    removeOrgAdmin: ["Admin", "OrgAdminForOrgId"],
    getOrgAdmins: ["Admin", "OrgAdmin"],
  },
  TOKEN: {
    save: ["Admin"],
    getAllTokens: ["Admin", "OrgAdmin"],
    get: ["Admin", "OrgAdmin"],
    update: ["Admin"],
    getDecimals: ["Admin", "OrgAdmin"],
    getTokensByName: ["Admin", "OrgAdmin"],
    addRoleMember: ["Admin", "OrgAdminRoleCheck"],
    removeRoleMember: ["Admin", "OrgAdminRoleCheck"],
    isInRole: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getTotalMintedTokens: ["Admin", "OrgAdmin"],
    getNetTokens: ["Admin", "OrgAdmin"],
    getTokenHistory: ["Admin", "OrgAdmin"],
  },
  ROLE: {
    getAccountsByRole: ["Admin"],
    getOrgAccountsByRole: ["Admin", "OrgAdminForOrgId"],
    getUsersByRole: ["Admin"],
    getOrgUsersByRole: ["Admin", "OrgAdminForOrgId"],
  },
  TRANSACTION: {
    deleteTransactions: ["Admin"],
  },ACCOUNT: {
    createAccount: ["Admin", "OrgAdminForOrgId"],
    associateToken: ["Admin", "OrgAdminForAccountId"],
    getAllAccounts: ["Admin"],
    getAllOrgAccounts: ["Admin", "OrgAdminForOrgId"],
    getAccountsByUser: ["Admin", "OrgAdminForOrgId", "MultipleAccountOwner"],
    getAccount: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    history: ["Admin", "AccountOwner"],
    getAccountTransactionHistory: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getAccountTransactionHistoryWithFilters: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getSubTransactionsById: ["Admin", "TransactionInvoker"],
    getSubTransactionsByIdWithFilters: ["Admin", "TransactionInvoker"],
    getAccountBalance: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getAccountOnHoldBalance: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getOnHoldIds: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getConversionHistory: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
  },
  ACCOUNT_STATUS: {
    get: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    history: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    activateAccount: ["Admin", "OrgAdminForOrgId"],
    suspendAccount: ["Admin", "OrgAdminForOrgId"],
    deleteAccount: ["Admin", "OrgAdminForOrgId"],
  },
  TOKEN_CONVERSION: {
    initializeExchangePoolUser: ["Admin"],
    addConversionRate: ["Admin"],
    updateConversionRate: ["Admin"],
    getConversionRate: ["Admin", "OrgAdmin", "AnyAccountOwner"],
    getConversionRateHistory: ["Admin", "OrgAdmin", "AnyAccountOwner"],
    tokenConversion: ["Admin", "AnyAccountOwner"],
    getExchangePoolUser: ["Admin"],
  },
}
await this.Ctx.Auth.checkAuthorization(<parameters>);
參數:
  • classFuncName: string – 類別與方法之間的對應值,如 ../lib/constant.ts 檔案中所述。
  • ...args – 變數引數,其中 args[0] 會採用常數 'TOKEN' ,而 args[1] 會採用 account_id 來新增 AccountOwner 的存取控制檢查。若要新增 MultipleAccountOwner 的存取控制檢查,args[1] 會採用 org_id,而 args[2] 則採用 user_id
傳回值:
  • 成功實現承諾。發生錯誤時,拒絕並顯示錯誤訊息。
addOrgAdmin
此方法會將使用者新增為組織的 Org Admin
Ctx.Admin.addOrgAdmin(org_id, user_id)
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會出現一則訊息,其中包含新增為組織 Org Admin 的使用者詳細資訊。
傳回值範例:
{
    "msg": "Successfully added Org Admin (Org_Id: Org1MSP, User_Id: orgAdmin)"
}
removeOrgAdmin
此方法會移除使用者作為組織的 Org Admin
Ctx.Admin.removeOrgAdmin(org_id, user_id)
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會顯示一則訊息,其中包含作為組織 Org Admin 移除之使用者的詳細資料。
傳回值範例:
{
  "msg": "Successfully removed Org Admin (Org_Id Org1MSP User_Id orgAdmin)"
}
getOrgAdmins
此方法會傳回屬於組織 Org Admin 的所有使用者清單。
Ctx.Admin.getAllOrgAdmins()
參數:
傳回值:
  • 成功時,JSON 格式的陣列包含 orgIduserId 物件。
傳回值範例:
{
    "admins": [
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin"
        },
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin1"
        },
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin2"
        }
    ]
}
addTokenAuditor
此方法會將使用者新增為鏈碼的 Token Auditor
this.Ctx.Admin.addTokenAuditor(org_id, user_id)
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會出現一則訊息,其中包含新增為鏈碼 Token Auditor 的使用者詳細資料。
傳回值範例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "txid": "cd81f6c4c9e7c18ece357dbf5c139ef66ef2d6566be3b14de5f6d0a3fd4bb2f0",
        "payload": {
            "msg": "Successfully added Token Auditor (Org_Id: CB, User_Id: cb)"
        },
        "encode": "JSON",
        "sourceURL": "cb-oabcs1-bom.blockchain.ocp.example.com:20009",
        "blockNumber": 196
    }
}
removeTokenAuditor
此方法會移除使用者作為鏈碼的 Token Auditor
this.Ctx.Admin.removeTokenAuditor(org_id, user_id)
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會顯示一則訊息,其中包含被移除為鏈碼 Token Auditor 的使用者詳細資料。
傳回值範例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "txid": "a886a6040fbc76374a3c78c89ab0ffc9f7b8391cc5239b169bf3b878cf40c67b",
        "payload": {
            "msg": "Successfully removed Token Auditor (Org_Id: CB, User_Id: cb)"
        },
        "encode": "JSON",
        "sourceURL": "cb-oabcs1-bom.blockchain.ocp.example.com:20010",
        "blockNumber": 219
    }
}
getTokenAuditors
此方法會傳回鏈碼的所有 Token Auditors
this.Ctx.Admin.getAllTokenAuditors()
傳回值範例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "payload": {
            "auditors": [
                {
                    "org_id": "CB",
                    "user_id": "auditor_user_cb"
                }
            ]
        },
        "encode": "JSON"
    }
}
addOrgAuditor
此方法會將使用者新增為鏈碼的 Org Auditor
this.Ctx.Admin.addOrgAuditor(org_id, user_id)
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會出現一則訊息,其中包含新增為鏈碼 Org Auditor 的使用者詳細資料。
傳回值範例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "txid": "44bbad35a1478cb714e32f7cfd551897868a203520aab9cea5771d3aadc1cf03",
        "payload": {
            "msg": "Successfully added Org Auditor (Org_Id: CB, User_Id: cb)"
        },
        "encode": "JSON",
        "sourceURL": "cb-oabcs1-bom.blockchain.ocp.example.com:20009",
        "blockNumber": 198
    }
}
removeOrgAuditor
此方法會移除使用者作為鏈碼的 Org Auditor
this.Ctx.Admin.removeOrgAuditor(org_id, user_id)
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,會顯示一則訊息,其中包含被移除為鏈碼 Org Auditor 的使用者詳細資料。
傳回值範例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "txid": "c3bc720461004a53b37c68d4bb264858b88d980bc093a0a3ebb62a32974fb306",
        "payload": {
            "msg": "Successfully removed Org Auditor (Org_Id: CB, User_Id: cb)"
        },
        "encode": "JSON",
        "sourceURL": "cb-oabcs1-bom.blockchain.ocp.example.com:20010",
        "blockNumber": 221
    }
}
getOrgAuditors
此方法會傳回鏈碼的所有 Org Auditors
this.Ctx.Admin.getAllOrgAuditors()
傳回值範例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "payload": {
            "auditors": [
                {
                    "org_id": "FI1",
                    "user_id": "auditor_user_fi1"
                },
                {
                    "org_id": "FI2",
                    "user_id": "auditor_user_fi2"
                }
            ]
        },
        "encode": "JSON"
    }
}

權杖組態管理方法

save
這個方法會建立一個記號,並將它的特性儲存到狀態資料庫中。
Ctx.Token.save(token: <Instance of Token Class>,extraMetadata?:any)
參數:
  • token: <Instance of Token Class> – 要操作的記號資產。
傳回值:
  • 成功時,包含變數替代字明細的承諾訊息。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
   "assetType":"otoken",
   "token_id":"digiCurr101",
   "token_name":"digicur",
   "token_type":"fungible",
   "behaviors":[
      "divisible",
      "mintable",
      "transferable",
      "burnable",
      "roles"
   ],
   "roles":{
      "minter_role_name":"minter"
   },
   "mintable":{
      "max_mint_quantity":1000
   },
   "divisible":{
      "decimal":2
   },
   "currency_name":"DOLLAR",
   "token_to_currency_ratio":1
}
update
此方法會更新記號特性。記號資產建立後,您只會更新 token_desc 值及其自訂特性。
Ctx.Token.update(token: <Instance of Token Class>)
參數:
  • token: <Instance of Token Class> – 要操作的記號資產。
傳回值:
  • 成功時,包含變數替代字明細的承諾訊息。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
   "assetType":"otoken",
   "token_id":"digiCurr101",
   "token_name":"digicur",
   "token_desc":"Digital Currency equiv of dollar",
   "token_type":"fungible",
   "behaviors":[
      "divisible",
      "mintable",
      "transferable",
      "burnable",
      "roles"
   ],
   "roles":{
      "minter_role_name":"minter"
   },
   "mintable":{
      "max_mint_quantity":1000
   },
   "divisible":{
      "decimal":2
   },
   "currency_name":"DOLLAR",
   "token_to_currency_ratio":1
}
getTokenDecimals
此方法會傳回小數記號可用的小數位數。如果未指定 divisible 行為,則預設值為 0。
Ctx.Token.getTokenDecimals(token_id: string)
參數:
  • token_id: string – 記號的 ID。
傳回值:
  • 成功時,記號的小數位數即為數字資料類型。發生錯誤時,系統會傳回錯誤訊息。
傳回值範例:
1
get
如果某個記號物件存在於狀態資料庫中,這個方法會傳回該物件。
Ctx.Token.get(token_id: string)
參數:
  • token_id: string – 要傳回之記號的 ID。
傳回值:
  • 成功時,以 JSON 表示權杖的承諾。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
    "assetType": "otoken",
    "token_id": "token1",
    "token_name": "account",
    "token_desc": "Token 1",
    "token_type": "fungible",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "holdable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner",
        "notary_role_name": "notary"
    },
    "mintable": {
        "max_mint_quantity": 20000
    },
    "divisible": {
        "decimal": 1
    },
    "token_to_currency_ratio": 2,
    "currency_representation": "EURO"
}
history
此方法會傳回指定記號的歷史記錄。
Ctx.Token.history(tokenId)
參數:
  • tokenId: string – 記號的 ID。
傳回值:
  • 成功時,具有指定變數替代字之帳戶歷史記錄明細陣列的承諾。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
[
    {
        "trxId": "0d75f09446a60088afb948c6aca046e261fddcd43df416076201cdc5565f1a35",
        "timeStamp": "2023-09-01T16:48:41.000Z",
        "value": {
            "assetType": "otoken",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "token_desc": "updatedDesc",
            "token_standard": "ttf+",
            "token_type": "fungible",
            "token_unit": "fractional",
            "behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter"
            },
            "mintable": {
                "max_mint_quantity": 1000
            },
            "divisible": {
                "decimal": 2
            }
        }
    },
    {
        "trxId": "3666344878b043b65d5b821cc79c042ba52aec467618800df5cf14eac69f72fa",
        "timeStamp": "2023-08-31T20:24:55.000Z",
        "value": {
            "assetType": "otoken",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "token_standard": "ttf+",
            "token_type": "fungible",
            "token_unit": "fractional",
            "behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter"
            },
            "mintable": {
                "max_mint_quantity": 1000
            },
            "divisible": {
                "decimal": 2
            }
        }
    }
]
getAllTokens
此方法會傳回狀態資料庫中儲存的所有記號資產。此方法使用 Berkeley DB SQL RTF 查詢,而且只能在連線至遠端 Oracle Blockchain Platform 網路時呼叫。
Ctx.Token.getAllTokens()
參數:
傳回值:
  • 成功時,它會傳回包含所有權杖資產的承諾。發生錯誤時會傳回錯誤訊息。
傳回值範例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "txid": "98e0a0a115803d25b843d630e6b23c435a192a03eb0a301fc9375f05da49a8b2",
        "payload": [
            {
                "key": "token1",
                "valueJson": {
                    "assetType": "otoken",
                    "token_id": "token1",
                    "token_name": "vtok",
                    "token_type": "fungible",
                    "behaviours": [
                        "divisible",
                        "mintable",
                        "transferable",
                        "burnable",
                        "holdable",
                        "roles"
                    ],
                    "roles": {
                        "burner_role_name": "burner",
                        "notary_role_name": "notary"
                    },
                    "mintable": {
                        "max_mint_quantity": 0
                    },
                    "divisible": {
                        "decimal": 1
                    }
                }
            }
        ],
        "encode": "JSON"
    }
}
getTokensByName
此方法會傳回具有指定名稱的所有記號資產。此方法使用 Berkeley DB SQL RTF 查詢,而且只能在連線至遠端 Oracle Blockchain Platform 網路時呼叫。
Ctx.Token.getTokensByName(token_name: string)
參數:
  • token_name: string – 對應至模型之 Token_name 特性的記號名稱。此值為記號的類別名稱。
傳回值:
  • 它會傳回指定名稱之所有權杖資產的陣列 (JSON 格式)。
傳回值範例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "txid": "98e0a0a115803d25b843d630e6b23c435a192a03eb0a301fc9375f05da49a8b2",
        "payload": [
            {
                "key": "token1",
                "valueJson": {
                    "assetType": "otoken",
                    "token_id": "token1",
                    "token_name": "vtok",
                    "token_type": "fungible",
                    "behaviours": [
                        "divisible",
                        "mintable",
                        "transferable",
                        "burnable",
                        "holdable",
                        "roles"
                    ],
                    "roles": {
                        "burner_role_name": "burner",
                        "notary_role_name": "notary"
                    },
                    "mintable": {
                        "max_mint_quantity": 0
                    },
                    "divisible": {
                        "decimal": 1
                    }
                }
            }
        ],
        "encode": "JSON"
    }
}
isTokenType
此方法指出具有指定 ID 的記號資產是否存在。
Ctx.Token.isTokenType(token_id: string)
參數:
  • token_id: string – 要檢查之記號的 ID。
傳回值:
  • 成功時,如果具有指定 ID 的權杖資產存在,則承諾為 true 。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
true
getByRange
此方法會在內部呼叫結構 getStateByRange 方法。即使分類帳傳回任何具有指定 ID 的資產,此方法仍會將資產轉換成呼叫者資產類型。
<Token ClassCtx.Token.getByRange(start_token_id: string, end_token_id: string, token_class_reference?: <Instance of Token Class> )
參數:
  • startId: string – 範圍的起始索引鍵。此金鑰包含在範圍內。
  • endId: string – 範圍的結束索引鍵。此按鍵已從範圍中排除。
  • token: <Instance of Token Class> – 要操作的記號資產。
傳回值:
  • 成功時,具有 <Token Class> 陣列的承諾。發生錯誤時,拒絕並顯示錯誤訊息。
範例:
@validator(yup.string(), yup.string())
public async getDigiCurrGetByRange(start_token_id: string, end_token_id: string) {
   return await this.Ctx.Token.getByRange(start_token_id, end_token_id, DigiCurr);
}
傳回值範例:
[
    {
        "assetType": "otoken",
        "token_id": "token1",
        "token_name": "digicur",
        "token_desc": "Token 1",
        "token_type": "fungible",
        "behaviors": [
            "divisible",
            "mintable",
            "transferable",
            "burnable",
            "holdable",
            "roles"
        ],
        "roles": {
            "minter_role_name": "minter",
            "burner_role_name": "burner",
            "notary_role_name": "notary"
        },
        "mintable": {
            "max_mint_quantity": 20000
        },
        "divisible": {
            "decimal": 0
        },
        "token_to_currency_ratio": 1.5,
        "currency_representation": "USD"
    },
    {
        "assetType": "otoken",
        "token_id": "token2",
        "token_name": "digicur",
        "token_desc": "Token2",
        "token_type": "fungible",
        "behaviors": [
            "divisible",
            "mintable",
            "transferable",
            "burnable",
            "holdable",
            "roles"
        ],
        "roles": {
            "minter_role_name": "minter",
            "burner_role_name": "burner",
            "notary_role_name": "notary"
        },
        "mintable": {
            "max_mint_quantity": 20000
        },
        "divisible": {
            "decimal": 0
        },
        "token_to_currency_ratio": 1,
        "currency_representation": "EURO"
    }
]

帳戶管理方法

getCallerAccountId
此方法會傳回呼叫程式的帳戶 ID。
Ctx.Account.getCallerAccountId(token_id: string)
參數:
  • tokenId: string – 記號的 ID。
傳回值:
  • 成功時,具有來電者帳戶 ID 的承諾。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f
generateAccountId
此方法會傳回帳戶 ID,這是一組英數字元,前面加上 oaccount~<token asset name>~,後面接著執行處理擁有者的使用者名稱或電子郵件 ID (user_id) 雜湊,或登入執行處理的使用者、目前網路組織中使用者的成員服務提供者 ID (org_id) 以及唯一記號 ID (token_id)。
Ctx.Account.generateAccountId(token_id: string, org_id: string, user_id: string)
參數:
  • tokenId: string – 記號的 ID。
  • orgId: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • userId: string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,具有所產生帳戶 ID 的承諾。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f
createAccount
這個方法會為指定的使用者與記號建立帳號。每個在任何時間點都有權杖的使用者都必須有帳戶。帳戶會追蹤使用者的餘額、保留餘額和交易歷史記錄。帳戶 ID 是一組英數字元,前面加上 oaccount~<token asset name>~,後面接著執行處理擁有者的使用者名稱或電子郵件 ID (user_id) 雜湊,或登入執行處理的使用者 (目前網路組織中使用者的成員服務提供者 ID (org_id)。只有鏈碼的 Token Admin 或指定的組織 Org Admin 才能呼叫此方法。
this.Ctx.Account.createAccount(org_id: string, user_id: string, token_type: string)
參數:
  • org_id: string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
  • token_type: string – 記號的類型,必須是 fungible
傳回值:
  • 成功時,採用 JSON 格式的新帳戶物件。
傳回值範例:
{
  "assetType": "oaccount",
  "bapAccountVersion": 0,
  "account_id": "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
  "user_id": "admin",
  "org_id": "Org1MSP",
  "token_type": "fungible",
  "token_id": "",
  "token_name": "",
  "balance": 0,
  "onhold_balance": 0
}
associateTokenToAccount
此方法會將有趣的記號與帳戶建立關聯。只有鏈碼的 Token Admin 或相關組織的 Org Admin 才能呼叫此方法。
async associateTokenToAccount(account_id: string, token_id: string)
參數:
  • account_id: string – 帳戶的 ID。
  • token_id: string – 記號的 ID。
傳回值:
  • 成功時,已更新帳戶的 JSON 物件。
傳回值範例:
{
    "assetType": "oaccount",
    "bapAccountVersion": 0,
    "account_id": "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
    "user_id": "admin",
    "org_id": "Org1MSP",
    "token_type": "fungible",
    "token_id": "fungible",
    "token_name": "fiatmoneytok",
    "balance": 0,
    "onhold_balance": 0
}
getAccountWithStatus
此方法會傳回指定帳戶的帳戶詳細資料,包括帳戶狀態。
Ctx.Account.getAccountWithStatus(account_id: string)
參數:
  • account_id: string – 帳戶的 ID。
傳回值:
  • 成功時,具有帳戶明細的承諾。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
  "bapAccountVersion": 0,
  "assetType": "oaccount",
  "status": "active",
  "account_id": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
  "user_id": "idcqa",
  "org_id": "appdev",
  "token_type": "fungible",
  "token_id": "t1",
  "token_name": "obptok",
  "balance": 0,
  "onhold_balance": 0
}
getAccount
此方法會傳回指定帳戶的帳戶詳細資料。
Ctx.Account.getAccount(account_id: string)
參數:
  • account_id: string – 帳戶的 ID。
傳回值:
  • 成功時,具有帳戶明細的承諾。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
   "assetType":"oaccount",
   "bapAccountVersion": 0,
   "account_id":"oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
   "user_id":"user1",
   "org_id":"Org1MSP",
   "token_id":"digiCurr101",
   "token_name":"digicur",
   "balance":0,
   "onhold_balance":0
}
history
此方法會傳回指定帳戶的帳戶歷史記錄詳細資料陣列。
Ctx.Account.history(account_id: string)
參數:
  • account_id: string – 帳戶的 ID。
傳回值:
  • 成功時,具有帳戶歷史記錄明細陣列的承諾。發生錯誤時,拒絕並顯示錯誤訊息。傳回值與 getAccountHistory 方法相同。
傳回值範例:
[
    {
      "trxId":"2gsdh17fff222467e5667be042e33ce18e804b3e065cca15de306f837e416d7c3e",
      "timeStamp":1629718288,
      "value":{
         "assetType":"oaccount",
         "account_id":"oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
         "user_id":"user1",
         "org_id":"Org1MSP",
         "token_id":"digiCurr101",
         "token_name":"digicur",
         "balance":100,
         "onhold_balance":0,
         "bapAccountVersion": 1
   },
   {
      "trxId":"9fd07fff222467e5667be042e33ce18e804b3e065cca15de306f837e416d7c3e",
      "timeStamp":1629718288,
      "value":{
         "assetType":"oaccount",
         "account_id":"oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
         "user_id":"user1",
         "org_id":"Org1MSP",
         "token_id":"digiCurr101",
         "token_name":"digicur",
         "balance":0,
         "onhold_balance":0,
         "bapAccountVersion": 0
      }
   }
]
getAccountOnHoldBalance
此方法會傳回指定帳戶的保留結餘。
Ctx.Account.getAccountOnHoldBalance(account_id: string)
參數:
  • account_id: string – 帳戶的 ID。
傳回值:
  • 成功時,具有 JSON 物件的承諾會顯示指定帳戶的保留餘額。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
   "holding_balance":0,
   "msg":"Total Holding Balance of Account Id oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id: Org1MSP, user_id: user1) is 0"
}
getAllAccounts
這個方法會傳回所有帳號的清單。此方法使用 Berkeley DB SQL RTF 查詢,而且只能在連線至遠端 Oracle Blockchain Platform 網路時呼叫。
Ctx.Account.getAllAccounts()
參數:
傳回值:
  • 成功時,具有列出所有帳戶之 JSON 物件的承諾。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
[
           {
               "key": "oaccount~digicur~2e2ef3375ae347cbd7b4d3d7be5cece803f9c36a184aaf2b8d332c5d2dcead52",
               "valueJson": {
                   "assetType": "oaccount",
                   "account_id": "oaccount~digicur~2e2ef3375ae347cbd7b4d3d7be5cece803f9c36a184aaf2b8d332c5d2dcead52",
                   "user_id": "admin",
                   "org_id": "Org1MSP",
                   "token_id": "digiCurr101",
                   "token_name": "digicur",
                   "bapAccountVersion": 0,
                   "balance": 0,
                   "onhold_balance": 0
               }
           },
           {
               "key": "oaccount~digicur~30080c7e5ba94035af57fbbccbbb495e92515e4b2b3dbcd476eb1c0343e4da65",
               "valueJson": {
                   "assetType": "oaccount",
                   "account_id": "oaccount~digicur~30080c7e5ba94035af57fbbccbbb495e92515e4b2b3dbcd476eb1c0343e4da65",
                   "bapAccountVersion": 0,
                   "user_id": "user1",
                   "org_id": "Org1MSP",
                   "token_id": "digiCurr101",
                   "token_name": "digicur",
                   "balance": 0,
                   "onhold_balance": 0
               }
           },
           {
               "key": "oaccount~digicur~cbde438258cb01a82f71a9a9f8029243c40c6d836a505432120529c2b3c2ff0c",
               "valueJson": {
                   "assetType": "oaccount",
                   "account_id": "oaccount~digicur~cbde438258cb01a82f71a9a9f8029243c40c6d836a505432120529c2b3c2ff0c",
                   "bapAccountVersion": 0,
                   "user_id": "user2",
                   "org_id": "Org1MSP",
                   "token_id": "digiCurr101",
                   "token_name": "digicur",
                   "balance": 0,
                   "onhold_balance": 0
               }
           },
           {
               "key": "oaccount~digicur~ecbc3aefcc562d3049c988717940195b30297e95012b7824bbd33a57ca50a626",
               "valueJson": {
                   "assetType": "oaccount",
                   "account_id": "oaccount~digicur~ecbc3aefcc562d3049c988717940195b30297e95012b7824bbd33a57ca50a626",
                   "bapAccountVersion": 0,
                   "user_id": "user3",
                   "org_id": "Org1MSP",
                   "token_id": "digiCurr101",
                   "token_name": "digicur",
                   "balance": 500,
                   "onhold_balance": 0
               }
           }
       ]
getUserByAccountId
此方法會傳回指定帳戶的使用者詳細資料。
Ctx.Account.getUserByAccountId(account_id: string)
參數:
  • account_id: string – 帳戶的 ID。
傳回值:
  • 成功時,具有包含三個特性之 JSON 物件的承諾:
    • user_id – 使用者的使用者名稱或電子郵件 ID。
    • org_id – 目前網路組織中使用者的成員服務提供者 (MSP) ID。
    • token_id – 記號的 ID。
  • 發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
   "token_id": "digiCurr101",
   "user_id": "user1",
   "org_id": "Org1MSP"
}
getAccountBalance
此方法會傳回指定帳戶的帳戶餘額。
Ctx.Account.getAccountBalance(account_id: string)
參數:
  • account_id: string – 帳戶的 ID。
傳回值:
  • 成功時,含有 JSON 物件的承諾訊息,其中包含兩個特性:
    • msg – 顯示目前餘額的訊息。
    • user_balance – 目前餘額的數值。
  • 發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
    "msg": "Current Balance is: 200",
    "user_balance": 200
}
getAllOrgAccounts
此方法會傳回屬於指定組織的所有記號帳戶清單。
Ctx.Account.getAllOrgAccounts(org_id: string) 
參數:
  • org_id: string – 組織的成員服務提供者 (MSP) ID。
傳回值:
  • 成功時,指定組織的所有客戶清單。
傳回值範例:
[
    {
        "key": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
        "valueJson": {
            "bapAccountVersion": 0,
            "assetType": "oaccount",
            "account_id": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
            "user_id": "idcqa",
            "org_id": "appdev",
            "token_type": "fungible",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "balance": 0,
            "onhold_balance": 0
        }
    },
    {
        "key": "oaccount~620fcf5deb5fd5a65c0b5b10fda129de0f629ccd232c5891c130e24a574df50a",
        "valueJson": {
            "bapAccountVersion": 0,
            "assetType": "oaccount",
            "account_id": "oaccount~620fcf5deb5fd5a65c0b5b10fda129de0f629ccd232c5891c130e24a574df50a",
            "user_id": "example_minter",
            "org_id": "appdev",
            "token_type": "fungible",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "balance": 0,
            "onhold_balance": 0
        }
    }
]

角色管理方法

addRoleMember
此方法會新增角色至指定的使用者和記號。
Ctx.Token.addRoleMember(role: string, account_id: string, token: <Instance of Token Class>)
參數:
  • role: string – 要新增至指定使用者的角色名稱。mintableburnable 行為對應至規格檔案的 minter_role_nameburner_role_name 特性。同樣地,notary 角色對應至規格檔案的 notary_role_name 特性。
  • account_id: number – 要新增角色的帳戶 ID。
  • token: <Instance of Token Class> – 要操作的記號資產。
傳回值:
  • 成功時,將出現成功訊息的承諾。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
    "msg":"Successfully added role minter to oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id :          Org1MSP, user_id : user1)"
}
removeRoleMember
這個方法會從指定的使用者和記號中移除角色。
Ctx.Token.removeRoleMember(role: string, account_id: string, token: <Instance of Token Class>)
參數:
  • role: string – 要從指定使用者移除的角色名稱。mintableburnable 行為對應至規格檔案的 minter_role_nameburner_role_name 特性。同樣地,notary 角色對應至規格檔案的 notary_role_name 特性。
  • account_id: number – 從中移除角色的帳戶 ID。
  • token: <Instance of Token Class> – 要操作的記號資產。
傳回值:
  • 成功時,將出現成功訊息的承諾。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
  "msg":"successfully removed member_id oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1) from role minter"
}
getAccountsByRole
此方法會傳回指定角色和記號的所有帳戶清單。
Ctx.Role.getAccountsByRole(token_id: string, role: string)
參數:
  • token_id: string – 記號的 ID。
  • role: string – 要搜尋的角色名稱。
傳回值:
  • 成功時,具有 JSON 物件的承諾會列出指定角色和權杖的所有帳戶。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
    "accounts": [
        "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
        "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f"
    ]
}
getAccountsByUser
此方法會傳回指定使用者的所有帳戶 ID 清單。
async getAccountsByUser(org_id: string, user_id: string)
參數:
  • org_id string – 目前組織中使用者的會員服務提供者 (MSP) ID。
  • user_id string – 使用者的使用者名稱或電子郵件 ID。
傳回值:
  • 成功時,JSON 帳戶 ID 陣列。
傳回值範例:
{"accounts":["oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f"]}
getUsersByRole
此方法會傳回指定角色和記號之所有使用者的清單。
Ctx.Role.getUsersByRole(token_id: string, role: string)
參數:
  • token_id: string – 記號的 ID。
  • role: string – 要搜尋的角色名稱。
傳回值:
  • 成功時,具有 JSON 物件的承諾會列出指定角色和權杖的所有使用者。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
   "users":[
      {
         "token_id":"digiCurr101",
         "user_id":"user1",
         "org_id":"Org1MSP"
      }
   ]
}
isInRole
此方法指示使用者和記號是否具有指定的角色。
Ctx.Token.isInRole(role: string, account_id: string, token: <Instance of Token Class>)
參數:
  • role: string – 要檢查的角色名稱。
  • account_id: number – 要檢查的帳戶 ID。
  • token: <Instance of Token Class> – 要操作的記號資產。
傳回值:
  • 成功時,如果使用者具備該角色,則承諾為 true ;如果使用者沒有該角色,則為 false 。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{"result":"true"}
getOrgAccountsByRole
此方法會傳回指定組織中具有指定角色之所有帳戶的相關資訊。
Ctx.Role.getOrgAccountsByRole(token_id: string, role: string, org_id: string)
參數:
  • token_id: string – 記號的 ID。
  • role: string – 要檢查的角色名稱。
  • org_id: string – 組織的成員服務提供者 (MSP) ID。
傳回值:
  • 成功時,指定組織中具有指定角色的所有客戶清單。
傳回值範例:
{
    "accounts": [
        "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
        "oaccount~9c650574af9025a6106c8d12a801b079eda9ae2e3399fc2fbd5bd683d738a850"
    ]
}
getOrgUsersByRole
此方法會傳回指定組織中具有指定角色之所有使用者的相關資訊。
Ctx.Role.getOrgUsersByRole(token_id: string, role: string, org_id: string)
參數:
  • token_id: string – 記號的 ID。
  • role: string – 要檢查的角色名稱。
  • org_id: string – 組織的成員服務提供者 (MSP) ID。
傳回值:
  • 成功時,指定組織中具有指定角色的所有使用者清單。
傳回值範例:
{
    "users": [
        {
            "token_id": "token",
            "user_id": "admin",
            "org_id": "Org1MSP"
        },
        {
            "token_id": "token",
            "user_id": "orgAdmin",
            "org_id": "Org1MSP"
        }
    ]
}
roleCheck
此方法會檢查提供的帳戶 ID 是否為任何角色的成員。
Ctx.Token.roleCheck(account_id: string, token: <Instance of Token Class>)
參數:
  • account_id: string – 要檢查的帳戶 ID。
  • token: <Instance of Token Class> – 要操作的記號資產。
傳回值:
  • 如果帳戶 ID 是任何角色的一部分,則會傳回 true。否則,會傳回 false
傳回值範例:
{ result: true }

交易歷史記錄管理的方式

getAccountTransactionHistory
此方法會傳回指定帳戶的交易記錄詳細資料陣列。
Ctx.Account.getAccountTransactionHistory(account_id: string)
參數:
  • account_id: string – 帳戶的 ID。
傳回值:
  • 傳回值與 getAccountTransactionHistory 方法相同。
  • 成功時,具有科目交易物件陣列的承諾:
    • transaction_id – 交易的 ID。
    • transacted_account – 進行交易的帳戶。
    • transaction_type – 交易類型。
    • transacted_amount - 交易金額。
    • timestamp – 交易的時間。
    • balance – 交易時的帳戶餘額。
    • onhold_balance – 交易時的保留結餘。
    • sub_transactions – 僅適用於大量傳輸,這是大量傳輸一部分的交易清單。
    • holding_idholdTokens 方法傳回的唯一識別碼。
    • token_id – 記號的 ID。
  • 發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
[
   {
      "transaction_id":"otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
      "transacted_amount":20,
      "timestamp":"2021-08-17T06:04:24.000Z",
      "balance":60,
      "onhold_balance":0,
      "token_id":"digiCurr101",
      "transaction_type":"BULKTRANSFER",
      "sub_transactions":[
         {
            "transacted_account":"oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
            "transaction_type":"CREDIT",
            "transaction_id":"otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c4ca4238a0b923820dcc509a6f75849b",
            "transacted_amount":10
         }
      ]
   },
   {
      "transaction_id":"otransaction~757864d5369bd0539d044caeb3bb4898db310fd7aa740f45a9938771903d43da",
      "transacted_amount":50,
      "timestamp":"2021-08-17T06:02:44.000Z",
      "balance":50,
      "onhold_balance":0,
      "token_id":"digiCurr101",
      "transacted_account":"oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
      "transaction_type":"CREDIT"
   }
]
getAccountTransactionHistoryWithFilters
此方法會傳回指定帳戶的交易記錄詳細資料陣列。只有在連線至遠端 Oracle Blockchain Platform 網路時才能呼叫此方法。
await this.Ctx.Account.getAccountTransactionHistoryWithFilters(account_id: string, filters?: Filters)
參數:
  • account_id: string – 帳戶的 ID。
  • filters: string – 選擇性參數。如果空白,則會傳回所有記錄。PageSize 特性決定要傳回的記錄數目。如果 PageSize 為 0,則預設頁面大小為 20。Bookmark 特性決定要傳回之記錄的開始索引。如需詳細資訊,請參閱 Hyperledger Fabric 文件。必須以 RFC-3339 格式指定 StartTimeEndTime 特性。
範例:

ochain invoke getAccountTransactionHistoryWithFilters 'token1' 'appbuilder12' 'user_minter' '{"PageSize":10,"Bookmark":"1","StartTime":"2022-01-25T17:41:42Z","EndTime":"2022-01-25T17:59:10Z"}'

[
    {
        "transaction_id": "otransaction~672897b5a4fa78b421c000e4d6d4f71f3d46529bfbb5b4be10bf5471dc35ce89",
        "transacted_amount": 5,
        "timestamp": "2022-04-20T15:46:04.000Z",
        "token_id": "token1",
        "transacted_account": "oaccount~16c38d804413ebabf416360d374f76c973d4e71c74adfde73cc40c7c274883b8",
        "transaction_type": "DEBIT",
        "balance": 90,
        "onhold_balance": 0
    },
    {
        "transaction_id": "otransaction~467bb67a33aaffca4487f33dcd46c9844efdb5421a2e7b6aa2d53152eb2c6d85",
        "transacted_amount": 5,
        "timestamp": "2022-04-20T15:45:47.000Z",
        "token_id": "token1",
        "transacted_account": "oaccount~fbf95683b21bbc91a22205819ac1e2e9c90355d536821ed3fe22b7d23915c248",
        "transaction_type": "DEBIT",
        "balance": 95,
        "onhold_balance": 0
    },
    {
        "transaction_id": "otransaction~c6d56ce54a9bbe24597d1d10448e39316dc6f16328bf3c5b0c8ef10e1dfeb397",
        "transacted_amount": 100,
        "timestamp": "2022-04-20T15:44:26.000Z",
        "token_id": "token1",
        "transacted_account": "oaccount~deb5fb0906c40506f6c2d00c573b774e01a53dd91499e651d92ac4778b6add6a",
        "transaction_type": "MINT",
        "balance": 100,
        "onhold_balance": 0
    }
]
getSubTransactionHistory
此方法會傳回指定交易之交易歷史記錄詳細資訊的陣列。
await this.Ctx.Account.getSubTransactionHistory(transaction_id)
參數:
  • transaction_id: string – 大量傳輸交易的 ID。
範例:

ochain invoke GetAccountSubTransactionHistory 'otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b'

[
    {
        "transacted_account": "oaccount~16c38d804413ebabf416360d374f76c973d4e71c74adfde73cc40c7c274883b8",
        "transaction_type": "DEBIT",
        "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c81e728d9d4c2f636f067f89cc14862c",
        "transacted_amount": 5,
        "timestamp": "2022-04-20T15:52:21.000Z",
        "token_id": "token1",
        "balance": 80,
        "onhold_balance": 0
    },
    {
        "transacted_account": "oaccount~fbf95683b21bbc91a22205819ac1e2e9c90355d536821ed3fe22b7d23915c248",
        "transaction_type": "DEBIT",
        "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c4ca4238a0b923820dcc509a6f75849b",
        "transacted_amount": 5,
        "timestamp": "2022-04-20T15:52:21.000Z",
        "token_id": "token1",
        "balance": 85,
        "onhold_balance": 0
    }
]
getSubTransactionHistoryWithFilters
此方法會傳回指定異動之子異動歷史記錄明細的陣列。
await this.Ctx.Account.getSubTransactionHistoryWithFilters(transaction_id: string, filters?: SubTransactionFilters)
參數:
  • transaction_id: string – 大量傳輸交易的 ID。
  • filters: string – 選擇性參數。如果空白,則會傳回所有記錄。PageSize 特性決定要傳回的記錄數目。如果 PageSize 為 0,則預設頁面大小為 20。Bookmark 特性決定要傳回之記錄的開始索引。如需詳細資訊,請參閱 Hyperledger Fabric 文件。必須以 RFC-3339 格式指定 StartTimeEndTime 特性。
範例:

ochain invoke GetAccountSubTransactionHistoryWithFilters 'otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b' '{"PageSize":10,"Bookmark":"1"}'

[
    {
        "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c81e728d9d4c2f636f067f89cc14862c",
        "transacted_amount": 5,
        "timestamp": "2022-04-20T15:52:21.000Z",
        "token_id": "token1",
        "transacted_account": "oaccount~16c38d804413ebabf416360d374f76c973d4e71c74adfde73cc40c7c274883b8",
        "transaction_type": "DEBIT",
        "balance": 80,
        "onhold_balance": 0
    },
    {
        "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c4ca4238a0b923820dcc509a6f75849b",
        "transacted_amount": 5,
        "timestamp": "2022-04-20T15:52:21.000Z",
        "token_id": "token1",
        "transacted_account": "oaccount~fbf95683b21bbc91a22205819ac1e2e9c90355d536821ed3fe22b7d23915c248",
        "transaction_type": "DEBIT",
        "balance": 85,
        "onhold_balance": 0
    }
]
getTransactionById
此方法會傳回 Transaction 資產的歷史記錄。
async getTransactionById(transaction_id: string)
參數:
  • transaction_id: string – 交易資產的 ID。
傳回值:
  • 成功時,交易資產歷史記錄。
傳回值範例:
{
    "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
    "history": [
        {
            "trxId": "68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
            "timeStamp": 1629180264,
            "value": {
                "assetType": "otransaction",
                "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
                "token_id": "digiCurr101",
                "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
                "to_account_id": "",
                "transaction_type": "BULKTRANSFER",
                "amount": 20,
                "timestamp": "2021-08-17T06:04:24.000Z",
                "number_of_sub_transactions": 2,
                "holding_id": ""
            }
        }
    ],
    "sub_transactions": [
        {
            "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c4ca4238a0b923820dcc509a6f75849b",
            "history": [
                {
                    "trxId": "68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
                    "timeStamp": 1629180264,
                    "value": {
                        "assetType": "otransaction",
                        "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c4ca4238a0b923820dcc509a6f75849b",
                        "token_id": "digiCurr101",
                        "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
                        "to_account_id": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
                        "transaction_type": "TRANSFER",
                        "amount": 10,
                        "timestamp": "2021-08-17T06:04:24.000Z",
                        "number_of_sub_transactions": 0,
                        "holding_id": ""
                    }
                }
            ]
        },
        {
            "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c81e728d9d4c2f636f067f89cc14862c",
            "history": [
                {
                    "trxId": "68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
                    "timeStamp": 1629180264,
                    "value": {
                        "assetType": "otransaction",
                        "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c81e728d9d4c2f636f067f89cc14862c",
                        "token_id": "digiCurr101",
                        "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
                        "to_account_id": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
                        "transaction_type": "TRANSFER",
                        "amount": 10,
                        "timestamp": "2021-08-17T06:04:24.000Z",
                        "number_of_sub_transactions": 0,
                        "holding_id": ""
                    }
                }
            ]
        }
    ]
}
deleteHistoricalTransactions
此方法會傳回指定帳戶的交易記錄詳細資料陣列。
async deleteHistoricalTransactions(time_to_expiration: Date)
參數:
  • time_to_expiration: Date – 表示何時刪除交易的時戳。將刪除早於指定時間的交易資產。
傳回值:
  • 傳回值與 getAccountTransactionHistory 方法相同。
  • 成功時,具有科目交易物件陣列的承諾:
    • transaction_id – 交易的 ID。
    • transacted_account – 進行交易的帳戶。
    • transaction_type – 交易類型。
    • transacted_amount - 交易金額。
    • timestamp – 交易的時間。
    • balance – 交易時的帳戶餘額。
    • onhold_balance – 交易時的保留結餘。
    • sub_transactions – 僅適用於大量傳輸,這是大量傳輸一部分的交易清單。
    • holding_idholdTokens 方法傳回的唯一識別碼。
    • token_id – 記號的 ID。
  • 發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
"payload": {
            "msg": "Successfuly deleted transaction older than date: Thu Aug 19 2021 11:19:36 GMT+0000 (Coordinated Universal Time).",
            "transactions": [
                "otransaction~ec3366dd48b4ce2838f820f2f138648e6e55a07226713e59b411ff31b0d21058"
            ]
        }

權杖行為管理

權杖生命週期管理方法是以權杖分類架構的標準為基礎。若要使用記號生命週期方法,請從 ../lib/token 模組匯入 Token 類別。
import { Token } from '../lib/token';

權杖行為管理方法 - 可變行為

mint
此方法會提示數量的記號,然後由方法的呼叫程式所擁有。來電者必須具有帳戶與次要角色。數量必須在規格檔案中 divisible 行為的 decimal 參數所指定的小數值內。
Ctx.Token.mint(quantity: number, token: <Instance of Token Class>)
參數:
  • quantity: number – 要提示的記號總數。
  • token: <Instance of Token Class> – 要提示的記號資產。
傳回值:
  • 成功時,具有成功訊息和 toAccount 詳細資訊的承諾。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
  "msg":"Successfully minted 1000 tokens to Account Id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: admin)"
}
getTotalMintedTokens
此方法會傳回所提示的記號總數。
Ctx.Token.getTotalMintedTokens(token: <Instance of Token Class>)
參數:
  • token: <Instance of Token Class> – 要操作的記號資產。
傳回值:
  • 成功時,以數字資料類型表示的預期記號數量。發生錯誤時,系統會傳回錯誤訊息。
傳回值範例:
4000
getNetTokens
此方法會傳回系統中可用記號的淨數量。網路記號是記號燒錄後剩餘的記號數量。方程式形式:淨記號 = 總鑄幣記號 - 總燃燒記號。如果沒有燒錄記號,則網路記號的數目會等於總鑄幣的記號。
Ctx.Token.getNetTokens(token: <Instance of Token Class>)
參數:
  • token: <Instance of Token Class> – 要操作的記號資產。
傳回值:
  • 成功時,以數字資料類型表示的淨權杖數量。發生錯誤時,系統會傳回錯誤訊息。
傳回值範例:
2000
getMaxMintQuantity
此方法會傳回記號的最大可移動數量。如果未指定 max_mint_quantity 行為,則預設值為 0,可提示任意數目的記號。
Ctx.Token.getMaxMintQuantity(token: <Instance of Token Class>)
參數:
  • token: <Instance of Token Class> – 要操作的記號資產。
傳回值:
  • 成功時,權杖的可移動數量上限 (以數字資料類型表示)。發生錯誤時,系統會傳回錯誤訊息。
傳回值範例:
20000

權杖行為管理方法 - 可轉移行為

transfer
此方法會將記號從交易呼叫程式轉移至 to_account_id 帳戶。此方法的呼叫者必須具有帳戶,且數量必須在規格檔案中 divisible 行為的 decimal 參數所指定的小數值內。
Ctx.Token.transfer(to_account_id: string, quantity: number, token: <Instance of Token Class>)
參數:
  • to_account_id: string – 接收記號的帳戶 ID。
  • quantity: number – 要傳輸的記號總數。
傳回值:
  • 成功時,將出現成功訊息的承諾。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
 "msg":"Successfully transferred 50 tokens from account id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: admin) to account id: oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (Org-Id: Org1MSP, User-Id: user1)"
}
bulkTransfer
此方法會將變數替代字從呼叫者帳戶大量傳輸至 flow 物件中指定的帳戶。此方法的來電者必須已建立帳戶。
Ctx.Token.bulkTransfer(flow: object[], token: <Instance of Token Class>)
參數:
  • flow: object[] – 指定接收者詳細資訊和數量的 JSON 物件陣列。移轉數量必須在規格檔案中 divisible 行為的 decimal 參數所指定的小數值內。舉例而言:
    [{
    	"to_org_id": "Org1MSP",
    	"to_user_id": "user1",
    	"quantity": 10
    }, {
    	"to_org_id": "Org1MSP",
    	"to_user_id": "user2",
    	"quantity": 10
    }]
  • token: <Instance of Token Class> – 要操作的記號資產。
傳回值:
  • 成功時,將獲得成功訊息和帳戶資訊的承諾。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
    "from_account_id": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
    "msg": "Successfully transferred 2 tokens from Account Id oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (Org-Id: Org1MSP, User-Id: user1)",
    "sub_transactions": [
        {
            "amount": 1,
            "to_account_id": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e"
        },
        {
            "amount": 1,
            "to_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df"
        }
    ]
}

權杖行為管理方法 - 可保留行為

hold
此方法使用 to_account_id 帳戶代表權杖的擁有者建立保留。已指定公證人帳戶,該帳戶負責完成或解除保留。建立保留時,系統會保留付款人的指定變數替代字餘額。保留完成或解除之前,無法移轉保留餘額。此方法的來電者必須已建立帳戶。
Ctx.Token.hold(operation_id: string, to_account_id: string, notary_account_id: string, quantity: number, time_to_expiration: Date, token: <Instance of Token Class>)
參數:
  • operation_id: string – 識別保留作業的唯一 ID。通常此 ID 會由用戶端應用程式傳送。
  • to_account_id: string – 接收記號的帳戶 ID。
  • notary__account_id: string – 公證帳戶的 ID。
  • quantity: number – 保留的記號總數。
  • time_to_expiration: Date – 保留到期前的持續時間。為永久保留指定 0 。否則,請使用 RFC-3339 格式。例如,2021-06-02T12
  • token: <Instance of Token Class> – 要保留的記號資產。
傳回值:
  • 成功時,將出現成功訊息的承諾。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
 "msg": "account id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (org_id : Org1MSP, user_id : user1) is successfully holding 10 tokens",
}
executeHold
此方法會完成記號的保留,將先前保留的指定記號數量轉移給接收者。如果 quantity 值小於實際保留值,則剩餘金額會再次提供給權杖的原始擁有者。只有具有指定作業 ID 之 notary 角色的 AccountOwner ID 才能呼叫此方法。只有公證人才能完成保留。
Ctx.Token.executeHold(operation_id: string, quantity: number, token: <Instance of Token Class>)
參數:
  • operation_id: string – 識別保留作業的唯一 ID。通常此 ID 會由用戶端應用程式傳送。
  • quantity: number – 完成保留的記號總數。
  • token: <Instance of Token Class> – 要完成保留的記號資產。
傳回值:
  • 成功時,將出現成功訊息的承諾。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
 "msg": "user with accountId: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (org_id : Org1MSP, user_id : user1) has successfully executed 5  tokens(digiCurr101) from the hold with Operation Id opr_121",
}
releaseHold
此方法會解除保留記號。轉帳未完成,所有保留的權杖都會再次提供給原始擁有者使用。具有 notary 角色的 AccountOwner ID 可在指定的時間限制內呼叫此方法,或由付款人、受款人或公證人在指定的時間限制之後呼叫。
Ctx.Token.releaseHold(operation_id: string, token: <Instance of Token Class>)
參數:
  • operation_id: string – 識別保留作業的唯一 ID。通常此 ID 會由用戶端應用程式傳送。
  • token: <Instance of Token Class> – 要解除保留的記號資產。
傳回值:
  • 成功時,將出現成功訊息的承諾。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
  "msg": "Successfully released 5 tokens from Operation Id opr_121 to Account Id: oaccount~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (org_id : Org1MSP, user_id : user1)",
}
getOnHoldIds
此方法會傳回指定帳戶之所有持有 ID 的清單。
Ctx.Account.getOnHoldIds(account_id: string)
參數:
  • account_id: string – 帳戶的 ID。
傳回值:
  • 成功時,具有 JSON 物件的承諾會列出指定帳戶的所有持有 ID。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
   "msg":"Holding Ids are: ohold~digicur~digiCurr101~opr_121",
   "holding_ids":[
      "ohold~digicur~digiCurr101~opr_121"
   ]
}
getOnHoldDetailsWithOperationId
此方法會傳回指定作業 ID 與變數替代字的保留異動明細。
Ctx.Hold.getOnHoldDetailsWithOperationId(token_id: string, operation_id: string)
參數:
  • token_id: string – 記號的 ID。
  • operation_id: string – 識別保留作業的唯一 ID。通常此 ID 會由用戶端應用程式傳送。
傳回值:
  • 成功時,包含下列特性的保留物件:
    • holding_id – 交易的持有 ID。
    • operation_id: string – 識別保留作業的唯一 ID。通常此 ID 會由用戶端應用程式傳送。
    • from_account_id - 保留權杖目前擁有者的帳戶 ID。
    • to_account_id – 接收者的帳戶 ID。
    • notary_account_id – 公證人的帳戶 ID。
    • token_id: string – 已儲存記號的 ID。
    • quantity – 保留 ID 的記號數量。
    • time_to_expiration – 保留到期前的持續時間。
  • 發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
    "assetType": "ohold",
    "holding_id": "ohold~digicur~digiCurr101~opr_121",
    "operation_id": "opr_121",
    "token_name": "digicur",
    "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
    "to_account_id": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
    "notary_account_id": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
    "token_id": "digiCurr101",
    "quantity": 10,
    "time_to_expiration": "2022-08-01T18:30:00.000Z"
}
getOnHoldBalanceWithOperationId
此方法會傳回指定作業 ID 與變數替代字的保留餘額。任何人都可以呼叫這個方法。
Ctx.Hold.getOnHoldBalanceWithOperationId(token_id: string, operation_id: string)
參數:
  • token_id: string – 記號的 ID。
  • operation_id: string – 識別保留作業的唯一 ID。通常此 ID 會由用戶端應用程式傳送。
傳回值:
  • 成功時,具有指定作業 ID 與變數替代字保留餘額的承諾物件。發生錯誤時,拒絕並顯示錯誤訊息
傳回值範例:
{
    "msg": "Current Holding Balance of Operation 'op1' for token 'token1' is: 10",
    "holding_balance": 10
}

記號行為管理方法 - 可燃行為

burn
此方法會停用或燒錄交易呼叫者帳戶中的記號。此方法的來電者必須具有帳戶與燒錄者角色。數量必須在規格檔案中 divisible 行為的 decimal 參數所指定的小數值內。
Ctx.Token.burn(quantity: number, token: <Instance of Token Class>)
參數:
  • quantity: number – 要燒錄的記號總數。
  • token: <Instance of Token Class> – 要燒錄的記號資產。
傳回值:
  • 成功時,將出現成功訊息的承諾。發生錯誤時,拒絕並顯示錯誤訊息。
傳回值範例:
{
 "msg":"Successfully burned 10 tokens from account id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: admin)"
}