Исключение потока в CollectSignaturesFlow - PullRequest
0 голосов
/ 27 июня 2018

Я создаю поток для извлечения подписей из CollectSignaturesFlow другой стороны, и я сталкиваюсь с проблемой ниже в журнале.

@InitiatingFlow
@StartableByRPC
public static class BGInitiator extends FlowLogic<SignedTransaction> {

    private final Party manufacturer;
    private final Party regulator;
    private final String bgData;

    public BGInitiator(Party manufacturer,Party regulator, String bgData) {
        this.manufacturer = manufacturer;
        this.regulator = regulator;
        this.bgData = bgData;
    }
    private final Step GENERATING_TRANSACTION = new Step("Generating transaction based on YO.");
    private final Step BUILDING_TRANSACTION = new Step("Verifying contract constraints.");
    private final Step SIGNING_TRANSACTION = new Step("Signing transaction with our private key.");
    private final Step GATHERING_SIGS = new Step("Gathering the counterparty's signature.") {
        @Override
        public ProgressTracker childProgressTracker() {
            return CollectSignaturesFlow.Companion.tracker();
        }
    };
    private final Step FINALISING_TRANSACTION = new Step("Obtaining notary signature and recording transaction.") {
        @Override
        public ProgressTracker childProgressTracker() {
            return FinalityFlow.Companion.tracker();
        }
    };

    private final ProgressTracker progressTracker = new ProgressTracker(
            GENERATING_TRANSACTION,
            BUILDING_TRANSACTION,
            SIGNING_TRANSACTION,
            GATHERING_SIGS,
            FINALISING_TRANSACTION
    );

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

    @Suspendable
    @Override
    public SignedTransaction call() throws FlowException {
        progressTracker.setCurrentStep(GENERATING_TRANSACTION);

        Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);
        BGState bgState = new BGState(getOurIdentity(),manufacturer,regulator,bgData);

        progressTracker.setCurrentStep(BUILDING_TRANSACTION);
        final List<PublicKey> requiredSigners = bgState.getParticipantKeys();
        final List<Party> parties = bgState.getParties();
         final PublicKey me = bgState.getSeller().getOwningKey();


        final TransactionBuilder tb = new TransactionBuilder(notary)
                .addOutputState(bgState,BGContract.BG_CONTRACT_ID)
                .addCommand(new BGContract.Commands.Send(),requiredSigners);

        progressTracker.setCurrentStep(SIGNING_TRANSACTION);
        final SignedTransaction ptx = getServiceHub().signInitialTransaction(tb,me);

        progressTracker.setCurrentStep(GATHERING_SIGS);



        FlowSession manufacturerflow = initiateFlow(manufacturer);
        final SignedTransaction stx = subFlow(new CollectSignaturesFlow(ptx,ImmutableSet.of(manufacturerflow),ImmutableList.of(me),GATHERING_SIGS.childProgressTracker()));

        progressTracker.setCurrentStep(FINALISING_TRANSACTION);
        return subFlow(new FinalityFlow(stx,FINALISING_TRANSACTION.childProgressTracker()));
    }
}

После развертывания и выполнения поток останавливается, выдавая мне следующую ошибку:

java.lang.IllegalArgumentException: The Initiator of CollectSignaturesFlow must pass in exactly the sessions required to sign the transaction.
at net.corda.core.flows.CollectSignaturesFlow.call(CollectSignaturesFlow.kt:108) ~[corda-core-2.0.0.jar:?]
at net.corda.core.flows.CollectSignaturesFlow.call(CollectSignaturesFlow.kt:64) ~[corda-core-2.0.0.jar:?]
at net.corda.core.flows.FlowLogic.subFlow(FlowLogic.kt:243) ~[corda-core-2.0.0.jar:?]
at com.example.flow.BGFlow$BGInitiator.call(BGFlow.java:107) ~[java-source-0.1.jar:?]

Я считаю, что я прохожу необходимый сеанс потока, и я все еще получаю это. Есть идеи, как это решить?

Редактировать 1: когда я заменяю потоковую сессию на несколько сессий, используя приведенный ниже код и выполняю его, поток срабатывает и даже ничего не записывает в журналы. Я хотел бы знать, является ли следующий способ верным для получения подписей.

 List<FlowSession> flowSessions = parties.stream().map(a -> initiateFlow(a)).collect(Collectors.toList());
        final SignedTransaction stx = subFlow(new CollectSignaturesFlow(ptx,flowSessions,ImmutableList.of(me),GATHERING_SIGS.childProgressTracker()));

Код getParties () в BGState:

public List<Party> getParties(){
    return Arrays.asList(manufacturer,regulator);
}

Определение BGState:

public class BGState implements LinearState,QueryableState {

private final Party seller;
private final Party manufacturer;
private final Party regulator;
private final String senderToReceiverInformation;
private final UniqueIdentifier linearId;



public BGState(Party seller, Party manufacturer,Party regulator,String senderToReceiverInformation) {
    this.seller = seller;
    this. manufacturer= manufacturer;
    this.regulator = regulator;
    this.senderToReceiverInformation = senderToReceiverInformation;
    this.linearId = new UniqueIdentifier();
}


public Party getSeller() {
    return seller;
}

public Party getManufacturer() {
    return manufacturer;
}

public Party getRegulator() {
    return regulator;
}



@NotNull
@Override
public UniqueIdentifier getLinearId() {
    return linearId;
}

@NotNull
@Override
public PersistentState generateMappedObject(MappedSchema schema) {
    if (schema instanceof BGSchema) {
        return new BGSchema.Bg760(
                this.seller,
                this.manufacturer,
                this.regulator,
                this.senderToReceiverInformation,
                this.linearId
        );
    } else {
        throw new IllegalArgumentException("Unrecognised schema $schema");
    }
}

@NotNull
@Override
public Iterable<MappedSchema> supportedSchemas() {
    return ImmutableList.of(new BGSchema());
}

@NotNull
@Override
public List<AbstractParty> getParticipants() {
    return Arrays.asList(seller,manufacturer,regulator);
}
public List<PublicKey> getParticipantKeys(){
    return  getParticipants().stream().map(AbstractParty :: getOwningKey).collect(Collectors.toList());
}
public List<Party> getParties(){
    return Arrays.asList(manufacturer,regulator);
}

}

1 Ответ

0 голосов
/ 27 июня 2018

Список FlowSession с, переданный CollectSignaturesFlow, должен точно соответствовать требуемым подписавшим транзакции.

В этом случае FlowSession не было передано для регулятора, который является одним из обязательных подписантов.

...