Pass a custom bigchain instance to util.sign_tx

This commit is contained in:
Rodolphe Marques 2016-06-29 16:47:58 +02:00
parent d6ea728459
commit a66a18b0d4
4 changed files with 9 additions and 6 deletions

View File

@ -217,13 +217,13 @@ class BaseConsensusRules(AbstractConsensusRules):
payload)
@staticmethod
def sign_transaction(transaction, private_key):
def sign_transaction(transaction, private_key, bigchain=None):
"""Sign a transaction
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
def validate_fulfillments(signed_transaction):

View File

@ -85,7 +85,7 @@ class Bigchain(object):
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):
"""Validate the fulfillment(s) of a transaction.

View File

@ -298,7 +298,7 @@ def create_tx(current_owners, new_owners, inputs, operation, payload=None):
return transaction
def sign_tx(transaction, signing_keys):
def sign_tx(transaction, signing_keys, bigchain=None):
"""Sign a transaction
A transaction signed with the `current_owner` corresponding private key.
@ -306,6 +306,8 @@ def sign_tx(transaction, signing_keys):
Args:
transaction (dict): transaction to sign.
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:
dict: transaction with the `fulfillment` fields populated.
@ -324,10 +326,11 @@ def sign_tx(transaction, signing_keys):
tx = copy.deepcopy(transaction)
bigchain = bigchain if bigchain is not None else bigchaindb.Bigchain()
for fulfillment in tx['transaction']['fulfillments']:
fulfillment_message = get_fulfillment_message(transaction, fulfillment)
# TODO: avoid instantiation, pass as argument!
bigchain = bigchaindb.Bigchain()
input_condition = get_input_condition(bigchain, fulfillment)
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

View File

@ -23,7 +23,7 @@ def mock_requests_post(monkeypatch):
@pytest.fixture
def mock_bigchaindb_sign(monkeypatch):
def mockreturn(transaction, private_key):
def mockreturn(transaction, private_key, bigchain):
return transaction
monkeypatch.setattr('bigchaindb.util.sign_tx', mockreturn)