智能合约开发与测试1

news2024/9/20 14:38:09

智能合约开发与测试

任务一:智能合约设计

(1)编写新能源智能合约功能需求文档。

区块链新能源管理智能合约功能需求包括资产与能源绑定、用户管理、能源交易、智能结算等,确保安全性、隐私保护和可扩展性,提高能源利用效率,促进能源流转,实现自动化交易与透明管理。

(2)完成区块链新能源管理智能合约的设计。

  1. 设计区块链新能源管理智能合约接口,画出区块链新能源管理智能合约的角色UML用例图;

  2. 以图文结合的方式描述智能合约各参与实体间的关系。

任务二:智能合约开发

(1)太阳能板管理接口编码

  1. 根据文档要求,编写太阳能板新增接口功能,必须将新增太阳能板数据存入指定表中,在存储完成后需触发后事件并返回存储与否的标识;

  2. 根据文档要求,编写太阳能板修改接口,必须通过指定表修改完成数据更新,在完成更新后需触发事件并返回更新与否的标识。

    编写SolarPanelsStorage.sol

    /**
     * 太阳能板详情存储器,记录太阳能板的详细信息
     */
    pragma solidity ^0.4.25;
    pragma experimental ABIEncoderV2;
    
    import "./Table.sol";
    import "./LibString.sol";
    import "./Ownable.sol";
    import "./MapStorage.sol";
    
    contract SolarPanelsStorage is Ownable {
    
        using LibString for string;
    
        MapStorage private mapStorage;
    
        event InsertResult(int256);
        event UpdateResult(int256);
    
        TableFactory tf;
        string constant TABLE_NAME = "sp_goods";
    
        string constant TABLE_NAME2 = "_interface";
        
        string constant TABLE_NAME3 = "spu_order";
    
        /**
        * 创建太能能电池板实体
        * +---------------------------+----------------+-----------------------------------------+
        * | Field                     |     Type       |      Desc                               |
        * +---------------------------+----------------+-----------------------------------------+
        * | num_id                    | string                 | 编号
        * | sp_name                   | string                 | 太阳能板名称
        * | sp_actual_Power           | string                 | 实际功率(单位:W)
        * | sp_rated_Power            | string                 | 额定功率(单位:W)
        * | sp_input_Time             | string                 | 生效时间(单位:h)
        * | sp_position               | string                 | 投放位置
        * | sp_price                  | string                 | 单价 (单位:元)
        * | Owner_ship                | string                 | 所属权(address)
        * +---------------------------+----------------+-----------------------------------------+
        */
        constructor() public {
            tf = TableFactory(0x1001);
            tf.createTable(TABLE_NAME, "num_id", "sp_name,sp_actual_Power,sp_rated_Power,sp_input_Time,sp_position,sp_price,Owner_ship");
            tf.createTable(TABLE_NAME2, "Owner_ship", "num_id,sp_name,sp_actual_Power,sp_rated_Power,sp_input_Time,sp_position,sp_price");
            tf.createTable(TABLE_NAME3, "Owner_ship", "data,from,to,num_id");
            mapStorage = new MapStorage();
        }
    //TABLE_NAME(表1)
        /**
        * "85414020.00,太阳能电池,150W,205W,20h,China,5000RMB,test"
        * 插入数据
        */
        function insert(string memory _numid, string memory name,
        string memory actual_Power,string memory rated_Power,string memory input_Time,
        string memory position,string memory price,string Ownership) public onlyOwner returns(int) {
            // Goods memory _goods = convertGoods(_goodsStr);
            Table table = tf.openTable(TABLE_NAME);
            Entry entry = table.newEntry();
            // convertEntry(_goods, entry);
            entry.set("num_id",_numid);
            entry.set("sp_name",name);
            entry.set("sp_actual_Power",actual_Power);
            entry.set("sp_rated_Power",rated_Power);
            entry.set("sp_input_Time",input_Time);
            entry.set("sp_position",position);
            entry.set("sp_price",price);
            entry.set("Owner_ship",Ownership);
            int256 count = table.insert(_numid, entry);
            emit InsertResult(count);
            return count;
        }
    
        /**
        *  "1,太阳能电池,150W,205W,20h,China,1000RMB,test"
        * 更新数据
        */
        function update(string memory _numid, string memory _goodsStr) public onlyOwner returns(int256) {
            Goods memory _goods = convertGoods(_goodsStr);
            Table table = tf.openTable(TABLE_NAME);
            require(_isnumidExist(table, _goods.numid), "update: current numid not exist");
            Entry entry = table.newEntry();
            convertEntry(_goods, entry);
            Condition condition = table.newCondition();
            int256 count = table.update(_numid, entry, condition);
            emit UpdateResult(count);
            return count;
        }
    
        /**
        *  85414020.00
        *  test3
        *  更改所属权
        */
        function transfer(string memory _numid, string memory Ownership) public returns(int256) {
            
            Table table = tf.openTable(TABLE_NAME);
            // require(_isnumidExist(table, _numid), "update: current numid not exist");
            
            Entry entry = table.newEntry();
            entry.set("sp_price", "已出售");
            entry.set("Owner_ship", Ownership);
            
            Condition condition = table.newCondition();
            int256 count = table.update(_numid, entry, condition);
            emit UpdateResult(count);
            return count;
        }
        
        /**
        *  85414020.00
        *  test3
        *  更改单价
        */
        function saller(string memory _numid, string memory _price) public returns(int256) {
            int code = 0;
            
            Table table = tf.openTable(TABLE_NAME);
            require(_isnumidExist(table, _numid), "0");
            
            Entry entry = table.newEntry();
            entry.set("sp_price", _price);
            
            Condition condition = table.newCondition();
            int256 count = table.update(_numid, entry, condition);
            if(count != 1) {
                // 失败? 无权限或者其他错误?
                code = 0;
                return code;
            }
            emit UpdateResult(count);
            return count;
        }    
        
        /**
        * 通过numid查询数据
        */
        
        function getDetail(string memory _num_id) public view returns(string[] memory){
            Table table = tf.openTable(TABLE_NAME);
            Condition condition = table.newCondition();
            Entries entries = table.select(_num_id, condition);
            
            string[] memory value_list = new string[](uint256(entries.size()));
            
            for (int256 i = 0; i < entries.size(); ++i) {
                Entry entry = entries.get(i);
                value_list[uint256(i)] = _returnData(entry);
                
            }
            return value_list;
        }
    
        
        function convertGoods(string memory _str) private returns(Goods){
            string[] memory ss = _str.split(",");
            return Goods(ss[0],ss[1],ss[2],ss[3],ss[4],ss[5],ss[6],ss[7]);
        }
    
        function convertEntry(Goods memory _goods, Entry entry) private {
            entry.set("num_id",_goods.numid);
            entry.set("sp_name",_goods.name);
            entry.set("sp_actual_Power",_goods.actual_Power);
            entry.set("sp_rated_Power",_goods.rated_Power);
            entry.set("sp_input_Time",_goods.input_Time);
            entry.set("sp_position",_goods.position);
            entry.set("sp_price",_goods.price);
            entry.set("Owner_ship",_goods.Ownership);
            
        }
    
        function _isnumidExist(Table _table, string memory _id) internal view returns(bool) {
            Condition condition = _table.newCondition();
            return _table.select(_id, condition).size() != int(0);
        }
    
        //拼接成json数据
        function _returnData(Entry _entry) internal view returns(string){
    
            string memory _json = "{";
    
            _json = _json.concat("'numid':'");
            _json = _json.concat(_entry.getString("num_id"));
            _json = _json.concat("',");
    
            _json = _json.concat("'name':'");
            _json = _json.concat(_entry.getString("sp_name"));
            _json = _json.concat("',");
    
            _json = _json.concat("'actual_Power':'");
            _json = _json.concat(_entry.getString("sp_actual_Power"));
            _json = _json.concat("',");
    
            _json = _json.concat("'rated_Power':'");
            _json = _json.concat(_entry.getString("sp_rated_Power"));
            _json = _json.concat("',");
    
            _json = _json.concat("'input_Time':'");
            _json = _json.concat(_entry.getString("sp_input_Time"));
            _json = _json.concat("',");
    
            _json = _json.concat("'position':'");
            _json = _json.concat(_entry.getString("sp_position"));
            _json = _json.concat("',");
    
            _json = _json.concat("'price':'");
            _json = _json.concat(_entry.getString("sp_price"));
            _json = _json.concat("',");
    
            _json = _json.concat("'Ownership':'");
            _json = _json.concat(_entry.getString("Owner_ship"));
            _json = _json.concat("'");
    
    
            _json = _json.concat("}");
    
            return _json;
        }
    
        struct Goods {
            string numid; //编号
            string name; //太阳能板名称
            string actual_Power; //实际功率(单位:W)
            string rated_Power; //额定功率(单位:W)
            string input_Time; //生效时间(单位:h)
            string position; //投放位置
            string price; //单价 (单位:元)
            string Ownership; //所属权(address)
        }
    
        /**
        * 插入数据,已有数据不添加
        */
        function insert2(string memory Owner_ship, string memory numid, string memory name,
        string memory actual_Power,string memory rated_Power,string memory input_Time,
        string memory position,string memory price) public onlyOwner returns(int) {
            // Assert memory _assert = convertAssert2(_value);
            Table table = tf.openTable(TABLE_NAME2);
            Entry entry = table.newEntry();
            // convertEntry2(_assert, entry);
            entry.set("num_id",numid);
            entry.set("sp_name",name);
            entry.set("sp_actual_Power",actual_Power);
            entry.set("sp_rated_Power",rated_Power);
            entry.set("sp_input_Time",input_Time);
            entry.set("sp_position",position);
            entry.set("sp_price",price);
            entry.set("Owner_ship",Owner_ship);
            int count = table.insert(Owner_ship, entry);
            return count;
        }
        
        /**
        * 通过key获取value,可以存在多个value
        */
        function select2(string memory _key) public view returns(string[] memory){
            Table table = tf.openTable(TABLE_NAME2);
            Condition condition = table.newCondition();
            Entries entries = table.select(_key, condition);
            string[] memory value_list = new string[](uint256(entries.size()));
            for (int256 i = 0; i < entries.size(); ++i) {
                Entry entry = entries.get(i);
                value_list[uint256(i)] = _returnData2(entry);
                
            }
            return value_list;
        }
    
        // function saller2(string memory Owner_ship, string memory _price) public returns(int256) {
        //     int code = 0;
        //     Table table = tf.openTable(TABLE_NAME2);
        //     Entry entry = table.newEntry();
        //     entry.set("sp_price", _price);
        //     Condition condition = table.newCondition();
        //     int256 count = table.update(Owner_ship, entry, condition);
        //     if(count != 1) {
        //         // 失败? 无权限或者其他错误?
        //         code = 0;
        //         return code;
        //     }
        //     emit UpdateResult(count);
        //     return count;
        // }  
        
        
        function convertAssert2(string memory _str) private returns(Assert){
            string[] memory ss = _str.split(",");
            return Assert(ss[0],ss[1],ss[2],ss[3],ss[4],ss[5],ss[6],ss[7]);
        }
    
        function convertEntry2(Assert memory _assert, Entry entry) private {
            entry.set("num_id",_assert.numid);
            entry.set("sp_name",_assert.name);
            entry.set("sp_actual_Power",_assert.actual_Power);
            entry.set("sp_rated_Power",_assert.rated_Power);
            entry.set("sp_input_Time",_assert.input_Time);
            entry.set("sp_position",_assert.position);
            entry.set("sp_price",_assert.price);
            entry.set("Owner_ship",_assert.Ownership);
    
        }
    
        //拼接成json数据
        function _returnData2(Entry _entry) internal view returns(string){
    
            string memory _json = "{";
            
            _json = _json.concat("numid:'");
            _json = _json.concat(_entry.getString("num_id"));
            _json = _json.concat("',");
    
            _json = _json.concat("name:'");
            _json = _json.concat(_entry.getString("sp_name"));
            _json = _json.concat("',");
    
            _json = _json.concat("actual_Power:'");
            _json = _json.concat(_entry.getString("sp_actual_Power"));
            _json = _json.concat("',");
    
            _json = _json.concat("rated_Power:'");
            _json = _json.concat(_entry.getString("sp_rated_Power"));
            _json = _json.concat("',");
    
            _json = _json.concat("input_Time:'");
            _json = _json.concat(_entry.getString("sp_input_Time"));
            _json = _json.concat("',");
    
            _json = _json.concat("position:'");
            _json = _json.concat(_entry.getString("sp_position"));
            _json = _json.concat("',");
    
            _json = _json.concat("price:'");
            _json = _json.concat(_entry.getString("sp_price"));
            _json = _json.concat("',");
            
            _json = _json.concat("Ownership:'");
            _json = _json.concat(_entry.getString("Owner_ship"));
            _json = _json.concat("'");
    
            _json = _json.concat("}");
    
            return _json;
        }
        
        struct Assert {
            string numid; //编号
            string name; //太阳能板名称
            string actual_Power; //实际功率(单位:W)
            string rated_Power; //额定功率(单位:W)
            string input_Time; //生效时间(单位:h)
            string position; //投放位置
            string price; //单价 (单位:元)
            string Ownership; //所属权(address)
        }
    
    
    
    
        function insertorder(string memory Owner_ship,string memory _from,string memory _to,string memory _numid) 
        public returns(int) {
            Table table = tf.openTable(TABLE_NAME3);
            Entry entry = table.newEntry();
            entry.set("from", _from);
            entry.set("to",_to);
            entry.set("num_id",_numid);
            
            int count = table.insert(Owner_ship, entry);
            return count;
        }
    
        function selectorder(string memory Owner_ship) public view returns(string[] memory){
            Table table = tf.openTable(TABLE_NAME3);
            Condition condition = table.newCondition();
            Entries entries = table.select(Owner_ship, condition);
            string[] memory value_list = new string[](uint256(entries.size()));
            for (int256 i = 0; i < entries.size(); ++i) {
                Entry entry = entries.get(i);
                value_list[uint256(i)] = _returnData3(entry);
                
            }
            return value_list;
        }
        
        function uint2str(uint i) internal returns (string c) {
            if (i == 0) return "0";
            uint j = i;
            uint length;
            while (j != 0){
                length++;
                j /= 10;
            }
            bytes memory bstr = new bytes(length);
            uint k = length - 1;
            while (i != 0){
                bstr[k--] = byte(48 + i % 10);
                i /= 10;
            }
            c = string(bstr);
        }
        
        function getDate() public view returns(string) {
            uint time = uint(now);
            return uint2str(time);
        }
        
        function _returnData3(Entry _entry) internal view returns(string){
            
            string memory _json = "{";
    
            _json = _json.concat("data:'");
            _json = _json.concat(getDate());
            _json = _json.concat("',");
    
            _json = _json.concat("from:'");
            _json = _json.concat(_entry.getString("from"));
            _json = _json.concat("',");
    
            _json = _json.concat("to:'");
            _json = _json.concat(_entry.getString("to"));
            _json = _json.concat("',");
            
            _json = _json.concat("num_id:'");
            _json = _json.concat(_entry.getString("num_id"));
            _json = _json.concat("'");
    
            _json = _json.concat("}");
    
            return _json;
        }
        
        // function getDetail(string memory _num_id) public view returns(string memory _json){
        //     Entry entry = select(_num_id);
        //     _json = _returnData(entry);
        // }
        
    
        // /**
        // *  通过numid获取实体
        // */
        // function select(string memory _numid) private view returns(Entry _entry){
        //     Table table = tf.openTable(TABLE_NAME);
        //     require(_isnumidExist(table, _numid), "select: current numid not exist");
    
        //     Condition condition = table.newCondition();
        //     _entry = table.select(_numid, condition).get(int(0));
        // }
        
        // function select2( string memory id) public view returns(string[] memory){
        //     Table table =tf.openTable(TABLE_NAME);
        //     // require(_isnumidExist(table, _numid), "select: current numid not exist");
            
        //     Condition condition = table.newCondition();
        //     // condition.limit(2);
        //     // condition.EQ("Owner_ship", _Owner_ship);
            
        //     Entries entries = table.select(id, condition);
        //     string[] memory list = new string[](uint256(entries.size()));
            
        //     for(int i = 0; i < entries.size(); ++i){
        //       Entry entry = entries.get(i);
               
        //       list[uint256(i)] = entry.getString("Owner_ship");
        //     }        
        //     return list;
        //     // _entry = table.select(_numid, condition).get(int(7));
        // }
        
        // function SelectOwnership(string memory _Owner_ship) public view returns(string, string){
        //     Table table = tf.openTable(TABLE_NAME);
        //     Condition condition = table.newCondition();
        //     Entries entries = table.select(_Owner_ship, condition);
        //     for(int i = 0; i < entries.size(); ++i){
        //       return select2(i);
        //     }
            
        // }
        
        // function select3(string memory _numid) public view returns (string[] memory,string[] memory,string[] memory,
        // string[] memory,string[] memory,string[] memory,string[] memory,string[] memory)
        // {
        //     Table table = tf.openTable(TABLE_NAME);
    
        //     Condition condition = table.newCondition();
    
        //     Entries entries = table.select(_numid, condition);
        //     string[] memory a = new string[](uint256(entries.size()));
        //     string[] memory b = new string[](uint256(entries.size()));
        //     string[] memory c = new string[](uint256(entries.size()));
        //     string[] memory d = new string[](uint256(entries.size()));
        //     string[] memory e = new string[](uint256(entries.size()));
        //     string[] memory f = new string[](uint256(entries.size()));
        //     string[] memory g = new string[](uint256(entries.size()));
        //     string[] memory h = new string[](uint256(entries.size()));
    
        //     for (int256 i = 0; i < entries.size(); ++i) {
        //         Entry entry = entries.get(i);
    
        //         a[uint256(i)] = entry.getString("numid");
        //         b[uint256(i)] = entry.getString("name");
        //         c[uint256(i)] = entry.getString("actual_Power");
        //         d[uint256(i)] = entry.getString("rated_Power");
        //         e[uint256(i)] = entry.getString("input_Time");
        //         f[uint256(i)] = entry.getString("position");
        //         g[uint256(i)] = entry.getString("price");
        //         h[uint256(i)] = entry.getString("Ownership");
        //     }
    
        //     return (a, b, c, d, e, f, g, h);        
        // }
    }
    
    

3

(2)能源管理接口编码

  1. 根据文档要求,编写能源新增接口功能,必须将新增能源数据存入指定表中,在存储完成后需触发后事件并返回存储与否的标识;

  2. 根据文档要求,编写能源修改接口,必须通过指定表修改完成数据更新,在完成更新后需触发事件并返回更新与否的标识。

    /**
     * 电力能源详情存储器,记录电力能源详细信息
     */
    pragma solidity ^0.4.25;
    pragma experimental ABIEncoderV2;
    
    import "./Table.sol";
    import "./LibString.sol";
    import "./Ownable.sol";
    
    
    contract EnergyStorage is Ownable {
    
        using LibString for string;
    
        event Result(int count);
    
        TableFactory tf;
        string constant TABLE_NAME = "E_energy";
        string constant TABLE_NAME2 = "E_order";
    
        constructor() public {
            tf = TableFactory(0x1001);
            tf.createTable(TABLE_NAME, "num_id", "energy");
    
            tf.createTable(TABLE_NAME2, "UAddress", "id,from,to,total,price");
        }
    
    
        /**
        * ""
        * 插入数据
        */
        function insert(string memory _numid) public returns(int) {
            int count = int(0);
            Table table = tf.openTable(TABLE_NAME);
            if(!_numid.empty()){
                Entry entry = table.newEntry();
                entry.set("energy", int(0));
                count = table.insert(_numid, entry);
            }
            emit Result(count);
            return count;
        }
     
        function insert2(string memory _UAddress, string memory order) public returns(int) {
            int count = int(0);
            Order memory _order = convertGoods(order);
            Table table = tf.openTable(TABLE_NAME2);
             if(!_UAddress.empty()){
                Entry entry = table.newEntry();
                convertEntry(_order, entry);
                
                count = table.insert(_UAddress, entry);
             }
            return count;
        }   
            
        function update(string memory _numid) public returns(int) {
            int count = int(0);
            int produce_random = rand();
            Table table = tf.openTable(TABLE_NAME);
            if(!_numid.empty()){
                Entry entry = table.newEntry();
                entry.set("energy", produce_random);
                count = table.insert(_numid, entry);
            }
            emit Result(count);
            return count;
        }
        
        /**
        * 通过key获取value,可以存在多个value
        */
        function select(string memory _numid) public view returns(int[] memory){
            Table table = tf.openTable(TABLE_NAME);
            Condition condition = table.newCondition();
            Entries entries = table.select(_numid, condition);
            
            int[] memory value_list = new int[](uint256(entries.size()));
            
            for (int256 i = 0; i < entries.size(); ++i) {
                Entry entry = entries.get(i);
                value_list[uint256(i)] = entry.getInt("energy");
            }
            
            return value_list;
    
        }
        
        function getOrder(string memory _id) public view returns(string[] memory){
            Table table = tf.openTable(TABLE_NAME2);
            Condition condition = table.newCondition();
            Entries entries = table.select(_id, condition);
            
            string[] memory value_list = new string[](uint256(entries.size()));
            
            for (int256 i = 0; i < entries.size(); ++i) {
                Entry entry = entries.get(i);
                value_list[uint256(i)] = _returnData(entry);
                
            }
            return value_list;
        }    
        
        //能量总和
        function getEnergy(string memory _numid) public view returns(uint){
            int[] memory value_list = select(_numid);
            uint total = 0;
            for (uint256 i = 0; i < value_list.length; i++) {
                // Arr[i] = uint(value_list[uint256(i)]);
                total += uint(value_list[uint256(i)]);
            }
            
            return total;
    
        }
        
        function remove(string memory _numid, string memory _energy) public returns(int) {
            int count = int(0);
            Table table = tf.openTable(TABLE_NAME);
            Condition condition = table.newCondition();
            condition.EQ("energy",_energy);
            count = table.remove(_numid,condition);  
            emit Result(count);
            return count;        
        }    
    
        //产生随机数
        function rand() private view returns(int) {
            int rand = int(keccak256(abi.encodePacked(block.difficulty, now))) % 100;
            if(rand < 70 && rand > 50){rand += 60;}
            if(rand < 50 && rand > 40){rand += 70;}
            if(rand < 40 && rand > 30){rand += 80;}
            if(rand < 30 && rand > 20){rand += 90;}
            if(rand < 20){rand += 100;}
            if(rand <= 0){rand += 110;}
            return rand;
        }
        
        //拼接成json数据
        function _returnData(Entry _entry) internal view returns(string){
    
            string memory _json = "{";
            
            _json = _json.concat("'UAddress':'");
            _json = _json.concat(_entry.getString("UAddress"));
            _json = _json.concat("',");
    
            _json = _json.concat("'id':'");
            _json = _json.concat(_entry.getString("id"));
            _json = _json.concat("',");
    
            _json = _json.concat("'from':'");
            _json = _json.concat(_entry.getString("from"));
            _json = _json.concat("',");
    
            _json = _json.concat("'to':'");
            _json = _json.concat(_entry.getString("to"));
            _json = _json.concat("',");
            
            _json = _json.concat("'total':'");
            _json = _json.concat(_entry.getString("total"));
            _json = _json.concat("',");
            
            _json = _json.concat("'price':'");
            _json = _json.concat(_entry.getString("price"));
            _json = _json.concat("'");
    
    
            _json = _json.concat("}");
    
            return _json;
        }
        
        
        function convertGoods(string memory _str) private returns(Order){
            string[] memory ss = _str.split(",");
            return Order(ss[0],ss[1],ss[2],ss[3],ss[4],ss[5]);
        }
    
        function convertEntry(Order memory _order, Entry entry) private {
            entry.set("UAddress",_order._UAddress);
            entry.set("id",_order._id);
            entry.set("from",_order._from);
            entry.set("to",_order._to);
            entry.set("total",_order._total);
            entry.set("price",_order._price);
            
        }   
        
        struct Order{
            string _UAddress;
            string _id;
            string _from;
            string _to;
            string _total;
            string _price;
        }
    
        // struct Energy {
        //     string Ownership;
        //     string energy_loss; //能量损耗
        //     string energy_produce; //剩余能量
        //     string today_produce; //今日发电
        //     string tody_loss;//今日消耗
        //     string yesterday_produce;//昨日发电
        //     string yesterday_loss;//昨日消耗
        //     string week_produce;//本周发电
        //     string week_loss;//本周消耗
        //     string month_produce;//本月发电
        //     string month_loss;//本月消耗       
    
        // } 
        /**
        * 创建质押物品表
        * +---------------------------+----------------+-----------------------------------------+
        * | Field                     |     Type       |      Desc                               |
        * +---------------------------+----------------+-----------------------------------------+
        * | num_id                          string
        * | energy_loss;                    string          
          | energy_produce;                 string              
          | today_produce;                  string              
          | tody_loss;                      string
          | yesterday_produce;              string
          | yesterday_loss;                 string
          | week_produce;                   string
          | week_loss;                      string
          | month_produce;                  string
          | month_loss;                     string
        * +---------------------------+----------------+-----------------------------------------+
        */
    }
    
    

    在这里插入图片描述

(3)合约部署和调用

  1. 解决代码错误和警告,正确编译并部署合约,成功获取部署的合约地址和ABI;

    在这里插入图片描述

  2. 调用太阳能板查询合约接口,完整验证业务流程;

    在这里插入图片描述

    在这里插入图片描述

在这里插入图片描述

查询新增太阳能板数据

在这里插入图片描述

在这里插入图片描述

查询新增太阳能板数据

在这里插入图片描述

在这里插入图片描述

  1. 调用能源查询合约接口,完整验证业务流程。

    使用energy_insert接口,新增能源。

    在这里插入图片描述

    在这里插入图片描述

在这里插入图片描述

使用太阳能板编号查询新增能源。(get_numid_Energy)

在这里插入图片描述

任务三:智能合约测试

  1. 调用太阳能板查询合约接口,完整验证业务流程;

    在这里插入图片描述

    在这里插入图片描述

  2. 调用能源查询合约接口,完整验证业务流程。

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2087266.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

2024年第六届控制与机器人国际会议(ICCR 2024)即将召开!

2024年第六届控制与机器人国际会议&#xff08;ICCR 2024&#xff09;将于2024年12月5日至7日在日本横滨举行。智能机器人结合了多种概念、学科和技术&#xff0c;共同创造出各种有用的设备、操作器和自主实体&#xff0c;为特定人类社区服务&#xff0c;如制造设备、医疗和远程…

【练习】哈希表的使用

&#x1f3a5; 个人主页&#xff1a;Dikz12&#x1f525;个人专栏&#xff1a;算法(Java)&#x1f4d5;格言&#xff1a;吾愚多不敏&#xff0c;而愿加学欢迎大家&#x1f44d;点赞✍评论⭐收藏 目录 1.哈希表简介 2.两数之和 题目描述 题解 代码实现 2.面试题.判定是否…

代码随想录Day 28|题目:122.买卖股票的最佳时机Ⅱ、55.跳跃游戏、45.跳跃游戏Ⅱ、1005.K次取反后最大化的数组和

提示&#xff1a;DDU&#xff0c;供自己复习使用。欢迎大家前来讨论~ 文章目录 题目题目一&#xff1a;122.买卖股票的最佳时机 II贪心算法&#xff1a;动态规划 题目二&#xff1a;55.跳跃游戏解题思路&#xff1a; 题目三&#xff1a; 45.跳跃游戏 II解题思路方法一方法二 题…

在Centos中的mysql的备份与恢复

1.物理备份 冷备份&#xff1a;关闭数据库时进行热备份&#xff1a;数据库运行时进行&#xff0c;依赖于数据库日志文件温备份&#xff1a;数据库不可写入但可读的状态下进行 2.逻辑备份 对数据库的表或者对象进行备份 3.备份策略 完全备份&#xff1a;每次都备份完整的数…

