Транзакция Hyperledger Fabric Composer не работает - PullRequest
0 голосов
/ 24 сентября 2018

Я пытаюсь добавить эту транзакцию с именем placeOrder Я хочу добавить участника Customer перед созданием ресурса Order и сопоставить его отношение с активом Order при обработке этой транзакции.Но я получаю клиенту не определенную ошибку.Кто-нибудь может помочь?Спасибо.

Мои модели

namespace org.isn.customer

participant Customer identified by email {
 o String firstName
 o String lastName
 o String email
 o String password
}

enum Status{
    o ACTIVE
    o OFF_THE_ROAD  
}

asset Vehicle identified by serial {
 o String brand
 o String model
 o String color
 o Status status
 o Double price
 o String serial
}
asset Order identified by orderId{
 o String orderId
 o Vehicle item
 --> Customer customer
}

transaction PlaceOrder {
    o String orderId
    --> Vehicle item
    o Customer customer
}

script.js

/**
 * @param {org.isn.shop.PlaceOrder}orderRequest  
 * @transaction
 */

async function placeOrder(orderRequest){

    const factory = getFactory(); 
    const customerRegistry = await getParticipantRegistry("org.isn.customer.Customer");
    const customerExists = await customerRegistry.exists(orderRequest.customer.email);

    if(!customerExists){ 
        const customer = factory.newResource("org.isn.customer","Customer",orderRequest.customer.email);
        customer.firstName = orderRequest.customer.firstName;
        customer.lastName = orderRequest.customer.lastName;
        customer.email = orderRequest.customer.email;
        customer.password = orderRequest.customer.password;
        await customerRegistry.add(customer);
    }else{
        const customer = await customerRegistry.get(orderRequest.customer.email);    
    }

    const order = await factory.newResource("org.isn.shop","Order",orderRequest.orderId);
    order.customer = customer.getIdentifier();
    order.item = orderRequest.item;
    const orderRegistry = await getAssetRegistry("org.isn.shop.Order");
    await orderRegistry.add(order);

    const PlaceOrderEvent = factory.newEvent("org.isn.shop","PlaceOrderEvent");
    placeOrderEvent.order = order;
    emit(placeOrderEvent);
}

Ответы [ 2 ]

0 голосов
/ 24 сентября 2018

Следующая версия Модели и JS будет работать для нового и существующего клиента:

    namespace org.isn.customer

participant Customer identified by email {
 o String firstName
 o String lastName
 o String email
 o String password
}

enum Status{
o ACTIVE
o OFF_THE_ROAD  
}

asset Vehicle identified by serial {
 o String brand
 o String model
 o String color
 o Status status
 o Double price
 o String serial
}

asset Order identified by orderId{
 o String orderId
 --> Vehicle item
 --> Customer customer
}

transaction PlaceOrder {
    o String orderId
    --> Vehicle item
    o Customer customer
}


/**
 * @param {org.isn.customer.PlaceOrder}orderRequest  
 * @transaction
 */

async function placeOrder(orderRequest){
    const factory = getFactory(); 
    const customerRegistry = await getParticipantRegistry("org.isn.customer.Customer");
    const customerExists = await customerRegistry.exists(orderRequest.customer.email);
    if(!customerExists){ 
        var customer = factory.newResource("org.isn.customer","Customer",orderRequest.customer.email);
        customer.firstName = orderRequest.customer.firstName;
        customer.lastName = orderRequest.customer.lastName;
        customer.email = orderRequest.customer.email;
        customer.password = orderRequest.customer.password;
        await customerRegistry.add(customer);
    }else{
        var customer = await customerRegistry.get(orderRequest.customer.email);    
    }
    const order = await factory.newResource("org.isn.customer","Order",orderRequest.orderId);
    order.customer = factory.newRelationship("org.isn.customer","Customer",customer.getIdentifier());
    order.item = orderRequest.item;
    const orderRegistry = await getAssetRegistry("org.isn.customer.Order");
    await orderRegistry.add(order);
}

Обратите внимание на следующее: В Актив заказа Я изменил o Vehicle должно быть --> Vehicle item для соответствия с транзакцией.

Я также использовал var customer в обоих кодах if и else.

(Чтобы заставить мою работу работать, мне пришлось использоватьто же пространство имен, но, возможно, у вас были отдельные файлы .cto)

0 голосов
/ 24 сентября 2018

o Customer customer должно стать --> Customer customer, тогда вы сможете ссылаться на orderRequest.customer.firstName и т. Д., Также не уверены, что вам нужно order.customer = customer.getIdentifier();, возможно, должно стать order.customer.email = customer.getIdentifier();

...