Beispiel #1
0
def _new_payment_command_transaction(command: offchain.PaymentCommand,
                                     status: TransactionStatus) -> Transaction:
    payment = command.payment
    sender_address, source_subaddress = _account_address_and_subaddress(
        payment.sender.address)
    destination_address, destination_subaddress = _account_address_and_subaddress(
        payment.receiver.address)
    source_id = get_account_id_from_subaddr(source_subaddress)
    destination_id = get_account_id_from_subaddr(destination_subaddress)

    return Transaction(
        type=TransactionType.OFFCHAIN,
        status=status,
        amount=payment.action.amount,
        currency=payment.action.currency,
        created_timestamp=datetime.utcnow(),
        source_id=source_id,
        source_address=sender_address,
        source_subaddress=source_subaddress,
        destination_id=destination_id,
        destination_address=destination_address,
        destination_subaddress=destination_subaddress,
        reference_id=command.reference_id(),
        command_json=offchain.to_json(command),
    )
 def _create_payment_command(self,
                             account_id: str,
                             cmd: offchain.PaymentCommand,
                             validate: bool = False) -> None:
     self.app.store.create(
         PaymentCommand,
         before_create=lambda _: cmd.validate(None) if validate else None,
         account_id=account_id,
         is_sender=cmd.is_sender(),
         reference_id=cmd.reference_id(),
         is_inbound=cmd.is_inbound(),
         cid=cmd.id(),
         payment_object=asdict(cmd.payment),
     )
Beispiel #3
0
def _lock_and_save_inbound_command(
        command: offchain.PaymentCommand) -> Transaction:
    def validate_and_save(txn: Optional[Transaction]) -> Transaction:
        if txn:
            prior = _txn_payment_command(txn)
            if command == prior:
                return
            command.validate(prior)
            txn.command_json = offchain.to_json(command)
            txn.status = _command_transaction_status(
                command, TransactionStatus.OFF_CHAIN_INBOUND)
        else:
            txn = _new_payment_command_transaction(
                command, TransactionStatus.OFF_CHAIN_INBOUND)
        return txn

    return lock_for_update(command.reference_id(), validate_and_save)
Beispiel #4
0
 def _enqueue_follow_up_action(self,
                               command: offchain.PaymentCommand) -> None:
     if command.follow_up_action():
         self.task_queue.append(lambda app: app._offchain_business_action(
             command.reference_id()))