Hyperledger composer javascript return value

坚强是说给别人听的谎言 提交于 2020-01-06 06:05:28

问题


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.

Model

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

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

Transaction

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;
  }  
}

I want get with this. https://localhost:3000/api/SampleLogin

return True or False

回答1:


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?



来源:https://stackoverflow.com/questions/49597701/hyperledger-composer-javascript-return-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!