Esempio n. 1
0
 def validate_params(self):
     # single
     validate(self.params, self.get_schema())
     # relational
     PrivateChainUtil.validate_message_signature(
         self.event['requestContext']['authorizer']['claims']['cognito:username'],
         self.params['signature'],
         self.params['wallet_address']
     )
     # 既に登録済みの場合は処理中断
     if UserUtil.exists_private_eth_address(self.dynamodb,
                                            self.event['requestContext']['authorizer']['claims']['cognito:username']):
         raise ValidationError('private_eth_address is exists.')
    def exec_main_proc(self):
        user_id = self.event['requestContext']['authorizer']['claims'][
            'cognito:username']
        address = self.event['requestContext']['authorizer']['claims'].get(
            'custom:private_eth_address')

        # 現在のトークン量を取得
        # まだウォレットアドレスを作成していないユーザには 0 を返す
        if address is None:
            balance = '0x0'
        elif not UserUtil.exists_private_eth_address(self.dynamodb, user_id):
            # Cognito上にprivate_eth_addressは存在するが、カストディ規制のウォレット移行が完了していないユーザにも0を返す
            balance = '0x0'
        else:
            balance = PrivateChainUtil.get_balance(address)

        return {'statusCode': 200, 'body': json.dumps({'result': balance})}
 def test_exists_wallet_address_ok_not_exists_configuration_data(self):
     test_user = '******'
     result = UserUtil.exists_private_eth_address(self.dynamodb, test_user)
     self.assertFalse(result)
 def test_exists_wallet_address_ok_not_exists_private_eth_address(self):
     test_user = '******'
     result = UserUtil.exists_private_eth_address(self.dynamodb, test_user)
     self.assertFalse(result)
 def test_exists_wallet_address_ok_exists_configuration_data(self):
     test_user = '******'
     result = UserUtil.exists_private_eth_address(self.dynamodb, test_user)
     self.assertTrue(result)