-
initializeExchangePoolUser
- 此方法初始化交换池用户,这是一次性活动。此方法只能由链代码的
Token Admin
调用。
-
@Validator(yup.string(), yup.string())
public async initializeExchangePoolUser(org_id: string, user_id: string){
await this.Ctx.Auth.checkAuthorization('TOKEN_CONVERSION.initializeExchangePoolUser', 'TOKEN');
return await this.Ctx.TokenConvertor.initializeExchangePoolUser(org_id, user_id);
}
- 参数:
org_id: string
- 当前组织中用户的成员服务提供者 (MSP) ID。
user_id: string
- 用户的用户名或电子邮件 ID。
- 返回:
- 成功时,显示一条消息,其中包含交换池用户的详细信息。
- 返回值示例:
{
"assetType": "oconversion",
"convertor_id": "bcb1f3b1442c625d3ce205660c5e717c5858a1fe1e12c325df799a851ceaa09b",
"org_id": "Org1MSP",
"user_id": "exchangepooluser"
}
-
createExchangePoolAccounts
- 此方法为给定的标记 ID 数组创建交换池标记帐户。此方法只能由链代码的
Token Admin
调用。
-
@Validator(yup.array().of(yup.string()))
public async createExchangePoolAccounts(token_ids: string[]){
await this.Ctx.Auth.checkAuthorization('TOKEN_CONVERSION.initializeExchangePoolUser', 'TOKEN');
return await this.Ctx.TokenConvertor.createExchangePoolAccounts(token_ids);
}
- 参数:
token_ids: string []
- 标记 ID 的数组。
- 返回:
- 成功后,将列出包含所创建的交换池帐户详细信息的对象。
- 返回值示例:
[
{
"account_id": "oaccount~cc9d84f6d4a5976532493ef5200c9603e138adc35166ffd5fd1aad9c1647f034",
"token_id": "USD",
"status": "created"
},
{
"account_id": "oaccount~3d4933111ec8bd6cc1ebb43f2b2c390deb929cfa534f9c6ada8e63bac04a13c0",
"token_id": "INR",
"status": "created"
}
]
-
addConversionRate
- 此方法为一对令牌添加转换率。令牌转换率最多可以指定八位小数。此方法只能由链代码的
Token Admin
调用。
-
@Validator(yup.string(), yup.string(), yup.number())
public async addConversionRate(from_token_id:string , to_token_id:string, token_conversion_rate: number) {
await this.Ctx.Auth.checkAuthorization('TOKEN_CONVERSION.addConversionRate', 'TOKEN');
return await this.Ctx.TokenConvertor.addConversionToken(from_token_id,to_token_id,token_conversion_rate);
}
- 参数:
from_token_id: string
- 要转换的令牌的 ID。
to_token_id: string
- 要转换到的令牌的 ID。
token_conversion_rate: number
- 将 from_token_id
标记转换为 to_token_id
标记的速率。
- 返回:
- 返回值示例:
{
"assetType": "oconversionRate",
"conversion_rate_id": "oconversionRate~91c7eeb0614e7a50b1d5ecad559fcbc80b94034648bf405c9491dacf8d57873b",
"from_token_id": "USD",
"to_token_id": "INR",
"conversion_rate": 10
}
-
getConversionRate
- 此方法获取一对令牌的当前转换率。此方法可由链代码的
Token Admin
、任何 Org Admin
和任何令牌帐户所有者调用。
-
@Validator(yup.string(), yup.string())
public async getConversionRate(from_token_id:string , to_token_id:string) {
await this.Ctx.Auth.checkAuthorization('TOKEN_CONVERSION.getConversionRate', 'TOKEN');
const conversion_rate_id = await this.Ctx.TokenConversionRate.getConversionRateId(from_token_id, to_token_id);
return await this.Ctx.TokenConversionRate.get(conversion_rate_id);
}
- 参数:
from_token_id: string
- 要转换的令牌的 ID。
to_token_id: string
- 要转换到的令牌的 ID。
- 返回:
- 返回值示例:
{
"assetType": "oconversionRate",
"conversion_rate_id": "oconversionRate~91c7eeb0614e7a50b1d5ecad559fcbc80b94034648bf405c9491dacf8d57873b",
"from_token_id": "USD",
"to_token_id": "INR",
"conversion_rate": 10
}
-
updateConversionRate
- 此方法更新一对令牌的当前转换率。令牌转换率最多可以指定八位小数。此方法只能由链代码的
Token Admin
调用。
-
@Validator(yup.string(), yup.string(), yup.number())
public async updateConversionRate(from_token_id:string , to_token_id:string, token_conversion_rate: number) {
await this.Ctx.Auth.checkAuthorization('TOKEN_CONVERSION.updateConversionRate', 'TOKEN');
return await this.Ctx.TokenConvertor.updateTokenConversionRate(from_token_id,to_token_id,token_conversion_rate);
}
- 参数:
from_token_id: string
- 要转换的令牌的 ID。
to_token_id: string
- 要转换到的令牌的 ID。
token_conversion_rate: number
- 将 from_token_id
标记转换为 to_token_id
标记的速率。
- 返回:
- 成功后,更新后的转换率对象的 JSON 表示形式。
- 返回值示例:
{
"assetType": "oconversionRate",
"conversion_rate_id": "oconversionRate~91c7eeb0614e7a50b1d5ecad559fcbc80b94034648bf405c9491dacf8d57873b",
"from_token_id": "USD",
"to_token_id": "INR",
"conversion_rate": 20
}
-
mintWithFundingExchangePool
- 此方法根据指定的标记 ID 和数量在调用者的帐户中铸造标记。然后,铸造数量中标记的百分比将传输到交换池标记账户。
-
@Validator(yup.string(), yup.number(), yup.number())
public async mintWithFundingExchangePool(token_id: string, token_quantity: number, percentage_token_to_exchange_pool: number) {
return await this.Ctx.TokenConvertor.mintWithFundingExchangePool(token_id, token_quantity, percentage_token_to_exchange_pool);
}
- 参数:
token_id: string
- 到 mint 的标记的 ID。
token_quantity: number
- 到 mint 的令牌总数。
percentage_token_to_exchange_pool: number
- 要传输到交换池令牌帐户的铸造令牌百分比。
- 返回:
- 成功后,将显示一条消息,指示已成功铸造交换池并为其提供资金。
- 返回值示例:
{
"msg": "Successfully minted 100 tokens to Account Id: oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb (Org-Id: Org1MSP, User-Id: admin) and Successfully transfered 20 tokens to exchange pool Account with Account Id: oaccount~cc9d84f6d4a5976532493ef5200c9603e138adc35166ffd5fd1aad9c1647f034 (Org-Id: Org1MSP, User-Id: exchangepooluser) "
}
-
tokenConversion
- 此方法将标记从调用者的帐户转换为由
to_token_id
、to_org_id
和 to_user_id
值指定的帐户。此方法可由链代码的 Token Admin
和任何令牌帐户所有者调用。交换池用户无法调用此方法。
-
@Validator(yup.string(),yup.string(),yup.string(),yup.string(),yup.number())
public async tokenConversion(from_token_id:string, to_token_id:string, to_org_id:string, to_user_id:string, token_quantity:number){
await this.Ctx.Auth.checkAuthorization('TOKEN_CONVERSION.tokenConversion', 'TOKEN');
return await this.Ctx.TokenConvertor.tokenConversion(from_token_id,to_token_id,to_org_id,to_user_id,token_quantity);
}
- 参数:
from_token_id: string
- 要转换的令牌的 ID。
to_token_id: string
- 要转换到的令牌的 ID。
to_org_id: string
- 当前组织中接收令牌的用户的成员资格服务提供商 (MSP) ID。
to_user_id: string
- 接收令牌的用户的用户名或电子邮件 ID。
token_quantity: number
- 要传输的令牌总数。
- 返回:
- 返回值示例:
{
"msg": "Succesfully converted 5 of tokens with tokenId: [USD] from AccountId: oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb (Org-Id: Org1MSP, User-Id: admin) to 100 of tokens with tokenId: [INR] to AccountId: oaccount~25e2e66718b6dbb59aea9c32acebec60e09d912b2578d4933d377ae5d0628f1e (Org-Id: Org1MSP, User-Id: user) as per the conversion rate of 20"
}
-
getConversionHistory
- 此方法返回指定令牌帐户的令牌转换历史记录。此方法可由链代码的
Token Admin
、指定组织的 Org Admin
或令牌帐户所有者调用。
-
@Validator(yup.string(), yup.string(), yup.string())
public async getConversionHistory(token_id: string, org_id: string, user_id: string) {
const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
await this.Ctx.Auth.checkAuthorization("ACCOUNT.getConversionHistory", "TOKEN", { account_id });
return await this.Ctx.Account.getTokenConversionHistory(account_id, org_id, user_id);
}
- 参数:
token_id: string
- 标记的 ID。
org_id: string
- 当前组织中用户的成员服务提供者 (MSP) ID。
user_id: string
- 用户的用户名或电子邮件 ID。
- 返回:
- 成功时,带有转换历史记录详细信息的 JSON 对象。
- 返回值示例:
[
{
"transaction_id": "otransaction~34edd19e03ec8bbbc77bc3372081410a824a5c10f9aa522b3a6390d7e8cb11cf",
"from_account_id": "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
"to_account_id": "oaccount~25e2e66718b6dbb59aea9c32acebec60e09d912b2578d4933d377ae5d0628f1e",
"transacted_amount": 5,
"converted_amount": 100,
"conversion_rate": "20",
"from_token_id": "USD",
"to_token_id": "INR",
"balance": 75,
"onhold_balance": 0,
"timestamp": "2022-11-30T11:03:20.000Z",
"transaction_type": "TOKEN_CONVERSION_DEBIT"
}
]
-
getConversionRateHistory
- 此方法返回一对令牌的令牌转换率历史记录。此方法可由链代码的
Token Admin
、任何 Org Admin
和任何令牌帐户所有者调用。
-
@Validator(yup.string(), yup.string())
public async getConversionRateHistory(from_token_id:string , to_token_id:string) {
const conversion_rate_id = await this.Ctx.TokenConversionRate.getConversionRateId(from_token_id,to_token_id);
await this.Ctx.Auth.checkAuthorization('TOKEN_CONVERSION.getConversionRateHistory', 'TOKEN');
return await this.Ctx.TokenConversionRate.history(conversion_rate_id);
}
- 参数:
from_token_id: string
- 用于计算折换率的要转换的标记的 ID。
to_token_id: string
- 要转换为的标记的 ID,用于计算转换率。
- 返回:
- 成功时,具有折换率历史记录详细信息的 JSON 对象。
- 返回值示例:
[
{
"trxId": "0b1ba7bc2620e1438b6580365e5c0ab852247ccfa5a3eb2157d3baca02c0e521",
"timeStamp": "2022-11-30T10:23:38.000Z",
"value": {
"assetType": "oconversionRate",
"conversion_rate_id": "oconversionRate~91c7eeb0614e7a50b1d5ecad559fcbc80b94034648bf405c9491dacf8d57873b",
"from_token_id": "USD",
"to_token_id": "INR",
"conversion_rate": 20
}
},
{
"trxId": "36fc40ddb3d8308ee7e156af700da131d78d941fe390fc57985b7589e7035d5c",
"timeStamp": "2022-11-30T10:13:18.000Z",
"value": {
"assetType": "oconversionRate",
"conversion_rate_id": "oconversionRate~91c7eeb0614e7a50b1d5ecad559fcbc80b94034648bf405c9491dacf8d57873b",
"from_token_id": "USD",
"to_token_id": "INR",
"conversion_rate": 10
}
}
]
-
getExchangePoolUser
- 此方法返回交换池用户的
org_id
和 user_id
值。此方法只能由链代码的 Token Admin
调用。
-
@Validator()
public async getExchangePoolUser() {
await this.Ctx.Auth.checkAuthorization('TOKEN_CONVERSION.getExchangePoolUser', 'TOKEN');
return await this.Ctx.TokenConvertor.getExchangePoolUser();
}
- 参数:
- 返回:
- 成功后,将显示一条消息,其中包含有关交换池用户的信息。
- 返回值示例:
{
"assetType": "oconversion",
"convertor_id": "bcb1f3b1442c625d3ce205660c5e717c5858a1fe1e12c325df799a851ceaa09b",
"org_id": "Org1MSP",
"user_id": "exchangepooluser"
}