首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >net.corda.confidential.SwapIdentitiesFlow;

net.corda.confidential.SwapIdentitiesFlow;
EN

Stack Overflow用户
提问于 2018-12-25 14:56:21
回答 1查看 271关注 0票数 0

gradlew.bat洁净deployNodesJava的控制台输出

在我的flow类中使用SwapIdentitiesFlow(所有者)之后,我的项目就无法工作了(下面的代码)。我已经使用Gradle重新导入了我的项目,但没有任何好处。我仍然得到:“错误:包net.corda.confidential不存在导入net.corda.confidential

有趣的是,外部库有一个名字类似的文件( net.corda:corda-confidential-identities:corda-3.0) Gradle: This和语句也存在。

其他类似的问题并没有帮助,正如我提到的,重新导入该项目不起作用。一开始,我在那门课上得到了一条红线。提示我为它添加类路径。构建没有错误,但是gradlew.bat..。确实如此。

谢谢你的帮助。

代码语言:javascript
复制
package java_bootcamp;

import co.paralleluniverse.fibers.Suspendable;
import com.google.common.collect.ImmutableList;
import net.corda.confidential.SwapIdentitiesFlow;
import net.corda.core.contracts.StateAndRef;
import net.corda.core.flows.*;
import net.corda.core.identity.AbstractParty;
import net.corda.core.identity.AnonymousParty;
import net.corda.core.identity.Party;
import net.corda.core.transactions.SignedTransaction;
import net.corda.core.transactions.TransactionBuilder;
import net.corda.core.utilities.ProgressTracker;

import java.security.PublicKey;
import java.util.HashMap;
import java.util.List;

@InitiatingFlow
@StartableByRPC
public class BallotTransferFlow extends FlowLogic<SignedTransaction> {
private final Party owner;

public BallotTransferFlow(Party owner)
{
    this.owner = owner;
}

private final ProgressTracker progressTracker = new ProgressTracker();

@Override
public ProgressTracker getProgressTracker() {
    return progressTracker;
}


@Suspendable
public SignedTransaction call() throws FlowException {
    // We get a reference to our own identity.
    AbstractParty issuer = getOurIdentity();

    // We extract all the `VoteStates from the vault.
    List<StateAndRef<VoteState>> voteStateAndRefs = getServiceHub().getVaultService().queryBy(VoteState.class).getStates();

    // We find the `VoteState` of the issuer.
    StateAndRef<VoteState> inputVoteStateAndRef = voteStateAndRefs
            .stream().filter(voteStateAndRef -> {
                VoteState voteState = voteStateAndRef.getState().getData();
                return voteState.getOwner().equals(issuer) && voteState.getVote()==1;
            }).findAny().orElseThrow(() -> new IllegalArgumentException("The Ballot State for this owner was not found."));
    VoteState inputVoteState = inputVoteStateAndRef.getState().getData();


    // We find the `VoteState` of the candidate.
    StateAndRef<VoteState> inputVoteStateAndRef1 = voteStateAndRefs
            .stream().filter(voteStateAndRef -> {
                VoteState voteState = voteStateAndRef.getState().getData();
                return voteState.getOwner().equals(owner);
            }).findAny().orElseThrow(() -> new IllegalArgumentException("The Candidate State for this owner was not found."));
    VoteState oldCandidateState = inputVoteStateAndRef1.getState().getData();


    // We throw an exception if the flow was not started by the ballot's current owner.
    if (!(issuer.equals(inputVoteState.getOwner())))
        throw new IllegalStateException("This flow must be started by the current owner.");

    // We use the notary used by the input state.
    Party notary = inputVoteStateAndRef1.getState().getNotary();

    // We build a transaction using a `TransactionBuilder`.
    TransactionBuilder txBuilder = new TransactionBuilder(notary);


    VoteContract.Commands.Transfer commandData = new VoteContract.Commands.Transfer();
    final HashMap<Party, AnonymousParty> txKeys = subFlow(new SwapIdentitiesFlow(owner));
    if (txKeys.size() != 2) {
        throw new IllegalStateException("Something went wrong when generating confidential identities.");
    } else if (!txKeys.containsKey(getOurIdentity())) {
        throw new FlowException("Couldn't create our conf. identity.");
    } else if (!txKeys.containsKey(owner)) {
        throw new FlowException("Couldn't create lender's conf. identity.");
    }

    final AnonymousParty anonymousMe = txKeys.get(getOurIdentity());
    final AnonymousParty anonymousLender = txKeys.get(owner);

    // New Candidate State
    VoteState newCandidateState = new VoteState(oldCandidateState.getVote()+1, anonymousLender, anonymousMe);

    txBuilder.addInputState(inputVoteStateAndRef);
    txBuilder.addOutputState(newCandidateState, VoteContract.ID );
    List<PublicKey> requiredSigners = ImmutableList.of(inputVoteState.getOwner().getOwningKey());

    txBuilder.addCommand(commandData, requiredSigners);

    // We check that the transaction builder we've created meets the
    // contracts of the input and output states.
    txBuilder.verify(getServiceHub());


    // We sign the transaction with our private key, making it immutable.
    SignedTransaction signedTransaction = getServiceHub().signInitialTransaction(txBuilder);

    // We get the transaction notarised and recorded automatically by the platform.
    return subFlow(new FinalityFlow(signedTransaction));
}
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-03 16:00:05

从Corda 3开始,您可以通过将以下cordaCompile依赖项添加到build.gradle文件的dependencies块来修复这个问题:

代码语言:javascript
复制
cordaCompile "$corda_release_group:corda-confidential-identities:$corda_release_version"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53923415

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档