代币分类框架的基架 Go 项目

Blockchain App Builder 从您的令牌规范文件中获取输入,并生成一个功能齐全的支架链代码项目。

该项目自动生成令牌生命周期类和函数,包括 CRUD 和非 CRUD 方法。自动支持参数验证、编集/解编集和透明持久性功能。

有关基架项目和与令牌没有直接关系的方法的信息,请参见 Scaffolded Go Chaincode Project

型号

透明持久性功能(Transparent Persistence Capability,简称 ORM)捕获在 OchainModel 类中。

package src
type Digicur struct {
    AssetType               string                 `json:"AssetType" final:"otoken"`
    Token_id                string                 `json:"Token_id" id:"true" mandatory:"true" validate:"regexp=^[A-Za-z0-9][A-Za-z0-9_-]*$,max=16"`
    Token_name              string                 `json:"Token_name" final:"digicur"`
    Token_desc              string                 `json:"Token_desc" validate:"max=256"`
    Token_type              string                 `json:"Token_type" final:"fungible" validate:"regexp=^fungible$"`
    Behavior                []string               `json:"Behavior" final:"[\"divisible\",\"mintable\",\"transferable\",\"burnable\",\"holdable\",\"roles\"]"`
    Roles                   map[string]interface{} `json:"Roles" final:"{\"minter_role_name\":\"minter\",\"burner_role_name\":\"burner\",\"notary_role_name\":\"notary\"}"`
    Mintable                map[string]interface{} `json:"Mintable" final:"{\"Max_mint_quantity\":20000}"`
    Divisible               map[string]interface{} `json:"Divisible" final:"{\"Decimal\":1}"`
    Token_to_currency_ratio int                    `json:"Token_to_currency_ratio" validate:"int"`
    Currency_representation string                 `json:"Currency_representation" validate:"string"`
    Metadata                interface{}            `json:"Metadata,omitempty"`
}

控制器

只有一个主控制器。

type Controller struct {
    Ctx trxcontext.TrxContext
}

可以创建任意数量的类、函数或文件,但只能调用在主控制器类中定义的那些方法。其他方法将被隐藏。

您可以使用令牌 SDK 方法为业务应用程序编写定制方法。

如果在定制方法中使用多个标记 SDK 方法,则不要使用会影响状态数据库中相同键 - 值对的方法。

而是使用 BulkTransferTokens 方法从调用者的帐户转移到多个帐户,如以下代码片段中所示。

BulkTransferTokens(token_id string, flow: []map[string]interface{})

注意:

如果在定制方法中使用多个标记 SDK 方法,这些方法可能会影响状态数据库中的相同键 - 值对,请为标记链代码启用 MVCC 优化。有关更多信息,请参见 MVCC Optimization

自动生成的标记方法

Blockchain App Builder 自动生成支持令牌和令牌生命周期的方法。您可以使用这些方法初始化令牌、管理角色和账户以及完成其他令牌生命周期任务,而无需进行任何其他编码。控制器方法必须是公共的才能调用。公共方法名称以大写字符开头。以小写字符开头的方法名称是专用的。

访问控制管理的方法

AddTokenAdmin
此方法将用户添加为链代码的 Token Admin。此方法只能由链代码的 Token Admin 调用。
func (t *Controller) AddTokenAdmin(org_id string, user_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Admin.AddAdmin", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Admin.AddTokenAdmin(org_id, user_id)
}
参数:
  • org_id string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id string - 用户的用户名或电子邮件 ID。
返回:
  • 成功后,会显示一条消息,其中包含作为链代码的 Token Admin 添加的用户的详细信息。
返回值示例:
{
    "msg": "Successfully added Token Admin (Org_Id: Org1MSP, User_Id: user1)"
}
RemoveTokenAdmin
此方法将删除用户作为链代码的 Token Admin。此方法只能由链代码的 Token Admin 调用。
func (t *Controller) RemoveTokenAdmin(org_id string, user_id string) (interface{}, error) {
    auth, err := t.Ctx.Auth.CheckAuthorization("Admin.RemoveAdmin", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller  %s", err.Error())
    }
    return t.Ctx.Admin.RemoveAdmin(org_id, user_id)
}
参数:
  • org_id string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id string - 用户的用户名或电子邮件 ID。
返回:
  • 成功后,会显示一条消息,其中包含作为链代码的 Token Admin 删除的用户的详细信息。
返回值示例:
{"msg":"Successfuly removed Admin (Org_Id Org1MSP User_Id user1)"}
IsTokenAdmin
如果函数的调用方为 Token Admin,则此方法返回布尔值 true,否则返回 falseToken AdminOrg Admin 可以在区块链网络中的任何其他用户上调用此函数。其他用户只能在自己的帐户上调用此方法。
func (t *Controller) IsTokenAdmin(org_id string, user_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Admin.IsTokenAdmin", "TOKEN", map[string]string{"org_id": org_id, "user_id": user_id})
      if err != nil || !auth {
            return false, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Auth.IsUserTokenAdmin(org_id, user_id)
}
参数:
  • org_id string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id string - 用户的用户名或电子邮件 ID。
返回:
  • 如果调用方为 Token Admin,则该方法返回 true,否则返回 false
返回值示例:
{"result":false}
GetAllTokenAdmins
此方法返回作为链代码 Token Admin 的所有用户的列表。此方法只能由链代码的 Token AdminOrg Admin 调用。
func (t *Controller) GetAllTokenAdmins() (interface{}, error) {
    auth, err := t.Ctx.Auth.CheckAuthorization("Admin.GetAllAdmins", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller  %s", err.Error())
    }
    return t.Ctx.Admin.GetAllAdmins()
}
参数:
返回:
  • 成功后,将列出包含 OrgIdUserId 对象的 JSON 管理员列表。
返回值示例:
{"admins":[{"OrgId":"Org1MSP","UserId":"admin"},{"OrgId":"Org1MSP","UserId":"user2"}]}
AddOrgAdmin
此方法将用户添加为组织的 Org Admin。此方法只能由链代码的 Token Admin 或指定组织的 Org Admin 调用。
func (t *Controller) AddOrgAdmin(org_id string, user_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Admin.AddOrgAdmin", "TOKEN", map[string]string{"org_id": org_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.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 调用。
func (t *Controller) RemoveOrgAdmin(org_id string, user_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Admin.RemoveOrgAdmin", "TOKEN", map[string]string{"org_id": org_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.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 调用。
func (t *Controller) GetOrgAdmins() (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Admin.GetOrgAdmins", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Admin.GetAllOrgAdmins()
}
参数:
返回:
  • 成功后,将列出包含 OrgIdUserId 对象的 JSON 列表。
返回值示例:
{
    "admins": [
        {
            "OrgId": "Org1MSP",
            "UserId": "orgadmin"
        },
        {
            "OrgId": "Org1MSP",
            "UserId": "orgadmin1"
        },
        {
            "OrgId": "Org1MSP",
            "UserId": "orgadmin2"
        }
    ]
}

标记配置管理的方法

Init
部署链代码时将调用此方法。每个 Token Admin 都由必需的 adminList 参数中的 user_idorg_id 信息标识。user_id 是实例所有者或登录到实例的用户的用户名或电子邮件 ID。org_id 是当前网络组织中用户的成员服务提供者 (membership service provider,MSP) ID。
任何 Token Admin 用户都可以通过调用 AddTokenAdminRemoveTokenAdmin 方法来添加和删除其他 Token Admin 用户。
func (t *Controller) Init(adminList []admin.TokenAdminAsset) (interface{}, error) {
    list, err := t.Ctx.Admin.InitAdmin(adminList)
    if err != nil {
        return nil, fmt.Errorf("initializing admin list failed %s", err.Error())
    }
    return list, nil
}
参数:
  • adminList array- 指定令牌管理员列表的 {user_id, org_id} 信息数组。adminList 数组是必需的参数。
参数示例,Mac OSX 和 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 调用。
func (t *Controller) InitializeDigicurToken(asset Digicur) (interface{}, error) {
    auth, err := t.Ctx.Auth.CheckAuthorization("Token.Save", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
    }
    return t.Ctx.Token.Save(&asset)
}
参数:
  • asset <Token Class> - 标记资产作为参数传递到此方法。模型文件中介绍了标记资产的属性。
返回:
  • 成功后,将以 JSON 表示创建的令牌资产。
返回值示例:
{
    "AssetType": "otoken",
    "Token_id": "digiCurr101",
    "Token_name": "digicur",
    "Token_desc": "",
    "Token_type": "fungible",
    "Behavior": ["divisible", "mintable", "transferable", "burnable", "roles"],
    "Roles": {
        "minter_role_name": "minter"
    },
    "Mintable": {
        "Max_mint_quantity": 1000
    },
    "Divisible": {
        "Decimal": 2
    },
    "Currency_name": "",
    "Token_to_currency_ratio": 1
}
Update<Token Name>Token
此方法更新令牌属性。创建令牌资产后,只能更新 token_desc 属性和定制属性。此方法只能由链代码的 Token Admin 调用。
func (t *Controller) UpdateDigicurToken(asset Digicur) (interface{}, error) {
    auth, err := t.Ctx.Auth.CheckAuthorization("Token.Update", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
    }
    return t.Ctx.Token.Update(&asset)
}
参数:
  • asset <Token Class> - 标记资产作为参数传递到此方法。模型文件中介绍了标记资产的属性。
返回:
  • 成功后,将更新令牌资产的 JSON 表示形式。
返回值示例:
{
    "AssetType": "otoken",
    "Token_id": "digiCurr101",
    "Token_name": "digicur",
    "Token_desc": "Digital Currency equiv of dollar",
    "Token_type": "fungible",
    "Behavior": ["divisible", "mintable", "transferable", "burnable", "roles"],
    "Roles": {
        "minter_role_name": "minter"
    },
    "Mintable": {
        "Max_mint_quantity": 1000
    },
    "Divisible": {
        "Decimal": 2
    },
    "Currency_name": "",
    "Token_to_currency_ratio": 1
}
GetTokenDecimals
此方法返回为小数标记配置的小数位数。如果未指定令牌的 divisible 行为,则默认值为 0。此方法只能由链代码的 Token AdminOrg Admin 调用。
func (t *Controller) GetTokenDecimals(token_id string) (interface{}, error) {
    auth, err := t.Ctx.Auth.CheckAuthorization("Token.GetTokenDecimals", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
    }
    tokenDecimal, err := t.Ctx.Token.GetTokenDecimals(token_id)
    if err != nil {
        return nil, fmt.Errorf("Error in GetTokenDecimals %s", err.Error())
    }
    response := make(map[string]interface{})
    response["msg"] = fmt.Sprintf("Token Id: %s has %d decimal places.", token_id, tokenDecimal)
    return response, nil
}
参数:
  • token_id string - 标记的 ID。
返回:
  • 成功后,将显示标记小数位数的 JSON 字符串。
返回值示例:
{"msg":"Token Id: digiCurr101 has 1 decimal places."}
GetTokenById
如果标记对象存在于状态数据库中,则此方法返回该对象。此方法只能由链代码的 Token AdminOrg Admin 调用。
func (t *Controller) GetTokenById(token_id string) (interface{}, error) {
    auth, err := t.Ctx.Auth.CheckAuthorization("Token.Get", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller  %s", err.Error())
    }
    tokenAsset, err := t.getTokenObject(token_id)
    if err != nil {
        return nil, err
    }
    return tokenAsset.Interface(), err
}
参数:
  • token_id string - 标记的 ID。
返回:
  • 成功时,表示令牌资产的 JSON 对象。
返回值示例:
{
    "AssetType": "otoken",
    "Token_id": "digiCurr101",
    "Token_name": "digicur",
    "Token_desc": "Digital Currency equiv of dollar",
    "Token_type": "fungible",
    "Behavior": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "Roles": {
        "minter_role_name": "minter"
    },
    "Mintable": {
        "Max_mint_quantity": 1000
    },
    "Divisible": {
        "Decimal": 2
    },
    "Currency_name": "",
    "Token_to_currency_ratio": 1
}
GetTokenHistory
此方法返回指定标记 ID 的标记历史记录。任何用户都可以调用此方法。
func (t *Controller) GetTokenHistory(token_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Token.GetTokenHistory", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Token.History(token_id)
}
参数:
  • tokenId: string - 标记的 ID。
返回:
  • 成功时,表示令牌历史记录的 JSON 对象。
返回值示例:
[
    {
        "IsDelete": "false",
        "Timestamp": "2023-09-01T16:46:33Z",
        "TxId": "12333b8a4f63aa9b3a34072efcbd7df546c6d1e7d82a7a9596e899383656d6f7",
        "Value": {
            "AssetType": "otoken",
            "Behavior": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "Currency_name1": "",
            "Divisible": {
                "Decimal": 2
            },
            "Mintable": {
                "Max_mint_quantity": 1000
            },
            "Roles": {
                "minter_role_name": "minter"
            },
            "Token_desc": "updated description",
            "Token_id": "token",
            "Token_name": "fiatmoneytok",
            "Token_to_currency_ratio": 0,
            "Token_type": "fungible",
            "Token_unit": "fractional"
        }
    },
    {
        "IsDelete": "false",
        "Timestamp": "2023-09-01T16:04:25Z",
        "TxId": "99702e2dad7554a5ee4716a0d01d3e394cbce39bea8bade265d8911f30ebad0b",
        "Value": {
            "AssetType": "otoken",
            "Behavior": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "Currency_name1": "",
            "Divisible": {
                "Decimal": 2
            },
            "Mintable": {
                "Max_mint_quantity": 1000
            },
            "Roles": {
                "minter_role_name": "minter"
            },
            "Token_desc": "",
            "Token_id": "token",
            "Token_name": "fiatmoneytok",
            "Token_to_currency_ratio": 0,
            "Token_type": "fungible",
            "Token_unit": "fractional"
        }
    }
]
GetAllTokens
此方法返回状态数据库中存储的所有标记。此方法只能由链代码的 Token AdminOrg Admin 调用。
func (t *Controller) GetAllTokens() (interface{}, error) {
    auth, err := t.Ctx.Auth.CheckAuthorization("Token.GetAllTokens", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller  %s", err.Error())
    }
    return t.Ctx.Token.GetAllTokens()
}
参数:
返回:
  • 成功时,表示所有令牌资产的 JSON 对象。
返回值示例:
"payload": [
    {
        "key": "t1",
        "valueJson": {
            "AssetType": "otoken",
            "Behavior": [
                "divisible",
                "mintable",
                "transferable",
                "holdable",
                "burnable",
                "roles"
            ],
            "Currency_name": "Currency_name value",
            "Divisible": {
                "Decimal": 8
            },
            "Mintable": {
                "Max_mint_quantity": 10000
            },
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter",
                "notary_role_name": "notary"
            },
            "Token_desc": "Token_desc value",
            "Token_id": "t1",
            "Token_name": "obptok",
            "Token_to_currency_ratio": 2,
            "Token_type": "fungible",
            "Token_unit": "fractional"
        }
    }
]
GetTokensByName
此方法返回具有指定名称的所有标记对象。此方法只能由链代码的 Token AdminOrg Admin 调用。此方法使用 Berkeley DB SQL 富查询,并且只能在连接到远程 Oracle Blockchain Platform 网络时调用。
func (t *Controller) GetTokensByName(token_name string) (interface{}, error) {
    auth, err := t.Ctx.Auth.CheckAuthorization("Token.GetTokensByName", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller  %s", err.Error())
    }
    return t.Ctx.Token.GetTokensByName(token_name)
}
参数:
  • token_name string - 要检索的标记的名称。该名称对应于规范文件中的 Token_name 属性。该值是标记的类名。
返回:
  • 成功时,与名称匹配的所有令牌资产的 JSON 对象。
返回值示例:
"payload": [
    {
        "key": "t1",
        "valueJson": {
            "AssetType": "otoken",
            "Behavior": [
                "divisible",
                "mintable",
                "transferable",
                "holdable",
                "burnable",
                "roles"
            ],
            "Currency_name": "Currency_name value",
            "Divisible": {
                "Decimal": 8
            },
            "Mintable": {
                "Max_mint_quantity": 10000
            },
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter",
                "notary_role_name": "notary"
            },
            "Token_desc": "Token_desc value",
            "Token_id": "t1",
            "Token_name": "obptok",
            "Token_to_currency_ratio": 999,
            "Token_type": "fungible",
            "Token_unit": "fractional"
        }
    },
    {
        "key": "obp2",
        "valueJson": {
            "AssetType": "otoken",
            "Behavior": [
                "divisible",
                "mintable",
                "transferable",
                "holdable",
                "burnable",
                "roles"
            ],
            "Currency_name": "",
            "Divisible": {
                "Decimal": 8
            },
            "Mintable": {
                "Max_mint_quantity": 10000
            },
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter",
                "notary_role_name": "notary"
            },
            "Token_desc": "",
            "Token_id": "obp2",
            "Token_name": "obptok",
            "Token_to_currency_ratio": 0,
            "Token_type": "fungible",
            "Token_unit": "fractional"
        }
    }
]

账户管理方法

CreateAccount
此方法为指定的用户和令牌创建帐户。必须为在任何时刻具有令牌的任何用户创建帐户。账户跟踪余额、暂挂余额和事务处理历史记录。帐户 ID 是字母数字字符集,以 oaccount~<token asset name>~ 为前缀,后跟实例所有者或登录到实例的用户的用户名或电子邮件 ID (user_id) 的散列,即当前网络组织中用户的成员服务提供者 ID (org_id)。此方法只能由链代码的 Token Admin 或指定组织的 Org Admin 调用。
unc (t *Controller) CreateAccount(org_id string, user_id string, token_type string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.CreateAccount", "TOKEN", map[string]string{"org_id": org_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.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",
   "AccountId":"oaccount~a73085a385bc96c4a45aa2dff032e7dede82c0664dee5f396b7c5854eeafd4bd",
   "BapAccountVersion": 0,
   "UserId":"user1",
   "OrgId":"Org1MSP",
   "AccountType":"fungible",
   "TokenId":"",
   "TokenName":"",
   "Balance":0,
   "BalanceOnHold":0
}
AssociateTokenToAccount
此方法将可替换令牌与帐户关联。此方法只能由链代码的 Token Admin 或相关组织的 Org Admin 调用。
func (t *Controller) AssociateTokenToAccount(account_id string, token_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.AssociateToken", "TOKEN", map[string]string{"account_id": account_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Account.AssociateToken(account_id, token_id)
}
参数:
  • account_id string - 帐户的 ID。
  • token_id string - 标记的 ID。
返回:
  • 成功后,将更新账户的 JSON 对象。BapAccountVersion 参数在帐户对象中定义,供内部使用。
返回值示例:
{ 
"AssetType":"oaccount", 
"AccountId":"oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb", 
"BapAccountVersion": 0,
"UserId":"admin", 
"OrgId":"Org1MSP", 
"AccountType":"fungible", 
"TokenId":"token1", 
"TokenName":"loyaltok", 
"Balance":0, 
"BalanceOnHold":0 
}
GetAccount
此方法返回指定用户和令牌的帐户详细信息。此方法只能由链代码的 Token Admin、指定组织的 Org Admin 或帐户的 AccountOwner 调用。
func (t *Controller) GetAccount(token_id string, org_id string, user_id string) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetAccount", "TOKEN", map[string]string{"account_id": account_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Account.GetAccountWithStatus(account_id)
}
参数:
  • token_id string - 标记的 ID。
  • org_id string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id string - 用户的用户名或电子邮件 ID。
返回:
  • 成功时,包含以下属性的 JSON 帐户对象:
  • AccountId - 用户帐户的 ID。
  • UserId - 用户的用户名或电子邮件 ID。
  • OrgId - 当前组织中用户的成员服务提供者 (MSP) ID。
  • TokenId - 标记的 ID。
  • Balance - 帐户的当前余额。
  • BalanceOnHold - 账户的当前暂挂余额。
  • BapAccountVersion - 用于内部使用的帐户对象参数。
  • Status - 用户账户的当前状态。
返回值示例:
{
  "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
  "AssetType": "oaccount",
  "Balance": 95,
  "BalanceOnHold": 0,
  "BapAccountVersion": 8,
  "OrgId": "appdev",
  "Status": "active",
  "TokenId": "obp1",
  "TokenName": "obptok",
  "TokenType": "fungible",
  "UserId": "idcqa"
}
GetAccountHistory
此方法返回指定用户和令牌的帐户历史记录详细信息。此方法只能由链代码的 Token Admin 或帐户的 AccountOwner 调用。
func (t *Controller) GetAccountHistory(token_id string, org_id string, user_id string) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.History", "TOKEN", map[string]string{"account_id": account_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Account.History(account_id)
}
参数:
  • token_id string - 标记的 ID。
  • org_id string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id string - 用户的用户名或电子邮件 ID。
返回:
  • 成功时,包含以下属性的 JSON 帐户对象数组:
  • TxId - 分类账返回的事务处理的事务处理 ID。
  • Timestamp - 事务处理的时间。
  • IsDelete - 指示是否删除记录的布尔值。
  • Value - 帐户对象的 JSON 字符串。BapAccountVersion 参数在帐户对象中定义,供内部使用。
返回值示例:
[
  {
      "IsDelete": "false",
      "Timestamp": "2023-08-28T19:31:15Z",
      "TxId": "adde470a63860ec1013bd5c5987e8a506a48942a91b0f39fc8e561374042bd27",
      "Value": {
          "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
          "AssetType": "oaccount",
          "Balance": 100,
          "BalanceOnHold": 0,
          "BapAccountVersion": 1,
          "OrgId": "Org1MSP",
          "TokenId": "t1",
          "TokenName": "obptok",
          "TokenType": "fungible",
          "UserId": "idcqa"
      }
  },
  {
      "IsDelete": "false",
      "Timestamp": "2023-08-28T19:30:23Z",
      "TxId": "8fbeda2ba60ba175091faae5ae369247775f2cba45c4d6d1ead6f0b05be84743",
      "Value": {
          "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
          "AssetType": "oaccount",
          "Balance": 0,
          "BalanceOnHold": 0,
          "BapAccountVersion": 0,
          "OrgId": "Org1MSP",
          "TokenId": "t1",
          "TokenName": "obptok",
          "TokenType": "fungible",
          "UserId": "idcqa"
      }
  },
  {
      "IsDelete": "false",
      "Timestamp": "2023-08-28T19:29:54Z",
      "TxId": "19bb296ae71709e91b097ba5d9ebd7f7522095880382fbf5913334a46a6026aa",
      "Value": {
          "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
          "AssetType": "oaccount",
          "Balance": 0,
          "BalanceOnHold": 0,
          "BapAccountVersion": 0,
          "OrgId": "Org1MSP",
          "TokenId": "",
          "TokenName": "",
          "TokenType": "fungible",
          "UserId": "idcqa"
      }
  }
]
GetAccountOnHoldBalance
此方法返回指定账户和令牌的当前暂挂余额。此方法只能由链代码的 Token Admin、指定组织的 Org Admin 或帐户的 AccountOwner 调用。
func (t *Controller) GetAccountOnHoldBalance(token_id string, org_id string, user_id string) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetAccountOnHoldBalance", "TOKEN", map[string]string{"account_id": account_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      response, err := t.Ctx.Account.GetAccountOnHoldBalance(account_id)
      return response, err
}
参数:
  • token_id string - 标记的 ID。
  • org_id string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_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
此方法返回所有帐户的列表。此方法只能由链代码的 Token Admin 调用。此方法使用 Berkeley DB SQL 富查询,并且只能在连接到远程 Oracle Blockchain Platform 网络时调用。
func (t *Controller) GetAllAccounts() (interface{}, error) {
    auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetAllAccounts", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller  %s", err.Error())
    }
    return t.Ctx.Account.GetAllAccounts()
}
参数:
返回:
  • 成功后,将生成一个包含所有帐户的 JSON 数组。
返回值示例:
[
    {
        "key": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
        "valueJson": {
            "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
            "AssetType": "oaccount",
            "Balance": 100,
            "BalanceOnHold": 0,
            "BapAccountVersion": 1,
            "OrgId": "appdev",
            "TokenId": "t1",
            "TokenName": "obptok",
            "TokenType": "fungible",
            "UserId": "idcqa"
        }
    }
]
GetUserByAccountId
此方法返回指定帐户的用户详细信息(org_iduser_id)。链代码的任何用户都可以调用此方法。
func (t *Controller) GetUserByAccountId(account_id string) (interface{}, error) {
    return t.Ctx.Account.GetUserByAccountById(account_id)
}
参数:
  • account_id string - 帐户的 ID。
返回:
  • 成功时,用户详细信息的 JSON 对象(org_idtoken_iduser_id)。
返回值示例:
{"org_id":"Org1MSP","token_id":"digiCurr101","user_id":"user1"}
GetAccountBalance
此方法返回指定帐户和令牌的当前余额。此方法只能由链代码的 Token Admin、指定组织的 Org Admin 或帐户的 AccountOwner 调用。
func (t *Controller) GetAccountBalance(token_id string, org_id string, user_id string) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetAccountBalance", "TOKEN", map[string]string{"account_id": account_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      response, err := t.Ctx.Account.GetAccountBalance(account_id)
      return response, err
}
参数:
  • token_id string - 标记的 ID。
  • org_id string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id string - 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将以 JSON 表示当前账户余额。
返回值示例:
{"msg":"Current Balance of oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f is 0","user_balance":0}
GetAllOrgAccounts
此方法返回属于指定组织的所有令牌帐户的列表。此方法只能由链代码的 Token Admin 或指定组织的 Org Admin 调用。
func (t *Controller) GetAllOrgAccounts(org_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetAllOrgAccounts", "TOKEN", map[string]string{"org_id": org_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Account.GetAllOrgAccounts(org_id)
}
参数:
  • org_id: string - 组织的成员服务提供者 (MSP) ID。
返回:
  • 成功后,将列出指定组织的所有帐户。
返回值示例:
[
    {
        "key": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
        "valueJson": {
            "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
            "AssetType": "oaccount",
            "Balance": 0,
            "BalanceOnHold": 0,
            "BapAccountVersion": 0,
            "OrgId": "appdev",
            "TokenId": "token",
            "TokenName": "fiatmoneytok",
            "TokenType": "fungible",
            "UserId": "idcqa"
        }
    },
    {
        "key": "oaccount~9c650574af9025a6106c8d12a801b079eda9ae2e3399fc2fbd5bd683d738a850",
        "valueJson": {
            "AccountId": "oaccount~9c650574af9025a6106c8d12a801b079eda9ae2e3399fc2fbd5bd683d738a850",
            "AssetType": "oaccount",
            "Balance": 0,
            "BalanceOnHold": 0,
            "BapAccountVersion": 0,
            "OrgId": "appdev",
            "TokenId": "token",
            "TokenName": "fiatmoneytok",
            "TokenType": "fungible",
            "UserId": "example_minter"
        }
    }
]

角色管理的方法

AddRole
此方法向指定用户和令牌添加角色。此方法只能由链代码的 Token Admin 或具有指定角色的指定组织的 Org Admin 调用。
func (t *Controller) AddRole(token_id string, user_role string, org_id string, user_id string) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, err
      }
      tokenAssetValue, err := t.getTokenObject(token_id)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("Token.AddRoleMember", "TOKEN", map[string]string{"org_id": org_id, "token_id": token_id, "role": user_role})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Token.AddRoleMember(user_role, account_id, tokenAssetValue.Interface())
}
参数:
  • token_id string - 标记的 ID。
  • user_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 oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1)"}
