-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding ability to send an array of tokens #119
Open
micahriggan
wants to merge
10
commits into
bitpay:master
Choose a base branch
from
micahriggan:feature/send-many-tokens
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
df7aaa4
Adding ability to send an array of tokens
micahriggan 1493c8b
Updating test to use some addresses, rather than assuming local accou…
micahriggan 1d52040
Adding some error messages, and removing owner requirement
micahriggan c4f6612
>= for require
micahriggan 744e2dc
Send to many test function
micahriggan 2bfdbd1
Allow local testing and ci testing
micahriggan 1a397dd
Test with send, to make sure sends don't brick the validation
micahriggan 819f1f0
Don't allow usage of more ETH than msg.value
micahriggan e83efd5
Sum up the eth and make sure contract received that amount
micahriggan 17ff28e
Adding sendFrom param
micahriggan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,20 @@ pragma solidity ^0.4.23; | |
import "./IERC20.sol"; | ||
|
||
contract SendToMany { | ||
|
||
address owner; | ||
mapping(address => uint) private tokenSums; | ||
|
||
constructor() { | ||
constructor() public { | ||
owner = msg.sender; | ||
} | ||
|
||
modifier isOwner() { | ||
require(msg.sender == owner); | ||
require(msg.sender == owner, "must be the owner address"); | ||
_; | ||
} | ||
|
||
function sendMany(address[] addresses, uint[] amounts, address tokenContract) public payable isOwner { | ||
function sendMany(address[] memory addresses, uint[] memory amounts, address tokenContract) public payable isOwner { | ||
require(addresses.length == amounts.length); | ||
uint sum = 0; | ||
for(uint i = 0; i < amounts.length; i++) { | ||
|
@@ -26,10 +28,48 @@ contract SendToMany { | |
require(token.transferFrom(msg.sender, addresses[i], amounts[i]), "token transfer failed"); | ||
} | ||
} else { | ||
require((address(this).balance + msg.value) >= sum, "ETH balance too low for this batch"); | ||
require((msg.value) >= sum, "must send enough ETH"); | ||
for(i = 0; i < addresses.length; i++) { | ||
addresses[i].transfer(amounts[i]); | ||
} | ||
} | ||
} | ||
|
||
|
||
function validateBatch(address[] memory addresses, uint[] memory amounts, address[] memory tokenContracts, uint sentValue, address sender) public view returns(bool) { | ||
require(addresses.length == amounts.length, "must provide same length addresses and amounts"); | ||
require(addresses.length == tokenContracts.length, "must provide same length addresses and tokenContracts"); | ||
for(uint i = 0; i < addresses.length; i++) { | ||
address tokenContract = tokenContracts[i]; | ||
uint amount = amounts[i]; | ||
tokenSums[tokenContract] += amount; | ||
uint sum = tokenSums[tokenContract]; | ||
if(tokenContract != 0x0) { | ||
IERC20 token = IERC20(tokenContract); | ||
require(token.allowance(sender, address(this)) >= sum, "This contract is not allowed enough funds for this batch"); | ||
} else { | ||
require(sentValue >= sum, "must send enough ETH"); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
function batchSend(address[] memory addresses, uint[] memory amounts, address[] memory tokenContracts) public payable { | ||
require(addresses.length == amounts.length, "must provide same length addresses and amounts"); | ||
require(addresses.length == tokenContracts.length, "must provide same length addresses and tokenContracts"); | ||
uint ethSum = 0; | ||
for(uint i = 0; i < addresses.length; i++) { | ||
address tokenContract = tokenContracts[i]; | ||
address recipient = addresses[i]; | ||
uint amount = amounts[i]; | ||
if(tokenContract != 0x0) { | ||
IERC20 token = IERC20(tokenContract); | ||
require(token.transferFrom(msg.sender, recipient, amount), "token transfer failed"); | ||
} else { | ||
ethSum += amount; | ||
require(msg.value >= ethSum, "must send enough ETH"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make exact equal |
||
recipient.transfer(amount); | ||
} | ||
} | ||
} | ||
} |
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reduce duplication