每日OJ_牛客_Rational Arithmetic(英文题模拟有理数运算)

目录 牛客_Rational Arithmetic&#xff08;英文题模拟有理数运算&#xff09; 解析代码 牛客_Rational Arithmetic&#xff08;英文题模拟有理数运算&#xff09; Rational Arithmetic (20)__牛客网 解析代码 本题看上去不难&#xff0c;但是存在几个问题&#xff1a; 除…

【C++】汇编分析

传参 有的是用寄存器传参&#xff0c;有的用push传参 我在MSVC编译测出来的是PUSH传参&#xff08;debug模式&#xff09;&#xff0c;具体过程如下 long func(long a, long b, long c, long d,long e, long f, long g, long h) {long sum;sum (a b c d e f g h);ret…

《机器学习》文本数据分析之关键词提取、TF-IDF、项目实现 <上>

目录 一、如何进行关键词提取 1、关键词提取步骤 1&#xff09;数据收集 2&#xff09;数据准备 3&#xff09;模型建立 4&#xff09;模型结果统计 5&#xff09;TF-IDF分析 2、什么是语料库 3、如何进行中文分词 1&#xff09;导包 2&#xff09;导入分词库 3&#xff09…

智能优化特征选择|基于鲸鱼WOA优化算法实现的特征选择研究Matlab程序(SVM分类器)

智能优化特征选择|基于鲸鱼WOA优化算法实现的特征选择研究Matlab程序&#xff08;SVM分类器&#xff09; 文章目录 一、基本原理鲸鱼智能优化特征选择&#xff08;WOA&#xff09;结合SVM分类器的详细原理和流程原理流程 二、实验结果三、核心代码四、代码获取五、总结 智能优化…

js | XMLHttpRequest

是什么&#xff1f; 和serve交互数据的对象&#xff1b;能够达到页面部分刷新的效果&#xff0c;也就是获取数据之后&#xff0c;不会使得整个页面都刷新&#xff1b;虽然名字是XML&#xff0c;但不限于XML数据。 怎么用&#xff1f; function reqListener() {console.log(thi…

理解数据库系统的内部结构

数据库系统在我们的数字世界中扮演着关键角色。本文将介绍数据库系统的内部结构&#xff0c;帮助初学者了解其基本概念。 数据库系统的三级模式 数据库系统内部采用三级模式二级映像结构&#xff0c;包括外模式、模式和内模式。这种结构确保了数据的逻辑独立性和物理独立性。…

全能型AI vs 专业型AI:未来是草莓味的AI吗?

草莓&#xff1a;全能型AI的新宠儿&#xff1f; 根据最近的消息&#xff0c;OpenAI的“草莓”模型据说是一个全能型AI&#xff0c;无论是解数学题还是搞定主观营销策略&#xff0c;它都能轻松驾驭。这个AI不仅仅是能解决问题&#xff0c;更是能够跨越多个领域&#xff0c;展现出…

