在以太坊中编译Solidity代码时出现断言错误

时间:2018-11-15 19:50:45

标签: compilation ethereum solidity

H:\ Ethereum \ Kickstarter \ ethereum>节点compile.js H:\ Ethereum \ Kickstarter \ node_modules \ solc \ soljson.js:1 (函数(导出,需求,模块,__ filename,__ dirname){var Module; if(!Module)Module =(typeof Module!==“ undefined”?Module:null)|| {}; var moduleOverrides = {};用于(模块中的var键){if(Module.hasOwnProperty(key)){moduleOverrides [key] = Module [key]}} var ENVIRONMENT_IS_WEB = typeof window ===“ =” object“; var ENVIRONMENT_IS_WORKER = typeof importScripts ===” function “; var ENVIRONMENT_IS_NODE =进程的类型===” =“对象” && typeof require ===“功能” &&! ])Module [“ print”] = function print(x){process [“ stdout”]。write(x +“ \ n”)}; if(!Module [“ printErr”])Module [“ printErr”] = function printErr(x){process [“ stderr”]。write(x +“ \ n”)}; var nodeFS = require(“ fs”); var nodePath = require(“ path”); Module [“ read”] = function read(filename,binary){filename = nodePath“ normalize”; var ret = nodeFS“ readFileSync”; if(!ret

AssertionError [ERR_ASSERTION]:指定了无效的回调。     在wrapCallback(H:\ Ethereum \ Kickstarter \ node_modules \ solc \ wrapper.js:16:5)     在runWithReadCallback(H:\ Ethereum \ Kickstarter \ node_modules \ solc \ wrapper.js:37:42)     在compileStandard(H:\ Ethereum \ Kickstarter \ node_modules \ solc \ wrapper.js:78:14)     在Object.compileStandardWrapper(H:\ Ethereum \ Kickstarter \ node_modules \ solc \ wrapper.js:85:14)     在对象。 (H:\ Ethereum \ Kickstarter \ ethereum \ compile.js:19:21)     在Module._compile(module.js:652:30)     在Object.Module._extensions..js(module.js:663:10)     在Module.load(module.js:565:32)     在tryModuleLoad(module.js:505:12)     在Function.Module._load(module.js:497:3)

2 个答案:

答案 0 :(得分:2)

以下内容将获得Solidity Compiler的最新稳定版本:

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sonal.mindwerx.Functions.Functions;
import com.sonal.mindwerx.Item.SearchModel;
import com.sonal.mindwerx.R;
import com.sonal.mindwerx.SearchDisplay;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;


public class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.MyViewHolder> implements Filterable {
    ArrayList<SearchModel> filterList;
    private List<SearchModel> searchlist;
    private Context context;
    String mSearchText = "";

    public class MyViewHolder extends RecyclerView.ViewHolder {


        public TextView tv_name_search, tv_code_search;
        public LinearLayout ll_search_item;

        public MyViewHolder(View view) {
            super(view);

            tv_name_search = (TextView) view.findViewById(R.id.tv_name_search);
            tv_code_search = (TextView) view.findViewById(R.id.tv_code_search);
            ll_search_item = (LinearLayout) view.findViewById(R.id.ll_search_item);

        }
    }


    public SearchAdapter(Context context, ArrayList<SearchModel> searchlist) {
        this.context = context;
        this.searchlist = searchlist;
        this.filterList = searchlist;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.search_item, parent, false);
        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position) {
        final SearchModel searchModel = searchlist.get(position);
        holder.tv_name_search.setText(searchModel.getName());
        holder.tv_code_search.setText(searchModel.getCode());

        holder.ll_search_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, SearchDisplay.class);
                intent.putExtra("sonalcode", searchModel.getCode());
                String rate = searchModel.getRate();
                intent.putExtra("rate", searchModel.getRate());
                intent.putExtra("productid", searchModel.getProductid());
                intent.putExtra("brandid", searchModel.getBrandid());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return searchlist.size();
    }

    CustomFilter filter;


    @Override
    public Filter getFilter() {
        if (filter == null) {
            filter = new CustomFilter();
        }
        return filter;
    }


    class CustomFilter extends Filter {
        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            // TODO Auto-generated method stub
            FilterResults results = new FilterResults();
            if (constraint != null && constraint.length() > 0) {
                //CONSTARINT TO UPPER
                constraint = constraint.toString().toLowerCase();

                ArrayList<SearchModel> filters = new ArrayList<SearchModel>();
                String[] separated = constraint.toString().toLowerCase().split(" ");
                //get specific items
                for (int i = 0; i < filterList.size(); i++) {
                    for (int j = 0; j < separated.length; j++) {

                        if (filterList.get(i).getName().toLowerCase().contains(separated[j]) || filterList.get(i).getCode().toLowerCase().contains(separated[j])) {
                            SearchModel p = new SearchModel(filterList.get(i).getBrandid(), filterList.get(i).getProductid(), filterList.get(i).getRate(), filterList.get(i).getImage(), filterList.get(i).getName(), filterList.get(i).getCode());
                            filters.add(p);
                            break;
                        }
                    }
                }
                results.count = filters.size();
                results.values = filters;
            } else {
                results.count = filterList.size();
                results.values = filterList;
            }

            return results;
        }

        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {
            // TODO Auto-generated method stub
            searchlist = (ArrayList<SearchModel>) results.values;
            notifyDataSetChanged();
        }
    }


} 

对我来说,这个版本有问题。我使用以下命令将 solc 降级为较旧的版本(删除了当前安装的版本之后)。

    npm install --save solc

此问题已解决。此外,我将 contracts 目录中的智能合约的第一行更改为:

    npm install --save solc@0.4.17

答案 1 :(得分:0)

按照Divyanshu的建议运行以下命令

npm install --save solc@0.4.17

并确认合同的第一行是

pragma solidity ^ 0.4.17;