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);
        }
    
    }
    

      

  • 相关阅读:
    -1%256的值是多少?
    Glut,程序的基本架构
    剑指offer:数值的整数次方
    剑指offer:二进制中1的个数
    剑指offer:斐波那契数列的应用
    剑指offer:斐波那契数列
    剑指offer:旋转数组中的最小数字
    弱智的grub消除法
    POJ 3126 Prime Path
    HDU 1426 Sudoku Killer
  • 原文地址:https://www.cnblogs.com/zhangmingcheng/p/11848566.html
Copyright © 2011-2022 走看看