C++学习/复习补充记录 --- 图论(深搜,广搜)

数据结构与算法 | 深搜&#xff08;DFS&#xff09;与广搜&#xff08;BFS&#xff09;_深搜广搜算法-CSDN博客 深度优先搜索理论基础 深搜和广搜的区别&#xff1a; &#xff08;通俗版&#xff09; dfs是可一个方向去搜&#xff0c;不到黄河不回头&#xff0c;直到遇到绝境了…

消费电子钛时代到来!天工股份抢占发展高地,业绩爆发式增长、前景广阔

消费电子“钛时代”正加速到来。 27日凌晨&#xff0c;苹果正式定档iPhone 16系列新品的发布会日期。据悉&#xff0c;本次iPhone 16 Pro系列将全系标配钛金属中框&#xff0c;继续沿用并升级此前在iPhone 15 Pro系列上应用的钛金属材质。 回看去年9月秋季新品发布会&#xf…

三秒学会--百度网盘下载提速10倍的小tip

开启优化速率 从2mb-->20mb 纵享新丝滑~

PHP安装扩展包时忽略依赖强制安装

正常安装时会检查依赖包&#xff0c;比如是否安装了reids扩展&#xff0c;是否安装了gd库等&#xff0c;卖到依赖包安装失败。 如下提示&#xff1a; 这样会导致你的包安装不上。 使用下面命令&#xff0c;强制安装&#xff0c;如下&#xff1a; 加上 --ignore-platform-req…

