<commit_before>/**
 * Main App Controller for the Angular Material Starter App
 * @param UsersDataService
 * @param $mdSidenav
 * @constructor
 */
function EthereumService($q) {

    var self = this;

    self.abi = [ { "constant": true, "inputs": [ { "name": "serial", "type": "string" } ], "name": "getCustomer", "outputs": [ { "name": "", "type": "address", "value": "0x0000000000000000000000000000000000000000" } ], "payable": false, "type": "function" }, { "constant": false, "inputs": [ { "name": "serial", "type": "string" }, { "name": "customer", "type": "address" }, { "name": "endDate", "type": "uint256" } ], "name": "requestWarranty", "outputs": [], "payable": false, "type": "function" }, { "constant": false, "inputs": [ { "name": "contractAddress", "type": "address" } ], "name": "updateCalculator", "outputs": [], "payable": false, "type": "function" }, { "constant": true, "inputs": [ { "name": "serial", "type": "string" } ], "name": "getEndDate", "outputs": [ { "name": "", "type": "uint256", "value": "0" } ], "payable": false, "type": "function" }, { "constant": true, "inputs": [ { "name": "serial", "type": "string" } ], "name": "isWarrantyValid", "outputs": [ { "name": "", "type": "bool", "value": true } ], "payable": false, "type": "function" }, { "inputs": [], "type": "constructor" } ];
    self.dappId = "epam.hackathon";

    self.contractAddress = "0xF65a613630e112cc2Fc0fB382770E3845b857105";
    self.walletBar = new WalletBar({
        containerName:'#signInId',
        dappNamespace: self.dappId,
        blockchain: "morden"
    });

    self.web3 = new Web3();
    self.WarrantyContract;
    self.waitForWallet = self.walletBar.applyHook(self.web3)
    .then(function() {
        self.WarrantyContract = self.web3.eth.contract(self.abi).at(self.contractAddress);
    })
    .catch(function(err) {
        console.log(err);
    });

    function prepareForTransaction() {
      self.walletBar.createSecureSigner();
    }

    self.getInfo = function(serial) {
      return self.waitForWallet.then(function() {
       return $q.all({
          isWarrantyValid: self.isWarrantyValid(serial),
          customer: self.getCustomer(serial),
          warrantyEndDate: self.getWarrantyEndDate(serial)
        });
     });
    }

    self.isWarrantyValid = function(serial) {
      var defer = $q.defer();

      self.WarrantyContract.isWarrantyValid(serial, function(err, result){
        if(err) {
          defer.reject(err);
        }else {
          defer.resolve(result);
        }
      });

      return defer.promise;
    }

    self.getCustomer = function(serial) {
      var defer = $q.defer();

      self.WarrantyContract.getCustomer(serial, function(err, result){
        if(err) {
          defer.reject(err);
        }else {
          defer.resolve(result);
        }
      });

      return defer.promise;
    }

    self.getWarrantyEndDate = function(serial) {
      var defer = $q.defer();

      self.WarrantyContract.getWarrantyEndDate(serial, function(err, result){
        if(err) {
          defer.reject(err);
        }else {
          defer.resolve(result);
        }
      });

      return defer.promise;
    }

    self.requestWarranty = function(serial, owner, endDate) {
      var defer = $q.defer();
      prepareForTransaction();
      self.WarrantyContract.requestWarranty(serial, owner, endDate.getTime(), function(err, result){
        if(err) {
          defer.reject(err);
        }else {
          defer.resolve(result);
        }
      });

      return defer.promise;
    }

    return self;
}

export default ['$q', EthereumService ];<commit_msg>you have to specify the account for each transaction<commit_after>/**
 * Main App Controller for the Angular Material Starter App
 * @param UsersDataService
 * @param $mdSidenav
 * @constructor
 */
function EthereumService($q) {

    var self = this;

    self.abi = [ { "constant": true, "inputs": [ { "name": "serial", "type": "string" } ], "name": "getCustomer", "outputs": [ { "name": "", "type": "address", "value": "0x0000000000000000000000000000000000000000" } ], "payable": false, "type": "function" }, { "constant": false, "inputs": [ { "name": "serial", "type": "string" }, { "name": "customer", "type": "address" }, { "name": "endDate", "type": "uint256" } ], "name": "requestWarranty", "outputs": [], "payable": false, "type": "function" }, { "constant": false, "inputs": [ { "name": "contractAddress", "type": "address" } ], "name": "updateCalculator", "outputs": [], "payable": false, "type": "function" }, { "constant": true, "inputs": [ { "name": "serial", "type": "string" } ], "name": "getEndDate", "outputs": [ { "name": "", "type": "uint256", "value": "0" } ], "payable": false, "type": "function" }, { "constant": true, "inputs": [ { "name": "serial", "type": "string" } ], "name": "isWarrantyValid", "outputs": [ { "name": "", "type": "bool", "value": true } ], "payable": false, "type": "function" }, { "inputs": [], "type": "constructor" } ];
    self.dappId = "epam.hackathon";

    self.contractAddress = "0xF65a613630e112cc2Fc0fB382770E3845b857105";
    self.walletBar = new WalletBar({
        containerName:'#signInId',
        dappNamespace: self.dappId,
        blockchain: "morden"
    });

    self.web3 = new Web3();
    self.WarrantyContract;
    self.waitForWallet = self.walletBar.applyHook(self.web3)
    .then(function() {
        self.WarrantyContract = self.web3.eth.contract(self.abi).at(self.contractAddress);
    })
    .catch(function(err) {
        console.log(err);
    });

    function prepareForTransaction() {
      var account = self.walletBar.getCurrentAccount(); // get account selected in wallet bar
      if (!account) return alert("You must log in to transact");
      self.walletBar.createSecureSigner();
      return account;
    }

    self.getInfo = function(serial) {
      return self.waitForWallet.then(function() {
       return $q.all({
          isWarrantyValid: self.isWarrantyValid(serial),
          customer: self.getCustomer(serial),
          warrantyEndDate: self.getWarrantyEndDate(serial)
        });
     });
    }

    self.isWarrantyValid = function(serial) {
      var defer = $q.defer();

      self.WarrantyContract.isWarrantyValid(serial, function(err, result){
        if(err) {
          defer.reject(err);
        }else {
          defer.resolve(result);
        }
      });

      return defer.promise;
    }

    self.getCustomer = function(serial) {
      var defer = $q.defer();

      self.WarrantyContract.getCustomer(serial, function(err, result){
        if(err) {
          defer.reject(err);
        }else {
          defer.resolve(result);
        }
      });

      return defer.promise;
    }

    self.getWarrantyEndDate = function(serial) {
      var defer = $q.defer();

      self.WarrantyContract.getWarrantyEndDate(serial, function(err, result){
        if(err) {
          defer.reject(err);
        }else {
          defer.resolve(result);
        }
      });

      return defer.promise;
    }

    self.requestWarranty = function(serial, owner, endDate) {
      var defer = $q.defer();
      var account = prepareForTransaction();
      self.WarrantyContract.requestWarranty(serial, owner, endDate.getTime(),{from:account}, function(err, result){
        if(err) {
          defer.reject(err);
        }else {
          defer.resolve(result);
        }
      });

      return defer.promise;
    }

    return self;
}

export default ['$q', EthereumService ];
{'fraction_non_alphanumeric': 0.17737411513289703, 'fraction_numerical': 0.021904634700146922, 'mean_word_length': 3.0, 'pattern_counts': {'":': 110, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2613140', 'n_tokens_mistral': 2555, 'n_tokens_neox': 2340, 'n_words': 474}