Building your Own Network - Discussion

#1

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

2 Likes

#2

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)

1 Like

#3

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.

1 Like

#4

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
}
0 Likes

#5

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?

0 Likes

#6

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

1 Like

#7

Haha weird… Works in chrome for me…

0 Likes

#8

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

2 Likes

#9

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:

What does this mean?

Thanks!

1 Like

#10

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

#11

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:

0 Likes

#12

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

1 Like

#13

Thanks, I will try to make it work!

0 Likes