常见概念 -- dBm, mW,dB之间的关系

dBm与mW dBm&#xff08;毫瓦分贝&#xff09;与mW&#xff08;毫瓦&#xff09;都是光功率的单位。 两者之间的换算关系&#xff1a;dBm10xlgP。其中P为功率&#xff0c;单位为mW。 如&#xff1a;1mW可换算为0dBm。 dBm与dB dBm为光功率的单位&#xff0c;d…

GraphPad Prism下载安装教程怎样中文汉化

GraphPad Prism下载安装教程怎样中文汉化&#xff1a; GraphPad Prism 是一款集生物统计、曲线拟合和科技绘图于一体的软件&#xff0c;主要用于医学和生物科学领域的数据分析和绘图&#xff0c;具有高效、简便、多功能和高质量的特点&#xff0c;被广泛应用于科研、教育和业界…

告别繁琐,拥抱简单!用户好评如潮的录屏软件

不论你是有游戏过程录制的需求&#xff0c;还是教学片段录制的需求肯定都需要电脑屏幕录制工具吧。除了小巧便捷的ocam录屏之外还有不少类似工具可供我们选择。这次我就给你介绍几款我用过的录屏工具吧。 1.福昕录屏大师 链接&#xff1a;www.foxitsoftware.cn/REC/ 这款录屏…

智慧猪场实训中心解决方案

一、引言 随着科技的飞速发展&#xff0c;传统养猪业正经历着前所未有的变革。为了提高养猪效率、降低生产成本并保障猪只健康&#xff0c;智慧养猪场的概念应运而生。唯众特此推出《智慧猪场实训中心解决方案》&#xff0c;旨在通过先进的技术与管理手段&#xff0c;为养猪业培…

MQ专题:延迟消息的通用方案

一、主要内容 本文将实现一个MQ延迟消息的通用方案。 方案不依赖于MQ中间件&#xff0c;依靠MySQL和DelayQueue解决&#xff0c;不管大家用的是什么MQ&#xff0c;具体是RocketMQ、RabbitMQ还是kafka&#xff0c;本文这个方案你都可以拿去直接使用&#xff0c;可以轻松实现任…