Building your Own Network - Discussion

Welcome to the discussion about this lecture. Here you can ask questions or post feedback about this specific lecture.

2 Likes

I checked all files and every line of code multiple times, all items defined exactly as per Filip’s clip, no problem detected in the code by the system . but still wont let me deploy with this error message. Does anyone have the same problem? Thanks!
(PS: I’m not a programmer…yet)

image

1 Like

Even though I haven’t seen your code. I would guess you still have a reference somewhere to the old SampleTransaction. All of those instances should be renamed to CarTransaction. Take a look in all you files and see if you have any “SampleTransaction” in any of them. If you don’t. Please send me the code and I can take a look.

3 Likes

Thanks Filip, here’s my code. Still can’t find the old SampleTransaction :face_with_monocle:

Model file:

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Sample business network definition.
 */
namespace org.example.basic

asset Car identified by carId {
  o String carId
  --> Person owner
  o Integer year
  o String brand
}

participant Person identified by personId {
  o String personId
  o String firstName
  o String lastName
  o Integer age
}

transaction CarTransaction {
  --> Car car
  --> Person newOwner
}

event CarTransferEvent {
  --> Car car
  --> Person prevOwner
  --> Person newOwner
}

Script File:

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* global getAssetRegistry getFactory emit */

/**
 * Sample transaction processor function.
 * @param {org.example.basic.CarTransaction} tx The sample transaction instance.
 * @transaction
 */
async function carTransaction(tx) {  // eslint-disable-line no-unused-vars

    // Save the old value of the asset.
    const prevOwner = tx.car.owner;

    // Update the asset with the new value.
    tx.car.owner = tx.newOwner;

    // Get the asset registry for the asset.
    const assetRegistry = await getAssetRegistry('org.example.basic.Car');
    // Update the asset in the asset registry.
    await assetRegistry.update(tx.car);

    // Emit an event for the modified asset.
    let event = getFactory().newEvent('org.example.basic', 'CarTransferEvent');
    event.car = tx.car;
    event.prevOwner = prevOwner;
    event.newOwner = tx.newOwner;
    emit(event);
}

Access Control:

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Sample access control list.
 */
rule EverybodyCanReadEverything {
    description: "Allow all participants read access to all resources"
    participant: "org.example.basic.Person"
    operation: READ
    resource: "org.example.basic.*"
    action: ALLOW
}

rule EverybodyCanSubmitTransactions {
    description: "Allow all participants to submit transactions"
    participant: "org.example.basic.Person"
    operation: CREATE
    resource: "org.example.basic.CarTransaction"
    action: ALLOW
}

rule OwnerHasFullAccessToTheirAssets {
    description: "Allow all participants full access to their assets"
    participant(p): "org.example.basic.Person"
    operation: ALL
    resource(r): "org.example.basic.Car"
    condition: (r.owner.getIdentifier() === p.getIdentifier())
    action: ALLOW
}

rule SystemACL {
    description: "System ACL to permit all access"
    participant: "org.hyperledger.composer.system.Participant"
    operation: ALL
    resource: "org.hyperledger.composer.system.**"
    action: ALLOW
}

rule NetworkAdminUser {
    description: "Grant business network administrators full access to user resources"
    participant: "org.hyperledger.composer.system.NetworkAdmin"
    operation: ALL
    resource: "**"
    action: ALLOW
}

rule NetworkAdminSystem {
    description: "Grant business network administrators full access to system resources"
    participant: "org.hyperledger.composer.system.NetworkAdmin"
    operation: ALL
    resource: "org.hyperledger.composer.system.**"
    action: ALLOW
}

Thank you! I copy/pasted your exact code into the playground and it worked without trouble for me. So that’s weird. When do you get the error? When you press the deploy button?

1 Like

Hi Filip, thanks for testing it out. I kept trying the same code with Chrome with no success. I switched to Brave browser and ran the same code and immediately successfully deployed.

Must be Google plotting to sabotage blockchain… lol

4 Likes

Haha weird… Works in chrome for me…

Great review of HyperLedger- I feel comfortable with it now. By the way, 50 isn’t old and Saab is better. LOL!!!

3 Likes

Hi Filip,

I tried doing the code from scratch after watching all 3 videos. Everything seemed to work fine until I tried to process a transaction:
image

What does this mean?

Thanks!

1 Like

Figured it out! :slight_smile:

It had something to do with not being consistent with my "Car car"s. I had accidentally kept a “Car asset” somewhere.

2 Likes

Hey @filip,

Thanks for the intro to the composer, it is super interesting and nice to play around. I was wondering if it is possible to create the following network: My participants are people that can create clubs (Asset) and teams (another asset type). Participants can own clubs and teams but I also want clubs to own a team. Which means that an Asset type could be an owner of another asset type.

Is it possible to create that from the basic network, does the logic make sense to you? Really appreciate your input :slight_smile:

1 Like

Yeah I think that would be possible. Haven’t tried but I see no reason why not.

2 Likes

Thanks, I will try to make it work!

@filip Can we think of assets, participants as structs??

Yes, absolutely. They are all different types of structs I would say.

1 Like

Thank you. When I heard that Bob was “old” at 50, I thought…
“dang Filip - 50 is not old.”

2 Likes

Hi.

I agree… Just saying!
Ivo

1 Like

Hi @filip

  1. Really nice basic example. I also noticed the Blockchain ID showing when the transaction was successfully submitted. Would have been nice to see how the system generates and error message if wrong input is entered in the transaction
  2. I assume that due to the lack of user unfriendliness of the Composer’s interface, in normal development environment there would be another abstraction layer on top of the HyperLedger which provides a more GUI like UI or UX otherwise i suspect end user will panic and say that the screen is “too technical” lol
1 Like

Hmm The site doesn’t seem to work anymore :frowning: you guys going to make any updates on that part?

1 Like

Hello sir, which site do you mean? we will update the course in a future, we are working on other improvements right now, but we are aware that the business course need to get some few updates.

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.