Created
April 9, 2019 22:49
-
-
Save k06a/c7a29c17ba41876359f643a5be49b208 to your computer and use it in GitHub Desktop.
Multisend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.7; | |
contract Token { | |
mapping(address => uint256) public balanceOf; | |
mapping(address => mapping(address => uint256)) public allowance; | |
event Transfer(address indexed from, address indexed to, uint256 amount); | |
function transfer(address to, uint256 amount) public returns(bool) { | |
_transfer(msg.sender, to, amount); | |
return true; | |
} | |
function approve(address to, uint256 amount) public returns(bool) { | |
allowance[msg.sender][to] = amount; | |
return true; | |
} | |
function transferFrom(address from, address to, uint256 amount) public returns(bool) { | |
require(allowance[from][msg.sender] >= amount); | |
allowance[from][msg.sender] -= amount; | |
_transfer(from, to, amount); | |
} | |
function _transfer(address from, address to, uint256 amount) internal { | |
require(balanceOf[from] >= amount); | |
balanceOf[from] -= amount; | |
balanceOf[to] += amount; | |
emit Transfer(from, to, amount); | |
} | |
constructor() public { | |
balanceOf[msg.sender] = 1000000; | |
} | |
} | |
contract Multisend { | |
Token public _token; | |
constructor() public { | |
_token = new Token(); | |
} | |
function f(address[] calldata tos, uint256[] calldata amounts) external { | |
Token token = _token; | |
for (uint i = 0; i < tos.length; i++) { | |
token.transfer(tos[i], amounts[i]); | |
} | |
} | |
function g(bytes calldata data) external { | |
Token token = _token; | |
bytes memory arg = new bytes(68); | |
for (uint256 i = 0; i < data.length; i += 68) { | |
assembly { | |
calldatacopy(add(32, arg), add(0x44, i), 68) | |
let b := call(gas, token, 0, add(32, arg), 68, 0, 0) | |
} | |
} | |
} | |
function g2(bytes memory data) public { | |
Token token = _token; | |
for (uint256 i = 0; i < data.length; i += 68) { | |
assembly { | |
let b := call(gas, token, 0, add(add(32, data), i), 68, 0, 0) | |
} | |
} | |
} | |
} | |
// ["0xca35b7d915458ef540ade6068dfe2f44e8fa7335", "0xca35b7d915458ef540ade6068dfe2f44e8fa733c", "0xca35b7d915458ef540ade6068dfe2f44e8fa733d", "0xca35b7d915458ef540ade6068dfe2f44e8fa733e", "0xca35b7d915458ef540ade6068dfe2f44e8fa7330"], [1,2,3,4,5] | |
// a9059cbb000000000000000000000000ca35b7d915458ef540ade6068dfe2f44e8fa73350000000000000000000000000000000000000000000000000000000000000001a9059cbb000000000000000000000000ca35b7d915458ef540ade6068dfe2f44e8fa733c0000000000000000000000000000000000000000000000000000000000000002a9059cbb000000000000000000000000ca35b7d915458ef540ade6068dfe2f44e8fa733d0000000000000000000000000000000000000000000000000000000000000003a9059cbb000000000000000000000000ca35b7d915458ef540ade6068dfe2f44e8fa733e0000000000000000000000000000000000000000000000000000000000000004a9059cbb000000000000000000000000ca35b7d915458ef540ade6068dfe2f44e8fa73300000000000000000000000000000000000000000000000000000000000000005 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment