Skip to content

Instantly share code, notes, and snippets.

@sherlock-shi-x
Last active February 20, 2018 13:24
Show Gist options
  • Save sherlock-shi-x/3ba76df704ed9be256603307342e30f1 to your computer and use it in GitHub Desktop.
Save sherlock-shi-x/3ba76df704ed9be256603307342e30f1 to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.18;
contract BotAlice {
address owner;
mapping (address => bool) isAdmins;
IMainContract private iMainContract;
IBotBob private iBotBob;
function BotAlice() public {
owner = msg.sender;
isAdmins[owner] = true;
iMainContract = IMainContract(0xd62ccc23c5e1db41c017913303bdb09e570284f6);
}
modifier onlyAdmins() {
require(isAdmins[msg.sender]);
_;
}
/*
* only read
*/
function queryAdmin(address _addr) public view returns(bool v) {
return isAdmins[_addr];
}
function queryMainContract() public view returns(address _addr) {
return iMainContract;
}
function queryBob() public view returns(address _addr) {
return iBotBob;
}
function addAdmins(address _addr) public {
require(isAdmins[msg.sender]);
isAdmins[_addr] = true;
}
function setMainContractAddr(address _addr) onlyAdmins() public {
iMainContract = IMainContract(_addr);
}
function setBotBobAddr(address _addr) onlyAdmins() public {
iBotBob = IBotBob(_addr);
}
function bid(uint tokenId, uint maxPrice) onlyAdmins() payable public {
bool flag = true;
while (iMainContract.priceOf(tokenId) < maxPrice) {
if (flag) {
iMainContract.buy(tokenId);
} else {
iBotBob.buy(tokenId);
}
flag = !flag;
}
}
function sendMoney() payable public {
}
}
interface IMainContract {
function buy(uint256 _itemId) payable public;
function priceOf (uint256 _itemId) public view returns (uint256 _price);
function ownerOf (uint256 _itemId) public view returns (address _owner);
}
interface IBotBob {
function buy(uint256 _itemId) payable public;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment