简体   繁体   English

关于 Hyperledger Fabric 上下文

[英]On Hyperledger Fabric Context

I would appreciate some help with this small issue.我会很感激这个小问题的一些帮助。 According to the comercial paper smart contract , present in Fabric-samples, one can define a custom Context , which allows handling logic across different transactions.根据 Fabric-samples 中的商业论文智能合约,可以定义一个自定义Context ,它允许跨不同事务处理逻辑。 Can we define a variable in a Context, initialized as 0, and increment it at each transaction?我们可以在 Context 中定义一个变量,初始化为 0,并在每个事务中增加它吗? I do not seem able to increment it, ie, the counter always resets at each transation:我似乎无法增加它,即计数器总是在每次交易时重置:

class CustomContext extends Context {

constructor() {
    super();
    this.comercialPaperList = new PaperList(this);
    this.counter = 0;
}

generateLogId() {
    return this.numberLogs++;
}

getLatestLogId() {
    return this.numberLogs;
}

} }

class MyContract extends Contract {

constructor() {
    // Unique namespace when multiple contracts per chaincode file
    super('...');
}

/**
 * Define a custom context for a citius log
*/
createContext() {
    return new CustomContext();

I have a test transaction which increments the counter:我有一个增加计数器的测试事务:

async incrementC (ctx)  {
    let before = await ctx.getLatestLogId();
    console.log(before);
    let new = await ctx.generateLogId();
    console.log(new);
    console.log("============== after inc")
    let after = await ctx.getLatestLogId();
    console.log(after);
}

On the first time I execute the incrementC transaction, I obtain 0, 1, 1, as expected.在我第一次执行 incrementC 事务时,我按预期获得了 0、1、1。 On the following times, I obtain exacly the same, as if context did not store the updates.在以下时间,我获得完全相同,好像上下文没有存储更新。

Any insights?任何见解?

A Custom context has the same scope as a non custom context, it is the context for the currently executing transaction only.自定义上下文与非自定义上下文具有相同的范围,它仅是当前正在执行的事务的上下文。 It is not able to span across multiple transaction requests.它不能跨越多个事务请求。 If the documentation implies this then I would suggest that there is something wrong with the documentation and a jira should be raised at https://jira.hyperledger.org to raise this as an issue.如果文档暗示了这一点,那么我会建议文档有问题,应该在https://jira.hyperledger.org上提出一个 jira 来提出这个问题。 So unfortunately what you are trying to do will not work.所以不幸的是,你正在尝试做的事情不会奏效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM