最开始引入:

pragma experimental ABIEncoderV2;
pragma solidity ^0.4.25;
pragma experimental ABIEncoderV2;// import "./Table.sol";contract StudentScoreByCRUD{address private _owner;modifier onlyOwner{require(_owner == msg.sender, "Auth: only owner is authorized");_;}constructor () public {_owner = msg.sender;}event createEvent(address owner, string tableName);event insertEvent(address studentId, string courseName, int score);event updateEvent(address studentId, string courseName, int score);event removeEvent(address studentId, string courseName);// 创建成绩表function create() public onlyOwner returns(int){TableFactory tf = TableFactory(0x1001);int count = tf.createTable("stu_score", "student_id", "course_name, score");emit createEvent(msg.sender, "stu_score");return count;}// 插入成绩操作function insert(address studentId, string courseName, int score) public onlyOwner returns(int){TableFactory tf = TableFactory(0x1001);Table table = tf.openTable("stu_score");string memory stuIdStr = addressToString(studentId);Entry entry = table.newEntry();entry.set("student_id", stuIdStr);entry.set("course_name", courseName);entry.set("score", score);int count = table.insert(stuIdStr, entry);emit insertEvent(studentId, courseName, score);return count;}function addressToString(address addr) private pure returns(string) {// Convert addr to bytesbytes20 value = bytes20(uint160(addr));bytes memory strBytes = new bytes(42);// Encode hex prefixstrBytes[0] = '0';strBytes[1] = 'x';// Encode bytes usig hex encodingfor(uint i = 0; i < 20; i++){uint8 byteValue = uint8(value[i]);strBytes[2 + (i<<1)] = encode(byteValue >> 4);strBytes[3 + (i<<1)] = encode(byteValue & 0x0f);}return string(strBytes);}function encode(uint8 num) private pure returns(byte){// 0-9 -> 0-9if(num >= 0 && num <= 9){return byte(num + 48);}// 10-15 -> a-freturn byte(num + 87);}// 更新成绩操作function update(address studentId, string courseName, int newScore) public onlyOwner returns(int){TableFactory tf = TableFactory(0x1001);Table table = tf.openTable("stu_score");Entry entry = table.newEntry();entry.set("score", newScore);string memory stuIdStr = addressToString(studentId);Condition condition = table.newCondition();condition.EQ("student_id", stuIdStr);condition.EQ("course_name", courseName);int count = table.update(stuIdStr, entry, condition);emit updateEvent(studentId, courseName, newScore);return count;}// 删除成绩操作function remove(address studentId, string courseName) public onlyOwner returns(int){TableFactory tf = TableFactory(0x1001);Table table = tf.openTable("stu_score");string memory stuIdStr = addressToString(studentId);Condition condition = table.newCondition();condition.EQ("student_id", stuIdStr);condition.EQ("course_name", courseName);int count = table.remove(stuIdStr, condition);emit removeEvent(studentId, courseName);return count;}// 查询成绩操作function select(address studentId, string courseName) public view returns(int, string){TableFactory tf = TableFactory(0x1001);Table table = tf.openTable("stu_score");string memory stuIdStr = addressToString(studentId);Condition condition = table.newCondition();condition.EQ("student_id", stuIdStr);condition.EQ("course_name", courseName);Entries entries = table.select(stuIdStr, condition);if(entries.size() == 0){return (0, stuIdStr);}else{return (entries.get(0).getInt("score"), stuIdStr);}}// 查询某个学生的某课成绩所有成绩function select_all_scores(address studentId, string courseName) public view returns(int[]){TableFactory tf = TableFactory(0x1001);Table table = tf.openTable("stu_score");string memory stuIdStr = addressToString(studentId);Condition condition = table.newCondition();condition.EQ("student_id", stuIdStr);condition.EQ("course_name", courseName);Entries entries = table.select(stuIdStr, condition);// 初始化数组大小int[] memory user_scores_list = new int[](uint256(entries.size()));// 给数组赋值for(int i=0; i<entries.size(); ++i) {Entry entry = entries.get(i);// 添加数组元素user_scores_list[uint256(i)] = entry.getInt("score");}return user_scores_list;}// 查询某个学生的所有成绩function select_scores_info(address studentId) public view returns(string[], int[]){TableFactory tf = TableFactory(0x1001);Table table = tf.openTable("stu_score");string memory stuIdStr = addressToString(studentId);Condition condition = table.newCondition();condition.EQ("student_id", stuIdStr);Entries entries = table.select(stuIdStr, condition);// 初始化数组大小string[] memory user_courses_list = new string[](uint256(entries.size()));int[] memory user_scores_list = new int[](uint256(entries.size()));// 给数组赋值for(int i=0; i<entries.size(); ++i) {Entry entry = entries.get(i);// 添加数组元素user_courses_list[uint256(i)] = entry.getString("course_name");user_scores_list[uint256(i)] = entry.getInt("score");}return (user_courses_list, user_scores_list);}}// table.sol,因为在webase-front的IDE中无法直接引用,所以将源码放到代码文件中contract TableFactory {function openTable(string memory) public view returns (Table) {} //open tablefunction createTable(string memory, string memory, string memory) public returns (int256) {} //create table}//select conditioncontract Condition {function EQ(string memory, int256) public {}function EQ(string memory, string memory) public {}function NE(string memory, int256) public {}function NE(string memory, string memory) public {}function GT(string memory, int256) public {}function GE(string memory, int256) public {}function LT(string memory, int256) public {}function LE(string memory, int256) public {}function limit(int256) public {}function limit(int256, int256) public {}}//one recordcontract Entry {function getInt(string memory) public view returns (int256) {}function getUInt(string memory) public view returns (int256) {}function getAddress(string memory) public view returns (address) {}function getBytes64(string memory) public view returns (bytes1[64] memory) {}function getBytes32(string memory) public view returns (bytes32) {}function getString(string memory) public view returns (string memory) {}function set(string memory, int256) public {}function set(string memory, uint256) public {}function set(string memory, string memory) public {}function set(string memory, address) public {}}//record setscontract Entries {function get(int256) public view returns (Entry) {}function size() public view returns (int256) {}}//Table main contractcontract Table {function select(string memory, Condition) public view returns (Entries) {}function insert(string memory, Entry) public returns (int256) {}function update(string memory, Entry, Condition) public returns (int256) {}function remove(string memory, Condition) public returns (int256) {}function newEntry() public view returns (Entry) {}function newCondition() public view returns (Condition) {}}contract KVTableFactory {function openTable(string memory) public view returns (KVTable) {}function createTable(string memory, string memory, string memory) public returns (int256) {}}//KVTable per permiary key has only one Entrycontract KVTable {function get(string memory) public view returns (bool, Entry) {}function set(string memory, Entry) public returns (int256) {}function newEntry() public view returns (Entry) {}}

参考:https://ethereum.stackexchange.com/questions/69077/how-can-i-return-dynamic-string-array-in-solidity

FISCO BCOS Solidity 智能合约 return string[] This type is only supported in the new experimental ABI相关推荐

  1. Solidity智能合约库:区块链工程师的随身工具箱

    编者荐语: Solidity使用起来不如其他语言那般丝滑顺畅?安全事故难以避免?社区迎来适用于FISCO BCOS的Solidity智能合约库,轻松破解合约的各种小难题,让合约开发更加快速高效.省时省 ...

  2. 微众银行Solidity智能合约库:区块链工程师的随身工具箱

    区块链技术在经历了十余年的发展后,渐呈"燎原之势",不断在各行业落地生根.但同时,从技术的角度看,区块链应用开发仍然有着较高的门槛,存在不少痛点.为了提升应用开发各环节的用户体验, ...

  3. 基于以太坊的次高价盲拍solidity智能合约(二)

    基于以太坊的次高价盲拍solidity智能合约(二) 4.揭标 5.第三方仲裁人终结拍卖 4.揭标 揭标的过程应该是本智能合约中最复杂且具有灵魂的关键步骤. 当每个发起过竞标的用户,利用该标的隐式价格 ...

  4. 微众银行《Solidity智能合约库》区块链工程师的随身工具箱之初体验相当的nice

    文章目录 一.智能合约库简介 二.痛点及解决方式 痛点一:计算可能溢出 痛点二:转换不够便捷 痛点三:数组操作不够丰富 痛点四:不提供字符串内置操作 痛点五:高级数据结构不完备 总结 一.智能合约库简 ...

  5. 蚂蚁区块链第12课 如何使用命令行编译工具solcjs编译Solidity智能合约?

    1,摘要 蚂蚁区块链合约平台支持 Solidity 智能合约,针对合约源代码的编译,可以直接通过蚂蚁区块链 Cloud IDE 合约开发环境进行合约编译.部署.测试和调试. 本文介绍由蚂蚁区块链平台提 ...

  6. 以太坊solidity智能合约-生成随机数

    Solidity随机数生成 在以太坊的只能合约中,没有提供像其他面向对象编程一样的生成随机数的工具类或方法.其实,所谓的随机数也是伪随机的,没有哪一种语言能够真正的生成随机数. 对于solidity来 ...

  7. Solidity 智能合约入门

    Solidity 智能合约入门 存储合约示例 将一个数据放置在链上 // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.4.16 &l ...

  8. 【区块链实战】Solidity 智能合约如何给账户充值

    目录 一.实战场景 二.知识点 智能合约 智能合约函数 智能合约充值 payable 关键字 智能合约部署地址 智能合约的运行 合约 this 对象 三.菜鸟实战 四.运行结果 一.实战场景 Soli ...

  9. solidity智能合约implicit conversion异常

    问题场景 在使用^0.5.10版本的solidity时,如果使用this关键字会出现以下问题. 代码: require(tokenContract.balanceOf(this) >= _num ...

  10. solidity智能合约中tx.origin的正确使用场景

    简介 tx.origin是Solidity的一个全局变量,它遍历整个调用栈并返回最初发送调用(或事务)的帐户的地址.在智能合约中使用此变量进行身份验证会使合约容易受到类似网络钓鱼的攻击. 但针对tx. ...

最新文章

  1. 岳阳机器人餐厅在哪_从机器人咖啡看未来餐饮行业大方向,如何才能活下去?...
  2. redis 的一主二从三哨兵模式
  3. 清除BSS段的一般做法
  4. chime-4 lstm_CHIME-6挑战赛回顾
  5. LOJ洛谷P1248加工生产调度(贪心、Johnson 法则)
  6. yii2的Console定时任务创建
  7. 13种重要的云原生工具,让交付过程更快
  8. java list stream avg_Java 8 Stream API中的多个聚合函数
  9. 《火星人敏捷开发手册》 2011-08-18版本发布
  10. java如何代码找错误_如何编写可怕的Java代码?
  11. C#进行MapX二次开发之地图搜索
  12. JSP程序设计 第2版 pdf
  13. 浅谈博客、微博与轻博客的区别与联系
  14. 开wifi微信定位服务器,企业微信wifi定位
  15. 最强的右键菜单工具:超级右键专业版 mac中文版
  16. 【日记本砸】21.02.01-12 过程只是过程,目的才是目的。
  17. 数据库事务(Transaction)详解
  18. 计算机网络题库与答案西电,西电计算机网络期末试题.doc
  19. 【推理引擎】ONNXRuntime 的架构设计
  20. kali PIN码破解

热门文章

  1. TextView属性android:ellipsize实现跑马灯效果
  2. 通过SQL Server命令行启动及停止SQL服务的方法
  3. 开启WIN 7下的administrator用户的方法(VISTA一样)
  4. [NOI2003]Editor [AHOI2006]文本编辑器editor BZOJ1507BZOJ1269
  5. 代码片段:基于 JDK 8 time包的时间工具类 TimeUtil
  6. python 重新执行循环中出错的那一次
  7. javascript对数组的操作
  8. c++ pair类型的基本问题
  9. 拓端tecdat|R语言最优化问题中的共轭函数
  10. 拓端tecdat|R语言广义线性模型GLM、多项式回归和广义可加模型GAM预测泰坦尼克号幸存者