Hyperledger Composer JavaScript返回值 [英] Hyperledger composer javascript return value

查看:60
本文介绍了Hyperledger Composer JavaScript返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建用于登录的智能合约.当用户输入正确的用户名和密码后,它将返回真,并且将不正确的返回假到我的Web应用程序.

I want to create smart contract for login. When users input username and password are correct its will return true and incorrect return false to my web application.

型号

participant SampleParticipant identified by participantId {
  o String participantId
  o String username
  o String password
}

transaction SampleLogin {
  --> SampleParticipant participant
  o String inputUsername
  o String inputPassword
}

交易

function sampleLogin(tx) {

  var username = tx.participant.username;
  var password = tx.participant.password;
  var inputUsername = tx.inputUsername;
  var inputPassword = tx.inputPassword;

  if (username == inputUsername && password == inputPassword){
    //return true;
  }else{
    //return false;
  }  
}

我想要得到这个. https://localhost:3000/api/SampleLogin

return True or False

推荐答案

TP从REST API返回200(已提交事务). TP返回一个Promise,可以将其解析为布尔值,其值为true或false-取决于您的结果(上述).您不会从TP中return退出.在我看来,您的登录代码在客户端应用中会更好-否则,您将为每个登录集(无论好坏)以及ID和密码存储在分类帐中创建事务.这就是你想要的吗?

The TP returns a 200 from the REST API (transaction submitted). The TP returns a Promise which can be resolved as a Boolean, having value either true or false - depending on your result (above). You wouldn't return out from the TP. Seems to me your login code would be better in a client app - otherwise you're creating a transaction for each and every login set, good or bad and with the id and password stored in the ledger. Is this what you want?

这篇关于Hyperledger Composer JavaScript返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