Отсутствуют подписи в транзакции 3CA098 для ключей: - подписавшими: com.template.contracts.IOUContract.Create - PullRequest
0 голосов
/ 28 января 2020

Мой класс Контракта, в котором объявлен класс Create, должен ли я написать что-то и в классе create? Новичок в corda, так что если у кого-то есть какие-либо ссылки, Учебники, Примеры изучения corda с "Java", пожалуйста, поделитесь в комментариях плюс уже завершенные Ключевые концепции из Do c. Заранее спасибо

```

    package com.template.contracts;

    import com.template.states.IOUState;
    import net.corda.core.contracts.CommandData;
    import net.corda.core.contracts.Contract;
    import net.corda.core.transactions.LedgerTransaction;
    import net.corda.core.contracts.CommandWithParties;
    import net.corda.core.identity.Party;

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


    import static net.corda.core.contracts.ContractsDSL.requireSingleCommand;

    // ************
    // * Contract *
    // ************
    public class IOUContract implements Contract {
        // This is used to identify our contract when building a transaction.
        public static final String ID = "com.template.contracts.IOUContract";

        //our Create Command
        public static class Create implements CommandData{

        }

        // A transaction is valid if the verify() function of the contract of all the transaction's input and output states
        // does not throw an exception.
        @Override
        public void verify(LedgerTransaction tx) {
            final CommandWithParties<IOUContract.Create> command =requireSingleCommand(tx.getCommands(),IOUContract.Create.class);

            //Constraints on the shape of the transaction

            if(!tx.getInputs().isEmpty())
                throw new IllegalArgumentException("No inputs should be consumed when issuisng an IOU.");
            if(!(tx.getOutputs().size()==1))
                throw new IllegalArgumentException("There should be one output state of type IOUState.");

            //IOU-specific constraints.
            final IOUState  output =tx.outputsOfType(IOUState.class).get(0);
            final Party lender = output.getLender();
            final Party borrower =output.getBorrower();
            if(output.getValue()<=0)
                throw new IllegalArgumentException("This IOU's value must be non-negative");
            if(lender.equals(borrower))
                throw new IllegalArgumentException("The lender and the borrower cannot be same entity");

            //Constraints on the signers.
            final List<PublicKey> requiredSigners =command.getSigners();
            final List<PublicKey> exceptedSigners =Arrays.asList(borrower.getOwningKey(),lender.getOwningKey());
            if(requiredSigners.size() !=  2)
                throw new IllegalArgumentException("There must be two signers");
            if(!(requiredSigners.containsAll(exceptedSigners)))
                throw new IllegalArgumentException("The borrower and lender must be signers.");
        }

        // Used to indicate the transaction's intent.
        public interface Commands extends CommandData {
            class Action implements Commands {}
        }
```

Ссылка:

Followed the link:- "https://docs.corda.r3.com/tut-two-party-contract.html"

1 Ответ

0 голосов
/ 28 января 2020
  1. Внутри вашего государственного контракта вы устанавливаете правила валидации. Например, в Create как заемщик, так и кредитор должны требовать подписывающих лиц: https://github.com/corda/samples/blob/018502310b56bc1bb31440380af4b89e9bbd7ed8/cordapp-example/contracts-java/src/main/java/com/example/contract/IOUContract.java#L46
  2. Внутри потока, когда вы назначаете команду для транзакции, вы должны указать, кто необходимые подписывающие лица (они должны соответствовать ожиданиям вашего контракта): https://github.com/corda/samples/blob/018502310b56bc1bb31440380af4b89e9bbd7ed8/cordapp-example/workflows-java/src/main/java/com/example/flow/ExampleFlow.java#L91
  3. Если исходный узел потока является кредитором, узел подписывает транзакцию: https://github.com/corda/samples/blob/018502310b56bc1bb31440380af4b89e9bbd7ed8/cordapp-example/workflows-java/src/main/java/com/example/flow/ExampleFlow.java#L106
  4. В потоке респондента заемщик также подписывает транзакцию: https://github.com/corda/samples/blob/018502310b56bc1bb31440380af4b89e9bbd7ed8/cordapp-example/workflows-java/src/main/java/com/example/flow/ExampleFlow.java#L150

Таким образом, вы собрали обе подписи.

...