Beispiel #1
0
    def handle(self, *args, **options):
        # config
        block = 'latest'

        # setup
        network = options['network']
        web3 = get_web3(network)
        contract_address = getStandardBountiesContractAddresss(network)
        contract = getBountyContract(network)
        last_block_hash = None

        while True:
            # wait for a new block
            block = web3.eth.getBlock('latest')
            block_hash = block['hash']

            if last_block_hash == block_hash:
                time.sleep(1)
                continue

            print('got new block %s' % web3.toHex(block_hash))

            # get txs
            transactions = block['transactions']
            for tx in transactions:
                tx = web3.eth.getTransaction(tx)
                if not tx or tx['to'] != contract_address:
                    continue

                print('found a stdbounties tx')
                data = tx['input']
                method_id = data[:10]
                if method_id == '0x7e9e511d':
                    # issueAndActivateBounty
                    bounty_id = contract.functions.getNumBounties().call() - 1
                else:
                    # any other method
                    bounty_id = int(data[10:74], 16)
                print('process_bounty %d' % bounty_id)
                process_bounty(bounty_id, network)
                print('done process_bounty %d' % bounty_id)

            last_block_hash = block_hash
Beispiel #2
0
 def test_get_bounty_contract():
     assert getBountyContract(
         'mainnet').address == "0x2af47a65da8CD66729b4209C22017d6A5C2d2400"
Beispiel #3
0
def get_bounty_id(_id, network):
    if _id > 0:
        return _id
    contract = getBountyContract(network)
    bounty_id = contract.functions.getNumBounties().call() - 1
    return bounty_id + _id