Пример #1
0
    def _do_trans(self, vfrom, value, vto, state):
        msg = 'transfer "{n}"->"{t}" by {v}'.format(n=vfrom, t=vto, v=value)
        LOGGER.debug(msg)

        if vfrom not in state or vto not in state:
            raise InvalidTransaction(
                'Verb is "trans" but vallet "{}" or vallet "{}" not in state'.
                format(vfrom, vto))

        curr = state[vfrom]
        token = BgtTokenInfo()
        token.ParseFromString(curr)
        to = state[vto]
        token1 = BgtTokenInfo()
        token1.ParseFromString(to)
        LOGGER.debug('_do_tans token[%s]=%s', token.group_code, value)
        decd = token.decimals - value
        if decd < MIN_VALUE:
            raise InvalidTransaction(
                'Verb is "trans", but result would be less than {}'.format(
                    MIN_VALUE))
        incd = token1.decimals + value
        if incd > MAX_VALUE:
            raise InvalidTransaction(
                'Verb is "inc", but result would be greater than {}'.format(
                    MAX_VALUE))

        updated = {k: v for k, v in state.items()}
        token.decimals = decd
        updated[vfrom] = token.SerializeToString()
        token1.decimals = incd
        updated[vto] = token1.SerializeToString()

        return updated
Пример #2
0
    def _do_dec(self, name, value, to, state):
        msg = 'Decrementing "{n}" by {v}'.format(n=name, v=value)
        LOGGER.debug(msg)

        if name not in state:
            raise InvalidTransaction(
                'Verb is "dec" but name "{}" not in state'.format(name))

        curr = state[name]
        token = BgtTokenInfo()
        token.ParseFromString(curr)
        LOGGER.debug('_do_dec token[%s]=%s', token.group_code, token.decimals,
                     value)
        decd = token.decimals - value

        if decd < MIN_VALUE:
            raise InvalidTransaction(
                'Verb is "dec", but result would be less than {}'.format(
                    MIN_VALUE))

        updated = {k: v for k, v in state.items()}
        token.decimals = decd
        updated[name] = token.SerializeToString()

        return updated
Пример #3
0
    def _do_set(self,name, value, state):
        msg = 'Setting "{n}" to {v}'.format(n=name, v=value)
        LOGGER.debug(msg)
        

        if name in state:
            raise InvalidTransaction('Verb is "set", but already exists: Name: {n}, Value {v}'.format(n=name,v=state[name]))

        updated = {k: v for k, v in state.items()}
        #owner_key = self._context.sign('BGT_token'.encode(),self._private_key)
        token = BgtTokenInfo(group_code = 'BGT_token',
                             owner_key = self._signer.sign('BGT_token'.encode()), #owner_key,
                             sign = self._public_key.as_hex(),
                             decimals = int(value)
                )
        updated[name] = token.SerializeToString()
        LOGGER.debug('_do_set updated=%s',updated)
        return updated