def __init__(self, signer=None):
     self._asset_addr = Address(Address.FAMILY_ASSET)
     self._setting_addr = Address(Address.FAMILY_SETTING)
     self._factory = MessageFactory(family_name=Address.NAMESPACE_ASSET,
                                    family_version="0.1.0",
                                    namespace=[self._asset_addr.ns_family],
                                    signer=signer)
class SettingMessageFactory(object):
    def __init__(self, signer=None):
        self._asset_addr = Address(Address.FAMILY_ASSET)
        self._setting_addr = Address(Address.FAMILY_SETTING)
        self._factory = MessageFactory(
            family_name=Address.NAMESPACE_SETTING,
            family_version="0.1.0",
            namespace=[self._setting_addr.ns_family],
            signer=signer)

    @property
    def public_key(self):
        return self._factory.get_public_key()

    def create_tp_register(self):
        return self._factory.create_tp_register()

    def create_tp_response(self, status):
        return self._factory.create_tp_response(status)

    def _create_tp_process_request(self, dimension, payload):
        address = self._setting_addr.settings(dimension)
        inputs = [address, self._asset_addr.candidates(dimension)]
        outputs = [address, self._asset_addr.candidates(dimension)]
        return self._factory.create_tp_process_request(
            payload.SerializeToString(), inputs, outputs, [])

    def create_payload_request(self, settings, dimension, action):
        payload = SettingPayload(action=action,
                                 dimension=dimension,
                                 data=settings.SerializeToString())
        return self._create_tp_process_request(dimension, payload)

    def create_setting_transaction(self, auth_keys, thresh, dimension, action):
        setting = Settings(auth_list=auth_keys, threshold=thresh)
        return self.create_payload_request(setting, dimension, action)

    def create_get_request(self, address):
        return self._factory.create_get_request([address])

    def create_get_response(self, address, data=None):
        return self._factory.create_get_response({address: data})

    def create_set_request(self, address, setting=None):
        return self._factory.create_set_request({address: setting})

    def create_set_response(self, address):
        return self._factory.create_set_response([address])

    def create_add_event_request(self, key):
        return self._factory.create_add_event_request(
            "hashblock.setting/update", [("updated", key)])

    def create_add_event_response(self):
        return self._factory.create_add_event_response()
示例#3
0
def __create_settings(signer, assetauths, assetthresh, unitauths, unitthresh):
    """Creates and returns a batch of setting transactions"""
    valid_signer(signer)
    _asset_addrs = Address.asset_addresser()
    _unit_addrs = Address.unit_addresser()
    asset_auth_keys = __validate_settings(assetauths, assetthresh)
    unit_auth_keys = __validate_settings(unitauths, unitthresh)
    setting_txn_build = compose_builder(create_transaction,
                                        __create_inputs_outputs,
                                        __create_setting)
    asset_setting_txn = setting_txn_build(
        (signer, _asset_addrs, asset_auth_keys, assetthresh))[1]
    unit_setting_txn = setting_txn_build(
        (signer, _unit_addrs, unit_auth_keys, unitthresh))[1]
    return [asset_setting_txn, unit_setting_txn]
示例#4
0
 def __init__(self, signer=None):
     self._match_addr = Address(Address.FAMILY_MATCH)
     self._factory = MessageFactory(
         family_name=Address.NAMESPACE_MATCH,
         family_version="0.1.0",
         namespace=[self._match_addr.ns_family],
         signer=signer)
示例#5
0
 def get(self, address):
     """Return asset details"""
     tail = request.path.split('/')[-2]
     f = decode_asset if tail == 'asset' else decode_unit
     if Address.valid_leaf_address(address):
         return f(address), 200
     else:
         return {"address": "not a valid address", "data": ""}, 400
示例#6
0
def __create_inputs_outputs(ingest):
    """Creates the input and output addresses for setting transaction"""
    signer, addresser, payload = ingest
    inputs = [addresser.setting_address, addresser.candidate_address]
    outputs = [addresser.setting_address, addresser.candidate_address]
    return (
        signer,
        Address.setting_addresser(),
        # addresser,
        {
            "inputs": inputs,
            "outputs": outputs
        },
        payload)
示例#7
0
 def __init__(self):
     self._addresser = Address.exchange_utxq_addresser()
示例#8
0
from modules.config import sawtooth_rest_host
from modules.config import key_owner, agreement_secret
from modules.state import State
from modules.exceptions import AuthException
from modules.address import Address

from protobuf.exchange_pb2 import UTXQ
from protobuf.exchange_pb2 import MTXQ
from protobuf.setting_pb2 import Settings
from protobuf.unit_pb2 import Unit
from protobuf.unit_pb2 import UnitCandidates
from protobuf.asset_pb2 import Asset
from protobuf.asset_pb2 import AssetCandidates

