Skip to content

Instantly share code, notes, and snippets.

@ahbanavi
Created April 14, 2022 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahbanavi/bcf392a82bdc93198698c921aef4937d to your computer and use it in GitHub Desktop.
Save ahbanavi/bcf392a82bdc93198698c921aef4937d to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.13+commit.abaa5c0e.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
contract SimpleSplitter {
event Received(address, uint256);
error PaymentFailed();
error WrongShares();
address private immutable _addr1;
address private immutable _addr2;
uint256 private immutable _share1;
uint256 private immutable _share2;
constructor(address addr1_, address addr2_, uint256 share1_, uint256 share2_) {
_addr1 = addr1_;
_addr2 = addr2_;
if (share1_ + share2_ != 100) revert WrongShares();
_share1 = share1_;
_share2 = share2_;
}
receive() external payable {
emit Received(msg.sender, msg.value);
}
function withdraw() external {
uint256 balance = address(this).balance;
(bool success1, ) = _addr1.call{value: balance * _share1 / 100 }("");
(bool success2, ) = _addr2.call{value: balance * _share2 / 100 }("");
if (!success1 && !success2) revert PaymentFailed();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment