Package lighthouse.protocol

Examples of lighthouse.protocol.Project


    }

    private void tryLoadPledge(Path path) {
        LHProtos.Pledge pledge = loadPledge(path);
        if (pledge != null) {
            Project project = getProjectById(pledge.getProjectId());
            if (project != null) {
                pledgesByPath.put(path, pledge);
                getPledgesOrCreate(project).add(pledge);
            } else {
                // TODO: This can happen if we're importing a project that already has pledges next to the file.
View Full Code Here


    }

    @Nullable
    public Project tryLoadProject(Path path, int indexToReplace) {
        executor.checkOnThread();
        Project p = loadProject(path);
        if (p != null) {
            synchronized (this) {
                if (projectsById.containsKey(p.getID()) && indexToReplace < 0) {
                    log.info("Already have project id {}, skipping load", p.getID());
                    return projectsById.get(p.getID());
                }
                projectsById.put(p.getID(), p);
            }
            if (indexToReplace >= 0) {
                projects.set(indexToReplace, p);
                log.info("Replaced project at index {} with newly loaded project", indexToReplace);
            } else {
                projects.add(p);
            }
            projectsByPath.put(path, p);
            if (!projectStates.containsKey(p.getID())) {
                // Assume new projects are open: we have no other way to tell for now: would require a block explorer
                // lookup to detect that the project came and went already. But we do remember even if the project
                // is deleted and came back.
                projectStates.put(p.getID(), new LighthouseBackend.ProjectStateInfo(LighthouseBackend.ProjectState.OPEN, null));
            }
        }
        return p;
    }
View Full Code Here

    @Nullable
    private static Project loadProject(Path from) {
        log.info("Attempting to load project file {}", from);
        try (InputStream is = Files.newInputStream(from)) {
            LHProtos.Project proto = LHProtos.Project.parseFrom(is);
            return new Project(proto);
        } catch (IOException e) {
            log.error("File appeared in directory but could not be read, ignoring: {}", e.getMessage());
            return null;
        } catch (PaymentProtocolException e) {
            // Don't know how to load this file!
View Full Code Here

        }
    }

    public Project saveProject(LHProtos.Project project, String fileID) throws IOException {
        // Probably on the UI thread here. Do the IO write on the UI thread to simplify error handling.
        final Project obj = unchecked(() -> new Project(project));
        final Path filename = Paths.get(fileID + PROJECT_FILE_EXTENSION);
        final Path path = AppDirectory.dir().resolve(filename + ".tmp");
        log.info("Saving project to: {}", path);
        // Do a write to a temp file name here to ensure a project file is not partially written and becomes partially
        // visible via directory notifications.
View Full Code Here

            @Override
            public void onCoinsSent(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
                flags[1] = true;
            }
        }, Threading.SAME_THREAD);
        Project project = new Project(makeProject(wallet, 100_000));
        PledgingWallet.PendingPledge pledge = wallet.createPledge(project, 100_000, null);
        assertNull(pledge.dependency);
        assertNotNull(pledge.pledge);
        final LHProtos.Pledge commit = pledge.commit(true);
        assertEquals(500_000, objects.wallet.getBalance().longValue());
        assertTrue(flags[0]);
        assertTrue(flags[1]);

        Transaction contract = project.completeContract(ImmutableSet.of(commit));
        assertEquals(contract.getInput(0).duplicateDetached(), pledge.pledge.getInput(0).duplicateDetached());
        List<TransactionOutput> outputs = ImmutableList.of(checkNotNull(pledge.pledge.getInput(0).getConnectedOutput()).duplicateDetached());
        project.verifyPledge(outpoint -> CompletableFuture.completedFuture(outputs), commit).get();
    }
