예제 #1
0
    def sign_transaction(self, transaction, private_key, public_key=None):
        """Sign a transaction

        Refer to the documentation of ``bigchaindb.util.sign_tx``
        """

        return util.sign_tx(transaction, private_key, public_key)
예제 #2
0
    def sign_transaction(transaction, private_key):
        """Sign a transaction

        Refer to the documentation of ``bigchaindb.util.sign_tx``
        """

        return util.sign_tx(transaction, private_key)
    def sign_transaction(transaction, private_key):
        """Sign a transaction

        Refer to the documentation of ``bigchaindb.util.sign_tx``
        """

        return util.sign_tx(transaction, private_key)
예제 #4
0
def test_transform_create(b, user_private_key, user_public_key):
    tx = util.create_tx(user_public_key, user_public_key, None, 'CREATE')
    tx = util.transform_create(tx)
    tx = util.sign_tx(tx, b.me_private)

    assert tx['transaction']['current_owner'] == b.me
    assert tx['transaction']['new_owner'] == user_public_key
    assert util.verify_signature(tx)
예제 #5
0
def test_transform_create(b, user_sk, user_vk):
    from bigchaindb import util
    tx = util.create_tx(user_vk, user_vk, None, 'CREATE')
    tx = util.transform_create(tx)
    tx = util.sign_tx(tx, b.me_private)

    assert tx['transaction']['fulfillments'][0]['current_owners'][0] == b.me
    assert tx['transaction']['conditions'][0]['new_owners'][0] == user_vk
    assert util.verify_signature(tx)
예제 #6
0
    def create(self, payload=None):
        """Issue a transaction to create an asset.

        Args:
            payload (dict): the payload for the transaction.

        Return:
            The transaction pushed to the Federation.
        """

        tx = util.create_tx(self.public_key,
                            self.public_key,
                            None,
                            operation='CREATE',
                            payload=payload)
        signed_tx = util.sign_tx(tx, self.private_key)
        return self._push(signed_tx)
예제 #7
0
    def transfer(self, new_owner, tx_input, payload=None):
        """Issue a transaction to transfer an asset.

        Args:
            new_owner (str): the public key of the new owner
            tx_input (str): the id of the transaction to use as input
            payload (dict, optional): the payload for the transaction.

        Return:
            The transaction pushed to the Federation.
        """

        tx = util.create_tx(self.public_key,
                            new_owner,
                            tx_input,
                            operation='TRANSFER',
                            payload=payload)
        signed_tx = util.sign_tx(tx, self.private_key)
        return self._push(signed_tx)
예제 #8
0
def create_transaction():
    """API endpoint to push transactions to the Federation.

    Return:
        A JSON string containing the data about the transaction.
    """
    bigchain = current_app.config['bigchain']

    val = {}

    # `force` will try to format the body of the POST request even if the `content-type` header is not
    # set to `application/json`
    tx = request.get_json(force=True)

    if tx['transaction']['operation'] == 'CREATE':
        tx = util.transform_create(tx)
        tx = util.sign_tx(tx, bigchain.me_private)

    if not util.verify_signature(tx):
        val['error'] = 'Invalid transaction signature'

    val = bigchain.write_transaction(tx)

    return flask.jsonify(**tx)