RemoveRole
此方法将从指定用户和令牌中删除角色。此方法只能由链代码的 Token Admin 或具有指定角色的指定组织的 Org Admin 调用。
func (t *Controller) RemoveRole(token_id string, user_role string, org_id string, user_id string) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, err
      }
      tokenAssetValue, err := t.getTokenObject(token_id)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("Token.RemoveRoleMember", "TOKEN", map[string]string{"org_id": org_id, "token_id": token_id, "role": user_role})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Token.RemoveRoleMember(user_role, account_id, tokenAssetValue.Interface())
}
参数:
  • token_id string - 标记的 ID。
  • user_role string - 要从指定用户中删除的角色的名称。mintableburnable 行为对应于规范文件的 minter_role_nameburner_role_name 属性。同样,notary 角色对应于规范文件的 notary_role_name 属性。
  • org_id string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id string - 用户的用户名或电子邮件 ID。
返回:
  • 成功时,会显示包含账户详细信息的消息。
返回值示例:
{"msg":"successfully removed member_id oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1) from role minter"}
GetAccountsByRole
此方法返回指定角色和令牌的所有帐户 ID 的列表。此方法只能由链代码的 Token Admin 调用。
func (t *Controller) GetAccountsByRole(token_id string, user_role string) (interface{}, error) {
    auth, err:= t.Ctx.Auth.CheckAuthorization("Role.GetAccountsByRole", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
    }
    return t.Ctx.Role.GetAccountsByRole(token_id, user_role)
}
参数:
  • token_id string - 标记的 ID。
  • user_role string - 要搜索的角色的名称。
返回:
  • 成功后,将生成 JSON 帐户 ID 数组。
返回值示例:
{
    "accounts": [
        "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4"
    ]
}
GetAccountsByUser
此方法返回指定组织 ID 和用户 ID 的所有帐户 ID 的列表。此方法只能由链代码的 Token Admin、指定组织的 Org Admin 或参数中指定的 Account Owner 调用。
func (t *Controller) GetAccountsByUser(org_id string, user_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetAccountsByUser", "TOKEN", map[string]string{"org_id": org_id, "user_id": user_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Account.GetAccountsByUser(org_id, user_id)
}
参数:
  • org_id string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id string - 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将生成 JSON 帐户 ID 数组。
返回值示例:
{
    "accounts": [
        "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4"
    ]
}
GetUsersByRole
此方法返回指定角色和令牌的所有用户的列表。此方法只能由链代码的 Token Admin 或参数中指定的 Account Owner 调用。
func (t *Controller) GetUsersByRole(token_id string, user_role string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Role.GetUsersByRole", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Role.GetUsersByRole(token_id, user_role)
}
参数:
  • token_id string - 标记的 ID。
  • user_role string - 要搜索的角色的名称。
返回:
  • 成功后,用户对象的 JSON 数组(org_iduser_id)。
返回值示例:
{"Users":[{"org_id":"Org1MSP","token_id":"digiCurr101","user_id":"user1"}]}
IsInRole
此方法返回布尔值以指示用户和令牌是否具有指定的角色。此方法只能由链代码的 Token Admin、指定组织的 Org Admin 或帐户的 AccountOwner 调用。
func (t *Controller) IsInRole(token_id string, org_id string, user_id string, user_role string) (interface{}, error) {
      tokenAssetValue, err := t.getTokenObject(token_id)
      if err != nil {
            return nil, err
      }
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("Token.IsInRole", "TOKEN", map[string]string{"account_id": account_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      result, err := t.Ctx.Token.IsInRole(user_role, account_id, tokenAssetValue.Interface())
      if err != nil {
            return nil, fmt.Errorf("error in IsInRole %s", err.Error())
      }
      response := make(map[string]interface{})
      response["result"] = result
      return response, nil
}
参数:
  • token_id string - 标记的 ID。
  • org_id string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id string - 用户的用户名或电子邮件 ID。
  • user_role string - 要搜索的角色的名称。
返回:
  • 成功后,将生成布尔结果的 JSON 字符串。
返回值示例:
{"result":false}
GetOrgUsersByRole
此方法返回有关在指定组织中具有指定角色的所有用户的信息。此方法只能由链代码的 Token Admin 或指定组织的 Org Admin 调用。
func (t *Controller) GetOrgUsersByRole(token_id string, user_role string, org_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Role.GetOrgUsersByRole", "TOKEN", map[string]string{"org_id": org_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Role.GetOrgUsersByRole(token_id, user_role, org_id)
}
参数:
  • token_id: string - 标记的 ID。
  • role: string - 要检查的角色的名称。
  • org_id: string - 组织的成员服务提供者 (MSP) ID。
返回:
  • 成功后,将列出指定组织中具有指定角色的所有用户。
返回值示例:
{
    "Users": [
        {
            "org_id": "Org1MSP",
            "token_id": "token",
            "user_id": "admin"
        },
        {
            "org_id": "Org1MSP",
            "token_id": "token",
            "user_id": "orgAdmin"
        }
    ]
}
GetOrgAccountsByRole
此方法返回有关在指定组织中具有指定角色的所有帐户的信息。此方法只能由链代码的 Token Admin 或指定组织的 Org Admin 调用。
func (t *Controller) GetOrgAccountsByRole(token_id string, user_role string, org_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Role.GetOrgAccountsByRole", "TOKEN", map[string]string{"org_id": org_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Role.GetOrgAccountsByRole(token_id, user_role, org_id)
}
参数:
  • token_id: string - 标记的 ID。
  • role: string - 要检查的角色的名称。
  • org_id: string - 组织的成员服务提供者 (MSP) ID。
返回:
  • 成功后,将列出在指定组织中具有指定角色的所有客户。
返回值示例:
{
    "accounts": [
        "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
         "oaccount~9c650574af9025a6106c8d12a801b079eda9ae2e3399fc2fbd5bd683d738a850"
    ]
}

事务处理历史记录管理方法

GetAccountTransactionHistory
此方法返回指定用户和令牌的帐户事务处理历史记录详细信息数组。此方法只能由链代码的 Token Admin、指定组织的 Org Admin 或帐户的 AccountOwner 调用。
func (t *Controller) GetAccountTransactionHistory(token_id string, org_id string, user_id string) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetAccountTransactionHistory", "TOKEN", map[string]string{"account_id": account_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }

      transactionArray, err := t.Ctx.Account.GetAccountTransactionHistory(account_id, org_id, user_id)
      return transactionArray, err
}
参数:
  • token_id string - 标记的 ID。
  • org_id string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id string - 用户的用户名或电子邮件 ID。
返回:
  • 成功时,包含以下属性的 JSON 账户事务处理对象数组:
  • balance - 账户余额。
  • holding_id - 持有帐户的 ID。
  • onhold_balance - 暂挂余额。
  • timestamp - 事务处理的时间。
  • token_id - 标记的 ID。
  • transacted_account - 发生交易的帐户。
  • transacted_amount - 事务处理的金额。
  • transaction_id - 事务处理的 ID。
  • transaction_type - 事务处理的类型。
返回值示例:
[{
    "balance": 199,
    "onhold_balance": 0,
    "timestamp": "2021-08-16T17:42:32.905+05:30",
    "token_id": "digiCurr101",
    "transacted_account": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
    "transacted_amount": 1,
    "transaction_id": "otransaction~c8a9fa001aba6e0d8391b034655889df47eb5103713840b999a4ab41f5e57b38",
    "transaction_type": "DEBIT"
}, {
    "balance": 200,
    "onhold_balance": 0,
    "timestamp": "2021-08-16T17:41:59.262+05:30",
    "token_id": "digiCurr101",
    "transacted_account": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
    "transacted_amount": 100,
    "transaction_id": "otransaction~65a0bf8ae8108baa7495fbab91c205651c055e9f480f6808753287173026aa69",
    "transaction_type": "MINT"
}]
GetAccountTransactionHistoryWithFilters
此方法返回指定用户和令牌的帐户事务处理历史记录详细信息数组。此方法只能由链代码的 Token Admin、指定组织的 Org Admin 或帐户的 AccountOwner 调用。仅当连接到远程 Oracle Blockchain Platform 网络时才能调用此方法。
func (t *Controller) GetAccountTransactionHistoryWithFilters(token_id string, org_id string, user_id string, filters ...account.AccountHistoryFilters) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetAccountTransactionHistoryWithFilters", "TOKEN", map[string]string{"account_id": account_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }

      // sample format of filter: []string{"3", "", "2022-01-16T15:16:36+00:00", "2022-01-17T15:16:36+00:00"}
      transactionArray, err := t.Ctx.Account.GetAccountTransactionHistoryWithFilters(account_id, org_id, user_id, filters...)
      return transactionArray, err
}
参数:
  • 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~3f9c306b0ef6994885939c1a6eb5f063b06617ecb932d4a043f323ba53d55f9f",
    "transacted_amount": 200,
    "timestamp": "2022-02-15T18:27:13.000Z",
    "token_id": "token1",
    "transacted_account": "oaccount~obptok~26e046c8ba8b98da2cdabb78113d67200581ea3d4eea5aa324
1abd3598e05d05",
    "transaction_type": "DEBIT",
    "balance": 9200,
    "onhold_balance": 0
  },
  {
    "transaction_id": "otransaction~f1d37c3abd5c85c0a399f246d8eb68257c49ab4fe4cdfd3501908583c51c421e",
    "transacted_amount": 200,
    "timestamp": "2022-02-15T18:27:02.000Z",
    "token_id": "token1",
    "transaction_type": "BULKTRANSFER",
    "number_of_sub_transactions": 2,
    "balance": 9600,
    "onhold_balance": 0
  },
  {
    "transaction_id": "otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b",
    "transacted_amount": 200,
    "timestamp": "2022-02-15T18:26:57.000Z",
    "token_id": "token1",
    "transaction_type": "BULKTRANSFER",
    "number_of_sub_transactions": 2,
    "balance": 9800,
    "onhold_balance": 0
  },
  {
    "transaction_id": "otransaction~07331a1f7be99d6750973674a783da9ec9ca17df23747cdf52d388865d93f9a",
    "transacted_amount": 10000,
    "timestamp": "2022-02-15T18:26:30.000Z",
    "token_id": "token1",
    "transacted_account": "oaccount~obptok~88b62f329f20fffc6fc9231cb51019a5e9550c78b657123d140897
62397d2b55",
    "transaction_type": "MINT",
    "balance": 10000,
    "onhold_balance": 0
  }
]
GetSubTransactionsById
此方法返回指定事务处理的子事务处理历史记录详细信息数组。
func (t *Controller) GetSubTransactionsById(transaction_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetSubTransactionsById", "TOKEN", map[string]string{"transaction_id": transaction_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Account.GetSubTransactionsById(transaction_id)
}
参数:
  • transaction_id string - 事务处理的 ID。
示例:

ochain invoke GetAccountSubTransactionHistory 'otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b'

[
  {
    "transaction_id": "otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b~c4ca4238a0b923820dcc509a6f75849b",
    "transacted_amount": 100,
    "timestamp": "2022-02-15T18:26:57.000Z",
    "token_id": "token1",
    "transacted_account": "oaccount~obptok~6600eb38d365552b76f41d4186acece104f31eae331a440f963e6fa75b62ff21",
    "transaction_type": "DEBIT",
    "balance": 9900,
    "onhold_balance": 0
  },
  {
    "transaction_id": "otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b~c81e728d9d4c2f636f067f89cc14862c",
    "transacted_amount": 100,
    "timestamp": "2022-02-15T18:26:57.000Z",
    "token_id": "token1",
    "transacted_account": "oaccount~obptok~26e046c8ba8b98da2cdabb78113d67200581ea3d4eea5aa3241abd3598e05d05",
    "transaction_type": "DEBIT",
    "balance": 9800,
    "onhold_balance": 0
  }
]
GetSubTransactionsByIdWithFilters
此方法返回指定事务处理的子事务处理历史记录详细信息数组。
func (t *Controller) GetSubTransactionsByIdWithFilters(transaction_id string, filters ...account.SubTransactionFilters) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetSubTransactionsByIdWithFilters", "TOKEN", map[string]string{"transaction_id": transaction_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Account.GetSubTransactionsByIdWithFilters(transaction_id, filters...)
}
参数:
  • 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~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b~c4ca4238a0b923820dcc509a6f75849b",
"transacted_amount": 100,
"timestamp": "2022-02-15T18:26:57.000Z",
"token_id": "token1",
"transacted_account": "oaccount~obptok~6600eb38d365552b76f41d4186acece104f31eae331a440f963e6fa75b62ff21",
"transaction_type": "DEBIT",
"balance": 9900,
"onhold_balance": 0
},
{
"transaction_id": "otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b~c81e728d9d4c2f636f067f89cc14862c",
"transacted_amount": 100,
"timestamp": "2022-02-15T18:26:57.000Z",
"token_id": "token1",
"transacted_account": "oaccount~obptok~26e046c8ba8b98da2cdabb78113d67200581ea3d4eea5aa3241abd3598e05d05",
"transaction_type": "DEBIT",
"balance": 9800,
"onhold_balance": 0
}
]
GetTransactionById
此方法返回 Transaction 资产的历史记录。
func (t *Controller) GetTransactionById(transaction_id string) (interface{}, error) {
    return t.Ctx.Transaction.GetTransactionById(transaction_id)
}
参数:
  • transaction_id string - 事务处理资产的 ID。
返回:
  • 成功后,将生成事务处理历史记录的 JSON 数组。
返回值示例:
{
    "history": [
        {
            "IsDelete": "false",
            "Timestamp": "2021-08-16 20:19:05.028 +0530 IST",
            "TxId": "67042154a6853011d111b13f73943f06d2a6ae3cfb9a84cb104482c359eb2220",
            "Value": {
                "Amount": 3,
                "AssetType": "otransaction",
                "FromAccountId": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
                "HoldingId": "ohold~digicur~digiCurr101~op2",
                "NumberOfSubTransactions": 0,
                "Timestamp": "2021-08-16T20:19:05+05:30",
                "ToAccountId": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
                "TokenId": "digiCurr101",
                "TransactionId": "otransaction~67042154a6853011d111b13f73943f06d2a6ae3cfb9a84cb104482c359eb2220",
                "TransactionType": "RELEASEHOLD"
            }
        }
    ],
    "transaction_id": "otransaction~67042154a6853011d111b13f73943f06d2a6ae3cfb9a84cb104482c359eb2220"
}
DeleteHistoricalTransactions
此方法从状态数据库中删除较早的事务处理。
func (t *Controller) DeleteHistoricalTransactions(timestamp string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Transaction.DeleteHistoricalTransactions", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Transaction.DeleteHistoricalTransactions(timestamp)
}
参数:
  • timestamp string - 指示何时删除事务处理的时间戳。将删除早于指定时间的事务处理资产。

标记行为管理的方法 - 可最小化行为

IssueTokens
此方法铸币令牌,该令牌随后由方法的调用者拥有。调用方必须具有帐户和 minter 角色。可以铸造的标记数受规范文件中 mintable 行为的 max_mint_quantity 属性的限制。如果未指定 max_mint_quantity 属性,则可以铸造数量不限的标记。数量必须在规范文件中 divisible 行为的 decimal 参数指定的小数值内。此方法只能由具有 minter 角色的帐户的 AccountOwner 调用。
func (t *Controller) IssueTokens(token_id string, quantity float64) (interface{}, error) {
    tokenAssetValue, err := t.getTokenObject(token_id)
    if err != nil {
        return nil, err
    }
    return t.Ctx.Token.Mint(quantity, tokenAssetValue.Interface())
}
参数:
  • token_id string - 标记的 ID。
  • quantity float64 - 到 mint 的标记数。
返回:
  • 成功时,会显示包含账户详细信息的消息。
返回值示例:
{"msg":"Successfully minted 100 tokens to account oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1)"}
GetTotalMintedTokens
此方法返回指定令牌的铸造令牌总数。此方法只能由链代码的 Token AdminOrg Admin 调用。
func (t *Controller) GetTotalMintedTokens(token_id string) (interface{}, error) {
    tokenAssetValue, err := t.getTokenObject(token_id)
    if err != nil {
        return nil, err
    }
    auth, err := t.Ctx.Auth.CheckAuthorization("Token.GetTotalMintedTokens", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
    }
    return t.Ctx.Token.GetTotalMintedTokens(tokenAssetValue.Interface())
}
参数:
  • token_id string - 标记的 ID。
返回:
  • 成功时,指示令牌总数的 JSON 字符串。
返回值示例:
{"msg":"total minted amount for token with id digiCurr101 is 1000","quantity":1000}
GetNetTokens
此方法返回系统中指定令牌的可用令牌的总净数。净令牌总数是令牌被烧毁后剩余的令牌数量。在方程式形式中,净令牌 = 总铸造令牌 - 总烧毁令牌。如果没有刻录标记,则净标记的数量等于铸造标记的总数。此方法只能由链代码的 Token AdminOrg Admin 调用。
func (t *Controller) GetNetTokens(token_id string) (interface{}, error) {
    tokenAssetValue, err := t.getTokenObject(token_id)
    if err != nil {
        return nil, err
    }
    auth, err := t.Ctx.Auth.CheckAuthorization("Token.GetNetTokens", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
    }
    return t.Ctx.Token.GetNetTokens(tokenAssetValue.Interface())
}
参数:
  • token_id string - 标记的 ID。
返回:
  • 成功时,指示令牌净数的 JSON 字符串。
返回值示例:
{"msg":"net minted amount for token with id digiCurr101 is 1000","quantity":1000}

标记行为管理的方法 - 可传输行为

TransferTokens
此方法将令牌从调用方传输到指定的帐户。方法的调用方必须具有一个帐户。数量必须在规范文件中 divisible 行为的 decimal 参数指定的小数值内。此方法只能由帐户的 AccountOwner 调用。
func (t *Controller) TransferTokens(token_id string, to_org_id string, to_user_id string, quantity float64) (interface{}, error) {
    tokenAssetValue, err := t.getTokenObject(token_id)
    if err != nil {
        return nil, err
    }
    to_account_id, err := t.Ctx.Account.GenerateAccountId(token_id, to_org_id, to_user_id)
    if err != nil {
        return nil, err
    }
    return t.Ctx.Token.Transfer(to_account_id, quantity, tokenAssetValue.Interface())
}
参数:
  • token_id string - 标记的 ID。
  • to_org_id string - 当前组织中接收者的成员服务提供者 (MSP) ID。
  • to_user_id string - 接收者的用户名或电子邮件 ID。
  • quantity float64 - 要传输的令牌数。
返回:
  • 成功后,将显示一条消息,其中包含两个帐户的详细信息。
返回值示例:
{"msg":"successfully transferred 1 tokens from account oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1) to account oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (org_id : Org1MSP, user_id : admin)"}
BulkTransferTokens
此方法用于将标记从调用方帐户批量传输到 flow 对象中指定的帐户。数量必须位于此方法的规范 file.The 调用方中 divisible 行为的 decimal 参数指定的小数值内,且必须已创建账户。此方法只能由帐户的 AccountOwner 调用。
func (t *Controller) BulkTransferTokens(token_id string, flow[]map[string]interface{}) (interface{}, error) {
    tokenAssetValue, err := t.getTokenObject(token_id)
    if err != nil {
        return nil, err
    }
    return t.Ctx.Token.BulkTransfer(flow, tokenAssetValue.Interface())
}
参数:
  • token_id string - 标记的 ID。
  • flow[]map[string]interface{} - 指定接收器详细信息和数量的 JSON 对象数组。
    • to_org_id string - 当前组织中接收者的成员服务提供者 (MSP) ID。
    • to_user_id string - 接收者的用户名或电子邮件 ID。
    • quantity float64 - 要传输的令牌数。
    例如:
    [{
    	"to_org_id": "Org1MSP",
    	"to_user_id": "user1",
    	"quantity": 10
    }, {
    	"to_org_id": "Org1MSP",
    	"to_user_id": "user2",
    	"quantity": 10
    }]
返回:
  • 表示成功的消息。
返回值示例:
{
    "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"
        }
    ]
}

标记行为管理的方法 - 可暂挂行为

HoldTokens
此方法使用 to_account_id 帐户代表令牌的所有者创建暂挂。指定公证帐户,该帐户负责完成或释放暂挂。创建暂挂时,付款人的指定标记余额将被暂挂。在暂挂完成或释放之前,无法转移暂挂余额。此方法的调用方必须已创建账户。此方法只能由帐户的 AccountOwner 调用。
func (t *Controller) HoldTokens(token_id string, operation_id string, to_org_id string, to_user_id string, notary_org_id string, notary_user_id string, quantity float64, TimeToExpiration string) (interface{}, error) {
      tokenAssetValue, err := t.getTokenObject(token_id)
      if err != nil {
            return nil, err
      }
      notary_account_id, err := t.Ctx.Account.GenerateAccountId(token_id, notary_org_id, notary_user_id)
      if err != nil {
            return nil, fmt.Errorf("error in getting notary account id from org_id: %s and user_id: %s with token_id: %s, error %s ", notary_org_id, notary_user_id, token_id, err.Error())
      }
      to_account_id, err := t.Ctx.Account.GenerateAccountId(token_id, to_org_id, to_user_id)
      if err != nil {
            return nil, fmt.Errorf("error in getting to_account id from org_id: %s and user_id: %s with token_id: %s, error %s ", to_org_id, to_user_id, token_id, err.Error())
      }
      return t.Ctx.Token.Hold(operation_id, to_account_id, notary_account_id, quantity, TimeToExpiration, tokenAssetValue.Interface())
}
参数:
  • 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 float64 - 要暂挂的令牌数。
  • time_to_expiration - 暂挂到期的时间。指定 0 表示永久暂挂。否则使用 RFC-3339 格式。例如,2021-06-02T12:46:06Z
返回:
  • 成功后,将显示包含呼叫者帐户并保留详细信息的消息。
返回值示例:
{"msg":"AccountId oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1) is successfully holding 2 tokens"}
ExecuteHoldTokens
此方法完成对令牌的暂挂。令牌所有者以前持有的令牌数量将转移给接收者。如果 quantity 值小于实际暂挂值,则剩余金额将再次提供给令牌的原始所有者。此方法只能由具有 notary 角色的 AccountOwner ID 调用。暂挂只能由公证人完成。
func (t *Controller) ExecuteHoldTokens(token_id string, operation_id string, quantity float64) (interface{} error) {
    tokenAssetValue, err := t.getTokenObject(token_id)
    if err != nil {
        return nil, err
    }
    return t.Ctx.Token.ExecuteHold(operation_id, quantity, tokenAssetValue.Interface())
}
参数:
  • token_id string - 标记的 ID。
  • operation_id string - 用于标识暂挂操作的唯一 ID。通常,此 ID 由客户机应用程序传递。
  • quantity float64 - 要转移的暂挂令牌数。
返回:
  • 成功后,将显示一条消息,其中包含呼叫者的帐户 ID 和事务处理数量。
返回值示例:
{"msg":"Account Id oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1) has successfully executed '1' tokens(digiCurr101) from the hold with Operation Id 'op1'"}
ReleaseHoldTokens
此方法释放对标记的暂挂。转移未完成,所有保留的令牌都再次可供原始所有者使用。此方法可由 Account Owner ID 在指定时间限制内具有 notary 角色或者在指定时间限制后由付款人、受款人或公证人调用。
func (t *Controller) ReleaseHoldTokens(token_id string, operation_id string) (interface{} error) {
    tokenAssetValue, err := t.getTokenObject(token_id)
    if err != nil {
        return nil, err
    }
    return t.Ctx.Token.ReleaseHold(operation_id, tokenAssetValue.Interface())
}
参数:
  • token_id string - 标记的 ID。
  • operation_id string - 用于标识暂挂操作的唯一 ID。通常,此 ID 由客户机应用程序传递。
返回:
  • 成功后,将显示一条消息,指明已释放暂挂。
返回值示例:
{"msg":"Successfully released '3' tokens from Operation Id 'op2' to Account Id oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1)"}
GetOnHoldIds
此方法返回指定帐户的所有持有 ID 的列表。可以通过链代码的 Token Admin、指定组织的 Org Admin 或帐户的 Account Owner 调用此方法。
func (t *Controller) GetOnHoldIds(token_id string, org_id string, user_id string) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetOnHoldIds", "TOKEN", map[string]string{"account_id": account_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Account.GetOnHoldIDs(account_id)
}
参数:
  • token_id string - 标记的 ID。
  • org_id string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id string - 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将列出 JSON 存储 ID。持有 ID 是 ohold 资产类型、令牌名称、令牌 ID 和操作 ID 的串联。
返回值示例:
{"holding_ids":["ohold~loyaltok123~t1~op1"],"msg":"Holding Ids are: [ohold~loyaltok123~t1~op1]"}
GetOnHoldDetailsWithOperationId
此方法返回指定操作 ID 和标记的暂挂事务处理详细信息。任何人都可以调用此方法。
func (t *Controller) GetOnHoldDetailsWithOperationId(token_id string, operation_id string) (interface{} error) {
    return t.Ctx.Hold.GetOnHoldDetailsWithOperationId(token_id, operation_id)
}
参数:
  • token_id string - 标记的 ID。
  • operation_id string - 用于标识暂挂操作的唯一 ID。通常,此 ID 由客户机应用程序传递。
返回:
  • 成功时,包含以下属性的 JSON hold 对象:
  • HoldingId - 交易的持有者 ID。
  • OperationId - 用于标识暂挂操作的唯一 ID。通常,此 ID 由客户机应用程序传递。
  • FromAccountId - 暂挂令牌的当前所有者的账户 ID。
  • ToAccountId - 接收者的账户 ID。
  • NotaryAccountId - 公证人的帐户 ID。
  • TokenId- 保存的标记的 ID。
  • Quantity - 暂挂 ID 的令牌数量。
  • TimeToExpiration - 暂挂到期之前的持续时间。
返回值示例:
{
    "AssetType": "ohold",
    "HoldingId": "ohold~digicur~digiCurr101~op1",
    "OperationId": "op1",
    "TokenName": "digicur",
    "FromAccountId": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
    "ToAccountId": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
    "NotaryAccountId": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
    "TokenId": "digiCurr101",
    "Quantity": 2,
    "TimeToExpiration": "0"
}
GetOnHoldBalanceWithOperationId
此方法返回指定操作 ID 和标记的暂挂余额。任何人都可以调用此方法。
func (t *Controller) GetOnHoldBalanceWithOperationId(token_id string, operation_id string) (interface{} error) {
    return t.Ctx.Hold.GetOnHoldBalanceWithOperationId(token_id, operation_id)
}
参数:
  • token_id string - 标记的 ID。
  • operation_id string - 用于标识暂挂操作的唯一 ID。通常,此 ID 由客户机应用程序传递。
返回:
  • 成功时,指示保持平衡的 JSON 字符串。
返回值示例:
{
	"holding_balance": 10,
	"msg": "Current Holding Balance of OperationId opr_121 for token digiCurr101 is : 10"
}

标记行为管理的方法 - 可刻录行为