View Full Code Here

        // sized stub output.
        WalletTestObjects objects = new WalletTestObjects(() -> new PledgingWallet(UnitTestParams.get()));
        PledgingWallet wallet = (PledgingWallet) objects.wallet;
        objects.sendAmounts(1_000_000, 2_000_000);

        Project project = new Project(makeProject(wallet, 3_000_000));
        PledgingWallet.PendingPledge pledge = wallet.createPledge(project, 2_500_000, null);
        assertNotNull(pledge.dependency);
        assertNotNull(pledge.pledge);
        assertEquals(2, pledge.dependency.getOutputs().size());
        assertTrue(2_500_000 == pledge.dependency.getOutput(0).getValue().longValue() ||
View Full Code Here

    public void dontSpendStubs() throws Exception {
        // Form a pledge and then try to spend it with another pledge. Should reject.
        WalletTestObjects objects = new WalletTestObjects(() -> new PledgingWallet(UnitTestParams.get()));
        PledgingWallet wallet = (PledgingWallet) objects.wallet;
        objects.sendAmounts(1_000_000);
        Project project = new Project(makeProject(wallet, 3_000_000));
        PledgingWallet.PendingPledge pledge = wallet.createPledge(project, 1_000_000, null);
        pledge.commit(true);
        // Check that pledges are serialized.
        wallet = roundtripWallet(wallet);
        // This line should fail because the output we received is already pledged elsewhere.
View Full Code Here

    public void canRevokePledges() throws Exception {
        WalletTestObjects objects = new WalletTestObjects(() -> new PledgingWallet(UnitTestParams.get()));
        PledgingWallet wallet = (PledgingWallet) objects.wallet;
        objects.sendAmounts(1_000_000);

        Project project = new Project(makeProject(wallet, 3_000_000));
        PledgingWallet.PendingPledge pledge = wallet.createPledge(project, 500_000, null);
        pledge.commit(true);
        final MockTransactionBroadcaster.TxFuturePair txFuturePair = objects.broadcaster.waitForTxFuture();
        txFuturePair.succeed();
        Transaction stubTx = txFuturePair.tx;
View Full Code Here

    public void claim() throws Exception {
        // Check the wallet notices when its pledge has been claimed and understands the current state.

        WalletTestObjects objects1 = new WalletTestObjects(() -> new PledgingWallet(UnitTestParams.get()));
        PledgingWallet wallet1 = (PledgingWallet) objects1.wallet;
        Project project = new Project(makeProject(wallet1, 1_000_000));
        objects1.sendAmounts(1_000_000);
        PledgingWallet.PendingPledge ppledge1 = wallet1.createPledge(project, 500_000, null);
        LHProtos.Pledge pledge1 = ppledge1.commit(true);
        {
            final MockTransactionBroadcaster.TxFuturePair txFuturePair = objects1.broadcaster.waitForTxFuture();
            txFuturePair.succeed();
        }

        WalletTestObjects objects2 = new WalletTestObjects(() -> new PledgingWallet(UnitTestParams.get()));
        PledgingWallet wallet2 = (PledgingWallet) objects2.wallet;
        objects2.sendAmounts(1_000_000);
        PledgingWallet.PendingPledge ppledge2 = wallet2.createPledge(project, 500_000, null);
        LHProtos.Pledge pledge2 = ppledge2.commit(true);
        {
            final MockTransactionBroadcaster.TxFuturePair txFuturePair = objects2.broadcaster.waitForTxFuture();
            txFuturePair.succeed();
        }

        LHProtos.Pledge[] claimedPledge = new LHProtos.Pledge[1];
        Transaction[] claimTx = new Transaction[1];
        wallet1.addOnClaimHandler((p, tx) -> {
            claimedPledge[0] = p;
            claimTx[0] = tx;
        }, Threading.SAME_THREAD);

        // We now have two wallets that have made two separate pledges, which is sufficient to complete the project.
        Transaction contract = project.completeContract(ImmutableSet.of(pledge1, pledge2));
        objects1.receiveViaBlock(contract);

        assertEquals(pledge1, claimedPledge[0]);
        assertEquals(2, claimTx[0].getInputs().size());
        assertEquals(project.getOutputs(), claimTx[0].getOutputs());
    }
View Full Code Here

                contractOuts.put(tx.getOutput(0), pledge);
                log.info("Loaded pledge {}", LHUtils.hashFromPledge(pledge));
                wallet.pledges.put(output, pledge);
            }
            for (LHProtos.Project project : ext.getProjectsList()) {
                Project p = new Project(project);
                LHProtos.Pledge pledgeForProject = contractOuts.get(p.getOutputs().get(0));
                wallet.projects.put(p, pledgeForProject);
            }
            for (LHProtos.Pledge pledge : ext.getRevokedPledgesList()) {
                wallet.revokedPledges.put(hashFromPledge(pledge), pledge);
            }
View Full Code Here

TOP

Related Classes of lighthouse.protocol.Project

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.