Exemple #1
0
def set_can_call(chain, authority, caller_address, code_address, can_call,
                 function_signature):
    sig_as_hex = function_signature_to_4byte_selector(function_signature)
    sig_as_bytes = decode_hex(sig_as_hex)

    can_already_call = authority.call().canCall(
        callerAddress=caller_address,
        codeAddress=code_address,
        sig=sig_as_bytes,
    )
    if can_already_call:
        click.echo(
            "Permissions already set for: {0}".format(function_signature))
        return

    click.echo("Setting up permissions for:\n"
               "- function: {0}\n"
               "- sig: {1}\n"
               "- caller_address: {2}\n"
               "- code_address: {3}\n"
               "- can_call: {4}".format(
                   function_signature,
                   sig_as_hex,
                   caller_address,
                   code_address,
                   ("Yes" if can_call else "No"),
               ))
    click.echo("Sending authorization transaction... ", nl=False)
    authorize_txn_hash = authority.transact().setCanCall(
        callerAddress=caller_address,
        codeAddress=code_address,
        sig=sig_as_bytes,
        can=can_call,
    )
    click.echo("SENT")
    click.echo("Authorize Transaction Hash: {0}".format(authorize_txn_hash))
    click.echo("Waiting for transaction to be mined... ", nl=False)
    chain.wait.for_receipt(authorize_txn_hash, timeout=600)
    click.echo("MINED")

    check_can_call = authority.call().canCall(
        callerAddress=caller_address,
        codeAddress=code_address,
        sig=sig_as_bytes,
    )
    if check_can_call is not can_call:
        click.echo("Something went wrong.  Authorization did not go though")
        import pdb
        pdb.set_trace()
        raise ValueError("Failed to set authorization")
    return
Exemple #2
0
 def _whitelist_call(code_address, function_signature, can_call):
     sig = decode_hex(
         function_signature_to_4byte_selector(function_signature))
     chain.wait.for_receipt(
         authority.transact({
             'from': authority.call().owner(),
         }).setAnyoneCanCall(
             codeAddress=code_address,
             sig=sig,
             can=can_call,
         ))
     assert authority.call().canCall(
         '0x0000000000000000000000000000000000000000',
         codeAddress=code_address,
         sig=sig,
     ) is can_call
Exemple #3
0
 def _authorize_call(caller_address, code_address, function_signature,
                     can_call):
     sig = decode_hex(
         function_signature_to_4byte_selector(function_signature))
     chain.wait.for_receipt(
         authority.transact({
             'from': authority.call().authority(),
         }).setCanCall(
             callerAddress=caller_address,
             codeAddress=code_address,
             sig=sig,
             can=can_call,
         ))
     assert authority.call().canCall(
         callerAddress=caller_address,
         codeAddress=code_address,
         sig=sig,
     ) is can_call