コード例 #1
0
ファイル: deploy.py プロジェクト: arjunhassard/nucypher
def transfer_tokens(general_config, actor_options, target_address, value,
                    allowance):
    """Transfer tokens from contract's owner address to another address"""

    emitter = general_config.emitter
    ADMINISTRATOR, deployer_address, _, local_registry = actor_options.create_actor(
        emitter)

    token_agent = ContractAgency.get_agent(
        NucypherTokenAgent,
        registry=local_registry)  # type: NucypherTokenAgent
    tokens = NU.from_nunits(token_agent.get_balance(deployer_address))
    emitter.echo(
        DISPLAY_SENDER_TOKEN_BALANCE_BEFORE_TRANSFER.format(
            token_balance=tokens))
    if not target_address:
        target_address = click.prompt(PROMPT_RECIPIENT_CHECKSUM_ADDRESS,
                                      type=EIP55_CHECKSUM_ADDRESS)
    if not value:
        stake_value_range = click.FloatRange(min=0, clamp=False)
        value = NU.from_tokens(
            click.prompt(PROMPT_TOKEN_VALUE, type=stake_value_range))

    value = NuNits(int(value))
    if allowance:
        confirmation = CONFIRM_TOKEN_ALLOWANCE.format(
            value=value,
            deployer_address=deployer_address,
            spender_address=target_address)
    else:
        confirmation = CONFIRM_TOKEN_TRANSFER.format(
            value=value,
            deployer_address=deployer_address,
            target_address=target_address)
    click.confirm(confirmation, abort=True)

    if allowance:
        receipt = token_agent.approve_transfer(amount=value,
                                               sender_address=deployer_address,
                                               spender_address=target_address)
    else:
        receipt = token_agent.transfer(amount=value,
                                       sender_address=deployer_address,
                                       target_address=target_address)
    paint_receipt_summary(emitter=emitter, receipt=receipt)
コード例 #2
0
ファイル: agents.py プロジェクト: KPrasch/nucypher
 def get_allowance(self, owner: ChecksumAddress,
                   spender: ChecksumAddress) -> NuNits:
     """Check the amount of tokens that an owner allowed to a spender"""
     allowance: int = self.contract.functions.allowance(owner,
                                                        spender).call()
     return NuNits(allowance)
コード例 #3
0
ファイル: agents.py プロジェクト: KPrasch/nucypher
 def get_balance(self, address: ChecksumAddress) -> NuNits:
     """Get the NU balance (in NuNits) of a token holder address, or of this contract address"""
     balance: int = self.contract.functions.balanceOf(address).call()
     return NuNits(balance)
コード例 #4
0
ファイル: token.py プロジェクト: orionNode/nucypher
 def to_nunits(self) -> NuNits:
     """Returns an int value in NuNit"""
     return NuNits(self.__value)