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

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)


#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.


#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
}

#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?


#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


#7

Haha weird… Works in chrome for me…