mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Merge pull request #410 from bigchaindb/feat/pass-custom-bigchain-instance-sign_tx
Pass a custom bigchain instance to util.sign_tx
This commit is contained in:
commit
e6b665a003
@ -217,13 +217,13 @@ class BaseConsensusRules(AbstractConsensusRules):
|
|||||||
payload)
|
payload)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def sign_transaction(transaction, private_key):
|
def sign_transaction(transaction, private_key, bigchain=None):
|
||||||
"""Sign a transaction
|
"""Sign a transaction
|
||||||
|
|
||||||
Refer to the documentation of ``bigchaindb.util.sign_tx``
|
Refer to the documentation of ``bigchaindb.util.sign_tx``
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return util.sign_tx(transaction, private_key)
|
return util.sign_tx(transaction, private_key, bigchain=bigchain)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def validate_fulfillments(signed_transaction):
|
def validate_fulfillments(signed_transaction):
|
||||||
|
@ -85,7 +85,7 @@ class Bigchain(object):
|
|||||||
dict: transaction with any signatures applied.
|
dict: transaction with any signatures applied.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return self.consensus.sign_transaction(transaction, *args, **kwargs)
|
return self.consensus.sign_transaction(transaction, *args, bigchain=self, **kwargs)
|
||||||
|
|
||||||
def validate_fulfillments(self, signed_transaction, *args, **kwargs):
|
def validate_fulfillments(self, signed_transaction, *args, **kwargs):
|
||||||
"""Validate the fulfillment(s) of a transaction.
|
"""Validate the fulfillment(s) of a transaction.
|
||||||
|
@ -298,7 +298,7 @@ def create_tx(current_owners, new_owners, inputs, operation, payload=None):
|
|||||||
return transaction
|
return transaction
|
||||||
|
|
||||||
|
|
||||||
def sign_tx(transaction, signing_keys):
|
def sign_tx(transaction, signing_keys, bigchain=None):
|
||||||
"""Sign a transaction
|
"""Sign a transaction
|
||||||
|
|
||||||
A transaction signed with the `current_owner` corresponding private key.
|
A transaction signed with the `current_owner` corresponding private key.
|
||||||
@ -306,6 +306,8 @@ def sign_tx(transaction, signing_keys):
|
|||||||
Args:
|
Args:
|
||||||
transaction (dict): transaction to sign.
|
transaction (dict): transaction to sign.
|
||||||
signing_keys (list): list of base58 encoded private keys to create the fulfillments of the transaction.
|
signing_keys (list): list of base58 encoded private keys to create the fulfillments of the transaction.
|
||||||
|
bigchain (obj): bigchain instance used to get the details of the previous transaction outputs. Useful
|
||||||
|
if the `Bigchain` instance was instantiated with parameters that override the config file.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: transaction with the `fulfillment` fields populated.
|
dict: transaction with the `fulfillment` fields populated.
|
||||||
@ -324,10 +326,11 @@ def sign_tx(transaction, signing_keys):
|
|||||||
|
|
||||||
tx = copy.deepcopy(transaction)
|
tx = copy.deepcopy(transaction)
|
||||||
|
|
||||||
|
bigchain = bigchain if bigchain is not None else bigchaindb.Bigchain()
|
||||||
|
|
||||||
for fulfillment in tx['transaction']['fulfillments']:
|
for fulfillment in tx['transaction']['fulfillments']:
|
||||||
fulfillment_message = get_fulfillment_message(transaction, fulfillment)
|
fulfillment_message = get_fulfillment_message(transaction, fulfillment)
|
||||||
# TODO: avoid instantiation, pass as argument!
|
# TODO: avoid instantiation, pass as argument!
|
||||||
bigchain = bigchaindb.Bigchain()
|
|
||||||
input_condition = get_input_condition(bigchain, fulfillment)
|
input_condition = get_input_condition(bigchain, fulfillment)
|
||||||
parsed_fulfillment = cc.Fulfillment.from_dict(input_condition['condition']['details'])
|
parsed_fulfillment = cc.Fulfillment.from_dict(input_condition['condition']['details'])
|
||||||
# for the case in which the type of fulfillment is not covered by this method
|
# for the case in which the type of fulfillment is not covered by this method
|
||||||
|
@ -23,7 +23,7 @@ def mock_requests_post(monkeypatch):
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_bigchaindb_sign(monkeypatch):
|
def mock_bigchaindb_sign(monkeypatch):
|
||||||
def mockreturn(transaction, private_key):
|
def mockreturn(transaction, private_key, bigchain):
|
||||||
return transaction
|
return transaction
|
||||||
|
|
||||||
monkeypatch.setattr('bigchaindb.util.sign_tx', mockreturn)
|
monkeypatch.setattr('bigchaindb.util.sign_tx', mockreturn)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user