abdul rashid
abdul rashid

Reputation: 750

Hyperledger Updating asset and participant in a same transaction

I am testing the relationship in hyperledger.

My model file has a transaction myTransaction which has a relationship with Account using from variable.

Also this from (Account) has relationship with AccountHolder using accountholder in asset

/*
 * My first BlockChain Application
 */
namespace org.bahrain.rashidbank

asset Account identified by accountId {
    o String accountId
    o Double balance
    -- > AccountHolder accountholder
}

participant AccountHolder identified by accountholderId {
    o String accountholderId
    o String additionaldata

}

transaction myTransaction {
    -- > Account from
    o Double somenumber
    o String additionaldataa
    o String accountholderID
}

Model file

My Javascript Script file is trying to update balance and additionaldata using the transaction object rashidtransaction

/*
 * @param {org.bahrain.rashidbank.myTransaction} rashidtransaction
 * @transaction
 */
function anyfunctionname(rashidtransaction) {
    console.log("Passed Parameters", rashidtransaction);
    rashidtransaction.from.balance = rashidtransaction.somenumber;

    rashidtransaction.from.accountholder.accountholderId = rashidtransaction.accountholderID;
    rashidtransaction.from.accountholder.additionaldata = rashidtransaction.additionaldataa;


    return getAssetRegistry('org.bahrain.rashidbank.Account')
        .then(function(assetregistry) {

            return assetregistry.update(rashidtransaction.from);

        })
}

Script File

Following is the Transaction i am creating in the test page. But throwing following error

t: Instance org.bahrain.rashidbank.Account#Rashid missing required field accountholder

enter image description here

Question: Why Can't I update the AccountHolder.additionaldata participant in the same transaction.

Upvotes: 0

Views: 1235

Answers (1)

Paradox
Paradox

Reputation: 367

First I don't think you'd be able to change the unique id while updating the asset. First, you have to delete that resource and create a new resource with that unique id.

To answer your question to in order to update account holder resource you have to update its own registry i.e You also have to update accounts registry as follows:

/**
 * @param {org.bahrain.rashidbank.myTransaction} rashidtransaction
 * @transaction
 */
async function anyfunctionname(rashidtransaction) {
  let assetReg = await getAssetRegistry('org.bahrain.rashidbank.Account')
  let participantReg = await getParticipantRegistry('org.bahrain.rashidbank.AccountHolder')

  rashidtransaction.from.balance = rashidtransaction.somenumber;
  rashidtransaction.from.accountholder.additionaldata = rashidtransaction.additionaldataa;

  await assetReg.update(rashidtransaction.from)
  await participantReg.update(rashidtransaction.from.accountholder)
}

Upvotes: 1

Related Questions