BurnTokens
此方法从事务处理调用者的账户中停用或刻录标记。此方法的调用方必须具有帐户和刻录器角色。数量必须在规范文件中 divisible 行为的 decimal 参数指定的小数值内。此方法可由具有刻录程序角色的帐户的 Account Owner 调用。
func (t *Controller) BurnTokens(token_id string, quantity float64) (interface{} error) {
    tokenAssetValue, err := t.getTokenObject(token_id)
    if err != nil {
        return nil, err
    }
    return t.Ctx.Token.Burn(quantity, tokenAssetValue.Interface())
}
参数:
  • token_id string - 标记的 ID。
  • quantity float64 - 要刻录的标记数。
返回:
  • 成功时,会显示成功消息,其中包含已刻录的令牌数量和账户 ID。
返回值示例:
{"msg":"Successfully burned 1 tokens from account id: oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e (org_id : Org1MSP, user_id : user2)"}

定制方法

您可以使用令牌 SDK 方法为业务应用程序编写定制方法。

使用令牌 SDK 方法时,务必跟踪返回值。此外,为了避免双重支出,请勿组合对状态数据库中的相同键 - 值对运行的多个异步函数。而是使用 BulkTransferTokens 方法在一个方法中进行多个传输。

以下示例说明如何在定制方法中使用标记 SDK 方法。调用 BuyTicket 方法时,它将 20 个令牌从调用者的帐户转移到卖方的帐户,并返回转移的事务处理消息。

func (t *Controller) BuyTicket(TokenId string, SellerOrgId string, SellerUserId string) (interface{}, error){
	token, err := t.Ctx.Token.Get(TokenId)
	if err != nil {
		return nil, err
	}
	
	/**
	* The following method t.Ctx.Account.GenerateAccountId(TokenId, SellerOrgId, SellerUserId) generates account id of the seller
	*/
	sellerAccountId, err := t.Ctx.Account.GenerateAccountId(TokenId, SellerOrgId, SellerUserId)
    if err != nil {
		return nil, err
	}   

	/**
	* The following method t.Ctx.Token.Transfer(sellerAccountId, 20, token) transfers the quantity 20 from caller's
	* account & to seller's account.
	*/
    transaction, err := t.Ctx.Token.Transfer(sellerAccountId, 20, token)
    if err != nil {
		return nil, err
	}
    return transaction, nil
}

标记 SDK 方法

访问控制管理的方法

令牌 SDK 提供访问控制功能。某些方法只能由令牌的 Token AdminOrg AdminAccountOwner 调用。您可以使用此功能确保仅由目标用户执行操作。任何未经授权的访问都会导致错误。要使用访问控制功能,请从 ../lib/auth 模块导入 Authorization 类。
import { Authorization } from '../lib/auth';
AddAdmin
此方法将用户添加为令牌链代码的 Token Admin
Ctx.AddAdmin(org_id string, user_id string) (interface{}, error)
参数:
  • user_id - 用户的用户名或电子邮件 ID。
  • org_id- 当前网络组织中用户的成员服务提供者 (Membership Service Provider,MSP) ID。
返回:
  • 成功时,将显示成功消息以及所添加的 Token Admin 用户的详细信息。出错时,包含错误消息的非零错误对象。
返回值示例:
{"msg":"Successfully added Admin (Org_Id: Org1MSP, User_Id: user2)"}
RemoveAdmin
此方法将删除用户作为标记链代码的 Token Admin
Ctx.RemoveAdmin(org_id string, user_id string) (interface{}, error)
参数:
  • user_id - 用户的用户名或电子邮件 ID。
  • org_id- 当前网络组织中用户的成员服务提供者 (Membership Service Provider,MSP) ID。
返回:
  • 成功时,将显示成功消息以及已删除的 Token Admin 用户的详细信息。出错时,包含错误消息的非零错误对象。
返回值示例:
{"msg":"Successfuly removed Admin (Org_Id Org1MSP User_Id user1)"}
GetAllAdmins
此方法返回作为标记链代码 Token Admin 的所有用户的列表。
Ctx.GetAllAdmins() (interface{}, error)
参数:
返回:
  • 成功后,将列出作为令牌链代码 Token Admin 的所有用户。出错时,包含错误消息的非零错误对象。
返回值示例:
[{"OrgId":"Org1MSP","UserId":"admin"},{"OrgId":"Org1MSP","UserId":"user1"}]
GetAllAdminUsers
此方法返回作为标记链代码 Token Admin 的所有用户的列表。
Ctx.Admin.GetAllAdminUsers() (interface{}, error) 
参数:
返回:
  • 成功后,将列出作为 map[string]interface{} 形式的标记链代码的 Token Admin 的所有用户。出错时,包含错误消息的非零错误对象。
返回值示例:
{"admins":[{"OrgId":"Org1MSP","UserId":"admin"},{"OrgId":"Org1MSP","UserId":"user1"}]}
CheckAuthorization
使用此方法可将访问控制添加到链代码。许多自动生成的标记方法都使用访问控制。oChainUtil.go 文件中介绍了 SDK 接收器与具有访问控制的方法之间的映射。要使用您自己的访问控制或禁用访问控制,请从自动生成的控制器方法和定制方法中删除访问控制代码。
var t TokenAccess
      var r RoleAccess
      var a AccountAccess
      var as AccountStatusAccess
      var h HoldAccess
      var ad AdminAccess
      var trx TransactionAccess
      var tc TokenConversionAccess
      var auth AuthAccess

      auth.IsTokenAdmin = []string{"Admin", "MultipleAccountOwner"}

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

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

      r.GetAccountsByRole = []string{"Admin"}
      r.GetUsersByRole = []string{"Admin"}
      r.GetOrgAccountsByRole = []string{"Admin", "OrgAdminOrgIdCheck"}
      r.GetOrgUsersByRole = []string{"Admin", "OrgAdminOrgIdCheck"}

      tc.InitializeExchangePoolUser = []string{"Admin"}
      tc.AddConversionRate = []string{"Admin"}
      tc.UpdateConversionRate = []string{"Admin"}
      tc.GetConversionRate = []string{"Admin", "OrgAdmin", "AnyAccountOwner"}
      tc.GetConversionRateHistory = []string{"Admin", "OrgAdmin", "AnyAccountOwner"}
      tc.TokenConversion = []string{"Admin", "AnyAccountOwner"}
      tc.GetExchangePoolUser = []string{"Admin"}
Ctx.Auth.CheckAuthorization(classFuncName string, args ...string) (bool, error)
参数:
  • classFuncName string- 接收器与方法之间的映射值,如 oChainUtil.go 文件中所述。
  • args- 可变参数,其中 args[0] 是常量 TOKENargs[1]account_id 参数(如果需要)。
返回:
  • 布尔值响应和错误消息(如果遇到错误)。
IsUserTokenAdmin
如果函数的调用方为 Token Admin,则此方法返回布尔值 true。否则,方法返回 false
Ctx.Auth.IsUserTokenAdmin()  (bool, error)
参数:
  • user_id - 用户的用户名或电子邮件 ID。
  • org_id- 当前网络组织中用户的成员服务提供者 (Membership Service Provider,MSP) ID。
返回:
  • 布尔值响应和错误消息(如果遇到错误)。
返回值示例:
{"result":false}
AddOrgAdmin
此方法将用户添加为组织的 Org Admin
Ctx.Admin.AddOrgAdmin(org_id, user_id) (interface{}, error)
参数:
  • 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) (interface{}, error)
参数:
  • 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() (interface{}, error)
参数:
返回:
  • 成功后,将列出包含 OrgIdUserId 对象的 JSON 列表。
返回值示例:
{
    "admins": [
        {
            "OrgId": "Org1MSP",
            "UserId": "orgadmin"
        },
        {
            "OrgId": "Org1MSP",
            "UserId": "orgadmin1"
        },
        {
            "OrgId": "Org1MSP",
            "UserId": "orgadmin2"
        }
    ]
}

标记配置管理的方法

GetTokenDecimals
此方法返回可用于小数标记的小数位数。如果未指定 divisible 行为,则默认值为 0。
Ctx.Token.GetTokenDecimals(token_id string) (int, error)
参数:
返回:
  • 成功时,标记的小数位数,在数字数据类型中。出错时,包含错误消息的非零错误对象。
返回值示例:
1
GetAllTokens
此方法返回在状态数据库中保存的所有标记资产。此方法使用 Berkeley DB SQL 富查询,并且只能在连接到远程 Oracle Blockchain Platform 网络时调用。
Ctx.Token.GetAllTokens()  (interface{}, error)
参数:
返回:
  • 成功后,会出现一系列包含所有令牌资产的映射。出错时,包含错误消息的非零错误对象。
返回值示例:
"payload": [
    {
        "key": "t1",
        "valueJson": {
            "AssetType": "otoken",
            "Behavior": [
                "divisible",
                "mintable",
                "transferable",
                "holdable",
                "burnable",
                "roles"
            ],
            "Currency_name": "Currency_name value",
            "Divisible": {
                "Decimal": 8
            },
            "Mintable": {
                "Max_mint_quantity": 10000
            },
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter",
                "notary_role_name": "notary"
            },
            "Token_desc": "Token_desc value",
            "Token_id": "t1",
            "Token_name": "obptok",
            "Token_to_currency_ratio": 999,
            "Token_type": "fungible",
            "Token_unit": "fractional"
        }
    }
]
GetTokensByName
此方法返回具有指定名称的所有标记资产。此方法使用 Berkeley DB SQL 富查询,并且只能在连接到远程 Oracle Blockchain Platform 网络时调用。
Ctx.Token.GetTokensByName(token_name string) (interface{}, error)
参数:
  • token_name string- 令牌的名称,与模型的 Token_name 属性相对应。该值是标记的类名。
返回:
  • 它返回指定名称的所有标记资产的映射数组。
返回值示例:
"payload": [
    {
        "key": "t1",
        "valueJson": {
            "AssetType": "otoken",
            "Behavior": [
                "divisible",
                "mintable",
                "transferable",
                "holdable",
                "burnable",
                "roles"
            ],
            "Currency_name": "Currency_name value",
            "Divisible": {
                "Decimal": 8
            },
            "Mintable": {
                "Max_mint_quantity": 10000
            },
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter",
                "notary_role_name": "notary"
            },
            "Token_desc": "Token_desc value",
            "Token_id": "t1",
            "Token_name": "obptok",
            "Token_to_currency_ratio": 999,
            "Token_type": "fungible",
            "Token_unit": "fractional"
        }
    },
    {
        "key": "obp2",
        "valueJson": {
            "AssetType": "otoken",
            "Behavior": [
                "divisible",
                "mintable",
                "transferable",
                "holdable",
                "burnable",
                "roles"
            ],
            "Currency_name": "",
            "Divisible": {
                "Decimal": 8
            },
            "Mintable": {
                "Max_mint_quantity": 10000
            },
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter",
                "notary_role_name": "notary"
            },
            "Token_desc": "",
            "Token_id": "obp2",
            "Token_name": "obptok",
            "Token_to_currency_ratio": 0,
            "Token_type": "fungible",
            "Token_unit": "fractional"
        }
    }
]
Get
如果标记对象存在于状态数据库中,则此方法返回该对象。此方法只能由标记链代码的 Token Admin 调用。
Ctx.Get(Id string, result ...interface{}) (interface{}, error)
参数:
  • token_id: string - 要返回的令牌的 ID。
  • result- 可变参数,其中第一个参数 result[0] 是所需类型的空 Token 对象的引用。
返回:
  • 成功时,使用标记资产数据的映射。可变参数 result[0] 包含令牌数据。出错时,包含错误消息的非零错误对象。
返回值示例:
{
    "AssetType": "otoken",
    "Token_id": "digiCurr101",
    "Token_name": "digicur",
    "Token_desc": "Digital Currency equiv of dollar",
    "Token_type": "fungible",
    "Behavior": ["divisible", "mintable", "transferable", "burnable", "holdable", "roles"],
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter",
        "notary_role_name": "notary"
    },
    "Mintable": {
        "Max_mint_quantity": 20000
    },
    "Divisible": {
        "Decimal": 1
    },
    "Token_to_currency_ratio": 1,
    "Currency_representation": "DOLLAR"
}
IsTokenType
此方法测试指定的令牌 ID 是否存在令牌资产。
Ctx.Model.IsTokenType(token_id: string) error
参数:
  • token_id: string - 要检查的令牌的 ID。
返回:
  • 如果存在具有指定 ID 的令牌资产,则出现 nil 错误。否则,包含错误消息的非零错误对象。
返回值示例:
nil
Save
此方法创建令牌并将其属性保存在状态数据库中。
Ctx.Token.Save(args ...interface{}) (interface{}, error)
参数:
  • token_id: string - 要返回的令牌的 ID。
  • args- 可变参数,其中第一个参数 args[0] 是要添加到分类帐的所需类型的标记 struct 数据的引用。
返回:
  • 成功后,会有一个 interface{} 对象,其中包含有关保存到状态数据库的令牌的详细信息。出错时,包含错误消息的非零错误对象。
返回值示例:
{
    "AssetType": "otoken",
    "Token_id": "digiCurr101",
    "Token_name": "digicur",
    "Token_desc": "",
    "Token_type": "fungible",
    "Behavior": ["divisible", "mintable", "transferable", "burnable", "roles"],
    "Roles": {
        "minter_role_name": "minter"
    },
    "Mintable": {
        "Max_mint_quantity": 1000
    },
    "Divisible": {
        "Decimal": 2
    },
    "Currency_name": "",
    "Token_to_currency_ratio": 1
}
Update
此方法更新令牌属性。创建令牌资产后,只能更新 token_desc 值及其定制属性。
Ctx.Token.Update(args ...interface{}) (interface{}, error)
参数:
  • 包含对要在分类账中更新的所需类型的标记 struct 数据的参考的资产。
返回:
  • 成功时,将显示包含令牌详细信息的 promise 消息。出错时,拒绝并显示错误消息。
返回值示例:
{
    "AssetType": "otoken",
    "Token_id": "digiCurr101",
    "Token_name": "digicur",
    "Token_desc": "Digital Currency equiv of dollar",
    "Token_type": "fungible",
    "Behavior": ["divisible", "mintable", "transferable", "burnable", "roles"],
    "Roles": {
        "minter_role_name": "minter"
    },
    "Mintable": {
        "Max_mint_quantity": 1000
    },
    "Divisible": {
        "Decimal": 2
    },
    "Currency_name": "",
    "Token_to_currency_ratio": 1
}
GetByRange
此方法在内部调用网状结构网络 getStateByRange 方法。即使从分类账返回具有给定 ID 的任何资产,此方法仍会将资产强制转换为调用方资产类型。
Ctx.Token.GetByRange(startId string, endId string, asset ...interface{}) ([]map[string]interface{}, error)
参数:
  • startId: string - 范围的起始键。此键包含在范围中。
  • endId: string - 范围的结束键。此键被排除在范围之外。
  • asset[0]- 所需类型的标记的空分片。如果方法成功运行,则包含请求的结果。
返回:
  • 成功时,包含 token_id 值在指定范围内的标记的标记资产详细信息的映射片。出错时,包含错误消息的非零错误对象。
返回值示例:
[{
    "Key": "oaccount~loyaltok123~a4bd3d8abfb1708198971311df77bb527233bcf9121ff95b0526bc056c4b8974",
    "Record": {
        "AccountId": "oaccount~loyaltok123~a4bd3d8abfb1708198971311df77bb527233bcf9121ff95b0526bc056c4b8974",
        "AssetType": "oaccount",
        "Balance": 99,
        "BalanceOnHold": 1,
        "BapAccountVersion": 0,
        "OrgId": "Org1MSP",
        "TokenId": "t1",
        "TokenName": "loyaltok123",
        "UserId": "u1"
    }
}, {
    "Key": "oaccount~loyaltok123~ac30c5ca924a2c7def61acf596d91e0cca70bc8cd233179df4efb2791b56336b",
    "Record": {
        "AccountId": "oaccount~loyaltok123~ac30c5ca924a2c7def61acf596d91e0cca70bc8cd233179df4efb2791b56336b",
        "AssetType": "oaccount",
        "Balance": 0,
        "BalanceOnHold": 0,
        "BapAccountVersion": 0,
        "OrgId": "Org1MSP",
        "TokenId": "t1",
        "TokenName": "loyaltok123",
        "UserId": "u2"
    }
}, {
    "Key": "oaccount~loyaltok123~aef96c40d99e09ef17f9bdda7038e8fbe829a327bae2b4d8d9fcf752190f3ff0",
    "Record": {
        "AccountId": "oaccount~loyaltok123~aef96c40d99e09ef17f9bdda7038e8fbe829a327bae2b4d8d9fcf752190f3ff0",
        "AssetType": "oaccount",
        "Balance": 0,
        "BapAccountVersion": 0,
        "BalanceOnHold": 0,
        "OrgId": "Org1MSP",
        "TokenId": "t1",
        "TokenName": "loyaltok123",
        "UserId": "admin"
    }
}, {
    "Key": "oadmin~Org1MSP~admin",
    "Record": {
        "AssetType": "oadmin",
        "Key": "oadmin~Org1MSP~admin",
        "OrgId": "Org1MSP",
        "UserId": "admin"
    }
}, {
    "Key": "ohold~loyaltok123~t1~op1",
    "Record": {
        "AssetType": "ohold",
        "FromAccountId": "oaccount~loyaltok123~a4bd3d8abfb1708198971311df77bb527233bcf9121ff95b0526bc056c4b8974",
        "HoldingId": "ohold~loyaltok123~t1~op1",
        "NotaryAccountId": "oaccount~loyaltok123~ac30c5ca924a2c7def61acf596d91e0cca70bc8cd233179df4efb2791b56336b",
        "OperationId": "op1",
        "Quantity": 1,
        "TimeToExpiration": "0",
        "ToAccountId": "oaccount~loyaltok123~aef96c40d99e09ef17f9bdda7038e8fbe829a327bae2b4d8d9fcf752190f3ff0",
        "TokenId": "t1",
        "TokenName": "loyaltok123"
    }
}, {
    "Key": "ometadata~loyaltok123~t1",
    "Record": {
        "AssetType": "ometadata",
        "Metadata_id": "ometadata~loyaltok123~t1",
        "Token_id": "t1",
        "Token_name": "loyaltok123",
        "Total_minted_amount": 100,
        "Total_supply": 100
    }
}, {
    "Key": "orole~t1~minter~oaccount~loyaltok123~a4bd3d8abfb1708198971311df77bb527233bcf9121ff95b0526bc056c4b8974",
    "Record": {
        "AccountID": "oaccount~loyaltok123~a4bd3d8abfb1708198971311df77bb527233bcf9121ff95b0526bc056c4b8974",
        "AssetType": "orole",
        "Key": "orole~t1~minter~oaccount~loyaltok123~a4bd3d8abfb1708198971311df77bb527233bcf9121ff95b0526bc056c4b8974",
        "RoleName": "minter",
        "TokenId": "t1"
    }
}, {
    "Key": "otransaction~4a774f6493f6521cab9eda96822cb3bb4103c0738ee2dbb9a193b868ace36fa5",
    "Record": {
        "Amount": 100,
        "AssetType": "otransaction",
        "FromAccountId": "",
        "HoldingId": "",
        "NumberOfSubTransactions": 0,
        "Timestamp": "2021-08-25T23:04:42+05:30",
        "ToAccountId": "oaccount~loyaltok123~a4bd3d8abfb1708198971311df77bb527233bcf9121ff95b0526bc056c4b8974",
        "TokenId": "t1",
        "TransactionId": "otransaction~4a774f6493f6521cab9eda96822cb3bb4103c0738ee2dbb9a193b868ace36fa5",
        "TransactionType": "MINT"
    }
}, {
    "Key": "otransaction~69f3cefbcb64b73f01a0eadff87169f456873ccebe61ca8da3eef3f465f0c129",
    "Record": {
        "Amount": 1,
        "AssetType": "otransaction",
        "FromAccountId": "oaccount~loyaltok123~a4bd3d8abfb1708198971311df77bb527233bcf9121ff95b0526bc056c4b8974",
        "HoldingId": "ohold~loyaltok123~t1~op1",
        "NumberOfSubTransactions": 0,
        "Timestamp": "2021-08-25T23:06:13+05:30",
        "ToAccountId": "oaccount~loyaltok123~aef96c40d99e09ef17f9bdda7038e8fbe829a327bae2b4d8d9fcf752190f3ff0",
        "TokenId": "t1",
        "TransactionId": "otransaction~69f3cefbcb64b73f01a0eadff87169f456873ccebe61ca8da3eef3f465f0c129",
        "TransactionType": "ONHOLD"
    }
}, {
    "Key": "t1",
    "Record": {
        "AssetType": "otoken",
        "Behavior": ["divisible", "mintable", "transferable", "burnable", "holdable", "roles"],
        "Currency_Name": "a",
        "Divisible": {
            "Decimal": 2
        },
        "Effective_From_Date": "2020-09-09T00:00:00Z",
        "Mintable": {
            "Max_mint_quantity": 10000
        },
        "Roles": {
            "minter_role_name": "minter"
        },
        "Token_To_Currency_Ratio": 1,
        "Token_desc": "",
        "Token_id": "t1",
        "Token_name": "loyaltok123",
        "Token_type": "fungible"
    }
}]
History
此方法返回指定标记 ID 的标记历史记录。
Ctx.Token.History(tokenId string) (interface{}, error)
参数:
  • tokenId: string - 标记的 ID。
返回:
  • 成功时,表示令牌历史记录的 JSON 数组。
返回值示例:
[
    {
        "IsDelete": "false",
        "Timestamp": "2023-09-01T16:46:33Z",
        "TxId": "12333b8a4f63aa9b3a34072efcbd7df546c6d1e7d82a7a9596e899383656d6f7",
        "Value": {
            "AssetType": "otoken",
            "Behavior": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "Currency_name1": "",
            "Divisible": {
                "Decimal": 2
            },
            "Mintable": {
                "Max_mint_quantity": 1000
            },
            "Roles": {
                "minter_role_name": "minter"
            },
            "Token_desc": "updated description",
            "Token_id": "token",
            "Token_name": "fiatmoneytok",
            "Token_to_currency_ratio": 0,
            "Token_type": "fungible",
            "Token_unit": "fractional"
        }
    },
    {
        "IsDelete": "false",
        "Timestamp": "2023-09-01T16:04:25Z",
        "TxId": "99702e2dad7554a5ee4716a0d01d3e394cbce39bea8bade265d8911f30ebad0b",
        "Value": {
            "AssetType": "otoken",
            "Behavior": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "Currency_name1": "",
            "Divisible": {
                "Decimal": 2
            },
            "Mintable": {
                "Max_mint_quantity": 1000
            },
            "Roles": {
                "minter_role_name": "minter"
            },
            "Token_desc": "",
            "Token_id": "token",
            "Token_name": "fiatmoneytok",
            "Token_to_currency_ratio": 0,
            "Token_type": "fungible",
            "Token_unit": "fractional"
        }
    }
]

账户管理方法

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) (string, error)
参数:
  • token_id: string - 标记的 ID。
  • org_id: string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id: string - 用户的用户名或电子邮件 ID。
返回:
  • 成功时,生成的账户 ID。出错时,拒绝并显示错误消息。
返回值示例:
oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f
CreateAccount
此方法为指定的用户和令牌创建帐户。每个在任何时候都有令牌的用户都必须有一个帐户。账户跟踪用户的余额、暂挂余额和事务处理历史记录。帐户 ID 是字母数字字符集,以 oaccount~<token asset name>~ 为前缀,后跟实例所有者或登录到实例的用户的用户名或电子邮件 ID (user_id) 的散列,即当前网络组织中用户的成员服务提供者 ID (org_id)。此方法只能由链代码的 Token Admin 调用。
t.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
返回:
  • 成功时,创建的客户对象。出错时,拒绝并显示错误消息。
返回值示例:
{
 "AssetType":"oaccount",
"AccountId":"oaccount~a73085a385bc96c4a45aa2dff032e7dede82c0664dee5f396b7c5854eeafd4bd",
   "UserId":"user1",
   "OrgId":"Org1MSP",
   "BapAccountVersion": 0,
   "AccountType":"fungible",
   "TokenId":"",
   "TokenName":"",
   "Balance":0,
   "BalanceOnHold":0
}
AssociateToken
此方法将可替换令牌与帐户关联。此方法只能由链代码的 Token Admin 调用。
t.Ctx.Account.AssociateToken(account_id, token_id)
参数:
  • account_id string - 帐户的 ID。
  • token_id string - 标记的 ID。
返回:
  • 成功后,将更新账户的 JSON 对象。
返回值示例:
{ 
"AssetType":"oaccount", 
"AccountId":"oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb", 
"BapAccountVersion": 0,
"UserId":"admin", 
"OrgId":"Org1MSP", 
"AccountType":"fungible", 
"TokenId":"token1", 
"TokenName":"loyaltok", 
"Balance":0, 
"BalanceOnHold":0 
}
GetAccountWithStatus
此方法返回指定帐户的帐户详细信息,包括帐户状态。
Ctx.Account.GetAccountWithStatus(account_id string) (interface{}, error)
参数:
  • account_id: string - 帐户的 ID。
返回:
  • 成功时,请求的客户详细信息。出错时,拒绝并显示错误消息。
返回值示例:
{
  "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
  "AssetType": "oaccount",
  "Balance": 95,
  "BalanceOnHold": 0,
  "BapAccountVersion": 8,
  "OrgId": "appdev",
  "Status": "active",
  "TokenId": "obp1",
  "TokenName": "obptok",
  "TokenType": "fungible",
  "UserId": "idcqa"
}
GetAccount
此方法返回指定帐户的帐户详细信息。
Ctx.Account.GetAccount(account_id string) (Account, error)
参数:
  • account_id: string - 帐户的 ID。
返回:
  • 成功时,请求的客户详细信息。出错时,拒绝并显示错误消息。
返回值示例:
{
    "AssetType": "oaccount",
    "BapAccountVersion": 0,
    "AccountId": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
    "UserId": "user1",
    "OrgId": "Org1MSP",
    "TokenId": "digiCurr101",
    "TokenName": "digicur",
    "Balance": 0,
    "BalanceOnHold": 0
}
GetAccountHistory
此方法返回指定帐户的帐户历史记录详细信息数组。
Ctx.Account.History(account_id string) ([]interface{}, error)
参数:
  • account_id: string - 帐户的 ID。
返回:
  • 成功时,包含账户历史记录详细信息的 map[string]interface{} 数组。帐户数据显示在映射中的 Value 键下方。出错时,包含错误消息的非零错误对象。返回值与 "GetAccountHistory" 方法相同。
