本文整理汇总了Python中bigchaindb.models.Transaction.transfer方法的典型用法代码示例。如果您正苦于以下问题:Python Transaction.transfer方法的具体用法?Python Transaction.transfer怎么用?Python Transaction.transfer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bigchaindb.models.Transaction
的用法示例。
在下文中一共展示了Transaction.transfer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_spent_with_double_spend_detected
# 需要导入模块: from bigchaindb.models import Transaction [as 别名]
# 或者: from bigchaindb.models.Transaction import transfer [as 别名]
def test_get_spent_with_double_spend_detected(self, b, alice):
from bigchaindb.models import Transaction
from bigchaindb.common.exceptions import DoubleSpend
from bigchaindb.exceptions import CriticalDoubleSpend
tx = Transaction.create([alice.public_key], [([alice.public_key], 1)])
tx = tx.sign([alice.private_key])
b.store_bulk_transactions([tx])
transfer_tx = Transaction.transfer(tx.to_inputs(), [([alice.public_key], 1)],
asset_id=tx.id)
transfer_tx = transfer_tx.sign([alice.private_key])
transfer_tx2 = Transaction.transfer(tx.to_inputs(), [([alice.public_key], 2)],
asset_id=tx.id)
transfer_tx2 = transfer_tx2.sign([alice.private_key])
with pytest.raises(DoubleSpend):
b.validate_transaction(transfer_tx2, [transfer_tx])
b.store_bulk_transactions([transfer_tx])
with pytest.raises(DoubleSpend):
b.validate_transaction(transfer_tx2)
b.store_bulk_transactions([transfer_tx2])
with pytest.raises(CriticalDoubleSpend):
b.get_spent(tx.id, 0)
示例2: test_post_transaction_responses
# 需要导入模块: from bigchaindb.models import Transaction [as 别名]
# 或者: from bigchaindb.models.Transaction import transfer [as 别名]
def test_post_transaction_responses(tendermint_ws_url, b):
from bigchaindb.common.crypto import generate_key_pair
from bigchaindb.models import Transaction
alice = generate_key_pair()
bob = generate_key_pair()
tx = Transaction.create([alice.public_key],
[([alice.public_key], 1)],
asset=None)\
.sign([alice.private_key])
code, message = b.write_transaction(tx, 'broadcast_tx_commit')
assert code == 202
tx_transfer = Transaction.transfer(tx.to_inputs(),
[([bob.public_key], 1)],
asset_id=tx.id)\
.sign([alice.private_key])
code, message = b.write_transaction(tx_transfer, 'broadcast_tx_commit')
assert code == 202
carly = generate_key_pair()
double_spend = Transaction.transfer(
tx.to_inputs(),
[([carly.public_key], 1)],
asset_id=tx.id,
).sign([alice.private_key])
for mode in ('broadcast_tx_sync', 'broadcast_tx_commit'):
code, message = b.write_transaction(double_spend, mode)
assert code == 500
assert message == 'Transaction validation failed'
示例3: test_amount_error_transfer
# 需要导入模块: from bigchaindb.models import Transaction [as 别名]
# 或者: from bigchaindb.models.Transaction import transfer [as 别名]
def test_amount_error_transfer(alice, b, user_pk, user_sk):
from bigchaindb.models import Transaction
from bigchaindb.common.exceptions import AmountError
# CREATE divisible asset
tx_create = Transaction.create([alice.public_key], [([user_pk], 100)], asset={'name': random.random()})
tx_create_signed = tx_create.sign([alice.private_key])
b.store_bulk_transactions([tx_create_signed])
# TRANSFER
# output amount less than input amount
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [([alice.public_key], 50)],
asset_id=tx_create.id)
tx_transfer_signed = tx_transfer.sign([user_sk])
with pytest.raises(AmountError):
tx_transfer_signed.validate(b)
# TRANSFER
# output amount greater than input amount
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [([alice.public_key], 101)],
asset_id=tx_create.id)
tx_transfer_signed = tx_transfer.sign([user_sk])
with pytest.raises(AmountError):
tx_transfer_signed.validate(b)
示例4: test_get_spent_key_order
# 需要导入模块: from bigchaindb.models import Transaction [as 别名]
# 或者: from bigchaindb.models.Transaction import transfer [as 别名]
def test_get_spent_key_order(b, user_pk, user_sk, user2_pk, user2_sk):
from bigchaindb import backend
from bigchaindb.models import Transaction
from bigchaindb.common.crypto import generate_key_pair
from bigchaindb.common.exceptions import DoubleSpend
alice = generate_key_pair()
bob = generate_key_pair()
tx1 = Transaction.create([user_pk],
[([alice.public_key], 3), ([user_pk], 2)],
asset=None)\
.sign([user_sk])
b.store_bulk_transactions([tx1])
inputs = tx1.to_inputs()
tx2 = Transaction.transfer([inputs[1]], [([user2_pk], 2)], tx1.id).sign([user_sk])
assert tx2.validate(b)
tx2_dict = tx2.to_dict()
fulfills = tx2_dict['inputs'][0]['fulfills']
tx2_dict['inputs'][0]['fulfills'] = {'output_index': fulfills['output_index'],
'transaction_id': fulfills['transaction_id']}
backend.query.store_transactions(b.connection, [tx2_dict])
tx3 = Transaction.transfer([inputs[1]], [([bob.public_key], 2)], tx1.id).sign([user_sk])
with pytest.raises(DoubleSpend):
tx3.validate(b)
示例5: test_get_divisble_transactions_returns_500
# 需要导入模块: from bigchaindb.models import Transaction [as 别名]
# 或者: from bigchaindb.models.Transaction import transfer [as 别名]
def test_get_divisble_transactions_returns_500(b, client):
from bigchaindb.models import Transaction
from bigchaindb.common import crypto
import json
TX_ENDPOINT = '/api/v1/transactions'
def mine(tx_list):
b.store_bulk_transactions(tx_list)
alice_priv, alice_pub = crypto.generate_key_pair()
bob_priv, bob_pub = crypto.generate_key_pair()
carly_priv, carly_pub = crypto.generate_key_pair()
create_tx = Transaction.create([alice_pub], [([alice_pub], 4)])
create_tx.sign([alice_priv])
res = client.post(TX_ENDPOINT, data=json.dumps(create_tx.to_dict()))
assert res.status_code == 202
mine([create_tx])
transfer_tx = Transaction.transfer(create_tx.to_inputs(),
[([alice_pub], 3), ([bob_pub], 1)],
asset_id=create_tx.id)
transfer_tx.sign([alice_priv])
res = client.post(TX_ENDPOINT, data=json.dumps(transfer_tx.to_dict()))
assert res.status_code == 202
mine([transfer_tx])
transfer_tx_carly = Transaction.transfer([transfer_tx.to_inputs()[1]],
[([carly_pub], 1)],
asset_id=create_tx.id)
transfer_tx_carly.sign([bob_priv])
res = client.post(TX_ENDPOINT, data=json.dumps(transfer_tx_carly.to_dict()))
assert res.status_code == 202
mine([transfer_tx_carly])
asset_id = create_tx.id
url = TX_ENDPOINT + '?asset_id=' + asset_id
assert client.get(url).status_code == 200
assert len(client.get(url).json) == 3
url = OUTPUTS_ENDPOINT + '?public_key=' + alice_pub
assert client.get(url).status_code == 200
url = OUTPUTS_ENDPOINT + '?public_key=' + bob_pub
assert client.get(url).status_code == 200
url = OUTPUTS_ENDPOINT + '?public_key=' + carly_pub
assert client.get(url).status_code == 200
示例6: test_get_spent_issue_1271
# 需要导入模块: from bigchaindb.models import Transaction [as 别名]
# 或者: from bigchaindb.models.Transaction import transfer [as 别名]
def test_get_spent_issue_1271(b, alice, bob, carol):
from bigchaindb.models import Transaction
tx_1 = Transaction.create(
[carol.public_key],
[([carol.public_key], 8)],
).sign([carol.private_key])
assert tx_1.validate(b)
b.store_bulk_transactions([tx_1])
tx_2 = Transaction.transfer(
tx_1.to_inputs(),
[([bob.public_key], 2),
([alice.public_key], 2),
([carol.public_key], 4)],
asset_id=tx_1.id,
).sign([carol.private_key])
assert tx_2.validate(b)
b.store_bulk_transactions([tx_2])
tx_3 = Transaction.transfer(
tx_2.to_inputs()[2:3],
[([alice.public_key], 1),
([carol.public_key], 3)],
asset_id=tx_1.id,
).sign([carol.private_key])
assert tx_3.validate(b)
b.store_bulk_transactions([tx_3])
tx_4 = Transaction.transfer(
tx_2.to_inputs()[1:2] + tx_3.to_inputs()[0:1],
[([bob.public_key], 3)],
asset_id=tx_1.id,
).sign([alice.private_key])
assert tx_4.validate(b)
b.store_bulk_transactions([tx_4])
tx_5 = Transaction.transfer(
tx_2.to_inputs()[0:1],
[([alice.public_key], 2)],
asset_id=tx_1.id,
).sign([bob.private_key])
assert tx_5.validate(b)
b.store_bulk_transactions([tx_5])
assert b.get_spent(tx_2.id, 0) == tx_5
assert not b.get_spent(tx_5.id, 0)
assert b.get_outputs_filtered(alice.public_key)
assert b.get_outputs_filtered(alice.public_key, spent=False)
示例7: test_get_spent_multiple_owners
# 需要导入模块: from bigchaindb.models import Transaction [as 别名]
# 或者: from bigchaindb.models.Transaction import transfer [as 别名]
def test_get_spent_multiple_owners(self, b, user_sk, user_pk, alice):
from bigchaindb.common import crypto
from bigchaindb.models import Transaction
user2_sk, user2_pk = crypto.generate_key_pair()
user3_sk, user3_pk = crypto.generate_key_pair()
transactions = []
for i in range(3):
payload = {'somedata': i}
tx = Transaction.create([alice.public_key], [([user_pk, user2_pk], 1)],
payload)
tx = tx.sign([alice.private_key])
transactions.append(tx)
b.store_bulk_transactions(transactions)
owned_inputs_user1 = b.fastquery.get_outputs_by_public_key(user_pk)
# check spents
for input_tx in owned_inputs_user1:
assert b.get_spent(input_tx.txid, input_tx.output) is None
# create a transaction
tx = Transaction.transfer(transactions[0].to_inputs(),
[([user3_pk], 1)],
asset_id=transactions[0].id)
tx = tx.sign([user_sk, user2_sk])
b.store_bulk_transactions([tx])
# check that used inputs are marked as spent
assert b.get_spent(transactions[0].id, 0) == tx
# check that the other remain marked as unspent
for unspent in transactions[1:]:
assert b.get_spent(unspent.id, 0) is None
示例8: test_get_spent_single_tx_single_output
# 需要导入模块: from bigchaindb.models import Transaction [as 别名]
# 或者: from bigchaindb.models.Transaction import transfer [as 别名]
def test_get_spent_single_tx_single_output(self, b, user_sk, user_pk, alice):
from bigchaindb.common import crypto
from bigchaindb.models import Transaction
user2_sk, user2_pk = crypto.generate_key_pair()
tx = Transaction.create([alice.public_key], [([user_pk], 1)])
tx = tx.sign([alice.private_key])
b.store_bulk_transactions([tx])
owned_inputs_user1 = b.fastquery.get_outputs_by_public_key(user_pk).pop()
# check spents
input_txid = owned_inputs_user1.txid
spent_inputs_user1 = b.get_spent(input_txid, 0)
assert spent_inputs_user1 is None
# create a transaction and send it
tx = Transaction.transfer(tx.to_inputs(), [([user2_pk], 1)],
asset_id=tx.id)
tx = tx.sign([user_sk])
b.store_bulk_transactions([tx])
spent_inputs_user1 = b.get_spent(input_txid, 0)
assert spent_inputs_user1 == tx
示例9: test_get_owned_ids_multiple_owners
# 需要导入模块: from bigchaindb.models import Transaction [as 别名]
# 或者: from bigchaindb.models.Transaction import transfer [as 别名]
def test_get_owned_ids_multiple_owners(self, b, user_sk, user_pk, alice):
from bigchaindb.common import crypto
from bigchaindb.common.transaction import TransactionLink
from bigchaindb.models import Transaction
user2_sk, user2_pk = crypto.generate_key_pair()
user3_sk, user3_pk = crypto.generate_key_pair()
tx = Transaction.create([alice.public_key], [([user_pk, user2_pk], 1)])
tx = tx.sign([alice.private_key])
b.store_bulk_transactions([tx])
owned_inputs_user1 = b.fastquery.get_outputs_by_public_key(user_pk)
owned_inputs_user2 = b.fastquery.get_outputs_by_public_key(user_pk)
expected_owned_inputs_user1 = [TransactionLink(tx.id, 0)]
assert owned_inputs_user1 == owned_inputs_user2
assert owned_inputs_user1 == expected_owned_inputs_user1
tx = Transaction.transfer(tx.to_inputs(), [([user3_pk], 1)],
asset_id=tx.id)
tx = tx.sign([user_sk, user2_sk])
b.store_bulk_transactions([tx])
owned_inputs_user1 = b.fastquery.get_outputs_by_public_key(user_pk)
owned_inputs_user2 = b.fastquery.get_outputs_by_public_key(user2_pk)
spent_user1 = b.get_spent(tx.id, 0)
assert owned_inputs_user1 == owned_inputs_user2
assert not spent_user1
示例10: test_get_owned_ids_single_tx_multiple_outputs
# 需要导入模块: from bigchaindb.models import Transaction [as 别名]
# 或者: from bigchaindb.models.Transaction import transfer [as 别名]
def test_get_owned_ids_single_tx_multiple_outputs(self, b, user_sk,
user_pk, alice):
from bigchaindb.common import crypto
from bigchaindb.common.transaction import TransactionLink
from bigchaindb.models import Transaction
user2_sk, user2_pk = crypto.generate_key_pair()
# create divisible asset
tx_create = Transaction.create([alice.public_key], [([user_pk], 1), ([user_pk], 1)])
tx_create_signed = tx_create.sign([alice.private_key])
b.store_bulk_transactions([tx_create_signed])
# get input
owned_inputs_user1 = b.fastquery.get_outputs_by_public_key(user_pk)
owned_inputs_user2 = b.fastquery.get_outputs_by_public_key(user2_pk)
expected_owned_inputs_user1 = [TransactionLink(tx_create.id, 0),
TransactionLink(tx_create.id, 1)]
assert owned_inputs_user1 == expected_owned_inputs_user1
assert owned_inputs_user2 == []
# transfer divisible asset divided in two outputs
tx_transfer = Transaction.transfer(tx_create.to_inputs(),
[([user2_pk], 1), ([user2_pk], 1)],
asset_id=tx_create.id)
tx_transfer_signed = tx_transfer.sign([user_sk])
b.store_bulk_transactions([tx_transfer_signed])
owned_inputs_user1 = b.fastquery.get_outputs_by_public_key(user_pk)
owned_inputs_user2 = b.fastquery.get_outputs_by_public_key(user2_pk)
assert owned_inputs_user1 == expected_owned_inputs_user1
assert owned_inputs_user2 == [TransactionLink(tx_transfer.id, 0),
TransactionLink(tx_transfer.id, 1)]
示例11: test_get_owned_ids_single_tx_single_output
# 需要导入模块: from bigchaindb.models import Transaction [as 别名]
# 或者: from bigchaindb.models.Transaction import transfer [as 别名]
def test_get_owned_ids_single_tx_single_output(self, b, user_sk, user_pk, alice):
from bigchaindb.common import crypto
from bigchaindb.common.transaction import TransactionLink
from bigchaindb.models import Transaction
user2_sk, user2_pk = crypto.generate_key_pair()
tx = Transaction.create([alice.public_key], [([user_pk], 1)])
tx = tx.sign([alice.private_key])
b.store_bulk_transactions([tx])
owned_inputs_user1 = b.fastquery.get_outputs_by_public_key(user_pk)
owned_inputs_user2 = b.fastquery.get_outputs_by_public_key(user2_pk)
assert owned_inputs_user1 == [TransactionLink(tx.id, 0)]
assert owned_inputs_user2 == []
tx_transfer = Transaction.transfer(tx.to_inputs(), [([user2_pk], 1)],
asset_id=tx.id)
tx_transfer = tx_transfer.sign([user_sk])
b.store_bulk_transactions([tx_transfer])
owned_inputs_user1 = b.fastquery.get_outputs_by_public_key(user_pk)
owned_inputs_user2 = b.fastquery.get_outputs_by_public_key(user2_pk)
assert owned_inputs_user1 == [TransactionLink(tx.id, 0)]
assert owned_inputs_user2 == [TransactionLink(tx_transfer.id, 0)]
示例12: test_multiple_owners_before_multiple_owners_after_single_input
# 需要导入模块: from bigchaindb.models import Transaction [as 别名]
# 或者: from bigchaindb.models.Transaction import transfer [as 别名]
def test_multiple_owners_before_multiple_owners_after_single_input(self, b,
user_sk,
user_pk,
alice):
from bigchaindb.common import crypto
from bigchaindb.models import Transaction
user2_sk, user2_pk = crypto.generate_key_pair()
user3_sk, user3_pk = crypto.generate_key_pair()
user4_sk, user4_pk = crypto.generate_key_pair()
tx = Transaction.create([alice.public_key], [([user_pk, user2_pk], 1)])
tx = tx.sign([alice.private_key])
b.store_bulk_transactions([tx])
# get input
tx_link = b.fastquery.get_outputs_by_public_key(user_pk).pop()
tx_input = b.get_transaction(tx_link.txid)
tx = Transaction.transfer(tx_input.to_inputs(),
[([user3_pk, user4_pk], 1)],
asset_id=tx_input.id)
tx = tx.sign([user_sk, user2_sk])
tx.validate(b)
assert len(tx.inputs) == 1
assert len(tx.outputs) == 1
示例13: test_single_in_single_own_multiple_out_mix_own_transfer
# 需要导入模块: from bigchaindb.models import Transaction [as 别名]
# 或者: from bigchaindb.models.Transaction import transfer [as 别名]
def test_single_in_single_own_multiple_out_mix_own_transfer(alice, b, user_pk,
user_sk):
from bigchaindb.models import Transaction
# CREATE divisible asset
tx_create = Transaction.create([alice.public_key], [([user_pk], 100)], asset={'name': random.random()})
tx_create_signed = tx_create.sign([alice.private_key])
# TRANSFER
tx_transfer = Transaction.transfer(tx_create.to_inputs(),
[([alice.public_key], 50), ([alice.public_key, alice.public_key], 50)],
asset_id=tx_create.id)
tx_transfer_signed = tx_transfer.sign([user_sk])
b.store_bulk_transactions([tx_create_signed])
assert tx_transfer_signed.validate(b) == tx_transfer_signed
assert len(tx_transfer_signed.outputs) == 2
assert tx_transfer_signed.outputs[0].amount == 50
assert tx_transfer_signed.outputs[1].amount == 50
output_cid1 = tx_transfer_signed.outputs[1].to_dict()
assert 'subconditions' in output_cid1['condition']['details']
assert len(output_cid1['condition']['details']['subconditions']) == 2
assert len(tx_transfer_signed.inputs) == 1
b.store_bulk_transactions([tx_transfer_signed])
with pytest.raises(DoubleSpend):
tx_transfer_signed.validate(b)
示例14: test_get_asset_id_transfer_transaction
# 需要导入模块: from bigchaindb.models import Transaction [as 别名]
# 或者: from bigchaindb.models.Transaction import transfer [as 别名]
def test_get_asset_id_transfer_transaction(b, signed_create_tx, user_pk):
from bigchaindb.models import Transaction
tx_transfer = Transaction.transfer(signed_create_tx.to_inputs(), [([user_pk], 1)],
signed_create_tx.id)
asset_id = Transaction.get_asset_id(tx_transfer)
assert asset_id == tx_transfer.asset['id']
示例15: test_muiltiple_in_mix_own_multiple_out_single_own_transfer
# 需要导入模块: from bigchaindb.models import Transaction [as 别名]
# 或者: from bigchaindb.models.Transaction import transfer [as 别名]
def test_muiltiple_in_mix_own_multiple_out_single_own_transfer(alice, b, user_pk,
user_sk):
from bigchaindb.models import Transaction
from bigchaindb.common.transaction import _fulfillment_to_details
# CREATE divisible asset
tx_create = Transaction.create([alice.public_key], [([user_pk], 50), ([user_pk, alice.public_key], 50)],
asset={'name': random.random()})
tx_create_signed = tx_create.sign([alice.private_key])
# TRANSFER
tx_transfer = Transaction.transfer(tx_create.to_inputs(), [([alice.public_key], 100)],
asset_id=tx_create.id)
tx_transfer_signed = tx_transfer.sign([alice.private_key, user_sk])
b.store_bulk_transactions([tx_create_signed])
assert tx_transfer_signed.validate(b) == tx_transfer_signed
assert len(tx_transfer_signed.outputs) == 1
assert tx_transfer_signed.outputs[0].amount == 100
assert len(tx_transfer_signed.inputs) == 2
ffill_fid0 = _fulfillment_to_details(tx_transfer_signed.inputs[0].fulfillment)
ffill_fid1 = _fulfillment_to_details(tx_transfer_signed.inputs[1].fulfillment)
assert 'subconditions' not in ffill_fid0
assert 'subconditions' in ffill_fid1
assert len(ffill_fid1['subconditions']) == 2
b.store_bulk_transactions([tx_transfer_signed])
with pytest.raises(DoubleSpend):
tx_transfer_signed.validate(b)