aboutsummaryrefslogtreecommitdiff
path: root/examples/multicoin/mc_test.sol
blob: bfd42a5d864539cfdb3dcae5ac887f35d5948687 (plain) (blame)
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
pragma solidity >=0.6.0;

contract MCTest {
    address constant MultiCoin = 0x0100000000000000000000000000000000000000;
    uint256 balance;
    constructor() public {
        // enable multi-coin functionality (it is disabled by default)
        (bool success,) = MultiCoin.delegatecall(abi.encodeWithSignature("enableMultiCoin()"));
        require(success);
    }

    function updateBalance(uint256 coinid) public {
        (bool success, bytes memory data) = MultiCoin.delegatecall(abi.encodeWithSignature("getBalance(uint256)", coinid));
        require(success);
        balance = abi.decode(data, (uint256));
    }

    function deposit() public payable {}

    function withdraw(uint256 amount, uint256 coinid, uint256 amount2) public {
        (bool success,) = MultiCoin.delegatecall(
            abi.encodeWithSignature("transfer(address,uint256,uint256,uint256)",
                                    msg.sender, amount, coinid, amount2));

        require(success);
    }
}