博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
FISCO BCOS Solidity 智能合约Compiler error:Stack too deep, try removing local variables 如何传递超过16个参数变量
阅读量:2037 次
发布时间:2019-04-28

本文共 2061 字,大约阅读时间需要 6 分钟。

一、原因:

stack 保存很小的局部变量,免费使用,但有数量限制(16个变量),包含参数和返回值(including parameters and return parameters)

 

二、解决方法:

1. 减少输入参数:

a. 以数组的方式传入

原来是

// 设置用户信息function set_user_info(string user_address, string name, string age) public returns(int) {    TableFactory tf = TableFactory(0x1001);    Table table = tf.openTable("user");    Entry entry = table.newEntry();    entry.set("user_address", user_address);    entry.set("name", name);    entry.set("age", age);    int count = table.insert(name, entry);}

可修改为

// 设置用户信息// user_info是一个数组,如["xxxxx", "张三", "20"]function set_user_info(string[] user_info) public returns(int) {    TableFactory tf = TableFactory(0x1001);    Table table = tf.openTable("user");    Entry entry = table.newEntry();    entry.set("user_address", user_info[0]);    entry.set("name", user_info[1]);    entry.set("age", user_info[2]);    int count = table.insert(user_info[0], entry);}

这种方法比较适合传入一组数据

b. 可拆成两个小函数

// 设置用户信息-姓名function set_user_info_name(string user_address, string name) public returns(int) {    TableFactory tf = TableFactory(0x1001);    Table table = tf.openTable("user");    Entry entry = table.newEntry();    entry.set("user_address", user_address);    entry.set("name", name);    int count = table.insert(user_address, entry);    return count;}// 设置用户信息-年龄function set_user_info_age(string user_address, string age) public returns(int) {    TableFactory tf = TableFactory(0x1001);    Table table = tf.openTable("user");    Entry entry = table.newEntry();    entry.set("age", age);    Condition condition = table.newCondition();    condition.EQ("user_address", user_address);                      int count = table.update(user_address, entry, condition);    return count;}

这种方法比较适合传入多组数据

 

2. 减少返回参数:

a. 以数组的形式返回

原来

// 得到用户信息function get_user_info(string user_address) public returns(string name, string age) {    // xxxx    return (name, age);}

可改为

// 得到用户信息function get_user_info(string user_address) public returns(string[] user_info) {    // xxxx    user_info['name'] = '张三';    user_info['age'] = 20;    return user_info;}

 

 

3. 将参数拼接成字符串

 

 

 

 

转载地址:http://mvkof.baihongyu.com/

你可能感兴趣的文章
Netty 源码分析之 三 我就是大名鼎鼎的 EventLoop(一)
查看>>
导入一个maven工程后一直显示importing maven projects
查看>>
eclipse 把当前git目录中项目关联上git
查看>>
Eclipse中用git解决冲突----避免每次重新拉代码
查看>>
Springboot 之 自定义配置文件及读取配置文件
查看>>
服务器端判断request来自Ajax请求(异步)还是传统请求(同步)
查看>>
git adding files to index has encountered a problem
查看>>
git学习六:git提交忽略不必要的文件或文件夹
查看>>
springcloud(三):服务提供与调用
查看>>
Memcached 和 Redis 分布式锁方案
查看>>
乐视秒杀:每秒十万笔交易的数据架构解读
查看>>
如何解决秒杀的性能问题和超卖的讨论
查看>>
centos 卸载软件
查看>>
Linux下MySQL备份以及crontab定时备份(crontab表达式简介)
查看>>
powerdesigner: used normalization rules prevent from reusing this data item in a primary
查看>>
PowerDesigner最基础的使用方法入门学习
查看>>
eclipse maven 查找重复依赖
查看>>
MySQL数据表生成ER图 workbench使用
查看>>
创建Maven web项目时 出现 web.xml is missing and <failOnMissingWebXml> is set to true错误 pox.xml编译错误
查看>>
Maven几个常用的maven插件
查看>>