Search in sources :

Example 6 with Approvable

use of com.icodici.universa.Approvable in project universa by UniversaBlockchain.

the class SplitJoinPermission method checkSplitJoinCase.

private boolean checkSplitJoinCase(Contract changed) {
    Decimal splitJoinSum = Decimal.ZERO;
    for (Contract c : changed.getSiblings()) {
        splitJoinSum = splitJoinSum.add(new Decimal(c.getStateData().getString(fieldName)));
    }
    Decimal rSum = Decimal.ZERO;
    for (Approvable r : changed.getRevokingItems()) {
        if (r instanceof Contract) {
            Contract c = (Contract) r;
            if (!isMergeable(c) || !validateMergeFields(changed, c))
                return false;
            rSum = rSum.add(new Decimal(((Contract) r).getStateData().getString(fieldName)));
        }
    }
    return splitJoinSum.compareTo(rSum) == 0;
}
Also used : Decimal(com.icodici.universa.Decimal) Approvable(com.icodici.universa.Approvable) Contract(com.icodici.universa.contract.Contract)

Example 7 with Approvable

use of com.icodici.universa.Approvable in project universa by UniversaBlockchain.

the class SplitJoinPermission method checkMerge.

private void checkMerge(Contract changed, MapDelta<String, Binder, Binder> dataChanges, Decimal newValue) {
    boolean isValid;
    // merge means there are mergeable contracts in the revoking items
    Decimal sum = Decimal.ZERO;
    for (Approvable a : changed.getRevokingItems()) {
        if (a instanceof Contract) {
            Contract c = (Contract) a;
            if (!isMergeable(c) || !validateMergeFields(changed, c))
                return;
            sum = sum.add(new Decimal(getFieldName(c)));
        }
    }
    isValid = sum.compareTo(newValue) == 0;
    if (!isValid)
        isValid = checkSplitJoinCase(changed);
    if (isValid)
        dataChanges.remove(fieldName);
}
Also used : Decimal(com.icodici.universa.Decimal) Approvable(com.icodici.universa.Approvable) Contract(com.icodici.universa.contract.Contract)

Example 8 with Approvable

use of com.icodici.universa.Approvable in project universa by UniversaBlockchain.

the class MainTest method registerContract500_seal.

@Test
public void registerContract500_seal() throws Exception {
    TestSpace ts = prepareTestSpace();
    Contract contract = createContract500(ts.myKey);
    ItemResult itemResult = ts.client.register(contract.getLastSealedBinary(), 10000);
    assertEquals(ItemState.DECLINED, itemResult.state);
    int i = 0;
    for (Approvable sub : contract.getNewItems()) {
        ItemResult subItemResult = ts.client.getState(sub);
        System.out.println("" + (i++) + " - " + subItemResult.state);
        assertEquals(ItemState.UNDEFINED, subItemResult.state);
    }
    ts.nodes.forEach(n -> n.shutdown());
}
Also used : Approvable(com.icodici.universa.Approvable) Test(org.junit.Test)

Example 9 with Approvable

use of com.icodici.universa.Approvable in project universa by UniversaBlockchain.

the class MainTest method registerContract500approvedHalf_seal.

@Test
public void registerContract500approvedHalf_seal() throws Exception {
    TestSpace ts = prepareTestSpace();
    Contract contract = createContract500(ts.myKey);
    int i = 0;
    for (Approvable sub : contract.getNewItems()) {
        ++i;
        Contract subContract = (Contract) sub;
        if (i % 2 == 0) {
            ItemResult subItemResult = ts.client.register(subContract.getLastSealedBinary(), 1000);
            assertEquals(ItemState.APPROVED, subItemResult.state);
        } else {
            ItemResult subItemResult = ts.client.getState(subContract.getId());
            assertEquals(ItemState.UNDEFINED, subItemResult.state);
        }
        if (i % 10 == 0)
            System.out.println("register subContract: " + i);
    }
    ItemResult itemResult = ts.client.register(contract.getLastSealedBinary(), 10000);
    assertEquals(ItemState.DECLINED, itemResult.state);
    i = 0;
    for (Approvable sub : contract.getNewItems()) {
        ++i;
        ItemResult subItemResult = ts.client.getState(sub);
        System.out.println("" + i + " - " + subItemResult.state);
        if (i % 2 == 0)
            assertEquals(ItemState.APPROVED, subItemResult.state);
        else
            assertEquals(ItemState.UNDEFINED, subItemResult.state);
    }
    ts.nodes.forEach(n -> n.shutdown());
}
Also used : Approvable(com.icodici.universa.Approvable) Test(org.junit.Test)

Example 10 with Approvable

use of com.icodici.universa.Approvable in project universa by UniversaBlockchain.

the class MainTest method registerContract500approved_pack.

@Test
public void registerContract500approved_pack() throws Exception {
    TestSpace ts = prepareTestSpace();
    Contract contract = createContract500(ts.myKey);
    int i = 0;
    for (Approvable sub : contract.getNewItems()) {
        Contract subContract = (Contract) sub;
        ItemResult subItemResult = ts.client.register(subContract.getLastSealedBinary(), 1000);
        assertEquals(ItemState.APPROVED, subItemResult.state);
        ++i;
        if (i % 10 == 0)
            System.out.println("register subContract: " + i);
    }
    System.out.println("register parent contract...");
    ItemResult itemResult = ts.client.register(contract.getPackedTransaction(), 30000);
    assertEquals(ItemState.DECLINED, itemResult.state);
    Thread.sleep(5000);
    i = 0;
    for (Approvable sub : contract.getNewItems()) {
        ItemResult subItemResult = ts.client.getState(sub);
        System.out.println("" + (i++) + " - " + subItemResult.state);
        assertEquals(ItemState.APPROVED, subItemResult.state);
    }
    ts.nodes.forEach(n -> n.shutdown());
}
Also used : Approvable(com.icodici.universa.Approvable) Test(org.junit.Test)

Aggregations

Approvable (com.icodici.universa.Approvable)11 Test (org.junit.Test)6 Decimal (com.icodici.universa.Decimal)3 Contract (com.icodici.universa.contract.Contract)3 PrivateKey (com.icodici.crypto.PrivateKey)1 HashId (com.icodici.universa.HashId)1