Project { public Transaction completeContract(Set<LHProtos.Pledge> pledges) { Transaction contract = new Transaction(params); outputs.forEach(contract::addOutput); long allPledgesValue = pledges.stream().mapToLong(pledge -> pledge.getPledgeDetails().getTotalInputValue()).sum(); if (allPledgesValue != goalAmount) throw new Ex.ValueMismatch(allPledgesValue - goalAmount); pledges.stream().map(this::fastSanityCheck).forEach(pledge -> { pledge.getInputs().forEach(contract::addInput); }); contract.setPurpose(Transaction.Purpose.ASSURANCE_CONTRACT_CLAIM); contract.verify(); return contract; } Project(LHProtos.ProjectDetails details);  Project(LHProtos.Project proto); static LHProtos.ProjectDetails.Builder makeDetails(NetworkParameters params, String title, String memo, Address to, Coin value, DeterministicKey authKey, int lookaheadSize); LHProtos.Project getProto(); LHProtos.ProjectDetails getProtoDetails(); String getID(); Sha256Hash getIDHash(); boolean isServerAssisted(); String getTitle(); String getEmail(); String getMemo(); Coin getGoalAmount(); ByteString getCoverImage(); List<TransactionOutput> getOutputs(); Instant getExpires(); boolean isExpired(); @Nullable URI getPaymentURL(); CompletableFuture<LHProtos.Pledge> verifyPledge(UTXOSource peer, LHProtos.Pledge pledge); Transaction fastSanityCheck(LHProtos.Pledge pledge); Transaction completeContract(Set<LHProtos.Pledge> pledges); CompletableFuture<LHProtos.ProjectStatus> getStatus(PledgingWallet wallet, @Nullable KeyParameter key); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); String getSuggestedFileName(); static String getSuggestedFileName(String title); Coin getMinPledgeAmount(); static Coin getMinPledgeAmountFrom(long minPledgeAmount); @Nullable String signAsOwner(PledgingWallet wallet, String message, @Nullable KeyParameter aesKey); void authenticateOwner(String message, String signatureBase64); byte[] getAuthKey(); int getAuthKeyIndex(); NetworkParameters getParams(); static final int COVER_IMAGE_WIDTH; static final int COVER_IMAGE_HEIGHT; static String GET_STATUS_USER_AGENT; }
@Test(expected = Ex.ValueMismatch.class) public void incompleteContract() throws Exception { TxData pledgeTX1 = makePledge(details, 0.1); TxData pledgeTX2 = makePledge(details, 0.7); LHProtos.Pledge.Builder pledge1 = LHProtos.Pledge.newBuilder(); pledge1.addTransactions(ByteString.copyFrom(pledgeTX1.pledge.bitcoinSerialize())); pledge1.getPledgeDetailsBuilder().setTotalInputValue((long) (Coin.COIN.longValue() * 0.1)); pledge1.getPledgeDetailsBuilder().setTimestamp(Utils.currentTimeSeconds()); pledge1.getPledgeDetailsBuilder().setProjectId("abc"); LHProtos.Pledge.Builder pledge2 = LHProtos.Pledge.newBuilder(); pledge2.addTransactions(ByteString.copyFrom(pledgeTX2.pledge.bitcoinSerialize())); pledge2.getPledgeDetailsBuilder().setTotalInputValue((long) (Coin.COIN.longValue() * 0.7)); pledge2.getPledgeDetailsBuilder().setTimestamp(Utils.currentTimeSeconds()); pledge2.getPledgeDetailsBuilder().setProjectId("abc"); pledge2.getPledgeDetailsBuilder(); Project project = new Project(projectBuilder.build()); Transaction contract = project.completeContract(ImmutableSet.of(pledge1.build(), pledge2.build())); assertEquals(2, contract.getInputs().size()); }
@Test public void completeContract() throws Exception { TxData pledgeTX1 = makePledge(details, 0.1); TxData pledgeTX2 = makePledge(details, 0.9); LHProtos.Pledge.Builder pledge1 = LHProtos.Pledge.newBuilder(); pledge1.addTransactions(ByteString.copyFrom(pledgeTX1.pledge.bitcoinSerialize())); pledge1.getPledgeDetailsBuilder().setTotalInputValue((long) (Coin.COIN.longValue() * 0.1)); pledge1.getPledgeDetailsBuilder().setTimestamp(Utils.currentTimeSeconds()); pledge1.getPledgeDetailsBuilder().setProjectId("abc"); pledge1.getPledgeDetailsBuilder(); LHProtos.Pledge.Builder pledge2 = LHProtos.Pledge.newBuilder(); pledge2.addTransactions(ByteString.copyFrom(pledgeTX2.pledge.bitcoinSerialize())); pledge2.getPledgeDetailsBuilder().setTotalInputValue((long) (Coin.COIN.longValue() * 0.9)); pledge2.getPledgeDetailsBuilder().setTimestamp(Utils.currentTimeSeconds()); pledge2.getPledgeDetailsBuilder().setProjectId("abc"); pledge2.getPledgeDetailsBuilder(); Project project = new Project(projectBuilder.build()); Transaction contract = project.completeContract(ImmutableSet.of(pledge1.build(), pledge2.build())); assertEquals(2, contract.getInputs().size()); }