返回值示例:
[
  {
      "IsDelete": "false",
      "Timestamp": "2023-08-28T19:31:15Z",
      "TxId": "adde470a63860ec1013bd5c5987e8a506a48942a91b0f39fc8e561374042bd27",
      "Value": {
          "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
          "AssetType": "oaccount",
          "Balance": 100,
          "BalanceOnHold": 0,
          "BapAccountVersion": 1,
          "OrgId": "Org1MSP",
          "TokenId": "t1",
          "TokenName": "obptok",
          "TokenType": "fungible",
          "UserId": "idcqa"
      }
  },
  {
      "IsDelete": "false",
      "Timestamp": "2023-08-28T19:30:23Z",
      "TxId": "8fbeda2ba60ba175091faae5ae369247775f2cba45c4d6d1ead6f0b05be84743",
      "Value": {
          "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
          "AssetType": "oaccount",
          "Balance": 0,
          "BalanceOnHold": 0,
          "BapAccountVersion": 0,
          "OrgId": "Org1MSP",
          "TokenId": "t1",
          "TokenName": "obptok",
          "TokenType": "fungible",
          "UserId": "idcqa"
      }
  },
  {
      "IsDelete": "false",
      "Timestamp": "2023-08-28T19:29:54Z",
      "TxId": "19bb296ae71709e91b097ba5d9ebd7f7522095880382fbf5913334a46a6026aa",
      "Value": {
          "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
          "AssetType": "oaccount",
          "Balance": 0,
          "BalanceOnHold": 0,
          "BapAccountVersion": 0,
          "OrgId": "Org1MSP",
          "TokenId": "",
          "TokenName": "",
          "TokenType": "fungible",
          "UserId": "idcqa"
      }
  }
]
GetAccountOnHoldBalance
此方法返回指定账户的暂挂余额。
Ctx.Account.getAccountOnHoldBalance(account_id: string)
参数:
  • account_id: string - 帐户的 ID。
返回:
  • 成功时,具有当前暂挂余额和成功消息的 promise 对象。出错时,包含错误消息的非零错误对象。
返回值示例:
{
   "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 富查询,并且只能在连接到远程 Oracle Blockchain Platform 网络时调用。
Ctx.func (t *Controller) GetAllAccounts() (interface{}, error)
参数:
返回:
  • 成功后,将生成一个列出所有帐户的 JSON 数组。
返回值示例:
"payload": [
    {
        "key": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
        "valueJson": {
            "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
            "AssetType": "oaccount",
            "Balance": 100,
            "BalanceOnHold": 0,
            "BapAccountVersion": 1,
            "OrgId": "appdev",
            "TokenId": "t1",
            "TokenName": "obptok",
            "TokenType": "fungible",
            "UserId": "idcqa"
        }
    }
]
GetUserByAccountId
此方法返回指定帐户的用户详细信息。
Ctx.Account.GetUserByAccountById(account_id string) (interface{}, error)
参数:
  • account_id: string - 帐户的 ID。
返回:
  • 成功时,使用包含三个属性的 JSON 对象的 promise:
    • user_id - 用户的用户名或电子邮件 ID。
    • org_id- 当前网络组织中用户的成员服务提供者 (Membership Service Provider,MSP) ID。
    • token_id - 标记的 ID。
  • 出错时,包含错误消息的非零错误对象。
返回值示例:
{
   "org_id":"Org1MSP",
   "token_id":"digiCurr101",
   "user_id":"user1"
}
GetAccountBalance
此方法返回指定帐户的帐户余额。
Ctx.GetAccountBalance(token_id string, org_id string, user_id string) (interface{}, error)
参数:
  • account_id: string - 帐户的 ID。
返回:
  • 成功时,带有消息字符串和当前余额的接口。出错时,包含错误消息的非零错误对象。
返回值示例:
{
    "msg": "Current Balance of +p2uaMTsU9D74l9XpHQ2c55ic/2gbO4NZITC4Zq4P8E= is: 200",
    "user_balance": 200
}
GetAllOrgAccounts
此方法返回属于指定组织的所有令牌帐户的列表。
Ctx.Account.GetAllOrgAccounts(org_id string) (interface{}, error)
参数:
  • org_id: string - 组织的成员服务提供者 (MSP) ID。
返回:
  • 成功后,将列出指定组织的所有帐户。
返回值示例:
[
    {
        "key": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
        "valueJson": {
            "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
            "AssetType": "oaccount",
            "Balance": 0,
            "BalanceOnHold": 0,
            "BapAccountVersion": 0,
            "OrgId": "appdev",
            "TokenId": "token",
            "TokenName": "fiatmoneytok",
            "TokenType": "fungible",
            "UserId": "idcqa"
        }
    },
    {
        "key": "oaccount~9c650574af9025a6106c8d12a801b079eda9ae2e3399fc2fbd5bd683d738a850",
        "valueJson": {
            "AccountId": "oaccount~9c650574af9025a6106c8d12a801b079eda9ae2e3399fc2fbd5bd683d738a850",
            "AssetType": "oaccount",
            "Balance": 0,
            "BalanceOnHold": 0,
            "BapAccountVersion": 0,
            "OrgId": "appdev",
            "TokenId": "token",
            "TokenName": "fiatmoneytok",
            "TokenType": "fungible",
            "UserId": "example_minter"
        }
    }
]

角色管理的方法

AddRoleMember
此方法向指定用户和令牌添加角色。
Ctx.Token.AddRoleMember(role string, account_id string, tokenAsset interface{}) (interface{}, error)
参数:
  • role: string- 要添加到指定用户的角色的名称。mintableburnable 行为对应于规范文件的 minter_role_nameburner_role_name 属性。同样,notary 角色对应于规范文件的 notary_role_name 属性。
  • account_id: number - 要向其添加角色的帐户 ID。
  • tokenAsset-tokenAsset 参数包含要操作的标记数据的引用。
返回:
  • 成功后,它将返回一个映射,其中包含一条成功消息,指示将角色添加到账户。出错时,包含错误消息的非零错误对象。
返回值示例:
{
   "msg":"Successfully added role minter to oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1)"
}
RemoveRoleMember
此方法将从指定用户和令牌中删除角色。
Ctx.Token.RemoveRoleMember(role string, account_id string, tokenAsset interface{}) (interface{}, error)
参数:
  • role: string- 要从指定用户中删除的角色的名称。mintableburnable 行为对应于规范文件的 minter_role_nameburner_role_name 属性。同样,notary 角色对应于规范文件的 notary_role_name 属性。
  • account_id: number - 要从中删除角色的帐户 ID。
  • tokenAsset-tokenAsset 参数包含要操作的标记数据的引用。
返回:
  • 成功后,它将返回一个映射,其中包含一条成功消息,指示从账户中删除角色。出错时,包含错误消息的非零错误对象。
返回值示例:
{
  "msg":"successfully removed member_id oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1) from role minter"
}
GetAccountsByRole
此方法返回指定角色和令牌的所有帐户的列表。
Ctx.Role.GetAccountsByRole(token_id string, user_role string) (interface{}, error)
参数:
  • token_id: string - 标记的 ID。
  • role: string - 要搜索的角色的名称。
返回:
  • 成功后,将生成 JSON 帐户 ID 数组。出错时,包含错误消息的非零错误对象。
返回值示例:
{"accounts":["oaccount~obptok~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f"]}
GetUsersByRole
此方法返回指定角色和令牌的所有用户的列表。
Ctx.Role.GetUsersByRole(token_id string, user_role string) (interface{}, error)
参数:
  • 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, tokenAsset interface{}) (bool, error)
参数:
  • role: string - 要检查的角色的名称。
  • account_id: number - 要检查的帐户 ID。
  • tokenAsset-tokenAsset 参数包含要操作的标记数据的引用。
返回:
  • 成功后,它将返回一个映射,其中包含一条成功消息,指示从账户中删除角色。出错时,包含错误消息的非零错误对象。
返回值示例:
{
    "result": false
}
RoleCheck
此方法检查提供的账户 ID 是否为任何角色的成员。
Ctx.Token.RoleCheck(account_id string, tokenAsset interface{}) (bool, error)
参数:
  • account_id: string - 要检查的帐户 ID。
  • tokenAsset-tokenAsset 参数包含要操作的标记数据的引用。
返回:
  • 如果指定的帐户具有任何角色,则显示成功消息和布尔值 true 。否则,布尔值 false 。出错时,包含错误消息的非零错误对象。
返回值示例:
{ result: true }
GetOrgUsersByRole
此方法返回有关在指定组织中具有指定角色的所有用户的信息。
Ctx.Role.GetOrgUsersByRole(token_id string, user_role string, org_id string) (interface{}, error)
参数:
  • token_id: string - 标记的 ID。
  • role: string - 要检查的角色的名称。
  • org_id: string - 组织的成员服务提供者 (MSP) ID。
返回:
  • 成功后,将列出指定组织中具有指定角色的所有用户。
返回值示例:
{
    "Users": [
        {
            "org_id": "Org1MSP",
            "token_id": "token",
            "user_id": "admin"
        },
        {
            "org_id": "Org1MSP",
            "token_id": "token",
            "user_id": "orgAdmin"
        }
    ]
}
GetOrgAccountsByRole
此方法返回有关在指定组织中具有指定角色的所有帐户的信息。
Ctx.Role.GetOrgAccountsByRole(token_id string, user_role string, org_id string) (interface{}, error)
参数:
  • token_id: string - 标记的 ID。
  • role: string - 要检查的角色的名称。
  • org_id: string - 组织的成员服务提供者 (MSP) ID。
返回:
  • 成功后,将列出在指定组织中具有指定角色的所有客户。
返回值示例:
{
    "accounts": [
        "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
         "oaccount~9c650574af9025a6106c8d12a801b079eda9ae2e3399fc2fbd5bd683d738a850"
    ]
}

事务处理历史记录管理方法

GetAccountTransactionHistory
此方法返回指定账户的事务处理历史记录详细信息数组。
Ctx.Account.GetAccountTransactionHistory(account_id string) (interface{}, error)
参数:
  • account_id: string - 帐户的 ID。
返回:
  • 返回值与 "GetAccountTransactionHistory" 方法相同。
  • 成功后,将生成一系列 JSON 账户事务处理对象。
  • 出错时,包含错误消息的非零错误对象。
返回值示例:
[
  {
      "NumberOfSubTransactions": 2,
      "balance": 160,
      "onhold_balance": 0,
      "timestamp": "2023-09-06T06:51:48Z",
      "token_id": "t1",
      "transacted_amount": 20,
      "transaction_id": "otransaction~bd3e8d7d0bcdbed0469a2fccfe95f7ebbeb1987d8385bccf5c84bf80251e748c",
      "transaction_type": "BULKTRANSFER"
  },
  {
      "balance": 180,
      "onhold_balance": 0,
      "timestamp": "2023-09-06T06:47:14Z",
      "token_id": "t1",
      "transacted_account": "oaccount~692a7465c01e36b694cb8ae86e6c6584240aa1f865fde54f95f32429eadd4097",
      "transacted_amount": 10,
      "transaction_id": "otransaction~250996f1df6a36a1b647f522efcaaf48fd70452d711c247fc4cd475b8e752b08",
      "transaction_type": "DEBIT"
  },
  {
      "balance": 190,
      "onhold_balance": 0,
      "timestamp": "2023-09-06T06:47:08Z",
      "token_id": "t1",
      "transacted_account": "oaccount~bb5a0b57d895327c8a8cd1f267310cbf3ae542bc854fab8188b5083a969d72fb",
      "transacted_amount": 10,
      "transaction_id": "otransaction~664325a25ae6b19b23693c66f83811184e0a78fabb49122359a2dbf209f32976",
      "transaction_type": "DEBIT"
  },
  {
      "balance": 200,
      "onhold_balance": 0,
      "timestamp": "2023-09-06T06:46:46Z",
      "token_id": "t1",
      "transacted_account": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
      "transacted_amount": 100,
      "transaction_id": "otransaction~7f49564b1eb61d4c8be0ef61cd5e635b533ca533907944e4ec500f390237fd6b",
      "transaction_type": "MINT"
  },
  {
      "balance": 100,
      "onhold_balance": 0,
      "timestamp": "2023-08-28T19:31:15Z",
      "token_id": "t1",
      "transacted_account": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
      "transacted_amount": 100,
      "transaction_id": "otransaction~adde470a63860ec1013bd5c5987e8a506a48942a91b0f39fc8e561374042bd27",
      "transaction_type": "MINT"
  }
]
GetAccountTransactionHistoryWithFilters
此方法返回指定事务处理的事务处理历史记录详细信息数组。仅当连接到远程 Oracle Blockchain Platform 网络时才能调用此方法。
t.Ctx.Account.GetAccountTransactionHistoryWithFilters (transaction_id: string, filters?: SubTransactionFilters)
参数:
  • Transaction_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"}'

[
    {
        "balance": 90,
        "onhold_balance": 0,
        "timestamp": "2022-04-20T19:43:36Z",
        "token_id": "tokenId",
        "transacted_account": "oaccount~7a4d67118e623a876b77c67e76b819269a8d4a509aece5d2263fb274a9beb3b8",
        "transacted_amount": 5,
        "transaction_id": "otransaction~dd9986d3686e52264935558e42026fbf8a9af48b06a3256a58b453f5ada4e636",
        "transaction_type": "DEBIT"
    },
    {
        "balance": 95,
        "onhold_balance": 0,
        "timestamp": "2022-04-20T19:43:22Z",
        "token_id": "tokenId",
        "transacted_account": "oaccount~0642308fc4c514c257ebf04326c63f990e2531bfd59d0b952056094da61e04ab",
        "transacted_amount": 5,
        "transaction_id": "otransaction~5e53424de3d691cf6b2a55ea3dc478c555d8784111c11847e594194d6c2e7755",
        "transaction_type": "DEBIT"
    },
    {
        "balance": 100,
        "onhold_balance": 0,
        "timestamp": "2022-04-20T19:42:54Z",
        "token_id": "tokenId",
        "transacted_account": "oaccount~b63935592a702d30bedb87ae97b9b1ba7d0f346716adc4f5a4192220bf410d4e",
        "transacted_amount": 100,
        "transaction_id": "otransaction~94c467825ce9f66cc69958d38b169022a69eebc66b75b7d6e0b0585af2c3c228",
        "transaction_type": "MINT"
    }
]
GetSubTransactionsById
此方法返回指定事务处理的事务处理历史记录详细信息数组。
t.Ctx.Account.GetSubTransactionsById(transaction_id string)
参数:
  • transaction_id: string - 事务处理的 ID。
