Modified Client module and web views to use plublic consensus methods

for creating/signing/verifying instead of the functions in utils.py --
those are now only called by the the BaseConsensusRules class in
consensus.py.
This commit is contained in:
Matt Smith 2016-03-13 22:26:35 -07:00
parent 5c4529f120
commit 037b5110fe
2 changed files with 29 additions and 9 deletions

View File

@ -15,7 +15,8 @@ class Client:
In the future, a Client might connect to >1 hosts. In the future, a Client might connect to >1 hosts.
""" """
def __init__(self, public_key=None, private_key=None, api_endpoint=None): def __init__(self, public_key=None, private_key=None, api_endpoint=None,
consensus_plugin=None):
"""Initialize the Client instance """Initialize the Client instance
There are three ways in which the Client instance can get its parameters. There are three ways in which the Client instance can get its parameters.
@ -28,8 +29,11 @@ class Client:
Args: Args:
public_key (str): the base58 encoded public key for the ECDSA secp256k1 curve. public_key (str): the base58 encoded public key for the ECDSA secp256k1 curve.
private_key (str): the base58 encoded private key for the ECDSA secp256k1 curve. private_key (str): the base58 encoded private key for the ECDSA secp256k1 curve.
host (str): hostname where the rethinkdb is running. api_endpoint (str): a URL where rethinkdb is running.
port (int): port in which rethinkb is running (usually 28015). format: scheme://hostname:port
consensus_plugin (str): the registered name of your installed
consensus plugin. The `core` plugin is built into BigchainDB;
others must be installed via pip.
""" """
config_utils.autoconfigure() config_utils.autoconfigure()
@ -37,6 +41,7 @@ class Client:
self.public_key = public_key or bigchaindb.config['keypair']['public'] self.public_key = public_key or bigchaindb.config['keypair']['public']
self.private_key = private_key or bigchaindb.config['keypair']['private'] self.private_key = private_key or bigchaindb.config['keypair']['private']
self.api_endpoint = api_endpoint or bigchaindb.config['api_endpoint'] self.api_endpoint = api_endpoint or bigchaindb.config['api_endpoint']
self.consensus = config_utils.load_consensus_plugin(consensus_plugin)
if not self.public_key or not self.private_key: if not self.public_key or not self.private_key:
raise exceptions.KeypairNotFoundException() raise exceptions.KeypairNotFoundException()
@ -51,8 +56,15 @@ class Client:
The transaction pushed to the Federation. The transaction pushed to the Federation.
""" """
tx = util.create_tx(self.public_key, self.public_key, None, operation='CREATE', payload=payload) tx = self.consensus.create_transaction(
signed_tx = util.sign_tx(tx, self.private_key) current_owner=self.public_key,
new_owner=self.public_key,
tx_input=None,
operation='CREATE',
payload=payload)
signed_tx = self.consensus.sign_transaction(
tx, private_key=self.private_key)
return self._push(signed_tx) return self._push(signed_tx)
def transfer(self, new_owner, tx_input, payload=None): def transfer(self, new_owner, tx_input, payload=None):
@ -67,8 +79,15 @@ class Client:
The transaction pushed to the Federation. The transaction pushed to the Federation.
""" """
tx = util.create_tx(self.public_key, new_owner, tx_input, operation='TRANSFER', payload=payload) tx = self.consensus.create_transaction(
signed_tx = util.sign_tx(tx, self.private_key) current_owner=self.public_key,
new_owner=new_owner,
tx_input=tx_input,
operation='TRANSFER',
payload=payload)
signed_tx = self.consensus.sign_transaction(
tx, private_key=self.private_key)
return self._push(signed_tx) return self._push(signed_tx)
def _push(self, tx): def _push(self, tx):

View File

@ -57,9 +57,10 @@ def create_transaction():
if tx['transaction']['operation'] == 'CREATE': if tx['transaction']['operation'] == 'CREATE':
tx = util.transform_create(tx) tx = util.transform_create(tx)
tx = util.sign_tx(tx, bigchain.me_private) tx = bigchain.consensus.sign_transaction(
tx, private_key=bigchain.me_private)
if not util.verify_signature(tx): if not bigchain.consensus.verify_signature(tx):
val['error'] = 'Invalid transaction signature' val['error'] = 'Invalid transaction signature'
val = bigchain.write_transaction(tx) val = bigchain.write_transaction(tx)