Exemplo n.º 1
0
    def makeRawCompatible(raw):
        """
        Converts a raw representation of a wallet from any previous version
        to the current version. If the raw representation of the wallet is
        of the current version then this method does nothing.

        :param raw: the wallet's raw representation to convert
        """

        # At first, call makeRawCompatible method of base class(es)
        # if it contains such the method

        rawClassVersion = raw.get(getClassVersionKey(Wallet), 0)
        if rawClassVersion < 1:
            Wallet.convertRawToVersion1(raw)
Exemplo n.º 2
0
    def makeRawCompatible(raw):
        """
        Updates a raw representation of a wallet from any previous version
        to the current version. If the raw representation of the wallet is
        of the current version or higher then this method does nothing.

        :param raw: the wallet's raw representation to update
        """

        # At first, call makeRawCompatible method of base class(es)
        # if it contains such the method

        rawClassVersion = raw.get(getClassVersionKey(Wallet))
        if rawClassVersion is None:
            rawClassVersion = \
                raw.get(getClassVersionKeyBeforeRebranding(Wallet), 0)

        for version in range(rawClassVersion, Wallet.CLASS_VERSION):
            Wallet.RAW_UPDATERS[version + 1](raw)
Exemplo n.º 3
0
    def __init__(self,
                 name: str = None,
                 supportedDidMethods: DidMethods = None):
        PWallet.__init__(self, name, supportedDidMethods or DefaultDidMethods)
        TrustAnchoring.__init__(self)

        # Copy the class version to the instance for the version
        # to be serialized when the wallet is persisted
        setattr(self, getClassVersionKey(Wallet), Wallet.CLASS_VERSION)

        self._attributes = {}  # type: Dict[(str, Identifier,
        # Optional[Identifier]), Attribute]

        self.env = None  # Helps to know associated environment
        self._nodes = {}
        self._upgrades = {}
        self._pconfigs = {}

        self._connections = OrderedDict()  # type: Dict[str, Connection]
        # Note, ordered dict to make iteration deterministic

        self.knownIds = {}  # type: Dict[str, Identifier]

        # transactions not yet submitted
        self._pending = deque()  # type Tuple[Request, Tuple[str, Identifier,
        #  Optional[Identifier]]

        # pending transactions that have been prepared (probably submitted)
        self._prepared = {}  # type: Dict[(Identifier, int), Request]
        self.lastKnownSeqs = {}  # type: Dict[str, int]

        self.replyHandler = {
            ATTRIB: self._attribReply,
            GET_ATTR: self._getAttrReply,
            NYM: self._nymReply,
            GET_NYM: self._getNymReply,
            GET_TXNS: self._getTxnsReply,
            NODE: self._nodeReply,
            POOL_UPGRADE: self._poolUpgradeReply,
            POOL_CONFIG: self._poolConfigReply
        }
Exemplo n.º 4
0
    def convertRawToVersion1(raw):

        fieldRenamings = {
            'linkStatus': 'connection_status',
            'linkLastSynced': 'connection_last_synced',
            'linkLastSyncNo': 'connection_last_sync_no',
            'invitationNonce': 'request_nonce',

            # rule for the intermediate renaming state
            'connectionLastSynced': 'connection_last_synced'
        }

        def renameConnectionFields(connection):
            for key in connection:
                if key in fieldRenamings:
                    connection[fieldRenamings[key]] = connection.pop(key)

        def processDict(d):
            if d.get(tags.OBJECT) == 'sovrin_client.client.wallet.link.Link':
                d[tags.OBJECT] = \
                    'sovrin_client.client.wallet.connection.Connection'
                renameConnectionFields(d)
            for key in d:
                processValue(d[key])

        def processList(l):
            for item in l:
                processValue(item)

        def processValue(v):
            if isinstance(v, dict):
                processDict(v)
            elif isinstance(v, list):
                processList(v)

        if '_links' in raw:
            raw['_connections'] = raw.pop('_links')
        processValue(raw)

        # Add/update the class version entry
        raw[getClassVersionKey(Wallet)] = 1
Exemplo n.º 5
0
def getClassVersionKeyBeforeRebranding(cls):
    return getClassVersionKey(cls).replace('indy_client', 'sovrin_client')
Exemplo n.º 6
0
    def update(cls, raw):
        cls._traverseDict(raw)

        raw.pop(getClassVersionKeyBeforeRebranding(Wallet), None)
        raw[getClassVersionKey(Wallet)] = 2