Exemple #1
0
 def __init__(self, sdk: KinAccount, channel: str):
     self.write_sdk = sdk
     self.write_sdk.raw_seed = BaseKeypair.from_seed(
         sdk.keypair.secret_seed).raw_seed()
     self.root_address = self.write_sdk.keypair.public_address
     self.channel = channel
     self.channel_address = Keypair.address_from_seed(channel)
Exemple #2
0
def balance_api():
    """endpoint used to get the current balance of the seed and channels"""
    if not config.DEBUG:
        limit_to_localhost()

    base_seed, channel_seeds = ssm.get_stellar_credentials()
    balance = {'base_seed': {}, 'channel_seeds': {}}

    from kin import Keypair
    kp = Keypair()
    balance['base_seed']['kin'] = get_kin_balance(
        kp.address_from_seed(base_seed))
    index = 0
    for channel in channel_seeds:
        # seeds only need to carry XLMs
        balance['channel_seeds'][index] = {'kin': 0}
        balance['channel_seeds'][index]['kin'] = get_kin_balance(
            kp.address_from_seed(channel))
        index = index + 1

    return jsonify(status='ok', balance=balance)
    def onboard_with_phone(self, userid, phone_num):
        resp = self.app.post('/user/register',
                             data=json.dumps({
                                 'user_id': str(userid),
                                 'os': 'android',
                                 'device_model': 'samsung8',
                                 'device_id': '234234',
                                 'time_zone': '05:00',
                                 'token': 'fake_token',
                                 'app_ver': '1.0'
                             }),
                             headers={},
                             content_type='application/json')
        self.assertEqual(resp.status_code, 200)

        # phone authenticate

        resp = self.app.post('/user/firebase/update-id-token',
                             data=json.dumps({
                                 'token': 'fake-token',
                                 'phone_number': phone_num
                             }),
                             headers={USER_ID_HEADER: str(userid)},
                             content_type='application/json')
        self.assertEqual(resp.status_code, 200)

        print('onboarding user --------------')
        from kin import Keypair
        kp = Keypair()
        address = kp.address_from_seed(kp.generate_seed())
        resp = self.app.post('/user/onboard',
                             data=json.dumps({'public_address': address}),
                             headers={USER_ID_HEADER: str(userid)},
                             content_type='application/json')

        print(json.loads(resp.data))
        self.assertEqual(resp.status_code, 200)

        # try onboarding again with the same user - should fail
        print('onboarding same user second time should fail --------------')
        resp = self.app.post('/user/onboard',
                             data=json.dumps({'public_address': address}),
                             headers={USER_ID_HEADER: str(userid)},
                             content_type='application/json')
        print(json.loads(resp.data))
        self.assertEqual(resp.status_code, 400)

        return address