mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-25 11:05:10 +00:00
added more comment consistancy fix
Signed-off-by: Ali Shahverdi <ali@Alis-MacBook-Pro.local>
This commit is contained in:
parent
615f2fe6f9
commit
1c1b7788e8
10 changed files with 37 additions and 37 deletions
|
|
@ -75,7 +75,7 @@ async function main(): Promise<void> {
|
||||||
await getAssetsByRange(contractOrg1);
|
await getAssetsByRange(contractOrg1);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
//Attempt to transfer asset without prior aprroval from Org2, transaction expected to fail.
|
// Attempt to transfer asset without prior aprroval from Org2, transaction expected to fail.
|
||||||
console.log('\nAttempt TransferAsset without prior AgreeToTransfer');
|
console.log('\nAttempt TransferAsset without prior AgreeToTransfer');
|
||||||
await transferAsset(contractOrg1, assetID1);
|
await transferAsset(contractOrg1, assetID1);
|
||||||
doFail('TransferAsset transaction succeeded when it was expected to fail');
|
doFail('TransferAsset transaction succeeded when it was expected to fail');
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ async function initContractFromOrg1Identity() {
|
||||||
try {
|
try {
|
||||||
// Create a new gateway for connecting to Org's peer node.
|
// Create a new gateway for connecting to Org's peer node.
|
||||||
const gatewayOrg1 = new Gateway();
|
const gatewayOrg1 = new Gateway();
|
||||||
//connect using Discovery enabled
|
// Connect using Discovery enabled
|
||||||
await gatewayOrg1.connect(ccpOrg1,
|
await gatewayOrg1.connect(ccpOrg1,
|
||||||
{ wallet: walletOrg1, identity: Org1UserId, discovery: { enabled: true, asLocalhost: true } });
|
{ wallet: walletOrg1, identity: Org1UserId, discovery: { enabled: true, asLocalhost: true } });
|
||||||
|
|
||||||
|
|
@ -191,15 +191,15 @@ async function main() {
|
||||||
console.log('\n**************** As Org1 Client ****************');
|
console.log('\n**************** As Org1 Client ****************');
|
||||||
console.log('Adding Assets to work with:\n--> Submit Transaction: CreateAsset ' + assetID1);
|
console.log('Adding Assets to work with:\n--> Submit Transaction: CreateAsset ' + assetID1);
|
||||||
let statefulTxn = contractOrg1.createTransaction('CreateAsset');
|
let statefulTxn = contractOrg1.createTransaction('CreateAsset');
|
||||||
//if you need to customize endorsement to specific set of Orgs, use setEndorsingOrganizations
|
// if you need to customize endorsement to specific set of Orgs, use setEndorsingOrganizations
|
||||||
//statefulTxn.setEndorsingOrganizations(mspOrg1);
|
// statefulTxn.setEndorsingOrganizations(mspOrg1);
|
||||||
let tmapData = Buffer.from(JSON.stringify(asset1Data));
|
let tmapData = Buffer.from(JSON.stringify(asset1Data));
|
||||||
statefulTxn.setTransient({
|
statefulTxn.setTransient({
|
||||||
asset_properties: tmapData
|
asset_properties: tmapData
|
||||||
});
|
});
|
||||||
result = await statefulTxn.submit();
|
result = await statefulTxn.submit();
|
||||||
|
|
||||||
//Add asset2
|
// Add asset2
|
||||||
console.log('\n--> Submit Transaction: CreateAsset ' + assetID2);
|
console.log('\n--> Submit Transaction: CreateAsset ' + assetID2);
|
||||||
statefulTxn = contractOrg1.createTransaction('CreateAsset');
|
statefulTxn = contractOrg1.createTransaction('CreateAsset');
|
||||||
tmapData = Buffer.from(JSON.stringify(asset2Data));
|
tmapData = Buffer.from(JSON.stringify(asset2Data));
|
||||||
|
|
@ -285,13 +285,13 @@ async function main() {
|
||||||
});
|
});
|
||||||
result = await statefulTxn.submit();
|
result = await statefulTxn.submit();
|
||||||
|
|
||||||
//Again ReadAsset : results will show that the buyer identity now owns the asset:
|
// Again ReadAsset : results will show that the buyer identity now owns the asset:
|
||||||
console.log('\n--> Evaluate Transaction: ReadAsset ' + assetID1);
|
console.log('\n--> Evaluate Transaction: ReadAsset ' + assetID1);
|
||||||
result = await contractOrg1.evaluateTransaction('ReadAsset', assetID1);
|
result = await contractOrg1.evaluateTransaction('ReadAsset', assetID1);
|
||||||
console.log(`<-- result: ${prettyJSONString(result.toString())}`);
|
console.log(`<-- result: ${prettyJSONString(result.toString())}`);
|
||||||
verifyAssetData(mspOrg1, result, assetID1, 'green', 20, Org2UserId);
|
verifyAssetData(mspOrg1, result, assetID1, 'green', 20, Org2UserId);
|
||||||
|
|
||||||
//Confirm that transfer removed the private details from the Org1 collection:
|
// Confirm that transfer removed the private details from the Org1 collection:
|
||||||
console.log('\n--> Evaluate Transaction: ReadAssetPrivateDetails');
|
console.log('\n--> Evaluate Transaction: ReadAssetPrivateDetails');
|
||||||
// ReadAssetPrivateDetails reads data from Org's private collection: Should return empty
|
// ReadAssetPrivateDetails reads data from Org's private collection: Should return empty
|
||||||
result = await contractOrg1.evaluateTransaction('ReadAssetPrivateDetails', org1PrivateCollectionName, assetID1);
|
result = await contractOrg1.evaluateTransaction('ReadAssetPrivateDetails', org1PrivateCollectionName, assetID1);
|
||||||
|
|
@ -307,7 +307,7 @@ async function main() {
|
||||||
console.log('\n********* Demo deleting asset **************');
|
console.log('\n********* Demo deleting asset **************');
|
||||||
let dataForDelete = { assetID: assetID2 };
|
let dataForDelete = { assetID: assetID2 };
|
||||||
try {
|
try {
|
||||||
//Non-owner Org2 should not be able to DeleteAsset. Expect an error from DeleteAsset
|
// Non-owner Org2 should not be able to DeleteAsset. Expect an error from DeleteAsset
|
||||||
console.log('--> Attempt Transaction: as Org2 DeleteAsset ' + assetID2);
|
console.log('--> Attempt Transaction: as Org2 DeleteAsset ' + assetID2);
|
||||||
statefulTxn = contractOrg2.createTransaction('DeleteAsset');
|
statefulTxn = contractOrg2.createTransaction('DeleteAsset');
|
||||||
tmapData = Buffer.from(JSON.stringify(dataForDelete));
|
tmapData = Buffer.from(JSON.stringify(dataForDelete));
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ func (s *SmartContract) ReadAsset(ctx contractapi.TransactionContextInterface, a
|
||||||
return nil, fmt.Errorf("failed to read asset: %v", err)
|
return nil, fmt.Errorf("failed to read asset: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//No Asset found, return empty response
|
// No Asset found, return empty response
|
||||||
if assetJSON == nil {
|
if assetJSON == nil {
|
||||||
log.Printf("%v does not exist in collection %v", assetID, assetCollection)
|
log.Printf("%v does not exist in collection %v", assetID, assetCollection)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ func TestReadAssetPrivateDetails(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Nil(t, assetBytes)
|
require.Nil(t, assetBytes)
|
||||||
|
|
||||||
//read from the collection with no access
|
// read from the collection with no access
|
||||||
chaincodeStub.GetPrivateDataReturns(nil, fmt.Errorf("collection not found"))
|
chaincodeStub.GetPrivateDataReturns(nil, fmt.Errorf("collection not found"))
|
||||||
assetBytes, err = assetTransferCC.ReadAssetPrivateDetails(transactionContext, myOrg2PrivCollection, "id1")
|
assetBytes, err = assetTransferCC.ReadAssetPrivateDetails(transactionContext, myOrg2PrivCollection, "id1")
|
||||||
require.EqualError(t, err, "failed to read asset details: collection not found")
|
require.EqualError(t, err, "failed to read asset details: collection not found")
|
||||||
|
|
@ -72,7 +72,7 @@ func TestReadTransferAgreement(t *testing.T) {
|
||||||
transactionContext, chaincodeStub := prepMocksAsOrg1()
|
transactionContext, chaincodeStub := prepMocksAsOrg1()
|
||||||
assetTransferCC := chaincode.SmartContract{}
|
assetTransferCC := chaincode.SmartContract{}
|
||||||
|
|
||||||
//TransferAgreement does not exist
|
// TransferAgreement does not exist
|
||||||
assetBytes, err := assetTransferCC.ReadTransferAgreement(transactionContext, "id1")
|
assetBytes, err := assetTransferCC.ReadTransferAgreement(transactionContext, "id1")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Nil(t, assetBytes)
|
require.Nil(t, assetBytes)
|
||||||
|
|
@ -115,7 +115,7 @@ func TestQueryAssetByOwner(t *testing.T) {
|
||||||
|
|
||||||
func TestQueryAssets(t *testing.T) {
|
func TestQueryAssets(t *testing.T) {
|
||||||
transactionContext, chaincodeStub := prepMocksAsOrg1()
|
transactionContext, chaincodeStub := prepMocksAsOrg1()
|
||||||
//Iterator with no records
|
// Iterator with no records
|
||||||
iterator := &mocks.StateQueryIterator{}
|
iterator := &mocks.StateQueryIterator{}
|
||||||
iterator.HasNextReturns(false)
|
iterator.HasNextReturns(false)
|
||||||
chaincodeStub.GetPrivateDataQueryResultReturns(iterator, nil)
|
chaincodeStub.GetPrivateDataQueryResultReturns(iterator, nil)
|
||||||
|
|
@ -150,7 +150,7 @@ func TestQueryAssets(t *testing.T) {
|
||||||
|
|
||||||
func TestGetAssetByRange(t *testing.T) {
|
func TestGetAssetByRange(t *testing.T) {
|
||||||
transactionContext, chaincodeStub := prepMocksAsOrg1()
|
transactionContext, chaincodeStub := prepMocksAsOrg1()
|
||||||
//Iterator with no records
|
// Iterator with no records
|
||||||
iterator := &mocks.StateQueryIterator{}
|
iterator := &mocks.StateQueryIterator{}
|
||||||
iterator.HasNextReturns(false)
|
iterator.HasNextReturns(false)
|
||||||
chaincodeStub.GetPrivateDataByRangeReturns(iterator, nil)
|
chaincodeStub.GetPrivateDataByRangeReturns(iterator, nil)
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ func (s *SmartContract) CreateAsset(ctx contractapi.TransactionContextInterface)
|
||||||
// Asset properties are private, therefore they get passed in transient field, instead of func args
|
// Asset properties are private, therefore they get passed in transient field, instead of func args
|
||||||
transientAssetJSON, ok := transientMap["asset_properties"]
|
transientAssetJSON, ok := transientMap["asset_properties"]
|
||||||
if !ok {
|
if !ok {
|
||||||
//log error to stdout
|
// log error to stdout
|
||||||
return fmt.Errorf("asset not found in the transient map input")
|
return fmt.Errorf("asset not found in the transient map input")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ func TestCreateAssetSuccessful(t *testing.T) {
|
||||||
setReturnAssetPropsInTransientMap(t, chaincodeStub, testAsset)
|
setReturnAssetPropsInTransientMap(t, chaincodeStub, testAsset)
|
||||||
err := assetTransferCC.CreateAsset(transactionContext)
|
err := assetTransferCC.CreateAsset(transactionContext)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
//Validate PutPrivateData calls
|
// Validate PutPrivateData calls
|
||||||
calledCollection, calledId, _ := chaincodeStub.PutPrivateDataArgsForCall(0)
|
calledCollection, calledId, _ := chaincodeStub.PutPrivateDataArgsForCall(0)
|
||||||
require.Equal(t, assetCollectionName, calledCollection)
|
require.Equal(t, assetCollectionName, calledCollection)
|
||||||
require.Equal(t, "id1", calledId)
|
require.Equal(t, "id1", calledId)
|
||||||
|
|
@ -149,7 +149,7 @@ func TestAgreeToTransferBadInput(t *testing.T) {
|
||||||
|
|
||||||
assetPrivDetail := &chaincode.AssetPrivateDetails{
|
assetPrivDetail := &chaincode.AssetPrivateDetails{
|
||||||
ID: "id1",
|
ID: "id1",
|
||||||
//no AppraisedValue
|
// no AppraisedValue
|
||||||
}
|
}
|
||||||
setReturnAssetPrivateDetailsInTransientMap(t, chaincodeStub, assetPrivDetail)
|
setReturnAssetPrivateDetailsInTransientMap(t, chaincodeStub, assetPrivDetail)
|
||||||
origAsset := chaincode.Asset{
|
origAsset := chaincode.Asset{
|
||||||
|
|
@ -165,7 +165,7 @@ func TestAgreeToTransferBadInput(t *testing.T) {
|
||||||
require.EqualError(t, err, "appraisedValue field must be a positive integer")
|
require.EqualError(t, err, "appraisedValue field must be a positive integer")
|
||||||
|
|
||||||
assetPrivDetail = &chaincode.AssetPrivateDetails{
|
assetPrivDetail = &chaincode.AssetPrivateDetails{
|
||||||
//no ID
|
// no ID
|
||||||
AppraisedValue: 500,
|
AppraisedValue: 500,
|
||||||
}
|
}
|
||||||
setReturnAssetPrivateDetailsInTransientMap(t, chaincodeStub, assetPrivDetail)
|
setReturnAssetPrivateDetailsInTransientMap(t, chaincodeStub, assetPrivDetail)
|
||||||
|
|
@ -177,7 +177,7 @@ func TestAgreeToTransferBadInput(t *testing.T) {
|
||||||
AppraisedValue: 500,
|
AppraisedValue: 500,
|
||||||
}
|
}
|
||||||
setReturnAssetPrivateDetailsInTransientMap(t, chaincodeStub, assetPrivDetail)
|
setReturnAssetPrivateDetailsInTransientMap(t, chaincodeStub, assetPrivDetail)
|
||||||
//asset does not exist
|
// asset does not exist
|
||||||
setReturnPrivateDataInStub(t, chaincodeStub, nil)
|
setReturnPrivateDataInStub(t, chaincodeStub, nil)
|
||||||
err = assetTransferCC.AgreeToTransfer(transactionContext)
|
err = assetTransferCC.AgreeToTransfer(transactionContext)
|
||||||
require.EqualError(t, err, "id1 does not exist")
|
require.EqualError(t, err, "id1 does not exist")
|
||||||
|
|
@ -232,7 +232,7 @@ func TestTransferAssetBadInput(t *testing.T) {
|
||||||
BuyerMSP: myOrg2Msp,
|
BuyerMSP: myOrg2Msp,
|
||||||
}
|
}
|
||||||
setReturnAssetOwnerInTransientMap(t, chaincodeStub, assetNewOwner)
|
setReturnAssetOwnerInTransientMap(t, chaincodeStub, assetNewOwner)
|
||||||
//asset does not exist
|
// asset does not exist
|
||||||
setReturnPrivateDataInStub(t, chaincodeStub, nil)
|
setReturnPrivateDataInStub(t, chaincodeStub, nil)
|
||||||
err = assetTransferCC.TransferAsset(transactionContext)
|
err = assetTransferCC.TransferAsset(transactionContext)
|
||||||
require.EqualError(t, err, "id1 does not exist")
|
require.EqualError(t, err, "id1 does not exist")
|
||||||
|
|
@ -254,15 +254,15 @@ func TestTransferAssetSuccessful(t *testing.T) {
|
||||||
Owner: myOrg1Clientid,
|
Owner: myOrg1Clientid,
|
||||||
}
|
}
|
||||||
setReturnPrivateDataInStub(t, chaincodeStub, &origAsset)
|
setReturnPrivateDataInStub(t, chaincodeStub, &origAsset)
|
||||||
//to ensure we pass data hash verification
|
// to ensure we pass data hash verification
|
||||||
chaincodeStub.GetPrivateDataHashReturns([]byte("datahash"), nil)
|
chaincodeStub.GetPrivateDataHashReturns([]byte("datahash"), nil)
|
||||||
//to ensure that ReadTransferAgreement call returns org2 client ID
|
// to ensure that ReadTransferAgreement call returns org2 client ID
|
||||||
chaincodeStub.GetPrivateDataReturnsOnCall(1, []byte(myOrg2Clientid), nil)
|
chaincodeStub.GetPrivateDataReturnsOnCall(1, []byte(myOrg2Clientid), nil)
|
||||||
chaincodeStub.CreateCompositeKeyReturns(transferAgreementObjectType+"id1", nil)
|
chaincodeStub.CreateCompositeKeyReturns(transferAgreementObjectType+"id1", nil)
|
||||||
|
|
||||||
err := assetTransferCC.TransferAsset(transactionContext)
|
err := assetTransferCC.TransferAsset(transactionContext)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
//Validate PutPrivateData calls
|
// Validate PutPrivateData calls
|
||||||
expectedNewAsset := origAsset
|
expectedNewAsset := origAsset
|
||||||
expectedNewAsset.Owner = myOrg2Clientid
|
expectedNewAsset.Owner = myOrg2Clientid
|
||||||
expectedNewAssetBytes, err := json.Marshal(expectedNewAsset)
|
expectedNewAssetBytes, err := json.Marshal(expectedNewAsset)
|
||||||
|
|
@ -289,7 +289,7 @@ func TestTransferAssetByNonOwner(t *testing.T) {
|
||||||
BuyerMSP: myOrg1Msp,
|
BuyerMSP: myOrg1Msp,
|
||||||
}
|
}
|
||||||
setReturnAssetOwnerInTransientMap(t, chaincodeStub, assetNewOwner)
|
setReturnAssetOwnerInTransientMap(t, chaincodeStub, assetNewOwner)
|
||||||
//Try to transfer asset owned by Org2
|
// Try to transfer asset owned by Org2
|
||||||
org2Asset := chaincode.Asset{
|
org2Asset := chaincode.Asset{
|
||||||
ID: "id1",
|
ID: "id1",
|
||||||
Type: "testfulasset",
|
Type: "testfulasset",
|
||||||
|
|
@ -318,10 +318,10 @@ func TestTransferAssetWithoutAnAgreement(t *testing.T) {
|
||||||
Owner: myOrg1Clientid,
|
Owner: myOrg1Clientid,
|
||||||
}
|
}
|
||||||
setReturnPrivateDataInStub(t, chaincodeStub, &orgAsset)
|
setReturnPrivateDataInStub(t, chaincodeStub, &orgAsset)
|
||||||
//to ensure we pass data hash verification
|
// to ensure we pass data hash verification
|
||||||
chaincodeStub.GetPrivateDataHashReturns([]byte("datahash"), nil)
|
chaincodeStub.GetPrivateDataHashReturns([]byte("datahash"), nil)
|
||||||
chaincodeStub.CreateCompositeKeyReturns(transferAgreementObjectType+"id1", nil)
|
chaincodeStub.CreateCompositeKeyReturns(transferAgreementObjectType+"id1", nil)
|
||||||
//ReadTransferAgreement call returns no buyer client ID
|
// ReadTransferAgreement call returns no buyer client ID
|
||||||
chaincodeStub.GetPrivateDataReturnsOnCall(1, []byte{}, nil)
|
chaincodeStub.GetPrivateDataReturnsOnCall(1, []byte{}, nil)
|
||||||
|
|
||||||
err := assetTransferCC.TransferAsset(transactionContext)
|
err := assetTransferCC.TransferAsset(transactionContext)
|
||||||
|
|
@ -346,7 +346,7 @@ func TestTransferAssetNonMatchingAppraisalValue(t *testing.T) {
|
||||||
}
|
}
|
||||||
setReturnPrivateDataInStub(t, chaincodeStub, &orgAsset)
|
setReturnPrivateDataInStub(t, chaincodeStub, &orgAsset)
|
||||||
chaincodeStub.CreateCompositeKeyReturns(transferAgreementObjectType+"id1", nil)
|
chaincodeStub.CreateCompositeKeyReturns(transferAgreementObjectType+"id1", nil)
|
||||||
//data hash different in each collection
|
// data hash different in each collection
|
||||||
chaincodeStub.GetPrivateDataHashReturnsOnCall(0, []byte("datahash1"), nil)
|
chaincodeStub.GetPrivateDataHashReturnsOnCall(0, []byte("datahash1"), nil)
|
||||||
chaincodeStub.GetPrivateDataHashReturnsOnCall(1, []byte("datahash2"), nil)
|
chaincodeStub.GetPrivateDataHashReturnsOnCall(1, []byte("datahash2"), nil)
|
||||||
|
|
||||||
|
|
@ -369,7 +369,7 @@ func prepMocks(orgMSP, clientId string) (*mocks.TransactionContext, *mocks.Chain
|
||||||
clientIdentity := &mocks.ClientIdentity{}
|
clientIdentity := &mocks.ClientIdentity{}
|
||||||
clientIdentity.GetMSPIDReturns(orgMSP, nil)
|
clientIdentity.GetMSPIDReturns(orgMSP, nil)
|
||||||
clientIdentity.GetIDReturns(clientId, nil)
|
clientIdentity.GetIDReturns(clientId, nil)
|
||||||
//set matching msp ID using peer shim env variable
|
// set matching msp ID using peer shim env variable
|
||||||
os.Setenv("CORE_PEER_LOCALMSPID", orgMSP)
|
os.Setenv("CORE_PEER_LOCALMSPID", orgMSP)
|
||||||
transactionContext.GetClientIdentityReturns(clientIdentity)
|
transactionContext.GetClientIdentityReturns(clientIdentity)
|
||||||
return transactionContext, chaincodeStub
|
return transactionContext, chaincodeStub
|
||||||
|
|
|
||||||
|
|
@ -319,7 +319,7 @@ public final class AssetTransfer implements ContractInterface {
|
||||||
// write private data from this peer.
|
// write private data from this peer.
|
||||||
verifyClientOrgMatchesPeerOrg(ctx);
|
verifyClientOrgMatchesPeerOrg(ctx);
|
||||||
|
|
||||||
//Make submitting client the owner
|
// Make submitting client the owner
|
||||||
asset.setOwner(clientID);
|
asset.setOwner(clientID);
|
||||||
System.out.printf("CreateAsset Put: collection %s, ID %s\n", ASSET_COLLECTION_NAME, assetID);
|
System.out.printf("CreateAsset Put: collection %s, ID %s\n", ASSET_COLLECTION_NAME, assetID);
|
||||||
System.out.printf("Put: collection %s, ID %s\n", ASSET_COLLECTION_NAME, new String(asset.serialize()));
|
System.out.printf("Put: collection %s, ID %s\n", ASSET_COLLECTION_NAME, new String(asset.serialize()));
|
||||||
|
|
@ -328,7 +328,7 @@ public final class AssetTransfer implements ContractInterface {
|
||||||
// Get collection name for this organization.
|
// Get collection name for this organization.
|
||||||
String orgCollectionName = getCollectionName(ctx);
|
String orgCollectionName = getCollectionName(ctx);
|
||||||
|
|
||||||
//Save AssetPrivateDetails to org collection
|
// Save AssetPrivateDetails to org collection
|
||||||
AssetPrivateDetails assetPriv = new AssetPrivateDetails(assetID, appraisedValue);
|
AssetPrivateDetails assetPriv = new AssetPrivateDetails(assetID, appraisedValue);
|
||||||
System.out.printf("Put AssetPrivateDetails: collection %s, ID %s\n", orgCollectionName, assetID);
|
System.out.printf("Put AssetPrivateDetails: collection %s, ID %s\n", orgCollectionName, assetID);
|
||||||
stub.putPrivateData(orgCollectionName, assetID, assetPriv.serialize());
|
stub.putPrivateData(orgCollectionName, assetID, assetPriv.serialize());
|
||||||
|
|
@ -392,12 +392,12 @@ public final class AssetTransfer implements ContractInterface {
|
||||||
|
|
||||||
verifyClientOrgMatchesPeerOrg(ctx);
|
verifyClientOrgMatchesPeerOrg(ctx);
|
||||||
|
|
||||||
//Save AssetPrivateDetails to org collection
|
// Save AssetPrivateDetails to org collection
|
||||||
System.out.printf("Put AssetPrivateDetails: collection %s, ID %s\n", orgCollectionName, assetID);
|
System.out.printf("Put AssetPrivateDetails: collection %s, ID %s\n", orgCollectionName, assetID);
|
||||||
stub.putPrivateData(orgCollectionName, assetID, assetPriv.serialize());
|
stub.putPrivateData(orgCollectionName, assetID, assetPriv.serialize());
|
||||||
|
|
||||||
String clientID = ctx.getClientIdentity().getId();
|
String clientID = ctx.getClientIdentity().getId();
|
||||||
//Write the AgreeToTransfer key in assetCollection
|
// Write the AgreeToTransfer key in assetCollection
|
||||||
CompositeKey aggKey = stub.createCompositeKey(AGREEMENT_KEYPREFIX, assetID);
|
CompositeKey aggKey = stub.createCompositeKey(AGREEMENT_KEYPREFIX, assetID);
|
||||||
System.out.printf("AgreeToTransfer Put: collection %s, ID %s, Key %s\n", ASSET_COLLECTION_NAME, assetID, aggKey);
|
System.out.printf("AgreeToTransfer Put: collection %s, ID %s, Key %s\n", ASSET_COLLECTION_NAME, assetID, aggKey);
|
||||||
stub.putPrivateData(ASSET_COLLECTION_NAME, aggKey.toString(), clientID);
|
stub.putPrivateData(ASSET_COLLECTION_NAME, aggKey.toString(), clientID);
|
||||||
|
|
@ -470,15 +470,15 @@ public final class AssetTransfer implements ContractInterface {
|
||||||
String newOwner = transferAgreement.getBuyerID();
|
String newOwner = transferAgreement.getBuyerID();
|
||||||
thisAsset.setOwner(newOwner);
|
thisAsset.setOwner(newOwner);
|
||||||
|
|
||||||
//Save updated Asset to collection
|
// Save updated Asset to collection
|
||||||
System.out.printf("Transfer Asset: collection %s, ID %s to owner %s\n", ASSET_COLLECTION_NAME, assetID, newOwner);
|
System.out.printf("Transfer Asset: collection %s, ID %s to owner %s\n", ASSET_COLLECTION_NAME, assetID, newOwner);
|
||||||
stub.putPrivateData(ASSET_COLLECTION_NAME, assetID, thisAsset.serialize());
|
stub.putPrivateData(ASSET_COLLECTION_NAME, assetID, thisAsset.serialize());
|
||||||
|
|
||||||
// delete the key from owners collection
|
// Delete the key from owners collection
|
||||||
String ownersCollectionName = getCollectionName(ctx);
|
String ownersCollectionName = getCollectionName(ctx);
|
||||||
stub.delPrivateData(ownersCollectionName, assetID);
|
stub.delPrivateData(ownersCollectionName, assetID);
|
||||||
|
|
||||||
//Delete the transfer agreement from the asset collection
|
// Delete the transfer agreement from the asset collection
|
||||||
CompositeKey aggKey = stub.createCompositeKey(AGREEMENT_KEYPREFIX, assetID);
|
CompositeKey aggKey = stub.createCompositeKey(AGREEMENT_KEYPREFIX, assetID);
|
||||||
System.out.printf("AgreeToTransfer deleteKey: collection %s, ID %s, Key %s\n", ASSET_COLLECTION_NAME, assetID, aggKey);
|
System.out.printf("AgreeToTransfer deleteKey: collection %s, ID %s, Key %s\n", ASSET_COLLECTION_NAME, assetID, aggKey);
|
||||||
stub.delPrivateData(ASSET_COLLECTION_NAME, aggKey.toString());
|
stub.delPrivateData(ASSET_COLLECTION_NAME, aggKey.toString());
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ export class AssetContract extends Contract {
|
||||||
sigsPolicies.push(signedBy);
|
sigsPolicies.push(signedBy);
|
||||||
});
|
});
|
||||||
|
|
||||||
// create the policy such that it requires any N signature's from all of the principals provided
|
// Create the policy such that it requires any N signature's from all of the principals provided
|
||||||
const allOf = {
|
const allOf = {
|
||||||
n: nOrgs,
|
n: nOrgs,
|
||||||
rules: sigsPolicies
|
rules: sigsPolicies
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import { RED, RESET } from './utils';
|
||||||
const channelName = 'mychannel';
|
const channelName = 'mychannel';
|
||||||
const chaincodeName = 'secured';
|
const chaincodeName = 'secured';
|
||||||
|
|
||||||
//Use a random key so that we can run multiple times
|
// Use a random key so that we can run multiple times
|
||||||
const now = Date.now().toString();
|
const now = Date.now().toString();
|
||||||
let assetKey: string;
|
let assetKey: string;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ export const peerEndpointOrg2 = 'localhost:9051';
|
||||||
export const peerNameOrg1 = 'peer0.org1.example.com';
|
export const peerNameOrg1 = 'peer0.org1.example.com';
|
||||||
export const peerNameOrg2 = 'peer0.org2.example.com';
|
export const peerNameOrg2 = 'peer0.org2.example.com';
|
||||||
|
|
||||||
//Collection Names
|
// Collection Names
|
||||||
export const org1PrivateCollectionName = 'Org1MSPPrivateCollection';
|
export const org1PrivateCollectionName = 'Org1MSPPrivateCollection';
|
||||||
export const org2PrivateCollectionName = 'Org2MSPPrivateCollection';
|
export const org2PrivateCollectionName = 'Org2MSPPrivateCollection';
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue