Example #1
0
def make_tx():
    return transaction_model.TransactionModel(dc_id="something",
                                              block_id="an id",
                                              txn_id="blah",
                                              txn_type="a type",
                                              tag="tags",
                                              timestamp="123",
                                              payload="a payload")
Example #2
0
def create_tx():
    return transaction_model.TransactionModel(
        dc_id="dc_id",
        block_id="123",
        txn_id="txn_id",
        timestamp="12345",
        txn_type="test",
        tag="tag",
        payload="payload",
        signature="signature",
        full_hash="full_hash",
        invoker="invoker",
    )
Example #3
0
 def test_from_input(self):
     meta = {
         "txn_type": "sotmething",
         "dc_id": "an id",
         "txn_id": "another id",
         "timestamp": "123456",
         "payload": "a payload",
         "tag": "a tag",
         "invoker": "a sweet invoker id",
         "full_hash": "a full hash",
         "signature": "a signature",
     }
     # Test new_from_user_input
     create_task = {
         "txn_type": meta["txn_type"],
         "payload": meta["payload"],
         "tag": meta["tag"]
     }
     user_input = {
         "version": "1",
         "txn_type": meta["txn_type"],
         "payload": meta["payload"],
         "tag": meta["tag"]
     }
     test = transaction_model.new_from_user_input(user_input)
     for key in create_task.keys():
         self.assertEqual(test.__dict__[key], meta[key])
     # Test new_from_queue_input
     queue_task = {
         "version": "2",
         "header": {
             "txn_type": meta["txn_type"],
             "dc_id": meta["dc_id"],
             "txn_id": meta["txn_id"],
             "timestamp": meta["timestamp"],
             "tag": meta["tag"],
             "invoker": meta["invoker"],
         },
         "payload": meta["payload"],
     }
     test = transaction_model.new_from_queue_input(queue_task)
     for key in meta.keys():
         if key != "full_hash" and key != "signature":
             self.assertEqual(test.__dict__[key], meta[key])
     # Test new_from_stripped_block_input
     txn = transaction_model.TransactionModel(**meta)
     test = transaction_model.new_from_stripped_block_input(
         json.dumps(txn.export_as_stripped(), separators=(",", ":")))
     for key in meta.keys():
         if key != "payload":
             self.assertEqual(test.__dict__[key], meta[key])
Example #4
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)
Example #5
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)