Exemplo n.º 1
0
    def handle_escrow(self, tx, current_ledger_id):
        print('called handle_escrow {}'.format(tx['id']))

        ilp_header = tx['transaction']['data']['payload']['ilp_header']
        if 'hops' not in ilp_header:
            ilp_header['hops'] = []
        ilp_header['hops'].append({
            'ledger': current_ledger_id,
            'txid': tx['id']
        })

        destination_ledger_id = ilp_header['ledger']

        ledger = get_bigchain(ledger_id=destination_ledger_id)
        source = self.accounts[destination_ledger_id]['vk']
        to = ilp_header['account']
        asset_id = ledger.get_owned_ids(source).pop()
        sk = self.accounts[destination_ledger_id]['sk']

        condition = cc.Fulfillment.from_dict(tx['transaction']['conditions'][0]['condition']['details'])

        timelocks, _ = get_subcondition_indices_from_type(condition, cc.TimeoutFulfillment.TYPE_ID)
        expires_at = timelocks[0].expire_time.decode()

        hashlocks, _ = get_subcondition_indices_from_type(condition, cc.PreimageSha256Fulfillment.TYPE_ID)
        execution_condition = hashlocks[0].serialize_uri()

        escrow_asset(bigchain=ledger,
                     source=source,
                     to=to,
                     asset_id=asset_id,
                     sk=sk,
                     expires_at=expires_at,
                     ilp_header=ilp_header,
                     execution_condition=execution_condition)
Exemplo n.º 2
0
    def handle_escrow(self, tx, current_ledger_id):
        print('called handle_escrow {}'.format(tx['id']))

        ilp_header = tx['transaction']['data']['payload']['ilp_header']
        if 'hops' not in ilp_header:
            ilp_header['hops'] = []
        ilp_header['hops'].append({
            'ledger': current_ledger_id,
            'txid': tx['id']
        })

        destination_ledger_id = ilp_header['ledger']

        ledger = get_bigchain(ledger_id=destination_ledger_id)
        source = self.accounts[destination_ledger_id]['vk']
        to = ilp_header['account']
        asset_id = ledger.get_owned_ids(source).pop()
        sk = self.accounts[destination_ledger_id]['sk']

        condition = cc.Fulfillment.from_dict(
            tx['transaction']['conditions'][0]['condition']['details'])

        timelocks, _ = get_subcondition_indices_from_type(
            condition, cc.TimeoutFulfillment.TYPE_ID)
        expires_at = timelocks[0].expire_time.decode()

        hashlocks, _ = get_subcondition_indices_from_type(
            condition, cc.PreimageSha256Fulfillment.TYPE_ID)
        execution_condition = hashlocks[0].serialize_uri()

        escrow_asset(bigchain=ledger,
                     source=source,
                     to=to,
                     asset_id=asset_id,
                     sk=sk,
                     expires_at=expires_at,
                     ilp_header=ilp_header,
                     execution_condition=execution_condition)
Exemplo n.º 3
0
def escrow_asset(asset_id, cid):
    json_payload = request.get_json(force=True)
    source = json_payload.pop('source')
    expires_at = json_payload.pop('expiresAt')
    ilp_header = json_payload.pop('ilpHeader', None)
    execution_condition = json_payload.pop('executionCondition')
    to = json_payload.pop('to')

    tx = assets.escrow_asset(bigchain=bigchain,
                             source=source['vk'],
                             to=to['vk'],
                             asset_id={
                                 'txid': asset_id,
                                 'cid': int(cid)
                             },
                             sk=source['sk'],
                             expires_at=expires_at,
                             ilp_header=ilp_header,
                             execution_condition=execution_condition)

    return flask.jsonify(**tx)