Contract 0xA5e04A2B90a2d7AFEC5ac137902d207CaA6C709F

Contract Overview

Balance:
100 wei
Txn Hash
Method
Block
From
To
Value
0x3d745c79f2d7e08e3fb06fa17ec10bb1293944aa6ebfb728d64210690e553515Update79800722020-05-27 11:13:38764 days 11 hrs ago0x281609b6005d3e3235230d9b88e5dd46f9078e76 IN  0xa5e04a2b90a2d7afec5ac137902d207caa6c709f0 Ether0.00075372535
0x9074ab8ec98c28dec3cc863005910057aa1cb1e6edd0a91da4ecd89d71ea376aBid79330332020-05-19 16:58:45772 days 6 hrs ago0x0f60841dfdd78535e11f71192e1ddece598fe541 IN  0xa5e04a2b90a2d7afec5ac137902d207caa6c709f100 wei0.0001050951
0x6c662bec973d7028499fd601b7cbf61c45de74943730a672793cff535c912b190x6080604079324792020-05-19 14:35:41772 days 8 hrs ago0x0f60841dfdd78535e11f71192e1ddece598fe541 IN  Contract Creation0 Ether0.0008350281
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading

Similar Match Source Code
Note: This contract matches the deployed ByteCode of the Source Code for Contract 0x6d69f6927ab65a2d3c01dbf2e0cf5974e34e1780

Contract Name:
StockBetting

Compiler Version
v0.5.16+commit.9c3226ce

Optimization Enabled:
No with 200 runs

Other Settings:
default evmVersion, MIT license
/**
 *Submitted for verification at Etherscan.io on 2020-05-11
*/

pragma solidity 0.5.16;


contract StockBetting {
    struct Bid {
        address payable account;

        uint bid; // estimated stock value in now + _biddingtime
        uint amount; //todo: replace with deposit
    }

    Bid[] public bids;

    // mapping(address => Bid) public bids;
    
    // todo: Change to private
    // Time how long the contract is active 
    uint public runEndTime;
    
    // Time how long the bids are allowed
    uint public bidEndTime;

    // admin of the contract -> StockVoting
    address payable public chairperson;

    //todo: publish address of winner (after contract ended)

    // Set to true at the end, disallows any change.
    // By default initialized to `false`.
    bool ended;

    // Events that will be emitted on changes.
    event Payout(address payable winner, uint payout);
    event Debug(uint value);

    constructor(
        //todo payable
        address payable _chairperson,
        uint _runTime,
        uint _bidTime
        )
    public {
        chairperson = _chairperson;
        // todo: Safe?
        runEndTime = now + _runTime;
        bidEndTime = now + _bidTime;
    }

    /// Bid on the auction with the value sent
    /// together with this transaction.
    function bid(uint bidValue) public payable {
        // The keyword payable
        // is required for the function to
        // be able to receive Ether.

        // Revert the call if the bidding
        // period is over.
        require(
            now <= runEndTime,
            "No bid possible anymore, the run time has ended"
        );
        require(
            now <= bidEndTime,
            "No bid possible anymore, the time to bid has ended"
        );

        bids.push(Bid({
            account: msg.sender,
            bid: bidValue,
            amount: msg.value
        }));


        // if (highestBid != 0) {
        //     // Sending back the money by simply using
        //     // highestBidder.send(highestBid) is a security risk
        //     // because it could execute an untrusted contract.
        //     // It is always safer to let the recipients
        //     // withdraw their money themselves.
        //     pendingReturns[highestBidder] += highestBid;
        // }
        // highestBidder = msg.sender;
        // highestBid = msg.value;

        //todo: publish event when bidadded...
        // emit HighestBidIncreased(msg.sender, msg.value);
    }

    /// End the betting because the time is up 
    /// to the winner.
    function bettingEnd(uint stockValue) external payable {
        // 1. checking conditions
        // 2. performing actions (potentially changing conditions)
        // 3. interacting with other contracts

        require(msg.sender==chairperson, "Not the rights to end this contract");
        require(now >= runEndTime, "Runtime of contract is not over yet");
        require(!ended, "Contract has already ended");


        if(1==bids.length)
        {
            // One on bid Give bider possibility to withdraw bet
            address payable lonelyBider = bids[0].account;
            uint bidsum = bids[0].amount;
            emit Payout(lonelyBider, bidsum);

            //todo: give voter possibility to withdraw money (safer)
            lonelyBider.transfer(bidsum);
            return;
        }

        // 2. Effects
        ended = true;
        uint payoutsum = 0;
        //todo: optimize -> not safe
        // int distance = Math.abs(numbers[0] - myNumber);
        uint previous_diff = 10000;
        address payable winner;

        for (uint p = 0; p < bids.length; p++) {
            payoutsum = payoutsum + bids[p].amount;
            uint bidValue = bids[p].bid;
            //Calculate absolute value (distance to stockValue)
            uint diffStock = (stockValue > bidValue) ? stockValue - bidValue : bidValue - stockValue;

            if(previous_diff>diffStock)
            {
                previous_diff = diffStock;
                winner = bids[p].account;
            }
        }

        emit Payout(winner, payoutsum);

        // 3. Interaction
        // Note that this is not visible on the blockchain, it is only executed through the contract itself
        // https://ethereum.stackexchange.com/questions/8315/confused-by-internal-transactions
        //todo: give winner possibility to withdraw money (safer)

        winner.transfer(payoutsum);
    }

    // Getter/Setter
    function getBidofAccount(address payable bider) public view returns(uint) {
        for (uint p = 0; p < bids.length; p++) {
            if (bids[p].account == bider){
                return bids[p].bid;
            }
        }
    }

   	function getBalance(address payable addr) public view returns(uint) {
		return addr.balance;
	}

    function setrunEndTime(uint _newrunEndTime) public {
        require(msg.sender==chairperson, "Not the rights to change this value");
		runEndTime = _newrunEndTime;
	}
    function setbidEndTime(uint _newbidEndTime) public {
        require(msg.sender==chairperson, "Not the rights to change this value");
		bidEndTime = _newbidEndTime;
    }
}

Contract ABI

[{"inputs":[{"internalType":"address payable","name":"_chairperson","type":"address"},{"internalType":"uint256","name":"_runTime","type":"uint256"},{"internalType":"uint256","name":"_bidTime","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Debug","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address payable","name":"winner","type":"address"},{"indexed":false,"internalType":"uint256","name":"payout","type":"uint256"}],"name":"Payout","type":"event"},{"constant":false,"inputs":[{"internalType":"uint256","name":"stockValue","type":"uint256"}],"name":"bettingEnd","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"bidValue","type":"uint256"}],"name":"bid","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[],"name":"bidEndTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"bids","outputs":[{"internalType":"address payable","name":"account","type":"address"},{"internalType":"uint256","name":"bid","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"chairperson","outputs":[{"internalType":"address payable","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address payable","name":"addr","type":"address"}],"name":"getBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address payable","name":"bider","type":"address"}],"name":"getBidofAccount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"runEndTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"_newbidEndTime","type":"uint256"}],"name":"setbidEndTime","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"_newrunEndTime","type":"uint256"}],"name":"setrunEndTime","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]

608060405234801561001057600080fd5b50604051610dc4380380610dc48339818101604052606081101561003357600080fd5b8101908080519060200190929190805190602001909291908051906020019092919050505082600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550814201600181905550804201600281905550505050610d07806100bd6000396000f3fe6080604052600436106100915760003560e01c80634ba9a927116100595780634ba9a927146102445780636cf151f01461026f578063900181971461029d578063d5cc85da146102c8578063f8b2cb4f1461030357610091565b80630cd8b5ad146100965780632e4176cf146100d15780634262a0db146101285780634423c5f11461018d578063454a2ab314610216575b600080fd5b3480156100a257600080fd5b506100cf600480360360208110156100b957600080fd5b8101908080359060200190929190505050610368565b005b3480156100dd57600080fd5b506100e6610418565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561013457600080fd5b506101776004803603602081101561014b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061043e565b6040518082815260200191505060405180910390f35b34801561019957600080fd5b506101c6600480360360208110156101b057600080fd5b8101908080359060200190929190505050610500565b604051808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001838152602001828152602001935050505060405180910390f35b6102426004803603602081101561022c57600080fd5b8101908080359060200190929190505050610557565b005b34801561025057600080fd5b506102596106cc565b6040518082815260200191505060405180910390f35b61029b6004803603602081101561028557600080fd5b81019080803590602001909291905050506106d2565b005b3480156102a957600080fd5b506102b2610b31565b6040518082815260200191505060405180910390f35b3480156102d457600080fd5b50610301600480360360208110156102eb57600080fd5b8101908080359060200190929190505050610b37565b005b34801561030f57600080fd5b506103526004803603602081101561032657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610be7565b6040518082815260200191505060405180910390f35b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461040e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180610cb06023913960400191505060405180910390fd5b8060018190555050565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600080600090505b6000805490508110156104f9578273ffffffffffffffffffffffffffffffffffffffff166000828154811061047757fe5b906000526020600020906003020160000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614156104ec57600081815481106104d257fe5b9060005260206000209060030201600101549150506104fb565b8080600101915050610446565b505b919050565b6000818154811061050d57fe5b90600052602060002090600302016000915090508060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060010154908060020154905083565b6001544211156105b2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602f815260200180610c4f602f913960400191505060405180910390fd5b60025442111561060d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526032815260200180610c7e6032913960400191505060405180910390fd5b600060405180606001604052803373ffffffffffffffffffffffffffffffffffffffff168152602001838152602001348152509080600181540180825580915050906001820390600052602060002090600302016000909192909190915060008201518160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550602082015181600101556040820151816002015550505050565b60025481565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610778576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180610c2c6023913960400191505060405180910390fd5b6001544210156107d3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180610c096023913960400191505060405180910390fd5b600360149054906101000a900460ff1615610856576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f436f6e74726163742068617320616c726561647920656e64656400000000000081525060200191505060405180910390fd5b600080549050600114156109835760008060008154811061087357fe5b906000526020600020906003020160000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690506000806000815481106108b657fe5b90600052602060002090600302016002015490507f5afeca38b2064c23a692c4cf353015d80ab3ecc417b4f893f372690c11fbd9a68282604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a18173ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f1935050505015801561097b573d6000803e3d6000fd5b505050610b2e565b6001600360146101000a81548160ff021916908315150217905550600080905060006127109050600080600090505b600080549050811015610a7757600081815481106109cc57fe5b9060005260206000209060030201600201548401935060008082815481106109f057fe5b90600052602060002090600302016001015490506000818711610a1557868203610a19565b8187035b905080851115610a685780945060008381548110610a3357fe5b906000526020600020906003020160000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1693505b505080806001019150506109b2565b507f5afeca38b2064c23a692c4cf353015d80ab3ecc417b4f893f372690c11fbd9a68184604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a18073ffffffffffffffffffffffffffffffffffffffff166108fc849081150290604051600060405180830381858888f19350505050158015610b29573d6000803e3d6000fd5b505050505b50565b60015481565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610bdd576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180610cb06023913960400191505060405180910390fd5b8060028190555050565b60008173ffffffffffffffffffffffffffffffffffffffff1631905091905056fe52756e74696d65206f6620636f6e7472616374206973206e6f74206f766572207965744e6f74207468652072696768747320746f20656e64207468697320636f6e74726163744e6f2062696420706f737369626c6520616e796d6f72652c207468652072756e2074696d652068617320656e6465644e6f2062696420706f737369626c6520616e796d6f72652c207468652074696d6520746f206269642068617320656e6465644e6f74207468652072696768747320746f206368616e676520746869732076616c7565a265627a7a7231582005985fc3cd6536dc70774f66377d8024467d7e388975f6bd1d84fd742ac10ea764736f6c634300051000320000000000000000000000000f60841dfdd78535e11f71192e1ddece598fe541000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000014

Deployed ByteCode Sourcemap

29:5261:0:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4938:170;;8:9:-1;5:2;;;30:1;27;20:12;5:2;4938:170:0;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;4938:170:0;;;;;;;;;;;;;;;;;:::i;:::-;;547:34;;8:9:-1;5:2;;;30:1;27;20:12;5:2;547:34:0;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;4586:239;;8:9:-1;5:2;;;30:1;27;20:12;5:2;4586:239:0;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;4586:239:0;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;238:17;;8:9:-1;5:2;;;30:1;27;20:12;5:2;238:17:0;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;238:17:0;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1294:1232;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;1294:1232:0;;;;;;;;;;;;;;;;;:::i;:::-;;471:22;;8:9:-1;5:2;;;30:1;27;20:12;5:2;471:22:0;;;:::i;:::-;;;;;;;;;;;;;;;;;;;2607:1949;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;2607:1949:0;;;;;;;;;;;;;;;;;:::i;:::-;;393:22;;8:9:-1;5:2;;;30:1;27;20:12;5:2;393:22:0;;;:::i;:::-;;;;;;;;;;;;;;;;;;;5114:173;;8:9:-1;5:2;;;30:1;27;20:12;5:2;5114:173:0;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;5114:173:0;;;;;;;;;;;;;;;;;:::i;:::-;;4833:97;;8:9:-1;5:2;;;30:1;27;20:12;5:2;4833:97:0;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;4833:97:0;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;4938:170;5020:11;;;;;;;;;;;5008:23;;:10;:23;;;5000:71;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;5089:14;5076:10;:27;;;;4938:170;:::o;547:34::-;;;;;;;;;;;;;:::o;4586:239::-;4654:4;4676:6;4685:1;4676:10;;4671:147;4692:4;:11;;;;4688:1;:15;4671:147;;;4748:5;4729:24;;:4;4734:1;4729:7;;;;;;;;;;;;;;;;;;:15;;;;;;;;;;;;:24;;;4725:82;;;4780:4;4785:1;4780:7;;;;;;;;;;;;;;;;;;:11;;;4773:18;;;;;4725:82;4705:3;;;;;;;4671:147;;;;4586:239;;;;:::o;238:17::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;1294:1232::-;1564:10;;1557:3;:17;;1535:114;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1689:10;;1682:3;:17;;1660:117;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1790:4;1800:110;;;;;;;;1828:10;1800:110;;;;;;1858:8;1800:110;;;;1889:9;1800:110;;;1790:121;;39:1:-1;33:3;27:10;23:18;57:10;52:3;45:23;79:10;72:17;;0:93;1790:121:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1294:1232;:::o;471:22::-;;;;:::o;2607:1949::-;2845:11;;;;;;;;;;;2833:23;;:10;:23;;;2825:71;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2922:10;;2915:3;:17;;2907:65;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2992:5;;;;;;;;;;;2991:6;2983:45;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;3049:4;:11;;;;3046:1;:14;3043:392;;;3152:27;3182:4;3187:1;3182:7;;;;;;;;;;;;;;;;;;:15;;;;;;;;;;;;3152:45;;3212:11;3226:4;3231:1;3226:7;;;;;;;;;;;;;;;;;;:14;;;3212:28;;3260:27;3267:11;3280:6;3260:27;;;;;;;;;;;;;;;;;;;;;;;;;;;;3374:11;:20;;:28;3395:6;3374:28;;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;3374:28:0;3417:7;;;;3043:392;3478:4;3470:5;;:12;;;;;;;;;;;;;;;;;;3493:14;3510:1;3493:18;;3620;3641:5;3620:26;;3657:22;3697:6;3706:1;3697:10;;3692:474;3713:4;:11;;;;3709:1;:15;3692:474;;;3770:4;3775:1;3770:7;;;;;;;;;;;;;;;;;;:14;;;3758:9;:26;3746:38;;3799:13;3815:4;3820:1;3815:7;;;;;;;;;;;;;;;;;;:11;;;3799:27;;3906:14;3937:8;3924:10;:21;3923:71;;3984:10;3973:8;:21;3923:71;;;3962:8;3949:10;:21;3923:71;3906:88;;4028:9;4014:13;:23;4011:144;;;4087:9;4071:25;;4124:4;4129:1;4124:7;;;;;;;;;;;;;;;;;;:15;;;;;;;;;;;;4115:24;;4011:144;3692:474;;3726:3;;;;;;;3692:474;;;;4183:25;4190:6;4198:9;4183:25;;;;;;;;;;;;;;;;;;;;;;;;;;;;4522:6;:15;;:26;4538:9;4522:26;;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;4522:26:0;2607:1949;;;;;:::o;393:22::-;;;;:::o;5114:173::-;5196:11;;;;;;;;;;;5184:23;;:10;:23;;;5176:71;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;5265:14;5252:10;:27;;;;5114:173;:::o;4833:97::-;4895:4;4913;:12;;;4906:19;;4833:97;;;:::o

Swarm Source

bzzr://05985fc3cd6536dc70774f66377d8024467d7e388975f6bd1d84fd742ac10ea7
Block Transaction Difficulty Gas Used Reward
Block Uncle Number Difficulty Gas Used Reward
Loading

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.