Java 验证两方之间的事务时出错

Java 验证两方之间的事务时出错,java,corda,Java,Corda,我得到以下错误: [错误]14:37:15-0400[节点线程-1]内部验证程序。-验证事务95C242529D07CCC5F657909F7A1D40EF8F5BD5D748D81E97C3E4F2534BC54334时出错。[errorCode=1英尺47m,更多信息位于=https://errors.corda.net/OS/4.4/1oup47m] {actor_id=internalShell,actor_-owning_-identity=O=Toyota,L=London,C=GB

我得到以下错误:

[错误]14:37:15-0400[节点线程-1]内部验证程序。-验证事务95C242529D07CCC5F657909F7A1D40EF8F5BD5D748D81E97C3E4F2534BC54334时出错。[errorCode=1英尺47m,更多信息位于=https://errors.corda.net/OS/4.4/1oup47m] {actor_id=internalShell,actor_-owning_-identity=O=Toyota,L=London,C=GB,actor_-store_-id=NODE_-CONFIG,fiber-id=10000001,flow-id=b716ec51-d40e-4a9e-a7bc-d3e917ea6dd8,invocation_-id=a317a00a-af20-454a-bcc7-02d131be67c7,invocation_-timestamp=2020-06-23T18:37:13.897Z,origin=internalShell,session=session_-B8796-077;=908;-A478;-3741;-A30340,session次tamp=2020-06-23T18:37:12.984Z,螺纹id=188}

当我尝试从Corda node(丰田)终端运行时:

start carregistration流程发起人carMake:Toyota,carModel:Rav4,车年:2016,carMileage:31424.0,carVin:asdfghjkloiu76543,车主:“O=AutoSmart,L=New York,C=US”

我有丰田和AutoSmart两方。丰田是发行人,AutoSmart是所有者

CarState:


import com.template.contracts.CarContract;
import net.corda.core.contracts.BelongsToContract;
import net.corda.core.contracts.ContractState;
import net.corda.core.identity.AbstractParty;
import net.corda.core.identity.Party;
import org.jetbrains.annotations.NotNull;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@BelongsToContract(CarContract.class)
public class CarState implements ContractState {

    private String carMake;
    private String carModel;
    private int carYear;
    private float carMileAge;
    private String carVIN;
    private Party issuer;
    private Party owner;

    public CarState(String carMake, String carModel, int carYear, float carMileAge, String carVIN, Party issuer, Party owner) {
        this.carMake = carMake;
        this.carModel = carModel;
        this.carYear = carYear;
        this.carMileAge = carMileAge;
        this.carVIN = carVIN;
        this.issuer = issuer;
        this.owner = owner;
    }


    public String getCarMake() {
        return carMake;
    }

    public String getCarModel() {
        return carModel;
    }

    public int getCarYear() {
        return carYear;
    }

    public float getCarMileAge() {
        return carMileAge;
    }

    public String getCarVIN() {
        return carVIN;
    }

    public Party getIssuer(){
        return issuer;
    }

    public Party getOwner(){
        return owner;
    }

    @NotNull
    @Override
    public List<AbstractParty> getParticipants() {
        return Arrays.asList(issuer,owner);

    }
}

导入com.template.contracts.CarContract;
导入net.corda.core.contracts.BelongsToContract;
导入net.corda.core.contracts.ContractState;
导入net.corda.core.identity.AbstractParty;
导入net.corda.core.identity.Party;
导入org.jetbrains.annotations.NotNull;
导入java.util.ArrayList;
导入java.util.array;
导入java.util.List;
@BelongsToContract(CarContract.class)
公共类CarState实现ContractState{
私人字符串卡马克;
私人字符串卡莫德尔;
私人国际年;
私人浮动卡梅利;
私人字符串卡文;
私人发行人;
私人业主;
公共CarState(字符串carMake、字符串carModel、整数carYear、浮动carMileAge、字符串carVIN、第三方发行人、第三方所有者){
this.carMake=carMake;
this.carModel=carModel;
this.carYear=carYear;
这个.carMileAge=carMileAge;
这个。卡文=卡文;
this.issuer=发行人;
this.owner=所有者;
}
公共字符串getCarMake(){
返回卡马克;
}
公共字符串getCarModel(){
返回carModel;
}
公共整数getCarYear(){
返回年份;
}
公共浮点数{
返回卡梅隆;
}
公共字符串getCarVIN(){
返回卡文;
}
公众党{
退货发行人;
}
公共方getOwner(){
归还所有人;
}
@NotNull
@凌驾
公开名单{
返回数组.asList(颁发者、所有者);
}
}
CarContract


import net.corda.core.contracts.Command;
import net.corda.core.contracts.CommandData;
import net.corda.core.contracts.Contract;
import net.corda.core.contracts.ContractState;
import net.corda.core.identity.Party;
import net.corda.core.transactions.LedgerTransaction;
import org.jetbrains.annotations.NotNull;
import com.template.states.CarState;

import java.awt.*;
import java.security.PublicKey;
import java.util.List;

public class CarContract implements Contract {
    public static final String CID = "com.template.contracts.CarContract";

    @Override
    public void verify(@NotNull LedgerTransaction tx) throws IllegalArgumentException {


    // shape constraints
    if (tx.getCommands().size()!=1){
        throw new IllegalArgumentException("Should contain only one command");
    }

    Command command = tx.getCommand(0);
    CommandData commandType = command.getValue();

    if(commandType instanceof Register){

        // shape constraints
        if (!(tx.getInputStates().size()!=0)){
            throw new IllegalArgumentException("Registration contract should have no input states.");
        }

        if (tx.getOutputStates().size() != 1){
            throw new IllegalArgumentException("Registration contract should only have single output state");
        }

        // content constraints
        ContractState outputState = tx.getOutput(0);

        if (!(outputState instanceof CarState)){
            throw new IllegalArgumentException("Not a car state");
        }


        if (!((CarState) outputState).getCarMake().equals("Toyota") ||
                ((CarState) outputState).getCarMake().equals("Honda") ||
                ((CarState) outputState).getCarMake().equals("Subaru")){
            throw new IllegalArgumentException("Car must be either a Honda, Toyota or a Subaru");
        }

        if (((CarState) outputState).getCarYear()<2015){
            throw new IllegalArgumentException("Car must not be older than 2015 year model.");
        }

        if (((CarState) outputState).getCarVIN().length()!=17){
            throw new IllegalArgumentException("VIN must be 17 characters in length and valid.");
        }
        //signers constraints
        Party issuer = ((CarState) outputState).getIssuer();
        PublicKey issuerKey = issuer.getOwningKey();

        List<PublicKey> requiredSigners = command.getSigners();
        if (!(requiredSigners.contains(issuerKey))){
            throw new IllegalArgumentException("Both issuer and owner of car must sign the contract.");
        }

    }
    else{

        throw new IllegalArgumentException("Commnd type not recognixed");
    }

     //
    }

    public static class Register implements CommandData{};

}

导入net.corda.core.contracts.Command;
导入net.corda.core.contracts.CommandData;
导入net.corda.core.contracts.Contract;
导入net.corda.core.contracts.ContractState;
导入net.corda.core.identity.Party;
导入net.corda.core.transactions.LedgerTransaction;
导入org.jetbrains.annotations.NotNull;
导入com.template.states.CarState;
导入java.awt.*;
导入java.security.PublicKey;
导入java.util.List;
公共类CarContract实现契约{
公共静态最终字符串CID=“com.template.contracts.CarContract”;
@凌驾
public void verify(@NotNull LedgerTransaction tx)抛出IllegalArgumentException{
//形状约束
如果(tx.getCommands().size()!=1){
抛出新的IllegalArgumentException(“应仅包含一个命令”);
}
Command Command=tx.getCommand(0);
CommandData commandType=command.getValue();
if(寄存器的commandType实例){
//形状约束
如果(!(tx.getInputState().size()!=0)){
抛出新的IllegalArgumentException(“注册合同应该没有输入状态”);
}
如果(tx.getOutputState().size()!=1){
抛出新的IllegalArgumentException(“注册合同应仅具有单个输出状态”);
}
//内容限制
ContractState outputState=tx.getOutput(0);
如果(!(输出状态实例为CarState)){
抛出新的IllegalArgumentException(“非汽车状态”);
}
如果(!((CarState)outputState).getCarMake()等于(“丰田”)||
((CarState)outputState.getCarMake().equals(“本田”)||
((CarState)outputState.getCarMake().equals(“斯巴鲁”)){
抛出新的IllegalArgumentException(“汽车必须是本田、丰田或斯巴鲁”);
}

if(((CarState)outputState).getCarYear()我在合同中看到这部分代码有问题

    // shape constraints
    if (!(tx.getInputStates().size()!=0)){
        throw new IllegalArgumentException("Registration contract should have no input states.");
    }
输入大小应该为零。但是,您正在否定该条件。这意味着如果输入大小实际上为零,您将得到一个异常


而且您的事务中没有输入,因此这应该会引发合同验证异常

我发现合同中的这部分代码有问题

    // shape constraints
    if (!(tx.getInputStates().size()!=0)){
        throw new IllegalArgumentException("Registration contract should have no input states.");
    }
输入大小应该为零。但是,您正在否定该条件。这意味着如果输入大小实际上为零,您将得到一个异常


您的交易中没有输入,因此这将引发合同验证异常

1-请共享堆栈跟踪的更多输出,以详细了解错误。2-您的合同中的错误消息<代码>发卡机构和车主必须签署合同。
与您检查的内容不匹配(您仅检查
发卡机构是否已签名:
如果(!(requiredSigners.contains(issuerKey))
)。3-您应在签名之前验证交易(即在
签名交易(txB)之前添加
txB.verify()
,对可能无效的事务进行签名有什么意义?一旦您分享了有关错误的更多详细信息并进行了修复,我可能就能确定发生了什么。另外,为什么您不使用
要求的
/
语法而不是
if
语句?请参见示例。并使用
    // shape constraints
    if (!(tx.getInputStates().size()!=0)){
        throw new IllegalArgumentException("Registration contract should have no input states.");
    }