Esempio n. 1
0
def close_asset(name):
    """Create an CloseOffer txn and wrap it in a Batch and list.
    Args:
        name (str): The identifier of the Offer.
    Returns:
        tuple: List of Batch, signature tuple
    """
    global context
    global signer

    batcher_private_key = Secp256k1PrivateKey.from_hex(BATCHER_PRIVATE_KEY)
    batcher_signer = CryptoFactory(context).new_signer(batcher_private_key)

    public_key = signer.get_public_key().as_hex()

    inputs = [addresshandler.make_asset_address(asset_id=name)]

    outputs = [addresshandler.make_asset_address(asset_id=name)]

    close_txn = payload_pb2.CloseAsset(
        name=name)

    payload = payload_pb2.TransactionPayload(
        payload_type=payload_pb2.TransactionPayload.CLOSE_ASSET,
        close_asset=close_txn)

    return make_header_and_batch(
        payload=payload,
        inputs=inputs,
        outputs=outputs,
        txn_key=signer,
        batch_key=batcher_signer)
Esempio n. 2
0
def create_asset(name, description, no_steps, rules):
    """Create a CreateAsset txn and wrap it in a batch and list.
    Args:
        name (str): The name of the asset.
        description (str): A description of the asset.
        no_steps (int): number of approval steps for asset
        rules (list): List of protobuf.rule_pb2.Rule
    Returns:
        tuple: List of Batch, signature tuple
    """
    
    global context
    global signer

    #context = create_context('secp256k1')
    #private_key = context.new_random_private_key()
    #signer = CryptoFactory(context).new_signer(private_key)

    batcher_private_key = Secp256k1PrivateKey.from_hex(BATCHER_PRIVATE_KEY)
    batcher_signer = CryptoFactory(context).new_signer(batcher_private_key)

    public_key = signer.get_public_key().as_hex()

    inputs = [addresshandler.make_asset_address(asset_id=name),
              addresshandler.make_account_address(account_id=public_key)]

    outputs = [addresshandler.make_asset_address(asset_id=name)]

    asset = payload_pb2.CreateAsset(
        name=name,
        description=description,
        num_steps=no_steps,
        rules=rules
    )

    payload = payload_pb2.TransactionPayload(
        payload_type=payload_pb2.TransactionPayload.CREATE_ASSET,
        create_asset=asset)

    return make_header_and_batch(
        payload=payload,
        inputs=inputs,
        outputs=outputs,
        txn_key=signer,
        batch_key=batcher_signer)
Esempio n. 3
0
    def close_asset(self, name):
        address = addresshandler.make_asset_address(name)

        container = self._get_asset_container(self._state_entries, address)
        asset = None
        try:
            asset = self._delete_asset_from_container(container, name)
        except KeyError:
            # We are fine with returning None for an asset that doesn't exist
            pass

        return self._context.delete_state([address], self._timeout)
Esempio n. 4
0
    def get_asset(self, name):
        address = addresshandler.make_asset_address(asset_id=name)

        self._state_entries.extend(
            self._context.get_state(addresses=[address],
                                    timeout=self._timeout))

        container = self._get_asset_container(self._state_entries, address)
        asset = None
        try:
            asset = self._get_asset_from_container(container, name)
        except KeyError:
            # We are fine with returning None for an asset that doesn't exist
            pass
        return asset
Esempio n. 5
0
def approve_asset(name,
                apprvl_step):
    """Create an AcceptOffer txn and wrap it in a Batch and list.
    Args:
        name (str): The identifier of the Offer.
        apprvl_step (int): The number of units of exchange.
    Returns:
        tuple: List of Batch, signature tuple
    """
    global context
    global signer

    batcher_private_key = Secp256k1PrivateKey.from_hex(BATCHER_PRIVATE_KEY)
    batcher_signer = CryptoFactory(context).new_signer(batcher_private_key)

    public_key = signer.get_public_key().as_hex()
    
    inputs = [addresshandler.make_asset_address(asset_id=name),
              addresshandler.make_account_address(account_id=public_key)]

    outputs = [addresshandler.make_asset_address(asset_id=name)]

    approve_txn = payload_pb2.ApproveAsset(
        name=name,
        approval_step=apprvl_step)

    payload = payload_pb2.TransactionPayload(
        payload_type=payload_pb2.TransactionPayload.APPROVE_ASSET,
        approve_asset=approve_txn)

    return make_header_and_batch(
        payload=payload,
        inputs=inputs,
        outputs=outputs,
        txn_key=signer,
        batch_key=batcher_signer)
Esempio n. 6
0
    def approve_asset(self, name, approver_level):
        address = addresshandler.make_asset_address(name)

        container = self._get_asset_container(self._state_entries, address)

        try:
            asset = self._get_asset_from_container(container, name)
        except KeyError:
            #asset = container.entries.add()
            print("Asset {} not found for approval".format(name))

        if (asset.curr_step <= approver_level) and (asset.curr_step <=
                                                    asset.num_steps):
            asset.curr_step = asset.curr_step + 1

        state_entries_send = {}
        state_entries_send[address] = container.SerializeToString()
        return self._context.set_state(state_entries_send, self._timeout)
Esempio n. 7
0
    def set_asset(self, name, description, num_steps, rules):
        address = addresshandler.make_asset_address(name)

        container = self._get_asset_container(self._state_entries, address)

        try:
            asset = self._get_asset_from_container(container, name)
        except KeyError:
            asset = container.entries.add()

        asset.name = name
        asset.description = description
        asset.num_steps = num_steps
        asset.rules.extend(rules)

        state_entries_send = {}
        state_entries_send[address] = container.SerializeToString()
        return self._context.set_state(state_entries_send, self._timeout)