zoukankan      html  css  js  c++  java
  • 以太坊多重钱包离线签名

    pragma solidity ^0.4.23;
    
    contract MultiSign {
    
        uint public nonce;                 
        uint public threshold;             // 满足threshold个签名即可转账
        mapping (address => bool) owners; // 共同拥有人
        address[] public ownersArr;        // 共同拥有人地址
        
        modifier isManager{
            require(
                owners[msg.sender] == true);
            _;
        }
        //充值事件
        event DepositFunds(address from, uint amount);
        //转账事件
        event TransferFunds(address to, uint amount);
    
        constructor(uint threshold_, address[] owners_) public {
            require(owners_.length <= 10 && threshold_ <= owners_.length && threshold_ != 0);
            for (uint i=0; i<owners_.length; i++) {
                require(owners_[i] != address(0x0) && owners[owners_[i]] == false);
                owners[owners_[i]] = true;
            }
            ownersArr = owners_;
            threshold = threshold_;
        }
    
        //转账
        function executeTransfer(uint8[] sigV, bytes32[] sigR, bytes32[] sigS, address destination, uint value, bytes data) isManager public{
            require(sigR.length == threshold);
            require(sigR.length == sigS.length && sigR.length == sigV.length);
            bytes32 txHash = keccak256(byte(0x19), byte(0), address(this), destination, value, data, nonce);
    
            bytes memory prefix = "x19Ethereum Signed Message:
    32";
            for (uint i = 0; i < threshold; i++) {
                bytes32 prefixedHash = keccak256(prefix, txHash);
                address recovered = ecrecover(prefixedHash, sigV[i], sigR[i], sigS[i]);
                require(recovered != address(0x0) && owners[recovered] == true);
            }
            require(address(destination).call.value(value)(data));
            nonce = nonce + 1;
            emit TransferFunds(destination, value);
        }
        
        function balanceOf() public view returns(uint){
            return address(this).balance;
        }
    
         //充值
         function () public payable{
            emit DepositFunds(msg.sender, msg.value);
        }
    
    }
    

      

  • 相关阅读:
    Base64正反编码
    json数据测试接口
    ajax上传进度条
    ajax利用php上传图片
    ajax缓存 header头文件
    ajax同步与异步
    ajax的post请求与编码
    ajax的get请求与编码
    ajax获取服务器响应信息
    创建ajax对象
  • 原文地址:https://www.cnblogs.com/zhangmingcheng/p/11848566.html
Copyright © 2011-2022 走看看