如何在 hyperledger composer 中获取特定资产的交易历史记录?
How to get history of transactions for particular Asset in hyperledger composer?
我试过下面的代码,但我无法获取特定资产的交易历史,有人能帮我解决这个问题吗?
@commit(假)
@returns(订单[])
交易订单历史{
o 字符串订单号
}在此处输入代码
/**
* 样本交易
* @param {org.acme.Block.orderHistory} 购买
* @交易
*/
异步函数 orderHistory(transaction) {
const orderNumber = purchase.orderNumber;
const nativeSupport = purchase.nativeSupport;
const assetRegistry = await getAssetRegistry('org.acme.Block.Order')
const nativeKey = getNativeAPI().createCompositeKey('Asset:org.acme.Block.Order', [orderNumber]);
console.log(nativeKey);
const iterator = await getNativeAPI().getHistoryForKey(nativeKey);
let results = [];
let res = {done : false};
while (!res.done) {
res = await iterator.next();
if (res && res.value && res.value.value) {
console.log(res);
let val = res.value.value.toString('utf8');
if (val.length > 0) {
results.push(JSON.parse(val));
}
}
if (res && res.done) {
try {
iterator.close();
}
catch (err) {
}
}
}
return results;
在 hyperledger composer 中,所有交易都存储在 Historian Record 中 (https://hyperledger.github.io/composer/unstable/reference/historian.html)。所以查询和使用相同的将解决您的问题。 Historian 记录是在 Hyperledger composer 命名空间中定义的资产。
历史记录定义为:
asset HistorianRecord identified by transactionId {
o String transactionId
o String transactionType
--> Transaction transactionInvoked
--> Participant participantInvoking optional
--> Identity identityUsed optional
o Event[] eventsEmitted optional
o DateTime transactionTimestamp
}
您可以阅读有关 Historian Client API 的更多信息,这将证明对您有用:https://hyperledger.github.io/composer/v0.19/api/client-historian
此外,请阅读有关作曲家资产历史的讨论:https://github.com/hyperledger/composer/issues/2458
我试过下面的代码,但我无法获取特定资产的交易历史,有人能帮我解决这个问题吗?
@commit(假)
@returns(订单[])
交易订单历史{
o 字符串订单号
}在此处输入代码
/** * 样本交易 * @param {org.acme.Block.orderHistory} 购买 * @交易 */ 异步函数 orderHistory(transaction) {
const orderNumber = purchase.orderNumber;
const nativeSupport = purchase.nativeSupport;
const assetRegistry = await getAssetRegistry('org.acme.Block.Order')
const nativeKey = getNativeAPI().createCompositeKey('Asset:org.acme.Block.Order', [orderNumber]);
console.log(nativeKey);
const iterator = await getNativeAPI().getHistoryForKey(nativeKey);
let results = [];
let res = {done : false};
while (!res.done) {
res = await iterator.next();
if (res && res.value && res.value.value) {
console.log(res);
let val = res.value.value.toString('utf8');
if (val.length > 0) {
results.push(JSON.parse(val));
}
}
if (res && res.done) {
try {
iterator.close();
}
catch (err) {
}
}
}
return results;
在 hyperledger composer 中,所有交易都存储在 Historian Record 中 (https://hyperledger.github.io/composer/unstable/reference/historian.html)。所以查询和使用相同的将解决您的问题。 Historian 记录是在 Hyperledger composer 命名空间中定义的资产。
历史记录定义为:
asset HistorianRecord identified by transactionId {
o String transactionId
o String transactionType
--> Transaction transactionInvoked
--> Participant participantInvoking optional
--> Identity identityUsed optional
o Event[] eventsEmitted optional
o DateTime transactionTimestamp
}
您可以阅读有关 Historian Client API 的更多信息,这将证明对您有用:https://hyperledger.github.io/composer/v0.19/api/client-historian
此外,请阅读有关作曲家资产历史的讨论:https://github.com/hyperledger/composer/issues/2458