当前位置: 首页>>代码示例>>Python>>正文


Python Bigchain.sign_transaction方法代码示例

本文整理汇总了Python中bigchaindb.Bigchain.sign_transaction方法的典型用法代码示例。如果您正苦于以下问题:Python Bigchain.sign_transaction方法的具体用法?Python Bigchain.sign_transaction怎么用?Python Bigchain.sign_transaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bigchaindb.Bigchain的用法示例。


在下文中一共展示了Bigchain.sign_transaction方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_write_transaction

# 需要导入模块: from bigchaindb import Bigchain [as 别名]
# 或者: from bigchaindb.Bigchain import sign_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
开发者ID:Gogistics,项目名称:bigchaindb,代码行数:11,代码来源:benchmark_utils.py

示例2: mint_coin

# 需要导入模块: from bigchaindb import Bigchain [as 别名]
# 或者: from bigchaindb.Bigchain import sign_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))
开发者ID:bigchaindb,项目名称:bigchaindb-jukebox,代码行数:15,代码来源:stream_coin.py

示例3: transfer_coin

# 需要导入模块: from bigchaindb import Bigchain [as 别名]
# 或者: from bigchaindb.Bigchain import sign_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']))
开发者ID:bigchaindb,项目名称:bigchaindb-jukebox,代码行数:15,代码来源:stream_coin.py

示例4: pay_royalties

# 需要导入模块: from bigchaindb import Bigchain [as 别名]
# 或者: from bigchaindb.Bigchain import sign_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))
开发者ID:bigchaindb,项目名称:bigchaindb-jukebox,代码行数:17,代码来源:stream_coin.py

示例5: ChainQuery

# 需要导入模块: from bigchaindb import Bigchain [as 别名]
# 或者: from bigchaindb.Bigchain import sign_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.")
开发者ID:CsterKuroi,项目名称:Charitychain,代码行数:81,代码来源:bigchainQuery.py

示例6: open

# 需要导入模块: from bigchaindb import Bigchain [as 别名]
# 或者: from bigchaindb.Bigchain import sign_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)
开发者ID:diminator,项目名称:bigchaindb-trade-logger,代码行数:33,代码来源:main.py

示例7:

# 需要导入模块: from bigchaindb import Bigchain [as 别名]
# 或者: from bigchaindb.Bigchain import sign_transaction [as 别名]
"""
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
"""

tx_retrieved = b.get_transaction(tx_signed['id'])

print(json.dumps(tx_retrieved, sort_keys=True, indent=4, separators=(',', ':')))
开发者ID:dangerousbeans,项目名称:bigchaindb,代码行数:32,代码来源:run_doc_python_server_api_examples.py

示例8: Bigchain

# 需要导入模块: from bigchaindb import Bigchain [as 别名]
# 或者: from bigchaindb.Bigchain import sign_transaction [as 别名]
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)
    print(data)
开发者ID:ChesTaylor,项目名称:csci455,代码行数:31,代码来源:dummytransfer.py

示例9:

# 需要导入模块: from bigchaindb import Bigchain [as 别名]
# 或者: from bigchaindb.Bigchain import sign_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'],
            "trader":testuser1_pub
开发者ID:CsterKuroi,项目名称:Charitychain,代码行数:33,代码来源:transfer.py


注:本文中的bigchaindb.Bigchain.sign_transaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。