1

我正在运行 Meteor 应用程序并遇到一个我无法弄清楚的错误。我正在使用快速表单将文档插入集合中,其中一个字段是使用自动值从 web3 api 调用中获取的哈希地址。

//Schema with autovalue to obtain hash address via web3 call
CustomerSchema = new SimpleSchema({
  customerBlockchainAddress: {
    type: String,
    label: "Blockchain Address",
    autoValue: function() {
         var address = web3.personal.newAccount("password");
         console.log("Address: ", address);
         return address;
     },
     autoform: {
         type: "hidden"
     }
  },
//additional schema fields 

该方法由快速表单调用。见下文:

//HTML
<template name="NewCompany">
    <div class="new-document-container">


    {{#if isSuccessfulCompany }}
        <h3 class="success">Successfully registered company information. <br /> <br /> </h3>
    {{else}}
        <h3>Register Company Information:</h3><br />
        {{> quickForm collection="Companies" id="insertCompanyForm" type="method" meteormethod="insertCompany" class="new-Company-form"}}
    {{/ if}}

</div>

插入方法:

insertCustomer:function(customer){
    CustomerSchema.clean(customer, {
      extendAutoValueContext: {
        isInsert: true,
        isUpdate: false,
        isUpsert: false,
        isFromTrustedCode: false
      }
    });
    check(customer, CustomerSchema);
    if (! this.userId) {
        throw new Meteor.Error('not-authorized');
    }
    if(! Roles.userIsInRole(this.userId,'individual')){
        throw new Meteor.Error('not-authorized for your role');
    }
    //custom API that takes fields from the customer doc and stores    
    them on the blockchain
    Meteor.call('individualRegistration', customer, function (error,            
    result) {
             if (error) {
                 console.log("error", error);
             };
             console.log(result);
         });
    return Customers.insert(customer);
}

我得到的错误是:

Exception while invoking method 'insertCustomer' TypeError:       
XMLHttpRequest is not a function

使用日志语句,AutoValue 函数按预期从 web3 调用中获取新地址,但在引发错误之前,它使用不同的地址打印了四次。如果我只用一个字符串对地址进行硬编码,则插入函数可以使用自定义 API 按预期正常工作。

当 API 调用正常工作并插入到集合中并且该版本使用过时版本的 Meteor 和过时的包时,我回滚到我的应用程序的先前版本。调用“流星更新”后,调用停止工作并显示相同的错误。有人可以解释一下可能导致此错误的原因。

更新:我正确更新了 aldeed:autoform 并删除了 aldeed:simple-schema 并按照软件包自述文件中的指示安装了 NPM simpl-schema。错误仍然被抛出。

谢谢

4

0 回答 0