Example #1
0
def _(properties, defaults=None) -> LockedTransferUnsignedState:
    defaults = defaults or LOCKED_TRANSFER_DEFAULTS
    parameters = _properties_to_dict(properties, defaults)

    lock = HashTimeLockState(
        amount=parameters.pop('amount'),
        expiration=parameters.pop('expiration'),
        secrethash=sha3(parameters.pop('secret')),
    )

    balance_proof_parameters = _properties_to_dict(
        parameters.pop('balance_proof'),
        defaults.balance_proof,
    )
    balance_proof_parameters['canonical_identifier'] = CanonicalIdentifier(
        chain_identifier=balance_proof_parameters.pop('chain_id'),
        token_network_address=balance_proof_parameters.pop(
            'token_network_identifier'),
        channel_identifier=balance_proof_parameters.pop('channel_identifier'),
    )
    if balance_proof_parameters['locksroot'] == EMPTY_MERKLE_ROOT:
        balance_proof_parameters['locksroot'] = lock.lockhash
    balance_proof = BalanceProofUnsignedState(**balance_proof_parameters)

    return LockedTransferUnsignedState(balance_proof=balance_proof,
                                       lock=lock,
                                       **parameters)
Example #2
0
def make_transfer(
    amount: typing.TokenAmount = EMPTY,
    initiator: typing.InitiatorAddress = EMPTY,
    target: typing.TargetAddress = EMPTY,
    expiration: typing.BlockExpiration = EMPTY,
    secret: typing.Secret = EMPTY,
    identifier: typing.PaymentID = EMPTY,
    nonce: typing.Nonce = EMPTY,
    transferred_amount: typing.TokenAmount = EMPTY,
    locked_amount: typing.TokenAmount = EMPTY,
    token_network_identifier: typing.TokenNetworkID = EMPTY,
    channel_identifier: typing.ChannelID = EMPTY,
    locksroot: typing.Locksroot = EMPTY,
    token: typing.TargetAddress = EMPTY,
) -> LockedTransferUnsignedState:
    amount = if_empty(amount, UNIT_TRANSFER_AMOUNT)
    initiator = if_empty(initiator, make_address())
    target = if_empty(target, make_address())
    expiration = if_empty(expiration, UNIT_REVEAL_TIMEOUT)
    secret = if_empty(secret, make_secret())
    identifier = if_empty(identifier, 1)
    nonce = if_empty(nonce, 1)
    transferred_amount = if_empty(transferred_amount, 0)
    token_network_identifier = if_empty(token_network_identifier,
                                        UNIT_TOKEN_NETWORK_ADDRESS)
    channel_identifier = if_empty(channel_identifier, UNIT_CHANNEL_ID)
    token = if_empty(token, UNIT_TOKEN_ADDRESS)

    secrethash = sha3(secret)
    lock = HashTimeLockState(
        amount=amount,
        expiration=expiration,
        secrethash=secrethash,
    )

    if locksroot is EMPTY:
        locksroot = lock.lockhash
        locked_amount = amount
    else:
        assert locked_amount

    unsigned_balance_proof = BalanceProofUnsignedState(
        nonce=nonce,
        transferred_amount=transferred_amount,
        locked_amount=locked_amount,
        locksroot=locksroot,
        token_network_identifier=token_network_identifier,
        channel_identifier=channel_identifier,
        chain_id=UNIT_CHAIN_ID,
    )

    return LockedTransferUnsignedState(
        payment_identifier=identifier,
        token=token,
        balance_proof=unsigned_balance_proof,
        lock=lock,
        initiator=initiator,
        target=target,
    )
Example #3
0
def make_transfer(amount,
                  initiator,
                  target,
                  expiration,
                  secret,
                  identifier=1,
                  nonce=1,
                  transferred_amount=0,
                  locked_amount=None,
                  channel_identifier=UNIT_CHANNEL_ADDRESS,
                  locksroot=None,
                  token=UNIT_TOKEN_ADDRESS):

    secrethash = sha3(secret)
    lock = HashTimeLockState(
        amount,
        expiration,
        secrethash,
    )

    if locksroot is None:
        locksroot = lock.lockhash
        locked_amount = amount
    else:
        assert locked_amount

    unsigned_balance_proof = BalanceProofUnsignedState(
        nonce,
        transferred_amount,
        locked_amount,
        locksroot,
        channel_identifier,
    )

    transfer_state = LockedTransferUnsignedState(
        identifier,
        UNIT_REGISTRY_IDENTIFIER,
        token,
        unsigned_balance_proof,
        lock,
        initiator,
        target,
    )

    return transfer_state
Example #4
0
def _(properties, defaults=None) -> LockedTransferUnsignedState:
    defaults = defaults or LOCKED_TRANSFER_DEFAULTS
    parameters = _properties_to_dict(properties, defaults)

    lock = HashTimeLockState(
        amount=parameters.pop('amount'),
        expiration=parameters.pop('expiration'),
        secrethash=sha3(parameters.pop('secret')),
    )

    balance_proof_parameters = _properties_to_dict(
        parameters.pop('balance_proof'),
        defaults.balance_proof,
    )
    if balance_proof_parameters['locksroot'] == EMPTY_MERKLE_ROOT:
        balance_proof_parameters['locksroot'] = lock.lockhash
    balance_proof = BalanceProofUnsignedState(**balance_proof_parameters)

    return LockedTransferUnsignedState(balance_proof=balance_proof,
                                       lock=lock,
                                       **parameters)