Example #1
0
    def handle_execute(self, tx):
        print('called handle_execute {}'.format(tx['id']))

        ilp_header = tx['transaction']['data']['payload']['ilp_header']

        hop = ilp_header['hops'][0]

        ledger = get_bigchain(ledger_id=hop['ledger'])
        tx_escrow = ledger.get_transaction(hop['txid'])

        source = self.accounts[hop['ledger']]['vk']
        to = source
        asset_id = {
            'txid': hop['txid'],
            'cid': 0
        }
        sk = self.accounts[hop['ledger']]['sk']

        fulfillment = cc.Fulfillment.from_uri(tx['transaction']['fulfillments'][0]['fulfillment'])

        hashlocks, _ = get_subcondition_indices_from_type(fulfillment, cc.PreimageSha256Fulfillment.TYPE_ID)
        execution_fulfillment = hashlocks[0].serialize_uri()

        fulfill_escrow_asset(bigchain=ledger,
                             source=source,
                             to=to,
                             asset_id=asset_id,
                             sk=sk,
                             execution_fulfillment=execution_fulfillment)
Example #2
0
    def handle_execute(self, tx):
        print('called handle_execute {}'.format(tx['id']))

        ilp_header = tx['transaction']['data']['payload']['ilp_header']

        hop = ilp_header['hops'][0]

        ledger = get_bigchain(ledger_id=hop['ledger'])
        tx_escrow = ledger.get_transaction(hop['txid'])

        source = self.accounts[hop['ledger']]['vk']
        to = source
        asset_id = {'txid': hop['txid'], 'cid': 0}
        sk = self.accounts[hop['ledger']]['sk']

        fulfillment = cc.Fulfillment.from_uri(
            tx['transaction']['fulfillments'][0]['fulfillment'])

        hashlocks, _ = get_subcondition_indices_from_type(
            fulfillment, cc.PreimageSha256Fulfillment.TYPE_ID)
        execution_fulfillment = hashlocks[0].serialize_uri()

        fulfill_escrow_asset(bigchain=ledger,
                             source=source,
                             to=to,
                             asset_id=asset_id,
                             sk=sk,
                             execution_fulfillment=execution_fulfillment)
Example #3
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)
Example #4
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)
import functools
import os
import logging

from tornado import websocket, web, ioloop
from tornado.gen import coroutine

import rethinkdb as r

from init_accounts import get_bigchain

clients = []
bigchain = get_bigchain()

# from http://blog.hiphipjorge.com/django-and-realtime-using-django-with-tornado-and-rethinkdb/
r.set_loop_type('tornado')


logger = logging.getLogger('tornado')


@coroutine
def print_changes(db_table):
    conn = yield bigchain.conn
    feed = yield r.table(db_table).changes().run(conn)
    while (yield feed.fetch_next()):
        change = yield feed.next()
        block = get_block_from_change(change, db_table)
        for client in clients:
            for tx in block:
                # TODO: use REQL for filtering
Example #6
0
 def _listen_events(self, ledger_id):
     ledger = get_bigchain(ledger_id=ledger_id)
     for change in r.table('bigchain').changes().run(ledger.conn):
         if change['old_val'] is None:
             self._handle_block(change['new_val'], ledger_id)
import functools
import os
import logging

from tornado import websocket, web, ioloop
from tornado.gen import coroutine

import rethinkdb as r

from init_accounts import get_bigchain

clients = []
bigchain = get_bigchain()

# from http://blog.hiphipjorge.com/django-and-realtime-using-django-with-tornado-and-rethinkdb/
r.set_loop_type('tornado')

logger = logging.getLogger('tornado')


@coroutine
def print_changes(db_table):
    conn = yield bigchain.conn
    feed = yield r.table(db_table).changes().run(conn)
    while (yield feed.fetch_next()):
        change = yield feed.next()
        block = get_block_from_change(change, db_table)
        for client in clients:
            for tx in block:
                # TODO: use REQL for filtering
                if tx_contains_vk(tx['transaction'], client.username):
Example #8
0
 def _listen_events(self, ledger_id):
     ledger = get_bigchain(ledger_id=ledger_id)
     for change in r.table('bigchain').changes().run(ledger.conn):
         if change['old_val'] is None:
             self._handle_block(change['new_val'], ledger_id)