예제 #1
0
def ledger_contract_action(action: str, txn_type: str, entrypoint: str, image_digest: str) -> None:
    """Ledgers contract data when submit contract is a success
    Args:
        action (Enum): Which action to perform when ledgering
        txn_type (str): Transaction type to post to the chain
        image_digest (str): Docker image SHA-256 to use in ledgering
    """
    model = transaction_model.TransactionModel(
        txn_type=namespace.Namespaces.Contract.value,
        dc_id=keys.get_public_id(),
        txn_id=str(uuid.uuid4()),
        tag=f"contract:{txn_type}",
        timestamp=str(int(time.time())),
        payload={"action": action, "txn_type": txn_type, "contract_entrypoint": entrypoint, "image_digest": image_digest},
    )
    queue.enqueue_generic(model.export_as_queue_task(), queue=queue.INCOMING_TX_KEY, deadline=0)
예제 #2
0
    def submit_invocation_request(self) -> None:
        """Submit this model as an invocation request to the queue to be handled by the contract invoker"""
        contract_model = smart_contract_model.SmartContractModel(
            txn_type=self.txn_type,
            sc_id=self.id,
            execution_order=self.execution_order)
        txn_model = transaction_model.TransactionModel(
            txn_type=self.txn_type,
            dc_id=keys.get_public_id(),
            txn_id="cron",
            timestamp=str(int(time.time())),
            payload={})
        invoke_request = contract_model.export_as_invoke_request(
            invoke_transaction=txn_model.export_as_queue_task(
                dict_payload=True))

        _log.info(
            f"Sending invocation request for txn_type: {self.txn_type} contract_id: {self.id}"
        )
        queue.enqueue_generic(content=invoke_request,
                              queue=queue.CONTRACT_INVOKE_MQ_KEY,
                              deadline=0)