以太坊多重钱包离线签名

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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:\n32";
        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);
    }
 
}

测试:

  

posted @   人艰不拆_zmc  阅读(644)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 张高兴的大模型开发实战:(一)使用 Selenium 进行网页爬虫
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示