mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 22:45:44 +00:00
__init__ transfer now uses multiple assets
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
e32047d999
commit
ebc1a4d85e
@ -105,7 +105,7 @@ class Transaction(object):
|
||||
# dicts holding a `data` property. Asset payloads for 'TRANSFER'
|
||||
# operations must be dicts holding an `id` property.
|
||||
|
||||
# Changes: CREATE needs list of 1 asset that holds data in asset or None
|
||||
# NOTE: Changes: CREATE needs list of 1 asset that holds data in asset or None
|
||||
if (operation == self.CREATE and
|
||||
assets is not None and not (isinstance(assets, list) and 'data' in assets[0])):
|
||||
raise TypeError(('`asset` must be None or a list of length 1 with a dict holding a `data` '
|
||||
@ -114,10 +114,14 @@ class Transaction(object):
|
||||
# asset is not None and not (isinstance(asset, dict) and 'data' in asset)):
|
||||
# raise TypeError(('`asset` must be None or a dict holding a `data` '
|
||||
# " property instance for '{}' Transactions".format(operation)))
|
||||
# NOTE: Changes: TRANSFER needs a list of at least on asset that holds id in each asset
|
||||
elif (operation == self.TRANSFER and
|
||||
not (isinstance(assets, dict) and 'id' in assets)):
|
||||
raise TypeError(('`asset` must be a dict holding an `id` property '
|
||||
'for \'TRANSFER\' Transactions'))
|
||||
assets is not None and not (isinstance(assets, list) and all('id' in asset for asset in assets))):
|
||||
raise TypeError(('`asset` must be a list containing dicts holding an `id` property'))
|
||||
# elif (operation == self.TRANSFER and
|
||||
# not (isinstance(assets, dict) and 'id' in assets)):
|
||||
# raise TypeError(('`asset` must be a dict holding an `id` property '
|
||||
# 'for \'TRANSFER\' Transactions'))
|
||||
|
||||
if outputs and not isinstance(outputs, list):
|
||||
raise TypeError('`outputs` must be a list instance or None')
|
||||
@ -567,7 +571,7 @@ class Transaction(object):
|
||||
return Transaction._to_str(tx)
|
||||
|
||||
@classmethod
|
||||
def get_asset_id(cls, transactions):
|
||||
def get_asset_ids(cls, transactions):
|
||||
"""Get the asset id from a list of :class:`~.Transactions`.
|
||||
|
||||
This is useful when we want to check if the multiple inputs of a
|
||||
@ -607,7 +611,7 @@ class Transaction(object):
|
||||
else:
|
||||
asset_ids.extend([asset['id'] for asset in tx.assets])
|
||||
|
||||
return asset_ids.pop()
|
||||
return asset_ids
|
||||
|
||||
@staticmethod
|
||||
def validate_id(tx_body):
|
||||
|
||||
@ -23,7 +23,7 @@ def test_validate_transfer_asset_id_mismatch(b, signed_create_tx, user_pk, user_
|
||||
from planetmint.transactions.common.exceptions import AssetIdMismatch
|
||||
|
||||
tx_transfer = Transfer.generate(signed_create_tx.to_inputs(), [([user_pk], 1)],
|
||||
signed_create_tx.id)
|
||||
[signed_create_tx.id])
|
||||
tx_transfer.asset['id'] = 'a' * 64
|
||||
tx_transfer_signed = tx_transfer.sign([user_sk])
|
||||
|
||||
@ -36,15 +36,15 @@ def test_validate_transfer_asset_id_mismatch(b, signed_create_tx, user_pk, user_
|
||||
def test_get_asset_id_create_transaction(alice, user_pk):
|
||||
from planetmint.models import Transaction
|
||||
tx_create = Create.generate([alice.public_key], [([user_pk], 1)])
|
||||
assert Transaction.get_asset_id(tx_create) == tx_create.id
|
||||
assert Transaction.get_asset_ids(tx_create) == tx_create.id
|
||||
|
||||
|
||||
def test_get_asset_id_transfer_transaction(b, signed_create_tx, user_pk):
|
||||
from planetmint.models import Transaction
|
||||
|
||||
tx_transfer = Transfer.generate(signed_create_tx.to_inputs(), [([user_pk], 1)],
|
||||
signed_create_tx.id)
|
||||
asset_id = Transaction.get_asset_id(tx_transfer)
|
||||
[signed_create_tx.id])
|
||||
asset_id = Transaction.get_asset_ids(tx_transfer)
|
||||
assert asset_id == tx_transfer.asset['id']
|
||||
|
||||
# This test is not relevant anymore
|
||||
@ -60,7 +60,7 @@ def test_asset_id_mismatch(alice, user_pk):
|
||||
tx2.sign([alice.private_key])
|
||||
|
||||
with pytest.raises(AssetIdMismatch):
|
||||
Transaction.get_asset_id([tx1, tx2])
|
||||
Transaction.get_asset_ids([tx1, tx2])
|
||||
|
||||
|
||||
def test_create_valid_divisible_asset(b, user_pk, user_sk):
|
||||
|
||||
@ -26,7 +26,7 @@ def test_get_txids_filtered(signed_create_tx, signed_transfer_tx):
|
||||
conn.db.transactions.insert_one(signed_create_tx.to_dict())
|
||||
conn.db.transactions.insert_one(signed_transfer_tx.to_dict())
|
||||
|
||||
asset_id = Transaction.get_asset_id([signed_create_tx, signed_transfer_tx])
|
||||
asset_id = Transaction.get_asset_ids([signed_create_tx, signed_transfer_tx])
|
||||
|
||||
# Test get by just asset id
|
||||
txids = set(query.get_txids_filtered(conn, asset_id))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user