示例:

ochain invoke GetSubTransactionsById 'otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b'

[
    {
        "balance": 80,
        "onhold_balance": 0,
        "timestamp": "2022-04-21T05:02:33Z",
        "token_id": "tokenId",
        "transacted_account": "oaccount~7a4d67118e623a876b77c67e76b819269a8d4a509aece5d2263fb274a9beb3b8",
        "transacted_amount": 5,
        "transaction_id": "otransaction~33de5d63058d5e9abc011bc850878dfb7ac3080495729aed345c45b2f21735fa~c81e728d9d4c2f636f067f89cc14862c",
        "transaction_type": "DEBIT"
    },
    {
        "balance": 85,
        "onhold_balance": 0,
        "timestamp": "2022-04-21T05:02:33Z",
        "token_id": "tokenId",
        "transacted_account": "oaccount~0642308fc4c514c257ebf04326c63f990e2531bfd59d0b952056094da61e04ab",
        "transacted_amount": 5,
        "transaction_id": "otransaction~33de5d63058d5e9abc011bc850878dfb7ac3080495729aed345c45b2f21735fa~c4ca4238a0b923820dcc509a6f75849b",
        "transaction_type": "DEBIT"
    }
]
GetSubTransactionsByIdWithFilters
此方法返回指定事务处理的事务处理历史记录详细信息数组。
t.Ctx.Account.GetSubTransactionsByIdWithFilters(transaction_id string, filters ...SubTransactionFilters)
参数:
  • transaction_id: string - 事务处理的 ID。
  • filters: string- 可选参数。如果为空,将返回所有记录。PageSize 属性确定要返回的记录数。如果 PageSize 为 0,则默认页面大小为 20。Bookmark 属性确定要返回的记录起始索引。有关更多信息,请参见 Hyperledger Fabric 文档。必须以 RFC-3339 格式指定 StartTimeEndTime 属性。
示例:

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

[
    {
        "balance": 80,
        "onhold_balance": 0,
        "timestamp": "2022-04-21T05:02:33Z",
        "token_id": "tokenId",
        "transacted_account": "oaccount~7a4d67118e623a876b77c67e76b819269a8d4a509aece5d2263fb274a9beb3b8",
        "transacted_amount": 5,
        "transaction_id": "otransaction~33de5d63058d5e9abc011bc850878dfb7ac3080495729aed345c45b2f21735fa~c81e728d9d4c2f636f067f89cc14862c",
        "transaction_type": "DEBIT"
    },
    {
        "balance": 85,
        "onhold_balance": 0,
        "timestamp": "2022-04-21T05:02:33Z",
        "token_id": "tokenId",
        "transacted_account": "oaccount~0642308fc4c514c257ebf04326c63f990e2531bfd59d0b952056094da61e04ab",
        "transacted_amount": 5,
        "transaction_id": "otransaction~33de5d63058d5e9abc011bc850878dfb7ac3080495729aed345c45b2f21735fa~c4ca4238a0b923820dcc509a6f75849b",
        "transaction_type": "DEBIT"
    }
]
GetTransactionById
此方法返回 Transaction 资产的历史记录。
t.Ctx.Transaction.GetTransactionById(transaction_id string)
参数:
  • transaction_id string - 事务处理资产的 ID。
返回值示例:
{
    "history": [
        {
            "IsDelete": "false",
            "Timestamp": "2021-08-16 20:19:05.028 +0530 IST",
            "TxId": "67042154a6853011d111b13f73943f06d2a6ae3cfb9a84cb104482c359eb2220",
            "Value": {
                "Amount": 3,
                "AssetType": "otransaction",
                "FromAccountId": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
                "HoldingId": "ohold~digicur~digiCurr101~op2",
                "NumberOfSubTransactions": 0,
                "Timestamp": "2021-08-16T20:19:05+05:30",
                "ToAccountId": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
                "TokenId": "digiCurr101",
                "TransactionId": "otransaction~67042154a6853011d111b13f73943f06d2a6ae3cfb9a84cb104482c359eb2220",
                "TransactionType": "RELEASEHOLD"
            }
        }
    ],
    "transaction_id": "otransaction~67042154a6853011d111b13f73943f06d2a6ae3cfb9a84cb104482c359eb2220"
}
DeleteHistoricalTransactions
此方法从状态数据库中删除较早的事务处理。
func (t *Controller) DeleteHistoricalTransactions(timestamp string) (interface{}, error)
参数:
  • time_to_expiration: Date - 指示何时删除事务处理的时间戳。将删除早于指定时间的事务处理资产。
返回值示例:
"payload": {
    "msg": "Successfuly deleted transaction older than date:2021-08-18T05:43:30Z",
    "transactions": [
        "otransaction~57d81f681aa215bb73d6c017d16be8b283d3fcb50051c85891a97d1d407fc342"
    ]
}

标记行为管理的方法 - 可最小化行为

Mint
此方法铸币令牌,该令牌随后由方法的调用者拥有。调用方必须具有帐户和 minter 角色。可以铸造的标记数受规范文件中 mintable 行为的 max_mint_quantity 属性的限制。如果未指定 max_mint_quantity 属性,则可以铸造数量不限的标记。数量必须在规范文件中 divisible 行为的 decimal 参数指定的小数值内。此方法只能由具有 minter 角色的帐户的 AccountOwner 调用。
Ctx.Token.Mint(quantity float64, tokenAsset interface{}) (interface{}, error)
参数:
  • quantity: number - 到 mint 的标记数。
  • tokenAsset - 对 mint 的标记资产的引用。
返回:
  • 成功时,显示一条成功消息。出错时,包含错误消息的非零错误对象。
返回值示例:
{
  "msg":"Successfully minted 1000 tokens to Account Id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: admin)"
}
GetTotalMintedTokens
此方法返回铸造标记的总数。
Ctx.Token.GetTotalMintedTokens(tokenAsset interface{}) (map[string]interface{}, error)
参数:
  • tokenAsset-tokenAsset 参数包含要操作的标记数据的引用。
返回:
  • 成功时,数字数据类型中的成功消息和总铸造标记的映射。出错时,包含错误消息的非零错误对象。
返回值示例:
{"msg":"total minted amount for token with id digiCurr101 is 0","quantity":0}
GetNetTokens
此方法返回系统中可用于指定标记的标记的净数量。净令牌是令牌燃烧后剩余的令牌数量。在方程式形式:净代币 = 总铸造代币 - 总烧毁代币。如果没有刻录标记,则净标记的数量等于铸造标记的总数。
Ctx.Token.GetNetTokens(tokenAsset interface{}) (map[string]interface{}, error)
参数:
  • tokenAsset-tokenAsset 参数包含要操作的标记数据的引用。
返回:
  • 成功时,成功消息和数字数据类型中标记的净数量的映射。出错时,出现错误消息。
返回值示例:
{"msg":"net minted amount for token with id digiCurr101 is 0","quantity":0}
GetMaxMintQuantity
此方法返回令牌的最大可最小数量。如果未指定 max_mint_quantity 行为,则默认值为 0,这允许铸造任意数量的标记。
Ctx.Token.GetMaxMintQuantity(token_id string) (float64, error)
参数:
  • token_id: string - 要检查的标记 ID。
返回:
  • 成功时,标记的最大可最小数量(以数字数据类型表示)。出错时,包含错误消息的非零错误对象。
返回值示例:
20000

标记行为管理的方法 - 可传输行为

Transfer
此方法将令牌从调用方传输到指定的帐户。方法的调用方必须具有一个帐户。数量必须在规范文件中 divisible 行为的 decimal 参数指定的小数值内。此方法只能由帐户的 AccountOwner 调用。
Ctx.Token.Transfer(to_account_id string, quantity float64, tokenAsset interface{}) (interface{}, error)
参数:
  • to_account_id: string - 用于接收令牌的帐户 ID。
  • quantity: number - 要传输的令牌总数。
  • tokenAsset-tokenAsset 参数包含要操作的标记数据的引用。
返回:
  • 成功时,显示一条成功消息。出错时,包含错误消息的非零错误对象。返回值与 "TransferTokens" 方法相同。
返回值示例:
{     "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 []map[string]interface{}, tokenAsset interface{}) (interface{}, error)
参数:
  • 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
    }]
  • tokenAsset-tokenAsset 参数包含要操作的标记数据的引用。
返回:
  • 成功时,会出现一条成功消息,其中包含传输的令牌数。出错时,包含错误消息的非零错误对象。
返回值示例:
{
    "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 float64, TimeToExpiration string, tokenAsset)) (interface{}, error)
参数:
  • 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
  • tokenAsset-tokenAsset 参数包含要操作的标记数据的引用。
返回:
  • 成功时,显示一条成功消息。出错时,包含错误消息的非零错误对象。
返回值示例:
{
 "msg": "account id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (org_id : Org1MSP, user_id : user1) is successfully holding 10 tokens",
}
ExecuteHold
此方法完成对令牌的暂挂,将以前暂挂的指定数量的令牌转移给接收方。如果 quantity 值小于实际暂挂值,则剩余金额将再次提供给令牌的原始所有者。此方法只能由具有 notary 角色的 AccountOwner ID 调用。
Ctx.Token.ExecuteHold(operation_id string, quantity float64, tokenAsset interface{}) (interface{}, error)
参数:
  • operation_id: string - 用于标识暂挂操作的唯一 ID。通常,此 ID 由客户机应用程序传递。
  • quantity: number - 要暂挂的令牌总数。
  • tokenAsset-tokenAsset 参数包含要操作的标记数据的引用。
返回:
  • 成功时,显示一条成功消息。出错时,包含错误消息的非零错误对象。
返回值示例:
{"msg":"Account Id oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1) has successfully executed '1' tokens(digiCurr101) from the hold with Operation Id 'op1'"}
ReleaseHold
此方法释放对标记的暂挂。转移未完成,所有保留的令牌都再次可供原始所有者使用。此方法可由 Account Owner ID 在指定时间限制内具有 notary 角色或者在指定时间限制后由付款人、受款人或公证人调用。
Ctx.Token.ReleaseHold(operation_id string, tokenAsset interface{}) (interface{}, error)
参数:
  • operation_id: string - 用于标识暂挂操作的唯一 ID。通常,此 ID 由客户机应用程序传递。
  • tokenAsset-tokenAsset 参数包含要操作的标记数据的引用。
返回:
  • 成功时,显示一条成功消息。出错时,包含错误消息的非零错误对象。
返回值示例:
{"msg":"Successfully released '3' tokens from Operation Id 'op2' to Account Id oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1)"}
GetOnHoldIds
此方法返回指定用户和令牌的所有持有 ID 的列表。
Ctx.Account.GetOnHoldIDs(account_id string) (map[string]interface{}, error)
参数:
  • token_id - 标记的 ID。
  • org_id- 当前网络组织中用户的成员服务提供者 (Membership Service Provider,MSP) ID。
  • user_id - 用户的用户名或电子邮件 ID。
返回:
  • 成功时,包含持有 ID 列表的 JSON 对象。持有 ID 是通过连接资产类型 (ohold)、令牌名称、令牌 ID 和操作 ID 形成的。
返回值示例:
{"holding_ids":["ohold~loyaltok123~t1~op1"],"msg":"Holding Ids are: [ohold~loyaltok123~t1~op1]"}
GetOnHoldDetailsWithOperationID
此方法返回指定操作 ID 和标记的暂挂事务处理详细信息。
Ctx.Hold.GetOnHoldDetailsWithOperationID(token_id string, operation_id string) (Hold, error)
参数:
  • token_id: string - 标记的 ID。
  • operation_id: string - 用于标识暂挂操作的唯一 ID。通常,此 ID 由客户机应用程序传递。
返回:
  • 返回值与 "GetOnHoldDetailsWithOperationId" 方法相同。
  • 成功时,包含指定操作 ID 和标记的暂挂事务处理详细信息的 promise 对象。暂挂对象包括以下属性:
    • 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",
    "HoldingId": "ohold~digicur~digiCurr101~op1",
    "OperationId": "op1",
    "TokenName": "digicur",
    "FromAccountId": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
    "ToAccountId": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
    "NotaryAccountId": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
    "TokenId": "digiCurr101",
    "Quantity": 2,
    "TimeToExpiration": "0"
}
GetOnHoldBalanceWithOperationID
此方法返回指定操作 ID 和标记的暂挂余额。
Ctx.Hold.GetOnHoldBalanceWithOperationID(token_id string, operation_id string) (map[string]interface{}, error)
参数:
  • token_id: string - 标记的 ID。
  • operation_id: string - 用于标识暂挂操作的唯一 ID。通常,此 ID 由客户机应用程序传递。
返回:
  • 成功时,指定操作 ID 和标记的暂挂余额。出错时,包含错误消息的非零错误对象。
返回值示例:
{
    "holding_balance": 10,
    "msg": "Current Holding Balance of OperationId opr_121 for token digiCurr101 is : 10"
}

标记行为管理的方法 - 可刻录行为

Burn
此方法从事务处理调用者的账户中停用或刻录标记。此方法的调用方必须具有帐户和刻录器角色。数量必须在规范文件中 divisible 行为的 decimal 参数指定的小数值内。
Ctx.Token.Burn(quantity float64 , tokenAsset interface{}) (interface{}, error)
参数:
  • quantity: number - 要刻录的令牌总数。
  • tokenAsset-tokenAsset 参数包含要操作的标记数据的引用。
返回:
  • 成功时,显示一条成功消息。出错时,包含错误消息的非零错误对象。
返回值示例:
{
 "msg":"Successfully burned 10 tokens from account id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: admin)"
}