Ejemplo n.º 1
0
def example(txn) -> tc.Number:
    txn.a = tc.Number(5) # this is a State
    txn.b = tc.Number(10) # this is a State
    txn.product = txn.a * txn.b # this is a Ref
    return txn.product
Ejemplo n.º 2
0
 def _configure(self):
     self.weight = tc.Chain.Sync(tc.Number(0))
Ejemplo n.º 3
0
import unittest
import tinychain as tc

from testutils import start_host


CONSERVED = tc.Number(20)


class Balance(tc.Cluster):
    __uri__ = tc.URI("/app/balance")

    def _configure(self):
        self.weight = tc.Chain.Sync(10)


class Left(Balance):
    __uri__ = "http://127.0.0.1:8702" + tc.uri(Balance)

    @tc.put_method
    def weigh(self, txn, key: tc.Nil, new_value: tc.Number):
        right = tc.use(Right)

        txn.total = CONSERVED
        txn.current = self.weight.subject()
        txn.update = tc.After(
            self.weight.set(new_value),
            right.weigh(None, txn.total - new_value))

        return tc.If(txn.current == new_value, None, txn.update)
Ejemplo n.º 4
0
 def _configure(self):
     self.rev = tc.Chain.Sync(tc.Number(0))