asset_addresser = Address.asset_addresser()
unit_addresser = Address.unit_addresser()
setting_addresser = Address.setting_addresser()
utxq_addresser = Address.exchange_utxq_addresser()
mtxq_addresser = Address.exchange_mtxq_addresser()

STATE_CRYPTO = State()


def get_node(address):
    return RestClient(sawtooth_rest_host()).get_leaf(address)


def __get_leaf_data(address, partner_secret=None):
    """Fetch leaf data from chain"""
    ddict = RestClient(sawtooth_rest_host()).get_leaf(address)
示例#9
0
 def setUpClass(cls):
     super().setUpClass()
     cls.factory = MatchMessageFactory()
     cls._match_addr = Address(Address.FAMILY_MATCH)
     load_hashblock_config()
class AssetMessageFactory(object):
    def __init__(self, signer=None):
        self._asset_addr = Address(Address.FAMILY_ASSET)
        self._setting_addr = Address(Address.FAMILY_SETTING)
        self._factory = MessageFactory(family_name=Address.NAMESPACE_ASSET,
                                       family_version="0.1.0",
                                       namespace=[self._asset_addr.ns_family],
                                       signer=signer)

    @property
    def public_key(self):
        return self._factory.get_public_key()

    def create_tp_register(self):
        return self._factory.create_tp_register()

    def create_tp_response(self, status):
        return self._factory.create_tp_response(status)

    def _create_tp_process_request(self, asset, dimension, payload):
        asset_address = self._asset_addr.asset_item(dimension, asset.system,
                                                    asset.key)
        inputs = [
            self._setting_addr.settings(dimension),
            self._asset_addr.candidates(dimension), asset_address
        ]

        outputs = [self._asset_addr.candidates(dimension), asset_address]

        return self._factory.create_tp_process_request(
            payload.SerializeToString(), inputs, outputs, [])

    def create_proposal_transaction(self, asset, dimension, nonce):
        proposal = AssetProposal(
            asset=asset.SerializeToString(),
            type=AssetProposal.UNIT
            if dimension is Address.DIMENSION_UNIT else AssetProposal.RESOURCE,
            nonce=nonce)
        payload = AssetPayload(action=AssetPayload.ACTION_PROPOSE,
                               dimension=dimension,
                               data=proposal.SerializeToString())

        return self._create_tp_process_request(asset, dimension, payload)

    def create_vote_transaction(self, proposal_id, asset, dimension, vote):
        avote = AssetVote(proposal_id=proposal_id, vote=vote)
        payload = AssetPayload(action=AssetPayload.ACTION_VOTE,
                               dimension=dimension,
                               data=avote.SerializeToString())

        return self._create_tp_process_request(asset, dimension, payload)

    def create_unset_vote_transaction(self, proposal_id, asset, dimension,
                                      vote):
        avote = AssetVote(proposal_id=proposal_id, vote=vote)
        payload = AssetPayload(action=AssetPayload.ACTION_UNSET,
                               dimension=dimension,
                               data=avote.SerializeToString())

        return self._create_tp_process_request(asset, dimension, payload)

    def create_get_request(self, address):
        addresses = [address]
        return self._factory.create_get_request(addresses)

    def create_get_response(self, address, data):
        return self._factory.create_get_response({address: data})

    def create_set_request(self, address, data):
        return self._factory.create_set_request({address: data})

    def create_set_response(self, address):
        addresses = [address]
        return self._factory.create_set_response(addresses)

    def create_add_event_request(self, address):
        return self._factory.create_add_event_request("hashbloc.asset/update",
                                                      [("updated", address)])

    def create_add_event_response(self):
        return self._factory.create_add_event_response()
示例#11
0
 def __init__(self):
     self._addresser = Address.unit_addresser()
     self._auth_list = None
     self._action = None
     self._settings = None
示例#12
0
 def __init__(self):
     self._addresser = Address.track_addresser()
     self._auth_list = None
     self._action = None
from protobuf.asset_pb2 import AssetCandidates
from protobuf.setting_pb2 import Settings
from protobuf.setting_pb2 import SettingPayload

from modules.address import Address

from hashblock_setting_test.setting_message_factory \
    import SettingMessageFactory

from sawtooth_processor_test.transaction_processor_test_case \
    import TransactionProcessorTestCase

VOTER2 = "59c272cb554c7100dd6c1e38b5c77f158146be29373329e503bfcb81e70d1ddd"
EMPTY_CANDIDATES = AssetCandidates(candidates=[]).SerializeToString()

_asset_addr = Address(Address.FAMILY_ASSET)
_setting_addr = Address(Address.FAMILY_SETTING)


class TestSetting(TransactionProcessorTestCase):
    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.factory = SettingMessageFactory()
        cls.setting = Settings(auth_list=','.join(
            [cls.factory.public_key, VOTER2]),
                               threshold='2')

    def _expect_get(self, address, data=None):
        received = self.validator.expect(
            self.factory.create_get_request(address))