以太坊数据合约与控制合约分离

pragma solidity ^0.4.18;

contract orderData {
    struct    orderProduct  {
        address  seller; // 卖家
        address buyers; // 买家
        uint256 id;
        string productName;
        uint256  unitPrice;
        uint256  totalPrice;
        uint256  purchaseQuantity;  // 购买数量
        string  subTiem; // 订单提交时间
        string  payTime; // 支付时间
        uint256 orderStatus;// 订单状态:1是没支付;2是已经支付;3 确认收货;4 是申请退款;5是退款完成  
    }  
   
    mapping(uint256 =>orderProduct ) public  orderProductMap; 
 // 在JAVA程序中直接调用 orderData 
   //的  orderProductMap 方法就可以获取数据,因为 orderProductMap 变量被声明为 public 所以以太坊
  // 会自动给这个变量创建个 同名的 orderProductMap  方法获取值。比如要提取 orderProductMap 小标
  // 为 1 的元素,使用 orderProductMap(1) 调用 orderProductMap方法。

     
 // 注意一个函数控制在10个参数以内,参数过多会报堆栈过深的错误。
// 这里用来做判断的参数不能设置为 bool 类型,如果为 bool 类型,调用函数时不能传入的参数是 t rue还 f als
// 函数接受到的都是 true。
    function setOrderProductMap(address _seller,uint256 _c1,address _buyers,uint256 _c2,
              uint256 _id,uint256 _c3,string _productName,uint256 _c4,
        uint256 _unitPrice,uint256 _c5/*uint256 _totalPrice,uint256 _purchaseQuantity,string _subTiem,
        uint256 _orderStatus*/) public {
                  if(_c1==1) {
                      orderProductMap[_id].seller=_seller;
                  }
                  if (_c2==1) {
                      orderProductMap[_id].buyers=_buyers;
                  }
                  if (_c3==1) {
                      orderProductMap[_id].id=_id;
                  }
                  if (_c4==1) {
                      orderProductMap[_id].productName=_productName;
                  }
                  if (_c5==1) {
                      orderProductMap[_id].unitPrice=_unitPrice;
                  }
                  /*
                  orderProductMap[_id].totalPrice=_totalPrice;
                  orderProductMap[_id].purchaseQuantity=_purchaseQuantity;
                  orderProductMap[_id].subTiem=_subTiem;
                  //orderProductMap[_id].payTime=_payTime;
                  orderProductMap[_id].orderStatus=_orderStatus;*/
             
        }
         
        function setOrderProductMap2(uint256 _id,uint256 _totalPrice,uint256 _c1,uint256 _purchaseQuantity,
              uint256 _c2,string _subTiem,uint256 _c3,
              uint256 _orderStatus,uint256 _c4) public {
                  if(_c1==1) {
                      orderProductMap[_id].totalPrice=_totalPrice;
                  }
                  if (_c2==1) {
                      orderProductMap[_id].purchaseQuantity=_purchaseQuantity;
                  }
                  if (_c3==1) {
                      orderProductMap[_id].subTiem=_subTiem;
                  }
                  if (_c4==1) {
                    orderProductMap[_id].orderStatus=_orderStatus;  
                  }
               
               
                   
                   
                   
                  //orderProductMap[_id].payTime=_payTime;
                 
             
        }
     
        function setPayTime(uint256 _id,string _payTime,uint256 _orderStatus) public {
            orderProductMap[_id].payTime = _payTime;
              orderProductMap[_id].orderStatus = _orderStatus;
        }
     
}

contract orderControlContract {

    orderData od;
     

    function orderControlContract() public {
        address addr = 0xbde95422681e4c3984635af2f2f35f8c44a4ddc9; // 数据合约的地址。先部署数据合约,然后把数据合约
       // 的电子复制粘贴到这里

        od = orderData(addr);
    }

    function setOrderdataControl(address _seller,uint256 _c1,address _buyers,uint256 _c2,
              uint256 _id,uint256 _c3,string _productName,uint256 _c4,
        uint256 _unitPrice,uint256 _c5/*uint256 _totalPrice,uint256 _purchaseQuantity,string _subTiem,
        uint256 _orderStatus*/) public {
          od.setOrderProductMap( _seller,_c1, _buyers,_c2, _id,_c3, _productName,_c4,
                _unitPrice,_c5);
    }
     
    function setOrderdataControl2(uint256 _id,uint256 _totalPrice,uint256 _c1,uint256 _purchaseQuantity
              ,uint256 _c2,string _subTiem,uint256 _c3,
              uint256 _orderStatus,uint256 _c4) public {
          od.setOrderProductMap2(_id, _totalPrice, _c1, _purchaseQuantity
              , _c2, _subTiem, _c3,
              _orderStatus, _c4);
    }
   
     
    function setPayTimeControl(uint256 _id,string _payTime,uint256 _orderStatus) public {
        od.setPayTime(_id,_payTime,_orderStatus);
    }
     
     
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值