本文整理汇总了Python中bigchaindb.Bigchain.create_transaction方法的典型用法代码示例。如果您正苦于以下问题:Python Bigchain.create_transaction方法的具体用法?Python Bigchain.create_transaction怎么用?Python Bigchain.create_transaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bigchaindb.Bigchain
的用法示例。
在下文中一共展示了Bigchain.create_transaction方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_invalid_tx
# 需要导入模块: from bigchaindb import Bigchain [as 别名]
# 或者: from bigchaindb.Bigchain import create_transaction [as 别名]
def create_invalid_tx():
"""Create and return an invalid transaction.
The transaction is invalid because it's missing the signature."""
b = Bigchain()
tx = b.create_transaction(b.me, b.me, None, 'CREATE')
return tx
示例2: create_write_transaction
# 需要导入模块: from bigchaindb import Bigchain [as 别名]
# 或者: from bigchaindb.Bigchain import create_transaction [as 别名]
def create_write_transaction(tx_left):
b = Bigchain()
while tx_left > 0:
# use uuid to prevent duplicate transactions (transactions with the same hash)
tx = b.create_transaction(b.me, b.me, None, 'CREATE',
payload={'msg': str(uuid.uuid4())})
tx_signed = b.sign_transaction(tx, b.me_private)
b.write_transaction(tx_signed)
tx_left -= 1
示例3: mint_coin
# 需要导入模块: from bigchaindb import Bigchain [as 别名]
# 或者: from bigchaindb.Bigchain import create_transaction [as 别名]
def mint_coin(user_pk):
b = Bigchain()
coin_id = uuid.uuid4()
for i in range(10):
payload = {
'coin_id': str(coin_id),
'coin_share': str(i)
}
tx = b.create_transaction(b.me, user_pk, None, 'CREATE', payload=payload)
tx_signed = b.sign_transaction(tx, b.me_private)
b.write_transaction(tx_signed)
print('MINT {} {} {}'.format(tx['id'], coin_id, i))
示例4: transfer_coin
# 需要导入模块: from bigchaindb import Bigchain [as 别名]
# 或者: from bigchaindb.Bigchain import create_transaction [as 别名]
def transfer_coin(user_vk, user_sk, coin_id):
b = Bigchain()
coins = get_owned_coins(user_vk)
if coin_id in coins.keys():
for tx in coins[coin_id]:
tx_input = {'txid': tx['id'], 'cid': 0}
tx_transfer = b.create_transaction(user_vk, b.me, tx_input, 'TRANSFER',
payload=tx['transaction']['data']['payload'])
tx_transfer_signed = b.sign_transaction(tx_transfer, user_sk)
b.write_transaction(tx_transfer_signed)
print('TRANSFER {} {} {}'.format(tx_transfer_signed['id'],
coin_id, tx['transaction']['data']['payload']['coin_share']))
示例5: pay_royalties
# 需要导入模块: from bigchaindb import Bigchain [as 别名]
# 或者: from bigchaindb.Bigchain import create_transaction [as 别名]
def pay_royalties(label_vk, artist_vk, tx, label_share=7, artist_share=3):
b = Bigchain()
payload = tx['transaction']['data']['payload']
tx_input = {'txid': tx['id'], 'cid': 0}
if int(payload['coin_share']) < artist_share:
new_owner = artist_vk
else:
new_owner = label_vk
tx_royalties = b.create_transaction(b.me, new_owner, tx_input, 'TRANSFER', payload=payload)
tx_royalties_signed = b.sign_transaction(tx_royalties, b.me_private)
b.write_transaction(tx_royalties_signed)
print('ROYALTIES {} {} {} {}'.format(tx_royalties['id'], payload['coin_id'],
payload['coin_share'], new_owner))
示例6: ChainQuery
# 需要导入模块: from bigchaindb import Bigchain [as 别名]
# 或者: from bigchaindb.Bigchain import create_transaction [as 别名]
class ChainQuery(object):
def __init__(
self, host=None, port=None, dbname=None, pub_key=None, priv_key=None, keyring=[], consensus_plugin=None
):
self.host = host
self.port = port
self.dbname = dbname
self.conn = r.connect(host=host, port=port, db=dbname)
self.bigchain = Bigchain(
host=host,
port=port,
dbname=dbname,
public_key=pub_key,
private_key=priv_key,
keyring=keyring,
consensus_plugin=consensus_plugin,
)
# test
def test(self):
tables = r.db("bigchain").table_list().run(self.conn)
# print(tables)
return tables
# create key_pair for user
def generate_key_pair(self):
return crypto.generate_key_pair()
# create asset
def create_asset(self, public_key, digital_asset_payload):
tx = self.bigchain.create_transaction(
self.bigchain.me, public_key, None, "CREATE", payload=digital_asset_payload
)
tx_signed = self.bigchain.sign_transaction(tx, self.bigchain.me_private)
return self.bigchain.write_transaction(tx_signed)
# get transaction by payload_uuid
def getTxid_by_payload_uuid(self, payload_uuid):
cursor = (
r.table("bigchain")
.get_all(payload_uuid, index="payload_uuid")
.pluck({"block": {"transactions": "id"}})
.run(self.conn)
)
transactions = list(cursor)
return transactions
# get transaction by payload
def getTxid_by_payload(self, payload):
pass
# get currentowner of a payload(assert)
def getOwnerofAssert(self, payload):
return
# get one's assert
def get_owned_asserts(self, pub_key):
return
# if tx contains someone
def tx_contains_one(self, tx, one_pub):
for condition in tx["conditions"]:
if one_pub in condition["new_owners"]:
return True
for fullfillment in tx["fulfillments"]:
if one_pub in fullfillment["current_owners"]:
return True
# transfer assert to another, old_owner create this transaction,so need old_owner's pub/priv key.
def transfer_assert(self, old_owner_pub, old_owner_priv, new_owner_pub, tx_id):
tx_transfer = self.bigchain.create_transaction(old_owner_pub, new_owner_pub, tx_id, "TRANSFER")
tx_transfer_signed = self.bigchain.sign_transaction(tx_transfer, old_owner_priv)
# check if the transaction is valid
check = self.bigchain.is_valid_transaction(tx_transfer_signed)
if check:
self.bigchain.write_transaction(tx_transfer_signed)
else:
logger.info("this transaction is invalid.")
示例7: open
# 需要导入模块: from bigchaindb import Bigchain [as 别名]
# 或者: from bigchaindb.Bigchain import create_transaction [as 别名]
# "NET PRICE": "25" ,
# "PRICE": "50" ,
# "QUANTITY": "50000" ,
# "SIDE": "S" ,
# "TYPE": "EQ"
# },
# ...]
data = []
with open('data.csv', 'r') as fid:
reader = csv.DictReader(fid)
for row in reader:
data.append(row)
# generate distinct users from the CPTY1 column and assign keys
users = []
for user_name in set([d['CPTY1'] for d in data]):
sk, vk = b.generate_keys()
user = users.append(
{
'name': user_name,
'signing_key': sk,
'verifying_key': vk
}
)
# create assets on the blockchain with the payload and assign to the user
for asset in data:
user = [u for u in users if u['name'] == asset['CPTY1']][0]
tx = b.create_transaction(b.me, user['verifying_key'], None, 'CREATE', payload=asset)
tx_signed = b.sign_transaction(tx, b.me_private)
b.write_transaction(tx_signed)
示例8: Bigchain
# 需要导入模块: from bigchaindb import Bigchain [as 别名]
# 或者: from bigchaindb.Bigchain import create_transaction [as 别名]
from bigchaindb import Bigchain
import writeout
import random
b = Bigchain()
random.seed(3)
for x in range(1,8):
# define a digital asset data payload
digital_asset_payload = {'choice': random.randint(0,100)}
# a create transaction uses the operation `CREATE` and has no inputs
priv, pub = writeout.importData("user"+str(x))
tx = b.create_transaction(b.me, pub, None, 'CREATE', payload=digital_asset_payload)
#tx = b.create_transaction(b.me, pub, None, 'CREATE')
# all transactions need to be signed by the user creating the transaction
tx_signed = b.sign_transaction(tx, b.me_private)
writeout.exportData(tx_signed, "user"+str(x)+"vote")
# write the transaction to the bigchain
# the transaction will be stored in a backlog where it will be validated,
# included in a block, and written to the bigchain
print(b.write_transaction(tx_signed))
示例9: Bigchain
# 需要导入模块: from bigchaindb import Bigchain [as 别名]
# 或者: from bigchaindb.Bigchain import create_transaction [as 别名]
b = Bigchain()
"""
Create a Digital Asset
"""
# create a test user
testuser1_priv, testuser1_pub = crypto.generate_key_pair()
# define a digital asset data payload
digital_asset_payload = {'msg': 'Hello BigchainDB!'}
# a create transaction uses the operation `CREATE` and has no inputs
tx = b.create_transaction(b.me, testuser1_pub, None, 'CREATE', payload=digital_asset_payload)
# all transactions need to be signed by the user creating the transaction
tx_signed = b.sign_transaction(tx, b.me_private)
# write the transaction to the bigchain
# the transaction will be stored in a backlog where it will be validated,
# included in a block, and written to the bigchain
b.write_transaction(tx_signed)
sleep(8)
"""
Read the Creation Transaction from the DB
"""
示例10: print
# 需要导入模块: from bigchaindb import Bigchain [as 别名]
# 或者: from bigchaindb.Bigchain import create_transaction [as 别名]
# user A
testuser1_priv, testuser1_pub = crypto.generate_key_pair()
print("testuser1_priv:"+testuser1_priv)
print("testuser1_pub:"+testuser1_pub)
payload = {
"msg" : "first charge for user A",
"issue" : "charge",
"category" : "currency",
"amount" : 300,
"asset":"",
"account":0,
"previous":"genesis",
"trader":""
}
tx = b.create_transaction(b.me, testuser1_pub, None, 'CREATE', payload=payload)
tx_signed = b.sign_transaction(tx, b.me_private)
if b.is_valid_transaction(tx_signed):
b.write_transaction(tx_signed)
print(tx_signed)
# user B
testuser2_priv, testuser2_pub = crypto.generate_key_pair()
print("testuser2_priv:"+testuser2_priv)
print("testuser2_pub:"+testuser2_pub)
payload2 = {
"msg" : "first charge for user B",
"issue" : "charge",
"category" : "currency",
"amount" : 400,
示例11: Bigchain
# 需要导入模块: from bigchaindb import Bigchain [as 别名]
# 或者: from bigchaindb.Bigchain import create_transaction [as 别名]
from bigchaindb import Bigchain
import writeout
b = Bigchain()
govt_priv, govt_pub = writeout.importData("govt")
for x in range(1,8):
priv, pub = writeout.importData("user"+str(x))
tx_signed = writeout.importData("user"+str(x)+"vote")
tx_retrieved = b.get_transaction(tx_signed['id'])
print(tx_retrieved)
# create a transfer transaction
tx_transfer = b.create_transaction(pub, govt_pub, tx_retrieved['id'], 'TRANSFER')
print(tx_transfer)
# sign the transaction
tx_transfer_signed = b.sign_transaction(tx_transfer, priv)
print(tx_transfer_signed)
# write the transaction
b.write_transaction(tx_transfer_signed)
# check if the transaction is already in the bigchain
tx_transfer_retrieved = b.get_transaction(tx_transfer_signed['id'])
print(tx_transfer_retrieved)
data = b.validate_transaction(tx_transfer_signed)
示例12:
# 需要导入模块: from bigchaindb import Bigchain [as 别名]
# 或者: from bigchaindb.Bigchain import create_transaction [as 别名]
testuser1_last=b.get_owned_ids(testuser1_pub).pop()
payload_A = {
"msg" : "node send -50 to A,is -50",
"issue" : "cost",
"category" : "currency",
"amount" : 50,
"asset":"",
# final owner 's account
"account":300,
"previous":testuser1_last['txid'],
"trader":testuser2_pub
}
tx_create= b.create_transaction(b.me, testuser1_pub, None, 'CREATE', payload=payload_A)
tx_create_signed = b.sign_transaction(tx_create, b.me_private)
if b.is_valid_transaction(tx_create_signed):
b.write_transaction(tx_create_signed)
# node create transaction for b,
testuser2_last=b.get_owned_ids(testuser2_pub).pop()
payload_B = {
"msg" : "node send +50 to B,is +50",
"issue" : "earn",
"category" : "currency",
"amount" : 50,
"asset":"",
# final owner 's account
"account":400,
"previous":testuser2_last['txid'],